QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 QMenu *createSaveMenu( int groupIndex, QMenu *parentMenu = nullptr );
51
52 void setMeshLayer( QgsMeshLayer *meshLayer );
53
54 signals:
55 void datasetGroupSaved( const QString &uri );
56
57 private:
58 QgsMeshLayer *mMeshLayer = nullptr;
59
60 void saveDatasetGroup( int datasetGroup, const QString &driver, const QString &fileSuffix );
61};
62
69class QgsMeshDatasetGroupTreeModel : public QAbstractItemModel
70{
71 Q_OBJECT
72 public:
81
82 explicit QgsMeshDatasetGroupTreeModel( QObject *parent = nullptr );
83
84 QVariant data( const QModelIndex &index, int role ) const override;
85 Qt::ItemFlags flags( const QModelIndex &index ) const override;
86 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
87 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
88 QModelIndex parent( const QModelIndex &index ) const override;
89 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
90 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
91
93 void syncToLayer( QgsMeshLayer *layer );
94
97
100
103
105 bool isEnabled( const QModelIndex &index ) const;
106
108 void resetDefault( QgsMeshLayer *meshLayer );
109
111 void setAllGroupsAsEnabled( bool isEnabled );
112
114 void removeItem( const QModelIndex &index );
115
117 void setPersistentDatasetGroup( const QModelIndex &index, const QString &uri );
118
119 private:
120 std::unique_ptr<QgsMeshDatasetGroupTreeItem> mRootItem;
121};
122
130{
131 Q_OBJECT
132 public:
133 QgsMeshAvailableDatasetGroupTreeModel( QObject *parent = nullptr );
134
135 QVariant data( const QModelIndex &index, int role ) const override;
136 bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
137 Qt::ItemFlags flags( const QModelIndex &index ) const override;
138 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
139 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
140
141 private:
142 QString textDisplayed( const QModelIndex &index ) const;
143 QColor backGroundColor( const QModelIndex &index ) const;
144};
145
151class QgsMeshDatasetGroupProxyModel : public QSortFilterProxyModel
152{
153 Q_OBJECT
154 public:
155 QgsMeshDatasetGroupProxyModel( QAbstractItemModel *sourceModel );
156
157 Qt::ItemFlags flags( const QModelIndex &index ) const override;
158 QVariant data( const QModelIndex &index, int role ) const override;
159
161 int activeScalarGroup() const;
162
164 void setActiveScalarGroup( int group );
165
167 int activeVectorGroup() const;
168
170 void setActiveVectorGroup( int group );
171
173 void syncToLayer( QgsMeshLayer *layer );
174
175 protected:
176 bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
177
178 private:
179 int mActiveScalarGroupIndex = -1;
180 int mActiveVectorGroupIndex = -1;
181};
182
189class QgsMeshDatasetGroupTreeItemDelegate : public QStyledItemDelegate
190{
191 Q_OBJECT
192 public:
193 QgsMeshDatasetGroupTreeItemDelegate( QObject *parent = nullptr );
194
195 void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
196
198 QRect iconRect( const QRect &rect, bool isVector ) const;
199
200 QSize sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
201
202 private:
203 const QPixmap mScalarSelectedPixmap;
204 const QPixmap mScalarDeselectedPixmap;
205 const QPixmap mVectorSelectedPixmap;
206 const QPixmap mVectorDeselectedPixmap;
207
208 QRect iconRect( const QRect &rect, int pos ) const;
209};
210
217class GUI_EXPORT QgsMeshDatasetGroupTreeView : public QTreeView
218{
219 Q_OBJECT
220 public:
221 QgsMeshDatasetGroupTreeView( QWidget *parent = nullptr );
222
223 void syncToLayer( QgsMeshLayer *layer );
224 void resetDefault( QgsMeshLayer *meshLayer );
225
227
228 signals:
229 void apply();
230
231 public slots:
232 void selectAllGroups();
233 void deselectAllGroups();
234
235 protected:
236 void contextMenuEvent( QContextMenuEvent *event ) override;
237
238 private slots:
239 void removeCurrentItem();
240 void onDatasetGroupSaved( const QString &uri );
241
242 private:
245
246 void selectAllItem( bool isChecked );
247 QMenu *createContextMenu();
248};
249
258class GUI_EXPORT QgsMeshActiveDatasetGroupTreeView : public QTreeView
259{
260 Q_OBJECT
261
262 public:
263 QgsMeshActiveDatasetGroupTreeView( QWidget *parent = nullptr );
264
266 void setLayer( QgsMeshLayer *layer );
267
269 int activeScalarGroup() const;
270
272 int activeVectorGroup() const;
273
275 void syncToLayer();
276
277 void mousePressEvent( QMouseEvent *event ) override;
278
279 public slots:
281 void setActiveScalarGroup( int group );
282
284 void setActiveVectorGroup( int group );
285
286 signals:
288 void activeScalarGroupChanged( int groupIndex );
289
291 void activeVectorGroupChanged( int groupIndex );
292
293 private:
294 void setActiveGroup();
295
298 QgsMeshLayer *mMeshLayer = nullptr; // not owned
299};
300
306class GUI_EXPORT QgsMeshDatasetGroupListModel : public QAbstractListModel
307{
308 Q_OBJECT
309 public:
310 explicit QgsMeshDatasetGroupListModel( QObject *parent );
311
313 void syncToLayer( QgsMeshLayer *layer );
314
315 int rowCount( const QModelIndex &parent ) const override;
316 QVariant data( const QModelIndex &index, int role ) const override;
317
318 void setDisplayProviderName( bool displayProviderName );
319
320 QStringList variableNames() const;
321
322 private:
323 QgsMeshDatasetGroupTreeItem *mRootItem = nullptr;
324 bool mDisplayProviderName = false;
325};
326
327#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