foo
This commit is contained in:
parent
e7e51f5f9d
commit
21daf9db99
4 changed files with 33 additions and 18 deletions
|
@ -15,6 +15,7 @@ protected:
|
||||||
InnerDecklistNode *parent;
|
InnerDecklistNode *parent;
|
||||||
public:
|
public:
|
||||||
AbstractDecklistNode(InnerDecklistNode *_parent = 0);
|
AbstractDecklistNode(InnerDecklistNode *_parent = 0);
|
||||||
|
virtual ~AbstractDecklistNode() { }
|
||||||
virtual QString getName() const = 0;
|
virtual QString getName() const = 0;
|
||||||
InnerDecklistNode *getParent() const { return parent; }
|
InnerDecklistNode *getParent() const { return parent; }
|
||||||
int depth() const;
|
int depth() const;
|
||||||
|
|
|
@ -64,11 +64,11 @@ void DeckListModel::rebuildTree()
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,11 +148,11 @@ QModelIndex DeckListModel::index(int row, int column, const QModelIndex &parent)
|
||||||
// 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ 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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,14 +170,20 @@ Qt::ItemFlags DeckListModel::flags(const QModelIndex &index) const
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
Qt::ItemFlags result = Qt::ItemIsEnabled;
|
Qt::ItemFlags result = Qt::ItemIsEnabled;
|
||||||
if (getNode<DecklistModelCardNode *>(index)) {
|
if (getNode<DecklistModelCardNode *>(index))
|
||||||
result |= Qt::ItemIsSelectable;
|
result |= Qt::ItemIsSelectable;
|
||||||
if (index.column() == 0)
|
|
||||||
result |= Qt::ItemIsEditable;
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeckListModel::emitRecursiveUpdates(const QModelIndex &index)
|
||||||
|
{
|
||||||
|
if (!index.isValid())
|
||||||
|
return;
|
||||||
|
emit dataChanged(index, index);
|
||||||
|
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);
|
||||||
|
@ -189,7 +195,7 @@ bool DeckListModel::setData(const QModelIndex &index, const QVariant &value, int
|
||||||
case 1: node->setName(value.toString()); break;
|
case 1: node->setName(value.toString()); break;
|
||||||
default: return false;
|
default: return false;
|
||||||
}
|
}
|
||||||
emit dataChanged(index, index);
|
emitRecursiveUpdates(index);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,9 +216,11 @@ bool DeckListModel::removeRows(int row, int count, const QModelIndex &parent)
|
||||||
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
|
||||||
|
emitRecursiveUpdates(parent);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -231,23 +239,25 @@ InnerDecklistNode *DeckListModel::createNodeIfNeeded(const QString &name, InnerD
|
||||||
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);
|
||||||
beginInsertRows(nodeToIndex(cardTypeNode), cardTypeNode->size(), cardTypeNode->size());
|
QModelIndex parentIndex = nodeToIndex(cardTypeNode);
|
||||||
|
beginInsertRows(parentIndex, cardTypeNode->size(), cardTypeNode->size());
|
||||||
cardNode = new DecklistModelCardNode(decklistCard, cardTypeNode);
|
cardNode = new DecklistModelCardNode(decklistCard, cardTypeNode);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
sort(1);
|
sort(1);
|
||||||
|
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);
|
||||||
emit dataChanged(ind, ind);
|
emitRecursiveUpdates(ind);
|
||||||
return ind;
|
return ind;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,9 +45,10 @@ private:
|
||||||
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;
|
||||||
|
void emitRecursiveUpdates(const QModelIndex &index);
|
||||||
void debugIndexInfo(const QString &func, const QModelIndex &index) const;
|
void debugIndexInfo(const QString &func, const QModelIndex &index) const;
|
||||||
void debugShowTree(InnerDecklistNode *node, int depth) const;
|
void debugShowTree(InnerDecklistNode *node, int depth) const;
|
||||||
|
|
||||||
template<typename T> T getNode(const QModelIndex &index) const
|
template<typename T> T getNode(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
|
|
|
@ -180,7 +180,7 @@ void WndDeckEditor::actNewDeck()
|
||||||
{
|
{
|
||||||
if (!confirmClose())
|
if (!confirmClose())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
deckModel->cleanList();
|
deckModel->cleanList();
|
||||||
nameEdit->setText(QString());
|
nameEdit->setText(QString());
|
||||||
commentsEdit->setText(QString());
|
commentsEdit->setText(QString());
|
||||||
|
@ -240,9 +240,10 @@ void WndDeckEditor::addCardHelper(const QString &zoneName)
|
||||||
if (!currentIndex.isValid())
|
if (!currentIndex.isValid())
|
||||||
return;
|
return;
|
||||||
const QString cardName = databaseModel->index(currentIndex.row(), 0).data().toString();
|
const QString cardName = databaseModel->index(currentIndex.row(), 0).data().toString();
|
||||||
|
|
||||||
QModelIndex newCardIndex = deckModel->addCard(cardName, zoneName);
|
QModelIndex newCardIndex = deckModel->addCard(cardName, zoneName);
|
||||||
recursiveExpand(newCardIndex);
|
recursiveExpand(newCardIndex);
|
||||||
|
deckView->setCurrentIndex(newCardIndex);
|
||||||
|
|
||||||
setWindowModified(true);
|
setWindowModified(true);
|
||||||
}
|
}
|
||||||
|
@ -273,6 +274,7 @@ void WndDeckEditor::actIncrement()
|
||||||
return;
|
return;
|
||||||
const QModelIndex numberIndex = currentIndex.sibling(currentIndex.row(), 0);
|
const QModelIndex numberIndex = currentIndex.sibling(currentIndex.row(), 0);
|
||||||
const int count = deckModel->data(numberIndex, Qt::EditRole).toInt();
|
const int count = deckModel->data(numberIndex, Qt::EditRole).toInt();
|
||||||
|
deckView->setCurrentIndex(numberIndex);
|
||||||
deckModel->setData(numberIndex, count + 1, Qt::EditRole);
|
deckModel->setData(numberIndex, count + 1, Qt::EditRole);
|
||||||
setWindowModified(true);
|
setWindowModified(true);
|
||||||
}
|
}
|
||||||
|
@ -284,6 +286,7 @@ void WndDeckEditor::actDecrement()
|
||||||
return;
|
return;
|
||||||
const QModelIndex numberIndex = currentIndex.sibling(currentIndex.row(), 0);
|
const QModelIndex numberIndex = currentIndex.sibling(currentIndex.row(), 0);
|
||||||
const int count = deckModel->data(numberIndex, Qt::EditRole).toInt();
|
const int count = deckModel->data(numberIndex, Qt::EditRole).toInt();
|
||||||
|
deckView->setCurrentIndex(numberIndex);
|
||||||
if (count == 1)
|
if (count == 1)
|
||||||
deckModel->removeRow(currentIndex.row(), currentIndex.parent());
|
deckModel->removeRow(currentIndex.row(), currentIndex.parent());
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue