diff --git a/src/Joystick/Joystick.h b/src/Joystick/Joystick.h index 63b39e3817b..2221b18e942 100644 --- a/src/Joystick/Joystick.h +++ b/src/Joystick/Joystick.h @@ -14,6 +14,7 @@ #include "QGCMAVLink.h" #include "CustomActionManager.h" +#include "QmlObjectListModel.h" #include #include diff --git a/src/QmlControls/CustomAction.cc b/src/QmlControls/CustomAction.cc index 849cef3054c..0da331f5da6 100644 --- a/src/QmlControls/CustomAction.cc +++ b/src/QmlControls/CustomAction.cc @@ -9,8 +9,46 @@ #include "CustomAction.h" #include "Vehicle.h" +#include "QGCLoggingCategory.h" -void CustomAction::sendTo(Vehicle* vehicle) { +QGC_LOGGING_CATEGORY(CustomActionLog, "qgc.qmlcontrols.customaction") + +CustomAction::CustomAction(QObject *parent) + : QObject(parent) +{ + // qCDebug(CustomActionLog) << Q_FUNC_INFO << this; +} + +CustomAction::CustomAction( + const QString &label, + const QString &description, + MAV_CMD mavCmd, + MAV_COMPONENT compId, + float param1, + float param2, + float param3, + float param4, + float param5, + float param6, + float param7, + QObject *parent +) : QObject(parent) + , _label(label) + , _description(description) + , _mavCmd(mavCmd) + , _compId(compId) + , _params{ param1, param2, param3, param4, param5, param6, param7 } +{ + // qCDebug(CustomActionLog) << Q_FUNC_INFO << this; +}; + +CustomAction::~CustomAction() +{ + // qCDebug(CustomActionLog) << Q_FUNC_INFO << this; +} + +void CustomAction::sendTo(Vehicle *vehicle) +{ if (vehicle) { const bool showError = true; vehicle->sendMavCommand(_compId, _mavCmd, showError, _params[0], _params[1], _params[2], _params[3], _params[4], _params[5], _params[6]); diff --git a/src/QmlControls/CustomAction.h b/src/QmlControls/CustomAction.h index 6ccb1c370bc..9166c41b5a8 100644 --- a/src/QmlControls/CustomAction.h +++ b/src/QmlControls/CustomAction.h @@ -11,49 +11,49 @@ #include "MAVLinkLib.h" +#include #include +#include + +Q_DECLARE_LOGGING_CATEGORY(CustomActionLog) class Vehicle; class CustomAction: public QObject { Q_OBJECT - - Q_PROPERTY(QString label READ label CONSTANT) - Q_PROPERTY(QString description READ description CONSTANT) + QML_ELEMENT + Q_MOC_INCLUDE("Vehicle.h") + Q_PROPERTY(QString label READ label CONSTANT) + Q_PROPERTY(QString description READ description CONSTANT) public: - CustomAction() { CustomAction(QString(), QString(), MAV_CMD(0), MAV_COMPONENT(0), 0, 0, 0, 0, 0, 0, 0); } // this is required for QML reflection + explicit CustomAction(QObject *parent = nullptr); CustomAction( - QString label, - QString description, - MAV_CMD mavCmd, - MAV_COMPONENT compId, - float param1, - float param2, - float param3, - float param4, - float param5, - float param6, - float param7, - QObject* parent = nullptr) - : QObject (parent) - , _label (label) - , _description (description) - , _mavCmd (mavCmd) - , _compId (compId) - , _params { param1, param2, param3, param4, param5, param6, param7 } - {}; - - Q_INVOKABLE void sendTo(Vehicle* vehicle); - - QString label () const { return _label; } - QString description() const { return _description; } + const QString &label, + const QString &description, + MAV_CMD mavCmd, + MAV_COMPONENT compId, + float param1, + float param2, + float param3, + float param4, + float param5, + float param6, + float param7, + QObject *parent = nullptr + ); + ~CustomAction(); + + Q_INVOKABLE void sendTo(Vehicle *vehicle); + + const QString &label() const { return _label; } + const QString &description() const { return _description; } private: - QString _label; - QString _description; - MAV_CMD _mavCmd; - MAV_COMPONENT _compId; - float _params[7]; + const QString _label; + const QString _description; + const MAV_CMD _mavCmd = MAV_CMD_ENUM_END; + const MAV_COMPONENT _compId = MAV_COMPONENT_ENUM_END; + const float _params[7]{}; }; diff --git a/src/QmlControls/CustomActionManager.cc b/src/QmlControls/CustomActionManager.cc index e4e7ca1911c..654afe6da80 100644 --- a/src/QmlControls/CustomActionManager.cc +++ b/src/QmlControls/CustomActionManager.cc @@ -7,70 +7,82 @@ * ****************************************************************************/ -#include -#include -#include - #include "CustomActionManager.h" #include "CustomAction.h" +#include "Fact.h" #include "JsonHelper.h" #include "QGCApplication.h" #include "SettingsManager.h" +#include "QGCLoggingCategory.h" +#include "QmlObjectListModel.h" + +#include +#include +#include -CustomActionManager::CustomActionManager(QObject* parent) +QGC_LOGGING_CATEGORY(CustomActionManagerLog, "qgc.qmlcontrols.customactionmanager") + +CustomActionManager::CustomActionManager(QObject *parent) : QObject(parent) + , _actions(new QmlObjectListModel(this)) { - + // qCDebug(CustomActionManagerLog) << Q_FUNC_INFO << this; } -CustomActionManager::CustomActionManager(Fact* actionFileNameFact, QObject* parent) +CustomActionManager::CustomActionManager(Fact *actionFileNameFact, QObject *parent) : QObject(parent) + , _actions(new QmlObjectListModel(this)) { setActionFileNameFact(actionFileNameFact); } -void CustomActionManager::setActionFileNameFact(Fact* actionFileNameFact) +CustomActionManager::~CustomActionManager() +{ + // qCDebug(CustomActionManagerLog) << Q_FUNC_INFO << this; +} + +void CustomActionManager::setActionFileNameFact(Fact *actionFileNameFact) { _actionFileNameFact = actionFileNameFact; emit actionFileNameFactChanged(); - connect(_actionFileNameFact, &Fact::rawValueChanged, this, &CustomActionManager::_loadActionsFile); + (void) connect(_actionFileNameFact, &Fact::rawValueChanged, this, &CustomActionManager::_loadActionsFile); _loadActionsFile(); } -void CustomActionManager::_loadActionsFile() +void CustomActionManager::_loadActionsFile() { - _actions.clearAndDeleteContents(); - QString actionFileName = _actionFileNameFact->rawValue().toString(); + _actions->clearAndDeleteContents(); + const QString actionFileName = _actionFileNameFact->rawValue().toString(); if (actionFileName.isEmpty()) { return; } // Custom actions are always loaded from the custom actions save path - QString savePath = qgcApp()->toolbox()->settingsManager()->appSettings()->customActionsSavePath(); - QDir saveDir(savePath); - QString fullPath = saveDir.absoluteFilePath(actionFileName); + const QString savePath = qgcApp()->toolbox()->settingsManager()->appSettings()->customActionsSavePath(); + const QDir saveDir = QDir(savePath); + const QString fullPath = saveDir.absoluteFilePath(actionFileName); // It's ok for the file to not exist - QFileInfo fileInfo(fullPath); + const QFileInfo fileInfo = QFileInfo(fullPath); if (!fileInfo.exists()) { return; } - const char* kQgcFileType = "CustomActions"; - const char* kActionListKey = "actions"; + constexpr const char *kQgcFileType = "CustomActions"; + constexpr const char *kActionListKey = "actions"; - _actions.clearAndDeleteContents(); + _actions->clearAndDeleteContents(); QString errorString; int version; - QJsonObject jsonObject = JsonHelper::openInternalQGCJsonFile(fullPath, kQgcFileType, 1, 1, version, errorString); + const QJsonObject jsonObject = JsonHelper::openInternalQGCJsonFile(fullPath, kQgcFileType, 1, 1, version, errorString); if (!errorString.isEmpty()) { - qgcApp()->showAppMessage(tr("Failed to load custom actions file: `%1` error: `%2`").arg(fullPath).arg(errorString)); + qgcApp()->showAppMessage(tr("Failed to load custom actions file: `%1` error: `%2`").arg(fullPath, errorString)); return; } - QList keyInfoList = { + const QList keyInfoList = { { kActionListKey, QJsonValue::Array, /* required= */ true }, }; if (!JsonHelper::validateKeys(jsonObject, keyInfoList, errorString)) { @@ -78,17 +90,15 @@ void CustomActionManager::_loadActionsFile() return; } - QJsonArray actionList = jsonObject[kActionListKey].toArray(); - for (auto actionJson: actionList) { + const QJsonArray actionList = jsonObject[kActionListKey].toArray(); + for (const auto &actionJson: actionList) { if (!actionJson.isObject()) { qgcApp()->showAppMessage(tr("Custom actions file - incorrect format: JsonValue not an object")); - _actions.clearAndDeleteContents(); + _actions->clearAndDeleteContents(); return; } - auto actionObj = actionJson.toObject(); - - QList actionKeyInfoList = { + const QList actionKeyInfoList = { { "label", QJsonValue::String, /* required= */ true }, { "description", QJsonValue::String, /* required= */ true }, { "mavCmd", QJsonValue::Double, /* required= */ true }, @@ -102,26 +112,28 @@ void CustomActionManager::_loadActionsFile() { "param6", QJsonValue::Double, /* required= */ false }, { "param7", QJsonValue::Double, /* required= */ false }, }; + + const auto actionObj = actionJson.toObject(); if (!JsonHelper::validateKeys(actionObj, actionKeyInfoList, errorString)) { qgcApp()->showAppMessage(tr("Custom actions file - incorrect format: %1").arg(errorString)); - _actions.clearAndDeleteContents(); + _actions->clearAndDeleteContents(); return; } - auto label = actionObj["label"].toString(); - auto description = actionObj["description"].toString(); - auto mavCmd = (MAV_CMD)actionObj["mavCmd"].toInt(); - auto compId = (MAV_COMPONENT)actionObj["compId"].toInt(MAV_COMP_ID_AUTOPILOT1); - auto param1 = actionObj["param1"].toDouble(0.0); - auto param2 = actionObj["param2"].toDouble(0.0); - auto param3 = actionObj["param3"].toDouble(0.0); - auto param4 = actionObj["param4"].toDouble(0.0); - auto param5 = actionObj["param5"].toDouble(0.0); - auto param6 = actionObj["param6"].toDouble(0.0); - auto param7 = actionObj["param7"].toDouble(0.0); - - CustomAction* action = new CustomAction(label, description, mavCmd, compId, param1, param2, param3, param4, param5, param6, param7, this); + const auto label = actionObj["label"].toString(); + const auto description = actionObj["description"].toString(); + const auto mavCmd = (MAV_CMD)actionObj["mavCmd"].toInt(); + const auto compId = (MAV_COMPONENT)actionObj["compId"].toInt(MAV_COMP_ID_AUTOPILOT1); + const auto param1 = actionObj["param1"].toDouble(0.0); + const auto param2 = actionObj["param2"].toDouble(0.0); + const auto param3 = actionObj["param3"].toDouble(0.0); + const auto param4 = actionObj["param4"].toDouble(0.0); + const auto param5 = actionObj["param5"].toDouble(0.0); + const auto param6 = actionObj["param6"].toDouble(0.0); + const auto param7 = actionObj["param7"].toDouble(0.0); + + CustomAction *const action = new CustomAction(label, description, mavCmd, compId, param1, param2, param3, param4, param5, param6, param7, this); QQmlEngine::setObjectOwnership(action, QQmlEngine::CppOwnership); - _actions.append(action); + (void) _actions->append(action); } } diff --git a/src/QmlControls/CustomActionManager.h b/src/QmlControls/CustomActionManager.h index 3d4d736bfa6..26e2ebbfb86 100644 --- a/src/QmlControls/CustomActionManager.h +++ b/src/QmlControls/CustomActionManager.h @@ -9,10 +9,14 @@ #pragma once -#include "Fact.h" -#include "QmlObjectListModel.h" - +#include #include +#include + +Q_DECLARE_LOGGING_CATEGORY(CustomActionManagerLog) + +class Fact; +class QmlObjectListModel; /// Loads the specified action file and provides access to the actions it contains. /// Action files are loaded from the default CustomActions directory. @@ -20,25 +24,28 @@ class CustomActionManager : public QObject { Q_OBJECT - - Q_PROPERTY(Fact* actionFileNameFact READ actionFileNameFact WRITE setActionFileNameFact NOTIFY actionFileNameFactChanged) - Q_PROPERTY(QmlObjectListModel* actions READ actions CONSTANT) + QML_ELEMENT + Q_MOC_INCLUDE("Fact.h") + Q_MOC_INCLUDE("QmlObjectListModel.h") + Q_PROPERTY(Fact* actionFileNameFact READ actionFileNameFact WRITE setActionFileNameFact NOTIFY actionFileNameFactChanged) + Q_PROPERTY(QmlObjectListModel* actions READ actions CONSTANT) public: - CustomActionManager(QObject* parent = nullptr); - CustomActionManager(Fact* actionFileNameFact, QObject* parent = nullptr); + explicit CustomActionManager(QObject *parent = nullptr); + explicit CustomActionManager(Fact *actionFileNameFact, QObject *parent = nullptr); + ~CustomActionManager(); - Fact* actionFileNameFact (void) { return _actionFileNameFact; } - void setActionFileNameFact (Fact* actionFileNameFact); - QmlObjectListModel* actions (void) { return &_actions; } + Fact *actionFileNameFact() { return _actionFileNameFact; } + void setActionFileNameFact(Fact *actionFileNameFact); + QmlObjectListModel *actions() { return _actions; } signals: void actionFileNameFactChanged(); private slots: - void _loadActionsFile(void); + void _loadActionsFile(); private: - Fact* _actionFileNameFact; - QmlObjectListModel _actions; + Fact *_actionFileNameFact = nullptr; + QmlObjectListModel *_actions = nullptr; }; diff --git a/src/QmlControls/EditPositionDialogController.cc b/src/QmlControls/EditPositionDialogController.cc index fbdaa041973..245581bd378 100644 --- a/src/QmlControls/EditPositionDialogController.cc +++ b/src/QmlControls/EditPositionDialogController.cc @@ -13,29 +13,40 @@ #include "QGCToolbox.h" #include "MultiVehicleManager.h" #include "Vehicle.h" +#include "QGCLoggingCategory.h" + +QGC_LOGGING_CATEGORY(EditPositionDialogControllerLog, "qgc.qmlcontrols.editpositiondialogcontroller") QMap EditPositionDialogController::_metaDataMap; -EditPositionDialogController::EditPositionDialogController(void) - : _latitudeFact (0, _latitudeFactName, FactMetaData::valueTypeDouble) - , _longitudeFact (0, _longitudeFactName, FactMetaData::valueTypeDouble) - , _zoneFact (0, _zoneFactName, FactMetaData::valueTypeUint8) - , _hemisphereFact (0, _hemisphereFactName, FactMetaData::valueTypeUint8) - , _eastingFact (0, _eastingFactName, FactMetaData::valueTypeDouble) - , _northingFact (0, _northingFactName, FactMetaData::valueTypeDouble) - , _mgrsFact (0, _mgrsFactName, FactMetaData::valueTypeString) +EditPositionDialogController::EditPositionDialogController(QObject *parent) + : QObject(parent) + , _latitudeFact(new Fact(0, _latitudeFactName, FactMetaData::valueTypeDouble, this)) + , _longitudeFact(new Fact(0, _longitudeFactName, FactMetaData::valueTypeDouble, this)) + , _zoneFact(new Fact(0, _zoneFactName, FactMetaData::valueTypeUint8, this)) + , _hemisphereFact(new Fact(0, _hemisphereFactName, FactMetaData::valueTypeUint8, this)) + , _eastingFact(new Fact(0, _eastingFactName, FactMetaData::valueTypeDouble, this)) + , _northingFact(new Fact(0, _northingFactName, FactMetaData::valueTypeDouble, this)) + , _mgrsFact(new Fact(0, _mgrsFactName, FactMetaData::valueTypeString, this)) { + // qCDebug(EditPositionDialogControllerLog) << Q_FUNC_INFO << this; + if (_metaDataMap.isEmpty()) { _metaDataMap = FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/EditPositionDialog.FactMetaData.json"), nullptr /* QObject parent */); } - _latitudeFact.setMetaData (_metaDataMap[_latitudeFactName]); - _longitudeFact.setMetaData (_metaDataMap[_longitudeFactName]); - _zoneFact.setMetaData (_metaDataMap[_zoneFactName]); - _hemisphereFact.setMetaData (_metaDataMap[_hemisphereFactName]); - _eastingFact.setMetaData (_metaDataMap[_eastingFactName]); - _northingFact.setMetaData (_metaDataMap[_northingFactName]); - _mgrsFact.setMetaData (_metaDataMap[_mgrsFactName]); + _latitudeFact->setMetaData(_metaDataMap[_latitudeFactName]); + _longitudeFact->setMetaData(_metaDataMap[_longitudeFactName]); + _zoneFact->setMetaData(_metaDataMap[_zoneFactName]); + _hemisphereFact->setMetaData(_metaDataMap[_hemisphereFactName]); + _eastingFact->setMetaData(_metaDataMap[_eastingFactName]); + _northingFact->setMetaData(_metaDataMap[_northingFactName]); + _mgrsFact->setMetaData(_metaDataMap[_mgrsFactName]); +} + +EditPositionDialogController::~EditPositionDialogController() +{ + // qCDebug(EditPositionDialogControllerLog) << Q_FUNC_INFO << this; } void EditPositionDialogController::setCoordinate(QGeoCoordinate coordinate) @@ -46,55 +57,55 @@ void EditPositionDialogController::setCoordinate(QGeoCoordinate coordinate) } } -void EditPositionDialogController::initValues(void) +void EditPositionDialogController::initValues() { - _latitudeFact.setRawValue(_coordinate.latitude()); - _longitudeFact.setRawValue(_coordinate.longitude()); + _latitudeFact->setRawValue(_coordinate.latitude()); + _longitudeFact->setRawValue(_coordinate.longitude()); double easting, northing; - int zone = QGCGeo::convertGeoToUTM(_coordinate, easting, northing); - if (zone >= 1 && zone <= 60) { - _zoneFact.setRawValue(zone); - _hemisphereFact.setRawValue(_coordinate.latitude() < 0); - _eastingFact.setRawValue(easting); - _northingFact.setRawValue(northing); + const int zone = QGCGeo::convertGeoToUTM(_coordinate, easting, northing); + if ((zone >= 1) && (zone <= 60)) { + _zoneFact->setRawValue(zone); + _hemisphereFact->setRawValue(_coordinate.latitude() < 0); + _eastingFact->setRawValue(easting); + _northingFact->setRawValue(northing); } - QString mgrs = QGCGeo::convertGeoToMGRS(_coordinate); + + const QString mgrs = QGCGeo::convertGeoToMGRS(_coordinate); if (!mgrs.isEmpty()) { - _mgrsFact.setRawValue(mgrs); + _mgrsFact->setRawValue(mgrs); } } -void EditPositionDialogController::setFromGeo(void) +void EditPositionDialogController::setFromGeo() { - _coordinate.setLatitude(_latitudeFact.rawValue().toDouble()); - _coordinate.setLongitude(_longitudeFact.rawValue().toDouble()); + _coordinate.setLatitude(_latitudeFact->rawValue().toDouble()); + _coordinate.setLongitude(_longitudeFact->rawValue().toDouble()); emit coordinateChanged(_coordinate); } -void EditPositionDialogController::setFromUTM(void) +void EditPositionDialogController::setFromUTM() { - qDebug() << _eastingFact.rawValue().toDouble() << _northingFact.rawValue().toDouble() << _zoneFact.rawValue().toInt() << (_hemisphereFact.rawValue().toInt() == 1); - if (QGCGeo::convertUTMToGeo(_eastingFact.rawValue().toDouble(), _northingFact.rawValue().toDouble(), _zoneFact.rawValue().toInt(), _hemisphereFact.rawValue().toInt() == 1, _coordinate)) { - qDebug() << _eastingFact.rawValue().toDouble() << _northingFact.rawValue().toDouble() << _zoneFact.rawValue().toInt() << (_hemisphereFact.rawValue().toInt() == 1) << _coordinate; + qCDebug(EditPositionDialogControllerLog) << _eastingFact->rawValue().toDouble() << _northingFact->rawValue().toDouble() << _zoneFact->rawValue().toInt() << (_hemisphereFact->rawValue().toInt() == 1); + if (QGCGeo::convertUTMToGeo(_eastingFact->rawValue().toDouble(), _northingFact->rawValue().toDouble(), _zoneFact->rawValue().toInt(), _hemisphereFact->rawValue().toInt() == 1, _coordinate)) { + qCDebug(EditPositionDialogControllerLog) << _eastingFact->rawValue().toDouble() << _northingFact->rawValue().toDouble() << _zoneFact->rawValue().toInt() << (_hemisphereFact->rawValue().toInt() == 1) << _coordinate; emit coordinateChanged(_coordinate); } else { initValues(); } } -void EditPositionDialogController::setFromMGRS(void) +void EditPositionDialogController::setFromMGRS() { - if (QGCGeo::convertMGRSToGeo(_mgrsFact.rawValue().toString(), _coordinate)) { + if (QGCGeo::convertMGRSToGeo(_mgrsFact->rawValue().toString(), _coordinate)) { emit coordinateChanged(_coordinate); } else { initValues(); } } -void EditPositionDialogController::setFromVehicle(void) +void EditPositionDialogController::setFromVehicle() { - _coordinate = qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()->coordinate(); - emit coordinateChanged(_coordinate); + setCoordinate(qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()->coordinate()); } diff --git a/src/QmlControls/EditPositionDialogController.h b/src/QmlControls/EditPositionDialogController.h index 2b41856b5f3..21efc159eb6 100644 --- a/src/QmlControls/EditPositionDialogController.h +++ b/src/QmlControls/EditPositionDialogController.h @@ -12,62 +12,67 @@ #include "Fact.h" #include +#include #include +#include + +Q_DECLARE_LOGGING_CATEGORY(EditPositionDialogControllerLog) class EditPositionDialogController : public QObject { Q_OBJECT - -public: - EditPositionDialogController(void); - + QML_ELEMENT Q_PROPERTY(QGeoCoordinate coordinate READ coordinate WRITE setCoordinate NOTIFY coordinateChanged) - Q_PROPERTY(Fact* latitude READ latitude CONSTANT) - Q_PROPERTY(Fact* longitude READ longitude CONSTANT) - Q_PROPERTY(Fact* zone READ zone CONSTANT) - Q_PROPERTY(Fact* hemisphere READ hemisphere CONSTANT) - Q_PROPERTY(Fact* easting READ easting CONSTANT) - Q_PROPERTY(Fact* northing READ northing CONSTANT) - Q_PROPERTY(Fact* mgrs READ mgrs CONSTANT) + Q_PROPERTY(Fact *latitude READ latitude CONSTANT) + Q_PROPERTY(Fact *longitude READ longitude CONSTANT) + Q_PROPERTY(Fact *zone READ zone CONSTANT) + Q_PROPERTY(Fact *hemisphere READ hemisphere CONSTANT) + Q_PROPERTY(Fact *easting READ easting CONSTANT) + Q_PROPERTY(Fact *northing READ northing CONSTANT) + Q_PROPERTY(Fact *mgrs READ mgrs CONSTANT) + +public: + explicit EditPositionDialogController(QObject *parent = nullptr); + ~EditPositionDialogController(); - QGeoCoordinate coordinate(void) const { return _coordinate; } - Fact* latitude (void) { return &_latitudeFact; } - Fact* longitude (void) { return &_longitudeFact; } - Fact* zone (void) { return &_zoneFact; } - Fact* hemisphere(void) { return &_hemisphereFact; } - Fact* easting (void) { return &_eastingFact; } - Fact* northing (void) { return &_northingFact; } - Fact* mgrs (void) { return &_mgrsFact; } + Q_INVOKABLE void initValues(); + Q_INVOKABLE void setFromGeo(); + Q_INVOKABLE void setFromUTM(); + Q_INVOKABLE void setFromMGRS(); + Q_INVOKABLE void setFromVehicle(); void setCoordinate(QGeoCoordinate coordinate); + QGeoCoordinate coordinate() const { return _coordinate; } - Q_INVOKABLE void initValues(void); - Q_INVOKABLE void setFromGeo(void); - Q_INVOKABLE void setFromUTM(void); - Q_INVOKABLE void setFromMGRS(void); - Q_INVOKABLE void setFromVehicle(void); + Fact *latitude() { return _latitudeFact; } + Fact *longitude() { return _longitudeFact; } + Fact *zone() { return _zoneFact; } + Fact *hemisphere() { return _hemisphereFact; } + Fact *easting() { return _eastingFact; } + Fact *northing() { return _northingFact; } + Fact *mgrs() { return _mgrsFact; } signals: void coordinateChanged(QGeoCoordinate coordinate); private: - static QMap _metaDataMap; - QGeoCoordinate _coordinate; - Fact _latitudeFact; - Fact _longitudeFact; - Fact _zoneFact; - Fact _hemisphereFact; - Fact _eastingFact; - Fact _northingFact; - Fact _mgrsFact; + Fact *_latitudeFact = nullptr; + Fact *_longitudeFact = nullptr; + Fact *_zoneFact = nullptr; + Fact *_hemisphereFact = nullptr; + Fact *_eastingFact = nullptr; + Fact *_northingFact = nullptr; + Fact *_mgrsFact = nullptr; + + static QMap _metaDataMap; - static constexpr const char* _latitudeFactName = "Latitude"; - static constexpr const char* _longitudeFactName = "Longitude"; - static constexpr const char* _zoneFactName = "Zone"; - static constexpr const char* _hemisphereFactName = "Hemisphere"; - static constexpr const char* _eastingFactName = "Easting"; - static constexpr const char* _northingFactName = "Northing"; - static constexpr const char* _mgrsFactName = "MGRS"; + static constexpr const char *_latitudeFactName = "Latitude"; + static constexpr const char *_longitudeFactName = "Longitude"; + static constexpr const char *_zoneFactName = "Zone"; + static constexpr const char *_hemisphereFactName = "Hemisphere"; + static constexpr const char *_eastingFactName = "Easting"; + static constexpr const char *_northingFactName = "Northing"; + static constexpr const char *_mgrsFactName = "MGRS"; }; diff --git a/src/QmlControls/ParameterEditorController.cc b/src/QmlControls/ParameterEditorController.cc index a2863f40288..12347b1bddb 100644 --- a/src/QmlControls/ParameterEditorController.cc +++ b/src/QmlControls/ParameterEditorController.cc @@ -12,10 +12,16 @@ #include "ParameterManager.h" #include "AppSettings.h" #include "Vehicle.h" +#include "QGCLoggingCategory.h" -ParameterEditorController::ParameterEditorController(void) - : _parameterMgr(_vehicle->parameterManager()) +QGC_LOGGING_CATEGORY(ParameterEditorControllerLog, "qgc.qmlcontrols.parametereditorcontroller") + +ParameterEditorController::ParameterEditorController(QObject *parent) + : FactPanelController(parent) + , _parameterMgr(_vehicle->parameterManager()) { + // qCDebug(ParameterEditorControllerLog) << Q_FUNC_INFO << this; + _buildLists(); connect(this, &ParameterEditorController::currentCategoryChanged, this, &ParameterEditorController::_currentCategoryChanged); @@ -31,7 +37,7 @@ ParameterEditorController::ParameterEditorController(void) ParameterEditorController::~ParameterEditorController() { - + // qCDebug(ParameterEditorControllerLog) << Q_FUNC_INFO << this; } void ParameterEditorController::_buildListsForComponent(int compId) diff --git a/src/QmlControls/ParameterEditorController.h b/src/QmlControls/ParameterEditorController.h index fd860b227fe..9895525b747 100644 --- a/src/QmlControls/ParameterEditorController.h +++ b/src/QmlControls/ParameterEditorController.h @@ -13,7 +13,11 @@ #include "QmlObjectListModel.h" #include "FactMetaData.h" +#include #include +#include + +Q_DECLARE_LOGGING_CATEGORY(ParameterEditorControllerLog) class ParameterManager; @@ -83,23 +87,23 @@ class ParameterEditorDiff : public QObject class ParameterEditorController : public FactPanelController { Q_OBJECT + QML_ELEMENT + Q_PROPERTY(QString searchText MEMBER _searchText NOTIFY searchTextChanged) + Q_PROPERTY(QmlObjectListModel* categories READ categories CONSTANT) + Q_PROPERTY(QObject* currentCategory READ currentCategory WRITE setCurrentCategory NOTIFY currentCategoryChanged) + Q_PROPERTY(QObject* currentGroup READ currentGroup WRITE setCurrentGroup NOTIFY currentGroupChanged) + Q_PROPERTY(QmlObjectListModel* parameters MEMBER _parameters NOTIFY parametersChanged) + Q_PROPERTY(bool showModifiedOnly MEMBER _showModifiedOnly NOTIFY showModifiedOnlyChanged) + + // These property are related to the diff associated with a load from file + Q_PROPERTY(bool diffOtherVehicle MEMBER _diffOtherVehicle NOTIFY diffOtherVehicleChanged) + Q_PROPERTY(bool diffMultipleComponents MEMBER _diffMultipleComponents NOTIFY diffMultipleComponentsChanged) + Q_PROPERTY(QmlObjectListModel* diffList READ diffList CONSTANT) public: - ParameterEditorController(void); + explicit ParameterEditorController(QObject *parent = nullptr); ~ParameterEditorController(); - Q_PROPERTY(QString searchText MEMBER _searchText NOTIFY searchTextChanged) - Q_PROPERTY(QmlObjectListModel* categories READ categories CONSTANT) - Q_PROPERTY(QObject* currentCategory READ currentCategory WRITE setCurrentCategory NOTIFY currentCategoryChanged) - Q_PROPERTY(QObject* currentGroup READ currentGroup WRITE setCurrentGroup NOTIFY currentGroupChanged) - Q_PROPERTY(QmlObjectListModel* parameters MEMBER _parameters NOTIFY parametersChanged) - Q_PROPERTY(bool showModifiedOnly MEMBER _showModifiedOnly NOTIFY showModifiedOnlyChanged) - - // These property are related to the diff associated with a load from file - Q_PROPERTY(bool diffOtherVehicle MEMBER _diffOtherVehicle NOTIFY diffOtherVehicleChanged) - Q_PROPERTY(bool diffMultipleComponents MEMBER _diffMultipleComponents NOTIFY diffMultipleComponentsChanged) - Q_PROPERTY(QmlObjectListModel* diffList READ diffList CONSTANT) - Q_INVOKABLE QStringList searchParameters(const QString& searchText, bool searchInName=true, bool searchInDescriptions=true); Q_INVOKABLE void saveToFile (const QString& filename); diff --git a/src/QmlControls/QGCFileDialogController.cc b/src/QmlControls/QGCFileDialogController.cc index c590ff08150..f52393537b6 100644 --- a/src/QmlControls/QGCFileDialogController.cc +++ b/src/QmlControls/QGCFileDialogController.cc @@ -12,20 +12,31 @@ #include "QGCLoggingCategory.h" #include "QGCApplication.h" #include "SettingsManager.h" + #include -QGC_LOGGING_CATEGORY(QGCFileDialogControllerLog, "QGCFileDialogControllerLog") +QGC_LOGGING_CATEGORY(QGCFileDialogControllerLog, "qgc.qmlcontrols.qgcfiledialogcontroller") + +QGCFileDialogController::QGCFileDialogController(QObject *parent) + : QObject(parent) +{ + // qCDebug(QGCFileDialogControllerLog) << Q_FUNC_INFO << this; +} + +QGCFileDialogController::~QGCFileDialogController() +{ + // qCDebug(QGCFileDialogControllerLog) << Q_FUNC_INFO << this; +} -QStringList QGCFileDialogController::getFiles(const QString& directoryPath, const QStringList& nameFilters) +QStringList QGCFileDialogController::getFiles(const QString &directoryPath, const QStringList &nameFilters) { qCDebug(QGCFileDialogControllerLog) << "getFiles" << directoryPath << nameFilters; - QStringList files; QDir fileDir(directoryPath); + const QFileInfoList fileInfoList = fileDir.entryInfoList(nameFilters, QDir::Files, QDir::Name); - QFileInfoList fileInfoList = fileDir.entryInfoList(nameFilters, QDir::Files, QDir::Name); - - for (const QFileInfo& fileInfo: fileInfoList) { + QStringList files; + for (const QFileInfo &fileInfo: fileInfoList) { qCDebug(QGCFileDialogControllerLog) << "getFiles found" << fileInfo.fileName(); files << fileInfo.fileName(); } @@ -33,7 +44,7 @@ QStringList QGCFileDialogController::getFiles(const QString& directoryPath, cons return files; } -bool QGCFileDialogController::fileExists(const QString& filename) +bool QGCFileDialogController::fileExists(const QString &filename) { return QFile(filename).exists(); } @@ -49,7 +60,7 @@ QString QGCFileDialogController::fullyQualifiedFilename(const QString& directory extensionFound = false; for (const QString& nameFilter: nameFilters) { if (nameFilter.startsWith("*.")) { - QString fileExtension = nameFilter.right(nameFilter.length() - 2); + const QString fileExtension = nameFilter.right(nameFilter.length() - 2); if (fileExtension != "*") { if (firstFileExtention.isEmpty()) { firstFileExtention = fileExtension; @@ -71,28 +82,26 @@ QString QGCFileDialogController::fullyQualifiedFilename(const QString& directory filenameWithExtension = QStringLiteral("%1.%2").arg(filename).arg(firstFileExtention); } - return directoryPath + QStringLiteral("/") + filenameWithExtension; + return (directoryPath + QStringLiteral("/") + filenameWithExtension); } -void QGCFileDialogController::deleteFile(const QString& filename) +void QGCFileDialogController::deleteFile(const QString &filename) { QFile::remove(filename); } -QString QGCFileDialogController::fullFolderPathToShortMobilePath(const QString& fullFolderPath) +QString QGCFileDialogController::fullFolderPathToShortMobilePath(const QString &fullFolderPath) { -#ifdef __mobile__ - QString defaultSavePath = qgcApp()->toolbox()->settingsManager()->appSettings()->savePath()->rawValueString(); +#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) + const QString defaultSavePath = qgcApp()->toolbox()->settingsManager()->appSettings()->savePath()->rawValueString(); if (fullFolderPath.startsWith(defaultSavePath)) { - int lastDirSepIndex = fullFolderPath.lastIndexOf(QStringLiteral("/")); - return QCoreApplication::applicationName() + QStringLiteral("/") + fullFolderPath.right(fullFolderPath.length() - lastDirSepIndex); - } else { - return fullFolderPath; + const int lastDirSepIndex = fullFolderPath.lastIndexOf(QStringLiteral("/")); + return (QCoreApplication::applicationName() + QStringLiteral("/") + fullFolderPath.right(fullFolderPath.length() - lastDirSepIndex)); } #else - qWarning() << "QGCFileDialogController::fullFolderPathToShortMobilePath should only be used in mobile builds"; - return fullFolderPath; + qCWarning(QGCFileDialogControllerLog) << Q_FUNC_INFO << "should only be used in mobile builds"; #endif + return fullFolderPath; } QString QGCFileDialogController::urlToLocalFile(QUrl url) @@ -101,7 +110,7 @@ QString QGCFileDialogController::urlToLocalFile(QUrl url) // Seems to be new behavior with Qt6. if (url.isLocalFile()) { return url.toLocalFile(); - } else { - return url.toString(); } + + return url.toString(); } diff --git a/src/QmlControls/QGCFileDialogController.h b/src/QmlControls/QGCFileDialogController.h index 36383b64f82..8be185d9d72 100644 --- a/src/QmlControls/QGCFileDialogController.h +++ b/src/QmlControls/QGCFileDialogController.h @@ -10,34 +10,40 @@ #pragma once +#include #include #include -#include +#include Q_DECLARE_LOGGING_CATEGORY(QGCFileDialogControllerLog) class QGCFileDialogController : public QObject { Q_OBJECT + // TODO: Q_NAMESPACE + QML_ELEMENT public: + explicit QGCFileDialogController(QObject *parent = nullptr); + ~QGCFileDialogController(); + /// Return all file in the specified path which match the specified extension - Q_INVOKABLE QStringList getFiles(const QString& directoryPath, const QStringList& nameFilters); + Q_INVOKABLE static QStringList getFiles(const QString &directoryPath, const QStringList &nameFilters); /// Returns the fully qualified file name from the specified parts. /// If filename has no file extension the first file extension is nameFilters is added to the filename. - Q_INVOKABLE QString fullyQualifiedFilename(const QString& directoryPath, const QString& filename, const QStringList& nameFilters = QStringList()); + Q_INVOKABLE static QString fullyQualifiedFilename(const QString &directoryPath, const QString &filename, const QStringList &nameFilters = QStringList()); /// Check for file existence of specified fully qualified file name - Q_INVOKABLE bool fileExists(const QString& filename); - + Q_INVOKABLE static bool fileExists(const QString &filename); + /// Deletes the file specified by the fully qualified file name - Q_INVOKABLE void deleteFile(const QString& filename); + Q_INVOKABLE static void deleteFile(const QString &filename); - Q_INVOKABLE QString urlToLocalFile(QUrl url); + Q_INVOKABLE static QString urlToLocalFile(QUrl url); /// Important: Should only be used in mobile builds where default save location cannot be changed. /// Returns the standard QGC location portion of a fully qualified folder path. /// Example: "/Users/Don/Document/QGroundControl/Missions" returns "QGroundControl/Missions" - Q_INVOKABLE QString fullFolderPathToShortMobilePath(const QString& fullFolderPath); + Q_INVOKABLE static QString fullFolderPathToShortMobilePath(const QString &fullFolderPath); }; diff --git a/src/QmlControls/RCChannelMonitorController.cc b/src/QmlControls/RCChannelMonitorController.cc index df686dcf405..7ed3402f32e 100644 --- a/src/QmlControls/RCChannelMonitorController.cc +++ b/src/QmlControls/RCChannelMonitorController.cc @@ -10,17 +10,27 @@ #include "RCChannelMonitorController.h" #include "Vehicle.h" +#include "QGCLoggingCategory.h" -RCChannelMonitorController::RCChannelMonitorController(void) - : _chanCount(0) +QGC_LOGGING_CATEGORY(RCChannelMonitorControllerLog, "qgc.qmlcontrols.rcchannelmonitorcontroller") + +RCChannelMonitorController::RCChannelMonitorController(QObject *parent) + : FactPanelController(parent) +{ + // qCDebug(RCChannelMonitorControllerLog) << Q_FUNC_INFO << this; + + (void) connect(_vehicle, &Vehicle::rcChannelsChanged, this, &RCChannelMonitorController::_rcChannelsChanged); +} + +RCChannelMonitorController::~RCChannelMonitorController() { - connect(_vehicle, &Vehicle::rcChannelsChanged, this, &RCChannelMonitorController::_rcChannelsChanged); + // qCDebug(RCChannelMonitorControllerLog) << Q_FUNC_INFO << this; } void RCChannelMonitorController::_rcChannelsChanged(int channelCount, int pwmValues[QGCMAVLink::maxRcChannels]) { - for (int channel=0; channel +#include + +Q_DECLARE_LOGGING_CATEGORY(RCChannelMonitorControllerLog) + class RCChannelMonitorController : public FactPanelController { Q_OBJECT + QML_ELEMENT + Q_PROPERTY(int channelCount READ channelCount NOTIFY channelCountChanged) public: - RCChannelMonitorController(void); - - Q_PROPERTY(int channelCount READ channelCount NOTIFY channelCountChanged) + explicit RCChannelMonitorController(QObject *parent = nullptr); + ~RCChannelMonitorController(); - int channelCount(void) const{ return _chanCount; } + int channelCount() const { return _chanCount; } signals: void channelCountChanged(int channelCount); @@ -32,5 +38,5 @@ private slots: void _rcChannelsChanged(int channelCount, int pwmValues[QGCMAVLink::maxRcChannels]); private: - int _chanCount; + int _chanCount = 0; }; diff --git a/src/QmlControls/RCToParamDialogController.cc b/src/QmlControls/RCToParamDialogController.cc index 2028568c733..3b5f16c5d63 100644 --- a/src/QmlControls/RCToParamDialogController.cc +++ b/src/QmlControls/RCToParamDialogController.cc @@ -13,40 +13,52 @@ #include "ParameterManager.h" #include "MultiVehicleManager.h" #include "Vehicle.h" +#include "QGCLoggingCategory.h" +#include "Fact.h" + +QGC_LOGGING_CATEGORY(RCToParamDialogControllerLog, "qgc.qmlcontrols.rctoparamdialogcontroller") QMap RCToParamDialogController::_metaDataMap; -RCToParamDialogController::RCToParamDialogController(void) - : _scaleFact (0, _scaleFactName, FactMetaData::valueTypeDouble) - , _centerFact (0, _centerFactName, FactMetaData::valueTypeDouble) - , _minFact (0, _minFactName, FactMetaData::valueTypeDouble) - , _maxFact (0, _maxFactName, FactMetaData::valueTypeDouble) +RCToParamDialogController::RCToParamDialogController(QObject *parent) + : QObject(parent) + , _scaleFact(new Fact(0, _scaleFactName, FactMetaData::valueTypeDouble, this)) + , _centerFact(new Fact(0, _centerFactName, FactMetaData::valueTypeDouble, this)) + , _minFact(new Fact(0, _minFactName, FactMetaData::valueTypeDouble, this)) + , _maxFact(new Fact(0, _maxFactName, FactMetaData::valueTypeDouble, this)) { + // qCDebug(RCToParamDialogControllerLog) << Q_FUNC_INFO << this; + if (_metaDataMap.isEmpty()) { _metaDataMap = FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/RCToParamDialog.FactMetaData.json"), nullptr /* QObject parent */); } - _scaleFact.setMetaData (_metaDataMap[_scaleFactName], true /* setDefaultFromMetaData */); - _centerFact.setMetaData (_metaDataMap[_centerFactName]); - _minFact.setMetaData (_metaDataMap[_minFactName]); - _maxFact.setMetaData (_metaDataMap[_maxFactName]); + _scaleFact->setMetaData(_metaDataMap[_scaleFactName], true /* setDefaultFromMetaData */); + _centerFact->setMetaData(_metaDataMap[_centerFactName]); + _minFact->setMetaData(_metaDataMap[_minFactName]); + _maxFact->setMetaData(_metaDataMap[_maxFactName]); +} + +RCToParamDialogController::~RCToParamDialogController() +{ + // qCDebug(RCToParamDialogControllerLog) << Q_FUNC_INFO << this;` } -void RCToParamDialogController::setTuningFact(Fact* tuningFact) +void RCToParamDialogController::setTuningFact(Fact *tuningFact) { _tuningFact = tuningFact; emit tuningFactChanged(tuningFact); - _centerFact.setRawValue(_tuningFact->rawValue().toDouble()); - _minFact.setRawValue(_tuningFact->rawMin().toDouble()); - _maxFact.setRawValue(_tuningFact->rawMax().toDouble()); + _centerFact->setRawValue(_tuningFact->rawValue().toDouble()); + _minFact->setRawValue(_tuningFact->rawMin().toDouble()); + _maxFact->setRawValue(_tuningFact->rawMax().toDouble()); - connect(_tuningFact, &Fact::vehicleUpdated, this, &RCToParamDialogController::_parameterUpdated); + (void) connect(_tuningFact, &Fact::vehicleUpdated, this, &RCToParamDialogController::_parameterUpdated); qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()->parameterManager()->refreshParameter(ParameterManager::defaultComponentId, _tuningFact->name()); } -void RCToParamDialogController::_parameterUpdated(void) +void RCToParamDialogController::_parameterUpdated() { _ready = true; - emit readyChanged(true); + emit readyChanged(_ready); } diff --git a/src/QmlControls/RCToParamDialogController.h b/src/QmlControls/RCToParamDialogController.h index 4d9318185f4..9e4ddb1dabb 100644 --- a/src/QmlControls/RCToParamDialogController.h +++ b/src/QmlControls/RCToParamDialogController.h @@ -9,50 +9,57 @@ #pragma once -#include "Fact.h" - +#include #include +#include + +Q_DECLARE_LOGGING_CATEGORY(RCToParamDialogControllerLog) + +class Fact; +class FactMetaData; class RCToParamDialogController : public QObject { Q_OBJECT - + QML_ELEMENT + Q_MOC_INCLUDE("Fact.h") + Q_PROPERTY(Fact *tuningFact READ tuningFact WRITE setTuningFact NOTIFY tuningFactChanged) + Q_PROPERTY(Fact *scale READ scale CONSTANT) + Q_PROPERTY(Fact *center READ center CONSTANT) + Q_PROPERTY(Fact *min READ min CONSTANT) + Q_PROPERTY(Fact *max READ max CONSTANT) + Q_PROPERTY(bool ready MEMBER _ready NOTIFY readyChanged) // true: editing can begin, false: still waiting for param update from vehicle + public: - RCToParamDialogController(void); - - Q_PROPERTY(Fact* tuningFact READ tuningFact WRITE setTuningFact NOTIFY tuningFactChanged) - Q_PROPERTY(bool ready MEMBER _ready NOTIFY readyChanged) // true: editing can begin, false: still waiting for param update from vehicle - Q_PROPERTY(Fact* scale READ scale CONSTANT) - Q_PROPERTY(Fact* center READ center CONSTANT) - Q_PROPERTY(Fact* min READ min CONSTANT) - Q_PROPERTY(Fact* max READ max CONSTANT) - - Fact* tuningFact (void) { return _tuningFact; } - Fact* scale (void) { return &_scaleFact; } - Fact* center (void) { return &_centerFact; } - Fact* min (void) { return &_minFact; } - Fact* max (void) { return &_maxFact; } - void setTuningFact (Fact* tuningFact); + explicit RCToParamDialogController(QObject *parent = nullptr); + ~RCToParamDialogController(); + + Fact *tuningFact() { return _tuningFact; } + Fact *scale() { return _scaleFact; } + Fact *center() { return _centerFact; } + Fact *min() { return _minFact; } + Fact *max() { return _maxFact; } + void setTuningFact(Fact *tuningFact); signals: - void tuningFactChanged (Fact* fact); - void readyChanged (bool ready); + void tuningFactChanged(Fact *fact); + void readyChanged(bool ready); private slots: - void _parameterUpdated(void); + void _parameterUpdated(); private: + Fact *_tuningFact = nullptr; + Fact *_scaleFact = nullptr; + Fact *_centerFact = nullptr; + Fact *_minFact = nullptr; + Fact *_maxFact = nullptr; + bool _ready = false; + static QMap _metaDataMap; - Fact* _tuningFact = nullptr; - bool _ready = false; - Fact _scaleFact; - Fact _centerFact; - Fact _minFact; - Fact _maxFact; - - static constexpr const char* _scaleFactName = "Scale"; - static constexpr const char* _centerFactName = "CenterValue"; - static constexpr const char* _minFactName = "MinValue"; - static constexpr const char* _maxFactName = "MaxValue"; + static constexpr const char *_scaleFactName = "Scale"; + static constexpr const char *_centerFactName = "CenterValue"; + static constexpr const char *_minFactName = "MinValue"; + static constexpr const char *_maxFactName = "MaxValue"; }; diff --git a/src/QmlControls/ScreenToolsController.cc b/src/QmlControls/ScreenToolsController.cc index f33c571854f..ccc25c4c1d5 100644 --- a/src/QmlControls/ScreenToolsController.cc +++ b/src/QmlControls/ScreenToolsController.cc @@ -13,25 +13,44 @@ #include "ScreenToolsController.h" #include "QGCApplication.h" +#include "QGCLoggingCategory.h" +#include "SettingsManager.h" + +#include #include #include #include -#include "SettingsManager.h" - #if defined(Q_OS_IOS) #include #endif -ScreenToolsController::ScreenToolsController() +QGC_LOGGING_CATEGORY(ScreenToolsControllerLog, "qgc.qmlcontrols.screentoolscontroller") + +ScreenToolsController::ScreenToolsController(QObject *parent) + : QObject(parent) +{ + // qCDebug(ScreenToolsControllerLog) << Q_FUNC_INFO << this; +} + +ScreenToolsController::~ScreenToolsController() { + // qCDebug(ScreenToolsControllerLog) << Q_FUNC_INFO << this; +} + +int ScreenToolsController::mouseX() +{ + return QCursor::pos().x(); +} +int ScreenToolsController::mouseY() +{ + return QCursor::pos().y(); } -bool -ScreenToolsController::hasTouch() const +bool ScreenToolsController::hasTouch() { - for (const auto& inputDevice: QInputDevice::devices()) { + for (const auto &inputDevice: QInputDevice::devices()) { if (inputDevice->type() == QInputDevice::DeviceType::TouchScreen) { return true; } @@ -39,8 +58,7 @@ ScreenToolsController::hasTouch() const return false; } -QString -ScreenToolsController::iOSDevice() const +QString ScreenToolsController::iOSDevice() { #if defined(Q_OS_IOS) struct utsname systemInfo; @@ -51,29 +69,30 @@ ScreenToolsController::iOSDevice() const #endif } -QString -ScreenToolsController::fixedFontFamily() const +QString ScreenToolsController::fixedFontFamily() { return QFontDatabase::systemFont(QFontDatabase::FixedFont).family(); } -QString -ScreenToolsController::normalFontFamily() const +QString ScreenToolsController::normalFontFamily() { //-- See App.SettinsGroup.json for index - int langID = qgcApp()->toolbox()->settingsManager()->appSettings()->qLocaleLanguage()->rawValue().toInt(); - if(langID == QLocale::Korean) { - return QString("NanumGothic"); - } else { - return QString("Open Sans"); + const int langID = qgcApp()->toolbox()->settingsManager()->appSettings()->qLocaleLanguage()->rawValue().toInt(); + if (langID == QLocale::Korean) { + return QStringLiteral("NanumGothic"); } + + return QStringLiteral("Open Sans"); } -double ScreenToolsController::defaultFontDescent(int pointSize) const +double ScreenToolsController::defaultFontDescent(int pointSize) { return QFontMetrics(QFont(normalFontFamily(), pointSize)).descent(); } -#ifndef __mobile__ -bool ScreenToolsController::fakeMobile() const { return qgcApp()->fakeMobile(); } +#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS) +bool ScreenToolsController::fakeMobile() +{ + return qgcApp()->fakeMobile(); +} #endif diff --git a/src/QmlControls/ScreenToolsController.h b/src/QmlControls/ScreenToolsController.h index 53979bdded6..3b8a5bf742c 100644 --- a/src/QmlControls/ScreenToolsController.h +++ b/src/QmlControls/ScreenToolsController.h @@ -13,20 +13,18 @@ #pragma once -#include -#include +#include +#include +#include -/*! - @brief Screen helper tools for QML widgets -*/ +Q_DECLARE_LOGGING_CATEGORY(ScreenToolsControllerLog) /// This Qml control is used to return screen parameters -class ScreenToolsController : public QQuickItem +class ScreenToolsController : public QObject { Q_OBJECT -public: - ScreenToolsController(); - + QML_ELEMENT + // TODO: Q_NAMESPACE Q_PROPERTY(bool isAndroid READ isAndroid CONSTANT) Q_PROPERTY(bool isiOS READ isiOS CONSTANT) Q_PROPERTY(bool isMobile READ isMobile CONSTANT) @@ -41,73 +39,77 @@ class ScreenToolsController : public QQuickItem Q_PROPERTY(QString fixedFontFamily READ fixedFontFamily CONSTANT) Q_PROPERTY(QString normalFontFamily READ normalFontFamily CONSTANT) - // Returns current mouse position - Q_INVOKABLE int mouseX(void) { return QCursor::pos().x(); } - Q_INVOKABLE int mouseY(void) { return QCursor::pos().y(); } +public: + explicit ScreenToolsController(QObject *parent = nullptr); + ~ScreenToolsController(); + + /// Returns current mouse position + Q_INVOKABLE static int mouseX(); + Q_INVOKABLE static int mouseY(); // QFontMetrics::descent for default font - Q_INVOKABLE double defaultFontDescent(int pointSize) const; + Q_INVOKABLE static double defaultFontDescent(int pointSize); -#if defined(__mobile__) - bool isMobile () const { return true; } - bool fakeMobile () const { return false; } +#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) + static bool isMobile() { return true; } + static bool fakeMobile() { return false; } #else - bool isMobile () const { return fakeMobile(); } - bool fakeMobile () const; + static bool isMobile() { return fakeMobile(); } + static bool fakeMobile(); #endif #if defined (Q_OS_ANDROID) - bool isAndroid () { return true; } - bool isiOS () { return false; } - bool isLinux () { return false; } - bool isMacOS () { return false; } - bool isWindows () { return false; } + static bool isAndroid() { return true; } + static bool isiOS() { return false; } + static bool isLinux() { return false; } + static bool isMacOS() { return false; } + static bool isWindows() { return false; } #elif defined(Q_OS_IOS) - bool isAndroid () { return false; } - bool isiOS () { return true; } - bool isLinux () { return false; } - bool isMacOS () { return false; } - bool isWindows () { return false; } + static bool isAndroid() { return false; } + static bool isiOS() { return true; } + static bool isLinux() { return false; } + static bool isMacOS() { return false; } + static bool isWindows() { return false; } #elif defined(Q_OS_MAC) - bool isAndroid () { return false; } - bool isiOS () { return false; } - bool isLinux () { return false; } - bool isMacOS () { return true; } - bool isWindows () { return false; } + static bool isAndroid() { return false; } + static bool isiOS() { return false; } + static bool isLinux() { return false; } + static bool isMacOS() { return true; } + static bool isWindows() { return false; } #elif defined(Q_OS_LINUX) - bool isAndroid () { return false; } - bool isiOS () { return false; } - bool isLinux () { return true; } - bool isMacOS () { return false; } - bool isWindows () { return false; } + static bool isAndroid() { return false; } + static bool isiOS() { return false; } + static bool isLinux() { return true; } + static bool isMacOS() { return false; } + static bool isWindows() { return false; } #elif defined(Q_OS_WIN) - bool isAndroid () { return false; } - bool isiOS () { return false; } - bool isLinux () { return false; } - bool isMacOS () { return false; } - bool isWindows () { return true; } + static bool isAndroid() { return false; } + static bool isiOS() { return false; } + static bool isLinux() { return false; } + static bool isMacOS() { return false; } + static bool isWindows() { return true; } #else - bool isAndroid () { return false; } - bool isiOS () { return false; } - bool isLinux () { return false; } - bool isMacOS () { return false; } - bool isWindows () { return false; } + static bool isAndroid() { return false; } + static bool isiOS() { return false; } + static bool isLinux() { return false; } + static bool isMacOS() { return false; } + static bool isWindows() { return false; } #endif #if defined(NO_SERIAL_LINK) - bool isSerialAvailable () { return false; } + static bool isSerialAvailable() { return false; } #else - bool isSerialAvailable () { return true; } + static bool isSerialAvailable() { return true; } #endif #ifdef QT_DEBUG - bool isDebug () { return true; } + static bool isDebug() { return true; } #else - bool isDebug () { return false; } + static bool isDebug() { return false; } #endif - bool hasTouch () const; - QString iOSDevice () const; - QString fixedFontFamily () const; - QString normalFontFamily () const; + static bool hasTouch(); + static QString iOSDevice(); + static QString fixedFontFamily(); + static QString normalFontFamily(); };