35#include <QContextMenuEvent>
40#include "moc_qgselevationprofilelayertreeview.cpp"
57 case Qt::DecorationRole:
68 std::unique_ptr<QgsSymbol> symbol;
69 switch ( layer->type() )
76 switch ( elevationProperties->
type() )
84 symbol.reset( markerSymbol->clone() );
92 symbol.reset( fillSymbol->clone() );
100 symbol.reset( lineSymbol->clone() );
114 if ( renderer->symbol()->type() == symbol->type() )
117 symbol.reset( renderer->symbol()->clone() );
122 symbol->setColor( renderer->symbol()->color() );
123 symbol->setOpacity( renderer->symbol()->opacity() );
140 symbol.reset( lineSymbol->clone() );
147 symbol.reset( fillSymbol->clone() );
164 symbol.reset( lineSymbol->clone() );
171 symbol.reset( fillSymbol->clone() );
186 symbol.reset( lineSymbol->clone() );
193 symbol.reset( fillSymbol->clone() );
218 case Qt::ToolTipRole:
226 QString title = !layer->metadata().title().isEmpty() ? layer->metadata().title() : !layer->serverProperties()->title().isEmpty() ? layer->serverProperties()->title()
227 : !layer->serverProperties()->shortName().isEmpty() ? layer->serverProperties()->shortName()
230 title =
"<b>" + title.toHtmlEscaped() +
"</b>";
235 const QString elevationPropertiesSummary = layer->elevationProperties() ? layer->elevationProperties()->htmlSummary() : QString();
236 if ( !elevationPropertiesSummary.isEmpty() )
237 parts << elevationPropertiesSummary;
239 return parts.join( QLatin1String(
"<br/>" ) );
253 if ( !mAllowModifications )
258 if ( role == Qt::CheckStateRole )
260 const bool checked =
static_cast<Qt::CheckState
>( value.toInt() ) == Qt::Checked;
263 layer->setCustomProperty( QStringLiteral(
"_include_in_elevation_profiles" ), checked );
280 f.setFlag( Qt::ItemFlag::ItemIsEditable,
false );
287 if ( !mAllowModifications )
290 if ( action == Qt::IgnoreAction )
293 if ( !
data->hasFormat( QStringLiteral(
"application/qgis.layertreemodeldata" ) ) )
297 if ( action == Qt::MoveAction )
299 const QString source =
data->data( QStringLiteral(
"application/qgis.layertree.source" ) );
300 if ( source.isEmpty() || source != QStringLiteral(
":0x%1" ).arg(
reinterpret_cast<quintptr
>(
this ), 2 * QT_POINTER_SIZE, 16, QLatin1Char(
'0' ) ) )
306 return QgsLayerTreeModel::canDropMimeData(
data, action, row, column,
parent );
311 if ( !mAllowModifications )
314 if ( action == Qt::IgnoreAction )
317 if ( !
data->hasFormat( QStringLiteral(
"application/qgis.layertreemodeldata" ) ) )
321 const QString source =
data->data( QStringLiteral(
"application/qgis.layertree.source" ) );
322 if ( source.isEmpty() || source != QStringLiteral(
":0x%1" ).arg(
reinterpret_cast<quintptr
>(
this ), 2 * QT_POINTER_SIZE, 16, QLatin1Char(
'0' ) ) )
324 if ( action == Qt::CopyAction )
326 QByteArray encodedLayerTreeData =
data->data( QStringLiteral(
"application/qgis.layertreemodeldata" ) );
328 QDomDocument layerTreeDoc;
329 if ( !layerTreeDoc.setContent( QString::fromUtf8( encodedLayerTreeData ) ) )
332 QDomElement rootLayerTreeElem = layerTreeDoc.documentElement();
333 if ( rootLayerTreeElem.tagName() != QLatin1String(
"layer_tree_model_data" ) )
336 QList<QgsMapLayer *> layersToAdd;
338 QDomElement elem = rootLayerTreeElem.firstChildElement();
339 while ( !elem.isNull() )
344 if (
QgsMapLayer *layer = qobject_cast<QgsLayerTreeLayer *>( node.get() )->layer() )
346 layersToAdd << layer;
349 elem = elem.nextSiblingElement();
352 if ( !layersToAdd.empty() )
368 if ( !mAllowModifications )
374 mimeData->setData( QStringLiteral(
"application/qgis.restrictlayertreemodelsubclass" ),
"QgsElevationProfileLayerTreeModel" );
384 mAllowModifications = allow;
393 : QSortFilterProxyModel( parent )
396 setSourceModel( mModel );
397 setDynamicSortFilter(
true );
402 const QModelIndex sourceIndex = mModel->index( sourceRow, 0, sourceParent );
405 switch ( node->nodeType() )
411 if (
QgsMapLayer *layer = layerTreeLayer->layer() )
414 if ( !layer->elevationProperties() || !layer->elevationProperties()->hasElevation() )
433 if (
QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( layerTreeLayer->layer() ) )
435 if ( !qgis::down_cast<QgsVectorLayerElevationProperties *>( layer->elevationProperties() )->respectLayerSymbology() )
468 mLayerTree = rootNode;
475 setModel( mProxyModel );
490 std::reverse( sortedLayers.begin(), sortedLayers.end() );
491 for (
QgsMapLayer *layer : std::as_const( sortedLayers ) )
494 if ( mLayerTree->findLayer( layer ) )
499 if ( layer->customProperty( QStringLiteral(
"_include_in_elevation_profiles" ) ).isValid() )
501 node->
setItemVisibilityChecked( layer->customProperty( QStringLiteral(
"_include_in_elevation_profiles" ) ).toBool() );
505 node->
setItemVisibilityChecked( layer->elevationProperties() && layer->elevationProperties()->showByDefaultInElevationProfilePlots() );
523 auto customNode = std::make_unique< QgsLayerTreeCustomNode >( sourceId, sourceName.isEmpty() ? sourceId : sourceName );
524 customNode->setItemVisibilityChecked(
true );
530 QgsDebugError( QString(
"The custom node with id '%1' could not be added!" ).arg( sourceId ) );
535 mLayerTree->removeCustomNode( sourceId );
545 header()->setMinimumSectionSize( viewport()->width() );
546 QTreeView::resizeEvent( event );
@ Group
Composite group layer. Added in QGIS 3.24.
@ Plugin
Plugin based layer.
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
@ Mesh
Mesh layer. Added in QGIS 3.2.
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
@ ContinuousSurface
The features should be treated as representing values on a continuous surface (eg contour lines).
@ IndividualFeatures
Treat each feature as an individual object (eg buildings).
@ Line
The elevation surface will be rendered using a line symbol.
@ FillBelow
The elevation surface will be rendered using a fill symbol below the surface level.
@ FillAbove
The elevation surface will be rendered using a fill symbol above the surface level.
Interface for classes which can generate elevation profiles.
static QgsProfileSourceRegistry * profileSourceRegistry()
Returns registry of available profile source implementations.
A layer tree model subclass for elevation profiles.
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
void addLayers(const QList< QgsMapLayer * > &layers)
Emitted when layers should be added to the profile, e.g.
QgsElevationProfileLayerTreeModel(QgsLayerTree *rootNode, QObject *parent=nullptr)
Construct a new tree model with given layer tree (root node must not be nullptr).
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
QMimeData * mimeData(const QModelIndexList &indexes) const override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
void setAllowModifications(bool allow)
Sets whether modifications like renaming, reordering nodes are supported.
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override
A proxy model for elevation profiles.
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
QgsElevationProfileLayerTreeProxyModel(QgsElevationProfileLayerTreeModel *model, QObject *parent=nullptr)
Constructor for QgsElevationProfileLayerTreeProxyModel.
void populateInitialSources(QgsProject *project)
Initially populates the tree view using layers from a project, as well as sources from the source reg...
QgsElevationProfileLayerTreeProxyModel * proxyModel()
Returns the view's proxy model.
QgsElevationProfileLayerTreeView(QgsLayerTree *rootNode, QWidget *parent=nullptr)
Construct a new tree view with given layer tree (root node must not be nullptr).
void removeNodeForUnregisteredSource(const QString &sourceId)
Removes a custom node from the layer tree corresponding to an unregistered profile source.
void addNodeForRegisteredSource(const QString &sourceId, const QString &sourceName)
Adds a custom node in the layer tree corresponding to a registered profile source.
void populateMissingLayers(QgsProject *project)
Adds any layers from a project which currently aren't within the profile's layer tree.
void resizeEvent(QResizeEvent *event) override
void addLayers(const QList< QgsMapLayer * > &layers)
Emitted when layers should be added to the profile, e.g.
static const QString CUSTOM_NODE_ELEVATION_PROFILE_SOURCE
void setLayerTree(QgsLayerTree *rootNode)
Sets a new layer tree root node to use for the view.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Layer tree custom node serves as a node for objects that are not layers nor groups.
Layer tree node points to a map layer.
An abstract interface for legend items returned from QgsMapLayerLegend implementation.
QgsLayerTreeLayer * layerNode() const
Returns pointer to the parent layer node.
Flags flags() const
Returns OR-ed combination of model flags.
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
QgsLayerTreeModel(QgsLayerTree *rootNode, QObject *parent=nullptr)
Construct a new tree model with given layer tree (root node must not be nullptr).
QModelIndex parent(const QModelIndex &child) const override
void setFlag(Flag f, bool on=true)
Enable or disable a model flag.
QgsRenderContext * createTemporaryRenderContext() const
Returns a temporary render context.
QgsLayerTreeNode * index2node(const QModelIndex &index) const
Returns layer tree node for given index.
QMimeData * mimeData(const QModelIndexList &indexes) const override
static int scaleIconSize(int standardSize)
Scales an layer tree model icon size to compensate for display pixel density, making the icon size hi...
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
@ AllowNodeChangeVisibility
Allow user to set node visibility with a checkbox.
@ ShowLegendAsTree
For legends that support it, will show them in a tree instead of a list (needs also ShowLegend)....
@ AllowNodeReorder
Allow reordering with drag'n'drop.
@ AllowNodeRename
Allow renaming of groups and layers.
@ AllowLegendChangeState
Allow check boxes for legend nodes (if supported by layer's legend).
Base class for nodes in a layer tree.
@ NodeCustom
Leaf node pointing to a custom object.
@ NodeGroup
Container of other groups and layers.
@ NodeLayer
Leaf node pointing to a layer.
static QgsLayerTreeNode * readXml(QDomElement &element, const QgsReadWriteContext &context)
Read layer tree from XML.
NodeType nodeType() const
Find out about type of the node. It is usually shorter to use convenience functions from QgsLayerTree...
void setItemVisibilityChecked(bool checked)
Check or uncheck a node (independently of its ancestors or children).
void setLayerTreeModel(QgsLayerTreeModel *model)
Associates a layer tree model with the view.
QgsLayerTreeViewBase(QWidget *parent=nullptr)
Constructor for QgsLayerTreeViewBase.
Namespace with helper functions for layer tree operations.
static QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer.
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
static bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
A line symbol type, for rendering LineString and MultiLineString geometries.
static QList< QgsMapLayer * > sortLayersByType(const QList< QgsMapLayer * > &layers, const QList< Qgis::LayerType > &order)
Sorts a list of map layers by their layer type, respecting the order of types specified.
Base class for all map layer types.
A marker symbol type, for rendering Point and MultiPoint geometries.
Mesh layer specific subclass of QgsMapLayerElevationProperties.
Qgis::ProfileSurfaceSymbology profileSymbology() const
Returns the symbology option used to render the mesh profile in elevation profile plots.
QgsLineSymbol * profileLineSymbol() const
Returns the line symbol used to render the mesh profile in elevation profile plots.
QgsFillSymbol * profileFillSymbol() const
Returns the fill symbol used to render the mesh profile in elevation profile plots.
QList< QgsAbstractProfileSource * > profileSources() const
Returns a list of registered profile sources.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
static QgsProject * instance()
Returns the QgsProject singleton instance.
QVector< T > layers() const
Returns a list of registered map layers with a specified layer type.
Raster layer specific subclass of QgsMapLayerElevationProperties.
QgsLineSymbol * profileLineSymbol() const
Returns the line symbol used to render the raster profile in elevation profile plots.
Qgis::ProfileSurfaceSymbology profileSymbology() const
Returns the symbology option used to render the raster profile in elevation profile plots.
QgsFillSymbol * profileFillSymbol() const
Returns the fill symbol used to render the raster profile in elevation profile plots.
A feature renderer which renders all features with the same symbol.
static QPixmap symbolPreviewPixmap(const QgsSymbol *symbol, QSize size, int padding=0, QgsRenderContext *customContext=nullptr, bool selected=false, const QgsExpressionContext *expressionContext=nullptr, const QgsLegendPatchShape *shape=nullptr, const QgsScreenProperties &screen=QgsScreenProperties())
Returns a pixmap preview for a color ramp.
Vector layer specific subclass of QgsMapLayerElevationProperties.
QgsFillSymbol * profileFillSymbol() const
Returns the symbol used to render polygons for the layer in elevation profile plots.
Qgis::VectorProfileType type() const
Returns the type of profile the layer represents.
QgsLineSymbol * profileLineSymbol() const
Returns the symbol used to render lines for the layer in elevation profile plots.
QgsMarkerSymbol * profileMarkerSymbol() const
Returns the symbol used to render points for the layer in elevation profile plots.
Qgis::ProfileSurfaceSymbology profileSymbology() const
Returns the symbology option used to render the vector profile in elevation profile plots.
bool respectLayerSymbology() const
Returns true if layer symbology should be respected when rendering elevation profile plots.
bool extrusionEnabled() const
Returns true if extrusion is enabled.
Represents a vector layer which manages a vector based dataset.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.
#define QgsDebugError(str)