Rework the way sets selection/importing works; fix #539 (rebased)

This commit is contained in:
Fabio Bas 2015-04-18 18:47:09 +02:00
parent e69ca60164
commit 881cea27f4
13 changed files with 369 additions and 162 deletions

View file

@ -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);

View file

@ -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; }
};

View file

@ -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<SetToDownload> &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<QCheckBox *>(sender());
QList<SetToDownload> &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)
{

View file

@ -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<QCheckBox *> checkBoxList;
private slots:
void actCheckAll();
void actUncheckAll();
void checkBoxChanged(int state);
};
class SaveSetsPage : public OracleWizardPage
{
Q_OBJECT