Expose child-props to QML binding class
This commit is contained in:
parent
edb5be38ee
commit
c2c3bc17f6
9 changed files with 280 additions and 32 deletions
|
@ -112,8 +112,6 @@ if (HAVE_QT)
|
|||
LaunchConfig.hxx
|
||||
MPServersModel.cpp
|
||||
MPServersModel.h
|
||||
PathUrlHelper.cxx
|
||||
PathUrlHelper.hxx
|
||||
RecentAircraftModel.cxx
|
||||
RecentAircraftModel.hxx
|
||||
RecentLocationsModel.cxx
|
||||
|
@ -176,12 +174,16 @@ if (HAVE_QT)
|
|||
FlightPlanController.hxx
|
||||
RouteDiagram.cxx
|
||||
RouteDiagram.hxx
|
||||
StackController.cxx
|
||||
StackController.hxx
|
||||
ModelDataExtractor.cxx
|
||||
ModelDataExtractor.hxx
|
||||
HoverArea.cxx
|
||||
HoverArea.hxx
|
||||
FGQQWindowManager.cxx
|
||||
FGQQWindowManager.hxx
|
||||
PathUrlHelper.cxx
|
||||
PathUrlHelper.hxx
|
||||
)
|
||||
|
||||
set_property(TARGET fgqmlui PROPERTY AUTOMOC ON)
|
||||
|
|
|
@ -1,3 +1,21 @@
|
|||
// Copyright (C) 2020 James Turner <james@flightgear.org>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "FGQmlPropertyNode.hxx"
|
||||
|
||||
#include <QVector3D>
|
||||
|
@ -120,6 +138,7 @@ void FGQmlPropertyNode::setNode(SGPropertyNode_ptr node)
|
|||
emit parentPropChanged(parentProp());
|
||||
emit pathChanged(path());
|
||||
emit valueChangedNotify(value());
|
||||
emit childPropsChanged();
|
||||
}
|
||||
|
||||
SGPropertyNode_ptr FGQmlPropertyNode::node() const
|
||||
|
@ -135,9 +154,40 @@ void FGQmlPropertyNode::valueChanged(SGPropertyNode *node)
|
|||
emit valueChangedNotify(value());
|
||||
}
|
||||
|
||||
void FGQmlPropertyNode::childAdded(SGPropertyNode* pr, SGPropertyNode* child)
|
||||
{
|
||||
if (pr == _prop) {
|
||||
emit childPropsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void FGQmlPropertyNode::childRemoved(SGPropertyNode* pr, SGPropertyNode* child)
|
||||
{
|
||||
if (pr == _prop) {
|
||||
emit childPropsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void FGQmlPropertyNode::setPath(QString path)
|
||||
{
|
||||
SGPropertyNode_ptr node = fgGetNode(path.toStdString(), false /* don't create */);
|
||||
setNode(node);
|
||||
}
|
||||
|
||||
|
||||
int FGQmlPropertyNode::childCount() const
|
||||
{
|
||||
if (!_prop)
|
||||
return 0;
|
||||
return _prop->nChildren();
|
||||
}
|
||||
|
||||
FGQmlPropertyNode* FGQmlPropertyNode::childAt(int index) const
|
||||
{
|
||||
if (!_prop || (_prop->nChildren() <= index))
|
||||
return nullptr;
|
||||
|
||||
auto pp = new FGQmlPropertyNode;
|
||||
pp->setNode(_prop->getChild(index));
|
||||
return pp;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,24 @@
|
|||
// Copyright (C) 2020 James Turner <james@flightgear.org>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
#ifndef FGQMLPROPERTYNODE_HXX
|
||||
#define FGQMLPROPERTYNODE_HXX
|
||||
|
||||
#include <QObject>
|
||||
#include <QQmlListProperty>
|
||||
#include <QVariant>
|
||||
|
||||
#include <simgear/props/props.hxx>
|
||||
|
@ -17,6 +34,9 @@ public:
|
|||
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged)
|
||||
Q_PROPERTY(FGQmlPropertyNode* parentProp READ parentProp NOTIFY parentPropChanged)
|
||||
|
||||
Q_PROPERTY(QQmlListProperty<FGQmlPropertyNode> childProps READ childProps NOTIFY childPropsChanged)
|
||||
|
||||
|
||||
Q_INVOKABLE bool set(QVariant newValue);
|
||||
|
||||
// children accessor
|
||||
|
@ -30,24 +50,53 @@ public:
|
|||
void setNode(SGPropertyNode_ptr node);
|
||||
|
||||
SGPropertyNode_ptr node() const;
|
||||
|
||||
QQmlListProperty<FGQmlPropertyNode> childProps()
|
||||
{
|
||||
return QQmlListProperty<FGQmlPropertyNode>(this,
|
||||
nullptr,
|
||||
nullptr,
|
||||
children_count,
|
||||
child_at,
|
||||
nullptr);
|
||||
}
|
||||
|
||||
|
||||
int childCount() const;
|
||||
FGQmlPropertyNode* childAt(int index) const;
|
||||
|
||||
protected:
|
||||
// SGPropertyChangeListener API
|
||||
|
||||
void valueChanged(SGPropertyNode * node) override;
|
||||
void childAdded(SGPropertyNode* pr, SGPropertyNode* child) override;
|
||||
void childRemoved(SGPropertyNode* pr, SGPropertyNode* child) override;
|
||||
|
||||
signals:
|
||||
signals:
|
||||
|
||||
void valueChangedNotify(QVariant value);
|
||||
|
||||
void pathChanged(QString path);
|
||||
|
||||
void parentPropChanged(FGQmlPropertyNode* parentProp);
|
||||
void childPropsChanged();
|
||||
|
||||
public slots:
|
||||
public slots:
|
||||
|
||||
void setPath(QString path);
|
||||
void setPath(QString path);
|
||||
|
||||
private:
|
||||
static int children_count(QQmlListProperty<FGQmlPropertyNode>* prop)
|
||||
{
|
||||
return static_cast<FGQmlPropertyNode*>(prop->object)->childCount();
|
||||
}
|
||||
|
||||
static FGQmlPropertyNode* child_at(QQmlListProperty<FGQmlPropertyNode>* prop,
|
||||
int index)
|
||||
{
|
||||
return static_cast<FGQmlPropertyNode*>(prop->object)->childAt(index);
|
||||
}
|
||||
|
||||
private:
|
||||
SGPropertyNode_ptr _prop;
|
||||
};
|
||||
|
||||
|
|
|
@ -27,35 +27,36 @@
|
|||
#include <Main/fg_props.hxx>
|
||||
#include "version.h"
|
||||
|
||||
#include "QtLauncher.hxx"
|
||||
#include "QmlAircraftInfo.hxx"
|
||||
#include "LauncherArgumentTokenizer.hxx"
|
||||
#include "PathUrlHelper.hxx"
|
||||
#include "PopupWindowTracker.hxx"
|
||||
#include "RecentAircraftModel.hxx"
|
||||
#include "RecentLocationsModel.hxx"
|
||||
#include "ThumbnailImageItem.hxx"
|
||||
#include "PreviewImageItem.hxx"
|
||||
#include "MPServersModel.h"
|
||||
#include "AircraftSearchFilterModel.hxx"
|
||||
#include "DefaultAircraftLocator.hxx"
|
||||
#include "LaunchConfig.hxx"
|
||||
#include "AircraftModel.hxx"
|
||||
#include "LocationController.hxx"
|
||||
#include "QmlPositioned.hxx"
|
||||
#include "PixmapImageItem.hxx"
|
||||
#include "AircraftSearchFilterModel.hxx"
|
||||
#include "AirportDiagram.hxx"
|
||||
#include "CarrierDiagram.hxx"
|
||||
#include "NavaidDiagram.hxx"
|
||||
#include "RouteDiagram.hxx"
|
||||
#include "QmlRadioButtonHelper.hxx"
|
||||
#include "UnitsModel.hxx"
|
||||
#include "NavaidSearchModel.hxx"
|
||||
#include "FlightPlanController.hxx"
|
||||
#include "ModelDataExtractor.hxx"
|
||||
#include "CarriersLocationModel.hxx"
|
||||
#include "SetupRootDialog.hxx"
|
||||
#include "DefaultAircraftLocator.hxx"
|
||||
#include "FlightPlanController.hxx"
|
||||
#include "HoverArea.hxx"
|
||||
#include "LaunchConfig.hxx"
|
||||
#include "LauncherArgumentTokenizer.hxx"
|
||||
#include "LocationController.hxx"
|
||||
#include "MPServersModel.h"
|
||||
#include "ModelDataExtractor.hxx"
|
||||
#include "NavaidDiagram.hxx"
|
||||
#include "NavaidSearchModel.hxx"
|
||||
#include "PathUrlHelper.hxx"
|
||||
#include "PixmapImageItem.hxx"
|
||||
#include "PopupWindowTracker.hxx"
|
||||
#include "PreviewImageItem.hxx"
|
||||
#include "QmlAircraftInfo.hxx"
|
||||
#include "QmlPositioned.hxx"
|
||||
#include "QmlRadioButtonHelper.hxx"
|
||||
#include "QtLauncher.hxx"
|
||||
#include "RecentAircraftModel.hxx"
|
||||
#include "RecentLocationsModel.hxx"
|
||||
#include "RouteDiagram.hxx"
|
||||
#include "SetupRootDialog.hxx"
|
||||
#include "StackController.hxx"
|
||||
#include "ThumbnailImageItem.hxx"
|
||||
#include "UnitsModel.hxx"
|
||||
|
||||
using namespace simgear::pkg;
|
||||
|
||||
|
@ -154,7 +155,7 @@ void LauncherController::initQML()
|
|||
qmlRegisterUncreatableType<Units>("FlightGear", 1, 0, "Units", "Only for enum");
|
||||
qmlRegisterType<UnitsModel>("FlightGear", 1, 0, "UnitsModel");
|
||||
|
||||
qmlRegisterType<FileDialogWrapper>("FlightGear.Launcher", 1, 0, "FileDialog");
|
||||
qmlRegisterType<FileDialogWrapper>("FlightGear", 1, 0, "FileDialog");
|
||||
qmlRegisterType<QmlAircraftInfo>("FlightGear.Launcher", 1, 0, "AircraftInfo");
|
||||
qmlRegisterType<PopupWindowTracker>("FlightGear.Launcher", 1, 0, "PopupWindowTracker");
|
||||
|
||||
|
@ -174,6 +175,7 @@ void LauncherController::initQML()
|
|||
qmlRegisterType<RouteDiagram>("FlightGear", 1, 0, "RouteDiagram");
|
||||
qmlRegisterType<QmlRadioButtonGroup>("FlightGear", 1, 0, "RadioButtonGroup");
|
||||
qmlRegisterType<HoverArea>("FlightGear", 1, 0, "HoverArea");
|
||||
qmlRegisterType<StackController>("FlightGear", 1, 0, "StackController");
|
||||
|
||||
qmlRegisterType<ModelDataExtractor>("FlightGear", 1, 0, "ModelDataExtractor");
|
||||
|
||||
|
|
|
@ -1,3 +1,24 @@
|
|||
// PathUrlHelper.cxx - manage a stack of QML items
|
||||
//
|
||||
// Written by James Turner, started March 2018
|
||||
//
|
||||
// Copyright (C) 2018 James Turner <james@flightgear.org>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
|
||||
#include "PathUrlHelper.hxx"
|
||||
|
||||
#include <QFileDialog>
|
||||
|
|
|
@ -1,3 +1,23 @@
|
|||
// PathUrlHelper.hxx - manage a stack of QML items
|
||||
//
|
||||
// Written by James Turner, started March 2018
|
||||
//
|
||||
// Copyright (C) 2018 James Turner <james@flightgear.org>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
#ifndef PATHURLHELPER_H
|
||||
#define PATHURLHELPER_H
|
||||
|
||||
|
|
53
src/GUI/StackController.cxx
Normal file
53
src/GUI/StackController.cxx
Normal file
|
@ -0,0 +1,53 @@
|
|||
// StackController.cxx - manage a stack of QML items
|
||||
//
|
||||
// Written by James Turner, started February 2019
|
||||
//
|
||||
// Copyright (C) 2019 James Turner <james@flightgear.org>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
#include "StackController.hxx"
|
||||
|
||||
StackController::StackController()
|
||||
{
|
||||
}
|
||||
|
||||
QUrl StackController::currentPageSource() const
|
||||
{
|
||||
if (m_stack.empty())
|
||||
return {};
|
||||
return m_stack.front();
|
||||
}
|
||||
|
||||
void StackController::push(QUrl page)
|
||||
{
|
||||
m_stack.push_front(page);
|
||||
emit currentPageChanged();
|
||||
}
|
||||
|
||||
void StackController::pop()
|
||||
{
|
||||
if (m_stack.empty())
|
||||
return;
|
||||
m_stack.pop_front();
|
||||
emit currentPageChanged();
|
||||
}
|
||||
|
||||
void StackController::replace(QUrl url)
|
||||
{
|
||||
m_stack.clear();
|
||||
m_stack.push_back(url);
|
||||
emit currentPageChanged();
|
||||
}
|
51
src/GUI/StackController.hxx
Normal file
51
src/GUI/StackController.hxx
Normal file
|
@ -0,0 +1,51 @@
|
|||
// StackController.hxx - manage a stack of QML items
|
||||
//
|
||||
// Written by James Turner, started February 2019
|
||||
//
|
||||
// Copyright (C) 2019 James Turner <james@flightgear.org>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
|
||||
#ifndef FG_GUI_STACK_CONTROLLER_HXX
|
||||
#define FG_GUI_STACK_CONTROLLER_HXX
|
||||
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
#include <QVector>
|
||||
|
||||
class StackController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QUrl currentPageSource READ currentPageSource NOTIFY currentPageChanged)
|
||||
|
||||
public:
|
||||
StackController();
|
||||
|
||||
Q_INVOKABLE void push(QUrl page);
|
||||
Q_INVOKABLE void pop();
|
||||
Q_INVOKABLE void replace(QUrl url);
|
||||
|
||||
QUrl currentPageSource() const;
|
||||
|
||||
signals:
|
||||
void currentPageChanged();
|
||||
|
||||
private:
|
||||
QVector<QUrl> m_stack;
|
||||
};
|
||||
|
||||
#endif // FG_GUI_STACK_CONTROLLER_HXX
|
|
@ -1,5 +1,5 @@
|
|||
import QtQuick 2.4
|
||||
import FlightGear.Launcher 1.0 as FG
|
||||
import FlightGear 1.0 as FG
|
||||
|
||||
import "."
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue