QGIS API Documentation 3.99.0-Master (a5475b57e34)
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
32class QgsLayerTree;
35class QgsMapLayer;
36
37
47{
48 Q_OBJECT
49
50 public:
55 explicit QgsElevationProfileLayerTreeModel( QgsLayerTree *rootNode, QObject *parent = nullptr );
56
57 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
58 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
59 Qt::ItemFlags flags( const QModelIndex &index ) const override;
60 bool canDropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) const override;
61 bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
62 QMimeData *mimeData( const QModelIndexList &indexes ) const override;
63
69 void setAllowModifications( bool allow );
70
76 bool allowModifications() const { return mAllowModifications; }
77
78 signals:
79
85 void addLayers( const QList<QgsMapLayer *> &layers );
86
87 private:
88#ifdef SIP_RUN
90#endif
91
92 bool mAllowModifications = true;
93};
94
103class GUI_EXPORT QgsElevationProfileLayerTreeProxyModel : public QSortFilterProxyModel
104{
105 Q_OBJECT
106
107 public:
111 explicit QgsElevationProfileLayerTreeProxyModel( QgsElevationProfileLayerTreeModel *model, QObject *parent = nullptr );
112
113 protected:
114 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
115
116 private:
117 QgsElevationProfileLayerTreeModel *mModel = nullptr;
118};
119
129{
130 Q_OBJECT
131
132 public:
134
139 explicit QgsElevationProfileLayerTreeView( QgsLayerTree *rootNode, QWidget *parent = nullptr );
140
146 void setLayerTree( QgsLayerTree *rootNode );
147
151 void populateInitialSources( QgsProject *project );
152
159
160 public slots:
161
173 void addNodeForRegisteredSource( const QString &sourceId, const QString &sourceName );
174
182 void removeNodeForUnregisteredSource( const QString &sourceId );
183
189 void populateMissingLayers( QgsProject *project );
190
191 signals:
192
198 void addLayers( const QList<QgsMapLayer *> &layers );
199
200 protected:
201 void resizeEvent( QResizeEvent *event ) override;
202
203 private:
204 QgsElevationProfileLayerTreeModel *mModel = nullptr;
205 QgsElevationProfileLayerTreeProxyModel *mProxyModel = nullptr;
206 QgsLayerTree *mLayerTree = nullptr;
207};
208
209
210#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:83
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:113