Modifier.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 MODIFIER_H
00011 #define MODIFIER_H
00012 
00013 #include <QtCore/QObject>
00014 
00015 /**
00016  *  Tracks modifications to an object.
00017  *
00018  *  This class stores a modified flag that can be set with setModified() and
00019  *  queried with isModified().  The modified() signal is emitted whenever
00020  *  setModified() is called with a value of \c true.  The attachSignal() method
00021  *  can be called to setup a signal/slot connection where the setModified()
00022  *  method is called whenever the given signal is emitted.
00023  *
00024  *  This class can be used to track modifications in two ways:
00025  *  -# An object can subclass this class to store a modification state and to
00026  *     provide a common modified() signal that can be automatically emitted
00027  *     when other GUI widgets are modified.
00028  *  -# This class can be created by an object to track modifications of another
00029  *     object that does not track its own modifications.
00030  */
00031 class Modifier : public QObject
00032 {
00033    Q_OBJECT
00034 
00035 public:
00036    /**
00037     *  Creates the modifier object.
00038     *
00039     *  The constructor creates the Modifier object in an unmodified state.
00040     */
00041    Modifier() :
00042       mModified(false)
00043    {
00044    }
00045 
00046    /**
00047     *  Attaches a signal to the object that sets the object in a modified
00048     *  state.
00049     *
00050     *  This method connects the given signal to the setModified() slot method
00051     *  to automatically set the object in a modified state whenever the signal
00052     *  is emitted.
00053     *
00054     *  @param   pObject
00055     *           The object that emits the signal.
00056     *  @param   pSignal
00057     *           The signal to connect to the setModified() slot.
00058     *
00059     *  @return  Returns \c true if the signal was successfully connected to the
00060     *           setModified() slot; otherwise returns \c false.
00061     *
00062     *  @see     isModified()
00063     */
00064    bool attachSignal(QObject* pObject, const char* pSignal)
00065    {
00066       return connect(pObject, pSignal, this, SLOT(setModified()));
00067    }
00068 
00069    /**
00070     *  Queries whether the object is in a modified state.
00071     *
00072     *  @return  Returns \c true if the object has been modified as a result of
00073     *           calling setModified() with a value of \c true.  Returns
00074     *           \c false if the object has not been modified since creation or
00075     *           since the last call to setModified() with a value of \c false.
00076     *
00077     *  @see     setModified()
00078     */
00079    bool isModified() const
00080    {
00081       return mModified;
00082    }
00083 
00084 public slots:
00085    /**
00086     *  Sets whether the object is in a modified state.
00087     *
00088     *  This method can be called directly to set or reset the modified state.
00089     *  It can also be called as a result of the signal that is passed into
00090     *  attachSignal() being emitted.
00091     *
00092     *  @param   bModified
00093     *           Set this parameter to \c true to indicate that the object is in
00094     *           a modified state or \c false to indicate that the object is no
00095     *           longer in a modified state.
00096     *
00097     *  @see     isModified()
00098     */
00099    void setModified(bool bModified = true)
00100    {
00101       mModified = bModified;
00102       if (mModified == true)
00103       {
00104          emit modified();
00105       }
00106    }
00107 
00108 signals:
00109    /**
00110     *  Emitted when the object has been modified.
00111     *
00112     *  This signal is automatically emitted when setModified() is called with a
00113     *  value of \c true.
00114     */
00115    void modified();
00116 
00117 private:
00118    Modifier(const Modifier& rhs);
00119    Modifier& operator=(const Modifier& rhs);
00120    bool mModified;
00121 };
00122 
00123 #endif

Software Development Kit - Opticks 4.9.0 Build 16218