chore(cpn): move model edit setup classes to own code files (#5678)
This commit is contained in:
@@ -17,6 +17,9 @@ set(${PROJECT_NAME}_NAMES
|
|||||||
mixerslistwidget
|
mixerslistwidget
|
||||||
modeledit
|
modeledit
|
||||||
modeloptions
|
modeloptions
|
||||||
|
setup_timer
|
||||||
|
setup_module
|
||||||
|
setup_function_switches
|
||||||
setup
|
setup
|
||||||
telemetry
|
telemetry
|
||||||
telemetry_customscreens
|
telemetry_customscreens
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -23,261 +23,16 @@
|
|||||||
|
|
||||||
#include "modeledit.h"
|
#include "modeledit.h"
|
||||||
#include "eeprominterface.h"
|
#include "eeprominterface.h"
|
||||||
#include "compounditemmodels.h"
|
|
||||||
#include "filtereditemmodels.h"
|
#include "filtereditemmodels.h"
|
||||||
|
#include "setup_timer.h"
|
||||||
#include <QSortFilterProxyModel>
|
#include "setup_module.h"
|
||||||
|
#include "setup_function_switches.h"
|
||||||
constexpr char MIMETYPE_TIMER[] = "application/x-companion-timer";
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class Setup;
|
class Setup;
|
||||||
class Timer;
|
|
||||||
class Module;
|
|
||||||
class FunctionSwitches;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class AutoLineEdit;
|
class AutoLineEdit;
|
||||||
class FilteredItemModel;
|
|
||||||
|
|
||||||
class TimerPanel : public ModelPanel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
TimerPanel(QWidget * parent, ModelData & model, TimerData & timer, GeneralSettings & generalSettings, Firmware * firmware,
|
|
||||||
QWidget * prevFocus, FilteredItemModelFactory * panelFilteredModels, CompoundItemModelFactory * panelItemModels);
|
|
||||||
virtual ~TimerPanel();
|
|
||||||
|
|
||||||
virtual void update();
|
|
||||||
QWidget * getLastFocus();
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void onNameChanged();
|
|
||||||
void onItemModelAboutToBeUpdated();
|
|
||||||
void onItemModelUpdateComplete();
|
|
||||||
void onCountdownBeepChanged(int index);
|
|
||||||
void onModeChanged(int index);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void nameChanged();
|
|
||||||
void modeChanged();
|
|
||||||
|
|
||||||
private:
|
|
||||||
TimerData & timer;
|
|
||||||
Ui::Timer * ui;
|
|
||||||
void connectItemModelEvents(const FilteredItemModel * itemModel);
|
|
||||||
int modelsUpdateCnt;
|
|
||||||
};
|
|
||||||
|
|
||||||
class ModulePanel : public ModelPanel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
ModulePanel(QWidget * parent, ModelData & model, ModuleData & module, GeneralSettings & generalSettings, Firmware * firmware, int moduleIdx,
|
|
||||||
FilteredItemModelFactory * panelFilteredItemModels = nullptr, CompoundItemModelFactory * panelItemModels = nullptr);
|
|
||||||
virtual ~ModulePanel();
|
|
||||||
virtual void update();
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void onExtendedLimitsToggled();
|
|
||||||
void onFailsafeModified(unsigned index);
|
|
||||||
void updateTrainerModeItemModel();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void channelsRangeChanged();
|
|
||||||
void failsafeModified(unsigned index);
|
|
||||||
void updateItemModels();
|
|
||||||
void protocolChanged();
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void setupFailsafes();
|
|
||||||
void onProtocolChanged(int index);
|
|
||||||
void on_ppmDelay_editingFinished();
|
|
||||||
void on_channelsCount_editingFinished();
|
|
||||||
void on_channelsStart_editingFinished();
|
|
||||||
void on_ppmPolarity_currentIndexChanged(int index);
|
|
||||||
void on_ppmOutputType_currentIndexChanged(int index);
|
|
||||||
void on_ppmFrameLength_editingFinished();
|
|
||||||
void on_rxNumber_editingFinished();
|
|
||||||
void on_failsafeMode_currentIndexChanged(int value);
|
|
||||||
void onMultiProtocolChanged(int index);
|
|
||||||
void onSubTypeChanged();
|
|
||||||
void on_autoBind_stateChanged(int state);
|
|
||||||
void on_disableChMap_stateChanged(int state);
|
|
||||||
void on_raw12bits_stateChanged(int state);
|
|
||||||
void on_racingMode_stateChanged(int state);
|
|
||||||
void on_disableTelem_stateChanged(int state);
|
|
||||||
void on_lowPower_stateChanged(int state);
|
|
||||||
void on_r9mPower_currentIndexChanged(int index);
|
|
||||||
void setChannelFailsafeValue(const int channel, const int value, quint8 updtSb = 0);
|
|
||||||
void onFailsafeComboIndexChanged(int index);
|
|
||||||
void onFailsafeUsecChanged(int value);
|
|
||||||
void onFailsafePercentChanged(double value);
|
|
||||||
void onFailsafesDisplayValueTypeChanged(int type);
|
|
||||||
void onRfFreqChanged(int freq);
|
|
||||||
void updateFailsafe(unsigned channel);
|
|
||||||
void on_optionValue_valueChanged(int value);
|
|
||||||
void onClearAccessRxClicked();
|
|
||||||
void on_chkOption_stateChanged(int state);
|
|
||||||
void on_cboOption_currentIndexChanged(int value);
|
|
||||||
|
|
||||||
private:
|
|
||||||
enum FailsafeValueDisplayTypes { FAILSAFE_DISPLAY_PERCENT = 1, FAILSAFE_DISPLAY_USEC = 2 };
|
|
||||||
|
|
||||||
struct ChannelFailsafeWidgetsGroup {
|
|
||||||
QLabel * label;
|
|
||||||
QComboBox * combo;
|
|
||||||
QSpinBox * sbUsec;
|
|
||||||
QDoubleSpinBox * sbPercent;
|
|
||||||
};
|
|
||||||
|
|
||||||
ModuleData & module;
|
|
||||||
int moduleIdx;
|
|
||||||
Ui::Module *ui;
|
|
||||||
QMap<int, ChannelFailsafeWidgetsGroup> failsafeGroupsMap;
|
|
||||||
static quint8 failsafesValueDisplayType; // FailsafeValueDisplayTypes
|
|
||||||
void updateFailsafeUI(unsigned channel, quint8 updtSb);
|
|
||||||
FilteredItemModel *trainerModeItemModel;
|
|
||||||
static bool isTrainerModule(int index) { return index < 0; }
|
|
||||||
static bool isInternalModule(int index) { return index == 0; }
|
|
||||||
static bool isExternalModule(int index) { return index > 0; }
|
|
||||||
};
|
|
||||||
|
|
||||||
class FilteredGroupSwitchesModel: public QSortFilterProxyModel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit FilteredGroupSwitchesModel(AbstractItemModel * sourceModel, int group, ModelData * model, int switchcnt) :
|
|
||||||
QSortFilterProxyModel(nullptr),
|
|
||||||
m_group(group),
|
|
||||||
m_switchcnt(switchcnt),
|
|
||||||
m_model(model)
|
|
||||||
{
|
|
||||||
setFilterKeyColumn(0);
|
|
||||||
setDynamicSortFilter(true);
|
|
||||||
setSourceModel(sourceModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit FilteredGroupSwitchesModel(AbstractItemModel * sourceModel) :
|
|
||||||
FilteredGroupSwitchesModel(sourceModel, 0, nullptr, 0) {}
|
|
||||||
virtual ~FilteredGroupSwitchesModel() {};
|
|
||||||
|
|
||||||
void setGroup(int group) { m_group = group; }
|
|
||||||
int getGroup() const { return m_group; }
|
|
||||||
void setSwitchcnt(int n) { m_switchcnt = n; }
|
|
||||||
int getSwitchcnt() const { return m_switchcnt; }
|
|
||||||
void setModel(ModelData* model) { m_model = model; }
|
|
||||||
ModelData* getModel() const { return m_model; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
int m_group = 0;
|
|
||||||
int m_switchcnt = 0;
|
|
||||||
ModelData* m_model = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
class FilteredSwitchGroupsModel: public QSortFilterProxyModel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit FilteredSwitchGroupsModel(AbstractItemModel * sourceModel, int sw, ModelData * model) :
|
|
||||||
QSortFilterProxyModel(nullptr),
|
|
||||||
m_switch(sw),
|
|
||||||
m_model(model)
|
|
||||||
{
|
|
||||||
setFilterKeyColumn(0);
|
|
||||||
setDynamicSortFilter(true);
|
|
||||||
setSourceModel(sourceModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit FilteredSwitchGroupsModel(AbstractItemModel * sourceModel) :
|
|
||||||
FilteredSwitchGroupsModel(sourceModel, 0, nullptr) {}
|
|
||||||
virtual ~FilteredSwitchGroupsModel() {};
|
|
||||||
|
|
||||||
void setSwitch(int group) { m_switch = group; }
|
|
||||||
int getSwitch() const { return m_switch; }
|
|
||||||
void setModel(ModelData* model) { m_model = model; }
|
|
||||||
ModelData* getModel() const { return m_model; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
int m_switch = 0;
|
|
||||||
ModelData* m_model = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
class FilteredSwitchConfigsModel: public QSortFilterProxyModel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit FilteredSwitchConfigsModel(AbstractItemModel * sourceModel, int sw, ModelData * model) :
|
|
||||||
QSortFilterProxyModel(nullptr),
|
|
||||||
m_switch(sw),
|
|
||||||
m_model(model)
|
|
||||||
{
|
|
||||||
setFilterKeyColumn(0);
|
|
||||||
setDynamicSortFilter(true);
|
|
||||||
setSourceModel(sourceModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit FilteredSwitchConfigsModel(AbstractItemModel * sourceModel) :
|
|
||||||
FilteredSwitchConfigsModel(sourceModel, 0, nullptr) {}
|
|
||||||
virtual ~FilteredSwitchConfigsModel() {};
|
|
||||||
|
|
||||||
void setSwitch(int group) { m_switch = group; }
|
|
||||||
int getSwitch() const { return m_switch; }
|
|
||||||
void setModel(ModelData* model) { m_model = model; }
|
|
||||||
ModelData* getModel() const { return m_model; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
int m_switch = 0;
|
|
||||||
ModelData* m_model = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
class FunctionSwitchesPanel : public ModelPanel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
FunctionSwitchesPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware);
|
|
||||||
virtual ~FunctionSwitchesPanel();
|
|
||||||
|
|
||||||
void update();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void updateDataModels();
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void on_nameEditingFinished();
|
|
||||||
void on_configCurrentIndexChanged(int index);
|
|
||||||
void on_startPosnCurrentIndexChanged(int index);
|
|
||||||
void on_groupStartPosnCurrentIndexChanged(int index);
|
|
||||||
void on_groupChanged(int value);
|
|
||||||
void on_alwaysOnGroupChanged(int value);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Ui::FunctionSwitches * ui;
|
|
||||||
QVector<AutoLineEdit *> aleNames;
|
|
||||||
QVector<QComboBox *> cboConfigs;
|
|
||||||
QVector<QComboBox *> cboStartupPosns;
|
|
||||||
QVector<QComboBox *> cboGroups;
|
|
||||||
QVector<QCheckBox *> cbAlwaysOnGroups;
|
|
||||||
QVector<QComboBox *> cboGroupStartupPosns;
|
|
||||||
QVector<FilteredGroupSwitchesModel *> filterGroupSwitches;
|
|
||||||
QVector<FilteredSwitchGroupsModel *> filterSwitchGroups;
|
|
||||||
QVector<FilteredSwitchConfigsModel *> filterSwitchConfigs;
|
|
||||||
int switchcnt;
|
|
||||||
AbstractStaticItemModel *fsConfig;
|
|
||||||
AbstractStaticItemModel *fsGroupStart;
|
|
||||||
};
|
|
||||||
|
|
||||||
class SetupPanel : public ModelPanel
|
class SetupPanel : public ModelPanel
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,323 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) EdgeTX
|
||||||
|
*
|
||||||
|
* Based on code named
|
||||||
|
* opentx - https://github.com/opentx/opentx
|
||||||
|
* 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 "setup_function_switches.h"
|
||||||
|
#include "ui_setup_function_switches.h"
|
||||||
|
#include "namevalidator.h"
|
||||||
|
#include "autolineedit.h"
|
||||||
|
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
|
bool FilteredGroupSwitchesModel::filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const
|
||||||
|
{
|
||||||
|
if (sourceRow == 0) return true;
|
||||||
|
if (sourceRow == m_switchcnt + 1) {
|
||||||
|
if (m_model->getFuncSwitchAlwaysOnGroup(m_group) || m_model->getFuncGroupSwitchCount(m_group, m_switchcnt) == 0)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ((int)m_model->getFuncSwitchGroup(sourceRow - 1) == m_group)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FilteredSwitchGroupsModel::filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const
|
||||||
|
{
|
||||||
|
if (sourceRow == 0) return true;
|
||||||
|
if (m_model->getFuncSwitchConfig(m_switch) == ModelData::FUNC_SWITCH_CONFIG_NONE) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FilteredSwitchConfigsModel::filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const
|
||||||
|
{
|
||||||
|
if (sourceRow == ModelData::FUNC_SWITCH_CONFIG_NONE || sourceRow == ModelData::FUNC_SWITCH_CONFIG_2POS) return true;
|
||||||
|
return !m_model->getFuncSwitchAlwaysOnGroupForSwitch(m_switch);
|
||||||
|
}
|
||||||
|
|
||||||
|
FunctionSwitchesPanel::FunctionSwitchesPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware):
|
||||||
|
ModelPanel(parent, model, generalSettings, firmware),
|
||||||
|
ui(new Ui::FunctionSwitches)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
fsConfig = ModelData::funcSwitchConfigItemModel();
|
||||||
|
AbstractStaticItemModel *fsStart = ModelData::funcSwitchStartItemModel();
|
||||||
|
AbstractStaticItemModel *fsGroups = ModelData::funcSwitchGroupsModel();
|
||||||
|
|
||||||
|
Board::Type board = firmware->getBoard();
|
||||||
|
|
||||||
|
lock = true;
|
||||||
|
|
||||||
|
switchcnt = Boards::getCapability(board, Board::FunctionSwitches);
|
||||||
|
|
||||||
|
fsGroupStart = ModelData::funcSwitchGroupStartSwitchModel(switchcnt);
|
||||||
|
|
||||||
|
for (int i = 0; i < switchcnt; i++) {
|
||||||
|
QLabel * lblSwitchId = new QLabel(this);
|
||||||
|
lblSwitchId->setText(tr("SW%1").arg(i + 1));
|
||||||
|
|
||||||
|
AutoLineEdit * aleName = new AutoLineEdit(this);
|
||||||
|
aleName->setProperty("index", i);
|
||||||
|
aleName->setValidator(new NameValidator(board, this));
|
||||||
|
aleName->setField((char *)model.functionSwitchNames[i], 3);
|
||||||
|
|
||||||
|
QComboBox * cboConfig = new QComboBox(this);
|
||||||
|
cboConfig->setProperty("index", i);
|
||||||
|
auto configFilter = new FilteredSwitchConfigsModel(fsConfig, i, &model);
|
||||||
|
cboConfig->setModel(configFilter);
|
||||||
|
filterSwitchConfigs << configFilter;
|
||||||
|
|
||||||
|
QComboBox * cboStartPosn = new QComboBox(this);
|
||||||
|
cboStartPosn->setProperty("index", i);
|
||||||
|
cboStartPosn->setModel(fsStart);
|
||||||
|
|
||||||
|
QComboBox * cboGroup = new QComboBox(this);
|
||||||
|
cboGroup->setProperty("index", i);
|
||||||
|
auto groupFilter = new FilteredSwitchGroupsModel(fsGroups, i, &model);
|
||||||
|
cboGroup->setModel(groupFilter);
|
||||||
|
filterSwitchGroups << groupFilter;
|
||||||
|
|
||||||
|
int row = 0;
|
||||||
|
int coloffset = 1;
|
||||||
|
ui->gridSwitches->addWidget(lblSwitchId, row++, i + coloffset);
|
||||||
|
ui->gridSwitches->addWidget(aleName, row++, i + coloffset);
|
||||||
|
ui->gridSwitches->addWidget(cboConfig, row++, i + coloffset);
|
||||||
|
ui->gridSwitches->addWidget(cboStartPosn, row++, i + coloffset);
|
||||||
|
ui->gridSwitches->addWidget(cboGroup, row++, i + coloffset);
|
||||||
|
|
||||||
|
connect(aleName, &AutoLineEdit::currentDataChanged, this, &FunctionSwitchesPanel::on_nameEditingFinished);
|
||||||
|
connect(cboConfig, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FunctionSwitchesPanel::on_configCurrentIndexChanged);
|
||||||
|
connect(cboStartPosn, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FunctionSwitchesPanel::on_startPosnCurrentIndexChanged);
|
||||||
|
connect(cboGroup, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FunctionSwitchesPanel::on_groupChanged);
|
||||||
|
|
||||||
|
aleNames << aleName;
|
||||||
|
cboConfigs << cboConfig;
|
||||||
|
cboStartupPosns << cboStartPosn;
|
||||||
|
cboGroups << cboGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i += 1) {
|
||||||
|
QLabel * lblGroupId = new QLabel(this);
|
||||||
|
lblGroupId->setText(tr("Group %1").arg(i + 1));
|
||||||
|
|
||||||
|
QCheckBox * cbAlwaysOnGroup = new QCheckBox(this);
|
||||||
|
cbAlwaysOnGroup->setProperty("index", i);
|
||||||
|
|
||||||
|
QComboBox * cboStartPosn = new QComboBox(this);
|
||||||
|
cboStartPosn->setProperty("index", i);
|
||||||
|
auto filter = new FilteredGroupSwitchesModel(fsGroupStart, i + 1, &model, switchcnt);
|
||||||
|
cboStartPosn->setModel(filter);
|
||||||
|
filterGroupSwitches << filter;
|
||||||
|
|
||||||
|
int row = 0;
|
||||||
|
int coloffset = 1;
|
||||||
|
ui->gridGroups->addWidget(lblGroupId, row++, i + coloffset);
|
||||||
|
ui->gridGroups->addWidget(cbAlwaysOnGroup, row++, i + coloffset);
|
||||||
|
ui->gridGroups->addWidget(cboStartPosn, row++, i + coloffset);
|
||||||
|
|
||||||
|
connect(cbAlwaysOnGroup, &QCheckBox::toggled, this, &FunctionSwitchesPanel::on_alwaysOnGroupChanged);
|
||||||
|
connect(cboStartPosn, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FunctionSwitchesPanel::on_groupStartPosnCurrentIndexChanged);
|
||||||
|
|
||||||
|
cbAlwaysOnGroups << cbAlwaysOnGroup;
|
||||||
|
cboGroupStartupPosns << cboStartPosn;
|
||||||
|
}
|
||||||
|
|
||||||
|
update();
|
||||||
|
|
||||||
|
lock = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
FunctionSwitchesPanel::~FunctionSwitchesPanel()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FunctionSwitchesPanel::update()
|
||||||
|
{
|
||||||
|
lock = true;
|
||||||
|
|
||||||
|
for (int i = 0; i < switchcnt; i++) {
|
||||||
|
filterSwitchConfigs[i]->invalidate();
|
||||||
|
filterSwitchGroups[i]->invalidate();
|
||||||
|
|
||||||
|
aleNames[i]->update();
|
||||||
|
cboConfigs[i]->setCurrentIndex(filterSwitchConfigs[i]->mapFromSource(fsConfig->index(model->getFuncSwitchConfig(i), 0)).row());
|
||||||
|
cboStartupPosns[i]->setCurrentIndex(model->getFuncSwitchStart(i));
|
||||||
|
unsigned int grp = model->getFuncSwitchGroup(i);
|
||||||
|
cboGroups[i]->setCurrentIndex(grp);
|
||||||
|
|
||||||
|
cboStartupPosns[i]->setEnabled(cboConfigs[i]->currentIndex() >= ModelData::FUNC_SWITCH_CONFIG_2POS && (grp == 0));
|
||||||
|
|
||||||
|
cboGroups[i]->setEnabled(cboConfigs[i]->currentIndex() >= ModelData::FUNC_SWITCH_CONFIG_TOGGLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i += 1) {
|
||||||
|
filterGroupSwitches[i]->invalidate();
|
||||||
|
|
||||||
|
model->setGroupSwitchState(i + 1, switchcnt);
|
||||||
|
|
||||||
|
cbAlwaysOnGroups[i]->setChecked(model->getFuncSwitchAlwaysOnGroup(i + 1));
|
||||||
|
cboGroupStartupPosns[i]->setCurrentIndex(filterGroupSwitches[i]->mapFromSource(fsGroupStart->index(model->getFuncGroupSwitchStart(i + 1, switchcnt), 0)).row());
|
||||||
|
}
|
||||||
|
|
||||||
|
lock = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FunctionSwitchesPanel::on_nameEditingFinished()
|
||||||
|
{
|
||||||
|
emit updateDataModels();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FunctionSwitchesPanel::on_configCurrentIndexChanged(int index)
|
||||||
|
{
|
||||||
|
if (!sender())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QComboBox * cb = qobject_cast<QComboBox *>(sender());
|
||||||
|
|
||||||
|
if (cb && !lock) {
|
||||||
|
lock = true;
|
||||||
|
bool ok = false;
|
||||||
|
unsigned int sw = sender()->property("index").toInt(&ok);
|
||||||
|
unsigned int config = filterSwitchConfigs[sw]->mapToSource(filterSwitchConfigs[sw]->index(index, 0)).row();
|
||||||
|
if (ok && model->getFuncSwitchConfig(sw) != config) {
|
||||||
|
model->setFuncSwitchConfig(sw, config);
|
||||||
|
if (config != ModelData::FUNC_SWITCH_CONFIG_2POS) {
|
||||||
|
model->setFuncSwitchStart(sw, ModelData::FUNC_SWITCH_START_PREVIOUS);
|
||||||
|
if ((config == ModelData::FUNC_SWITCH_CONFIG_NONE) || model->getFuncSwitchAlwaysOnGroupForSwitch(sw))
|
||||||
|
model->setFuncSwitchGroup(sw, 0);
|
||||||
|
}
|
||||||
|
update();
|
||||||
|
emit modified();
|
||||||
|
emit updateDataModels();
|
||||||
|
}
|
||||||
|
lock = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FunctionSwitchesPanel::on_startPosnCurrentIndexChanged(int index)
|
||||||
|
{
|
||||||
|
if (!sender())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QComboBox * cb = qobject_cast<QComboBox *>(sender());
|
||||||
|
|
||||||
|
if (cb && !lock) {
|
||||||
|
lock = true;
|
||||||
|
bool ok = false;
|
||||||
|
unsigned int sw = sender()->property("index").toInt(&ok);
|
||||||
|
if (ok && model->getFuncSwitchStart(sw) != (unsigned int)index) {
|
||||||
|
model->setFuncSwitchStart(sw, index);
|
||||||
|
update();
|
||||||
|
emit modified();
|
||||||
|
}
|
||||||
|
lock = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FunctionSwitchesPanel::on_groupStartPosnCurrentIndexChanged(int index)
|
||||||
|
{
|
||||||
|
if (!sender())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QComboBox * cb = qobject_cast<QComboBox *>(sender());
|
||||||
|
|
||||||
|
if (cb && !lock) {
|
||||||
|
lock = true;
|
||||||
|
bool ok = false;
|
||||||
|
unsigned int grp = sender()->property("index").toInt(&ok);
|
||||||
|
unsigned int sw = filterGroupSwitches[grp]->mapToSource(filterGroupSwitches[grp]->index(index, 0)).row();
|
||||||
|
if (ok && model->getFuncGroupSwitchStart(grp + 1, switchcnt) != sw) {
|
||||||
|
model->setFuncGroupSwitchStart(grp + 1, sw, switchcnt);
|
||||||
|
update();
|
||||||
|
emit modified();
|
||||||
|
}
|
||||||
|
lock = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FunctionSwitchesPanel::on_groupChanged(int value)
|
||||||
|
{
|
||||||
|
if (!sender())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QComboBox * cb = qobject_cast<QComboBox *>(sender());
|
||||||
|
|
||||||
|
if (cb && !lock) {
|
||||||
|
lock = true;
|
||||||
|
bool ok = false;
|
||||||
|
int sw = sender()->property("index").toInt(&ok);
|
||||||
|
unsigned int grp = filterSwitchGroups[sw]->mapToSource(filterSwitchGroups[sw]->index(value, 0)).row();
|
||||||
|
if (ok && model->getFuncSwitchGroup(sw) != grp) {
|
||||||
|
unsigned oldGrp = model->getFuncSwitchGroup(sw);
|
||||||
|
if (model->getFuncSwitchAlwaysOnGroup(grp)) {
|
||||||
|
if (model->getFuncSwitchConfig(sw) == ModelData::FUNC_SWITCH_CONFIG_TOGGLE)
|
||||||
|
model->setFuncSwitchConfig(sw, ModelData::FUNC_SWITCH_CONFIG_2POS);
|
||||||
|
}
|
||||||
|
if ((grp == 0) || (model->getFuncGroupSwitchStart(grp, switchcnt) == 0))
|
||||||
|
model->setFuncSwitchStart(sw, ModelData::FUNC_SWITCH_START_PREVIOUS);
|
||||||
|
else
|
||||||
|
model->setFuncSwitchStart(sw, ModelData::FUNC_SWITCH_START_OFF);
|
||||||
|
model->setFuncSwitchGroup(sw, grp);
|
||||||
|
if (oldGrp > 0)
|
||||||
|
model->setFuncGroupSwitchStart(oldGrp, model->getFuncGroupSwitchStart(oldGrp, switchcnt), switchcnt);
|
||||||
|
update();
|
||||||
|
emit modified();
|
||||||
|
emit updateDataModels();
|
||||||
|
}
|
||||||
|
lock = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FunctionSwitchesPanel::on_alwaysOnGroupChanged(int value)
|
||||||
|
{
|
||||||
|
if (!sender())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QCheckBox * cb = qobject_cast<QCheckBox *>(sender());
|
||||||
|
|
||||||
|
if (cb && !lock) {
|
||||||
|
lock = true;
|
||||||
|
bool ok = false;
|
||||||
|
int grp = sender()->property("index").toInt(&ok) + 1;
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
model->setFuncSwitchAlwaysOnGroup(grp, (unsigned int)value);
|
||||||
|
if (value) {
|
||||||
|
for (int i = 0; i < switchcnt; i += 1) {
|
||||||
|
if (((int)model->getFuncSwitchGroup(i) == grp) && (model->getFuncSwitchConfig(i) == ModelData::FUNC_SWITCH_CONFIG_TOGGLE))
|
||||||
|
model->setFuncSwitchConfig(i, ModelData::FUNC_SWITCH_CONFIG_2POS);
|
||||||
|
}
|
||||||
|
if ((int)model->getFuncGroupSwitchStart(grp, switchcnt) == switchcnt + 1) {
|
||||||
|
for (int i = 0; i < switchcnt; i += 1) {
|
||||||
|
if ((int)model->getFuncSwitchGroup(i) == grp)
|
||||||
|
model->setFuncSwitchStart(i, ModelData::FUNC_SWITCH_START_PREVIOUS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
update();
|
||||||
|
emit modified();
|
||||||
|
}
|
||||||
|
|
||||||
|
lock = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,166 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) EdgeTX
|
||||||
|
*
|
||||||
|
* Based on code named
|
||||||
|
* opentx - https://github.com/opentx/opentx
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "modeledit.h"
|
||||||
|
#include "eeprominterface.h"
|
||||||
|
#include "filtereditemmodels.h"
|
||||||
|
|
||||||
|
class AutoLineEdit;
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class FunctionSwitches;
|
||||||
|
}
|
||||||
|
|
||||||
|
class FilteredGroupSwitchesModel: public QSortFilterProxyModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit FilteredGroupSwitchesModel(AbstractItemModel * sourceModel, int group, ModelData * model, int switchcnt) :
|
||||||
|
QSortFilterProxyModel(nullptr),
|
||||||
|
m_group(group),
|
||||||
|
m_switchcnt(switchcnt),
|
||||||
|
m_model(model)
|
||||||
|
{
|
||||||
|
setFilterKeyColumn(0);
|
||||||
|
setDynamicSortFilter(true);
|
||||||
|
setSourceModel(sourceModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit FilteredGroupSwitchesModel(AbstractItemModel * sourceModel) :
|
||||||
|
FilteredGroupSwitchesModel(sourceModel, 0, nullptr, 0) {}
|
||||||
|
virtual ~FilteredGroupSwitchesModel() {};
|
||||||
|
|
||||||
|
void setGroup(int group) { m_group = group; }
|
||||||
|
int getGroup() const { return m_group; }
|
||||||
|
void setSwitchcnt(int n) { m_switchcnt = n; }
|
||||||
|
int getSwitchcnt() const { return m_switchcnt; }
|
||||||
|
void setModel(ModelData* model) { m_model = model; }
|
||||||
|
ModelData* getModel() const { return m_model; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_group = 0;
|
||||||
|
int m_switchcnt = 0;
|
||||||
|
ModelData* m_model = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
class FilteredSwitchGroupsModel: public QSortFilterProxyModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit FilteredSwitchGroupsModel(AbstractItemModel * sourceModel, int sw, ModelData * model) :
|
||||||
|
QSortFilterProxyModel(nullptr),
|
||||||
|
m_switch(sw),
|
||||||
|
m_model(model)
|
||||||
|
{
|
||||||
|
setFilterKeyColumn(0);
|
||||||
|
setDynamicSortFilter(true);
|
||||||
|
setSourceModel(sourceModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit FilteredSwitchGroupsModel(AbstractItemModel * sourceModel) :
|
||||||
|
FilteredSwitchGroupsModel(sourceModel, 0, nullptr) {}
|
||||||
|
virtual ~FilteredSwitchGroupsModel() {};
|
||||||
|
|
||||||
|
void setSwitch(int group) { m_switch = group; }
|
||||||
|
int getSwitch() const { return m_switch; }
|
||||||
|
void setModel(ModelData* model) { m_model = model; }
|
||||||
|
ModelData* getModel() const { return m_model; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_switch = 0;
|
||||||
|
ModelData* m_model = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
class FilteredSwitchConfigsModel: public QSortFilterProxyModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit FilteredSwitchConfigsModel(AbstractItemModel * sourceModel, int sw, ModelData * model) :
|
||||||
|
QSortFilterProxyModel(nullptr),
|
||||||
|
m_switch(sw),
|
||||||
|
m_model(model)
|
||||||
|
{
|
||||||
|
setFilterKeyColumn(0);
|
||||||
|
setDynamicSortFilter(true);
|
||||||
|
setSourceModel(sourceModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit FilteredSwitchConfigsModel(AbstractItemModel * sourceModel) :
|
||||||
|
FilteredSwitchConfigsModel(sourceModel, 0, nullptr) {}
|
||||||
|
virtual ~FilteredSwitchConfigsModel() {};
|
||||||
|
|
||||||
|
void setSwitch(int group) { m_switch = group; }
|
||||||
|
int getSwitch() const { return m_switch; }
|
||||||
|
void setModel(ModelData* model) { m_model = model; }
|
||||||
|
ModelData* getModel() const { return m_model; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_switch = 0;
|
||||||
|
ModelData* m_model = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
class FunctionSwitchesPanel : public ModelPanel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
FunctionSwitchesPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware);
|
||||||
|
virtual ~FunctionSwitchesPanel();
|
||||||
|
|
||||||
|
void update();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void updateDataModels();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void on_nameEditingFinished();
|
||||||
|
void on_configCurrentIndexChanged(int index);
|
||||||
|
void on_startPosnCurrentIndexChanged(int index);
|
||||||
|
void on_groupStartPosnCurrentIndexChanged(int index);
|
||||||
|
void on_groupChanged(int value);
|
||||||
|
void on_alwaysOnGroupChanged(int value);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::FunctionSwitches * ui;
|
||||||
|
QVector<AutoLineEdit *> aleNames;
|
||||||
|
QVector<QComboBox *> cboConfigs;
|
||||||
|
QVector<QComboBox *> cboStartupPosns;
|
||||||
|
QVector<QComboBox *> cboGroups;
|
||||||
|
QVector<QCheckBox *> cbAlwaysOnGroups;
|
||||||
|
QVector<QComboBox *> cboGroupStartupPosns;
|
||||||
|
QVector<FilteredGroupSwitchesModel *> filterGroupSwitches;
|
||||||
|
QVector<FilteredSwitchGroupsModel *> filterSwitchGroups;
|
||||||
|
QVector<FilteredSwitchConfigsModel *> filterSwitchConfigs;
|
||||||
|
int switchcnt;
|
||||||
|
AbstractStaticItemModel *fsConfig;
|
||||||
|
AbstractStaticItemModel *fsGroupStart;
|
||||||
|
};
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) EdgeTX
|
||||||
|
*
|
||||||
|
* Based on code named
|
||||||
|
* opentx - https://github.com/opentx/opentx
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "modeledit.h"
|
||||||
|
#include "eeprominterface.h"
|
||||||
|
#include "filtereditemmodels.h"
|
||||||
|
|
||||||
|
constexpr char FIM_ANTENNAMODE[] {"Antenna Mode"};
|
||||||
|
constexpr char FIM_CRSFARMSWITCH[] {"CRSF Arming Switch"};
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class Module;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ModulePanel : public ModelPanel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
ModulePanel(QWidget * parent, ModelData & model, ModuleData & module, GeneralSettings & generalSettings, Firmware * firmware, int moduleIdx,
|
||||||
|
FilteredItemModelFactory * panelFilteredItemModels = nullptr, CompoundItemModelFactory * panelItemModels = nullptr);
|
||||||
|
virtual ~ModulePanel();
|
||||||
|
|
||||||
|
virtual void update();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void onExtendedLimitsToggled();
|
||||||
|
void onFailsafeModified(unsigned index);
|
||||||
|
void updateTrainerModeItemModel();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void channelsRangeChanged();
|
||||||
|
void failsafeModified(unsigned index);
|
||||||
|
void updateItemModels();
|
||||||
|
void protocolChanged();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void setupFailsafes();
|
||||||
|
void onProtocolChanged(int index);
|
||||||
|
void on_ppmDelay_editingFinished();
|
||||||
|
void on_channelsCount_editingFinished();
|
||||||
|
void on_channelsStart_editingFinished();
|
||||||
|
void on_ppmPolarity_currentIndexChanged(int index);
|
||||||
|
void on_ppmOutputType_currentIndexChanged(int index);
|
||||||
|
void on_ppmFrameLength_editingFinished();
|
||||||
|
void on_rxNumber_editingFinished();
|
||||||
|
void on_failsafeMode_currentIndexChanged(int value);
|
||||||
|
void onMultiProtocolChanged(int index);
|
||||||
|
void onSubTypeChanged();
|
||||||
|
void on_autoBind_stateChanged(int state);
|
||||||
|
void on_disableChMap_stateChanged(int state);
|
||||||
|
void on_raw12bits_stateChanged(int state);
|
||||||
|
void on_racingMode_stateChanged(int state);
|
||||||
|
void on_disableTelem_stateChanged(int state);
|
||||||
|
void on_lowPower_stateChanged(int state);
|
||||||
|
void on_r9mPower_currentIndexChanged(int index);
|
||||||
|
void setChannelFailsafeValue(const int channel, const int value, quint8 updtSb = 0);
|
||||||
|
void onFailsafeComboIndexChanged(int index);
|
||||||
|
void onFailsafeUsecChanged(int value);
|
||||||
|
void onFailsafePercentChanged(double value);
|
||||||
|
void onFailsafesDisplayValueTypeChanged(int type);
|
||||||
|
void onRfFreqChanged(int freq);
|
||||||
|
void updateFailsafe(unsigned channel);
|
||||||
|
void on_optionValue_valueChanged(int value);
|
||||||
|
void onClearAccessRxClicked();
|
||||||
|
void on_chkOption_stateChanged(int state);
|
||||||
|
void on_cboOption_currentIndexChanged(int value);
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum FailsafeValueDisplayTypes { FAILSAFE_DISPLAY_PERCENT = 1, FAILSAFE_DISPLAY_USEC = 2 };
|
||||||
|
|
||||||
|
struct ChannelFailsafeWidgetsGroup {
|
||||||
|
QLabel * label;
|
||||||
|
QComboBox * combo;
|
||||||
|
QSpinBox * sbUsec;
|
||||||
|
QDoubleSpinBox * sbPercent;
|
||||||
|
};
|
||||||
|
|
||||||
|
ModuleData & module;
|
||||||
|
int moduleIdx;
|
||||||
|
Ui::Module *ui;
|
||||||
|
QMap<int, ChannelFailsafeWidgetsGroup> failsafeGroupsMap;
|
||||||
|
static quint8 failsafesValueDisplayType; // FailsafeValueDisplayTypes
|
||||||
|
void updateFailsafeUI(unsigned channel, quint8 updtSb);
|
||||||
|
FilteredItemModel *trainerModeItemModel;
|
||||||
|
static bool isTrainerModule(int index) { return index < 0; }
|
||||||
|
static bool isInternalModule(int index) { return index == 0; }
|
||||||
|
static bool isExternalModule(int index) { return index > 0; }
|
||||||
|
};
|
||||||
@@ -0,0 +1,186 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) EdgeTX
|
||||||
|
*
|
||||||
|
* Based on code named
|
||||||
|
* opentx - https://github.com/opentx/opentx
|
||||||
|
* 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 "setup_timer.h"
|
||||||
|
#include "ui_setup_timer.h"
|
||||||
|
#include "namevalidator.h"
|
||||||
|
|
||||||
|
TimerPanel::TimerPanel(QWidget * parent, ModelData & model, TimerData & timer, GeneralSettings & generalSettings, Firmware * firmware,
|
||||||
|
QWidget * prevFocus, FilteredItemModelFactory * panelFilteredModels, CompoundItemModelFactory * panelItemModels):
|
||||||
|
ModelPanel(parent, model, generalSettings, firmware),
|
||||||
|
timer(timer),
|
||||||
|
ui(new Ui::Timer),
|
||||||
|
modelsUpdateCnt(0)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
connectItemModelEvents(panelFilteredModels->getItemModel(FIM_TIMERSWITCH));
|
||||||
|
|
||||||
|
lock = true;
|
||||||
|
|
||||||
|
// Name
|
||||||
|
int length = firmware->getCapability(TimersName);
|
||||||
|
if (length == 0)
|
||||||
|
ui->name->hide();
|
||||||
|
else {
|
||||||
|
ui->name->setValidator(new NameValidator(firmware->getBoard(), this));
|
||||||
|
ui->name->setField(timer.name, length, this);
|
||||||
|
connect(ui->name, SIGNAL(currentDataChanged()), this, SLOT(onNameChanged()));
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->value->setField(timer.val, this);
|
||||||
|
ui->value->setMaximumTime(firmware->getMaxTimerStart());
|
||||||
|
connect(ui->value, &AutoTimeEdit::currentDataChanged, [=](const int val) {
|
||||||
|
update();
|
||||||
|
});
|
||||||
|
|
||||||
|
ui->mode->setModel(panelItemModels->getItemModel(AIM_TIMER_MODE));
|
||||||
|
ui->mode->setField(timer.mode, this);
|
||||||
|
connect(ui->mode, SIGNAL(currentDataChanged(int)), this, SLOT(onModeChanged(int)));
|
||||||
|
|
||||||
|
ui->swtch->setModel(panelFilteredModels->getItemModel(FIM_TIMERSWITCH));
|
||||||
|
ui->swtch->setField(timer.swtch, this);
|
||||||
|
|
||||||
|
ui->countdownBeep->setModel(panelItemModels->getItemModel(AIM_TIMER_COUNTDOWNBEEP));
|
||||||
|
ui->countdownBeep->setField(timer.countdownBeep, this);
|
||||||
|
connect(ui->countdownBeep, SIGNAL(currentDataChanged(int)), this, SLOT(onCountdownBeepChanged(int)));
|
||||||
|
|
||||||
|
ui->minuteBeep->setField(timer.minuteBeep, this);
|
||||||
|
|
||||||
|
if (firmware->getCapability(PermTimers)) {
|
||||||
|
ui->persistent->setModel(panelItemModels->getItemModel(AIM_TIMER_PERSISTENT));
|
||||||
|
ui->persistent->setField(timer.persistent, this);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ui->persistent->hide();
|
||||||
|
ui->persistentValue->hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->countdownStart->setModel(panelItemModels->getItemModel(AIM_TIMER_COUNTDOWNSTART));
|
||||||
|
ui->countdownStart->setField(timer.countdownStart, this);
|
||||||
|
|
||||||
|
|
||||||
|
ui->showElapsed->setModel(panelItemModels->getItemModel(AIM_TIMER_SHOWELAPSED));
|
||||||
|
ui->showElapsed->setField(timer.showElapsed, this);
|
||||||
|
|
||||||
|
disableMouseScrolling();
|
||||||
|
QWidget::setTabOrder(prevFocus, ui->name);
|
||||||
|
QWidget::setTabOrder(ui->name, ui->value);
|
||||||
|
QWidget::setTabOrder(ui->value, ui->mode);
|
||||||
|
QWidget::setTabOrder(ui->mode, ui->countdownBeep);
|
||||||
|
QWidget::setTabOrder(ui->countdownBeep, ui->countdownStart);
|
||||||
|
QWidget::setTabOrder(ui->countdownStart, ui->minuteBeep);
|
||||||
|
QWidget::setTabOrder(ui->minuteBeep, ui->persistent);
|
||||||
|
QWidget::setTabOrder(ui->persistent, ui->showElapsed);
|
||||||
|
|
||||||
|
update();
|
||||||
|
lock = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
TimerPanel::~TimerPanel()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TimerPanel::update()
|
||||||
|
{
|
||||||
|
lock = true;
|
||||||
|
|
||||||
|
ui->name->updateValue();
|
||||||
|
ui->mode->updateValue();
|
||||||
|
ui->swtch->updateValue();
|
||||||
|
ui->value->updateValue();
|
||||||
|
ui->countdownBeep->updateValue();
|
||||||
|
ui->minuteBeep->updateValue();
|
||||||
|
ui->countdownStart->updateValue();
|
||||||
|
ui->showElapsed->updateValue();
|
||||||
|
|
||||||
|
if (timer.mode != TimerData::TIMERMODE_OFF)
|
||||||
|
ui->swtch->setEnabled(true);
|
||||||
|
else
|
||||||
|
ui->swtch->setEnabled(false);
|
||||||
|
|
||||||
|
if (timer.countdownBeep == TimerData::COUNTDOWNBEEP_SILENT) {
|
||||||
|
ui->countdownStartLabel->setEnabled(false);
|
||||||
|
ui->countdownStart->setEnabled(false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ui->countdownStartLabel->setEnabled(true);
|
||||||
|
ui->countdownStart->setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (firmware->getCapability(PermTimers)) {
|
||||||
|
ui->persistent->updateValue();
|
||||||
|
ui->persistentValue->setText(timer.pvalueToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timer.val) {
|
||||||
|
ui->showElapsed->setEnabled(true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ui->showElapsed->setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
lock = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget * TimerPanel::getLastFocus()
|
||||||
|
{
|
||||||
|
return ui->persistent;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TimerPanel::connectItemModelEvents(const FilteredItemModel * itemModel)
|
||||||
|
{
|
||||||
|
connect(itemModel, &FilteredItemModel::aboutToBeUpdated, this, &TimerPanel::onItemModelAboutToBeUpdated);
|
||||||
|
connect(itemModel, &FilteredItemModel::updateComplete, this, &TimerPanel::onItemModelUpdateComplete);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TimerPanel::onItemModelAboutToBeUpdated()
|
||||||
|
{
|
||||||
|
lock = true;
|
||||||
|
modelsUpdateCnt++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TimerPanel::onItemModelUpdateComplete()
|
||||||
|
{
|
||||||
|
modelsUpdateCnt--;
|
||||||
|
if (modelsUpdateCnt < 1) {
|
||||||
|
update();
|
||||||
|
lock = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TimerPanel::onNameChanged()
|
||||||
|
{
|
||||||
|
emit nameChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TimerPanel::onCountdownBeepChanged(int index)
|
||||||
|
{
|
||||||
|
timer.countdownBeepChanged();
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TimerPanel::onModeChanged(int index)
|
||||||
|
{
|
||||||
|
timer.modeChanged();
|
||||||
|
update();
|
||||||
|
emit modeChanged();
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) EdgeTX
|
||||||
|
*
|
||||||
|
* Based on code named
|
||||||
|
* opentx - https://github.com/opentx/opentx
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "modeledit.h"
|
||||||
|
#include "eeprominterface.h"
|
||||||
|
#include "filtereditemmodels.h"
|
||||||
|
|
||||||
|
constexpr char FIM_TIMERSWITCH[] {"Timer Switch"};
|
||||||
|
constexpr char MIMETYPE_TIMER[] {"application/x-companion-timer"};
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class Timer;
|
||||||
|
}
|
||||||
|
|
||||||
|
class TimerPanel : public ModelPanel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
TimerPanel(QWidget * parent, ModelData & model, TimerData & timer, GeneralSettings & generalSettings, Firmware * firmware,
|
||||||
|
QWidget * prevFocus, FilteredItemModelFactory * panelFilteredModels, CompoundItemModelFactory * panelItemModels);
|
||||||
|
virtual ~TimerPanel();
|
||||||
|
|
||||||
|
virtual void update();
|
||||||
|
QWidget * getLastFocus();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void onNameChanged();
|
||||||
|
void onModeChanged(int index);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onItemModelAboutToBeUpdated();
|
||||||
|
void onItemModelUpdateComplete();
|
||||||
|
void onCountdownBeepChanged(int index);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void nameChanged();
|
||||||
|
void modeChanged();
|
||||||
|
|
||||||
|
private:
|
||||||
|
TimerData & timer;
|
||||||
|
Ui::Timer * ui;
|
||||||
|
void connectItemModelEvents(const FilteredItemModel * itemModel);
|
||||||
|
int modelsUpdateCnt;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user