statistics/mobile: set currentIndex of QML combo boxes

Use Q_PROPERTYs of the StatsManager to correctly set
the current index of comboboxes after a state changed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-01-10 18:00:19 +01:00 committed by Dirk Hohndel
parent 8f8ee5c589
commit 9a0c5df744
3 changed files with 28 additions and 6 deletions

View file

@ -37,6 +37,7 @@ Kirigami.Page {
TemplateComboBox {
id: var1
model: statsManager.var1List
currentIndex: statsManager.var1Index;
Layout.fillWidth: false
onCurrentIndexChanged: {
statsManager.var1Changed(currentIndex)
@ -54,6 +55,7 @@ Kirigami.Page {
TemplateComboBox {
id: var1Binner
model: statsManager.binner1List
currentIndex: statsManager.binner1Index;
Layout.fillWidth: false
onCurrentIndexChanged: {
statsManager.var1BinnerChanged(currentIndex)
@ -71,6 +73,7 @@ Kirigami.Page {
TemplateComboBox {
id: var2
model: statsManager.var2List
currentIndex: statsManager.var2Index;
Layout.fillWidth: false
onCurrentIndexChanged: {
statsManager.var2Changed(currentIndex)
@ -88,6 +91,7 @@ Kirigami.Page {
TemplateComboBox {
id: var2Binner
model: statsManager.binner2List
currentIndex: statsManager.binner2Index;
Layout.fillWidth: false
onCurrentIndexChanged: {
statsManager.var2BinnerChanged(currentIndex)

View file

@ -28,31 +28,37 @@ void StatsManager::doit()
view->plot(state);
}
static void setVariableList(const StatsState::VariableList &list, QStringList &stringList)
static void setVariableList(const StatsState::VariableList &list, QStringList &stringList, int &idx)
{
stringList.clear();
for (const StatsState::Variable &v: list.variables)
stringList.push_back(v.name);
idx = list.selected;
}
static void setBinnerList(const StatsState::BinnerList &list, QStringList &stringList)
static void setBinnerList(const StatsState::BinnerList &list, QStringList &stringList, int &idx)
{
stringList.clear();
for (const QString &v: list.binners)
stringList.push_back(v);
idx = list.selected;
}
void StatsManager::updateUi()
{
uiState = state.getUIState();
setVariableList(uiState.var1, var1List);
setBinnerList(uiState.binners1, binner1List);
setVariableList(uiState.var2, var2List);
setBinnerList(uiState.binners2, binner2List);
setVariableList(uiState.var1, var1List, var1Index);
setBinnerList(uiState.binners1, binner1List, binner1Index);
setVariableList(uiState.var2, var2List, var2Index);
setBinnerList(uiState.binners2, binner2List, binner2Index);
var1ListChanged();
binner1ListChanged();
var2ListChanged();
binner2ListChanged();
var1IndexChanged();
binner1IndexChanged();
var2IndexChanged();
binner2IndexChanged();
if (view)
view->plot(state);

View file

@ -14,6 +14,10 @@ public:
Q_PROPERTY(QStringList binner1List MEMBER binner1List NOTIFY binner1ListChanged)
Q_PROPERTY(QStringList var2List MEMBER var2List NOTIFY var2ListChanged)
Q_PROPERTY(QStringList binner2List MEMBER binner2List NOTIFY binner2ListChanged)
Q_PROPERTY(int var1Index MEMBER var1Index NOTIFY var1IndexChanged)
Q_PROPERTY(int binner1Index MEMBER binner1Index NOTIFY binner1IndexChanged)
Q_PROPERTY(int var2Index MEMBER var2Index NOTIFY var2IndexChanged)
Q_PROPERTY(int binner2Index MEMBER binner2Index NOTIFY binner2IndexChanged)
StatsManager();
~StatsManager();
@ -28,6 +32,10 @@ signals:
void binner1ListChanged();
void var2ListChanged();
void binner2ListChanged();
void var1IndexChanged();
void binner1IndexChanged();
void var2IndexChanged();
void binner2IndexChanged();
private:
StatsView *view;
StatsState state;
@ -35,6 +43,10 @@ private:
QStringList binner1List;
QStringList var2List;
QStringList binner2List;
int var1Index;
int binner1Index;
int var2Index;
int binner2Index;
StatsState::UIState uiState; // Remember UI state so that we can interpret indexes
void updateUi();