Each ModelEdit window now has its own FirmwareInterface (it means that

we could open 2 ModelEdit windows on different firmwares)
This commit is contained in:
bsongis
2014-04-18 16:55:53 +02:00
parent c5ac19a054
commit 50a73a3af5
30 changed files with 253 additions and 245 deletions
+48 -48
View File
@@ -5,8 +5,8 @@
#include "helpers.h"
#include "appdata.h"
TimerPanel::TimerPanel(QWidget *parent, ModelData & model, TimerData & timer, GeneralSettings & generalSettings):
ModelPanel(parent, model, generalSettings),
TimerPanel::TimerPanel(QWidget *parent, ModelData & model, TimerData & timer, GeneralSettings & generalSettings, FirmwareInterface * firmware):
ModelPanel(parent, model, generalSettings, firmware),
timer(timer),
ui(new Ui::Timer)
{
@@ -17,7 +17,7 @@ TimerPanel::TimerPanel(QWidget *parent, ModelData & model, TimerData & timer, Ge
// Mode
populateSwitchCB(ui->mode, timer.mode, generalSettings, POPULATE_TIMER_MODES);
if (!GetCurrentFirmware()->getCapability(PermTimers)) {
if (!firmware->getCapability(PermTimers)) {
ui->persistent->hide();
ui->persistentValue->hide();
}
@@ -41,7 +41,7 @@ void TimerPanel::update()
int sec = timer.val % 60;
ui->value->setTime(QTime(0, min, sec));
if (GetCurrentFirmware()->getCapability(PermTimers)) {
if (firmware->getCapability(PermTimers)) {
int sign = 1;
int pvalue = timer.pvalue;
if (pvalue < 0) {
@@ -94,8 +94,8 @@ void TimerPanel::on_minuteBeep_toggled(bool checked)
/******************************************************************************/
ModulePanel::ModulePanel(QWidget *parent, ModelData & model, ModuleData & module, GeneralSettings & generalSettings, int moduleIdx):
ModelPanel(parent, model, generalSettings),
ModulePanel::ModulePanel(QWidget *parent, ModelData & model, ModuleData & module, GeneralSettings & generalSettings, FirmwareInterface * firmware, int moduleIdx):
ModelPanel(parent, model, generalSettings, firmware),
module(module),
moduleIdx(moduleIdx),
ui(new Ui::Module)
@@ -112,7 +112,7 @@ ModulePanel::ModulePanel(QWidget *parent, ModelData & model, ModuleData & module
else {
ui->label_trainerMode->hide();
ui->trainerMode->hide();
if (GetCurrentFirmware()->getCapability(NumModules) > 1) {
if (firmware->getCapability(NumModules) > 1) {
if (moduleIdx == 0)
label = tr("Internal Radio System");
else
@@ -132,7 +132,7 @@ ModulePanel::ModulePanel(QWidget *parent, ModelData & model, ModuleData & module
}
}
if (GetCurrentFirmware()->getCapability(HasFailsafe)) {
if (firmware->getCapability(HasFailsafe)) {
for (int i=0; i<16; i++) {
QLabel * label = new QLabel(this);
label->setText(QString::number(i+1));
@@ -211,7 +211,7 @@ void ModulePanel::update()
ui->channelsCount->setVisible(mask & MASK_CHANNELS_RANGE);
ui->channelsCount->setEnabled(mask & MASK_CHANNELS_COUNT);
ui->channelsCount->setValue(module.channelsCount);
ui->channelsCount->setSingleStep(GetCurrentFirmware()->getCapability(HasPPMStart) ? 1 : 2);
ui->channelsCount->setSingleStep(firmware->getCapability(HasPPMStart) ? 1 : 2);
// PPM settings fields
ui->label_ppmPolarity->setVisible(mask & MASK_PPM_FIELDS);
@@ -223,10 +223,10 @@ void ModulePanel::update()
ui->label_ppmFrameLength->setVisible(mask & MASK_PPM_FIELDS);
ui->ppmFrameLength->setVisible(mask & MASK_PPM_FIELDS);
ui->ppmFrameLength->setMinimum(module.channelsCount*(model.extendedLimits ? 2.250 :2)+3.5);
ui->ppmFrameLength->setMaximum(GetCurrentFirmware()->getCapability(PPMFrameLength));
ui->ppmFrameLength->setMaximum(firmware->getCapability(PPMFrameLength));
ui->ppmFrameLength->setValue(22.5+((double)module.ppmFrameLength)*0.5);
if (GetCurrentFirmware()->getCapability(HasFailsafe)) {
if (firmware->getCapability(HasFailsafe)) {
ui->label_failsafeMode->setVisible(mask & MASK_FAILSAFES);
ui->failsafeMode->setVisible(mask & MASK_FAILSAFES);
ui->failsafeMode->setCurrentIndex(module.failsafeMode);
@@ -323,8 +323,8 @@ void ModulePanel::onFailsafeSpinChanged(double value)
/******************************************************************************/
Setup::Setup(QWidget *parent, ModelData & model, GeneralSettings & generalSettings):
ModelPanel(parent, model, generalSettings),
SetupPanel::SetupPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, FirmwareInterface * firmware):
ModelPanel(parent, model, generalSettings, firmware),
ui(new Ui::Setup)
{
lock = true;
@@ -336,23 +336,23 @@ Setup::Setup(QWidget *parent, ModelData & model, GeneralSettings & generalSettin
ui->name->setMaxLength(IS_TARANIS(GetEepromInterface()->getBoard()) ? 12 : 10);
for (int i=0; i<C9X_MAX_TIMERS; i++) {
timers[i] = new TimerPanel(this, model, model.timers[i], generalSettings);
timers[i] = new TimerPanel(this, model, model.timers[i], generalSettings, firmware);
ui->gridLayout->addWidget(timers[i], 1+i, 1);
connect(timers[i], SIGNAL(modified()), this, SLOT(onChildModified()));
}
for (int i=0; i<GetCurrentFirmware()->getCapability(NumModules); i++) {
modules[i] = new ModulePanel(this, model, model.moduleData[i], generalSettings, i);
for (int i=0; i<firmware->getCapability(NumModules); i++) {
modules[i] = new ModulePanel(this, model, model.moduleData[i], generalSettings, firmware, i);
ui->modulesLayout->addWidget(modules[i]);
connect(modules[i], SIGNAL(modified()), this, SLOT(onChildModified()));
}
if (GetCurrentFirmware()->getCapability(ModelTrainerEnable)) {
modules[C9X_NUM_MODULES] = new ModulePanel(this, model, model.moduleData[C9X_NUM_MODULES], generalSettings, -1);
if (firmware->getCapability(ModelTrainerEnable)) {
modules[C9X_NUM_MODULES] = new ModulePanel(this, model, model.moduleData[C9X_NUM_MODULES], generalSettings, firmware, -1);
ui->modulesLayout->addWidget(modules[C9X_NUM_MODULES]);
}
if (GetCurrentFirmware()->getCapability(ModelImage)) {
if (firmware->getCapability(ModelImage)) {
QStringList items;
items.append("");
QString path = g.profile[g.id()].sdPath();
@@ -399,13 +399,13 @@ Setup::Setup(QWidget *parent, ModelData & model, GeneralSettings & generalSettin
ui->imagePreview->hide();
}
if (!GetCurrentFirmware()->getCapability(HasDisplayText)) {
if (!firmware->getCapability(HasDisplayText)) {
ui->displayText->hide();
}
// Beep Center checkboxes
int analogs = 4 + GetCurrentFirmware()->getCapability(Pots);
for (int i=0; i<analogs+GetCurrentFirmware()->getCapability(RotaryEncoders); i++) {
int analogs = 4 + firmware->getCapability(Pots);
for (int i=0; i<analogs+firmware->getCapability(RotaryEncoders); i++) {
QCheckBox * checkbox = new QCheckBox(this);
checkbox->setProperty("index", i);
checkbox->setText(i<analogs ? AnalogString(i) : RotaryEncoderString(i-analogs));
@@ -415,7 +415,7 @@ Setup::Setup(QWidget *parent, ModelData & model, GeneralSettings & generalSettin
}
// Startup switches warnings
for (int i=0; i<GetCurrentFirmware()->getCapability(Switches)-1; i++) {
for (int i=0; i<firmware->getCapability(Switches)-1; i++) {
QLabel * label = new QLabel(this);
QSlider * slider = new QSlider(this);
QCheckBox * cb = new QCheckBox(this);
@@ -449,11 +449,11 @@ Setup::Setup(QWidget *parent, ModelData & model, GeneralSettings & generalSettin
startupSwitchesSliders << slider;
startupSwitchesCheckboxes << cb;
}
ui->switchesStartupLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, GetCurrentFirmware()->getCapability(Switches));
ui->switchesStartupLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, firmware->getCapability(Switches));
// Pot warnings
if(IS_TARANIS(GetEepromInterface()->getBoard())) {
for (int i=0; i<GetCurrentFirmware()->getCapability(Pots); i++) {
for (int i=0; i<firmware->getCapability(Pots); i++) {
QCheckBox * cb = new QCheckBox(this);
cb->setProperty("index", i+1);
cb->setText(AnalogString(i+4));
@@ -469,43 +469,43 @@ Setup::Setup(QWidget *parent, ModelData & model, GeneralSettings & generalSettin
lock = false;
}
Setup::~Setup()
SetupPanel::~SetupPanel()
{
delete ui;
}
void Setup::on_extendedLimits_toggled(bool checked)
void SetupPanel::on_extendedLimits_toggled(bool checked)
{
model.extendedLimits = checked;
emit extendedLimitsToggled();
emit modified();
}
void Setup::on_throttleWarning_toggled(bool checked)
void SetupPanel::on_throttleWarning_toggled(bool checked)
{
model.disableThrottleWarning = !checked;
emit modified();
}
void Setup::on_throttleReverse_toggled(bool checked)
void SetupPanel::on_throttleReverse_toggled(bool checked)
{
model.throttleReversed = checked;
emit modified();
}
void Setup::on_extendedTrims_toggled(bool checked)
void SetupPanel::on_extendedTrims_toggled(bool checked)
{
model.extendedTrims = checked;
emit modified();
}
void Setup::on_trimIncrement_currentIndexChanged(int index)
void SetupPanel::on_trimIncrement_currentIndexChanged(int index)
{
model.trimInc = index-2;
emit modified();
}
void Setup::on_throttleSource_currentIndexChanged(int index)
void SetupPanel::on_throttleSource_currentIndexChanged(int index)
{
if (!lock) {
model.thrTraceSrc = ui->throttleSource->itemData(index).toInt();
@@ -513,14 +513,14 @@ void Setup::on_throttleSource_currentIndexChanged(int index)
}
}
void Setup::on_name_editingFinished()
void SetupPanel::on_name_editingFinished()
{
int length = ui->name->maxLength();
strncpy(model.name, ui->name->text().toAscii(), length);
emit modified();
}
void Setup::on_image_currentIndexChanged(int index)
void SetupPanel::on_image_currentIndexChanged(int index)
{
if (!lock) {
strncpy(model.bitmap, ui->image->currentText().toAscii(), 10);
@@ -552,7 +552,7 @@ void Setup::on_image_currentIndexChanged(int index)
}
}
void Setup::populateThrottleSourceCB()
void SetupPanel::populateThrottleSourceCB()
{
const QString sources9x[] = { QObject::tr("THR"), QObject::tr("P1"), QObject::tr("P2"), QObject::tr("P3")};
const QString sourcesTaranis[] = { QObject::tr("THR"), QObject::tr("S1"), QObject::tr("S2"), QObject::tr("S3"), QObject::tr("LS"), QObject::tr("RS")};
@@ -585,7 +585,7 @@ void Setup::populateThrottleSourceCB()
lock = false;
}
void Setup::update()
void SetupPanel::update()
{
ui->name->setText(model.name);
@@ -615,20 +615,20 @@ void Setup::update()
modules[i]->update();
}
void Setup::updateBeepCenter()
void SetupPanel::updateBeepCenter()
{
for (int i=0; i<centerBeepCheckboxes.size(); i++) {
centerBeepCheckboxes[i]->setChecked(model.beepANACenter & (0x01 << i));
}
}
void Setup::updateStartupSwitches()
void SetupPanel::updateStartupSwitches()
{
lock = true;
unsigned int switchStates = model.switchWarningStates;
for (int i=0; i<GetCurrentFirmware()->getCapability(Switches)-1; i++) {
for (int i=0; i<firmware->getCapability(Switches)-1; i++) {
QSlider * slider = startupSwitchesSliders[i];
QCheckBox * cb = startupSwitchesCheckboxes[i];
bool enabled = !(model.nSwToWarn & (1 << i));
@@ -647,7 +647,7 @@ void Setup::updateStartupSwitches()
lock = false;
}
void Setup::startupSwitchEdited(int value)
void SetupPanel::startupSwitchEdited(int value)
{
if (!lock) {
int shift = 0;
@@ -686,7 +686,7 @@ void Setup::startupSwitchEdited(int value)
}
}
void Setup::startupSwitchToggled(bool checked)
void SetupPanel::startupSwitchToggled(bool checked)
{
if (!lock) {
int index = sender()->property("index").toInt()-1;
@@ -701,7 +701,7 @@ void Setup::startupSwitchToggled(bool checked)
}
}
void Setup::updatePotWarnings()
void SetupPanel::updatePotWarnings()
{
lock = true;
int mode = model.nPotsToWarn >> 6;
@@ -719,7 +719,7 @@ void Setup::updatePotWarnings()
lock = false;
}
void Setup::potWarningToggled(bool checked)
void SetupPanel::potWarningToggled(bool checked)
{
if (!lock) {
int index = sender()->property("index").toInt()-1;
@@ -734,7 +734,7 @@ void Setup::potWarningToggled(bool checked)
}
}
void Setup::on_potWarningMode_currentIndexChanged(int index)
void SetupPanel::on_potWarningMode_currentIndexChanged(int index)
{
if (!lock) {
int mask = 0xC0;
@@ -746,19 +746,19 @@ void Setup::on_potWarningMode_currentIndexChanged(int index)
}
}
void Setup::on_displayText_toggled(bool checked)
void SetupPanel::on_displayText_toggled(bool checked)
{
model.displayText = checked;
emit modified();
}
void Setup::on_throttleTrim_toggled(bool checked)
void SetupPanel::on_throttleTrim_toggled(bool checked)
{
model.thrTrim = checked;
emit modified();
}
void Setup::onBeepCenterToggled(bool checked)
void SetupPanel::onBeepCenterToggled(bool checked)
{
if (!lock) {
int index = sender()->property("index").toInt();
@@ -771,7 +771,7 @@ void Setup::onBeepCenterToggled(bool checked)
}
}
void Setup::onChildModified()
void SetupPanel::onChildModified()
{
emit modified();
}