chore(cpn): move model edit setup classes to own code files (#5678)

This commit is contained in:
Neil Horne
2024-11-24 08:20:06 +10:00
committed by GitHub
parent 79adb58dfc
commit 6c2f97ca68
9 changed files with 1958 additions and 1797 deletions
+3 -248
View File
@@ -23,261 +23,16 @@
#include "modeledit.h"
#include "eeprominterface.h"
#include "compounditemmodels.h"
#include "filtereditemmodels.h"
#include <QSortFilterProxyModel>
constexpr char MIMETYPE_TIMER[] = "application/x-companion-timer";
#include "setup_timer.h"
#include "setup_module.h"
#include "setup_function_switches.h"
namespace Ui {
class Setup;
class Timer;
class Module;
class FunctionSwitches;
}
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
{