1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-24 00:35:18 +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 mainwindow.cpp
companion.cpp companion.cpp
qcustomplot.cpp qcustomplot.cpp
wizarddata.cpp
wizarddialog.cpp wizarddialog.cpp
) )
@ -176,6 +177,7 @@ set(companion_MOC_HDRS
mainwindow.h mainwindow.h
qcustomplot.h qcustomplot.h
helpers.h helpers.h
wizarddata.h
wizarddialog.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 <QtGui>
#include "wizarddialog.h" #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) WizardDialog::WizardDialog(QWidget *parent)
: QWizard(parent) : QWizard(parent)
{ {
@ -83,32 +42,66 @@ void WizardDialog::showHelp()
QString message; QString message;
switch (currentId()) { switch (currentId()) {
case Page_Models: message = tr("Select the type of model you want to create settings for."); break; case Page_Models:
case Page_Throttle: message = tr("Select the receiver channel that is connected to your ESC or throttle servo."); break; message = tr("Enter a name for your model and select model type."); 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. " case Page_Throttle:
"These aircrafts do not have a tail with control surfaces"); break; message = tr("Select the receiver channel that is connected to your ESC or throttle servo.<br><br>"
case Page_Ailerons: message = tr("One or two channels are used to control the Ailerons. " "Throttle - Spektrum: CH1, Futaba: CH3"); break;
"If your servos are connected by a common Y-cable you should select the single-servo option."); break; case Page_Wingtypes:
case Page_Flaps: message = tr("This wizard assumes that your flaps are controlled by a switch. " 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. "
"If your flaps are controlled by a potentiometer you can change that manually later." "The main control surface on a standard wing controlls the roll of the aircraft. This surface is called an aileron.<br>"
"Just select the correct receiver channel and an arbitrary switch."); break; "The control surface of a delta wing controls both roll and elevation. This surface is called an elevon. "); break;
case Page_Airbrakes: message = tr("Air brakes are used to reduce the speed of advanced sail planes. " case Page_Ailerons:
"It is very uncommon on other types of planes."); break; message = tr("Models use one or two channels to control the ailerons.<br>"
case Page_Bank: message = tr("Please note that, even if the elevons are controlled by separate servos, " "A so called Y-cable can be used to connect single receiver channel to two separeate aileron servos. "
"these may be controlled by a common channel."); break; "If your servos are connected by a Y-cable you should select the single-servo option.<br><br>"
case Page_Rudder: message = tr("TBD."); break; "Aileron - Spektrum: CH2, Futaba: CH1"); break;
case Page_Tails: message = tr("Select the tail type of your plane."); break; case Page_Flaps:
case Page_Tail: message = tr("TBD."); break; message = tr("This wizard assumes that your flaps are controlled by a switch. "
case Page_Vtail: message = tr("TBD."); break; "If your flaps are controlled by a potentiometer you can change that manually later."); break;
case Page_Simpletail: message = tr("TBD."); break; case Page_Airbrakes:
case Page_Flybar: message = tr("TBD."); break; message = tr("Air brakes are used to reduce the speed of advanced sail planes.<br>"
case Page_Cyclic: message = tr("TBD."); break; "They are very uncommon on other types of planes."); break;
case Page_Gyro: message = tr("TBD."); break; case Page_Bank:
case Page_Fblheli: message = tr("TBD."); break; message = tr("Models use one or two channels to control the elevons.<br>"
case Page_Helictrl: message = tr("TBD."); break; "A so called Y-cable can be used to connect single receiver channel to two separeate elevon servos. "
case Page_Multirotor: message = tr("TBD."); break; "If your servos are connected by a Y-cable you should select the single-servo option."); break;
case Page_Conclusion: message = tr("TBD."); break; case Page_Rudder:
default: message = tr("Move on. Nothin to see here."); 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); 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++) 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); 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) if (index<0 || index >= MAX_CHANNELS)
return false; return false;
if (!wizDlg->channel[index].isEmpty()) if (!wizDlg->mix.channel[index].isEmpty())
return false; return false;
wizDlg->channel[index].sourceDlg = pageCurrent; wizDlg->mix.channel[index].sourceDlg = pageCurrent;
wizDlg->channel[index].input1 = input1; wizDlg->mix.channel[index].input1 = input1;
wizDlg->channel[index].input2 = input2; wizDlg->mix.channel[index].input2 = input2;
wizDlg->channel[index].weight1 = weight1; wizDlg->mix.channel[index].weight1 = weight1;
wizDlg->channel[index].weight2 = weight2; wizDlg->mix.channel[index].weight2 = weight2;
return true; return true;
} }
@ -165,8 +158,8 @@ void StandardPage::releaseChannels()
{ {
for (int i=0; i<MAX_CHANNELS; i++) for (int i=0; i<MAX_CHANNELS; i++)
{ {
if (wizDlg->channel[i].sourceDlg == pageCurrent){ if (wizDlg->mix.channel[i].sourceDlg == pageCurrent){
wizDlg->channel[i].clear(); wizDlg->mix.channel[i].clear();
} }
} }
} }
@ -202,6 +195,18 @@ ModelSelectionPage::ModelSelectionPage(WizardDialog *dlg, QString image, QString
l->addWidget(helicopterRB); 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 int ModelSelectionPage::nextId() const
{ {
if (helicopterRB->isChecked()) if (helicopterRB->isChecked())
@ -700,15 +705,8 @@ ConclusionPage::ConclusionPage(WizardDialog *dlg, QString image, QString title,
} }
void ConclusionPage::initializePage(){ void ConclusionPage::initializePage(){
QString str;
for (int i=0; i<MAX_CHANNELS; i++){ textLabel->setText(wizDlg->mix.toString());
if (!wizDlg->channel[i].isEmpty()){
str += QString(tr("Channel %1: ").arg(i+1));
str += wizDlg->channel[i].print();
str += QString("<br>");
}
}
textLabel->setText(str);
} }

View file

@ -1,7 +1,7 @@
#ifndef WIZARDDIALOG_H #ifndef WIZARDDIALOG_H
#define WIZARDDIALOG_H #define WIZARDDIALOG_H
#include <QWizard> #include <QWizard>
#include "wizarddata.h"
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QCheckBox; class QCheckBox;
@ -11,28 +11,6 @@ class QRadioButton;
class QComboBox; class QComboBox;
QT_END_NAMESPACE 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 class WizardDialog : public QWizard
{ {
Q_OBJECT Q_OBJECT
@ -43,7 +21,7 @@ public:
Page_Fblheli, Page_Helictrl, Page_Multirotor, Page_Fblheli, Page_Helictrl, Page_Multirotor,
Page_Conclusion }; Page_Conclusion };
Channel channel[MAX_CHANNELS]; Mix mix;
WizardDialog(QWidget *parent = 0); WizardDialog(QWidget *parent = 0);
private slots: private slots:
@ -57,7 +35,7 @@ public:
StandardPage(int curPage, WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); StandardPage(int curPage, WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1);
WizardDialog *wizDlg; WizardDialog *wizDlg;
void populateCB( QComboBox *); 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 releaseChannels();
void cleanupPage(); void cleanupPage();
private: private:
@ -77,6 +55,7 @@ private:
QRadioButton *planeRB; QRadioButton *planeRB;
QRadioButton *multirotorRB; QRadioButton *multirotorRB;
QRadioButton *helicopterRB; QRadioButton *helicopterRB;
bool validatePage();
int nextId() const; int nextId() const;
}; };