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