Skip to content

Commit

Permalink
REFAC(client): Implement loadComboBox() that sets the index based on …
Browse files Browse the repository at this point in the history
…the data

The function that already existed took the index instead of the data,
making it susceptible to errors because the data could be passed instead of the index.

Also, with this new iteration of loadComboBox() we can reorder the items shown to the user as desired.
  • Loading branch information
davidebeatrici committed Jun 1, 2024
1 parent 6bd2d2e commit b83f5ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/mumble/ConfigWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,18 @@ void ConfigWidget::loadComboBox(QComboBox *c, int v) {
disconnect(SIGNAL(intSignal(int)));
}
}

void ConfigWidget::loadComboBox(QComboBox *c, const QVariant &v) {
const int index = c->findData(v);
if (index == -1) {
return;
}

if (c->currentIndex() != index) {
c->setCurrentIndex(index);
} else {
connect(this, SIGNAL(intSignal(int)), c, SIGNAL(currentIndexChanged(int)));
emit intSignal(index);
disconnect(SIGNAL(intSignal(int)));
}
}
1 change: 1 addition & 0 deletions src/mumble/ConfigWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ConfigWidget : public QWidget {
void loadSlider(QSlider *, int);
void loadCheckBox(QAbstractButton *, bool);
void loadComboBox(QComboBox *, int);
void loadComboBox(QComboBox *, const QVariant &);
signals:
void intSignal(int);

Expand Down

0 comments on commit b83f5ef

Please sign in to comment.