diff --git a/cockatrice/src/carddatabase.cpp b/cockatrice/src/carddatabase.cpp index 3adc8d25..5fbf81c5 100644 --- a/cockatrice/src/carddatabase.cpp +++ b/cockatrice/src/carddatabase.cpp @@ -33,7 +33,7 @@ static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardSet *set) CardSet::CardSet(const QString &_shortName, const QString &_longName, const QString &_setType, const QDate &_releaseDate) : shortName(_shortName), longName(_longName), releaseDate(_releaseDate), setType(_setType) { - updateSortKey(); + loadSetOptions(); } QString CardSet::getCorrectedShortName() const @@ -58,12 +58,36 @@ void CardSet::setSortKey(unsigned int _sortKey) settings.setValue("sortkey", sortKey); } -void CardSet::updateSortKey() +void CardSet::loadSetOptions() { QSettings settings; settings.beginGroup("sets"); settings.beginGroup(shortName); + sortKey = settings.value("sortkey", 0).toInt(); + enabled = settings.value("enabled", false).toBool(); + isknown = settings.value("isknown", false).toBool(); + // qDebug() << "load set" << shortName << "key" << sortKey; +} + +void CardSet::setEnabled(bool _enabled) +{ + enabled = _enabled; + + QSettings settings; + settings.beginGroup("sets"); + settings.beginGroup(shortName); + settings.setValue("enabled", enabled); +} + +void CardSet::setIsKnown(bool _isknown) +{ + isknown = _isknown; + + QSettings settings; + settings.beginGroup("sets"); + settings.beginGroup(shortName); + settings.setValue("isknown", isknown); } class SetList::CompareFunctor { @@ -79,6 +103,81 @@ void SetList::sortByKey() qSort(begin(), end(), CompareFunctor()); } +int SetList::getEnabledSetsNum() +{ + int num=0; + for (int i = 0; i < size(); ++i) + { + CardSet *set = at(i); + if(set->getEnabled()) + ++num; + } + return num; +} + +int SetList::getUnknownSetsNum() +{ + int num=0; + for (int i = 0; i < size(); ++i) + { + CardSet *set = at(i); + if(!set->getIsKnown()) + ++num; + } + return num; +} + +void SetList::enableAllUnknown() +{ + for (int i = 0; i < size(); ++i) + { + CardSet *set = at(i); + if(!set->getIsKnown()) + { + set->setIsKnown(true); + set->setEnabled(true); + } + } +} + +void SetList::enableAll() +{ + for (int i = 0; i < size(); ++i) + { + CardSet *set = at(i); + set->setIsKnown(true); + set->setEnabled(true); + } +} + +void SetList::markAllAsKnown() +{ + for (int i = 0; i < size(); ++i) + { + CardSet *set = at(i); + if(!set->getIsKnown()) + { + set->setIsKnown(true); + } + } +} + +void SetList::guessSortKeys() +{ + // sort by release date DESC; invalid dates to the bottom. + QDate distantFuture(2050, 1, 1); + int aHundredYears = 36500; + for (int i = 0; i < size(); ++i) + { + CardSet *set = at(i); + QDate date = set->getReleaseDate(); + if(date.isNull()) + set->setSortKey(aHundredYears); + else + set->setSortKey(date.daysTo(distantFuture)); + } +} + PictureToLoad::PictureToLoad(CardInfo *_card, bool _hq) : card(_card), setIndex(0), hq(_hq) { @@ -512,7 +611,7 @@ void CardInfo::getPixmap(QSize size, QPixmap &pixmap) void CardInfo::clearPixmapCache() { - qDebug() << "Deleting pixmap for" << name; + //qDebug() << "Deleting pixmap for" << name; QPixmapCache::remove(pixmapCacheKey); } @@ -736,7 +835,11 @@ void CardDatabase::loadSetsFromXml(QXmlStreamReader &xml) else if (xml.name() == "releasedate") releaseDate = QDate::fromString(xml.readElementText(), Qt::ISODate); } - sets.insert(shortName, new CardSet(shortName, longName, setType, releaseDate)); + + CardSet * newSet = getSet(shortName); + newSet->setLongName(longName); + newSet->setSetType(setType); + newSet->setReleaseDate(releaseDate); } } } @@ -907,6 +1010,11 @@ void CardDatabase::picDownloadHqChanged() } } +void CardDatabase::emitCardListChanged() +{ + emit cardListChanged(); +} + LoadStatus CardDatabase::loadCardDatabase(const QString &path, bool tokens) { LoadStatus tempLoadStatus = NotLoaded; @@ -919,8 +1027,6 @@ LoadStatus CardDatabase::loadCardDatabase(const QString &path, bool tokens) while (setsIterator.hasNext()) allSets.append(setsIterator.next().value()); allSets.sortByKey(); - for (int i = 0; i < allSets.size(); ++i) - allSets[i]->setSortKey(i); emit cardListChanged(); } diff --git a/cockatrice/src/carddatabase.h b/cockatrice/src/carddatabase.h index 9b3b622c..080a136e 100644 --- a/cockatrice/src/carddatabase.h +++ b/cockatrice/src/carddatabase.h @@ -31,6 +31,7 @@ private: unsigned int sortKey; QDate releaseDate; QString setType; + bool enabled, isknown; public: CardSet(const QString &_shortName = QString(), const QString &_longName = QString(), const QString &_setType = QString(), const QDate &_releaseDate = QDate()); QString getCorrectedShortName() const; @@ -38,9 +39,17 @@ public: QString getLongName() const { return longName; } QString getSetType() const { return setType; } QDate getReleaseDate() const { return releaseDate; } + void setLongName(QString & _longName) { longName = _longName; } + void setSetType(QString & _setType) { setType = _setType; } + void setReleaseDate(QDate & _releaseDate) { releaseDate = _releaseDate; } + + void loadSetOptions(); int getSortKey() const { return sortKey; } void setSortKey(unsigned int _sortKey); - void updateSortKey(); + bool getEnabled() const { return enabled; } + void setEnabled(bool _enabled); + bool getIsKnown() const { return isknown; } + void setIsKnown(bool _isknown); }; class SetList : public QList { @@ -48,6 +57,12 @@ private: class CompareFunctor; public: void sortByKey(); + void guessSortKeys(); + void enableAllUnknown(); + void enableAll(); + void markAllAsKnown(); + int getEnabledSetsNum(); + int getUnknownSetsNum(); }; class PictureToLoad { @@ -253,6 +268,7 @@ public: public slots: void clearPixmapCache(); LoadStatus loadCardDatabase(const QString &path, bool tokens = false); + void emitCardListChanged(); private slots: void imageLoaded(CardInfo *card, QImage image); void picDownloadChanged(); diff --git a/cockatrice/src/carddatabasemodel.cpp b/cockatrice/src/carddatabasemodel.cpp index 9562398c..70502cdd 100644 --- a/cockatrice/src/carddatabasemodel.cpp +++ b/cockatrice/src/carddatabasemodel.cpp @@ -42,7 +42,10 @@ QVariant CardDatabaseModel::data(const QModelIndex &index, int role) const QStringList setList; const QList &sets = card->getSets(); for (int i = 0; i < sets.size(); i++) - setList << sets[i]->getShortName(); + { + if(sets[i]->getEnabled()) + setList << sets[i]->getShortName(); + } return setList.join(", "); } case ManaCostColumn: return role == SortRole ? @@ -77,9 +80,26 @@ void CardDatabaseModel::updateCardList() for (int i = 0; i < cardList.size(); ++i) disconnect(cardList[i], 0, this, 0); - cardList = db->getCardList(); - for (int i = 0; i < cardList.size(); ++i) - connect(cardList[i], SIGNAL(cardInfoChanged(CardInfo *)), this, SLOT(cardInfoChanged(CardInfo *))); + cardList.clear(); + + foreach(CardInfo * card, db->getCardList()) + { + bool hasSet = false; + foreach(CardSet * set, card->getSets()) + { + if(set->getEnabled()) + { + hasSet = true; + break; + } + } + + if(hasSet) + { + cardList.append(card); + connect(card, SIGNAL(cardInfoChanged(CardInfo *)), this, SLOT(cardInfoChanged(CardInfo *))); + } + } endResetModel(); } diff --git a/cockatrice/src/setsmodel.cpp b/cockatrice/src/setsmodel.cpp index bd6dc006..18f6797c 100644 --- a/cockatrice/src/setsmodel.cpp +++ b/cockatrice/src/setsmodel.cpp @@ -4,6 +4,11 @@ SetsModel::SetsModel(CardDatabase *_db, QObject *parent) : QAbstractTableModel(parent), sets(_db->getSetList()) { sets.sortByKey(); + foreach(CardSet *set, sets) + { + if(set->getEnabled()) + enabledSets.insert(set); + } } SetsModel::~SetsModel() @@ -20,12 +25,20 @@ int SetsModel::rowCount(const QModelIndex &parent) const QVariant SetsModel::data(const QModelIndex &index, int role) const { - if (!index.isValid() || (index.column() >= NUM_COLS) || (index.row() >= rowCount()) || (role != Qt::DisplayRole)) + if (!index.isValid() || (index.column() >= NUM_COLS) || (index.row() >= rowCount())) return QVariant(); CardSet *set = sets[index.row()]; + + if ( role == Qt::CheckStateRole && index.column() == EnabledCol ) + return static_cast< int >( enabledSets.contains(set) ? Qt::Checked : Qt::Unchecked ); + + if (role != Qt::DisplayRole) + return QVariant(); + switch (index.column()) { - case SortKeyCol: return QString("%1").arg(set->getSortKey(), 4, 10, QChar('0')); + case SortKeyCol: return QString("%1").arg(set->getSortKey(), 8, 10, QChar('0')); + case IsKnownCol: return set->getIsKnown(); case SetTypeCol: return set->getSetType(); case ShortNameCol: return set->getShortName(); case LongNameCol: return set->getLongName(); @@ -34,12 +47,24 @@ QVariant SetsModel::data(const QModelIndex &index, int role) const } } +bool SetsModel::setData(const QModelIndex & index, const QVariant & value, int role) +{ + if (role == Qt::CheckStateRole && index.column () == EnabledCol) + { + toggleRow(index.row(), value == Qt::Checked); + return true; + } + return false; +} + QVariant SetsModel::headerData(int section, Qt::Orientation orientation, int role) const { if ((role != Qt::DisplayRole) || (orientation != Qt::Horizontal)) return QVariant(); switch (section) { case SortKeyCol: return tr("Key"); + case IsKnownCol: return tr("Is known"); + case EnabledCol: return tr("Enabled"); case SetTypeCol: return tr("Set type"); case ShortNameCol: return tr("Set code"); case LongNameCol: return tr("Long name"); @@ -50,8 +75,17 @@ QVariant SetsModel::headerData(int section, Qt::Orientation orientation, int rol Qt::ItemFlags SetsModel::flags(const QModelIndex &index) const { - Qt::ItemFlags result = QAbstractTableModel::flags(index); - return result | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; + if (!index.isValid()) + return 0; + + Qt::ItemFlags flags = QAbstractTableModel::flags(index) | + Qt::ItemIsDragEnabled | + Qt::ItemIsDropEnabled; + + if ( index.column() == EnabledCol) + flags |= Qt::ItemIsUserCheckable; + + return flags; } Qt::DropActions SetsModel::supportedDropActions() const @@ -86,6 +120,30 @@ bool SetsModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int r return true; } +void SetsModel::toggleRow(int row, bool enable) +{ + CardSet *temp = sets.at(row); + + if(enable) + enabledSets.insert(temp); + else + enabledSets.remove(temp); + + emit dataChanged(index(row, EnabledCol), index(row, EnabledCol)); +} + +void SetsModel::toggleAll(bool enable) +{ + enabledSets.clear(); + if(enable) + { + foreach(CardSet *set, sets) + enabledSets.insert(set); + } + + emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); +} + void SetsModel::swapRows(int oldRow, int newRow) { beginRemoveRows(QModelIndex(), oldRow, oldRow); @@ -124,19 +182,35 @@ void SetsModel::sort(int column, Qt::SortOrder order) emit dataChanged(index(0, 0), index(numRows - 1, columnCount() - 1)); } -void SetsModel::save() +void SetsModel::save(CardDatabase *db) { + // order for (int i = 0; i < sets.size(); i++) - sets[i]->setSortKey(i); + sets[i]->setSortKey(i+1); + + // enabled sets + foreach(CardSet *set, sets) + set->setEnabled(enabledSets.contains(set)); sets.sortByKey(); + + db->emitCardListChanged(); } void SetsModel::restore(CardDatabase *db) { + // order sets = db->getSetList(); sets.sortByKey(); + // enabled sets + enabledSets.clear(); + foreach(CardSet *set, sets) + { + if(set->getEnabled()) + enabledSets.insert(set); + } + emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } diff --git a/cockatrice/src/setsmodel.h b/cockatrice/src/setsmodel.h index 8655fe88..d5791820 100644 --- a/cockatrice/src/setsmodel.h +++ b/cockatrice/src/setsmodel.h @@ -3,6 +3,7 @@ #include #include +#include #include "carddatabase.h" class SetsProxyModel; @@ -21,16 +22,18 @@ class SetsModel : public QAbstractTableModel { Q_OBJECT friend class SetsProxyModel; private: - static const int NUM_COLS = 5; + static const int NUM_COLS = 7; SetList sets; + QSet enabledSets; public: - enum SetsColumns { SortKeyCol, LongNameCol, ShortNameCol, SetTypeCol, ReleaseDateCol }; + enum SetsColumns { SortKeyCol, IsKnownCol, EnabledCol, LongNameCol, ShortNameCol, SetTypeCol, ReleaseDateCol }; SetsModel(CardDatabase *_db, QObject *parent = 0); ~SetsModel(); int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const { Q_UNUSED(parent); return NUM_COLS; } QVariant data(const QModelIndex &index, int role) const; + bool setData(const QModelIndex & index, const QVariant & value, int role); QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; Qt::ItemFlags flags(const QModelIndex &index) const; Qt::DropActions supportedDropActions() const; @@ -39,8 +42,10 @@ public: bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); QStringList mimeTypes() const; void swapRows(int oldRow, int newRow); + void toggleRow(int row, bool enable); + void toggleAll(bool enable); void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); - void save(); + void save(CardDatabase *db); void restore(CardDatabase *db); }; diff --git a/cockatrice/src/tab_deck_editor.cpp b/cockatrice/src/tab_deck_editor.cpp index 1816e101..bb3d9e27 100644 --- a/cockatrice/src/tab_deck_editor.cpp +++ b/cockatrice/src/tab_deck_editor.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include "tab_deck_editor.h" #include "window_sets.h" #include "carddatabase.h" @@ -287,10 +288,13 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent) deckEditToolBar->addAction(aDecrement); deckEditToolBar->addAction(aIncrement); deckEditToolBar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); - + retranslateUi(); resize(950, 700); + + connect(this, SIGNAL(setListChanged()), db, SIGNAL(cardListChanged())); + QTimer::singleShot(0, this, SLOT(checkUnknownSets())); } TabDeckEditor::~TabDeckEditor() @@ -781,3 +785,40 @@ void TabDeckEditor::filterRemove(QAction *action) { filterModel->removeRow(idx.row(), idx.parent()); } + +void TabDeckEditor::checkUnknownSets() +{ + SetList sets = db->getSetList(); + + // no set is enabled. Probably this is the first time running trice + if(!sets.getEnabledSetsNum()) + { + sets.guessSortKeys(); + sets.sortByKey(); + sets.enableAll(); + db->emitCardListChanged(); + + actEditSets(); + return; + } + + int numUnknownSets = sets.getUnknownSetsNum(); + // no unkown sets. + if(!numUnknownSets) + return; + + int ret = QMessageBox::question(this, tr("New sets found"), tr("%1 new set(s) have been found in the card database. Do you want to enable them?").arg(numUnknownSets), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Yes); + + switch(ret) + { + case QMessageBox::No: + sets.markAllAsKnown(); + break; + case QMessageBox::Yes: + sets.enableAllUnknown(); + db->emitCardListChanged(); + break; + default: + break; + } +} \ No newline at end of file diff --git a/cockatrice/src/tab_deck_editor.h b/cockatrice/src/tab_deck_editor.h index 1fba8e7c..af83703d 100644 --- a/cockatrice/src/tab_deck_editor.h +++ b/cockatrice/src/tab_deck_editor.h @@ -111,10 +111,12 @@ public: void setDeck(DeckLoader *_deckLoader); void setModified(bool _windowModified); bool confirmClose(); - public slots: - void closeRequest(); +public slots: + void closeRequest(); + void checkUnknownSets(); signals: - void deckEditorClosing(TabDeckEditor *tab); + void deckEditorClosing(TabDeckEditor *tab); + void setListChanged(); }; #endif diff --git a/cockatrice/src/window_sets.cpp b/cockatrice/src/window_sets.cpp index 6fdc1849..b5178421 100644 --- a/cockatrice/src/window_sets.cpp +++ b/cockatrice/src/window_sets.cpp @@ -7,6 +7,9 @@ #include #include #include +#include +#include +#include WndSets::WndSets(QWidget *parent) : QMainWindow(parent) @@ -37,12 +40,18 @@ WndSets::WndSets(QWidget *parent) view->sortByColumn(SetsModel::SortKeyCol, Qt::AscendingOrder); view->setColumnHidden(SetsModel::SortKeyCol, true); + view->setColumnHidden(SetsModel::IsKnownCol, true); view->setRootIsDecorated(false); - saveButton = new QPushButton(tr("Save set ordering")); - connect(saveButton, SIGNAL(clicked()), this, SLOT(actSave())); - restoreButton = new QPushButton(tr("Restore saved set ordering")); - connect(restoreButton, SIGNAL(clicked()), this, SLOT(actRestore())); + enableButton = new QPushButton(tr("Enable set")); + connect(enableButton, SIGNAL(clicked()), this, SLOT(actEnable())); + disableButton = new QPushButton(tr("Disable set")); + connect(disableButton, SIGNAL(clicked()), this, SLOT(actDisable())); + enableAllButton = new QPushButton(tr("Enable all sets")); + connect(enableAllButton, SIGNAL(clicked()), this, SLOT(actEnableAll())); + disableAllButton = new QPushButton(tr("Disable all sets")); + connect(disableAllButton, SIGNAL(clicked()), this, SLOT(actDisableAll())); + upButton = new QPushButton(tr("Move selected set up")); connect(upButton, SIGNAL(clicked()), this, SLOT(actUp())); downButton = new QPushButton(tr("Move selected set down")); @@ -52,6 +61,8 @@ WndSets::WndSets(QWidget *parent) bottomButton = new QPushButton(tr("Move selected set to bottom")); connect(bottomButton, SIGNAL(clicked()), this, SLOT(actBottom())); + enableButton->setDisabled(true); + disableButton->setDisabled(true); upButton->setDisabled(true); downButton->setDisabled(true); topButton->setDisabled(true); @@ -60,17 +71,31 @@ WndSets::WndSets(QWidget *parent) connect(view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), this, SLOT(actToggleButtons(const QItemSelection &, const QItemSelection &))); + QGroupBox *toggleFrame = new QGroupBox(tr("Enable sets")); + QVBoxLayout *toggleVBox = new QVBoxLayout; + toggleVBox->addWidget(enableButton); + toggleVBox->addWidget(disableButton); + toggleVBox->addWidget(enableAllButton); + toggleVBox->addWidget(disableAllButton); + toggleFrame->setLayout(toggleVBox); + + QGroupBox *sortFrame = new QGroupBox(tr("Sort sets")); + QVBoxLayout *sortVBox = new QVBoxLayout; + sortVBox->addWidget(upButton); + sortVBox->addWidget(downButton); + sortVBox->addWidget(topButton); + sortVBox->addWidget(bottomButton); + sortFrame->setLayout(sortVBox); + + QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + connect(buttonBox, SIGNAL(accepted()), this, SLOT(actSave())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(actRestore())); + QGridLayout *mainLayout = new QGridLayout; mainLayout->addWidget(view, 0, 0, 1, 2); - - mainLayout->addWidget(upButton, 1, 0, 1, 1); - mainLayout->addWidget(downButton, 2, 0, 1, 1); - - mainLayout->addWidget(topButton, 1, 1, 1, 1); - mainLayout->addWidget(bottomButton, 2, 1, 1, 1); - - mainLayout->addWidget(saveButton, 3, 0, 1, 1); - mainLayout->addWidget(restoreButton, 3, 1, 1, 1); + mainLayout->addWidget(toggleFrame, 1, 0, 1, 1); + mainLayout->addWidget(sortFrame, 1, 1, 1, 1); + mainLayout->addWidget(buttonBox, 2, 0, 1, 2); QWidget *centralWidget = new QWidget; centralWidget->setLayout(mainLayout); @@ -86,13 +111,15 @@ WndSets::~WndSets() void WndSets::actSave() { - model->save(); + model->save(db); QMessageBox::information(this, tr("Success"), tr("The sets database has been saved successfully.")); + close(); } void WndSets::actRestore() { model->restore(db); + close(); } void WndSets::actToggleButtons(const QItemSelection & selected, const QItemSelection &) @@ -102,6 +129,8 @@ void WndSets::actToggleButtons(const QItemSelection & selected, const QItemSelec downButton->setDisabled(disabled); topButton->setDisabled(disabled); bottomButton->setDisabled(disabled); + enableButton->setDisabled(disabled); + disableButton->setDisabled(disabled); } void WndSets::selectRow(int row) @@ -111,6 +140,34 @@ void WndSets::selectRow(int row) view->scrollTo(idx, QAbstractItemView::EnsureVisible); } +void WndSets::actEnable() +{ + QModelIndexList rows = view->selectionModel()->selectedRows(); + if(rows.empty()) + return; + + model->toggleRow(rows.first().row(), true); +} + +void WndSets::actDisable() +{ + QModelIndexList rows = view->selectionModel()->selectedRows(); + if(rows.empty()) + return; + + model->toggleRow(rows.first().row(), false); +} + +void WndSets::actEnableAll() +{ + model->toggleAll(true); +} + +void WndSets::actDisableAll() +{ + model->toggleAll(false); +} + void WndSets::actUp() { QModelIndexList rows = view->selectionModel()->selectedRows(); diff --git a/cockatrice/src/window_sets.h b/cockatrice/src/window_sets.h index d2c52823..cd341cdb 100644 --- a/cockatrice/src/window_sets.h +++ b/cockatrice/src/window_sets.h @@ -15,13 +15,18 @@ class WndSets : public QMainWindow { private: SetsModel *model; QTreeView *view; - QPushButton *saveButton, *restoreButton, *upButton, *downButton, *bottomButton, *topButton; + QPushButton *enableButton, *disableButton, *enableAllButton, *disableAllButton, + *upButton, *downButton, *bottomButton, *topButton; public: WndSets(QWidget *parent = 0); ~WndSets(); protected: void selectRow(int row); private slots: + void actEnable(); + void actDisable(); + void actEnableAll(); + void actDisableAll(); void actSave(); void actRestore(); void actUp(); diff --git a/oracle/src/oracleimporter.cpp b/oracle/src/oracleimporter.cpp index 56bdb9f5..bca5c92a 100644 --- a/oracle/src/oracleimporter.cpp +++ b/oracle/src/oracleimporter.cpp @@ -32,7 +32,6 @@ bool OracleImporter::readSetsFromByteArray(const QByteArray &data) QVariant editionCards; QString setType; QDate releaseDate; - bool import; while (it.hasNext()) { map = it.next().toMap(); @@ -45,11 +44,7 @@ bool OracleImporter::readSetsFromByteArray(const QByteArray &data) setType[0] = setType[0].toUpper(); releaseDate = map.value("releaseDate").toDate(); - // core and expansion sets are marked to be imported by default - import = (0 == QString::compare(setType, QString("core"), Qt::CaseInsensitive) || - 0 == QString::compare(setType, QString("expansion"), Qt::CaseInsensitive)); - - newSetList.append(SetToDownload(edition, editionLong, editionCards, import, setType, releaseDate)); + newSetList.append(SetToDownload(edition, editionLong, editionCards, setType, releaseDate)); } qSort(newSetList); @@ -265,10 +260,7 @@ int OracleImporter::startImport() while (it.hasNext()) { - curSet = & it.next(); - if(!curSet->getImport()) - continue; - + curSet = & it.next(); CardSet *set = new CardSet(curSet->getShortName(), curSet->getLongName(), curSet->getSetType(), curSet->getReleaseDate()); if (!sets.contains(set->getShortName())) sets.insert(set->getShortName(), set); diff --git a/oracle/src/oracleimporter.h b/oracle/src/oracleimporter.h index 75a3a7b1..e3f06a44 100644 --- a/oracle/src/oracleimporter.h +++ b/oracle/src/oracleimporter.h @@ -8,7 +8,6 @@ class SetToDownload { private: QString shortName, longName; - bool import; QVariant cards; QDate releaseDate; QString setType; @@ -18,10 +17,8 @@ public: const QVariant &getCards() const { return cards; } const QString &getSetType() const { return setType; } const QDate &getReleaseDate() const { return releaseDate; } - bool getImport() const { return import; } - void setImport(bool _import) { import = _import; } - SetToDownload(const QString &_shortName, const QString &_longName, const QVariant &_cards, bool _import, const QString &_setType = QString(), const QDate &_releaseDate = QDate()) - : shortName(_shortName), longName(_longName), import(_import), cards(_cards), releaseDate(_releaseDate), setType(_setType) { } + SetToDownload(const QString &_shortName, const QString &_longName, const QVariant &_cards, const QString &_setType = QString(), const QDate &_releaseDate = QDate()) + : shortName(_shortName), longName(_longName), cards(_cards), releaseDate(_releaseDate), setType(_setType) { } bool operator<(const SetToDownload &set) const { return longName.compare(set.longName, Qt::CaseInsensitive) < 0; } }; diff --git a/oracle/src/oraclewizard.cpp b/oracle/src/oraclewizard.cpp index bbcbb7cc..75a5204e 100644 --- a/oracle/src/oraclewizard.cpp +++ b/oracle/src/oraclewizard.cpp @@ -56,7 +56,6 @@ OracleWizard::OracleWizard(QWidget *parent) addPage(new IntroPage); addPage(new LoadSetsPage); - addPage(new ChooseSetsPage); addPage(new SaveSetsPage); retranslateUi(); @@ -427,94 +426,6 @@ void LoadSetsPage::importFinished() } } -ChooseSetsPage::ChooseSetsPage(QWidget *parent) - : OracleWizardPage(parent) -{ - checkBoxLayout = new QVBoxLayout; - - QWidget *checkboxFrame = new QWidget(this); - checkboxFrame->setLayout(checkBoxLayout); - - QScrollArea *checkboxArea = new QScrollArea(this); - checkboxArea->setWidget(checkboxFrame); - checkboxArea->setWidgetResizable(true); - - checkAllButton = new QPushButton(this); - connect(checkAllButton, SIGNAL(clicked()), this, SLOT(actCheckAll())); - uncheckAllButton = new QPushButton(this); - connect(uncheckAllButton, SIGNAL(clicked()), this, SLOT(actUncheckAll())); - - QGridLayout *layout = new QGridLayout(this); - layout->addWidget(checkboxArea, 0, 0, 1, 2); - layout->addWidget(checkAllButton, 1, 0); - layout->addWidget(uncheckAllButton, 1, 1); - - setLayout(layout); -} - -void ChooseSetsPage::initializePage() -{ - // populate checkbox list - for (int i = 0; i < checkBoxList.size(); ++i) - delete checkBoxList[i]; - checkBoxList.clear(); - - QList &sets = wizard()->importer->getSets(); - for (int i = 0; i < sets.size(); ++i) { - QCheckBox *checkBox = new QCheckBox(sets[i].getLongName()); - checkBox->setChecked(sets[i].getImport()); - connect(checkBox, SIGNAL(stateChanged(int)), this, SLOT(checkBoxChanged(int))); - checkBoxLayout->addWidget(checkBox); - checkBoxList << checkBox; - } -} - -void ChooseSetsPage::retranslateUi() -{ - setTitle(tr("Sets selection")); - setSubTitle(tr("The following sets has been found in the source file. " - "Please mark the sets that will be imported.\n" - "All core and expansion sets are selected by default.")); - - checkAllButton->setText(tr("&Check all")); - uncheckAllButton->setText(tr("&Uncheck all")); -} - -void ChooseSetsPage::checkBoxChanged(int state) -{ - QCheckBox *checkBox = qobject_cast(sender()); - QList &sets = wizard()->importer->getSets(); - for (int i = 0; i < sets.size(); ++i) - if (sets[i].getLongName() == checkBox->text()) { - sets[i].setImport(state); - break; - } -} - -void ChooseSetsPage::actCheckAll() -{ - for (int i = 0; i < checkBoxList.size(); ++i) - checkBoxList[i]->setChecked(true); -} - -void ChooseSetsPage::actUncheckAll() -{ - for (int i = 0; i < checkBoxList.size(); ++i) - checkBoxList[i]->setChecked(false); -} - -bool ChooseSetsPage::validatePage() -{ - for (int i = 0; i < checkBoxList.size(); ++i) - { - if(checkBoxList[i]->isChecked()) - return true; - } - - QMessageBox::critical(this, tr("Error"), tr("Please mark at least one set.")); - return false; -} - SaveSetsPage::SaveSetsPage(QWidget *parent) : OracleWizardPage(parent) { diff --git a/oracle/src/oraclewizard.h b/oracle/src/oraclewizard.h index e74edb6b..0656a659 100644 --- a/oracle/src/oraclewizard.h +++ b/oracle/src/oraclewizard.h @@ -98,25 +98,6 @@ private slots: void zipDownloadFailed(const QString &message); }; -class ChooseSetsPage : public OracleWizardPage -{ - Q_OBJECT -public: - ChooseSetsPage(QWidget *parent = 0); - void retranslateUi(); -protected: - void initializePage(); - bool validatePage(); -private: - QPushButton *checkAllButton, *uncheckAllButton; - QVBoxLayout *checkBoxLayout; - QList checkBoxList; -private slots: - void actCheckAll(); - void actUncheckAll(); - void checkBoxChanged(int state); -}; - class SaveSetsPage : public OracleWizardPage { Q_OBJECT