QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
CameraSpec.cc
Go to the documentation of this file.
1#include "CameraSpec.h"
2#include "JsonHelper.h"
3
4#include <QtQml/QQmlEngine>
5
6CameraSpec::CameraSpec(const QString& settingsGroup, QObject* parent)
7 : QObject (parent)
8 , _dirty (false)
9 , _metaDataMap (FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/CameraSpec.FactMetaData.json"), this))
10 , _sensorWidthFact (settingsGroup, _metaDataMap[_sensorWidthName])
11 , _sensorHeightFact (settingsGroup, _metaDataMap[_sensorHeightName])
12 , _imageWidthFact (settingsGroup, _metaDataMap[_imageWidthName])
13 , _imageHeightFact (settingsGroup, _metaDataMap[_imageHeightName])
14 , _focalLengthFact (settingsGroup, _metaDataMap[_focalLengthName])
15 , _landscapeFact (settingsGroup, _metaDataMap[_landscapeName])
16 , _fixedOrientationFact (settingsGroup, _metaDataMap[_fixedOrientationName])
17 , _minTriggerIntervalFact (settingsGroup, _metaDataMap[_minTriggerIntervalName])
18{
19 QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
20}
21
23{
24 _sensorWidthFact.setRawValue (other._sensorWidthFact.rawValue());
25 _sensorHeightFact.setRawValue (other._sensorHeightFact.rawValue());
26 _imageWidthFact.setRawValue (other._imageWidthFact.rawValue());
27 _imageHeightFact.setRawValue (other._imageHeightFact.rawValue());
28 _focalLengthFact.setRawValue (other._focalLengthFact.rawValue());
29 _landscapeFact.setRawValue (other._landscapeFact.rawValue());
30 _fixedOrientationFact.setRawValue (other._fixedOrientationFact.rawValue());
31 _minTriggerIntervalFact.setRawValue (other._minTriggerIntervalFact.rawValue());
32
33 return *this;
34}
35
36void CameraSpec::setDirty(bool dirty)
37{
38 if (_dirty != dirty) {
39 _dirty = dirty;
40 emit dirtyChanged(_dirty);
41 }
42}
43
44void CameraSpec::save(QJsonObject& json) const
45{
46 json[_sensorWidthName] = _sensorWidthFact.rawValue().toDouble();
47 json[_sensorHeightName] = _sensorHeightFact.rawValue().toDouble();
48 json[_imageWidthName] = _imageWidthFact.rawValue().toDouble();
49 json[_imageHeightName] = _imageHeightFact.rawValue().toDouble();
50 json[_focalLengthName] = _focalLengthFact.rawValue().toDouble();
51 json[_landscapeName] = _landscapeFact.rawValue().toBool();
52 json[_fixedOrientationName] = _fixedOrientationFact.rawValue().toBool();
53 json[_minTriggerIntervalName] = _minTriggerIntervalFact.rawValue().toDouble();
54}
55
56bool CameraSpec::load(const QJsonObject& json, QString& errorString)
57{
58 QList<JsonHelper::KeyValidateInfo> keyInfoList = {
59 { _sensorWidthName, QJsonValue::Double, true },
60 { _sensorHeightName, QJsonValue::Double, true },
61 { _imageWidthName, QJsonValue::Double, true },
62 { _imageHeightName, QJsonValue::Double, true },
63 { _focalLengthName, QJsonValue::Double, true },
64 { _landscapeName, QJsonValue::Bool, true },
65 { _fixedOrientationName, QJsonValue::Bool, true },
66 { _minTriggerIntervalName, QJsonValue::Double, true },
67 };
68 if (!JsonHelper::validateKeys(json, keyInfoList, errorString)) {
69 return false;
70 }
71
72 _sensorWidthFact.setRawValue (json[_sensorWidthName].toDouble());
73 _sensorHeightFact.setRawValue (json[_sensorHeightName].toDouble());
74 _imageWidthFact.setRawValue (json[_imageWidthName].toInt());
75 _imageHeightFact.setRawValue (json[_imageHeightName].toInt());
76 _focalLengthFact.setRawValue (json[_focalLengthName].toDouble());
77 _landscapeFact.setRawValue (json[_landscapeName].toBool());
78 _fixedOrientationFact.setRawValue (json[_fixedOrientationName].toBool());
79 _minTriggerIntervalFact.setRawValue (json[_minTriggerIntervalName].toDouble());
80
81 return true;
82}
QString errorString
void save(QJsonObject &json) const
Definition CameraSpec.cc:44
bool dirty(void) const
Definition CameraSpec.h:33
const CameraSpec & operator=(const CameraSpec &other)
Definition CameraSpec.cc:22
void setDirty(bool dirty)
Definition CameraSpec.cc:36
CameraSpec(const QString &settingsGroup, QObject *parent=nullptr)
Definition CameraSpec.cc:6
void dirtyChanged(bool dirty)
bool load(const QJsonObject &json, QString &errorString)
Definition CameraSpec.cc:56
bool validateKeys(const QJsonObject &jsonObject, const QList< KeyValidateInfo > &keyInfo, QString &errorString)