From e0582cd398a940f903a899f4b73f83bbde4a9c45 Mon Sep 17 00:00:00 2001 From: bsongis Date: Thu, 13 Mar 2014 08:44:50 +0100 Subject: [PATCH] Some refactoring in the new Wizard --- companion/src/CMakeLists.txt | 1 - companion/src/eeprominterface.cpp | 19 ----------- companion/src/eeprominterface.h | 2 -- companion/src/mdichild.cpp | 7 ++-- companion/src/wizarddata.cpp | 28 ++++++++++++++-- companion/src/wizarddata.h | 56 ++++++++++++++++++++++--------- companion/src/wizarddialog.cpp | 5 +-- companion/src/wizarddialog.h | 2 +- 8 files changed, 72 insertions(+), 48 deletions(-) diff --git a/companion/src/CMakeLists.txt b/companion/src/CMakeLists.txt index 5d60e530b..d52b40b1c 100644 --- a/companion/src/CMakeLists.txt +++ b/companion/src/CMakeLists.txt @@ -177,7 +177,6 @@ set(companion_MOC_HDRS mainwindow.h qcustomplot.h helpers.h - wizarddata.h wizarddialog.h ) diff --git a/companion/src/eeprominterface.cpp b/companion/src/eeprominterface.cpp index 6c63bb6f9..78e72131d 100644 --- a/companion/src/eeprominterface.cpp +++ b/companion/src/eeprominterface.cpp @@ -972,25 +972,6 @@ bool ModelData::isempty() return !used; } -void ModelData::importWizardData( unsigned int id, const WizMix mix ) -{ - clear(); - used = true; - modelId = id+1; - - // Safe copy model name - strncpy ( name, mix.name, WIZ_MODEL_NAME_LENGTH); - name[WIZ_MODEL_NAME_LENGTH] = 0; - - for (int i=0; i 0){ - - //**** INSERT MIXER HERE **** - } - } -} - void ModelData::setDefaultMixes(GeneralSettings & settings) { if (IS_TARANIS(GetEepromInterface()->getBoard())) { diff --git a/companion/src/eeprominterface.h b/companion/src/eeprominterface.h index 1af0de25f..f4a2bc7dc 100644 --- a/companion/src/eeprominterface.h +++ b/companion/src/eeprominterface.h @@ -24,7 +24,6 @@ #include #include #include -#include "wizarddata.h" #if __GNUC__ #define PACK( __Declaration__ ) __Declaration__ __attribute__((__packed__)) @@ -951,7 +950,6 @@ class ModelData { void clear(); bool isempty(); - void importWizardData(unsigned int, const WizMix); void setDefaultMixes(GeneralSettings & settings); void setDefaultValues(unsigned int id, GeneralSettings & settings); diff --git a/companion/src/mdichild.cpp b/companion/src/mdichild.cpp index 5101fa6eb..0405e6a12 100644 --- a/companion/src/mdichild.cpp +++ b/companion/src/mdichild.cpp @@ -185,11 +185,10 @@ void MdiChild::wizardEdit() int row = ui->modelsList->currentRow(); if (row > 0) { checkAndInitModel(row); - WizardDialog *wizard = new WizardDialog(this); + WizardDialog * wizard = new WizardDialog(row, this); wizard->exec(); - if (wizard->mix.complete){ - ModelData &model = radioData.models[row - 1]; - model.importWizardData(row - 1, wizard->mix); + if (wizard->mix.complete /*TODO rather test the exec() result?*/) { + radioData.models[row - 1] = wizard->mix; setModified(); } } diff --git a/companion/src/wizarddata.cpp b/companion/src/wizarddata.cpp index 427651c47..839350e52 100644 --- a/companion/src/wizarddata.cpp +++ b/companion/src/wizarddata.cpp @@ -28,11 +28,33 @@ void Channel::clear() weight2 = 0; } -WizMix::WizMix() +WizMix::WizMix(const unsigned int modelId): + complete(false), + modelId(modelId), + vehicle(NOVEHICLE) { - complete = false; strcpy(name, " "); - vehicle = NOVEHICLE; +} + +WizMix::operator ModelData() +{ + ModelData model; + + model.used = true; + model.modelId = modelId; + + // Safe copy model name + strncpy(model.name, name, WIZ_MODEL_NAME_LENGTH); + model.name[WIZ_MODEL_NAME_LENGTH] = 0; + + for (int i=0; i 0) { + //**** INSERT MIXER HERE **** + } + } + + return model; } diff --git a/companion/src/wizarddata.h b/companion/src/wizarddata.h index 68cc5ffd7..33620b230 100644 --- a/companion/src/wizarddata.h +++ b/companion/src/wizarddata.h @@ -15,34 +15,58 @@ #ifndef WIZARDDATA_H #define WIZARDDATA_H +#include "eeprominterface.h" + #define WIZ_MAX_CHANNELS 8 + +// TODO use a constant common to the whole companion +// TODO when in the wizard use the getCapacity(...) to know how long the name can be #define WIZ_MODEL_NAME_LENGTH 12 -enum Input {NOINPUT, THROTTLE, RUDDER, ELEVATOR, AILERON, FLAP, AIRBREAK}; -enum Vehicle {NOVEHICLE, PLANE, MULTICOPTER, HELICOPTER }; +enum Input { + NOINPUT, + THROTTLE, + RUDDER, + ELEVATOR, + AILERON, + FLAP, + AIRBREAK +}; + +enum Vehicle { + NOVEHICLE, + PLANE, + MULTICOPTER, + HELICOPTER +}; class Channel { -public: - int sourceDlg; // Originating dialog, only of interest for producer - Input input1; - Input input2; - int weight1; - int weight2; + public: + int sourceDlg; // Originating dialog, only of interest for producer + Input input1; + Input input2; + int weight1; + int weight2; - Channel(); - void clear(); + Channel(); + void clear(); }; class WizMix { -public: - bool complete; - char name[WIZ_MODEL_NAME_LENGTH + 1]; - Vehicle vehicle; - Channel channel[WIZ_MAX_CHANNELS]; + public: + bool complete; + char name[WIZ_MODEL_NAME_LENGTH + 1]; + unsigned int modelId; + Vehicle vehicle; + Channel channel[WIZ_MAX_CHANNELS]; - WizMix(); + explicit WizMix(const unsigned int modelId); + operator ModelData(); + + private: + WizMix(); }; #endif // WIZARDDATA_H diff --git a/companion/src/wizarddialog.cpp b/companion/src/wizarddialog.cpp index 0eaf56d3e..dc3ac05a0 100644 --- a/companion/src/wizarddialog.cpp +++ b/companion/src/wizarddialog.cpp @@ -16,8 +16,9 @@ #include "wizarddialog.h" #include "wizarddata.h" -WizardDialog::WizardDialog(QWidget *parent) - : QWizard(parent) +WizardDialog::WizardDialog(unsigned int modelId, QWidget *parent) + : QWizard(parent), + mix(modelId) { setWindowTitle(tr("Model Wizard")); diff --git a/companion/src/wizarddialog.h b/companion/src/wizarddialog.h index 35cc66793..f8d3d9a89 100644 --- a/companion/src/wizarddialog.h +++ b/companion/src/wizarddialog.h @@ -36,7 +36,7 @@ public: Page_Conclusion }; WizMix mix; - WizardDialog(QWidget *parent = 0); + WizardDialog(const unsigned int modelId, QWidget *parent = 0); private slots: void showHelp();