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