ACF $AcfVersion:0$
CSelectionParam.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// Qt includes
6#include <QtCore/QMap>
7
8// ACF includes
10#include <iser/ISerializable.h>
12#include <iprm/IOptionsList.h>
13
14
15namespace iprm
16{
17
18
22class CSelectionParam: virtual public ISelectionParam
23{
24public:
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 override;
54 virtual int GetSelectedOptionIndex() const override;
55 virtual bool SetSelectedOptionIndex(int index) override;
56 virtual ISelectionParam* GetSubselection(int index) const override;
57
58 // reimplemented (iser::ISerializable)
59 virtual bool Serialize(iser::IArchive& archive) override;
60
61 // reimplemented (istd::IChangeable)
62 virtual bool CopyFrom(const istd::IChangeable& object, CompatibilityMode mode = CM_WITHOUT_REFS) override;
64
65protected:
69 int CalcIndexFromId(const QByteArray& optionId, int suggestedIndex = NO_SELECTION) const;
74
79 class ConstraintsObserver: public imod::TSingleModelObserverBase<iprm::IOptionsList>
80 {
81 public:
83
84 // reimplemented (imod::TSingleModelObserverBase<iprm::IOptionsList>)
85 virtual void OnUpdate(const istd::IChangeable::ChangeSet& changeSet) override;
86
87 private:
88 CSelectionParam& m_parent;
89 };
90
91private:
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
107
Basic implementation for a single model observer with binding to concrete data object interface.
ConstraintsObserver(CSelectionParam &parent)
virtual void OnUpdate(const istd::IChangeable::ChangeSet &changeSet) override
Called on update of observed model.
Basic implementation of selection parameter.
virtual int GetSelectedOptionIndex() const override
Get selected index.
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 SetSelectedOptionById(const QByteArray &selectedOptionId)
Set selection index according to a given option ID.
virtual bool SetSelectedOptionIndex(int index) override
Set index of selected option.
void SetSelectionConstraints(const IOptionsList *constraintsPtr)
Set selection constraints for this selection object.
bool SyncIndexWithId()
Synchronize current index to optimal one.
virtual const IOptionsList * GetSelectionConstraints() const override
Get constraints of this parameter.
virtual bool CopyFrom(const istd::IChangeable &object, CompatibilityMode mode=CM_WITHOUT_REFS) override
Copy this object from another one.
virtual istd::TUniqueInterfacePtr< istd::IChangeable > CloneMe(CompatibilityMode mode=CM_WITHOUT_REFS) const override
Make a copy of this object.
virtual ISelectionParam * GetSubselection(int index) const override
Get sub-selection for specified option.
virtual bool Serialize(iser::IArchive &archive) override
Load or store state of this object as a archive stream.
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.
Constraints of selection from set of possibilities.
Interface allowing to select single option from list of options.
@ NO_SELECTION
Indicates no option is currently selected.
Represents an input/output persistence archive for object serialization.
Definition IArchive.h:164
Set of change flags (its IDs).
Definition IChangeable.h:36
Common interface for data model objects, which can be changed.
Definition IChangeable.h:28
CompatibilityMode
Control how relationship betweeen objects are interpreted.
@ CM_WITHOUT_REFS
External references are simple ignored.
Unique ownership smart pointer for interface types.
Contains interfaces and implementations of flexible parameter concept.