QGIS API Documentation 3.41.0-Master (af5edcb665c)
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 "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
42class QgsMeshDatasetGroupSaveMenu : public QObject
43{
44 Q_OBJECT
45 public:
46 QgsMeshDatasetGroupSaveMenu( QObject *parent = nullptr )
47 : QObject( parent ) {}
48 QMenu *createSaveMenu( int groupIndex, QMenu *parentMenu = nullptr );
49
50 void setMeshLayer( QgsMeshLayer *meshLayer );
51
52 signals:
53 void datasetGroupSaved( const QString &uri );
54
55 private:
56 QgsMeshLayer *mMeshLayer = nullptr;
57
58 void saveDatasetGroup( int datasetGroup, const QString &driver, const QString &fileSuffix );
59};
60
67class QgsMeshDatasetGroupTreeModel : public QAbstractItemModel
68{
69 Q_OBJECT
70 public:
79
80 explicit QgsMeshDatasetGroupTreeModel( QObject *parent = nullptr );
81
82 QVariant data( const QModelIndex &index, int role ) const override;
83 Qt::ItemFlags flags( const QModelIndex &index ) const override;
84 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
85 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
86 QModelIndex parent( const QModelIndex &index ) const override;
87 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
88 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
89
91 void syncToLayer( QgsMeshLayer *layer );
92
95
98
101
103 bool isEnabled( const QModelIndex &index ) const;
104
106 void resetDefault( QgsMeshLayer *meshLayer );
107
109 void setAllGroupsAsEnabled( bool isEnabled );
110
112 void removeItem( const QModelIndex &index );
113
115 void setPersistentDatasetGroup( const QModelIndex &index, const QString &uri );
116
117 private:
118 std::unique_ptr<QgsMeshDatasetGroupTreeItem> mRootItem;
119};
120
126{
127 Q_OBJECT
128 public:
129 QgsMeshAvailableDatasetGroupTreeModel( QObject *parent = nullptr );
130
131 QVariant data( const QModelIndex &index, int role ) const override;
132 bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
133 Qt::ItemFlags flags( const QModelIndex &index ) const override;
134 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
135 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
136
137 private:
138 QString textDisplayed( const QModelIndex &index ) const;
139 QColor backGroundColor( const QModelIndex &index ) const;
140};
141
146class QgsMeshDatasetGroupProxyModel : public QSortFilterProxyModel
147{
148 Q_OBJECT
149 public:
150 QgsMeshDatasetGroupProxyModel( QAbstractItemModel *sourceModel );
151
152 Qt::ItemFlags flags( const QModelIndex &index ) const override;
153 QVariant data( const QModelIndex &index, int role ) const override;
154
156 int activeScalarGroup() const;
157
159 void setActiveScalarGroup( int group );
160
162 int activeVectorGroup() const;
163
165 void setActiveVectorGroup( int group );
166
168 void syncToLayer( QgsMeshLayer *layer );
169
170 protected:
171 bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
172
173 private:
174 int mActiveScalarGroupIndex = -1;
175 int mActiveVectorGroupIndex = -1;
176};
177
184class QgsMeshDatasetGroupTreeItemDelegate : public QStyledItemDelegate
185{
186 Q_OBJECT
187 public:
188 QgsMeshDatasetGroupTreeItemDelegate( QObject *parent = nullptr );
189
190 void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
191
193 QRect iconRect( const QRect &rect, bool isVector ) const;
194
195 QSize sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
196
197 private:
198 const QPixmap mScalarSelectedPixmap;
199 const QPixmap mScalarDeselectedPixmap;
200 const QPixmap mVectorSelectedPixmap;
201 const QPixmap mVectorDeselectedPixmap;
202
203 QRect iconRect( const QRect &rect, int pos ) const;
204};
205
212class GUI_EXPORT QgsMeshDatasetGroupTreeView : public QTreeView
213{
214 Q_OBJECT
215 public:
216 QgsMeshDatasetGroupTreeView( QWidget *parent = nullptr );
217
218 void syncToLayer( QgsMeshLayer *layer );
219 void resetDefault( QgsMeshLayer *meshLayer );
220
221 QgsMeshDatasetGroupTreeItem *datasetGroupTreeRootItem();
222
223 signals:
224 void apply();
225
226 public slots:
227 void selectAllGroups();
228 void deselectAllGroups();
229
230 protected:
231 void contextMenuEvent( QContextMenuEvent *event ) override;
232
233 private slots:
234 void removeCurrentItem();
235 void onDatasetGroupSaved( const QString &uri );
236
237 private:
240
241 void selectAllItem( bool isChecked );
242 QMenu *createContextMenu();
243};
244
253class GUI_EXPORT QgsMeshActiveDatasetGroupTreeView : public QTreeView
254{
255 Q_OBJECT
256
257 public:
258 QgsMeshActiveDatasetGroupTreeView( QWidget *parent = nullptr );
259
261 void setLayer( QgsMeshLayer *layer );
262
264 int activeScalarGroup() const;
265
267 int activeVectorGroup() const;
268
270 void syncToLayer();
271
272 void mousePressEvent( QMouseEvent *event ) override;
273
274 public slots:
276 void setActiveScalarGroup( int group );
277
279 void setActiveVectorGroup( int group );
280
281 signals:
283 void activeScalarGroupChanged( int groupIndex );
284
286 void activeVectorGroupChanged( int groupIndex );
287
288 private:
289 void setActiveGroup();
290
293 QgsMeshLayer *mMeshLayer = nullptr; // not owned
294};
295
300class GUI_EXPORT QgsMeshDatasetGroupListModel : public QAbstractListModel
301{
302 Q_OBJECT
303 public:
304 explicit QgsMeshDatasetGroupListModel( QObject *parent );
305
307 void syncToLayer( QgsMeshLayer *layer );
308
309 int rowCount( const QModelIndex &parent ) const override;
310 QVariant data( const QModelIndex &index, int role ) const override;
311
312 void setDisplayProviderName( bool displayProviderName );
313
314 QStringList variableNames() const;
315
316 private:
317 QgsMeshDatasetGroupTreeItem *mRootItem = nullptr;
318 bool mDisplayProviderName = false;
319};
320
321#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.
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 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
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