Sensor ui refactoring
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _HELPERS_DATA_H_
|
||||
#define _HELPERS_DATA_H_
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
#endif // _HELPERS_DATA_H_
|
||||
@@ -57,17 +57,65 @@ 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);
|
||||
}
|
||||
|
||||
constexpr int SENSOR_ISCONFIGURABLE { 1 << 1 };
|
||||
constexpr int SENSOR_PRINT_GPS { 1 << 2 };
|
||||
constexpr int SENSOR_PRINT_CELLS { 1 << 3 };
|
||||
constexpr int SENSOR_PRINT_CONSUMPTION { 1 << 4 };
|
||||
constexpr int SENSOR_PRINT_RATIO { 1 << 5 };
|
||||
constexpr int SENSOR_PRINT_TOTALIZE { 1 << 6 };
|
||||
constexpr int SENSOR_PRINT_SOURCES_12 { 1 << 7 };
|
||||
constexpr int SENSOR_PRINT_SOURCES_34 { 1 << 8 };
|
||||
constexpr char FMT_LABEL[] { "<b>%1:</b> " };
|
||||
constexpr char FMT_VALUE[] { "%1 " };
|
||||
constexpr char FMT_LABEL_VALUE[] { "<b>%1:</b> %2 " };
|
||||
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[] { "<b>%1:</b> " };
|
||||
constexpr char FMT_VALUE[] { "%1 " };
|
||||
constexpr char FMT_LABEL_VALUE[] { "<b>%1:</b> %2 " };
|
||||
|
||||
QString SensorData::paramsToString(const ModelData * model) const
|
||||
{
|
||||
@@ -75,62 +123,45 @@ QString SensorData::paramsToString(const ModelData * model) const
|
||||
return "";
|
||||
|
||||
QString str;
|
||||
int mask = 0;
|
||||
int mask = getMask();
|
||||
|
||||
if (type == TELEM_TYPE_CALCULATED) {
|
||||
if (formula < TELEM_FORMULA_CELL)
|
||||
mask |= SENSOR_ISCONFIGURABLE;
|
||||
if (formula == TELEM_FORMULA_DIST)
|
||||
mask |= SENSOR_PRINT_GPS;
|
||||
if (formula == TELEM_FORMULA_CELL)
|
||||
mask |= SENSOR_PRINT_CELLS;
|
||||
if (formula == TELEM_FORMULA_CONSUMPTION)
|
||||
mask |= SENSOR_PRINT_CONSUMPTION;
|
||||
if (formula <= TELEM_FORMULA_MULTIPLY)
|
||||
mask |= SENSOR_PRINT_SOURCES_12;
|
||||
if (formula < TELEM_FORMULA_MULTIPLY)
|
||||
mask |= SENSOR_PRINT_SOURCES_34;
|
||||
if (formula == TELEM_FORMULA_TOTALIZE)
|
||||
mask |= SENSOR_PRINT_TOTALIZE;
|
||||
|
||||
str.append(QString(FMT_LABEL_VALUE).arg(tr("Formula")).arg(formulaToString(formula)));
|
||||
}
|
||||
else {
|
||||
if (unit < UNIT_FIRST_VIRTUAL)
|
||||
mask |= (SENSOR_ISCONFIGURABLE | SENSOR_PRINT_RATIO);
|
||||
|
||||
str.append(QString(FMT_LABEL_VALUE).arg(tr("Id")).arg(QString::number(id, 16).toUpper()));
|
||||
str.append(QString(FMT_LABEL_VALUE).arg(tr("Instance")).arg(instance));
|
||||
}
|
||||
|
||||
if (mask & SENSOR_PRINT_CELLS) {
|
||||
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(index)));
|
||||
}
|
||||
|
||||
if (mask & SENSOR_PRINT_SOURCES_12) {
|
||||
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_PRINT_SOURCES_34) {
|
||||
if (i < 2 || mask & SENSOR_HAS_SOURCES_34) {
|
||||
str.append(QString(FMT_VALUE).arg(sourceToString(model, sources[i])));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mask & SENSOR_PRINT_CONSUMPTION || mask & SENSOR_PRINT_TOTALIZE)
|
||||
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_PRINT_GPS) {
|
||||
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)));
|
||||
}
|
||||
|
||||
str.append(QString(FMT_LABEL_VALUE).arg(tr("Unit")).arg(unitToString(unit)));
|
||||
if (mask & SENSOR_ISCONFIGURABLE)
|
||||
str.append(QString(FMT_LABEL_VALUE).arg(tr("Unit")).arg(unitToString(unit)));
|
||||
|
||||
if (mask & SENSOR_ISCONFIGURABLE && unit != UNIT_FAHRENHEIT)
|
||||
if (mask & SENSOR_HAS_PRECISION)
|
||||
str.append(QString(FMT_LABEL_VALUE).arg(tr("Precision")).arg(precToString(prec)));
|
||||
|
||||
if (mask & SENSOR_PRINT_RATIO) {
|
||||
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));
|
||||
@@ -149,12 +180,78 @@ QString SensorData::paramsToString(const ModelData * model) const
|
||||
if (type == TELEM_TYPE_CALCULATED)
|
||||
str.append(QString(FMT_LABEL_VALUE).arg(tr("Persist")).arg(boolToString(persistent)));
|
||||
|
||||
str.append(QString(FMT_LABEL_VALUE).arg(tr("Positive")).arg(boolToString(onlyPositive)));
|
||||
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::typeToString(const int value)
|
||||
{
|
||||
|
||||
@@ -21,16 +21,30 @@
|
||||
#ifndef SENSORDATA_H
|
||||
#define SENSORDATA_H
|
||||
|
||||
#include "helpersdata.h"
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
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:
|
||||
@@ -171,7 +185,17 @@ class SensorData {
|
||||
QString getOrigin(const ModelData* model) const;
|
||||
void clear() { memset(this, 0, sizeof(SensorData)); }
|
||||
bool isEmpty() 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);
|
||||
|
||||
@@ -27,13 +27,13 @@
|
||||
|
||||
#include <TimerEdit>
|
||||
|
||||
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)
|
||||
|
||||
@@ -94,11 +94,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 +107,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;
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="name">
|
||||
<widget class="AutoLineEdit" name="name">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
@@ -59,23 +59,13 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="type">
|
||||
<widget class="AutoComboBox" name="type">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Custom</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Calculated</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@@ -147,7 +137,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="origin">
|
||||
<widget class="AutoLineEdit" name="origin">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
@@ -175,58 +165,13 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="formula">
|
||||
<widget class="AutoComboBox" name="formula">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Average</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Min</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Max</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Multiply</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Totalize</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Cell</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Consumption</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Dist</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@@ -412,138 +357,13 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="unit">
|
||||
<widget class="AutoComboBox" name="unit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Raw (-)</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>V</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>A</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>mA</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>kt</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>m/s</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>ft/s</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>km/h</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>mph</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>m</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>ft</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>°C</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>°F</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>%</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>mAh</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>W</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>mW</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>dBm</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>RPM</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>g</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>°</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Rad</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>mL</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>US fl.Oz.</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>ml/min</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@@ -560,7 +380,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="AutoPrecisionComboBox" name="prec"/>
|
||||
<widget class="AutoComboBox" name="prec"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="ratioLabel">
|
||||
@@ -720,9 +540,9 @@
|
||||
<header>autohexspinbox.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>AutoPrecisionComboBox</class>
|
||||
<extends>QComboBox</extends>
|
||||
<header>autoprecisioncombobox.h</header>
|
||||
<class>AutoLineEdit</class>
|
||||
<extends>QLineEdit</extends>
|
||||
<header>autolineedit.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
|
||||
@@ -836,7 +836,7 @@ QString MultiModelPrinter::printSensors()
|
||||
columns.appendCellStart(20, true);
|
||||
COMPARE(model->sensorData[i].nameToString(i));
|
||||
columns.appendCellEnd(true);
|
||||
COMPARECELLWIDTH(model->sensorData[i].isAvailable() ? SensorData::typeToString(model->sensorData[i].type) : "", 15);
|
||||
COMPARECELLWIDTH(model->sensorData[i].isAvailable() ? model->sensorData[i].typeToString() : "", 15);
|
||||
COMPARECELLWIDTH(model->sensorData[i].paramsToString(model), 65);
|
||||
columns.appendRowEnd();
|
||||
}
|
||||
|
||||
@@ -45,6 +45,11 @@ class AutoCheckBox: public QCheckBox
|
||||
updateValue();
|
||||
}
|
||||
|
||||
void setEnabled(bool enabled)
|
||||
{
|
||||
QCheckBox::setEnabled(enabled);
|
||||
}
|
||||
|
||||
void updateValue()
|
||||
{
|
||||
lock = true;
|
||||
|
||||
@@ -71,10 +71,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 +89,8 @@ class AutoLineEdit: public QLineEdit
|
||||
|
||||
if (panel)
|
||||
emit panel->modified();
|
||||
|
||||
emit currentDataChanged();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user