mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
started implementing a simple deck editor
This commit is contained in:
parent
46a43aade4
commit
e6d6162426
13 changed files with 333 additions and 27 deletions
|
|
@ -1,6 +1,13 @@
|
|||
#include "decklistmodel.h"
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include "decklistmodel.h"
|
||||
#include "carddatabase.h"
|
||||
|
||||
DeckListModel::DeckListModel(CardDatabase *_db, QObject *parent)
|
||||
: QAbstractListModel(parent), db(_db)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
DeckListModel::~DeckListModel()
|
||||
{
|
||||
|
|
@ -57,13 +64,14 @@ void DeckListModel::cleanList()
|
|||
while (i.hasNext())
|
||||
delete i.next();
|
||||
deckList.clear();
|
||||
reset();
|
||||
}
|
||||
|
||||
void DeckListModel::loadFromFile(const QString &fileName)
|
||||
bool DeckListModel::loadFromFile(const QString &fileName)
|
||||
{
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
return;
|
||||
return false;
|
||||
QTextStream in(&file);
|
||||
cleanList();
|
||||
while (!in.atEnd()) {
|
||||
|
|
@ -81,7 +89,23 @@ void DeckListModel::loadFromFile(const QString &fileName)
|
|||
DecklistRow *row = new DecklistRow(number, line.mid(i + 1), isSideboard);
|
||||
deckList << row;
|
||||
}
|
||||
cacheCardPictures();
|
||||
reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeckListModel::saveToFile(const QString &fileName)
|
||||
{
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
return false;
|
||||
QTextStream out(&file);
|
||||
QListIterator<DecklistRow *> i(deckList);
|
||||
while (i.hasNext()) {
|
||||
DecklistRow *r = i.next();
|
||||
out << QString("%1%2 %3\n").arg(r->isSideboard() ? "SB: " : "").arg(r->getNumber()).arg(r->getCard());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
DecklistRow *DeckListModel::getRow(int row) const
|
||||
|
|
@ -90,3 +114,12 @@ DecklistRow *DeckListModel::getRow(int row) const
|
|||
return 0;
|
||||
return deckList.at(row);
|
||||
}
|
||||
|
||||
void DeckListModel::cacheCardPictures()
|
||||
{
|
||||
QListIterator<DecklistRow *> i(deckList);
|
||||
while (i.hasNext()) {
|
||||
DecklistRow *r = i.next();
|
||||
db->getCard(r->getCard())->getPixmap();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue