WQtControlPanel.h 13.9 KB
Newer Older
wiebel's avatar
wiebel committed
1 2
//---------------------------------------------------------------------------
//
3
// Project: OpenWalnut ( http://www.openwalnut.org )
wiebel's avatar
wiebel committed
4
//
5 6
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
wiebel's avatar
wiebel committed
7
//
wiebel's avatar
wiebel committed
8
// This file is part of OpenWalnut.
wiebel's avatar
wiebel committed
9
//
wiebel's avatar
wiebel committed
10
// OpenWalnut is free software: you can redistribute it and/or modify
wiebel's avatar
wiebel committed
11 12 13 14
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
wiebel's avatar
wiebel committed
15
// OpenWalnut is distributed in the hope that it will be useful,
wiebel's avatar
wiebel committed
16 17 18 19 20
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
wiebel's avatar
wiebel committed
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
wiebel's avatar
wiebel committed
22
//
wiebel's avatar
wiebel committed
23 24
//---------------------------------------------------------------------------

25 26
#ifndef WQTCONTROLPANEL_H
#define WQTCONTROLPANEL_H
27

Sebastian Eichelbaum's avatar
[STYLE]  
Sebastian Eichelbaum committed
28
#include <list>
29
#include <string>
30
#include <vector>
wiebel's avatar
wiebel committed
31 32

#include <QtGui/QDockWidget>
33
#include <QtGui/QSplitter>
34 35 36
#include <QtGui/QTabWidget>
#include <QtGui/QVBoxLayout>
#include <QtGui/QWidget>
37
#include <QtGui/QListWidget>
wiebel's avatar
wiebel committed
38

39 40
#include "core/dataHandler/WDataSet.h"
#include "core/graphicsEngine/WROI.h"
41

42
#include "../WQtModuleConfig.h"
43

44
#include "../WQtCombinerToolbar.h"
45
#include "WQtPropertyGroupWidget.h"
schurade's avatar
schurade committed
46
#include "WQtModuleHeaderTreeItem.h"
Mathias Goldau's avatar
Mathias Goldau committed
47
#include "WQtModuleTreeItem.h"
schurade's avatar
schurade committed
48
#include "WQtRoiHeaderTreeItem.h"
Mathias Goldau's avatar
Mathias Goldau committed
49
#include "WQtSubjectTreeItem.h"
50
#include "WQtTreeWidget.h"
51
#include "../guiElements/WQtDockWidget.h"
52

53
class WMainWindow;
54
class WQtColormapper;
55

wiebel's avatar
wiebel committed
56
/**
57
 * container widget for a tree widget with context menu and some control widgets
wiebel's avatar
wiebel committed
58
 */
59
class WQtControlPanel : public WQtDockWidget
wiebel's avatar
wiebel committed
60
{
61 62
    Q_OBJECT

63
public:
64
    /**
65
     * Constructor.
66 67 68
     *
     * \param parent Parent widget.
     */
69
    explicit WQtControlPanel( WMainWindow* parent = 0 );
wiebel's avatar
wiebel committed
70

71
    /**
72
     * Default Destructor.
73
     */
74
    virtual ~WQtControlPanel();
75

76 77 78 79 80
    /**
     * Complete own GUI setup. This is useful when not all the information is available during construction. Called by the WMainWindow.
     */
    void completeGuiSetup();

81
    /**
82
     * Adds a page to the context widget
schurade's avatar
schurade committed
83 84
     *
     * \param content A widget with controls
85
     * \param propContents The prop group widget.
86 87
     *
     * \return the index of the new tab
88
     */
89
    int addTabWidgetContent( QWidget* content, WQtPropertyGroupWidget* propContents );
90

91
    /**
92
     * Adds a subject entry to the tree widget
schurade's avatar
schurade committed
93 94 95
     *
     * \param name The entry name of the subjectin the tree widget
     * \return A pointer to the tree widget item
96 97
     */
    WQtSubjectTreeItem* addSubject( std::string name );
wiebel's avatar
wiebel committed
98

99
    /**
100
     * Adds a dataset entry to any given subject in the tree widget
schurade's avatar
schurade committed
101 102 103 104 105
     *
     * \param module shared pointer to the module associated with this tree widget entry
     * \param subjectId subject id this dataset belongs to
     *
     * \return A pointer to the tree widget item
106
     */
107
    WQtDatasetTreeItem* addDataset( boost::shared_ptr< WModule > module, int subjectId = 0 );
108

109
    /**
110
     * Adds a module to the control panel.
111 112 113
     *
     * \param module the module to add.
     *
114
     * \return the representation in control panel.
115
     */
116 117
    WQtModuleTreeItem* addModule( boost::shared_ptr< WModule > module );

schurade's avatar
[DOC]  
schurade committed
118
    /**
119
     * Adds a ROI entry to the control panel
schurade's avatar
[DOC]  
schurade committed
120
     *
121
     * \param roi pointer to the ROI representation object
schurade's avatar
[DOC]  
schurade committed
122
     */
123
    void addRoi( osg::ref_ptr< WROI > roi );
schurade's avatar
schurade committed
124

125
    /**
126
     * Removes a ROI entry from the control panel
127
     *
128
     * \param roi pointer to the ROI representation object
129
     */
130
    void removeRoi( osg::ref_ptr< WROI > roi );
131

132
    /**
133
     * helper funtion to connect all qt widgets with their functions
134 135 136
     */
    void connectSlots();

137
    /**
138
     * Returns the module currently selected in control panel.
139 140 141 142 143
     *
     * \return the module.
     */
    boost::shared_ptr< WModule > getSelectedModule();

schurade's avatar
schurade committed
144
    /**
145
     * Returns the currently selected ROI.
schurade's avatar
schurade committed
146
     *
147
     * \return pointer to ROI representation
schurade's avatar
schurade committed
148
     */
149
    osg::ref_ptr< WROI > getSelectedRoi();
schurade's avatar
schurade committed
150

schurade's avatar
schurade committed
151
    /**
152
     * Returns the first ROI in the currently selected branch.
schurade's avatar
schurade committed
153
     *
154
     * \return pointer to ROI representation
schurade's avatar
schurade committed
155
     */
156
    osg::ref_ptr< WROI > getFirstRoiInSelectedBranch();
schurade's avatar
schurade committed
157

158 159 160 161 162 163 164 165 166 167
    /**
     * Returns a checkable action that can be used to show or close this dock widget.
     * The action's text is set to the dock widget's window title.
     *
     * This member function is overwritten to add a keyboard shortcut to this action.
     *
     * \return Modified QAction
     */
    QAction* toggleViewAction() const;

168 169 170 171 172
    /**
     * Selects the uppermost entry in the module tree.
     */
    void selectUpperMostEntry();

173 174 175 176 177
    /**
     * Gets the ROI dock widget.
     *
     * \return the ROI dock.
     */
178
    WQtDockWidget* getRoiDock() const;
179

180 181 182 183 184 185 186
    /**
     * Return the action to delete a selected roi
     *
     * \return the action
     */
    QAction* getRoiDeleteAction() const;

187 188 189 190 191
    /**
     * Gets the module dock widget.
     *
     * \return the module dock
     */
192
    WQtDockWidget* getModuleDock() const;
193

194 195 196 197 198
    /**
     * Gets the colormapper dock
     *
     * \return the dock
     */
199
    WQtDockWidget* getColormapperDock() const;
200

201 202 203 204 205
    /**
     * Returns the module excluder. It then can be used for configuration.
     *
     * \return the module excluder.
     */
206
    WQtModuleConfig& getModuleConfig() const;
207 208 209 210 211 212 213 214

    /**
     * Returns an action which can be triggered by the user if some module are missing.
     *
     * \return the action.
     */
    QAction* getMissingModuleAction() const;

215 216 217 218
    /**
     * Sets the module which is now active. Updates the GUI accordingly. Can be NULL which causes the GUI to remove all module specific stuff.
     *
     * \param module the module to activate
219
     * \param forceUpdate force update even if the module is the same as the current one.
220
     */
221
    void setActiveModule( WModule::SPtr module, bool forceUpdate = false );
222 223 224 225 226 227 228

    /**
     * Used to clean the GUI from any module specify widgets.
     *
     * \param selectTopmost select top element or keep current
     */
    void deactivateModuleSelection( bool selectTopmost = true );
229
protected:
230 231 232 233 234 235 236 237 238 239
    /**
     * Custom event dispatcher. Gets called by QT's Event system every time an event got sent to this widget. This event handler
     * processes several custom events, like WModuleAssocEvent.
     *
     * \param event the event that got transmitted.
     *
     * \return true if the event got handled properly.
     */
    virtual bool event( QEvent* event );

schurade's avatar
schurade committed
240 241
    /**
     * Helper function to return the first subject id in the tree widget
242 243
     *
     * \return index of first subject in tree
schurade's avatar
schurade committed
244 245 246 247
     */
    int getFirstSubject();

    /**
schurade's avatar
[DOC]  
schurade committed
248 249
     * fills the modul toolbar with buttons for modules that are compatible with the currently
     * selected dataset
schurade's avatar
schurade committed
250
     *
schurade's avatar
[DOC]  
schurade committed
251
     * \param module pointer to the currently selected module
252
     *
schurade's avatar
schurade committed
253
     */
254
    void createCompatibleButtons( boost::shared_ptr< WModule > module );
schurade's avatar
schurade committed
255

256 257 258 259
    /**
     * Reference to the main window of the application.
     */
    WMainWindow* m_mainWindow;
260

261
    /**
262
     * Searches the specified tree for all tree items matching the specified module.
263 264
     *
     * \param module the module uses as search criteria.
265
     * \param where in which subtree to search.
266 267 268
     *
     * \return a list of all matching items.
     */
269 270 271 272 273 274
    std::list< WQtTreeItem* > findItemsByModule( boost::shared_ptr< WModule > module, QTreeWidgetItem* where );

    /**
     * Searches the tree for all tree items matching the specified module.
     *
     * \param module the module uses as search criteria.
Robert Frohl's avatar
Robert Frohl committed
275
     *
276 277
     * \return a list of all matching items.
     */
278 279
    std::list< WQtTreeItem* > findItemsByModule( boost::shared_ptr< WModule > module );

280 281 282 283 284 285
    /**
     * As QTabWidget::clear() does not delete tabs, we have to manage that ourselves.
     * So this function clears all tabs and deletes the data as well.
     */
    void clearAndDeleteTabs();

286
private:
287
    WQtTreeWidget* m_moduleTreeWidget; //!< pointer to the tree widget
288 289 290

    WQtTreeWidget* m_roiTreeWidget; //!< pointer to the tree widget

291 292
    WQtColormapper* m_colormapper; //!< the colormapper control widget

schurade's avatar
[DOC]  
schurade committed
293
    QTabWidget* m_tabWidget; //!< pointer to the tab widget
schurade's avatar
schurade committed
294

295 296
    QTabWidget* m_tabWidget2; //!< pointer to the tab widget

297 298
    QSplitter* m_splitter; //!< splitter to have resizable widgets in the control panel

schurade's avatar
[DOC]  
schurade committed
299
    WQtModuleHeaderTreeItem* m_tiModules; //!< header for modules
schurade's avatar
schurade committed
300

301
    WQtRoiHeaderTreeItem* m_tiRois; //!< header for ROIs
schurade's avatar
schurade committed
302

303 304
    bool m_showToolBarText; //!< Show tool bar icons with text

305 306
    WQtDockWidget* m_roiDock;     //!< the dock widget with the ROI tree
    WQtDockWidget* m_moduleDock;  //!< the dock widget with the module tree
307

308 309 310 311 312
    /**
     * The action to remove a module from the tree.
     */
    QAction* m_deleteModuleAction;

313 314 315 316 317
    /**
     * The action to remove a ROI from the tree.
     */
    QAction* m_deleteRoiAction;

318 319 320 321 322 323 324 325 326 327
    /**
     * Action which uses a compatibles list (submenu) to connect a selected item with other existing modules.
     */
    QAction* m_connectWithModuleAction;

    /**
     * Action which uses a compatibles list (submenu) to connect a selected item with other prototypes.
     */
    QAction* m_connectWithPrototypeAction;

328 329 330 331 332
    /**
     * Action which uses a list of all modules allowing them to be added without any connections.
     */
    QAction* m_addModuleAction;

333 334 335 336 337
    /**
     * Action which disconnects a connector from the module.
     */
    QAction* m_disconnectAction;

338 339 340 341 342 343 344 345
    /**
     * List all actions created for applying a prototype. Is needed for m_addModuleAction.
     *
     * \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
     * manually.
     */
    WQtCombinerActionList m_addModuleActionList;

346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
    /**
     * List all actions created for applying a prototype. Is needed for m_connectWithPrototypeAction.
     *
     * \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
     * manually.
     */
    WQtCombinerActionList m_connectWithPrototypeActionList;

    /**
     * List all actions created for applying a prototype. Is needed for m_connectWithModuleAction.
     *
     * \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
     * manually.
     */
    WQtCombinerActionList m_connectWithModuleActionList;

    /**
     * List all actions created for applying a prototype. Is needed for m_disconnectAction.
     *
     * \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
     * manually.
     */
    WQtCombinerActionList m_disconnectActionList;

370 371 372 373 374 375
    /**
     * If true, a selection change does not cause the property tab to rebuild. This is useful if multiple items get selected at once
     * programatically.
     */
    bool m_ignoreSelectionChange;

376 377 378 379 380
    /**
     * Ignore recursive selection update in network editor.
     */
    bool m_ignoreSelectionChangeNWE;

381 382 383 384
    /**
     * The WQtCombinerActionList needs some predicate which decides whether to exclude a certain module from the list or not. We use this
     * predicate here. It is configured internally using a white and blacklist.
     */
385
    WQtModuleConfig* m_moduleExcluder;
386 387 388 389 390 391

    /**
     * Action giving the user fast access to the module config dialog.
     */
    QAction* m_missingModuleAction;

392 393 394 395
    /**
     * The module currently active
     */
    WModule::SPtr m_activeModule;
396 397 398 399 400 401

    /**
     * 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(
     * depending on the number of tabs. Sometimes, some tabs are not visible).
     */
    QString m_previousTab;
402 403
private slots:
    /**
schurade's avatar
schurade committed
404 405
     * function that gets called when a tree item is selected, on a new select that tab widget
     * is rebuilt with the controls provided by the tree item
406 407
     */
    void selectTreeItem();
408

409 410 411 412 413
    /**
     * This de-selects and re-selects the current item. This is useful for updating compatibles bar and similar if data changes
     */
    void reselectTreeItem();

414 415 416
    /**
     * function that gets called when a tree item is selected, on a new select that tab widget
     * is rebuilt with the controls provided by the tree item
417 418
     *
     * \param item the item that has been clicked
419
     */
420
    void selectRoiTreeItem( QTreeWidgetItem* item );
421

422 423 424 425 426 427
    /**
     * Will be called to select the data module for the given texture.
     * \param texture the texture currently selected.
     */
    void selectDataModule( osg::ref_ptr< WGETexture3D > texture );

428 429 430 431 432 433 434 435 436
    /**
     * Search the tree item representing this module
     *
     * \param module the module
     *
     * \return the item or null if not found
     */
    QTreeWidgetItem* findModuleItem( WModule::SPtr module ) const;

437 438 439
    /**
     * function that builds the property tab
     *
440
     * \param props the properties.
441
     * \param infoProps the information properties shown on a separate tab
Sebastian Eichelbaum's avatar
[DOC]  
Sebastian Eichelbaum committed
442
     * \param name the name used as title. Can be empty but should not.
443
     */
444
    void buildPropTab( boost::shared_ptr< WProperties > props, boost::shared_ptr< WProperties > infoProps, const std::string& name );
445

schurade's avatar
schurade committed
446
    /**
447 448 449 450
     * Function gets change when a change to a tree item occurs.
     *
     * \param item the item
     * \param column column index
schurade's avatar
schurade committed
451
     */
452
    void changeTreeItem( QTreeWidgetItem* item, int column );
schurade's avatar
schurade committed
453

schurade's avatar
schurade committed
454
    /**
455
     * delete a ROI tree item
schurade's avatar
schurade committed
456
     */
457
    void deleteROITreeItem();
schurade's avatar
schurade committed
458

459
    /**
460
     * delete a module
461
     */
462
    void deleteModule();
463

schurade's avatar
schurade committed
464
    /**
465
     * function to notify the ROI manager of any drag&drop action in the ROI tree
466 467
     *
     * \param event the drop event
schurade's avatar
schurade committed
468
     */
469
    void handleRoiDragDrop( QDropEvent* event );
wiebel's avatar
wiebel committed
470 471
};

472
#endif  // WQTCONTROLPANEL_H