34 : QAbstractListModel( parent )
39int QgsVectorTileBasicLabelingListModel::rowCount(
const QModelIndex &parent )
const
41 if ( parent.isValid() )
44 return mLabeling->styles().count();
47int QgsVectorTileBasicLabelingListModel::columnCount(
const QModelIndex & )
const
52QVariant QgsVectorTileBasicLabelingListModel::data(
const QModelIndex &index,
int role )
const
54 if ( index.row() < 0 || index.row() >= mLabeling->styles().count() )
57 const QList<QgsVectorTileBasicLabelingStyle> styles = mLabeling->styles();
65 if ( index.column() == 0 )
67 else if ( index.column() == 1 )
68 return style.
layerName().isEmpty() ? tr(
"(all layers)" ) : style.layerName();
69 else if ( index.column() == 2 )
71 else if ( index.column() == 3 )
73 else if ( index.column() == 4 )
74 return style.
filterExpression().isEmpty() ? tr(
"(no filter)" ) : style.filterExpression();
81 if ( index.column() == 0 )
83 else if ( index.column() == 1 )
85 else if ( index.column() == 2 )
87 else if ( index.column() == 3 )
89 else if ( index.column() == 4 )
95 case Qt::CheckStateRole:
97 if ( index.column() != 0 )
99 return style.
isEnabled() ? Qt::Checked : Qt::Unchecked;
102 case Qt::DecorationRole:
104 if ( index.column() == 0 )
131QVariant QgsVectorTileBasicLabelingListModel::headerData(
int section, Qt::Orientation orientation,
int role )
const
133 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < 5 )
136 lst << tr(
"Label" ) << tr(
"Layer" ) << tr(
"Min. Zoom" ) << tr(
"Max. Zoom" ) << tr(
"Filter" );
143Qt::ItemFlags QgsVectorTileBasicLabelingListModel::flags(
const QModelIndex &index )
const
145 if ( !index.isValid() )
146 return Qt::ItemIsDropEnabled;
148 const Qt::ItemFlag checkable = ( index.column() == 0 ? Qt::ItemIsUserCheckable : Qt::NoItemFlags );
150 return Qt::ItemIsEnabled | Qt::ItemIsSelectable |
151 Qt::ItemIsEditable | checkable |
152 Qt::ItemIsDragEnabled;
155bool QgsVectorTileBasicLabelingListModel::setData(
const QModelIndex &index,
const QVariant &value,
int role )
157 if ( !index.isValid() )
162 if ( role == Qt::CheckStateRole )
164 style.
setEnabled( value.toInt() == Qt::Checked );
165 mLabeling->setStyle( index.row(), style );
166 emit dataChanged( index, index );
170 if ( role == Qt::EditRole )
172 if ( index.column() == 0 )
174 else if ( index.column() == 1 )
176 else if ( index.column() == 2 )
178 else if ( index.column() == 3 )
180 else if ( index.column() == 4 )
183 mLabeling->setStyle( index.row(), style );
184 emit dataChanged( index, index );
191bool QgsVectorTileBasicLabelingListModel::removeRows(
int row,
int count,
const QModelIndex &parent )
193 QList<QgsVectorTileBasicLabelingStyle> styles = mLabeling->styles();
195 if ( row < 0 || row >= styles.count() )
198 beginRemoveRows( parent, row, row + count - 1 );
200 for (
int i = 0; i < count; i++ )
202 if ( row < styles.count() )
204 styles.removeAt( row );
208 mLabeling->setStyles( styles );
216 beginInsertRows( QModelIndex(), row, row );
218 QList<QgsVectorTileBasicLabelingStyle> styles = mLabeling->styles();
219 styles.insert( row, style );
220 mLabeling->setStyles( styles );
225Qt::DropActions QgsVectorTileBasicLabelingListModel::supportedDropActions()
const
227 return Qt::MoveAction;
230QStringList QgsVectorTileBasicLabelingListModel::mimeTypes()
const
233 types << QStringLiteral(
"application/vnd.text.list" );
237QMimeData *QgsVectorTileBasicLabelingListModel::mimeData(
const QModelIndexList &indexes )
const
239 QMimeData *mimeData =
new QMimeData();
240 QByteArray encodedData;
242 QDataStream stream( &encodedData, QIODevice::WriteOnly );
244 const auto constIndexes = indexes;
245 for (
const QModelIndex &index : constIndexes )
248 if ( !index.isValid() || index.column() != 0 )
254 QDomElement rootElem = doc.createElement( QStringLiteral(
"vector_tile_basic_labeling_style_mime" ) );
256 doc.appendChild( rootElem );
258 stream << doc.toString( -1 );
261 mimeData->setData( QStringLiteral(
"application/vnd.text.list" ), encodedData );
265bool QgsVectorTileBasicLabelingListModel::dropMimeData(
const QMimeData *data,
266 Qt::DropAction action,
int row,
int column,
const QModelIndex &parent )
270 if ( action == Qt::IgnoreAction )
273 if ( !data->hasFormat( QStringLiteral(
"application/vnd.text.list" ) ) )
276 if ( parent.column() > 0 )
279 QByteArray encodedData = data->data( QStringLiteral(
"application/vnd.text.list" ) );
280 QDataStream stream( &encodedData, QIODevice::ReadOnly );
286 row = rowCount( parent );
289 while ( !stream.atEnd() )
295 if ( !doc.setContent( text ) )
297 const QDomElement rootElem = doc.documentElement();
298 if ( rootElem.tagName() != QLatin1String(
"vector_tile_basic_labeling_style_mime" ) )
304 insertStyle( row + rows, style );
316 , mMapCanvas( canvas )
317 , mMessageBar( messageBar )
321 layout()->setContentsMargins( 0, 0, 0, 0 );
323 mFilterLineEdit->setShowClearButton(
true );
324 mFilterLineEdit->setShowSearchIcon(
true );
325 mFilterLineEdit->setPlaceholderText( tr(
"Filter rules" ) );
327 QMenu *menuAddRule =
new QMenu( btnAddRule );
331 btnAddRule->setMenu( menuAddRule );
334 connect( btnEditRule, &QPushButton::clicked,
this, &QgsVectorTileBasicLabelingWidget::editStyle );
335 connect( btnRemoveRule, &QAbstractButton::clicked,
this, &QgsVectorTileBasicLabelingWidget::removeStyle );
339 connect( mLabelModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsVectorTileBasicLabelingWidget::labelModeChanged );
341 connect( viewStyles, &QAbstractItemView::doubleClicked,
this, &QgsVectorTileBasicLabelingWidget::editStyleAtIndex );
348 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( scale,
354 mLabelCurrentZoom->setText( tr(
"Current zoom: %1" ).arg( zoom ) );
356 mProxyModel->setCurrentZoom( zoom );
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 ) ) );
368 connect( mCheckVisibleOnly, &QCheckBox::toggled,
this, [ = ](
bool filter )
370 mProxyModel->setFilterVisible( filter );
373 connect( mFilterLineEdit, &QgsFilterLineEdit::textChanged,
this, [ = ](
const QString & text )
375 mProxyModel->setFilterString( text );
385 disconnect( mVTLayer );
401 mOptionsStackedWidget->setCurrentIndex( mLabelModeComboBox->currentIndex() );
403 mModel =
new QgsVectorTileBasicLabelingListModel( mLabeling.get(), viewStyles );
404 mProxyModel =
new QgsVectorTileBasicLabelingProxyModel( mModel, viewStyles );
405 viewStyles->setModel( mProxyModel );
410 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(),
416 mProxyModel->setCurrentZoom( zoom );
424QgsVectorTileBasicLabelingWidget::~QgsVectorTileBasicLabelingWidget() =
default;
426void QgsVectorTileBasicLabelingWidget::apply()
428 mVTLayer->setLabeling( mLabeling->clone() );
429 mVTLayer->setLabelsEnabled( mLabelModeComboBox->currentIndex() == 1 );
432void QgsVectorTileBasicLabelingWidget::labelModeChanged()
434 mOptionsStackedWidget->setCurrentIndex( mLabelModeComboBox->currentIndex() );
435 emit widgetChanged();
458 const int rows = mModel->rowCount();
459 mModel->insertStyle( rows, style );
460 viewStyles->selectionModel()->setCurrentIndex( mProxyModel->mapFromSource( mModel->index( rows, 0 ) ), QItemSelectionModel::ClearAndSelect );
463void QgsVectorTileBasicLabelingWidget::editStyle()
465 editStyleAtIndex( viewStyles->selectionModel()->currentIndex() );
468void QgsVectorTileBasicLabelingWidget::editStyleAtIndex(
const QModelIndex &proxyIndex )
470 const QModelIndex index = mProxyModel->mapToSource( proxyIndex );
471 if ( index.row() < 0 || index.row() >= mLabeling->styles().count() )
487 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(),
496 tileScope.
setVariable(
"vector_tile_zoom", mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoom( mMapCanvas->scale() ) :
QgsVectorTileUtils::scaleToZoom( mMapCanvas->scale() ), true );
506 QgsLabelingPanelWidget *widget =
new QgsLabelingPanelWidget( labelSettings, vectorLayer, mMapCanvas, panel );
507 widget->setContext( context );
508 widget->setPanelTitle( style.
styleName() );
514 QgsLabelSettingsDialog dlg( labelSettings, vectorLayer, mMapCanvas,
this, labelSettings.
layerType );
519 mLabeling->setStyle( index.row(), style );
520 emit widgetChanged();
525void QgsVectorTileBasicLabelingWidget::updateLabelingFromWidget()
527 const int index = mProxyModel->mapToSource( viewStyles->selectionModel()->currentIndex() ).row();
533 QgsLabelingPanelWidget *widget = qobject_cast<QgsLabelingPanelWidget *>( sender() );
536 mLabeling->setStyle( index, style );
537 emit widgetChanged();
540void QgsVectorTileBasicLabelingWidget::removeStyle()
542 const QModelIndexList sel = viewStyles->selectionModel()->selectedIndexes();
545 for (
const QModelIndex &proxyIndex : sel )
547 const QModelIndex sourceIndex = mProxyModel->mapToSource( proxyIndex );
548 if ( !res.contains( sourceIndex.row() ) )
549 res << sourceIndex.row();
551 std::sort( res.begin(), res.end() );
553 for (
int i = res.size() - 1; i >= 0; --i )
555 mModel->removeRow( res[ i ] );
558 viewStyles->selectionModel()->clear();
568 mLabelingGui =
new QgsLabelingGui( vectorLayer, mapCanvas, labelSettings,
this, labelSettings.
layerType );
569 mLabelingGui->setLabelMode( QgsLabelingGui::Labels );
571 mLabelingGui->layout()->setContentsMargins( 0, 0, 0, 0 );
572 QVBoxLayout *l =
new QVBoxLayout;
573 l->addWidget( mLabelingGui );
579void QgsLabelingPanelWidget::setDockMode(
bool dockMode )
582 mLabelingGui->setDockMode( dockMode );
587 mLabelingGui->setContext( context );
592 return mLabelingGui->layerSettings();
596QgsVectorTileBasicLabelingProxyModel::QgsVectorTileBasicLabelingProxyModel( QgsVectorTileBasicLabelingListModel *source, QObject *parent )
597 : QSortFilterProxyModel( parent )
599 setSourceModel( source );
600 setDynamicSortFilter(
true );
603void QgsVectorTileBasicLabelingProxyModel::setCurrentZoom(
int zoom )
609void QgsVectorTileBasicLabelingProxyModel::setFilterVisible(
bool enabled )
611 mFilterVisible = enabled;
615void QgsVectorTileBasicLabelingProxyModel::setFilterString(
const QString &
string )
617 mFilterString = string;
621bool QgsVectorTileBasicLabelingProxyModel::filterAcceptsRow(
int source_row,
const QModelIndex &source_parent )
const
623 if ( mCurrentZoom >= 0 && mFilterVisible )
625 const int rowMinZoom = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::MinZoom ).toInt();
626 const int rowMaxZoom = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::MaxZoom ).toInt();
628 if ( rowMinZoom >= 0 && rowMinZoom > mCurrentZoom )
631 if ( rowMaxZoom >= 0 && rowMaxZoom < mCurrentZoom )
635 if ( !mFilterString.isEmpty() )
637 const QString name = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::Label ).toString();
638 const QString layer = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::Layer ).toString();
639 const QString filter = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::Filter ).toString();
640 if ( !name.contains( mFilterString, Qt::CaseInsensitive )
641 && !layer.contains( mFilterString, Qt::CaseInsensitive )
642 && !filter.contains( mFilterString, Qt::CaseInsensitive ) )
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
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)
Emitted when the scale of the map changes.
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.
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.
virtual QString type() const =0
Unique type string of the labeling configuration implementation.
virtual QgsVectorTileLabeling * clone() const =0SIP_FACTORY
Returns a new copy of the object.
Implements a map layer that is dedicated to rendering of vector tiles.
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
QgsVectorTileLabeling * labeling() const
Returns currently assigned labeling.
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.
const double ICON_PADDING_FACTOR