QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgsvectortilebasiclabelingwidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsvectortilebasiclabelingwidget.cpp
3 --------------------------------------
4 Date : May 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 "qgis.h"
19#include "qgsapplication.h"
21#include "qgsvectortilelayer.h"
22#include "qgslabelinggui.h"
23#include "qgsmapcanvas.h"
24#include "qgsvectortileutils.h"
25
26#include <QMenu>
27
29
30const double ICON_PADDING_FACTOR = 0.16;
31
32QgsVectorTileBasicLabelingListModel::QgsVectorTileBasicLabelingListModel( QgsVectorTileBasicLabeling *l, QObject *parent )
33 : QAbstractListModel( parent )
34 , mLabeling( l )
35{
36}
37
38int QgsVectorTileBasicLabelingListModel::rowCount( const QModelIndex &parent ) const
39{
40 if ( parent.isValid() )
41 return 0;
42
43 return mLabeling->styles().count();
44}
45
46int QgsVectorTileBasicLabelingListModel::columnCount( const QModelIndex & ) const
47{
48 return 5;
49}
50
51QVariant QgsVectorTileBasicLabelingListModel::data( const QModelIndex &index, int role ) const
52{
53 if ( index.row() < 0 || index.row() >= mLabeling->styles().count() )
54 return QVariant();
55
56 const QList<QgsVectorTileBasicLabelingStyle> styles = mLabeling->styles();
57 const QgsVectorTileBasicLabelingStyle &style = styles[index.row()];
58
59 switch ( role )
60 {
61 case Qt::DisplayRole:
62 case Qt::ToolTipRole:
63 {
64 if ( index.column() == 0 )
65 return style.styleName();
66 else if ( index.column() == 1 )
67 return style.layerName().isEmpty() ? tr( "(all layers)" ) : style.layerName();
68 else if ( index.column() == 2 )
69 return style.minZoomLevel() >= 0 ? style.minZoomLevel() : QVariant();
70 else if ( index.column() == 3 )
71 return style.maxZoomLevel() >= 0 ? style.maxZoomLevel() : QVariant();
72 else if ( index.column() == 4 )
73 return style.filterExpression().isEmpty() ? tr( "(no filter)" ) : style.filterExpression();
74
75 break;
76 }
77
78 case Qt::EditRole:
79 {
80 if ( index.column() == 0 )
81 return style.styleName();
82 else if ( index.column() == 1 )
83 return style.layerName();
84 else if ( index.column() == 2 )
85 return style.minZoomLevel();
86 else if ( index.column() == 3 )
87 return style.maxZoomLevel();
88 else if ( index.column() == 4 )
89 return style.filterExpression();
90
91 break;
92 }
93
94 case Qt::CheckStateRole:
95 {
96 if ( index.column() != 0 )
97 return QVariant();
98 return style.isEnabled() ? Qt::Checked : Qt::Unchecked;
99 }
100
101 case Qt::DecorationRole:
102 {
103 if ( index.column() == 0 )
104 {
105 const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
106 return QgsPalLayerSettings::labelSettingsPreviewPixmap( style.labelSettings(), QSize( iconSize, iconSize ), QString(), static_cast< int >( iconSize * ICON_PADDING_FACTOR ) );
107 }
108 break;
109 }
110
111 case MinZoom:
112 return style.minZoomLevel();
113
114 case MaxZoom:
115 return style.maxZoomLevel();
116
117 case Label:
118 return style.styleName();
119
120 case Layer:
121 return style.layerName();
122
123 case Filter:
124 return style.filterExpression();
125
126 }
127 return QVariant();
128}
129
130QVariant QgsVectorTileBasicLabelingListModel::headerData( int section, Qt::Orientation orientation, int role ) const
131{
132 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < 5 )
133 {
134 QStringList lst;
135 lst << tr( "Label" ) << tr( "Layer" ) << tr( "Min. Zoom" ) << tr( "Max. Zoom" ) << tr( "Filter" );
136 return lst[section];
137 }
138
139 return QVariant();
140}
141
142Qt::ItemFlags QgsVectorTileBasicLabelingListModel::flags( const QModelIndex &index ) const
143{
144 if ( !index.isValid() )
145 return Qt::ItemIsDropEnabled;
146
147 const Qt::ItemFlag checkable = ( index.column() == 0 ? Qt::ItemIsUserCheckable : Qt::NoItemFlags );
148
149 return Qt::ItemIsEnabled | Qt::ItemIsSelectable |
150 Qt::ItemIsEditable | checkable |
151 Qt::ItemIsDragEnabled;
152}
153
154bool QgsVectorTileBasicLabelingListModel::setData( const QModelIndex &index, const QVariant &value, int role )
155{
156 if ( !index.isValid() )
157 return false;
158
159 QgsVectorTileBasicLabelingStyle style = mLabeling->style( index.row() );
160
161 if ( role == Qt::CheckStateRole )
162 {
163 style.setEnabled( value.toInt() == Qt::Checked );
164 mLabeling->setStyle( index.row(), style );
165 emit dataChanged( index, index );
166 return true;
167 }
168
169 if ( role == Qt::EditRole )
170 {
171 if ( index.column() == 0 )
172 style.setStyleName( value.toString() );
173 else if ( index.column() == 1 )
174 style.setLayerName( value.toString() );
175 else if ( index.column() == 2 )
176 style.setMinZoomLevel( value.toInt() );
177 else if ( index.column() == 3 )
178 style.setMaxZoomLevel( value.toInt() );
179 else if ( index.column() == 4 )
180 style.setFilterExpression( value.toString() );
181
182 mLabeling->setStyle( index.row(), style );
183 emit dataChanged( index, index );
184 return true;
185 }
186
187 return false;
188}
189
190bool QgsVectorTileBasicLabelingListModel::removeRows( int row, int count, const QModelIndex &parent )
191{
192 QList<QgsVectorTileBasicLabelingStyle> styles = mLabeling->styles();
193
194 if ( row < 0 || row >= styles.count() )
195 return false;
196
197 beginRemoveRows( parent, row, row + count - 1 );
198
199 for ( int i = 0; i < count; i++ )
200 {
201 if ( row < styles.count() )
202 {
203 styles.removeAt( row );
204 }
205 }
206
207 mLabeling->setStyles( styles );
208
209 endRemoveRows();
210 return true;
211}
212
213void QgsVectorTileBasicLabelingListModel::insertStyle( int row, const QgsVectorTileBasicLabelingStyle &style )
214{
215 beginInsertRows( QModelIndex(), row, row );
216
217 QList<QgsVectorTileBasicLabelingStyle> styles = mLabeling->styles();
218 styles.insert( row, style );
219 mLabeling->setStyles( styles );
220
221 endInsertRows();
222}
223
224Qt::DropActions QgsVectorTileBasicLabelingListModel::supportedDropActions() const
225{
226 return Qt::MoveAction;
227}
228
229QStringList QgsVectorTileBasicLabelingListModel::mimeTypes() const
230{
231 QStringList types;
232 types << QStringLiteral( "application/vnd.text.list" );
233 return types;
234}
235
236QMimeData *QgsVectorTileBasicLabelingListModel::mimeData( const QModelIndexList &indexes ) const
237{
238 QMimeData *mimeData = new QMimeData();
239 QByteArray encodedData;
240
241 QDataStream stream( &encodedData, QIODevice::WriteOnly );
242
243 const auto constIndexes = indexes;
244 for ( const QModelIndex &index : constIndexes )
245 {
246 // each item consists of several columns - let's add it with just first one
247 if ( !index.isValid() || index.column() != 0 )
248 continue;
249
250 const QgsVectorTileBasicLabelingStyle style = mLabeling->style( index.row() );
251
252 QDomDocument doc;
253 QDomElement rootElem = doc.createElement( QStringLiteral( "vector_tile_basic_labeling_style_mime" ) );
254 style.writeXml( rootElem, QgsReadWriteContext() );
255 doc.appendChild( rootElem );
256
257 stream << doc.toString( -1 );
258 }
259
260 mimeData->setData( QStringLiteral( "application/vnd.text.list" ), encodedData );
261 return mimeData;
262}
263
264bool QgsVectorTileBasicLabelingListModel::dropMimeData( const QMimeData *data,
265 Qt::DropAction action, int row, int column, const QModelIndex &parent )
266{
267 Q_UNUSED( column )
268
269 if ( action == Qt::IgnoreAction )
270 return true;
271
272 if ( !data->hasFormat( QStringLiteral( "application/vnd.text.list" ) ) )
273 return false;
274
275 if ( parent.column() > 0 )
276 return false;
277
278 QByteArray encodedData = data->data( QStringLiteral( "application/vnd.text.list" ) );
279 QDataStream stream( &encodedData, QIODevice::ReadOnly );
280 int rows = 0;
281
282 if ( row == -1 )
283 {
284 // the item was dropped at a parent - we may decide where to put the items - let's append them
285 row = rowCount( parent );
286 }
287
288 while ( !stream.atEnd() )
289 {
290 QString text;
291 stream >> text;
292
293 QDomDocument doc;
294 if ( !doc.setContent( text ) )
295 continue;
296 const QDomElement rootElem = doc.documentElement();
297 if ( rootElem.tagName() != QLatin1String( "vector_tile_basic_labeling_style_mime" ) )
298 continue;
299
301 style.readXml( rootElem, QgsReadWriteContext() );
302
303 insertStyle( row + rows, style );
304 ++rows;
305 }
306 return true;
307}
308
309
310//
311
312
313QgsVectorTileBasicLabelingWidget::QgsVectorTileBasicLabelingWidget( QgsVectorTileLayer *layer, QgsMapCanvas *canvas, QgsMessageBar *messageBar, QWidget *parent )
314 : QgsMapLayerConfigWidget( layer, canvas, parent )
315 , mMapCanvas( canvas )
316 , mMessageBar( messageBar )
317{
318
319 setupUi( this );
320 layout()->setContentsMargins( 0, 0, 0, 0 );
321
322 mFilterLineEdit->setShowClearButton( true );
323 mFilterLineEdit->setShowSearchIcon( true );
324 mFilterLineEdit->setPlaceholderText( tr( "Filter rules" ) );
325
326 QMenu *menuAddRule = new QMenu( btnAddRule );
327 menuAddRule->addAction( tr( "Marker" ), this, [this] { addStyle( Qgis::GeometryType::Point ); } );
328 menuAddRule->addAction( tr( "Line" ), this, [this] { addStyle( Qgis::GeometryType::Line ); } );
329 menuAddRule->addAction( tr( "Fill" ), this, [this] { addStyle( Qgis::GeometryType::Polygon ); } );
330 btnAddRule->setMenu( menuAddRule );
331
332 //connect( btnAddRule, &QPushButton::clicked, this, &QgsVectorTileBasicLabelingWidget::addStyle );
333 connect( btnEditRule, &QPushButton::clicked, this, &QgsVectorTileBasicLabelingWidget::editStyle );
334 connect( btnRemoveRule, &QAbstractButton::clicked, this, &QgsVectorTileBasicLabelingWidget::removeStyle );
335
336 mLabelModeComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "labelingNone.svg" ) ), tr( "No Labels" ) );
337 mLabelModeComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "labelingRuleBased.svg" ) ), tr( "Rule-based Labeling" ) );
338 connect( mLabelModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsVectorTileBasicLabelingWidget::labelModeChanged );
339
340 connect( viewStyles, &QAbstractItemView::doubleClicked, this, &QgsVectorTileBasicLabelingWidget::editStyleAtIndex );
341
342 if ( mMapCanvas )
343 {
344 connect( mMapCanvas, &QgsMapCanvas::scaleChanged, this, [ = ]( double scale )
345 {
346 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
347 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( scale,
348 mapSettings.destinationCrs(),
349 mapSettings.visibleExtent(),
350 mapSettings.outputSize(),
351 mapSettings.outputDpi() ) : 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 = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(),
360 mapSettings.destinationCrs(),
361 mapSettings.visibleExtent(),
362 mapSettings.outputSize(),
363 mapSettings.outputDpi() ) : mMapCanvas->scale();
364 mLabelCurrentZoom->setText( tr( "Current zoom: %1" ).arg( mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 ) ) );
365 }
366
367 connect( mCheckVisibleOnly, &QCheckBox::toggled, this, [ = ]( bool filter )
368 {
369 mProxyModel->setFilterVisible( filter );
370 } );
371
372 connect( mFilterLineEdit, &QgsFilterLineEdit::textChanged, this, [ = ]( const QString & text )
373 {
374 mProxyModel->setFilterString( text );
375 } );
376
377 setLayer( layer );
378}
379
380void QgsVectorTileBasicLabelingWidget::setLayer( QgsVectorTileLayer *layer )
381{
382 if ( mVTLayer )
383 {
384 disconnect( mVTLayer );
385 }
386
387 mVTLayer = layer;
388 connect( mVTLayer, &QgsMapLayer::styleChanged, this, [ = ]() { setLayer( mVTLayer ); } );
389
390 if ( layer && layer->labeling() && layer->labeling()->type() == QLatin1String( "basic" ) )
391 {
392 mLabeling.reset( static_cast<QgsVectorTileBasicLabeling *>( layer->labeling()->clone() ) );
393 whileBlocking( mLabelModeComboBox )->setCurrentIndex( layer->labelsEnabled() ? 1 : 0 );
394 }
395 else
396 {
397 mLabeling.reset( new QgsVectorTileBasicLabeling() );
398 whileBlocking( mLabelModeComboBox )->setCurrentIndex( 1 );
399 }
400 mOptionsStackedWidget->setCurrentIndex( mLabelModeComboBox->currentIndex() );
401
402 mModel = new QgsVectorTileBasicLabelingListModel( mLabeling.get(), viewStyles );
403 mProxyModel = new QgsVectorTileBasicLabelingProxyModel( 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
423QgsVectorTileBasicLabelingWidget::~QgsVectorTileBasicLabelingWidget() = default;
424
425void QgsVectorTileBasicLabelingWidget::apply()
426{
427 mVTLayer->setLabeling( mLabeling->clone() );
428 mVTLayer->setLabelsEnabled( mLabelModeComboBox->currentIndex() == 1 );
429}
430
431void QgsVectorTileBasicLabelingWidget::labelModeChanged()
432{
433 mOptionsStackedWidget->setCurrentIndex( mLabelModeComboBox->currentIndex() );
434 emit widgetChanged();
435}
436
437void QgsVectorTileBasicLabelingWidget::addStyle( Qgis::GeometryType geomType )
438{
440 style.setGeometryType( geomType );
441 switch ( geomType )
442 {
444 style.setFilterExpression( QStringLiteral( "geometry_type($geometry)='Point'" ) );
445 break;
447 style.setFilterExpression( QStringLiteral( "geometry_type($geometry)='Line'" ) );
448 break;
450 style.setFilterExpression( QStringLiteral( "geometry_type($geometry)='Polygon'" ) );
451 break;
454 break;
455 }
456
457 const int rows = mModel->rowCount();
458 mModel->insertStyle( rows, style );
459 viewStyles->selectionModel()->setCurrentIndex( mProxyModel->mapFromSource( mModel->index( rows, 0 ) ), QItemSelectionModel::ClearAndSelect );
460}
461
462void QgsVectorTileBasicLabelingWidget::editStyle()
463{
464 editStyleAtIndex( viewStyles->selectionModel()->currentIndex() );
465}
466
467void QgsVectorTileBasicLabelingWidget::editStyleAtIndex( const QModelIndex &proxyIndex )
468{
469 const QModelIndex index = mProxyModel->mapToSource( proxyIndex );
470 if ( index.row() < 0 || index.row() >= mLabeling->styles().count() )
471 return;
472
473 const QgsVectorTileBasicLabelingStyle style = mLabeling->style( index.row() );
474
475 QgsPalLayerSettings labelSettings = style.labelSettings();
476 if ( labelSettings.layerType == Qgis::GeometryType::Unknown )
477 labelSettings.layerType = style.geometryType();
478
480 context.setMapCanvas( mMapCanvas );
481 context.setMessageBar( mMessageBar );
482
483 if ( mMapCanvas )
484 {
485 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
486 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(),
487 mapSettings.destinationCrs(),
488 mapSettings.visibleExtent(),
489 mapSettings.outputSize(),
490 mapSettings.outputDpi() ) : mMapCanvas->scale();
491 const int zoom = mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 );
492 QList<QgsExpressionContextScope> scopes = context.additionalExpressionContextScopes();
494 tileScope.setVariable( "zoom_level", zoom, true );
495 tileScope.setVariable( "vector_tile_zoom", mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoom( mMapCanvas->scale() ) : QgsVectorTileUtils::scaleToZoom( mMapCanvas->scale() ), true );
496 scopes << tileScope;
497 context.setAdditionalExpressionContextScopes( scopes );
498 }
499
500 QgsVectorLayer *vectorLayer = nullptr; // TODO: have a temporary vector layer with sub-layer's fields?
501
503 if ( panel && panel->dockMode() )
504 {
505 QgsLabelingPanelWidget *widget = new QgsLabelingPanelWidget( labelSettings, vectorLayer, mMapCanvas, panel );
506 widget->setContext( context );
507 widget->setPanelTitle( style.styleName() );
508 connect( widget, &QgsPanelWidget::widgetChanged, this, &QgsVectorTileBasicLabelingWidget::updateLabelingFromWidget );
509 openPanel( widget );
510 }
511 else
512 {
513 QgsLabelSettingsDialog dlg( labelSettings, vectorLayer, mMapCanvas, this, labelSettings.layerType );
514 if ( dlg.exec() )
515 {
516 QgsVectorTileBasicLabelingStyle style = mLabeling->style( index.row() );
517 style.setLabelSettings( dlg.settings() );
518 mLabeling->setStyle( index.row(), style );
519 emit widgetChanged();
520 }
521 }
522}
523
524void QgsVectorTileBasicLabelingWidget::updateLabelingFromWidget()
525{
526 const int index = mProxyModel->mapToSource( viewStyles->selectionModel()->currentIndex() ).row();
527 if ( index < 0 )
528 return;
529
530 QgsVectorTileBasicLabelingStyle style = mLabeling->style( index );
531
532 QgsLabelingPanelWidget *widget = qobject_cast<QgsLabelingPanelWidget *>( sender() );
533 style.setLabelSettings( widget->labelSettings() );
534
535 mLabeling->setStyle( index, style );
536 emit widgetChanged();
537}
538
539void QgsVectorTileBasicLabelingWidget::removeStyle()
540{
541 const QModelIndexList sel = viewStyles->selectionModel()->selectedIndexes();
542
543 QList<int > res;
544 for ( const QModelIndex &proxyIndex : sel )
545 {
546 const QModelIndex sourceIndex = mProxyModel->mapToSource( proxyIndex );
547 if ( !res.contains( sourceIndex.row() ) )
548 res << sourceIndex.row();
549 }
550 std::sort( res.begin(), res.end() );
551
552 for ( int i = res.size() - 1; i >= 0; --i )
553 {
554 mModel->removeRow( res[ i ] );
555 }
556 // make sure that the selection is gone
557 viewStyles->selectionModel()->clear();
558}
559
560
561//
562
563
564QgsLabelingPanelWidget::QgsLabelingPanelWidget( const QgsPalLayerSettings &labelSettings, QgsVectorLayer *vectorLayer, QgsMapCanvas *mapCanvas, QWidget *parent )
565 : QgsPanelWidget( parent )
566{
567 mLabelingGui = new QgsLabelingGui( vectorLayer, mapCanvas, labelSettings, this, labelSettings.layerType );
568 mLabelingGui->setLabelMode( QgsLabelingGui::Labels );
569
570 mLabelingGui->layout()->setContentsMargins( 0, 0, 0, 0 );
571 QVBoxLayout *l = new QVBoxLayout;
572 l->addWidget( mLabelingGui );
573 setLayout( l );
574
575 connect( mLabelingGui, &QgsTextFormatWidget::widgetChanged, this, &QgsLabelingPanelWidget::widgetChanged );
576}
577
578void QgsLabelingPanelWidget::setDockMode( bool dockMode )
579{
580 QgsPanelWidget::setDockMode( dockMode );
581 mLabelingGui->setDockMode( dockMode );
582}
583
584void QgsLabelingPanelWidget::setContext( const QgsSymbolWidgetContext &context )
585{
586 mLabelingGui->setContext( context );
587}
588
589QgsPalLayerSettings QgsLabelingPanelWidget::labelSettings()
590{
591 return mLabelingGui->layerSettings();
592}
593
594
595QgsVectorTileBasicLabelingProxyModel::QgsVectorTileBasicLabelingProxyModel( QgsVectorTileBasicLabelingListModel *source, QObject *parent )
596 : QSortFilterProxyModel( parent )
597{
598 setSourceModel( source );
599 setDynamicSortFilter( true );
600}
601
602void QgsVectorTileBasicLabelingProxyModel::setCurrentZoom( int zoom )
603{
604 mCurrentZoom = zoom;
605 invalidateFilter();
606}
607
608void QgsVectorTileBasicLabelingProxyModel::setFilterVisible( bool enabled )
609{
610 mFilterVisible = enabled;
611 invalidateFilter();
612}
613
614void QgsVectorTileBasicLabelingProxyModel::setFilterString( const QString &string )
615{
616 mFilterString = string;
617 invalidateFilter();
618}
619
620bool QgsVectorTileBasicLabelingProxyModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const
621{
622 if ( mCurrentZoom >= 0 && mFilterVisible )
623 {
624 const int rowMinZoom = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::MinZoom ).toInt();
625 const int rowMaxZoom = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::MaxZoom ).toInt();
626
627 if ( rowMinZoom >= 0 && rowMinZoom > mCurrentZoom )
628 return false;
629
630 if ( rowMaxZoom >= 0 && rowMaxZoom < mCurrentZoom )
631 return false;
632 }
633
634 if ( !mFilterString.isEmpty() )
635 {
636 const QString name = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::Label ).toString();
637 const QString layer = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::Layer ).toString();
638 const QString filter = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::Filter ).toString();
639 if ( !name.contains( mFilterString, Qt::CaseInsensitive )
640 && !layer.contains( mFilterString, Qt::CaseInsensitive )
641 && !filter.contains( mFilterString, Qt::CaseInsensitive ) )
642 {
643 return false;
644 }
645 }
646
647 return true;
648}
649
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.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
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.
void styleChanged()
Signal emitted whenever a change affects the layer's style.
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.
Contains settings for how a map layer will be labeled.
Qgis::GeometryType layerType
Geometry type of layers associated with these settings.
static QPixmap labelSettingsPreviewPixmap(const QgsPalLayerSettings &settings, QSize size, const QString &previewText=QString(), int padding=0, const QgsScreenProperties &screen=QgsScreenProperties())
Returns a pixmap preview for label settings.
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.
virtual void setDockMode(bool dockMode)
Set the widget in dock mode which tells the widget to emit panel widgets and not open dialogs.
bool dockMode()
Returns the dock mode state.
The class is used as a container of context for various read/write operations on other objects.
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.
void widgetChanged()
Emitted when the text format defined by the widget changes.
Represents a vector layer which manages a vector based data sets.
Configuration of a single style within QgsVectorTileBasicLabeling.
QgsPalLayerSettings labelSettings() const
Returns labeling configuration of this style.
QString layerName() const
Returns name of the sub-layer to render (empty layer means that all layers match)
void setLayerName(const QString &name)
Sets name of the sub-layer to render (empty layer means that all layers match)
QString filterExpression() const
Returns filter expression (empty filter means that all features match)
void setMinZoomLevel(int minZoom)
Sets minimum zoom level index (negative number means no limit).
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const
Writes object content to given DOM element.
int maxZoomLevel() const
Returns the maximum zoom level index (negative number means no limit).
void setFilterExpression(const QString &expr)
Sets filter expression (empty filter means that all features match)
int minZoomLevel() const
Returns the minimum zoom level index (negative number means no limit).
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Reads object content from given DOM element.
void setMaxZoomLevel(int maxZoom)
Sets maximum zoom level index (negative number means no limit).
void setStyleName(const QString &name)
Sets human readable name of this style.
void setGeometryType(Qgis::GeometryType geomType)
Sets type of the geometry that will be used (point / line / polygon)
void setLabelSettings(const QgsPalLayerSettings &settings)
Sets labeling configuration of this style.
Qgis::GeometryType geometryType() const
Returns type of the geometry that will be used (point / line / polygon)
void setEnabled(bool enabled)
Sets whether this style is enabled (used for rendering)
QString styleName() const
Returns human readable name of this style.
bool isEnabled() const
Returns whether this style is enabled (used for rendering)
Basic labeling configuration for vector tile layers.
virtual QString type() const =0
Unique type string of the labeling configuration implementation.
virtual QgsVectorTileLabeling * clone() const =0SIP_FACTORY
Returns a new copy of the object.
Implements a map layer that is dedicated to rendering of vector tiles.
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
QgsVectorTileLabeling * labeling() const
Returns currently assigned labeling.
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,...
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition qgis.h:4258
const double ICON_PADDING_FACTOR