Merge pull request #1981 from MarkyMarkMcDonald/feature/create-token-dialog-uses-name-as-search

Create token dialog uses name as search
This commit is contained in:
ctrlaltca 2016-05-17 21:49:49 +02:00
commit cf3e172d25
4 changed files with 22 additions and 4 deletions

View file

@ -186,6 +186,10 @@ bool CardDatabaseDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex
if (((isToken == ShowTrue) && !info->getIsToken()) || ((isToken == ShowFalse) && info->getIsToken()))
return false;
return rowMatchesCardName(info);
}
bool CardDatabaseDisplayModel::rowMatchesCardName(CardInfo const *info) const {
if (!cardName.isEmpty() && !info->getName().contains(cardName, Qt::CaseInsensitive))
return false;
@ -233,8 +237,7 @@ TokenDisplayModel::TokenDisplayModel(QObject *parent)
bool TokenDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex & /*sourceParent*/) const
{
CardInfo const *info = static_cast<CardDatabaseModel *>(sourceModel())->getCard(sourceRow);
return info->getIsToken();
return info->getIsToken() && rowMatchesCardName(info);
}
int TokenDisplayModel::rowCount(const QModelIndex &parent) const

View file

@ -61,7 +61,7 @@ public:
protected:
bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
bool rowMatchesCardName(CardInfo const *info) const;
bool canFetchMore(const QModelIndex &parent) const;
void fetchMore(const QModelIndex &parent);
private slots:

View file

@ -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:"));
@ -132,7 +133,7 @@ void DlgCreateToken::tokenSelectionChanged(const QModelIndex &current, 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());
@ -146,6 +147,17 @@ void DlgCreateToken::tokenSelectionChanged(const QModelIndex &current, 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)

View file

@ -25,6 +25,7 @@ public:
bool getDestroy() const;
private slots:
void tokenSelectionChanged(const QModelIndex &current, 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