From 90655ff631eb6c19c2976dd5e4a5e7100de78707 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Wed, 22 Jul 2015 17:35:44 +0200 Subject: [PATCH 1/2] Prefer enabled sets when loading images; fix #1235 --- cockatrice/src/carddatabase.cpp | 38 ++++++++++++++++++++++++++++++--- cockatrice/src/carddatabase.h | 4 +++- cockatrice/src/window_sets.cpp | 2 +- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/cockatrice/src/carddatabase.cpp b/cockatrice/src/carddatabase.cpp index 4291e9d6..fe0fe122 100644 --- a/cockatrice/src/carddatabase.cpp +++ b/cockatrice/src/carddatabase.cpp @@ -92,7 +92,7 @@ void CardSet::setIsKnown(bool _isknown) settings.setValue("isknown", isknown); } -class SetList::CompareFunctor { +class SetList::KeyCompareFunctor { public: inline bool operator()(CardSet *a, CardSet *b) const { @@ -102,7 +102,39 @@ public: void SetList::sortByKey() { - qSort(begin(), end(), CompareFunctor()); + qSort(begin(), end(), KeyCompareFunctor()); +} + +class SetList::EnabledAndKeyCompareFunctor { +public: + inline bool operator()(CardSet *a, CardSet *b) const + { + if(a->getEnabled()) + { + if(b->getEnabled()) + { + // both enabled: sort by key + return a->getSortKey() < b->getSortKey(); + } else { + // only a enabled + return true; + } + } else { + if(b->getEnabled()) + { + // only b enabled + return false; + } else { + // both disabled: sort by key + return a->getSortKey() < b->getSortKey(); + } + } + } +}; + +void SetList::sortByEnabledAndKey() +{ + qSort(begin(), end(), EnabledAndKeyCompareFunctor()); } int SetList::getEnabledSetsNum() @@ -185,7 +217,7 @@ PictureToLoad::PictureToLoad(CardInfo *_card, bool _hq) { if (card) { sortedSets = card->getSets(); - sortedSets.sortByKey(); + sortedSets.sortByEnabledAndKey(); } } diff --git a/cockatrice/src/carddatabase.h b/cockatrice/src/carddatabase.h index ac34f081..df3995da 100644 --- a/cockatrice/src/carddatabase.h +++ b/cockatrice/src/carddatabase.h @@ -54,8 +54,10 @@ public: class SetList : public QList { private: - class CompareFunctor; + class KeyCompareFunctor; + class EnabledAndKeyCompareFunctor; public: + void sortByEnabledAndKey(); void sortByKey(); void guessSortKeys(); void enableAllUnknown(); diff --git a/cockatrice/src/window_sets.cpp b/cockatrice/src/window_sets.cpp index b2c9ce3c..4df5d9b2 100644 --- a/cockatrice/src/window_sets.cpp +++ b/cockatrice/src/window_sets.cpp @@ -92,7 +92,7 @@ WndSets::WndSets(QWidget *parent) QLabel *labNotes = new QLabel; - labNotes->setText("" + tr("hints:") + "" + ""); + labNotes->setText("" + tr("hints:") + "" + ""); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); connect(buttonBox, SIGNAL(accepted()), this, SLOT(actSave())); From a001238b749859a4a4dfede712aed970bc09258e Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Sun, 26 Jul 2015 11:46:09 +0200 Subject: [PATCH 2/2] Force cache clear on sets database save. --- cockatrice/src/carddatabase.cpp | 2 ++ cockatrice/src/window_sets.cpp | 1 + 2 files changed, 3 insertions(+) diff --git a/cockatrice/src/carddatabase.cpp b/cockatrice/src/carddatabase.cpp index fe0fe122..3804fe8d 100644 --- a/cockatrice/src/carddatabase.cpp +++ b/cockatrice/src/carddatabase.cpp @@ -889,6 +889,8 @@ void CardDatabase::clearPixmapCache() } if (noCard) noCard->clearPixmapCache(); + + QPixmapCache::clear(); } void CardDatabase::loadSetsFromXml(QXmlStreamReader &xml) diff --git a/cockatrice/src/window_sets.cpp b/cockatrice/src/window_sets.cpp index 4df5d9b2..890688cf 100644 --- a/cockatrice/src/window_sets.cpp +++ b/cockatrice/src/window_sets.cpp @@ -123,6 +123,7 @@ WndSets::~WndSets() void WndSets::actSave() { model->save(db); + db->clearPixmapCache(); QMessageBox::information(this, tr("Success"), tr("The sets database has been saved successfully.")); close(); }