ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvDBRoot.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 // Qt
11 #include <QAbstractItemModel>
12 #include <QPoint>
13 #include <QTreeView>
14 
15 // CV_DB_LIB
16 #include <ecvHObject.h>
17 
18 // System
19 #include <unordered_set>
20 
21 class QAction;
22 class QStandardItemModel;
23 
25 class ccHObject;
26 
29  size_t selCount;
30  size_t sfCount;
31  size_t colorCount;
32  size_t normalsCount;
33  size_t octreeCount;
34  size_t cloudCount;
35  size_t gridCound;
36  size_t groupCount;
37  size_t polylineCount;
38  size_t planeCount;
39  size_t circleCount;
40  size_t meshCount;
41  size_t imageCount;
42  size_t sensorCount;
45  size_t kdTreeCount;
46 
47  void reset() { memset(this, 0, sizeof(dbTreeSelectionInfo)); }
48 };
49 
51 class ccCustomQTreeView : public QTreeView {
52  Q_OBJECT
53 
54 public:
56  explicit ccCustomQTreeView(QWidget* parent) : QTreeView(parent) {}
57 
58 protected:
59  // inherited from QTreeView
60  virtual QItemSelectionModel::SelectionFlags selectionCommand(
61  const QModelIndex& index, const QEvent* event = nullptr) const;
62 };
63 
65 class ccDBRoot : public QAbstractItemModel {
66  Q_OBJECT
67 
68 public:
70 
74  ccDBRoot(ccCustomQTreeView* dbTreeWidget,
75  QTreeView* propertiesTreeWidget,
76  QObject* parent = nullptr);
77 
79  virtual ~ccDBRoot() override;
80 
81  void hide();
82  void show();
83 
86 
88  void hidePropertiesView();
90  void updatePropertiesView();
91 
94  return m_ccPropDelegate;
95  }
96 
98  void addElement(ccHObject* object, bool autoExpand = true);
99 
101 
103  void removeElement(ccHObject* object);
104 
106 
110  void removeElements(ccHObject::Container& objects);
111 
113  ccHObject* find(int uniqueID) const;
114 
118 
121  size_t getSelectedEntities(ccHObject::Container& selectedEntities,
123  dbTreeSelectionInfo* info = nullptr);
124 
126  void expandElement(ccHObject* object, bool state);
127 
129  void unselectEntity(ccHObject* obj);
130 
132  void unselectAllEntities();
133 
135  void unloadAll();
136 
137  // inherited from QAbstractItemModel
138  virtual QVariant data(const QModelIndex& index, int role) const override;
139  virtual QModelIndex index(
140  int row,
141  int column,
142  const QModelIndex& parentIndex = QModelIndex()) const override;
143  QModelIndex index(ccHObject* object);
144  virtual QModelIndex parent(const QModelIndex& index) const override;
145  virtual int rowCount(
146  const QModelIndex& parent = QModelIndex()) const override;
147  virtual int columnCount(
148  const QModelIndex& parent = QModelIndex()) const override;
149  virtual Qt::ItemFlags flags(const QModelIndex& index) const override;
150  virtual bool setData(const QModelIndex& index,
151  const QVariant& value,
152  int role = Qt::EditRole) override;
153  virtual Qt::DropActions supportedDropActions() const override;
154  virtual bool dropMimeData(const QMimeData* data,
155  Qt::DropAction action,
156  int row,
157  int column,
158  const QModelIndex& parent) override;
159  virtual QMap<int, QVariant> itemData(
160  const QModelIndex& index) const override;
161  virtual Qt::DropActions supportedDragActions() const override {
162  return Qt::MoveAction;
163  }
164 
165 public slots:
166  void changeSelection(const QItemSelection& selected,
167  const QItemSelection& deselected);
169  void redrawCCObject(ccHObject* object, bool forceRedraw = true);
170  void redrawCCObjectAndChildren(ccHObject* object, bool forceRedraw = true);
171  void updateCCObject(ccHObject* object);
172  void deleteSelectedEntities();
173 
175 
181  void selectEntity(ccHObject* obj, bool forceAdditiveSelection = false);
182 
184 
186  void selectEntities(std::unordered_set<int> entIDs);
187 
189 
193  void selectEntities(const ccHObject::Container& entities,
194  bool incremental = false);
195 
196 protected:
205  TG_3D_NAME
206  };
207 
211 
212 protected slots:
213  void showContextMenu(const QPoint&);
214 
215  void expandBranch();
216  void collapseBranch();
218  void sortChildrenAZ();
219  void sortChildrenZA();
220  void sortChildrenType();
221  void selectByTypeAndName();
222  void exportImages();
223 
224  inline void toggleSelectedEntities() {
226  }
229  }
232  }
235  }
236  inline void toggleSelectedEntitiesSF() {
238  }
241  }
244  }
245 
246  void addEmptyGroup();
249  void enableBubbleViewMode();
250  void editLabelScalarValue();
251 
252 signals:
254  void dbIsEmpty();
256 
257 protected:
259 
262  void alignCameraWithEntity(bool reverse);
263 
265  void showPropertiesView(ccHObject* obj);
266 
269 
272 
274  void expandOrCollapseHoveredBranch(bool expand);
275 
278  bool typeIsExclusive = true,
279  QString name = QString(),
280  bool nameIsRegex = false);
281 
284 
286  QTreeView* m_dbTreeWidget;
287 
290 
292  QStandardItemModel* m_propertiesModel;
295 
297  QAction* m_expandBranch;
311  QAction* m_exportImages;
329  QAction* m_addEmptyGroup;
338 
341 };
MouseEvent event
int64_t CV_CLASS_ENUM
Type of object type flags (64 bits)
Definition: CVTypes.h:97
std::string name
char type
#define slots
#define signals
Custom QTreeView widget (for advanced selection behavior)
Definition: ecvDBRoot.h:51
virtual QItemSelectionModel::SelectionFlags selectionCommand(const QModelIndex &index, const QEvent *event=nullptr) const
Definition: ecvDBRoot.cpp:2437
ccCustomQTreeView(QWidget *parent)
Default constructor.
Definition: ecvDBRoot.h:56
GUI database tree root.
Definition: ecvDBRoot.h:65
ccPropertiesTreeDelegate * getPropertiesDelegate()
Get properties tree delegate.
Definition: ecvDBRoot.h:93
QAction * m_alignCameraWithEntity
Context menu action: use 3-points labels or planes to orient camera.
Definition: ecvDBRoot.h:331
void updatePropertiesView()
Updates properties view.
Definition: ecvDBRoot.cpp:1225
QAction * m_sortChildrenType
Context menu action: sort children by type.
Definition: ecvDBRoot.h:307
void toggleSelectedEntitiesMat()
Definition: ecvDBRoot.h:239
void editLabelScalarValue()
Definition: ecvDBRoot.cpp:2106
void show()
Definition: ecvDBRoot.cpp:393
void hidePropertiesView()
Hides properties view.
Definition: ecvDBRoot.cpp:1210
void expandElement(ccHObject *object, bool state)
Expands tree at a given node.
Definition: ecvDBRoot.cpp:477
virtual QModelIndex index(int row, int column, const QModelIndex &parentIndex=QModelIndex()) const override
Definition: ecvDBRoot.cpp:921
void dbIsNotEmptyAnymore()
int countSelectedEntities(CV_CLASS_ENUM filter=CV_TYPES::OBJECT)
Definition: ecvDBRoot.cpp:1256
QAction * m_enableBubbleViewMode
Context menu action: enable bubble-view (on a sensor)
Definition: ecvDBRoot.h:335
void hide()
Definition: ecvDBRoot.cpp:388
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: ecvDBRoot.cpp:994
void sortChildrenZA()
Definition: ecvDBRoot.cpp:1830
QAction * m_sortChildrenZA
Context menu action: sort children in reverse alphabetical order.
Definition: ecvDBRoot.h:305
void updateCCObject(ccHObject *object)
Definition: ecvDBRoot.cpp:1237
QAction * m_gatherInformation
Context menu action: gather (recursive) information on selected entities.
Definition: ecvDBRoot.h:301
QAction * m_editLabelScalarValue
Context menu action: change current scalar value (via a 2D label)
Definition: ecvDBRoot.h:337
void gatherRecursiveInformation()
Definition: ecvDBRoot.cpp:1699
ccDBRoot(ccCustomQTreeView *dbTreeWidget, QTreeView *propertiesTreeWidget, QObject *parent=nullptr)
Default constructor.
Definition: ecvDBRoot.cpp:262
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition: ecvDBRoot.cpp:777
QAction * m_toggleSelectedEntities
Context menu action: enabled/disable selected entities.
Definition: ecvDBRoot.h:315
void unselectEntity(ccHObject *obj)
Unselects a given entity.
Definition: ecvDBRoot.cpp:1035
virtual ~ccDBRoot() override
Destructor.
Definition: ecvDBRoot.cpp:382
void toggleSelectedEntities()
Definition: ecvDBRoot.h:224
QTreeView * m_dbTreeWidget
Associated widget for DB tree.
Definition: ecvDBRoot.h:286
virtual QModelIndex parent(const QModelIndex &index) const override
Definition: ecvDBRoot.cpp:963
QAction * m_deleteSelectedEntities
Context menu action: delete selected entities.
Definition: ecvDBRoot.h:313
void toggleSelectedEntities3DName()
Definition: ecvDBRoot.h:242
QAction * m_toggleSelectedEntitiesNormals
Context menu action: hide/show selected entities normals.
Definition: ecvDBRoot.h:321
QPoint m_contextMenuPos
Last context menu pos.
Definition: ecvDBRoot.h:340
void toggleSelectedEntitiesVisibility()
Definition: ecvDBRoot.h:227
QAction * m_selectByTypeAndName
Context menu action: select object by type and/or by name.
Definition: ecvDBRoot.h:309
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
Definition: ecvDBRoot.cpp:1401
void removeElements(ccHObject::Container &objects)
Removes several elements at once from the DB tree.
Definition: ecvDBRoot.cpp:513
void alignCameraWithEntityIndirect()
Definition: ecvDBRoot.h:248
QAction * m_addEmptyGroup
Context menu action: add empty group.
Definition: ecvDBRoot.h:329
void sortChildrenType()
Definition: ecvDBRoot.cpp:1832
void redrawCCObjectAndChildren(ccHObject *object, bool forceRedraw=true)
Definition: ecvDBRoot.cpp:1250
void toggleSelectedEntitiesSF()
Definition: ecvDBRoot.h:236
ccHObject * m_treeRoot
Associated DB root.
Definition: ecvDBRoot.h:283
virtual QVariant data(const QModelIndex &index, int role) const override
Definition: ecvDBRoot.cpp:690
void selectEntity(ccHObject *obj, bool forceAdditiveSelection=false)
Selects a given entity.
Definition: ecvDBRoot.cpp:1054
virtual Qt::DropActions supportedDropActions() const override
Definition: ecvDBRoot.cpp:1338
void selectEntities(std::unordered_set< int > entIDs)
Selects multiple entities at once (shortcut to the other version)
Definition: ecvDBRoot.cpp:1109
QAction * m_toggleSelectedEntitiesMat
Context menu action: hide/show selected entities materials/textures.
Definition: ecvDBRoot.h:323
ccHObject * getRootEntity()
Returns associated root object.
Definition: ecvDBRoot.cpp:421
void redrawCCObject(ccHObject *object, bool forceRedraw=true)
Definition: ecvDBRoot.cpp:1245
void selectChildrenByTypeAndName(CV_CLASS_ENUM type, bool typeIsExclusive=true, QString name=QString(), bool nameIsRegex=false)
Selects objects by type and/or name.
Definition: ecvDBRoot.cpp:1971
QAction * m_alignCameraWithEntityReverse
Context menu action: reverse of m_alignCameraWithEntity.
Definition: ecvDBRoot.h:333
size_t getSelectedEntities(ccHObject::Container &selectedEntities, CV_CLASS_ENUM filter=CV_TYPES::OBJECT, dbTreeSelectionInfo *info=nullptr)
Definition: ecvDBRoot.cpp:1273
void selectByTypeAndName()
Definition: ecvDBRoot.cpp:1900
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: ecvDBRoot.cpp:983
QAction * m_toggleSelectedEntitiesColor
Context menu action: hide/show selected entities color.
Definition: ecvDBRoot.h:319
SortRules
Entities sorting schemes.
Definition: ecvDBRoot.h:268
@ SORT_BY_TYPE
Definition: ecvDBRoot.h:268
@ SORT_Z2A
Definition: ecvDBRoot.h:268
@ SORT_A2Z
Definition: ecvDBRoot.h:268
ccHObject * find(int uniqueID) const
Finds an element in DB.
Definition: ecvDBRoot.cpp:1197
void alignCameraWithEntity(bool reverse)
Aligns the camera with the currently selected entity.
Definition: ecvDBRoot.cpp:1628
void showPropertiesView(ccHObject *obj)
Shows properties view for a given element.
Definition: ecvDBRoot.cpp:1201
virtual QMap< int, QVariant > itemData(const QModelIndex &index) const override
Definition: ecvDBRoot.cpp:1389
void reflectObjectPropChange(ccHObject *obj)
Definition: ecvDBRoot.cpp:1216
void expandOrCollapseHoveredBranch(bool expand)
Expands or collapses hovered item.
Definition: ecvDBRoot.cpp:1590
QAction * m_sortChildrenAZ
Context menu action: sort children in alphabetical order.
Definition: ecvDBRoot.h:303
void unselectAllEntities()
Unselects all entities.
Definition: ecvDBRoot.cpp:1047
void toggleSelectedEntitiesColor()
Definition: ecvDBRoot.h:230
QAction * m_toggleSelectedEntities3DName
Context menu action: hide/show selected entities 3D name.
Definition: ecvDBRoot.h:327
void sortChildrenAZ()
Definition: ecvDBRoot.cpp:1828
void unloadAll()
Unloads all entities.
Definition: ecvDBRoot.cpp:398
TOGGLE_PROPERTY
Entity property that can be toggled.
Definition: ecvDBRoot.h:198
@ TG_ENABLE
Definition: ecvDBRoot.h:199
@ TG_3D_NAME
Definition: ecvDBRoot.h:205
@ TG_COLOR
Definition: ecvDBRoot.h:201
@ TG_MATERIAL
Definition: ecvDBRoot.h:204
@ TG_NORMAL
Definition: ecvDBRoot.h:203
@ TG_VISIBLE
Definition: ecvDBRoot.h:200
void toggleSelectedEntitiesProperty(TOGGLE_PROPERTY prop)
Definition: ecvDBRoot.cpp:2023
void enableBubbleViewMode()
Definition: ecvDBRoot.cpp:2088
QStandardItemModel * m_propertiesModel
Selected entity's properties data model.
Definition: ecvDBRoot.h:292
void changeSelection(const QItemSelection &selected, const QItemSelection &deselected)
Definition: ecvDBRoot.cpp:999
void removeElement(ccHObject *object)
Removes an element from the DB tree.
Definition: ecvDBRoot.cpp:554
virtual Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: ecvDBRoot.cpp:1342
void sortSelectedEntitiesChildren(SortRules rule)
Sorts selected entities children.
Definition: ecvDBRoot.cpp:1836
QAction * m_expandBranch
Context menu action: expand tree branch.
Definition: ecvDBRoot.h:297
QTreeView * m_propertiesTreeWidget
Associated widget for selected entity's properties tree.
Definition: ecvDBRoot.h:289
void showContextMenu(const QPoint &)
Definition: ecvDBRoot.cpp:2284
void toggleSelectedEntitiesNormals()
Definition: ecvDBRoot.h:233
void expandBranch()
Definition: ecvDBRoot.cpp:1586
QAction * m_collapseBranch
Context menu action: collapse tree branch.
Definition: ecvDBRoot.h:299
void collapseBranch()
Definition: ecvDBRoot.cpp:1588
QAction * m_exportImages
Context menu action: export images.
Definition: ecvDBRoot.h:311
void exportImages()
Definition: ecvDBRoot.cpp:2159
void dbIsEmpty()
ccPropertiesTreeDelegate * m_ccPropDelegate
Selected entity's properties delegate.
Definition: ecvDBRoot.h:294
void alignCameraWithEntityDirect()
Definition: ecvDBRoot.h:247
QAction * m_toggleSelectedEntitiesSF
Context menu action: hide/show selected entities SF.
Definition: ecvDBRoot.h:325
void addEmptyGroup()
Definition: ecvDBRoot.cpp:2074
QAction * m_toggleSelectedEntitiesVisibility
Context menu action: hide/show selected entities.
Definition: ecvDBRoot.h:317
void deleteSelectedEntities()
Definition: ecvDBRoot.cpp:593
void addElement(ccHObject *object, bool autoExpand=true)
Adds an element to the DB tree.
Definition: ecvDBRoot.cpp:423
virtual Qt::DropActions supportedDragActions() const override
Definition: ecvDBRoot.h:161
void selectionChanged()
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
std::vector< ccHObject * > Container
Standard instances container (for children, etc.)
Definition: ecvHObject.h:337
GUI properties list dialog element.
@ OBJECT
Definition: CVTypes.h:102
Precise statistics about current selection.
Definition: ecvDBRoot.h:28
size_t gblSensorCount
Definition: ecvDBRoot.h:43
size_t polylineCount
Definition: ecvDBRoot.h:37
size_t cameraSensorCount
Definition: ecvDBRoot.h:44