Salome HOME
7f0a3a71b3181f86bf24cde6ea50a06480ef971c
[modules/gui.git] / src / TreeData / TreeGuiManager.cxx
1 // Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
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 // Author: Guillaume Boulant (EDF/R&D)
21
22 #include "TreeGuiManager.hxx"
23
24 // SALOME includes
25 #include <QStringList>
26
27 // XCAD includes
28 #include "TreeView.hxx"
29 #include "QtHelper.hxx"
30
31 // TODO:
32 // IMP: The constructor should have a dockwidget as argument.
33 // The creation of the void dockwidget (without the data tree
34 // embedded) should be done previously by the StandardApp_Module.
35 // The constructor would fill the dockwidget with a data tree view
36
37 /*!
38  * The construction of the gui manager setups a graphic framework that
39  * consists in a set of dock widgets implanted in the SALOME GUI and
40  * embedding a tree view rendering a data model (collection of data
41  * objects) in a hierarchic graphical organisation.
42  *
43  * The data model is a straith list of data objects while the view is
44  * a tree representation of this collection where folders corresponds
45  * to specific properties of the objects.
46  *
47  * This represention is for the needs of navigation in a huge amount
48  * of data and to ease the selection and processing of items.
49  */
50 TreeGuiManager::TreeGuiManager(SalomeApp_Application * salomeApp, const char * title)
51   : TreeObserver()
52 {
53   _salomeApp = salomeApp;
54   
55   bool tabify = false;
56   _dockWidgets = new DockWidgets(_salomeApp, tabify, title);
57
58   // Create a TreeView to be associated to a TreeModel dedicated to
59   // the Xcad data:
60   _dataTreeView = new TreeView();
61   QStringList headers;
62   headers << tr("Name") << tr("Value");
63   _dataTreeModel = new TreeModel(headers);
64   _dataTreeView->setModel(_dataTreeModel);
65
66   // Then plug the TreeView in the dock widget:
67   _dockWidgets->setDataView(_dataTreeView);
68
69   // We specify here the dataview to be observed
70   this->observe(_dataTreeView);
71 }
72
73 /*!
74  * This returns the SALOME application (SalomeApp_Application
75  * instance) associated to this TreeGuiManager.
76  */
77 SalomeApp_Application * TreeGuiManager::getSalomeApplication() {
78   return _salomeApp;
79 }
80
81
82 /*!
83  * This function set a layout of the different dock widgets in one
84  * single tabbed widget.
85  */
86 void TreeGuiManager::tabifyDockWidgets(bool tabify) {
87   _dockWidgets->tabify(tabify);
88 }
89
90 /*!
91  * This function switch on/off the dock widgets managed by this
92  * gui manager.
93  */
94 void TreeGuiManager::showDockWidgets(bool isVisible) {
95   _dockWidgets->show(isVisible);
96 }
97
98 /*!
99  * This returns the data tree model defined in this
100  * TreeGuiManager. The data tree model is a tree representation of the
101  * data model associated to this TreeGuiManager.
102  */
103 TreeModel * TreeGuiManager::getDataTreeModel() {
104   return _dataTreeModel;
105 }
106
107 /*!
108  * This returns the data tree view defined in this
109  * TreeGuiManager. The data tree view can be request to customize the
110  * popup menu associated to the tree representation.
111  */
112 TreeView * TreeGuiManager::getDataTreeView() {
113   return _dataTreeView;
114 }
115
116 /*!
117  * This returns the dock widgets manager
118  */
119 DockWidgets * TreeGuiManager::getDockWidgets() {
120   return _dockWidgets;
121 }
122
123 /*!
124  * This function specifies the data model to be used by the
125  * TreeGuiManager.
126  */
127 void TreeGuiManager::setDataModel(DataModel * dataModel) {
128   _dataModel = dataModel;
129 }
130
131 DataModel * TreeGuiManager::getDataModel() {
132   return _dataModel;
133 }
134
135 /*!
136  * This function processes the edit signals received from the
137  * TreeView. This is a default implementation that only prints the
138  * reception of the signal and some information about the dataObject
139  * associated to the item whose id is specified. In practice, the data
140  * model could be requested here to retrieve the data object to be
141  * edited from the nameId.
142  * TO BE IMPLEMENTED IN A DOMAIN SPECIFIC VERSION OF THIS CLASS
143  */
144
145 void TreeGuiManager::processItemList(QStringList itemNameIdList,
146                                      int /*actionId*/)
147 {
148   // WARN: THIS IS A DEFAULT IMPLEMENTATION GIVEN FOR DEMONSTRATION
149   // OF WHAT TO DO WITH THE PARAMETERS
150
151   QString itemNameId = itemNameIdList[0];
152   LOG("TreeGuiManager: signal received : process item "<<itemNameId);
153   DataObject * dataObject = _dataModel->getDataObject(QS2S(itemNameId));
154   if ( dataObject != NULL ) {
155     LOG("TreeGuiManager: dataObject = "<<dataObject->toString().c_str());
156   } else {
157     LOG("TreeGuiManager: no data object associated to this item");
158   }
159 }