ACF $AcfVersion:0$
CParamsManagerCompBase.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/QVector>
7
8// ACF includes
9#include <istd/TDelPtr.h>
10#include <imod/TModelWrap.h>
13#include <iprm/IParamsSet.h>
16#include <iprm/IParamsManager.h>
17#include <iprm/CNameParam.h>
18
19
20namespace iprm
21{
22
23
25{
26public:
28
29 I_BEGIN_BASE_COMPONENT(CParamsManagerCompBaseAttr);
30 I_ASSIGN(m_elementIndexParamIdAttrPtr, "ElementIndexParamId", "ID of index of returned parameter set in manager list", false, "Index");
31 I_ASSIGN(m_elementUuidParamIdAttrPtr, "ElementUuidParamId", "ID of object uuid of returned parameter set in manager list", false, "Uuid");
32 I_ASSIGN(m_elementNameParamIdAttrPtr, "ElementNameParamId", "ID of the name of returned parameter set in manager list", false, "Name");
33 I_ASSIGN(m_elementDescriptionParamIdAttrPtr, "ElementDescriptionParamId", "ID of the description of returned parameter set in manager list", false, "Description");
34 I_ASSIGN_MULTI_0(m_fixedParamSetsCompPtr, "FixedParamSets", "List of references to fixed parameter set", false);
35 I_ASSIGN_MULTI_0(m_fixedSetNamesAttrPtr, "FixedSetNames", "List of fixed parameter names", false);
36 I_ASSIGN_MULTI_0(m_fixedSetDescriptionsAttrPtr, "FixedSetDescriptions", "List of fixed parameter descriptions", false);
37 I_ASSIGN_MULTI_0(m_fixedSetIdsAttrPtr, "FixedSetIds", "List of fixed parameter IDs", false);
38 I_ASSIGN(m_defaultSetNameAttrPtr, "DefaultSetName", "Default name of parameter set. Use %1 to insert automatic enumeration, %0 to substitute name of the corresponding factory (MultiParams only)", true, "<noname>");
39 I_ASSIGN(m_serializeSelectionAttrPtr, "SerializeSelection", "If enabled, the current parameter set selection will be serialized", true, true);
40 I_ASSIGN(m_defaultSelectedIndexAttrPtr, "DefaultSelection", "If enabled, the given parameter set will be automatically selected", false, -1);
41 I_ASSIGN(m_allowDisabledAttrPtr, "AllowDisabled", "Control if disabled parameters are supported", true, false);
42 I_ASSIGN(m_supportEnablingAttrPtr, "SupportEnabling", "Control if enabling or disabling of parameters is allowed (works only if disabled parameters are supported)", true, true);
43 I_ASSIGN(m_allowEditFixedAttrPtr, "AllowEditFixed", "If enabled, the editing of fixed parameters is enabled", true, true);
44 I_END_COMPONENT;
45
46protected:
47 I_MULTIREF(IParamsSet, m_fixedParamSetsCompPtr);
48 I_MULTITEXTATTR(m_fixedSetNamesAttrPtr);
49 I_MULTITEXTATTR(m_fixedSetDescriptionsAttrPtr);
50 I_MULTIATTR(QByteArray, m_fixedSetIdsAttrPtr);
51 I_TEXTATTR(m_defaultSetNameAttrPtr);
52 I_ATTR(bool, m_serializeSelectionAttrPtr);
53 I_ATTR(int, m_defaultSelectedIndexAttrPtr);
54 I_ATTR(bool, m_allowDisabledAttrPtr);
55 I_ATTR(bool, m_supportEnablingAttrPtr);
56 I_ATTR(bool, m_allowEditFixedAttrPtr);
57 I_ATTR(QByteArray, m_elementIndexParamIdAttrPtr);
58 I_ATTR(QByteArray, m_elementUuidParamIdAttrPtr);
59 I_ATTR(QByteArray, m_elementNameParamIdAttrPtr);
60 I_ATTR(QByteArray, m_elementDescriptionParamIdAttrPtr);
61};
62
63
69 virtual public IParamsManager,
70 virtual public IOptionsManager
71{
72public:
74
75 I_BEGIN_BASE_COMPONENT(CParamsManagerCompBase);
76 I_REGISTER_INTERFACE(ISelectionParam);
77 I_REGISTER_INTERFACE(IParamsManager);
78 I_REGISTER_INTERFACE(iser::ISerializable);
79 I_REGISTER_INTERFACE(IOptionsManager);
80 I_REGISTER_INTERFACE(IOptionsList);
81 I_REGISTER_SUBELEMENT(SelectedParams);
82 I_REGISTER_SUBELEMENT_INTERFACE(SelectedParams, iprm::IParamsSet, ExtractCurrentParams);
83 I_REGISTER_SUBELEMENT_INTERFACE(SelectedParams, iser::IObject, ExtractCurrentParams);
84 I_REGISTER_SUBELEMENT_INTERFACE(SelectedParams, iser::ISerializable, ExtractCurrentParams);
85 I_REGISTER_SUBELEMENT_INTERFACE(SelectedParams, istd::IChangeable, ExtractCurrentParams);
86 I_REGISTER_SUBELEMENT_INTERFACE(SelectedParams, imod::IModel, ExtractCurrentParams);
87
88 I_ASSIGN(m_parentSelectionCompPtr, "ParentSelection", "Parent selection component", false, "ParentSelection");
89 I_END_COMPONENT;
90
92
93 bool IsNameUnique(const QString& name) const;
94
95 // reimplemented (iprm::IParamsManager)
96 virtual int InsertParamsSet(int typeIndex = -1, int index = -1) override;
97 virtual bool RemoveParamsSet(int index) override;
98 virtual bool SwapParamsSet(int index1, int index2) override;
99 virtual IParamsSet* GetParamsSet(int index) const override;
100 virtual iprm::IParamsSetUniquePtr CreateParameterSet(int typeIndex = -1, int index = -1) const override;
101 virtual int GetIndexOperationFlags(int index = -1) const override;
102 virtual bool SetIndexOperationFlags(int index, int flags) override;
103 virtual int GetParamsSetsCount() const override;
104 virtual QString GetParamsSetName(int index) const override;
105 virtual bool SetParamsSetName(int index, const QString& name) override;
106 virtual QString GetParamsSetDescription(int index) const override;
107 virtual void SetParamsSetDescription(int index, const QString& description) override;
108
109 // reimplemented (iprm::ISelectionParam)
110 virtual const IOptionsList* GetSelectionConstraints() const override;
111 virtual int GetSelectedOptionIndex() const override;
112 virtual bool SetSelectedOptionIndex(int index) override;
113 virtual ISelectionParam* GetSubselection(int index) const override;
114
115 // reimplemented (iprm::IOptionsList)
116 virtual int GetOptionsFlags() const override;
117 virtual int GetOptionsCount() const override;
118 virtual QString GetOptionName(int index) const override;
119 virtual QString GetOptionDescription(int index) const override;
120 virtual QByteArray GetOptionId(int index) const override;
121 virtual bool IsOptionEnabled(int index) const override;
122
123protected:
125 int FindParamSetIndex(const QString& name) const;
126 int FindFixedParamSetIndex(const QString& name) const;
127
128 // virtual methods
129 virtual QString CalculateNewDefaultName(int typeIndex = -1) const;
130
131 // abstract methods
132
136 virtual bool IsParameterCreationSupported() const = 0;
137
141 virtual int GetCreatedParamsSetsCount() const = 0;
142
146 virtual iprm::IParamsSetUniquePtr CreateParamsSetInstance(int typeIndex = -1) const = 0;
147
148 // reimplemented (icomp::CComponentBase)
149 virtual void OnComponentCreated() override;
150
151protected:
153
154 class ParamSet;
155
156 class UuidParam: virtual public INameParam
157 {
158 public:
159 UuidParam(const ParamSet& parent);
160
161 // reimplemented (iprm::INameParam)
162 virtual const QString& GetName() const override;
163 virtual void SetName(const QString& name) override;
164 virtual bool IsNameFixed() const override;
165
166 // reimplemented (iser::ISerializable)
167 virtual bool Serialize(iser::IArchive& archive) override;
168
169 private:
170 mutable QString m_uuid;
171 const ParamSet& m_parent;
172 };
173
174 class ParamSet:
175 virtual public IParamsSet,
176 virtual public ISelectionParam,
177 virtual public INameParam
178 {
179 public:
181
182 // reimplemented (iprm::IParamsSet)
183 virtual Ids GetParamIds(bool editableOnly = false) const override;
184 virtual const iser::ISerializable* GetParameter(const QByteArray& id) const override;
185 virtual iser::ISerializable* GetEditableParameter(const QByteArray& id) override;
186 virtual const IParamsInfoProvider* GetParamsInfoProvider() const override;
187
188 // reimplemented (iprm::ISelectionParam)
189 virtual const IOptionsList* GetSelectionConstraints() const override;
190 virtual int GetSelectedOptionIndex() const override;
191 virtual bool SetSelectedOptionIndex(int index) override;
192 virtual ISelectionParam* GetSubselection(int index) const override;
193
194 // reimplemented (iprm::INameParam)
195 virtual const QString& GetName() const override;
196 virtual void SetName(const QString& name) override;
197 virtual bool IsNameFixed() const override;
198
199 // reimplemented (iser::IObject)
200 virtual QByteArray GetFactoryId() const override;
201
202 // reimplemented (iser::ISerializable)
203 virtual bool Serialize(iser::IArchive& archive) override;
204
205 // reimplemented (istd::IChangeable)
207
209 QByteArray uuid;
210 QString name;
217 };
218
219 class SelectedParams: virtual public IParamsSet
220 {
221 public:
223
224 // reimplemented (iprm::IParamsSet)
225 virtual Ids GetParamIds(bool editableOnly = false) const override;
226 virtual const iser::ISerializable* GetParameter(const QByteArray& id) const override;
227 virtual iser::ISerializable* GetEditableParameter(const QByteArray& id) override;
228 virtual const IParamsInfoProvider* GetParamsInfoProvider() const override;
229
230 // reimplemented (iser::IObject)
231 virtual QByteArray GetFactoryId() const override;
232
233 // reimplemented (iser::ISerializable)
234 virtual bool Serialize(iser::IArchive& archive) override;
235
237 };
238
239 typedef std::unique_ptr<ParamSet> ParamSetPtr;
240
241 typedef std::vector<ParamSetPtr> ParamSets;
242
243
245
247
249
250private:
251 // static template methods for subelement access
252 template <class InterfaceType>
253 static InterfaceType* ExtractCurrentParams(CParamsManagerCompBase& component)
254 {
255 return &component.m_selectedParams;
256 }
257
258 imod::TModelWrap<SelectedParams> m_selectedParams;
259
260 I_REF(ISelectionParam, m_parentSelectionCompPtr);
261};
262
263
264} // namespace iprm
265
266
267
268
Base class for component implementation.
Reflects the changes of observed objects as changes of some other object (over istd::IChangeable),...
Common interface for model objects, that supports Model/Observer design pattern.
Definition IModel.h:25
This model wrapper provides a simple connection between a concrete istd::IChangeable implementation a...
Definition TModelWrap.h:24
Implementation of a named object over iprm::INameParam interface.
Definition CNameParam.h:17
virtual Ids GetParamIds(bool editableOnly=false) const override
Get list of used parameter IDs in the parameter set.
virtual ISelectionParam * GetSubselection(int index) const override
Get sub-selection for specified option.
virtual void SetName(const QString &name) override
Set the object name.
virtual int GetSelectedOptionIndex() const override
Get selected index.
virtual iser::ISerializable * GetEditableParameter(const QByteArray &id) override
Get access to editable parameter (read-write access).
virtual QByteArray GetFactoryId() const override
virtual const IParamsInfoProvider * GetParamsInfoProvider() const override
Get parameter information provider.
virtual const iser::ISerializable * GetParameter(const QByteArray &id) const override
Get any parameter (read-only access).
virtual bool SetSelectedOptionIndex(int index) override
Set index of selected option.
virtual const QString & GetName() const override
Get the object name.
virtual bool IsNameFixed() const override
Return true if the name is fixed (non-editable).
virtual bool Serialize(iser::IArchive &archive) override
Load or store state of this object as a archive stream.
virtual bool CopyFrom(const istd::IChangeable &object, istd::IChangeable::CompatibilityMode mode=CM_WITHOUT_REFS) override
Copy this object from another one.
virtual const IOptionsList * GetSelectionConstraints() const override
Get constraints of this parameter.
virtual Ids GetParamIds(bool editableOnly=false) const override
Get list of used parameter IDs in the parameter set.
virtual QByteArray GetFactoryId() const override
virtual iser::ISerializable * GetEditableParameter(const QByteArray &id) override
Get access to editable parameter (read-write access).
virtual const IParamsInfoProvider * GetParamsInfoProvider() const override
Get parameter information provider.
virtual const iser::ISerializable * GetParameter(const QByteArray &id) const override
Get any parameter (read-only access).
virtual bool Serialize(iser::IArchive &archive) override
Load or store state of this object as a archive stream.
virtual const QString & GetName() const override
Get the object name.
virtual bool IsNameFixed() const override
Return true if the name is fixed (non-editable).
virtual void SetName(const QString &name) override
Set the object name.
virtual bool Serialize(iser::IArchive &archive) override
Load or store state of this object as a archive stream.
I_MULTITEXTATTR(m_fixedSetDescriptionsAttrPtr)
I_MULTITEXTATTR(m_fixedSetNamesAttrPtr)
I_TEXTATTR(m_defaultSetNameAttrPtr)
Implementation of parameter manager.
void EnsureParamsSetModelDetached(iprm::IParamsSet *paramsSetPtr) const
virtual IParamsSet * GetParamsSet(int index) const override
Get selected parameter set.
int FindFixedParamSetIndex(const QString &name) const
virtual const IOptionsList * GetSelectionConstraints() const override
Get constraints of this parameter.
virtual bool SetParamsSetName(int index, const QString &name) override
Set name of specified parameter set.
virtual bool RemoveParamsSet(int index) override
Remove parameter set at selected position.
virtual QString CalculateNewDefaultName(int typeIndex=-1) const
std::vector< ParamSetPtr > ParamSets
virtual int GetIndexOperationFlags(int index=-1) const override
Get operation control flags of some parameter set or whole manager.
CParamsManagerCompBaseAttr BaseClass
virtual QString GetParamsSetDescription(int index) const override
Get the description of the specified parameter set.
virtual QString GetOptionDescription(int index) const override
Get human-readable description for an option.
virtual int GetOptionsCount() const override
Get number of managed options.
virtual void SetParamsSetDescription(int index, const QString &description) override
Set the description of the specified parameter set.
virtual int GetParamsSetsCount() const override
Get number of managed parameter sets.
virtual bool IsParameterCreationSupported() const =0
Return true if creation of parameter sets is supported by the implementation.
virtual QString GetParamsSetName(int index) const override
Get name of specified parameter set.
virtual iprm::IParamsSetUniquePtr CreateParamsSetInstance(int typeIndex=-1) const =0
Create a new instance of the parameter set.
virtual int GetOptionsFlags() const override
Get constraints flags.
virtual int GetCreatedParamsSetsCount() const =0
Get the number of parameter sets created at the run time.
virtual bool SetIndexOperationFlags(int index, int flags) override
Set operation control flags of some parameter-set.
imod::CModelUpdateBridge m_updateBridge
std::unique_ptr< ParamSet > ParamSetPtr
int FindParamSetIndex(const QString &name) const
virtual bool SetSelectedOptionIndex(int index) override
Set index of selected option.
virtual bool IsOptionEnabled(int index) const override
Return true if the option is enabled and can be selected.
virtual int GetSelectedOptionIndex() const override
Get selected index.
virtual QString GetOptionName(int index) const override
Get name of specified option.
virtual ISelectionParam * GetSubselection(int index) const override
Get sub-selection for specified option.
virtual int InsertParamsSet(int typeIndex=-1, int index=-1) override
Insert new parameter set at selected position.
virtual bool SwapParamsSet(int index1, int index2) override
Swap two parameter sets.
virtual void OnComponentCreated() override
bool IsNameUnique(const QString &name) const
virtual iprm::IParamsSetUniquePtr CreateParameterSet(int typeIndex=-1, int index=-1) const override
Create a new parameter set instance.
virtual QByteArray GetOptionId(int index) const override
Get option ID.
Interface for an object containing a name.
Definition INameParam.h:67
Constraints of selection from set of possibilities.
Common interface for the management of dynamic selection constraints.
Provider of parameter information (name and description).
Manager of parameter sets.
Set of general parameters.
Definition IParamsSet.h:81
QSet< QByteArray > Ids
Definition IParamsSet.h:83
Interface allowing to select single option from list of options.
Represents an input/output persistence archive for object serialization.
Definition IArchive.h:164
Common interface for factorisable model objects.
Definition IObject.h:23
Common class for all classes which objects can be archived or restored from archive.
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.