Commit 748aac7e authored by sylvanbasilisk's avatar sylvanbasilisk
Browse files

whitespace modifications in preparation for merge

parent 378cc91c
...@@ -2,12 +2,12 @@ ...@@ -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() ...@@ -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 @@ ...@@ -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 @@ ...@@ -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; ...@@ -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
...@@ -39,665 +39,665 @@ ...@@ -39,665 +39,665 @@
void SearchLineEdit::keyPressEvent(QKeyEvent *event) void SearchLineEdit::keyPressEvent(QKeyEvent *event)
{ {
if (treeView && ((event->key() == Qt::Key_Up) || (event->key() == Qt::Key_Down))) if (treeView && ((event->key() == Qt::Key_Up) || (event->key() == Qt::Key_Down)))
QCoreApplication::sendEvent(treeView, event); QCoreApplication::sendEvent(treeView, event);
QLineEdit::keyPressEvent(event); QLineEdit::keyPressEvent(event);
} }
TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent) TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent)
: Tab(_tabSupervisor, parent), modified(false) : Tab(_tabSupervisor, parent), modified(false)
{ {
aClearSearch = new QAction(QString(), this); aClearSearch = new QAction(QString(), this);
aClearSearch->setIcon(QIcon(":/resources/icon_clearsearch.svg")); aClearSearch->setIcon(QIcon(":/resources/icon_clearsearch.svg"));
connect(aClearSearch, SIGNAL(triggered()), this, SLOT(actClearSearch())); connect(aClearSearch, SIGNAL(triggered()), this, SLOT(actClearSearch()));
searchLabel = new QLabel(); searchLabel = new QLabel();
searchEdit = new SearchLineEdit; searchEdit = new SearchLineEdit;
searchLabel->setBuddy(searchEdit); searchLabel->setBuddy(searchEdit);
searchKeySignals.filterDelete(false); searchKeySignals.filterDelete(false);
searchEdit->installEventFilter(&searchKeySignals); searchEdit->installEventFilter(&searchKeySignals);
connect(searchEdit, SIGNAL(textChanged(const QString &)), this, SLOT(updateSearch(const QString &))); connect(searchEdit, SIGNAL(textChanged(const QString &)), this, SLOT(updateSearch(const QString &)));
connect(&searchKeySignals, SIGNAL(onEnter()), this, SLOT(actAddCard())); connect(&searchKeySignals, SIGNAL(onEnter()), this, SLOT(actAddCard()));
connect(&searchKeySignals, SIGNAL(onRight()), this, SLOT(actAddCard())); connect(&searchKeySignals, SIGNAL(onRight()), this, SLOT(actAddCard()));
connect(&searchKeySignals, SIGNAL(onCtrlRight()), this, SLOT(actAddCardToSideboard())); connect(&searchKeySignals, SIGNAL(onCtrlRight()), this, SLOT(actAddCardToSideboard()));
connect(&searchKeySignals, SIGNAL(onLeft()), this, SLOT(actDecrementCard())); connect(&searchKeySignals, SIGNAL(onLeft()), this, SLOT(actDecrementCard()));
connect(&searchKeySignals, SIGNAL(onCtrlLeft()), this, SLOT(actDecrementCardFromSideboard())); connect(&searchKeySignals, SIGNAL(onCtrlLeft()), this, SLOT(actDecrementCardFromSideboard()));
connect(&searchKeySignals, SIGNAL(onCtrlEnter()), this, SLOT(actAddCardToSideboard())); connect(&searchKeySignals, SIGNAL(onCtrlEnter()), this, SLOT(actAddCardToSideboard()));
QToolBar *deckEditToolBar = new QToolBar; QToolBar *deckEditToolBar = new QToolBar;
deckEditToolBar->setOrientation(Qt::Horizontal); deckEditToolBar->setOrientation(Qt::Horizontal);
deckEditToolBar->setIconSize(QSize(24, 24)); deckEditToolBar->setIconSize(QSize(24, 24));
QHBoxLayout *searchLayout = new QHBoxLayout; QHBoxLayout *searchLayout = new QHBoxLayout;
searchLayout->addWidget(deckEditToolBar); searchLayout->addWidget(deckEditToolBar);
searchLayout->addWidget(searchLabel); searchLayout->addWidget(searchLabel);
searchLayout->addWidget(searchEdit); searchLayout->addWidget(searchEdit);
databaseModel = new CardDatabaseModel(db, this); databaseModel = new CardDatabaseModel(db, this);
databaseDisplayModel = new CardDatabaseDisplayModel(this); databaseDisplayModel = new CardDatabaseDisplayModel(this);
databaseDisplayModel->setSourceModel(databaseModel); databaseDisplayModel->setSourceModel(databaseModel);
databaseDisplayModel->setFilterKeyColumn(0); databaseDisplayModel->setFilterKeyColumn(0);
databaseDisplayModel->sort(0, Qt::AscendingOrder); databaseDisplayModel->sort(0, Qt::AscendingOrder);
databaseView = new QTreeView(); databaseView = new QTreeView();
databaseView->setModel(databaseDisplayModel); databaseView->setModel(databaseDisplayModel);
databaseView->setUniformRowHeights(true); databaseView->setUniformRowHeights(true);
databaseView->setRootIsDecorated(false); databaseView->setRootIsDecorated(false);
databaseView->setAlternatingRowColors(true); databaseView->setAlternatingRowColors(true);
databaseView->setSortingEnabled(true); databaseView->setSortingEnabled(true);
databaseView->sortByColumn(0, Qt::AscendingOrder); databaseView->sortByColumn(0, Qt::AscendingOrder);
databaseView->resizeColumnToContents(0); databaseView->resizeColumnToContents(0);
connect(databaseView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(updateCardInfoLeft(const QModelIndex &, const QModelIndex &))); connect(databaseView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(updateCardInfoLeft(const QModelIndex &, const QModelIndex &)));
connect(databaseView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(actAddCard())); connect(databaseView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(actAddCard()));
databaseView->installEventFilter(&dbViewKeySignals); databaseView->installEventFilter(&dbViewKeySignals);
connect(&dbViewKeySignals, SIGNAL(onEnter()), this, SLOT(actAddCard())); connect(&dbViewKeySignals, SIGNAL(onEnter()), this, SLOT(actAddCard()));
connect(&dbViewKeySignals, SIGNAL(onRight()), this, SLOT(actAddCard())); connect(&dbViewKeySignals, SIGNAL(onRight()), this, SLOT(actAddCard()));
connect(&dbViewKeySignals, SIGNAL(onCtrlRight()), this, SLOT(actAddCardToSideboard())); connect(&dbViewKeySignals, SIGNAL(onCtrlRight()), this, SLOT(actAddCardToSideboard()));
connect(&dbViewKeySignals, SIGNAL(onLeft()), this, SLOT(actDecrementCard())); connect(&dbViewKeySignals, SIGNAL(onLeft()), this, SLOT(actDecrementCard()));
connect(&dbViewKeySignals, SIGNAL(onCtrlLeft()), this, SLOT(actDecrementCardFromSideboard())); connect(&dbViewKeySignals, SIGNAL(onCtrlLeft()), this, SLOT(actDecrementCardFromSideboard()));
connect(&dbViewKeySignals, SIGNAL(onCtrlEnter()), this, SLOT(actAddCardToSideboard())); connect(&dbViewKeySignals, SIGNAL(onCtrlEnter()), this, SLOT(actAddCardToSideboard()));
searchEdit->setTreeView(databaseView); searchEdit->setTreeView(databaseView);
QVBoxLayout *leftFrame = new QVBoxLayout; QVBoxLayout *leftFrame = new QVBoxLayout;
leftFrame->addLayout(searchLayout); leftFrame->addLayout(searchLayout);
leftFrame->addWidget(databaseView); leftFrame->addWidget(databaseView);
cardInfo = new CardFrame(250, 356); cardInfo = new CardFrame(250, 356);
aCardTextOnly = new QAction(QString(), this); aCardTextOnly = new QAction(QString(), this);
aCardTextOnly->setCheckable(true); aCardTextOnly->setCheckable(true);
connect(aCardTextOnly, SIGNAL(triggered()), cardInfo, SLOT(toggleCardTextOnly())); connect(aCardTextOnly, SIGNAL(triggered()), cardInfo, SLOT(toggleCardTextOnly()));
filterModel = new FilterTreeModel(); filterModel = new FilterTreeModel();
databaseDisplayModel->setFilterTree(filterModel->filterTree()); databaseDisplayModel->setFilterTree(filterModel->filterTree());
filterView = new QTreeView; filterView = new QTreeView;
filterView->setModel(filterModel); filterView->setModel(filterModel);
filterView->setMaximumWidth(250); filterView->setMaximumWidth(250);
filterView->setUniformRowHeights(true); filterView->setUniformRowHeights(true);
filterView->setHeaderHidden(true); filterView->setHeaderHidden(true);
filterView->setContextMenuPolicy(Qt::CustomContextMenu); filterView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(filterModel, SIGNAL(layoutChanged()), filterView, SLOT(expandAll())); connect(filterModel, SIGNAL(layoutChanged()), filterView, SLOT(expandAll()));
connect(filterView, SIGNAL(customContextMenuRequested(const QPoint &)), connect(filterView, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(filterViewCustomContextMenu(const QPoint &))); this, SLOT(filterViewCustomContextMenu(const QPoint &)));
FilterBuilder *filterBuilder = new FilterBuilder; FilterBuilder *filterBuilder = new FilterBuilder;
filterBuilder->setMaximumWidth(250); filterBuilder->setMaximumWidth(250);
connect(filterBuilder, SIGNAL(add(const CardFilter *)), filterModel, SLOT(addFilter(const CardFilter *))); connect(filterBuilder, SIGNAL(add(const CardFilter *)), filterModel, SLOT(addFilter(const CardFilter *)));
QVBoxLayout *filter = new QVBoxLayout; QVBoxLayout *filter = new QVBoxLayout;
filter->addWidget(filterBuilder, 0, Qt::AlignTop); filter->addWidget(filterBuilder, 0, Qt::AlignTop);
filter->addWidget(filterView, 10); filter->addWidget(filterView, 10);
QVBoxLayout *middleFrame = new QVBoxLayout; QVBoxLayout *middleFrame = new QVBoxLayout;
middleFrame->addWidget(cardInfo, 0, Qt::AlignTop); middleFrame->addWidget(cardInfo, 0, Qt::AlignTop);
middleFrame->addLayout(filter, 10); middleFrame->addLayout(filter, 10);
deckModel = new DeckListModel(this); deckModel = new DeckListModel(this);
connect(deckModel, SIGNAL(deckHashChanged()), this, SLOT(updateHash())); connect(deckModel, SIGNAL(deckHashChanged()), this, SLOT(updateHash()));
deckView = new QTreeView(); deckView = new QTreeView();
deckView->setModel(deckModel); deckView->setModel(deckModel);
deckView->setUniformRowHeights(true); deckView->setUniformRowHeights(true);
deckView->header()->setResizeMode(QHeaderView::ResizeToContents); deckView->header()->setResizeMode(QHeaderView::ResizeToContents);
deckViewKeySignals.filterLeftRight(false); deckViewKeySignals.filterLeftRight(false);
deckView->installEventFilter(&deckViewKeySignals); deckView->installEventFilter(&deckViewKeySignals);
connect(deckView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(updateCardInfoRight(const QModelIndex &, const QModelIndex &))); connect(deckView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(updateCardInfoRight(const QModelIndex &, const QModelIndex &)));
connect(&deckViewKeySignals, SIGNAL(onEnter()), this, SLOT(actIncrement())); connect(&deckViewKeySignals, SIGNAL(onEnter()), this, SLOT(actIncrement()));
connect(&deckViewKeySignals, SIGNAL(onRight()), this, SLOT(actIncrement())); connect(&deckViewKeySignals, SIGNAL(onRight()), this, SLOT(actIncrement()));
connect(&deckViewKeySignals, SIGNAL(onLeft()), this, SLOT(actDecrement())); connect(&deckViewKeySignals, SIGNAL(onLeft()), this, SLOT(actDecrement()));
connect(&deckViewKeySignals, SIGNAL(onDelete()), this, SLOT(actRemoveCard())); connect(&deckViewKeySignals, SIGNAL(onDelete()), this, SLOT(actRemoveCard()));
nameLabel = new QLabel(); nameLabel = new QLabel();
nameEdit = new QLineEdit; nameEdit = new QLineEdit;
nameLabel->setBuddy(nameEdit); nameLabel->setBuddy(nameEdit);
connect(nameEdit, SIGNAL(textChanged(const QString &)), this, SLOT(updateName(const QString &))); connect(nameEdit, SIGNAL(textChanged(const QString &)), this, SLOT(updateName(const QString &)));
commentsLabel = new QLabel(); commentsLabel = new QLabel();
commentsEdit = new QTextEdit; commentsEdit = new QTextEdit;
commentsEdit->setMaximumHeight(70); commentsEdit->setMaximumHeight(70);
commentsLabel->setBuddy(commentsEdit); commentsLabel->setBuddy(commentsEdit);
connect(commentsEdit, SIGNAL(textChanged()), this, SLOT(updateComments())); connect(commentsEdit, SIGNAL(textChanged()), this, SLOT(updateComments()));
hashLabel1 = new QLabel(); hashLabel1 = new QLabel();
hashLabel = new QLabel; hashLabel = new QLabel;
QGridLayout *grid = new QGridLayout; QGridLayout *grid = new QGridLayout;
grid->addWidget(nameLabel, 0, 0); grid->addWidget(nameLabel, 0, 0);
grid->addWidget(nameEdit, 0, 1); grid->addWidget(nameEdit, 0, 1);
grid->addWidget(commentsLabel, 1, 0); grid->addWidget(commentsLabel, 1, 0);
grid->addWidget(commentsEdit, 1, 1); grid->addWidget(commentsEdit, 1, 1);
grid->addWidget(hashLabel1, 2, 0); grid->addWidget(hashLabel1, 2, 0);
grid->addWidget(hashLabel, 2, 1); grid->addWidget(hashLabel, 2, 1);
// Update price // Update price
aUpdatePrices = new QAction(QString(), this); aUpdatePrices = new QAction(QString(), this);
aUpdatePrices->setIcon(QIcon(":/resources/icon_update.png")); aUpdatePrices->setIcon(QIcon(":/resources/icon_update.png"));
connect(aUpdatePrices, SIGNAL(triggered()), this, SLOT(actUpdatePrices())); connect(aUpdatePrices, SIGNAL(triggered()), this, SLOT(actUpdatePrices()));
if (!settingsCache->getPriceTagFeature()) if (!settingsCache->getPriceTagFeature())
aUpdatePrices->setVisible(false); aUpdatePrices->setVisible(false);
QToolBar *deckToolBar = new QToolBar; QToolBar *deckToolBar = new QToolBar;
deckToolBar->setOrientation(Qt::Vertical); deckToolBar->setOrientation(Qt::Vertical);
deckToolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); deckToolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
deckToolBar->setIconSize(QSize(24, 24)); deckToolBar->setIconSize(QSize(24, 24));
deckToolBar->addAction(aUpdatePrices); deckToolBar->addAction(aUpdatePrices);
QHBoxLayout *deckToolbarLayout = new QHBoxLayout; QHBoxLayout *deckToolbarLayout = new QHBoxLayout;
deckToolbarLayout->addStretch(); deckToolbarLayout->addStretch();
deckToolbarLayout->addWidget(deckToolBar); deckToolbarLayout->addWidget(deckToolBar);
deckToolbarLayout->addStretch(); deckToolbarLayout->addStretch();
QVBoxLayout *rightFrame = new QVBoxLayout; QVBoxLayout *rightFrame = new QVBoxLayout;
rightFrame->addLayout(grid); rightFrame->addLayout(grid);
rightFrame->addWidget(deckView, 10); rightFrame->addWidget(deckView, 10);
rightFrame->addLayout(deckToolbarLayout); rightFrame->addLayout(deckToolbarLayout);
QHBoxLayout *mainLayout = new QHBoxLayout; QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addLayout(leftFrame, 10); mainLayout->addLayout(leftFrame, 10);
mainLayout->addLayout(middleFrame); mainLayout->addLayout(middleFrame);
mainLayout->addLayout(rightFrame); mainLayout->addLayout(rightFrame);
setLayout(mainLayout); setLayout(mainLayout);
aNewDeck = new QAction(QString(), this); aNewDeck = new QAction(QString(), this);
aNewDeck->setShortcuts(QKeySequence::New); aNewDeck->setShortcuts(QKeySequence::New);
connect(aNewDeck, SIGNAL(triggered()), this, SLOT(actNewDeck())); connect(aNewDeck, SIGNAL(triggered()), this, SLOT(actNewDeck()));
aLoadDeck = new QAction(QString(), this); aLoadDeck = new QAction(QString(), this);
aLoadDeck->setShortcuts(QKeySequence::Open); aLoadDeck->setShortcuts(QKeySequence::Open);
connect(aLoadDeck, SIGNAL(triggered()), this, SLOT(actLoadDeck())); connect(aLoadDeck, SIGNAL(triggered()), this, SLOT(actLoadDeck()));
aSaveDeck = new QAction(QString(), this); aSaveDeck = new QAction(QString(), this);
aSaveDeck->setShortcuts(QKeySequence::Save); aSaveDeck->setShortcuts(QKeySequence::Save);
connect(aSaveDeck, SIGNAL(triggered()), this, SLOT(actSaveDeck())); connect(aSaveDeck, SIGNAL(triggered()), this, SLOT(actSaveDeck()));
aSaveDeckAs = new QAction(QString(), this); aSaveDeckAs = new QAction(QString(), this);
// aSaveDeckAs->setShortcuts(QKeySequence::SaveAs); // aSaveDeckAs->setShortcuts(QKeySequence::SaveAs);
connect(aSaveDeckAs, SIGNAL(triggered()), this, SLOT(actSaveDeckAs())); connect(aSaveDeckAs, SIGNAL(triggered()), this, SLOT(actSaveDeckAs()));
aLoadDeckFromClipboard = new QAction(QString(), this); aLoadDeckFromClipboard = new QAction(QString(), this);
connect(aLoadDeckFromClipboard, SIGNAL(triggered()), this, SLOT(actLoadDeckFromClipboard())); connect(aLoadDeckFromClipboard, SIGNAL(triggered()), this, SLOT(actLoadDeckFromClipboard()));
aLoadDeckFromClipboard->setShortcuts(QKeySequence::Paste); aLoadDeckFromClipboard->setShortcuts(QKeySequence::Paste);
aSaveDeckToClipboard = new QAction(QString(), this); aSaveDeckToClipboard = new QAction(QString(), this);
connect(aSaveDeckToClipboard, SIGNAL(triggered()), this, SLOT(actSaveDeckToClipboard())); connect(aSaveDeckToClipboard, SIGNAL(triggered()), this, SLOT(actSaveDeckToClipboard()));
aSaveDeckToClipboard->setShortcuts(QKeySequence::Copy); aSaveDeckToClipboard->setShortcuts(QKeySequence::Copy);
aPrintDeck = new QAction(QString(), this); aPrintDeck = new QAction(QString(), this);
aPrintDeck->setShortcuts(QKeySequence::Print); aPrintDeck->setShortcuts(QKeySequence::Print);
connect(aPrintDeck, SIGNAL(triggered()), this, SLOT(actPrintDeck())); connect(aPrintDeck, SIGNAL(triggered()), this, SLOT(actPrintDeck()));
aAnalyzeDeck = new QAction(QString(), this); aAnalyzeDeck = new QAction(QString(), this);
connect(aAnalyzeDeck, SIGNAL(triggered()), this, SLOT(actAnalyzeDeck())); connect(aAnalyzeDeck, SIGNAL(triggered()), this, SLOT(actAnalyzeDeck()));
aClose = new QAction(QString(), this); aClose = new QAction(QString(), this);
connect(aClose, SIGNAL(triggered()), this, SLOT(closeRequest())); connect(aClose, SIGNAL(triggered()), this, SLOT(closeRequest()));
aEditSets = new QAction(QString(), this); aEditSets = new QAction(QString(), this);
connect(aEditSets, SIGNAL(triggered()), this, SLOT(actEditSets())); connect(aEditSets, SIGNAL(triggered()), this, SLOT(actEditSets()));
aEditTokens = new QAction(QString(), this); aEditTokens = new QAction(QString(), this);
connect(aEditTokens, SIGNAL(triggered()), this, SLOT(actEditTokens())); connect(aEditTokens, SIGNAL(triggered()), this, SLOT(actEditTokens()));
deckMenu = new QMenu(this); deckMenu = new QMenu(this);
deckMenu->addAction(aNewDeck); deckMenu->addAction(aNewDeck);
deckMenu->addAction(aLoadDeck); deckMenu->addAction(aLoadDeck);
deckMenu->addAction(aSaveDeck); deckMenu->addAction(aSaveDeck);
deckMenu->addAction(aSaveDeckAs); deckMenu->addAction(aSaveDeckAs);
deckMenu->addSeparator(); deckMenu->addSeparator();
deckMenu->addAction(aLoadDeckFromClipboard); deckMenu->addAction(aLoadDeckFromClipboard);
deckMenu->addAction(aSaveDeckToClipboard); deckMenu->addAction(aSaveDeckToClipboard);
deckMenu->addSeparator(); deckMenu->addSeparator();
deckMenu->addAction(aPrintDeck); deckMenu->addAction(aPrintDeck);
deckMenu->addSeparator(); deckMenu->addSeparator();
deckMenu->addAction(aAnalyzeDeck); deckMenu->addAction(aAnalyzeDeck);
deckMenu->addSeparator(); deckMenu->addSeparator();
deckMenu->addAction(aClose); deckMenu->addAction(aClose);
addTabMenu(deckMenu); addTabMenu(deckMenu);
dbMenu = new QMenu(this); dbMenu = new QMenu(this);
dbMenu->addAction(aEditSets); dbMenu->addAction(aEditSets);
dbMenu->addAction(aEditTokens); dbMenu->addAction(aEditTokens);
dbMenu->addSeparator(); dbMenu->addSeparator();
dbMenu->addAction(aClearSearch); dbMenu->addAction(aClearSearch);
dbMenu->addAction(aCardTextOnly); dbMenu->addAction(aCardTextOnly);
addTabMenu(dbMenu); addTabMenu(dbMenu);
aAddCard = new QAction(QString(), this); aAddCard = new QAction(QString(), this);
aAddCard->setIcon(QIcon(":/resources/arrow_right_green.svg")); aAddCard->setIcon(QIcon(":/resources/arrow_right_green.svg"));
connect(aAddCard, SIGNAL(triggered()), this, SLOT(actAddCard())); connect(aAddCard, SIGNAL(triggered()), this, SLOT(actAddCard()));
aAddCardToSideboard = new QAction(QString(), this); aAddCardToSideboard = new QAction(QString(), this);
aAddCardToSideboard->setIcon(QIcon(":/resources/add_to_sideboard.svg")); aAddCardToSideboard->setIcon(QIcon(":/resources/add_to_sideboard.svg"));
connect(aAddCardToSideboard, SIGNAL(triggered()), this, SLOT(actAddCardToSideboard())); connect(aAddCardToSideboard, SIGNAL(triggered()), this, SLOT(actAddCardToSideboard()));
aRemoveCard = new QAction(QString(), this); aRemoveCard = new QAction(QString(), this);
aRemoveCard->setIcon(QIcon(":/resources/remove_row.svg")); aRemoveCard->setIcon(QIcon(":/resources/remove_row.svg"));
connect(aRemoveCard, SIGNAL(triggered()), this, SLOT(actRemoveCard())); connect(aRemoveCard, SIGNAL(triggered()), this, SLOT(actRemoveCard()));
aIncrement = new QAction(QString(), this); aIncrement = new QAction(QString(), this);
aIncrement->setIcon(QIcon(":/resources/increment.svg")); aIncrement->setIcon(QIcon(":/resources/increment.svg"));
connect(aIncrement, SIGNAL(triggered()), this, SLOT(actIncrement())); connect(aIncrement, SIGNAL(triggered()), this, SLOT(actIncrement()));
aDecrement = new QAction(QString(), this); aDecrement = new QAction(QString(), this);
aDecrement->setIcon(QIcon(":/resources/decrement.svg")); aDecrement->setIcon(QIcon(":/resources/decrement.svg"));
connect(aDecrement, SIGNAL(triggered()), this, SLOT(actDecrement())); connect(aDecrement, SIGNAL(triggered()), this, SLOT(actDecrement()));
deckEditToolBar->addAction(aAddCard); deckEditToolBar->addAction(aAddCard);
deckEditToolBar->addAction(aAddCardToSideboard); deckEditToolBar->addAction(aAddCardToSideboard);
deckEditToolBar->addAction(aRemoveCard); deckEditToolBar->addAction(aRemoveCard);
deckEditToolBar->addAction(aIncrement); deckEditToolBar->addAction(aIncrement);
deckEditToolBar->addAction(aDecrement); deckEditToolBar->addAction(aDecrement);
deckEditToolBar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); deckEditToolBar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
retranslateUi(); retranslateUi();
resize(950, 700); resize(950, 700);
} }
TabDeckEditor::~TabDeckEditor() TabDeckEditor::~TabDeckEditor()
{ {
emit deckEditorClosing(this); emit deckEditorClosing(this);
} }
void TabDeckEditor::retranslateUi() void TabDeckEditor::retranslateUi()
{ {
aCardTextOnly->setText(tr("Show card text only")); aCardTextOnly->setText(tr("Show card text only"));
aClearSearch->setText(tr("&Clear search")); aClearSearch->setText(tr("&Clear search"));
searchLabel->setText(tr("&Search for:")); searchLabel->setText(tr("&Search for:"));
nameLabel->setText(tr("Deck &name:")); nameLabel->setText(tr("Deck &name:"));
commentsLabel->setText(tr("&Comments:")); commentsLabel->setText(tr("&Comments:"));
hashLabel1->setText(tr("Hash:")); hashLabel1->setText(tr("Hash:"));
aUpdatePrices->setText(tr("&Update prices")); aUpdatePrices->setText(tr("&Update prices"));
aUpdatePrices->setShortcut(tr("Ctrl+U")); aUpdatePrices->setShortcut(tr("Ctrl+U"));
aNewDeck->setText(tr("&New deck")); aNewDeck->setText(tr("&New deck"));
aLoadDeck->setText(tr("&Load deck...")); aLoadDeck->setText(tr("&Load deck..."));
aSaveDeck->setText(tr("&Save deck")); aSaveDeck->setText(tr("&Save deck"));
aSaveDeckAs->setText(tr("Save deck &as...")); aSaveDeckAs->setText(tr("Save deck &as..."));
aLoadDeckFromClipboard->setText(tr("Load deck from cl&ipboard...")); aLoadDeckFromClipboard->setText(tr("Load deck from cl&ipboard..."));
aSaveDeckToClipboard->setText(tr("Save deck to clip&board")); aSaveDeckToClipboard->setText(tr("Save deck to clip&board"));
aPrintDeck->setText(tr("&Print deck...")); aPrintDeck->setText(tr("&Print deck..."));
aAnalyzeDeck->setText(tr("&Analyze deck on deckstats.net")); aAnalyzeDeck->setText(tr("&Analyze deck on deckstats.net"));
aClose->setText(tr("&Close")); aClose->setText(tr("&Close"));
aClose->setShortcut(tr("Ctrl+Q")); aClose->setShortcut(tr("Ctrl+Q"));
aAddCard->setText(tr("Add card to &maindeck")); aAddCard->setText(tr("Add card to &maindeck"));
aAddCardToSideboard->setText(tr("Add card to &sideboard")); aAddCardToSideboard->setText(tr("Add card to &sideboard"));
aRemoveCard->setText(tr("&Remove row")); aRemoveCard->setText(tr("&Remove row"));
aRemoveCard->setShortcut(tr("Del")); aRemoveCard->setShortcut(tr("Del"));
aIncrement->setText(tr("&Increment number")); aIncrement->setText(tr("&Increment number"));
aIncrement->setShortcut(tr("+")); aIncrement->setShortcut(tr("+"));
aDecrement->setText(tr("&Decrement number")); aDecrement->setText(tr("&Decrement number"));
aDecrement->setShortcut(tr("-")); aDecrement->setShortcut(tr("-"));
deckMenu->setTitle(tr("&Deck editor")); deckMenu->setTitle(tr("&Deck editor"));
dbMenu->setTitle(tr("C&ard database")); dbMenu->setTitle(tr("C&ard database"));
aEditSets->setText(tr("&Edit sets...")); aEditSets->setText(tr("&Edit sets..."));
aEditTokens->setText(tr("Edit &tokens...")); aEditTokens->setText(tr("Edit &tokens..."));
} }
QString TabDeckEditor::getTabText() const QString TabDeckEditor::getTabText() const
{ {
QString result = tr("Deck: %1").arg(nameEdit->text()); QString result = tr("Deck: %1").arg(nameEdit->text());
if (modified) if (modified)
result.prepend("* "); result.prepend("* ");
return result; return result;
} }
void TabDeckEditor::updateName(const QString &name) void TabDeckEditor::updateName(const QString &name)
{ {
deckModel->getDeckList()->setName(name); deckModel->getDeckList()->setName(name);
setModified(true); setModified(true);
} }
void TabDeckEditor::updateComments() void TabDeckEditor::updateComments()
{ {
deckModel->getDeckList()->setComments(commentsEdit->toPlainText()); deckModel->getDeckList()->setComments(commentsEdit->toPlainText());
setModified(true); setModified(true);
} }
void TabDeckEditor::updateCardInfoLeft(const QModelIndex &current, const QModelIndex &/*previous*/) void TabDeckEditor::updateCardInfoLeft(const QModelIndex &current, const QModelIndex &/*previous*/)
{ {
cardInfo->setCard(current.sibling(current.row(), 0).data().toString()); cardInfo->setCard(current.sibling(current.row(), 0).data().toString());
} }
void TabDeckEditor::updateCardInfoRight(const QModelIndex &current, const QModelIndex &/*previous*/) void TabDeckEditor::updateCardInfoRight(const QModelIndex &current, const QModelIndex &/*previous*/)
{ {
if (!current.isValid()) if (!current.isValid())
return; return;
if (!current.model()->hasChildren(current.sibling(current.row(), 0))) if (!current.model()->hasChildren(current.sibling(current.row(), 0)))
cardInfo->setCard(current.sibling(current.row(), 1).data().toString()); cardInfo->setCard(current.sibling(current.row(), 1).data().toString());
} }
void TabDeckEditor::updateSearch(const QString &search) void TabDeckEditor::updateSearch(const QString &search)
{ {
databaseDisplayModel->setCardNameBeginning(search); databaseDisplayModel->setCardNameBeginning(search);
QModelIndexList sel = databaseView->selectionModel()->selectedRows(); QModelIndexList sel = databaseView->selectionModel()->selectedRows();
if (sel.isEmpty() && databaseDisplayModel->rowCount()) if (sel.isEmpty() && databaseDisplayModel->rowCount())
databaseView->selectionModel()->setCurrentIndex(databaseDisplayModel->index(0, 0), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); databaseView->selectionModel()->setCurrentIndex(databaseDisplayModel->index(0, 0), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
} }
void TabDeckEditor::updateHash() void TabDeckEditor::updateHash()
{ {
hashLabel->setText(deckModel->getDeckList()->getDeckHash()); hashLabel->setText(deckModel->getDeckList()->getDeckHash());
} }
bool TabDeckEditor::confirmClose() bool TabDeckEditor::confirmClose()
{ {
if (modified) { if (modified) {
QMessageBox::StandardButton ret = QMessageBox::warning(this, tr("Are you sure?"), QMessageBox::StandardButton ret = QMessageBox::warning(this, tr("Are you sure?"),
tr("The decklist has been modified.\nDo you want to save the changes?"), tr("The decklist has been modified.\nDo you want to save the changes?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
if (ret == QMessageBox::Save) if (ret == QMessageBox::Save)
return actSaveDeck(); return actSaveDeck();
else if (ret == QMessageBox::Cancel) else if (ret == QMessageBox::Cancel)
return false; return false;
} }
return true; return true;
} }
void TabDeckEditor::closeRequest() void TabDeckEditor::closeRequest()
{ {
if (confirmClose()) if (confirmClose())
deleteLater(); deleteLater();
} }
void TabDeckEditor::actNewDeck() void TabDeckEditor::actNewDeck()
{ {
if (!confirmClose()) if (!confirmClose())
return; return;
deckModel->cleanList(); deckModel->cleanList();
nameEdit->setText(QString()); nameEdit->setText(QString());
commentsEdit->setText(QString()); commentsEdit->setText(QString());
hashLabel->setText(QString()); hashLabel->setText(QString());
setModified(false); setModified(false);
} }
void TabDeckEditor::actLoadDeck() void TabDeckEditor::actLoadDeck()
{ {
if (!confirmClose()) if (!confirmClose())
return; return;
QFileDialog dialog(this, tr("Load deck")); QFileDialog dialog(this, tr("Load deck"));
dialog.setDirectory(settingsCache->getDeckPath()); dialog.setDirectory(settingsCache->getDeckPath());
dialog.setNameFilters(DeckLoader::fileNameFilters); dialog.setNameFilters(DeckLoader::fileNameFilters);
if (!dialog.exec()) if (!dialog.exec())
return; return;
QString fileName = dialog.selectedFiles().at(0); QString fileName = dialog.selectedFiles().at(0);
DeckLoader::FileFormat fmt = DeckLoader::getFormatFromNameFilter(dialog.selectedNameFilter()); DeckLoader::FileFormat fmt = DeckLoader::getFormatFromNameFilter(dialog.selectedNameFilter());
DeckLoader *l = new DeckLoader; DeckLoader *l = new DeckLoader;
if (l->loadFromFile(fileName, fmt)) if (l->loadFromFile(fileName, fmt))
setDeck(l); setDeck(l);
else else
delete l; delete l;
} }
void TabDeckEditor::saveDeckRemoteFinished(const Response &response) void TabDeckEditor::saveDeckRemoteFinished(const Response &response)
{ {
if (response.response_code() != Response::RespOk) if (response.response_code() != Response::RespOk)
QMessageBox::critical(this, tr("Error"), tr("The deck could not be saved.")); QMessageBox::critical(this, tr("Error"), tr("The deck could not be saved."));
else else
setModified(false); setModified(false);
} }
bool TabDeckEditor::actSaveDeck() bool TabDeckEditor::actSaveDeck()
{ {
DeckLoader *const deck = deckModel->getDeckList(); DeckLoader *const deck = deckModel->getDeckList();
if (deck->getLastRemoteDeckId() != -1) { if (deck->getLastRemoteDeckId() != -1) {
Command_DeckUpload cmd; Command_DeckUpload cmd;
cmd.set_deck_id(deck->getLastRemoteDeckId()); cmd.set_deck_id(deck->getLastRemoteDeckId());
cmd.set_deck_list(deck->writeToString_Native().toStdString()); cmd.set_deck_list(deck->writeToString_Native().toStdString());
PendingCommand *pend = AbstractClient::prepareSessionCommand(cmd); PendingCommand *pend = AbstractClient::prepareSessionCommand(cmd);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(saveDeckRemoteFinished(Response))); connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(saveDeckRemoteFinished(Response)));
tabSupervisor->getClient()->sendCommand(pend); tabSupervisor->getClient()->sendCommand(pend);
return true; return true;
} else if (deck->getLastFileName().isEmpty()) } else if (deck->getLastFileName().isEmpty())
return actSaveDeckAs(); return actSaveDeckAs();
else if (deck->saveToFile(deck->getLastFileName(), deck->getLastFileFormat())) { else if (deck->saveToFile(deck->getLastFileName(), deck->getLastFileFormat())) {
setModified(false); setModified(false);
return true; return true;
} }
QMessageBox::critical(this, tr("Error"), tr("The deck could not be saved.\nPlease check that the directory is writable and try again.")); QMessageBox::critical(this, tr("Error"), tr("The deck could not be saved.\nPlease check that the directory is writable and try again."));
return false; return false;
} }
bool TabDeckEditor::actSaveDeckAs() bool TabDeckEditor::actSaveDeckAs()
{ {
QFileDialog dialog(this, tr("Save deck")); QFileDialog dialog(this, tr("Save deck"));
dialog.setDirectory(settingsCache->getDeckPath()); dialog.setDirectory(settingsCache->getDeckPath());
dialog.setAcceptMode(QFileDialog::AcceptSave); dialog.setAcceptMode(QFileDialog::AcceptSave);
dialog.setConfirmOverwrite(true); dialog.setConfirmOverwrite(true);
dialog.setDefaultSuffix("cod"); dialog.setDefaultSuffix("cod");
dialog.setNameFilters(DeckLoader::fileNameFilters); dialog.setNameFilters(DeckLoader::fileNameFilters);
dialog.selectFile(deckModel->getDeckList()->getName()); dialog.selectFile(deckModel->getDeckList()->getName());
if (!dialog.exec()) if (!dialog.exec())
return false; return false;
QString fileName = dialog.selectedFiles().at(0); QString fileName = dialog.selectedFiles().at(0);
DeckLoader::FileFormat fmt = DeckLoader::getFormatFromNameFilter(dialog.selectedNameFilter()); DeckLoader::FileFormat fmt = DeckLoader::getFormatFromNameFilter(dialog.selectedNameFilter());
if (!deckModel->getDeckList()->saveToFile(fileName, fmt)) { if (!deckModel->getDeckList()->saveToFile(fileName, fmt)) {
QMessageBox::critical(this, tr("Error"), tr("The deck could not be saved.\nPlease check that the directory is writable and try again.")); QMessageBox::critical(this, tr("Error"), tr("The deck could not be saved.\nPlease check that the directory is writable and try again."));
return false; return false;
} }
setModified(false); setModified(false);
return true; return true;
} }
void TabDeckEditor::actLoadDeckFromClipboard() void TabDeckEditor::actLoadDeckFromClipboard()
{ {
if (!confirmClose()) if (!confirmClose())
return; return;
DlgLoadDeckFromClipboard dlg; DlgLoadDeckFromClipboard dlg;
if (!dlg.exec()) if (!dlg.exec())
return; return;
setDeck(dlg.getDeckList()); setDeck(dlg.getDeckList());
setModified(true); setModified(true);
} }
void TabDeckEditor::actSaveDeckToClipboard() void TabDeckEditor::actSaveDeckToClipboard()
{ {
QString buffer; QString buffer;
QTextStream stream(&buffer); QTextStream stream(&buffer);
deckModel->getDeckList()->saveToStream_Plain(stream); deckModel->getDeckList()->saveToStream_Plain(stream);
QApplication::clipboard()->setText(buffer, QClipboard::Clipboard); QApplication::clipboard()->setText(buffer, QClipboard::Clipboard);
QApplication::clipboard()->setText(buffer, QClipboard::Selection); QApplication::clipboard()->setText(buffer, QClipboard::Selection);
} }
void TabDeckEditor::actPrintDeck() void TabDeckEditor::actPrintDeck()
{ {
QPrintPreviewDialog *dlg = new QPrintPreviewDialog(this); QPrintPreviewDialog *dlg = new QPrintPreviewDialog(this);
connect(dlg, SIGNAL(paintRequested(QPrinter *)), deckModel, SLOT(printDeckList(QPrinter *))); connect(dlg, SIGNAL(paintRequested(QPrinter *)), deckModel, SLOT(printDeckList(QPrinter *)));
dlg->exec(); dlg->exec();
} }
void TabDeckEditor::actAnalyzeDeck() void TabDeckEditor::actAnalyzeDeck()
{ {
DeckStatsInterface *interface = new DeckStatsInterface(this); // it deletes itself when done DeckStatsInterface *interface = new DeckStatsInterface(this); // it deletes itself when done
interface->analyzeDeck(deckModel->getDeckList()); interface->analyzeDeck(deckModel->getDeckList());
} }
void TabDeckEditor::actEditSets() void TabDeckEditor::actEditSets()
{ {
WndSets *w = new WndSets; WndSets *w = new WndSets;
w->setWindowModality(Qt::WindowModal); w->setWindowModality(Qt::WindowModal);
w->show(); w->show();
} }
void TabDeckEditor::actEditTokens() void TabDeckEditor::actEditTokens()
{ {
DlgEditTokens dlg(databaseModel); DlgEditTokens dlg(databaseModel);
dlg.exec(); dlg.exec();
db->saveToFile(settingsCache->getTokenDatabasePath(), true); db->saveToFile(settingsCache->getTokenDatabasePath(), true);
} }
void TabDeckEditor::actClearSearch() void TabDeckEditor::actClearSearch()
{ {
databaseDisplayModel->clearSearch(); databaseDisplayModel->clearSearch();
} }
void TabDeckEditor::recursiveExpand(const QModelIndex &index) void TabDeckEditor::recursiveExpand(const QModelIndex &index)
{ {
if (index.parent().isValid()) if (index.parent().isValid())
recursiveExpand(index.parent()); recursiveExpand(index.parent());
deckView->expand(index); deckView->expand(index);
} }
CardInfo *TabDeckEditor::currentCardInfo() const CardInfo *TabDeckEditor::currentCardInfo() const
{ {
const QModelIndex currentIndex = databaseView->selectionModel()->currentIndex(); const QModelIndex currentIndex = databaseView->selectionModel()->currentIndex();
if (!currentIndex.isValid()) if (!currentIndex.isValid())
return NULL; return NULL;
const QString cardName = currentIndex.sibling(currentIndex.row(), 0).data().toString(); const QString cardName = currentIndex.sibling(currentIndex.row(), 0).data().toString();
return db->getCard(cardName); return db->getCard(cardName);
} }
void TabDeckEditor::addCardHelper(QString zoneName) void TabDeckEditor::addCardHelper(QString zoneName)
{ {
const CardInfo *info; const CardInfo *info;
info = currentCardInfo(); info = currentCardInfo();
if(!info) if(!info)
return; return;
if (info->getIsToken()) if (info->getIsToken())
zoneName = "tokens"; zoneName = "tokens";
QModelIndex newCardIndex = deckModel->addCard(info->getName(), zoneName); QModelIndex newCardIndex = deckModel->addCard(info->getName(), zoneName);
recursiveExpand(newCardIndex); recursiveExpand(newCardIndex);
deckView->setCurrentIndex(newCardIndex); deckView->setCurrentIndex(newCardIndex);
setModified(true); setModified(true);
} }
void TabDeckEditor::actAddCard() void TabDeckEditor::actAddCard()
{ {
addCardHelper("main"); addCardHelper("main");
} }
void TabDeckEditor::actAddCardToSideboard() void TabDeckEditor::actAddCardToSideboard()
{ {
addCardHelper("side"); addCardHelper("side");
} }
void TabDeckEditor::actRemoveCard() void TabDeckEditor::actRemoveCard()
{ {
const QModelIndex &currentIndex = deckView->selectionModel()->currentIndex(); const QModelIndex &currentIndex = deckView->selectionModel()->currentIndex();
if (!currentIndex.isValid() || deckModel->hasChildren(currentIndex)) if (!currentIndex.isValid() || deckModel->hasChildren(currentIndex))
return; return;
deckModel->removeRow(currentIndex.row(), currentIndex.parent()); deckModel->removeRow(currentIndex.row(), currentIndex.parent());
setModified(true); setModified(true);
} }
void TabDeckEditor::offsetCountAtIndex(const QModelIndex &idx, int offset) void TabDeckEditor::offsetCountAtIndex(const QModelIndex &idx, int offset)
{ {
if (!idx.isValid() || offset == 0) if (!idx.isValid() || offset == 0)
return; return;
const QModelIndex numberIndex = idx.sibling(idx.row(), 0); const QModelIndex numberIndex = idx.sibling(idx.row(), 0);
const int count = deckModel->data(numberIndex, Qt::EditRole).toInt(); const int count = deckModel->data(numberIndex, Qt::EditRole).toInt();
const int new_count = count + offset; const int new_count = count + offset;
deckView->setCurrentIndex(numberIndex); deckView->setCurrentIndex(numberIndex);
if (new_count <= 0) if (new_count <= 0)
deckModel->removeRow(idx.row(), idx.parent()); deckModel->removeRow(idx.row(), idx.parent());
else else
deckModel->setData(numberIndex, new_count, Qt::EditRole); deckModel->setData(numberIndex, new_count, Qt::EditRole);
setModified(true); setModified(true);
} }
void TabDeckEditor::decrementCardHelper(QString zoneName) void TabDeckEditor::decrementCardHelper(QString zoneName)
{ {
const CardInfo *info; const CardInfo *info;
QModelIndex idx; QModelIndex idx;
info = currentCardInfo(); info = currentCardInfo();
if(!info) if(!info)
return; return;
if (info->getIsToken()) if (info->getIsToken())
zoneName = "tokens"; zoneName = "tokens";
idx = deckModel->findCard(info->getName(), zoneName); idx = deckModel->findCard(info->getName(), zoneName);
offsetCountAtIndex(idx, -1); offsetCountAtIndex(idx, -1);
} }
void TabDeckEditor::actDecrementCard() void TabDeckEditor::actDecrementCard()
{ {
decrementCardHelper("main"); decrementCardHelper("main");
} }
void TabDeckEditor::actDecrementCardFromSideboard() void TabDeckEditor::actDecrementCardFromSideboard()
{ {
decrementCardHelper("side"); decrementCardHelper("side");
} }
void TabDeckEditor::actIncrement() void TabDeckEditor::actIncrement()
{ {
const QModelIndex &currentIndex = deckView->selectionModel()->currentIndex(); const QModelIndex &currentIndex = deckView->selectionModel()->currentIndex();
offsetCountAtIndex(currentIndex, 1); offsetCountAtIndex(currentIndex, 1);
} }
void TabDeckEditor::actDecrement() void TabDeckEditor::actDecrement()
{ {
const QModelIndex &currentIndex = deckView->selectionModel()->currentIndex(); const QModelIndex &currentIndex = deckView->selectionModel()->currentIndex();
offsetCountAtIndex(currentIndex, -1); offsetCountAtIndex(currentIndex, -1);
} }
void TabDeckEditor::actUpdatePrices() void TabDeckEditor::actUpdatePrices()
{ {
aUpdatePrices->setDisabled(true); aUpdatePrices->setDisabled(true);
PriceUpdater *up = new PriceUpdater(deckModel->getDeckList()); PriceUpdater *up = new PriceUpdater(deckModel->getDeckList());
connect(up, SIGNAL(finishedUpdate()), this, SLOT(finishedUpdatingPrices())); connect(up, SIGNAL(finishedUpdate()), this, SLOT(finishedUpdatingPrices()));
up->updatePrices(); up->updatePrices();
} }
void TabDeckEditor::finishedUpdatingPrices() void TabDeckEditor::finishedUpdatingPrices()
{ {
deckModel->pricesUpdated(); deckModel->pricesUpdated();
setModified(true); setModified(true);
aUpdatePrices->setDisabled(false); aUpdatePrices->setDisabled(false);
} }
void TabDeckEditor::setDeck(DeckLoader *_deck) void TabDeckEditor::setDeck(DeckLoader *_deck)
{ {
deckModel->setDeckList(_deck); deckModel->setDeckList(_deck);
nameEdit->setText(deckModel->getDeckList()->getName()); nameEdit->setText(deckModel->getDeckList()->getName());
commentsEdit->setText(deckModel->getDeckList()->getComments()); commentsEdit->setText(deckModel->getDeckList()->getComments());
updateHash(); updateHash();
deckModel->sort(1); deckModel->sort(1);
deckView->expandAll(); deckView->expandAll();
setModified(false); setModified(false);
db->cacheCardPixmaps(deckModel->getDeckList()->getCardList()); db->cacheCardPixmaps(deckModel->getDeckList()->getCardList());
deckView->expandAll(); deckView->expandAll();
setModified(false); setModified(false);
} }
void TabDeckEditor::setModified(bool _modified) void TabDeckEditor::setModified(bool _modified)
{ {
modified = _modified; modified = _modified;
emit tabTextChanged(this, getTabText()); emit tabTextChanged(this, getTabText());
} }
void TabDeckEditor::filterViewCustomContextMenu(const QPoint &point) { void TabDeckEditor::filterViewCustomContextMenu(const QPoint &point) {
QMenu menu; QMenu menu;
QAction *action; QAction *action;
QModelIndex idx; QModelIndex idx;
idx = filterView->indexAt(point); idx = filterView->indexAt(point);
if (!idx.isValid()) if (!idx.isValid())
return; return;
action = menu.addAction(QString("delete")); action = menu.addAction(QString("delete"));
action->setData(point); action->setData(point);
connect(&menu, SIGNAL(triggered(QAction *)), connect(&menu, SIGNAL(triggered(QAction *)),
this, SLOT(filterRemove(QAction *))); this, SLOT(filterRemove(QAction *)));
menu.exec(filterView->mapToGlobal(point)); menu.exec(filterView->mapToGlobal(point));
} }
void TabDeckEditor::filterRemove(QAction *action) { void TabDeckEditor::filterRemove(QAction *action) {
QPoint point; QPoint point;
QModelIndex idx; QModelIndex idx;
point = action->data().toPoint(); point = action->data().toPoint();
idx = filterView->indexAt(point); idx = filterView->indexAt(point);
if (!idx.isValid()) if (!idx.isValid())
return; return;
filterModel->removeRow(idx.row(), idx.parent()); filterModel->removeRow(idx.row(), idx.parent());
} }
...@@ -20,98 +20,98 @@ class FilterTreeModel; ...@@ -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 &current, const QModelIndex &previous); void updateCardInfoLeft(const QModelIndex &current, const QModelIndex &previous);
void updateCardInfoRight(const QModelIndex &current, const QModelIndex &previous); void updateCardInfoRight(const QModelIndex &current, 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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment