mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-11-29 07:24:13 +01:00
OP-1150/OP-1068: Create a QStateMachine based wizard infrastructure
This commit is contained in:
parent
1f27bffb38
commit
ce2113f912
@ -0,0 +1,34 @@
|
||||
import QtQuick 2.0
|
||||
|
||||
Rectangle{
|
||||
property alias text : textLabel.text
|
||||
property bool active
|
||||
property bool done
|
||||
height: 25
|
||||
color : "transparent"
|
||||
Rectangle{
|
||||
id: line
|
||||
x: parent.height / 2 -1
|
||||
y: 0
|
||||
width: 2
|
||||
height: parent.height
|
||||
color: "#ff0000"
|
||||
}
|
||||
Rectangle{
|
||||
x: 3
|
||||
y: 3
|
||||
id: circle
|
||||
width: parent.height - (y * 2)
|
||||
height: width
|
||||
color: parent.active ? "red" : ( parent.done ? "green" : "grey")
|
||||
border.color: "transparent"
|
||||
border.width: 0
|
||||
radius: parent.active ? 0 : width * 0.5
|
||||
rotation: 45
|
||||
}
|
||||
Text{
|
||||
id: textLabel
|
||||
x: parent.height + 4
|
||||
y: 0 //parent.height
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
#include "wizardmodel.h"
|
||||
|
||||
WizardModel::WizardModel(QObject *parent) :
|
||||
QStateMachine(parent)
|
||||
{
|
||||
}
|
||||
|
||||
WizardState* WizardModel::currentState(){
|
||||
foreach (QAbstractState *value, this->configuration()){
|
||||
if(value->parent() != 0){\
|
||||
return static_cast<WizardState*>(value);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
#ifndef WIZARDMODEL_H
|
||||
#define WIZARDMODEL_H
|
||||
|
||||
#include <QStateMachine>
|
||||
#include <QQmlListProperty>
|
||||
#include "wizardstate.h"
|
||||
|
||||
class WizardModel : public QStateMachine
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QQmlListProperty<QObject> steps READ steps CONSTANT)
|
||||
Q_PROPERTY(QString instructions READ instructions NOTIFY instructionChanged)
|
||||
Q_PROPERTY(WizardState* currentState READ currentState NOTIFY currentStateChanged)
|
||||
public:
|
||||
explicit WizardModel(QObject *parent = 0);
|
||||
|
||||
QQmlListProperty<QObject> steps() {
|
||||
return QQmlListProperty<QObject>(this, m_steps);
|
||||
}
|
||||
|
||||
QString instructions(){
|
||||
return m_instructions;
|
||||
}
|
||||
|
||||
void setInstructions(QString instructions){
|
||||
m_instructions = instructions;
|
||||
emit instructionChanged();
|
||||
}
|
||||
WizardState *currentState();
|
||||
protected:
|
||||
QList<QObject*> m_steps;
|
||||
private:
|
||||
QString m_instructions;
|
||||
signals:
|
||||
void instructionChanged();
|
||||
void currentStateChanged();
|
||||
public slots:
|
||||
|
||||
};
|
||||
|
||||
#endif // WIZARDMODEL_H
|
@ -0,0 +1,46 @@
|
||||
#include "wizardstate.h"
|
||||
|
||||
WizardState::WizardState(QString name, QState *parent) :
|
||||
QState(parent)
|
||||
{
|
||||
m_stepName = name;
|
||||
m_done = false;
|
||||
m_active = false;
|
||||
}
|
||||
|
||||
void WizardState::setCompletion(qint8 completion){
|
||||
m_completion = completion;
|
||||
emit completionChanged();
|
||||
}
|
||||
|
||||
void WizardState::setStepName(QString name)
|
||||
{
|
||||
m_stepName = name;
|
||||
emit stepNameChanged();
|
||||
}
|
||||
|
||||
void WizardState::onEntry(QEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
m_active = true;
|
||||
emit isActiveChanged();
|
||||
}
|
||||
|
||||
void WizardState::onExit(QEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
m_active = false;
|
||||
setIsDone(true);
|
||||
emit isActiveChanged();
|
||||
}
|
||||
|
||||
void WizardState::clean()
|
||||
{
|
||||
setIsDone(false);
|
||||
}
|
||||
|
||||
void WizardState::setIsDone(bool done)
|
||||
{
|
||||
m_done = done;
|
||||
emit isDoneChanged();
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
#ifndef WIZARDSTATE_H
|
||||
#define WIZARDSTATE_H
|
||||
|
||||
#include <QState>
|
||||
|
||||
class WizardState : public QState
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool isActive READ isActive NOTIFY isActiveChanged)
|
||||
Q_PROPERTY(bool isDone READ isDone NOTIFY isDoneChanged)
|
||||
Q_PROPERTY(qint8 completion READ completion NOTIFY completionChanged)
|
||||
Q_PROPERTY(QString stepName READ stepName NOTIFY stepNameChanged)
|
||||
public:
|
||||
explicit WizardState(QString name, QState *parent = 0);
|
||||
bool isActive(){
|
||||
return m_active;
|
||||
}
|
||||
|
||||
bool isDone(){
|
||||
return m_done;
|
||||
}
|
||||
|
||||
qint8 completion(){
|
||||
return m_completion;
|
||||
}
|
||||
|
||||
QString stepName(){
|
||||
return m_stepName;
|
||||
}
|
||||
|
||||
void setStepName(QString name);
|
||||
void setCompletion(qint8 completion);
|
||||
virtual void onEntry(QEvent *event) Q_DECL_OVERRIDE;
|
||||
virtual void onExit(QEvent *event) Q_DECL_OVERRIDE;
|
||||
signals:
|
||||
void isActiveChanged();
|
||||
void isDoneChanged();
|
||||
void stepNameChanged();
|
||||
void completionChanged();
|
||||
public slots:
|
||||
void clean();
|
||||
private:
|
||||
void setIsDone(bool done);
|
||||
bool m_done;
|
||||
bool m_active;
|
||||
qint8 m_completion;
|
||||
QString m_stepName;
|
||||
};
|
||||
|
||||
#endif // WIZARDSTATE_H
|
@ -2,12 +2,16 @@ TEMPLATE = lib
|
||||
TARGET = Config
|
||||
DEFINES += CONFIG_LIBRARY
|
||||
QT += svg
|
||||
QT += opengl
|
||||
QT += qml quick
|
||||
|
||||
include(config_dependencies.pri)
|
||||
|
||||
INCLUDEPATH += ../../libs/eigen
|
||||
|
||||
OTHER_FILES += Config.pluginspec
|
||||
OTHER_FILES += Config.pluginspec \
|
||||
calibration/magcalibrationui.qml \
|
||||
calibration/WizardStepIndicator.qml
|
||||
|
||||
HEADERS += configplugin.h \
|
||||
configgadgetwidget.h \
|
||||
@ -41,7 +45,9 @@ HEADERS += configplugin.h \
|
||||
dblspindelegate.h \
|
||||
configrevohwwidget.h \
|
||||
calibration/calibrationutils.h \
|
||||
calibration/thermalcalibration.h
|
||||
calibration/thermalcalibration.h \
|
||||
calibration/wizardstate.h \
|
||||
calibration/wizardmodel.h
|
||||
|
||||
SOURCES += configplugin.cpp \
|
||||
configgadgetwidget.cpp \
|
||||
@ -76,7 +82,9 @@ SOURCES += configplugin.cpp \
|
||||
dblspindelegate.cpp \
|
||||
configrevohwwidget.cpp \
|
||||
calibration/calibrationutils.cpp \
|
||||
calibration/thermalcalibration.cpp
|
||||
calibration/thermalcalibration.cpp \
|
||||
calibration/wizardstate.cpp \
|
||||
calibration/wizardmodel.cpp
|
||||
|
||||
FORMS += airframe.ui \
|
||||
airframe_ccpm.ui \
|
||||
|
@ -30,5 +30,6 @@
|
||||
<file>images/pipx-selected.png</file>
|
||||
<file>images/pipx-normal.png</file>
|
||||
<file>images/revolution_top.png</file>
|
||||
<file>calibration/WizardStepIndicator.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
Loading…
Reference in New Issue
Block a user