ctkLayoutFactory.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #ifndef __ctkLayoutFactory_h
  15. #define __ctkLayoutFactory_h
  16. // Qt includes
  17. #include <QMetaObject>
  18. // CTK includes
  19. #include "ctkLayoutManager.h"
  20. class ctkLayoutFactoryPrivate;
  21. /// \ingroup Widgets
  22. /// This class gives the ability to control externally the
  23. /// instantiation of view widgets by registering view factories.
  24. /// Depending on the view XML element in the layout document, the best
  25. /// registered view factory is being used to create and setup the corresponding
  26. /// widget.
  27. /// \sa ctkLayoutManager, ctkViewFactory
  28. class CTK_WIDGETS_EXPORT ctkLayoutFactory: public ctkLayoutManager
  29. {
  30. Q_OBJECT
  31. public:
  32. ctkLayoutFactory(QObject* parent = 0);
  33. explicit ctkLayoutFactory(QWidget* viewport, QObject* parent);
  34. virtual ~ctkLayoutFactory();
  35. using ctkLayoutManager::setLayout;
  36. using ctkLayoutManager::layout;
  37. /// Register a view factory.
  38. /// The factory is prepended to the list of factories.
  39. /// If the factory has no parent, ctkLayoutManager takes ownership.
  40. /// Otherwise you should make sure the factory is not deleted until the
  41. /// factory is unregisted or until the manager is deleted.
  42. /// \sa unregisterViewFactory(), registerViewFactories()
  43. void registerViewFactory(ctkLayoutViewFactory* factory);
  44. /// Unregister a view factory.
  45. /// If the factory is owned by the ctkLayoutManager, the factory is deleted.
  46. /// \sa registerViewFactory(), registerViewFactories()
  47. void unregisterViewFactory(ctkLayoutViewFactory* factory);
  48. /// Return the list of view factories that are registered.
  49. /// \sa registerViewFactory(), unregisterViewFactory()
  50. QList<ctkLayoutViewFactory*> registeredViewFactories()const;
  51. protected:
  52. /// Call beginSetupLayout() and endSetupLayout() on all the registeredfactories.
  53. /// \sa setupView()
  54. virtual void setupLayout();
  55. /// Find the layoutElement factory and call viewFromXML() on it.
  56. /// \sa viewsFromXML(), setupView()
  57. virtual QWidget* viewFromXML(QDomElement layoutElement);
  58. /// Find the layoutElement factory and call viewsFromXML() on it.
  59. /// \sa viewFromXML(), setupView()
  60. virtual QList<QWidget*> viewsFromXML(QDomElement layoutElement);
  61. /// Find the layoutElement factory and setupView() on it.
  62. /// \sa viewFromXML(), viewsFromXML()
  63. virtual void setupView(QDomElement layoutElement, QWidget* view);
  64. /// Return all the registered factories that can handle the layoutElement.
  65. QList<ctkLayoutViewFactory*> viewFactories(QDomElement viewElement)const;
  66. private:
  67. Q_DECLARE_PRIVATE(ctkLayoutFactory);
  68. Q_DISABLE_COPY(ctkLayoutFactory);
  69. };
  70. #endif