QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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 "qgsguiutils.h"
19#include "qgssymbollayerutils.h"
21#include "qgsvectortilelayer.h"
23#include "qgsstyle.h"
24#include "qgsmapcanvas.h"
25#include "qgsvectortileutils.h"
26
27#include <QAbstractListModel>
28#include <QInputDialog>
29#include <QMenu>
30
31
33
34
35QgsVectorTileBasicRendererListModel::QgsVectorTileBasicRendererListModel( QgsVectorTileBasicRenderer *r, QObject *parent )
36 : QAbstractListModel( parent )
37 , mRenderer( r )
38{
39}
40
41int QgsVectorTileBasicRendererListModel::rowCount( const QModelIndex &parent ) const
42{
43 if ( parent.isValid() )
44 return 0;
45
46 return mRenderer->styles().count();
47}
48
49int QgsVectorTileBasicRendererListModel::columnCount( const QModelIndex & ) const
50{
51 return 5;
52}
53
54QVariant QgsVectorTileBasicRendererListModel::data( const QModelIndex &index, int role ) const
55{
56 if ( index.row() < 0 || index.row() >= mRenderer->styles().count() )
57 return QVariant();
58
59 const QList<QgsVectorTileBasicRendererStyle> styles = mRenderer->styles();
60 const QgsVectorTileBasicRendererStyle &style = styles[index.row()];
61
62 switch ( role )
63 {
64 case Qt::DisplayRole:
65 case Qt::ToolTipRole:
66 {
67 if ( index.column() == 0 )
68 return style.styleName();
69 else if ( index.column() == 1 )
70 return style.layerName().isEmpty() ? tr( "(all layers)" ) : style.layerName();
71 else if ( index.column() == 2 )
72 return style.minZoomLevel() >= 0 ? style.minZoomLevel() : QVariant();
73 else if ( index.column() == 3 )
74 return style.maxZoomLevel() >= 0 ? style.maxZoomLevel() : QVariant();
75 else if ( index.column() == 4 )
76 return style.filterExpression().isEmpty() ? tr( "(no filter)" ) : style.filterExpression();
77
78 break;
79 }
80
81 case Qt::EditRole:
82 {
83 if ( index.column() == 0 )
84 return style.styleName();
85 else if ( index.column() == 1 )
86 return style.layerName();
87 else if ( index.column() == 2 )
88 return style.minZoomLevel();
89 else if ( index.column() == 3 )
90 return style.maxZoomLevel();
91 else if ( index.column() == 4 )
92 return style.filterExpression();
93
94 break;
95 }
96
97 case Qt::DecorationRole:
98 {
99 if ( index.column() == 0 && style.symbol() )
100 {
101 const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
103 }
104 break;
105 }
106
107 case Qt::CheckStateRole:
108 {
109 if ( index.column() != 0 )
110 return QVariant();
111 return style.isEnabled() ? Qt::Checked : Qt::Unchecked;
112 }
113
114 case MinZoom:
115 return style.minZoomLevel();
116
117 case MaxZoom:
118 return style.maxZoomLevel();
119
120 case Label:
121 return style.styleName();
122
123 case Layer:
124 return style.layerName();
125
126 case Filter:
127 return style.filterExpression();
128
129 }
130 return QVariant();
131}
132
133QVariant QgsVectorTileBasicRendererListModel::headerData( int section, Qt::Orientation orientation, int role ) const
134{
135 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < 5 )
136 {
137 QStringList lst;
138 lst << tr( "Label" ) << tr( "Layer" ) << tr( "Min. Zoom" ) << tr( "Max. Zoom" ) << tr( "Filter" );
139 return lst[section];
140 }
141
142 return QVariant();
143}
144
145Qt::ItemFlags QgsVectorTileBasicRendererListModel::flags( const QModelIndex &index ) const
146{
147 if ( !index.isValid() )
148 return Qt::ItemIsDropEnabled;
149
150 const Qt::ItemFlag checkable = ( index.column() == 0 ? Qt::ItemIsUserCheckable : Qt::NoItemFlags );
151
152 return Qt::ItemIsEnabled | Qt::ItemIsSelectable |
153 Qt::ItemIsEditable | checkable |
154 Qt::ItemIsDragEnabled;
155}
156
157bool QgsVectorTileBasicRendererListModel::setData( const QModelIndex &index, const QVariant &value, int role )
158{
159 if ( !index.isValid() )
160 return false;
161
162 QgsVectorTileBasicRendererStyle style = mRenderer->style( index.row() );
163
164 if ( role == Qt::CheckStateRole )
165 {
166 style.setEnabled( value.toInt() == Qt::Checked );
167 mRenderer->setStyle( index.row(), style );
168 emit dataChanged( index, index );
169 return true;
170 }
171
172 if ( role == Qt::EditRole )
173 {
174 if ( index.column() == 0 )
175 style.setStyleName( value.toString() );
176 else if ( index.column() == 1 )
177 style.setLayerName( value.toString() );
178 else if ( index.column() == 2 )
179 style.setMinZoomLevel( value.toInt() );
180 else if ( index.column() == 3 )
181 style.setMaxZoomLevel( value.toInt() );
182 else if ( index.column() == 4 )
183 style.setFilterExpression( value.toString() );
184
185 mRenderer->setStyle( index.row(), style );
186 emit dataChanged( index, index );
187 return true;
188 }
189
190 return false;
191}
192
193bool QgsVectorTileBasicRendererListModel::removeRows( int row, int count, const QModelIndex &parent )
194{
195 QList<QgsVectorTileBasicRendererStyle> styles = mRenderer->styles();
196
197 if ( row < 0 || row >= styles.count() )
198 return false;
199
200 beginRemoveRows( parent, row, row + count - 1 );
201
202 for ( int i = 0; i < count; i++ )
203 {
204 if ( row < styles.count() )
205 {
206 styles.removeAt( row );
207 }
208 }
209
210 mRenderer->setStyles( styles );
211
212 endRemoveRows();
213 return true;
214}
215
216void QgsVectorTileBasicRendererListModel::insertStyle( int row, const QgsVectorTileBasicRendererStyle &style )
217{
218 beginInsertRows( QModelIndex(), row, row );
219
220 QList<QgsVectorTileBasicRendererStyle> styles = mRenderer->styles();
221 styles.insert( row, style );
222 mRenderer->setStyles( styles );
223
224 endInsertRows();
225}
226
227Qt::DropActions QgsVectorTileBasicRendererListModel::supportedDropActions() const
228{
229 return Qt::MoveAction;
230}
231
232QStringList QgsVectorTileBasicRendererListModel::mimeTypes() const
233{
234 QStringList types;
235 types << QStringLiteral( "application/vnd.text.list" );
236 return types;
237}
238
239QMimeData *QgsVectorTileBasicRendererListModel::mimeData( const QModelIndexList &indexes ) const
240{
241 QMimeData *mimeData = new QMimeData();
242 QByteArray encodedData;
243
244 QDataStream stream( &encodedData, QIODevice::WriteOnly );
245
246 const auto constIndexes = indexes;
247 for ( const QModelIndex &index : constIndexes )
248 {
249 // each item consists of several columns - let's add it with just first one
250 if ( !index.isValid() || index.column() != 0 )
251 continue;
252
253 const QgsVectorTileBasicRendererStyle style = mRenderer->style( index.row() );
254
255 QDomDocument doc;
256 QDomElement rootElem = doc.createElement( QStringLiteral( "vector_tile_basic_renderer_style_mime" ) );
257 style.writeXml( rootElem, QgsReadWriteContext() );
258 doc.appendChild( rootElem );
259
260 stream << doc.toString( -1 );
261 }
262
263 mimeData->setData( QStringLiteral( "application/vnd.text.list" ), encodedData );
264 return mimeData;
265}
266
267bool QgsVectorTileBasicRendererListModel::dropMimeData( const QMimeData *data,
268 Qt::DropAction action, int row, int column, const QModelIndex &parent )
269{
270 Q_UNUSED( column )
271
272 if ( action == Qt::IgnoreAction )
273 return true;
274
275 if ( !data->hasFormat( QStringLiteral( "application/vnd.text.list" ) ) )
276 return false;
277
278 if ( parent.column() > 0 )
279 return false;
280
281 QByteArray encodedData = data->data( QStringLiteral( "application/vnd.text.list" ) );
282 QDataStream stream( &encodedData, QIODevice::ReadOnly );
283 int rows = 0;
284
285 if ( row == -1 )
286 {
287 // the item was dropped at a parent - we may decide where to put the items - let's append them
288 row = rowCount( parent );
289 }
290
291 while ( !stream.atEnd() )
292 {
293 QString text;
294 stream >> text;
295
296 QDomDocument doc;
297 if ( !doc.setContent( text ) )
298 continue;
299 const QDomElement rootElem = doc.documentElement();
300 if ( rootElem.tagName() != QLatin1String( "vector_tile_basic_renderer_style_mime" ) )
301 continue;
302
304 style.readXml( rootElem, QgsReadWriteContext() );
305
306 insertStyle( row + rows, style );
307 ++rows;
308 }
309 return true;
310}
311
312
313//
314
315
316QgsVectorTileBasicRendererWidget::QgsVectorTileBasicRendererWidget( QgsVectorTileLayer *layer, QgsMapCanvas *canvas, QgsMessageBar *messageBar, QWidget *parent )
317 : QgsMapLayerConfigWidget( layer, canvas, parent )
318 , mMapCanvas( canvas )
319 , mMessageBar( messageBar )
320{
321 setupUi( this );
322 layout()->setContentsMargins( 0, 0, 0, 0 );
323
324 mFilterLineEdit->setShowClearButton( true );
325 mFilterLineEdit->setShowSearchIcon( true );
326 mFilterLineEdit->setPlaceholderText( tr( "Filter rules" ) );
327
328 QMenu *menuAddRule = new QMenu( btnAddRule );
329 menuAddRule->addAction( tr( "Marker" ), this, [this] { addStyle( QgsWkbTypes::PointGeometry ); } );
330 menuAddRule->addAction( tr( "Line" ), this, [this] { addStyle( QgsWkbTypes::LineGeometry ); } );
331 menuAddRule->addAction( tr( "Fill" ), this, [this] { addStyle( QgsWkbTypes::PolygonGeometry ); } );
332 btnAddRule->setMenu( menuAddRule );
333
334 connect( btnEditRule, &QPushButton::clicked, this, &QgsVectorTileBasicRendererWidget::editStyle );
335 connect( btnRemoveRule, &QAbstractButton::clicked, this, &QgsVectorTileBasicRendererWidget::removeStyle );
336
337 connect( viewStyles, &QAbstractItemView::doubleClicked, this, &QgsVectorTileBasicRendererWidget::editStyleAtIndex );
338
339 if ( mMapCanvas )
340 {
341 connect( mMapCanvas, &QgsMapCanvas::scaleChanged, this, [ = ]( double scale )
342 {
343 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
344 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(),
345 mapSettings.destinationCrs(),
346 mapSettings.visibleExtent(),
347 mapSettings.outputSize(),
348 mapSettings.outputDpi() ) : scale;
349 const int zoom = mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 );
350 mLabelCurrentZoom->setText( tr( "Current zoom: %1" ).arg( zoom ) );
351 if ( mProxyModel )
352 mProxyModel->setCurrentZoom( zoom );
353 } );
354
355 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
356 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(),
357 mapSettings.destinationCrs(),
358 mapSettings.visibleExtent(),
359 mapSettings.outputSize(),
360 mapSettings.outputDpi() ) : mMapCanvas->scale();
361 mLabelCurrentZoom->setText( tr( "Current zoom: %1" ).arg( mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 ) ) );
362 }
363
364 connect( mCheckVisibleOnly, &QCheckBox::toggled, this, [ = ]( bool filter )
365 {
366 mProxyModel->setFilterVisible( filter );
367 } );
368
369 connect( mFilterLineEdit, &QgsFilterLineEdit::textChanged, this, [ = ]( const QString & text )
370 {
371 mProxyModel->setFilterString( text );
372 } );
373
374 setLayer( layer );
375}
376
377void QgsVectorTileBasicRendererWidget::setLayer( QgsVectorTileLayer *layer )
378{
379 mVTLayer = layer;
380
381 if ( layer && layer->renderer() && layer->renderer()->type() == QLatin1String( "basic" ) )
382 {
383 mRenderer.reset( static_cast<QgsVectorTileBasicRenderer *>( layer->renderer()->clone() ) );
384 }
385 else
386 {
387 mRenderer.reset( new QgsVectorTileBasicRenderer() );
388 }
389
390 mModel = new QgsVectorTileBasicRendererListModel( mRenderer.get(), viewStyles );
391 mProxyModel = new QgsVectorTileBasicRendererProxyModel( mModel, viewStyles );
392 viewStyles->setModel( mProxyModel );
393
394 if ( mMapCanvas )
395 {
396 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
397 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(),
398 mapSettings.destinationCrs(),
399 mapSettings.visibleExtent(),
400 mapSettings.outputSize(),
401 mapSettings.outputDpi() ) : mMapCanvas->scale();
402 const int zoom = mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 );
403 mProxyModel->setCurrentZoom( zoom );
404 }
405
406 connect( mModel, &QAbstractItemModel::dataChanged, this, &QgsPanelWidget::widgetChanged );
407 connect( mModel, &QAbstractItemModel::rowsInserted, this, &QgsPanelWidget::widgetChanged );
408 connect( mModel, &QAbstractItemModel::rowsRemoved, this, &QgsPanelWidget::widgetChanged );
409}
410
411QgsVectorTileBasicRendererWidget::~QgsVectorTileBasicRendererWidget() = default;
412
413void QgsVectorTileBasicRendererWidget::apply()
414{
415 mVTLayer->setRenderer( mRenderer->clone() );
416}
417
418void QgsVectorTileBasicRendererWidget::addStyle( QgsWkbTypes::GeometryType geomType )
419{
420 QgsVectorTileBasicRendererStyle style( QString(), QString(), geomType );
421 style.setSymbol( QgsSymbol::defaultSymbol( geomType ) );
422
423 switch ( geomType )
424 {
426 style.setFilterExpression( QStringLiteral( "geometry_type($geometry)='Point'" ) );
427 break;
429 style.setFilterExpression( QStringLiteral( "geometry_type($geometry)='Line'" ) );
430 break;
432 style.setFilterExpression( QStringLiteral( "geometry_type($geometry)='Polygon'" ) );
433 break;
436 break;
437 }
438
439 const int rows = mModel->rowCount();
440 mModel->insertStyle( rows, style );
441 viewStyles->selectionModel()->setCurrentIndex( mProxyModel->mapFromSource( mModel->index( rows, 0 ) ), QItemSelectionModel::ClearAndSelect );
442}
443
444void QgsVectorTileBasicRendererWidget::editStyle()
445{
446 editStyleAtIndex( viewStyles->selectionModel()->currentIndex() );
447}
448
449void QgsVectorTileBasicRendererWidget::editStyleAtIndex( const QModelIndex &proxyIndex )
450{
451 const QModelIndex index = mProxyModel->mapToSource( proxyIndex );
452 if ( index.row() < 0 || index.row() >= mRenderer->styles().count() )
453 return;
454
455 QgsVectorTileBasicRendererStyle style = mRenderer->style( index.row() );
456
457 if ( !style.symbol() )
458 return;
459
460 std::unique_ptr< QgsSymbol > symbol( style.symbol()->clone() );
461
463 context.setMapCanvas( mMapCanvas );
464 context.setMessageBar( mMessageBar );
465
466 if ( mMapCanvas )
467 {
468 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
469 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(),
470 mapSettings.destinationCrs(),
471 mapSettings.visibleExtent(),
472 mapSettings.outputSize(),
473 mapSettings.outputDpi() ) : mMapCanvas->scale();
474 const int zoom = mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 );
475 QList<QgsExpressionContextScope> scopes = context.additionalExpressionContextScopes();
477 tileScope.setVariable( "zoom_level", zoom, true );
478 tileScope.setVariable( "vector_tile_zoom", mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoom( mMapCanvas->scale() ) : QgsVectorTileUtils::scaleToZoom( mMapCanvas->scale() ), true );
479 scopes << tileScope;
480 context.setAdditionalExpressionContextScopes( scopes );
481 }
482
483 QgsVectorLayer *vectorLayer = nullptr; // TODO: have a temporary vector layer with sub-layer's fields?
484
486 if ( panel && panel->dockMode() )
487 {
488 QgsSymbolSelectorWidget *dlg = new QgsSymbolSelectorWidget( symbol.release(), QgsStyle::defaultStyle(), vectorLayer, panel );
489 dlg->setContext( context );
490 dlg->setPanelTitle( style.styleName() );
491 connect( dlg, &QgsPanelWidget::widgetChanged, this, &QgsVectorTileBasicRendererWidget::updateSymbolsFromWidget );
492 connect( dlg, &QgsPanelWidget::panelAccepted, this, &QgsVectorTileBasicRendererWidget::cleanUpSymbolSelector );
493 openPanel( dlg );
494 }
495 else
496 {
497 QgsSymbolSelectorDialog dlg( symbol.get(), QgsStyle::defaultStyle(), vectorLayer, panel );
498 dlg.setContext( context );
499 if ( !dlg.exec() || !symbol )
500 {
501 return;
502 }
503
504 style.setSymbol( symbol.release() );
505 mRenderer->setStyle( index.row(), style );
506 emit widgetChanged();
507 }
508}
509
510void QgsVectorTileBasicRendererWidget::updateSymbolsFromWidget()
511{
512 const int index = mProxyModel->mapToSource( viewStyles->selectionModel()->currentIndex() ).row();
513 if ( index < 0 )
514 return;
515
516 QgsVectorTileBasicRendererStyle style = mRenderer->style( index );
517
518 QgsSymbolSelectorWidget *dlg = qobject_cast<QgsSymbolSelectorWidget *>( sender() );
519 style.setSymbol( dlg->symbol()->clone() );
520
521 mRenderer->setStyle( index, style );
522 emit widgetChanged();
523}
524
525void QgsVectorTileBasicRendererWidget::cleanUpSymbolSelector( QgsPanelWidget *container )
526{
527 QgsSymbolSelectorWidget *dlg = qobject_cast<QgsSymbolSelectorWidget *>( container );
528 if ( !dlg )
529 return;
530
531 delete dlg->symbol();
532}
533
534void QgsVectorTileBasicRendererWidget::removeStyle()
535{
536 const QModelIndexList sel = viewStyles->selectionModel()->selectedIndexes();
537
538 QList<int > res;
539 for ( const QModelIndex &proxyIndex : sel )
540 {
541 const QModelIndex sourceIndex = mProxyModel->mapToSource( proxyIndex );
542 if ( !res.contains( sourceIndex.row() ) )
543 res << sourceIndex.row();
544 }
545 std::sort( res.begin(), res.end() );
546
547 for ( int i = res.size() - 1; i >= 0; --i )
548 {
549 mModel->removeRow( res[ i ] );
550 }
551 // make sure that the selection is gone
552 viewStyles->selectionModel()->clear();
553}
554
555QgsVectorTileBasicRendererProxyModel::QgsVectorTileBasicRendererProxyModel( QgsVectorTileBasicRendererListModel *source, QObject *parent )
556 : QSortFilterProxyModel( parent )
557{
558 setSourceModel( source );
559 setDynamicSortFilter( true );
560}
561
562void QgsVectorTileBasicRendererProxyModel::setCurrentZoom( int zoom )
563{
564 mCurrentZoom = zoom;
565 invalidateFilter();
566}
567
568void QgsVectorTileBasicRendererProxyModel::setFilterVisible( bool enabled )
569{
570 mFilterVisible = enabled;
571 invalidateFilter();
572}
573
574void QgsVectorTileBasicRendererProxyModel::setFilterString( const QString &string )
575{
576 mFilterString = string;
577 invalidateFilter();
578}
579
580bool QgsVectorTileBasicRendererProxyModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const
581{
582 if ( mCurrentZoom >= 0 && mFilterVisible )
583 {
584 const int rowMinZoom = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicRendererListModel::MinZoom ).toInt();
585 const int rowMaxZoom = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicRendererListModel::MaxZoom ).toInt();
586
587 if ( rowMinZoom >= 0 && rowMinZoom > mCurrentZoom )
588 return false;
589
590 if ( rowMaxZoom >= 0 && rowMaxZoom < mCurrentZoom )
591 return false;
592 }
593
594 if ( !mFilterString.isEmpty() )
595 {
596 const QString name = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicRendererListModel::Label ).toString();
597 const QString layer = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicRendererListModel::Layer ).toString();
598 const QString filter = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicRendererListModel::Filter ).toString();
599 if ( !name.contains( mFilterString, Qt::CaseInsensitive )
600 && !layer.contains( mFilterString, Qt::CaseInsensitive )
601 && !filter.contains( mFilterString, Qt::CaseInsensitive ) )
602 {
603 return false;
604 }
605 }
606
607 return true;
608}
609
610
611
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.
Definition: qgsmapcanvas.h:90
void scaleChanged(double)
Emitted when the scale of the map changes.
A panel widget that can be shown in the map style dock.
The QgsMapSettings class contains configuration for rendering of the map.
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.
Definition: qgsmessagebar.h:61
Base class for any widget that can be shown as a inline panel.
void panelAccepted(QgsPanelWidget *panel)
Emitted when the panel is accepted by the user.
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.
bool dockMode()
Returns the dock mode state.
The class is used as a container of context for various read/write operations on other objects.
static QgsStyle * defaultStyle()
Returns default application-wide style.
Definition: qgsstyle.cpp:145
static QIcon symbolPreviewIcon(const QgsSymbol *symbol, QSize size, int padding=0, QgsLegendPatchShape *shape=nullptr)
Returns an icon preview for a color ramp.
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.
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.
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
Definition: qgssymbol.cpp:704
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
Represents a vector layer which manages a vector based data sets.
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 minimum zoom level index (negative number means no limit)
int maxZoomLevel() const
Returns maxnimum 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.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:141
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,...