Commit 9a5935a3 authored by Christian Mollekopf's avatar Christian Mollekopf
Browse files

ReparentingModel: Simplified and clearer update mechanism.

Instead of replacing the complete node, which was just a workaround to the
reparentingmodel not knowing anything about the personnode, we delegate that
work to the node itself.
parent 2ced59f5
......@@ -216,6 +216,11 @@ bool PersonNode::isDuplicateOf(const QModelIndex& sourceIndex)
return (sourceIndex.data(PersonRole).value<Person>().uid == mPerson.uid);
}
void PersonNode::update(const Node::Ptr &node)
{
mPerson = node.staticCast<PersonNode>()->mPerson;
}
Person PersonNodeManager::person(const QModelIndex &sourceIndex)
{
Person person;
......
......@@ -104,6 +104,7 @@ private:
virtual bool setData(const QVariant& variant, int role);
virtual bool adopts(const QModelIndex& sourceIndex);
virtual bool isDuplicateOf(const QModelIndex& sourceIndex);
virtual void update(const Node::Ptr &node);
Person mPerson;
Qt::CheckState mCheckState;
......
......@@ -117,6 +117,11 @@ bool ReparentingModel::Node::isDuplicateOf(const QModelIndex& /* sourceIndex */)
return false;
}
void ReparentingModel::Node::update(const Node::Ptr &/* node */)
{
}
bool ReparentingModel::Node::isSourceNode() const
{
return mIsSourceNode;
......@@ -278,17 +283,8 @@ void ReparentingModel::updateNode(const ReparentingModel::Node::Ptr &node)
{
Q_FOREACH(const ReparentingModel::Node::Ptr &existing, mProxyNodes) {
if (*existing == *node) {
node->parent = existing->parent;
node->children = existing->children;
Q_FOREACH(ReparentingModel::Node::Ptr child, existing->children) {
child->parent = node.data();
}
node->sourceIndex = existing->sourceIndex;
int r = row(existing.data());
mProxyNodes.replace(mProxyNodes.indexOf(existing), node);
existing->parent->children.replace(r, node);
const QModelIndex i = index(node.data());
Q_ASSERT(i.row() == r);
existing->update(node);
const QModelIndex i = index(existing.data());
emit dataChanged(i, i);
return;
}
......
......@@ -50,6 +50,7 @@ public:
virtual bool setData(const QVariant &variant, int role);
virtual bool adopts(const QModelIndex &sourceIndex);
virtual bool isDuplicateOf(const QModelIndex &sourceIndex);
virtual void update(const Node::Ptr &node);
bool isSourceNode() const;
void reparent(Node *node);
......
......@@ -76,6 +76,13 @@ private:
return sourceIndex.data().toString().contains(mParent);
}
void update(const Node::Ptr &node)
{
mName = node.staticCast<DummyNode>()->mName;
mData = node.staticCast<DummyNode>()->mData;
}
QString mName;
QString mData;
};
......@@ -743,4 +750,4 @@ void ReparentingModelTest::testRemoveNodeByNodeManagerWithDataChanged()
QTEST_MAIN(ReparentingModelTest)
#include "reparentingmodeltest.moc"
\ No newline at end of file
Markdown is supported
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