-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathItemProperties.cpp
425 lines (359 loc) · 14.2 KB
/
ItemProperties.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
////////////////////////////////////////////////////////////////////////
// Copyright 2009-2018 NTESS. Under the terms
// of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
// Copyright (c) 2009-2018, NTESS
// All rights reserved.
//
// Portions are copyright of other developers:
// See the file CONTRIBUTORS.TXT in the top level directory
// the distribution for more information.
//
// This file is part of the SST software package. For license
// information, see the LICENSE file in the top level directory of the
// distribution.
////////////////////////////////////////////////////////////////////////
#include "ItemProperties.h"
////////////////////////////////////////////////////////////
ItemProperty::ItemProperty(ItemProperties* ParentItemProperties, QString PropertyName, QString OrigPropertyName, QString PropertyValue, QString PropertyDesc, bool ReadOnly, bool Exportable, bool DynamicFlag, QString ControllingParam)
{
// Init the Variables
m_ParentProperties = ParentItemProperties;
m_PropertyName = PropertyName;
m_OriginalPropertyName = OrigPropertyName;
m_PropertyValue = PropertyValue;
m_DefaultValue = PropertyValue;
m_PropertyDesc = PropertyDesc;
m_ReadOnly = ReadOnly;
m_Exportable = Exportable;
m_DynamicFlag = DynamicFlag;
m_DefaultValue = PropertyValue;
m_ControllingProperty = ControllingParam;
m_NumInstances = 0;
}
ItemProperty::~ItemProperty()
{
}
void ItemProperty::SetValue(QString NewValue, bool PerformCallback /*=true*/)
{
// Set the Property Value, Callback the PropertyChanged if requested (happens most of the time)
m_PropertyValue = NewValue;
// Tell the Parent Properties List that this property changed, it may also tell the
// Graphical Item if the PerformCallback is true
m_ParentProperties->PropertyChanged(m_PropertyName, m_PropertyValue, PerformCallback);
}
void ItemProperty::SaveData(QDataStream& DataStreamOut)
{
// Serialization Save
// Save off the data
DataStreamOut << m_PropertyName;
DataStreamOut << m_OriginalPropertyName;
DataStreamOut << m_PropertyValue;
DataStreamOut << m_DefaultValue;
DataStreamOut << m_PropertyDesc;
DataStreamOut << m_ReadOnly;
DataStreamOut << m_Exportable;
DataStreamOut << m_DynamicFlag;
DataStreamOut << m_ControllingProperty;
DataStreamOut << (qint32)m_NumInstances;
}
ItemProperty::ItemProperty(ItemProperties* ParentItemProperties, QDataStream& DataStreamIn)
{
// Serialization Load
m_ParentProperties = ParentItemProperties;
// Read In the data
DataStreamIn >> m_PropertyName;
DataStreamIn >> m_OriginalPropertyName;
DataStreamIn >> m_PropertyValue;
DataStreamIn >> m_DefaultValue;
DataStreamIn >> m_PropertyDesc;
DataStreamIn >> m_ReadOnly;
DataStreamIn >> m_Exportable;
DataStreamIn >> m_DynamicFlag;
DataStreamIn >> m_ControllingProperty;
DataStreamIn >> m_NumInstances;
}
////////////////////////////////////////////////////////////
ItemProperties::ItemProperties(GraphicItemBase* ParentGraphicItemBase)
{
// Init Variables
m_ParentGraphicItemBase = ParentGraphicItemBase; // Base Graphic Item that holds these properties
m_PropertyList.clear();
}
ItemProperties::~ItemProperties()
{
ItemProperty* PropItem;
int x;
int NumProperties = GetNumProperties();
// Delete all the properties that were created
for (x = 0; x < NumProperties; x++) {
PropItem = m_PropertyList.at(0);
delete PropItem;
m_PropertyList.removeAt(0);
}
}
void ItemProperties::AddProperty(QString PropertyName, QString PropertyValue /*=""*/, QString PropertyDesc /*=""*/, bool ReadOnly /*=false*/, bool Exportable/*=true*/)
{
int Index1;
int Index2;
QString ControllingParamName;
QString NewPropertyName;
// Search The Property Name for NOT containing a "%d" or a "%("
// that will indicate that it is a Static Property
if ((PropertyName.contains("%d") == false) && (PropertyName.contains("%(") == false) ) {
// This is a Static Property;
AddStaticProperty(PropertyName, PropertyValue, PropertyDesc, ReadOnly, Exportable);
return;
}
// If we get here, then this is a Dynamic Property, but we still have to figure a few things out.
// Search the Property Name for a "%d" that will indicate that it is a Dynamic Property with no Associated parameter
if (PropertyName.contains("%d") == true) {
// This is a Dynamic Port; We Need to identify that the port is unconfigured
AddDynamicProperty(PropertyName, PropertyValue, PropertyDesc, ReadOnly, Exportable, "");
return;
}
// If we get here, then this is a Dynamic Property, but it has a assocated Parameter
// (a Component Parameter). we need to crack the Parameter from the property name
Index1 = PropertyName.indexOf("%(", 0);
Index2 = PropertyName.indexOf(")d", Index1);
// Make sure we found both items
if ((Index1 >= 0) && (Index2 > Index1)) {
// Extract the Parameter Name
ControllingParamName = PropertyName.mid(Index1 + 2, Index2 - Index1 - 2);
// Create the New Property Name With the Controlling Parameter stripped out
NewPropertyName = PropertyName.left(Index1+1) + PropertyName.mid(Index2 + 1);
// Change the parameter name Name
AddDynamicProperty(NewPropertyName, PropertyValue, PropertyDesc, ReadOnly, Exportable, ControllingParamName);
return;
} else {
// Fall back and say the parameter is static
AddStaticProperty(PropertyName, PropertyValue, PropertyDesc, ReadOnly, Exportable);
return;
}
}
int ItemProperties::GetNumProperties()
{
return m_PropertyList.count();
}
void ItemProperties::SetPropertyValue(QString PropertyName, QString PropertyValue)
{
ItemProperty* PropItem;
PropItem = GetProperty(PropertyName);
if (PropItem != NULL) {
PropItem->SetValue(PropertyValue);
}
}
void ItemProperties::SetPropertyValue(int Index, QString PropertyValue)
{
ItemProperty* PropItem;
if (Index < GetNumProperties()) {
PropItem = m_PropertyList.at(Index);
PropItem->SetValue(PropertyValue);
}
}
int ItemProperties::GetPropertyIndex(QString PropertyName)
{
int x;
for (x = 0; x < GetNumProperties(); x++) {
if (PropertyName == m_PropertyList.at(x)->GetName()) {
return x;
}
}
return -1;
}
QString ItemProperties::GetPropertyValue(QString PropertyName)
{
int x;
for (x = 0; x < GetNumProperties(); x++) {
if (PropertyName == m_PropertyList.at(x)->GetName()) {
return m_PropertyList.at(x)->GetValue();
}
}
return "";
}
QString ItemProperties::GetPropertyDesc(QString PropertyName)
{
int x;
for (x = 0; x < GetNumProperties(); x++) {
if (PropertyName == m_PropertyList.at(x)->GetName()) {
return m_PropertyList.at(x)->GetDesc();
}
}
return "";
}
ItemProperty* ItemProperties::GetProperty(QString PropertyName)
{
int x;
for (x = 0; x < GetNumProperties(); x++) {
if (PropertyName == m_PropertyList.at(x)->GetName()) {
return m_PropertyList.at(x);
}
}
return NULL;
}
ItemProperty* ItemProperties::GetProperty(int Index)
{
if (Index < GetNumProperties()) {
return m_PropertyList.at(Index);
}
return NULL;
}
void ItemProperties::SaveData(QDataStream& DataStreamOut)
{
int x;
// Serialization Save
// Save the number of Properties and then each one
DataStreamOut << (qint32)m_PropertyList.count();
for (x = 0; x < m_PropertyList.count(); x++) {
m_PropertyList[x]->SaveData(DataStreamOut);
}
}
void ItemProperties::LoadData(QDataStream& DataStreamIn)
{
int NumProperties;
// Serialization Load
// Load the number of properties
DataStreamIn >> NumProperties;
// Load each individual property
for (int x = 0; x < NumProperties; x++) {
// Create the new ItemProperty
ItemProperty* PropItem = new ItemProperty(this, DataStreamIn);
// Add it to the list
m_PropertyList.push_back(PropItem);
}
}
void ItemProperties::PropertyChanged(QString PropName, QString PropNewValue, bool PerformCallback)
{
// This property has changed, tell the Graphical Item if the PerformCallback is true
if (PerformCallback == true) {
GetParentGraphicItemBase()->PropertyChanged(PropName, PropNewValue);
}
CheckIfDynamicPropertyChanged(PropName, PropNewValue, PerformCallback);
}
void ItemProperties::CheckIfDynamicPropertyChanged(QString PropName, QString PropNewValue, bool PerformCallback)
{
int x;
ItemProperty* Property;
int NumNewInstances;
QStringList ProcessedPropertyNamesList;
QString PropertyOriginalName;
// Now check to see if this parameter is a controlling parameter for any dynamic parameters
for (x = 0; x < m_PropertyList.count(); x++) {
Property = m_PropertyList.at(x);
PropertyOriginalName = Property->GetOriginalPropertyName();
// See if we have already processed this property
if (ProcessedPropertyNamesList.contains(PropertyOriginalName) == false) {
// See if the property Name matches a controlling Property name
if ((PropName == Property->GetControllingProperty()) && (Property->GetDynamicFlag() == true)) {
// Get the number of current instances of the dynamic property
NumNewInstances = PropNewValue.toInt();
// Adust Property in Main array
AdjustDynamicPropertyInList(Property->GetName(), NumNewInstances, PerformCallback);
// Reset the loop and do it again
x = -1;
}
}
ProcessedPropertyNamesList.append(PropertyOriginalName);
}
}
void ItemProperties::AdjustDynamicPropertyInList(QString PropertyName, int NumInstances, bool PerformCallback)
{
int x;
int StartingListIndex;
ItemProperty* CurrentProperty;
ItemProperty* NewProperty;
int CurrentInstances;
QString OrigPropertyName;
QString NewName;
QString RemoveName;
bool AdjustmentMade = false;
// Find the Index of the Dynamic Property Name and a pointer to the object. Note: Name will either have a %d or a 0 inside it
StartingListIndex = GetPropertyIndex(PropertyName);
CurrentProperty = GetProperty(PropertyName);
CurrentInstances = CurrentProperty->GetNumInstances();
OrigPropertyName = CurrentProperty->GetOriginalPropertyName();
// Do we add new instances
if (NumInstances > CurrentInstances) {
for (x = CurrentInstances; x < NumInstances; x++) {
// Replace the %d in the original name with the new Index
NewName = OrigPropertyName;
NewName.replace("%d", QString("%1").arg(x));
if (x == 0) {
// Special case for the first entry
CurrentProperty->SetName(NewName);
} else {
// Create the new ItemProperty
NewProperty = new ItemProperty(this, NewName, CurrentProperty->GetOriginalPropertyName(), CurrentProperty->GetDefaultValue(), CurrentProperty->GetDesc(), CurrentProperty->GetReadOnly(), CurrentProperty->GetExportable(), true, CurrentProperty->GetControllingProperty());
// Add it to the list at the right location
m_PropertyList.insert(StartingListIndex + x, NewProperty);
}
AdjustmentMade = true;
}
}
// Do we remove instances
if (NumInstances < CurrentInstances) {
for (x = CurrentInstances - 1; x >= NumInstances; x--) {
RemoveName = OrigPropertyName;
RemoveName.replace("%d", QString("%1").arg(x));
StartingListIndex = GetPropertyIndex(RemoveName);
CurrentProperty = GetProperty(RemoveName);
if (x == 0) {
// Special Case for the first entry
CurrentProperty->SetName(OrigPropertyName);
} else {
// Figure out what the name that we want to remove
m_PropertyList.removeAt(StartingListIndex);
delete CurrentProperty;
}
AdjustmentMade = true;
}
}
// Perform the callback if an adjustment was made
if (AdjustmentMade == true) {
// Go through all properties with the original name we first processed and update the number of instances
for (x = 0; x < m_PropertyList.count(); x++)
{
CurrentProperty = m_PropertyList.at(x);
if (CurrentProperty->GetOriginalPropertyName() == OrigPropertyName) {
CurrentProperty->SetNumInstances(NumInstances);
}
}
if (PerformCallback == true) {
m_ParentGraphicItemBase->DynamicPropertiesChanged(this);
}
}
}
void ItemProperties::AddStaticProperty(QString PropertyName, QString PropertyValue, QString PropertyDesc, bool ReadOnly, bool Exportable)
{
ItemProperty* PropItem;
// Check to see that the Property Name is unique
if (IsPropertyNameNotInList(PropertyName) == true) {
// Create the new ItemProperty
PropItem = new ItemProperty(this, PropertyName, PropertyName, PropertyValue, PropertyDesc, ReadOnly, Exportable, false, "");
// Add it to the list
m_PropertyList.push_back(PropItem);
}
}
void ItemProperties::AddDynamicProperty(QString PropertyName, QString PropertyValue, QString PropertyDesc, bool ReadOnly, bool Exportable, QString ControllingParam)
{
ItemProperty* PropItem;
// Check to see that the Property Name is unique
if (IsPropertyNameNotInList(PropertyName) == true) {
// Create the new ItemProperty
PropItem = new ItemProperty(this, PropertyName, PropertyName, PropertyValue, PropertyDesc, ReadOnly, Exportable, true, ControllingParam);
// Add it to the list
m_PropertyList.push_back(PropItem);
}
}
bool ItemProperties::IsPropertyNameNotInList(QString PropertyName)
{
int x;
// See if the property name is already in the list
for (x = 0; x < m_PropertyList.count(); x++) {
if (PropertyName == m_PropertyList.at(x)->GetName()) {
return false;
}
}
return true;
}