Skip to content

Commit

Permalink
DlgTrackInfoMulti: move comobox change funcs to separate slots
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed May 24, 2024
1 parent d78c47e commit 4350b46
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 38 deletions.
92 changes: 54 additions & 38 deletions src/library/dlgtrackinfomulti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,26 +176,8 @@ void DlgTrackInfoMulti::init() {

connect(pBox,
&QComboBox::currentIndexChanged,
[this, pBox]() {
pBox->blockSignals(true); // Prevent recursive calls
// If we have multiple values we also added the Clear item.
// If that item has been selected, remove the placeholder in order to have a
// somewhat safe indicator for whether the box has been edited.
// Used in validEditText().
auto data = pBox->currentData(Qt::UserRole);
if (data.isValid() && data.toString() == kClearItem) {
pBox->lineEdit()->setPlaceholderText(QString());
pBox->setCurrentIndex(-1); // This clears the edit text
// Remove the Clear item after use.
pBox->removeItem(pBox->findData(kClearItem));
}
if (pBox == txtKey) {
// Since we've blocked change signals we need to trigger
// the key validation manually.
slotKeyTextChanged();
}
pBox->blockSignals(false);
});
this,
&DlgTrackInfoMulti::slotTagBoxIndexChanged);
}
// Note: unlike other tags, comments can be multi-line, though while QComboBox
// can have multi-line items its Q*Line*Edit is not suitable for editing multi-
Expand All @@ -217,24 +199,8 @@ void DlgTrackInfoMulti::init() {
txtCommentBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
connect(txtCommentBox,
&QComboBox::currentIndexChanged,
[this]() {
txtCommentBox->blockSignals(true);
txtComment->setPlaceholderText(QString());
// If we have multiple value we also added the Clear All item.
// If the Clear item has been selected, remove the placeholder
// in order to have a safe indicator in validEditText() whether
// the box has been edited.
auto data = txtCommentBox->currentData(Qt::UserRole);
if (data.isValid() && data.toString() == kClearItem) {
txtCommentBox->setCurrentIndex(-1); // This clears the edit text
// Remove the Clear item after use.
txtCommentBox->removeItem(txtCommentBox->findData(kClearItem));
txtComment->clear();
} else {
txtComment->setPlainText(txtCommentBox->currentText());
}
txtCommentBox->blockSignals(false);
});
this,
&DlgTrackInfoMulti::slotCommentBoxIndexChanged);

// Set up key validation, i.e. check manually entered key texts
// Note: this is also triggered if the popup is opened.
Expand Down Expand Up @@ -785,6 +751,56 @@ void DlgTrackInfoMulti::slotTrackChanged(TrackId trackId) {
}
}

void DlgTrackInfoMulti::slotTagBoxIndexChanged() {
QComboBox* pBox = qobject_cast<QComboBox*>(sender());
VERIFY_OR_DEBUG_ASSERT(pBox && pBox != txtCommentBox) {
return;
}

pBox->blockSignals(true); // Prevent recursive calls
// If we have multiple values we also added the Clear item.
// If that item has been selected, remove the placeholder in order to have a
// somewhat safe indicator for whether the box has been edited.
// Used in validEditText().
auto data = pBox->currentData(Qt::UserRole);
if (data.isValid() && data.toString() == kClearItem) {
pBox->lineEdit()->setPlaceholderText(QString());
pBox->setCurrentIndex(-1); // This clears the edit text
// Remove the Clear item after use.
pBox->removeItem(pBox->findData(kClearItem));
}
if (pBox == txtKey) {
// Since we've blocked change signals we need to trigger
// the key validation manually.
slotKeyTextChanged();
}
pBox->blockSignals(false);
}

void DlgTrackInfoMulti::slotCommentBoxIndexChanged() {
QComboBox* pBox = qobject_cast<QComboBox*>(sender());
VERIFY_OR_DEBUG_ASSERT(pBox && pBox == txtCommentBox) {
return;
}

txtCommentBox->blockSignals(true);
txtComment->setPlaceholderText(QString());
// If we have multiple value we also added the Clear All item.
// If the Clear item has been selected, remove the placeholder
// in order to have a safe indicator in validEditText() whether
// the box has been edited.
auto data = txtCommentBox->currentData(Qt::UserRole);
if (data.isValid() && data.toString() == kClearItem) {
txtCommentBox->setCurrentIndex(-1); // This clears the edit text
// Remove the Clear item after use.
txtCommentBox->removeItem(txtCommentBox->findData(kClearItem));
txtComment->clear();
} else {
txtComment->setPlainText(txtCommentBox->currentText());
}
txtCommentBox->blockSignals(false);
}

void DlgTrackInfoMulti::slotKeyTextChanged() {
// textChanged() is also emitted when the popup is opened.
// No need to validate in that case.
Expand Down
2 changes: 2 additions & 0 deletions src/library/dlgtrackinfomulti.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class DlgTrackInfoMulti : public QDialog, public Ui::DlgTrackInfoMulti {
/// the dialog from all tracks. This discards pending changes.
void slotTrackChanged(TrackId trackId);

void slotTagBoxIndexChanged();
void slotCommentBoxIndexChanged();
void slotKeyTextChanged();

void slotColorButtonClicked();
Expand Down

0 comments on commit 4350b46

Please sign in to comment.