OptionQWidgetWrapper.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 OPTIONQWIDGETWRAPPER_H
00011 #define OPTIONQWIDGETWRAPPER_H
00012 
00013 #include "OptionShell.h"
00014 
00015 #include <string>
00016 
00017 /**
00018  * \ingroup ShellModule
00019  * This templated class provides a way to implement
00020  * both the Option interface and provide a QWidget
00021  * by writing a single class instead of two.
00022  * This templated class is used by writing a QWidget
00023  * subclass and then doing the following to register the
00024  * plug-in:
00025  *
00026  * @code
00027  *    //assume SampleOption is a subclass of QWidget and
00028  *    //the plug-in belongs to a module that was registered
00029  *    //using REGISTER_MODULE(SampleModule);
00030  *    REGISTER_PLUGIN(SampleModule, SampleOption, OptionQWidgetWrapper<SampleOption>());
00031  * @endcode
00032  *
00033  * The templated argument must meet the following requirements:
00034  *  <ul>
00035  *    <li>Provide a default constructor.</li>
00036  *    <li>Subclass QWidget.</li>
00037  *    <li>Provide a static getName() method. @see PlugIn::getName()</li>
00038  *    <li>Provide a static getOptionName() method. @see Option::getOptionName()</li>
00039  *    <li>Provide a static getDescription() method. @see PlugIn::getDescription()</li>
00040  *    <li>Provide a static getVersion() method. @see PlugIn::getVersion()</li>
00041  *    <li>Provide a static getCreator() method. @see PlugIn::getCreator()</li>
00042  *    <li>Provide a static getCopyright() method. @see PlugIn::getCopyright()</li>
00043  *    <li>Provide a static getShortDescription() method. @see PlugIn::getShortDescription()</li>
00044  *    <li>Provide a static isProduction() method. @see PlugIn::isProduction()</li>
00045  *    <li>Provide an applyChanges() method. @see Option::applyChanges()</li>
00046  *  </ul>
00047  */
00048 template <typename OptionWidget>
00049 class OptionQWidgetWrapper : public OptionShell
00050 {
00051 public:
00052    /**
00053     * Instantiates this option plug-in by
00054     * querying the templated class using
00055     * it's provided static methods.
00056     */
00057    OptionQWidgetWrapper()
00058    {
00059       PlugInShell::setName(OptionWidget::getName());
00060       setOptionName(OptionWidget::getOptionName());   
00061       setDescription(OptionWidget::getDescription());
00062       setVersion(OptionWidget::getVersion());
00063       setCreator(OptionWidget::getCreator());
00064       setCopyright(OptionWidget::getCopyright());
00065       setShortDescription(OptionWidget::getShortDescription());
00066       setProductionStatus(OptionWidget::isProduction());
00067       setDescriptorId(OptionWidget::getDescriptorId());
00068    }
00069 
00070    /**
00071     * Destroys this option plug-in.
00072     */
00073    ~OptionQWidgetWrapper()
00074    {
00075    }
00076 
00077    /**
00078     * Applies the changes by calling applyChanges()
00079     * on the templated class.
00080     */
00081    void applyChanges()
00082    {
00083       OptionWidget* pWidget = dynamic_cast<OptionWidget*>(getStoredWidget());
00084       if (pWidget == NULL)
00085       {
00086          return;
00087       }
00088       pWidget->applyChanges();
00089    }
00090 
00091 protected:
00092    /**
00093     * Creates the option widget by instantiating the
00094     * templated class which must be a subclass of QWidget.
00095     */
00096    QWidget* createOptionsWidget()
00097    {
00098       return new OptionWidget();
00099    }
00100 };
00101 
00102 #endif

Software Development Kit - Opticks 4.9.0 Build 16218