Merge pull request #974 from ctrlaltca/deckeditor
Speed up deck editor filtering
This commit is contained in:
commit
af33ff5b0e
3 changed files with 15 additions and 17 deletions
|
@ -407,6 +407,7 @@ CardInfo::CardInfo(CardDatabase *_db,
|
||||||
tableRow(_tableRow)
|
tableRow(_tableRow)
|
||||||
{
|
{
|
||||||
pixmapCacheKey = QLatin1String("card_") + name;
|
pixmapCacheKey = QLatin1String("card_") + name;
|
||||||
|
simpleName = CardInfo::simplifyName(name);
|
||||||
|
|
||||||
for (int i = 0; i < sets.size(); i++)
|
for (int i = 0; i < sets.size(); i++)
|
||||||
sets[i]->append(this);
|
sets[i]->append(this);
|
||||||
|
@ -660,14 +661,14 @@ void CardDatabase::clear()
|
||||||
void CardDatabase::addCard(CardInfo *card)
|
void CardDatabase::addCard(CardInfo *card)
|
||||||
{
|
{
|
||||||
cards.insert(card->getName(), card);
|
cards.insert(card->getName(), card);
|
||||||
simpleNameCards.insert(CardInfo::simplifyName(card->getName()), card);
|
simpleNameCards.insert(card->getSimpleName(), card);
|
||||||
emit cardAdded(card);
|
emit cardAdded(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDatabase::removeCard(CardInfo *card)
|
void CardDatabase::removeCard(CardInfo *card)
|
||||||
{
|
{
|
||||||
cards.remove(card->getName());
|
cards.remove(card->getName());
|
||||||
simpleNameCards.remove(CardInfo::simplifyName(card->getName()));
|
simpleNameCards.remove(card->getSimpleName());
|
||||||
emit cardRemoved(card);
|
emit cardRemoved(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -142,6 +142,7 @@ public:
|
||||||
MuidMap muids = MuidMap());
|
MuidMap muids = MuidMap());
|
||||||
~CardInfo();
|
~CardInfo();
|
||||||
const QString &getName() const { return name; }
|
const QString &getName() const { return name; }
|
||||||
|
const QString &getSimpleName() const { return simpleName; }
|
||||||
bool getIsToken() const { return isToken; }
|
bool getIsToken() const { return isToken; }
|
||||||
const SetList &getSets() const { return sets; }
|
const SetList &getSets() const { return sets; }
|
||||||
const QString &getManaCost() const { return manacost; }
|
const QString &getManaCost() const { return manacost; }
|
||||||
|
|
|
@ -125,19 +125,16 @@ bool CardDatabaseDisplayModel::lessThan(const QModelIndex &left, const QModelInd
|
||||||
|
|
||||||
if (!cardName.isEmpty())
|
if (!cardName.isEmpty())
|
||||||
{
|
{
|
||||||
// exact match should be at top
|
bool isLeftType = leftString.startsWith(cardName, Qt::CaseInsensitive);
|
||||||
if (leftString.compare(cardName, Qt::CaseInsensitive) == 0)
|
bool isRightType = rightString.startsWith(cardName, Qt::CaseInsensitive);
|
||||||
|
|
||||||
|
// test for an exact match: isLeftType && leftString.size() == cardName.size()
|
||||||
|
// or an exclusive start match: isLeftType && !isRightType
|
||||||
|
if (isLeftType && (!isRightType || leftString.size() == cardName.size()))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// exact match should be at top
|
// same checks for the right string
|
||||||
if (rightString.compare(cardName, Qt::CaseInsensitive) == 0)
|
if (isRightType && (!isLeftType || rightString.size() == cardName.size()))
|
||||||
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 false;
|
||||||
}
|
}
|
||||||
return QString::localeAwareCompare(leftString, rightString) < 0;
|
return QString::localeAwareCompare(leftString, rightString) < 0;
|
||||||
|
@ -150,12 +147,11 @@ bool CardDatabaseDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex
|
||||||
if (((isToken == ShowTrue) && !info->getIsToken()) || ((isToken == ShowFalse) && info->getIsToken()))
|
if (((isToken == ShowTrue) && !info->getIsToken()) || ((isToken == ShowFalse) && info->getIsToken()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!CardInfo::simplifyName(info->getName()).contains(cardName, Qt::CaseInsensitive))
|
if (!cardName.isEmpty() && !info->getSimpleName().contains(cardName, Qt::CaseInsensitive))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!cardNameSet.isEmpty())
|
if (!cardNameSet.isEmpty() && !cardNameSet.contains(info->getName()))
|
||||||
if (!cardNameSet.contains(info->getName()))
|
return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
if (filterTree != NULL)
|
if (filterTree != NULL)
|
||||||
return filterTree->acceptsCard(info);
|
return filterTree->acceptsCard(info);
|
||||||
|
|
Loading…
Reference in a new issue