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