Launcher: fix the descriptionForState/null warning
This commit is contained in:
parent
9fbd879c9f
commit
361225f919
3 changed files with 29 additions and 41 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue