QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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#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::resyncToCurrentLayer()
382{
383 setLayer( mVTLayer );
384}
385
386void QgsVectorTileBasicLabelingWidget::setLayer( QgsVectorTileLayer *layer )
387{
388 if ( mVTLayer && mVTLayer != layer )
389 {
390 disconnect( mVTLayer, &QgsMapLayer::styleChanged, this, &QgsVectorTileBasicLabelingWidget::resyncToCurrentLayer );
391 }
392 else if ( layer )
393 {
394 connect( layer, &QgsMapLayer::styleChanged, this, &QgsVectorTileBasicLabelingWidget::resyncToCurrentLayer );
395 }
396
397 mVTLayer = layer;
398
399 if ( mVTLayer && mVTLayer->labeling() && mVTLayer->labeling()->type() == QLatin1String( "basic" ) )
400 {
401 mLabeling.reset( static_cast<QgsVectorTileBasicLabeling *>( mVTLayer->labeling()->clone() ) );
402 whileBlocking( mLabelModeComboBox )->setCurrentIndex( mVTLayer->labelsEnabled() ? 1 : 0 );
403 }
404 else
405 {
406 mLabeling.reset( new QgsVectorTileBasicLabeling() );
407 whileBlocking( mLabelModeComboBox )->setCurrentIndex( 1 );
408 }
409 mOptionsStackedWidget->setCurrentIndex( mLabelModeComboBox->currentIndex() );
410
411 mModel = new QgsVectorTileBasicLabelingListModel( mLabeling.get(), viewStyles );
412 mProxyModel = new QgsVectorTileBasicLabelingProxyModel( mModel, viewStyles );
413 viewStyles->setModel( mProxyModel );
414
415 if ( mMapCanvas )
416 {
417 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
418 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(),
419 mapSettings.destinationCrs(),
420 mapSettings.visibleExtent(),
421 mapSettings.outputSize(),
422 mapSettings.outputDpi() ) : mMapCanvas->scale();
423 const int zoom = mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 );
424 mProxyModel->setCurrentZoom( zoom );
425 }
426
427 connect( mModel, &QAbstractItemModel::dataChanged, this, &QgsPanelWidget::widgetChanged );
428 connect( mModel, &QAbstractItemModel::rowsInserted, this, &QgsPanelWidget::widgetChanged );
429 connect( mModel, &QAbstractItemModel::rowsRemoved, this, &QgsPanelWidget::widgetChanged );
430}
431
432QgsVectorTileBasicLabelingWidget::~QgsVectorTileBasicLabelingWidget() = default;
433
434void QgsVectorTileBasicLabelingWidget::apply()
435{
436 mVTLayer->setLabeling( mLabeling->clone() );
437 mVTLayer->setLabelsEnabled( mLabelModeComboBox->currentIndex() == 1 );
438}
439
440void QgsVectorTileBasicLabelingWidget::labelModeChanged()
441{
442 mOptionsStackedWidget->setCurrentIndex( mLabelModeComboBox->currentIndex() );
443 emit widgetChanged();
444}
445
446void QgsVectorTileBasicLabelingWidget::addStyle( Qgis::GeometryType geomType )
447{
449 style.setGeometryType( geomType );
450 switch ( geomType )
451 {
453 style.setFilterExpression( QStringLiteral( "geometry_type(@geometry)='Point'" ) );
454 break;
456 style.setFilterExpression( QStringLiteral( "geometry_type(@geometry)='Line'" ) );
457 break;
459 style.setFilterExpression( QStringLiteral( "geometry_type(@geometry)='Polygon'" ) );
460 break;
463 break;
464 }
465
466 const int rows = mModel->rowCount();
467 mModel->insertStyle( rows, style );
468 viewStyles->selectionModel()->setCurrentIndex( mProxyModel->mapFromSource( mModel->index( rows, 0 ) ), QItemSelectionModel::ClearAndSelect );
469}
470
471void QgsVectorTileBasicLabelingWidget::editStyle()
472{
473 editStyleAtIndex( viewStyles->selectionModel()->currentIndex() );
474}
475
476void QgsVectorTileBasicLabelingWidget::editStyleAtIndex( const QModelIndex &proxyIndex )
477{
478 const QModelIndex index = mProxyModel->mapToSource( proxyIndex );
479 if ( index.row() < 0 || index.row() >= mLabeling->styles().count() )
480 return;
481
482 const QgsVectorTileBasicLabelingStyle style = mLabeling->style( index.row() );
483
484 QgsPalLayerSettings labelSettings = style.labelSettings();
485 if ( labelSettings.layerType == Qgis::GeometryType::Unknown )
486 labelSettings.layerType = style.geometryType();
487
489 context.setMapCanvas( mMapCanvas );
490 context.setMessageBar( mMessageBar );
491
492 if ( mMapCanvas )
493 {
494 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
495 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(),
496 mapSettings.destinationCrs(),
497 mapSettings.visibleExtent(),
498 mapSettings.outputSize(),
499 mapSettings.outputDpi() ) : mMapCanvas->scale();
500 const int zoom = mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 );
501 QList<QgsExpressionContextScope> scopes = context.additionalExpressionContextScopes();
503 tileScope.setVariable( "zoom_level", zoom, true );
504 tileScope.setVariable( "vector_tile_zoom", mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoom( mMapCanvas->scale() ) : QgsVectorTileUtils::scaleToZoom( mMapCanvas->scale() ), true );
505 scopes << tileScope;
506 context.setAdditionalExpressionContextScopes( scopes );
507 }
508
509 QgsVectorLayer *vectorLayer = nullptr; // TODO: have a temporary vector layer with sub-layer's fields?
510
512 if ( panel && panel->dockMode() )
513 {
514 QgsLabelingPanelWidget *widget = new QgsLabelingPanelWidget( labelSettings, vectorLayer, mMapCanvas, panel );
515 widget->setContext( context );
516 widget->setPanelTitle( style.styleName() );
517 connect( widget, &QgsPanelWidget::widgetChanged, this, &QgsVectorTileBasicLabelingWidget::updateLabelingFromWidget );
518 openPanel( widget );
519 }
520 else
521 {
522 QgsLabelSettingsDialog dlg( labelSettings, vectorLayer, mMapCanvas, this, labelSettings.layerType );
523 if ( dlg.exec() )
524 {
525 QgsVectorTileBasicLabelingStyle style = mLabeling->style( index.row() );
526 style.setLabelSettings( dlg.settings() );
527 mLabeling->setStyle( index.row(), style );
528 emit widgetChanged();
529 }
530 }
531}
532
533void QgsVectorTileBasicLabelingWidget::updateLabelingFromWidget()
534{
535 const int index = mProxyModel->mapToSource( viewStyles->selectionModel()->currentIndex() ).row();
536 if ( index < 0 )
537 return;
538
539 QgsVectorTileBasicLabelingStyle style = mLabeling->style( index );
540
541 QgsLabelingPanelWidget *widget = qobject_cast<QgsLabelingPanelWidget *>( sender() );
542 style.setLabelSettings( widget->labelSettings() );
543
544 mLabeling->setStyle( index, style );
545 emit widgetChanged();
546}
547
548void QgsVectorTileBasicLabelingWidget::removeStyle()
549{
550 const QModelIndexList sel = viewStyles->selectionModel()->selectedIndexes();
551
552 QList<int > res;
553 for ( const QModelIndex &proxyIndex : sel )
554 {
555 const QModelIndex sourceIndex = mProxyModel->mapToSource( proxyIndex );
556 if ( !res.contains( sourceIndex.row() ) )
557 res << sourceIndex.row();
558 }
559 std::sort( res.begin(), res.end() );
560
561 for ( int i = res.size() - 1; i >= 0; --i )
562 {
563 mModel->removeRow( res[ i ] );
564 }
565 // make sure that the selection is gone
566 viewStyles->selectionModel()->clear();
567}
568
569
570//
571
572
573QgsLabelingPanelWidget::QgsLabelingPanelWidget( const QgsPalLayerSettings &labelSettings, QgsVectorLayer *vectorLayer, QgsMapCanvas *mapCanvas, QWidget *parent )
574 : QgsPanelWidget( parent )
575{
576 mLabelingGui = new QgsLabelingGui( vectorLayer, mapCanvas, labelSettings, this, labelSettings.layerType );
577 mLabelingGui->setLabelMode( QgsLabelingGui::Labels );
578
579 mLabelingGui->layout()->setContentsMargins( 0, 0, 0, 0 );
580 QVBoxLayout *l = new QVBoxLayout;
581 l->addWidget( mLabelingGui );
582 setLayout( l );
583
584 connect( mLabelingGui, &QgsTextFormatWidget::widgetChanged, this, &QgsLabelingPanelWidget::widgetChanged );
585}
586
587void QgsLabelingPanelWidget::setDockMode( bool dockMode )
588{
589 QgsPanelWidget::setDockMode( dockMode );
590 mLabelingGui->setDockMode( dockMode );
591}
592
593void QgsLabelingPanelWidget::setContext( const QgsSymbolWidgetContext &context )
594{
595 mLabelingGui->setContext( context );
596}
597
598QgsPalLayerSettings QgsLabelingPanelWidget::labelSettings()
599{
600 return mLabelingGui->layerSettings();
601}
602
603
604QgsVectorTileBasicLabelingProxyModel::QgsVectorTileBasicLabelingProxyModel( QgsVectorTileBasicLabelingListModel *source, QObject *parent )
605 : QSortFilterProxyModel( parent )
606{
607 setSourceModel( source );
608 setDynamicSortFilter( true );
609}
610
611void QgsVectorTileBasicLabelingProxyModel::setCurrentZoom( int zoom )
612{
613 mCurrentZoom = zoom;
614 invalidateFilter();
615}
616
617void QgsVectorTileBasicLabelingProxyModel::setFilterVisible( bool enabled )
618{
619 mFilterVisible = enabled;
620 invalidateFilter();
621}
622
623void QgsVectorTileBasicLabelingProxyModel::setFilterString( const QString &string )
624{
625 mFilterString = string;
626 invalidateFilter();
627}
628
629bool QgsVectorTileBasicLabelingProxyModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const
630{
631 if ( mCurrentZoom >= 0 && mFilterVisible )
632 {
633 const int rowMinZoom = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::MinZoom ).toInt();
634 const int rowMaxZoom = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::MaxZoom ).toInt();
635
636 if ( rowMinZoom >= 0 && rowMinZoom > mCurrentZoom )
637 return false;
638
639 if ( rowMaxZoom >= 0 && rowMaxZoom < mCurrentZoom )
640 return false;
641 }
642
643 if ( !mFilterString.isEmpty() )
644 {
645 const QString name = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::Label ).toString();
646 const QString layer = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::Layer ).toString();
647 const QString filter = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::Filter ).toString();
648 if ( !name.contains( mFilterString, Qt::CaseInsensitive )
649 && !layer.contains( mFilterString, Qt::CaseInsensitive )
650 && !filter.contains( mFilterString, Qt::CaseInsensitive ) )
651 {
652 return false;
653 }
654 }
655
656 return true;
657}
658
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:5821
const double ICON_PADDING_FACTOR