Fixed card search
Card search will now order the following way: 1. Exact match at top 2. Exact match with preceding values sorted lexically. 3. Match contained in word sorted lexically
This commit is contained in:
parent
90880c8b7e
commit
b5dd7a42ce
2 changed files with 69 additions and 28 deletions
|
@ -117,40 +117,78 @@ CardDatabaseDisplayModel::CardDatabaseDisplayModel(QObject *parent)
|
||||||
setSortCaseSensitivity(Qt::CaseInsensitive);
|
setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool CardDatabaseDisplayModel::lessThan(const QModelIndex &left, const QModelIndex &right) const {
|
||||||
|
|
||||||
|
QString leftString = sourceModel()->data(left).toString();
|
||||||
|
QString rightString = sourceModel()->data(right).toString();
|
||||||
|
|
||||||
|
if (leftString.compare(cardName, Qt::CaseInsensitive) == 0) {// exact match should be at top
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rightString.compare(cardName, Qt::CaseInsensitive) == 0) {// exact match should be at top
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isLeftType2 = leftString.startsWith(cardName, Qt::CaseInsensitive);
|
||||||
|
bool isRightType2 = rightString.startsWith(cardName, Qt::CaseInsensitive);
|
||||||
|
if (isLeftType2 && !isRightType2)
|
||||||
|
return true;
|
||||||
|
if (isRightType2 && !isLeftType2)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return QString::localeAwareCompare(leftString, rightString) < 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
bool CardDatabaseDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex & /*sourceParent*/) const
|
bool CardDatabaseDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex & /*sourceParent*/) const
|
||||||
{
|
{
|
||||||
CardInfo const *info = static_cast<CardDatabaseModel *>(sourceModel())->getCard(sourceRow);
|
CardInfo const *info = static_cast<CardDatabaseModel *>(sourceModel())->getCard(sourceRow);
|
||||||
if (((isToken == ShowTrue) && !info->getIsToken()) || ((isToken == ShowFalse) && info->getIsToken()))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!cardNameBeginning.isEmpty())
|
bool show = false;
|
||||||
if (!info->getName().startsWith(cardNameBeginning, Qt::CaseInsensitive))
|
if (!cardName.isEmpty()) {
|
||||||
return false;
|
if (info->getName().contains(cardName, Qt::CaseInsensitive)) {
|
||||||
|
show = true;
|
||||||
if (!cardName.isEmpty())
|
}
|
||||||
if (!info->getName().contains(cardName, Qt::CaseInsensitive))
|
} else
|
||||||
return false;
|
return true;// search is empty, show all
|
||||||
|
|
||||||
if (!cardNameSet.isEmpty())
|
|
||||||
if (!cardNameSet.contains(info->getName()))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!cardText.isEmpty())
|
|
||||||
if (!info->getText().contains(cardText, Qt::CaseInsensitive))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!cardColors.isEmpty())
|
|
||||||
if (QSet<QString>::fromList(info->getColors()).intersect(cardColors).isEmpty() && !(info->getColors().isEmpty() && cardColors.contains("X")))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!cardTypes.isEmpty())
|
|
||||||
if (!cardTypes.contains(info->getMainCardType()))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (filterTree != NULL)
|
return show; // term was not found
|
||||||
return filterTree->acceptsCard(info);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
|
//if (((isToken == ShowTrue) && !info->getIsToken()) || ((isToken == ShowFalse) && info->getIsToken()))
|
||||||
|
// return false;
|
||||||
|
//
|
||||||
|
//if (!cardNameBeginning.isEmpty())
|
||||||
|
// if (!info->getName().startsWith(cardNameBeginning, Qt::CaseInsensitive))
|
||||||
|
// return false;
|
||||||
|
//
|
||||||
|
//if (!cardName.isEmpty())
|
||||||
|
// if (!info->getName().contains(cardName, Qt::CaseInsensitive))
|
||||||
|
// return false;
|
||||||
|
//
|
||||||
|
//if (!cardNameSet.isEmpty())
|
||||||
|
// if (!cardNameSet.contains(info->getName()))
|
||||||
|
// return false;
|
||||||
|
//
|
||||||
|
//if (!cardText.isEmpty())
|
||||||
|
// if (!info->getText().contains(cardText, Qt::CaseInsensitive))
|
||||||
|
// return false;
|
||||||
|
//
|
||||||
|
//if (!cardColors.isEmpty())
|
||||||
|
// if (QSet<QString>::fromList(info->getColors()).intersect(cardColors).isEmpty() && !(info->getColors().isEmpty() && cardColors.contains("X")))
|
||||||
|
// return false;
|
||||||
|
//
|
||||||
|
//if (!cardTypes.isEmpty())
|
||||||
|
// if (!cardTypes.contains(info->getMainCardType()))
|
||||||
|
// return false;
|
||||||
|
|
||||||
|
//if (filterTree != NULL)
|
||||||
|
// return filterTree->acceptsCard(info);
|
||||||
|
|
||||||
|
//return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDatabaseDisplayModel::clearSearch()
|
void CardDatabaseDisplayModel::clearSearch()
|
||||||
|
|
|
@ -37,6 +37,7 @@ public:
|
||||||
private:
|
private:
|
||||||
FilterBool isToken;
|
FilterBool isToken;
|
||||||
QString cardNameBeginning, cardName, cardText;
|
QString cardNameBeginning, cardName, cardText;
|
||||||
|
QString searchTerm;
|
||||||
QSet<QString> cardNameSet, cardTypes, cardColors;
|
QSet<QString> cardNameSet, cardTypes, cardColors;
|
||||||
FilterTree *filterTree;
|
FilterTree *filterTree;
|
||||||
public:
|
public:
|
||||||
|
@ -46,11 +47,13 @@ public:
|
||||||
void setCardNameBeginning(const QString &_beginning) { cardNameBeginning = _beginning; invalidate(); }
|
void setCardNameBeginning(const QString &_beginning) { cardNameBeginning = _beginning; invalidate(); }
|
||||||
void setCardName(const QString &_cardName) { cardName = _cardName; invalidate(); }
|
void setCardName(const QString &_cardName) { cardName = _cardName; invalidate(); }
|
||||||
void setCardNameSet(const QSet<QString> &_cardNameSet) { cardNameSet = _cardNameSet; invalidate(); }
|
void setCardNameSet(const QSet<QString> &_cardNameSet) { cardNameSet = _cardNameSet; invalidate(); }
|
||||||
|
void setSearchTerm(const QString &_searchTerm) { searchTerm = _searchTerm; }
|
||||||
void setCardText(const QString &_cardText) { cardText = _cardText; invalidate(); }
|
void setCardText(const QString &_cardText) { cardText = _cardText; invalidate(); }
|
||||||
void setCardTypes(const QSet<QString> &_cardTypes) { cardTypes = _cardTypes; invalidate(); }
|
void setCardTypes(const QSet<QString> &_cardTypes) { cardTypes = _cardTypes; invalidate(); }
|
||||||
void setCardColors(const QSet<QString> &_cardColors) { cardColors = _cardColors; invalidate(); }
|
void setCardColors(const QSet<QString> &_cardColors) { cardColors = _cardColors; invalidate(); }
|
||||||
void clearSearch();
|
void clearSearch();
|
||||||
protected:
|
protected:
|
||||||
|
bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
|
||||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
||||||
private slots:
|
private slots:
|
||||||
void filterTreeChanged();
|
void filterTreeChanged();
|
||||||
|
|
Loading…
Reference in a new issue