From 8dd8b434b21bada2d6af1ac914bab439c7b42bb8 Mon Sep 17 00:00:00 2001 From: Mark McDonald Date: Wed, 11 May 2016 21:30:14 -0400 Subject: [PATCH] Make "create token" dialog's card name a filter * There is a circular update loop I had to cut off where the name field updates the filter and then the currentRowChanged signal is firing without a row. * I chose to make a private method to show intent instead of relying on other QLineEdit methods (textEdited) that don't fire signals. * Some other shenanigans may be at hand that are causing this workaround, but my familiarity with Qt is pretty low. --- cockatrice/src/dlg_create_token.cpp | 14 +++++++++++++- cockatrice/src/dlg_create_token.h | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cockatrice/src/dlg_create_token.cpp b/cockatrice/src/dlg_create_token.cpp index 02c867bb..7bf320ed 100644 --- a/cockatrice/src/dlg_create_token.cpp +++ b/cockatrice/src/dlg_create_token.cpp @@ -23,6 +23,7 @@ DlgCreateToken::DlgCreateToken(const QStringList &_predefinedTokens, QWidget *pa nameLabel = new QLabel(tr("&Name:")); nameEdit = new QLineEdit(tr("Token")); nameEdit->selectAll(); + connect(nameEdit, SIGNAL(textChanged(const QString &)), this, SLOT(updateSearch(const QString &))); nameLabel->setBuddy(nameEdit); colorLabel = new QLabel(tr("C&olor:")); @@ -135,7 +136,7 @@ void DlgCreateToken::tokenSelectionChanged(const QModelIndex ¤t, const QMo if(cardInfo) { - nameEdit->setText(cardInfo->getName()); + updateSearchFieldWithoutUpdatingFilter(cardInfo->getName()); const QChar cardColor = cardInfo->getColorChar(); colorEdit->setCurrentIndex(colorEdit->findData(cardColor, Qt::UserRole, Qt::MatchFixedString)); ptEdit->setText(cardInfo->getPowTough()); @@ -149,6 +150,17 @@ void DlgCreateToken::tokenSelectionChanged(const QModelIndex ¤t, const QMo } } +void DlgCreateToken::updateSearchFieldWithoutUpdatingFilter(const QString &newValue) const { + nameEdit->blockSignals(true); + nameEdit->setText(newValue); + nameEdit->blockSignals(false); +} + +void DlgCreateToken::updateSearch(const QString &search) +{ + cardDatabaseDisplayModel->setCardName(search); +} + void DlgCreateToken::actChooseTokenFromAll(bool checked) { if (checked) diff --git a/cockatrice/src/dlg_create_token.h b/cockatrice/src/dlg_create_token.h index 26589742..ec212471 100644 --- a/cockatrice/src/dlg_create_token.h +++ b/cockatrice/src/dlg_create_token.h @@ -25,6 +25,7 @@ public: bool getDestroy() const; private slots: void tokenSelectionChanged(const QModelIndex ¤t, const QModelIndex &previous); + void updateSearch(const QString &search); void actChooseTokenFromAll(bool checked); void actChooseTokenFromDeck(bool checked); void actOk(); @@ -37,6 +38,8 @@ private: QLineEdit *nameEdit, *ptEdit, *annotationEdit; QCheckBox *destroyCheckBox; QRadioButton *chooseTokenFromAllRadioButton, *chooseTokenFromDeckRadioButton; + + void updateSearchFieldWithoutUpdatingFilter(const QString &newValue) const; }; #endif