QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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 const int zoom = mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 );
353 mLabelCurrentZoom->setText( tr( "Current zoom: %1" ).arg( zoom ) );
354 if ( mProxyModel )
355 mProxyModel->setCurrentZoom( zoom );
356 } );
357
358 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
359 const double tileScale
360 = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(), mapSettings.destinationCrs(), mapSettings.visibleExtent(), mapSettings.outputSize(), mapSettings.outputDpi() )
361 : mMapCanvas->scale();
362 mLabelCurrentZoom->setText( tr( "Current zoom: %1" ).arg( mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 ) ) );
363 }
364
365 connect( mCheckVisibleOnly, &QCheckBox::toggled, this, [this]( bool filter ) { mProxyModel->setFilterVisible( filter ); } );
366
367 connect( mFilterLineEdit, &QgsFilterLineEdit::textChanged, this, [this]( const QString &text ) { mProxyModel->setFilterString( text ); } );
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
400 = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(), mapSettings.destinationCrs(), mapSettings.visibleExtent(), mapSettings.outputSize(), mapSettings.outputDpi() )
401 : mMapCanvas->scale();
402 const int zoom = mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 );
403 mProxyModel->setCurrentZoom( zoom );
404 }
405
406 connect( mModel, &QAbstractItemModel::dataChanged, this, &QgsPanelWidget::widgetChanged );
407 connect( mModel, &QAbstractItemModel::rowsInserted, this, &QgsPanelWidget::widgetChanged );
408 connect( mModel, &QAbstractItemModel::rowsRemoved, this, &QgsPanelWidget::widgetChanged );
409
410 mOpacityWidget->setOpacity( mVTLayer->opacity() );
411
412 //blend mode
413 mBlendModeComboBox->setShowClippingModes( QgsProjectUtils::layerIsContainedInGroupLayer( QgsProject::instance(), mVTLayer ) );
414 mBlendModeComboBox->setBlendMode( mVTLayer->blendMode() );
415}
416
417QgsVectorTileBasicRendererWidget::~QgsVectorTileBasicRendererWidget() = default;
418
419void QgsVectorTileBasicRendererWidget::apply()
420{
421 mVTLayer->setRenderer( mRenderer->clone() );
422 mVTLayer->setBlendMode( mBlendModeComboBox->blendMode() );
423 mVTLayer->setOpacity( mOpacityWidget->opacity() );
424}
425
426void QgsVectorTileBasicRendererWidget::addStyle( Qgis::GeometryType geomType )
427{
428 QgsVectorTileBasicRendererStyle style( QString(), QString(), geomType );
429 style.setSymbol( QgsSymbol::defaultSymbol( geomType ) );
430
431 switch ( geomType )
432 {
434 style.setFilterExpression( u"geometry_type(@geometry)='Point'"_s );
435 break;
437 style.setFilterExpression( u"geometry_type(@geometry)='Line'"_s );
438 break;
440 style.setFilterExpression( u"geometry_type(@geometry)='Polygon'"_s );
441 break;
444 break;
445 }
446
447 const int rows = mModel->rowCount();
448 mModel->insertStyle( rows, style );
449 viewStyles->selectionModel()->setCurrentIndex( mProxyModel->mapFromSource( mModel->index( rows, 0 ) ), QItemSelectionModel::ClearAndSelect );
450}
451
452void QgsVectorTileBasicRendererWidget::editStyle()
453{
454 editStyleAtIndex( viewStyles->selectionModel()->currentIndex() );
455}
456
457void QgsVectorTileBasicRendererWidget::editStyleAtIndex( const QModelIndex &proxyIndex )
458{
459 const QModelIndex index = mProxyModel->mapToSource( proxyIndex );
460 if ( index.row() < 0 || index.row() >= mRenderer->styles().count() )
461 return;
462
463 QgsVectorTileBasicRendererStyle style = mRenderer->style( index.row() );
464
465 if ( !style.symbol() )
466 return;
467
468 std::unique_ptr<QgsSymbol> symbol( style.symbol()->clone() );
469
471 context.setMapCanvas( mMapCanvas );
472 context.setMessageBar( mMessageBar );
473
474 if ( mMapCanvas )
475 {
476 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
477 const double tileScale
478 = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(), mapSettings.destinationCrs(), mapSettings.visibleExtent(), mapSettings.outputSize(), mapSettings.outputDpi() )
479 : mMapCanvas->scale();
480 const int zoom = mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 );
481 QList<QgsExpressionContextScope> scopes = context.additionalExpressionContextScopes();
483 tileScope.setVariable( "zoom_level", zoom, true );
484 tileScope.setVariable( "vector_tile_zoom", mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoom( mMapCanvas->scale() ) : QgsVectorTileUtils::scaleToZoom( mMapCanvas->scale() ), true );
485 scopes << tileScope;
486 context.setAdditionalExpressionContextScopes( scopes );
487 }
488
489 QgsVectorLayer *vectorLayer = nullptr; // TODO: have a temporary vector layer with sub-layer's fields?
490
492 if ( panel && panel->dockMode() )
493 {
495 widget->setContext( context );
496 widget->setPanelTitle( style.styleName() );
497 connect( widget, &QgsPanelWidget::widgetChanged, this, [this, widget] { updateSymbolsFromWidget( widget ); } );
498 openPanel( widget );
499 }
500 else
501 {
502 QgsSymbolSelectorDialog dlg( symbol.get(), QgsStyle::defaultStyle(), vectorLayer, panel );
503 dlg.setContext( context );
504 if ( !dlg.exec() || !symbol )
505 {
506 return;
507 }
508
509 style.setSymbol( symbol.release() );
510 mRenderer->setStyle( index.row(), style );
511 emit widgetChanged();
512 }
513}
514
515void QgsVectorTileBasicRendererWidget::updateSymbolsFromWidget( QgsSymbolSelectorWidget *widget )
516{
517 const int index = mProxyModel->mapToSource( viewStyles->selectionModel()->currentIndex() ).row();
518 if ( index < 0 )
519 return;
520
521 QgsVectorTileBasicRendererStyle style = mRenderer->style( index );
522
523 style.setSymbol( widget->symbol()->clone() );
524
525 mRenderer->setStyle( index, style );
526 emit widgetChanged();
527}
528
529void QgsVectorTileBasicRendererWidget::removeStyle()
530{
531 const QModelIndexList sel = viewStyles->selectionModel()->selectedIndexes();
532
533 QList<int> res;
534 for ( const QModelIndex &proxyIndex : sel )
535 {
536 const QModelIndex sourceIndex = mProxyModel->mapToSource( proxyIndex );
537 if ( !res.contains( sourceIndex.row() ) )
538 res << sourceIndex.row();
539 }
540 std::sort( res.begin(), res.end() );
541
542 for ( int i = res.size() - 1; i >= 0; --i )
543 {
544 mModel->removeRow( res[i] );
545 }
546 // make sure that the selection is gone
547 viewStyles->selectionModel()->clear();
548}
549
550QgsVectorTileBasicRendererProxyModel::QgsVectorTileBasicRendererProxyModel( QgsVectorTileBasicRendererListModel *source, QObject *parent )
551 : QSortFilterProxyModel( parent )
552{
553 setSourceModel( source );
554 setDynamicSortFilter( true );
555}
556
557void QgsVectorTileBasicRendererProxyModel::setCurrentZoom( int zoom )
558{
559 mCurrentZoom = zoom;
560 invalidateFilter();
561}
562
563void QgsVectorTileBasicRendererProxyModel::setFilterVisible( bool enabled )
564{
565 mFilterVisible = enabled;
566 invalidateFilter();
567}
568
569void QgsVectorTileBasicRendererProxyModel::setFilterString( const QString &string )
570{
571 mFilterString = string;
572 invalidateFilter();
573}
574
575bool QgsVectorTileBasicRendererProxyModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const
576{
577 if ( mCurrentZoom >= 0 && mFilterVisible )
578 {
579 const int rowMinZoom = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicRendererListModel::MinZoom ).toInt();
580 const int rowMaxZoom = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicRendererListModel::MaxZoom ).toInt();
581
582 if ( rowMinZoom >= 0 && rowMinZoom > mCurrentZoom )
583 return false;
584
585 if ( rowMaxZoom >= 0 && rowMaxZoom < mCurrentZoom )
586 return false;
587 }
588
589 if ( !mFilterString.isEmpty() )
590 {
591 const QString name = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicRendererListModel::Label ).toString();
592 const QString layer = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicRendererListModel::Layer ).toString();
593 const QString filter = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicRendererListModel::Filter ).toString();
594 if ( !name.contains( mFilterString, Qt::CaseInsensitive ) && !layer.contains( mFilterString, Qt::CaseInsensitive ) && !filter.contains( mFilterString, Qt::CaseInsensitive ) )
595 {
596 return false;
597 }
598 }
599
600 return true;
601}
602
603
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:379
@ Point
Points.
Definition qgis.h:380
@ Line
Lines.
Definition qgis.h:381
@ Polygon
Polygons.
Definition qgis.h:382
@ Unknown
Unknown types.
Definition qgis.h:383
@ Null
No geometry.
Definition qgis.h:384
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:148
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,...