diff --git a/companion/src/firmwares/CMakeLists.txt b/companion/src/firmwares/CMakeLists.txt index e50d9241b..bf05bc44d 100644 --- a/companion/src/firmwares/CMakeLists.txt +++ b/companion/src/firmwares/CMakeLists.txt @@ -30,6 +30,7 @@ string(REPLACE ".cpp" ".h" firmwares_HDRS "${firmwares_SRCS}") list(APPEND firmwares_HDRS eepromimportexport.h moduledata.h + helpersdata.h ) set(firmwares_QT diff --git a/companion/src/firmwares/helpersdata.h b/companion/src/firmwares/helpersdata.h new file mode 100644 index 000000000..29273e5f0 --- /dev/null +++ b/companion/src/firmwares/helpersdata.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#pragma once + +#include + +class FieldRange +{ + Q_DECLARE_TR_FUNCTIONS(FieldRange) + + public: + FieldRange(): + decimals(0), + min(0.0), + max(0.0), + step(1.0), + offset(0.0), + prefix(""), + unit("") + { + } + + float getValue(int value) { return float(value) * step; } + + int decimals; + double min; + double max; + double step; + double offset; + QString prefix; + QString unit; +}; diff --git a/companion/src/firmwares/rawsource.cpp b/companion/src/firmwares/rawsource.cpp index 67ad743b6..898c0ca4a 100644 --- a/companion/src/firmwares/rawsource.cpp +++ b/companion/src/firmwares/rawsource.cpp @@ -60,7 +60,7 @@ RawSourceRange RawSource::getRange(const ModelData * model, const GeneralSetting result.min = -30000 * result.step; result.max = +30000 * result.step; result.decimals = sensor.prec; - result.unit = sensor.unitString(); + result.unit = SensorData::unitToString(qr.quot); break; } diff --git a/companion/src/firmwares/sensordata.cpp b/companion/src/firmwares/sensordata.cpp index ebcccfa6a..a87dc6d21 100644 --- a/companion/src/firmwares/sensordata.cpp +++ b/companion/src/firmwares/sensordata.cpp @@ -33,12 +33,316 @@ void SensorData::updateUnit() } } -// TODO depreciated -QString SensorData::unitString() const +QString SensorData::nameToString(int index) const +{ + return RadioData::getElementName(tr("TELE"), index + 1, label); +} + +QString SensorData::getOrigin(const ModelData * model) const +{ + if (type != TELEM_TYPE_CUSTOM || !id) + return QString(); + + const ModuleData & module = model->moduleData[moduleIdx]; + if (module.isPxx2Module() && rxIdx <= 2 && module.access.receivers & (1 << rxIdx)) { + return QString(module.access.receiverName[rxIdx]); + } + else { + return QString(); + } +} + +bool SensorData::isEmpty() const +{ + return (!isAvailable() && type == 0 && id == 0 && subid == 0 && instance == 0 && rxIdx == 0 && moduleIdx == 0 && unit == 0 && ratio == 0 && prec == 0 && offset == 0 && autoOffset == 0 && filter == 0 && onlyPositive == 0 && logs == 0); +} + +QString SensorData::idToString() const +{ + return idToString(id); +} + +QString SensorData::typeToString() const +{ + return typeToString(type); +} + +QString SensorData::formulaToString() const +{ + return formulaToString(formula); +} + +QString SensorData::cellIndexToString() const +{ + return cellIndexToString(index); +} + +QString SensorData::unitToString() const { return unitToString(unit); } +QString SensorData::precToString() const +{ + return precToString(prec); +} + +int SensorData::getMask() const +{ + int mask = 0; + + if (type == TELEM_TYPE_CALCULATED) { + if (formula < TELEM_FORMULA_CELL) + mask |= SENSOR_ISCONFIGURABLE | SENSOR_HAS_POSITIVE; + if (formula == TELEM_FORMULA_DIST) + mask |= SENSOR_HAS_GPS; + if (formula == TELEM_FORMULA_CELL) + mask |= SENSOR_HAS_CELLS; + if (formula == TELEM_FORMULA_CONSUMPTION) + mask |= SENSOR_HAS_CONSUMPTION; + if (formula <= TELEM_FORMULA_MULTIPLY) + mask |= SENSOR_HAS_SOURCES_12; + if (formula < TELEM_FORMULA_MULTIPLY) + mask |= SENSOR_HAS_SOURCES_34; + if (formula == TELEM_FORMULA_TOTALIZE) + mask |= SENSOR_HAS_TOTALIZE; + } + else { + if (unit < UNIT_FIRST_VIRTUAL) + mask |= (SENSOR_ISCONFIGURABLE | SENSOR_HAS_RATIO | SENSOR_HAS_POSITIVE); + } + + if (mask & SENSOR_ISCONFIGURABLE && unit != UNIT_FAHRENHEIT) + mask |= SENSOR_HAS_PRECISION; + + return mask; +} + +constexpr char FMT_LABEL[] { "%1: " }; +constexpr char FMT_VALUE[] { "%1 " }; +constexpr char FMT_LABEL_VALUE[] { "%1: %2 " }; + +QString SensorData::paramsToString(const ModelData * model) const +{ + if (!isAvailable()) + return ""; + + QString str; + int mask = getMask(); + + if (type == TELEM_TYPE_CALCULATED) { + str.append(QString(FMT_LABEL_VALUE).arg(tr("Formula")).arg(formulaToString())); + } + else { + str.append(QString(FMT_LABEL_VALUE).arg(tr("Id")).arg(idToString())); + str.append(QString(FMT_LABEL_VALUE).arg(tr("Instance")).arg(instance)); + } + + if (mask & SENSOR_HAS_CELLS) { + str.append(QString(FMT_LABEL_VALUE).arg(tr("Sensor")).arg(sourceToString(model, source))); + str.append(QString(FMT_VALUE).arg(cellIndexToString())); + } + + if (mask & SENSOR_HAS_SOURCES_12) { + str.append(QString(FMT_LABEL).arg(tr("Sources"))); + for (int i = 0; i < 4; i++) { + if (i < 2 || mask & SENSOR_HAS_SOURCES_34) { + str.append(QString(FMT_VALUE).arg(sourceToString(model, sources[i]))); + } + } + } + + if (mask & SENSOR_HAS_CONSUMPTION || mask & SENSOR_HAS_TOTALIZE) + str.append(QString(FMT_LABEL_VALUE).arg(tr("Sensor")).arg(sourceToString(model, amps))); + + if (mask & SENSOR_HAS_GPS) { + str.append(QString(FMT_LABEL_VALUE).arg(tr("GPS")).arg(sourceToString(model, gps))); + str.append(QString(FMT_LABEL_VALUE).arg(tr("Alt")).arg(sourceToString(model, alt))); + } + + if (mask & SENSOR_ISCONFIGURABLE) + str.append(QString(FMT_LABEL_VALUE).arg(tr("Unit")).arg(unitToString())); + + if (mask & SENSOR_HAS_PRECISION) + str.append(QString(FMT_LABEL_VALUE).arg(tr("Precision")).arg(precToString())); + + if (mask & SENSOR_HAS_RATIO) { + if (unit != UNIT_RPMS) { + int precsn = prec == 0 ? 1 : pow(10, prec); + str.append(QString(FMT_LABEL_VALUE).arg(tr("Ratio")).arg((float)ratio / 10)); + str.append(QString(FMT_LABEL_VALUE).arg(tr("Offset")).arg(QString::number((float)offset / precsn, 'f', prec))); + str.append(QString(FMT_LABEL_VALUE).arg(tr("Auto Offset")).arg(boolToString(autoOffset))); + } + else { + str.append(QString(FMT_LABEL_VALUE).arg(tr("Blades")).arg(ratio)); // TODO refactor to dedicated RPMS field + str.append(QString(FMT_LABEL_VALUE).arg(tr("Multiplier")).arg(offset)); // TODO refactor to dedicated RPMS field + } + } + + if (mask & SENSOR_ISCONFIGURABLE) + str.append(QString(FMT_LABEL_VALUE).arg(tr("Filter")).arg(boolToString(filter))); + + if (type == TELEM_TYPE_CALCULATED) + str.append(QString(FMT_LABEL_VALUE).arg(tr("Persist")).arg(boolToString(persistent))); + + if (mask & SENSOR_HAS_POSITIVE) + str.append(QString(FMT_LABEL_VALUE).arg(tr("Positive")).arg(boolToString(onlyPositive))); + + str.append(QString(FMT_LABEL_VALUE).arg(tr("Log")).arg(boolToString(logs))); + + return str; +} + +FieldRange SensorData::getRatioRange() const +{ + FieldRange result; + + if (unit == SensorData::UNIT_RPMS) { + result.decimals = 0; + result.max = 30000; + result.min = 1; + result.step = 1; + } + else { + result.decimals = 1; + result.max = 30000; + result.min = 0; + result.step = 0.1; + } + + return result; +} + +FieldRange SensorData::getOffsetRange() const +{ + FieldRange result; + + if (unit == SensorData::UNIT_RPMS) { + result.decimals = 0; + result.max = 30000; + result.min = 1; + result.step = 1; + } + else { + result.decimals = prec; + result.max = 30000.0f / powf(10.0f, prec); + result.min = -result.max; + result.step = pow(0.1, prec); + } + + return result; +} + +void SensorData::formulaChanged() +{ + switch (formula) { + case TELEM_FORMULA_CELL: + prec = 2; + unit = UNIT_VOLTS; + break; + case TELEM_FORMULA_CONSUMPTION: + prec = 0; + unit = UNIT_MAH; + break; + case TELEM_FORMULA_DIST: + prec = 0; + unit = UNIT_METERS; + break; + } +} + +void SensorData::unitChanged() +{ + if (unit == UNIT_FAHRENHEIT) + prec = 0; +} + +// static +QString SensorData::idToString(const int value) +{ + return QString::number(value, 16).toUpper(); +} + +// static +QString SensorData::typeToString(const int value) +{ + switch(value) { + case TELEM_TYPE_CUSTOM: + return tr("Custom"); + case TELEM_TYPE_CALCULATED: + return tr("Calculated"); + default: + return CPN_STR_UNKNOWN_ITEM; + } +} + +// static +QString SensorData::formulaToString(const int value) +{ + switch(value) { + case TELEM_FORMULA_ADD: + return tr("Add"); + case TELEM_FORMULA_AVERAGE: + return tr("Average"); + case TELEM_FORMULA_MIN: + return tr("Minimum"); + case TELEM_FORMULA_MAX: + return tr("Maximum"); + case TELEM_FORMULA_MULTIPLY: + return tr("Multiply"); + case TELEM_FORMULA_TOTALIZE: + return tr("Totalize"); + case TELEM_FORMULA_CELL: + return tr("Cell"); + case TELEM_FORMULA_CONSUMPTION: + return tr("Consumption"); + case TELEM_FORMULA_DIST: + return tr("Distance"); + default: + return CPN_STR_UNKNOWN_ITEM; + } +} + +// static +QString SensorData::cellIndexToString(const int value) +{ + if (value == TELEM_CELL_INDEX_LOWEST) + return tr("Lowest"); + if (value > TELEM_CELL_INDEX_LOWEST && value < TELEM_CELL_INDEX_HIGHEST) + return tr("Cell %1").arg(value - TELEM_CELL_INDEX_LOWEST); + if (value== TELEM_CELL_INDEX_HIGHEST) + return tr("Highest"); + if (value == TELEM_CELL_INDEX_DELTA) + return tr("Delta"); + return CPN_STR_UNKNOWN_ITEM; +} + +// static +QString SensorData::precToString(const int value) +{ + return QString("0.%1").arg(QString(value, '0')); +} + +// static +QString SensorData::sourceToString(const ModelData * model, const int index, const bool sign) +{ + if (model) { + const QString prfx = sign ? index < 0 ? "-" : "+" : ""; + + if (abs(index) > 0) { + const SensorData &sd = model->sensorData[abs(index) - 1]; + if (sd.type == SensorData::TELEM_TYPE_CUSTOM) + return QString("%1%2 (%3)").arg(prfx).arg(sd.label).arg(sd.getOrigin(model)); + else + return QString("%1%2").arg(prfx).arg(sd.label); + } + else + return CPN_STR_NONE_ITEM; + } + + return ""; +} + // static QString SensorData::unitToString(const int value) { @@ -106,110 +410,6 @@ QString SensorData::unitToString(const int value) } } -QString SensorData::nameToString(int index) const -{ - return RadioData::getElementName(tr("TELE"), index + 1, label); -} - -QString SensorData::getOrigin(const ModelData * model) const -{ - if (type != TELEM_TYPE_CUSTOM || !id) - return QString(); - - const ModuleData & module = model->moduleData[moduleIdx]; - if (module.isPxx2Module() && rxIdx <= 2 && module.access.receivers & (1 << rxIdx)) { - return QString(module.access.receiverName[rxIdx]); - } - else { - return QString(); - } -} - -bool SensorData::isEmpty() const -{ - return (!isAvailable() && type == 0 && id == 0 && subid == 0 && instance == 0 && rxIdx == 0 && moduleIdx == 0 && unit == 0 && ratio == 0 && prec == 0 && offset == 0 && autoOffset == 0 && filter == 0 && onlyPositive == 0 && logs == 0); -} - -// static -QString SensorData::typeToString(const int value) -{ - switch(value) { - case TELEM_TYPE_CUSTOM: - return tr("Custom"); - case TELEM_TYPE_CALCULATED: - return tr("Calculated"); - default: - return CPN_STR_UNKNOWN_ITEM; - } -} - -// static -QString SensorData::formulaToString(const int value) -{ - switch(value) { - case TELEM_FORMULA_ADD: - return tr("Add"); - case TELEM_FORMULA_AVERAGE: - return tr("Average"); - case TELEM_FORMULA_MIN: - return tr("Minimum"); - case TELEM_FORMULA_MAX: - return tr("Maximum"); - case TELEM_FORMULA_MULTIPLY: - return tr("Multiply"); - case TELEM_FORMULA_TOTALIZE: - return tr("Totalize"); - case TELEM_FORMULA_CELL: - return tr("Cell"); - case TELEM_FORMULA_CONSUMPTION: - return tr("Consumption"); - case TELEM_FORMULA_DIST: - return tr("Distance"); - default: - return CPN_STR_UNKNOWN_ITEM; - } -} - -// static -QString SensorData::cellIndexToString(const int value) -{ - if (value == TELEM_CELL_INDEX_LOWEST) - return tr("Lowest"); - if (value > TELEM_CELL_INDEX_LOWEST && value < TELEM_CELL_INDEX_HIGHEST) - return tr("Cell %1").arg(value - TELEM_CELL_INDEX_LOWEST); - if (value== TELEM_CELL_INDEX_HIGHEST) - return tr("Highest"); - if (value == TELEM_CELL_INDEX_DELTA) - return tr("Delta"); - return CPN_STR_UNKNOWN_ITEM; -} - -// static -QString SensorData::precisionToString(const int value) -{ - return QString("0.%1").arg(QString(value, '0')); -} - -// static -QString SensorData::sourceToString(const ModelData * model, const int index, const bool sign) -{ - if (model) { - const QString prfx = sign ? index < 0 ? "-" : "+" : ""; - - if (abs(index) > 0) { - const SensorData &sd = model->sensorData[abs(index) - 1]; - if (sd.type == SensorData::TELEM_TYPE_CUSTOM) - return QString("%1%2 (%3)").arg(prfx).arg(sd.label).arg(sd.getOrigin(model)); - else - return QString("%1%2").arg(prfx).arg(sd.label); - } - else - return CPN_STR_NONE_ITEM; - } - - return ""; -} - // static bool SensorData::isSourceAvailable(const ModelData * model, const int index) { diff --git a/companion/src/firmwares/sensordata.h b/companion/src/firmwares/sensordata.h index afd9d7891..5e888d749 100644 --- a/companion/src/firmwares/sensordata.h +++ b/companion/src/firmwares/sensordata.h @@ -18,19 +18,32 @@ * GNU General Public License for more details. */ -#ifndef SENSORDATA_H -#define SENSORDATA_H +#pragma once + +#include "helpersdata.h" #include -constexpr int CPN_MAX_SENSORS = 60; -constexpr int SENSOR_LABEL_LEN = 4; +constexpr int CPN_MAX_SENSORS { 60 }; +constexpr int SENSOR_LABEL_LEN { 4 }; + +constexpr int SENSOR_ISCONFIGURABLE { 1 << 1 }; +constexpr int SENSOR_HAS_GPS { 1 << 2 }; +constexpr int SENSOR_HAS_CELLS { 1 << 3 }; +constexpr int SENSOR_HAS_CONSUMPTION { 1 << 4 }; +constexpr int SENSOR_HAS_RATIO { 1 << 5 }; +constexpr int SENSOR_HAS_TOTALIZE { 1 << 6 }; +constexpr int SENSOR_HAS_SOURCES_12 { 1 << 7 }; +constexpr int SENSOR_HAS_SOURCES_34 { 1 << 8 }; +constexpr int SENSOR_HAS_POSITIVE { 1 << 9 }; +constexpr int SENSOR_HAS_PRECISION { 1 << 10 }; class ModelData; class AbstractStaticItemModel; class PrecisionItemModel; class SensorData { + Q_DECLARE_TR_FUNCTIONS(SensorData) public: @@ -167,19 +180,32 @@ class SensorData { bool isAvailable() const { return strlen(label) > 0; } void updateUnit(); - QString unitString() const; QString nameToString(int index) const; QString getOrigin(const ModelData* model) const; void clear() { memset(this, 0, sizeof(SensorData)); } bool isEmpty() const; + QString idToString() const; + QString typeToString() const; + QString formulaToString() const; + QString cellIndexToString() const; + QString unitToString() const; + QString precToString() const; + int getMask() const; + QString paramsToString(const ModelData * model) const; + FieldRange getRatioRange() const; + FieldRange getOffsetRange() const; + void formulaChanged(); + void unitChanged(); static QString sourceToString(const ModelData * model, const int index, const bool sign = false); static bool isSourceAvailable(const ModelData * model, const int index); + static QString idToString(const int value); static QString typeToString(const int value); static QString formulaToString(const int value); static QString cellIndexToString(const int value); static QString unitToString(const int value); - static QString precisionToString(const int value); + static QString precToString(const int value); + static QString boolToString(const bool value) { return value ? tr("Y") : tr("N"); } static AbstractStaticItemModel * typeItemModel(); static AbstractStaticItemModel * formulaItemModel(); @@ -187,5 +213,3 @@ class SensorData { static AbstractStaticItemModel * unitItemModel(); static PrecisionItemModel * precisionItemModel(); }; - -#endif // SENSORDATA_H diff --git a/companion/src/modeledit/telemetry.cpp b/companion/src/modeledit/telemetry.cpp index 423e10e5d..8cda220a9 100644 --- a/companion/src/modeledit/telemetry.cpp +++ b/companion/src/modeledit/telemetry.cpp @@ -27,13 +27,13 @@ #include -constexpr char FIM_RAWSOURCE[] {"Raw Source"}; -constexpr char FIM_TELEALLSRC[] {"Tele All Source"}; -constexpr char FIM_TELEPOSSRC[] {"Tele Pos Source"}; -constexpr char FIM_SENSORTYPE[] {"Sensor.Type"}; -constexpr char FIM_SENSORFORMULA[] {"Sensor.Formula"}; +constexpr char FIM_RAWSOURCE[] {"Raw Source"}; +constexpr char FIM_TELEALLSRC[] {"Tele All Source"}; +constexpr char FIM_TELEPOSSRC[] {"Tele Pos Source"}; +constexpr char FIM_SENSORTYPE[] {"Sensor.Type"}; +constexpr char FIM_SENSORFORMULA[] {"Sensor.Formula"}; constexpr char FIM_SENSORCELLINDEX[] {"Sensor.CellIndex"}; -constexpr char FIM_SENSORUNIT[] {"Sensor.Unit"}; +constexpr char FIM_SENSORUNIT[] {"Sensor.Unit"}; constexpr char FIM_SENSORPRECISION[] {"Sensor.Precision"}; TelemetryCustomScreen::TelemetryCustomScreen(QWidget *parent, ModelData & model, FrSkyScreenData & screen, GeneralSettings & generalSettings, @@ -336,9 +336,6 @@ TelemetrySensorPanel::TelemetrySensorPanel(QWidget *parent, SensorData & sensor, modelsUpdateCnt(0), parentLock(parentLock) { - // TODO ui definition housekeeping - // - remove all predefined combobox lists leaving to code - // - use Auto types for consistency ui->setupUi(this); FilteredItemModel * fltmdl; @@ -358,11 +355,19 @@ TelemetrySensorPanel::TelemetrySensorPanel(QWidget *parent, SensorData & sensor, ui->numLabel->setToolTip(tr("Popup menu available")); ui->numLabel->setMouseTracking(true); connect(ui->numLabel, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(on_customContextMenuRequested(QPoint))); + ui->name->setField(sensor.label, SENSOR_LABEL_LEN); + connect(ui->name, SIGNAL(currentDataChanged()), this, SLOT(on_nameDataChanged())); ui->id->setField(sensor.id, this); ui->instance->setField(sensor.instance, this); ui->type->setModel(panelFilteredItemModels->getItemModel(FIM_SENSORTYPE)); + ui->type->setField(sensor.type); + connect(ui->type, SIGNAL(currentDataChanged(int)), this, SLOT(update())); ui->formula->setModel(panelFilteredItemModels->getItemModel(FIM_SENSORFORMULA)); + ui->formula->setField(sensor.formula); + connect(ui->formula, SIGNAL(currentDataChanged(int)), this, SLOT(on_formulaDataChanged())); ui->unit->setModel(panelFilteredItemModels->getItemModel(FIM_SENSORUNIT)); + ui->unit->setField(sensor.unit); + connect(ui->unit, SIGNAL(currentDataChanged(int)), this, SLOT(on_unitDataChanged())); ui->ratio->setField(sensor.ratio, this); ui->offset->setField(sensor.offset, this); ui->autoOffset->setField(sensor.autoOffset, this); @@ -390,7 +395,9 @@ TelemetrySensorPanel::TelemetrySensorPanel(QWidget *parent, SensorData & sensor, ui->source3->setField(sensor.sources[2], this); ui->source4->setModel(fltmdl); ui->source4->setField(sensor.sources[3], this); - ui->prec->setField(sensor.prec, 0, 2, false, "", this); // TODO replace autoprecisioncombobox with autocombobox and filtereditemmodel + ui->prec->setModel(panelFilteredItemModels->getItemModel(FIM_SENSORPRECISION)); + ui->prec->setField(sensor.prec); + connect(ui->prec, SIGNAL(currentDataChanged(int)), this, SLOT(on_precDataChanged())); lock = false; update(); @@ -403,20 +410,13 @@ TelemetrySensorPanel::~TelemetrySensorPanel() void TelemetrySensorPanel::update() { - // TODO use bit mask - bool isConfigurable = false; - bool gpsFieldsDisplayed = false; - bool cellsFieldsDisplayed = false; - bool consFieldsDisplayed = false; - bool ratioFieldsDisplayed = false; - bool totalizeFieldsDisplayed = false; - bool sources12FieldsDisplayed = false; - bool sources34FieldsDisplayed = false; - lock = true; - ui->name->setText(sensor.label); - ui->type->setCurrentIndex(ui->type->findData(sensor.type)); - ui->unit->setCurrentIndex(ui->unit->findData(sensor.unit)); + int mask = sensor.getMask(); + + ui->name->updateValue(); + ui->type->updateValue(); + ui->formula->updateValue(); + ui->unit->updateValue(); ui->id->updateValue(); ui->instance->updateValue(); ui->ratio->updateValue(); @@ -443,13 +443,6 @@ void TelemetrySensorPanel::update() ui->origin->hide(); ui->formula->show(); ui->formula->setCurrentIndex(ui->formula->findData(sensor.formula)); - isConfigurable = (sensor.formula < SensorData::TELEM_FORMULA_CELL); - gpsFieldsDisplayed = (sensor.formula == SensorData::TELEM_FORMULA_DIST); - cellsFieldsDisplayed = (sensor.formula == SensorData::TELEM_FORMULA_CELL); - consFieldsDisplayed = (sensor.formula == SensorData::TELEM_FORMULA_CONSUMPTION); - sources12FieldsDisplayed = (sensor.formula <= SensorData::TELEM_FORMULA_MULTIPLY); - sources34FieldsDisplayed = (sensor.formula < SensorData::TELEM_FORMULA_MULTIPLY); - totalizeFieldsDisplayed = (sensor.formula == SensorData::TELEM_FORMULA_TOTALIZE); ui->source1->updateValue(); ui->source2->updateValue(); ui->source3->updateValue(); @@ -464,121 +457,78 @@ void TelemetrySensorPanel::update() ui->originLabel->setVisible(!origin.isEmpty()); ui->origin->setVisible(!origin.isEmpty()); ui->origin->setText(origin); - ui->formula->hide(); - isConfigurable = sensor.unit < SensorData::UNIT_FIRST_VIRTUAL; - ratioFieldsDisplayed = (sensor.unit < SensorData::UNIT_FIRST_VIRTUAL); - if (sensor.unit == SensorData::UNIT_RPMS) { - if (ui->ratio->decimals()) { - ui->ratio->setDecimals(0); - ui->ratio->setMaximum(30000); - ui->ratio->setMinimum(1); - ui->ratio->setSingleStep(1); - ui->offset->setDecimals(0); - ui->offset->setMaximum(30000); - ui->offset->setMinimum(1); - ui->offset->setSingleStep(1); - } - } - else { - if (!ui->ratio->decimals()) { - ui->ratio->setDecimals(1); - ui->ratio->setMaximum(3000); - ui->ratio->setMinimum(0); - ui->ratio->setSingleStep(0.1); - } - if (ui->offset->decimals() != (int)sensor.prec) { - ui->offset->setDecimals(sensor.prec); - ui->offset->setMaximum(30000.0f / powf(10.0f, sensor.prec)); - ui->offset->setMinimum(-ui->offset->maximum()); - ui->offset->setSingleStep(pow(0.1, sensor.prec)); - } - } + FieldRange rng = sensor.getRatioRange(); + ui->ratio->setDecimals(rng.decimals); + ui->ratio->setMaximum(rng.max); + ui->ratio->setMinimum(rng.min); + ui->ratio->setSingleStep(rng.step); + rng = sensor.getOffsetRange(); + ui->offset->setDecimals(rng.decimals); + ui->offset->setMaximum(rng.max); + ui->offset->setMinimum(rng.min); + ui->offset->setSingleStep(rng.step); } - ui->ratioLabel->setVisible(ratioFieldsDisplayed && sensor.unit != SensorData::UNIT_RPMS); - ui->bladesLabel->setVisible(sensor.unit == SensorData::UNIT_RPMS); - ui->ratio->setVisible(ratioFieldsDisplayed); - ui->offsetLabel->setVisible(ratioFieldsDisplayed && sensor.unit != SensorData::UNIT_RPMS); - ui->multiplierLabel->setVisible(sensor.unit == SensorData::UNIT_RPMS); - ui->offset->setVisible(ratioFieldsDisplayed); - ui->precLabel->setVisible(isConfigurable && sensor.unit != SensorData::UNIT_FAHRENHEIT); - ui->prec->setVisible(isConfigurable && sensor.unit != SensorData::UNIT_FAHRENHEIT); - ui->unit->setVisible((sensor.type == SensorData::TELEM_TYPE_CALCULATED && (sensor.formula == SensorData::TELEM_FORMULA_DIST)) || isConfigurable); - ui->gpsSensorLabel->setVisible(gpsFieldsDisplayed); - ui->gpsSensor->setVisible(gpsFieldsDisplayed); - ui->altSensorLabel->setVisible(gpsFieldsDisplayed); - ui->altSensor->setVisible(gpsFieldsDisplayed); - ui->ampsSensorLabel->setVisible(consFieldsDisplayed || totalizeFieldsDisplayed); - ui->ampsSensor->setVisible(consFieldsDisplayed || totalizeFieldsDisplayed); - ui->cellsSensorLabel->setVisible(cellsFieldsDisplayed); - ui->cellsSensor->setVisible(cellsFieldsDisplayed); - ui->cellsIndex->setVisible(cellsFieldsDisplayed); - ui->source1->setVisible(sources12FieldsDisplayed); - ui->source2->setVisible(sources12FieldsDisplayed); - ui->source3->setVisible(sources34FieldsDisplayed); - ui->source4->setVisible(sources34FieldsDisplayed); - ui->autoOffset->setVisible(sensor.unit != SensorData::UNIT_RPMS && isConfigurable); - ui->filter->setVisible(isConfigurable); - ui->persistent->setVisible(sensor.type == SensorData::TELEM_TYPE_CALCULATED); + ui->ratioLabel->setVisible(mask & SENSOR_HAS_RATIO && sensor.unit != SensorData::UNIT_RPMS); + ui->bladesLabel->setVisible(mask & SENSOR_HAS_RATIO && sensor.unit == SensorData::UNIT_RPMS); + ui->ratio->setVisible(mask & SENSOR_HAS_RATIO); + + ui->offsetLabel->setVisible(mask & SENSOR_HAS_RATIO && sensor.unit != SensorData::UNIT_RPMS); + ui->multiplierLabel->setVisible(mask & SENSOR_HAS_RATIO && sensor.unit == SensorData::UNIT_RPMS); + ui->offset->setVisible(mask & SENSOR_HAS_RATIO); + + ui->precLabel->setVisible(mask & SENSOR_HAS_PRECISION); + ui->prec->setVisible(mask & SENSOR_HAS_PRECISION); + + ui->unit->setVisible(mask & SENSOR_ISCONFIGURABLE); + + ui->gpsSensorLabel->setVisible(mask & SENSOR_HAS_GPS); + ui->gpsSensor->setVisible(mask & SENSOR_HAS_GPS); + + ui->altSensorLabel->setVisible(mask & SENSOR_HAS_GPS); + ui->altSensor->setVisible(mask & SENSOR_HAS_GPS); + + ui->ampsSensorLabel->setVisible(mask & SENSOR_HAS_CONSUMPTION || mask & SENSOR_HAS_TOTALIZE); + ui->ampsSensor->setVisible(mask & SENSOR_HAS_CONSUMPTION || mask & SENSOR_HAS_TOTALIZE); + + ui->cellsSensorLabel->setVisible(mask & SENSOR_HAS_CELLS); + ui->cellsSensor->setVisible(mask & SENSOR_HAS_CELLS); + ui->cellsIndex->setVisible(mask & SENSOR_HAS_CELLS); + + ui->source1->setVisible(mask & SENSOR_HAS_SOURCES_12); + ui->source2->setVisible(mask & SENSOR_HAS_SOURCES_12); + ui->source3->setVisible(mask & SENSOR_HAS_SOURCES_34); + ui->source4->setVisible(mask & SENSOR_HAS_SOURCES_34); + + ui->autoOffset->setEnabled(mask & SENSOR_HAS_RATIO && sensor.unit != SensorData::UNIT_RPMS); + ui->onlyPositive->setEnabled(mask & SENSOR_HAS_POSITIVE); + ui->filter->setEnabled(mask & SENSOR_ISCONFIGURABLE); + ui->persistent->setEnabled(sensor.type == SensorData::TELEM_TYPE_CALCULATED); lock = false; } -void TelemetrySensorPanel::on_name_editingFinished() +void TelemetrySensorPanel::on_nameDataChanged() { - if (!isLocked() && (sensor.label != ui->name->text().toLatin1())) { - strcpy(sensor.label, ui->name->text().toLatin1()); - emit dataModified(); - } + emit dataModified(); } -void TelemetrySensorPanel::on_type_currentIndexChanged(int index) +void TelemetrySensorPanel::on_formulaDataChanged() { - if (!isLocked()) { - sensor.type = ui->type->itemData(index).toInt(); - update(); - emit modified(); - } + sensor.formulaChanged(); + update(); } -void TelemetrySensorPanel::on_formula_currentIndexChanged(int index) +void TelemetrySensorPanel::on_unitDataChanged() { - if (!isLocked()) { - sensor.formula = ui->formula->itemData(index).toInt(); - if (sensor.formula == SensorData::TELEM_FORMULA_CELL) { - sensor.prec = 2; - sensor.unit = SensorData::UNIT_VOLTS; - } - else if (sensor.formula == SensorData::TELEM_FORMULA_CONSUMPTION) { - sensor.prec = 0; - sensor.unit = SensorData::UNIT_MAH; - } - else if (sensor.formula == SensorData::TELEM_FORMULA_DIST) { - sensor.prec = 0; - sensor.unit = SensorData::UNIT_METERS; - } - emit dataModified(); - } + sensor.unitChanged(); + update(); } -void TelemetrySensorPanel::on_unit_currentIndexChanged(int index) +void TelemetrySensorPanel::on_precDataChanged() { - if (!isLocked()) { - sensor.unit = ui->unit->itemData(index).toInt(); - if (sensor.unit == SensorData::UNIT_FAHRENHEIT) { - sensor.prec = 0; - } - update(); - emit modified(); - } -} - -void TelemetrySensorPanel::on_prec_valueChanged() -{ - if (!isLocked()) { - update(); - } + update(); } void TelemetrySensorPanel::on_customContextMenuRequested(QPoint pos) diff --git a/companion/src/modeledit/telemetry.h b/companion/src/modeledit/telemetry.h index 224f88020..3f04bebf6 100644 --- a/companion/src/modeledit/telemetry.h +++ b/companion/src/modeledit/telemetry.h @@ -18,8 +18,7 @@ * GNU General Public License for more details. */ -#ifndef _TELEMETRY_H_ -#define _TELEMETRY_H_ +#pragma once #include "modeledit.h" #include "eeprominterface.h" @@ -94,11 +93,6 @@ class TelemetrySensorPanel: public ModelPanel void moveDownSensor(int index); protected slots: - void on_name_editingFinished(); - void on_type_currentIndexChanged(int index); - void on_formula_currentIndexChanged(int index); - void on_unit_currentIndexChanged(int index); - void on_prec_valueChanged(); void on_customContextMenuRequested(QPoint pos); bool hasClipboardData(QByteArray * data = nullptr) const; void cmCopy(); @@ -112,6 +106,10 @@ class TelemetrySensorPanel: public ModelPanel void cmMoveDown(); void onItemModelAboutToBeUpdated(); void onItemModelUpdateComplete(); + void on_nameDataChanged(); + void on_formulaDataChanged(); + void on_unitDataChanged(); + void on_precDataChanged(); private: Ui::TelemetrySensor * ui; @@ -181,5 +179,3 @@ class TelemetryPanel : public ModelPanel void connectItemModelEvents(const int id); inline bool isLocked() { return lock; } }; - -#endif // _TELEMETRY_H_ diff --git a/companion/src/modeledit/telemetry_sensor.ui b/companion/src/modeledit/telemetry_sensor.ui index 12af2cf06..e70cc7aa2 100644 --- a/companion/src/modeledit/telemetry_sensor.ui +++ b/companion/src/modeledit/telemetry_sensor.ui @@ -40,7 +40,7 @@ - + 0 @@ -59,23 +59,13 @@ - + 0 0 - - - Custom - - - - - Calculated - - @@ -147,7 +137,7 @@ - + 0 @@ -175,58 +165,13 @@ - + 0 0 - - - Add - - - - - Average - - - - - Min - - - - - Max - - - - - Multiply - - - - - Totalize - - - - - Cell - - - - - Consumption - - - - - Dist - - @@ -412,138 +357,13 @@ - + 0 0 - - - Raw (-) - - - - - V - - - - - A - - - - - mA - - - - - kt - - - - - m/s - - - - - ft/s - - - - - km/h - - - - - mph - - - - - m - - - - - ft - - - - - °C - - - - - °F - - - - - % - - - - - mAh - - - - - W - - - - - mW - - - - - dBm - - - - - RPM - - - - - g - - - - - ° - - - - - Rad - - - - - mL - - - - - US fl.Oz. - - - - - ml/min - - @@ -560,7 +380,7 @@ - + @@ -720,9 +540,9 @@
autohexspinbox.h
- AutoPrecisionComboBox - QComboBox -
autoprecisioncombobox.h
+ AutoLineEdit + QLineEdit +
autolineedit.h
diff --git a/companion/src/modelprinter.cpp b/companion/src/modelprinter.cpp index 61bfedda9..282f53550 100644 --- a/companion/src/modelprinter.cpp +++ b/companion/src/modelprinter.cpp @@ -1071,17 +1071,6 @@ QString ModelPrinter::printRssiAlarmsDisabled(bool mb) return printBoolean(!mb, BOOLEAN_ENABLEDISABLE); } -QString ModelPrinter::printTelemetrySource(int val) -{ - QStringList strings = QStringList() << tr("None"); - - for (unsigned i=1; i<=CPN_MAX_SENSORS; ++i) { - strings << QString("%1").arg(model.sensorData[i-1].label); - } - - return QString("%1%2").arg((val < 0 ? "-" : "")).arg(strings.value(abs(val))); -} - QString ModelPrinter::printVarioSource(unsigned int val) { switch (val) { @@ -1155,144 +1144,6 @@ QString ModelPrinter::printIgnoreSensorIds(bool mb) return printBoolean(mb, BOOLEAN_ENABLEDISABLE); } -QString ModelPrinter::printSensorType(unsigned int val) -{ - switch (val) { - case SensorData::TELEM_TYPE_CUSTOM: - return tr("Custom"); - case SensorData::TELEM_TYPE_CALCULATED: - return tr("Calculated"); - default: - return CPN_STR_UNKNOWN_ITEM; - } -} - -QString ModelPrinter::printSensorFormula(unsigned int val) -{ - switch (val) { - case SensorData::TELEM_FORMULA_ADD: - return tr("Add"); - case SensorData::TELEM_FORMULA_AVERAGE: - return tr("Average"); - case SensorData::TELEM_FORMULA_MIN: - return tr("Min"); - case SensorData::TELEM_FORMULA_MAX: - return tr("Max"); - case SensorData::TELEM_FORMULA_MULTIPLY: - return tr("Multiply"); - case SensorData::TELEM_FORMULA_TOTALIZE: - return tr("Totalise"); - case SensorData::TELEM_FORMULA_CELL: - return tr("Cell"); - case SensorData::TELEM_FORMULA_CONSUMPTION: - return tr("Consumption"); - case SensorData::TELEM_FORMULA_DIST: - return tr("Distance"); - default: - return CPN_STR_UNKNOWN_ITEM; - } -} - -QString ModelPrinter::printSensorCells(unsigned int val) -{ - QStringList strings; - - strings << tr("Lowest"); - for (int i=1; i<=6; i++) - strings << tr("Cell %1").arg(i); - strings << tr("Highest") << tr("Delta"); - - return strings.value(val); -} - -QString ModelPrinter::printSensorTypeCond(unsigned int idx) -{ - if (!model.sensorData[idx].isAvailable()) - return ""; - else - return printSensorType(model.sensorData[idx].type); -} - -QString ModelPrinter::printSensorParams(unsigned int idx) -{ - QString str = ""; - SensorData sensor = model.sensorData[idx]; - - if (!sensor.isAvailable()) - return str; - - bool isConfigurable = false; - bool gpsFieldsPrinted = false; - bool cellsFieldsPrinted = false; - bool consFieldsPrinted = false; - bool ratioFieldsPrinted = false; - bool totalizeFieldsPrinted = false; - bool sources12FieldsPrinted = false; - bool sources34FieldsPrinted = false; - - if (sensor.type == SensorData::TELEM_TYPE_CALCULATED) { - isConfigurable = (sensor.formula < SensorData::TELEM_FORMULA_CELL); - gpsFieldsPrinted = (sensor.formula == SensorData::TELEM_FORMULA_DIST); - cellsFieldsPrinted = (sensor.formula == SensorData::TELEM_FORMULA_CELL); - consFieldsPrinted = (sensor.formula == SensorData::TELEM_FORMULA_CONSUMPTION); - sources12FieldsPrinted = (sensor.formula <= SensorData::TELEM_FORMULA_MULTIPLY); - sources34FieldsPrinted = (sensor.formula < SensorData::TELEM_FORMULA_MULTIPLY); - totalizeFieldsPrinted = (sensor.formula == SensorData::TELEM_FORMULA_TOTALIZE); - - str.append(printLabelValue(tr("F"), printSensorFormula(sensor.formula))); - } - else { - isConfigurable = sensor.unit < SensorData::UNIT_FIRST_VIRTUAL; - ratioFieldsPrinted = (sensor.unit < SensorData::UNIT_FIRST_VIRTUAL); - - str.append(printLabelValue(tr("Id"), QString::number(sensor.id,16).toUpper())); - str.append(printLabelValue(tr("Inst"), QString::number(sensor.instance))); - } - if (cellsFieldsPrinted) { - str.append(printLabelValue(tr("Sensor"), QString("%1 %2").arg(printTelemetrySource(sensor.source), false).arg(printSensorCells(sensor.index)))); - } - if (sources12FieldsPrinted) { - QStringList srcs; - for (int i=0;i<4;i++) { - if (i < 2 || sources34FieldsPrinted) { - srcs << printTelemetrySource(sensor.sources[i]); - } - } - str.append(printLabelValues(tr("Sources"), srcs)); - } - if (consFieldsPrinted || totalizeFieldsPrinted) - str.append(printLabelValue(tr("Sensor"), printTelemetrySource(sensor.amps))); - if (gpsFieldsPrinted) { - str.append(printLabelValue(tr("GPS"), printTelemetrySource(sensor.gps))); - str.append(printLabelValue(tr("Alt"), printTelemetrySource(sensor.alt))); - } - QString u = sensor.unitString(); - u = u.trimmed() == "" ? "-" : u; - str.append(printLabelValue(tr("Unit"), u)); - if (isConfigurable && sensor.unit != SensorData::UNIT_FAHRENHEIT) - str.append(printLabelValue(tr("Prec"), printTelemetryPrecision(sensor.prec))); - if (ratioFieldsPrinted) { - if (sensor.unit != SensorData::UNIT_RPMS) { - int prec = sensor.prec == 0 ? 1 : pow(10, sensor.prec); - str.append(printLabelValue(tr("Ratio"), QString::number((float)sensor.ratio / 10))); - str.append(printLabelValue(tr("Offset"), QString::number((float)sensor.offset / prec, 'f', sensor.prec))); - } - else if (sensor.unit == SensorData::UNIT_RPMS) { - str.append(printLabelValue(tr("Blades"), QString::number(sensor.ratio))); - str.append(printLabelValue(tr("Multi"), QString::number(sensor.offset))); - } - } - if (sensor.unit != SensorData::UNIT_RPMS && isConfigurable) - str.append(printLabelValue(tr("Auto Offset"), printBoolean(sensor.autoOffset, BOOLEAN_YN))); - if (isConfigurable) - str.append(printLabelValue(tr("Filter"), printBoolean(sensor.filter, BOOLEAN_YN))); - if (sensor.type == SensorData::TELEM_TYPE_CALCULATED) - str.append(printLabelValue(tr("Persist"), printBoolean(sensor.persistent, BOOLEAN_YN))); - str.append(printLabelValue(tr("Positive"), printBoolean(sensor.onlyPositive, BOOLEAN_YN))); - str.append(printLabelValue(tr("Log"), printBoolean(sensor.logs, BOOLEAN_YN), false)); - return str; -} - QString ModelPrinter::printTelemetryScreenType(unsigned int val) { switch (val) { @@ -1373,17 +1224,3 @@ QString ModelPrinter::printChecklist() } return str; } - -QString ModelPrinter::printTelemetryPrecision(unsigned int val) -{ - switch (val) { - case 0: - return tr("0."); - case 1: - return tr("0.0"); - case 2: - return tr("0.00"); - default: - return CPN_STR_UNKNOWN_ITEM; - } -} diff --git a/companion/src/modelprinter.h b/companion/src/modelprinter.h index 2cce3585d..ea2eab2d8 100644 --- a/companion/src/modelprinter.h +++ b/companion/src/modelprinter.h @@ -18,8 +18,7 @@ * GNU General Public License for more details. */ -#ifndef _MODELPRINTER_H_ -#define _MODELPRINTER_H_ +#pragma once #include #include @@ -116,22 +115,15 @@ class ModelPrinter: public QObject QString printLabelValue(const QString & lbl, const QString & val, const bool sep = false); QString printLabelValues(const QString & lbl, const QStringList & vals, const bool sep = false); QString printRssiAlarmsDisabled(bool mb); - QString printTelemetrySource(int val); QString printVarioSource(unsigned int val); QString printVarioCenterSilent(bool mb); QString printVoltsSource(unsigned int val); QString printCurrentSource(unsigned int val); QString printMahPersistent(bool mb); QString printIgnoreSensorIds(bool mb); - QString printSensorType(unsigned int val); - QString printSensorFormula(unsigned int val); - QString printSensorCells(unsigned int val); - QString printSensorTypeCond(unsigned int idx); - QString printSensorParams(unsigned int idx); QString printTelemetryScreenType(unsigned int val); QString printTelemetryScreen(unsigned int idx, unsigned int line, unsigned int width); QString printChecklist(); - QString printTelemetryPrecision(unsigned int val); private: Firmware * firmware; @@ -139,5 +131,3 @@ class ModelPrinter: public QObject const ModelData & model; }; - -#endif // _MODELPRINTER_H_ diff --git a/companion/src/multimodelprinter.cpp b/companion/src/multimodelprinter.cpp index 4da889cb1..17cb30be4 100644 --- a/companion/src/multimodelprinter.cpp +++ b/companion/src/multimodelprinter.cpp @@ -777,7 +777,7 @@ QString MultiModelPrinter::printTelemetry() if (firmware->getCapability(HasVario)) { columns.appendRowStart(tr("Altimetry"), 20); if (IS_HORUS_OR_TARANIS(firmware->getBoard())) { - LABELCOMPARECELL(tr("Vario source"), modelPrinter->printTelemetrySource(model->frsky.varioSource), 80); + LABELCOMPARECELL(tr("Vario source"), SensorData::sourceToString(model, model->frsky.varioSource), 80); } else { LABELCOMPARECELL(tr("Vario source"), modelPrinter->printVarioSource(model->frsky.varioSource), 80); @@ -801,8 +801,8 @@ QString MultiModelPrinter::printTelemetry() if (IS_HORUS_OR_TARANIS(firmware->getBoard())) { columns.appendRowStart(tr("Top Bar"), 20); columns.appendCellStart(80); - COMPARESTRING(tr("Volts source"), modelPrinter->printTelemetrySource(model->frsky.voltsSource), true); - COMPARESTRING(tr("Altitude source"), modelPrinter->printTelemetrySource(model->frsky.altitudeSource), false); + COMPARESTRING(tr("Volts source"), SensorData::sourceToString(model, model->frsky.voltsSource), true); + COMPARESTRING(tr("Altitude source"), SensorData::sourceToString(model, model->frsky.altitudeSource), false); columns.appendCellEnd(); columns.appendRowEnd(); } @@ -822,9 +822,9 @@ QString MultiModelPrinter::printSensors() int count = 0; columns.appendSectionTableStart(); columns.appendRowHeader(QStringList() << tr("Name") << tr("Type") << tr("Parameters")); - for (unsigned i=0; isensorData[i].isAvailable()) { tsEmpty = false; break; @@ -836,8 +836,8 @@ QString MultiModelPrinter::printSensors() columns.appendCellStart(20, true); COMPARE(model->sensorData[i].nameToString(i)); columns.appendCellEnd(true); - COMPARECELLWIDTH(modelPrinter->printSensorTypeCond(i), 15); - COMPARECELLWIDTH(modelPrinter->printSensorParams(i), 65); + COMPARECELLWIDTH(model->sensorData[i].isAvailable() ? model->sensorData[i].typeToString() : "", 15); + COMPARECELLWIDTH(model->sensorData[i].paramsToString(model), 65); columns.appendRowEnd(); } } diff --git a/companion/src/shared/autobitsetcheckbox.h b/companion/src/shared/autobitsetcheckbox.h index 6274e0117..ea86db956 100644 --- a/companion/src/shared/autobitsetcheckbox.h +++ b/companion/src/shared/autobitsetcheckbox.h @@ -18,8 +18,7 @@ * GNU General Public License for more details. */ -#ifndef AUTOBITSETCHECKBOX_H -#define AUTOBITSETCHECKBOX_H +#pragma once #include #include "genericpanel.h" @@ -174,5 +173,3 @@ class AutoBitsetCheckBox: public QCheckBox bool m_lock = false; GenericPanel * m_panel = nullptr; }; - -#endif // AUTOBITSETCHECKBOX_H diff --git a/companion/src/shared/autocheckbox.h b/companion/src/shared/autocheckbox.h index df99278a2..f5b233fed 100644 --- a/companion/src/shared/autocheckbox.h +++ b/companion/src/shared/autocheckbox.h @@ -18,8 +18,7 @@ * GNU General Public License for more details. */ -#ifndef _AUTOCHECKBOX_H_ -#define _AUTOCHECKBOX_H_ +#pragma once #include #include "modeledit/modeledit.h" @@ -45,6 +44,11 @@ class AutoCheckBox: public QCheckBox updateValue(); } + void setEnabled(bool enabled) + { + QCheckBox::setEnabled(enabled); + } + void updateValue() { lock = true; @@ -70,5 +74,3 @@ class AutoCheckBox: public QCheckBox ModelPanel * panel; bool lock; }; - -#endif // _AUTOCHECKBOX_H_ diff --git a/companion/src/shared/autocombobox.h b/companion/src/shared/autocombobox.h index 158352f97..784abaefa 100644 --- a/companion/src/shared/autocombobox.h +++ b/companion/src/shared/autocombobox.h @@ -18,8 +18,7 @@ * GNU General Public License for more details. */ -#ifndef _AUTOCOMBOBOX_H_ -#define _AUTOCOMBOBOX_H_ +#pragma once #include #include "genericpanel.h" @@ -137,5 +136,3 @@ class AutoComboBox: public QComboBox bool lock = false; bool hasModel = false; }; - -#endif // _AUTOCOMBOBOX_H_ diff --git a/companion/src/shared/autodoublespinbox.h b/companion/src/shared/autodoublespinbox.h index 17188243b..6560b6ea2 100644 --- a/companion/src/shared/autodoublespinbox.h +++ b/companion/src/shared/autodoublespinbox.h @@ -18,8 +18,7 @@ * GNU General Public License for more details. */ -#ifndef _AUTODOUBLESPINBOX_H_ -#define _AUTODOUBLESPINBOX_H_ +#pragma once #include #include "modeledit/modeledit.h" @@ -97,5 +96,3 @@ class AutoDoubleSpinBox: public QDoubleSpinBox ModelPanel * panel; bool lock; }; - -#endif // _AUTODOUBLESPINBOX_H_ diff --git a/companion/src/shared/autohexspinbox.h b/companion/src/shared/autohexspinbox.h index 7db76d2a3..d7df46bd6 100644 --- a/companion/src/shared/autohexspinbox.h +++ b/companion/src/shared/autohexspinbox.h @@ -18,8 +18,7 @@ * GNU General Public License for more details. */ -#ifndef _AUTOHEXSPINBOX_H_ -#define _AUTOHEXSPINBOX_H_ +#pragma once #include "hexspinbox.h" #include "modeledit/modeledit.h" @@ -68,5 +67,3 @@ class AutoHexSpinBox: public HexSpinBox ModelPanel * panel; bool lock; }; - -#endif // _AUTOHEXSPINBOX_H_ diff --git a/companion/src/shared/autolineedit.h b/companion/src/shared/autolineedit.h index 36d848972..0f888e6df 100644 --- a/companion/src/shared/autolineedit.h +++ b/companion/src/shared/autolineedit.h @@ -18,8 +18,7 @@ * GNU General Public License for more details. */ -#ifndef _AUTOLINEEDIT_H_ -#define _AUTOLINEEDIT_H_ +#pragma once #include #include @@ -71,10 +70,13 @@ class AutoLineEdit: public QLineEdit lock = false; } + signals: + void currentDataChanged(); + protected slots: void onEdited() { - if (lock) + if ((panel && panel->lock) || lock) return; if (field) @@ -86,6 +88,8 @@ class AutoLineEdit: public QLineEdit if (panel) emit panel->modified(); + + emit currentDataChanged(); } protected: @@ -94,5 +98,3 @@ class AutoLineEdit: public QLineEdit GenericPanel * panel; bool lock; }; - -#endif // _AUTOLINEEDIT_H_ diff --git a/companion/src/shared/autoprecisioncombobox.h b/companion/src/shared/autoprecisioncombobox.h index 4e143f286..e93059199 100644 --- a/companion/src/shared/autoprecisioncombobox.h +++ b/companion/src/shared/autoprecisioncombobox.h @@ -18,8 +18,7 @@ * GNU General Public License for more details. */ -#ifndef _AUTOPRECISIONCOMBOBOX_H_ -#define _AUTOPRECISIONCOMBOBOX_H_ +#pragma once #include "genericpanel.h" @@ -253,5 +252,3 @@ class AutoPrecisionComboBox: public QComboBox QString m_suffix = ""; bool m_lock = false; }; - -#endif // _AUTOPRECISIONCOMBOBOX_H_ diff --git a/companion/src/shared/genericpanel.h b/companion/src/shared/genericpanel.h index 5351355b6..bbb9b7254 100644 --- a/companion/src/shared/genericpanel.h +++ b/companion/src/shared/genericpanel.h @@ -18,8 +18,7 @@ * GNU General Public License for more details. */ -#ifndef _GENERICPANEL_H_ -#define _GENERICPANEL_H_ +#pragma once #include @@ -65,5 +64,3 @@ class GenericPanel : public QWidget void setFocusFilter(QWidget * w); void disableMouseScrolling(); }; - -#endif // _GENERICPANEL_H_ diff --git a/companion/src/shared/hexspinbox.h b/companion/src/shared/hexspinbox.h index fc404d98a..204cc8a55 100644 --- a/companion/src/shared/hexspinbox.h +++ b/companion/src/shared/hexspinbox.h @@ -18,8 +18,7 @@ * GNU General Public License for more details. */ -#ifndef _HEXSPINBOX_H_ -#define _HEXSPINBOX_H_ +#pragma once #include @@ -40,5 +39,3 @@ class HexSpinBox : public QSpinBox private: QRegExpValidator *validator; }; - -#endif // _HEXSPINBOX_H_ diff --git a/companion/src/shared/verticalscrollarea.h b/companion/src/shared/verticalscrollarea.h index 36f564dd7..d409a18ca 100644 --- a/companion/src/shared/verticalscrollarea.h +++ b/companion/src/shared/verticalscrollarea.h @@ -18,8 +18,7 @@ * GNU General Public License for more details. */ -#ifndef _VERTICALSCROLLAREA_H_ -#define _VERTICALSCROLLAREA_H_ +#pragma once #include @@ -36,6 +35,3 @@ class VerticalScrollArea : public QScrollArea private: GenericPanel * panel; }; - -#endif // _VERTICALSCROLLAREA_H_ -