QGIS API Documentation 3.41.0-Master (3440c17df1d)
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#include "moc_qgsvectortilebasicrendererwidget.cpp"
18
19#include "qgsguiutils.h"
20#include "qgssymbollayerutils.h"
22#include "qgsvectortilelayer.h"
24#include "qgsstyle.h"
25#include "qgsmapcanvas.h"
26#include "qgsvectortileutils.h"
27#include "qgsprojectutils.h"
28
29#include <QAbstractListModel>
30#include <QInputDialog>
31#include <QMenu>
32#include <QScreen>
33#include <QPointer>
34
35
37
38
39QgsVectorTileBasicRendererListModel::QgsVectorTileBasicRendererListModel( QgsVectorTileBasicRenderer *r, QObject *parent, QScreen *screen )
40 : QAbstractListModel( parent )
41 , mRenderer( r )
42 , mScreen( screen )
43{
44}
45
46int QgsVectorTileBasicRendererListModel::rowCount( const QModelIndex &parent ) const
47{
48 if ( parent.isValid() )
49 return 0;
50
51 return mRenderer->styles().count();
52}
53
54int QgsVectorTileBasicRendererListModel::columnCount( const QModelIndex & ) const
55{
56 return 5;
57}
58
59QVariant QgsVectorTileBasicRendererListModel::data( const QModelIndex &index, int role ) const
60{
61 if ( index.row() < 0 || index.row() >= mRenderer->styles().count() )
62 return QVariant();
63
64 const QList<QgsVectorTileBasicRendererStyle> styles = mRenderer->styles();
65 const QgsVectorTileBasicRendererStyle &style = styles[index.row()];
66
67 switch ( role )
68 {
69 case Qt::DisplayRole:
70 case Qt::ToolTipRole:
71 {
72 if ( index.column() == 0 )
73 return style.styleName();
74 else if ( index.column() == 1 )
75 return style.layerName().isEmpty() ? tr( "(all layers)" ) : style.layerName();
76 else if ( index.column() == 2 )
77 return style.minZoomLevel() >= 0 ? style.minZoomLevel() : QVariant();
78 else if ( index.column() == 3 )
79 return style.maxZoomLevel() >= 0 ? style.maxZoomLevel() : QVariant();
80 else if ( index.column() == 4 )
81 return style.filterExpression().isEmpty() ? tr( "(no filter)" ) : style.filterExpression();
82
83 break;
84 }
85
86 case Qt::EditRole:
87 {
88 if ( index.column() == 0 )
89 return style.styleName();
90 else if ( index.column() == 1 )
91 return style.layerName();
92 else if ( index.column() == 2 )
93 return style.minZoomLevel();
94 else if ( index.column() == 3 )
95 return style.maxZoomLevel();
96 else if ( index.column() == 4 )
97 return style.filterExpression();
98
99 break;
100 }
101
102 case Qt::DecorationRole:
103 {
104 if ( index.column() == 0 && style.symbol() )
105 {
106 const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
107 return QgsSymbolLayerUtils::symbolPreviewIcon( style.symbol(), QSize( iconSize, iconSize ), 0, nullptr, QgsScreenProperties( mScreen.data() ) );
108 }
109 break;
110 }
111
112 case Qt::CheckStateRole:
113 {
114 if ( index.column() != 0 )
115 return QVariant();
116 return style.isEnabled() ? Qt::Checked : Qt::Unchecked;
117 }
118
119 case MinZoom:
120 return style.minZoomLevel();
121
122 case MaxZoom:
123 return style.maxZoomLevel();
124
125 case Label:
126 return style.styleName();
127
128 case Layer:
129 return style.layerName();
130
131 case Filter:
132 return style.filterExpression();
133
134 }
135 return QVariant();
136}
137
138QVariant QgsVectorTileBasicRendererListModel::headerData( int section, Qt::Orientation orientation, int role ) const
139{
140 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < 5 )
141 {
142 QStringList lst;
143 lst << tr( "Label" ) << tr( "Layer" ) << tr( "Min. Zoom" ) << tr( "Max. Zoom" ) << tr( "Filter" );
144 return lst[section];
145 }
146
147 return QVariant();
148}
149
150Qt::ItemFlags QgsVectorTileBasicRendererListModel::flags( const QModelIndex &index ) const
151{
152 if ( !index.isValid() )
153 return Qt::ItemIsDropEnabled;
154
155 const Qt::ItemFlag checkable = ( index.column() == 0 ? Qt::ItemIsUserCheckable : Qt::NoItemFlags );
156
157 return Qt::ItemIsEnabled | Qt::ItemIsSelectable |
158 Qt::ItemIsEditable | checkable |
159 Qt::ItemIsDragEnabled;
160}
161
162bool QgsVectorTileBasicRendererListModel::setData( const QModelIndex &index, const QVariant &value, int role )
163{
164 if ( !index.isValid() )
165 return false;
166
167 QgsVectorTileBasicRendererStyle style = mRenderer->style( index.row() );
168
169 if ( role == Qt::CheckStateRole )
170 {
171 style.setEnabled( value.toInt() == Qt::Checked );
172 mRenderer->setStyle( index.row(), style );
173 emit dataChanged( index, index );
174 return true;
175 }
176
177 if ( role == Qt::EditRole )
178 {
179 if ( index.column() == 0 )
180 style.setStyleName( value.toString() );
181 else if ( index.column() == 1 )
182 style.setLayerName( value.toString() );
183 else if ( index.column() == 2 )
184 style.setMinZoomLevel( value.toInt() );
185 else if ( index.column() == 3 )
186 style.setMaxZoomLevel( value.toInt() );
187 else if ( index.column() == 4 )
188 style.setFilterExpression( value.toString() );
189
190 mRenderer->setStyle( index.row(), style );
191 emit dataChanged( index, index );
192 return true;
193 }
194
195 return false;
196}
197
198bool QgsVectorTileBasicRendererListModel::removeRows( int row, int count, const QModelIndex &parent )
199{
200 QList<QgsVectorTileBasicRendererStyle> styles = mRenderer->styles();
201
202 if ( row < 0 || row >= styles.count() )
203 return false;
204
205 beginRemoveRows( parent, row, row + count - 1 );
206
207 for ( int i = 0; i < count; i++ )
208 {
209 if ( row < styles.count() )
210 {
211 styles.removeAt( row );
212 }
213 }
214
215 mRenderer->setStyles( styles );
216
217 endRemoveRows();
218 return true;
219}
220
221void QgsVectorTileBasicRendererListModel::insertStyle( int row, const QgsVectorTileBasicRendererStyle &style )
222{
223 beginInsertRows( QModelIndex(), row, row );
224
225 QList<QgsVectorTileBasicRendererStyle> styles = mRenderer->styles();
226 styles.insert( row, style );
227 mRenderer->setStyles( styles );
228
229 endInsertRows();
230}
231
232Qt::DropActions QgsVectorTileBasicRendererListModel::supportedDropActions() const
233{
234 return Qt::MoveAction;
235}
236
237QStringList QgsVectorTileBasicRendererListModel::mimeTypes() const
238{
239 QStringList types;
240 types << QStringLiteral( "application/vnd.text.list" );
241 return types;
242}
243
244QMimeData *QgsVectorTileBasicRendererListModel::mimeData( const QModelIndexList &indexes ) const
245{
246 QMimeData *mimeData = new QMimeData();
247 QByteArray encodedData;
248
249 QDataStream stream( &encodedData, QIODevice::WriteOnly );
250
251 const auto constIndexes = indexes;
252 for ( const QModelIndex &index : constIndexes )
253 {
254 // each item consists of several columns - let's add it with just first one
255 if ( !index.isValid() || index.column() != 0 )
256 continue;
257
258 const QgsVectorTileBasicRendererStyle style = mRenderer->style( index.row() );
259
260 QDomDocument doc;
261 QDomElement rootElem = doc.createElement( QStringLiteral( "vector_tile_basic_renderer_style_mime" ) );
262 style.writeXml( rootElem, QgsReadWriteContext() );
263 doc.appendChild( rootElem );
264
265 stream << doc.toString( -1 );
266 }
267
268 mimeData->setData( QStringLiteral( "application/vnd.text.list" ), encodedData );
269 return mimeData;
270}
271
272bool QgsVectorTileBasicRendererListModel::dropMimeData( const QMimeData *data,
273 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( QStringLiteral( "application/vnd.text.list" ) ) )
281 return false;
282
283 if ( parent.column() > 0 )
284 return false;
285
286 QByteArray encodedData = data->data( QStringLiteral( "application/vnd.text.list" ) );
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() != QLatin1String( "vector_tile_basic_renderer_style_mime" ) )
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, [ = ]( double scale )
347 {
348 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
349 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(),
350 mapSettings.destinationCrs(),
351 mapSettings.visibleExtent(),
352 mapSettings.outputSize(),
353 mapSettings.outputDpi() ) : scale;
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
360 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
361 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(),
362 mapSettings.destinationCrs(),
363 mapSettings.visibleExtent(),
364 mapSettings.outputSize(),
365 mapSettings.outputDpi() ) : mMapCanvas->scale();
366 mLabelCurrentZoom->setText( tr( "Current zoom: %1" ).arg( mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 ) ) );
367 }
368
369 connect( mCheckVisibleOnly, &QCheckBox::toggled, this, [ = ]( bool filter )
370 {
371 mProxyModel->setFilterVisible( filter );
372 } );
373
374 connect( mFilterLineEdit, &QgsFilterLineEdit::textChanged, this, [ = ]( const QString & text )
375 {
376 mProxyModel->setFilterString( text );
377 } );
378
379 syncToLayer( layer );
380
381 connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsPanelWidget::widgetChanged );
382 connect( mBlendModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsPanelWidget::widgetChanged );
383}
384
385void QgsVectorTileBasicRendererWidget::syncToLayer( QgsMapLayer *layer )
386{
387 QgsVectorTileLayer *vtLayer = qobject_cast<QgsVectorTileLayer *>( layer );
388 if ( !vtLayer )
389 return;
390
391 mVTLayer = vtLayer;
392
393 if ( layer && vtLayer->renderer() && vtLayer->renderer()->type() == QLatin1String( "basic" ) )
394 {
395 mRenderer.reset( static_cast<QgsVectorTileBasicRenderer *>( vtLayer->renderer()->clone() ) );
396 }
397 else
398 {
399 mRenderer.reset( new QgsVectorTileBasicRenderer() );
400 }
401
402 mModel = new QgsVectorTileBasicRendererListModel( mRenderer.get(), viewStyles, screen() );
403 mProxyModel = new QgsVectorTileBasicRendererProxyModel( mModel, viewStyles );
404 viewStyles->setModel( mProxyModel );
405
406 if ( mMapCanvas )
407 {
408 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
409 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(),
410 mapSettings.destinationCrs(),
411 mapSettings.visibleExtent(),
412 mapSettings.outputSize(),
413 mapSettings.outputDpi() ) : mMapCanvas->scale();
414 const int zoom = mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 );
415 mProxyModel->setCurrentZoom( zoom );
416 }
417
418 connect( mModel, &QAbstractItemModel::dataChanged, this, &QgsPanelWidget::widgetChanged );
419 connect( mModel, &QAbstractItemModel::rowsInserted, this, &QgsPanelWidget::widgetChanged );
420 connect( mModel, &QAbstractItemModel::rowsRemoved, this, &QgsPanelWidget::widgetChanged );
421
422 mOpacityWidget->setOpacity( mVTLayer->opacity() );
423
424 //blend mode
425 mBlendModeComboBox->setShowClippingModes( QgsProjectUtils::layerIsContainedInGroupLayer( QgsProject::instance(), mVTLayer ) );
426 mBlendModeComboBox->setBlendMode( mVTLayer->blendMode() );
427}
428
429QgsVectorTileBasicRendererWidget::~QgsVectorTileBasicRendererWidget() = default;
430
431void QgsVectorTileBasicRendererWidget::apply()
432{
433 mVTLayer->setRenderer( mRenderer->clone() );
434 mVTLayer->setBlendMode( mBlendModeComboBox->blendMode() );
435 mVTLayer->setOpacity( mOpacityWidget->opacity() );
436}
437
438void QgsVectorTileBasicRendererWidget::addStyle( Qgis::GeometryType geomType )
439{
440 QgsVectorTileBasicRendererStyle style( QString(), QString(), geomType );
441 style.setSymbol( QgsSymbol::defaultSymbol( geomType ) );
442
443 switch ( geomType )
444 {
446 style.setFilterExpression( QStringLiteral( "geometry_type(@geometry)='Point'" ) );
447 break;
449 style.setFilterExpression( QStringLiteral( "geometry_type(@geometry)='Line'" ) );
450 break;
452 style.setFilterExpression( QStringLiteral( "geometry_type(@geometry)='Polygon'" ) );
453 break;
456 break;
457 }
458
459 const int rows = mModel->rowCount();
460 mModel->insertStyle( rows, style );
461 viewStyles->selectionModel()->setCurrentIndex( mProxyModel->mapFromSource( mModel->index( rows, 0 ) ), QItemSelectionModel::ClearAndSelect );
462}
463
464void QgsVectorTileBasicRendererWidget::editStyle()
465{
466 editStyleAtIndex( viewStyles->selectionModel()->currentIndex() );
467}
468
469void QgsVectorTileBasicRendererWidget::editStyleAtIndex( const QModelIndex &proxyIndex )
470{
471 const QModelIndex index = mProxyModel->mapToSource( proxyIndex );
472 if ( index.row() < 0 || index.row() >= mRenderer->styles().count() )
473 return;
474
475 QgsVectorTileBasicRendererStyle style = mRenderer->style( index.row() );
476
477 if ( !style.symbol() )
478 return;
479
480 std::unique_ptr< QgsSymbol > symbol( style.symbol()->clone() );
481
483 context.setMapCanvas( mMapCanvas );
484 context.setMessageBar( mMessageBar );
485
486 if ( mMapCanvas )
487 {
488 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
489 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(),
490 mapSettings.destinationCrs(),
491 mapSettings.visibleExtent(),
492 mapSettings.outputSize(),
493 mapSettings.outputDpi() ) : 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::widgetChanged, this, [ = ] { 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 widgetChanged();
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 widgetChanged();
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 )
609 && !layer.contains( mFilterString, Qt::CaseInsensitive )
610 && !filter.contains( mFilterString, Qt::CaseInsensitive ) )
611 {
612 return false;
613 }
614 }
615
616 return true;
617}
618
619
620
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:337
@ Polygon
Polygons.
@ Unknown
Unknown types.
@ Null
No geometry.
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:76
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.
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 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.
void setPanelTitle(const QString &panelTitle)
Set the title of the panel when shown in the interface.
bool dockMode()
Returns the dock mode state.
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.
The class is used as a container of context for various read/write operations on other objects.
Stores properties relating to a screen.
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
Definition qgsstyle.cpp:146
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 data sets.
Definition of map rendering of a subset of vector tile data.
void setEnabled(bool enabled)
Sets whether this style is enabled (used for rendering)
void setMinZoomLevel(int minZoom)
Sets minimum zoom level index (negative number means no limit).
void setLayerName(const QString &name)
Sets name of the sub-layer to render (empty layer means that all layers match)
QgsSymbol * symbol() const
Returns symbol for rendering.
QString filterExpression() const
Returns filter expression (empty filter means that all features match)
QString styleName() const
Returns human readable name of this style.
void setFilterExpression(const QString &expr)
Sets filter expression (empty filter means that all features match)
void setSymbol(QgsSymbol *sym)
Sets symbol for rendering. Takes ownership of the symbol.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const
Writes object content to given DOM element.
void setStyleName(const QString &name)
Sets human readable name of this style.
bool isEnabled() const
Returns whether this style is enabled (used for rendering)
void setMaxZoomLevel(int maxZoom)
Sets maximum zoom level index (negative number means no limit).
int minZoomLevel() const
Returns 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.
Random utility functions for working with vector tiles.
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,...