whitespace modifications in preparation for merge
This commit is contained in:
parent
378cc91c17
commit
748aac7ee8
6 changed files with 1013 additions and 1013 deletions
|
@ -2,12 +2,12 @@
|
||||||
#include "filtertree.h"
|
#include "filtertree.h"
|
||||||
|
|
||||||
CardDatabaseModel::CardDatabaseModel(CardDatabase *_db, QObject *parent)
|
CardDatabaseModel::CardDatabaseModel(CardDatabase *_db, QObject *parent)
|
||||||
: QAbstractListModel(parent), db(_db)
|
: QAbstractListModel(parent), db(_db)
|
||||||
{
|
{
|
||||||
connect(db, SIGNAL(cardListChanged()), this, SLOT(updateCardList()));
|
connect(db, SIGNAL(cardListChanged()), this, SLOT(updateCardList()));
|
||||||
connect(db, SIGNAL(cardAdded(CardInfo *)), this, SLOT(cardAdded(CardInfo *)));
|
connect(db, SIGNAL(cardAdded(CardInfo *)), this, SLOT(cardAdded(CardInfo *)));
|
||||||
connect(db, SIGNAL(cardRemoved(CardInfo *)), this, SLOT(cardRemoved(CardInfo *)));
|
connect(db, SIGNAL(cardRemoved(CardInfo *)), this, SLOT(cardRemoved(CardInfo *)));
|
||||||
updateCardList();
|
updateCardList();
|
||||||
}
|
}
|
||||||
|
|
||||||
CardDatabaseModel::~CardDatabaseModel()
|
CardDatabaseModel::~CardDatabaseModel()
|
||||||
|
@ -16,164 +16,164 @@ CardDatabaseModel::~CardDatabaseModel()
|
||||||
|
|
||||||
int CardDatabaseModel::rowCount(const QModelIndex &/*parent*/) const
|
int CardDatabaseModel::rowCount(const QModelIndex &/*parent*/) const
|
||||||
{
|
{
|
||||||
return cardList.size();
|
return cardList.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
int CardDatabaseModel::columnCount(const QModelIndex &/*parent*/) const
|
int CardDatabaseModel::columnCount(const QModelIndex &/*parent*/) const
|
||||||
{
|
{
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant CardDatabaseModel::data(const QModelIndex &index, int role) const
|
QVariant CardDatabaseModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
if ((index.row() >= cardList.size()) || (index.column() >= 5))
|
if ((index.row() >= cardList.size()) || (index.column() >= 5))
|
||||||
return QVariant();
|
return QVariant();
|
||||||
if (role != Qt::DisplayRole)
|
if (role != Qt::DisplayRole)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
CardInfo *card = cardList.at(index.row());
|
CardInfo *card = cardList.at(index.row());
|
||||||
switch (index.column()){
|
switch (index.column()){
|
||||||
case 0: return card->getName();
|
case 0: return card->getName();
|
||||||
case 1: {
|
case 1: {
|
||||||
QStringList setList;
|
QStringList setList;
|
||||||
const QList<CardSet *> &sets = card->getSets();
|
const QList<CardSet *> &sets = card->getSets();
|
||||||
for (int i = 0; i < sets.size(); i++)
|
for (int i = 0; i < sets.size(); i++)
|
||||||
setList << sets[i]->getShortName();
|
setList << sets[i]->getShortName();
|
||||||
return setList.join(", ");
|
return setList.join(", ");
|
||||||
}
|
}
|
||||||
case 2: return card->getManaCost();
|
case 2: return card->getManaCost();
|
||||||
case 3: return card->getCardType();
|
case 3: return card->getCardType();
|
||||||
case 4: return card->getPowTough();
|
case 4: return card->getPowTough();
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant CardDatabaseModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant CardDatabaseModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
if (role != Qt::DisplayRole)
|
if (role != Qt::DisplayRole)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
if (orientation != Qt::Horizontal)
|
if (orientation != Qt::Horizontal)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
switch (section) {
|
switch (section) {
|
||||||
case 0: return QString(tr("Name"));
|
case 0: return QString(tr("Name"));
|
||||||
case 1: return QString(tr("Sets"));
|
case 1: return QString(tr("Sets"));
|
||||||
case 2: return QString(tr("Mana cost"));
|
case 2: return QString(tr("Mana cost"));
|
||||||
case 3: return QString(tr("Card type"));
|
case 3: return QString(tr("Card type"));
|
||||||
case 4: return QString(tr("P/T"));
|
case 4: return QString(tr("P/T"));
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDatabaseModel::updateCardList()
|
void CardDatabaseModel::updateCardList()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < cardList.size(); ++i)
|
for (int i = 0; i < cardList.size(); ++i)
|
||||||
disconnect(cardList[i], 0, this, 0);
|
disconnect(cardList[i], 0, this, 0);
|
||||||
|
|
||||||
cardList = db->getCardList();
|
cardList = db->getCardList();
|
||||||
for (int i = 0; i < cardList.size(); ++i)
|
for (int i = 0; i < cardList.size(); ++i)
|
||||||
connect(cardList[i], SIGNAL(cardInfoChanged(CardInfo *)), this, SLOT(cardInfoChanged(CardInfo *)));
|
connect(cardList[i], SIGNAL(cardInfoChanged(CardInfo *)), this, SLOT(cardInfoChanged(CardInfo *)));
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDatabaseModel::cardInfoChanged(CardInfo *card)
|
void CardDatabaseModel::cardInfoChanged(CardInfo *card)
|
||||||
{
|
{
|
||||||
const int row = cardList.indexOf(card);
|
const int row = cardList.indexOf(card);
|
||||||
if (row == -1)
|
if (row == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
emit dataChanged(index(row, 0), index(row, 4));
|
emit dataChanged(index(row, 0), index(row, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDatabaseModel::cardAdded(CardInfo *card)
|
void CardDatabaseModel::cardAdded(CardInfo *card)
|
||||||
{
|
{
|
||||||
beginInsertRows(QModelIndex(), cardList.size(), cardList.size());
|
beginInsertRows(QModelIndex(), cardList.size(), cardList.size());
|
||||||
cardList.append(card);
|
cardList.append(card);
|
||||||
connect(card, SIGNAL(cardInfoChanged(CardInfo *)), this, SLOT(cardInfoChanged(CardInfo *)));
|
connect(card, SIGNAL(cardInfoChanged(CardInfo *)), this, SLOT(cardInfoChanged(CardInfo *)));
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDatabaseModel::cardRemoved(CardInfo *card)
|
void CardDatabaseModel::cardRemoved(CardInfo *card)
|
||||||
{
|
{
|
||||||
const int row = cardList.indexOf(card);
|
const int row = cardList.indexOf(card);
|
||||||
if (row == -1)
|
if (row == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
beginRemoveRows(QModelIndex(), row, row);
|
beginRemoveRows(QModelIndex(), row, row);
|
||||||
cardList.removeAt(row);
|
cardList.removeAt(row);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
CardDatabaseDisplayModel::CardDatabaseDisplayModel(QObject *parent)
|
CardDatabaseDisplayModel::CardDatabaseDisplayModel(QObject *parent)
|
||||||
: QSortFilterProxyModel(parent),
|
: QSortFilterProxyModel(parent),
|
||||||
isToken(ShowAll)
|
isToken(ShowAll)
|
||||||
{
|
{
|
||||||
filterTree = NULL;
|
filterTree = NULL;
|
||||||
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||||
setSortCaseSensitivity(Qt::CaseInsensitive);
|
setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CardDatabaseDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex & /*sourceParent*/) const
|
bool CardDatabaseDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex & /*sourceParent*/) const
|
||||||
{
|
{
|
||||||
CardInfo const *info = static_cast<CardDatabaseModel *>(sourceModel())->getCard(sourceRow);
|
CardInfo const *info = static_cast<CardDatabaseModel *>(sourceModel())->getCard(sourceRow);
|
||||||
|
|
||||||
if (((isToken == ShowTrue) && !info->getIsToken()) || ((isToken == ShowFalse) && info->getIsToken()))
|
if (((isToken == ShowTrue) && !info->getIsToken()) || ((isToken == ShowFalse) && info->getIsToken()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!cardNameBeginning.isEmpty())
|
if (!cardNameBeginning.isEmpty())
|
||||||
if (!info->getName().startsWith(cardNameBeginning, Qt::CaseInsensitive))
|
if (!info->getName().startsWith(cardNameBeginning, Qt::CaseInsensitive))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!cardName.isEmpty())
|
if (!cardName.isEmpty())
|
||||||
if (!info->getName().contains(cardName, Qt::CaseInsensitive))
|
if (!info->getName().contains(cardName, Qt::CaseInsensitive))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!cardNameSet.isEmpty())
|
if (!cardNameSet.isEmpty())
|
||||||
if (!cardNameSet.contains(info->getName()))
|
if (!cardNameSet.contains(info->getName()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!cardText.isEmpty())
|
if (!cardText.isEmpty())
|
||||||
if (!info->getText().contains(cardText, Qt::CaseInsensitive))
|
if (!info->getText().contains(cardText, Qt::CaseInsensitive))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!cardColors.isEmpty())
|
if (!cardColors.isEmpty())
|
||||||
if (QSet<QString>::fromList(info->getColors()).intersect(cardColors).isEmpty() && !(info->getColors().isEmpty() && cardColors.contains("X")))
|
if (QSet<QString>::fromList(info->getColors()).intersect(cardColors).isEmpty() && !(info->getColors().isEmpty() && cardColors.contains("X")))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!cardTypes.isEmpty())
|
if (!cardTypes.isEmpty())
|
||||||
if (!cardTypes.contains(info->getMainCardType()))
|
if (!cardTypes.contains(info->getMainCardType()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (filterTree != NULL)
|
if (filterTree != NULL)
|
||||||
return filterTree->acceptsCard(info);
|
return filterTree->acceptsCard(info);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDatabaseDisplayModel::clearSearch()
|
void CardDatabaseDisplayModel::clearSearch()
|
||||||
{
|
{
|
||||||
cardName.clear();
|
cardName.clear();
|
||||||
cardText.clear();
|
cardText.clear();
|
||||||
cardTypes.clear();
|
cardTypes.clear();
|
||||||
cardColors.clear();
|
cardColors.clear();
|
||||||
if (filterTree != NULL)
|
if (filterTree != NULL)
|
||||||
filterTree->clear();
|
filterTree->clear();
|
||||||
invalidateFilter();
|
invalidateFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDatabaseDisplayModel::setFilterTree(FilterTree *filterTree)
|
void CardDatabaseDisplayModel::setFilterTree(FilterTree *filterTree)
|
||||||
{
|
{
|
||||||
if (this->filterTree != NULL)
|
if (this->filterTree != NULL)
|
||||||
disconnect(this->filterTree, 0, this, 0);
|
disconnect(this->filterTree, 0, this, 0);
|
||||||
|
|
||||||
this->filterTree = filterTree;
|
this->filterTree = filterTree;
|
||||||
connect(this->filterTree, SIGNAL(changed()), this, SLOT(filterTreeChanged()));
|
connect(this->filterTree, SIGNAL(changed()), this, SLOT(filterTreeChanged()));
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDatabaseDisplayModel::filterTreeChanged()
|
void CardDatabaseDisplayModel::filterTreeChanged()
|
||||||
{
|
{
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,50 +10,50 @@
|
||||||
class FilterTree;
|
class FilterTree;
|
||||||
|
|
||||||
class CardDatabaseModel : public QAbstractListModel {
|
class CardDatabaseModel : public QAbstractListModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
CardDatabaseModel(CardDatabase *_db, QObject *parent = 0);
|
CardDatabaseModel(CardDatabase *_db, QObject *parent = 0);
|
||||||
~CardDatabaseModel();
|
~CardDatabaseModel();
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
QVariant data(const QModelIndex &index, int role) const;
|
QVariant data(const QModelIndex &index, int role) const;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
CardDatabase *getDatabase() const { return db; }
|
CardDatabase *getDatabase() const { return db; }
|
||||||
CardInfo *getCard(int index) const { return cardList[index]; }
|
CardInfo *getCard(int index) const { return cardList[index]; }
|
||||||
private:
|
private:
|
||||||
QList<CardInfo *> cardList;
|
QList<CardInfo *> cardList;
|
||||||
CardDatabase *db;
|
CardDatabase *db;
|
||||||
private slots:
|
private slots:
|
||||||
void updateCardList();
|
void updateCardList();
|
||||||
void cardAdded(CardInfo *card);
|
void cardAdded(CardInfo *card);
|
||||||
void cardRemoved(CardInfo *card);
|
void cardRemoved(CardInfo *card);
|
||||||
void cardInfoChanged(CardInfo *card);
|
void cardInfoChanged(CardInfo *card);
|
||||||
};
|
};
|
||||||
|
|
||||||
class CardDatabaseDisplayModel : public QSortFilterProxyModel {
|
class CardDatabaseDisplayModel : public QSortFilterProxyModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum FilterBool { ShowTrue, ShowFalse, ShowAll };
|
enum FilterBool { ShowTrue, ShowFalse, ShowAll };
|
||||||
private:
|
private:
|
||||||
FilterBool isToken;
|
FilterBool isToken;
|
||||||
QString cardNameBeginning, cardName, cardText;
|
QString cardNameBeginning, cardName, cardText;
|
||||||
QSet<QString> cardNameSet, cardTypes, cardColors;
|
QSet<QString> cardNameSet, cardTypes, cardColors;
|
||||||
FilterTree *filterTree;
|
FilterTree *filterTree;
|
||||||
public:
|
public:
|
||||||
CardDatabaseDisplayModel(QObject *parent = 0);
|
CardDatabaseDisplayModel(QObject *parent = 0);
|
||||||
void setFilterTree(FilterTree *filterTree);
|
void setFilterTree(FilterTree *filterTree);
|
||||||
void setIsToken(FilterBool _isToken) { isToken = _isToken; invalidate(); }
|
void setIsToken(FilterBool _isToken) { isToken = _isToken; invalidate(); }
|
||||||
void setCardNameBeginning(const QString &_beginning) { cardNameBeginning = _beginning; invalidate(); }
|
void setCardNameBeginning(const QString &_beginning) { cardNameBeginning = _beginning; invalidate(); }
|
||||||
void setCardName(const QString &_cardName) { cardName = _cardName; invalidate(); }
|
void setCardName(const QString &_cardName) { cardName = _cardName; invalidate(); }
|
||||||
void setCardNameSet(const QSet<QString> &_cardNameSet) { cardNameSet = _cardNameSet; invalidate(); }
|
void setCardNameSet(const QSet<QString> &_cardNameSet) { cardNameSet = _cardNameSet; invalidate(); }
|
||||||
void setCardText(const QString &_cardText) { cardText = _cardText; invalidate(); }
|
void setCardText(const QString &_cardText) { cardText = _cardText; invalidate(); }
|
||||||
void setCardTypes(const QSet<QString> &_cardTypes) { cardTypes = _cardTypes; invalidate(); }
|
void setCardTypes(const QSet<QString> &_cardTypes) { cardTypes = _cardTypes; invalidate(); }
|
||||||
void setCardColors(const QSet<QString> &_cardColors) { cardColors = _cardColors; invalidate(); }
|
void setCardColors(const QSet<QString> &_cardColors) { cardColors = _cardColors; invalidate(); }
|
||||||
void clearSearch();
|
void clearSearch();
|
||||||
protected:
|
protected:
|
||||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
||||||
private slots:
|
private slots:
|
||||||
void filterTreeChanged();
|
void filterTreeChanged();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -14,454 +14,454 @@
|
||||||
#include "deck_loader.h"
|
#include "deck_loader.h"
|
||||||
|
|
||||||
DeckListModel::DeckListModel(QObject *parent)
|
DeckListModel::DeckListModel(QObject *parent)
|
||||||
: QAbstractItemModel(parent)
|
: QAbstractItemModel(parent)
|
||||||
{
|
{
|
||||||
deckList = new DeckLoader;
|
deckList = new DeckLoader;
|
||||||
connect(deckList, SIGNAL(deckLoaded()), this, SLOT(rebuildTree()));
|
connect(deckList, SIGNAL(deckLoaded()), this, SLOT(rebuildTree()));
|
||||||
connect(deckList, SIGNAL(deckHashChanged()), this, SIGNAL(deckHashChanged()));
|
connect(deckList, SIGNAL(deckHashChanged()), this, SIGNAL(deckHashChanged()));
|
||||||
root = new InnerDecklistNode;
|
root = new InnerDecklistNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeckListModel::~DeckListModel()
|
DeckListModel::~DeckListModel()
|
||||||
{
|
{
|
||||||
delete root;
|
delete root;
|
||||||
delete deckList;
|
delete deckList;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckListModel::rebuildTree()
|
void DeckListModel::rebuildTree()
|
||||||
{
|
{
|
||||||
root->clearTree();
|
root->clearTree();
|
||||||
InnerDecklistNode *listRoot = deckList->getRoot();
|
InnerDecklistNode *listRoot = deckList->getRoot();
|
||||||
for (int i = 0; i < listRoot->size(); i++) {
|
for (int i = 0; i < listRoot->size(); i++) {
|
||||||
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
|
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
|
||||||
InnerDecklistNode *node = new InnerDecklistNode(currentZone->getName(), root);
|
InnerDecklistNode *node = new InnerDecklistNode(currentZone->getName(), root);
|
||||||
for (int j = 0; j < currentZone->size(); j++) {
|
for (int j = 0; j < currentZone->size(); j++) {
|
||||||
DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
|
DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
|
||||||
// XXX better sanity checking
|
// XXX better sanity checking
|
||||||
if (!currentCard)
|
if (!currentCard)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
CardInfo *info = db->getCard(currentCard->getName());
|
CardInfo *info = db->getCard(currentCard->getName());
|
||||||
QString cardType;
|
QString cardType;
|
||||||
if (!info)
|
if (!info)
|
||||||
cardType = "unknown";
|
cardType = "unknown";
|
||||||
else
|
else
|
||||||
cardType = info->getMainCardType();
|
cardType = info->getMainCardType();
|
||||||
InnerDecklistNode *cardTypeNode = dynamic_cast<InnerDecklistNode *>(node->findChild(cardType));
|
InnerDecklistNode *cardTypeNode = dynamic_cast<InnerDecklistNode *>(node->findChild(cardType));
|
||||||
if (!cardTypeNode)
|
if (!cardTypeNode)
|
||||||
cardTypeNode = new InnerDecklistNode(cardType, node);
|
cardTypeNode = new InnerDecklistNode(cardType, node);
|
||||||
|
|
||||||
new DecklistModelCardNode(currentCard, cardTypeNode);
|
new DecklistModelCardNode(currentCard, cardTypeNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
int DeckListModel::rowCount(const QModelIndex &parent) const
|
int DeckListModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
// debugIndexInfo("rowCount", parent);
|
// debugIndexInfo("rowCount", parent);
|
||||||
InnerDecklistNode *node = getNode<InnerDecklistNode *>(parent);
|
InnerDecklistNode *node = getNode<InnerDecklistNode *>(parent);
|
||||||
if (node)
|
if (node)
|
||||||
return node->size();
|
return node->size();
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DeckListModel::columnCount(const QModelIndex &/*parent*/) const
|
int DeckListModel::columnCount(const QModelIndex &/*parent*/) const
|
||||||
{
|
{
|
||||||
if (settingsCache->getPriceTagFeature())
|
if (settingsCache->getPriceTagFeature())
|
||||||
return 3;
|
return 3;
|
||||||
else
|
else
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant DeckListModel::data(const QModelIndex &index, int role) const
|
QVariant DeckListModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
// debugIndexInfo("data", index);
|
// debugIndexInfo("data", index);
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
if (index.column() >= columnCount())
|
if (index.column() >= columnCount())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
AbstractDecklistNode *temp = static_cast<AbstractDecklistNode *>(index.internalPointer());
|
AbstractDecklistNode *temp = static_cast<AbstractDecklistNode *>(index.internalPointer());
|
||||||
DecklistModelCardNode *card = dynamic_cast<DecklistModelCardNode *>(temp);
|
DecklistModelCardNode *card = dynamic_cast<DecklistModelCardNode *>(temp);
|
||||||
if (!card) {
|
if (!card) {
|
||||||
InnerDecklistNode *node = dynamic_cast<InnerDecklistNode *>(temp);
|
InnerDecklistNode *node = dynamic_cast<InnerDecklistNode *>(temp);
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::FontRole: {
|
case Qt::FontRole: {
|
||||||
QFont f;
|
QFont f;
|
||||||
f.setBold(true);
|
f.setBold(true);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
case Qt::EditRole:
|
case Qt::EditRole:
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0: return node->recursiveCount(true);
|
case 0: return node->recursiveCount(true);
|
||||||
case 1: return node->getVisibleName();
|
case 1: return node->getVisibleName();
|
||||||
case 2: return QString().sprintf("$%.2f", node->recursivePrice(true));
|
case 2: return QString().sprintf("$%.2f", node->recursivePrice(true));
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
case Qt::BackgroundRole: {
|
case Qt::BackgroundRole: {
|
||||||
int color = 90 + 60 * node->depth();
|
int color = 90 + 60 * node->depth();
|
||||||
return QBrush(QColor(color, 255, color));
|
return QBrush(QColor(color, 255, color));
|
||||||
}
|
}
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
case Qt::EditRole: {
|
case Qt::EditRole: {
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0: return card->getNumber();
|
case 0: return card->getNumber();
|
||||||
case 1: return card->getName();
|
case 1: return card->getName();
|
||||||
case 2: return QString().sprintf("$%.2f", card->getTotalPrice());
|
case 2: return QString().sprintf("$%.2f", card->getTotalPrice());
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case Qt::BackgroundRole: {
|
case Qt::BackgroundRole: {
|
||||||
int color = 255 - (index.row() % 2) * 30;
|
int color = 255 - (index.row() % 2) * 30;
|
||||||
return QBrush(QColor(color, color, color));
|
return QBrush(QColor(color, color, color));
|
||||||
}
|
}
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant DeckListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant DeckListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
if ((role != Qt::DisplayRole) || (orientation != Qt::Horizontal))
|
if ((role != Qt::DisplayRole) || (orientation != Qt::Horizontal))
|
||||||
return QVariant();
|
return QVariant();
|
||||||
if (section >= columnCount())
|
if (section >= columnCount())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
switch (section) {
|
switch (section) {
|
||||||
case 0: return tr("Number");
|
case 0: return tr("Number");
|
||||||
case 1: return tr("Card");
|
case 1: return tr("Card");
|
||||||
case 2: return tr("Price");
|
case 2: return tr("Price");
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex DeckListModel::index(int row, int column, const QModelIndex &parent) const
|
QModelIndex DeckListModel::index(int row, int column, const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
// debugIndexInfo("index", parent);
|
// debugIndexInfo("index", parent);
|
||||||
if (!hasIndex(row, column, parent))
|
if (!hasIndex(row, column, parent))
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
InnerDecklistNode *parentNode = getNode<InnerDecklistNode *>(parent);
|
InnerDecklistNode *parentNode = getNode<InnerDecklistNode *>(parent);
|
||||||
if (row >= parentNode->size())
|
if (row >= parentNode->size())
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
return createIndex(row, column, parentNode->at(row));
|
return createIndex(row, column, parentNode->at(row));
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex DeckListModel::parent(const QModelIndex &ind) const
|
QModelIndex DeckListModel::parent(const QModelIndex &ind) const
|
||||||
{
|
{
|
||||||
if (!ind.isValid())
|
if (!ind.isValid())
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
return nodeToIndex(static_cast<AbstractDecklistNode *>(ind.internalPointer())->getParent());
|
return nodeToIndex(static_cast<AbstractDecklistNode *>(ind.internalPointer())->getParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::ItemFlags DeckListModel::flags(const QModelIndex &index) const
|
Qt::ItemFlags DeckListModel::flags(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
Qt::ItemFlags result = Qt::ItemIsEnabled;
|
Qt::ItemFlags result = Qt::ItemIsEnabled;
|
||||||
result |= Qt::ItemIsSelectable;
|
result |= Qt::ItemIsSelectable;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckListModel::emitRecursiveUpdates(const QModelIndex &index)
|
void DeckListModel::emitRecursiveUpdates(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return;
|
return;
|
||||||
emit dataChanged(index, index);
|
emit dataChanged(index, index);
|
||||||
emitRecursiveUpdates(index.parent());
|
emitRecursiveUpdates(index.parent());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeckListModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
bool DeckListModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
{
|
{
|
||||||
DecklistModelCardNode *node = getNode<DecklistModelCardNode *>(index);
|
DecklistModelCardNode *node = getNode<DecklistModelCardNode *>(index);
|
||||||
if (!node || (role != Qt::EditRole))
|
if (!node || (role != Qt::EditRole))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0: node->setNumber(value.toInt()); break;
|
case 0: node->setNumber(value.toInt()); break;
|
||||||
case 1: node->setName(value.toString()); break;
|
case 1: node->setName(value.toString()); break;
|
||||||
case 2: node->setPrice(value.toFloat()); break;
|
case 2: node->setPrice(value.toFloat()); break;
|
||||||
default: return false;
|
default: return false;
|
||||||
}
|
}
|
||||||
emitRecursiveUpdates(index);
|
emitRecursiveUpdates(index);
|
||||||
deckList->updateDeckHash();
|
deckList->updateDeckHash();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeckListModel::removeRows(int row, int count, const QModelIndex &parent)
|
bool DeckListModel::removeRows(int row, int count, const QModelIndex &parent)
|
||||||
{
|
{
|
||||||
InnerDecklistNode *node = getNode<InnerDecklistNode *>(parent);
|
InnerDecklistNode *node = getNode<InnerDecklistNode *>(parent);
|
||||||
if (!node)
|
if (!node)
|
||||||
return false;
|
return false;
|
||||||
if (row + count > node->size())
|
if (row + count > node->size())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
beginRemoveRows(parent, row, row + count - 1);
|
beginRemoveRows(parent, row, row + count - 1);
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
AbstractDecklistNode *toDelete = node->takeAt(row);
|
AbstractDecklistNode *toDelete = node->takeAt(row);
|
||||||
if (DecklistModelCardNode *temp = dynamic_cast<DecklistModelCardNode *>(toDelete))
|
if (DecklistModelCardNode *temp = dynamic_cast<DecklistModelCardNode *>(toDelete))
|
||||||
deckList->deleteNode(temp->getDataNode());
|
deckList->deleteNode(temp->getDataNode());
|
||||||
delete toDelete;
|
delete toDelete;
|
||||||
}
|
}
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
|
||||||
if (!node->size() && (node != root))
|
if (!node->size() && (node != root))
|
||||||
removeRows(parent.row(), 1, parent.parent());
|
removeRows(parent.row(), 1, parent.parent());
|
||||||
else
|
else
|
||||||
emitRecursiveUpdates(parent);
|
emitRecursiveUpdates(parent);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
InnerDecklistNode *DeckListModel::createNodeIfNeeded(const QString &name, InnerDecklistNode *parent)
|
InnerDecklistNode *DeckListModel::createNodeIfNeeded(const QString &name, InnerDecklistNode *parent)
|
||||||
{
|
{
|
||||||
InnerDecklistNode *newNode = dynamic_cast<InnerDecklistNode *>(parent->findChild(name));
|
InnerDecklistNode *newNode = dynamic_cast<InnerDecklistNode *>(parent->findChild(name));
|
||||||
if (!newNode) {
|
if (!newNode) {
|
||||||
beginInsertRows(nodeToIndex(parent), parent->size(), parent->size());
|
beginInsertRows(nodeToIndex(parent), parent->size(), parent->size());
|
||||||
newNode = new InnerDecklistNode(name, parent);
|
newNode = new InnerDecklistNode(name, parent);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
return newNode;
|
return newNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
DecklistModelCardNode *DeckListModel::findCardNode(const QString &cardName, const QString &zoneName) const
|
DecklistModelCardNode *DeckListModel::findCardNode(const QString &cardName, const QString &zoneName) const
|
||||||
{
|
{
|
||||||
InnerDecklistNode *zoneNode, *typeNode;
|
InnerDecklistNode *zoneNode, *typeNode;
|
||||||
CardInfo *info;
|
CardInfo *info;
|
||||||
QString cardType;
|
QString cardType;
|
||||||
|
|
||||||
zoneNode = dynamic_cast<InnerDecklistNode *>(root->findChild(zoneName));
|
zoneNode = dynamic_cast<InnerDecklistNode *>(root->findChild(zoneName));
|
||||||
if(!zoneNode)
|
if(!zoneNode)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
info = db->getCard(cardName);
|
info = db->getCard(cardName);
|
||||||
if(!info)
|
if(!info)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
cardType = info->getMainCardType();
|
cardType = info->getMainCardType();
|
||||||
typeNode = dynamic_cast<InnerDecklistNode *>(zoneNode->findChild(cardType));
|
typeNode = dynamic_cast<InnerDecklistNode *>(zoneNode->findChild(cardType));
|
||||||
if(!typeNode)
|
if(!typeNode)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return dynamic_cast<DecklistModelCardNode *>(typeNode->findChild(cardName));
|
return dynamic_cast<DecklistModelCardNode *>(typeNode->findChild(cardName));
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex DeckListModel::findCard(const QString &cardName, const QString &zoneName) const
|
QModelIndex DeckListModel::findCard(const QString &cardName, const QString &zoneName) const
|
||||||
{
|
{
|
||||||
DecklistModelCardNode *cardNode;
|
DecklistModelCardNode *cardNode;
|
||||||
|
|
||||||
cardNode = findCardNode(cardName, zoneName);
|
cardNode = findCardNode(cardName, zoneName);
|
||||||
if(!cardNode)
|
if(!cardNode)
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
return nodeToIndex(cardNode);
|
return nodeToIndex(cardNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex DeckListModel::addCard(const QString &cardName, const QString &zoneName)
|
QModelIndex DeckListModel::addCard(const QString &cardName, const QString &zoneName)
|
||||||
{
|
{
|
||||||
InnerDecklistNode *zoneNode = createNodeIfNeeded(zoneName, root);
|
InnerDecklistNode *zoneNode = createNodeIfNeeded(zoneName, root);
|
||||||
|
|
||||||
CardInfo *info = db->getCard(cardName);
|
CardInfo *info = db->getCard(cardName);
|
||||||
QString cardType = info->getMainCardType();
|
QString cardType = info->getMainCardType();
|
||||||
InnerDecklistNode *cardTypeNode = createNodeIfNeeded(cardType, zoneNode);
|
InnerDecklistNode *cardTypeNode = createNodeIfNeeded(cardType, zoneNode);
|
||||||
|
|
||||||
DecklistModelCardNode *cardNode = dynamic_cast<DecklistModelCardNode *>(cardTypeNode->findChild(cardName));
|
DecklistModelCardNode *cardNode = dynamic_cast<DecklistModelCardNode *>(cardTypeNode->findChild(cardName));
|
||||||
if (!cardNode) {
|
if (!cardNode) {
|
||||||
DecklistCardNode *decklistCard = deckList->addCard(cardName, zoneName);
|
DecklistCardNode *decklistCard = deckList->addCard(cardName, zoneName);
|
||||||
QModelIndex parentIndex = nodeToIndex(cardTypeNode);
|
QModelIndex parentIndex = nodeToIndex(cardTypeNode);
|
||||||
beginInsertRows(parentIndex, cardTypeNode->size(), cardTypeNode->size());
|
beginInsertRows(parentIndex, cardTypeNode->size(), cardTypeNode->size());
|
||||||
cardNode = new DecklistModelCardNode(decklistCard, cardTypeNode);
|
cardNode = new DecklistModelCardNode(decklistCard, cardTypeNode);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
sort(1);
|
sort(1);
|
||||||
emitRecursiveUpdates(parentIndex);
|
emitRecursiveUpdates(parentIndex);
|
||||||
return nodeToIndex(cardNode);
|
return nodeToIndex(cardNode);
|
||||||
} else {
|
} else {
|
||||||
cardNode->setNumber(cardNode->getNumber() + 1);
|
cardNode->setNumber(cardNode->getNumber() + 1);
|
||||||
QModelIndex ind = nodeToIndex(cardNode);
|
QModelIndex ind = nodeToIndex(cardNode);
|
||||||
emitRecursiveUpdates(ind);
|
emitRecursiveUpdates(ind);
|
||||||
deckList->updateDeckHash();
|
deckList->updateDeckHash();
|
||||||
return ind;
|
return ind;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex DeckListModel::nodeToIndex(AbstractDecklistNode *node) const
|
QModelIndex DeckListModel::nodeToIndex(AbstractDecklistNode *node) const
|
||||||
{
|
{
|
||||||
if (node == root)
|
if (node == root)
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
return createIndex(node->getParent()->indexOf(node), 0, node);
|
return createIndex(node->getParent()->indexOf(node), 0, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckListModel::sortHelper(InnerDecklistNode *node, Qt::SortOrder order)
|
void DeckListModel::sortHelper(InnerDecklistNode *node, Qt::SortOrder order)
|
||||||
{
|
{
|
||||||
// Sort children of node and save the information needed to
|
// Sort children of node and save the information needed to
|
||||||
// update the list of persistent indexes.
|
// update the list of persistent indexes.
|
||||||
QVector<QPair<int, int> > sortResult = node->sort(order);
|
QVector<QPair<int, int> > sortResult = node->sort(order);
|
||||||
|
|
||||||
QModelIndexList from, to;
|
QModelIndexList from, to;
|
||||||
for (int i = sortResult.size() - 1; i >= 0; --i) {
|
for (int i = sortResult.size() - 1; i >= 0; --i) {
|
||||||
const int fromRow = sortResult[i].first;
|
const int fromRow = sortResult[i].first;
|
||||||
const int toRow = sortResult[i].second;
|
const int toRow = sortResult[i].second;
|
||||||
AbstractDecklistNode *temp = node->at(toRow);
|
AbstractDecklistNode *temp = node->at(toRow);
|
||||||
for (int j = columnCount(); j; --j) {
|
for (int j = columnCount(); j; --j) {
|
||||||
from << createIndex(fromRow, 0, temp);
|
from << createIndex(fromRow, 0, temp);
|
||||||
to << createIndex(toRow, 0, temp);
|
to << createIndex(toRow, 0, temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
changePersistentIndexList(from, to);
|
changePersistentIndexList(from, to);
|
||||||
|
|
||||||
// Recursion
|
// Recursion
|
||||||
for (int i = node->size() - 1; i >= 0; --i) {
|
for (int i = node->size() - 1; i >= 0; --i) {
|
||||||
InnerDecklistNode *subNode = dynamic_cast<InnerDecklistNode *>(node->at(i));
|
InnerDecklistNode *subNode = dynamic_cast<InnerDecklistNode *>(node->at(i));
|
||||||
if (subNode)
|
if (subNode)
|
||||||
sortHelper(subNode, order);
|
sortHelper(subNode, order);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckListModel::sort(int /*column*/, Qt::SortOrder order)
|
void DeckListModel::sort(int /*column*/, Qt::SortOrder order)
|
||||||
{
|
{
|
||||||
emit layoutAboutToBeChanged();
|
emit layoutAboutToBeChanged();
|
||||||
sortHelper(root, order);
|
sortHelper(root, order);
|
||||||
emit layoutChanged();
|
emit layoutChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckListModel::cleanList()
|
void DeckListModel::cleanList()
|
||||||
{
|
{
|
||||||
setDeckList(new DeckLoader);
|
setDeckList(new DeckLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckListModel::setDeckList(DeckLoader *_deck)
|
void DeckListModel::setDeckList(DeckLoader *_deck)
|
||||||
{
|
{
|
||||||
delete deckList;
|
delete deckList;
|
||||||
deckList = _deck;
|
deckList = _deck;
|
||||||
connect(deckList, SIGNAL(deckLoaded()), this, SLOT(rebuildTree()));
|
connect(deckList, SIGNAL(deckLoaded()), this, SLOT(rebuildTree()));
|
||||||
connect(deckList, SIGNAL(deckHashChanged()), this, SIGNAL(deckHashChanged()));
|
connect(deckList, SIGNAL(deckHashChanged()), this, SIGNAL(deckHashChanged()));
|
||||||
rebuildTree();
|
rebuildTree();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node)
|
void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node)
|
||||||
{
|
{
|
||||||
const int totalColumns = settingsCache->getPriceTagFeature() ? 3 : 2;
|
const int totalColumns = settingsCache->getPriceTagFeature() ? 3 : 2;
|
||||||
|
|
||||||
if (node->height() == 1) {
|
if (node->height() == 1) {
|
||||||
QTextBlockFormat blockFormat;
|
QTextBlockFormat blockFormat;
|
||||||
QTextCharFormat charFormat;
|
QTextCharFormat charFormat;
|
||||||
charFormat.setFontPointSize(11);
|
charFormat.setFontPointSize(11);
|
||||||
charFormat.setFontWeight(QFont::Bold);
|
charFormat.setFontWeight(QFont::Bold);
|
||||||
cursor->insertBlock(blockFormat, charFormat);
|
cursor->insertBlock(blockFormat, charFormat);
|
||||||
QString priceStr;
|
QString priceStr;
|
||||||
if (settingsCache->getPriceTagFeature())
|
if (settingsCache->getPriceTagFeature())
|
||||||
priceStr = QString().sprintf(": $%.2f", node->recursivePrice(true));
|
priceStr = QString().sprintf(": $%.2f", node->recursivePrice(true));
|
||||||
cursor->insertText(QString("%1: %2").arg(node->getVisibleName()).arg(node->recursiveCount(true)).append(priceStr));
|
cursor->insertText(QString("%1: %2").arg(node->getVisibleName()).arg(node->recursiveCount(true)).append(priceStr));
|
||||||
|
|
||||||
QTextTableFormat tableFormat;
|
QTextTableFormat tableFormat;
|
||||||
tableFormat.setCellPadding(0);
|
tableFormat.setCellPadding(0);
|
||||||
tableFormat.setCellSpacing(0);
|
tableFormat.setCellSpacing(0);
|
||||||
tableFormat.setBorder(0);
|
tableFormat.setBorder(0);
|
||||||
QTextTable *table = cursor->insertTable(node->size() + 1, totalColumns, tableFormat);
|
QTextTable *table = cursor->insertTable(node->size() + 1, totalColumns, tableFormat);
|
||||||
for (int i = 0; i < node->size(); i++) {
|
for (int i = 0; i < node->size(); i++) {
|
||||||
AbstractDecklistCardNode *card = dynamic_cast<AbstractDecklistCardNode *>(node->at(i));
|
AbstractDecklistCardNode *card = dynamic_cast<AbstractDecklistCardNode *>(node->at(i));
|
||||||
|
|
||||||
QTextCharFormat cellCharFormat;
|
QTextCharFormat cellCharFormat;
|
||||||
cellCharFormat.setFontPointSize(9);
|
cellCharFormat.setFontPointSize(9);
|
||||||
|
|
||||||
QTextTableCell cell = table->cellAt(i, 0);
|
QTextTableCell cell = table->cellAt(i, 0);
|
||||||
cell.setFormat(cellCharFormat);
|
cell.setFormat(cellCharFormat);
|
||||||
QTextCursor cellCursor = cell.firstCursorPosition();
|
QTextCursor cellCursor = cell.firstCursorPosition();
|
||||||
cellCursor.insertText(QString("%1 ").arg(card->getNumber()));
|
cellCursor.insertText(QString("%1 ").arg(card->getNumber()));
|
||||||
|
|
||||||
cell = table->cellAt(i, 1);
|
cell = table->cellAt(i, 1);
|
||||||
cell.setFormat(cellCharFormat);
|
cell.setFormat(cellCharFormat);
|
||||||
cellCursor = cell.firstCursorPosition();
|
cellCursor = cell.firstCursorPosition();
|
||||||
cellCursor.insertText(card->getName());
|
cellCursor.insertText(card->getName());
|
||||||
|
|
||||||
if (settingsCache->getPriceTagFeature()) {
|
if (settingsCache->getPriceTagFeature()) {
|
||||||
cell = table->cellAt(i, 2);
|
cell = table->cellAt(i, 2);
|
||||||
cell.setFormat(cellCharFormat);
|
cell.setFormat(cellCharFormat);
|
||||||
cellCursor = cell.firstCursorPosition();
|
cellCursor = cell.firstCursorPosition();
|
||||||
cellCursor.insertText(QString().sprintf("$%.2f ", card->getTotalPrice()));
|
cellCursor.insertText(QString().sprintf("$%.2f ", card->getTotalPrice()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (node->height() == 2) {
|
} else if (node->height() == 2) {
|
||||||
QTextBlockFormat blockFormat;
|
QTextBlockFormat blockFormat;
|
||||||
QTextCharFormat charFormat;
|
QTextCharFormat charFormat;
|
||||||
charFormat.setFontPointSize(14);
|
charFormat.setFontPointSize(14);
|
||||||
charFormat.setFontWeight(QFont::Bold);
|
charFormat.setFontWeight(QFont::Bold);
|
||||||
|
|
||||||
cursor->insertBlock(blockFormat, charFormat);
|
cursor->insertBlock(blockFormat, charFormat);
|
||||||
QString priceStr;
|
QString priceStr;
|
||||||
if (settingsCache->getPriceTagFeature())
|
if (settingsCache->getPriceTagFeature())
|
||||||
priceStr = QString().sprintf(": $%.2f", node->recursivePrice(true));
|
priceStr = QString().sprintf(": $%.2f", node->recursivePrice(true));
|
||||||
cursor->insertText(QString("%1: %2").arg(node->getVisibleName()).arg(node->recursiveCount(true)).append(priceStr));
|
cursor->insertText(QString("%1: %2").arg(node->getVisibleName()).arg(node->recursiveCount(true)).append(priceStr));
|
||||||
|
|
||||||
QTextTableFormat tableFormat;
|
QTextTableFormat tableFormat;
|
||||||
tableFormat.setCellPadding(10);
|
tableFormat.setCellPadding(10);
|
||||||
tableFormat.setCellSpacing(0);
|
tableFormat.setCellSpacing(0);
|
||||||
tableFormat.setBorder(0);
|
tableFormat.setBorder(0);
|
||||||
QVector<QTextLength> constraints;
|
QVector<QTextLength> constraints;
|
||||||
for (int i = 0; i < totalColumns; i++)
|
for (int i = 0; i < totalColumns; i++)
|
||||||
constraints << QTextLength(QTextLength::PercentageLength, 100.0 / totalColumns);
|
constraints << QTextLength(QTextLength::PercentageLength, 100.0 / totalColumns);
|
||||||
tableFormat.setColumnWidthConstraints(constraints);
|
tableFormat.setColumnWidthConstraints(constraints);
|
||||||
|
|
||||||
QTextTable *table = cursor->insertTable(1, totalColumns, tableFormat);
|
QTextTable *table = cursor->insertTable(1, totalColumns, tableFormat);
|
||||||
for (int i = 0; i < node->size(); i++) {
|
for (int i = 0; i < node->size(); i++) {
|
||||||
QTextCursor cellCursor = table->cellAt(0, (i * totalColumns) / node->size()).lastCursorPosition();
|
QTextCursor cellCursor = table->cellAt(0, (i * totalColumns) / node->size()).lastCursorPosition();
|
||||||
printDeckListNode(&cellCursor, dynamic_cast<InnerDecklistNode *>(node->at(i)));
|
printDeckListNode(&cellCursor, dynamic_cast<InnerDecklistNode *>(node->at(i)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cursor->movePosition(QTextCursor::End);
|
cursor->movePosition(QTextCursor::End);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckListModel::printDeckList(QPrinter *printer)
|
void DeckListModel::printDeckList(QPrinter *printer)
|
||||||
{
|
{
|
||||||
QTextDocument doc;
|
QTextDocument doc;
|
||||||
|
|
||||||
QFont font("Serif");
|
QFont font("Serif");
|
||||||
font.setStyleHint(QFont::Serif);
|
font.setStyleHint(QFont::Serif);
|
||||||
doc.setDefaultFont(font);
|
doc.setDefaultFont(font);
|
||||||
|
|
||||||
QTextCursor cursor(&doc);
|
QTextCursor cursor(&doc);
|
||||||
|
|
||||||
QTextBlockFormat headerBlockFormat;
|
QTextBlockFormat headerBlockFormat;
|
||||||
QTextCharFormat headerCharFormat;
|
QTextCharFormat headerCharFormat;
|
||||||
headerCharFormat.setFontPointSize(16);
|
headerCharFormat.setFontPointSize(16);
|
||||||
headerCharFormat.setFontWeight(QFont::Bold);
|
headerCharFormat.setFontWeight(QFont::Bold);
|
||||||
|
|
||||||
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
||||||
cursor.insertText(deckList->getName());
|
cursor.insertText(deckList->getName());
|
||||||
|
|
||||||
headerCharFormat.setFontPointSize(12);
|
headerCharFormat.setFontPointSize(12);
|
||||||
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
||||||
cursor.insertText(deckList->getComments());
|
cursor.insertText(deckList->getComments());
|
||||||
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
||||||
|
|
||||||
for (int i = 0; i < root->size(); i++) {
|
for (int i = 0; i < root->size(); i++) {
|
||||||
cursor.insertHtml("<br><img src=:/resources/hr.jpg>");
|
cursor.insertHtml("<br><img src=:/resources/hr.jpg>");
|
||||||
//cursor.insertHtml("<hr>");
|
//cursor.insertHtml("<hr>");
|
||||||
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
||||||
|
|
||||||
printDeckListNode(&cursor, dynamic_cast<InnerDecklistNode *>(root->at(i)));
|
printDeckListNode(&cursor, dynamic_cast<InnerDecklistNode *>(root->at(i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
doc.print(printer);
|
doc.print(printer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckListModel::pricesUpdated(InnerDecklistNode *node)
|
void DeckListModel::pricesUpdated(InnerDecklistNode *node)
|
||||||
{
|
{
|
||||||
if (!node)
|
if (!node)
|
||||||
node = root;
|
node = root;
|
||||||
|
|
||||||
if (node->isEmpty())
|
if (node->isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
emit dataChanged(createIndex(0, 2, node->at(0)), createIndex(node->size() - 1, 2, node->last()));
|
emit dataChanged(createIndex(0, 2, node->at(0)), createIndex(node->size() - 1, 2, node->last()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,63 +13,63 @@ class QTextCursor;
|
||||||
|
|
||||||
class DecklistModelCardNode : public AbstractDecklistCardNode {
|
class DecklistModelCardNode : public AbstractDecklistCardNode {
|
||||||
private:
|
private:
|
||||||
DecklistCardNode *dataNode;
|
DecklistCardNode *dataNode;
|
||||||
public:
|
public:
|
||||||
DecklistModelCardNode(DecklistCardNode *_dataNode, InnerDecklistNode *_parent) : AbstractDecklistCardNode(_parent), dataNode(_dataNode) { }
|
DecklistModelCardNode(DecklistCardNode *_dataNode, InnerDecklistNode *_parent) : AbstractDecklistCardNode(_parent), dataNode(_dataNode) { }
|
||||||
int getNumber() const { return dataNode->getNumber(); }
|
int getNumber() const { return dataNode->getNumber(); }
|
||||||
void setNumber(int _number) { dataNode->setNumber(_number); }
|
void setNumber(int _number) { dataNode->setNumber(_number); }
|
||||||
float getPrice() const { return dataNode->getPrice(); }
|
float getPrice() const { return dataNode->getPrice(); }
|
||||||
void setPrice(float _price) { dataNode->setPrice(_price); }
|
void setPrice(float _price) { dataNode->setPrice(_price); }
|
||||||
QString getName() const { return dataNode->getName(); }
|
QString getName() const { return dataNode->getName(); }
|
||||||
void setName(const QString &_name) { dataNode->setName(_name); }
|
void setName(const QString &_name) { dataNode->setName(_name); }
|
||||||
DecklistCardNode *getDataNode() const { return dataNode; }
|
DecklistCardNode *getDataNode() const { return dataNode; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class DeckListModel : public QAbstractItemModel {
|
class DeckListModel : public QAbstractItemModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private slots:
|
private slots:
|
||||||
void rebuildTree();
|
void rebuildTree();
|
||||||
public slots:
|
public slots:
|
||||||
void printDeckList(QPrinter *printer);
|
void printDeckList(QPrinter *printer);
|
||||||
signals:
|
signals:
|
||||||
void deckHashChanged();
|
void deckHashChanged();
|
||||||
public:
|
public:
|
||||||
DeckListModel(QObject *parent = 0);
|
DeckListModel(QObject *parent = 0);
|
||||||
~DeckListModel();
|
~DeckListModel();
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const;
|
int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const;
|
||||||
QVariant data(const QModelIndex &index, int role) const;
|
QVariant data(const QModelIndex &index, int role) const;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
||||||
QModelIndex parent(const QModelIndex &index) const;
|
QModelIndex parent(const QModelIndex &index) const;
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
bool setData(const QModelIndex &index, const QVariant &value, int role);
|
bool setData(const QModelIndex &index, const QVariant &value, int role);
|
||||||
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
|
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
|
||||||
|
|
||||||
QModelIndex findCard(const QString &cardName, const QString &zoneName) const;
|
QModelIndex findCard(const QString &cardName, const QString &zoneName) const;
|
||||||
QModelIndex addCard(const QString &cardName, const QString &zoneName);
|
QModelIndex addCard(const QString &cardName, const QString &zoneName);
|
||||||
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
|
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
|
||||||
void cleanList();
|
void cleanList();
|
||||||
DeckLoader *getDeckList() const { return deckList; }
|
DeckLoader *getDeckList() const { return deckList; }
|
||||||
void setDeckList(DeckLoader *_deck);
|
void setDeckList(DeckLoader *_deck);
|
||||||
void pricesUpdated(InnerDecklistNode *node = 0);
|
void pricesUpdated(InnerDecklistNode *node = 0);
|
||||||
private:
|
private:
|
||||||
DeckLoader *deckList;
|
DeckLoader *deckList;
|
||||||
InnerDecklistNode *root;
|
InnerDecklistNode *root;
|
||||||
InnerDecklistNode *createNodeIfNeeded(const QString &name, InnerDecklistNode *parent);
|
InnerDecklistNode *createNodeIfNeeded(const QString &name, InnerDecklistNode *parent);
|
||||||
QModelIndex nodeToIndex(AbstractDecklistNode *node) const;
|
QModelIndex nodeToIndex(AbstractDecklistNode *node) const;
|
||||||
DecklistModelCardNode *findCardNode(const QString &cardName, const QString &zoneName) const;
|
DecklistModelCardNode *findCardNode(const QString &cardName, const QString &zoneName) const;
|
||||||
void emitRecursiveUpdates(const QModelIndex &index);
|
void emitRecursiveUpdates(const QModelIndex &index);
|
||||||
void sortHelper(InnerDecklistNode *node, Qt::SortOrder order);
|
void sortHelper(InnerDecklistNode *node, Qt::SortOrder order);
|
||||||
|
|
||||||
void printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node);
|
void printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node);
|
||||||
|
|
||||||
template<typename T> T getNode(const QModelIndex &index) const
|
template<typename T> T getNode(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return dynamic_cast<T>(root);
|
return dynamic_cast<T>(root);
|
||||||
return dynamic_cast<T>(static_cast<AbstractDecklistNode *>(index.internalPointer()));
|
return dynamic_cast<T>(static_cast<AbstractDecklistNode *>(index.internalPointer()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -20,98 +20,98 @@ class FilterTreeModel;
|
||||||
class CardInfo;
|
class CardInfo;
|
||||||
|
|
||||||
class SearchLineEdit : public QLineEdit {
|
class SearchLineEdit : public QLineEdit {
|
||||||
private:
|
private:
|
||||||
QTreeView *treeView;
|
QTreeView *treeView;
|
||||||
protected:
|
protected:
|
||||||
void keyPressEvent(QKeyEvent *event);
|
void keyPressEvent(QKeyEvent *event);
|
||||||
public:
|
public:
|
||||||
SearchLineEdit() : QLineEdit(), treeView(0) { }
|
SearchLineEdit() : QLineEdit(), treeView(0) { }
|
||||||
void setTreeView(QTreeView *_treeView) { treeView = _treeView; }
|
void setTreeView(QTreeView *_treeView) { treeView = _treeView; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class TabDeckEditor : public Tab {
|
class TabDeckEditor : public Tab {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private slots:
|
private slots:
|
||||||
void updateName(const QString &name);
|
void updateName(const QString &name);
|
||||||
void updateComments();
|
void updateComments();
|
||||||
void updateHash();
|
void updateHash();
|
||||||
void updateCardInfoLeft(const QModelIndex ¤t, const QModelIndex &previous);
|
void updateCardInfoLeft(const QModelIndex ¤t, const QModelIndex &previous);
|
||||||
void updateCardInfoRight(const QModelIndex ¤t, const QModelIndex &previous);
|
void updateCardInfoRight(const QModelIndex ¤t, const QModelIndex &previous);
|
||||||
void updateSearch(const QString &search);
|
void updateSearch(const QString &search);
|
||||||
|
|
||||||
void actNewDeck();
|
void actNewDeck();
|
||||||
void actLoadDeck();
|
void actLoadDeck();
|
||||||
bool actSaveDeck();
|
bool actSaveDeck();
|
||||||
bool actSaveDeckAs();
|
bool actSaveDeckAs();
|
||||||
void actLoadDeckFromClipboard();
|
void actLoadDeckFromClipboard();
|
||||||
void actSaveDeckToClipboard();
|
void actSaveDeckToClipboard();
|
||||||
void actPrintDeck();
|
void actPrintDeck();
|
||||||
void actAnalyzeDeck();
|
void actAnalyzeDeck();
|
||||||
|
|
||||||
void actEditSets();
|
void actEditSets();
|
||||||
void actEditTokens();
|
void actEditTokens();
|
||||||
|
|
||||||
void actClearSearch();
|
void actClearSearch();
|
||||||
|
|
||||||
void actAddCard();
|
void actAddCard();
|
||||||
void actAddCardToSideboard();
|
void actAddCardToSideboard();
|
||||||
void actRemoveCard();
|
void actRemoveCard();
|
||||||
void actIncrement();
|
void actIncrement();
|
||||||
void actDecrement();
|
void actDecrement();
|
||||||
void actDecrementCard();
|
void actDecrementCard();
|
||||||
void actDecrementCardFromSideboard();
|
void actDecrementCardFromSideboard();
|
||||||
|
|
||||||
void actUpdatePrices();
|
void actUpdatePrices();
|
||||||
|
|
||||||
void finishedUpdatingPrices();
|
void finishedUpdatingPrices();
|
||||||
void saveDeckRemoteFinished(const Response &r);
|
void saveDeckRemoteFinished(const Response &r);
|
||||||
void filterViewCustomContextMenu(const QPoint &point);
|
void filterViewCustomContextMenu(const QPoint &point);
|
||||||
void filterRemove(QAction *action);
|
void filterRemove(QAction *action);
|
||||||
private:
|
private:
|
||||||
CardInfo *currentCardInfo() const;
|
CardInfo *currentCardInfo() const;
|
||||||
void addCardHelper(QString zoneName);
|
void addCardHelper(QString zoneName);
|
||||||
void offsetCountAtIndex(const QModelIndex &idx, int offset);
|
void offsetCountAtIndex(const QModelIndex &idx, int offset);
|
||||||
void decrementCardHelper(QString zoneName);
|
void decrementCardHelper(QString zoneName);
|
||||||
void recursiveExpand(const QModelIndex &index);
|
void recursiveExpand(const QModelIndex &index);
|
||||||
bool confirmClose();
|
bool confirmClose();
|
||||||
|
|
||||||
CardDatabaseModel *databaseModel;
|
CardDatabaseModel *databaseModel;
|
||||||
CardDatabaseDisplayModel *databaseDisplayModel;
|
CardDatabaseDisplayModel *databaseDisplayModel;
|
||||||
DeckListModel *deckModel;
|
DeckListModel *deckModel;
|
||||||
QTreeView *databaseView;
|
QTreeView *databaseView;
|
||||||
KeySignals dbViewKeySignals;
|
KeySignals dbViewKeySignals;
|
||||||
QTreeView *deckView;
|
QTreeView *deckView;
|
||||||
KeySignals deckViewKeySignals;
|
KeySignals deckViewKeySignals;
|
||||||
CardFrame *cardInfo;
|
CardFrame *cardInfo;
|
||||||
QLabel *searchLabel;
|
QLabel *searchLabel;
|
||||||
SearchLineEdit *searchEdit;
|
SearchLineEdit *searchEdit;
|
||||||
KeySignals searchKeySignals;
|
KeySignals searchKeySignals;
|
||||||
QLabel *nameLabel;
|
QLabel *nameLabel;
|
||||||
QLineEdit *nameEdit;
|
QLineEdit *nameEdit;
|
||||||
QLabel *commentsLabel;
|
QLabel *commentsLabel;
|
||||||
QTextEdit *commentsEdit;
|
QTextEdit *commentsEdit;
|
||||||
QLabel *hashLabel1;
|
QLabel *hashLabel1;
|
||||||
QLabel *hashLabel;
|
QLabel *hashLabel;
|
||||||
FilterTreeModel *filterModel;
|
FilterTreeModel *filterModel;
|
||||||
QTreeView *filterView;
|
QTreeView *filterView;
|
||||||
|
|
||||||
QMenu *deckMenu, *dbMenu;
|
QMenu *deckMenu, *dbMenu;
|
||||||
QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aLoadDeckFromClipboard, *aSaveDeckToClipboard, *aPrintDeck, *aAnalyzeDeck, *aClose;
|
QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aLoadDeckFromClipboard, *aSaveDeckToClipboard, *aPrintDeck, *aAnalyzeDeck, *aClose;
|
||||||
QAction *aEditSets, *aEditTokens, *aClearSearch, *aCardTextOnly;
|
QAction *aEditSets, *aEditTokens, *aClearSearch, *aCardTextOnly;
|
||||||
QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement, *aUpdatePrices;
|
QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement, *aUpdatePrices;
|
||||||
|
|
||||||
bool modified;
|
bool modified;
|
||||||
public:
|
public:
|
||||||
TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent = 0);
|
TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent = 0);
|
||||||
~TabDeckEditor();
|
~TabDeckEditor();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
QString getTabText() const;
|
QString getTabText() const;
|
||||||
void setDeck(DeckLoader *_deckLoader);
|
void setDeck(DeckLoader *_deckLoader);
|
||||||
void setModified(bool _windowModified);
|
void setModified(bool _windowModified);
|
||||||
public slots:
|
public slots:
|
||||||
void closeRequest();
|
void closeRequest();
|
||||||
signals:
|
signals:
|
||||||
void deckEditorClosing(TabDeckEditor *tab);
|
void deckEditorClosing(TabDeckEditor *tab);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue