QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
qgsvectortilebasicrendererwidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsvectortilebasicrendererwidget.cpp
3 --------------------------------------
4 Date : April 2020
5 Copyright : (C) 2020 by Martin Dobias
6 Email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17
18#include <memory>
19
20#include "qgsguiutils.h"
21#include "qgsmapcanvas.h"
22#include "qgsprojectutils.h"
23#include "qgsstyle.h"
24#include "qgssymbollayerutils.h"
27#include "qgsvectortilelayer.h"
28#include "qgsvectortileutils.h"
29
30#include <QAbstractListModel>
31#include <QInputDialog>
32#include <QMenu>
33#include <QPointer>
34#include <QScreen>
35
36#include "moc_qgsvectortilebasicrendererwidget.cpp"
37
39
40
41QgsVectorTileBasicRendererListModel::QgsVectorTileBasicRendererListModel( QgsVectorTileBasicRenderer *r, QObject *parent, QScreen *screen )
42 : QAbstractListModel( parent )
43 , mRenderer( r )
44 , mScreen( screen )
45{
46}
47
48int QgsVectorTileBasicRendererListModel::rowCount( const QModelIndex &parent ) const
49{
50 if ( parent.isValid() )
51 return 0;
52
53 return mRenderer->styles().count();
54}
55
56int QgsVectorTileBasicRendererListModel::columnCount( const QModelIndex & ) const
57{
58 return 5;
59}
60
61QVariant QgsVectorTileBasicRendererListModel::data( const QModelIndex &index, int role ) const
62{
63 if ( index.row() < 0 || index.row() >= mRenderer->styles().count() )
64 return QVariant();
65
66 const QList<QgsVectorTileBasicRendererStyle> styles = mRenderer->styles();
67 const QgsVectorTileBasicRendererStyle &style = styles[index.row()];
68
69 switch ( role )
70 {
71 case Qt::DisplayRole:
72 case Qt::ToolTipRole:
73 {
74 if ( index.column() == 0 )
75 return style.styleName();
76 else if ( index.column() == 1 )
77 return style.layerName().isEmpty() ? tr( "(all layers)" ) : style.layerName();
78 else if ( index.column() == 2 )
79 return style.minZoomLevel() >= 0 ? style.minZoomLevel() : QVariant();
80 else if ( index.column() == 3 )
81 return style.maxZoomLevel() >= 0 ? style.maxZoomLevel() : QVariant();
82 else if ( index.column() == 4 )
83 return style.filterExpression().isEmpty() ? tr( "(no filter)" ) : style.filterExpression();
84
85 break;
86 }
87
88 case Qt::EditRole:
89 {
90 if ( index.column() == 0 )
91 return style.styleName();
92 else if ( index.column() == 1 )
93 return style.layerName();
94 else if ( index.column() == 2 )
95 return style.minZoomLevel();
96 else if ( index.column() == 3 )
97 return style.maxZoomLevel();
98 else if ( index.column() == 4 )
99 return style.filterExpression();
100
101 break;
102 }
103
104 case Qt::DecorationRole:
105 {
106 if ( index.column() == 0 && style.symbol() )
107 {
108 const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
109 return QgsSymbolLayerUtils::symbolPreviewIcon( style.symbol(), QSize( iconSize, iconSize ), 0, nullptr, QgsScreenProperties( mScreen.data() ) );
110 }
111 break;
112 }
113
114 case Qt::CheckStateRole:
115 {
116 if ( index.column() != 0 )
117 return QVariant();
118 return style.isEnabled() ? Qt::Checked : Qt::Unchecked;
119 }
120
121 case MinZoom:
122 return style.minZoomLevel();
123
124 case MaxZoom:
125 return style.maxZoomLevel();
126
127 case Label:
128 return style.styleName();
129
130 case Layer:
131 return style.layerName();
132
133 case Filter:
134 return style.filterExpression();
135 }
136 return QVariant();
137}
138
139QVariant QgsVectorTileBasicRendererListModel::headerData( int section, Qt::Orientation orientation, int role ) const
140{
141 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < 5 )
142 {
143 QStringList lst;
144 lst << tr( "Label" ) << tr( "Layer" ) << tr( "Min. Zoom" ) << tr( "Max. Zoom" ) << tr( "Filter" );
145 return lst[section];
146 }
147
148 return QVariant();
149}
150
151Qt::ItemFlags QgsVectorTileBasicRendererListModel::flags( const QModelIndex &index ) const
152{
153 if ( !index.isValid() )
154 return Qt::ItemIsDropEnabled;
155
156 const Qt::ItemFlag checkable = ( index.column() == 0 ? Qt::ItemIsUserCheckable : Qt::NoItemFlags );
157
158 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable | checkable | Qt::ItemIsDragEnabled;
159}
160
161bool QgsVectorTileBasicRendererListModel::setData( const QModelIndex &index, const QVariant &value, int role )
162{
163 if ( !index.isValid() )
164 return false;
165
166 QgsVectorTileBasicRendererStyle style = mRenderer->style( index.row() );
167
168 if ( role == Qt::CheckStateRole )
169 {
170 style.setEnabled( value.toInt() == Qt::Checked );
171 mRenderer->setStyle( index.row(), style );
172 emit dataChanged( index, index );
173 return true;
174 }
175
176 if ( role == Qt::EditRole )
177 {
178 if ( index.column() == 0 )
179 style.setStyleName( value.toString() );
180 else if ( index.column() == 1 )
181 style.setLayerName( value.toString() );
182 else if ( index.column() == 2 )
183 style.setMinZoomLevel( value.toInt() );
184 else if ( index.column() == 3 )
185 style.setMaxZoomLevel( value.toInt() );
186 else if ( index.column() == 4 )
187 style.setFilterExpression( value.toString() );
188
189 mRenderer->setStyle( index.row(), style );
190 emit dataChanged( index, index );
191 return true;
192 }
193
194 return false;
195}
196
197bool QgsVectorTileBasicRendererListModel::removeRows( int row, int count, const QModelIndex &parent )
198{
199 QList<QgsVectorTileBasicRendererStyle> styles = mRenderer->styles();
200
201 if ( row < 0 || row >= styles.count() )
202 return false;
203
204 beginRemoveRows( parent, row, row + count - 1 );
205
206 for ( int i = 0; i < count; i++ )
207 {
208 if ( row < styles.count() )
209 {
210 styles.removeAt( row );
211 }
212 }
213
214 mRenderer->setStyles( styles );
215
216 endRemoveRows();
217 return true;
218}
219
220void QgsVectorTileBasicRendererListModel::insertStyle( int row, const QgsVectorTileBasicRendererStyle &style )
221{
222 beginInsertRows( QModelIndex(), row, row );
223
224 QList<QgsVectorTileBasicRendererStyle> styles = mRenderer->styles();
225 styles.insert( row, style );
226 mRenderer->setStyles( styles );
227
228 endInsertRows();
229}
230
231Qt::DropActions QgsVectorTileBasicRendererListModel::supportedDropActions() const
232{
233 return Qt::MoveAction;
234}
235
236QStringList QgsVectorTileBasicRendererListModel::mimeTypes() const
237{
238 QStringList types;
239 types << QStringLiteral( "application/vnd.text.list" );
240 return types;
241}
242
243QMimeData *QgsVectorTileBasicRendererListModel::mimeData( const QModelIndexList &indexes ) const
244{
245 QMimeData *mimeData = new QMimeData();
246 QByteArray encodedData;
247
248 QDataStream stream( &encodedData, QIODevice::WriteOnly );
249
250 const auto constIndexes = indexes;
251 for ( const QModelIndex &index : constIndexes )
252 {
253 // each item consists of several columns - let's add it with just first one
254 if ( !index.isValid() || index.column() != 0 )
255 continue;
256
257 const QgsVectorTileBasicRendererStyle style = mRenderer->style( index.row() );
258
259 QDomDocument doc;
260 QDomElement rootElem = doc.createElement( QStringLiteral( "vector_tile_basic_renderer_style_mime" ) );
261 style.writeXml( rootElem, QgsReadWriteContext() );
262 doc.appendChild( rootElem );
263
264 stream << doc.toString( -1 );
265 }
266
267 mimeData->setData( QStringLiteral( "application/vnd.text.list" ), encodedData );
268 return mimeData;
269}
270
271bool QgsVectorTileBasicRendererListModel::dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent )
272{
273 Q_UNUSED( column )
274
275 if ( action == Qt::IgnoreAction )
276 return true;
277
278 if ( !data->hasFormat( QStringLiteral( "application/vnd.text.list" ) ) )
279 return false;
280
281 if ( parent.column() > 0 )
282 return false;
283
284 QByteArray encodedData = data->data( QStringLiteral( "application/vnd.text.list" ) );
285 QDataStream stream( &encodedData, QIODevice::ReadOnly );
286 int rows = 0;
287
288 if ( row == -1 )
289 {
290 // the item was dropped at a parent - we may decide where to put the items - let's append them
291 row = rowCount( parent );
292 }
293
294 while ( !stream.atEnd() )
295 {
296 QString text;
297 stream >> text;
298
299 QDomDocument doc;
300 if ( !doc.setContent( text ) )
301 continue;
302 const QDomElement rootElem = doc.documentElement();
303 if ( rootElem.tagName() != QLatin1String( "vector_tile_basic_renderer_style_mime" ) )
304 continue;
305
307 style.readXml( rootElem, QgsReadWriteContext() );
308
309 insertStyle( row + rows, style );
310 ++rows;
311 }
312 return true;
313}
314
315
316//
317
318
319QgsVectorTileBasicRendererWidget::QgsVectorTileBasicRendererWidget( QgsVectorTileLayer *layer, QgsMapCanvas *canvas, QgsMessageBar *messageBar, QWidget *parent )
320 : QgsMapLayerConfigWidget( layer, canvas, parent )
321 , mMapCanvas( canvas )
322 , mMessageBar( messageBar )
323{
324 setupUi( this );
325 layout()->setContentsMargins( 0, 0, 0, 0 );
326
327 mFilterLineEdit->setShowClearButton( true );
328 mFilterLineEdit->setShowSearchIcon( true );
329 mFilterLineEdit->setPlaceholderText( tr( "Filter rules" ) );
330
331 QMenu *menuAddRule = new QMenu( btnAddRule );
332 menuAddRule->addAction( tr( "Marker" ), this, [this] { addStyle( Qgis::GeometryType::Point ); } );
333 menuAddRule->addAction( tr( "Line" ), this, [this] { addStyle( Qgis::GeometryType::Line ); } );
334 menuAddRule->addAction( tr( "Fill" ), this, [this] { addStyle( Qgis::GeometryType::Polygon ); } );
335 btnAddRule->setMenu( menuAddRule );
336
337 connect( btnEditRule, &QPushButton::clicked, this, &QgsVectorTileBasicRendererWidget::editStyle );
338 connect( btnRemoveRule, &QAbstractButton::clicked, this, &QgsVectorTileBasicRendererWidget::removeStyle );
339
340 connect( viewStyles, &QAbstractItemView::doubleClicked, this, &QgsVectorTileBasicRendererWidget::editStyleAtIndex );
341
342 if ( mMapCanvas )
343 {
344 connect( mMapCanvas, &QgsMapCanvas::scaleChanged, this, [this]( double scale ) {
345 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
346 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(), mapSettings.destinationCrs(), mapSettings.visibleExtent(), mapSettings.outputSize(), mapSettings.outputDpi() ) : scale;
347 const int zoom = mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 );
348 mLabelCurrentZoom->setText( tr( "Current zoom: %1" ).arg( zoom ) );
349 if ( mProxyModel )
350 mProxyModel->setCurrentZoom( zoom );
351 } );
352
353 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
354 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(), mapSettings.destinationCrs(), mapSettings.visibleExtent(), mapSettings.outputSize(), mapSettings.outputDpi() ) : mMapCanvas->scale();
355 mLabelCurrentZoom->setText( tr( "Current zoom: %1" ).arg( mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 ) ) );
356 }
357
358 connect( mCheckVisibleOnly, &QCheckBox::toggled, this, [this]( bool filter ) {
359 mProxyModel->setFilterVisible( filter );
360 } );
361
362 connect( mFilterLineEdit, &QgsFilterLineEdit::textChanged, this, [this]( const QString &text ) {
363 mProxyModel->setFilterString( text );
364 } );
365
366 syncToLayer( layer );
367
368 connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsPanelWidget::widgetChanged );
369 connect( mBlendModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsPanelWidget::widgetChanged );
370}
371
372void QgsVectorTileBasicRendererWidget::syncToLayer( QgsMapLayer *layer )
373{
374 QgsVectorTileLayer *vtLayer = qobject_cast<QgsVectorTileLayer *>( layer );
375 if ( !vtLayer )
376 return;
377
378 mVTLayer = vtLayer;
379
380 if ( layer && vtLayer->renderer() && vtLayer->renderer()->type() == QLatin1String( "basic" ) )
381 {
382 mRenderer.reset( static_cast<QgsVectorTileBasicRenderer *>( vtLayer->renderer()->clone() ) );
383 }
384 else
385 {
386 mRenderer = std::make_unique<QgsVectorTileBasicRenderer>();
387 }
388
389 mModel = new QgsVectorTileBasicRendererListModel( mRenderer.get(), viewStyles, screen() );
390 mProxyModel = new QgsVectorTileBasicRendererProxyModel( mModel, viewStyles );
391 viewStyles->setModel( mProxyModel );
392
393 if ( mMapCanvas )
394 {
395 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
396 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(), mapSettings.destinationCrs(), mapSettings.visibleExtent(), mapSettings.outputSize(), mapSettings.outputDpi() ) : mMapCanvas->scale();
397 const int zoom = mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 );
398 mProxyModel->setCurrentZoom( zoom );
399 }
400
401 connect( mModel, &QAbstractItemModel::dataChanged, this, &QgsPanelWidget::widgetChanged );
402 connect( mModel, &QAbstractItemModel::rowsInserted, this, &QgsPanelWidget::widgetChanged );
403 connect( mModel, &QAbstractItemModel::rowsRemoved, this, &QgsPanelWidget::widgetChanged );
404
405 mOpacityWidget->setOpacity( mVTLayer->opacity() );
406
407 //blend mode
408 mBlendModeComboBox->setShowClippingModes( QgsProjectUtils::layerIsContainedInGroupLayer( QgsProject::instance(), mVTLayer ) );
409 mBlendModeComboBox->setBlendMode( mVTLayer->blendMode() );
410}
411
412QgsVectorTileBasicRendererWidget::~QgsVectorTileBasicRendererWidget() = default;
413
414void QgsVectorTileBasicRendererWidget::apply()
415{
416 mVTLayer->setRenderer( mRenderer->clone() );
417 mVTLayer->setBlendMode( mBlendModeComboBox->blendMode() );
418 mVTLayer->setOpacity( mOpacityWidget->opacity() );
419}
420
421void QgsVectorTileBasicRendererWidget::addStyle( Qgis::GeometryType geomType )
422{
423 QgsVectorTileBasicRendererStyle style( QString(), QString(), geomType );
424 style.setSymbol( QgsSymbol::defaultSymbol( geomType ) );
425
426 switch ( geomType )
427 {
429 style.setFilterExpression( QStringLiteral( "geometry_type(@geometry)='Point'" ) );
430 break;
432 style.setFilterExpression( QStringLiteral( "geometry_type(@geometry)='Line'" ) );
433 break;
435 style.setFilterExpression( QStringLiteral( "geometry_type(@geometry)='Polygon'" ) );
436 break;
439 break;
440 }
441
442 const int rows = mModel->rowCount();
443 mModel->insertStyle( rows, style );
444 viewStyles->selectionModel()->setCurrentIndex( mProxyModel->mapFromSource( mModel->index( rows, 0 ) ), QItemSelectionModel::ClearAndSelect );
445}
446
447void QgsVectorTileBasicRendererWidget::editStyle()
448{
449 editStyleAtIndex( viewStyles->selectionModel()->currentIndex() );
450}
451
452void QgsVectorTileBasicRendererWidget::editStyleAtIndex( const QModelIndex &proxyIndex )
453{
454 const QModelIndex index = mProxyModel->mapToSource( proxyIndex );
455 if ( index.row() < 0 || index.row() >= mRenderer->styles().count() )
456 return;
457
458 QgsVectorTileBasicRendererStyle style = mRenderer->style( index.row() );
459
460 if ( !style.symbol() )
461 return;
462
463 std::unique_ptr<QgsSymbol> symbol( style.symbol()->clone() );
464
466 context.setMapCanvas( mMapCanvas );
467 context.setMessageBar( mMessageBar );
468
469 if ( mMapCanvas )
470 {
471 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
472 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(), mapSettings.destinationCrs(), mapSettings.visibleExtent(), mapSettings.outputSize(), mapSettings.outputDpi() ) : mMapCanvas->scale();
473 const int zoom = mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 );
474 QList<QgsExpressionContextScope> scopes = context.additionalExpressionContextScopes();
476 tileScope.setVariable( "zoom_level", zoom, true );
477 tileScope.setVariable( "vector_tile_zoom", mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoom( mMapCanvas->scale() ) : QgsVectorTileUtils::scaleToZoom( mMapCanvas->scale() ), true );
478 scopes << tileScope;
479 context.setAdditionalExpressionContextScopes( scopes );
480 }
481
482 QgsVectorLayer *vectorLayer = nullptr; // TODO: have a temporary vector layer with sub-layer's fields?
483
485 if ( panel && panel->dockMode() )
486 {
488 widget->setContext( context );
489 widget->setPanelTitle( style.styleName() );
490 connect( widget, &QgsPanelWidget::widgetChanged, this, [this, widget] { updateSymbolsFromWidget( widget ); } );
491 openPanel( widget );
492 }
493 else
494 {
495 QgsSymbolSelectorDialog dlg( symbol.get(), QgsStyle::defaultStyle(), vectorLayer, panel );
496 dlg.setContext( context );
497 if ( !dlg.exec() || !symbol )
498 {
499 return;
500 }
501
502 style.setSymbol( symbol.release() );
503 mRenderer->setStyle( index.row(), style );
504 emit widgetChanged();
505 }
506}
507
508void QgsVectorTileBasicRendererWidget::updateSymbolsFromWidget( QgsSymbolSelectorWidget *widget )
509{
510 const int index = mProxyModel->mapToSource( viewStyles->selectionModel()->currentIndex() ).row();
511 if ( index < 0 )
512 return;
513
514 QgsVectorTileBasicRendererStyle style = mRenderer->style( index );
515
516 style.setSymbol( widget->symbol()->clone() );
517
518 mRenderer->setStyle( index, style );
519 emit widgetChanged();
520}
521
522void QgsVectorTileBasicRendererWidget::removeStyle()
523{
524 const QModelIndexList sel = viewStyles->selectionModel()->selectedIndexes();
525
526 QList<int> res;
527 for ( const QModelIndex &proxyIndex : sel )
528 {
529 const QModelIndex sourceIndex = mProxyModel->mapToSource( proxyIndex );
530 if ( !res.contains( sourceIndex.row() ) )
531 res << sourceIndex.row();
532 }
533 std::sort( res.begin(), res.end() );
534
535 for ( int i = res.size() - 1; i >= 0; --i )
536 {
537 mModel->removeRow( res[i] );
538 }
539 // make sure that the selection is gone
540 viewStyles->selectionModel()->clear();
541}
542
543QgsVectorTileBasicRendererProxyModel::QgsVectorTileBasicRendererProxyModel( QgsVectorTileBasicRendererListModel *source, QObject *parent )
544 : QSortFilterProxyModel( parent )
545{
546 setSourceModel( source );
547 setDynamicSortFilter( true );
548}
549
550void QgsVectorTileBasicRendererProxyModel::setCurrentZoom( int zoom )
551{
552 mCurrentZoom = zoom;
553 invalidateFilter();
554}
555
556void QgsVectorTileBasicRendererProxyModel::setFilterVisible( bool enabled )
557{
558 mFilterVisible = enabled;
559 invalidateFilter();
560}
561
562void QgsVectorTileBasicRendererProxyModel::setFilterString( const QString &string )
563{
564 mFilterString = string;
565 invalidateFilter();
566}
567
568bool QgsVectorTileBasicRendererProxyModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const
569{
570 if ( mCurrentZoom >= 0 && mFilterVisible )
571 {
572 const int rowMinZoom = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicRendererListModel::MinZoom ).toInt();
573 const int rowMaxZoom = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicRendererListModel::MaxZoom ).toInt();
574
575 if ( rowMinZoom >= 0 && rowMinZoom > mCurrentZoom )
576 return false;
577
578 if ( rowMaxZoom >= 0 && rowMaxZoom < mCurrentZoom )
579 return false;
580 }
581
582 if ( !mFilterString.isEmpty() )
583 {
584 const QString name = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicRendererListModel::Label ).toString();
585 const QString layer = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicRendererListModel::Layer ).toString();
586 const QString filter = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicRendererListModel::Filter ).toString();
587 if ( !name.contains( mFilterString, Qt::CaseInsensitive )
588 && !layer.contains( mFilterString, Qt::CaseInsensitive )
589 && !filter.contains( mFilterString, Qt::CaseInsensitive ) )
590 {
591 return false;
592 }
593 }
594
595 return true;
596}
597
598
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:358
@ Point
Points.
Definition qgis.h:359
@ Line
Lines.
Definition qgis.h:360
@ Polygon
Polygons.
Definition qgis.h:361
@ Unknown
Unknown types.
Definition qgis.h:362
@ Null
No geometry.
Definition qgis.h:363
Single scope for storing variables and functions for use within a QgsExpressionContext.
void setVariable(const QString &name, const QVariant &value, bool isStatic=false)
Convenience method for setting a variable in the context scope by name name and value.
Map canvas is a class for displaying all GIS data types on a canvas.
void scaleChanged(double scale)
Emitted when the scale of the map changes.
A panel widget that can be shown in the map style dock.
Base class for all map layer types.
Definition qgsmaplayer.h:80
Contains configuration for rendering maps.
double scale() const
Returns the calculated map scale.
QSize outputSize() const
Returns the size of the resulting map image, in pixels.
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes output image size into account.
double outputDpi() const
Returns the DPI (dots per inch) used for conversion between real world units (e.g.
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
A bar for displaying non-blocking messages to the user.
void opacityChanged(double opacity)
Emitted when the opacity is changed in the widget, where opacity ranges from 0.0 (transparent) to 1....
Base class for any widget that can be shown as an inline panel.
bool dockMode() const
Returns the dock mode state.
void widgetChanged()
Emitted when the widget state changes.
static QgsPanelWidget * findParentPanel(QWidget *widget)
Traces through the parents of a widget to find if it is contained within a QgsPanelWidget widget.
void setPanelTitle(const QString &panelTitle)
Set the title of the panel when shown in the interface.
static bool layerIsContainedInGroupLayer(QgsProject *project, QgsMapLayer *layer)
Returns true if the specified layer is a child layer from any QgsGroupLayer in the given project.
static QgsProject * instance()
Returns the QgsProject singleton instance.
A container for the context for various read/write operations on objects.
Stores properties relating to a screen.
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
Definition qgsstyle.cpp:147
static QIcon symbolPreviewIcon(const QgsSymbol *symbol, QSize size, int padding=0, QgsLegendPatchShape *shape=nullptr, const QgsScreenProperties &screen=QgsScreenProperties())
Returns an icon preview for a color ramp.
A dialog that can be used to select and build a symbol.
Symbol selector widget that can be used to select and build a symbol.
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the symbol widget is shown, e.g., the associated map canvas and expression ...
QgsSymbol * symbol()
Returns the symbol that is currently active in the widget.
static QgsSymbolSelectorWidget * createWidgetWithSymbolOwnership(std::unique_ptr< QgsSymbol > symbol, QgsStyle *style, QgsVectorLayer *vl, QWidget *parent=nullptr)
Creates a QgsSymbolSelectorWidget which takes ownership of a symbol and maintains the ownership for t...
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
QList< QgsExpressionContextScope > additionalExpressionContextScopes() const
Returns the list of additional expression context scopes to show as available within the layer.
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
void setAdditionalExpressionContextScopes(const QList< QgsExpressionContextScope > &scopes)
Sets a list of additional expression context scopes to show as available within the layer.
void setMessageBar(QgsMessageBar *bar)
Sets the message bar associated with the widget.
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
static QgsSymbol * defaultSymbol(Qgis::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
Represents a vector layer which manages a vector based dataset.
Definition of map rendering of a subset of vector tile data.
void setEnabled(bool enabled)
Sets whether this style is enabled (used for rendering).
void setMinZoomLevel(int minZoom)
Sets minimum zoom level index (negative number means no limit).
void setLayerName(const QString &name)
Sets name of the sub-layer to render (empty layer means that all layers match).
QgsSymbol * symbol() const
Returns symbol for rendering.
QString filterExpression() const
Returns filter expression (empty filter means that all features match).
QString styleName() const
Returns human readable name of this style.
void setFilterExpression(const QString &expr)
Sets filter expression (empty filter means that all features match).
void setSymbol(QgsSymbol *sym)
Sets symbol for rendering. Takes ownership of the symbol.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const
Writes object content to given DOM element.
void setStyleName(const QString &name)
Sets human readable name of this style.
bool isEnabled() const
Returns whether this style is enabled (used for rendering).
void setMaxZoomLevel(int maxZoom)
Sets maximum zoom level index (negative number means no limit).
int minZoomLevel() const
Returns the minimum zoom level index (negative number means no limit).
int maxZoomLevel() const
Returns the maximum zoom level index (negative number means no limit).
QString layerName() const
Returns name of the sub-layer to render (empty layer means that all layers match).
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Reads object content from given DOM element.
The default vector tile renderer implementation.
Implements a map layer that is dedicated to rendering of vector tiles.
QgsVectorTileRenderer * renderer() const
Returns currently assigned renderer.
virtual QString type() const =0
Returns unique type name of the renderer implementation.
virtual QgsVectorTileRenderer * clone() const =0
Returns a clone of the renderer.
static double scaleToZoom(double mapScale, double z0Scale=559082264.0287178)
Finds zoom level given map scale denominator.
static int scaleToZoomLevel(double mapScale, int sourceMinZoom, int sourceMaxZoom, double z0Scale=559082264.0287178)
Finds the best fitting zoom level given a map scale denominator and allowed zoom level range.
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly,...