Introduction
The iprm library provides a flexible and extensible framework for managing parameters in applications. It offers a comprehensive set of interfaces and implementations for handling different types of parameters, parameter sets, and dynamic parameter management with support for serialization, validation, and change notification.
Key Features
- Type-Safe Parameter Management: Strongly typed parameter interfaces for text, IDs, names, and selections
- Dynamic Parameter Sets: Support for creating, modifying, and managing collections of parameters
- Selection Constraints: Flexible option lists with support for hierarchical selections
- Serialization: Built-in support for parameter persistence through the ACF serialization framework
- Change Notification: Observer pattern implementation for tracking parameter modifications
- Validation: Extensible parameter set validation framework
- State Management: Parameter state providers for managing edit/display states
Architecture
The iprm library is organized into several key components:
Parameter Types
Parameter Containers
Options and Constraints
Utilities
Usage Examples
Text Parameter Example
textParam.
SetText(
"Hello, World!");
QString text = textParam.
GetText();
Implementation of the text value over iprm::ITextParam interface.
virtual void SetText(const QString &text) override
Set the text value.
virtual bool Serialize(iser::IArchive &archive) override
Load or store state of this object as a archive stream.
virtual bool IsReadOnly() const override
Return true if the text is read-only.
virtual QString GetText() const override
Get the text value.
Implementation of archive using memory buffer to store the persistent objects.
Selection Parameter Example
optionsManager.
InsertOption(
"Option 1",
"opt1",
"First option");
optionsManager.
InsertOption(
"Option 2",
"opt2",
"Second option");
optionsManager.
InsertOption(
"Option 3",
"opt3",
"Third option");
Implementation of a simple options manager.
virtual bool InsertOption(const QString &optionName, const QByteArray &optionId, const QString &optionDescription=QString(), int index=-1) override
Insert an option at some position.
Basic implementation of selection parameter.
virtual int GetSelectedOptionIndex() const override
Get selected index.
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.
virtual const IOptionsList * GetSelectionConstraints() const override
Get constraints of this parameter.
Constraints of selection from set of possibilities.
virtual int GetOptionsCount() const =0
Get number of managed options.
virtual QString GetOptionName(int index) const =0
Get name of specified option.
Parameter Set Example
for (const QByteArray& id : paramIds)
{
}
if (editableParam)
{
if (textParam)
{
}
}
Set of general parameters.
virtual const iser::ISerializable * GetParameter(const QByteArray &id) const =0
Get any parameter (read-only access).
virtual iser::ISerializable * GetEditableParameter(const QByteArray &id)=0
Get access to editable parameter (read-write access).
virtual Ids GetParamIds(bool editableOnly=false) const =0
Get list of used parameter IDs in the parameter set.
Interface for an object containing simple text.
virtual void SetText(const QString &text)=0
Set the text value.
Common class for all classes which objects can be archived or restored from archive.
Parameter Manager Example
if (canInsert)
{
if (newIndex >= 0)
{
}
}
for (int i = 0; i < count; ++i)
{
}
if (canDelete)
{
}
if (canSwap)
{
}
Manager of parameter sets.
virtual bool SetParamsSetName(int index, const QString &name)=0
Set name of specified parameter set.
virtual int GetIndexOperationFlags(int index=-1) const =0
Get operation control flags of some parameter set or whole manager.
virtual bool SwapParamsSet(int index1, int index2)=0
Swap two parameter sets.
virtual int InsertParamsSet(int typeIndex=-1, int index=-1)=0
Insert new parameter set at selected position.
virtual int GetParamsSetsCount() const =0
Get number of managed parameter sets.
virtual QString GetParamsSetDescription(int index) const =0
Get the description of the specified parameter set.
virtual IParamsSet * GetParamsSet(int index) const =0
Get selected parameter set.
virtual bool RemoveParamsSet(int index)=0
Remove parameter set at selected position.
virtual QString GetParamsSetName(int index) const =0
Get name of specified parameter set.
@ MF_SUPPORT_DELETE
Active if delete of parameters is possible.
@ MF_SUPPORT_INSERT
Active if insert of parameters is possible.
@ MF_SUPPORT_SWAP
Active if swap of parameters with the other one is possible.
Options Manager Example
if (canAddOptions)
{
optionsManager.
InsertOption(
"Red",
"color_red",
"Red color", -1);
optionsManager.
InsertOption(
"Green",
"color_green",
"Green color", -1);
optionsManager.
InsertOption(
"Blue",
"color_blue",
"Blue color", -1);
}
for (int i = 0; i < optionsCount; ++i)
{
qDebug() << "Option" << i << ":" << name << "(" << id << ")";
}
if (canRemove)
{
}
virtual bool SetOptionDescription(int index, const QString &optionDescription) override
Set a new description for the option at the given index.
virtual bool RemoveOption(int index) override
Remove an option at the given index.
virtual int GetOptionOperationFlags(int index=-1) const override
Get operation control flags of some option or whole manager.
virtual bool SetOptionName(int index, const QString &optionName) override
Set a new name for the option at the given index.
virtual bool IsOptionEnabled(int index) const override
Return true if the option is enabled and can be selected.
virtual QString GetOptionDescription(int index) const override
Get human-readable description for an option.
virtual QString GetOptionName(int index) const override
Get name of specified option.
virtual QByteArray GetOptionId(int index) const override
Get option ID.
virtual int GetOptionsCount() const override
Get number of managed options.
virtual bool SetOptionEnabled(int index, bool isEnabled=true) override
Enables or disables a given option.
@ OOF_SUPPORT_DELETE
Active if delete of options is possible.
@ OOF_SUPPORT_INSERT
Active if insert of options is possible.
Enableable Parameter Example
if (canEnable)
{
if (success)
{
}
}
Basic implementation of IEnableableParam interface.
virtual bool IsEnabled() const override
Return true if something is enabled.
virtual bool IsEnablingAllowed() const override
Return true if enabling/disabling is allowed.
virtual bool SetEnabled(bool isEnabled=true) override
Set the enabled state.
Parameter Set Validation Example
#include <ilog/CMessageConsumer.h>
ilog::CMessageConsumer messageConsumer;
QByteArray validationContext = "myContext";
validationContext,
*paramsSet,
&messageConsumer);
if (!isValid)
{
}
Interface for consistency checking of a parameter set.
virtual bool IsParamsSetConsistent(const QByteArray &validationContextId, const IParamsSet ¶msSet, ilog::IMessageConsumer *validationMessagesConsumerPtr=NULL) const =0
Return true if the parameter set is consistent, false otherwise.
virtual Ids GetSupportedTypeIds() const =0
Get list of parameter type IDs which can be checked by the validator.
Serialization Example
textParam.
SetText(
"Important Data");
QString text = loadedTextParam.
GetText();
virtual bool Serialize(iser::IArchive &archive) override
Load or store state of this object as a archive stream.
Implementation of archive using memory buffer to read the persistent objects.
Change Notification Example
#include <imod/IModelObserver.h>
class MySelectionObserver : public imod::IModelObserver
{
public:
{
{
if (selection)
{
}
}
}
};
MySelectionObserver observer;
Interface allowing to select single option from list of options.
@ CF_SELECTION_CHANGED
Selection index has changed.
virtual int GetSelectedOptionIndex() const =0
Get selected index.
Set of change flags (its IDs).
bool Contains(int changeId) const
Check if there is specific change flag in the set.
Common interface for data model objects, which can be changed.
Thread Safety
The iprm library components are generally not thread-safe by default. When using parameters across multiple threads, appropriate synchronization mechanisms should be employed by the application.
Dependencies
The iprm library depends on the following ACF components:
- istd: Standard utilities, change notification interfaces
- iser: Serialization framework
- imod: Model-observer pattern implementation
- icomp: Component framework
- Qt Core: QString, QByteArray, QSet, and other core classes
Best Practices
- Use Smart Pointers: Prefer istd::TUniqueInterfacePtr and istd::TSharedInterfacePtr for memory management
- Check Operation Flags: Always verify operation flags before attempting insert/delete/swap operations
- Handle Validation: Use parameter set validators to ensure data consistency
- Leverage Serialization: Utilize built-in serialization for persistence and undo/redo functionality
- Observe Changes: Implement observers to react to parameter changes in a decoupled manner
- Clone Parameters: Use CloneMe() for creating copies of parameters rather than manual copying
- Check Constraints: Verify selection constraints before setting option indices
See Also