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
/****************************************************************************
*
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
#include "CameraSpec.h"
#include "JsonHelper.h"
#include <QQmlEngine>
const char* CameraSpec::_sensorWidthName = "SensorWidth";
const char* CameraSpec::_sensorHeightName = "SensorHeight";
const char* CameraSpec::_imageWidthName = "ImageWidth";
const char* CameraSpec::_imageHeightName = "ImageHeight";
const char* CameraSpec::_focalLengthName = "FocalLength";
const char* CameraSpec::_landscapeName = "Landscape";
const char* CameraSpec::_fixedOrientationName = "FixedOrientation";
const char* CameraSpec::_minTriggerIntervalName = "MinTriggerInterval";
CameraSpec::CameraSpec(QObject* parent)
: QObject (parent)
, _dirty (false)
, _metaDataMap (FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/CameraSpec.FactMetaData.json"), this))
, _sensorWidthFact (0, _sensorWidthName, FactMetaData::valueTypeDouble)
, _sensorHeightFact (0, _sensorHeightName, FactMetaData::valueTypeDouble)
, _imageWidthFact (0, _imageWidthName, FactMetaData::valueTypeUint32)
, _imageHeightFact (0, _imageHeightName, FactMetaData::valueTypeUint32)
, _focalLengthFact (0, _focalLengthName, FactMetaData::valueTypeDouble)
, _landscapeFact (0, _landscapeName, FactMetaData::valueTypeBool)
, _fixedOrientationFact (0, _fixedOrientationName, FactMetaData::valueTypeBool)
, _minTriggerIntervalFact (0, _minTriggerIntervalName, FactMetaData::valueTypeDouble)
{
_init(true);
}
CameraSpec::CameraSpec(const CameraSpec& other, QObject* parent)
: QObject (parent)
, _dirty (false)
, _metaDataMap (FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/CameraSpec.FactMetaData.json"), this))
, _sensorWidthFact (0, _sensorWidthName, FactMetaData::valueTypeDouble)
, _sensorHeightFact (0, _sensorHeightName, FactMetaData::valueTypeDouble)
, _imageWidthFact (0, _imageWidthName, FactMetaData::valueTypeUint32)
, _imageHeightFact (0, _imageHeightName, FactMetaData::valueTypeUint32)
, _focalLengthFact (0, _focalLengthName, FactMetaData::valueTypeDouble)
, _landscapeFact (0, _landscapeName, FactMetaData::valueTypeBool)
, _fixedOrientationFact (0, _fixedOrientationName, FactMetaData::valueTypeBool)
, _minTriggerIntervalFact (0, _minTriggerIntervalName, FactMetaData::valueTypeDouble)
{
_init(false);
*this = other;
}
const CameraSpec& CameraSpec::operator=(const CameraSpec& other)
{
_sensorWidthFact.setRawValue (other._sensorWidthFact.rawValue());
_sensorHeightFact.setRawValue (other._sensorHeightFact.rawValue());
_imageWidthFact.setRawValue (other._imageWidthFact.rawValue());
_imageHeightFact.setRawValue (other._imageHeightFact.rawValue());
_focalLengthFact.setRawValue (other._focalLengthFact.rawValue());
_landscapeFact.setRawValue (other._landscapeFact.rawValue());
_fixedOrientationFact.setRawValue (other._fixedOrientationFact.rawValue());
_minTriggerIntervalFact.setRawValue (other._minTriggerIntervalFact.rawValue());
return *this;
}
void CameraSpec::_init(bool setDefaults)
{
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
_sensorWidthFact.setMetaData (_metaDataMap[_sensorWidthName], setDefaults);
_sensorHeightFact.setMetaData (_metaDataMap[_sensorHeightName], setDefaults);
_imageWidthFact.setMetaData (_metaDataMap[_imageWidthName], setDefaults);
_imageHeightFact.setMetaData (_metaDataMap[_imageHeightName], setDefaults);
_focalLengthFact.setMetaData (_metaDataMap[_focalLengthName], setDefaults);
_landscapeFact.setMetaData (_metaDataMap[_landscapeName], setDefaults);
_fixedOrientationFact.setMetaData (_metaDataMap[_fixedOrientationName], setDefaults);
_minTriggerIntervalFact.setMetaData (_metaDataMap[_minTriggerIntervalName], setDefaults);
}
void CameraSpec::setDirty(bool dirty)
{
if (_dirty != dirty) {
_dirty = dirty;
emit dirtyChanged(_dirty);
}
}
void CameraSpec::save(QJsonObject& json) const
{
json[_sensorWidthName] = _sensorWidthFact.rawValue().toDouble();
json[_sensorHeightName] = _sensorHeightFact.rawValue().toDouble();
json[_imageWidthName] = _imageWidthFact.rawValue().toDouble();
json[_imageHeightName] = _imageHeightFact.rawValue().toDouble();
json[_focalLengthName] = _focalLengthFact.rawValue().toDouble();
json[_landscapeName] = _landscapeFact.rawValue().toBool();
json[_fixedOrientationName] = _fixedOrientationFact.rawValue().toBool();
json[_minTriggerIntervalName] = _minTriggerIntervalFact.rawValue().toDouble();
}
bool CameraSpec::load(const QJsonObject& json, QString& errorString)
{
QList<JsonHelper::KeyValidateInfo> keyInfoList = {
{ _sensorWidthName, QJsonValue::Double, true },
{ _sensorHeightName, QJsonValue::Double, true },
{ _imageWidthName, QJsonValue::Double, true },
{ _imageHeightName, QJsonValue::Double, true },
{ _focalLengthName, QJsonValue::Double, true },
{ _landscapeName, QJsonValue::Bool, true },
{ _fixedOrientationName, QJsonValue::Bool, true },
{ _minTriggerIntervalName, QJsonValue::Double, true },
};
if (!JsonHelper::validateKeys(json, keyInfoList, errorString)) {
return false;
}
_sensorWidthFact.setRawValue (json[_sensorWidthName].toDouble());
_sensorHeightFact.setRawValue (json[_sensorHeightName].toDouble());
_imageWidthFact.setRawValue (json[_imageWidthName].toInt());
_imageHeightFact.setRawValue (json[_imageHeightName].toInt());
_focalLengthFact.setRawValue (json[_focalLengthName].toDouble());
_landscapeFact.setRawValue (json[_landscapeName].toBool());
_fixedOrientationFact.setRawValue (json[_fixedOrientationName].toBool());
_minTriggerIntervalFact.setRawValue (json[_minTriggerIntervalName].toDouble());
return true;
}