Companion enhanced telemetry sensors context menu and other refinements across context menus (#7716)
Companion enhanced telemetry sensors context menu with reference updates
This commit is contained in:
@@ -28,9 +28,6 @@
|
||||
|
||||
#include <TimerEdit>
|
||||
|
||||
|
||||
/******************************************************/
|
||||
|
||||
TelemetryCustomScreen::TelemetryCustomScreen(QWidget *parent, ModelData & model, FrSkyScreenData & screen, GeneralSettings & generalSettings, Firmware * firmware, RawSourceFilterItemModel * srcModel):
|
||||
ModelPanel(parent, model, generalSettings, firmware),
|
||||
ui(new Ui::TelemetryCustomScreen),
|
||||
@@ -38,17 +35,17 @@ TelemetryCustomScreen::TelemetryCustomScreen(QWidget *parent, ModelData & model,
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
for (int l=0; l<4; l++) {
|
||||
for (int c=0; c<firmware->getCapability(TelemetryCustomScreensFieldsPerLine); c++) {
|
||||
for (int l = 0; l < firmware->getCapability(TelemetryCustomScreensLines); l++) {
|
||||
for (int c = 0; c < firmware->getCapability(TelemetryCustomScreensFieldsPerLine); c++) {
|
||||
fieldsCB[l][c] = new QComboBox(this);
|
||||
fieldsCB[l][c]->setProperty("index", c + (l<<8));
|
||||
fieldsCB[l][c]->setProperty("index", c + (l << 8));
|
||||
fieldsCB[l][c]->setModel(srcModel);
|
||||
ui->screenNumsLayout->addWidget(fieldsCB[l][c], l, c, 1, 1);
|
||||
connect(fieldsCB[l][c], SIGNAL(activated(int)), this, SLOT(customFieldChanged(int)));
|
||||
}
|
||||
}
|
||||
|
||||
for (int l=0; l<4; l++) {
|
||||
for (int l = 0; l < firmware->getCapability(TelemetryCustomScreensBars); l++) {
|
||||
barsCB[l] = new QComboBox(this);
|
||||
barsCB[l]->setProperty("index", l);
|
||||
barsCB[l]->setModel(srcModel);
|
||||
@@ -122,18 +119,18 @@ void TelemetryCustomScreen::update()
|
||||
ui->screenNums->setVisible(screen.type == TELEMETRY_SCREEN_NUMBERS);
|
||||
ui->screenBars->setVisible(screen.type == TELEMETRY_SCREEN_BARS);
|
||||
|
||||
for (int l=0; l<4; l++) {
|
||||
for (int c=0; c<firmware->getCapability(TelemetryCustomScreensFieldsPerLine); c++) {
|
||||
for (int l = 0; l < firmware->getCapability(TelemetryCustomScreensLines); l++) {
|
||||
for (int c = 0; c < firmware->getCapability(TelemetryCustomScreensFieldsPerLine); c++) {
|
||||
fieldsCB[l][c]->setCurrentIndex(fieldsCB[l][c]->findData(screen.body.lines[l].source[c].toValue()));
|
||||
}
|
||||
}
|
||||
|
||||
for (int l=0; l<4; l++) {
|
||||
for (int l = 0; l < firmware->getCapability(TelemetryCustomScreensBars); l++) {
|
||||
barsCB[l]->setCurrentIndex(barsCB[l]->findData(screen.body.bars[l].source.toValue()));
|
||||
}
|
||||
|
||||
if (screen.type == TELEMETRY_SCREEN_BARS) {
|
||||
for (int i=0; i<4; i++) {
|
||||
for (int i = 0; i < firmware->getCapability(TelemetryCustomScreensBars); i++) {
|
||||
updateBar(i);
|
||||
}
|
||||
}
|
||||
@@ -292,13 +289,14 @@ void TelemetryCustomScreen::barTimeChanged()
|
||||
|
||||
/******************************************************/
|
||||
|
||||
TelemetrySensorPanel::TelemetrySensorPanel(QWidget *parent, SensorData & sensor, int sensorIndex, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware):
|
||||
TelemetrySensorPanel::TelemetrySensorPanel(QWidget *parent, SensorData & sensor, int sensorIndex, int sensorCapability, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware):
|
||||
ModelPanel(parent, model, generalSettings, firmware),
|
||||
ui(new Ui::TelemetrySensor),
|
||||
sensor(sensor),
|
||||
lock(false),
|
||||
sensorIndex(sensorIndex),
|
||||
selectedIndex(0)
|
||||
selectedIndex(0),
|
||||
sensorCapability(sensorCapability)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->numLabel->setText(tr("TELE%1").arg(sensorIndex + 1));
|
||||
@@ -326,7 +324,7 @@ TelemetrySensorPanel::TelemetrySensorPanel(QWidget *parent, SensorData & sensor,
|
||||
ui->ampsSensor->setField(sensor.amps, this);
|
||||
ui->cellsSensor->setField(sensor.source, this);
|
||||
ui->cellsIndex->addItem(tr("Lowest"), SensorData::TELEM_CELL_INDEX_LOWEST);
|
||||
for (int i = 1; i <= 6; i++)
|
||||
for (int i = SensorData::TELEM_CELL_INDEX_LOWEST + 1; i < SensorData::TELEM_CELL_INDEX_HIGHEST; i++)
|
||||
ui->cellsIndex->addItem(tr("Cell %1").arg(i), i);
|
||||
ui->cellsIndex->addItem(tr("Highest"), SensorData::TELEM_CELL_INDEX_HIGHEST);
|
||||
ui->cellsIndex->addItem(tr("Delta"), SensorData::TELEM_CELL_INDEX_DELTA);
|
||||
@@ -475,8 +473,8 @@ void populateTelemetrySourcesComboBox(AutoComboBox * cb, const ModelData * model
|
||||
{
|
||||
cb->clear();
|
||||
if (negative) {
|
||||
for (int i=-CPN_MAX_SENSORS; i<0; ++i) {
|
||||
const SensorData& sensor = model->sensorData[-i-1];
|
||||
for (int i = -CPN_MAX_SENSORS; i < 0; ++i) {
|
||||
const SensorData& sensor = model->sensorData[-i - 1];
|
||||
if (sensor.isAvailable()) {
|
||||
if (sensor.type == SensorData::TELEM_TYPE_CUSTOM)
|
||||
cb->addItem(QString("-%1 (%2)").arg(sensor.label, sensor.getOrigin(model)), i);
|
||||
@@ -486,7 +484,7 @@ void populateTelemetrySourcesComboBox(AutoComboBox * cb, const ModelData * model
|
||||
}
|
||||
}
|
||||
cb->addItem("---", 0);
|
||||
for (unsigned i=1; i<=CPN_MAX_SENSORS; ++i) {
|
||||
for (unsigned i = 1; i <= CPN_MAX_SENSORS; ++i) {
|
||||
const SensorData& sensor = model->sensorData[i-1];
|
||||
if (sensor.isAvailable()) {
|
||||
if (sensor.type == SensorData::TELEM_TYPE_CUSTOM)
|
||||
@@ -572,6 +570,11 @@ void TelemetrySensorPanel::on_customContextMenuRequested(QPoint pos)
|
||||
contextMenu.addAction(CompanionIcon("paste.png"), tr("Paste"),this,SLOT(cmPaste()))->setEnabled(hasClipboardData());
|
||||
contextMenu.addAction(CompanionIcon("clear.png"), tr("Clear"),this,SLOT(cmClear()));
|
||||
contextMenu.addSeparator();
|
||||
contextMenu.addAction(CompanionIcon("arrow-right.png"), tr("Insert"),this,SLOT(cmInsert()))->setEnabled(insertAllowed());
|
||||
contextMenu.addAction(CompanionIcon("arrow-left.png"), tr("Delete"),this,SLOT(cmDelete()));
|
||||
contextMenu.addAction(CompanionIcon("moveup.png"), tr("Move Up"),this,SLOT(cmMoveUp()))->setEnabled(moveUpAllowed());
|
||||
contextMenu.addAction(CompanionIcon("movedown.png"), tr("Move Down"),this,SLOT(cmMoveDown()))->setEnabled(moveDownAllowed());
|
||||
contextMenu.addSeparator();
|
||||
contextMenu.addAction(CompanionIcon("clear.png"), tr("Clear All"),this,SLOT(cmClearAll()));
|
||||
|
||||
contextMenu.exec(globalPos);
|
||||
@@ -589,6 +592,21 @@ bool TelemetrySensorPanel::hasClipboardData(QByteArray * data) const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TelemetrySensorPanel::insertAllowed() const
|
||||
{
|
||||
return ((selectedIndex < sensorCapability - 1) && (model->sensorData[sensorCapability - 1].isEmpty()));
|
||||
}
|
||||
|
||||
bool TelemetrySensorPanel::moveDownAllowed() const
|
||||
{
|
||||
return selectedIndex < sensorCapability - 1;
|
||||
}
|
||||
|
||||
bool TelemetrySensorPanel::moveUpAllowed() const
|
||||
{
|
||||
return selectedIndex > 0;
|
||||
}
|
||||
|
||||
void TelemetrySensorPanel::cmCopy()
|
||||
{
|
||||
QByteArray data;
|
||||
@@ -600,8 +618,11 @@ void TelemetrySensorPanel::cmCopy()
|
||||
|
||||
void TelemetrySensorPanel::cmCut()
|
||||
{
|
||||
if (QMessageBox::question(this, CPN_STR_APP_NAME, tr("Cut Telemetry Sensor. Are you sure?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
|
||||
return;
|
||||
|
||||
cmCopy();
|
||||
cmClear();
|
||||
cmClear(false);
|
||||
}
|
||||
|
||||
void TelemetrySensorPanel::cmPaste()
|
||||
@@ -614,12 +635,15 @@ void TelemetrySensorPanel::cmPaste()
|
||||
}
|
||||
}
|
||||
|
||||
void TelemetrySensorPanel::cmClear()
|
||||
void TelemetrySensorPanel::cmClear(bool prompt)
|
||||
{
|
||||
if (QMessageBox::question(this, CPN_STR_APP_NAME, tr("Clear Telemetry Sensor. Are you sure?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
|
||||
return;
|
||||
if (prompt) {
|
||||
if (QMessageBox::question(this, CPN_STR_APP_NAME, tr("Clear Telemetry Sensor. Are you sure?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
|
||||
return;
|
||||
}
|
||||
|
||||
sensor.clear();
|
||||
model->updateAllReferences(ModelData::REF_UPD_TYPE_SENSOR, ModelData::REF_UPD_ACT_CLEAR, selectedIndex);
|
||||
emit dataModified();
|
||||
emit modified();
|
||||
}
|
||||
@@ -632,6 +656,26 @@ void TelemetrySensorPanel::cmClearAll()
|
||||
emit clearAllSensors();
|
||||
}
|
||||
|
||||
void TelemetrySensorPanel::cmInsert()
|
||||
{
|
||||
emit insertSensor(selectedIndex);
|
||||
}
|
||||
|
||||
void TelemetrySensorPanel::cmDelete()
|
||||
{
|
||||
emit deleteSensor(selectedIndex);
|
||||
}
|
||||
|
||||
void TelemetrySensorPanel::cmMoveUp()
|
||||
{
|
||||
emit moveUpSensor(selectedIndex);
|
||||
}
|
||||
|
||||
void TelemetrySensorPanel::cmMoveDown()
|
||||
{
|
||||
emit moveDownSensor(selectedIndex);
|
||||
}
|
||||
|
||||
/******************************************************/
|
||||
|
||||
TelemetryPanel::TelemetryPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware):
|
||||
@@ -640,6 +684,10 @@ TelemetryPanel::TelemetryPanel(QWidget *parent, ModelData & model, GeneralSettin
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
sensorCapability = firmware->getCapability(Sensors);
|
||||
if (sensorCapability > CPN_MAX_SENSORS) // TODO should be role of getCapability
|
||||
sensorCapability = CPN_MAX_SENSORS;
|
||||
|
||||
if (firmware->getCapability(NoTelemetryProtocol)) {
|
||||
model.frsky.usrProto = 1;
|
||||
}
|
||||
@@ -648,13 +696,17 @@ TelemetryPanel::TelemetryPanel(QWidget *parent, ModelData & model, GeneralSettin
|
||||
ui->varioCenterSilent->setField(model.frsky.varioCenterSilent, this);
|
||||
ui->A1GB->hide();
|
||||
ui->A2GB->hide();
|
||||
for (unsigned i= 0; i < CPN_MAX_SENSORS; ++i) {
|
||||
TelemetrySensorPanel * panel = new TelemetrySensorPanel(this, model.sensorData[i], i, model, generalSettings, firmware);
|
||||
for (int i = 0; i < sensorCapability; ++i) {
|
||||
TelemetrySensorPanel * panel = new TelemetrySensorPanel(this, model.sensorData[i], i, sensorCapability, model, generalSettings, firmware);
|
||||
ui->sensorsLayout->addWidget(panel);
|
||||
sensorPanels[i] = panel;
|
||||
connect(panel, SIGNAL(dataModified()), this, SLOT(update()));
|
||||
connect(panel, SIGNAL(modified()), this, SLOT(onModified()));
|
||||
connect(panel, SIGNAL(clearAllSensors()), this, SLOT(on_clearAllSensors()));
|
||||
connect(panel, SIGNAL(insertSensor(int)), this, SLOT(on_insertSensor(int)));
|
||||
connect(panel, SIGNAL(deleteSensor(int)), this, SLOT(on_deleteSensor(int)));
|
||||
connect(panel, SIGNAL(moveUpSensor(int)), this, SLOT(on_moveUpSensor(int)));
|
||||
connect(panel, SIGNAL(moveDownSensor(int)), this, SLOT(on_moveDownSensor(int)));
|
||||
}
|
||||
|
||||
if (IS_TARANIS_X9(firmware->getBoard())) {
|
||||
@@ -670,7 +722,7 @@ TelemetryPanel::TelemetryPanel(QWidget *parent, ModelData & model, GeneralSettin
|
||||
|
||||
for (int i = 0; i < firmware->getCapability(TelemetryCustomScreens); i++) {
|
||||
TelemetryCustomScreen * tab = new TelemetryCustomScreen(this, model, model.frsky.screens[i], generalSettings, firmware, srcModel);
|
||||
ui->customScreens->addTab(tab, tr("Telemetry screen %1").arg(i+1));
|
||||
ui->customScreens->addTab(tab, tr("Telemetry screen %1").arg(i + 1));
|
||||
telemetryCustomScreens[i] = tab;
|
||||
connect(tab, &TelemetryCustomScreen::modified, this, &TelemetryPanel::onModified);
|
||||
connect(this, &TelemetryPanel::updated, tab, &TelemetryCustomScreen::update);
|
||||
@@ -703,7 +755,7 @@ void TelemetryPanel::update()
|
||||
populateTelemetrySourcesComboBox(ui->varioSource, model, false);
|
||||
}
|
||||
|
||||
for (unsigned i=0; i<CPN_MAX_SENSORS; ++i) {
|
||||
for (int i = 0; i < sensorCapability; ++i) {
|
||||
sensorPanels[i]->update();
|
||||
}
|
||||
|
||||
@@ -761,10 +813,10 @@ void TelemetryPanel::setup()
|
||||
ui->VarioLabel_1->hide();
|
||||
ui->VarioLabel_2->hide();
|
||||
}
|
||||
ui->varioLimitMin_DSB->setValue(model->frsky.varioMin-10);
|
||||
ui->varioLimitMax_DSB->setValue(model->frsky.varioMax+10);
|
||||
ui->varioLimitCenterMax_DSB->setValue((model->frsky.varioCenterMax/10.0)+0.5);
|
||||
ui->varioLimitCenterMin_DSB->setValue((model->frsky.varioCenterMin/10.0)-0.5);
|
||||
ui->varioLimitMin_DSB->setValue(model->frsky.varioMin - 10);
|
||||
ui->varioLimitMax_DSB->setValue(model->frsky.varioMax + 10);
|
||||
ui->varioLimitCenterMax_DSB->setValue((model->frsky.varioCenterMax / 10.0) + 0.5);
|
||||
ui->varioLimitCenterMin_DSB->setValue((model->frsky.varioCenterMin / 10.0) - 0.5);
|
||||
}
|
||||
|
||||
ui->altimetryGB->setVisible(firmware->getCapability(HasVario)),
|
||||
@@ -842,7 +894,7 @@ void TelemetryPanel::on_frskyProtoCB_currentIndexChanged(int index)
|
||||
{
|
||||
if (!lock) {
|
||||
model->frsky.usrProto = index;
|
||||
for (int i=0; i<firmware->getCapability(TelemetryCustomScreens); i++)
|
||||
for (int i = 0; i < firmware->getCapability(TelemetryCustomScreens); i++)
|
||||
telemetryCustomScreens[i]->update();
|
||||
emit modified();
|
||||
}
|
||||
@@ -862,23 +914,23 @@ void TelemetryPanel::on_rssiAlarmCriticalSB_editingFinished()
|
||||
|
||||
void TelemetryPanel::on_varioLimitMin_DSB_editingFinished()
|
||||
{
|
||||
model->frsky.varioMin = round(ui->varioLimitMin_DSB->value()+10);
|
||||
model->frsky.varioMin = round(ui->varioLimitMin_DSB->value() + 10);
|
||||
emit modified();
|
||||
}
|
||||
|
||||
void TelemetryPanel::on_varioLimitMax_DSB_editingFinished()
|
||||
{
|
||||
model->frsky.varioMax = round(ui->varioLimitMax_DSB->value()-10);
|
||||
model->frsky.varioMax = round(ui->varioLimitMax_DSB->value() - 10);
|
||||
emit modified();
|
||||
}
|
||||
|
||||
void TelemetryPanel::on_varioLimitCenterMin_DSB_editingFinished()
|
||||
{
|
||||
if (!lock) {
|
||||
if (ui->varioLimitCenterMin_DSB->value()>ui->varioLimitCenterMax_DSB->value()) {
|
||||
if (ui->varioLimitCenterMin_DSB->value() > ui->varioLimitCenterMax_DSB->value()) {
|
||||
ui->varioLimitCenterMax_DSB->setValue(ui->varioLimitCenterMin_DSB->value());
|
||||
}
|
||||
model->frsky.varioCenterMin = round((ui->varioLimitCenterMin_DSB->value()+0.5)*10);
|
||||
model->frsky.varioCenterMin = round((ui->varioLimitCenterMin_DSB->value() + 0.5) * 10);
|
||||
emit modified();
|
||||
}
|
||||
}
|
||||
@@ -886,10 +938,10 @@ void TelemetryPanel::on_varioLimitCenterMin_DSB_editingFinished()
|
||||
void TelemetryPanel::on_varioLimitCenterMax_DSB_editingFinished()
|
||||
{
|
||||
if (!lock) {
|
||||
if (ui->varioLimitCenterMin_DSB->value()>ui->varioLimitCenterMax_DSB->value()) {
|
||||
if (ui->varioLimitCenterMin_DSB->value() > ui->varioLimitCenterMax_DSB->value()) {
|
||||
ui->varioLimitCenterMax_DSB->setValue(ui->varioLimitCenterMin_DSB->value());
|
||||
}
|
||||
model->frsky.varioCenterMax = round((ui->varioLimitCenterMax_DSB->value()-0.5)*10);
|
||||
model->frsky.varioCenterMax = round((ui->varioLimitCenterMax_DSB->value() - 0.5) * 10);
|
||||
emit modified();
|
||||
}
|
||||
}
|
||||
@@ -917,8 +969,56 @@ void TelemetryPanel::on_clearAllSensors()
|
||||
{
|
||||
for (int i = 0; i < CPN_MAX_SENSORS; i++) {
|
||||
model->sensorData[i].clear();
|
||||
model->updateAllReferences(ModelData::REF_UPD_TYPE_SENSOR, ModelData::REF_UPD_ACT_CLEAR, i);
|
||||
}
|
||||
|
||||
update();
|
||||
emit modified();
|
||||
}
|
||||
|
||||
void TelemetryPanel::on_insertSensor(int selectedIndex)
|
||||
{
|
||||
memmove(&model->sensorData[selectedIndex + 1], &model->sensorData[selectedIndex], (CPN_MAX_SENSORS - (selectedIndex + 1)) * sizeof(SensorData));
|
||||
model->sensorData[selectedIndex].clear();
|
||||
model->updateAllReferences(ModelData::REF_UPD_TYPE_SENSOR, ModelData::REF_UPD_ACT_SHIFT, selectedIndex, 0, 1);
|
||||
|
||||
update();
|
||||
emit modified();
|
||||
}
|
||||
|
||||
void TelemetryPanel::on_deleteSensor(int selectedIndex)
|
||||
{
|
||||
if (QMessageBox::question(this, CPN_STR_APP_NAME, tr("Delete Sensor. Are you sure?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
|
||||
return;
|
||||
|
||||
memmove(&model->sensorData[selectedIndex], &model->sensorData[selectedIndex + 1], (CPN_MAX_SENSORS - (selectedIndex + 1)) * sizeof(SensorData));
|
||||
model->sensorData[CPN_MAX_SENSORS - 1].clear();
|
||||
model->updateAllReferences(ModelData::REF_UPD_TYPE_SENSOR, ModelData::REF_UPD_ACT_SHIFT, selectedIndex, 0, -1);
|
||||
|
||||
update();
|
||||
emit modified();
|
||||
}
|
||||
|
||||
void TelemetryPanel::on_moveUpSensor(int selectedIndex)
|
||||
{
|
||||
swapData(selectedIndex, selectedIndex - 1);
|
||||
}
|
||||
|
||||
void TelemetryPanel::on_moveDownSensor(int selectedIndex)
|
||||
{
|
||||
swapData(selectedIndex, selectedIndex + 1);
|
||||
}
|
||||
|
||||
void TelemetryPanel::swapData(int idx1, int idx2)
|
||||
{
|
||||
if ((idx1 != idx2) && (!model->sensorData[idx1].isEmpty() || !model->sensorData[idx2].isEmpty())) {
|
||||
SensorData sdtmp = model->sensorData[idx2];
|
||||
SensorData *sd1 = &model->sensorData[idx1];
|
||||
SensorData *sd2 = &model->sensorData[idx2];
|
||||
memcpy(sd2, sd1, sizeof(SensorData));
|
||||
memcpy(sd1, &sdtmp, sizeof(SensorData));
|
||||
model->updateAllReferences(ModelData::REF_UPD_TYPE_SENSOR, ModelData::REF_UPD_ACT_SWAP, idx1, idx2);
|
||||
update();
|
||||
emit modified();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user