OpenWalnut  1.5.0dev
WQtTreeItem.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 WQTTREEITEM_H
26 #define WQTTREEITEM_H
27 
28 #include <memory>
29 #include <string>
30 #include <vector>
31 
32 #include <QProgressBar>
33 #include <QTreeWidgetItem>
34 #include <QtCore/QTimer>
35 #include <boost/signals2/connection.hpp>
36 
37 #include "WTreeItemTypes.h"
38 #include "core/kernel/WModule.h"
39 
40 /**
41  * Base class for all items in the control panel tree.
42  */
43 class WQtTreeItem: public QObject,
44  public QTreeWidgetItem
45 {
46  Q_OBJECT
47 
48 public:
49  /**
50  * Constructor creates an empty item.
51  *
52  * \param parent The widget managing this widget
53  * \param module The represented module
54  * \param type the type used for the treeitem. Used to identify the items.
55  */
56  WQtTreeItem( QTreeWidgetItem* parent, WTreeItemType type, std::shared_ptr< WModule > module );
57 
58  /**
59  * Destructor.
60  */
61  virtual ~WQtTreeItem();
62 
63  /**
64  * Get for the module pointer.
65  *
66  * \return the pointer to the module associated with this item.
67  */
69 
70  /**
71  * Returns the name used for this tree item.
72  *
73  * \return the name.
74  */
75  std::string getName();
76 
77  /**
78  * Gets called by the GUI whenever the module was removed from the root container and should now be deleted.
79  */
80  virtual void gotRemoved();
81 
82  /**
83  * The name of the input represented by this item.
84  *
85  * \return handled input
86  */
87  std::string getHandledInput() const;
88 
89  /**
90  * Sets the name of the input represented by this item.
91  *
92  * \param in the input name.
93  */
94  void setHandledInput( std::string in );
95 
96  /**
97  * The name of the output represented by this item.
98  *
99  * \return handled output
100  */
101  std::string getHandledOutput() const;
102 
103  /**
104  * Sets the name of the output represented by this item.
105  *
106  * \param out the output name.
107  */
108  void setHandledOutput( std::string out );
109 
110  /**
111  * Handle changes in check state.
112  */
113  virtual void handleCheckStateChange();
114 
115  /**
116  * Create tooltip for a given module. This can be used by all the widgets needing a tooltip for a module.
117  *
118  * \param module the module to create the tooltip for
119  *
120  * \return the tooltip.
121  */
122  static std::string createTooltip( WModule::SPtr module );
123 public slots:
124 
125  /**
126  * Gets called by m_updateTimer in some interval to update the item state, basing on the state of m_module.
127  */
128  void update();
129 
130 protected:
131  /**
132  * Updates the state of the tree item basing on the module's state.
133  */
134  virtual void updateState();
135 
136  /**
137  * Updates this item in regular intervals.
138  */
139  std::shared_ptr< QTimer > m_updateTimer;
140 
141  /**
142  * Name of the tree item.
143  */
144  std::string m_name;
145 
146  /**
147  * True if the treeitem and the module gets deleted currently.
148  */
150 
151  /**
152  * True if no delete event has been posted yet.
153  */
155 
156  /**
157  * The property containing the name of the module.
158  */
159  WPropString m_nameProp;
160 
161  /**
162  * The name of the input connector represented by this item.
163  */
164  std::string m_handledInput;
165 
166  /**
167  * The output name handled by this item
168  */
169  std::string m_handledOutput;
170 
171 private:
172  /**
173  * The module represented by this tree item.
174  */
175  std::shared_ptr< WModule > m_module;
176 
177  /**
178  * Called when the name property changes.
179  */
180  void nameChanged();
181 
182  /**
183  * The output connector update connections. The NEED to be disconnected on destruction manually!
184  */
185  std::vector< boost::signals2::connection > m_outputUpdateConnections;
186 
187  /**
188  * Called on output-connector update.
189  *
190  * \param connector the connector that was updated.
191  */
192  void slotDataChanged( std::shared_ptr< WModuleConnector > connector );
193 };
194 
195 #endif // WQTTREEITEM_H
std::shared_ptr< WModule > SPtr
Shared pointer to a WModule.
Definition: WModule.h:106
Base class for all items in the control panel tree.
Definition: WQtTreeItem.h:45
std::vector< boost::signals2::connection > m_outputUpdateConnections
The output connector update connections.
Definition: WQtTreeItem.h:185
std::shared_ptr< WModule > m_module
The module represented by this tree item.
Definition: WQtTreeItem.h:175
std::string m_name
Name of the tree item.
Definition: WQtTreeItem.h:144
WModule::SPtr getModule()
Get for the module pointer.
void setHandledOutput(std::string out)
Sets the name of the output represented by this item.
virtual ~WQtTreeItem()
Destructor.
Definition: WQtTreeItem.cpp:99
std::string getHandledOutput() const
The name of the output represented by this item.
std::string getHandledInput() const
The name of the input represented by this item.
std::string getName()
Returns the name used for this tree item.
void nameChanged()
Called when the name property changes.
void slotDataChanged(std::shared_ptr< WModuleConnector > connector)
Called on output-connector update.
bool m_deleteInProgress
True if the treeitem and the module gets deleted currently.
Definition: WQtTreeItem.h:149
virtual void updateState()
Updates the state of the tree item basing on the module's state.
static std::string createTooltip(WModule::SPtr module)
Create tooltip for a given module.
std::shared_ptr< QTimer > m_updateTimer
Updates this item in regular intervals.
Definition: WQtTreeItem.h:139
virtual void gotRemoved()
Gets called by the GUI whenever the module was removed from the root container and should now be dele...
void update()
Gets called by m_updateTimer in some interval to update the item state, basing on the state of m_modu...
WQtTreeItem(QTreeWidgetItem *parent, WTreeItemType type, std::shared_ptr< WModule > module)
Constructor creates an empty item.
Definition: WQtTreeItem.cpp:48
void setHandledInput(std::string in)
Sets the name of the input represented by this item.
std::string m_handledOutput
The output name handled by this item.
Definition: WQtTreeItem.h:169
bool m_needPostDeleteEvent
True if no delete event has been posted yet.
Definition: WQtTreeItem.h:154
std::string m_handledInput
The name of the input connector represented by this item.
Definition: WQtTreeItem.h:164
virtual void handleCheckStateChange()
Handle changes in check state.
WPropString m_nameProp
The property containing the name of the module.
Definition: WQtTreeItem.h:159