ACF $AcfVersion:0$
TMultiAttributeMember.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// ACF includes
8
9
10namespace icomp
11{
12
13
19template <typename Attribute>
21{
22public:
23 typedef Attribute AttributeType;
24 typedef typename Attribute::ValueType AttributeValueType;
25 typedef void InterfaceType;
26
28
36 void Init(const IComponent* ownerPtr, const IRealAttributeStaticInfo& staticInfo);
37
41 bool IsValid() const;
42
46 int GetCount() const;
47
51 const AttributeValueType& operator[](int index) const;
52
57 int FindValue(const AttributeValueType& value) const;
58
59protected:
61 const IComponent* ownerPtr,
62 const IRealAttributeStaticInfo& staticInfo,
63 const IComponent** definitionComponentPtr);
64
65
66private:
67 const Attribute* m_attributePtr;
68};
69
70
71// public methods
72
73template <typename Attribute>
78
79
80template <typename Attribute>
82 const IComponent* ownerPtr,
83 const IRealAttributeStaticInfo& staticInfo)
84{
85 InitInternal(ownerPtr, staticInfo, NULL);
86}
87
88
89template <typename Attribute>
91{
92 return (m_attributePtr != NULL);
93}
94
95
96template <typename Attribute>
98{
99 if (m_attributePtr != NULL){
100 return m_attributePtr->GetValuesCount();
101 }
102 else{
103 return 0;
104 }
105}
106
107
108template <typename Attribute>
110{
111 Q_ASSERT(index >= 0);
112 Q_ASSERT(index < GetCount());
113 Q_ASSERT(m_attributePtr != NULL); // operator* was called for invalid object, or no IsValid() check was called.
114 Q_ASSERT(m_attributePtr->GetValuesCount() == GetCount());
115
116 return m_attributePtr->GetValueAt(index);
117}
118
119
120template <typename Attribute>
122{
123 if (m_attributePtr != NULL){
124 return m_attributePtr->FindValue(value);
125 }
126
127 return -1;
128}
129
130
131// protected methods
132
133template <typename Attribute>
135 const IComponent* ownerPtr,
136 const IRealAttributeStaticInfo& staticInfo,
137 const IComponent** definitionComponentPtr)
138{
139 Q_ASSERT(ownerPtr != NULL);
140
141 const QByteArray& attributeId = staticInfo.GetAttributeId();
142 IComponentContextSharedPtr componentContextPtr = ownerPtr->GetComponentContext();
143 if (componentContextPtr.get()){
144 int definitionLevel = -1;
145 const iser::IObject* attributePtr = componentContextPtr->GetAttribute(attributeId, &definitionLevel);
146 m_attributePtr = dynamic_cast<const Attribute*>(attributePtr);
147
148 if (m_attributePtr != NULL){
149 Q_ASSERT(definitionLevel >= 0);
150
151 if (definitionComponentPtr != NULL){
152 while (definitionLevel > 0 && (ownerPtr != nullptr)){
153 ownerPtr = ownerPtr->GetParentComponent();
154// Q_ASSERT(ownerPtr != NULL);
155
156 --definitionLevel;
157 }
158
159 *definitionComponentPtr = ownerPtr;
160 }
161
162 return true;
163 }
164 }
165 else{
166 m_attributePtr = NULL;
167 }
168
169 return false;
170}
171
172
173// Translatable attribute
174
176{
177public:
179
181 {
182 }
183
184 explicit CMultiTextAttribute(int elementsCount, QString* valuesPtr)
185 : BaseClass(elementsCount, valuesPtr)
186 {
187 }
188
194
195 static QByteArray GetTypeName()
196 {
197 return "Text[]";
198 }
199
200 // reimplemented (iser::IObject)
201 virtual QByteArray GetFactoryId() const override
202 {
203 return GetTypeName();
204 }
205};
206
207
208class CMultiTextAttributeMember: public TMultiAttributeMember<CMultiTextAttribute>
209{
210public:
212
213 QString operator[](int index) const
214 {
215 return QCoreApplication::translate("Attribute", BaseClass::operator[](index).toLatin1());
216 }
217};
218
219
220} // namespace icomp
221
222
Template implementation of multiple component attribute.
CMultiTextAttribute(int elementsCount, QString *valuesPtr)
virtual QByteArray GetFactoryId() const override
iattr::CStringListAttribute BaseClass
TMultiAttributeMember< CMultiTextAttribute > BaseClass
@ AF_TRANSLATABLE
Attribute is able to translate.
Main component interface.
Definition IComponent.h:32
virtual const icomp::IComponent * GetParentComponent(bool ownerOnly=false) const =0
Get parent of this component.
virtual IComponentContextSharedPtr GetComponentContext() const =0
Get access to component context describing all application-specified component information loaded fro...
Interface adding to attribute static info functionality existing only for real attributes.
virtual const QByteArray & GetAttributeId() const =0
Get ID of this attribute.
Pointer to component attribute.
bool IsValid() const
Check if this attribute is valid.
int FindValue(const AttributeValueType &value) const
Find attribute value.
const AttributeValueType & operator[](int index) const
Access to object pointed by internal pointer.
Attribute::ValueType AttributeValueType
void Init(const IComponent *ownerPtr, const IRealAttributeStaticInfo &staticInfo)
Internal initialize of attribute.
int GetCount() const
Get number of attributes.
bool InitInternal(const IComponent *ownerPtr, const IRealAttributeStaticInfo &staticInfo, const IComponent **definitionComponentPtr)
Common interface for factorisable model objects.
Definition IObject.h:23
#define NULL
Definition istd.h:74
Package with interfaces and class used for components concept.
std::shared_ptr< icomp::IComponentContext > IComponentContextSharedPtr