summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRolf Eike Beer <eb@emlix.com>2016-10-11 11:15:34 (GMT)
committerRolf Eike Beer <kde@opensource.sf-tec.de>2016-10-11 16:16:46 (GMT)
commit0499dca3914633d1ece028a187a1c8fa22d9422d (patch)
treef6b4a1551bf2e4fbc51804f70635d8e4cd092682
parentdb3f6c49e6830de3726415a7ff02bd50dca54171 (diff)
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.
-rw-r--r--core/KGpgGroupNode.cpp6
-rw-r--r--core/KGpgKeyNode.cpp4
-rw-r--r--core/KGpgNode.cpp4
-rw-r--r--core/KGpgRootNode.cpp26
-rw-r--r--core/KGpgRootNode.h14
5 files changed, 12 insertions, 42 deletions
diff --git a/core/KGpgGroupNode.cpp b/core/KGpgGroupNode.cpp
index 2a0cb2b..b5de9b8 100644
--- a/core/KGpgGroupNode.cpp
+++ b/core/KGpgGroupNode.cpp
@@ -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
diff --git a/core/KGpgKeyNode.cpp b/core/KGpgKeyNode.cpp
index e509ab9..3737bd9 100644
--- a/core/KGpgKeyNode.cpp
+++ b/core/KGpgKeyNode.cpp
@@ -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);
}
}
diff --git a/core/KGpgNode.cpp b/core/KGpgNode.cpp
index 5c9605e..905812a 100644
--- a/core/KGpgNode.cpp
+++ b/core/KGpgNode.cpp
@@ -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 *
diff --git a/core/KGpgRootNode.cpp b/core/KGpgRootNode.cpp
index 7a27661..cd464d8 100644
--- a/core/KGpgRootNode.cpp
+++ b/core/KGpgRootNode.cpp
@@ -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;
-}
diff --git a/core/KGpgRootNode.h b/core/KGpgRootNode.h
index f75ad05..698b59a 100644
--- a/core/KGpgRootNode.h
+++ b/core/KGpgRootNode.h
@@ -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 *);
};