fix: enforce customisable switch rules when configuring (#4994)
This commit is contained in:
@@ -25,6 +25,8 @@
|
||||
#include "compounditemmodels.h"
|
||||
#include "filtereditemmodels.h"
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
constexpr char MIMETYPE_TIMER[] = "application/x-companion-timer";
|
||||
|
||||
namespace Ui {
|
||||
@@ -142,6 +144,103 @@ class ModulePanel : public ModelPanel
|
||||
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
|
||||
@@ -150,8 +249,7 @@ class FunctionSwitchesPanel : public ModelPanel
|
||||
FunctionSwitchesPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware);
|
||||
virtual ~FunctionSwitchesPanel();
|
||||
|
||||
virtual void update();
|
||||
void update(int index);
|
||||
void update();
|
||||
|
||||
signals:
|
||||
void updateDataModels();
|
||||
@@ -160,6 +258,7 @@ class FunctionSwitchesPanel : public ModelPanel
|
||||
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);
|
||||
|
||||
@@ -168,9 +267,15 @@ class FunctionSwitchesPanel : public ModelPanel
|
||||
QVector<AutoLineEdit *> aleNames;
|
||||
QVector<QComboBox *> cboConfigs;
|
||||
QVector<QComboBox *> cboStartupPosns;
|
||||
QVector<QSpinBox *> sbGroups;
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user