Skip to content

Commit

Permalink
Merge pull request #2792 from jamescowens/fix_poll_choice_limit
Browse files Browse the repository at this point in the history
poll, gui: Disable choice add button in poll wizard when choice limit is reached
  • Loading branch information
jamescowens authored Feb 3, 2025
2 parents 7dd8bac + 3ccf452 commit 0928f6f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/qt/voting/pollwizarddetailspage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ PollWizardDetailsPage::PollWizardDetailsPage(QWidget* parent)
ui->removeChoiceButton->setVisible(!selected.isEmpty());
});
connect(ui->addChoiceButton, &QAbstractButton::clicked, this, [=]() {
if ((size_t) ui->choicesList->model()->rowCount() >= GRC::POLL_MAX_CHOICES_SIZE - 1) {
ui->addChoiceButton->setDisabled(true);
ui->addChoiceButton->setToolTip(tr("Cannot have more than 20 choices in a poll."));
}

ui->choicesList->edit(m_choices_model->addItem());
ui->choicesList->scrollToBottom();
});
Expand All @@ -236,6 +241,11 @@ PollWizardDetailsPage::PollWizardDetailsPage(QWidget* parent)
});
connect(ui->removeChoiceButton, &QAbstractButton::clicked, this, [=]() {
m_choices_model->removeItem(ui->choicesList->selectionModel()->selectedIndexes().first());

if ((size_t) ui->choicesList->model()->rowCount() < GRC::POLL_MAX_CHOICES_SIZE) {
ui->addChoiceButton->setEnabled(true);
ui->addChoiceButton->setToolTip("");
}
});
connect(m_choices_model.get(), &ChoicesListModel::completeChanged, this, [=]() {
emit completeChanged();
Expand Down

0 comments on commit 0928f6f

Please sign in to comment.