PropertiesQWidgetWrapper.h

Go to the documentation of this file.
00001 /*
00002  * The information in this file is
00003  * Copyright(c) 2007 Ball Aerospace & Technologies Corporation
00004  * and is subject to the terms and conditions of the
00005  * GNU Lesser General Public License Version 2.1
00006  * The license text is available from   
00007  * http://www.gnu.org/licenses/lgpl.html
00008  */
00009 
00010 #ifndef PROPERTIESQWIDGETWRAPPER_H
00011 #define PROPERTIESQWIDGETWRAPPER_H
00012 
00013 #include "PropertiesShell.h"
00014 
00015 #include <string>
00016 
00017 /**
00018  *  \ingroup ShellModule
00019  *  A plug-in that both implements the Properties interface and provides a
00020  *  QWidget.
00021  *
00022  *  This templated class is used by writing a QWidget subclass and
00023  *  then doing the following to register the plug-in:
00024  *
00025  * @code
00026  *    //assume SampleProperties is a subclass of QWidget and
00027  *    //the plug-in belongs to a module that was registered
00028  *    //using REGISTER_MODULE(SampleModule);
00029  *    REGISTER_PLUGIN(SampleModule, SampleProperties, PropertiesQWidgetWrapper<SampleProperties>());
00030  * @endcode
00031  *
00032  *  The templated argument must meet the following requirements:
00033  *  - Subclasses QWidget.
00034  *  - Provides a default constructor.
00035  *  - Provides a static getName() method.  @see PlugIn::getName()
00036  *  - Provides a static getPropertiesName() method.  @see Properties::getPropertiesName()
00037  *  - Provides a static getDescription() method.  @see PlugIn::getDescription()
00038  *  - Provides a static getVersion() method.  @see PlugIn::getVersion()
00039  *  - Provides a static getCreator() method.  @see PlugIn::getCreator()
00040  *  - Provides a static getCopyright() method.  @see PlugIn::getCopyright()
00041  *  - Provides a static getShortDescription() method.  @see PlugIn::getShortDescription()
00042  *  - Provides a static isProduction() method.  @see PlugIn::isProduction()
00043  *  - Provides an applyChanges() method.  @see Properties::applyChanges()
00044  */
00045 template <typename PropertiesWidget>
00046 class PropertiesQWidgetWrapper : public PropertiesShell
00047 {
00048 public:
00049    /**
00050     *  Instantiates this properties plug-in by querying the templated class
00051     *  using its provided static methods.
00052     */
00053    PropertiesQWidgetWrapper()
00054    {
00055       PlugInShell::setName(PropertiesWidget::getName());
00056       setPropertiesName(PropertiesWidget::getPropertiesName());
00057       setDescription(PropertiesWidget::getDescription());
00058       setVersion(PropertiesWidget::getVersion());
00059       setCreator(PropertiesWidget::getCreator());
00060       setCopyright(PropertiesWidget::getCopyright());
00061       setShortDescription(PropertiesWidget::getShortDescription());
00062       setProductionStatus(PropertiesWidget::isProduction());
00063       setDescriptorId(PropertiesWidget::getDescriptorId());
00064    }
00065 
00066    /**
00067     *  Destroys this properties plug-in.
00068     */
00069    ~PropertiesQWidgetWrapper()
00070    {
00071    }
00072 
00073    /**
00074     *  Initializes the widget by calling initialize() on the templated class.
00075     *
00076     *  @param   pItem
00077     *           The session item for which to initialize the widget's values.
00078     *
00079     *  @return  Returns \c true if the widget was successfully initialized from
00080     *           the given session item; otherwise returns \c false.  If this
00081     *           method returns \c false, the widget is not added to the
00082     *           properties dialog.
00083     */
00084    bool initialize(SessionItem* pItem)
00085    {
00086       PropertiesWidget* pWidget = dynamic_cast<PropertiesWidget*>(getWidget());
00087       if (pWidget != NULL)
00088       {
00089          return pWidget->initialize(pItem);
00090       }
00091 
00092       return false;
00093    }
00094 
00095    /**
00096     *  Applies the changes in the widget.
00097     *
00098     *  This method is called when the user clicks the OK or Apply buttons in
00099     *  the properties dialog.  It applies the changes in the widget by calling
00100     *  applyChanges() on the templated class.  The applyChanges() method of the
00101     *  templated class should return \c true if all changes were successfully
00102     *  applied to the object.  It should also return \c true if no updates need
00103     *  to be made.
00104     *
00105     *  @return  This method returns the value returned from applyChanges() of
00106     *           the templated class or \c NULL if the widget has not been
00107     *           created.  If \c false is returned, the widget will be activated
00108     *           in the properties dialog if necessary and the dialog will not
00109     *           be closed if the OK button was clicked.
00110     */
00111    bool applyChanges()
00112    {
00113       PropertiesWidget* pWidget = dynamic_cast<PropertiesWidget*>(getWidget());
00114       if (pWidget != NULL)
00115       {
00116          return pWidget->applyChanges();
00117       }
00118 
00119       return false;
00120    }
00121 
00122 protected:
00123    /**
00124     *  Creates the properties widget.
00125     *
00126     *  This method creates the properties widget by directly instantiating the
00127     *  templated class, which must be a subclass of QWidget.
00128     */
00129    QWidget* createWidget()
00130    {
00131       return new PropertiesWidget();
00132    }
00133 };
00134 
00135 #endif

Software Development Kit - Opticks 4.9.0 Build 16218