QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
36 class QgsMeshLayer;
37 
42 class QgsMeshDatasetGroupSaveMenu: public QObject
43 {
44  Q_OBJECT
45  public:
46  QgsMeshDatasetGroupSaveMenu( QObject *parent = nullptr ): QObject( parent ) {}
47  QMenu *createSaveMenu( int groupIndex, QMenu *parentMenu = nullptr );
48 
49  void setMeshLayer( QgsMeshLayer *meshLayer );
50 
51  signals:
52  void datasetGroupSaved( const QString &uri );
53 
54  private:
55  QgsMeshLayer *mMeshLayer = nullptr;
56 
57  void saveDatasetGroup( int datasetGroup, const QString &driver, const QString &fileSuffix );
58 };
59 
66 class QgsMeshDatasetGroupTreeModel : public QAbstractItemModel
67 {
68  Q_OBJECT
69  public:
70  enum Roles
71  {
72  Name = Qt::UserRole,
77  };
78 
79  explicit QgsMeshDatasetGroupTreeModel( QObject *parent = nullptr );
80 
81  QVariant data( const QModelIndex &index, int role ) const override;
82  Qt::ItemFlags flags( const QModelIndex &index ) const override;
83  QVariant headerData( int section, Qt::Orientation orientation,
84  int role = Qt::DisplayRole ) const override;
85  QModelIndex index( int row, int column,
86  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 };
122 
128 {
129  public:
130  QgsMeshAvailableDatasetGroupTreeModel( QObject *parent = nullptr );
131 
132  QVariant data( const QModelIndex &index, int role ) const override;
133  bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
134  Qt::ItemFlags flags( const QModelIndex &index ) const override;
135  QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
136  int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
137 
138  private:
139  QString textDisplayed( const QModelIndex &index ) const;
140  QColor backGroundColor( const QModelIndex &index ) const;
141 };
142 
147 class QgsMeshDatasetGroupProxyModel: public QSortFilterProxyModel
148 {
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 
184 class QgsMeshDatasetGroupTreeItemDelagate: public QStyledItemDelegate
185 {
186  Q_OBJECT
187  public:
188  QgsMeshDatasetGroupTreeItemDelagate( QObject *parent = nullptr );
189 
190  void paint( QPainter *painter,
191  const QStyleOptionViewItem &option,
192  const QModelIndex &index ) const override;
193 
195  QRect iconRect( const QRect &rect, bool isVector ) const;
196 
197  QSize sizeHint( const QStyleOptionViewItem &option,
198  const QModelIndex &index ) const override;
199  private:
200  const QPixmap mScalarSelectedPixmap;
201  const QPixmap mScalarDeselectedPixmap;
202  const QPixmap mVectorSelectedPixmap;
203  const QPixmap mVectorDeselectedPixmap;
204 
205  QRect iconRect( const QRect &rect, int pos ) const;
206 };
207 
214 class GUI_EXPORT QgsMeshDatasetGroupTreeView: public QTreeView
215 {
216  Q_OBJECT
217  public:
218  QgsMeshDatasetGroupTreeView( QWidget *parent = nullptr );
219 
220  void syncToLayer( QgsMeshLayer *layer );
221  void resetDefault( QgsMeshLayer *meshLayer );
222 
223  QgsMeshDatasetGroupTreeItem *datasetGroupTreeRootItem();
224 
225  signals:
226  void apply();
227 
228  public slots:
229  void selectAllGroups();
230  void deselectAllGroups();
231 
232  protected:
233  void contextMenuEvent( QContextMenuEvent *event ) override;
234 
235  private slots:
236  void removeCurrentItem();
237  void onDatasetGroupSaved( const QString &uri );
238 
239  private:
241  QgsMeshDatasetGroupSaveMenu *mSaveMenu;
242 
243  void selectAllItem( bool isChecked );
244  QMenu *createContextMenu();
245 };
246 
255 class GUI_EXPORT QgsMeshActiveDatasetGroupTreeView : public QTreeView
256 {
257  Q_OBJECT
258 
259  public:
260  QgsMeshActiveDatasetGroupTreeView( QWidget *parent = nullptr );
261 
263  void setLayer( QgsMeshLayer *layer );
264 
266  int activeScalarGroup() const;
267 
269  int activeVectorGroup() const;
270 
272  void syncToLayer();
273 
274  void mousePressEvent( QMouseEvent *event ) override;
275 
276  public slots:
278  void setActiveScalarGroup( int group );
279 
281  void setActiveVectorGroup( int group );
282 
283  signals:
285  void activeScalarGroupChanged( int groupIndex );
286 
288  void activeVectorGroupChanged( int groupIndex );
289 
290  private:
291  void setActiveGroup();
292 
293  QgsMeshDatasetGroupProxyModel *mProxyModel;
295  QgsMeshLayer *mMeshLayer = nullptr; // not owned
296 };
297 
302 class GUI_EXPORT QgsMeshDatasetGroupListModel: public QAbstractListModel
303 {
304  public:
305  explicit QgsMeshDatasetGroupListModel( QObject *parent );
306 
308  void syncToLayer( QgsMeshLayer *layer );
309 
310  int rowCount( const QModelIndex &parent ) const override;
311  QVariant data( const QModelIndex &index, int role ) const override;
312 
313  void setDisplayProviderName( bool displayProviderName );
314 
315  QStringList variableNames() const;
316 
317  private:
318  QgsMeshDatasetGroupTreeItem *mRootItem = nullptr;
319  bool mDisplayProviderName = false;
320 };
321 
322 #endif // QGSMESHDATASETGROUPTREE_H
QgsMeshDatasetGroupTreeModel::data
QVariant data(const QModelIndex &index, int role) const override
Definition: qgsmeshdatasetgrouptreeview.cpp:46
QgsMeshDatasetGroupProxyModel::activeScalarGroup
int activeScalarGroup() const
Returns index of active group for contours.
Definition: qgsmeshdatasetgrouptreeview.cpp:249
QgsMeshDatasetGroupProxyModel::setActiveScalarGroup
void setActiveScalarGroup(int group)
Sets active group for contours.
Definition: qgsmeshdatasetgrouptreeview.cpp:254
QgsMeshDatasetGroupProxyModel::QgsMeshDatasetGroupProxyModel
QgsMeshDatasetGroupProxyModel(QAbstractItemModel *sourceModel)
Definition: qgsmeshdatasetgrouptreeview.cpp:243
QgsMeshDatasetGroupTreeModel::parent
QModelIndex parent(const QModelIndex &index) const override
Definition: qgsmeshdatasetgrouptreeview.cpp:113
QgsMeshDatasetGroupSaveMenu
Definition: qgsmeshdatasetgrouptreeview.h:42
QgsMeshDatasetGroupTreeView
Tree widget for display of the mesh dataset groups.
Definition: qgsmeshdatasetgrouptreeview.h:214
QgsMeshDatasetGroupTreeModel::Roles
Roles
Definition: qgsmeshdatasetgrouptreeview.h:70
QgsMeshDatasetGroupTreeModel::columnCount
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: qgsmeshdatasetgrouptreeview.cpp:40
QgsMeshDatasetGroupTreeItemDelagate::sizeHint
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: qgsmeshdatasetgrouptreeview.cpp:380
QgsMeshDatasetGroupProxyModel::data
QVariant data(const QModelIndex &index, int role) const override
Definition: qgsmeshdatasetgrouptreeview.cpp:291
QgsMeshAvailableDatasetGroupTreeModel::QgsMeshAvailableDatasetGroupTreeModel
QgsMeshAvailableDatasetGroupTreeModel(QObject *parent=nullptr)
Definition: qgsmeshdatasetgrouptreeview.cpp:771
QgsMeshDatasetGroupTreeItem
Tree item for display of the mesh dataset groups. Dataset group is set of datasets with the same name...
Definition: qgsmeshdataset.h:843
QgsMeshDatasetGroupTreeModel::isEnabled
bool isEnabled(const QModelIndex &index) const
Returns whether the dataset groups related to the QModelIndex is set as enabled.
Definition: qgsmeshdatasetgrouptreeview.cpp:175
QgsMeshDatasetGroupProxyModel::syncToLayer
void syncToLayer(QgsMeshLayer *layer)
Add groups to the model from mesh layer.
Definition: qgsmeshdatasetgrouptreeview.cpp:323
QgsMeshDatasetGroupSaveMenu::createSaveMenu
QMenu * createSaveMenu(int groupIndex, QMenu *parentMenu=nullptr)
Definition: qgsmeshdatasetgrouptreeview.cpp:688
QgsMeshDatasetGroupTreeItemDelagate::QgsMeshDatasetGroupTreeItemDelagate
QgsMeshDatasetGroupTreeItemDelagate(QObject *parent=nullptr)
Definition: qgsmeshdatasetgrouptreeview.cpp:341
QgsMeshDatasetGroupTreeModel::DatasetGroupIndex
@ DatasetGroupIndex
Definition: qgsmeshdatasetgrouptreeview.h:76
QgsMeshAvailableDatasetGroupTreeModel::data
QVariant data(const QModelIndex &index, int role) const override
Definition: qgsmeshdatasetgrouptreeview.cpp:774
QgsMeshDatasetGroupTreeItemDelagate::paint
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: qgsmeshdatasetgrouptreeview.cpp:350
QgsMeshDatasetGroupTreeModel::IsActiveVectorDatasetGroup
@ IsActiveVectorDatasetGroup
Definition: qgsmeshdatasetgrouptreeview.h:75
QgsMeshDatasetGroupTreeModel::syncToLayer
void syncToLayer(QgsMeshLayer *layer)
Synchronizes groups to the model from mesh layer.
Definition: qgsmeshdatasetgrouptreeview.cpp:144
QgsMeshDatasetGroupTreeModel::removeItem
void removeItem(const QModelIndex &index)
Removes an item from the tree.
Definition: qgsmeshdatasetgrouptreeview.cpp:214
QgsMeshDatasetGroupTreeModel
Item Model for QgsMeshDatasetGroupTreeItem.
Definition: qgsmeshdatasetgrouptreeview.h:66
QgsMeshDatasetGroupTreeModel::datasetGroupTreeItem
QgsMeshDatasetGroupTreeItem * datasetGroupTreeItem(int groupIndex)
Returns the dataset group tree item with index, keeps ownership.
Definition: qgsmeshdatasetgrouptreeview.cpp:159
QgsMeshDatasetGroupTreeModel::resetDefault
void resetDefault(QgsMeshLayer *meshLayer)
Resets all groups with default state from the mesh layer.
Definition: qgsmeshdatasetgrouptreeview.cpp:185
QgsMeshLayer
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:98
QgsMeshDatasetGroupProxyModel::setActiveVectorGroup
void setActiveVectorGroup(int group)
Sets active vector group.
Definition: qgsmeshdatasetgrouptreeview.cpp:271
QgsMeshDatasetGroupTreeModel::datasetGroupTreeRootItem
QgsMeshDatasetGroupTreeItem * datasetGroupTreeRootItem()
Returns the dataset group root tree item, keeps ownership.
Definition: qgsmeshdatasetgrouptreeview.cpp:154
QgsMeshDatasetGroupTreeModel::QgsMeshDatasetGroupTreeModel
QgsMeshDatasetGroupTreeModel(QObject *parent=nullptr)
Definition: qgsmeshdatasetgrouptreeview.cpp:34
QgsMeshDatasetGroupProxyModel::activeVectorGroup
int activeVectorGroup() const
Returns index of active group for vectors.
Definition: qgsmeshdatasetgrouptreeview.cpp:266
QgsMeshDatasetGroupTreeModel::IsActiveScalarDatasetGroup
@ IsActiveScalarDatasetGroup
Definition: qgsmeshdatasetgrouptreeview.h:74
QgsMeshDatasetGroupTreeModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition: qgsmeshdatasetgrouptreeview.cpp:81
QgsMeshAvailableDatasetGroupTreeModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Definition: qgsmeshdatasetgrouptreeview.cpp:832
SIP_NO_FILE
#define SIP_NO_FILE
Definition: fromencodedcomponenthelper.h:18
QgsMeshDatasetGroupSaveMenu::datasetGroupSaved
void datasetGroupSaved(const QString &uri)
QgsMeshDatasetGroupTreeModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: qgsmeshdatasetgrouptreeview.cpp:127
QgsMeshDatasetGroupProxyModel
Definition: qgsmeshdatasetgrouptreeview.h:147
QgsMeshDatasetGroupTreeModel::flags
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: qgsmeshdatasetgrouptreeview.cpp:73
QgsMeshDatasetGroupTreeModel::Name
@ Name
Definition: qgsmeshdatasetgrouptreeview.h:72
QgsMeshDatasetGroupTreeModel::setAllGroupsAsEnabled
void setAllGroupsAsEnabled(bool isEnabled)
Sets all groups as enabled.
Definition: qgsmeshdatasetgrouptreeview.cpp:196
QgsMeshDatasetGroupTreeItemDelagate::iconRect
QRect iconRect(const QRect &rect, bool isVector) const
Icon rectangle for given item rectangle.
Definition: qgsmeshdatasetgrouptreeview.cpp:367
QgsMeshAvailableDatasetGroupTreeModel::setData
bool setData(const QModelIndex &index, const QVariant &value, int role) override
Definition: qgsmeshdatasetgrouptreeview.cpp:796
QgsMeshDatasetGroupSaveMenu::setMeshLayer
void setMeshLayer(QgsMeshLayer *meshLayer)
Definition: qgsmeshdatasetgrouptreeview.cpp:732
QgsMeshAvailableDatasetGroupTreeModel
Definition: qgsmeshdatasetgrouptreeview.h:127
qgsmeshdataset.h
QgsMeshDatasetGroupProxyModel::flags
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: qgsmeshdatasetgrouptreeview.cpp:283
QgsMeshActiveDatasetGroupTreeView
Tree widget for display of the mesh dataset groups.
Definition: qgsmeshdatasetgrouptreeview.h:255
QgsMeshDatasetGroupSaveMenu::QgsMeshDatasetGroupSaveMenu
QgsMeshDatasetGroupSaveMenu(QObject *parent=nullptr)
Definition: qgsmeshdatasetgrouptreeview.h:46
QgsMeshDatasetGroupTreeModel::setPersistentDatasetGroup
void setPersistentDatasetGroup(const QModelIndex &index, const QString &uri)
Sets the dataset group as persistent with specified uri and for specified index.
Definition: qgsmeshdatasetgrouptreeview.cpp:229
QgsMeshDatasetGroupTreeModel::index
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Definition: qgsmeshdatasetgrouptreeview.cpp:93
QgsMeshDatasetGroupProxyModel::filterAcceptsRow
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
Definition: qgsmeshdatasetgrouptreeview.cpp:331
QgsMeshDatasetGroupListModel
Definition: qgsmeshdatasetgrouptreeview.h:302
QgsMeshAvailableDatasetGroupTreeModel::columnCount
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: qgsmeshdatasetgrouptreeview.cpp:849
QgsMeshDatasetGroupTreeItemDelagate
Delegate to display tree item with a contours and vector selector.
Definition: qgsmeshdatasetgrouptreeview.h:184
QgsMeshAvailableDatasetGroupTreeModel::flags
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: qgsmeshdatasetgrouptreeview.cpp:821
QgsMeshDatasetGroupTreeModel::IsVector
@ IsVector
Definition: qgsmeshdatasetgrouptreeview.h:73