MIRA
PropertyEditor.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #ifndef _MIRA_PROPERTYEDITOR_H_
48 #define _MIRA_PROPERTYEDITOR_H_
49 
50 #include <QVariant>
51 #include <QModelIndex>
52 #include <QIcon>
53 #include <QColor>
54 #include <QWidget>
55 #include <QLineEdit>
56 #include <QEvent>
57 #include <QMutex>
58 #include <QWaitCondition>
59 
61 #include <utils/EnumToFlags.h>
62 
64 #include <widgets/TreeViewFilter.h>
65 
66 class QToolButton;
67 
68 namespace mira {
69 
71 
72 class PropertyItemEditor;
73 
75 {
76  Q_OBJECT
77 
78 public:
79  PropertyEditor(QWidget *parent = 0);
80  virtual ~PropertyEditor();
81 
82 public:
83 
84  class Delegate;
85  typedef boost::shared_ptr<Delegate> DelegatePtr;
86 
87 public:
88 
90  PropertyNode* currentProperty();
91 
92 public slots:
93 
98  void clear();
99 
101  void addProperty(PropertyNode* property, QVariant user = QVariant());
102 
104  void removeProperty(PropertyNode* property);
105 
107  void moveUpProperty(PropertyNode* property);
108 
110  void moveDownProperty(PropertyNode* property);
111 
112  QVariant getUser(PropertyNode* property);
113 
114 public:
115 
120  void setHideSingleRootNode(bool hide = true);
121 
123  bool getHideSingleRootNode() const;
124 
125 public:
126 
127  void installFilterShortCut(QWidget* widget, const QString& shortcut = "Ctrl+F");
128 
129  bool getAutoHideFilterBar() const;
130 
131 public slots:
132 
133  void setAutoHideFilterBar(bool hide = true);
134  void showFilter();
135  void hideFilter();
136 
137 public:
138 
140  void setColor(const PropertyNode* property, const QColor& color);
141 
142  QColor getColor(const PropertyNode* property) const;
143 
144 public:
145 
146  std::string getText(const PropertyNode* property) const;
147  QIcon getIcon(const PropertyNode* property) const;
148  QColor getBackgroundColor(const PropertyNode* property) const;
149  QWidget* createEditor(PropertyNode* property, QWidget* parent);
150  std::string getName(const PropertyNode* property);
151 
152 protected:
153 
154  void timerEvent(QTimerEvent*);
155  void customEvent(QEvent*);
156 
157 private slots:
158 
159  void onDestroyedEditorDelegate(QObject*);
160 
161 public:
162 
163  const PropertyNode* getCurrentEditedProperty() const { return mCurrentEditedProperty; }
164 
165 public:
166 
169  virtual void beginAddChildren(const PropertyNode* node, int index, int count);
170  virtual void endAddChildren();
171 
172  virtual void beginRemoveChildren(const PropertyNode* node, int index, int count);
173  virtual void endRemoveChildren();
174 
175  virtual void beginMoveChildren(const PropertyNode* node, int index, int count, int destination);
176  virtual void endMoveChildren();
177 
179 private:
180 
181  struct AddRemoveChildEvent : public QEvent
182  {
183  static const QEvent::Type typeID;
184 
185  enum EventSubType {
186  BEGIN_ADD,
187  END_ADD,
188  BEGIN_REMOVE,
189  END_REMOVE,
190  BEGIN_MOVE,
191  END_MOVE
192  };
193 
194  AddRemoveChildEvent(EventSubType iSubtype, const PropertyNode* iNode = NULL,
195  int iIndex = 0, int iCount = 1,
196  bool iFirst = false, int iDestination = -1)
197  : QEvent(typeID), subtype(iSubtype), node(iNode),
198  index(iIndex), count(iCount), first(iFirst), destination(iDestination) {}
199 
200  EventSubType subtype;
201  const PropertyNode* node;
202  int index;
203  int count;
204  bool first;
205  int destination;
206  };
207 
208 public:
209 
210  const static QColor lightBlue;
211  const static QColor lightRed;
212  const static QColor lightGreen;
213  const static QColor lightYellow;
214  const static QColor lightPurple;
215 
216 private:
217 
218  class DelegateRegistry;
219  class Model;
220  class TreeView;
221  class ItemDelegate;
222 
223  //friend class DelegateRegistry;
224  friend class Model;
225  friend class TreeView;
226  friend class ItemDelegate;
227  friend class PropertyItemEditor;
228 
229  TreeView* mTreeView;
230  Model* mModel;
231  ItemDelegate* mItemDelegate;
232 
233  TreeViewFilter* mFilter;
234 
235  std::map<const PropertyNode*, QColor> mColorMap;
236 
237  int mUpdateTimerId;
238  bool mHideSingleRootNode;
239 
240  PropertyNode* mCurrentEditedProperty;
241 
242  QMutex mPropertyNodeListenerMutex;
243  QWaitCondition mPropertyNodeListenerCondition;
244  QList<QPersistentModelIndex> mPopulatingIndex;
245 };
246 
248 
259 class MIRA_GUI_WIDGETS_EXPORT PropertyEditor::Delegate : public Object
260 {
261  MIRA_ABSTRACT_OBJECT(Delegate)
262 public:
263 
265  typedef std::list<SupportedType> SupportedTypes;
266 
268  {
269  enum Flags {
271  TEXT = 0x01,
272 
274  ICON = 0x02,
275 
277  COLOR = 0x04,
278 
280  EDITOR = 0x08,
281 
283  DIALOG = 0x10,
284 
286  NAME = 0x20,
287  };
289 
290 
291  SupportedType(const Typename& iType, Flags iFlags) :
292  type(iType), flags(iFlags) {}
293 
294  Typename type; // the typename of the type
295 
297 
298  operator SupportedTypes()
299  {
300  SupportedTypes list;
301  list.push_back(*this);
302  return list;
303  }
304 
306  list.push_back(type);
307  return list;
308  }
309  };
310 
311  template <typename Type>
313  return SupportedType(typeName<Type>(), flags);
314  }
315 
316  virtual SupportedTypes supportedTypes() const = 0;
317 
321  virtual std::string getText(const PropertyNode* property) { return std::string(); }
322 
323  virtual QIcon getIcon(const PropertyNode* property) { return QIcon(); }
324 
325  virtual QColor getBackgroundColor(const PropertyNode* property) { return QColor(); }
326 
327  virtual QWidget* createEditor(PropertyNode* property, QWidget* parent) { return NULL; }
328 
329  virtual bool execDialog(PropertyNode* property, QWidget* parent) { return false; }
330 
331  virtual std::string getName(const PropertyNode* property) { return property->name(); }
332 };
333 
335 
337 {
338  Q_OBJECT
339 public:
340 
341  PropertyItemEditor(PropertyEditor* editor, QWidget* parent,
342  PropertyNode* property,
343  PropertyEditor::DelegatePtr editorDelegate,
344  PropertyEditor::DelegatePtr dialogDelegate);
345 
346  bool eventFilter(QObject *obj, QEvent *e);
347 
348 private slots:
349 
350  void buttonClicked();
351 
352 private:
353 
354  PropertyEditor* mEditor;
355  PropertyNode* mProperty;
356  QToolButton* mButton;
357  PropertyEditor::DelegatePtr mDialogDelegate;
358 
359 };
360 
362 
363 }
364 
365 #endif
#define MIRA_GUI_WIDGETS_EXPORT
Definition: GuiWidgetsExports.h:61
friend SupportedTypes operator+(SupportedTypes list, const SupportedType &type)
Definition: PropertyEditor.h:305
Abstract base class for all derived property node classes.
Definition: PropertyNode.h:202
static const QColor lightGreen
Definition: PropertyEditor.h:212
static const QColor lightPurple
Definition: PropertyEditor.h:214
Flags flags
Definition: PropertyEditor.h:296
boost::shared_ptr< Delegate > DelegatePtr
Definition: PropertyEditor.h:84
Declaration and implementation of the property node hierarchy.
Macros for generating logical operators for using enum values as flags.
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
std::string Typename
Definition: Typename.h:60
Definition: PropertyNode.h:430
virtual QWidget * createEditor(PropertyNode *property, QWidget *parent)
Definition: PropertyEditor.h:327
Definition: PropertyEditor.h:267
virtual std::string getText(const PropertyNode *property)
Returns text for a text label.
Definition: PropertyEditor.h:321
#define MIRA_ENUM_TO_FLAGS_INCLASS(EnumType)
Macro that can be used with enums that contain flags.
Definition: EnumToFlags.h:143
SupportedType(const Typename &iType, Flags iFlags)
Definition: PropertyEditor.h:291
#define MIRA_ABSTRACT_OBJECT(classIdentifier)
Use this MACRO instead of MIRA_OBJECT to declare the class as abstract.
Definition: FactoryMacros.h:239
virtual QColor getBackgroundColor(const PropertyNode *property)
Definition: PropertyEditor.h:325
virtual QIcon getIcon(const PropertyNode *property)
Definition: PropertyEditor.h:323
GUI export macro declaration.
PropertyHint type(const std::string &t)
Sets the attribute "type" to the specified value.
Definition: PropertyHint.h:295
Flags
Definition: PropertyEditor.h:269
The object class acts as a generic base class for classes which should be used with the classFactory...
Definition: Object.h:144
Filter widget containing an line edit that filters the elements of an assigned TreeView.
Definition: PropertyEditor.h:336
const PropertyNode * getCurrentEditedProperty() const
Definition: PropertyEditor.h:163
Typename type
Definition: PropertyEditor.h:294
static SupportedType makeSupportedType(SupportedType::Flags flags)
Definition: PropertyEditor.h:312
static const QColor lightBlue
Definition: PropertyEditor.h:210
Provides display and editing facilities for property items in the editor.
Definition: PropertyEditor.h:74
static const QColor lightRed
Definition: PropertyEditor.h:211
virtual std::string getName(const PropertyNode *property)
Definition: PropertyEditor.h:331
std::list< SupportedType > SupportedTypes
Definition: PropertyEditor.h:264
static const QColor lightYellow
Definition: PropertyEditor.h:213
Definition: TreeViewFilter.h:64
virtual bool execDialog(PropertyNode *property, QWidget *parent)
Definition: PropertyEditor.h:329