CSelectionParam.h
Go to the documentation of this file.
1 #ifndef iprm_CSelectionParam_included
2 #define iprm_CSelectionParam_included
3 
4 
5 // Qt includes
6 #include <QtCore/QMap>
7 
8 // ACF includes
10 #include <iser/ISerializable.h>
11 #include <iprm/ISelectionParam.h>
12 #include <iprm/IOptionsList.h>
13 
14 
15 namespace iprm
16 {
17 
18 
22 class CSelectionParam: virtual public ISelectionParam
23 {
24 public:
26 
30  void SetSelectionConstraints(const IOptionsList* constraintsPtr);
31 
35  void SetSubselection(int selectionIndex, ISelectionParam* selectionPtr);
36 
40  bool SetSelectedOptionById(const QByteArray& selectedOptionId);
41 
45  int GetOptionIndexById(const QByteArray& optionId) const;
46 
51 
52  // reimplemented (iprm::ISelectionParam)
53  virtual const IOptionsList* GetSelectionConstraints() const;
54  virtual int GetSelectedOptionIndex() const;
55  virtual bool SetSelectedOptionIndex(int index);
56  virtual ISelectionParam* GetSubselection(int index) const;
57 
58  // reimplemented (iser::ISerializable)
59  virtual bool Serialize(iser::IArchive& archive);
60 
61  // reimplemented (istd::IChangeable)
62  virtual bool CopyFrom(const istd::IChangeable& object, CompatibilityMode mode = CM_WITHOUT_REFS);
64 
65 protected:
69  int CalcIndexFromId(const QByteArray& optionId, int suggestedIndex = NO_SELECTION) const;
73  bool SyncIndexWithId();
74 
79  class ConstraintsObserver: public imod::TSingleModelObserverBase<iprm::IOptionsList>
80  {
81  public:
82  explicit ConstraintsObserver(CSelectionParam& parent);
83 
84  // reimplemented (imod::TSingleModelObserverBase<iprm::IOptionsList>)
85  virtual void OnUpdate(const istd::IChangeable::ChangeSet& changeSet);
86 
87  private:
88  CSelectionParam& m_parent;
89  };
90 
91 private:
92  int m_selectedOptionIndex;
93  QByteArray m_selectedOptionId;
94 
95  typedef QMap<int, iprm::ISelectionParam*> SubselectionMap;
96  SubselectionMap m_subselectionMap;
97 
98  const IOptionsList* m_constraintsPtr;
99  ConstraintsObserver m_constraintsObserver;
100 };
101 
102 
103 } // namespace iprm
104 
105 
106 #endif // !iprm_CSelectionParam_included
107 
108 
int CalcIndexFromId(const QByteArray &optionId, int suggestedIndex=NO_SELECTION) const
Calculate optimal index based on current selected index and ID.
int GetOptionIndexById(const QByteArray &optionId) const
Get index of an option by ID.
bool SyncIndexWithId()
Synchronize current index to optimal one.
External references are simple ignored.
Definition: IChangeable.h:197
CompatibilityMode
Control how relationship betweeen objects are interpreted.
Definition: IChangeable.h:186
void SetSelectionConstraints(const IOptionsList *constraintsPtr)
Set selection constraints for this selection object.
ConstraintsObserver(CSelectionParam &parent)
virtual istd::IChangeable * CloneMe(CompatibilityMode mode=CM_WITHOUT_REFS) const
Make a copy of this object.
Constraints of selection from set of possibilities.
Definition: IOptionsList.h:22
Basic implementation for a single model observer with binding to concrete data object interface...
void SetSubselection(int selectionIndex, ISelectionParam *selectionPtr)
Set sub-selection for a given option index.
ISelectionParam * GetActiveSubselection() const
Get sub-selection for the currently selected option.
virtual bool Serialize(iser::IArchive &archive)
Load or store state of this object as a archive stream.
virtual bool CopyFrom(const istd::IChangeable &object, CompatibilityMode mode=CM_WITHOUT_REFS)
Copy this object from another one.
virtual bool SetSelectedOptionIndex(int index)
Set index of selected option.
virtual int GetSelectedOptionIndex() const
Get selected index.
Represent input/output persistence archive.
Definition: IArchive.h:30
Common interface for data model objects, which can be changed.
Definition: IChangeable.h:24
Basic implementation of selection parameter.
virtual ISelectionParam * GetSubselection(int index) const
Get subselection for specified option.
virtual void OnUpdate(const istd::IChangeable::ChangeSet &changeSet)
Called on update of observed model.
Set of change flags (its IDs).
Definition: IChangeable.h:30
Interface allowing to select single option from list of options.
virtual const IOptionsList * GetSelectionConstraints() const
Get constraints of this parameter.
bool SetSelectedOptionById(const QByteArray &selectedOptionId)
Set selection index according to a given option ID.

© 2007-2017 Witold Gantzke and Kirill Lepskiy