1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-31 16:52:10 +01:00

LP-29 add ability to change vehicle model using up and down arrow key

wip : needs a proper UI to let user change model
This commit is contained in:
Philippe Renon 2016-03-12 18:48:45 +01:00
parent e6ada50587
commit 2c7333935d
4 changed files with 87 additions and 8 deletions

View File

@ -28,13 +28,18 @@
#include "pfdqmlcontext.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"
#include "uavobjectmanager.h"
#include "utils/stringutils.h"
#include "utils/pathutils.h"
#include "flightbatterysettings.h"
#include <QQmlContext>
#include <QDebug>
#include <QDirIterator>
const QString PfdQmlContext::CONTEXT_PROPERTY_NAME = "pfdContext";
PfdQmlContext::PfdQmlContext(QObject *parent) : QObject(parent),
m_speedUnit("m/s"),
@ -50,8 +55,13 @@ PfdQmlContext::PfdQmlContext(QObject *parent) : QObject(parent),
m_dateTime(QDateTime()),
m_minAmbientLight(0.03),
m_modelFile(""),
m_modelIndex(0),
m_backgroundImageFile("")
{}
{
addModelDir("helis");
addModelDir("multi");
addModelDir("planes");
}
PfdQmlContext::~PfdQmlContext()
{}
@ -220,11 +230,32 @@ QString PfdQmlContext::modelFile() const
void PfdQmlContext::setModelFile(const QString &arg)
{
if (m_modelFile != arg) {
m_modelFile = arg;
m_modelFile = arg;
m_modelIndex = m_modelFileList.indexOf(m_modelFile);
if (m_modelIndex == -1) {
m_modelIndex = 0;
}
emit modelFileChanged(modelFile());
}
}
void PfdQmlContext::nextModel()
{
m_modelIndex = (m_modelIndex + 1) % m_modelFileList.length();
setModelFile(m_modelFileList[m_modelIndex]);
}
void PfdQmlContext::previousModel()
{
m_modelIndex = (m_modelFileList.length() + m_modelIndex - 1) % m_modelFileList.length();
setModelFile(m_modelFileList[m_modelIndex]);
}
QStringList PfdQmlContext::modelFileList() const
{
return m_modelFileList;
}
QString PfdQmlContext::backgroundImageFile() const
{
return m_backgroundImageFile;
@ -281,12 +312,16 @@ void PfdQmlContext::loadConfiguration(PfdQmlGadgetConfiguration *config)
void PfdQmlContext::saveState(QSettings *settings)
{
Q_UNUSED(settings);
settings->setValue("modelFile", modelFile());
}
void PfdQmlContext::restoreState(QSettings *settings)
{
Q_UNUSED(settings);
QString file = settings->value("modelFile").toString();
if (!file.isEmpty()) {
setModelFile(file);
}
}
void PfdQmlContext::apply(QQmlContext *context)
@ -339,6 +374,17 @@ void PfdQmlContext::apply(QQmlContext *context)
}
}
// to expose settings values
context->setContextProperty("pfdContext", this);
// expose this context to Qml
context->setContextProperty(CONTEXT_PROPERTY_NAME, this);
}
void PfdQmlContext::addModelDir(QString dir)
{
QDirIterator it(Utils::GetDataPath() + "models/" + dir, QStringList("*.3ds"), QDir::NoFilter, QDirIterator::Subdirectories);
while (it.hasNext()) {
QString file = QDir::toNativeSeparators(it.next());
// qDebug() << file;
m_modelFileList.append(file);
}
}

View File

@ -52,7 +52,11 @@ class PfdQmlContext : public QObject {
Q_PROPERTY(QDateTime dateTime READ dateTime WRITE setDateTime NOTIFY dateTimeChanged)
Q_PROPERTY(double minimumAmbientLight READ minimumAmbientLight WRITE setMinimumAmbientLight NOTIFY minimumAmbientLightChanged)
Q_PROPERTY(QString modelFile READ modelFile WRITE setModelFile NOTIFY modelFileChanged)
// model
Q_PROPERTY(QString modelFile READ modelFile NOTIFY modelFileChanged)
Q_PROPERTY(QStringList modelFileList READ modelFileList CONSTANT FINAL)
// background
Q_PROPERTY(QString backgroundImageFile READ backgroundImageFile WRITE setBackgroundImageFile NOTIFY backgroundImageFileChanged)
public:
@ -87,8 +91,14 @@ public:
double minimumAmbientLight() const;
void setMinimumAmbientLight(double arg);
// model
QString modelFile() const;
void setModelFile(const QString &arg);
QStringList modelFileList() const;
Q_INVOKABLE void nextModel();
Q_INVOKABLE void previousModel();
// background
QString backgroundImageFile() const;
void setBackgroundImageFile(const QString &arg);
@ -121,6 +131,9 @@ signals:
void backgroundImageFileChanged(QString arg);
private:
// constants
static const QString CONTEXT_PROPERTY_NAME;
QString m_speedUnit;
double m_speedFactor;
QString m_altitudeUnit;
@ -138,7 +151,11 @@ private:
double m_minAmbientLight;
QString m_modelFile;
int m_modelIndex;
QStringList m_modelFileList;
QString m_backgroundImageFile;
void addModelDir(QString dir);
};
#endif /* PFDQMLCONTEXT_H_ */

View File

@ -89,4 +89,12 @@ OSGViewport {
// model will be tracked
trackNode: modelTransformNode
}
Keys.onUpPressed: {
pfdContext.nextModel();
}
Keys.onDownPressed: {
pfdContext.previousModel();
}
}

View File

@ -62,6 +62,14 @@ Item {
fieldOfView: 90
sceneNode: transformNode
}
Keys.onUpPressed: {
pfdContext.nextModel();
}
Keys.onDownPressed: {
pfdContext.previousModel();
}
}
}