QGIS API Documentation 3.99.0-Master (752b475928d)
Loading...
Searching...
No Matches
qgselevationprofilelayertreeview.h
Go to the documentation of this file.
1/***************************************************************************
2 qgselevationprofilelayertreeview.h
3 ---------------
4 begin : April 2022
5 copyright : (C) 2022 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSELEVATIONPROFILELAYERTREEVIEW_H
19#define QGSELEVATIONPROFILELAYERTREEVIEW_H
20
21#include "qgsconfig.h"
22
23#include "qgis_gui.h"
24#include "qgslayertreemodel.h"
25#include "qgslayertreeview.h"
26
27#include <QSortFilterProxyModel>
28#include <QTreeView>
29
30#define SIP_NO_FILE
31
32
33class QgsLayerTree;
36class QgsMapLayer;
37
38
48{
49 Q_OBJECT
50
51 public:
56 explicit QgsElevationProfileLayerTreeModel( QgsLayerTree *rootNode, QObject *parent = nullptr );
57
58 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
59 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
60 Qt::ItemFlags flags( const QModelIndex &index ) const override;
61 bool canDropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) const override;
62 bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
63 QMimeData *mimeData( const QModelIndexList &indexes ) const override;
64
70 void setAllowModifications( bool allow );
71
77 bool allowModifications() const { return mAllowModifications; }
78
79 signals:
80
86 void addLayers( const QList<QgsMapLayer *> &layers );
87
88 private:
89#ifdef SIP_RUN
91#endif
92
93 bool mAllowModifications = true;
94};
95
104class GUI_EXPORT QgsElevationProfileLayerTreeProxyModel : public QSortFilterProxyModel
105{
106 Q_OBJECT
107
108 public:
112 explicit QgsElevationProfileLayerTreeProxyModel( QgsElevationProfileLayerTreeModel *model, QObject *parent = nullptr );
113
114 protected:
115 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
116
117 private:
118 QgsElevationProfileLayerTreeModel *mModel = nullptr;
119};
120
130{
131 Q_OBJECT
132
133 public:
135
140 explicit QgsElevationProfileLayerTreeView( QgsLayerTree *rootNode, QWidget *parent = nullptr );
141
147 void setLayerTree( QgsLayerTree *rootNode );
148
152 void populateInitialSources( QgsProject *project );
153
160
161 public slots:
162
174 void addNodeForRegisteredSource( const QString &sourceId, const QString &sourceName );
175
183 void removeNodeForUnregisteredSource( const QString &sourceId );
184
190 void populateMissingLayers( QgsProject *project );
191
192 signals:
193
199 void addLayers( const QList<QgsMapLayer *> &layers );
200
201 protected:
202 void resizeEvent( QResizeEvent *event ) override;
203
204 private:
205 QgsElevationProfileLayerTreeModel *mModel = nullptr;
206 QgsElevationProfileLayerTreeProxyModel *mProxyModel = nullptr;
207 QgsLayerTree *mLayerTree = nullptr;
208};
209
210
211#endif // QGSELEVATIONPROFILELAYERTREEVIEW_H
A layer tree model subclass for elevation profiles.
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 allowModifications() const
Returns true if modifications like renaming, reordering nodes are supported.
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
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.
void setLayerTree(QgsLayerTree *rootNode)
Sets a new layer tree root node to use for the view.
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
QMimeData * mimeData(const QModelIndexList &indexes) const override
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
QgsLayerTreeViewBase(QWidget *parent=nullptr)
Constructor for QgsLayerTreeViewBase.
Namespace with helper functions for layer tree operations.
Base class for all map layer types.
Definition qgsmaplayer.h:80
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:109