From be70916e11f52ee563c5784836df675c9b016ab4 Mon Sep 17 00:00:00 2001 From: Gareth Pye Date: Tue, 3 Jan 2017 10:11:03 +1100 Subject: [PATCH] now sorting last selected set to top --- oraclecard.cpp | 11 ++++++----- oraclecard.h | 16 +++++++++++++--- pcmwindow.cpp | 40 ++++++++++++++++++++++++++++------------ setchoice.cpp | 6 +++--- 4 files changed, 50 insertions(+), 23 deletions(-) diff --git a/oraclecard.cpp b/oraclecard.cpp index 221f8fc..8d8bdbc 100644 --- a/oraclecard.cpp +++ b/oraclecard.cpp @@ -3,12 +3,13 @@ #include QString OracleCard::sImagePath = "/tmp/"; +QString OracleSet::sImagePath = "/tmp/"; QString OracleCard::getImagePath() const { - QDir path(QString("%1/%2").arg(sImagePath).arg(sMCISID)); + QDir path(QString("%1/%2").arg(sImagePath).arg(mySet->sMCISID)); path.mkpath("."); - return QString("%3/%1/%2.jpg").arg(sMCISID).arg(sSequenceNumber).arg(sImagePath); + return QString("%3/%1/%2.jpg").arg(mySet->sMCISID).arg(sSequenceNumber).arg(sImagePath); } QString OracleCard::getImageURL() const @@ -16,14 +17,14 @@ QString OracleCard::getImageURL() const return QString("http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=%1&type=card").arg(iMultiverseID); } -QString OracleCard::getLogoPath() const +QString OracleSet::getLogoPath(char cRarity) const { QDir path(QString("%1/%2").arg(sImagePath).arg(sMCISID)); path.mkpath("."); return QString("%3/%1/%2.jpg").arg(sMCISID).arg(cRarity).arg(sImagePath); //path makes sense because it will also have all the card images in that folder, not just the few rarities } -QString OracleCard::getLogoURL() const +QString OracleSet::getLogoURL(char cRarity) const { return QString("http://gatherer.wizards.com/Handlers/Image.ashx?type=symbol&set=%1&size=large&rarity=%2").arg(sGSID).arg(cRarity); } @@ -40,7 +41,7 @@ QString OracleCard::deckBoxInventoryLine(bool Foil) const if(sName.at(0) != '\"') //only if it doesn't start with a " already sName = QString("\"") + sName + "\""; - QString sSetLocal = this->sMySet; + QString sSetLocal = this->mySet->sMySet; if(sSetLocal == QString("Planechase 2012 Edition")) sSetLocal = "Planechase 2012"; if(sSetLocal == QString("Magic: The Gathering-Commander")) diff --git a/oraclecard.h b/oraclecard.h index 3281dcc..530dac5 100644 --- a/oraclecard.h +++ b/oraclecard.h @@ -2,19 +2,29 @@ #define ORACLECARD_H #include +#include + +class OracleSet +{ +public: + QString sMySet, sMCISID, sGSID; + QString getLogoPath(char cRarity) const; + QString getLogoURL(char cRarity) const; + QDateTime LastSelected; + static QString sImagePath; +}; class OracleCard { public: + OracleSet *mySet; quint64 iMultiverseID; - QString sNameEn, sMySet, sMCISID, sSequenceNumber, sGSID; + QString sNameEn, sSequenceNumber; char cRarity; double dValue; static QString sImagePath; QString getImagePath() const; QString getImageURL() const; - QString getLogoPath() const; - QString getLogoURL() const; QString deckBoxInventoryLine(bool Foil) const; }; #endif // ORACLECARD_H diff --git a/pcmwindow.cpp b/pcmwindow.cpp index 852a3fb..329a7e2 100644 --- a/pcmwindow.cpp +++ b/pcmwindow.cpp @@ -240,7 +240,7 @@ void PCMWindow::HandleSingleCard(OracleCard card) StatusString(QString("Trade: %1 ($%2)").arg(invRegularCard.sMyName).arg((isFoil() ? invFoilCard : invRegularCard).dMyMarketPrice)); mySound.setMedia(qCoins); mySound.play(); - fMyTradesOutput << "1,\"" << card.sNameEn << "\",\"" << card.sMySet << "\",Near Mint,English,"; + fMyTradesOutput << "1,\"" << card.sNameEn << "\",\"" << card.mySet->sMySet << "\",Near Mint,English,"; if(isFoil()) fMyTradesOutput << "Foil"; fMyTradesOutput << "\n"; @@ -272,6 +272,11 @@ bool quint64GreaterThan(const quint64 &v1, const quint64 &v2) { return v1 > v2; } +bool oracleCardGreaterThan(const OracleCard &v1, const OracleCard &v2) +{ + return v1.mySet->LastSelected > v2.mySet->LastSelected; + return v1.iMultiverseID > v2.iMultiverseID; +} void PCMWindow::HandleMultipleCards(OracleCard card, QList lCardIDs) { ui->cardAction->setText("Multiple Versions"); @@ -304,14 +309,18 @@ void PCMWindow::HandleMultipleCards(OracleCard card, QList lCardIDs) //As we haven't been able to trash the card, now we must determine what set it is from QGridLayout *MySetSelectorLayout = new QGridLayout(); - //we want the list to sort most recent set first, greatest multiverseID first is a close aproximation of that - qSort(lCardIDs.begin(), lCardIDs.end(), quint64GreaterThan); - - int count = 0; + //we want the list to sort most recent selected set first, then most recently printed. + QList OracleCards; for(auto&& CardID: lCardIDs) { OracleCard priceCard = qmOracle.value(CardID); + OracleCards.append(priceCard); + } + qSort(OracleCards.begin(), OracleCards.end(), oracleCardGreaterThan); + int count = 0; + for(auto&& priceCard: OracleCards) + { SetChoice *thisChoice = new SetChoice(priceCard, MySetSelectorLayout->widget()); thisChoice->setParent(MySetSelectorLayout->widget()); MySetSelectorLayout->addWidget((QWidget*)thisChoice, count % 10, count / 10); @@ -326,6 +335,7 @@ void PCMWindow::setSelected() { SetChoice *set = (SetChoice*)this->sender(); OracleCard card = set->MyCard; + card.mySet->LastSelected = QDateTime::currentDateTime(); //sort this to the top now. HandleSingleCard(card); CleanSetSelection(); @@ -441,6 +451,7 @@ void PCMWindow::on_pbOpenDatabase_clicked() qmOracle.clear(); OracleCard::sImagePath = ui->imageLocationLineEdit->text(); + OracleSet::sImagePath = ui->imageLocationLineEdit->text(); QFile fInput(ui->cardDatabaseLocationLineEdit->text()); if(fInput.open(QIODevice::ReadOnly | QIODevice::Text)) @@ -475,6 +486,13 @@ void PCMWindow::on_pbOpenDatabase_clicked() else sGSID = jSet["gathererCode"].toString(); + OracleSet *ThisSet = new OracleSet; + ThisSet->sMySet = jSet["name"].toString(); + ThisSet->sMCISID = sMCISID; + ThisSet->sGSID = sGSID; + ThisSet->LastSelected = QDateTime::currentDateTime(); + + for(auto&& cardIter: jCards) { QJsonObject jCard = cardIter.toObject(); @@ -517,9 +535,7 @@ void PCMWindow::on_pbOpenDatabase_clicked() //int iasf = 999; card.cRarity = jCard["rarity"].toString().at(0).toLatin1(); - card.sMySet = jSet["name"].toString(); - card.sMCISID = sMCISID; - card.sGSID = sGSID; + card.mySet = ThisSet; qmmMultiInverse.insert(sName, iID); //note this is now a Multi Map, this insert will never replace qmOracle.insert(iID, card); @@ -552,13 +568,13 @@ void PCMWindow::on_pbFullCardListDB_clicked() continue; //Deckbox doesn't like how we would generate tokens if(card.sNameEn.contains(QString("Big Furry Monster"), Qt::CaseInsensitive)) continue; //Deckbox doesn't like how we generate this name - if(card.sMySet.contains(QString("Tempest Remastered"), Qt::CaseInsensitive)) + if(card.mySet->sMySet.contains(QString("Tempest Remastered"), Qt::CaseInsensitive)) continue; //Not real cards - if(card.sMySet.contains(QString("Vintage Masters"), Qt::CaseInsensitive)) + if(card.mySet->sMySet.contains(QString("Vintage Masters"), Qt::CaseInsensitive)) continue; //Not real cards - if(card.sMySet.contains(QString("Vanguard"), Qt::CaseInsensitive)) + if(card.mySet->sMySet.contains(QString("Vanguard"), Qt::CaseInsensitive)) continue; //Deckbox doesn't like how we would Avatars - if(card.sMySet.contains(QString("Masters Edition"), Qt::CaseInsensitive)) + if(card.mySet->sMySet.contains(QString("Masters Edition"), Qt::CaseInsensitive)) continue; //Deckbox doesn't like how we would Avatars fFullCardListOutput << card.deckBoxInventoryLine(false); fFullCardListOutput << card.deckBoxInventoryLine(true); diff --git a/setchoice.cpp b/setchoice.cpp index 23e0d9c..f704c34 100644 --- a/setchoice.cpp +++ b/setchoice.cpp @@ -7,14 +7,14 @@ SetChoice::SetChoice(OracleCard Card, QWidget *parent) : QPushButton(parent), MyCard(Card), manager(0) { - setText(MyCard.sMySet); + setText(MyCard.mySet->sMySet); setFlat(true); QPalette pal = palette(); pal.setColor(QPalette::Button, QColor(Qt::white)); setAutoFillBackground(true); setPalette(pal); - QString sIconPath = MyCard.getLogoPath(); + QString sIconPath = MyCard.mySet->getLogoPath(MyCard.cRarity); QFileInfo ImageFileInfo(sIconPath); if(ImageFileInfo.exists() && ImageFileInfo.isFile()) { @@ -25,7 +25,7 @@ SetChoice::SetChoice(OracleCard Card, QWidget *parent) : QPushButton(parent), My setIcon(QIcon()); manager = new QNetworkAccessManager(); connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(ImageFetchFinished(QNetworkReply*))); - manager->get(QNetworkRequest(QUrl(MyCard.getLogoURL()))); + manager->get(QNetworkRequest(QUrl(MyCard.mySet->getLogoURL(MyCard.cRarity)))); sMyImageRequested = sIconPath; } }