1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-23 16:25:16 +03:00

Wizard data broken out into separate files.

This commit is contained in:
Kjell Kernen 2014-03-03 14:40:02 +01:00
parent 858c9193cb
commit b347b6f9c5
5 changed files with 597 additions and 512 deletions

View file

@ -152,6 +152,7 @@ set(companion_SRCS
mainwindow.cpp
companion.cpp
qcustomplot.cpp
wizarddata.cpp
wizarddialog.cpp
)
@ -176,6 +177,7 @@ set(companion_MOC_HDRS
mainwindow.h
qcustomplot.h
helpers.h
wizarddata.h
wizarddialog.h
)

View file

@ -0,0 +1,67 @@
#include "wizarddata.h"
QString inputName(Input input)
{
switch (input){
case THROTTLE: return "THR";
case RUDDER: return "RUD";
case ELEVATOR: return "ELE";
case AILERON: return "AIL";
case FLAP: return "FLP";
case AIRBREAK: return "AIR";
default: return "---";
}
}
QString vehicleName(Vehicle vehicle)
{
switch (vehicle){
case PLANE: return "Plane";
case MULTICOPTER: return "Multicopter";
case HELICOPTER: return "Helicopter";
default: return "---";
}
}
Channel::Channel()
{
clear();
}
void Channel::clear()
{
sourceDlg = -1;
input1 = NOINPUT;
input2 = NOINPUT;
weight1 = 0;
weight2 = 0;
}
bool Channel::isEmpty()
{
return sourceDlg < 0;
}
QString Channel::toString()
{
QString str;
str = QString("[%1, %2]").arg(inputName(input1)).arg(weight1);
if ( input2 != NOINPUT )
str += QString("[%1, %2]").arg(inputName(input2)).arg(weight2);
return str;
}
QString Mix::toString()
{
QString str;
str = QString(tr("Model Name: ")) + name + "\n";
str += QString(tr("Model Type: ")) + vehicleName(vehicleType) + "\n";
for (int i=0; i<MAX_CHANNELS; i++){
if (!channel[i].isEmpty()){
str += QString(tr("Channel %1: ").arg(i+1));
str += channel[i].toString();
str += QString("\n");
}
}
return str;
}

View file

@ -0,0 +1,39 @@
#ifndef WIZARDDATA_H
#define WIZARDDATA_H
#include <QObject>
#define MAX_CHANNELS 8
enum Input {NOINPUT, THROTTLE, RUDDER, ELEVATOR, AILERON, FLAP, AIRBREAK};
enum Vehicle {NOVEHICLE, PLANE, MULTICOPTER, HELICOPTER };
QString inputName(Input);
QString vehicleName(Input);
class Channel
{
public:
int sourceDlg; // Originating dialog, only of interest for producer
Input input1;
Input input2;
int weight1;
int weight2;
Channel();
bool isEmpty();
void clear();
QString toString();
};
class Mix:QObject
{
Q_OBJECT
public:
QString name;
Vehicle vehicleType;
Channel channel[MAX_CHANNELS];
QString toString();
};
#endif // WIZARDDATA_H

View file

@ -1,47 +1,6 @@
#include <QtGui>
#include "wizarddialog.h"
Channel::Channel()
{
clear();
}
void Channel::clear()
{
sourceDlg = -1;
input1 = UNDEFINED;
input2 = UNDEFINED;
weight1 = 0;
weight2 = 0;
}
bool Channel::isEmpty()
{
return sourceDlg < 0;
}
QString Channel::nameOf(Input input)
{
switch (input){
case THROTTLE: return "THR";
case RUDDER: return "RUD";
case ELEVATOR: return "ELE";
case AILERON: return "AIL";
case FLAP: return "FLP";
case AIRBREAK: return "AIR";
default: return "---";
}
}
QString Channel::print()
{
QString str;
str = QString("[%1, %2]").arg(nameOf(input1)).arg(weight1);
if ( input2 != UNDEFINED )
str += QString("[%1, %2]").arg(nameOf(input2)).arg(weight2);
return str;
}
WizardDialog::WizardDialog(QWidget *parent)
: QWizard(parent)
{
@ -83,32 +42,66 @@ void WizardDialog::showHelp()
QString message;
switch (currentId()) {
case Page_Models: message = tr("Select the type of model you want to create settings for."); break;
case Page_Throttle: message = tr("Select the receiver channel that is connected to your ESC or throttle servo."); break;
case Page_Wingtypes: message = tr("The wing control surfaces of flying wings and delta winged aircraft are called elevons and are used for controlling both elevation and roll. "
"These aircrafts do not have a tail with control surfaces"); break;
case Page_Ailerons: message = tr("One or two channels are used to control the Ailerons. "
"If your servos are connected by a common Y-cable you should select the single-servo option."); break;
case Page_Flaps: message = tr("This wizard assumes that your flaps are controlled by a switch. "
"If your flaps are controlled by a potentiometer you can change that manually later."
"Just select the correct receiver channel and an arbitrary switch."); break;
case Page_Airbrakes: message = tr("Air brakes are used to reduce the speed of advanced sail planes. "
"It is very uncommon on other types of planes."); break;
case Page_Bank: message = tr("Please note that, even if the elevons are controlled by separate servos, "
"these may be controlled by a common channel."); break;
case Page_Rudder: message = tr("TBD."); break;
case Page_Tails: message = tr("Select the tail type of your plane."); break;
case Page_Tail: message = tr("TBD."); break;
case Page_Vtail: message = tr("TBD."); break;
case Page_Simpletail: message = tr("TBD."); break;
case Page_Flybar: message = tr("TBD."); break;
case Page_Cyclic: message = tr("TBD."); break;
case Page_Gyro: message = tr("TBD."); break;
case Page_Fblheli: message = tr("TBD."); break;
case Page_Helictrl: message = tr("TBD."); break;
case Page_Multirotor: message = tr("TBD."); break;
case Page_Conclusion: message = tr("TBD."); break;
default: message = tr("Move on. Nothin to see here.");
case Page_Models:
message = tr("Enter a name for your model and select model type."); break;
case Page_Throttle:
message = tr("Select the receiver channel that is connected to your ESC or throttle servo.<br><br>"
"Throttle - Spektrum: CH1, Futaba: CH3"); break;
case Page_Wingtypes:
message = tr("Most aircraft have a main wing and a tail with control surfaces. Flying wings and delta winged aircraft only have a single wing. "
"The main control surface on a standard wing controlls the roll of the aircraft. This surface is called an aileron.<br>"
"The control surface of a delta wing controls both roll and elevation. This surface is called an elevon. "); break;
case Page_Ailerons:
message = tr("Models use one or two channels to control the ailerons.<br>"
"A so called Y-cable can be used to connect single receiver channel to two separeate aileron servos. "
"If your servos are connected by a Y-cable you should select the single-servo option.<br><br>"
"Aileron - Spektrum: CH2, Futaba: CH1"); break;
case Page_Flaps:
message = tr("This wizard assumes that your flaps are controlled by a switch. "
"If your flaps are controlled by a potentiometer you can change that manually later."); break;
case Page_Airbrakes:
message = tr("Air brakes are used to reduce the speed of advanced sail planes.<br>"
"They are very uncommon on other types of planes."); break;
case Page_Bank:
message = tr("Models use one or two channels to control the elevons.<br>"
"A so called Y-cable can be used to connect single receiver channel to two separeate elevon servos. "
"If your servos are connected by a Y-cable you should select the single-servo option."); break;
case Page_Rudder:
message = tr("Select the receiver channel that is connected to your rudder.<br><br>"
"Rudder - Spektrum: CH4, Futaba: CH4"); break;
case Page_Tails:
message = tr("Select the tail type of your plane."); break;
case Page_Tail:
message = tr("Select the Rudder and Elevator channels.<br><br>"
"Rudder - Spektrum: CH4, Futaba: CH4<br>"
"Elevator - Spektrum: CH3, Futaba: CH2"); break;
case Page_Vtail:
message = tr("Select the Rudder and Elevator channels.<br><br>"
"Rudder - Spektrum: CH4, Futaba: CH4<br>"
"Elevator - Spektrum: CH3, Futaba: CH2"); break;
case Page_Simpletail:
message = tr("Select the Elevator channel.<br><br>"
"Elevator - Spektrum: CH3, Futaba: CH2"); break;
case Page_Flybar:
message = tr("TBD."); break;
case Page_Cyclic:
message = tr("TBD."); break;
case Page_Gyro:
message = tr("TBD."); break;
case Page_Fblheli:
message = tr("TBD."); break;
case Page_Helictrl:
message = tr("TBD."); break;
case Page_Multirotor:
message = tr("Select the control channels for your multirotor.<br><br>"
"Throttle - Spektrum: CH1, Futaba: CH3<br>"
"Yaw - Spektrum: CH4, Futaba: CH4<br>"
"Pitch - Spektrum: CH3, Futaba: CH2<br>"
"Roll - Spektrum: CH2, Futaba: CH1"); break;
case Page_Conclusion:
message = tr("TBD."); break;
default:
message = tr("There is no help available for the current page.");
}
QMessageBox::information(this, tr("Model Wizard Help"), message);
}
@ -137,7 +130,7 @@ void StandardPage::populateCB( QComboBox *CB )
for (int i=0; i<MAX_CHANNELS; i++)
{
if (wizDlg->channel[i].isEmpty()){
if (wizDlg->mix.channel[i].isEmpty()){
CB->addItem(tr("Channel ") + QString("%1").arg(i+1), i);
}
}
@ -149,14 +142,14 @@ bool StandardPage::bookChannel(QString label, Input input1, int weight1, Input i
if (index<0 || index >= MAX_CHANNELS)
return false;
if (!wizDlg->channel[index].isEmpty())
if (!wizDlg->mix.channel[index].isEmpty())
return false;
wizDlg->channel[index].sourceDlg = pageCurrent;
wizDlg->channel[index].input1 = input1;
wizDlg->channel[index].input2 = input2;
wizDlg->channel[index].weight1 = weight1;
wizDlg->channel[index].weight2 = weight2;
wizDlg->mix.channel[index].sourceDlg = pageCurrent;
wizDlg->mix.channel[index].input1 = input1;
wizDlg->mix.channel[index].input2 = input2;
wizDlg->mix.channel[index].weight1 = weight1;
wizDlg->mix.channel[index].weight2 = weight2;
return true;
}
@ -165,8 +158,8 @@ void StandardPage::releaseChannels()
{
for (int i=0; i<MAX_CHANNELS; i++)
{
if (wizDlg->channel[i].sourceDlg == pageCurrent){
wizDlg->channel[i].clear();
if (wizDlg->mix.channel[i].sourceDlg == pageCurrent){
wizDlg->mix.channel[i].clear();
}
}
}
@ -202,6 +195,18 @@ ModelSelectionPage::ModelSelectionPage(WizardDialog *dlg, QString image, QString
l->addWidget(helicopterRB);
}
bool ModelSelectionPage::validatePage()
{
wizDlg->mix.name = nameLineEdit->text();
if (multirotorRB->isChecked())
wizDlg->mix.vehicleType = MULTICOPTER;
else if (helicopterRB->isChecked())
wizDlg->mix.vehicleType = HELICOPTER;
else
wizDlg->mix.vehicleType = PLANE;
return true;
}
int ModelSelectionPage::nextId() const
{
if (helicopterRB->isChecked())
@ -614,9 +619,9 @@ void FblPage::initializePage(){
bool FblPage::validatePage() {
releaseChannels();
return( bookChannel(throttleCB->currentText(), THROTTLE, 100 ) &&
bookChannel(yawCB->currentText(), RUDDER, 100 ) &&
bookChannel(pitchCB->currentText(), ELEVATOR, 100 ) &&
bookChannel(rollCB->currentText(), AILERON, 100 ));
bookChannel( yawCB->currentText(), RUDDER, 100 ) &&
bookChannel( pitchCB->currentText(), ELEVATOR, 100 ) &&
bookChannel( rollCB->currentText(), AILERON, 100 ));
}
HeliPage::HeliPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage)
@ -648,9 +653,9 @@ void HeliPage::initializePage(){
bool HeliPage::validatePage() {
releaseChannels();
return( bookChannel(throttleCB->currentText(), THROTTLE, 100 ) &&
bookChannel(yawCB->currentText(), RUDDER, 100 ) &&
bookChannel(pitchCB->currentText(), ELEVATOR, 100 ) &&
bookChannel(rollCB->currentText(), AILERON, 100 ));
bookChannel( yawCB->currentText(), RUDDER, 100 ) &&
bookChannel( pitchCB->currentText(), ELEVATOR, 100 ) &&
bookChannel( rollCB->currentText(), AILERON, 100 ));
}
MultirotorPage::MultirotorPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage)
@ -700,15 +705,8 @@ ConclusionPage::ConclusionPage(WizardDialog *dlg, QString image, QString title,
}
void ConclusionPage::initializePage(){
QString str;
for (int i=0; i<MAX_CHANNELS; i++){
if (!wizDlg->channel[i].isEmpty()){
str += QString(tr("Channel %1: ").arg(i+1));
str += wizDlg->channel[i].print();
str += QString("<br>");
}
}
textLabel->setText(str);
textLabel->setText(wizDlg->mix.toString());
}

View file

@ -1,7 +1,7 @@
#ifndef WIZARDDIALOG_H
#define WIZARDDIALOG_H
#include <QWizard>
#include "wizarddata.h"
QT_BEGIN_NAMESPACE
class QCheckBox;
@ -11,28 +11,6 @@ class QRadioButton;
class QComboBox;
QT_END_NAMESPACE
#define MAX_CHANNELS 8
enum Input {UNDEFINED, THROTTLE, RUDDER, ELEVATOR, AILERON, FLAP, AIRBREAK};
class Channel
{
public:
int sourceDlg;
Input input1;
Input input2;
int weight1;
int weight2;
Channel();
QString nameOf(Input);
bool isEmpty();
void clear();
QString print();
};
class WizardDialog : public QWizard
{
Q_OBJECT
@ -43,10 +21,10 @@ public:
Page_Fblheli, Page_Helictrl, Page_Multirotor,
Page_Conclusion };
Channel channel[MAX_CHANNELS];
Mix mix;
WizardDialog(QWidget *parent = 0);
private slots:
private slots:
void showHelp();
};
@ -57,7 +35,7 @@ public:
StandardPage(int curPage, WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1);
WizardDialog *wizDlg;
void populateCB( QComboBox *);
bool bookChannel(QString label, Input input1, int weight1, Input input2=UNDEFINED, int weight2=0 );
bool bookChannel(QString label, Input input1, int weight1, Input input2=NOINPUT, int weight2=0 );
void releaseChannels();
void cleanupPage();
private:
@ -77,6 +55,7 @@ private:
QRadioButton *planeRB;
QRadioButton *multirotorRB;
QRadioButton *helicopterRB;
bool validatePage();
int nextId() const;
};