Commit 0499dca3 authored by Rolf Eike Beer's avatar Rolf Eike Beer Committed by Rolf Eike Beer
Browse files

rework the tracking if KGpgRootNode is currently deleting

When the destructor is called the child objects may not do calls into the
functions of this object anymore. Tell them in advance that the root node is
going away so they do not even try.
parent db3f6c49
......@@ -140,10 +140,8 @@ KGpgGroupNode::KGpgGroupNode(KGpgRootNode *parent, const QString &name, const KG
KGpgGroupNode::~KGpgGroupNode()
{
KGpgRootNode *root = m_parent->toRootNode();
if (root != Q_NULLPTR)
root->m_groups--;
if (parent() != Q_NULLPTR)
m_parent->toRootNode()->m_groups--;
}
KgpgCore::KgpgItemType
......
......@@ -39,8 +39,10 @@ KGpgKeyNode::KGpgKeyNode(KGpgRootNode *parent, const KgpgCore::KgpgKey &k)
KGpgKeyNode::~KGpgKeyNode()
{
// do not try to access the root node if we are being deleted from there
KGpgRootNode * const root = parent() != Q_NULLPTR ? m_parent->toRootNode() : Q_NULLPTR;
foreach (KGpgRefNode *nd, m_refs) {
nd->unRef(m_parent->toRootNode());
nd->unRef(root);
}
}
......
......@@ -113,7 +113,7 @@ KGpgNode::toRootNode()
{
Q_ASSERT((m_parent == Q_NULLPTR) && (getType() == 0));
return static_cast<KGpgRootNode *>(this)->asRootNode();
return static_cast<KGpgRootNode *>(this);
}
const KGpgRootNode *
......@@ -121,7 +121,7 @@ KGpgNode::toRootNode() const
{
Q_ASSERT((m_parent == Q_NULLPTR) && (getType() == 0));
return static_cast<const KGpgRootNode *>(this)->asRootNode();
return static_cast<const KGpgRootNode *>(this);
}
KGpgUidNode *
......
......@@ -28,15 +28,17 @@
KGpgRootNode::KGpgRootNode(KGpgItemModel *model)
: KGpgExpandableNode(Q_NULLPTR),
m_groups(0),
m_deleting(false)
m_groups(0)
{
m_model = model;
}
KGpgRootNode::~KGpgRootNode()
{
m_deleting = true;
// clear the parents in all children to signal them not to do any
// update signalling
for (KGpgNode *child: children)
child->setParent(Q_NULLPTR);
}
void
......@@ -161,21 +163,3 @@ KGpgRootNode::findKeyRow(const KGpgKeyNode *key)
}
return -1;
}
KGpgRootNode *
KGpgRootNode::asRootNode()
{
if (m_deleting)
return Q_NULLPTR;
return this;
}
const KGpgRootNode *
KGpgRootNode::asRootNode() const
{
if (m_deleting)
return Q_NULLPTR;
return this;
}
......@@ -44,7 +44,6 @@ class KGpgRootNode : public KGpgExpandableNode
private:
int m_groups;
int m_deleting;
protected:
virtual void readChildren() Q_DECL_OVERRIDE;
......@@ -110,19 +109,6 @@ public:
*/
int groupChildren() const;
/**
* Return a pointer to this object or Q_NULLPTR
*
* This returns a pointer to this object if the object will persist,
* i.e. is not currently in destruction. If the object is already
* cleaning up Q_NULLPTR is returned.
*/
KGpgRootNode *asRootNode();
/**
* @overload
*/
const KGpgRootNode *asRootNode() const;
Q_SIGNALS:
void newKeyNode(KGpgKeyNode *);
};
......
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