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