From d11aef1373a5a7e1871fe60c292c9fdcc37361ca Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Wed, 9 Sep 2015 14:54:58 -0700 Subject: [PATCH] Support copy constructor --- src/FactSystem/Fact.cc | 48 +++++++++++++++++++++++++--------- src/FactSystem/Fact.h | 7 +++-- src/FactSystem/FactMetaData.cc | 34 ++++++++++++++++++++++++ src/FactSystem/FactMetaData.h | 4 +++ 4 files changed, 79 insertions(+), 14 deletions(-) diff --git a/src/FactSystem/Fact.cc b/src/FactSystem/Fact.cc index 6ae59e82b..d43488fa5 100644 --- a/src/FactSystem/Fact.cc +++ b/src/FactSystem/Fact.cc @@ -28,25 +28,49 @@ #include -Fact::Fact(void) : - _componentId(-1), - _value(0), - _type(FactMetaData::valueTypeInt32), - _metaData(NULL) +Fact::Fact(QObject* parent) + : QObject(parent) + , _componentId(-1) + , _value(0) + , _type(FactMetaData::valueTypeInt32) + , _metaData(NULL) { FactMetaData* metaData = new FactMetaData(_type, this); setMetaData(metaData); } -Fact::Fact(int componentId, QString name, FactMetaData::ValueType_t type, QObject* parent) : - QObject(parent), - _name(name), - _componentId(componentId), - _value(0), - _type(type), - _metaData(NULL) +Fact::Fact(int componentId, QString name, FactMetaData::ValueType_t type, QObject* parent) + : QObject(parent) + , _name(name) + , _componentId(componentId) + , _value(0) + , _type(type) + , _metaData(NULL) { + FactMetaData* metaData = new FactMetaData(_type, this); + setMetaData(metaData); +} +Fact::Fact(const Fact& other, QObject* parent) + : QObject(parent) +{ + *this = other; +} + +const Fact& Fact::operator=(const Fact& other) +{ + _name = other._name; + _componentId = other._componentId; + _value = other._value; + _type = other._type; + + if (_metaData && other._metaData) { + *_metaData = *other._metaData; + } else { + _metaData = NULL; + } + + return *this; } void Fact::forceSetValue(const QVariant& value) diff --git a/src/FactSystem/Fact.h b/src/FactSystem/Fact.h index b12647ad7..90be94d4a 100644 --- a/src/FactSystem/Fact.h +++ b/src/FactSystem/Fact.h @@ -40,9 +40,12 @@ class Fact : public QObject Q_OBJECT public: - Fact(void); + Fact(QObject* parent = NULL); Fact(int componentId, QString name, FactMetaData::ValueType_t type, QObject* parent = NULL); - + Fact(const Fact& other, QObject* parent = NULL); + + const Fact& operator=(const Fact& other); + Q_PROPERTY(int componentId READ componentId CONSTANT) Q_PROPERTY(QString name READ name CONSTANT) Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged USER true) diff --git a/src/FactSystem/FactMetaData.cc b/src/FactSystem/FactMetaData.cc index 33377ac08..3d63c41c9 100644 --- a/src/FactSystem/FactMetaData.cc +++ b/src/FactSystem/FactMetaData.cc @@ -32,6 +32,20 @@ #include +FactMetaData::FactMetaData(QObject* parent) : + QObject(parent), + _group("*Default Group"), + _type(valueTypeInt32), + _defaultValue(0), + _defaultValueAvailable(false), + _min(_minForType()), + _max(_maxForType()), + _minIsDefaultForType(true), + _maxIsDefaultForType(true) +{ + +} + FactMetaData::FactMetaData(ValueType_t type, QObject* parent) : QObject(parent), _group("*Default Group"), @@ -46,6 +60,26 @@ FactMetaData::FactMetaData(ValueType_t type, QObject* parent) : } +FactMetaData::FactMetaData(const FactMetaData& other, QObject* parent) + : QObject(parent) +{ + *this = other; +} + +const FactMetaData& FactMetaData::operator=(const FactMetaData& other) +{ + _group = other._group; + _type = other._type; + _defaultValue = other._defaultValue; + _defaultValueAvailable = other._defaultValueAvailable; + _min = other._min; + _max = other._max; + _minIsDefaultForType = other._minIsDefaultForType; + _maxIsDefaultForType = other._maxIsDefaultForType; + + return *this; +} + QVariant FactMetaData::defaultValue(void) { if (_defaultValueAvailable) { diff --git a/src/FactSystem/FactMetaData.h b/src/FactSystem/FactMetaData.h index 2afcdf198..8ad7c1118 100644 --- a/src/FactSystem/FactMetaData.h +++ b/src/FactSystem/FactMetaData.h @@ -52,7 +52,11 @@ public: valueTypeDouble } ValueType_t; + FactMetaData(QObject* parent = NULL); FactMetaData(ValueType_t type, QObject* parent = NULL); + FactMetaData(const FactMetaData& other, QObject* parent = NULL); + + const FactMetaData& operator=(const FactMetaData& other); // Property accessors QString name(void) { return _name; } -- 2.22.0