summaryrefslogtreecommitdiffstats
path: root/smtreeitem.cpp
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2013-06-25 20:02:41 +0200
committerArno <am@disconnect.de>2013-06-25 20:02:41 +0200
commiteb697d7a3b7fc8b8af052b6f025610dd85eb176b (patch)
tree04c410b656baf129d3e5bfcdb4ead80f15fba4ea /smtreeitem.cpp
parentae1582fa29de82c28872f826fa6f8b154bea88dc (diff)
downloadSheMov-eb697d7a3b7fc8b8af052b6f025610dd85eb176b.tar.gz
SheMov-eb697d7a3b7fc8b8af052b6f025610dd85eb176b.tar.bz2
SheMov-eb697d7a3b7fc8b8af052b6f025610dd85eb176b.zip
Fix random crashes in ArchiveCollector
This was a hard one, actually. Since we only returned a pointer from the ArchiveCollector, it worked _most_ of the time, but crashed at random when the view was reading the tree while the collector was updating it. So create a working copy constructor for SmRootItem and return a copy of the the tree when the collector is done. I bet that's also the reason for the random crashes in the filesystem view.
Diffstat (limited to 'smtreeitem.cpp')
-rw-r--r--smtreeitem.cpp40
1 files changed, 31 insertions, 9 deletions
diff --git a/smtreeitem.cpp b/smtreeitem.cpp
index 77a75d5..4548655 100644
--- a/smtreeitem.cpp
+++ b/smtreeitem.cpp
@@ -5,6 +5,9 @@
2 of the License, or (at your option) any later version.
*/
+#include <QVector>
+#include <QHash>
+
#include "smtreeitem.h"
SmTreeItem::SmTreeItem(const QList<QVariant> &data, SmTreeItem *parent) : mData(data), mParent(parent) {}
@@ -16,15 +19,34 @@ SmTreeItem::SmTreeItem(int rows, SmTreeItem *parent) : mParent(parent){
}
SmTreeItem::SmTreeItem(const SmTreeItem &other){
- mData = other.mData;
- if(other.mParent){
- mParent = new SmTreeItem(*mParent);
- }else{
- mParent = 0;
- }
- foreach(SmTreeItem *child, other.mChildren){
- mChildren << new SmTreeItem(*child);
- }
+ mParent = 0;
+ mData = other.mData;
+ QVector<SmTreeItem*> remaining;
+ QHash<const SmTreeItem*, SmTreeItem*> parents;
+ parents.insert(&other, this);
+ const SmTreeItem *cur = &other;
+ for(int i = 0; i < cur->childCount(); ++i){
+ remaining << cur->child(i);
+ }
+ while(cur){
+ cur = remaining.last();
+ remaining.pop_back();
+ for(int i = 0; i < cur->childCount(); ++i){
+ remaining << cur->child(i);
+ }
+ if(remaining.isEmpty()){
+ break;
+ }
+ SmTreeItem *newItem = new SmTreeItem(mData.size());
+ for(int i = 0; i < cur->columnCount(); ++i){
+ newItem->setData(i, cur->data(i));
+ }
+ SmTreeItem *newParent = parents.value(cur->parent());
+ newParent->appendChild(newItem);
+ newItem->setParent(newParent);
+ parents.insert(cur, newItem);
+
+ }
}
SmTreeItem::~SmTreeItem(){