Skip to content

Commit

Permalink
Avoid using QComboBox::setPlaceholderText
Browse files Browse the repository at this point in the history
  • Loading branch information
svendcs committed Aug 20, 2020
1 parent f981bb0 commit aa6a62c
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/ui/widgets/score_operator_window.cpp
Expand Up @@ -45,6 +45,7 @@ ScoreOperatorWindow::ScoreOperatorWindow()

findNextMatch();
disableControlButtons();
populateTatamiSelect();

createStatusBar();
createTournamentMenu();
Expand Down Expand Up @@ -116,14 +117,23 @@ void ScoreOperatorWindow::clearTatamiSelect() {

void ScoreOperatorWindow::populateTatamiSelect() {
const auto &tatamis = mStoreManager.getTournament().getTatamis();
mTatamiSelect->setEnabled(tatamis.tatamiCount() > 0);

if (tatamis.tatamiCount() == 0) {
mTatamiSelect->setEnabled(false);
return;
}

mTatamiSelect->setEnabled(true);

mTatamiSelect->addItem(tr("Please select a tatami.."));
mTatamiSelect->setItemData(0, QBrush(Qt::gray), Qt::ForegroundRole);

for (size_t i = 0; i < tatamis.tatamiCount(); ++i) {
mTatamiSelect->addItem(tr("Tatami %1").arg(QString::number(i+1)));

TatamiLocation location = {tatamis.getHandle(i)};
if (mTatami && location == *mTatami)
mTatamiSelect->setCurrentIndex(i);
mTatamiSelect->setCurrentIndex(i+1);
}
}

Expand Down Expand Up @@ -242,8 +252,6 @@ QWidget* ScoreOperatorWindow::createLowerSection() {
connect(mResetButton, &QPushButton::clicked, this, &ScoreOperatorWindow::resetButtonClick);

mTatamiSelect = new QComboBox(matchBox);
mTatamiSelect->setPlaceholderText(tr("Select tatami.."));
mTatamiSelect->setEnabled(false);
connect(mTatamiSelect, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ScoreOperatorWindow::setTatami);

subLayout->addWidget(mNextButton);
Expand Down Expand Up @@ -307,10 +315,12 @@ void ScoreOperatorWindow::endResetTournament() {
void ScoreOperatorWindow::setTatami(int index) {
const auto &tatamis = mStoreManager.getTournament().getTatamis();

if (index == -1 || static_cast<size_t>(index) >= tatamis.tatamiCount()) // in case the combobox was cleared
if (index == -1 || static_cast<size_t>(index) > tatamis.tatamiCount()) // in case the combobox was cleared
return;

TatamiLocation location{tatamis.getHandle(index)};
std::optional<TatamiLocation> location;
if (index > 0) // If the placeholder item was not selected
location = {tatamis.getHandle(index-1)};

if (location == mTatami)
return;
Expand Down

0 comments on commit aa6a62c

Please sign in to comment.