瀏覽代碼

Add ctkLayoutFactory and ctkLayoutViewFactory

ctkLayoutFactory gives the ability over ctkLayoutManager to control
externally the instantiation of view widgets by registering view factories.
Depending on the view XML element in the layout document, the best
registered view factory is being used to create and setup the corresponding
widget.
Julien Finet 11 年之前
父節點
當前提交
d9bafba93e

+ 6 - 3
Libs/Widgets/CMakeLists.txt

@@ -94,8 +94,12 @@ set(KIT_SRCS
   ctkIconEnginePlugin.h
   ctkLanguageComboBox.cpp
   ctkLanguageComboBox.h
+  ctkLayoutFactory.cpp
+  ctkLayoutFactory.h
   ctkLayoutManager.cpp
   ctkLayoutManager.h
+  ctkLayoutViewFactory.cpp
+  ctkLayoutViewFactory.h
   ctkMaterialPropertyPreviewLabel.cpp
   ctkMaterialPropertyPreviewLabel.h
   ctkMaterialPropertyWidget.cpp
@@ -147,8 +151,6 @@ set(KIT_SRCS
   ctkSettingsPanel.h
   ctkSignalMapper.cpp
   ctkSignalMapper.h
-  ctkSimpleLayoutManager.cpp
-  ctkSimpleLayoutManager.h
   ctkSizeGrip.cpp
   ctkSizeGrip.h
   ctkSliderWidget.cpp
@@ -237,7 +239,9 @@ set(KIT_MOC_SRCS
   ctkFontButton.h
   ctkIconEnginePlugin.h
   ctkLanguageComboBox.h
+  ctkLayoutFactory.h
   ctkLayoutManager.h
+  ctkLayoutViewFactory.h
   ctkMaterialPropertyPreviewLabel.h
   ctkMaterialPropertyWidget.h
   ctkMatrixWidget.h
@@ -262,7 +266,6 @@ set(KIT_MOC_SRCS
   ctkSettingsDialog.h
   ctkSettingsPanel.h
   ctkSignalMapper.h
-  ctkSimpleLayoutManager.h
   ctkSizeGrip.h
   ctkSliderWidget.h
   ctkTestApplication.h

+ 53 - 64
Libs/Widgets/Testing/Cpp/ctkLayoutManagerTest1.cpp

@@ -26,7 +26,8 @@
 
 // CTK includes
 #include "ctkSliderWidget.h"
-#include "ctkSimpleLayoutManager.h"
+#include "ctkLayoutFactory.h"
+#include "ctkLayoutViewFactory.h"
 
 // STD includes
 #include <iostream>
@@ -73,25 +74,6 @@ QString nestedLayout(
 "</layout>");
 
 /// \ingroup Widgets
-struct ctkCachedInstanciator
-  : public ctkWidgetInstanciator
-{
-  int CreateWidgetCount;
-  QWidgetList CachedWidgets;
-  virtual void beginSetupLayout()
-    {
-    this->CreateWidgetCount = 0;
-    }
-  virtual QWidget* createWidget()
-    {
-    if (this->CreateWidgetCount >= this->CachedWidgets.size())
-      {
-      QWidget* widget = new ctkSliderWidget;
-      this->CachedWidgets.push_back(widget);
-      }
-    return this->CachedWidgets[this->CreateWidgetCount++];
-    }
-};
 
 //-----------------------------------------------------------------------------
 int ctkLayoutManagerTest1(int argc, char * argv [] )
@@ -100,7 +82,7 @@ int ctkLayoutManagerTest1(int argc, char * argv [] )
 
   QWidget viewport;
   viewport.setWindowTitle("Simple layout");
-  ctkSimpleLayoutManager layoutManager;
+  ctkLayoutFactory layoutManager;
 
   layoutManager.setViewport(&viewport);
   if (layoutManager.viewport() != &viewport)
@@ -110,8 +92,9 @@ int ctkLayoutManagerTest1(int argc, char * argv [] )
     return EXIT_FAILURE;
     }
 
-  ctkTemplateInstanciator<QPushButton> pButtonInstanciator;
-  layoutManager.setViewInstanciator(&pButtonInstanciator);
+  ctkTemplateLayoutViewFactory<QPushButton>* pButtonInstanciator=
+    new ctkTemplateLayoutViewFactory<QPushButton>(&viewport);
+  layoutManager.registerViewFactory(pButtonInstanciator);
 
   QDomDocument simpleLayoutDoc("simplelayout");
   bool res = simpleLayoutDoc.setContent(simpleLayout);
@@ -132,7 +115,7 @@ int ctkLayoutManagerTest1(int argc, char * argv [] )
   layoutManager.setLayout(simpleLayoutDoc);
   if (layoutManager.layout() != simpleLayoutDoc)
     {
-    std::cerr << __LINE__ << ": ctkSimpleLayoutManager::setLayout() failed."
+    std::cerr << __LINE__ << ": ctkLayoutFactory::setLayout() failed."
               << std::endl;
     return EXIT_FAILURE;
     }
@@ -140,32 +123,32 @@ int ctkLayoutManagerTest1(int argc, char * argv [] )
 
   QWidget vbox;
   vbox.setWindowTitle("Vertical Box Layout");
-  ctkSimpleLayoutManager vboxLayoutManager;
-  vboxLayoutManager.setViewInstanciator(&pButtonInstanciator);
+  ctkLayoutFactory vboxLayoutManager;
+  vboxLayoutManager.registerViewFactory(pButtonInstanciator);
   vboxLayoutManager.setLayout(vboxLayoutDoc);
   vboxLayoutManager.setViewport(&vbox);
   vbox.show();
 
   QWidget grid;
   grid.setWindowTitle("Grid Layout");
-  ctkSimpleLayoutManager gridLayoutManager;
-  gridLayoutManager.setViewInstanciator(&pButtonInstanciator);
+  ctkLayoutFactory gridLayoutManager;
+  gridLayoutManager.registerViewFactory(pButtonInstanciator);
   gridLayoutManager.setLayout(gridLayoutDoc);
   gridLayoutManager.setViewport(&grid);
   grid.show();
 
   QWidget tab;
   tab.setWindowTitle("Tab Layout");
-  ctkSimpleLayoutManager tabLayoutManager;
-  tabLayoutManager.setViewInstanciator(&pButtonInstanciator);
+  ctkLayoutFactory tabLayoutManager;
+  tabLayoutManager.registerViewFactory(pButtonInstanciator);
   tabLayoutManager.setLayout(tabLayoutDoc);
   tabLayoutManager.setViewport(&tab);
   tab.show();
 
   QWidget nested;
   nested.setWindowTitle("Nested Layout");
-  ctkSimpleLayoutManager nestedLayoutManager;
-  nestedLayoutManager.setViewInstanciator(&pButtonInstanciator);
+  ctkLayoutFactory nestedLayoutManager;
+  nestedLayoutManager.registerViewFactory(pButtonInstanciator);
   nestedLayoutManager.setLayout(nestedLayoutDoc);
   nestedLayoutManager.setViewport(&nested);
   nested.show();
@@ -173,9 +156,10 @@ int ctkLayoutManagerTest1(int argc, char * argv [] )
   // TabToGrid
   QWidget tabToGrid;
   tabToGrid.setWindowTitle("Tab to Grid Layout");
-  ctkCachedInstanciator tabToGridInstanciator;
-  ctkSimpleLayoutManager tabToGridLayoutManager;
-  tabToGridLayoutManager.setViewInstanciator(&tabToGridInstanciator);
+  ctkTemplateLayoutViewFactory<ctkSliderWidget>* tabToGridInstanciator =
+    new ctkTemplateLayoutViewFactory<ctkSliderWidget>(&viewport);
+  ctkLayoutFactory tabToGridLayoutManager;
+  tabToGridLayoutManager.registerViewFactory(tabToGridInstanciator);
   tabToGridLayoutManager.setLayout(tabLayoutDoc);
   tabToGridLayoutManager.setViewport(&tabToGrid);
   tabToGrid.show();
@@ -188,26 +172,29 @@ int ctkLayoutManagerTest1(int argc, char * argv [] )
   QTimer::singleShot(200, &app, SLOT(quit()));
   app.exec();
 
-  if (tabToGridInstanciator.CachedWidgets[0]->isHidden() ||
-      tabToGridInstanciator.CachedWidgets[1]->isHidden() ||
-      tabToGridInstanciator.CachedWidgets[2]->isHidden() ||
-      tabToGridInstanciator.CachedWidgets[3]->isHidden())
+  if (tabToGridInstanciator->registeredViews().count() != 6 ||
+      tabToGridInstanciator->registeredViews()[0]->isHidden() ||
+      tabToGridInstanciator->registeredViews()[1]->isHidden() ||
+      tabToGridInstanciator->registeredViews()[2]->isHidden() ||
+      tabToGridInstanciator->registeredViews()[3]->isHidden())
     {
     std::cout << __LINE__ << " TabToGrid: "
               << "ctkLayoutManager::setupLayout() failed to show/hide widgets"
-              << tabToGridInstanciator.CachedWidgets[0]->isHidden() << " "
-              << tabToGridInstanciator.CachedWidgets[1]->isHidden() << " "
-              << tabToGridInstanciator.CachedWidgets[2]->isHidden() << " "
-              << tabToGridInstanciator.CachedWidgets[3]->isHidden() << std::endl;
+              << tabToGridInstanciator->registeredViews().count() << " "
+              << tabToGridInstanciator->registeredViews()[0]->isHidden() << " "
+              << tabToGridInstanciator->registeredViews()[1]->isHidden() << " "
+              << tabToGridInstanciator->registeredViews()[2]->isHidden() << " "
+              << tabToGridInstanciator->registeredViews()[3]->isHidden() << std::endl;
     return EXIT_FAILURE;
     }
 
   // TabToSimple
   QWidget tabToSimple;
   tabToSimple.setWindowTitle("Tab to Simple Layout");
-  ctkCachedInstanciator tabToSimpleInstanciator;
-  ctkSimpleLayoutManager tabToSimpleLayoutManager;
-  tabToSimpleLayoutManager.setViewInstanciator(&tabToSimpleInstanciator);
+  ctkTemplateLayoutViewFactory<ctkSliderWidget>* tabToSimpleInstanciator =
+    new ctkTemplateLayoutViewFactory<ctkSliderWidget>(&viewport);
+  ctkLayoutFactory tabToSimpleLayoutManager;
+  tabToSimpleLayoutManager.registerViewFactory(tabToSimpleInstanciator);
   //tabToSimpleLayoutManager.setLayout(gridLayoutDoc);
   tabToSimpleLayoutManager.setLayout(tabLayoutDoc);
   tabToSimpleLayoutManager.setViewport(&tabToSimple);
@@ -215,30 +202,32 @@ int ctkLayoutManagerTest1(int argc, char * argv [] )
 
   QTimer::singleShot(200, &app, SLOT(quit()));
   app.exec();
-
   tabToSimpleLayoutManager.setLayout(simpleLayoutDoc);
 
   QTimer::singleShot(200, &app, SLOT(quit()));
   app.exec();
 
-  if (tabToSimpleInstanciator.CachedWidgets[0]->isHidden() ||
-      tabToSimpleInstanciator.CachedWidgets[1]->isVisible() ||
-      tabToSimpleInstanciator.CachedWidgets[2]->isVisible())
+  if (tabToSimpleInstanciator->registeredViews().count() != 3 ||
+      tabToSimpleInstanciator->registeredViews()[0]->isHidden() ||
+      tabToSimpleInstanciator->registeredViews()[1]->isVisible() ||
+      tabToSimpleInstanciator->registeredViews()[2]->isVisible())
     {
     std::cout << __LINE__ << " TabToSimple: "
               << "ctkLayoutManager::setupLayout() failed to show/hide widgets"
-              << tabToSimpleInstanciator.CachedWidgets[0]->isHidden() << " "
-              << tabToSimpleInstanciator.CachedWidgets[1]->isVisible() << " "
-              << tabToSimpleInstanciator.CachedWidgets[2]->isVisible() << std::endl;
+              << tabToSimpleInstanciator->registeredViews().count() << " "
+              << tabToSimpleInstanciator->registeredViews()[0]->isHidden() << " "
+              << tabToSimpleInstanciator->registeredViews()[1]->isVisible() << " "
+              << tabToSimpleInstanciator->registeredViews()[2]->isVisible() << std::endl;
     return EXIT_FAILURE;
     }
 
   // NestedToTab
   QWidget nestedToTab;
   nestedToTab.setWindowTitle("Nested to Tab Layout");
-  ctkCachedInstanciator nestedToTabInstanciator;
-  ctkSimpleLayoutManager nestedToTabLayoutManager;
-  nestedToTabLayoutManager.setViewInstanciator(&nestedToTabInstanciator);
+  ctkTemplateLayoutViewFactory<ctkSliderWidget>* nestedToTabInstanciator =
+    new ctkTemplateLayoutViewFactory<ctkSliderWidget>(&viewport);
+  ctkLayoutFactory nestedToTabLayoutManager;
+  nestedToTabLayoutManager.registerViewFactory(nestedToTabInstanciator);
   nestedToTabLayoutManager.setLayout(nestedLayoutDoc);
   nestedToTabLayoutManager.setViewport(&nestedToTab);
   nestedToTab.show();
@@ -251,17 +240,17 @@ int ctkLayoutManagerTest1(int argc, char * argv [] )
   QTimer::singleShot(200, &app, SLOT(quit()));
   app.exec();
 
-  if (nestedToTabInstanciator.CachedWidgets[0]->isHidden() ||
-      nestedToTabInstanciator.CachedWidgets[1]->isVisible() ||
-      nestedToTabInstanciator.CachedWidgets[2]->isVisible() ||
-      nestedToTabInstanciator.CachedWidgets[3]->isVisible())
+  if (nestedToTabInstanciator->registeredViews()[0]->isHidden() ||
+      nestedToTabInstanciator->registeredViews()[1]->isVisible() ||
+      nestedToTabInstanciator->registeredViews()[2]->isVisible() ||
+      nestedToTabInstanciator->registeredViews()[3]->isVisible())
     {
     std::cout << __LINE__ << " NestedToTab: "
               << "ctkLayoutManager::setupLayout() failed to show/hide widgets"
-              << nestedToTabInstanciator.CachedWidgets[0]->isHidden() << " "
-              << nestedToTabInstanciator.CachedWidgets[1]->isVisible() << " "
-              << nestedToTabInstanciator.CachedWidgets[2]->isVisible() << " "
-              << nestedToTabInstanciator.CachedWidgets[3]->isVisible() << std::endl;
+              << nestedToTabInstanciator->registeredViews()[0]->isHidden() << " "
+              << nestedToTabInstanciator->registeredViews()[1]->isVisible() << " "
+              << nestedToTabInstanciator->registeredViews()[2]->isVisible() << " "
+              << nestedToTabInstanciator->registeredViews()[3]->isVisible() << std::endl;
     return EXIT_FAILURE;
     }
 

+ 180 - 0
Libs/Widgets/ctkLayoutFactory.cpp

@@ -0,0 +1,180 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0.txt
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+// Qt includes
+#include <QDebug>
+#include <QList>
+#include <QWidget>
+
+// CTK includes
+#include "ctkLayoutFactory.h"
+#include "ctkLayoutManager_p.h"
+#include "ctkLayoutViewFactory.h"
+
+//-----------------------------------------------------------------------------
+class ctkLayoutFactoryPrivate: public ctkLayoutManagerPrivate
+{
+public:
+  ctkLayoutFactoryPrivate(ctkLayoutManager& object);
+
+  /// List of factories to generate views from XML element.
+  QList<ctkLayoutViewFactory*> ViewFactories;
+
+  /// Save the factory that was used to generate the view
+  QHash<QWidget*, ctkLayoutViewFactory*> ViewFactory;
+};
+
+//-----------------------------------------------------------------------------
+ctkLayoutFactoryPrivate::ctkLayoutFactoryPrivate(ctkLayoutManager& object)
+  : ctkLayoutManagerPrivate(object)
+{
+}
+
+//-----------------------------------------------------------------------------
+// ctkLayoutFactory
+//-----------------------------------------------------------------------------
+ctkLayoutFactory::ctkLayoutFactory(QObject* parentObject)
+  : ctkLayoutManager(new ctkLayoutFactoryPrivate(*this), 0, parentObject)
+{
+}
+
+//-----------------------------------------------------------------------------
+ctkLayoutFactory::ctkLayoutFactory(QWidget* viewport, QObject* parentObject)
+  : ctkLayoutManager(new ctkLayoutFactoryPrivate(*this), viewport, parentObject)
+{
+}
+
+//-----------------------------------------------------------------------------
+ctkLayoutFactory::~ctkLayoutFactory()
+{
+}
+
+//-----------------------------------------------------------------------------
+void ctkLayoutFactory::registerViewFactory(ctkLayoutViewFactory* factory)
+{
+  Q_D(ctkLayoutFactory);
+  if (!factory)
+    {
+    return;
+    }
+  if (factory->parent() == 0)
+    {
+    factory->setParent(this);
+    }
+  d->ViewFactories.push_front(factory);
+}
+
+//-----------------------------------------------------------------------------
+void ctkLayoutFactory::unregisterViewFactory(ctkLayoutViewFactory* factory)
+{
+  Q_D(ctkLayoutFactory);
+  bool removed = d->ViewFactories.removeOne(factory);
+  if (removed && factory->parent() == this)
+    {
+    factory->deleteLater();
+    }
+}
+
+//-----------------------------------------------------------------------------
+QList<ctkLayoutViewFactory*> ctkLayoutFactory::registeredViewFactories()const
+{
+  Q_D(const ctkLayoutFactory);
+  return d->ViewFactories;
+}
+
+//-----------------------------------------------------------------------------
+void ctkLayoutFactory::setupLayout()
+{
+  Q_D(ctkLayoutFactory);
+  foreach(ctkLayoutViewFactory* factory, d->ViewFactories)
+    {
+    factory->beginSetupLayout();
+    }
+  this->ctkLayoutManager::setupLayout();
+  foreach(ctkLayoutViewFactory* factory, d->ViewFactories)
+    {
+    factory->endSetupLayout();
+    }
+}
+
+//-----------------------------------------------------------------------------
+QWidget* ctkLayoutFactory::viewFromXML(QDomElement viewElement)
+{
+  Q_D(ctkLayoutFactory);
+  QWidget* res = 0;
+  QList<ctkLayoutViewFactory*> factories = this->viewFactories(viewElement);
+  foreach(ctkLayoutViewFactory* factory, factories)
+    {
+    res = factory->viewFromXML(viewElement);
+    if (res)
+      {
+      d->ViewFactory[res] = factory;
+      break;
+      }
+    }
+  return res;
+}
+
+//-----------------------------------------------------------------------------
+QList<QWidget*> ctkLayoutFactory::viewsFromXML(QDomElement viewElement)
+{
+  QWidgetList res;
+  QList<ctkLayoutViewFactory*> factories = this->viewFactories(viewElement);
+  foreach(ctkLayoutViewFactory* factory, factories)
+    {
+    res = factory->viewsFromXML(viewElement);
+    if (!res.isEmpty())
+      {
+      break;
+      }
+    }
+  if (res.isEmpty())
+    {
+    res = this->ctkLayoutManager::viewsFromXML(viewElement);
+    }
+  return res;
+}
+
+//-----------------------------------------------------------------------------
+void ctkLayoutFactory::setupView(QDomElement viewElement, QWidget* view)
+{
+  Q_D(ctkLayoutFactory);
+  ctkLayoutViewFactory* factory = d->ViewFactory[view];
+  if (factory)
+    {
+    factory->setupView(viewElement, view);
+    }
+  this->ctkLayoutManager::setupView(viewElement, view);
+}
+
+//-----------------------------------------------------------------------------
+QList<ctkLayoutViewFactory*> ctkLayoutFactory::viewFactories(QDomElement viewElement)const
+{
+  Q_D(const ctkLayoutFactory);
+  QList<ctkLayoutViewFactory*> res;
+  foreach(ctkLayoutViewFactory* factory, d->ViewFactories)
+    {
+    if (factory->isElementSupported(viewElement))
+      {
+      res << factory;
+      }
+    }
+  return res;
+}

+ 87 - 0
Libs/Widgets/ctkLayoutFactory.h

@@ -0,0 +1,87 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0.txt
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+#ifndef __ctkLayoutFactory_h
+#define __ctkLayoutFactory_h
+
+// Qt includes
+#include <QMetaObject>
+
+// CTK includes
+#include "ctkLayoutManager.h"
+class ctkLayoutFactoryPrivate;
+
+/// \ingroup Widgets
+/// This class gives the ability to control externally the
+/// instantiation of view widgets by registering view factories.
+/// Depending on the view XML element in the layout document, the best
+/// registered view factory is being used to create and setup the corresponding
+/// widget.
+/// \sa ctkLayoutManager, ctkViewFactory
+class CTK_WIDGETS_EXPORT ctkLayoutFactory: public ctkLayoutManager
+{
+  Q_OBJECT
+public:
+  ctkLayoutFactory(QObject* parent = 0);
+  explicit ctkLayoutFactory(QWidget* viewport, QObject* parent);
+  virtual ~ctkLayoutFactory();
+
+  using ctkLayoutManager::setLayout;
+  using ctkLayoutManager::layout;
+
+  /// Register a view factory.
+  /// The factory is prepended to the list of factories.
+  /// If the factory has no parent, ctkLayoutManager takes ownership.
+  /// Otherwise you should make sure the factory is not deleted until the
+  /// factory is unregisted or until the manager is deleted.
+  /// \sa unregisterViewFactory(), registerViewFactories()
+  void registerViewFactory(ctkLayoutViewFactory* factory);
+  /// Unregister a view factory.
+  /// If the factory is owned by the ctkLayoutManager, the factory is deleted.
+  /// \sa registerViewFactory(), registerViewFactories()
+  void unregisterViewFactory(ctkLayoutViewFactory* factory);
+
+  /// Return the list of view factories that are registered.
+  /// \sa registerViewFactory(), unregisterViewFactory()
+  QList<ctkLayoutViewFactory*> registeredViewFactories()const;
+
+protected:
+  /// Call beginSetupLayout() and endSetupLayout() on all the registeredfactories.
+  /// \sa setupView()
+  virtual void setupLayout();
+  /// Find the layoutElement factory and call viewFromXML() on it.
+  /// \sa viewsFromXML(), setupView()
+  virtual QWidget* viewFromXML(QDomElement layoutElement);
+  /// Find the layoutElement factory and call viewsFromXML() on it.
+  /// \sa viewFromXML(), setupView()
+  virtual QList<QWidget*> viewsFromXML(QDomElement layoutElement);
+  /// Find the layoutElement factory and setupView() on it.
+  /// \sa viewFromXML(), viewsFromXML()
+  virtual void setupView(QDomElement layoutElement, QWidget* view);
+
+  /// Return all the registered factories that can handle the layoutElement.
+  QList<ctkLayoutViewFactory*> viewFactories(QDomElement viewElement)const;
+
+private:
+  Q_DECLARE_PRIVATE(ctkLayoutFactory);
+  Q_DISABLE_COPY(ctkLayoutFactory);
+};
+
+#endif

+ 5 - 12
Libs/Widgets/ctkLayoutManager.cpp

@@ -31,6 +31,7 @@
 // CTK includes
 #include "ctkLayoutManager.h"
 #include "ctkLayoutManager_p.h"
+#include "ctkLayoutViewFactory.h"
 
 //-----------------------------------------------------------------------------
 ctkLayoutManagerPrivate::ctkLayoutManagerPrivate(ctkLayoutManager& object)
@@ -302,11 +303,11 @@ QLayoutItem* ctkLayoutManager::processElement(QDomElement element)
     {
     return this->processLayoutElement(element);
     }
-  else if (element.tagName() == "view")
+  else //if (element.tagName() == "view")
     {
     return this->widgetItemFromXML(element);
     }
-  Q_ASSERT(element.tagName() != "layout" && element.tagName() != "view");
+  //Q_ASSERT(element.tagName() != "layout" && element.tagName() != "view");
   return 0;
 }
 
@@ -449,7 +450,7 @@ void ctkLayoutManager::addChildItemToLayout(QDomElement itemElement, QLayoutItem
 //-----------------------------------------------------------------------------
 QWidgetItem* ctkLayoutManager::widgetItemFromXML(QDomElement viewElement)
 {
-  Q_ASSERT(viewElement.tagName() == "view");
+  //Q_ASSERT(viewElement.tagName() == "view");
   QWidget* view = this->viewFromXML(viewElement);
   this->setupView(viewElement, view);
   return new QWidgetItem(view);
@@ -468,7 +469,7 @@ void ctkLayoutManager::setupView(QDomElement viewElement, QWidget* view)
 //-----------------------------------------------------------------------------
 QList<QLayoutItem*> ctkLayoutManager::widgetItemsFromXML(QDomElement viewElement)
 {
-  Q_ASSERT(viewElement.tagName() == "view");
+  ///Q_ASSERT(viewElement.tagName() == "view");
   QList<QLayoutItem*> res;
   QList<QWidget*> views = this->viewsFromXML(viewElement);
   Q_ASSERT(views.count());
@@ -481,14 +482,6 @@ QList<QLayoutItem*> ctkLayoutManager::widgetItemsFromXML(QDomElement viewElement
 }
 
 //-----------------------------------------------------------------------------
-QWidget* ctkLayoutManager::viewFromXML(QDomElement viewElement)
-{
-  Q_UNUSED(viewElement);
-  // default, for testing purpose. Must be reimplemented
-  return new QWidget(0);
-}
-
-//-----------------------------------------------------------------------------
 QList<QWidget*> ctkLayoutManager::viewsFromXML(QDomElement viewElement)
 {
   QList<QWidget*> res;

+ 80 - 3
Libs/Widgets/ctkLayoutManager.h

@@ -30,13 +30,52 @@ class QWidgetItem;
 // CTK includes
 #include "ctkWidgetsExport.h"
 class ctkLayoutManagerPrivate;
+class ctkLayoutViewFactory;
 
 /// \ingroup Widgets
-/// ctkLayoutManager is
+/// ctkLayoutManager is a layout manager that populates a widget (viewport)
+/// with widgets described into an XML document.
+/// To be used, ctkLayoutManager class must be derived and a subset of virtual
+/// methods must be reimplemented to support custom views.
+/// See below an example of layout XML document:
+/// \code
+/// <layout type=\"tab\">
+///  <item>
+///   <layout type=\"horizontal\">
+///    <item><view/></item>
+///    <item>
+///     <layout type=\"vertical\">
+///      <item><view/></item>
+///      <item><view/></item>
+///      <item>
+///       <layout type=\"grid\">
+///        <item row=\"0\" column=\"1\"><view/></item>
+///        <item row=\"1\" column=\"0\"><view/></item>
+///       </layout>
+///      </item>
+///     </layout>
+///    </item>
+///    <item><view/></item>
+///   </layout>
+///  </item>
+///  <item><view name=\"tab2\"/></item>
+///  <item><view name=\"tab3\"/></item>
+/// </layout>
+/// \endcode
+/// The layout elements describe widget containers that embed one or mulitple
+/// items.
+/// The item elements describe widgets or layouts that are children of
+/// layouts.
+/// The view elements can be any type of QWidget. viewFromXML() must be
+/// reimplemented to return the type(s) of QWidget(s) to use wherever the view
+/// element is listed in the layout. The XML element can contain any XML
+/// attribute to be parsed by viewFromXML() method.
+/// \sa ctkSimpleLayoutManager, ctkLayoutViewFactory
 class CTK_WIDGETS_EXPORT ctkLayoutManager: public QObject
 {
   Q_OBJECT
-  /// Spacing between the widgets in a layout
+  /// Spacing between the widgets in all the layouts.
+  /// \sa spacing(), setSpacing()
   Q_PROPERTY(int spacing READ spacing WRITE setSpacing)
 public:
   /// Constructor
@@ -49,7 +88,11 @@ public:
   void setViewport(QWidget* widget);
   Q_INVOKABLE QWidget* viewport()const;
 
+  /// Return the spacing property value.
+  /// \sa spacing
   int spacing()const;
+  /// Set the spacing property value.
+  /// \sa spacing
   void setSpacing(int spacing);
 
   void refresh();
@@ -70,15 +113,49 @@ protected:
   virtual void setLayout(const QDomDocument& newLayout);
   const QDomDocument layout()const;
 
+  /// Create the QLayoutItem for an XML element (e.g. "layout", "view"...)
+  /// and its nested elements.
+  /// \sa processLayoutElement()
   virtual QLayoutItem* processElement(QDomElement element);
+  /// Create the QLayoutItem for a "layout" XML element and its nested elements.
+  /// \sa processElement(), layoutFromXML(), processItemElement(), addChildItemToLayout()
   virtual QLayoutItem* processLayoutElement(QDomElement layoutElement);
+  /// Create the QLayoutItem for a "layout" XML element.
+  /// \sa processLayoutElement()
   virtual QLayoutItem* layoutFromXML(QDomElement layoutElement);
+  /// Create the QLayoutItem(s) of the "item" XML element.
+  /// \sa processItemElement()
   void                 processItemElement(QDomElement layoutElement, QLayoutItem* layoutItem);
+  /// Insert a child item into a layout.
+  /// \sa processLayoutElement()
   virtual void         addChildItemToLayout(QDomElement itemElement, QLayoutItem* childItem, QLayoutItem* layoutItem);
+  /// Utility method that creates, setups and wraps into a QWidgetItem the widget
+  /// of a view XML element.
+  /// \sa widgetsItemsFromXML(), viewFromXML()
   QWidgetItem*         widgetItemFromXML(QDomElement layoutElement);
+  /// Method is called each time a view is made visible into a layout.
+  /// This method can be reimplemented. Sets the widget visibility to true
+  /// by default.
+  /// \sa viewsFromXML()
   virtual void         setupView(QDomElement layoutElement, QWidget* view);
+  /// Create, setup and wrap into QWidgetItems the widgets of a view XML
+  /// element.
   QList<QLayoutItem*>  widgetItemsFromXML(QDomElement layoutElement);
-  virtual QWidget*     viewFromXML(QDomElement layoutElement);
+  /// Virtual method that returns a widget from a "view" layout element.
+  /// You are ensured that the tagName of the element is "view".
+  /// The XML element can contain an arbitrary number of XML attributes.
+  /// Create the widget if needed or reuse it from a previous call.
+  /// \sa viewsFromXML(), setupView()
+  virtual QWidget*     viewFromXML(QDomElement layoutElement) = 0;
+  /// Virtual method that returns a list of widgets from a "view" layout
+  /// element.
+  /// If the parent "item" element has a "multiple=true" XML attribute,
+  /// the "view" layout element can describe many widgets instead of just one
+  /// widget.
+  /// The returned widgets will automatically be layout into their parent
+  /// layout (e.g. boxlayout).
+  /// This method can be reimplemented. Returns viewFromXML() by default.
+  /// \sa viewFromXML(), 
   virtual QList<QWidget*> viewsFromXML(QDomElement layoutElement);
 
 private:

+ 8 - 0
Libs/Widgets/ctkLayoutManager_p.h

@@ -49,10 +49,18 @@ public:
   void clearLayout(QLayout* layout);
   void clearWidget(QWidget* widget, QLayout* parentLayout = 0);
 
+  /// The widget where the layout is populated into.
   QWidget*       Viewport;
+  /// The XML description of the current layout.
   QDomDocument   Layout;
+  /// All the QWidgets in the Viewports. The list contains the
+  /// LayoutWidgets as well as the "items" of the layout.
   QSet<QWidget*> Views;
+  /// All the widgets created by ctkLayoutManager.
+  /// Those widgets are "layout" widgets in a sense that they are simple
+  /// containers or spacers to layout the "views" of the layout.
   QSet<QWidget*> LayoutWidgets;
+  /// Unique spacing used by all the inner layouts.
   int            Spacing;
 };
 

+ 251 - 0
Libs/Widgets/ctkLayoutViewFactory.cpp

@@ -0,0 +1,251 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0.txt
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+// Qt includes
+#include <QDebug>
+#include <QDomElement>
+#include <QList>
+#include <QPair>
+#include <QVector>
+#include <QWidget>
+
+// CTK includes
+#include "ctkLayoutViewFactory.h"
+
+class ctkLayoutViewFactoryPrivate
+{
+  Q_DECLARE_PUBLIC(ctkLayoutViewFactory);
+public:
+  ctkLayoutViewFactoryPrivate(ctkLayoutViewFactory& obj);
+  ~ctkLayoutViewFactoryPrivate();
+  void init();
+
+protected:
+  ctkLayoutViewFactory* q_ptr;
+  typedef QPair<QDomElement, QWidget*> ViewFactory;
+  QVector<ViewFactory> Views;
+  bool UseCachedViews;
+  int NumberOfViewsInCurrentLayout;
+};
+
+//-----------------------------------------------------------------------------
+ctkLayoutViewFactoryPrivate::ctkLayoutViewFactoryPrivate(ctkLayoutViewFactory& object)
+  : q_ptr(&object)
+  , UseCachedViews(false)
+  , NumberOfViewsInCurrentLayout( 0 )
+{
+}
+
+//-----------------------------------------------------------------------------
+ctkLayoutViewFactoryPrivate::~ctkLayoutViewFactoryPrivate()
+{
+}
+
+//-----------------------------------------------------------------------------
+void ctkLayoutViewFactoryPrivate::init()
+{
+}
+
+//-----------------------------------------------------------------------------
+// ctkLayoutViewFactory
+//-----------------------------------------------------------------------------
+ctkLayoutViewFactory::ctkLayoutViewFactory(QObject* parentObject)
+  : QObject(parentObject)
+  , d_ptr(new ctkLayoutViewFactoryPrivate(*this))
+{
+  Q_D(ctkLayoutViewFactory);
+  d->init();
+}
+
+//-----------------------------------------------------------------------------
+ctkLayoutViewFactory::~ctkLayoutViewFactory()
+{
+}
+
+//-----------------------------------------------------------------------------
+QStringList ctkLayoutViewFactory::supportedElementNames()const
+{
+  return QStringList() << "view";
+}
+
+//-----------------------------------------------------------------------------
+bool ctkLayoutViewFactory::isElementSupported(QDomElement layoutElement)const
+{
+  return this->supportedElementNames().contains(layoutElement.tagName());
+}
+
+//-----------------------------------------------------------------------------
+bool ctkLayoutViewFactory::useCachedViews()const
+{
+  Q_D(const ctkLayoutViewFactory);
+  return d->UseCachedViews;
+}
+
+//-----------------------------------------------------------------------------
+void ctkLayoutViewFactory::setUseCachedViews(bool cache)
+{
+  Q_D(ctkLayoutViewFactory);
+  d->UseCachedViews = cache;
+}
+
+//-----------------------------------------------------------------------------
+void ctkLayoutViewFactory::beginSetupLayout()
+{
+  Q_D(ctkLayoutViewFactory);
+  // A new layout is set, reset the number of views being used in the layout.
+  d->NumberOfViewsInCurrentLayout = 0;
+}
+
+//-----------------------------------------------------------------------------
+void ctkLayoutViewFactory::endSetupLayout()
+{
+}
+
+//-----------------------------------------------------------------------------
+void ctkLayoutViewFactory::setupView(QDomElement viewElement, QWidget* view)
+{
+  Q_D(ctkLayoutViewFactory);
+  Q_ASSERT(view);
+  view->setVisible(true);
+  this->registerView(viewElement, view);
+}
+
+//-----------------------------------------------------------------------------
+QWidget* ctkLayoutViewFactory::viewFromXML(QDomElement layoutElement)
+{
+  Q_D(ctkLayoutViewFactory);
+  QWidgetList views = this->registeredViews(layoutElement);
+  // The same XML element has already been processed, reuse the view associated
+  // to it.
+  if (views.count())
+    {
+    return views[0];
+    }
+  // The layout element does not match any existing one, however we can just reuse
+  // one that was registered for a different layout element.
+  if (this->useCachedViews() &&
+      d->NumberOfViewsInCurrentLayout >= 0 && 
+      d->NumberOfViewsInCurrentLayout < d->Views.count())
+    {
+    QWidget* view = d->Views[d->NumberOfViewsInCurrentLayout].second;
+    return view;
+    }
+  return 0;
+}
+
+//-----------------------------------------------------------------------------
+QList<QWidget*> ctkLayoutViewFactory::viewsFromXML(QDomElement layoutElement)
+{
+  QWidgetList views = this->registeredViews(layoutElement);
+  if (views.isEmpty())
+    {
+    QWidget* view = this->viewFromXML(layoutElement);
+    if (view)
+      {
+      views << view;
+      }
+    }
+  return views;
+}
+
+//-----------------------------------------------------------------------------
+QList<QWidget*> ctkLayoutViewFactory::registeredViews()const
+{
+  Q_D(const ctkLayoutViewFactory);
+  QWidgetList res;
+  foreach(ctkLayoutViewFactoryPrivate::ViewFactory p, d->Views)
+    {
+    res << p.second;
+    }
+  return res;
+}
+
+//-----------------------------------------------------------------------------
+QList<QWidget*> ctkLayoutViewFactory
+::registeredViews(const QDomElement& layoutElement)const
+{
+  Q_D(const ctkLayoutViewFactory);
+  QWidgetList res;
+  foreach(ctkLayoutViewFactoryPrivate::ViewFactory p, d->Views)
+    {
+    if (p.first == layoutElement)
+      {
+      res << p.second;
+      }
+    }
+  return res;
+}
+
+//-----------------------------------------------------------------------------
+void ctkLayoutViewFactory::registerView(QDomElement layoutElement, QWidget* view)
+{
+  Q_D(ctkLayoutViewFactory);
+  QDomElement viewElement = this->layoutElement(view);
+  if (!viewElement.isNull())
+    { // replace the current view element with the new layout element.
+    ctkLayoutViewFactoryPrivate::ViewFactory item(viewElement, view);
+    int index = d->Views.indexOf(item);
+    Q_ASSERT(index >= 0);
+    d->Views[index].first = layoutElement;
+    }
+  else
+    {
+    d->Views.push_back(ctkLayoutViewFactoryPrivate::ViewFactory(layoutElement, view));
+    }
+  ++d->NumberOfViewsInCurrentLayout;
+}
+
+//-----------------------------------------------------------------------------
+void ctkLayoutViewFactory::unregisterView(QDomElement layoutElement, QWidget* view)
+{
+  Q_D(ctkLayoutViewFactory);
+  ctkLayoutViewFactoryPrivate::ViewFactory itemToRemove(layoutElement, view);
+  for (int index = d->Views.indexOf(itemToRemove) ; index >= 0 ;
+       index = d->Views.indexOf(itemToRemove))
+    {
+    d->Views.remove(index);
+    }
+}
+
+//-----------------------------------------------------------------------------
+void ctkLayoutViewFactory::unregisterView(QWidget* view)
+{
+  Q_D(ctkLayoutViewFactory);
+  for (QDomElement viewElement = this->layoutElement(view);
+       viewElement.isNull() ;
+       viewElement = this->layoutElement(view))
+    {
+    this->unregisterView(viewElement, view);
+    }
+}
+
+//-----------------------------------------------------------------------------
+QDomElement ctkLayoutViewFactory::layoutElement(QWidget* view)const
+{
+  Q_D(const ctkLayoutViewFactory);
+  for (int index = 0 ; index < d->Views.count(); ++index)
+    {
+    if (d->Views[index].second == view)
+      {
+      return d->Views[index].first;
+      }
+    }
+  return QDomElement();
+}

+ 182 - 0
Libs/Widgets/ctkLayoutViewFactory.h

@@ -0,0 +1,182 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0.txt
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+#ifndef __ctkLayoutViewFactory_h
+#define __ctkLayoutViewFactory_h
+
+// Qt includes
+#include <QObject>
+#include <QDomDocument>
+class QLayoutItem;
+class QWidgetItem;
+
+// CTK includes
+#include "ctkWidgetsExport.h"
+class ctkLayoutViewFactoryPrivate;
+
+/// \ingroup Widgets
+/// ctkLayoutViewFactory is a factory that creates and setups widgets for a
+/// specific view XML element from ctkLayoutManager.
+/// See ctkTemplateLayoutViewFactory for a factory that can instantiate
+/// any Qt widget.
+/// This class is meant to be derived with at least the method viewFromXML()
+/// being overwritten.
+/// \sa ctkLayoutManager, ctkTemplateLayoutViewFactory
+class CTK_WIDGETS_EXPORT ctkLayoutViewFactory: public QObject
+{
+  Q_OBJECT
+  /// This property controls whether the views are cached and reused
+  /// for a different layout. False by default.
+  /// \sa useCachedViews(), setUseCachedViews()
+  Q_PROPERTY(bool useCachedViews READ useCachedViews WRITE setUseCachedViews);
+public:
+  /// Constructor
+  ctkLayoutViewFactory(QObject* parent = 0);
+
+  /// Destructor
+  virtual ~ctkLayoutViewFactory();
+
+  /// Returns the list of element names supported by the factory (e.g. "view",
+  /// "myview"...). Returns ["view"] by default.
+  /// Can be reimplemented to support other element names.
+  /// \warning It is not possible to support the "layout" and "item" XML
+  /// elements.
+  /// \sa isSupportedElement()
+  virtual QStringList supportedElementNames()const;
+
+  /// Returns true if the layout element can be created and setup by the
+  /// factory. By default, returns true if the layout element name is
+  /// contained in supportedElementNames().
+  /// \sa supportedElementNames()
+  virtual bool isElementSupported(QDomElement layoutElement)const;
+
+  /// Return the useCachedViews property value.
+  /// \sa useCachedViews
+  bool useCachedViews()const;
+  /// Set the useCachedViews property value.
+  /// \sa useCachedViews
+  void setUseCachedViews(bool cache);
+
+  /// Called by the layout factory before a layout is setup.
+  /// \sa endSetupLayout()
+  virtual void beginSetupLayout();
+  /// Called by the layout factory after a layout is setup.
+  /// \sa beginSetupLayout()
+  virtual void endSetupLayout();
+
+  /// Method is called each time a view is made visible into a layout.
+  /// This method can be reimplemented. Sets the widget visibility to true
+  /// and register the view by default.
+  /// \sa viewsFromXML()
+  virtual void setupView(QDomElement layoutElement, QWidget* view);
+  /// Virtual method that returns a widget from a "view" layout element.
+  /// You are ensured that the tagName of the element is "view".
+  /// The XML element can contain an arbitrary number of XML attributes.
+  /// Create the widget if needed or reuse a compatible registered view.
+  /// \sa viewsFromXML(), setupView()
+  virtual QWidget* viewFromXML(QDomElement layoutElement);
+  /// Virtual method that returns a list of widgets from a "view" layout
+  /// element.
+  /// If the parent "item" element has a "multiple=true" XML attribute,
+  /// the "view" layout element can describe many widgets instead of just one
+  /// widget.
+  /// The returned widgets will automatically be layout into their parent
+  /// layout (e.g. boxlayout).
+  /// 
+  /// This method can be reimplemented. By default, returns the associated
+  /// registered views or viewFromXML() if no view was registered.
+  /// \sa viewFromXML()
+  virtual QList<QWidget*> viewsFromXML(QDomElement layoutElement);
+
+  /// Return all the widgets that have been registered.
+  /// Used internally for testing.
+  /// \sa registeredViews()
+  QList<QWidget*> registeredViews()const;
+protected:
+  QScopedPointer<ctkLayoutViewFactoryPrivate> d_ptr;
+
+  /// Return the list of widgets that have already been created by
+  /// view(s)FromXML().
+  /// \sa registerView(), unregisterView()
+  QList<QWidget*> registeredViews(const QDomElement& layoutElement)const;
+
+  /// Save the view to reuse it later on (in view(s)FromXML() ).
+  /// \sa registerView(), registeredViews()
+  virtual void registerView(QDomElement layoutElement, QWidget* view);
+
+  /// Forget about the view. The view is not being deleted.
+  /// \sa registerView(), registeredViews()
+  virtual void unregisterView(QDomElement layoutElement, QWidget* view);
+
+  /// Forget about the view. The view is not being deleted.
+  /// \sa registerView(), unregisterView()
+  virtual void unregisterView(QWidget* view);
+
+  /// Return the layout element registered with the view or a null element
+  /// if the view is not registered.
+  /// \sa registerView(), unregisterView()
+  QDomElement layoutElement(QWidget* view)const;
+
+private:
+  Q_DECLARE_PRIVATE(ctkLayoutViewFactory);
+  Q_DISABLE_COPY(ctkLayoutViewFactory);
+};
+
+/// \ingroup Widgets
+/// Instantiate a template QWidget anytime a view element is listed
+/// inside a layout element.
+/// \code
+/// QString tabLayout(
+///   "<layout type=\"tab\">"
+///   " <item><view name=\"tab1\"/></item>"
+///   " <item><view name=\"tab2\"/></item>"
+///   " <item><view name=\"tab3\"/></item>"
+///   "</layout>");
+/// QWidget tab;
+/// tab.setWindowTitle("Tab Layout");
+/// ctkTemplateLayoutViewFactory<QPushButton>* buttonFactory =
+///   new ctkTemplateLayoutViewFactory<QPushButton>(&tab);
+/// ctkLayoutFactory tabLayoutManager;
+/// tabLayoutManager.registerViewFactory(buttonFactory);
+/// tabToSimpleLayoutManager.setLayout(tabLayoutDoc);
+/// tabToSimpleLayoutManager.setViewport(&tab);
+/// tabToSimple.show();
+/// \endcode
+/// \sa ctkLayoutViewFactory
+template<class T>
+class ctkTemplateLayoutViewFactory: public ctkLayoutViewFactory
+{
+public:
+  ctkTemplateLayoutViewFactory(QObject* parent = 0)
+    : ctkLayoutViewFactory(parent)
+  {
+    this->setUseCachedViews(true);
+  }
+  virtual QWidget* viewFromXML(QDomElement layoutElement){
+    QWidget* res = this->ctkLayoutViewFactory::viewFromXML(layoutElement);
+    if (!res)
+      {
+      res = new T;
+      }
+    return res;
+    }
+};
+
+#endif

+ 0 - 125
Libs/Widgets/ctkSimpleLayoutManager.cpp

@@ -1,125 +0,0 @@
-/*=========================================================================
-
-  Library:   CTK
-
-  Copyright (c) Kitware Inc.
-
-  Licensed under the Apache License, Version 2.0 (the "License");
-  you may not use this file except in compliance with the License.
-  You may obtain a copy of the License at
-
-      http://www.apache.org/licenses/LICENSE-2.0.txt
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
-
-=========================================================================*/
-
-// Qt includes
-#include <QDebug>
-#include <QWidget>
-
-// CTK includes
-#include "ctkSimpleLayoutManager.h"
-#include "ctkLayoutManager_p.h"
-
-//-----------------------------------------------------------------------------
-class ctkSimpleLayoutManagerPrivate: public ctkLayoutManagerPrivate
-{
-public:
-  ctkSimpleLayoutManagerPrivate(ctkLayoutManager& object);
-  //QMetaObject ViewMetaObject;
-  ctkWidgetInstanciator* ViewInstanciator;
-};
-
-//-----------------------------------------------------------------------------
-ctkSimpleLayoutManagerPrivate::ctkSimpleLayoutManagerPrivate(ctkLayoutManager& object)
-  : ctkLayoutManagerPrivate(object)
-{
-  //this->ViewMetaObject = QWidget::staticMetaObject;
-  this->ViewInstanciator = 0;
-}
-
-//-----------------------------------------------------------------------------
-// ctkSimpleLayoutManager
-//-----------------------------------------------------------------------------
-ctkSimpleLayoutManager::ctkSimpleLayoutManager(QObject* parentObject)
-  : ctkLayoutManager(new ctkSimpleLayoutManagerPrivate(*this), 0, parentObject)
-{
-}
-
-//-----------------------------------------------------------------------------
-ctkSimpleLayoutManager::ctkSimpleLayoutManager(QWidget* viewport, QObject* parentObject)
-  : ctkLayoutManager(new ctkSimpleLayoutManagerPrivate(*this), viewport, parentObject)
-{
-}
-
-//-----------------------------------------------------------------------------
-ctkSimpleLayoutManager::~ctkSimpleLayoutManager()
-{
-
-}
-/*
-//-----------------------------------------------------------------------------
-void ctkSimpleLayoutManager::setViewMetaObject(const QMetaObject& viewMetaObject)
-{
-  Q_D(ctkSimpleLayoutManager);
-  d->ViewMetaObject = viewMetaObject;
-  this->refresh();
-}
-
-//-----------------------------------------------------------------------------
-const QMetaObject ctkSimpleLayoutManager::viewMetaObject()const
-{
-  Q_D(const ctkSimpleLayoutManager);
-  return d->ViewMetaObject;
-}
-*/
-
-//-----------------------------------------------------------------------------
-void ctkSimpleLayoutManager::setViewInstanciator(ctkWidgetInstanciator* instanciator)
-{
-  Q_D(ctkSimpleLayoutManager);
-  d->ViewInstanciator = instanciator;
-  this->refresh();
-}
-
-//-----------------------------------------------------------------------------
-ctkWidgetInstanciator* ctkSimpleLayoutManager::viewInstanciator()const
-{
-  Q_D(const ctkSimpleLayoutManager);
-  return d->ViewInstanciator;
-}
-
-//-----------------------------------------------------------------------------
-QWidget* ctkSimpleLayoutManager::viewFromXML(QDomElement viewElement)
-{
-  Q_UNUSED(viewElement);
-  Q_D(ctkSimpleLayoutManager);
-  //QObject* newView = d->ViewMetaObject.newInstance();
-  //Q_ASSERT(qobject_cast<QWidget*>(newView));
-  //return qobject_cast<QWidget*>(newView);
-  if (!d->ViewInstanciator)
-    {
-    return 0;
-    }
-  return d->ViewInstanciator->createWidget();
-}
-
-//-----------------------------------------------------------------------------
-void ctkSimpleLayoutManager::setupLayout()
-{
-  Q_D(ctkSimpleLayoutManager);
-  if (d->ViewInstanciator)
-    {
-    d->ViewInstanciator->beginSetupLayout();
-    }
-  this->ctkLayoutManager::setupLayout();
-  if (d->ViewInstanciator)
-    {
-    d->ViewInstanciator->endSetupLayout();
-    }
-}

+ 0 - 74
Libs/Widgets/ctkSimpleLayoutManager.h

@@ -1,74 +0,0 @@
-/*=========================================================================
-
-  Library:   CTK
-
-  Copyright (c) Kitware Inc.
-
-  Licensed under the Apache License, Version 2.0 (the "License");
-  you may not use this file except in compliance with the License.
-  You may obtain a copy of the License at
-
-      http://www.apache.org/licenses/LICENSE-2.0.txt
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
-
-=========================================================================*/
-
-#ifndef __ctkSimpleLayoutManager_h
-#define __ctkSimpleLayoutManager_h
-
-// Qt includes
-#include <QMetaObject>
-
-// CTK includes
-#include "ctkLayoutManager.h"
-class ctkSimpleLayoutManagerPrivate;
-
-/// \ingroup Widgets
-struct ctkWidgetInstanciator
-{
-  virtual void beginSetupLayout(){}
-  virtual void endSetupLayout(){}
-  virtual QWidget* createWidget() = 0;
-};
-
-/// \ingroup Widgets
-template<class T>
-struct ctkTemplateInstanciator:public ctkWidgetInstanciator
-{
-  virtual QWidget* createWidget() {return new T;}
-};
-
-/// \ingroup Widgets
-/// Utility class to access control on the DomDocument layout
-class CTK_WIDGETS_EXPORT ctkSimpleLayoutManager: public ctkLayoutManager
-{
-  Q_OBJECT
-public:
-  ctkSimpleLayoutManager(QObject* parent = 0);
-  explicit ctkSimpleLayoutManager(QWidget* viewport, QObject* parent);
-  virtual ~ctkSimpleLayoutManager();
-
-  using ctkLayoutManager::setLayout;
-  using ctkLayoutManager::layout;
-
-  // Note the default constructor of the class must be declared with
-  // Q_INVOKABLE.
-  //void setViewMetaObject(const QMetaObject& viewMetaObject);
-  //const QMetaObject viewMetaObject()const;
-  void setViewInstanciator(ctkWidgetInstanciator* instanciator);
-  ctkWidgetInstanciator* viewInstanciator()const;
-
-protected:
-  virtual QWidget* viewFromXML(QDomElement viewElement);
-  virtual void setupLayout();
-private:
-  Q_DECLARE_PRIVATE(ctkSimpleLayoutManager);
-  Q_DISABLE_COPY(ctkSimpleLayoutManager);
-};
-
-#endif