diff --git a/companion/src/wizarddialog.cpp b/companion/src/wizarddialog.cpp index ad46d1fb0..179efa974 100644 --- a/companion/src/wizarddialog.cpp +++ b/companion/src/wizarddialog.cpp @@ -1,6 +1,6 @@ /* * Author - Kjell Kernen - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. @@ -181,6 +181,16 @@ int StandardPage::nextFreeChannel(int channel) return -1; } +int StandardPage::totalChannelsAvailable() +{ + int c = 0; + for(int i=0; imix.channel[i].page == Page_None) + c++; + + return c; +} + void StandardPage::populateCB(QComboBox *cb, int preferred) { cb->clear(); @@ -214,7 +224,7 @@ bool StandardPage::bookChannel(QComboBox * cb, Input input1, int weight1, Input { int channel = cb->itemData(cb->currentIndex()).toInt(); if (channel<0 || channel>=WIZ_MAX_CHANNELS) - return false; + return false; if (wizDlg->mix.channel[channel].page != Page_None) return false; @@ -231,7 +241,7 @@ void StandardPage::releaseBookings() { for (int i=0; imix.channel[i].page == pageCurrent) { - wizDlg->mix.channel[i].clear(); + wizDlg->mix.channel[i].clear(); } } } @@ -298,7 +308,7 @@ bool ModelSelectionPage::validatePage() return true; } -int ModelSelectionPage::nextId() const +int ModelSelectionPage::nextId() const { if (helicopterRB->isChecked()) return Page_Cyclic; @@ -432,7 +442,7 @@ AileronsPage::AileronsPage(WizardDialog *dlg, QString image, QString title, QStr l->addWidget(aileron1CB); l->addWidget(new QLabel(tr("Second Aileron Channel:"))); l->addWidget(aileron2CB); - + connect(noAileronsRB, SIGNAL(toggled(bool)), this, SLOT(noAileronChannel())); connect(oneAileronRB, SIGNAL(toggled(bool)), this, SLOT(oneAileronChannel())); connect(twoAileronsRB, SIGNAL(toggled(bool)), this, SLOT(twoAileronChannels())); @@ -448,10 +458,10 @@ void AileronsPage::initializePage() bool AileronsPage::validatePage() { releaseBookings(); - if (noAileronsRB->isChecked()) { + if (noAileronsRB->isChecked()) { return true; } - if (oneAileronRB->isChecked()) { + if (oneAileronRB->isChecked()) { return (bookChannel(aileron1CB, AILERONS_INPUT, 100 )); } return( bookChannel(aileron1CB, AILERONS_INPUT, 100 ) && @@ -497,7 +507,7 @@ FlapsPage::FlapsPage(WizardDialog *dlg, QString image, QString title, QString te l->addWidget(flap1CB); l->addWidget(new QLabel(tr("Second Flap Channel:"))); l->addWidget(flap2CB); - + connect(noFlapsRB, SIGNAL(toggled(bool)), this, SLOT(noFlapChannel())); connect(oneFlapRB, SIGNAL(toggled(bool)), this, SLOT(oneFlapChannel())); connect(twoFlapsRB, SIGNAL(toggled(bool)), this, SLOT(twoFlapChannels())); @@ -512,10 +522,10 @@ void FlapsPage::initializePage() bool FlapsPage::validatePage() { releaseBookings(); - if (noFlapsRB->isChecked()) { + if (noFlapsRB->isChecked()) { return true; } - if (oneFlapRB->isChecked()) { + if (oneFlapRB->isChecked()) { return (bookChannel(flap1CB, FLAPS_INPUT, 100 )); } return( bookChannel(flap1CB, FLAPS_INPUT, 100 ) && @@ -561,7 +571,7 @@ AirbrakesPage::AirbrakesPage(WizardDialog *dlg, QString image, QString title, QS l->addWidget(airbrake1CB); l->addWidget(new QLabel(tr("Second Airbrake Channel:"))); l->addWidget(airbrake2CB); - + connect(noAirbrakesRB, SIGNAL(toggled(bool)), this, SLOT(noAirbrakeChannel())); connect(oneAirbrakeRB, SIGNAL(toggled(bool)), this, SLOT(oneAirbrakeChannel())); connect(twoAirbrakesRB, SIGNAL(toggled(bool)), this, SLOT(twoAirbrakeChannels())); @@ -577,10 +587,10 @@ void AirbrakesPage::initializePage() bool AirbrakesPage::validatePage() { releaseBookings(); - if (noAirbrakesRB->isChecked()) { + if (noAirbrakesRB->isChecked()) { return true; } - if (oneAirbrakeRB->isChecked()) { + if (oneAirbrakeRB->isChecked()) { return (bookChannel(airbrake1CB, AIRBRAKES_INPUT, 100 )); } return( bookChannel(airbrake1CB, AIRBRAKES_INPUT, 100 ) && @@ -708,11 +718,13 @@ TailPage::TailPage(WizardDialog *dlg, QString image, QString title, QString text elevatorCB = new QComboBox(); rudderCB = new QComboBox(); - QLayout *l = layout(); + l = layout(); l->addWidget(new QLabel(tr("Rudder Channel:"))); l->addWidget(rudderCB); l->addWidget(new QLabel(tr("Elevator Channel:"))); l->addWidget(elevatorCB); + + errorMessage = NULL; } void TailPage::initializePage() @@ -720,6 +732,13 @@ void TailPage::initializePage() populateCB(elevatorCB, getDefaultChannel(ELEVATOR_INPUT)); populateCB(rudderCB, getDefaultChannel(RUDDER_INPUT)); StandardPage::initializePage(); + + if (totalChannelsAvailable() < 2) { + errorMessage = new QLabel(tr("Only one channel still available!
" + "You probably should configure your model without using the wizard.")); + errorMessage->setStyleSheet("QLabel { color : red; }"); + l->addWidget(errorMessage); + } } bool TailPage::validatePage() @@ -729,9 +748,20 @@ bool TailPage::validatePage() bookChannel(rudderCB, RUDDER_INPUT, 100)); } +void TailPage::cleanupPage() +{ + if (errorMessage) + { + l->removeWidget(errorMessage); + delete errorMessage; + errorMessage = NULL; + } + StandardPage::cleanupPage(); +} + SimpleTailPage::SimpleTailPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage) : StandardPage(Page_Simpletail, dlg, image, title, text, nextPage) -{ +{ elevatorCB = new QComboBox(); QLayout *l = layout(); @@ -1001,7 +1031,7 @@ WizardPrinter::WizardPrinter(WizMix *wizMix) { mix = wizMix; } - + QString WizardPrinter::printChannel( Input input1, int weight1, Input input2, int weight2 ) { QString str; diff --git a/companion/src/wizarddialog.h b/companion/src/wizarddialog.h index 8e1f2146f..f96f170ba 100644 --- a/companion/src/wizarddialog.h +++ b/companion/src/wizarddialog.h @@ -1,6 +1,6 @@ /* * Author - Kjell Kernen - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. @@ -15,7 +15,7 @@ #ifndef WIZARDDIALOG_H #define WIZARDDIALOG_H #include -#include "wizarddata.h" +#include "wizarddata.h" QT_BEGIN_NAMESPACE class QCheckBox; @@ -46,7 +46,7 @@ class StandardPage: public QWizardPage StandardPage(WizardPage curPage, WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); WizardDialog *wizDlg; - protected: + protected: void releaseBookings(); void releasePreBookings(); void initializePage(); @@ -55,6 +55,7 @@ class StandardPage: public QWizardPage int nextFreeChannel(int channel = 0); void populateCB(QComboBox * cb, int preferred=-1); bool bookChannel(QComboBox * cb, Input input1, int weight1, Input input2=NO_INPUT, int weight2=0); + int totalChannelsAvailable(); private: QLabel *topLabel; @@ -67,48 +68,48 @@ class ModelSelectionPage: public StandardPage { Q_OBJECT public: - ModelSelectionPage(WizardDialog *dlg, QString image, QString title, QString text); + ModelSelectionPage(WizardDialog *dlg, QString image, QString title, QString text); private: QLineEdit *nameLineEdit; QRadioButton *planeRB; QRadioButton *multirotorRB; QRadioButton *helicopterRB; bool validatePage(); - int nextId() const; + int nextId() const; }; class WingtypeSelectionPage: public StandardPage { Q_OBJECT public: - WingtypeSelectionPage(WizardDialog *dlg, QString image, QString title, QString text); + WingtypeSelectionPage(WizardDialog *dlg, QString image, QString title, QString text); private: QRadioButton *deltaWingRB; QRadioButton *standardWingRB; - int nextId() const; + int nextId() const; }; class TailSelectionPage: public StandardPage { Q_OBJECT public: - TailSelectionPage(WizardDialog *dlg, QString image, QString title, QString text); + TailSelectionPage(WizardDialog *dlg, QString image, QString title, QString text); private: QRadioButton *vTailRB; QRadioButton *standardTailRB; QRadioButton *simpleTailRB; - int nextId() const; + int nextId() const; }; class FlybarSelectionPage: public StandardPage { Q_OBJECT public: - FlybarSelectionPage(WizardDialog *dlg, QString image, QString title, QString text); + FlybarSelectionPage(WizardDialog *dlg, QString image, QString title, QString text); private: QRadioButton *flybarRB; QRadioButton *noFlybarRB; - int nextId() const; + int nextId() const; }; class ThrottlePage: public StandardPage @@ -133,10 +134,10 @@ class AileronsPage: public StandardPage { Q_OBJECT public: - AileronsPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); + AileronsPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); void initializePage(); bool validatePage(); - + protected slots: void noAileronChannel(); void oneAileronChannel(); @@ -154,7 +155,7 @@ class FlapsPage: public StandardPage { Q_OBJECT public: - FlapsPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); + FlapsPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); void initializePage(); bool validatePage(); @@ -175,7 +176,7 @@ class AirbrakesPage: public StandardPage { Q_OBJECT public: - AirbrakesPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); + AirbrakesPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); void initializePage(); bool validatePage(); @@ -229,19 +230,22 @@ class TailPage: public StandardPage { Q_OBJECT public: - TailPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); + TailPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); void initializePage(); + void cleanupPage(); bool validatePage(); private: QComboBox *elevatorCB; QComboBox *rudderCB; + QLayout *l; + QLabel *errorMessage; }; class VTailPage: public StandardPage { Q_OBJECT public: - VTailPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); + VTailPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); void initializePage(); bool validatePage(); private: @@ -253,7 +257,7 @@ class SimpleTailPage: public StandardPage { Q_OBJECT public: - SimpleTailPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); + SimpleTailPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); void initializePage(); bool validatePage(); private: @@ -264,7 +268,7 @@ class CyclicPage: public StandardPage { Q_OBJECT public: - CyclicPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); + CyclicPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); void initializePage(); bool validatePage(); private: @@ -278,7 +282,7 @@ class GyroPage: public StandardPage { Q_OBJECT public: - GyroPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); + GyroPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); void initializePage(); bool validatePage(); private: @@ -291,7 +295,7 @@ class FblPage: public StandardPage { Q_OBJECT public: - FblPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); + FblPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); void initializePage(); bool validatePage(); private: @@ -305,7 +309,7 @@ class HeliPage: public StandardPage { Q_OBJECT public: - HeliPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); + HeliPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); void initializePage(); bool validatePage(); private: @@ -319,7 +323,7 @@ class MultirotorPage: public StandardPage { Q_OBJECT public: - MultirotorPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); + MultirotorPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); void initializePage(); bool validatePage(); private: @@ -333,7 +337,7 @@ class OptionsPage: public StandardPage { Q_OBJECT public: - OptionsPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); + OptionsPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); void initializePage(); bool validatePage(); private: @@ -346,7 +350,7 @@ class ConclusionPage: public StandardPage { Q_OBJECT public: - ConclusionPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); + ConclusionPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); void initializePage(); bool validatePage(); private: