SHAPER  9.15.0
XGUI_SketchConstraintsBrowser.h
1 // Copyright (C) 2014-2025 CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #ifndef XGUI_SketchConstraintsBrowser_H
21 #define XGUI_SketchConstraintsBrowser_H
22 
23 #include "XGUI.h"
24 #include <ModuleBase_Definitions.h>
25 #include <ModelAPI_Object.h>
26 #include <ModelAPI_ResultPart.h>
27 #include <ModelAPI_Events.h>
28 #include <ModelAPI_Folder.h>
29 #include <XGUI_DataModel.h>
30 #include <ModelAPI_Attribute.h>
31 
32 #include <QWidget>
33 #include <QTreeView>
34 #include <QLabel>
35 #include <QVBoxLayout>
36 #include <QHBoxLayout>
37 #include <QMap>
38 #include <QCheckBox>
39 #include <QScrollArea>
40 #include <QTreeWidget>
41 
42 class ModuleBase_IDocumentDataModel;
43 class XGUI_DataModel;
45 class XGUI_Workshop;
48 
49 //#define DEBUG_INDXES
50 
51 struct FeatStruct
52 {
53  FeaturePtr Feature;
54  std::vector<AttributePtr> Attributes;
55 };
56 
57 
58 class XGUI_EXPORT XGUI_ConstraintsViewTree : public QTreeWidget
59 {
60  Q_OBJECT
61 public:
64  XGUI_ConstraintsViewTree(QWidget* theParent = 0) : QTreeWidget(theParent) {}
65 
68  {
69  return static_cast<XGUI_DataModel*>(model());
70  }
71 
72 signals:
74  void contextMenuRequested(QContextMenuEvent* theEvent);
75 
76 protected slots:
78  virtual void contextMenuEvent(QContextMenuEvent* theEvent)
79  {
80  emit contextMenuRequested(theEvent);
81  }
82 
83  void closeEditor(QWidget* theEditor, QAbstractItemDelegate::EndEditHint theHint);
84 
85 };
86 
91 class XGUI_EXPORT XGUI_SketchConstraintsBrowser : public QWidget, public Events_Listener
92 {
93 Q_OBJECT
94  public:
95 
96  // Temporary for more simple modification
97  XGUI_ConstraintsViewTree* getViewTree() { return myViewTree; }
98 
99  bool IsInEditMode();
100 
101  // Make more good option
102  bool UpdateTree(const std::vector<std::pair<FeaturePtr, std::vector<AttributePtr>>>& theList);
103 
104  void CloseEditor();
105 
108  XGUI_SketchConstraintsBrowser(QWidget* theParent, XGUI_Workshop* theWorkshop);
110 
113  virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
114 
117  QObjectPtrList selectedObjects(QModelIndexList* theIndexes = 0) const;
118 
121  QObjectPtrList selectedConstraints(QModelIndexList* theIndexes = 0) const;
122 
125  void setObjectsSelected(const QObjectPtrList& theObjects);
126 
128  QModelIndexList selectedIndexes() const
129  {
130  if (myViewTree->selectionModel())
131  return myViewTree->selectionModel()->selectedIndexes();
132  else
133  return QModelIndexList();
134  }
135 
137  void initialize(ModuleBase_ITreeNode* theRoot);
138 
140  XGUI_Workshop* workshop() const { return myWorkshop; }
141 
142  void onSelectionChanged();
143 
144 public slots:
146  void onEditItem();
147 
149  void onDeactivateItems();
150 
151 private slots:
152  void SelectStateChanged(bool theState);
153 
154 signals:
157 
159  void contextMenuRequested(QContextMenuEvent* theEvent);
160 
162  void sizeChanged();
163 
164  void editValues();
165  void deleteConstraints();
166  void deactivate(bool, std::vector<FeaturePtr>);
167 
168 protected:
170  void resizeEvent(QResizeEvent* theEvent);
171 
172  private slots:
175  void onContextMenuRequested(QContextMenuEvent* theEvent);
176 
178  void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
179 
182  void onDoubleClick(const QModelIndex& theIndex);
183 
184  private:
185  XGUI_Workshop* myWorkshop;
186 
187  XGUI_ConstraintsViewTree* myViewTree;
188  QVBoxLayout* myLayout;
189  QHBoxLayout* myButtons;
190 
191  bool myLastState; //Store state of Extended Information CheckBox (need for correct reset after edit constraints)
192  QCheckBox* myExtInfo;
193  XGUI_ConstraintsItemDelegate* myDelegate;
194 
195  std::map<std::string, std::vector<FeatStruct>> myConstrs; // string - name of group, vector - constraints from group
196 };
197 
198 #endif
Class that reads data model definition XML for further processing in the XGUI_DataModel.
Definition: Config_DataModelReader.h:36
Base interface for any event listener.
Definition: Events_Listener.h:37
Definition: ModuleBase_ITreeNode.h:44
Definition: XGUI_SketchConstraintsBrowser.cpp:184
Definition: XGUI_SketchConstraintsBrowser.h:59
void contextMenuRequested(QContextMenuEvent *theEvent)
Emitted on context menu request.
XGUI_ConstraintsViewTree(QWidget *theParent=0)
Constructor.
Definition: XGUI_SketchConstraintsBrowser.h:64
virtual void contextMenuEvent(QContextMenuEvent *theEvent)
Redefinition of virtual method.
Definition: XGUI_SketchConstraintsBrowser.h:78
XGUI_DataModel * dataModel() const
Returns current data model.
Definition: XGUI_SketchConstraintsBrowser.h:67
This is a data model for Object Browser (QTreeView).
Definition: XGUI_DataModel.h:46
Object browser window object.
Definition: XGUI_SketchConstraintsBrowser.h:92
XGUI_Workshop * workshop() const
Returns current workshop.
Definition: XGUI_SketchConstraintsBrowser.h:140
void selectionChanged()
Emitted when selection is changed.
QModelIndexList selectedIndexes() const
Returns currently selected indexes.
Definition: XGUI_SketchConstraintsBrowser.h:128
void sizeChanged()
An signal emitted on resize of the Object Browser.
void contextMenuRequested(QContextMenuEvent *theEvent)
Emitted on context menu request.
Class which defines a configuration of the application (Workshop) and launches it.
Definition: XGUI_Workshop.h:83
Definition: XGUI_SketchConstraintsBrowser.h:52