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