33 : QAbstractListModel( parent )
38int QgsVectorTileBasicLabelingListModel::rowCount(
const QModelIndex &parent )
const
40 if ( parent.isValid() )
43 return mLabeling->styles().count();
46int QgsVectorTileBasicLabelingListModel::columnCount(
const QModelIndex & )
const
51QVariant QgsVectorTileBasicLabelingListModel::data(
const QModelIndex &index,
int role )
const
53 if ( index.row() < 0 || index.row() >= mLabeling->styles().count() )
56 const QList<QgsVectorTileBasicLabelingStyle> styles = mLabeling->styles();
64 if ( index.column() == 0 )
66 else if ( index.column() == 1 )
67 return style.
layerName().isEmpty() ? tr(
"(all layers)" ) : style.layerName();
68 else if ( index.column() == 2 )
70 else if ( index.column() == 3 )
72 else if ( index.column() == 4 )
73 return style.
filterExpression().isEmpty() ? tr(
"(no filter)" ) : style.filterExpression();
80 if ( index.column() == 0 )
82 else if ( index.column() == 1 )
84 else if ( index.column() == 2 )
86 else if ( index.column() == 3 )
88 else if ( index.column() == 4 )
94 case Qt::CheckStateRole:
96 if ( index.column() != 0 )
98 return style.
isEnabled() ? Qt::Checked : Qt::Unchecked;
101 case Qt::DecorationRole:
103 if ( index.column() == 0 )
130QVariant QgsVectorTileBasicLabelingListModel::headerData(
int section, Qt::Orientation orientation,
int role )
const
132 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < 5 )
135 lst << tr(
"Label" ) << tr(
"Layer" ) << tr(
"Min. Zoom" ) << tr(
"Max. Zoom" ) << tr(
"Filter" );
142Qt::ItemFlags QgsVectorTileBasicLabelingListModel::flags(
const QModelIndex &index )
const
144 if ( !index.isValid() )
145 return Qt::ItemIsDropEnabled;
147 const Qt::ItemFlag checkable = ( index.column() == 0 ? Qt::ItemIsUserCheckable : Qt::NoItemFlags );
149 return Qt::ItemIsEnabled | Qt::ItemIsSelectable |
150 Qt::ItemIsEditable | checkable |
151 Qt::ItemIsDragEnabled;
154bool QgsVectorTileBasicLabelingListModel::setData(
const QModelIndex &index,
const QVariant &value,
int role )
156 if ( !index.isValid() )
161 if ( role == Qt::CheckStateRole )
163 style.
setEnabled( value.toInt() == Qt::Checked );
164 mLabeling->setStyle( index.row(), style );
165 emit dataChanged( index, index );
169 if ( role == Qt::EditRole )
171 if ( index.column() == 0 )
173 else if ( index.column() == 1 )
175 else if ( index.column() == 2 )
177 else if ( index.column() == 3 )
179 else if ( index.column() == 4 )
182 mLabeling->setStyle( index.row(), style );
183 emit dataChanged( index, index );
190bool QgsVectorTileBasicLabelingListModel::removeRows(
int row,
int count,
const QModelIndex &parent )
192 QList<QgsVectorTileBasicLabelingStyle> styles = mLabeling->styles();
194 if ( row < 0 || row >= styles.count() )
197 beginRemoveRows( parent, row, row + count - 1 );
199 for (
int i = 0; i < count; i++ )
201 if ( row < styles.count() )
203 styles.removeAt( row );
207 mLabeling->setStyles( styles );
215 beginInsertRows( QModelIndex(), row, row );
217 QList<QgsVectorTileBasicLabelingStyle> styles = mLabeling->styles();
218 styles.insert( row, style );
219 mLabeling->setStyles( styles );
224Qt::DropActions QgsVectorTileBasicLabelingListModel::supportedDropActions()
const
226 return Qt::MoveAction;
229QStringList QgsVectorTileBasicLabelingListModel::mimeTypes()
const
232 types << QStringLiteral(
"application/vnd.text.list" );
236QMimeData *QgsVectorTileBasicLabelingListModel::mimeData(
const QModelIndexList &indexes )
const
238 QMimeData *mimeData =
new QMimeData();
239 QByteArray encodedData;
241 QDataStream stream( &encodedData, QIODevice::WriteOnly );
243 const auto constIndexes = indexes;
244 for (
const QModelIndex &index : constIndexes )
247 if ( !index.isValid() || index.column() != 0 )
253 QDomElement rootElem = doc.createElement( QStringLiteral(
"vector_tile_basic_labeling_style_mime" ) );
255 doc.appendChild( rootElem );
257 stream << doc.toString( -1 );
260 mimeData->setData( QStringLiteral(
"application/vnd.text.list" ), encodedData );
264bool QgsVectorTileBasicLabelingListModel::dropMimeData(
const QMimeData *data,
265 Qt::DropAction action,
int row,
int column,
const QModelIndex &parent )
269 if ( action == Qt::IgnoreAction )
272 if ( !data->hasFormat( QStringLiteral(
"application/vnd.text.list" ) ) )
275 if ( parent.column() > 0 )
278 QByteArray encodedData = data->data( QStringLiteral(
"application/vnd.text.list" ) );
279 QDataStream stream( &encodedData, QIODevice::ReadOnly );
285 row = rowCount( parent );
288 while ( !stream.atEnd() )
294 if ( !doc.setContent( text ) )
296 const QDomElement rootElem = doc.documentElement();
297 if ( rootElem.tagName() != QLatin1String(
"vector_tile_basic_labeling_style_mime" ) )
303 insertStyle( row + rows, style );
315 , mMapCanvas( canvas )
316 , mMessageBar( messageBar )
320 layout()->setContentsMargins( 0, 0, 0, 0 );
322 mFilterLineEdit->setShowClearButton(
true );
323 mFilterLineEdit->setShowSearchIcon(
true );
324 mFilterLineEdit->setPlaceholderText( tr(
"Filter rules" ) );
326 QMenu *menuAddRule =
new QMenu( btnAddRule );
330 btnAddRule->setMenu( menuAddRule );
333 connect( btnEditRule, &QPushButton::clicked,
this, &QgsVectorTileBasicLabelingWidget::editStyle );
334 connect( btnRemoveRule, &QAbstractButton::clicked,
this, &QgsVectorTileBasicLabelingWidget::removeStyle );
338 connect( mLabelModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsVectorTileBasicLabelingWidget::labelModeChanged );
340 connect( viewStyles, &QAbstractItemView::doubleClicked,
this, &QgsVectorTileBasicLabelingWidget::editStyleAtIndex );
347 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( scale,
353 mLabelCurrentZoom->setText( tr(
"Current zoom: %1" ).arg( zoom ) );
355 mProxyModel->setCurrentZoom( zoom );
359 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(),
360 mapSettings.destinationCrs(),
361 mapSettings.visibleExtent(),
362 mapSettings.outputSize(),
363 mapSettings.outputDpi() ) : mMapCanvas->scale();
364 mLabelCurrentZoom->setText( tr(
"Current zoom: %1" ).arg( mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoomLevel( tileScale ) :
QgsVectorTileUtils::scaleToZoomLevel( tileScale, 0, 99 ) ) );
367 connect( mCheckVisibleOnly, &QCheckBox::toggled,
this, [ = ](
bool filter )
369 mProxyModel->setFilterVisible( filter );
372 connect( mFilterLineEdit, &QgsFilterLineEdit::textChanged,
this, [ = ](
const QString & text )
374 mProxyModel->setFilterString( text );
384 disconnect( mVTLayer );
400 mOptionsStackedWidget->setCurrentIndex( mLabelModeComboBox->currentIndex() );
402 mModel =
new QgsVectorTileBasicLabelingListModel( mLabeling.get(), viewStyles );
403 mProxyModel =
new QgsVectorTileBasicLabelingProxyModel( mModel, viewStyles );
404 viewStyles->setModel( mProxyModel );
409 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(),
415 mProxyModel->setCurrentZoom( zoom );
423QgsVectorTileBasicLabelingWidget::~QgsVectorTileBasicLabelingWidget() =
default;
425void QgsVectorTileBasicLabelingWidget::apply()
427 mVTLayer->setLabeling( mLabeling->clone() );
428 mVTLayer->setLabelsEnabled( mLabelModeComboBox->currentIndex() == 1 );
431void QgsVectorTileBasicLabelingWidget::labelModeChanged()
433 mOptionsStackedWidget->setCurrentIndex( mLabelModeComboBox->currentIndex() );
434 emit widgetChanged();
457 const int rows = mModel->rowCount();
458 mModel->insertStyle( rows, style );
459 viewStyles->selectionModel()->setCurrentIndex( mProxyModel->mapFromSource( mModel->index( rows, 0 ) ), QItemSelectionModel::ClearAndSelect );
462void QgsVectorTileBasicLabelingWidget::editStyle()
464 editStyleAtIndex( viewStyles->selectionModel()->currentIndex() );
467void QgsVectorTileBasicLabelingWidget::editStyleAtIndex(
const QModelIndex &proxyIndex )
469 const QModelIndex index = mProxyModel->mapToSource( proxyIndex );
470 if ( index.row() < 0 || index.row() >= mLabeling->styles().count() )
486 const double tileScale = mVTLayer ? mVTLayer->tileMatrixSet().calculateTileScaleForMap( mMapCanvas->scale(),
495 tileScope.
setVariable(
"vector_tile_zoom", mVTLayer ? mVTLayer->tileMatrixSet().scaleToZoom( mMapCanvas->scale() ) :
QgsVectorTileUtils::scaleToZoom( mMapCanvas->scale() ), true );
505 QgsLabelingPanelWidget *widget =
new QgsLabelingPanelWidget( labelSettings, vectorLayer, mMapCanvas, panel );
506 widget->setContext( context );
507 widget->setPanelTitle( style.
styleName() );
513 QgsLabelSettingsDialog dlg( labelSettings, vectorLayer, mMapCanvas,
this, labelSettings.
layerType );
518 mLabeling->setStyle( index.row(), style );
519 emit widgetChanged();
524void QgsVectorTileBasicLabelingWidget::updateLabelingFromWidget()
526 const int index = mProxyModel->mapToSource( viewStyles->selectionModel()->currentIndex() ).row();
532 QgsLabelingPanelWidget *widget = qobject_cast<QgsLabelingPanelWidget *>( sender() );
535 mLabeling->setStyle( index, style );
536 emit widgetChanged();
539void QgsVectorTileBasicLabelingWidget::removeStyle()
541 const QModelIndexList sel = viewStyles->selectionModel()->selectedIndexes();
544 for (
const QModelIndex &proxyIndex : sel )
546 const QModelIndex sourceIndex = mProxyModel->mapToSource( proxyIndex );
547 if ( !res.contains( sourceIndex.row() ) )
548 res << sourceIndex.row();
550 std::sort( res.begin(), res.end() );
552 for (
int i = res.size() - 1; i >= 0; --i )
554 mModel->removeRow( res[ i ] );
557 viewStyles->selectionModel()->clear();
567 mLabelingGui =
new QgsLabelingGui( vectorLayer, mapCanvas, labelSettings,
this, labelSettings.
layerType );
568 mLabelingGui->setLabelMode( QgsLabelingGui::Labels );
570 mLabelingGui->layout()->setContentsMargins( 0, 0, 0, 0 );
571 QVBoxLayout *l =
new QVBoxLayout;
572 l->addWidget( mLabelingGui );
578void QgsLabelingPanelWidget::setDockMode(
bool dockMode )
581 mLabelingGui->setDockMode( dockMode );
586 mLabelingGui->setContext( context );
591 return mLabelingGui->layerSettings();
595QgsVectorTileBasicLabelingProxyModel::QgsVectorTileBasicLabelingProxyModel( QgsVectorTileBasicLabelingListModel *source, QObject *parent )
596 : QSortFilterProxyModel( parent )
598 setSourceModel( source );
599 setDynamicSortFilter(
true );
602void QgsVectorTileBasicLabelingProxyModel::setCurrentZoom(
int zoom )
608void QgsVectorTileBasicLabelingProxyModel::setFilterVisible(
bool enabled )
610 mFilterVisible = enabled;
614void QgsVectorTileBasicLabelingProxyModel::setFilterString(
const QString &
string )
616 mFilterString = string;
620bool QgsVectorTileBasicLabelingProxyModel::filterAcceptsRow(
int source_row,
const QModelIndex &source_parent )
const
622 if ( mCurrentZoom >= 0 && mFilterVisible )
624 const int rowMinZoom = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::MinZoom ).toInt();
625 const int rowMaxZoom = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::MaxZoom ).toInt();
627 if ( rowMinZoom >= 0 && rowMinZoom > mCurrentZoom )
630 if ( rowMaxZoom >= 0 && rowMaxZoom < mCurrentZoom )
634 if ( !mFilterString.isEmpty() )
636 const QString name = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::Label ).toString();
637 const QString layer = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::Layer ).toString();
638 const QString filter = sourceModel()->data( sourceModel()->index( source_row, 0, source_parent ), QgsVectorTileBasicLabelingListModel::Filter ).toString();
639 if ( !name.contains( mFilterString, Qt::CaseInsensitive )
640 && !layer.contains( mFilterString, Qt::CaseInsensitive )
641 && !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