Skip to content

Commit

Permalink
MIDI option delegate: add 'Unset all' action to options list
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed May 8, 2024
1 parent c7eb752 commit dfb7648
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/controllers/delegates/midioptionsdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ QWidget* MidiOptionsDelegate::createEditor(QWidget* parent,
pItem->setCheckable(true);
pModel->appendRow(pItem);
}
// Add a special item to uncheck all. See commitAndCloseEditor()
QStandardItem* pItem = new QStandardItem(tr("Unset all"));
pItem->setCheckable(false); // doesn't hurt to set this explicitly
pModel->appendRow(pItem);

// Unsetting the index clears the display text which is visible when closing
// the list view by clicking anywhere else. Default text is that of first
// added item. It can be set to any combination of existing item texts, e.g.
Expand Down Expand Up @@ -112,6 +117,9 @@ void MidiOptionsDelegate::setEditorData(QWidget* editor,
DEBUG_ASSERT(pModel);
for (int row = 0; row < pModel->rowCount(); row++) {
auto pItem = pModel->item(row, 0);

Check warning on line 119 in src/controllers/delegates/midioptionsdelegate.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy

'auto pItem' can be declared as 'auto *pItem' [readability-qualified-auto]
if (!pItem->isCheckable()) {
continue;
}
auto opt = static_cast<MidiOption>(pItem->data().toInt());
pItem->setCheckState(options.testFlag(opt) ? Qt::Checked : Qt::Unchecked);
}
Expand Down Expand Up @@ -151,7 +159,18 @@ void MidiOptionsDelegate::commitAndCloseEditor(int index) {
DEBUG_ASSERT(pModel);
auto* pItem = pModel->item(index);
DEBUG_ASSERT(pItem);
pItem->setCheckState(pItem->checkState() == Qt::Checked ? Qt::Unchecked : Qt::Checked);
if (pItem->isCheckable()) {
pItem->setCheckState(pItem->checkState() == Qt::Checked ? Qt::Unchecked : Qt::Checked);
} else {
// Clear was selected. Uncheck all other items
for (int row = 0; row < pModel->rowCount() - 1; row++) {
if (row == index) { // Actually it's the last item, but this is safer.
continue;
}
auto pItem = pModel->item(row, 0);

Check warning on line 170 in src/controllers/delegates/midioptionsdelegate.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy

'auto pItem' can be declared as 'auto *pItem' [readability-qualified-auto]
pItem->setCheckState(Qt::Unchecked);
}
}

emit commitData(pComboBox);
emit closeEditor(pComboBox);
Expand Down

0 comments on commit dfb7648

Please sign in to comment.