Use item models for ui lists
This commit is contained in:
committed by
Raphael Coeffic
parent
83b676b4dd
commit
9a07b83b00
@@ -1653,3 +1653,77 @@ AbstractStaticItemModel * ModelData::trainerModeItemModel(const GeneralSettings
|
|||||||
mdl->loadItemList();
|
mdl->loadItemList();
|
||||||
return mdl;
|
return mdl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ModelData::funcSwitchConfigToString(unsigned int index) const
|
||||||
|
{
|
||||||
|
if (index < CPN_MAX_FUNCTION_SWITCHES)
|
||||||
|
return funcSwitchConfigToString((functionSwitchConfig >> (2 * index)) & 0x03);
|
||||||
|
else
|
||||||
|
return CPN_STR_UNKNOWN_ITEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
QString ModelData::funcSwitchConfigToString(int value)
|
||||||
|
{
|
||||||
|
switch (value) {
|
||||||
|
case FUNC_SWITCH_CONFIG_NONE:
|
||||||
|
return tr("NONE");
|
||||||
|
case FUNC_SWITCH_CONFIG_TOGGLE:
|
||||||
|
return tr("TOGGLE");
|
||||||
|
case FUNC_SWITCH_CONFIG_2POS:
|
||||||
|
return tr("2POS");
|
||||||
|
default:
|
||||||
|
return CPN_STR_UNKNOWN_ITEM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
AbstractStaticItemModel * ModelData::funcSwitchConfigItemModel()
|
||||||
|
{
|
||||||
|
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
|
||||||
|
mdl->setName(AIM_MODELDATA_FUNCSWITCHCONFIG);
|
||||||
|
|
||||||
|
for (int i = FUNC_SWITCH_CONFIG_FIRST; i <= FUNC_SWITCH_CONFIG_LAST; i++) {
|
||||||
|
mdl->appendToItemList(funcSwitchConfigToString(i), i);
|
||||||
|
}
|
||||||
|
|
||||||
|
mdl->loadItemList();
|
||||||
|
return mdl;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ModelData::funcSwitchStartToString(unsigned int index) const
|
||||||
|
{
|
||||||
|
if (index < CPN_MAX_FUNCTION_SWITCHES)
|
||||||
|
return funcSwitchStartToString((functionSwitchStartConfig >> (2 * index)) & 0x03);
|
||||||
|
else
|
||||||
|
return CPN_STR_UNKNOWN_ITEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
QString ModelData::funcSwitchStartToString(int value)
|
||||||
|
{
|
||||||
|
switch (value) {
|
||||||
|
case FUNC_SWITCH_START_INACTIVE:
|
||||||
|
return CPN_STR_SW_INDICATOR_UP;
|
||||||
|
case FUNC_SWITCH_START_ACTIVE:
|
||||||
|
return CPN_STR_SW_INDICATOR_DN;
|
||||||
|
case FUNC_SWITCH_START_PREVIOUS:
|
||||||
|
return "=";
|
||||||
|
default:
|
||||||
|
return CPN_STR_UNKNOWN_ITEM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
AbstractStaticItemModel * ModelData::funcSwitchStartItemModel()
|
||||||
|
{
|
||||||
|
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
|
||||||
|
mdl->setName(AIM_MODELDATA_FUNCSWITCHSTART);
|
||||||
|
|
||||||
|
for (int i = FUNC_SWITCH_START_FIRST; i <= FUNC_SWITCH_START_LAST; i++) {
|
||||||
|
mdl->appendToItemList(funcSwitchStartToString(i), i);
|
||||||
|
}
|
||||||
|
|
||||||
|
mdl->loadItemList();
|
||||||
|
return mdl;
|
||||||
|
}
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ class RadioDataConversionState;
|
|||||||
class AbstractStaticItemModel;
|
class AbstractStaticItemModel;
|
||||||
|
|
||||||
constexpr char AIM_MODELDATA_TRAINERMODE[] {"modeldata.trainermode"};
|
constexpr char AIM_MODELDATA_TRAINERMODE[] {"modeldata.trainermode"};
|
||||||
|
constexpr char AIM_MODELDATA_FUNCSWITCHCONFIG[] {"modeldata.funcswitchconfig"};
|
||||||
|
constexpr char AIM_MODELDATA_FUNCSWITCHSTART[] {"modeldata.funcswitchstart"};
|
||||||
|
|
||||||
#define CHAR_FOR_NAMES " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-."
|
#define CHAR_FOR_NAMES " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-."
|
||||||
#define CHAR_FOR_NAMES_REGEX "[ A-Za-z0-9_.-,]*"
|
#define CHAR_FOR_NAMES_REGEX "[ A-Za-z0-9_.-,]*"
|
||||||
@@ -172,6 +174,22 @@ class ModelData {
|
|||||||
|
|
||||||
char registrationId[8+1];
|
char registrationId[8+1];
|
||||||
|
|
||||||
|
enum FunctionSwitchConfig {
|
||||||
|
FUNC_SWITCH_CONFIG_NONE,
|
||||||
|
FUNC_SWITCH_CONFIG_FIRST = FUNC_SWITCH_CONFIG_NONE,
|
||||||
|
FUNC_SWITCH_CONFIG_TOGGLE,
|
||||||
|
FUNC_SWITCH_CONFIG_2POS,
|
||||||
|
FUNC_SWITCH_CONFIG_LAST = FUNC_SWITCH_CONFIG_2POS
|
||||||
|
};
|
||||||
|
|
||||||
|
enum FunctionSwitchStart {
|
||||||
|
FUNC_SWITCH_START_INACTIVE,
|
||||||
|
FUNC_SWITCH_START_FIRST = FUNC_SWITCH_START_INACTIVE,
|
||||||
|
FUNC_SWITCH_START_ACTIVE,
|
||||||
|
FUNC_SWITCH_START_PREVIOUS,
|
||||||
|
FUNC_SWITCH_START_LAST = FUNC_SWITCH_START_PREVIOUS
|
||||||
|
};
|
||||||
|
|
||||||
// Function switches
|
// Function switches
|
||||||
unsigned int functionSwitchConfig;
|
unsigned int functionSwitchConfig;
|
||||||
unsigned int functionSwitchGroup;
|
unsigned int functionSwitchGroup;
|
||||||
@@ -268,6 +286,12 @@ class ModelData {
|
|||||||
static QString trainerModeToString(const int value);
|
static QString trainerModeToString(const int value);
|
||||||
static bool isTrainerModeAvailable(const GeneralSettings & generalSettings, const Firmware * firmware, const int value);
|
static bool isTrainerModeAvailable(const GeneralSettings & generalSettings, const Firmware * firmware, const int value);
|
||||||
static AbstractStaticItemModel * trainerModeItemModel(const GeneralSettings & generalSettings, const Firmware * firmware);
|
static AbstractStaticItemModel * trainerModeItemModel(const GeneralSettings & generalSettings, const Firmware * firmware);
|
||||||
|
QString funcSwitchConfigToString(unsigned int index) const;
|
||||||
|
static QString funcSwitchConfigToString(const int value);
|
||||||
|
static AbstractStaticItemModel * funcSwitchConfigItemModel();
|
||||||
|
QString funcSwitchStartToString(unsigned int index) const;
|
||||||
|
static QString funcSwitchStartToString(const int value);
|
||||||
|
static AbstractStaticItemModel * funcSwitchStartItemModel();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void removeGlobalVar(int & var);
|
void removeGlobalVar(int & var);
|
||||||
|
|||||||
@@ -990,6 +990,9 @@ FunctionSwitchesPanel::FunctionSwitchesPanel(QWidget * parent, ModelData & model
|
|||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
AbstractStaticItemModel *fsConfig = ModelData::funcSwitchConfigItemModel();
|
||||||
|
AbstractStaticItemModel *fsStart = ModelData::funcSwitchStartItemModel();
|
||||||
|
|
||||||
lock = true;
|
lock = true;
|
||||||
|
|
||||||
QRegExp rx(CHAR_FOR_NAMES_REGEX);
|
QRegExp rx(CHAR_FOR_NAMES_REGEX);
|
||||||
@@ -1005,19 +1008,13 @@ FunctionSwitchesPanel::FunctionSwitchesPanel(QWidget * parent, ModelData & model
|
|||||||
aleName->setValidator(new QRegExpValidator(rx, this));
|
aleName->setValidator(new QRegExpValidator(rx, this));
|
||||||
aleName->setField((char *)model.functionSwitchNames[i], 3);
|
aleName->setField((char *)model.functionSwitchNames[i], 3);
|
||||||
|
|
||||||
// TODO itemmodel
|
|
||||||
QComboBox * cboConfig = new QComboBox(this);
|
QComboBox * cboConfig = new QComboBox(this);
|
||||||
cboConfig->setProperty("index", i);
|
cboConfig->setProperty("index", i);
|
||||||
cboConfig->addItem(tr("NONE"));
|
cboConfig->setModel(fsConfig);
|
||||||
cboConfig->addItem(tr("TOGGLE"));
|
|
||||||
cboConfig->addItem(tr("2POS"));
|
|
||||||
|
|
||||||
// TODO itemmodel
|
|
||||||
QComboBox * cboStartPosn = new QComboBox(this);
|
QComboBox * cboStartPosn = new QComboBox(this);
|
||||||
cboStartPosn->setProperty("index", i);
|
cboStartPosn->setProperty("index", i);
|
||||||
cboStartPosn->addItem(CPN_STR_SW_INDICATOR_UP);
|
cboStartPosn->setModel(fsStart);
|
||||||
cboStartPosn->addItem(CPN_STR_SW_INDICATOR_DN);
|
|
||||||
cboStartPosn->addItem("=");
|
|
||||||
|
|
||||||
QSpinBox * sbGroup = new QSpinBox(this);
|
QSpinBox * sbGroup = new QSpinBox(this);
|
||||||
sbGroup->setProperty("index", i);
|
sbGroup->setProperty("index", i);
|
||||||
|
|||||||
Reference in New Issue
Block a user