Merge branch 'bsongis/companion_sensor_switches' into 2.2

This commit is contained in:
Kilrah
2017-08-09 11:37:56 +02:00
19 changed files with 330 additions and 136 deletions
+66 -26
View File
@@ -114,6 +114,23 @@ void getEEPROMZString(char *dst, const char *src, int size)
}
}
QString getElementName(const QString & prefix, unsigned int index, const char * name = NULL, bool padding = false)
{
QString result = prefix;
if (padding)
result += QString("%1").arg(index, 2, 10, QChar('0'));
else
result += QString("%1").arg(index);
if (name) {
QString trimmed = QString(name).trimmed();
if (trimmed.length() > 0) {
result += ":" + QString(name).trimmed();
}
}
return result;
}
float ValToTim(int value)
{
return ((value < -109 ? 129+value : (value < 7 ? (113+value)*5 : (53+value)*10))/10.0);
@@ -508,10 +525,12 @@ QString RawSource::toString(const ModelData * model, const GeneralSettings * con
int genAryIdx = 0;
switch (type) {
case SOURCE_TYPE_VIRTUAL_INPUT:
result = QObject::tr("[I%1]").arg(index+1, 2, 10, QChar('0'));
if (model && model->inputNames[index][0])
result.append(/*":" + */QString(model->inputNames[index]).trimmed());
return result;
{
const char * name = NULL;
if (model)
name = model->inputNames[index];
return getElementName(QCoreApplication::translate("Input", "I"), index + 1, name);
}
case SOURCE_TYPE_LUA_OUTPUT:
return QObject::tr("LUA%1%2").arg(index/16+1).arg(QChar('a'+index%16));
@@ -550,13 +569,15 @@ QString RawSource::toString(const ModelData * model, const GeneralSettings * con
return QObject::tr("CYC%1").arg(index+1);
case SOURCE_TYPE_PPM:
return QObject::tr("TR%1").arg(index+1, 2, 10, QChar('0'));
return getElementName(QCoreApplication::translate("Trainer", "TR"), index + 1);
case SOURCE_TYPE_CH:
result = QObject::tr("CH%1").arg(index+1, 2, 10, QChar('0'));
if (getCurrentFirmware()->getCapability(ChannelsName) && model && model->limitData[index].name[0])
result.append(":" + QString(model->limitData[index].name).trimmed());
return result;
{
const char * name = NULL;
if (getCurrentFirmware()->getCapability(ChannelsName) && model)
name = model->limitData[index].name;
return getElementName(QCoreApplication::translate("Channel", "CH"), index + 1, name);
}
case SOURCE_TYPE_SPECIAL:
return CHECK_IN_ARRAY(special, index);
@@ -564,7 +585,7 @@ QString RawSource::toString(const ModelData * model, const GeneralSettings * con
case SOURCE_TYPE_TELEMETRY:
if (IS_ARM(getCurrentBoard())) {
div_t qr = div(index, 3);
result = model ? QString(model->sensorData[qr.quot].label) : QString("[T%1]").arg(qr.quot+1, 2, 10, QChar('0'));
result = getElementName(QCoreApplication::translate("Telemetry", "TELE"), qr.quot+1, model ? model->sensorData[qr.quot].label : NULL);
if (qr.rem)
result += (qr.rem == 1 ? "-" : "+");
return result;
@@ -574,10 +595,12 @@ QString RawSource::toString(const ModelData * model, const GeneralSettings * con
}
case SOURCE_TYPE_GVAR:
result = QObject::tr("GV%1").arg(index+1, 2, 10, QChar('0'));
if (getCurrentFirmware()->getCapability(GvarsName) && model && model->gvars_names[index][0])
result.append(":" + QString(model->gvars_names[index]).trimmed());
return result;
{
const char * name = NULL;
if (getCurrentFirmware()->getCapability(GvarsName) && model)
name = model->gvars_names[index];
return getElementName(QCoreApplication::translate("Global Variable", "GV"), index + 1, name);
}
default:
return QObject::tr("----");
@@ -622,7 +645,7 @@ bool RawSource::isSlider(int * sliderIndex) const
* RawSwitch
*/
QString RawSwitch::toString(Board::Type board, const GeneralSettings * const generalSettings) const
QString RawSwitch::toString(Board::Type board, const GeneralSettings * const generalSettings, const ModelData * const modelData) const
{
if (board == Board::BOARD_UNKNOWN) {
board = getCurrentBoard();
@@ -634,10 +657,6 @@ QString RawSwitch::toString(Board::Type board, const GeneralSettings * const gen
QString("AIL"), QString("GEA"), QString("TRN")
};
static const QString flightModes[] = {
QObject::tr("FM0"), QObject::tr("FM1"), QObject::tr("FM2"), QObject::tr("FM3"), QObject::tr("FM4"), QObject::tr("FM5"), QObject::tr("FM6"), QObject::tr("FM7"), QObject::tr("FM8")
};
static const QString trimsSwitches[] = {
QObject::tr("RudTrim Left"), QObject::tr("RudTrim Right"),
QObject::tr("EleTrim Down"), QObject::tr("EleTrim Up"),
@@ -662,7 +681,7 @@ QString RawSwitch::toString(Board::Type board, const GeneralSettings * const gen
<< CPN_STR_SW_INDICATOR_DN;
if (index < 0) {
return CPN_STR_SW_INDICATOR_REV % RawSwitch(type, -index).toString(board, generalSettings);
return CPN_STR_SW_INDICATOR_REV % RawSwitch(type, -index).toString(board, generalSettings, modelData);
}
else {
QString swName;
@@ -682,7 +701,7 @@ QString RawSwitch::toString(Board::Type board, const GeneralSettings * const gen
}
case SWITCH_TYPE_VIRTUAL:
return QObject::tr("L%1").arg(index, 2, 10, QChar('0'));
return getElementName(QCoreApplication::translate("Logic Switch", "L"), index, NULL, true);
case SWITCH_TYPE_MULTIPOS_POT:
if (!getCurrentFirmware()->getCapability(MultiposPotsPositions))
@@ -710,7 +729,7 @@ QString RawSwitch::toString(Board::Type board, const GeneralSettings * const gen
return QObject::tr("One");
case SWITCH_TYPE_FLIGHT_MODE:
return CHECK_IN_ARRAY(flightModes, index-1);
return getElementName(QCoreApplication::translate("Flight mode", "FM"), index - 1, modelData ? modelData->flightModeData[index-1].name : NULL);
case SWITCH_TYPE_NONE:
return QObject::tr("----");
@@ -718,6 +737,12 @@ QString RawSwitch::toString(Board::Type board, const GeneralSettings * const gen
case SWITCH_TYPE_TIMER_MODE:
return CHECK_IN_ARRAY(timerModes, index);
case SWITCH_TYPE_SENSOR:
return getElementName(QCoreApplication::translate("Telemetry", "TELE"), index, modelData ? modelData->sensorData[index-1].label : NULL);
case SWITCH_TYPE_TELEMETRY:
return QObject::tr("Telemetry");
default:
return QObject::tr("???");
}
@@ -1086,10 +1111,7 @@ bool CurveData::isEmpty() const
QString CurveData::nameToString(const int idx) const
{
QString ret = QCoreApplication::translate("CurveData", "CV%1").arg(idx+1, 2, 10, QChar('0'));
if (name[0])
ret.append(":" + QString(name).trimmed());
return ret;
return getElementName(QCoreApplication::translate("Curve", "CV"), idx + 1, name);
}
QString LimitData::minToString() const
@@ -1745,6 +1767,24 @@ int ModelData::getChannelsMax(bool forceExtendedLimits) const
return 100;
}
bool ModelData::isAvailable(const RawSwitch & swtch) const
{
unsigned index = abs(swtch.index) - 1;
if (swtch.type == SWITCH_TYPE_VIRTUAL) {
return logicalSw[index].func != LS_FN_OFF;
}
else if (swtch.type == SWITCH_TYPE_FLIGHT_MODE) {
return index == 0 || flightModeData[index].swtch.type != SWITCH_TYPE_NONE;
}
else if (swtch.type == SWITCH_TYPE_SENSOR) {
return strlen(sensorData[index].label) > 0;
}
else {
return true;
}
}
QList<EEPROMInterface *> eepromInterfaces;
void unregisterEEpromInterfaces()
@@ -133,6 +133,7 @@ class SwitchesConversionTable: public ConversionTable {
addConversion(RawSwitch(SWITCH_TYPE_OFF), -val+offset);
addConversion(RawSwitch(SWITCH_TYPE_ON), val++);
if (version >= 216) {
addConversion(RawSwitch(SWITCH_TYPE_ONE, -1), -val+offset);
addConversion(RawSwitch(SWITCH_TYPE_ONE, 1), val++);
@@ -144,6 +145,15 @@ class SwitchesConversionTable: public ConversionTable {
}
}
if (IS_ARM(board) && version >= 218) {
addConversion(RawSwitch(SWITCH_TYPE_TELEMETRY, -1), -val+offset);
addConversion(RawSwitch(SWITCH_TYPE_TELEMETRY, 1), val++);
for (int i=1; i<=CPN_MAX_SENSORS; i++) {
addConversion(RawSwitch(SWITCH_TYPE_SENSOR, -i), -val+offset);
addConversion(RawSwitch(SWITCH_TYPE_SENSOR, i), val++);
}
}
if (version < 216) {
// previous "moment" switches
for (int i=1; i<=MAX_SWITCHES_POSITION(board, version); i++) {
-78
View File
@@ -404,84 +404,6 @@ void Helpers::getFileComboBoxValue(QComboBox * b, char * dest, int length)
}
}
void Helpers::addRawSwitchItems(QStandardItemModel * itemModel, const RawSwitchType & type, int count, const GeneralSettings * const generalSettings)
{
// Most RawSwitch() indices are one-based (vs. typical zero); these are exceptions to the rule:
const static QVector<int> rawSwitchIndexBaseZeroTypes = QVector<int>() << SWITCH_TYPE_NONE << SWITCH_TYPE_ON << SWITCH_TYPE_OFF << SWITCH_TYPE_TIMER_MODE;
int rawIdxAdj = 0;
const Board::Type board = getCurrentBoard();
int i = (count < 0 ? count : 1);
const int maxCount = (i < 0 ? 0 : count + i);
// handle exceptions in RawSwitch() index values
if (rawSwitchIndexBaseZeroTypes.contains(type))
rawIdxAdj = -1;
for ( ; i < maxCount; ++i) {
if (generalSettings) {
if (type == SWITCH_TYPE_SWITCH && IS_HORUS_OR_TARANIS(board) && !generalSettings->switchPositionAllowedTaranis(abs(i)))
continue;
if (type == SWITCH_TYPE_MULTIPOS_POT) {
int pot = div(abs(i) - 1, getCurrentFirmware()->getCapability(MultiposPotsPositions)).quot;
if (!generalSettings->isPotAvailable(pot) || generalSettings->potConfig[pot] != Board::POT_MULTIPOS_SWITCH)
continue;
}
}
RawSwitch rs(type, i + rawIdxAdj);
QStandardItem * modelItem = new QStandardItem(rs.toString(board, generalSettings));
modelItem->setData(rs.toValue(), Qt::UserRole);
itemModel->appendRow(modelItem);
}
}
QStandardItemModel * Helpers::getRawSwitchItemModel(const GeneralSettings * const generalSettings, SwitchContext context)
{
QStandardItemModel * itemModel = new QStandardItemModel();
Boards board = Boards(getCurrentBoard());
Board::Type btype = board.getBoardType();
Firmware * fw = getCurrentFirmware();
// Descending switch direction: NOT (!) switches
if (context != MixesContext && context != GlobalFunctionsContext && IS_ARM(btype)) {
addRawSwitchItems(itemModel, SWITCH_TYPE_FLIGHT_MODE, -fw->getCapability(FlightModes), generalSettings);
}
if (context != GlobalFunctionsContext) {
addRawSwitchItems(itemModel, SWITCH_TYPE_VIRTUAL, -fw->getCapability(LogicalSwitches), generalSettings);
}
addRawSwitchItems(itemModel, SWITCH_TYPE_ROTARY_ENCODER, -fw->getCapability(RotaryEncoders), generalSettings);
addRawSwitchItems(itemModel, SWITCH_TYPE_TRIM, -board.getCapability(Board::NumTrimSwitches), generalSettings);
addRawSwitchItems(itemModel, SWITCH_TYPE_MULTIPOS_POT, -(fw->getCapability(MultiposPots) * fw->getCapability(MultiposPotsPositions)), generalSettings);
addRawSwitchItems(itemModel, SWITCH_TYPE_SWITCH, -board.getCapability(Board::SwitchPositions), generalSettings);
// Ascending switch direction (including zero)
if (context == TimersContext) {
addRawSwitchItems(itemModel, SWITCH_TYPE_TIMER_MODE, 5, generalSettings);
}
else {
addRawSwitchItems(itemModel, SWITCH_TYPE_NONE, 1);
}
addRawSwitchItems(itemModel, SWITCH_TYPE_SWITCH, board.getCapability(Board::SwitchPositions), generalSettings);
addRawSwitchItems(itemModel, SWITCH_TYPE_MULTIPOS_POT, fw->getCapability(MultiposPots) * fw->getCapability(MultiposPotsPositions), generalSettings);
addRawSwitchItems(itemModel, SWITCH_TYPE_TRIM, board.getCapability(Board::NumTrimSwitches), generalSettings);
addRawSwitchItems(itemModel, SWITCH_TYPE_ROTARY_ENCODER, fw->getCapability(RotaryEncoders), generalSettings);
if (context != GlobalFunctionsContext) {
addRawSwitchItems(itemModel, SWITCH_TYPE_VIRTUAL, fw->getCapability(LogicalSwitches), generalSettings);
}
if (context != MixesContext && context != GlobalFunctionsContext && IS_ARM(btype)) {
addRawSwitchItems(itemModel, SWITCH_TYPE_FLIGHT_MODE, fw->getCapability(FlightModes), generalSettings);
}
if (context == SpecialFunctionsContext || context == GlobalFunctionsContext) {
addRawSwitchItems(itemModel, SWITCH_TYPE_ON, 1);
addRawSwitchItems(itemModel, SWITCH_TYPE_ONE, 1);
}
return itemModel;
}
void Helpers::addRawSourceItems(QStandardItemModel * itemModel, const RawSourceType & type, int count, const GeneralSettings * const generalSettings,
const ModelData * const model, const int start, const QList<int> exclude)
{
-12
View File
@@ -129,18 +129,6 @@ class CurveGroup : public QObject {
namespace Helpers
{
enum SwitchContext
{
LogicalSwitchesContext,
SpecialFunctionsContext,
GlobalFunctionsContext,
TimersContext,
MixesContext
};
void addRawSwitchItems(QStandardItemModel * itemModel, const RawSwitchType & type, int count, const GeneralSettings * const generalSettings = NULL);
QStandardItemModel * getRawSwitchItemModel(const GeneralSettings * const generalSettings = NULL, SwitchContext context = LogicalSwitchesContext);
void addRawSourceItems(QStandardItemModel * itemModel, const RawSourceType & type, int count, const GeneralSettings * const generalSettings = NULL,
const ModelData * const model = NULL, const int start = 0, const QList<int> exclude = QList<int>());
QStandardItemModel * getRawSourceItemModel(const GeneralSettings * const generalSettings = NULL, const ModelData * const model = NULL, unsigned int flags = 0);
+1
View File
@@ -16,6 +16,7 @@ set(modeledit_NAMES
)
set(modeledit_SRCS
switchitemmodel.cpp
flightmodes.cpp
inputs.cpp
mixes.cpp
+3 -1
View File
@@ -143,8 +143,10 @@ Curves::Curves(QWidget * parent, ModelData & model, GeneralSettings & generalSet
palette.setBrush(QPalette::Active, QPalette::ButtonText, QBrush(Qt::white));
#ifdef __APPLE__
edit->setStyleSheet(QString("color: %1;").arg(colors[i].name()));
#else
#elif defined WIN32 || !defined __GNUC__
edit->setStyleSheet(QString("background-color: %1; color: white;").arg(colors[i].name()));
#else
edit->setStyleSheet(QString("background-color: %1; color: white; padding: 2px 3px; border-style: outset; border-width: 1px; border-radius: 2px; border-color: inherit;").arg(colors[i].name()));
#endif
edit->setPalette(palette);
edit->setText(tr("Curve %1").arg(i+1));
+4 -2
View File
@@ -19,6 +19,7 @@
*/
#include "customfunctions.h"
#include "switchitemmodel.h"
#include "helpers.h"
#include "appdata.h"
@@ -73,8 +74,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
lock = true;
int num_fsw = model ? firmware->getCapability(CustomFunctions) : firmware->getCapability(GlobalFunctions);
rawSwitchItemModel = Helpers::getRawSwitchItemModel(&generalSettings, model ? Helpers::SpecialFunctionsContext : Helpers::GlobalFunctionsContext);
rawSwitchItemModel->setParent(this);
rawSwitchItemModel = new RawSwitchFilterItemModel(&generalSettings, model, model ? SpecialFunctionsContext : GlobalFunctionsContext);
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);
@@ -584,6 +584,8 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
void CustomFunctionsPanel::update()
{
rawSwitchItemModel->update();
lock = true;
int num_fsw = model ? firmware->getCapability(CustomFunctions) : firmware->getCapability(GlobalFunctions);
for (int i=0; i<num_fsw; i++) {
+4 -2
View File
@@ -21,9 +21,11 @@
#ifndef _CUSTOMFUNCTIONS_H_
#define _CUSTOMFUNCTIONS_H_
#include <QMediaPlayer>
#include "modeledit.h"
#include "eeprominterface.h"
#include <QMediaPlayer>
class RawSwitchFilterItemModel;
class RepeatComboBox: public QComboBox
{
@@ -74,7 +76,7 @@ class CustomFunctionsPanel : public GenericPanel
void populateFuncCB(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);
QStandardItemModel * rawSwitchItemModel;
RawSwitchFilterItemModel * rawSwitchItemModel;
QStandardItemModel * rawSrcInputsItemModel;
QStandardItemModel * rawSrcAllItemModel;
+2 -1
View File
@@ -20,6 +20,7 @@
#include "expodialog.h"
#include "ui_expodialog.h"
#include "switchitemmodel.h"
#include "helpers.h"
ExpoDialog::ExpoDialog(QWidget *parent, ModelData & model, ExpoData *expoData, GeneralSettings & generalSettings,
@@ -61,7 +62,7 @@ ExpoDialog::ExpoDialog(QWidget *parent, ModelData & model, ExpoData *expoData, G
curveGroup = new CurveGroup(ui->curveTypeCB, ui->curveGVarCB, ui->curveValueCB, ui->curveValueSB, ed->curve, model,
firmware->getCapability(HasInputDiff) ? 0 : (HIDE_DIFF | HIDE_NEGATIVE_CURVES));
ui->switchesCB->setModel(Helpers::getRawSwitchItemModel(&generalSettings, Helpers::MixesContext));
ui->switchesCB->setModel(new RawSwitchFilterItemModel(&generalSettings, &model, MixesContext));
ui->switchesCB->setCurrentIndex(ui->switchesCB->findData(ed->swtch.toValue()));
ui->sideCB->setCurrentIndex(ed->mode-1);
+10 -3
View File
@@ -20,6 +20,7 @@
#include "flightmodes.h"
#include "ui_flightmode.h"
#include "switchitemmodel.h"
#include "helpers.h"
FlightModePanel::FlightModePanel(QWidget * parent, ModelData & model, int phaseIdx, GeneralSettings & generalSettings, Firmware * firmware):
@@ -28,7 +29,8 @@ FlightModePanel::FlightModePanel(QWidget * parent, ModelData & model, int phaseI
phaseIdx(phaseIdx),
phase(model.flightModeData[phaseIdx]),
reCount(firmware->getCapability(RotaryEncoders)),
gvCount(firmware->getCapability(Gvars))
gvCount(firmware->getCapability(Gvars)),
rawSwitchItemModel(NULL)
{
ui->setupUi(this);
@@ -50,7 +52,8 @@ FlightModePanel::FlightModePanel(QWidget * parent, ModelData & model, int phaseI
// Phase switch
if (phaseIdx > 0) {
ui->swtch->setModel(Helpers::getRawSwitchItemModel(&generalSettings, Helpers::MixesContext));
rawSwitchItemModel = new RawSwitchFilterItemModel(&generalSettings, &model, MixesContext);
ui->swtch->setModel(rawSwitchItemModel);
ui->swtch->setCurrentIndex(ui->swtch->findData(phase.swtch.toValue()));
connect(ui->swtch, SIGNAL(currentIndexChanged(int)), this, SLOT(phaseSwitch_currentIndexChanged(int)));
}
@@ -228,6 +231,10 @@ FlightModePanel::~FlightModePanel()
void FlightModePanel::update()
{
if (rawSwitchItemModel) {
rawSwitchItemModel->update();
}
ui->name->setText(phase.name);
int scale = firmware->getCapability(SlowScale);
@@ -524,7 +531,7 @@ FlightModesPanel::FlightModesPanel(QWidget * parent, ModelData & model, GeneralS
QGridLayout * gridLayout = new QGridLayout(this);
tabWidget = new QTabWidget(this);
for (int i=0; i<modesCount; i++) {
FlightModePanel *tab = new FlightModePanel(tabWidget, model, i, generalSettings, firmware);
FlightModePanel * tab = new FlightModePanel(tabWidget, model, i, generalSettings, firmware);
tab->setProperty("index", i);
panels << tab;
connect(tab, SIGNAL(modified()), this, SLOT(onPhaseModified()));
+3
View File
@@ -24,6 +24,8 @@
#include "modeledit.h"
#include "eeprominterface.h"
class RawSwitchFilterItemModel;
namespace Ui {
class FlightMode;
}
@@ -74,6 +76,7 @@ class FlightModePanel : public ModelPanel
QVector<QComboBox *> trimsUse;
QVector<QSpinBox *> trimsValue;
QVector<QSlider *> trimsSlider;
RawSwitchFilterItemModel * rawSwitchItemModel;
void trimUpdate(unsigned int trim);
+2 -2
View File
@@ -19,6 +19,7 @@
*/
#include "logicalswitches.h"
#include "switchitemmodel.h"
#include "helpers.h"
LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware):
@@ -28,8 +29,7 @@ LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model,
Stopwatch s1("LogicalSwitchesPanel");
int channelsMax = model.getChannelsMax(true);
rawSwitchItemModel = Helpers::getRawSwitchItemModel(&generalSettings, Helpers::LogicalSwitchesContext);
rawSwitchItemModel->setParent(this);
rawSwitchItemModel = new RawSwitchFilterItemModel(&generalSettings, &model, LogicalSwitchesContext);
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 = Helpers::getRawSourceItemModel(&generalSettings, &model, srcFlags);
rawSourceItemModel->setParent(this);
+4 -2
View File
@@ -22,7 +22,9 @@
#define _LOGICALSWITCHES_H_
#include "modeledit.h"
#include "eeprominterface.h"
#include "radiodata.h"
class RawSwitchFilterItemModel;
class LogicalSwitchesPanel : public ModelPanel
{
@@ -58,7 +60,7 @@ class LogicalSwitchesPanel : public ModelPanel
QDoubleSpinBox * cswitchDelay[CPN_MAX_LOGICAL_SWITCHES];
QComboBox * cswitchSource1[CPN_MAX_LOGICAL_SWITCHES];
QComboBox * cswitchSource2[CPN_MAX_LOGICAL_SWITCHES];
QStandardItemModel * rawSwitchItemModel;
RawSwitchFilterItemModel * rawSwitchItemModel;
QStandardItemModel * rawSourceItemModel;
void setSwitchWidgetVisibility(int i);
int selectedSwitch;
+4 -3
View File
@@ -20,10 +20,11 @@
#include "mixerdialog.h"
#include "ui_mixerdialog.h"
#include "eeprominterface.h"
#include "radiodata.h"
#include "switchitemmodel.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) :
QDialog(parent),
ui(new Ui::MixerDialog),
model(model),
@@ -103,7 +104,7 @@ MixerDialog::MixerDialog(QWidget *parent, ModelData & model, MixData *mixdata, G
}
}
ui->switchesCB->setModel(Helpers::getRawSwitchItemModel(&generalSettings, Helpers::MixesContext));
ui->switchesCB->setModel(new RawSwitchFilterItemModel(&generalSettings, &model, MixesContext));
ui->switchesCB->setCurrentIndex(ui->switchesCB->findData(md->swtch.toValue()));
ui->warningCB->setCurrentIndex(md->mixWarn);
ui->mltpxCB->setCurrentIndex(md->mltpx);
+5 -1
View File
@@ -22,6 +22,7 @@
#include "ui_setup.h"
#include "ui_setup_timer.h"
#include "ui_setup_module.h"
#include "switchitemmodel.h"
#include "helpers.h"
#include "appdata.h"
#include "modelprinter.h"
@@ -50,7 +51,8 @@ TimerPanel::TimerPanel(QWidget *parent, ModelData & model, TimerData & timer, Ge
}
// Mode
ui->mode->setModel(Helpers::getRawSwitchItemModel(&generalSettings, Helpers::TimersContext));
rawSwitchItemModel = new RawSwitchFilterItemModel(&generalSettings, &model, TimersContext);
ui->mode->setModel(rawSwitchItemModel);
ui->mode->setCurrentIndex(ui->mode->findData(timer.mode.toValue()));
if (!firmware->getCapability(PermTimers)) {
@@ -91,6 +93,8 @@ TimerPanel::~TimerPanel()
void TimerPanel::update()
{
rawSwitchItemModel->update();
int hour = timer.val / 3600;
int min = (timer.val - (hour * 3600)) / 60;
int sec = (timer.val - (hour * 3600)) % 60;
+4 -1
View File
@@ -24,6 +24,8 @@
#include "modeledit.h"
#include "eeprominterface.h"
class RawSwitchFilterItemModel;
namespace Ui {
class Setup;
class Timer;
@@ -49,7 +51,8 @@ class TimerPanel : public ModelPanel
private:
TimerData & timer;
Ui::Timer *ui;
Ui::Timer * ui;
RawSwitchFilterItemModel * rawSwitchItemModel;
};
class ModulePanel : public ModelPanel
+144
View File
@@ -0,0 +1,144 @@
/*
* 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.
*/
#include "switchitemmodel.h"
#include "eeprominterface.h"
RawSwitchItemModel::RawSwitchItemModel(const GeneralSettings * const generalSettings, const ModelData * const modelData):
generalSettings(generalSettings),
modelData(modelData)
{
Boards board = Boards(getCurrentBoard());
Board::Type btype = board.getBoardType();
Firmware * fw = getCurrentFirmware();
// Descending switch direction: NOT (!) switches
if (IS_ARM(btype)) {
add(SWITCH_TYPE_SENSOR, -CPN_MAX_SENSORS);
add(SWITCH_TYPE_TELEMETRY, -1);
add(SWITCH_TYPE_FLIGHT_MODE, -fw->getCapability(FlightModes));
}
add(SWITCH_TYPE_VIRTUAL, -fw->getCapability(LogicalSwitches));
add(SWITCH_TYPE_ROTARY_ENCODER, -fw->getCapability(RotaryEncoders));
add(SWITCH_TYPE_TRIM, -board.getCapability(Board::NumTrimSwitches));
add(SWITCH_TYPE_MULTIPOS_POT, -(fw->getCapability(MultiposPots) * fw->getCapability(MultiposPotsPositions)));
add(SWITCH_TYPE_SWITCH, -board.getCapability(Board::SwitchPositions));
// Ascending switch direction (including zero)
add(SWITCH_TYPE_TIMER_MODE, 5);
add(SWITCH_TYPE_NONE, 1);
add(SWITCH_TYPE_SWITCH, board.getCapability(Board::SwitchPositions));
add(SWITCH_TYPE_MULTIPOS_POT, fw->getCapability(MultiposPots) * fw->getCapability(MultiposPotsPositions));
add(SWITCH_TYPE_TRIM, board.getCapability(Board::NumTrimSwitches));
add(SWITCH_TYPE_ROTARY_ENCODER, fw->getCapability(RotaryEncoders));
add(SWITCH_TYPE_VIRTUAL, fw->getCapability(LogicalSwitches));
if (IS_ARM(btype)) {
add(SWITCH_TYPE_FLIGHT_MODE, fw->getCapability(FlightModes));
add(SWITCH_TYPE_TELEMETRY, 1);
add(SWITCH_TYPE_SENSOR, CPN_MAX_SENSORS);
}
add(SWITCH_TYPE_ON, 1);
add(SWITCH_TYPE_ONE, 1);
}
void RawSwitchItemModel::add(const RawSwitchType & type, int count)
{
// Most RawSwitch() indices are one-based (vs. typical zero); these are exceptions to the rule:
const static QVector<int> rawSwitchIndexBaseZeroTypes = QVector<int>() << SWITCH_TYPE_NONE << SWITCH_TYPE_ON << SWITCH_TYPE_OFF << SWITCH_TYPE_TIMER_MODE;
int rawIdxAdj = 0;
const Board::Type board = getCurrentBoard();
int i = (count < 0 ? count : 1);
const int maxCount = (i < 0 ? 0 : count + i);
// handle exceptions in RawSwitch() index values
if (rawSwitchIndexBaseZeroTypes.contains(type))
rawIdxAdj = -1;
for ( ; i < maxCount; ++i) {
if (generalSettings) {
if (type == SWITCH_TYPE_SWITCH && IS_HORUS_OR_TARANIS(board) && !generalSettings->switchPositionAllowedTaranis(abs(i)))
continue;
if (type == SWITCH_TYPE_MULTIPOS_POT) {
int pot = div(abs(i) - 1, getCurrentFirmware()->getCapability(MultiposPotsPositions)).quot;
if (!generalSettings->isPotAvailable(pot) || generalSettings->potConfig[pot] != Board::POT_MULTIPOS_SWITCH)
continue;
}
}
RawSwitch rs(type, i + rawIdxAdj);
QStandardItem * modelItem = new QStandardItem(rs.toString(board, generalSettings, modelData));
modelItem->setData(rs.toValue(), Qt::UserRole);
appendRow(modelItem);
}
}
void RawSwitchItemModel::update()
{
for (int i=0; i<rowCount(); i++) {
QStandardItem * modelItem = item(i, 0);
RawSwitch swtch(modelItem->data(Qt::UserRole).toInt());
modelItem->setText(swtch.toString(getCurrentBoard(), generalSettings, modelData));
}
}
RawSwitchFilterItemModel::RawSwitchFilterItemModel(const GeneralSettings * const generalSettings, const ModelData * const modelData, SwitchContext context):
generalSettings(generalSettings),
modelData(modelData),
context(context),
parent(new RawSwitchItemModel(generalSettings, modelData))
{
setSourceModel(parent);
setDynamicSortFilter(false);
}
bool RawSwitchFilterItemModel::filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const
{
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
RawSwitch swtch(sourceModel()->data(index, Qt::UserRole).toInt());
if (swtch.type == SWITCH_TYPE_FLIGHT_MODE && (context == MixesContext || context == GlobalFunctionsContext))
return false;
if (swtch.type == SWITCH_TYPE_VIRTUAL && context == GlobalFunctionsContext)
return false;
if (swtch.type == SWITCH_TYPE_TIMER_MODE && context != TimersContext)
return false;
if (swtch.type == SWITCH_TYPE_NONE && context == TimersContext)
return false;
if (swtch.type == SWITCH_TYPE_SENSOR && context == GlobalFunctionsContext)
return false;
if ((swtch.type == SWITCH_TYPE_ON || swtch.type == SWITCH_TYPE_ONE) && (context != SpecialFunctionsContext && context != GlobalFunctionsContext))
return false;
if (!modelData->isAvailable(swtch))
return false;
return true;
}
void RawSwitchFilterItemModel::update()
{
parent->update();
invalidate();
}
+58
View File
@@ -0,0 +1,58 @@
/*
* 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.
*/
#include <QStandardItemModel>
#include <QSortFilterProxyModel>
#include "radiodata.h"
enum SwitchContext
{
LogicalSwitchesContext,
SpecialFunctionsContext,
GlobalFunctionsContext,
TimersContext,
MixesContext
};
class RawSwitchItemModel: public QStandardItemModel {
public:
RawSwitchItemModel(const GeneralSettings * const generalSettings, const ModelData * const modelData);
void update();
protected:
void add(const RawSwitchType & type, int count);
const GeneralSettings * generalSettings;
const ModelData * modelData;
};
class RawSwitchFilterItemModel: public QSortFilterProxyModel {
public:
RawSwitchFilterItemModel(const GeneralSettings * const generalSettings = NULL, const ModelData * const modelData = NULL, SwitchContext context = LogicalSwitchesContext);
void update();
protected:
const GeneralSettings * generalSettings;
const ModelData * modelData;
SwitchContext context;
RawSwitchItemModel * parent;
bool filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const override;
};
+6 -2
View File
@@ -250,7 +250,9 @@ enum RawSwitchType {
SWITCH_TYPE_OFF,
SWITCH_TYPE_ONE,
SWITCH_TYPE_FLIGHT_MODE,
SWITCH_TYPE_TIMER_MODE
SWITCH_TYPE_TIMER_MODE,
SWITCH_TYPE_TELEMETRY,
SWITCH_TYPE_SENSOR,
};
class RawSwitch {
@@ -278,7 +280,7 @@ class RawSwitch {
return index >= 0 ? (type * 256 + index) : -(type * 256 - index);
}
QString toString(Board::Type board = Board::BOARD_UNKNOWN, const GeneralSettings * const generalSettings = NULL) const;
QString toString(Board::Type board = Board::BOARD_UNKNOWN, const GeneralSettings * const generalSettings = NULL, const ModelData * const modelData = NULL) const;
bool operator== ( const RawSwitch& other) {
return (this->type == other.type) && (this->index == other.index);
@@ -1110,6 +1112,8 @@ class ModelData {
int getChannelsMax(bool forceExtendedLimits=false) const;
bool isAvailable(const RawSwitch & swtch) const;
protected:
void removeGlobalVar(int & var);
};