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;
|
||||
public:
|
||||
AbstractDecklistNode(InnerDecklistNode *_parent = 0);
|
||||
virtual ~AbstractDecklistNode() { }
|
||||
virtual QString getName() const = 0;
|
||||
InnerDecklistNode *getParent() const { return parent; }
|
||||
int depth() const;
|
||||
|
|
|
@ -170,14 +170,20 @@ Qt::ItemFlags DeckListModel::flags(const QModelIndex &index) const
|
|||
return 0;
|
||||
|
||||
Qt::ItemFlags result = Qt::ItemIsEnabled;
|
||||
if (getNode<DecklistModelCardNode *>(index)) {
|
||||
if (getNode<DecklistModelCardNode *>(index))
|
||||
result |= Qt::ItemIsSelectable;
|
||||
if (index.column() == 0)
|
||||
result |= Qt::ItemIsEditable;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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;
|
||||
default: return false;
|
||||
}
|
||||
emit dataChanged(index, index);
|
||||
emitRecursiveUpdates(index);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -213,6 +219,8 @@ bool DeckListModel::removeRows(int row, int count, const QModelIndex &parent)
|
|||
|
||||
if (!node->size() && (node != root))
|
||||
removeRows(parent.row(), 1, parent.parent());
|
||||
else
|
||||
emitRecursiveUpdates(parent);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -239,15 +247,17 @@ QModelIndex DeckListModel::addCard(const QString &cardName, const QString &zoneN
|
|||
DecklistModelCardNode *cardNode = dynamic_cast<DecklistModelCardNode *>(cardTypeNode->findChild(cardName));
|
||||
if (!cardNode) {
|
||||
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);
|
||||
endInsertRows();
|
||||
sort(1);
|
||||
emitRecursiveUpdates(parentIndex);
|
||||
return nodeToIndex(cardNode);
|
||||
} else {
|
||||
cardNode->setNumber(cardNode->getNumber() + 1);
|
||||
QModelIndex ind = nodeToIndex(cardNode);
|
||||
emit dataChanged(ind, ind);
|
||||
emitRecursiveUpdates(ind);
|
||||
return ind;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ private:
|
|||
InnerDecklistNode *root;
|
||||
InnerDecklistNode *createNodeIfNeeded(const QString &name, InnerDecklistNode *parent);
|
||||
QModelIndex nodeToIndex(AbstractDecklistNode *node) const;
|
||||
void emitRecursiveUpdates(const QModelIndex &index);
|
||||
void debugIndexInfo(const QString &func, const QModelIndex &index) const;
|
||||
void debugShowTree(InnerDecklistNode *node, int depth) const;
|
||||
|
||||
|
|
|
@ -243,6 +243,7 @@ void WndDeckEditor::addCardHelper(const QString &zoneName)
|
|||
|
||||
QModelIndex newCardIndex = deckModel->addCard(cardName, zoneName);
|
||||
recursiveExpand(newCardIndex);
|
||||
deckView->setCurrentIndex(newCardIndex);
|
||||
|
||||
setWindowModified(true);
|
||||
}
|
||||
|
@ -273,6 +274,7 @@ void WndDeckEditor::actIncrement()
|
|||
return;
|
||||
const QModelIndex numberIndex = currentIndex.sibling(currentIndex.row(), 0);
|
||||
const int count = deckModel->data(numberIndex, Qt::EditRole).toInt();
|
||||
deckView->setCurrentIndex(numberIndex);
|
||||
deckModel->setData(numberIndex, count + 1, Qt::EditRole);
|
||||
setWindowModified(true);
|
||||
}
|
||||
|
@ -284,6 +286,7 @@ void WndDeckEditor::actDecrement()
|
|||
return;
|
||||
const QModelIndex numberIndex = currentIndex.sibling(currentIndex.row(), 0);
|
||||
const int count = deckModel->data(numberIndex, Qt::EditRole).toInt();
|
||||
deckView->setCurrentIndex(numberIndex);
|
||||
if (count == 1)
|
||||
deckModel->removeRow(currentIndex.row(), currentIndex.parent());
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue