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