1
0
Fork 0

Launcher: fix the descriptionForState/null warning

This commit is contained in:
James Turner 2018-04-09 17:13:15 +01:00
parent 9fbd879c9f
commit 361225f919
3 changed files with 29 additions and 41 deletions

View file

@ -122,7 +122,7 @@ static AircraftStateVec readAircraftStates(const SGPath& setXMLPath)
} }
if (stateNames.empty()) { if (stateNames.empty()) {
qWarning() << "state with no names defined, skipping"; qWarning() << "state with no names defined, skipping" << QString::fromStdString(cn->getPath());
continue; continue;
} }
@ -157,9 +157,18 @@ class StatesModel : public QAbstractListModel
Q_PROPERTY(bool hasExplicitAuto READ hasExplicitAuto CONSTANT) Q_PROPERTY(bool hasExplicitAuto READ hasExplicitAuto CONSTANT)
public: public:
StatesModel()
{
}
StatesModel(const AircraftStateVec& states) : StatesModel(const AircraftStateVec& states) :
_data(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 // sort which places 'auto' item at the front if it exists
std::sort(_data.begin(), _data.end(), [](const StateInfo& a, const StateInfo& b) { std::sort(_data.begin(), _data.end(), [](const StateInfo& a, const StateInfo& b) {
if (a.primaryTag() == "auto") return true; if (a.primaryTag() == "auto") return true;
@ -246,6 +255,11 @@ public:
{ {
return _explicitAutoState; return _explicitAutoState;
} }
bool isEmpty() const
{
return _data.empty();
}
private: private:
AircraftStateVec _data; AircraftStateVec _data;
bool _explicitAutoState = false; bool _explicitAutoState = false;
@ -481,14 +495,14 @@ void QmlAircraftInfo::checkForStates()
{ {
QString path = pathOnDisk(); QString path = pathOnDisk();
if (path.isEmpty()) { if (path.isEmpty()) {
_statesModel.reset(); _statesModel.reset(new StatesModel);
emit infoChanged(); emit infoChanged();
return; return;
} }
auto states = readAircraftStates(SGPath::fromUtf8(path.toUtf8().toStdString())); auto states = readAircraftStates(SGPath::fromUtf8(path.toUtf8().toStdString()));
if (states.empty()) { if (states.empty()) {
_statesModel.reset(); _statesModel.reset(new StatesModel);
emit infoChanged(); emit infoChanged();
return; return;
} }
@ -504,7 +518,7 @@ void QmlAircraftInfo::setUri(QUrl u)
_item.clear(); _item.clear();
_package.clear(); _package.clear();
_statesModel.reset(); _statesModel.reset(new StatesModel);
if (u.isLocalFile()) { if (u.isLocalFile()) {
_item = LocalAircraftCache::instance()->findItemWithUri(u); _item = LocalAircraftCache::instance()->findItemWithUri(u);
@ -655,11 +669,13 @@ bool QmlAircraftInfo::isPackaged() const
return _package != PackageRef(); return _package != PackageRef();
} }
bool QmlAircraftInfo::hasStates() const
{
return !_statesModel->isEmpty();
}
StatesModel *QmlAircraftInfo::statesModel() StatesModel *QmlAircraftInfo::statesModel()
{ {
if (!hasStates())
return nullptr;
return _statesModel.data(); return _statesModel.data();
} }

View file

@ -103,10 +103,7 @@ public:
bool isPackaged() const; bool isPackaged() const;
bool hasStates() const bool hasStates() const;
{
return !_statesModel.isNull();
}
static const int StateTagRole; static const int StateTagRole;
static const int StateDescriptionRole; static const int StateDescriptionRole;

View file

@ -10,22 +10,7 @@ Item {
color: "#7f7f7f" color: "#7f7f7f"
} }
property string __aircraftDescription readonly property string __aircraftDescription: _launcher.selectedAircraftInfo.description
// 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: ""
}
// base image when preview not available // base image when preview not available
Rectangle { Rectangle {
@ -66,16 +51,14 @@ Item {
// conditional binding when we have valid previews // conditional binding when we have valid previews
Binding { Binding {
when: _launcher.selectedAircraftInfo != undefined && when: (_launcher.selectedAircraftInfo.previews.length > 0)
(_launcher.selectedAircraftInfo.previews.length > 0)
target: preview target: preview
property: "urlsList" property: "urlsList"
value: _launcher.selectedAircraftInfo.previews value: _launcher.selectedAircraftInfo.previews
} }
Binding { Binding {
when: _launcher.selectedAircraftInfo == undefined || when: _launcher.selectedAircraftInfo.previews.length === 0
_launcher.selectedAircraftInfo.previews.length == 0
target: preview target: preview
property: "urlsList" property: "urlsList"
value: _launcher.defaultSplashUrls() value: _launcher.defaultSplashUrls()
@ -114,6 +97,7 @@ Item {
baseTextColor: "white" baseTextColor: "white"
style: Text.Outline style: Text.Outline
styleColor: "black" styleColor: "black"
font.bold: true
onClicked: { onClicked: {
_launcher.launchUrl("http://flightgear.org/license.html"); _launcher.launchUrl("http://flightgear.org/license.html");
@ -208,14 +192,11 @@ Item {
} }
} }
Item { Item {
width: 1; height: 1 width: 1; height: 1
} }
// aircraft state row, if enabled // aircraft state row, if enabled
Item { Item {
width: 1; height: 1 width: 1; height: 1
visible: stateSelectionGroup.visible visible: stateSelectionGroup.visible
@ -241,13 +222,7 @@ Item {
maximumLineCount: 5 maximumLineCount: 5
elide: Text.ElideRight elide: Text.ElideRight
width: parent.width width: parent.width
text: _launcher.selectedAircraftInfo.statesModel.descriptionForState(stateSelectionCombo.currentIndex)
Binding {
when: _launcher.selectedAircraftInfo.statesModel != null
target: stateDescriptionText
property: "text"
value: _launcher.selectedAircraftInfo.statesModel.descriptionForState(stateSelectionCombo.currentIndex)
}
} }
Connections { Connections {