QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
Loading...
Searching...
No Matches
qgsmeshdatasetgrouptreeview.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmeshdatasetgrouptreeview.h
3 -----------------------------
4 begin : June 2018
5 copyright : (C) 2018 by Peter Petrik
6 email : zilolv at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSMESHDATASETGROUPTREE_H
17#define QGSMESHDATASETGROUPTREE_H
18
19#include <memory>
20
21#include "qgis_gui.h"
22#include "qgsmeshdataset.h"
23
24#include <QItemSelection>
25#include <QList>
26#include <QMap>
27#include <QMenu>
28#include <QObject>
29#include <QSortFilterProxyModel>
30#include <QStandardItemModel>
31#include <QStyledItemDelegate>
32#include <QTreeView>
33#include <QVector>
34
36
37class QgsMeshLayer;
38
44class QgsMeshDatasetGroupSaveMenu : public QObject
45{
46 Q_OBJECT
47 public:
48 QgsMeshDatasetGroupSaveMenu( QObject *parent = nullptr )
49 : QObject( parent )
50 {}
51 QMenu *createSaveMenu( int groupIndex, QMenu *parentMenu = nullptr );
52
53 void setMeshLayer( QgsMeshLayer *meshLayer );
54
55 signals:
56 void datasetGroupSaved( const QString &uri );
57
58 private:
59 QgsMeshLayer *mMeshLayer = nullptr;
60
61 void saveDatasetGroup( int datasetGroup, const QString &driver, const QString &fileSuffix );
62};
63
70class QgsMeshDatasetGroupTreeModel : public QAbstractItemModel
71{
72 Q_OBJECT
73 public:
82
83 explicit QgsMeshDatasetGroupTreeModel( QObject *parent = nullptr );
84
85 QVariant data( const QModelIndex &index, int role ) const override;
86 Qt::ItemFlags flags( const QModelIndex &index ) const override;
87 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
88 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
89 QModelIndex parent( const QModelIndex &index ) const override;
90 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
91 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
92
94 void syncToLayer( QgsMeshLayer *layer );
95
98
101
104
106 bool isEnabled( const QModelIndex &index ) const;
107
109 void resetDefault( QgsMeshLayer *meshLayer );
110
112 void setAllGroupsAsEnabled( bool isEnabled );
113
115 void removeItem( const QModelIndex &index );
116
118 void setPersistentDatasetGroup( const QModelIndex &index, const QString &uri );
119
120 private:
121 std::unique_ptr<QgsMeshDatasetGroupTreeItem> mRootItem;
122};
123
131{
132 Q_OBJECT
133 public:
134 QgsMeshAvailableDatasetGroupTreeModel( QObject *parent = nullptr );
135
136 QVariant data( const QModelIndex &index, int role ) const override;
137 bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
138 Qt::ItemFlags flags( const QModelIndex &index ) const override;
139 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
140 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
141
142 private:
143 QString textDisplayed( const QModelIndex &index ) const;
144 QColor backGroundColor( const QModelIndex &index ) const;
145};
146
152class QgsMeshDatasetGroupProxyModel : public QSortFilterProxyModel
153{
154 Q_OBJECT
155 public:
156 QgsMeshDatasetGroupProxyModel( QAbstractItemModel *sourceModel );
157
158 Qt::ItemFlags flags( const QModelIndex &index ) const override;
159 QVariant data( const QModelIndex &index, int role ) const override;
160
162 int activeScalarGroup() const;
163
165 void setActiveScalarGroup( int group );
166
168 int activeVectorGroup() const;
169
171 void setActiveVectorGroup( int group );
172
174 void syncToLayer( QgsMeshLayer *layer );
175
176 protected:
177 bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
178
179 private:
180 int mActiveScalarGroupIndex = -1;
181 int mActiveVectorGroupIndex = -1;
182};
183
190class QgsMeshDatasetGroupTreeItemDelegate : public QStyledItemDelegate
191{
192 Q_OBJECT
193 public:
194 QgsMeshDatasetGroupTreeItemDelegate( QObject *parent = nullptr );
195
196 void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
197
199 QRect iconRect( const QRect &rect, bool isVector ) const;
200
201 QSize sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
202
203 private:
204 const QPixmap mScalarSelectedPixmap;
205 const QPixmap mScalarDeselectedPixmap;
206 const QPixmap mVectorSelectedPixmap;
207 const QPixmap mVectorDeselectedPixmap;
208
209 QRect iconRect( const QRect &rect, int pos ) const;
210};
211
218class GUI_EXPORT QgsMeshDatasetGroupTreeView : public QTreeView
219{
220 Q_OBJECT
221 public:
222 QgsMeshDatasetGroupTreeView( QWidget *parent = nullptr );
223
224 void syncToLayer( QgsMeshLayer *layer );
225 void resetDefault( QgsMeshLayer *meshLayer );
226
228
229 signals:
230 void apply();
231
232 public slots:
233 void selectAllGroups();
234 void deselectAllGroups();
235
236 protected:
237 void contextMenuEvent( QContextMenuEvent *event ) override;
238
239 private slots:
240 void removeCurrentItem();
241 void onDatasetGroupSaved( const QString &uri );
242
243 private:
246
247 void selectAllItem( bool isChecked );
248 QMenu *createContextMenu();
249};
250
259class GUI_EXPORT QgsMeshActiveDatasetGroupTreeView : public QTreeView
260{
261 Q_OBJECT
262
263 public:
264 QgsMeshActiveDatasetGroupTreeView( QWidget *parent = nullptr );
265
267 void setLayer( QgsMeshLayer *layer );
268
270 int activeScalarGroup() const;
271
273 int activeVectorGroup() const;
274
276 void syncToLayer();
277
278 void mousePressEvent( QMouseEvent *event ) override;
279
280 public slots:
282 void setActiveScalarGroup( int group );
283
285 void setActiveVectorGroup( int group );
286
287 signals:
289 void activeScalarGroupChanged( int groupIndex );
290
292 void activeVectorGroupChanged( int groupIndex );
293
294 private:
295 void setActiveGroup();
296
299 QgsMeshLayer *mMeshLayer = nullptr; // not owned
300};
301
307class GUI_EXPORT QgsMeshDatasetGroupListModel : public QAbstractListModel
308{
309 Q_OBJECT
310 public:
311 explicit QgsMeshDatasetGroupListModel( QObject *parent );
312
314 void syncToLayer( QgsMeshLayer *layer );
315
316 int rowCount( const QModelIndex &parent ) const override;
317 QVariant data( const QModelIndex &index, int role ) const override;
318
319 void setDisplayProviderName( bool displayProviderName );
320
321 QStringList variableNames() const;
322
323 private:
324 QgsMeshDatasetGroupTreeItem *mRootItem = nullptr;
325 bool mDisplayProviderName = false;
326};
327
328#endif // QGSMESHDATASETGROUPTREE_H
void setActiveScalarGroup(int group)
Sets active group for contours.
QgsMeshActiveDatasetGroupTreeView(QWidget *parent=nullptr)
int activeScalarGroup() const
Returns index of active group for contours.
void setActiveVectorGroup(int group)
Sets active vector group.
void syncToLayer()
Synchronize widgets state with associated mesh layer.
void activeVectorGroupChanged(int groupIndex)
Selected dataset group for vectors changed. -1 for invalid group.
void mousePressEvent(QMouseEvent *event) override
void activeScalarGroupChanged(int groupIndex)
Selected dataset group for contours changed. -1 for invalid group.
int activeVectorGroup() const
Returns index of active group for vectors.
void setLayer(QgsMeshLayer *layer)
Associates mesh layer with the widget.
Item model for available mesh dataset groups.
Qt::ItemFlags flags(const QModelIndex &index) const override
bool setData(const QModelIndex &index, const QVariant &value, int role) override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
QVariant data(const QModelIndex &index, int role) const override
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
void setDisplayProviderName(bool displayProviderName)
QVariant data(const QModelIndex &index, int role) const override
int rowCount(const QModelIndex &parent) const override
void syncToLayer(QgsMeshLayer *layer)
Add groups to the model from mesh layer.
A proxy model for filtering mesh dataset groups.
void setActiveVectorGroup(int group)
Sets active vector group.
int activeScalarGroup() const
Returns index of active group for contours.
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
void setActiveScalarGroup(int group)
Sets active group for contours.
Qt::ItemFlags flags(const QModelIndex &index) const override
void syncToLayer(QgsMeshLayer *layer)
Add groups to the model from mesh layer.
int activeVectorGroup() const
Returns index of active group for vectors.
QgsMeshDatasetGroupProxyModel(QAbstractItemModel *sourceModel)
QVariant data(const QModelIndex &index, int role) const override
Responsible for creating menus for saving mesh dataset groups.
QMenu * createSaveMenu(int groupIndex, QMenu *parentMenu=nullptr)
void datasetGroupSaved(const QString &uri)
void setMeshLayer(QgsMeshLayer *meshLayer)
QgsMeshDatasetGroupSaveMenu(QObject *parent=nullptr)
Delegate to display tree item with a contours and vector selector.
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
QRect iconRect(const QRect &rect, bool isVector) const
Icon rectangle for given item rectangle.
Tree item for display of the mesh dataset groups.
QgsMeshDatasetGroupTreeItem * datasetGroupTreeItem(int groupIndex)
Returns the dataset group tree item with index, keeps ownership.
QVariant data(const QModelIndex &index, int role) const override
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
void syncToLayer(QgsMeshLayer *layer)
Synchronizes groups to the model from mesh layer.
bool isEnabled(const QModelIndex &index) const
Returns whether the dataset groups related to the QModelIndex is set as enabled.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
void resetDefault(QgsMeshLayer *meshLayer)
Resets all groups with default state from the mesh layer.
QgsMeshDatasetGroupTreeItem * datasetGroupTreeRootItem()
Returns the dataset group root tree item, keeps ownership.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
QgsMeshDatasetGroupTreeModel(QObject *parent=nullptr)
void removeItem(const QModelIndex &index)
Removes an item from the tree.
QModelIndex parent(const QModelIndex &index) const override
void setAllGroupsAsEnabled(bool isEnabled)
Sets all groups as enabled.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
void setPersistentDatasetGroup(const QModelIndex &index, const QString &uri)
Sets the dataset group as persistent with specified uri and for specified index.
Qt::ItemFlags flags(const QModelIndex &index) const override
QgsMeshDatasetGroupTreeView(QWidget *parent=nullptr)
QgsMeshDatasetGroupTreeItem * datasetGroupTreeRootItem()
void contextMenuEvent(QContextMenuEvent *event) override
void resetDefault(QgsMeshLayer *meshLayer)
Represents a mesh layer supporting display of data on structured or unstructured meshes.
#define SIP_NO_FILE