[Companion] Updates to use new RawSource data models in UI.

This commit is contained in:
Max Paperno
2018-07-12 13:20:06 -04:00
parent 3b8d177861
commit ed255ce1c3
12 changed files with 105 additions and 193 deletions
-79
View File
@@ -465,85 +465,6 @@ void Helpers::getFileComboBoxValue(QComboBox * b, char * dest, int length)
} }
} }
void Helpers::addRawSourceItems(QStandardItemModel * itemModel, const RawSourceType & type, int count, const GeneralSettings * const generalSettings,
const ModelData * const model, const int start)
{
for (int i = start; i < start + count; i++) {
RawSource src = RawSource(type, i);
if (!src.isAvailable(model, generalSettings, getCurrentBoard()))
continue;
QStandardItem * modelItem = new QStandardItem(src.toString(model, generalSettings));
modelItem->setData(src.toValue(), Qt::UserRole);
itemModel->appendRow(modelItem);
}
}
QStandardItemModel * Helpers::getRawSourceItemModel(const GeneralSettings * const generalSettings, const ModelData * const model, unsigned int flags)
{
QStandardItemModel * itemModel = new QStandardItemModel();
Boards board = Boards(getCurrentBoard());
Firmware * fw = getCurrentFirmware();
if (flags & POPULATE_NONE) {
addRawSourceItems(itemModel, SOURCE_TYPE_NONE, 1, generalSettings, model);
}
if (flags & POPULATE_SCRIPT_OUTPUTS) {
for (int i=0; i < getCurrentFirmware()->getCapability(LuaScripts); i++) {
addRawSourceItems(itemModel, SOURCE_TYPE_LUA_OUTPUT, fw->getCapability(LuaOutputsPerScript), generalSettings, model, i * 16);
}
}
if (model && (flags & POPULATE_VIRTUAL_INPUTS)) {
addRawSourceItems(itemModel, SOURCE_TYPE_VIRTUAL_INPUT, fw->getCapability(VirtualInputs), generalSettings, model);
}
if (flags & POPULATE_SOURCES) {
int totalSources = CPN_MAX_STICKS + board.getCapability(Board::Pots) + board.getCapability(Board::Sliders) + board.getCapability(Board::MouseAnalogs);
addRawSourceItems(itemModel, SOURCE_TYPE_STICK, totalSources, generalSettings, model);
addRawSourceItems(itemModel, SOURCE_TYPE_ROTARY_ENCODER, fw->getCapability(RotaryEncoders), generalSettings, model);
}
if (flags & POPULATE_TRIMS) {
addRawSourceItems(itemModel, SOURCE_TYPE_TRIM, board.getCapability(Board::NumTrims), generalSettings, model);
}
if (flags & POPULATE_SOURCES) {
addRawSourceItems(itemModel, SOURCE_TYPE_MAX, 1, generalSettings, model);
}
if (flags & POPULATE_SWITCHES) {
addRawSourceItems(itemModel, SOURCE_TYPE_SWITCH, board.getCapability(Board::Switches), generalSettings, model);
addRawSourceItems(itemModel, SOURCE_TYPE_CUSTOM_SWITCH, fw->getCapability(LogicalSwitches), generalSettings, model);
}
if (flags & POPULATE_SOURCES) {
addRawSourceItems(itemModel, SOURCE_TYPE_CYC, CPN_MAX_CYC, generalSettings, model);
addRawSourceItems(itemModel, SOURCE_TYPE_PPM, fw->getCapability(TrainerInputs), generalSettings, model);
addRawSourceItems(itemModel, SOURCE_TYPE_CH, fw->getCapability(Outputs), generalSettings, model);
}
if (flags & POPULATE_TELEMETRY) {
int count = 0;
if (IS_ARM(board.getBoardType())) {
addRawSourceItems(itemModel, SOURCE_TYPE_SPECIAL, 5, generalSettings, model);
count = CPN_MAX_SENSORS * 3;
}
else {
count = ((flags & POPULATE_TELEMETRYEXT) ? TELEMETRY_SOURCES_STATUS_COUNT : TELEMETRY_SOURCES_COUNT);
}
if (model && count)
addRawSourceItems(itemModel, SOURCE_TYPE_TELEMETRY, count, generalSettings, model);
}
if (flags & POPULATE_GVARS) {
addRawSourceItems(itemModel, SOURCE_TYPE_GVAR, fw->getCapability(Gvars), generalSettings, model);
}
return itemModel;
}
void Helpers::exportAppSettings(QWidget * dlgParent) void Helpers::exportAppSettings(QWidget * dlgParent)
{ {
static QString lastExpFile = CPN_SETTINGS_INI_PATH.arg(QDateTime::currentDateTime().toString("dd-MMM-yy")); static QString lastExpFile = CPN_SETTINGS_INI_PATH.arg(QDateTime::currentDateTime().toString("dd-MMM-yy"));
-18
View File
@@ -117,26 +117,8 @@ class CurveGroup : public QObject {
int lastType; int lastType;
}; };
#define POPULATE_NONE (1<<0)
#define POPULATE_SOURCES (1<<1)
#define POPULATE_TRIMS (1<<2)
#define POPULATE_SWITCHES (1<<3)
#define POPULATE_GVARS (1<<4)
#define POPULATE_TELEMETRY (1<<5)
#define POPULATE_TELEMETRYEXT (1<<6)
#define POPULATE_VIRTUAL_INPUTS (1<<7)
#define POPULATE_SCRIPT_OUTPUTS (1<<8)
#define GVARS_VARIANT 0x0001
#define FRSKY_VARIANT 0x0002
namespace Helpers namespace Helpers
{ {
void addRawSourceItems(QStandardItemModel * itemModel, const RawSourceType & type, int count, const GeneralSettings * const generalSettings = NULL,
const ModelData * const model = NULL, const int start = 0);
QStandardItemModel * getRawSourceItemModel(const GeneralSettings * const generalSettings = NULL, const ModelData * const model = NULL, unsigned int flags = 0);
void populateGvarUseCB(QComboBox *b, unsigned int phase); void populateGvarUseCB(QComboBox *b, unsigned int phase);
void populateGVCB(QComboBox & b, int value, const ModelData & model); void populateGVCB(QComboBox & b, int value, const ModelData & model);
QString getAdjustmentString(int16_t val, const ModelData * model = NULL, bool sign = false); QString getAdjustmentString(int16_t val, const ModelData * model = NULL, bool sign = false);
+14 -24
View File
@@ -20,6 +20,7 @@
#include "customfunctions.h" #include "customfunctions.h"
#include "switchitemmodel.h" #include "switchitemmodel.h"
#include "rawsourceitemmodel.h"
#include "helpers.h" #include "helpers.h"
#include "appdata.h" #include "appdata.h"
@@ -69,9 +70,6 @@ void RepeatComboBox::update()
CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, GeneralSettings & generalSettings, Firmware * firmware): CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, GeneralSettings & generalSettings, Firmware * firmware):
GenericPanel(parent, model, generalSettings, firmware), GenericPanel(parent, model, generalSettings, firmware),
functions(model ? model->customFn : generalSettings.customFn), functions(model ? model->customFn : generalSettings.customFn),
rawSwitchItemModel(NULL),
rawSrcInputsItemModel(NULL),
rawSrcAllItemModel(NULL),
mediaPlayerCurrent(-1), mediaPlayerCurrent(-1),
mediaPlayer(NULL) mediaPlayer(NULL)
{ {
@@ -79,7 +77,10 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
lock = true; lock = true;
int num_fsw = model ? firmware->getCapability(CustomFunctions) : firmware->getCapability(GlobalFunctions); int num_fsw = model ? firmware->getCapability(CustomFunctions) : firmware->getCapability(GlobalFunctions);
setDataModels(); rawSwitchItemModel = new RawSwitchFilterItemModel(&generalSettings, model, model ? SpecialFunctionsContext : GlobalFunctionsContext);
rawSrcAllItemModel = new RawSourceFilterItemModel(&generalSettings, model, this);
rawSrcInputsItemModel = new RawSourceFilterItemModel(rawSrcAllItemModel->sourceModel(), RawSource::InputSourceGroups, this);
rawSrcGVarsItemModel = new RawSourceFilterItemModel(rawSrcAllItemModel->sourceModel(), RawSource::GVarsGroup, this);
if (!firmware->getCapability(VoicesAsNumbers)) { if (!firmware->getCapability(VoicesAsNumbers)) {
tracksSet = getFilesSet(getSoundsPath(generalSettings), QStringList() << "*.wav" << "*.WAV", firmware->getCapability(VoicesMaxLength)); tracksSet = getFilesSet(getSoundsPath(generalSettings), QStringList() << "*.wav" << "*.WAV", firmware->getCapability(VoicesMaxLength));
@@ -253,24 +254,13 @@ CustomFunctionsPanel::~CustomFunctionsPanel()
stopSound(mediaPlayerCurrent); stopSound(mediaPlayerCurrent);
} }
void CustomFunctionsPanel::setDataModels() void CustomFunctionsPanel::updateDataModels()
{ {
if (rawSwitchItemModel) const bool oldLock = lock;
rawSwitchItemModel->update(); lock = true;
else rawSwitchItemModel->update();
rawSwitchItemModel = new RawSwitchFilterItemModel(&generalSettings, model, model ? SpecialFunctionsContext : GlobalFunctionsContext); rawSrcAllItemModel->update();
lock = oldLock;
// The RawSource item models have to be reloaded on every update(). TODO: convert to filtered model like for RawSwitches
if (rawSrcInputsItemModel)
rawSrcInputsItemModel->deleteLater();
if (rawSrcAllItemModel)
rawSrcAllItemModel->deleteLater();
rawSrcInputsItemModel = Helpers::getRawSourceItemModel(&generalSettings, model, POPULATE_NONE|POPULATE_SOURCES|POPULATE_VIRTUAL_INPUTS|POPULATE_TRIMS|POPULATE_SWITCHES);
rawSrcInputsItemModel->setParent(this);
rawSrcAllItemModel = Helpers::getRawSourceItemModel(&generalSettings, model, POPULATE_NONE|POPULATE_SOURCES|POPULATE_VIRTUAL_INPUTS|POPULATE_SWITCHES|POPULATE_GVARS|POPULATE_TRIMS|POPULATE_TELEMETRY|POPULATE_TELEMETRYEXT|POPULATE_SCRIPT_OUTPUTS);
rawSrcAllItemModel->setParent(this);
} }
void CustomFunctionsPanel::onMediaPlayerStateChanged(QMediaPlayer::State state) void CustomFunctionsPanel::onMediaPlayerStateChanged(QMediaPlayer::State state)
@@ -391,6 +381,7 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
unsigned int widgetsMask = 0; unsigned int widgetsMask = 0;
if (modified) { if (modified) {
const bool wasEmpty = cfn.isEmpty();
cfn.swtch = RawSwitch(fswtchSwtch[i]->currentData().toInt()); cfn.swtch = RawSwitch(fswtchSwtch[i]->currentData().toInt());
cfn.func = func; cfn.func = func;
cfn.enabled = fswtchEnable[i]->isChecked(); cfn.enabled = fswtchEnable[i]->isChecked();
@@ -603,8 +594,7 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
void CustomFunctionsPanel::update() void CustomFunctionsPanel::update()
{ {
setDataModels(); updateDataModels();
lock = true; lock = true;
int num_fsw = model ? firmware->getCapability(CustomFunctions) : firmware->getCapability(GlobalFunctions); int num_fsw = model ? firmware->getCapability(CustomFunctions) : firmware->getCapability(GlobalFunctions);
for (int i=0; i<num_fsw; i++) { for (int i=0; i<num_fsw; i++) {
@@ -749,7 +739,7 @@ void CustomFunctionsPanel::populateFuncParamCB(QComboBox *b, uint function, unsi
b->setCurrentIndex(b->findData(value)); b->setCurrentIndex(b->findData(value));
break; break;
case 2: case 2:
b->setModel(Helpers::getRawSourceItemModel(&generalSettings, model, POPULATE_GVARS)); b->setModel(rawSrcGVarsItemModel);
b->setCurrentIndex(b->findData(value)); b->setCurrentIndex(b->findData(value));
break; break;
} }
+5 -3
View File
@@ -26,6 +26,7 @@
#include <QMediaPlayer> #include <QMediaPlayer>
class RawSourceFilterItemModel;
class RawSwitchFilterItemModel; class RawSwitchFilterItemModel;
class TimerEdit; class TimerEdit;
@@ -61,7 +62,7 @@ class CustomFunctionsPanel : public GenericPanel
CustomFunctionData * functions; CustomFunctionData * functions;
private slots: private slots:
void setDataModels(); void updateDataModels();
void customFunctionEdited(); void customFunctionEdited();
void functionEdited(); void functionEdited();
void fsw_customContextMenuRequested(QPoint pos); void fsw_customContextMenuRequested(QPoint pos);
@@ -82,8 +83,9 @@ class CustomFunctionsPanel : public GenericPanel
void populateGVmodeCB(QComboBox *b, unsigned int value); void populateGVmodeCB(QComboBox *b, unsigned int value);
void populateFuncParamCB(QComboBox *b, uint function, unsigned int value, unsigned int adjustmode=0); void populateFuncParamCB(QComboBox *b, uint function, unsigned int value, unsigned int adjustmode=0);
RawSwitchFilterItemModel * rawSwitchItemModel; RawSwitchFilterItemModel * rawSwitchItemModel;
QStandardItemModel * rawSrcInputsItemModel; RawSourceFilterItemModel * rawSrcAllItemModel;
QStandardItemModel * rawSrcAllItemModel; RawSourceFilterItemModel * rawSrcInputsItemModel;
RawSourceFilterItemModel * rawSrcGVarsItemModel;
QSet<QString> tracksSet; QSet<QString> tracksSet;
QSet<QString> scriptsSet; QSet<QString> scriptsSet;
+2 -1
View File
@@ -21,6 +21,7 @@
#include "expodialog.h" #include "expodialog.h"
#include "ui_expodialog.h" #include "ui_expodialog.h"
#include "switchitemmodel.h" #include "switchitemmodel.h"
#include "rawsourceitemmodel.h"
#include "helpers.h" #include "helpers.h"
ExpoDialog::ExpoDialog(QWidget *parent, ModelData & model, ExpoData *expoData, GeneralSettings & generalSettings, ExpoDialog::ExpoDialog(QWidget *parent, ModelData & model, ExpoData *expoData, GeneralSettings & generalSettings,
@@ -93,7 +94,7 @@ ExpoDialog::ExpoDialog(QWidget *parent, ModelData & model, ExpoData *expoData, G
if (firmware->getCapability(VirtualInputs)) { if (firmware->getCapability(VirtualInputs)) {
ui->inputName->setMaxLength(firmware->getCapability(InputsLength)); ui->inputName->setMaxLength(firmware->getCapability(InputsLength));
ui->sourceCB->setModel(Helpers::getRawSourceItemModel(&generalSettings, &model, POPULATE_NONE | POPULATE_SOURCES | POPULATE_SWITCHES | POPULATE_TRIMS | POPULATE_TELEMETRY)); ui->sourceCB->setModel(new RawSourceFilterItemModel(&generalSettings, &model, (RawSource::InputSourceGroups & ~RawSource::InputsGroup) | RawSource::TelemGroup, this));
ui->sourceCB->setCurrentIndex(ui->sourceCB->findData(ed->srcRaw.toValue())); ui->sourceCB->setCurrentIndex(ui->sourceCB->findData(ed->srcRaw.toValue()));
ui->sourceCB->removeItem(0); ui->sourceCB->removeItem(0);
ui->inputName->setValidator(new QRegExpValidator(rx, this)); ui->inputName->setValidator(new QRegExpValidator(rx, this));
+9 -10
View File
@@ -21,15 +21,15 @@
#include "heli.h" #include "heli.h"
#include "ui_heli.h" #include "ui_heli.h"
#include "helpers.h" #include "helpers.h"
#include "rawsourceitemmodel.h"
HeliPanel::HeliPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware): HeliPanel::HeliPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware):
ModelPanel(parent, model, generalSettings, firmware), ModelPanel(parent, model, generalSettings, firmware),
ui(new Ui::Heli), ui(new Ui::Heli)
rawSourceItemModel(nullptr)
{ {
ui->setupUi(this); ui->setupUi(this);
setDataModels(); rawSourceItemModel = new RawSourceFilterItemModel(&generalSettings, &model, RawSource::InputSourceGroups, this);
connect(ui->swashType, SIGNAL(currentIndexChanged(int)), this, SLOT(edited())); connect(ui->swashType, SIGNAL(currentIndexChanged(int)), this, SLOT(edited()));
connect(ui->swashRingVal, SIGNAL(editingFinished()), this, SLOT(edited())); connect(ui->swashRingVal, SIGNAL(editingFinished()), this, SLOT(edited()));
@@ -66,19 +66,18 @@ HeliPanel::~HeliPanel()
delete ui; delete ui;
} }
void HeliPanel::setDataModels() void HeliPanel::updateDataModels()
{ {
if (rawSourceItemModel) const bool oldLock = lock;
rawSourceItemModel->deleteLater(); lock = true;
rawSourceItemModel->update();
rawSourceItemModel = Helpers::getRawSourceItemModel(&generalSettings, model, POPULATE_NONE | POPULATE_SOURCES | POPULATE_VIRTUAL_INPUTS | POPULATE_SWITCHES | POPULATE_TRIMS); lock = oldLock;
rawSourceItemModel->setParent(this);
} }
void HeliPanel::update() void HeliPanel::update()
{ {
lock = true; lock = true;
setDataModels(); updateDataModels();
ui->swashType->setCurrentIndex(model->swashRingData.type); ui->swashType->setCurrentIndex(model->swashRingData.type);
ui->swashCollectiveSource->setModel(rawSourceItemModel); ui->swashCollectiveSource->setModel(rawSourceItemModel);
+4 -2
View File
@@ -23,6 +23,8 @@
#include "modeledit.h" #include "modeledit.h"
class RawSourceFilterItemModel;
namespace Ui { namespace Ui {
class Heli; class Heli;
} }
@@ -37,12 +39,12 @@ class HeliPanel : public ModelPanel
void update(); void update();
private slots: private slots:
void setDataModels(); void updateDataModels();
void edited(); void edited();
private: private:
Ui::Heli *ui; Ui::Heli *ui;
QStandardItemModel * rawSourceItemModel; RawSourceFilterItemModel * rawSourceItemModel;
}; };
#endif // _HELI_H_ #endif // _HELI_H_
+18 -13
View File
@@ -20,21 +20,21 @@
#include "logicalswitches.h" #include "logicalswitches.h"
#include "switchitemmodel.h" #include "switchitemmodel.h"
#include "rawsourceitemmodel.h"
#include "helpers.h" #include "helpers.h"
#include <TimerEdit> #include <TimerEdit>
LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware): LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware):
ModelPanel(parent, model, generalSettings, firmware), ModelPanel(parent, model, generalSettings, firmware),
rawSourceItemModel(NULL),
selectedSwitch(0) selectedSwitch(0)
{ {
Stopwatch s1("LogicalSwitchesPanel"); Stopwatch s1("LogicalSwitchesPanel");
int channelsMax = model.getChannelsMax(true);
rawSwitchItemModel = new RawSwitchFilterItemModel(&generalSettings, &model, LogicalSwitchesContext); rawSwitchItemModel = new RawSwitchFilterItemModel(&generalSettings, &model, LogicalSwitchesContext);
setDataModels(); const unsigned srcGroups = firmware->getCapability(GvarsInCS) ? RawSource::AllSourceGroups : (RawSource::AllSourceGroups & ~RawSource::GVarsGroup);
rawSourceItemModel = new RawSourceFilterItemModel(&generalSettings, &model, srcGroups, this);
QStringList headerLabels; QStringList headerLabels;
headerLabels << "#" << tr("Function") << tr("V1") << tr("V2") << tr("AND Switch"); headerLabels << "#" << tr("Function") << tr("V1") << tr("V2") << tr("AND Switch");
@@ -45,6 +45,8 @@ LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model,
s1.report("header"); s1.report("header");
const int channelsMax = model.getChannelsMax(true);
lock = true; lock = true;
for (int i=0; i<firmware->getCapability(LogicalSwitches); i++) { for (int i=0; i<firmware->getCapability(LogicalSwitches); i++) {
// The label // The label
@@ -161,14 +163,13 @@ LogicalSwitchesPanel::~LogicalSwitchesPanel()
{ {
} }
void LogicalSwitchesPanel::setDataModels() void LogicalSwitchesPanel::updateDataModels()
{ {
if (rawSourceItemModel) const bool oldLock = lock;
rawSourceItemModel->deleteLater(); lock = true;
rawSwitchItemModel->update();
int srcFlags = POPULATE_NONE | POPULATE_SOURCES | POPULATE_SCRIPT_OUTPUTS | POPULATE_VIRTUAL_INPUTS | POPULATE_TRIMS | POPULATE_SWITCHES | POPULATE_TELEMETRY | (firmware->getCapability(GvarsInCS) ? POPULATE_GVARS : 0); rawSourceItemModel->update();
rawSourceItemModel = Helpers::getRawSourceItemModel(&generalSettings, model, srcFlags); lock = oldLock;
rawSourceItemModel->setParent(this);
} }
void LogicalSwitchesPanel::functionChanged() void LogicalSwitchesPanel::functionChanged()
@@ -179,6 +180,7 @@ void LogicalSwitchesPanel::functionChanged()
if (model->logicalSw[i].func == newFunc) if (model->logicalSw[i].func == newFunc)
return; return;
const unsigned oldFunc = model->logicalSw[i].func;
CSFunctionFamily oldFuncFamily = model->logicalSw[i].getFunctionFamily(); CSFunctionFamily oldFuncFamily = model->logicalSw[i].getFunctionFamily();
model->logicalSw[i].func = newFunc; model->logicalSw[i].func = newFunc;
CSFunctionFamily newFuncFamily = model->logicalSw[i].getFunctionFamily(); CSFunctionFamily newFuncFamily = model->logicalSw[i].getFunctionFamily();
@@ -194,7 +196,11 @@ void LogicalSwitchesPanel::functionChanged()
model->logicalSw[i].val2 = -129; model->logicalSw[i].val2 = -129;
} }
} }
update(); if (bool(oldFunc) != bool(newFunc))
update();
else
updateLine(i);
emit modified(); emit modified();
} }
@@ -435,7 +441,6 @@ void LogicalSwitchesPanel::updateLine(int i)
cswitchDelay[i]->setValue(model->logicalSw[i].delay/10.0); cswitchDelay[i]->setValue(model->logicalSw[i].delay/10.0);
} }
rawSwitchItemModel->update();
lock = false; lock = false;
} }
@@ -508,7 +513,7 @@ void LogicalSwitchesPanel::populateAndSwitchCB(QComboBox *b)
void LogicalSwitchesPanel::update() void LogicalSwitchesPanel::update()
{ {
setDataModels(); updateDataModels();
for (int i=0; i<firmware->getCapability(LogicalSwitches); i++) { for (int i=0; i<firmware->getCapability(LogicalSwitches); i++) {
updateLine(i); updateLine(i);
} }
+3 -2
View File
@@ -25,6 +25,7 @@
#include "radiodata.h" #include "radiodata.h"
class RawSwitchFilterItemModel; class RawSwitchFilterItemModel;
class RawSourceFilterItemModel;
class TimerEdit; class TimerEdit;
class LogicalSwitchesPanel : public ModelPanel class LogicalSwitchesPanel : public ModelPanel
@@ -38,7 +39,7 @@ class LogicalSwitchesPanel : public ModelPanel
virtual void update(); virtual void update();
private slots: private slots:
void setDataModels(); void updateDataModels();
void functionChanged(); void functionChanged();
void v1Edited(int value); void v1Edited(int value);
void v2Edited(int value); void v2Edited(int value);
@@ -66,7 +67,7 @@ class LogicalSwitchesPanel : public ModelPanel
QComboBox * cswitchSource1[CPN_MAX_LOGICAL_SWITCHES]; QComboBox * cswitchSource1[CPN_MAX_LOGICAL_SWITCHES];
QComboBox * cswitchSource2[CPN_MAX_LOGICAL_SWITCHES]; QComboBox * cswitchSource2[CPN_MAX_LOGICAL_SWITCHES];
RawSwitchFilterItemModel * rawSwitchItemModel; RawSwitchFilterItemModel * rawSwitchItemModel;
QStandardItemModel * rawSourceItemModel; RawSourceFilterItemModel * rawSourceItemModel;
int selectedSwitch; int selectedSwitch;
void populateCSWCB(QComboBox *b); void populateCSWCB(QComboBox *b);
+2 -1
View File
@@ -22,6 +22,7 @@
#include "ui_mixerdialog.h" #include "ui_mixerdialog.h"
#include "radiodata.h" #include "radiodata.h"
#include "switchitemmodel.h" #include "switchitemmodel.h"
#include "rawsourceitemmodel.h"
#include "helpers.h" #include "helpers.h"
MixerDialog::MixerDialog(QWidget *parent, ModelData & model, MixData * mixdata, GeneralSettings & generalSettings, Firmware * firmware) : MixerDialog::MixerDialog(QWidget *parent, ModelData & model, MixData * mixdata, GeneralSettings & generalSettings, Firmware * firmware) :
@@ -43,7 +44,7 @@ MixerDialog::MixerDialog(QWidget *parent, ModelData & model, MixData * mixdata,
this->setWindowTitle(tr("DEST -> %1").arg(RawSource(SOURCE_TYPE_CH, md->destCh-1).toString(&model, &generalSettings))); this->setWindowTitle(tr("DEST -> %1").arg(RawSource(SOURCE_TYPE_CH, md->destCh-1).toString(&model, &generalSettings)));
ui->sourceCB->setModel(Helpers::getRawSourceItemModel(&generalSettings, &model, POPULATE_NONE | POPULATE_SOURCES | POPULATE_SCRIPT_OUTPUTS | POPULATE_VIRTUAL_INPUTS | POPULATE_SWITCHES | POPULATE_TRIMS)); ui->sourceCB->setModel(new RawSourceFilterItemModel(&generalSettings, &model, RawSource::InputSourceGroups | RawSource::ScriptsGroup, this));
ui->sourceCB->setCurrentIndex(ui->sourceCB->findData(md->srcRaw.toValue())); ui->sourceCB->setCurrentIndex(ui->sourceCB->findData(md->srcRaw.toValue()));
ui->sourceCB->removeItem(0); ui->sourceCB->removeItem(0);
+42 -36
View File
@@ -25,6 +25,7 @@
#include "ui_telemetry_sensor.h" #include "ui_telemetry_sensor.h"
#include "helpers.h" #include "helpers.h"
#include "appdata.h" #include "appdata.h"
#include "rawsourceitemmodel.h"
#include <TimerEdit> #include <TimerEdit>
@@ -316,10 +317,11 @@ TelemetryAnalog::~TelemetryAnalog()
/******************************************************/ /******************************************************/
TelemetryCustomScreen::TelemetryCustomScreen(QWidget *parent, ModelData & model, FrSkyScreenData & screen, GeneralSettings & generalSettings, Firmware * firmware): TelemetryCustomScreen::TelemetryCustomScreen(QWidget *parent, ModelData & model, FrSkyScreenData & screen, GeneralSettings & generalSettings, Firmware * firmware, RawSourceFilterItemModel * srcModel):
ModelPanel(parent, model, generalSettings, firmware), ModelPanel(parent, model, generalSettings, firmware),
ui(new Ui::TelemetryCustomScreen), ui(new Ui::TelemetryCustomScreen),
screen(screen) screen(screen),
rawSourceItemModel(srcModel)
{ {
ui->setupUi(this); ui->setupUi(this);
@@ -327,15 +329,17 @@ TelemetryCustomScreen::TelemetryCustomScreen(QWidget *parent, ModelData & model,
for (int c=0; c<firmware->getCapability(TelemetryCustomScreensFieldsPerLine); c++) { for (int c=0; c<firmware->getCapability(TelemetryCustomScreensFieldsPerLine); c++) {
fieldsCB[l][c] = new QComboBox(this); 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(rawSourceItemModel);
ui->screenNumsLayout->addWidget(fieldsCB[l][c], l, c, 1, 1); ui->screenNumsLayout->addWidget(fieldsCB[l][c], l, c, 1, 1);
connect(fieldsCB[l][c], SIGNAL(currentIndexChanged(int)), this, SLOT(customFieldChanged(int))); connect(fieldsCB[l][c], SIGNAL(activated(int)), this, SLOT(customFieldChanged(int)));
} }
} }
for (int l=0; l<4; l++) { for (int l=0; l<4; l++) {
barsCB[l] = new QComboBox(this); barsCB[l] = new QComboBox(this);
barsCB[l]->setProperty("index", l); barsCB[l]->setProperty("index", l);
connect(barsCB[l], SIGNAL(currentIndexChanged(int)), this, SLOT(barSourceChanged(int))); barsCB[l]->setModel(rawSourceItemModel);
connect(barsCB[l], SIGNAL(activated(int)), this, SLOT(barSourceChanged(int)));
ui->screenBarsLayout->addWidget(barsCB[l], l, 0, 1, 1); ui->screenBarsLayout->addWidget(barsCB[l], l, 0, 1, 1);
minSB[l] = new QDoubleSpinBox(this); minSB[l] = new QDoubleSpinBox(this);
@@ -393,19 +397,6 @@ TelemetryCustomScreen::TelemetryCustomScreen(QWidget *parent, ModelData & model,
update(); update();
} }
void TelemetryCustomScreen::populateTelemetrySourceCB(QComboBox * b, RawSource & source, bool last)
{
int flags = POPULATE_NONE | POPULATE_TELEMETRY;
if (IS_ARM(firmware->getBoard())) {
flags |= POPULATE_SOURCES | POPULATE_SCRIPT_OUTPUTS | POPULATE_VIRTUAL_INPUTS | POPULATE_TRIMS | POPULATE_SWITCHES | (firmware->getCapability(GvarsInCS) ? POPULATE_GVARS : 0);
}
else if (last) {
flags |= POPULATE_TELEMETRYEXT;
}
b->setModel(Helpers::getRawSourceItemModel(&generalSettings, model, flags));
b->setCurrentIndex(b->findData(source.toValue()));
}
TelemetryCustomScreen::~TelemetryCustomScreen() TelemetryCustomScreen::~TelemetryCustomScreen()
{ {
delete ui; delete ui;
@@ -421,12 +412,12 @@ void TelemetryCustomScreen::update()
for (int l=0; l<4; l++) { for (int l=0; l<4; l++) {
for (int c=0; c<firmware->getCapability(TelemetryCustomScreensFieldsPerLine); c++) { for (int c=0; c<firmware->getCapability(TelemetryCustomScreensFieldsPerLine); c++) {
populateTelemetrySourceCB(fieldsCB[l][c], screen.body.lines[l].source[c], l==3); 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<4; l++) {
populateTelemetrySourceCB(barsCB[l], screen.body.bars[l].source); barsCB[l]->setCurrentIndex(barsCB[l]->findData(screen.body.bars[l].source.toValue()));
} }
if (screen.type == TELEMETRY_SCREEN_BARS) { if (screen.type == TELEMETRY_SCREEN_BARS) {
@@ -526,24 +517,36 @@ void TelemetryCustomScreen::scriptNameEdited()
void TelemetryCustomScreen::customFieldChanged(int value) void TelemetryCustomScreen::customFieldChanged(int value)
{ {
if (!lock) { if (lock || !sender() || !qobject_cast<QComboBox *>(sender()))
int index = sender()->property("index").toInt(); return;
screen.body.lines[index/256].source[index%256] = RawSource(((QComboBox *)sender())->itemData(value).toInt());
bool ok;
const int index = sender()->property("index").toInt(&ok),
i = index / 256,
m = index % 256;
const RawSource src(qobject_cast<QComboBox *>(sender())->itemData(value).toInt());
if (ok && screen.body.lines[i].source[m].toValue() != src.toValue()) {
screen.body.lines[i].source[m] = src;
emit modified(); emit modified();
} }
} }
void TelemetryCustomScreen::barSourceChanged(int value) void TelemetryCustomScreen::barSourceChanged(int value)
{ {
if (!lock) { if (lock || !sender() || !qobject_cast<QComboBox *>(sender()))
QComboBox * cb = qobject_cast<QComboBox*>(sender()); return;
int index = cb->property("index").toInt();
screen.body.bars[index].source = RawSource(((QComboBox *)sender())->itemData(value).toInt()); bool ok;
screen.body.bars[index].barMin = 0; const int index = sender()->property("index").toInt(&ok);
screen.body.bars[index].barMax = 0; const RawSource src(qobject_cast<QComboBox *>(sender())->itemData(value).toInt());
updateBar(index); if (!ok || screen.body.bars[index].source.toValue() == src.toValue())
emit modified(); return;
}
screen.body.bars[index].source = src;
screen.body.bars[index].barMin = 0;
screen.body.bars[index].barMax = 0;
updateBar(index);
emit modified();
} }
void TelemetryCustomScreen::barMinChanged(double value) void TelemetryCustomScreen::barMinChanged(double value)
@@ -854,11 +857,15 @@ TelemetryPanel::TelemetryPanel(QWidget *parent, ModelData & model, GeneralSettin
ui->topbarGB->hide(); ui->topbarGB->hide();
} }
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); 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; telemetryCustomScreens[i] = tab;
connect(tab, SIGNAL(modified()), this, SLOT(onModified())); connect(tab, &TelemetryCustomScreen::modified, this, &TelemetryPanel::onModified);
connect(this, &TelemetryPanel::updated, tab, &TelemetryCustomScreen::update);
} }
disableMouseScrolling(); disableMouseScrolling();
@@ -891,10 +898,9 @@ void TelemetryPanel::update()
for (int i=0; i<CPN_MAX_SENSORS; ++i) { for (int i=0; i<CPN_MAX_SENSORS; ++i) {
sensorPanels[i]->update(); sensorPanels[i]->update();
} }
for (int i=0; i<firmware->getCapability(TelemetryCustomScreens); i++) {
telemetryCustomScreens[i]->update();
}
} }
emit updated();
} }
void TelemetryPanel::setup() void TelemetryPanel::setup()
+6 -4
View File
@@ -25,6 +25,7 @@
#include "eeprominterface.h" #include "eeprominterface.h"
class AutoComboBox; class AutoComboBox;
class RawSourceFilterItemModel;
class TimerEdit; class TimerEdit;
namespace Ui { namespace Ui {
@@ -72,7 +73,7 @@ class TelemetryCustomScreen: public ModelPanel
Q_OBJECT Q_OBJECT
public: public:
TelemetryCustomScreen(QWidget *parent, ModelData & model, FrSkyScreenData & screen, GeneralSettings & generalSettings, Firmware * firmware); TelemetryCustomScreen(QWidget *parent, ModelData & model, FrSkyScreenData & screen, GeneralSettings & generalSettings, Firmware * firmware, RawSourceFilterItemModel * srcModel);
~TelemetryCustomScreen(); ~TelemetryCustomScreen();
void update(); void update();
@@ -85,13 +86,11 @@ class TelemetryCustomScreen: public ModelPanel
void barMaxChanged(double value); void barMaxChanged(double value);
void barTimeChanged(); void barTimeChanged();
protected:
void populateTelemetrySourceCB(QComboBox * b, RawSource & source, bool last=false);
private: private:
void updateBar(int line); void updateBar(int line);
Ui::TelemetryCustomScreen * ui; Ui::TelemetryCustomScreen * ui;
FrSkyScreenData & screen; FrSkyScreenData & screen;
RawSourceFilterItemModel * rawSourceItemModel;
QComboBox * fieldsCB[4][3]; QComboBox * fieldsCB[4][3];
QComboBox * barsCB[4]; QComboBox * barsCB[4];
QDoubleSpinBox * minSB[4]; QDoubleSpinBox * minSB[4];
@@ -137,6 +136,9 @@ class TelemetryPanel : public ModelPanel
virtual ~TelemetryPanel(); virtual ~TelemetryPanel();
virtual void update(); virtual void update();
signals:
void updated();
private slots: private slots:
void on_telemetryProtocol_currentIndexChanged(int index); void on_telemetryProtocol_currentIndexChanged(int index);
void onModified(); void onModified();