From 361225f919d7221471f0a1de011bb62d21e74485 Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 9 Apr 2018 17:13:15 +0100 Subject: [PATCH] Launcher: fix the descriptionForState/null warning --- src/GUI/QmlAircraftInfo.cxx | 30 +++++++++++++++++++++++------- src/GUI/QmlAircraftInfo.hxx | 5 +---- src/GUI/qml/Summary.qml | 35 +++++------------------------------ 3 files changed, 29 insertions(+), 41 deletions(-) diff --git a/src/GUI/QmlAircraftInfo.cxx b/src/GUI/QmlAircraftInfo.cxx index 8e548bd78..aaa9b1b3d 100644 --- a/src/GUI/QmlAircraftInfo.cxx +++ b/src/GUI/QmlAircraftInfo.cxx @@ -122,7 +122,7 @@ static AircraftStateVec readAircraftStates(const SGPath& setXMLPath) } if (stateNames.empty()) { - qWarning() << "state with no names defined, skipping"; + qWarning() << "state with no names defined, skipping" << QString::fromStdString(cn->getPath()); continue; } @@ -157,9 +157,18 @@ class StatesModel : public QAbstractListModel Q_PROPERTY(bool hasExplicitAuto READ hasExplicitAuto CONSTANT) public: + StatesModel() + { + } + StatesModel(const AircraftStateVec& states) : _data(states) { + // we use an empty model for aircraft with no states defined + if (states.empty()) { + return; + } + // sort which places 'auto' item at the front if it exists std::sort(_data.begin(), _data.end(), [](const StateInfo& a, const StateInfo& b) { if (a.primaryTag() == "auto") return true; @@ -246,6 +255,11 @@ public: { return _explicitAutoState; } + + bool isEmpty() const + { + return _data.empty(); + } private: AircraftStateVec _data; bool _explicitAutoState = false; @@ -481,14 +495,14 @@ void QmlAircraftInfo::checkForStates() { QString path = pathOnDisk(); if (path.isEmpty()) { - _statesModel.reset(); + _statesModel.reset(new StatesModel); emit infoChanged(); return; } auto states = readAircraftStates(SGPath::fromUtf8(path.toUtf8().toStdString())); if (states.empty()) { - _statesModel.reset(); + _statesModel.reset(new StatesModel); emit infoChanged(); return; } @@ -504,7 +518,7 @@ void QmlAircraftInfo::setUri(QUrl u) _item.clear(); _package.clear(); - _statesModel.reset(); + _statesModel.reset(new StatesModel); if (u.isLocalFile()) { _item = LocalAircraftCache::instance()->findItemWithUri(u); @@ -655,11 +669,13 @@ bool QmlAircraftInfo::isPackaged() const return _package != PackageRef(); } +bool QmlAircraftInfo::hasStates() const +{ + return !_statesModel->isEmpty(); +} + StatesModel *QmlAircraftInfo::statesModel() { - if (!hasStates()) - return nullptr; - return _statesModel.data(); } diff --git a/src/GUI/QmlAircraftInfo.hxx b/src/GUI/QmlAircraftInfo.hxx index 8a1755240..0d83441b8 100644 --- a/src/GUI/QmlAircraftInfo.hxx +++ b/src/GUI/QmlAircraftInfo.hxx @@ -103,10 +103,7 @@ public: bool isPackaged() const; - bool hasStates() const - { - return !_statesModel.isNull(); - } + bool hasStates() const; static const int StateTagRole; static const int StateDescriptionRole; diff --git a/src/GUI/qml/Summary.qml b/src/GUI/qml/Summary.qml index abeb0a1a8..afd553a70 100644 --- a/src/GUI/qml/Summary.qml +++ b/src/GUI/qml/Summary.qml @@ -10,22 +10,7 @@ Item { color: "#7f7f7f" } - property string __aircraftDescription - - // conditional bindings on aircraft description - Binding { - when: _launcher.selectedAircraftInfo != undefined - target: root - property: "__aircraftDescription" - value: _launcher.selectedAircraftInfo.description - } - - Binding { - when: _launcher.selectedAircraftInfo == undefined - target: root - property: "__aircraftDescription" - value: "" - } + readonly property string __aircraftDescription: _launcher.selectedAircraftInfo.description // base image when preview not available Rectangle { @@ -66,16 +51,14 @@ Item { // conditional binding when we have valid previews Binding { - when: _launcher.selectedAircraftInfo != undefined && - (_launcher.selectedAircraftInfo.previews.length > 0) + when: (_launcher.selectedAircraftInfo.previews.length > 0) target: preview property: "urlsList" value: _launcher.selectedAircraftInfo.previews } Binding { - when: _launcher.selectedAircraftInfo == undefined || - _launcher.selectedAircraftInfo.previews.length == 0 + when: _launcher.selectedAircraftInfo.previews.length === 0 target: preview property: "urlsList" value: _launcher.defaultSplashUrls() @@ -114,6 +97,7 @@ Item { baseTextColor: "white" style: Text.Outline styleColor: "black" + font.bold: true onClicked: { _launcher.launchUrl("http://flightgear.org/license.html"); @@ -208,14 +192,11 @@ Item { } } - - Item { width: 1; height: 1 } // aircraft state row, if enabled - Item { width: 1; height: 1 visible: stateSelectionGroup.visible @@ -241,13 +222,7 @@ Item { maximumLineCount: 5 elide: Text.ElideRight width: parent.width - - Binding { - when: _launcher.selectedAircraftInfo.statesModel != null - target: stateDescriptionText - property: "text" - value: _launcher.selectedAircraftInfo.statesModel.descriptionForState(stateSelectionCombo.currentIndex) - } + text: _launcher.selectedAircraftInfo.statesModel.descriptionForState(stateSelectionCombo.currentIndex) } Connections {