Image Component Library (ICL)
GUI.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLQt/src/ICLQt/GUI.h **
10 ** Module : ICLQt **
11 ** Authors: Christof Elbrechter **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 
33 #include <ICLUtils/CompatMacros.h>
34 #include <ICLUtils/SmartPtr.h>
35 #include <ICLUtils/Function.h>
36 #include <ICLQt/DataStore.h>
37 #include <ICLQt/GUIComponents.h>
38 #include <QLayout>
39 #include <QWidget>
40 #include <QApplication>
41 #include <string>
42 #include <vector>
43 #include <iostream>
44 
46 class QLayout;
49 namespace icl{
50  namespace qt{
51 
53  class GUIWidget;
54  class ProxyLayout;
55  class GUIDefinition;
58 
60  class ICLQt_API GUI{
61  private:
63 
64  virtual GUI &operator<<(const std::string &definition);
65 
66  protected:
68  GUI(const std::string &definition, QWidget *parent);
69 
70 
71  public:
74 
76 
78  static void register_widget_type(const std::string &tag, CreatorFunction f);
79 
81  static const int CELLW = 20;
83  static const int CELLH = 20;
84 
86  GUI(QWidget *parent=0);
87 
89  GUI(const GUIComponent &component, QWidget *parent=0);
90 
92  GUI(const GUI &gui,QWidget *parent=0);
93 
95  GUI &operator=(const GUI &other);
96 
98  virtual ~GUI();
99 
101  virtual GUI &operator<<(const GUIComponent &component);
102 
104 
105  virtual GUI &operator<<(const GUI &g);
106 
108  template<class T>
109  inline T &allocValue(const std::string &id, const T&val=T()){
110  return m_oDataStore.allocValue<T>(id,val);
111  }
112 
114  template<class T>
115  inline void release(const std::string &id){
116  m_oDataStore.release<T>(id);
117  }
118 
119  template<class T>
120  T &get(const std::string &id, bool typeCheck=true){
121  return m_oDataStore.getValue<T>(id,typeCheck);
122  }
123 
125  DataStore::Data operator[](const std::string &key){
126  return m_oDataStore.operator[](key);
127  }
128 
130  template<class T>
131  std::vector<T> collect(const std::vector<std::string> &keys){
132  return m_oDataStore.collect<T>(keys);
133  }
134 
136  virtual bool isVisible() const;
137 
139  virtual void create();
140 
142  virtual void show();
143 
145  virtual void hide();
146 
148  virtual void switchVisibility();
149 
152  return m_poWidget;
153  }
154 
156  inline void lockData() {
157  m_oDataStore.lock();
158  }
160  inline void unlockData() {
161  m_oDataStore.unlock();
162  }
164  void waitForCreation();
165 
167  const DataStore &getDataStore() const { return m_oDataStore; }
168 
170 
172 
174 
178 
179 
181 
187  void registerCallback(const Callback &cb, const std::string &handleNamesList, char listDelim=',');
188 
190 
191  void registerCallback(const ComplexCallback &cb, const std::string &handleNamesList, char listDelim=',');
192 
194  void removeCallbacks(const std::string &handleNamesList, char listDelim=',');
195 
197 
201  inline bool isDummy() const { return m_sDefinition == "" || m_sDefinition == "dummy"; }
202 
204  bool hasBeenCreated() const;
205 
207  static inline GUI create_gui_from_string(const std::string &definition, QWidget *parent){
208  return GUI(definition, parent);
209  }
210 
212  std::string createXMLDescription() const;
213 
214  protected:
216  virtual std::string createDefinition() const { return m_sDefinition; }
217 
218  private:
219 
220  static void to_string_recursive(const GUI *gui, std::ostream &str, int level);
221 
222  void create(QLayout *parentLayout,ProxyLayout *proxy, QWidget *parentWidget, DataStore *ds);
223 
225  std::string m_sDefinition;
226  std::vector<GUI*> m_children;
230  QWidget *m_poParent;
231  };
232  } // namespace qt
233 }
234 
static GUI create_gui_from_string(const std::string &definition, QWidget *parent)
legacy creation method (use with care)
Definition: GUI.h:207
The General Function Template.
Definition: Function.h:284
Extension of the associative container MultiTypeMap.
Definition: DataStore.h:47
undocument this line if you encounter any issues!
Definition: Any.h:37
QWidget * m_poParent
Definition: GUI.h:230
Main Class of ICL's GUI creation framework.
Definition: GUI.h:60
ICLQt_API core::Img< T > create(const std::string &name, core::format fmt=icl::core::formatRGB)
create a test image (converted to destination core::format) (affinity for floats)
bool m_bCreated
Definition: GUI.h:229
void lockData()
internally locks the datastore
Definition: GUI.h:156
std::string m_sDefinition
own definition string
Definition: GUI.h:225
GUIWidget * getRootWidget()
returns the root widget of the gui (only avialable after create() or show())
Definition: GUI.h:151
T & get(const std::string &id, bool typeCheck=true)
Definition: GUI.h:120
T & allocValue(const std::string &id, const T &val=T())
wraps the data-stores allocValue function
Definition: GUI.h:109
just a helper class for GUI Layouting
Definition: ProxyLayout.h:43
const DataStore & getDataStore() const
returns the GUI internal dataStore
Definition: GUI.h:167
void release(const std::string &id)
wraps the datastores release function
Definition: GUI.h:115
virtual std::string createDefinition() const
can be overwritten in subclasses (such as ContainerGUIComponent)
Definition: GUI.h:216
utils::Function< void, const std::string & > ComplexCallback
complex callback type that can be registered at GUI components
Definition: GUI.h:177
DataStore::Data operator[](const std::string &key)
returns a Data instance from the datastore
Definition: GUI.h:125
ICLUtils_API std::ostream & operator<<(std::ostream &s, const ConfigFile &cf)
Default ostream operator to put a ConfigFile into a stream.
The GUIComponent class servers as a generic interface for GUI definitions.
Definition: GUIComponent.h:44
GUIWidget * m_poWidget
Definition: GUI.h:227
Abstract class for GUI components.
Definition: GUIWidget.h:52
std::string str(const T &t)
convert a data type into a string using an std::ostringstream instance
Definition: StringUtils.h:136
std::vector< T > collect(const std::vector< std::string > &keys)
collects data from different components at once
Definition: GUI.h:131
utils::Function< void > Callback
simple callback, that can be registered at GUI components
Definition: GUI.h:171
#define ICLQt_API
Definition: CompatMacros.h:178
Arbitrary Data encapsulation type.
Definition: DataStore.h:63
void unlockData()
internally unlocks the data store
Definition: GUI.h:160
std::vector< GUI * > m_children
Definition: GUI.h:226
DataStore m_oDataStore
Definition: GUI.h:228
utils::Function< GUIWidget *, const GUIDefinition & > CreatorFunction
registered widget type creator function
Definition: GUI.h:73
bool isDummy() const
returns whether this GUI is a dummy GUI
Definition: GUI.h:201
ICLQt_API void show(const icl::core::ImgBase &image)
shows an image using TestImages::show