QGIS API Documentation  3.24.2-Tisler (13c1a02865)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
35 QgsVectorTileBasicRendererListModel::QgsVectorTileBasicRendererListModel( QgsVectorTileBasicRenderer *r, QObject *parent )
36  : QAbstractListModel( parent )
37  , mRenderer( r )
38 {
39 }
40 
41 int QgsVectorTileBasicRendererListModel::rowCount( const QModelIndex &parent ) const
42 {
43  if ( parent.isValid() )
44  return 0;
45 
46  return mRenderer->styles().count();
47 }
48 
49 int QgsVectorTileBasicRendererListModel::columnCount( const QModelIndex & ) const
50 {
51  return 5;
52 }
53 
54 QVariant 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 );
102  return QgsSymbolLayerUtils::symbolPreviewIcon( style.symbol(), QSize( iconSize, iconSize ) );
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  }
121  return QVariant();
122 }
123 
124 QVariant QgsVectorTileBasicRendererListModel::headerData( int section, Qt::Orientation orientation, int role ) const
125 {
126  if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < 5 )
127  {
128  QStringList lst;
129  lst << tr( "Label" ) << tr( "Layer" ) << tr( "Min. Zoom" ) << tr( "Max. Zoom" ) << tr( "Filter" );
130  return lst[section];
131  }
132 
133  return QVariant();
134 }
135 
136 Qt::ItemFlags QgsVectorTileBasicRendererListModel::flags( const QModelIndex &index ) const
137 {
138  if ( !index.isValid() )
139  return Qt::ItemIsDropEnabled;
140 
141  const Qt::ItemFlag checkable = ( index.column() == 0 ? Qt::ItemIsUserCheckable : Qt::NoItemFlags );
142 
143  return Qt::ItemIsEnabled | Qt::ItemIsSelectable |
144  Qt::ItemIsEditable | checkable |
145  Qt::ItemIsDragEnabled;
146 }
147 
148 bool QgsVectorTileBasicRendererListModel::setData( const QModelIndex &index, const QVariant &value, int role )
149 {
150  if ( !index.isValid() )
151  return false;
152 
153  QgsVectorTileBasicRendererStyle style = mRenderer->style( index.row() );
154 
155  if ( role == Qt::CheckStateRole )
156  {
157  style.setEnabled( value.toInt() == Qt::Checked );
158  mRenderer->setStyle( index.row(), style );
159  emit dataChanged( index, index );
160  return true;
161  }
162 
163  if ( role == Qt::EditRole )
164  {
165  if ( index.column() == 0 )
166  style.setStyleName( value.toString() );
167  else if ( index.column() == 1 )
168  style.setLayerName( value.toString() );
169  else if ( index.column() == 2 )
170  style.setMinZoomLevel( value.toInt() );
171  else if ( index.column() == 3 )
172  style.setMaxZoomLevel( value.toInt() );
173  else if ( index.column() == 4 )
174  style.setFilterExpression( value.toString() );
175 
176  mRenderer->setStyle( index.row(), style );
177  emit dataChanged( index, index );
178  return true;
179  }
180 
181  return false;
182 }
183 
184 bool QgsVectorTileBasicRendererListModel::removeRows( int row, int count, const QModelIndex &parent )
185 {
186  QList<QgsVectorTileBasicRendererStyle> styles = mRenderer->styles();
187 
188  if ( row < 0 || row >= styles.count() )
189  return false;
190 
191  beginRemoveRows( parent, row, row + count - 1 );
192 
193  for ( int i = 0; i < count; i++ )
194  {
195  if ( row < styles.count() )
196  {
197  styles.removeAt( row );
198  }
199  }
200 
201  mRenderer->setStyles( styles );
202 
203  endRemoveRows();
204  return true;
205 }
206 
207 void QgsVectorTileBasicRendererListModel::insertStyle( int row, const QgsVectorTileBasicRendererStyle &style )
208 {
209  beginInsertRows( QModelIndex(), row, row );
210 
211  QList<QgsVectorTileBasicRendererStyle> styles = mRenderer->styles();
212  styles.insert( row, style );
213  mRenderer->setStyles( styles );
214 
215  endInsertRows();
216 }
217 
218 Qt::DropActions QgsVectorTileBasicRendererListModel::supportedDropActions() const
219 {
220  return Qt::MoveAction;
221 }
222 
223 QStringList QgsVectorTileBasicRendererListModel::mimeTypes() const
224 {
225  QStringList types;
226  types << QStringLiteral( "application/vnd.text.list" );
227  return types;
228 }
229 
230 QMimeData *QgsVectorTileBasicRendererListModel::mimeData( const QModelIndexList &indexes ) const
231 {
232  QMimeData *mimeData = new QMimeData();
233  QByteArray encodedData;
234 
235  QDataStream stream( &encodedData, QIODevice::WriteOnly );
236 
237  const auto constIndexes = indexes;
238  for ( const QModelIndex &index : constIndexes )
239  {
240  // each item consists of several columns - let's add it with just first one
241  if ( !index.isValid() || index.column() != 0 )
242  continue;
243 
244  const QgsVectorTileBasicRendererStyle style = mRenderer->style( index.row() );
245 
246  QDomDocument doc;
247  QDomElement rootElem = doc.createElement( QStringLiteral( "vector_tile_basic_renderer_style_mime" ) );
248  style.writeXml( rootElem, QgsReadWriteContext() );
249  doc.appendChild( rootElem );
250 
251  stream << doc.toString( -1 );
252  }
253 
254  mimeData->setData( QStringLiteral( "application/vnd.text.list" ), encodedData );
255  return mimeData;
256 }
257 
258 bool QgsVectorTileBasicRendererListModel::dropMimeData( const QMimeData *data,
259  Qt::DropAction action, int row, int column, const QModelIndex &parent )
260 {
261  Q_UNUSED( column )
262 
263  if ( action == Qt::IgnoreAction )
264  return true;
265 
266  if ( !data->hasFormat( QStringLiteral( "application/vnd.text.list" ) ) )
267  return false;
268 
269  if ( parent.column() > 0 )
270  return false;
271 
272  QByteArray encodedData = data->data( QStringLiteral( "application/vnd.text.list" ) );
273  QDataStream stream( &encodedData, QIODevice::ReadOnly );
274  int rows = 0;
275 
276  if ( row == -1 )
277  {
278  // the item was dropped at a parent - we may decide where to put the items - let's append them
279  row = rowCount( parent );
280  }
281 
282  while ( !stream.atEnd() )
283  {
284  QString text;
285  stream >> text;
286 
287  QDomDocument doc;
288  if ( !doc.setContent( text ) )
289  continue;
290  const QDomElement rootElem = doc.documentElement();
291  if ( rootElem.tagName() != QLatin1String( "vector_tile_basic_renderer_style_mime" ) )
292  continue;
293 
295  style.readXml( rootElem, QgsReadWriteContext() );
296 
297  insertStyle( row + rows, style );
298  ++rows;
299  }
300  return true;
301 }
302 
303 
304 //
305 
306 
307 QgsVectorTileBasicRendererWidget::QgsVectorTileBasicRendererWidget( QgsVectorTileLayer *layer, QgsMapCanvas *canvas, QgsMessageBar *messageBar, QWidget *parent )
308  : QgsMapLayerConfigWidget( layer, canvas, parent )
309  , mMapCanvas( canvas )
310  , mMessageBar( messageBar )
311 {
312  setupUi( this );
313  layout()->setContentsMargins( 0, 0, 0, 0 );
314 
315  QMenu *menuAddRule = new QMenu( btnAddRule );
316  menuAddRule->addAction( tr( "Marker" ), this, [this] { addStyle( QgsWkbTypes::PointGeometry ); } );
317  menuAddRule->addAction( tr( "Line" ), this, [this] { addStyle( QgsWkbTypes::LineGeometry ); } );
318  menuAddRule->addAction( tr( "Fill" ), this, [this] { addStyle( QgsWkbTypes::PolygonGeometry ); } );
319  btnAddRule->setMenu( menuAddRule );
320 
321  connect( btnEditRule, &QPushButton::clicked, this, &QgsVectorTileBasicRendererWidget::editStyle );
322  connect( btnRemoveRule, &QAbstractButton::clicked, this, &QgsVectorTileBasicRendererWidget::removeStyle );
323 
324  connect( viewStyles, &QAbstractItemView::doubleClicked, this, &QgsVectorTileBasicRendererWidget::editStyleAtIndex );
325 
326  if ( mMapCanvas )
327  {
328  connect( mMapCanvas, &QgsMapCanvas::scaleChanged, this, [ = ]( double scale )
329  {
330  const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
331  const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(),
332  mapSettings.destinationCrs(),
333  mapSettings.visibleExtent(),
334  mapSettings.outputSize(),
335  mapSettings.outputDpi() ) : scale;
336  const int zoom = mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 );
337  mLabelCurrentZoom->setText( tr( "Current zoom: %1" ).arg( zoom ) );
338  if ( mProxyModel )
339  mProxyModel->setCurrentZoom( zoom );
340  } );
341 
342  const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
343  const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(),
344  mapSettings.destinationCrs(),
345  mapSettings.visibleExtent(),
346  mapSettings.outputSize(),
347  mapSettings.outputDpi() ) : mMapCanvas->scale();
348  mLabelCurrentZoom->setText( tr( "Current zoom: %1" ).arg( mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 ) ) );
349  }
350 
351  connect( mCheckVisibleOnly, &QCheckBox::toggled, this, [ = ]( bool filter )
352  {
353  mProxyModel->setFilterVisible( filter );
354  } );
355 
356  setLayer( layer );
357 }
358 
359 void QgsVectorTileBasicRendererWidget::setLayer( QgsVectorTileLayer *layer )
360 {
361  mVTLayer = layer;
362 
363  if ( layer && layer->renderer() && layer->renderer()->type() == QLatin1String( "basic" ) )
364  {
365  mRenderer.reset( static_cast<QgsVectorTileBasicRenderer *>( layer->renderer()->clone() ) );
366  }
367  else
368  {
369  mRenderer.reset( new QgsVectorTileBasicRenderer() );
370  }
371 
372  mModel = new QgsVectorTileBasicRendererListModel( mRenderer.get(), viewStyles );
373  mProxyModel = new QgsVectorTileBasicRendererProxyModel( mModel, viewStyles );
374  viewStyles->setModel( mProxyModel );
375 
376  if ( mMapCanvas )
377  {
378  const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
379  const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(),
380  mapSettings.destinationCrs(),
381  mapSettings.visibleExtent(),
382  mapSettings.outputSize(),
383  mapSettings.outputDpi() ) : mMapCanvas->scale();
384  const int zoom = mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 );
385  mProxyModel->setCurrentZoom( zoom );
386  }
387 
388  connect( mModel, &QAbstractItemModel::dataChanged, this, &QgsPanelWidget::widgetChanged );
389  connect( mModel, &QAbstractItemModel::rowsInserted, this, &QgsPanelWidget::widgetChanged );
390  connect( mModel, &QAbstractItemModel::rowsRemoved, this, &QgsPanelWidget::widgetChanged );
391 }
392 
393 QgsVectorTileBasicRendererWidget::~QgsVectorTileBasicRendererWidget() = default;
394 
395 void QgsVectorTileBasicRendererWidget::apply()
396 {
397  mVTLayer->setRenderer( mRenderer->clone() );
398 }
399 
400 void QgsVectorTileBasicRendererWidget::addStyle( QgsWkbTypes::GeometryType geomType )
401 {
402  QgsVectorTileBasicRendererStyle style( QString(), QString(), geomType );
403  style.setSymbol( QgsSymbol::defaultSymbol( geomType ) );
404 
405  switch ( geomType )
406  {
408  style.setFilterExpression( QStringLiteral( "geometry_type($geometry)='Point'" ) );
409  break;
411  style.setFilterExpression( QStringLiteral( "geometry_type($geometry)='Line'" ) );
412  break;
414  style.setFilterExpression( QStringLiteral( "geometry_type($geometry)='Polygon'" ) );
415  break;
418  break;
419  }
420 
421  const int rows = mModel->rowCount();
422  mModel->insertStyle( rows, style );
423  viewStyles->selectionModel()->setCurrentIndex( mProxyModel->mapFromSource( mModel->index( rows, 0 ) ), QItemSelectionModel::ClearAndSelect );
424 }
425 
426 void QgsVectorTileBasicRendererWidget::editStyle()
427 {
428  editStyleAtIndex( viewStyles->selectionModel()->currentIndex() );
429 }
430 
431 void QgsVectorTileBasicRendererWidget::editStyleAtIndex( const QModelIndex &proxyIndex )
432 {
433  const QModelIndex index = mProxyModel->mapToSource( proxyIndex );
434  if ( index.row() < 0 || index.row() >= mRenderer->styles().count() )
435  return;
436 
437  QgsVectorTileBasicRendererStyle style = mRenderer->style( index.row() );
438 
439  if ( !style.symbol() )
440  return;
441 
442  std::unique_ptr< QgsSymbol > symbol( style.symbol()->clone() );
443 
444  QgsSymbolWidgetContext context;
445  context.setMapCanvas( mMapCanvas );
446  context.setMessageBar( mMessageBar );
447 
448  if ( mMapCanvas )
449  {
450  const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
451  const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(),
452  mapSettings.destinationCrs(),
453  mapSettings.visibleExtent(),
454  mapSettings.outputSize(),
455  mapSettings.outputDpi() ) : mMapCanvas->scale();
456  const int zoom = mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 );
457  QList<QgsExpressionContextScope> scopes = context.additionalExpressionContextScopes();
458  QgsExpressionContextScope tileScope;
459  tileScope.setVariable( "zoom_level", zoom, true );
460  tileScope.setVariable( "vector_tile_zoom", mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoom( mMapCanvas->scale() ) : QgsVectorTileUtils::scaleToZoom( mMapCanvas->scale() ), true );
461  scopes << tileScope;
462  context.setAdditionalExpressionContextScopes( scopes );
463  }
464 
465  QgsVectorLayer *vectorLayer = nullptr; // TODO: have a temporary vector layer with sub-layer's fields?
466 
468  if ( panel && panel->dockMode() )
469  {
470  QgsSymbolSelectorWidget *dlg = new QgsSymbolSelectorWidget( symbol.release(), QgsStyle::defaultStyle(), vectorLayer, panel );
471  dlg->setContext( context );
472  dlg->setPanelTitle( style.styleName() );
473  connect( dlg, &QgsPanelWidget::widgetChanged, this, &QgsVectorTileBasicRendererWidget::updateSymbolsFromWidget );
474  connect( dlg, &QgsPanelWidget::panelAccepted, this, &QgsVectorTileBasicRendererWidget::cleanUpSymbolSelector );
475  openPanel( dlg );
476  }
477  else
478  {
479  QgsSymbolSelectorDialog dlg( symbol.get(), QgsStyle::defaultStyle(), vectorLayer, panel );
480  dlg.setContext( context );
481  if ( !dlg.exec() || !symbol )
482  {
483  return;
484  }
485 
486  style.setSymbol( symbol.release() );
487  mRenderer->setStyle( index.row(), style );
488  emit widgetChanged();
489  }
490 }
491 
492 void QgsVectorTileBasicRendererWidget::updateSymbolsFromWidget()
493 {
494  const int index = mProxyModel->mapToSource( viewStyles->selectionModel()->currentIndex() ).row();
495  if ( index < 0 )
496  return;
497 
498  QgsVectorTileBasicRendererStyle style = mRenderer->style( index );
499 
500  QgsSymbolSelectorWidget *dlg = qobject_cast<QgsSymbolSelectorWidget *>( sender() );
501  style.setSymbol( dlg->symbol()->clone() );
502 
503  mRenderer->setStyle( index, style );
504  emit widgetChanged();
505 }
506 
507 void QgsVectorTileBasicRendererWidget::cleanUpSymbolSelector( QgsPanelWidget *container )
508 {
509  QgsSymbolSelectorWidget *dlg = qobject_cast<QgsSymbolSelectorWidget *>( container );
510  if ( !dlg )
511  return;
512 
513  delete dlg->symbol();
514 }
515 
516 void QgsVectorTileBasicRendererWidget::removeStyle()
517 {
518  const QModelIndexList sel = viewStyles->selectionModel()->selectedIndexes();
519 
520  QList<int > res;
521  for ( const QModelIndex &proxyIndex : sel )
522  {
523  const QModelIndex sourceIndex = mProxyModel->mapToSource( proxyIndex );
524  if ( !res.contains( sourceIndex.row() ) )
525  res << sourceIndex.row();
526  }
527  std::sort( res.begin(), res.end() );
528 
529  for ( int i = res.size() - 1; i >= 0; --i )
530  {
531  mModel->removeRow( res[ i ] );
532  }
533  // make sure that the selection is gone
534  viewStyles->selectionModel()->clear();
535 }
536 
537 QgsVectorTileBasicRendererProxyModel::QgsVectorTileBasicRendererProxyModel( QgsVectorTileBasicRendererListModel *source, QObject *parent )
538  : QSortFilterProxyModel( parent )
539 {
540  setSourceModel( source );
541  setDynamicSortFilter( true );
542 }
543 
544 void QgsVectorTileBasicRendererProxyModel::setCurrentZoom( int zoom )
545 {
546  mCurrentZoom = zoom;
547  invalidateFilter();
548 }
549 
550 void QgsVectorTileBasicRendererProxyModel::setFilterVisible( bool enabled )
551 {
552  mFilterVisible = enabled;
553  invalidateFilter();
554 }
555 
556 bool QgsVectorTileBasicRendererProxyModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const
557 {
558  if ( mCurrentZoom < 0 || !mFilterVisible )
559  return true;
560 
561  const int rowMinZoom = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicRendererListModel::MinZoom ).toInt();
562  const int rowMaxZoom = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicRendererListModel::MaxZoom ).toInt();
563 
564  if ( rowMinZoom >= 0 && rowMinZoom > mCurrentZoom )
565  return false;
566 
567  if ( rowMaxZoom >= 0 && rowMaxZoom < mCurrentZoom )
568  return false;
569 
570  return true;
571 }
572 
573 
574 
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:131
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.
QgsSymbol * symbol()
Returns the symbol that is currently active in the widget.
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the symbol widget is shown, e.g., the associated map canvas and expression ...
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:355
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.
QgsSymbol * symbol() const
Returns symbol for rendering.
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)
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 QgsVectorTileRenderer * clone() const =0
Returns a clone of the renderer.
virtual QString type() const =0
Returns unique type name of the renderer implementation.
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,...