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