QGIS API Documentation 3.41.0-Master (45a0abf3bec)
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 }
129 return QVariant();
130}
131
132QVariant QgsVectorTileBasicLabelingListModel::headerData( int section, Qt::Orientation orientation, int role ) const
133{
134 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < 5 )
135 {
136 QStringList lst;
137 lst << tr( "Label" ) << tr( "Layer" ) << tr( "Min. Zoom" ) << tr( "Max. Zoom" ) << tr( "Filter" );
138 return lst[section];
139 }
140
141 return QVariant();
142}
143
144Qt::ItemFlags QgsVectorTileBasicLabelingListModel::flags( const QModelIndex &index ) const
145{
146 if ( !index.isValid() )
147 return Qt::ItemIsDropEnabled;
148
149 const Qt::ItemFlag checkable = ( index.column() == 0 ? Qt::ItemIsUserCheckable : Qt::NoItemFlags );
150
151 return Qt::ItemIsEnabled | Qt::ItemIsSelectable |
152 Qt::ItemIsEditable | checkable |
153 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,
267 Qt::DropAction action, int row, int column, const QModelIndex &parent )
268{
269 Q_UNUSED( column )
270
271 if ( action == Qt::IgnoreAction )
272 return true;
273
274 if ( !data->hasFormat( QStringLiteral( "application/vnd.text.list" ) ) )
275 return false;
276
277 if ( parent.column() > 0 )
278 return false;
279
280 QByteArray encodedData = data->data( QStringLiteral( "application/vnd.text.list" ) );
281 QDataStream stream( &encodedData, QIODevice::ReadOnly );
282 int rows = 0;
283
284 if ( row == -1 )
285 {
286 // the item was dropped at a parent - we may decide where to put the items - let's append them
287 row = rowCount( parent );
288 }
289
290 while ( !stream.atEnd() )
291 {
292 QString text;
293 stream >> text;
294
295 QDomDocument doc;
296 if ( !doc.setContent( text ) )
297 continue;
298 const QDomElement rootElem = doc.documentElement();
299 if ( rootElem.tagName() != QLatin1String( "vector_tile_basic_labeling_style_mime" ) )
300 continue;
301
303 style.readXml( rootElem, QgsReadWriteContext() );
304
305 insertStyle( row + rows, style );
306 ++rows;
307 }
308 return true;
309}
310
311
312//
313
314
315QgsVectorTileBasicLabelingWidget::QgsVectorTileBasicLabelingWidget( QgsVectorTileLayer *layer, QgsMapCanvas *canvas, QgsMessageBar *messageBar, QWidget *parent )
316 : QgsMapLayerConfigWidget( layer, canvas, parent )
317 , mMapCanvas( canvas )
318 , mMessageBar( messageBar )
319{
320
321 setupUi( this );
322 layout()->setContentsMargins( 0, 0, 0, 0 );
323
324 mFilterLineEdit->setShowClearButton( true );
325 mFilterLineEdit->setShowSearchIcon( true );
326 mFilterLineEdit->setPlaceholderText( tr( "Filter rules" ) );
327
328 QMenu *menuAddRule = new QMenu( btnAddRule );
329 menuAddRule->addAction( tr( "Marker" ), this, [this] { addStyle( Qgis::GeometryType::Point ); } );
330 menuAddRule->addAction( tr( "Line" ), this, [this] { addStyle( Qgis::GeometryType::Line ); } );
331 menuAddRule->addAction( tr( "Fill" ), this, [this] { addStyle( Qgis::GeometryType::Polygon ); } );
332 btnAddRule->setMenu( menuAddRule );
333
334 //connect( btnAddRule, &QPushButton::clicked, this, &QgsVectorTileBasicLabelingWidget::addStyle );
335 connect( btnEditRule, &QPushButton::clicked, this, &QgsVectorTileBasicLabelingWidget::editStyle );
336 connect( btnRemoveRule, &QAbstractButton::clicked, this, &QgsVectorTileBasicLabelingWidget::removeStyle );
337
338 mLabelModeComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "labelingNone.svg" ) ), tr( "No Labels" ) );
339 mLabelModeComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "labelingRuleBased.svg" ) ), tr( "Rule-based Labeling" ) );
340 connect( mLabelModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsVectorTileBasicLabelingWidget::labelModeChanged );
341
342 connect( viewStyles, &QAbstractItemView::doubleClicked, this, &QgsVectorTileBasicLabelingWidget::editStyleAtIndex );
343
344 if ( mMapCanvas )
345 {
346 connect( mMapCanvas, &QgsMapCanvas::scaleChanged, this, [ = ]( double scale )
347 {
348 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
349 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( scale,
350 mapSettings.destinationCrs(),
351 mapSettings.visibleExtent(),
352 mapSettings.outputSize(),
353 mapSettings.outputDpi() ) : scale;
354 const int zoom = mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 );
355 mLabelCurrentZoom->setText( tr( "Current zoom: %1" ).arg( zoom ) );
356 if ( mProxyModel )
357 mProxyModel->setCurrentZoom( zoom );
358 } );
359
360 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
361 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(),
362 mapSettings.destinationCrs(),
363 mapSettings.visibleExtent(),
364 mapSettings.outputSize(),
365 mapSettings.outputDpi() ) : mMapCanvas->scale();
366 mLabelCurrentZoom->setText( tr( "Current zoom: %1" ).arg( mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 ) ) );
367 }
368
369 connect( mCheckVisibleOnly, &QCheckBox::toggled, this, [ = ]( bool filter )
370 {
371 mProxyModel->setFilterVisible( filter );
372 } );
373
374 connect( mFilterLineEdit, &QgsFilterLineEdit::textChanged, this, [ = ]( const QString & text )
375 {
376 mProxyModel->setFilterString( text );
377 } );
378
379 setLayer( layer );
380}
381
382void QgsVectorTileBasicLabelingWidget::resyncToCurrentLayer()
383{
384 setLayer( mVTLayer );
385}
386
387void QgsVectorTileBasicLabelingWidget::setLayer( QgsVectorTileLayer *layer )
388{
389 if ( mVTLayer && mVTLayer != layer )
390 {
391 disconnect( mVTLayer, &QgsMapLayer::styleChanged, this, &QgsVectorTileBasicLabelingWidget::resyncToCurrentLayer );
392 }
393 else if ( layer )
394 {
395 connect( layer, &QgsMapLayer::styleChanged, this, &QgsVectorTileBasicLabelingWidget::resyncToCurrentLayer );
396 }
397
398 mVTLayer = layer;
399
400 if ( mVTLayer && mVTLayer->labeling() && mVTLayer->labeling()->type() == QLatin1String( "basic" ) )
401 {
402 mLabeling.reset( static_cast<QgsVectorTileBasicLabeling *>( mVTLayer->labeling()->clone() ) );
403 whileBlocking( mLabelModeComboBox )->setCurrentIndex( mVTLayer->labelsEnabled() ? 1 : 0 );
404 }
405 else
406 {
407 mLabeling.reset( new QgsVectorTileBasicLabeling() );
408 whileBlocking( mLabelModeComboBox )->setCurrentIndex( 1 );
409 }
410 mOptionsStackedWidget->setCurrentIndex( mLabelModeComboBox->currentIndex() );
411
412 mModel = new QgsVectorTileBasicLabelingListModel( mLabeling.get(), viewStyles );
413 mProxyModel = new QgsVectorTileBasicLabelingProxyModel( mModel, viewStyles );
414 viewStyles->setModel( mProxyModel );
415
416 if ( mMapCanvas )
417 {
418 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
419 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(),
420 mapSettings.destinationCrs(),
421 mapSettings.visibleExtent(),
422 mapSettings.outputSize(),
423 mapSettings.outputDpi() ) : mMapCanvas->scale();
424 const int zoom = mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 );
425 mProxyModel->setCurrentZoom( zoom );
426 }
427
428 connect( mModel, &QAbstractItemModel::dataChanged, this, &QgsPanelWidget::widgetChanged );
429 connect( mModel, &QAbstractItemModel::rowsInserted, this, &QgsPanelWidget::widgetChanged );
430 connect( mModel, &QAbstractItemModel::rowsRemoved, this, &QgsPanelWidget::widgetChanged );
431}
432
433QgsVectorTileBasicLabelingWidget::~QgsVectorTileBasicLabelingWidget() = default;
434
435void QgsVectorTileBasicLabelingWidget::apply()
436{
437 mVTLayer->setLabeling( mLabeling->clone() );
438 mVTLayer->setLabelsEnabled( mLabelModeComboBox->currentIndex() == 1 );
439}
440
441void QgsVectorTileBasicLabelingWidget::labelModeChanged()
442{
443 mOptionsStackedWidget->setCurrentIndex( mLabelModeComboBox->currentIndex() );
444 emit widgetChanged();
445}
446
447void QgsVectorTileBasicLabelingWidget::addStyle( Qgis::GeometryType geomType )
448{
450 style.setGeometryType( geomType );
451 switch ( geomType )
452 {
454 style.setFilterExpression( QStringLiteral( "geometry_type(@geometry)='Point'" ) );
455 break;
457 style.setFilterExpression( QStringLiteral( "geometry_type(@geometry)='Line'" ) );
458 break;
460 style.setFilterExpression( QStringLiteral( "geometry_type(@geometry)='Polygon'" ) );
461 break;
464 break;
465 }
466
467 const int rows = mModel->rowCount();
468 mModel->insertStyle( rows, style );
469 viewStyles->selectionModel()->setCurrentIndex( mProxyModel->mapFromSource( mModel->index( rows, 0 ) ), QItemSelectionModel::ClearAndSelect );
470}
471
472void QgsVectorTileBasicLabelingWidget::editStyle()
473{
474 editStyleAtIndex( viewStyles->selectionModel()->currentIndex() );
475}
476
477void QgsVectorTileBasicLabelingWidget::editStyleAtIndex( const QModelIndex &proxyIndex )
478{
479 const QModelIndex index = mProxyModel->mapToSource( proxyIndex );
480 if ( index.row() < 0 || index.row() >= mLabeling->styles().count() )
481 return;
482
483 const QgsVectorTileBasicLabelingStyle style = mLabeling->style( index.row() );
484
485 QgsPalLayerSettings labelSettings = style.labelSettings();
486 if ( labelSettings.layerType == Qgis::GeometryType::Unknown )
487 labelSettings.layerType = style.geometryType();
488
490 context.setMapCanvas( mMapCanvas );
491 context.setMessageBar( mMessageBar );
492
493 if ( mMapCanvas )
494 {
495 const QgsMapSettings &mapSettings = mMapCanvas->mapSettings();
496 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(),
497 mapSettings.destinationCrs(),
498 mapSettings.visibleExtent(),
499 mapSettings.outputSize(),
500 mapSettings.outputDpi() ) : mMapCanvas->scale();
501 const int zoom = mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) : QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 );
502 QList<QgsExpressionContextScope> scopes = context.additionalExpressionContextScopes();
504 tileScope.setVariable( "zoom_level", zoom, true );
505 tileScope.setVariable( "vector_tile_zoom", mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoom( mMapCanvas->scale() ) : QgsVectorTileUtils::scaleToZoom( mMapCanvas->scale() ), true );
506 scopes << tileScope;
507 context.setAdditionalExpressionContextScopes( scopes );
508 }
509
510 QgsVectorLayer *vectorLayer = nullptr; // TODO: have a temporary vector layer with sub-layer's fields?
511
513 if ( panel && panel->dockMode() )
514 {
515 QgsLabelingPanelWidget *widget = new QgsLabelingPanelWidget( labelSettings, vectorLayer, mMapCanvas, panel );
516 widget->setContext( context );
517 widget->setPanelTitle( style.styleName() );
518 connect( widget, &QgsPanelWidget::widgetChanged, this, &QgsVectorTileBasicLabelingWidget::updateLabelingFromWidget );
519 openPanel( widget );
520 }
521 else
522 {
523 QgsLabelSettingsDialog dlg( labelSettings, vectorLayer, mMapCanvas, this, labelSettings.layerType );
524 if ( dlg.exec() )
525 {
526 QgsVectorTileBasicLabelingStyle style = mLabeling->style( index.row() );
527 style.setLabelSettings( dlg.settings() );
528 mLabeling->setStyle( index.row(), style );
529 emit widgetChanged();
530 }
531 }
532}
533
534void QgsVectorTileBasicLabelingWidget::updateLabelingFromWidget()
535{
536 const int index = mProxyModel->mapToSource( viewStyles->selectionModel()->currentIndex() ).row();
537 if ( index < 0 )
538 return;
539
540 QgsVectorTileBasicLabelingStyle style = mLabeling->style( index );
541
542 QgsLabelingPanelWidget *widget = qobject_cast<QgsLabelingPanelWidget *>( sender() );
543 style.setLabelSettings( widget->labelSettings() );
544
545 mLabeling->setStyle( index, style );
546 emit widgetChanged();
547}
548
549void QgsVectorTileBasicLabelingWidget::removeStyle()
550{
551 const QModelIndexList sel = viewStyles->selectionModel()->selectedIndexes();
552
553 QList<int > res;
554 for ( const QModelIndex &proxyIndex : sel )
555 {
556 const QModelIndex sourceIndex = mProxyModel->mapToSource( proxyIndex );
557 if ( !res.contains( sourceIndex.row() ) )
558 res << sourceIndex.row();
559 }
560 std::sort( res.begin(), res.end() );
561
562 for ( int i = res.size() - 1; i >= 0; --i )
563 {
564 mModel->removeRow( res[ i ] );
565 }
566 // make sure that the selection is gone
567 viewStyles->selectionModel()->clear();
568}
569
570
571//
572
573
574QgsLabelingPanelWidget::QgsLabelingPanelWidget( const QgsPalLayerSettings &labelSettings, QgsVectorLayer *vectorLayer, QgsMapCanvas *mapCanvas, QWidget *parent )
575 : QgsPanelWidget( parent )
576{
577 mLabelingGui = new QgsLabelingGui( vectorLayer, mapCanvas, labelSettings, this, labelSettings.layerType );
578 mLabelingGui->setLabelMode( QgsLabelingGui::Labels );
579
580 mLabelingGui->layout()->setContentsMargins( 0, 0, 0, 0 );
581 QVBoxLayout *l = new QVBoxLayout;
582 l->addWidget( mLabelingGui );
583 setLayout( l );
584
585 connect( mLabelingGui, &QgsTextFormatWidget::widgetChanged, this, &QgsLabelingPanelWidget::widgetChanged );
586}
587
588void QgsLabelingPanelWidget::setDockMode( bool dockMode )
589{
590 QgsPanelWidget::setDockMode( dockMode );
591 mLabelingGui->setDockMode( dockMode );
592}
593
594void QgsLabelingPanelWidget::setContext( const QgsSymbolWidgetContext &context )
595{
596 mLabelingGui->setContext( context );
597}
598
599QgsPalLayerSettings QgsLabelingPanelWidget::labelSettings()
600{
601 return mLabelingGui->layerSettings();
602}
603
604
605QgsVectorTileBasicLabelingProxyModel::QgsVectorTileBasicLabelingProxyModel( QgsVectorTileBasicLabelingListModel *source, QObject *parent )
606 : QSortFilterProxyModel( parent )
607{
608 setSourceModel( source );
609 setDynamicSortFilter( true );
610}
611
612void QgsVectorTileBasicLabelingProxyModel::setCurrentZoom( int zoom )
613{
614 mCurrentZoom = zoom;
615 invalidateFilter();
616}
617
618void QgsVectorTileBasicLabelingProxyModel::setFilterVisible( bool enabled )
619{
620 mFilterVisible = enabled;
621 invalidateFilter();
622}
623
624void QgsVectorTileBasicLabelingProxyModel::setFilterString( const QString &string )
625{
626 mFilterString = string;
627 invalidateFilter();
628}
629
630bool QgsVectorTileBasicLabelingProxyModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const
631{
632 if ( mCurrentZoom >= 0 && mFilterVisible )
633 {
634 const int rowMinZoom = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::MinZoom ).toInt();
635 const int rowMaxZoom = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::MaxZoom ).toInt();
636
637 if ( rowMinZoom >= 0 && rowMinZoom > mCurrentZoom )
638 return false;
639
640 if ( rowMaxZoom >= 0 && rowMaxZoom < mCurrentZoom )
641 return false;
642 }
643
644 if ( !mFilterString.isEmpty() )
645 {
646 const QString name = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::Label ).toString();
647 const QString layer = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::Layer ).toString();
648 const QString filter = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::Filter ).toString();
649 if ( !name.contains( mFilterString, Qt::CaseInsensitive )
650 && !layer.contains( mFilterString, Qt::CaseInsensitive )
651 && !filter.contains( mFilterString, Qt::CaseInsensitive ) )
652 {
653 return false;
654 }
655 }
656
657 return true;
658}
659
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:5862
const double ICON_PADDING_FACTOR