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