QGIS API Documentation 3.41.0-Master (cea29feecf2)
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 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 | Qt::ItemIsEditable | checkable | Qt::ItemIsDragEnabled;
157}
158
159bool QgsVectorTileBasicRendererListModel::setData( const QModelIndex &index, const QVariant &value, int role )
160{
161 if ( !index.isValid() )
162 return false;
163
164 QgsVectorTileBasicRendererStyle style = mRenderer->style( index.row() );
165
166 if ( role == Qt::CheckStateRole )
167 {
168 style.setEnabled( value.toInt() == Qt::Checked );
169 mRenderer->setStyle( index.row(), style );
170 emit dataChanged( index, index );
171 return true;
172 }
173
174 if ( role == Qt::EditRole )
175 {
176 if ( index.column() == 0 )
177 style.setStyleName( value.toString() );
178 else if ( index.column() == 1 )
179 style.setLayerName( value.toString() );
180 else if ( index.column() == 2 )
181 style.setMinZoomLevel( value.toInt() );
182 else if ( index.column() == 3 )
183 style.setMaxZoomLevel( value.toInt() );
184 else if ( index.column() == 4 )
185 style.setFilterExpression( value.toString() );
186
187 mRenderer->setStyle( index.row(), style );
188 emit dataChanged( index, index );
189 return true;
190 }
191
192 return false;
193}
194
195bool QgsVectorTileBasicRendererListModel::removeRows( int row, int count, const QModelIndex &parent )
196{
197 QList<QgsVectorTileBasicRendererStyle> styles = mRenderer->styles();
198
199 if ( row < 0 || row >= styles.count() )
200 return false;
201
202 beginRemoveRows( parent, row, row + count - 1 );
203
204 for ( int i = 0; i < count; i++ )
205 {
206 if ( row < styles.count() )
207 {
208 styles.removeAt( row );
209 }
210 }
211
212 mRenderer->setStyles( styles );
213
214 endRemoveRows();
215 return true;
216}
217
218void QgsVectorTileBasicRendererListModel::insertStyle( int row, const QgsVectorTileBasicRendererStyle &style )
219{
220 beginInsertRows( QModelIndex(), row, row );
221
222 QList<QgsVectorTileBasicRendererStyle> styles = mRenderer->styles();
223 styles.insert( row, style );
224 mRenderer->setStyles( styles );
225
226 endInsertRows();
227}
228
229Qt::DropActions QgsVectorTileBasicRendererListModel::supportedDropActions() const
230{
231 return Qt::MoveAction;
232}
233
234QStringList QgsVectorTileBasicRendererListModel::mimeTypes() const
235{
236 QStringList types;
237 types << QStringLiteral( "application/vnd.text.list" );
238 return types;
239}
240
241QMimeData *QgsVectorTileBasicRendererListModel::mimeData( const QModelIndexList &indexes ) const
242{
243 QMimeData *mimeData = new QMimeData();
244 QByteArray encodedData;
245
246 QDataStream stream( &encodedData, QIODevice::WriteOnly );
247
248 const auto constIndexes = indexes;
249 for ( const QModelIndex &index : constIndexes )
250 {
251 // each item consists of several columns - let's add it with just first one
252 if ( !index.isValid() || index.column() != 0 )
253 continue;
254
255 const QgsVectorTileBasicRendererStyle style = mRenderer->style( index.row() );
256
257 QDomDocument doc;
258 QDomElement rootElem = doc.createElement( QStringLiteral( "vector_tile_basic_renderer_style_mime" ) );
259 style.writeXml( rootElem, QgsReadWriteContext() );
260 doc.appendChild( rootElem );
261
262 stream << doc.toString( -1 );
263 }
264
265 mimeData->setData( QStringLiteral( "application/vnd.text.list" ), encodedData );
266 return mimeData;
267}
268
269bool QgsVectorTileBasicRendererListModel::dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent )
270{
271 Q_UNUSED( column )
272
273 if ( action == Qt::IgnoreAction )
274 return true;
275
276 if ( !data->hasFormat( QStringLiteral( "application/vnd.text.list" ) ) )
277 return false;
278
279 if ( parent.column() > 0 )
280 return false;
281
282 QByteArray encodedData = data->data( QStringLiteral( "application/vnd.text.list" ) );
283 QDataStream stream( &encodedData, QIODevice::ReadOnly );
284 int rows = 0;
285
286 if ( row == -1 )
287 {
288 // the item was dropped at a parent - we may decide where to put the items - let's append them
289 row = rowCount( parent );
290 }
291
292 while ( !stream.atEnd() )
293 {
294 QString text;
295 stream >> text;
296
297 QDomDocument doc;
298 if ( !doc.setContent( text ) )
299 continue;
300 const QDomElement rootElem = doc.documentElement();
301 if ( rootElem.tagName() != QLatin1String( "vector_tile_basic_renderer_style_mime" ) )
302 continue;
303
305 style.readXml( rootElem, QgsReadWriteContext() );
306
307 insertStyle( row + rows, style );
308 ++rows;
309 }
310 return true;
311}
312
313
314//
315
316
317QgsVectorTileBasicRendererWidget::QgsVectorTileBasicRendererWidget( QgsVectorTileLayer *layer, QgsMapCanvas *canvas, QgsMessageBar *messageBar, QWidget *parent )
318 : QgsMapLayerConfigWidget( layer, canvas, parent )
319 , mMapCanvas( canvas )
320 , mMessageBar( messageBar )
321{
322 setupUi( this );
323 layout()->setContentsMargins( 0, 0, 0, 0 );
324
325 mFilterLineEdit->setShowClearButton( true );
326 mFilterLineEdit->setShowSearchIcon( true );
327 mFilterLineEdit->setPlaceholderText( tr( "Filter rules" ) );
328
329 QMenu *menuAddRule = new QMenu( btnAddRule );
330 menuAddRule->addAction( tr( "Marker" ), this, [this] { addStyle( Qgis::GeometryType::Point ); } );
331 menuAddRule->addAction( tr( "Line" ), this, [this] { addStyle( Qgis::GeometryType::Line ); } );
332 menuAddRule->addAction( tr( "Fill" ), this, [this] { addStyle( Qgis::GeometryType::Polygon ); } );
333 btnAddRule->setMenu( menuAddRule );
334
335 connect( btnEditRule, &QPushButton::clicked, this, &QgsVectorTileBasicRendererWidget::editStyle );
336 connect( btnRemoveRule, &QAbstractButton::clicked, this, &QgsVectorTileBasicRendererWidget::removeStyle );
337
338 connect( viewStyles, &QAbstractItemView::doubleClicked, this, &QgsVectorTileBasicRendererWidget::editStyleAtIndex );
339
340 if ( mMapCanvas )
341 {
342 connect( mMapCanvas, &QgsMapCanvas::scaleChanged, this, [=]( double scale ) {
343 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
344 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(), mapSettings.destinationCrs(), mapSettings.visibleExtent(), mapSettings.outputSize(), mapSettings.outputDpi() ) : scale;
345 const int zoom = mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 );
346 mLabelCurrentZoom->setText( tr( "Current zoom: %1" ).arg( zoom ) );
347 if ( mProxyModel )
348 mProxyModel->setCurrentZoom( zoom );
349 } );
350
351 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
352 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(), mapSettings.destinationCrs(), mapSettings.visibleExtent(), mapSettings.outputSize(), mapSettings.outputDpi() ) : mMapCanvas->scale();
353 mLabelCurrentZoom->setText( tr( "Current zoom: %1" ).arg( mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 ) ) );
354 }
355
356 connect( mCheckVisibleOnly, &QCheckBox::toggled, this, [=]( bool filter ) {
357 mProxyModel->setFilterVisible( filter );
358 } );
359
360 connect( mFilterLineEdit, &QgsFilterLineEdit::textChanged, this, [=]( const QString &text ) {
361 mProxyModel->setFilterString( text );
362 } );
363
364 syncToLayer( layer );
365
366 connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsPanelWidget::widgetChanged );
367 connect( mBlendModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsPanelWidget::widgetChanged );
368}
369
370void QgsVectorTileBasicRendererWidget::syncToLayer( QgsMapLayer *layer )
371{
372 QgsVectorTileLayer *vtLayer = qobject_cast<QgsVectorTileLayer *>( layer );
373 if ( !vtLayer )
374 return;
375
376 mVTLayer = vtLayer;
377
378 if ( layer && vtLayer->renderer() && vtLayer->renderer()->type() == QLatin1String( "basic" ) )
379 {
380 mRenderer.reset( static_cast<QgsVectorTileBasicRenderer *>( vtLayer->renderer()->clone() ) );
381 }
382 else
383 {
384 mRenderer.reset( new QgsVectorTileBasicRenderer() );
385 }
386
387 mModel = new QgsVectorTileBasicRendererListModel( mRenderer.get(), viewStyles, screen() );
388 mProxyModel = new QgsVectorTileBasicRendererProxyModel( mModel, viewStyles );
389 viewStyles->setModel( mProxyModel );
390
391 if ( mMapCanvas )
392 {
393 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
394 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(), mapSettings.destinationCrs(), mapSettings.visibleExtent(), mapSettings.outputSize(), mapSettings.outputDpi() ) : mMapCanvas->scale();
395 const int zoom = mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 );
396 mProxyModel->setCurrentZoom( zoom );
397 }
398
399 connect( mModel, &QAbstractItemModel::dataChanged, this, &QgsPanelWidget::widgetChanged );
400 connect( mModel, &QAbstractItemModel::rowsInserted, this, &QgsPanelWidget::widgetChanged );
401 connect( mModel, &QAbstractItemModel::rowsRemoved, this, &QgsPanelWidget::widgetChanged );
402
403 mOpacityWidget->setOpacity( mVTLayer->opacity() );
404
405 //blend mode
406 mBlendModeComboBox->setShowClippingModes( QgsProjectUtils::layerIsContainedInGroupLayer( QgsProject::instance(), mVTLayer ) );
407 mBlendModeComboBox->setBlendMode( mVTLayer->blendMode() );
408}
409
410QgsVectorTileBasicRendererWidget::~QgsVectorTileBasicRendererWidget() = default;
411
412void QgsVectorTileBasicRendererWidget::apply()
413{
414 mVTLayer->setRenderer( mRenderer->clone() );
415 mVTLayer->setBlendMode( mBlendModeComboBox->blendMode() );
416 mVTLayer->setOpacity( mOpacityWidget->opacity() );
417}
418
419void QgsVectorTileBasicRendererWidget::addStyle( Qgis::GeometryType geomType )
420{
421 QgsVectorTileBasicRendererStyle style( QString(), QString(), geomType );
422 style.setSymbol( QgsSymbol::defaultSymbol( geomType ) );
423
424 switch ( geomType )
425 {
427 style.setFilterExpression( QStringLiteral( "geometry_type(@geometry)='Point'" ) );
428 break;
430 style.setFilterExpression( QStringLiteral( "geometry_type(@geometry)='Line'" ) );
431 break;
433 style.setFilterExpression( QStringLiteral( "geometry_type(@geometry)='Polygon'" ) );
434 break;
437 break;
438 }
439
440 const int rows = mModel->rowCount();
441 mModel->insertStyle( rows, style );
442 viewStyles->selectionModel()->setCurrentIndex( mProxyModel->mapFromSource( mModel->index( rows, 0 ) ), QItemSelectionModel::ClearAndSelect );
443}
444
445void QgsVectorTileBasicRendererWidget::editStyle()
446{
447 editStyleAtIndex( viewStyles->selectionModel()->currentIndex() );
448}
449
450void QgsVectorTileBasicRendererWidget::editStyleAtIndex( const QModelIndex &proxyIndex )
451{
452 const QModelIndex index = mProxyModel->mapToSource( proxyIndex );
453 if ( index.row() < 0 || index.row() >= mRenderer->styles().count() )
454 return;
455
456 QgsVectorTileBasicRendererStyle style = mRenderer->style( index.row() );
457
458 if ( !style.symbol() )
459 return;
460
461 std::unique_ptr<QgsSymbol> symbol( style.symbol()->clone() );
462
464 context.setMapCanvas( mMapCanvas );
465 context.setMessageBar( mMessageBar );
466
467 if ( mMapCanvas )
468 {
469 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
470 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(), mapSettings.destinationCrs(), mapSettings.visibleExtent(), mapSettings.outputSize(), mapSettings.outputDpi() ) : mMapCanvas->scale();
471 const int zoom = mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 );
472 QList<QgsExpressionContextScope> scopes = context.additionalExpressionContextScopes();
474 tileScope.setVariable( "zoom_level", zoom, true );
475 tileScope.setVariable( "vector_tile_zoom", mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoom( mMapCanvas->scale() ) : QgsVectorTileUtils::scaleToZoom( mMapCanvas->scale() ), true );
476 scopes << tileScope;
477 context.setAdditionalExpressionContextScopes( scopes );
478 }
479
480 QgsVectorLayer *vectorLayer = nullptr; // TODO: have a temporary vector layer with sub-layer's fields?
481
483 if ( panel && panel->dockMode() )
484 {
486 widget->setContext( context );
487 widget->setPanelTitle( style.styleName() );
488 connect( widget, &QgsPanelWidget::widgetChanged, this, [=] { updateSymbolsFromWidget( widget ); } );
489 openPanel( widget );
490 }
491 else
492 {
493 QgsSymbolSelectorDialog dlg( symbol.get(), QgsStyle::defaultStyle(), vectorLayer, panel );
494 dlg.setContext( context );
495 if ( !dlg.exec() || !symbol )
496 {
497 return;
498 }
499
500 style.setSymbol( symbol.release() );
501 mRenderer->setStyle( index.row(), style );
502 emit widgetChanged();
503 }
504}
505
506void QgsVectorTileBasicRendererWidget::updateSymbolsFromWidget( QgsSymbolSelectorWidget *widget )
507{
508 const int index = mProxyModel->mapToSource( viewStyles->selectionModel()->currentIndex() ).row();
509 if ( index < 0 )
510 return;
511
512 QgsVectorTileBasicRendererStyle style = mRenderer->style( index );
513
514 style.setSymbol( widget->symbol()->clone() );
515
516 mRenderer->setStyle( index, style );
517 emit widgetChanged();
518}
519
520void QgsVectorTileBasicRendererWidget::removeStyle()
521{
522 const QModelIndexList sel = viewStyles->selectionModel()->selectedIndexes();
523
524 QList<int> res;
525 for ( const QModelIndex &proxyIndex : sel )
526 {
527 const QModelIndex sourceIndex = mProxyModel->mapToSource( proxyIndex );
528 if ( !res.contains( sourceIndex.row() ) )
529 res << sourceIndex.row();
530 }
531 std::sort( res.begin(), res.end() );
532
533 for ( int i = res.size() - 1; i >= 0; --i )
534 {
535 mModel->removeRow( res[i] );
536 }
537 // make sure that the selection is gone
538 viewStyles->selectionModel()->clear();
539}
540
541QgsVectorTileBasicRendererProxyModel::QgsVectorTileBasicRendererProxyModel( QgsVectorTileBasicRendererListModel *source, QObject *parent )
542 : QSortFilterProxyModel( parent )
543{
544 setSourceModel( source );
545 setDynamicSortFilter( true );
546}
547
548void QgsVectorTileBasicRendererProxyModel::setCurrentZoom( int zoom )
549{
550 mCurrentZoom = zoom;
551 invalidateFilter();
552}
553
554void QgsVectorTileBasicRendererProxyModel::setFilterVisible( bool enabled )
555{
556 mFilterVisible = enabled;
557 invalidateFilter();
558}
559
560void QgsVectorTileBasicRendererProxyModel::setFilterString( const QString &string )
561{
562 mFilterString = string;
563 invalidateFilter();
564}
565
566bool QgsVectorTileBasicRendererProxyModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const
567{
568 if ( mCurrentZoom >= 0 && mFilterVisible )
569 {
570 const int rowMinZoom = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicRendererListModel::MinZoom ).toInt();
571 const int rowMaxZoom = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicRendererListModel::MaxZoom ).toInt();
572
573 if ( rowMinZoom >= 0 && rowMinZoom > mCurrentZoom )
574 return false;
575
576 if ( rowMaxZoom >= 0 && rowMaxZoom < mCurrentZoom )
577 return false;
578 }
579
580 if ( !mFilterString.isEmpty() )
581 {
582 const QString name = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicRendererListModel::Label ).toString();
583 const QString layer = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicRendererListModel::Layer ).toString();
584 const QString filter = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicRendererListModel::Filter ).toString();
585 if ( !name.contains( mFilterString, Qt::CaseInsensitive )
586 && !layer.contains( mFilterString, Qt::CaseInsensitive )
587 && !filter.contains( mFilterString, Qt::CaseInsensitive ) )
588 {
589 return false;
590 }
591 }
592
593 return true;
594}
595
596
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,...