QGIS API Documentation 3.43.0-Master (b60ef06885e)
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 "qgis_gui.h"
20
21#include <QObject>
22#include <QTreeView>
23#include <QMap>
24#include <QMenu>
25#include <QVector>
26#include <QItemSelection>
27#include <QStandardItemModel>
28#include <QStyledItemDelegate>
29#include <QList>
30#include <QSortFilterProxyModel>
31#include <memory>
32#include "qgsmeshdataset.h"
33
35
36class QgsMeshLayer;
37
43class QgsMeshDatasetGroupSaveMenu : public QObject
44{
45 Q_OBJECT
46 public:
47 QgsMeshDatasetGroupSaveMenu( QObject *parent = nullptr )
48 : QObject( parent ) {}
49 QMenu *createSaveMenu( int groupIndex, QMenu *parentMenu = nullptr );
50
51 void setMeshLayer( QgsMeshLayer *meshLayer );
52
53 signals:
54 void datasetGroupSaved( const QString &uri );
55
56 private:
57 QgsMeshLayer *mMeshLayer = nullptr;
58
59 void saveDatasetGroup( int datasetGroup, const QString &driver, const QString &fileSuffix );
60};
61
68class QgsMeshDatasetGroupTreeModel : public QAbstractItemModel
69{
70 Q_OBJECT
71 public:
80
81 explicit QgsMeshDatasetGroupTreeModel( QObject *parent = nullptr );
82
83 QVariant data( const QModelIndex &index, int role ) const override;
84 Qt::ItemFlags flags( const QModelIndex &index ) const override;
85 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
86 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
87 QModelIndex parent( const QModelIndex &index ) const override;
88 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
89 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
90
92 void syncToLayer( QgsMeshLayer *layer );
93
96
99
102
104 bool isEnabled( const QModelIndex &index ) const;
105
107 void resetDefault( QgsMeshLayer *meshLayer );
108
110 void setAllGroupsAsEnabled( bool isEnabled );
111
113 void removeItem( const QModelIndex &index );
114
116 void setPersistentDatasetGroup( const QModelIndex &index, const QString &uri );
117
118 private:
119 std::unique_ptr<QgsMeshDatasetGroupTreeItem> mRootItem;
120};
121
129{
130 Q_OBJECT
131 public:
132 QgsMeshAvailableDatasetGroupTreeModel( QObject *parent = nullptr );
133
134 QVariant data( const QModelIndex &index, int role ) const override;
135 bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
136 Qt::ItemFlags flags( const QModelIndex &index ) const override;
137 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
138 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
139
140 private:
141 QString textDisplayed( const QModelIndex &index ) const;
142 QColor backGroundColor( const QModelIndex &index ) const;
143};
144
150class QgsMeshDatasetGroupProxyModel : public QSortFilterProxyModel
151{
152 Q_OBJECT
153 public:
154 QgsMeshDatasetGroupProxyModel( QAbstractItemModel *sourceModel );
155
156 Qt::ItemFlags flags( const QModelIndex &index ) const override;
157 QVariant data( const QModelIndex &index, int role ) const override;
158
160 int activeScalarGroup() const;
161
163 void setActiveScalarGroup( int group );
164
166 int activeVectorGroup() const;
167
169 void setActiveVectorGroup( int group );
170
172 void syncToLayer( QgsMeshLayer *layer );
173
174 protected:
175 bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
176
177 private:
178 int mActiveScalarGroupIndex = -1;
179 int mActiveVectorGroupIndex = -1;
180};
181
188class QgsMeshDatasetGroupTreeItemDelegate : public QStyledItemDelegate
189{
190 Q_OBJECT
191 public:
192 QgsMeshDatasetGroupTreeItemDelegate( QObject *parent = nullptr );
193
194 void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
195
197 QRect iconRect( const QRect &rect, bool isVector ) const;
198
199 QSize sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
200
201 private:
202 const QPixmap mScalarSelectedPixmap;
203 const QPixmap mScalarDeselectedPixmap;
204 const QPixmap mVectorSelectedPixmap;
205 const QPixmap mVectorDeselectedPixmap;
206
207 QRect iconRect( const QRect &rect, int pos ) const;
208};
209
216class GUI_EXPORT QgsMeshDatasetGroupTreeView : public QTreeView
217{
218 Q_OBJECT
219 public:
220 QgsMeshDatasetGroupTreeView( QWidget *parent = nullptr );
221
222 void syncToLayer( QgsMeshLayer *layer );
223 void resetDefault( QgsMeshLayer *meshLayer );
224
225 QgsMeshDatasetGroupTreeItem *datasetGroupTreeRootItem();
226
227 signals:
228 void apply();
229
230 public slots:
231 void selectAllGroups();
232 void deselectAllGroups();
233
234 protected:
235 void contextMenuEvent( QContextMenuEvent *event ) override;
236
237 private slots:
238 void removeCurrentItem();
239 void onDatasetGroupSaved( const QString &uri );
240
241 private:
244
245 void selectAllItem( bool isChecked );
246 QMenu *createContextMenu();
247};
248
257class GUI_EXPORT QgsMeshActiveDatasetGroupTreeView : public QTreeView
258{
259 Q_OBJECT
260
261 public:
262 QgsMeshActiveDatasetGroupTreeView( QWidget *parent = nullptr );
263
265 void setLayer( QgsMeshLayer *layer );
266
268 int activeScalarGroup() const;
269
271 int activeVectorGroup() const;
272
274 void syncToLayer();
275
276 void mousePressEvent( QMouseEvent *event ) override;
277
278 public slots:
280 void setActiveScalarGroup( int group );
281
283 void setActiveVectorGroup( int group );
284
285 signals:
287 void activeScalarGroupChanged( int groupIndex );
288
290 void activeVectorGroupChanged( int groupIndex );
291
292 private:
293 void setActiveGroup();
294
297 QgsMeshLayer *mMeshLayer = nullptr; // not owned
298};
299
305class GUI_EXPORT QgsMeshDatasetGroupListModel : public QAbstractListModel
306{
307 Q_OBJECT
308 public:
309 explicit QgsMeshDatasetGroupListModel( QObject *parent );
310
312 void syncToLayer( QgsMeshLayer *layer );
313
314 int rowCount( const QModelIndex &parent ) const override;
315 QVariant data( const QModelIndex &index, int role ) const override;
316
317 void setDisplayProviderName( bool displayProviderName );
318
319 QStringList variableNames() const;
320
321 private:
322 QgsMeshDatasetGroupTreeItem *mRootItem = nullptr;
323 bool mDisplayProviderName = false;
324};
325
326#endif // QGSMESHDATASETGROUPTREE_H
Tree widget for display of the mesh dataset groups.
void activeVectorGroupChanged(int groupIndex)
Selected dataset group for vectors changed. -1 for invalid group.
void activeScalarGroupChanged(int groupIndex)
Selected dataset group for contours changed. -1 for invalid group.
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
A model representing mesh dataset groups.
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.
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.
Item model for QgsMeshDatasetGroupTreeItem.
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
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
Tree widget for display of the mesh dataset groups.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
#define SIP_NO_FILE