CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkLayoutViewFactory.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Library: CTK
4 
5  Copyright (c) Kitware Inc.
6 
7  Licensed under the Apache License, Version 2.0 (the "License");
8  you may not use this file except in compliance with the License.
9  You may obtain a copy of the License at
10 
11  http://www.apache.org/licenses/LICENSE-2.0.txt
12 
13  Unless required by applicable law or agreed to in writing, software
14  distributed under the License is distributed on an "AS IS" BASIS,
15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  See the License for the specific language governing permissions and
17  limitations under the License.
18 
19 =========================================================================*/
20 
21 #ifndef __ctkLayoutViewFactory_h
22 #define __ctkLayoutViewFactory_h
23 
24 // Qt includes
25 #include <QObject>
26 #include <QDomDocument>
27 class QLayoutItem;
28 class QWidgetItem;
29 
30 // CTK includes
31 #include "ctkWidgetsExport.h"
32 class ctkLayoutViewFactoryPrivate;
33 
42 class CTK_WIDGETS_EXPORT ctkLayoutViewFactory: public QObject
43 {
44  Q_OBJECT
48  Q_PROPERTY(bool useCachedViews READ useCachedViews WRITE setUseCachedViews);
49 public:
51  ctkLayoutViewFactory(QObject* parent = 0);
52 
55 
62  virtual QStringList supportedElementNames()const;
63 
68  virtual bool isElementSupported(QDomElement layoutElement)const;
69 
72  bool useCachedViews()const;
75  void setUseCachedViews(bool cache);
76 
79  virtual void beginSetupLayout();
82  virtual void endSetupLayout();
83 
88  virtual void setupView(QDomElement layoutElement, QWidget* view);
97  virtual QWidget* viewFromXML(QDomElement layoutElement);
108  virtual QList<QWidget*> viewsFromXML(QDomElement layoutElement);
109 
114 protected:
115  QScopedPointer<ctkLayoutViewFactoryPrivate> d_ptr;
116 
119  virtual QWidget* createViewFromXML(QDomElement layoutElement);
123  virtual QList<QWidget*> createViewsFromXML(QDomElement layoutElement);
124 
128  QList<QWidget*> registeredViews(const QDomElement& layoutElement)const;
129 
132  virtual void registerView(QDomElement layoutElement, QWidget* view);
133 
136  virtual void unregisterView(QDomElement layoutElement, QWidget* view);
137 
140  virtual void unregisterView(QWidget* view);
141 
145  QDomElement layoutElement(QWidget* view)const;
146 
147 private:
148  Q_DECLARE_PRIVATE(ctkLayoutViewFactory);
149  Q_DISABLE_COPY(ctkLayoutViewFactory);
150 };
151 
173 template<class T>
175 {
176 public:
177  ctkTemplateLayoutViewFactory(QObject* parent = 0)
178  : ctkLayoutViewFactory(parent)
179  {
180  this->setUseCachedViews(true);
181  }
182  virtual QWidget* createViewFromXML(QDomElement layoutElement){
183  Q_UNUSED(layoutElement);
184  return new T;
185  }
186 };
187 
188 #endif
QDomElement layoutElement(QWidget *view) const
virtual void unregisterView(QWidget *view)
ctkLayoutViewFactory(QObject *parent=0)
Constructor.
QScopedPointer< ctkLayoutViewFactoryPrivate > d_ptr
virtual QList< QWidget * > createViewsFromXML(QDomElement layoutElement)
virtual void setupView(QDomElement layoutElement, QWidget *view)
virtual QWidget * createViewFromXML(QDomElement layoutElement)
virtual void endSetupLayout()
virtual void registerView(QDomElement layoutElement, QWidget *view)
virtual void unregisterView(QDomElement layoutElement, QWidget *view)
QList< QWidget * > registeredViews() const
bool useCachedViews() const
void setUseCachedViews(bool cache)
virtual QList< QWidget * > viewsFromXML(QDomElement layoutElement)
QList< QWidget * > registeredViews(const QDomElement &layoutElement) const
virtual bool isElementSupported(QDomElement layoutElement) const
virtual ~ctkLayoutViewFactory()
Destructor.
virtual void beginSetupLayout()
virtual QWidget * viewFromXML(QDomElement layoutElement)
virtual QStringList supportedElementNames() const
virtual QWidget * createViewFromXML(QDomElement layoutElement)
ctkTemplateLayoutViewFactory(QObject *parent=0)