QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 <memory>
19
20#include "qgis.h"
21#include "qgsapplication.h"
22#include "qgslabelinggui.h"
23#include "qgsmapcanvas.h"
24#include "qgsvectorlayer.h"
26#include "qgsvectortilelayer.h"
27#include "qgsvectortileutils.h"
28
29#include <QMenu>
30
31#include "moc_qgsvectortilebasiclabelingwidget.cpp"
32
34
35const double ICON_PADDING_FACTOR = 0.16;
36
37QgsVectorTileBasicLabelingListModel::QgsVectorTileBasicLabelingListModel( QgsVectorTileBasicLabeling *l, QObject *parent )
38 : QAbstractListModel( parent )
39 , mLabeling( l )
40{
41}
42
43int QgsVectorTileBasicLabelingListModel::rowCount( const QModelIndex &parent ) const
44{
45 if ( parent.isValid() )
46 return 0;
47
48 return mLabeling->styles().count();
49}
50
51int QgsVectorTileBasicLabelingListModel::columnCount( const QModelIndex & ) const
52{
53 return 5;
54}
55
56QVariant QgsVectorTileBasicLabelingListModel::data( const QModelIndex &index, int role ) const
57{
58 if ( index.row() < 0 || index.row() >= mLabeling->styles().count() )
59 return QVariant();
60
61 const QList<QgsVectorTileBasicLabelingStyle> styles = mLabeling->styles();
62 const QgsVectorTileBasicLabelingStyle &style = styles[index.row()];
63
64 switch ( role )
65 {
66 case Qt::DisplayRole:
67 case Qt::ToolTipRole:
68 {
69 if ( index.column() == 0 )
70 return style.styleName();
71 else if ( index.column() == 1 )
72 return style.layerName().isEmpty() ? tr( "(all layers)" ) : style.layerName();
73 else if ( index.column() == 2 )
74 return style.minZoomLevel() >= 0 ? style.minZoomLevel() : QVariant();
75 else if ( index.column() == 3 )
76 return style.maxZoomLevel() >= 0 ? style.maxZoomLevel() : QVariant();
77 else if ( index.column() == 4 )
78 return style.filterExpression().isEmpty() ? tr( "(no filter)" ) : style.filterExpression();
79
80 break;
81 }
82
83 case Qt::EditRole:
84 {
85 if ( index.column() == 0 )
86 return style.styleName();
87 else if ( index.column() == 1 )
88 return style.layerName();
89 else if ( index.column() == 2 )
90 return style.minZoomLevel();
91 else if ( index.column() == 3 )
92 return style.maxZoomLevel();
93 else if ( index.column() == 4 )
94 return style.filterExpression();
95
96 break;
97 }
98
99 case Qt::CheckStateRole:
100 {
101 if ( index.column() != 0 )
102 return QVariant();
103 return style.isEnabled() ? Qt::Checked : Qt::Unchecked;
104 }
105
106 case Qt::DecorationRole:
107 {
108 if ( index.column() == 0 )
109 {
110 const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
111 return QgsPalLayerSettings::labelSettingsPreviewPixmap( style.labelSettings(), QSize( iconSize, iconSize ), QString(), static_cast<int>( iconSize * ICON_PADDING_FACTOR ) );
112 }
113 break;
114 }
115
116 case MinZoom:
117 return style.minZoomLevel();
118
119 case MaxZoom:
120 return style.maxZoomLevel();
121
122 case Label:
123 return style.styleName();
124
125 case Layer:
126 return style.layerName();
127
128 case Filter:
129 return style.filterExpression();
130 }
131 return QVariant();
132}
133
134QVariant QgsVectorTileBasicLabelingListModel::headerData( int section, Qt::Orientation orientation, int role ) const
135{
136 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < 5 )
137 {
138 QStringList lst;
139 lst << tr( "Label" ) << tr( "Layer" ) << tr( "Min. Zoom" ) << tr( "Max. Zoom" ) << tr( "Filter" );
140 return lst[section];
141 }
142
143 return QVariant();
144}
145
146Qt::ItemFlags QgsVectorTileBasicLabelingListModel::flags( const QModelIndex &index ) const
147{
148 if ( !index.isValid() )
149 return Qt::ItemIsDropEnabled;
150
151 const Qt::ItemFlag checkable = ( index.column() == 0 ? Qt::ItemIsUserCheckable : Qt::NoItemFlags );
152
153 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable | checkable | Qt::ItemIsDragEnabled;
154}
155
156bool QgsVectorTileBasicLabelingListModel::setData( const QModelIndex &index, const QVariant &value, int role )
157{
158 if ( !index.isValid() )
159 return false;
160
161 QgsVectorTileBasicLabelingStyle style = mLabeling->style( index.row() );
162
163 if ( role == Qt::CheckStateRole )
164 {
165 style.setEnabled( value.toInt() == Qt::Checked );
166 mLabeling->setStyle( index.row(), style );
167 emit dataChanged( index, index );
168 return true;
169 }
170
171 if ( role == Qt::EditRole )
172 {
173 if ( index.column() == 0 )
174 style.setStyleName( value.toString() );
175 else if ( index.column() == 1 )
176 style.setLayerName( value.toString() );
177 else if ( index.column() == 2 )
178 style.setMinZoomLevel( value.toInt() );
179 else if ( index.column() == 3 )
180 style.setMaxZoomLevel( value.toInt() );
181 else if ( index.column() == 4 )
182 style.setFilterExpression( value.toString() );
183
184 mLabeling->setStyle( index.row(), style );
185 emit dataChanged( index, index );
186 return true;
187 }
188
189 return false;
190}
191
192bool QgsVectorTileBasicLabelingListModel::removeRows( int row, int count, const QModelIndex &parent )
193{
194 QList<QgsVectorTileBasicLabelingStyle> styles = mLabeling->styles();
195
196 if ( row < 0 || row >= styles.count() )
197 return false;
198
199 beginRemoveRows( parent, row, row + count - 1 );
200
201 for ( int i = 0; i < count; i++ )
202 {
203 if ( row < styles.count() )
204 {
205 styles.removeAt( row );
206 }
207 }
208
209 mLabeling->setStyles( styles );
210
211 endRemoveRows();
212 return true;
213}
214
215void QgsVectorTileBasicLabelingListModel::insertStyle( int row, const QgsVectorTileBasicLabelingStyle &style )
216{
217 beginInsertRows( QModelIndex(), row, row );
218
219 QList<QgsVectorTileBasicLabelingStyle> styles = mLabeling->styles();
220 styles.insert( row, style );
221 mLabeling->setStyles( styles );
222
223 endInsertRows();
224}
225
226Qt::DropActions QgsVectorTileBasicLabelingListModel::supportedDropActions() const
227{
228 return Qt::MoveAction;
229}
230
231QStringList QgsVectorTileBasicLabelingListModel::mimeTypes() const
232{
233 QStringList types;
234 types << QStringLiteral( "application/vnd.text.list" );
235 return types;
236}
237
238QMimeData *QgsVectorTileBasicLabelingListModel::mimeData( const QModelIndexList &indexes ) const
239{
240 QMimeData *mimeData = new QMimeData();
241 QByteArray encodedData;
242
243 QDataStream stream( &encodedData, QIODevice::WriteOnly );
244
245 const auto constIndexes = indexes;
246 for ( const QModelIndex &index : constIndexes )
247 {
248 // each item consists of several columns - let's add it with just first one
249 if ( !index.isValid() || index.column() != 0 )
250 continue;
251
252 const QgsVectorTileBasicLabelingStyle style = mLabeling->style( index.row() );
253
254 QDomDocument doc;
255 QDomElement rootElem = doc.createElement( QStringLiteral( "vector_tile_basic_labeling_style_mime" ) );
256 style.writeXml( rootElem, QgsReadWriteContext() );
257 doc.appendChild( rootElem );
258
259 stream << doc.toString( -1 );
260 }
261
262 mimeData->setData( QStringLiteral( "application/vnd.text.list" ), encodedData );
263 return mimeData;
264}
265
266bool QgsVectorTileBasicLabelingListModel::dropMimeData( const QMimeData *data, 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 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, [this]( double scale ) {
345 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
346 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( scale, mapSettings.destinationCrs(), mapSettings.visibleExtent(), mapSettings.outputSize(), mapSettings.outputDpi() ) : scale;
347 const int zoom = mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 );
348 mLabelCurrentZoom->setText( tr( "Current zoom: %1" ).arg( zoom ) );
349 if ( mProxyModel )
350 mProxyModel->setCurrentZoom( zoom );
351 } );
352
353 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
354 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(), mapSettings.destinationCrs(), mapSettings.visibleExtent(), mapSettings.outputSize(), mapSettings.outputDpi() ) : mMapCanvas->scale();
355 mLabelCurrentZoom->setText( tr( "Current zoom: %1" ).arg( mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 ) ) );
356 }
357
358 connect( mCheckVisibleOnly, &QCheckBox::toggled, this, [this]( bool filter ) {
359 mProxyModel->setFilterVisible( filter );
360 } );
361
362 connect( mFilterLineEdit, &QgsFilterLineEdit::textChanged, this, [this]( const QString &text ) {
363 mProxyModel->setFilterString( text );
364 } );
365
366 setLayer( layer );
367}
368
369void QgsVectorTileBasicLabelingWidget::resyncToCurrentLayer()
370{
371 setLayer( mVTLayer );
372}
373
374void QgsVectorTileBasicLabelingWidget::setLayer( QgsVectorTileLayer *layer )
375{
376 if ( mVTLayer && mVTLayer != layer )
377 {
378 disconnect( mVTLayer, &QgsMapLayer::styleChanged, this, &QgsVectorTileBasicLabelingWidget::resyncToCurrentLayer );
379 }
380 else if ( layer )
381 {
382 connect( layer, &QgsMapLayer::styleChanged, this, &QgsVectorTileBasicLabelingWidget::resyncToCurrentLayer );
383 }
384
385 mVTLayer = layer;
386
387 if ( mVTLayer && mVTLayer->labeling() && mVTLayer->labeling()->type() == QLatin1String( "basic" ) )
388 {
389 mLabeling.reset( static_cast<QgsVectorTileBasicLabeling *>( mVTLayer->labeling()->clone() ) );
390 whileBlocking( mLabelModeComboBox )->setCurrentIndex( mVTLayer->labelsEnabled() ? 1 : 0 );
391 }
392 else
393 {
394 mLabeling = std::make_unique<QgsVectorTileBasicLabeling>();
395 whileBlocking( mLabelModeComboBox )->setCurrentIndex( 1 );
396 }
397 mOptionsStackedWidget->setCurrentIndex( mLabelModeComboBox->currentIndex() );
398
399 mModel = new QgsVectorTileBasicLabelingListModel( mLabeling.get(), viewStyles );
400 mProxyModel = new QgsVectorTileBasicLabelingProxyModel( mModel, viewStyles );
401 viewStyles->setModel( mProxyModel );
402
403 if ( mMapCanvas )
404 {
405 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
406 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(), mapSettings.destinationCrs(), mapSettings.visibleExtent(), mapSettings.outputSize(), mapSettings.outputDpi() ) : mMapCanvas->scale();
407 const int zoom = mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 );
408 mProxyModel->setCurrentZoom( zoom );
409 }
410
411 connect( mModel, &QAbstractItemModel::dataChanged, this, &QgsPanelWidget::widgetChanged );
412 connect( mModel, &QAbstractItemModel::rowsInserted, this, &QgsPanelWidget::widgetChanged );
413 connect( mModel, &QAbstractItemModel::rowsRemoved, this, &QgsPanelWidget::widgetChanged );
414}
415
416QgsVectorTileBasicLabelingWidget::~QgsVectorTileBasicLabelingWidget() = default;
417
418void QgsVectorTileBasicLabelingWidget::apply()
419{
420 mVTLayer->setLabeling( mLabeling->clone() );
421 mVTLayer->setLabelsEnabled( mLabelModeComboBox->currentIndex() == 1 );
422}
423
424void QgsVectorTileBasicLabelingWidget::labelModeChanged()
425{
426 mOptionsStackedWidget->setCurrentIndex( mLabelModeComboBox->currentIndex() );
427 emit widgetChanged();
428}
429
430void QgsVectorTileBasicLabelingWidget::addStyle( Qgis::GeometryType geomType )
431{
433 style.setGeometryType( geomType );
434 switch ( geomType )
435 {
437 style.setFilterExpression( QStringLiteral( "geometry_type(@geometry)='Point'" ) );
438 break;
440 style.setFilterExpression( QStringLiteral( "geometry_type(@geometry)='Line'" ) );
441 break;
443 style.setFilterExpression( QStringLiteral( "geometry_type(@geometry)='Polygon'" ) );
444 break;
447 break;
448 }
449
450 const int rows = mModel->rowCount();
451 mModel->insertStyle( rows, style );
452 viewStyles->selectionModel()->setCurrentIndex( mProxyModel->mapFromSource( mModel->index( rows, 0 ) ), QItemSelectionModel::ClearAndSelect );
453}
454
455void QgsVectorTileBasicLabelingWidget::editStyle()
456{
457 editStyleAtIndex( viewStyles->selectionModel()->currentIndex() );
458}
459
460void QgsVectorTileBasicLabelingWidget::editStyleAtIndex( const QModelIndex &proxyIndex )
461{
462 const QModelIndex index = mProxyModel->mapToSource( proxyIndex );
463 if ( index.row() < 0 || index.row() >= mLabeling->styles().count() )
464 return;
465
466 const QgsVectorTileBasicLabelingStyle style = mLabeling->style( index.row() );
467
468 QgsPalLayerSettings labelSettings = style.labelSettings();
469 if ( labelSettings.layerType == Qgis::GeometryType::Unknown )
470 labelSettings.layerType = style.geometryType();
471
473 context.setMapCanvas( mMapCanvas );
474 context.setMessageBar( mMessageBar );
475
476 if ( mMapCanvas )
477 {
478 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
479 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(), mapSettings.destinationCrs(), mapSettings.visibleExtent(), mapSettings.outputSize(), mapSettings.outputDpi() ) : mMapCanvas->scale();
480 const int zoom = mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 );
481 QList<QgsExpressionContextScope> scopes = context.additionalExpressionContextScopes();
483 tileScope.setVariable( "zoom_level", zoom, true );
484 tileScope.setVariable( "vector_tile_zoom", mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoom( mMapCanvas->scale() ) : QgsVectorTileUtils::scaleToZoom( mMapCanvas->scale() ), true );
485 scopes << tileScope;
486 context.setAdditionalExpressionContextScopes( scopes );
487 }
488
489 QgsVectorLayer *vectorLayer = nullptr; // TODO: have a temporary vector layer with sub-layer's fields?
490
492 if ( panel && panel->dockMode() )
493 {
494 QgsLabelingPanelWidget *widget = new QgsLabelingPanelWidget( labelSettings, vectorLayer, mMapCanvas, panel );
495 widget->setContext( context );
496 widget->setPanelTitle( style.styleName() );
497 connect( widget, &QgsPanelWidget::widgetChanged, this, &QgsVectorTileBasicLabelingWidget::updateLabelingFromWidget );
498 openPanel( widget );
499 }
500 else
501 {
502 QgsLabelSettingsDialog dlg( labelSettings, vectorLayer, mMapCanvas, this, labelSettings.layerType );
503 if ( dlg.exec() )
504 {
505 QgsVectorTileBasicLabelingStyle style = mLabeling->style( index.row() );
506 style.setLabelSettings( dlg.settings() );
507 mLabeling->setStyle( index.row(), style );
508 emit widgetChanged();
509 }
510 }
511}
512
513void QgsVectorTileBasicLabelingWidget::updateLabelingFromWidget()
514{
515 const int index = mProxyModel->mapToSource( viewStyles->selectionModel()->currentIndex() ).row();
516 if ( index < 0 )
517 return;
518
519 QgsVectorTileBasicLabelingStyle style = mLabeling->style( index );
520
521 QgsLabelingPanelWidget *widget = qobject_cast<QgsLabelingPanelWidget *>( sender() );
522 style.setLabelSettings( widget->labelSettings() );
523
524 mLabeling->setStyle( index, style );
525 emit widgetChanged();
526}
527
528void QgsVectorTileBasicLabelingWidget::removeStyle()
529{
530 const QModelIndexList sel = viewStyles->selectionModel()->selectedIndexes();
531
532 QList<int> res;
533 for ( const QModelIndex &proxyIndex : sel )
534 {
535 const QModelIndex sourceIndex = mProxyModel->mapToSource( proxyIndex );
536 if ( !res.contains( sourceIndex.row() ) )
537 res << sourceIndex.row();
538 }
539 std::sort( res.begin(), res.end() );
540
541 for ( int i = res.size() - 1; i >= 0; --i )
542 {
543 mModel->removeRow( res[i] );
544 }
545 // make sure that the selection is gone
546 viewStyles->selectionModel()->clear();
547}
548
549
550//
551
552
553QgsLabelingPanelWidget::QgsLabelingPanelWidget( const QgsPalLayerSettings &labelSettings, QgsVectorLayer *vectorLayer, QgsMapCanvas *mapCanvas, QWidget *parent )
554 : QgsPanelWidget( parent )
555{
556 mLabelingGui = new QgsLabelingGui( vectorLayer, mapCanvas, labelSettings, this, labelSettings.layerType );
557 mLabelingGui->setLabelMode( QgsLabelingGui::Labels );
558
559 mLabelingGui->layout()->setContentsMargins( 0, 0, 0, 0 );
560 QVBoxLayout *l = new QVBoxLayout;
561 l->addWidget( mLabelingGui );
562 setLayout( l );
563
564 connect( mLabelingGui, &QgsTextFormatWidget::widgetChanged, this, &QgsLabelingPanelWidget::widgetChanged );
565}
566
567void QgsLabelingPanelWidget::setDockMode( bool dockMode )
568{
569 QgsPanelWidget::setDockMode( dockMode );
570 mLabelingGui->setDockMode( dockMode );
571}
572
573void QgsLabelingPanelWidget::setContext( const QgsSymbolWidgetContext &context )
574{
575 mLabelingGui->setContext( context );
576}
577
578QgsPalLayerSettings QgsLabelingPanelWidget::labelSettings()
579{
580 return mLabelingGui->layerSettings();
581}
582
583
584QgsVectorTileBasicLabelingProxyModel::QgsVectorTileBasicLabelingProxyModel( QgsVectorTileBasicLabelingListModel *source, QObject *parent )
585 : QSortFilterProxyModel( parent )
586{
587 setSourceModel( source );
588 setDynamicSortFilter( true );
589}
590
591void QgsVectorTileBasicLabelingProxyModel::setCurrentZoom( int zoom )
592{
593 mCurrentZoom = zoom;
594 invalidateFilter();
595}
596
597void QgsVectorTileBasicLabelingProxyModel::setFilterVisible( bool enabled )
598{
599 mFilterVisible = enabled;
600 invalidateFilter();
601}
602
603void QgsVectorTileBasicLabelingProxyModel::setFilterString( const QString &string )
604{
605 mFilterString = string;
606 invalidateFilter();
607}
608
609bool QgsVectorTileBasicLabelingProxyModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const
610{
611 if ( mCurrentZoom >= 0 && mFilterVisible )
612 {
613 const int rowMinZoom = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::MinZoom ).toInt();
614 const int rowMaxZoom = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::MaxZoom ).toInt();
615
616 if ( rowMinZoom >= 0 && rowMinZoom > mCurrentZoom )
617 return false;
618
619 if ( rowMaxZoom >= 0 && rowMaxZoom < mCurrentZoom )
620 return false;
621 }
622
623 if ( !mFilterString.isEmpty() )
624 {
625 const QString name = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::Label ).toString();
626 const QString layer = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::Layer ).toString();
627 const QString filter = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::Filter ).toString();
628 if ( !name.contains( mFilterString, Qt::CaseInsensitive )
629 && !layer.contains( mFilterString, Qt::CaseInsensitive )
630 && !filter.contains( mFilterString, Qt::CaseInsensitive ) )
631 {
632 return false;
633 }
634 }
635
636 return true;
637}
638
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:358
@ Point
Points.
Definition qgis.h:359
@ Line
Lines.
Definition qgis.h:360
@ Polygon
Polygons.
Definition qgis.h:361
@ Unknown
Unknown types.
Definition qgis.h:362
@ Null
No geometry.
Definition qgis.h:363
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 scale)
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.
Contains configuration for rendering maps.
double scale() const
Returns the calculated map scale.
QSize outputSize() const
Returns the size of the resulting map image, in pixels.
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes output image size into account.
double outputDpi() const
Returns the DPI (dots per inch) used for conversion between real world units (e.g.
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
A bar for displaying non-blocking messages to the user.
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 an inline panel.
bool dockMode() const
Returns the dock mode state.
void widgetChanged()
Emitted when the widget state changes.
static QgsPanelWidget * findParentPanel(QWidget *widget)
Traces through the parents of a widget to find if it is contained within a QgsPanelWidget widget.
virtual void setDockMode(bool dockMode)
Set the widget in dock mode which tells the widget to emit panel widgets and not open dialogs.
A container for the context for various read/write operations on 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 dataset.
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.
Implements a map layer that is dedicated to rendering of vector tiles.
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:6511
const double ICON_PADDING_FACTOR