| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 | 
							- /*=========================================================================
 
-   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);
 
-     d->Views.insert(view);
 
-     }
 
-   else
 
-     {
 
-     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;
 
- }
 
 
  |