OpenWalnut  1.5.0dev
WQtControlPanel.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WQTCONTROLPANEL_H
26 #define WQTCONTROLPANEL_H
27 
28 #include <list>
29 #include <memory>
30 #include <string>
31 #include <vector>
32 
33 #include <QDockWidget>
34 #include <QListWidget>
35 #include <QSplitter>
36 #include <QTabWidget>
37 #include <QVBoxLayout>
38 #include <QWidget>
39 
40 #include "../WQtCombinerToolbar.h"
41 #include "../WQtModuleConfig.h"
42 #include "../guiElements/WQtDockWidget.h"
43 #include "WQtModuleHeaderTreeItem.h"
44 #include "WQtModuleTreeItem.h"
45 #include "WQtPropertyGroupWidget.h"
46 #include "WQtRoiHeaderTreeItem.h"
47 #include "WQtSubjectTreeItem.h"
48 #include "WQtTreeWidget.h"
49 #include "core/dataHandler/WDataSet.h"
50 #include "core/graphicsEngine/WROI.h"
51 
52 class WMainWindow;
53 class WQtColormapper;
54 
55 /**
56  * container widget for a tree widget with context menu and some control widgets
57  */
59 {
60  Q_OBJECT
61 
62 public:
63  /**
64  * Constructor.
65  *
66  * \param parent Parent widget.
67  */
68  explicit WQtControlPanel( WMainWindow* parent = 0 );
69 
70  /**
71  * Default Destructor.
72  */
73  virtual ~WQtControlPanel();
74 
75  /**
76  * Complete own GUI setup. This is useful when not all the information is available during construction. Called by the WMainWindow.
77  */
78  void completeGuiSetup();
79 
80  /**
81  * Adds a page to the context widget
82  *
83  * \param content A widget with controls
84  * \param propContents The prop group widget.
85  *
86  * \return the index of the new tab
87  */
88  int addTabWidgetContent( QWidget* content, WQtPropertyGroupWidget* propContents );
89 
90  /**
91  * Adds a subject entry to the tree widget
92  *
93  * \param name The entry name of the subjectin the tree widget
94  * \return A pointer to the tree widget item
95  */
96  WQtSubjectTreeItem* addSubject( std::string name );
97 
98  /**
99  * Adds a dataset entry to any given subject in the tree widget
100  *
101  * \param module shared pointer to the module associated with this tree widget entry
102  * \param subjectId subject id this dataset belongs to
103  *
104  * \return A pointer to the tree widget item
105  */
106  WQtDatasetTreeItem* addDataset( std::shared_ptr< WModule > module, int subjectId = 0 );
107 
108  /**
109  * Adds a module to the control panel.
110  *
111  * \param module the module to add.
112  *
113  * \return the representation in control panel.
114  */
115  WQtModuleTreeItem* addModule( std::shared_ptr< WModule > module );
116 
117  /**
118  * Adds a ROI entry to the control panel
119  *
120  * \param roi pointer to the ROI representation object
121  */
122  void addRoi( osg::ref_ptr< WROI > roi );
123 
124  /**
125  * Removes a ROI entry from the control panel
126  *
127  * \param roi pointer to the ROI representation object
128  */
129  void removeRoi( osg::ref_ptr< WROI > roi );
130 
131  /**
132  * helper funtion to connect all qt widgets with their functions
133  */
134  void connectSlots();
135 
136  /**
137  * Returns the module currently selected in control panel.
138  *
139  * \return the module.
140  */
141  std::shared_ptr< WModule > getSelectedModule();
142 
143  /**
144  * Returns the currently selected ROI.
145  *
146  * \return pointer to ROI representation
147  */
148  osg::ref_ptr< WROI > getSelectedRoi();
149 
150  /**
151  * Returns the first ROI in the currently selected branch.
152  *
153  * \return pointer to ROI representation
154  */
155  osg::ref_ptr< WROI > getFirstRoiInSelectedBranch();
156 
157  /**
158  * Returns a checkable action that can be used to show or close this dock widget.
159  * The action's text is set to the dock widget's window title.
160  *
161  * This member function is overwritten to add a keyboard shortcut to this action.
162  *
163  * \return Modified QAction
164  */
165  QAction* toggleViewAction() const;
166 
167  /**
168  * Selects the uppermost entry in the module tree.
169  */
170  void selectUpperMostEntry();
171 
172  /**
173  * Gets the ROI dock widget.
174  *
175  * \return the ROI dock.
176  */
177  WQtDockWidget* getRoiDock() const;
178 
179  /**
180  * Return the action to delete a selected roi
181  *
182  * \return the action
183  */
184  QAction* getRoiDeleteAction() const;
185 
186  /**
187  * Gets the module dock widget.
188  *
189  * \return the module dock
190  */
191  WQtDockWidget* getModuleDock() const;
192 
193  /**
194  * Gets the colormapper dock
195  *
196  * \return the dock
197  */
199 
200  /**
201  * Returns the module config dialog. It then can be used for configuration.
202  *
203  * \return the module config dialog.
204  */
206 
207  /**
208  * Returns an action which can be triggered by the user if some module are missing.
209  *
210  * \return the action.
211  */
213 
214  /**
215  * Sets the module which is now active. Updates the GUI accordingly. Can be NULL which causes the GUI to remove all module specific stuff.
216  *
217  * \param module the module to activate
218  * \param forceUpdate force update even if the module is the same as the current one.
219  */
220  void setActiveModule( WModule::SPtr module, bool forceUpdate = false );
221 
222  /**
223  * Used to clean the GUI from any module specify widgets.
224  *
225  * \param selectTopmost select top element or keep current
226  */
227  void deactivateModuleSelection( bool selectTopmost = true );
228 protected:
229  /**
230  * Custom event dispatcher. Gets called by QT's Event system every time an event got sent to this widget. This event handler
231  * processes several custom events, like WModuleAssocEvent.
232  *
233  * \param event the event that got transmitted.
234  *
235  * \return true if the event got handled properly.
236  */
237  virtual bool event( QEvent* event );
238 
239  /**
240  * Helper function to return the first subject id in the tree widget
241  *
242  * \return index of first subject in tree
243  */
244  int getFirstSubject();
245 
246  /**
247  * fills the modul toolbar with buttons for modules that are compatible with the currently
248  * selected dataset
249  *
250  * \param module pointer to the currently selected module
251  *
252  */
253  void createCompatibleButtons( std::shared_ptr< WModule > module );
254 
255  /**
256  * Reference to the main window of the application.
257  */
259 
260  /**
261  * Searches the specified tree for all tree items matching the specified module.
262  *
263  * \param module the module uses as search criteria.
264  * \param where in which subtree to search.
265  *
266  * \return a list of all matching items.
267  */
268  std::list< WQtTreeItem* > findItemsByModule( std::shared_ptr< WModule > module, QTreeWidgetItem* where );
269 
270  /**
271  * Searches the tree for all tree items matching the specified module.
272  *
273  * \param module the module uses as search criteria.
274  *
275  * \return a list of all matching items.
276  */
277  std::list< WQtTreeItem* > findItemsByModule( std::shared_ptr< WModule > module );
278 
279  /**
280  * As QTabWidget::clear() does not delete tabs, we have to manage that ourselves.
281  * So this function clears all tabs and deletes the data as well.
282  */
283  void clearAndDeleteTabs();
284 
285 private:
286  WQtTreeWidget* m_moduleTreeWidget; //!< pointer to the tree widget
287 
288  WQtTreeWidget* m_roiTreeWidget; //!< pointer to the tree widget
289 
290  WQtColormapper* m_colormapper; //!< the colormapper control widget
291 
292  QTabWidget* m_tabWidget; //!< pointer to the tab widget
293 
294  WQtModuleHeaderTreeItem* m_tiModules; //!< header for modules
295 
296  WQtRoiHeaderTreeItem* m_tiRois; //!< header for ROIs
297 
298  WQtDockWidget* m_roiDock; //!< the dock widget with the ROI tree
299  WQtDockWidget* m_moduleDock; //!< the dock widget with the module tree
300 
301  /**
302  * The action to remove a module from the tree.
303  */
305 
306  /**
307  * The action to remove a ROI from the tree.
308  */
310 
311  /**
312  * Action which uses a compatibles list (submenu) to connect a selected item with other existing modules.
313  */
315 
316  /**
317  * Action which uses a compatibles list (submenu) to connect a selected item with other prototypes.
318  */
320 
321  /**
322  * Action which uses a list of all modules allowing them to be added without any connections.
323  */
325 
326  /**
327  * Action which disconnects a connector from the module.
328  */
330 
331  /**
332  * List all actions created for applying a prototype. Is needed for m_addModuleAction.
333  *
334  * \note We need to store this action list here as Qt is not able to delete the actions if they get replaced. We need to handle this
335  * manually.
336  */
338 
339  /**
340  * List all actions created for applying a prototype. Is needed for m_connectWithPrototypeAction.
341  *
342  * \note We need to store this action list here as Qt is not able to delete the actions if they get replaced. We need to handle this
343  * manually.
344  */
346 
347  /**
348  * List all actions created for applying a prototype. Is needed for m_connectWithModuleAction.
349  *
350  * \note We need to store this action list here as Qt is not able to delete the actions if they get replaced. We need to handle this
351  * manually.
352  */
354 
355  /**
356  * List all actions created for applying a prototype. Is needed for m_disconnectAction.
357  *
358  * \note We need to store this action list here as Qt is not able to delete the actions if they get replaced. We need to handle this
359  * manually.
360  */
362 
363  /**
364  * If true, a selection change does not cause the property tab to rebuild. This is useful if multiple items get selected at once
365  * programatically.
366  */
368 
369  /**
370  * The WQtCombinerActionList needs some predicate which decides whether to exclude a certain module from the list or not. We use this
371  * predicate here. It is configured internally using a white and blacklist.
372  */
374 
375  /**
376  * Action giving the user fast access to the module config dialog.
377  */
379 
380  /**
381  * The module currently active
382  */
384 
385  /**
386  * The title of the last selected tab in the control panel. This needs to be done using the tab name as the tab index is not consistent(
387  * depending on the number of tabs. Sometimes, some tabs are not visible).
388  */
389  QString m_previousTab;
390 private slots:
391  /**
392  * function that gets called when a tree item is selected, on a new select that tab widget
393  * is rebuilt with the controls provided by the tree item
394  */
395  void selectTreeItem();
396 
397  /**
398  * This de-selects and re-selects the current item. This is useful for updating compatibles bar and similar if data changes
399  */
400  void reselectTreeItem();
401 
402  /**
403  * function that gets called when a tree item is selected, on a new select that tab widget
404  * is rebuilt with the controls provided by the tree item
405  *
406  * \param item the item that has been clicked
407  */
408  void selectRoiTreeItem( QTreeWidgetItem* item );
409 
410  /**
411  * Will be called to select the data module for the given texture.
412  * \param texture the texture currently selected.
413  */
414  void selectDataModule( osg::ref_ptr< WGETexture3D > texture );
415 
416  /**
417  * Search the tree item representing this module
418  *
419  * \param module the module
420  *
421  * \return the item or null if not found
422  */
424 
425  /**
426  * function that builds the property tab
427  *
428  * \param props the properties.
429  * \param infoProps the information properties shown on a separate tab
430  * \param name the name used as title. Can be empty but should not.
431  * \param inject inject this widget to the property tab.
432  */
433  void buildPropTab( std::shared_ptr< WProperties > props, std::shared_ptr< WProperties > infoProps,
434  const std::string& name, QWidget* inject = NULL );
435 
436  /**
437  * Function gets change when a change to a tree item occurs.
438  *
439  * \param item the item
440  * \param column column index
441  */
442  void changeTreeItem( QTreeWidgetItem* item, int column );
443 
444  /**
445  * delete a ROI tree item
446  */
447  void deleteROITreeItem();
448 
449  /**
450  * delete a module
451  */
452  void deleteModule();
453 
454  /**
455  * function to notify the ROI manager of any drag&drop action in the ROI tree
456  *
457  * \param event the drop event
458  */
459  void handleRoiDragDrop( QDropEvent* event );
460 };
461 
462 #endif // WQTCONTROLPANEL_H
This class contains the main window and the layout of the widgets within the window.
Definition: WMainWindow.h:66
std::shared_ptr< WModule > SPtr
Shared pointer to a WModule.
Definition: WModule.h:106
This widget controls the colormapper of openwalnut.
This class represents a list of actions to apply a bunch of modules to others.
container widget for a tree widget with context menu and some control widgets
QAction * m_disconnectAction
Action which disconnects a connector from the module.
void deactivateModuleSelection(bool selectTopmost=true)
Used to clean the GUI from any module specify widgets.
QAction * m_connectWithModuleAction
Action which uses a compatibles list (submenu) to connect a selected item with other existing modules...
void connectSlots()
helper funtion to connect all qt widgets with their functions
WQtDockWidget * getModuleDock() const
Gets the module dock widget.
QAction * m_addModuleAction
Action which uses a list of all modules allowing them to be added without any connections.
void removeRoi(osg::ref_ptr< WROI > roi)
Removes a ROI entry from the control panel.
bool m_ignoreSelectionChange
If true, a selection change does not cause the property tab to rebuild.
std::list< WQtTreeItem * > findItemsByModule(std::shared_ptr< WModule > module, QTreeWidgetItem *where)
Searches the specified tree for all tree items matching the specified module.
WQtDockWidget * m_roiDock
the dock widget with the ROI tree
WQtDatasetTreeItem * addDataset(std::shared_ptr< WModule > module, int subjectId=0)
Adds a dataset entry to any given subject in the tree widget.
WQtModuleConfig & getModuleConfig() const
Returns the module config dialog.
WQtSubjectTreeItem * addSubject(std::string name)
Adds a subject entry to the tree widget.
osg::ref_ptr< WROI > getSelectedRoi()
Returns the currently selected ROI.
virtual bool event(QEvent *event)
Custom event dispatcher.
QAction * m_deleteModuleAction
The action to remove a module from the tree.
void deleteModule()
delete a module
void selectUpperMostEntry()
Selects the uppermost entry in the module tree.
WQtModuleConfig * m_moduleFilterConfig
The WQtCombinerActionList needs some predicate which decides whether to exclude a certain module from...
WQtModuleTreeItem * addModule(std::shared_ptr< WModule > module)
Adds a module to the control panel.
QTabWidget * m_tabWidget
pointer to the tab widget
virtual ~WQtControlPanel()
Default Destructor.
WQtCombinerActionList m_connectWithPrototypeActionList
List all actions created for applying a prototype.
int getFirstSubject()
Helper function to return the first subject id in the tree widget.
void clearAndDeleteTabs()
As QTabWidget::clear() does not delete tabs, we have to manage that ourselves.
WQtDockWidget * m_moduleDock
the dock widget with the module tree
WQtCombinerActionList m_addModuleActionList
List all actions created for applying a prototype.
QAction * getRoiDeleteAction() const
Return the action to delete a selected roi.
WQtModuleHeaderTreeItem * m_tiModules
header for modules
void completeGuiSetup()
Complete own GUI setup.
void handleRoiDragDrop(QDropEvent *event)
function to notify the ROI manager of any drag&drop action in the ROI tree
void reselectTreeItem()
This de-selects and re-selects the current item.
WQtTreeWidget * m_moduleTreeWidget
pointer to the tree widget
WQtTreeWidget * m_roiTreeWidget
pointer to the tree widget
WQtDockWidget * getColormapperDock() const
Gets the colormapper dock.
WMainWindow * m_mainWindow
Reference to the main window of the application.
QAction * toggleViewAction() const
Returns a checkable action that can be used to show or close this dock widget.
void selectDataModule(osg::ref_ptr< WGETexture3D > texture)
Will be called to select the data module for the given texture.
QAction * getMissingModuleAction() const
Returns an action which can be triggered by the user if some module are missing.
QAction * m_deleteRoiAction
The action to remove a ROI from the tree.
void selectTreeItem()
function that gets called when a tree item is selected, on a new select that tab widget is rebuilt wi...
void setActiveModule(WModule::SPtr module, bool forceUpdate=false)
Sets the module which is now active.
WQtDockWidget * getRoiDock() const
Gets the ROI dock widget.
WQtCombinerActionList m_disconnectActionList
List all actions created for applying a prototype.
void changeTreeItem(QTreeWidgetItem *item, int column)
Function gets change when a change to a tree item occurs.
QAction * m_connectWithPrototypeAction
Action which uses a compatibles list (submenu) to connect a selected item with other prototypes.
void createCompatibleButtons(std::shared_ptr< WModule > module)
fills the modul toolbar with buttons for modules that are compatible with the currently selected data...
osg::ref_ptr< WROI > getFirstRoiInSelectedBranch()
Returns the first ROI in the currently selected branch.
void addRoi(osg::ref_ptr< WROI > roi)
Adds a ROI entry to the control panel.
WQtControlPanel(WMainWindow *parent=0)
Constructor.
void deleteROITreeItem()
delete a ROI tree item
WQtRoiHeaderTreeItem * m_tiRois
header for ROIs
int addTabWidgetContent(QWidget *content, WQtPropertyGroupWidget *propContents)
Adds a page to the context widget.
WQtColormapper * m_colormapper
the colormapper control widget
WQtCombinerActionList m_connectWithModuleActionList
List all actions created for applying a prototype.
std::shared_ptr< WModule > getSelectedModule()
Returns the module currently selected in control panel.
QString m_previousTab
The title of the last selected tab in the control panel.
QAction * m_configModuleFilterAction
Action giving the user fast access to the module config dialog.
QTreeWidgetItem * findModuleItem(WModule::SPtr module) const
Search the tree item representing this module.
void selectRoiTreeItem(QTreeWidgetItem *item)
function that gets called when a tree item is selected, on a new select that tab widget is rebuilt wi...
void buildPropTab(std::shared_ptr< WProperties > props, std::shared_ptr< WProperties > infoProps, const std::string &name, QWidget *inject=NULL)
function that builds the property tab
WModule::SPtr m_activeModule
The module currently active.
Tree widget item to represent a dataset in the control panel tree widget.
Advanced QDockWidget.
Definition: WQtDockWidget.h:50
A class which acts as a binary predicate to check exclusion of modules by name using a whitelist and ...
This tree item represents a group of module items.
Tree widget item to represent a module in the control panel tree widget.
Container widget to contain a number of properties for the module context in the control panel.
Header item for ROIs.
tree widget item to represent a subject in the dataset brwoser tree widget
tree widget for the control panel
Definition: WQtTreeWidget.h:34