Add basic context menu to telemetry sensors in companion model edit (#7500)
This commit is contained in:
@@ -592,13 +592,28 @@ void TelemetryCustomScreen::barTimeChanged()
|
||||
}
|
||||
}
|
||||
|
||||
TelemetrySensorPanel::TelemetrySensorPanel(QWidget *parent, SensorData & sensor, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware):
|
||||
/******************************************************/
|
||||
|
||||
TelemetrySensorPanel::TelemetrySensorPanel(QWidget *parent, SensorData & sensor, int sensorIndex, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware):
|
||||
ModelPanel(parent, model, generalSettings, firmware),
|
||||
ui(new Ui::TelemetrySensor),
|
||||
sensor(sensor),
|
||||
lock(false)
|
||||
lock(false),
|
||||
sensorIndex(sensorIndex),
|
||||
selectedIndex(0)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->numLabel->setText(tr("TELE%1").arg(sensorIndex + 1));
|
||||
ui->numLabel->setProperty("index", sensorIndex);
|
||||
ui->numLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
QFontMetrics *f = new QFontMetrics(QFont());
|
||||
QSize sz;
|
||||
sz = f->size(Qt::TextSingleLine, "TELE00");
|
||||
ui->numLabel->setMinimumWidth(sz.width());
|
||||
ui->numLabel->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
ui->numLabel->setToolTip(tr("Popup menu available"));
|
||||
ui->numLabel->setMouseTracking(true);
|
||||
connect(ui->numLabel, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(on_customContextMenuRequested(QPoint)));
|
||||
ui->id->setField(sensor.id, this);
|
||||
ui->instance->setField(sensor.instance, this);
|
||||
ui->ratio->setField(sensor.ratio, this);
|
||||
@@ -613,7 +628,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 = 1; i <= 6; 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);
|
||||
@@ -622,6 +637,7 @@ TelemetrySensorPanel::TelemetrySensorPanel(QWidget *parent, SensorData & sensor,
|
||||
ui->source2->setField(sensor.sources[1], this);
|
||||
ui->source3->setField(sensor.sources[2], this);
|
||||
ui->source4->setField(sensor.sources[3], this);
|
||||
ui->prec->setField(sensor.prec, 0, 2, false, "", this);
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -645,7 +661,21 @@ void TelemetrySensorPanel::update()
|
||||
ui->name->setText(sensor.label);
|
||||
ui->type->setCurrentIndex(sensor.type);
|
||||
ui->unit->setCurrentIndex(sensor.unit);
|
||||
ui->prec->setValue(sensor.prec);
|
||||
ui->id->updateValue();
|
||||
ui->instance->updateValue();
|
||||
ui->ratio->updateValue();
|
||||
ui->offset->updateValue();
|
||||
ui->autoOffset->updateValue();
|
||||
ui->filter->updateValue();
|
||||
ui->logs->updateValue();
|
||||
ui->persistent->updateValue();
|
||||
ui->onlyPositive->updateValue();
|
||||
ui->gpsSensor->updateValue();
|
||||
ui->altSensor->updateValue();
|
||||
ui->ampsSensor->updateValue();
|
||||
ui->cellsSensor->updateValue();
|
||||
ui->cellsIndex->updateValue();
|
||||
ui->prec->updateValue();
|
||||
|
||||
if (sensor.type == SensorData::TELEM_TYPE_CALCULATED) {
|
||||
sensor.updateUnit();
|
||||
@@ -825,15 +855,85 @@ void TelemetrySensorPanel::on_unit_currentIndexChanged(int index)
|
||||
}
|
||||
}
|
||||
|
||||
void TelemetrySensorPanel::on_prec_valueChanged(double value)
|
||||
void TelemetrySensorPanel::on_prec_valueChanged()
|
||||
{
|
||||
if (!lock) {
|
||||
sensor.prec = value;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void TelemetrySensorPanel::on_customContextMenuRequested(QPoint pos)
|
||||
{
|
||||
QLabel *label = (QLabel *)sender();
|
||||
selectedIndex = label->property("index").toInt();
|
||||
QPoint globalPos = label->mapToGlobal(pos);
|
||||
|
||||
QMenu contextMenu;
|
||||
contextMenu.addAction(CompanionIcon("copy.png"), tr("Copy"),this,SLOT(cmCopy()));
|
||||
contextMenu.addAction(CompanionIcon("cut.png"), tr("Cut"),this,SLOT(cmCut()));
|
||||
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("clear.png"), tr("Clear All"),this,SLOT(cmClearAll()));
|
||||
|
||||
contextMenu.exec(globalPos);
|
||||
}
|
||||
|
||||
bool TelemetrySensorPanel::hasClipboardData(QByteArray * data) const
|
||||
{
|
||||
const QClipboard * clipboard = QApplication::clipboard();
|
||||
const QMimeData * mimeData = clipboard->mimeData();
|
||||
if (mimeData->hasFormat(MIMETYPE_TELE_SENSOR)) {
|
||||
if (data)
|
||||
data->append(mimeData->data(MIMETYPE_TELE_SENSOR));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void TelemetrySensorPanel::cmCopy()
|
||||
{
|
||||
QByteArray data;
|
||||
data.append((char*)&sensor, sizeof(SensorData));
|
||||
QMimeData *mimeData = new QMimeData;
|
||||
mimeData->setData(MIMETYPE_TELE_SENSOR, data);
|
||||
QApplication::clipboard()->setMimeData(mimeData, QClipboard::Clipboard);
|
||||
}
|
||||
|
||||
void TelemetrySensorPanel::cmCut()
|
||||
{
|
||||
cmCopy();
|
||||
cmClear();
|
||||
}
|
||||
|
||||
void TelemetrySensorPanel::cmPaste()
|
||||
{
|
||||
QByteArray data;
|
||||
if (hasClipboardData(&data)) {
|
||||
memcpy(&sensor, data.constData(), sizeof(SensorData));
|
||||
emit dataModified();
|
||||
emit modified();
|
||||
}
|
||||
}
|
||||
|
||||
void TelemetrySensorPanel::cmClear()
|
||||
{
|
||||
if (QMessageBox::question(this, CPN_STR_APP_NAME, tr("Clear Telemetry Sensor. Are you sure?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
|
||||
return;
|
||||
|
||||
sensor.clear();
|
||||
emit dataModified();
|
||||
emit modified();
|
||||
}
|
||||
|
||||
void TelemetrySensorPanel::cmClearAll()
|
||||
{
|
||||
if (QMessageBox::question(this, CPN_STR_APP_NAME, tr("Clear all Telemetry Sensors. Are you sure?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
|
||||
return;
|
||||
|
||||
emit clearAllSensors();
|
||||
}
|
||||
|
||||
/******************************************************/
|
||||
|
||||
TelemetryPanel::TelemetryPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware):
|
||||
@@ -851,12 +951,13 @@ 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], model, generalSettings, firmware);
|
||||
for (unsigned i= 0; i < CPN_MAX_SENSORS; ++i) {
|
||||
TelemetrySensorPanel * panel = new TelemetrySensorPanel(this, model.sensorData[i], i, 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()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -869,7 +970,7 @@ TelemetryPanel::TelemetryPanel(QWidget *parent, ModelData & model, GeneralSettin
|
||||
ui->A2Layout->addWidget(analogs[1]);
|
||||
connect(analogs[1], SIGNAL(modified()), this, SLOT(onModified()));
|
||||
}
|
||||
|
||||
|
||||
if (IS_TARANIS_X9(firmware->getBoard())) {
|
||||
ui->voltsSource->setField(model.frsky.voltsSource, this);
|
||||
ui->altitudeSource->setField(model.frsky.altitudeSource, this);
|
||||
@@ -881,7 +982,7 @@ TelemetryPanel::TelemetryPanel(QWidget *parent, ModelData & model, GeneralSettin
|
||||
RawSourceFilterItemModel * srcModel = (new RawSourceFilterItemModel(&generalSettings, &model, this));
|
||||
connect(this, &TelemetryPanel::updated, srcModel, &RawSourceFilterItemModel::update);
|
||||
|
||||
for (int i=0; i<firmware->getCapability(TelemetryCustomScreens); i++) {
|
||||
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));
|
||||
telemetryCustomScreens[i] = tab;
|
||||
@@ -963,7 +1064,7 @@ void TelemetryPanel::setup()
|
||||
ui->rssiSourceCB->setField(model->rssiSource, this);
|
||||
ui->rssiSourceCB->show();
|
||||
populateTelemetrySourcesComboBox(ui->rssiSourceCB, model, false);
|
||||
|
||||
|
||||
ui->rssiAlarmWarningCB->hide();
|
||||
ui->rssiAlarmCriticalCB->hide();
|
||||
ui->rssiAlarmWarningLabel->setText(tr("Low Alarm"));
|
||||
@@ -1198,3 +1299,13 @@ void TelemetryPanel::on_mahCount_ChkB_toggled(bool checked)
|
||||
ui->mahCount_SB->setDisabled(!checked);
|
||||
emit modified();
|
||||
}
|
||||
|
||||
void TelemetryPanel::on_clearAllSensors()
|
||||
{
|
||||
for (int i = 0; i < CPN_MAX_SENSORS; i++) {
|
||||
model->sensorData[i].clear();
|
||||
}
|
||||
|
||||
update();
|
||||
emit modified();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user