Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

RangeControl.h

Go to the documentation of this file.
00001 
00017 #ifndef RANGECONTROL_H
00018 #define RANGECONTROL_H
00019 
00020 
00021 #include <Midad/Util/Undoable.h>
00022 #include <Midad/Util/Range.h>
00023 #include <Midad/Util/Signals.h>
00024 
00025 template<class TYPE>
00026 class RangeControl : public Undoable, public SigC::Object
00027 {
00028 
00029 public:
00030 
00031     RangeControl(UndoHistory* history = 0, Range<TYPE>* range = 0)
00032         : fHistory(history), fRange(range), fBlockHistory(false) { 
00033         if (!fHistory) fHistory = SigC::manage(new UndoHistory);
00034         if (!fRange) fRange = SigC::manage(new Range<TYPE>); 
00035     }
00036 
00037 #if 0
00038     // copy constructor, assignment:
00039     RangeControl(const RangeControl<TYPE>& rhs) 
00040         : fHistory(rhs.fHistory), fRange(rhs.fRange){ }
00041     RangeControl& operator=(const RangeControl<TYPE>& that) {
00042         if (this == &that) return *this;
00043         this->fRange = that.fRange;
00044         this->fHistory = that.fHistory;
00045         return *this;
00046     }
00047 #endif
00048 
00049     virtual ~RangeControl() {}
00050 
00051     // Access current ranges values, setters add to the history
00052     void Set(TYPE min, TYPE max) {
00053         if (!fBlockHistory) fHistory->Store(*this);
00054         fRange->Set(min,max);
00055     }
00056     void SetMin(TYPE min) {
00057         if (!fBlockHistory) fHistory->Store(*this);
00058         fRange->SetMin(min);
00059     }
00060     void SetMax(TYPE max) {
00061         if (!fBlockHistory) fHistory->Store(*this);
00062         fRange->SetMax(max);
00063     }
00064     void Apply(Range<TYPE>* r) {
00065         if (!fBlockHistory) fHistory->Store(*this);
00066         fRange->Set(r->Min(),r->Max());
00067     }
00068 
00069 //    void Get(TYPE& min, TYPE& max) const { fRange->Get(min,max); }
00070 //    TYPE Min(void) const { return fRange->Min(); }
00071 //    TYPE Max(void) const { return fRange->Max(); }
00072 
00073     // Change which Range is used.  Nothing is known here about what
00074     // Range signals may be connected, nor is any signal emitted to
00075     // announce this change.  The old range is held in the history and
00076     // will be restored if an Undo() is called.  The range passed in
00077     // is held in a SigC::Ptr<> so understands manage().
00078     void UseRange(Range<TYPE>* range) {
00079         using namespace SigC;
00080         UndoItem ui(*this, 
00081                     SigC::bind(SigC::slot(*this,&RangeControl::UseRange),
00082                                fRange));
00083         fHistory->Store(ui);
00084         fRange = range;
00085     }
00086         
00087 
00088     Range<TYPE>& GetRange() { return *fRange; }
00089 
00090     // Undoable implementation
00091     UndoMemento GetMemento() {
00092         using namespace SigC;
00093         return bind(slot(*fRange,&Range<TYPE>::SetState),fRange->GetState());
00094     }
00095 
00096     void StartCompound() { 
00097         fHistory->Store(*this);
00098         fBlockHistory = true;
00099     }
00100     void StopCompound() {
00101         fBlockHistory = false;
00102     }
00103         
00104 
00105 private:
00106     SigC::Ptr<UndoHistory> fHistory;
00107     SigC::Ptr<Range<TYPE> > fRange;
00108     bool fBlockHistory;
00109 };                              // end of class RangeControl
00110 
00111 
00112 
00113 #endif  // RANGECONTROL_H

Generated on Mon Nov 23 05:28:08 2009 for loon by  doxygen 1.3.9.1