src/documentloader.cpp

changeset 1073
a0a0d581309b
parent 1072
9ce9496427f2
child 1079
67c6e5d32e68
equal deleted inserted replaced
1072:9ce9496427f2 1073:a0a0d581309b
21 #include "ldDocument.h" 21 #include "ldDocument.h"
22 #include "ldObject.h" 22 #include "ldObject.h"
23 #include "mainwindow.h" 23 #include "mainwindow.h"
24 #include "dialogs/openprogressdialog.h" 24 #include "dialogs/openprogressdialog.h"
25 25
26 DocumentLoader::DocumentLoader (bool onForeground, QObject *parent) : 26 DocumentLoader::DocumentLoader (Model* model, bool onForeground, QObject *parent) :
27 QObject (parent), 27 QObject (parent),
28 _model(model),
28 m_warningCount (0), 29 m_warningCount (0),
29 m_isDone (false), 30 m_isDone (false),
30 m_hasAborted (false), 31 m_hasAborted (false),
31 m_isOnForeground (onForeground) {} 32 m_isOnForeground (onForeground) {}
32 33
53 bool DocumentLoader::isOnForeground() const 54 bool DocumentLoader::isOnForeground() const
54 { 55 {
55 return m_isOnForeground; 56 return m_isOnForeground;
56 } 57 }
57 58
58 const LDObjectList& DocumentLoader::objects() const 59 const QVector<LDObject*>& DocumentLoader::objects() const
59 { 60 {
60 return m_objects; 61 return _model->objects();
61 } 62 }
62 63
63 void DocumentLoader::read (QIODevice* fp) 64 void DocumentLoader::read (QIODevice* fp)
64 { 65 {
65 if (fp and fp->isOpen()) 66 if (fp and fp->isOpen())
96 void DocumentLoader::work (int i) 97 void DocumentLoader::work (int i)
97 { 98 {
98 // User wishes to abort, so stop here now. 99 // User wishes to abort, so stop here now.
99 if (hasAborted()) 100 if (hasAborted())
100 { 101 {
101 for (LDObject* obj : m_objects)
102 obj->destroy();
103
104 m_objects.clear();
105 m_isDone = true; 102 m_isDone = true;
106 return; 103 return;
107 } 104 }
108 105
109 // Parse up to 200 lines per iteration 106 // Parse up to 200 lines per iteration
124 { 121 {
125 print ("Couldn't parse line #%1: %2", progress() + 1, static_cast<LDError*> (obj)->reason()); 122 print ("Couldn't parse line #%1: %2", progress() + 1, static_cast<LDError*> (obj)->reason());
126 ++m_warningCount; 123 ++m_warningCount;
127 } 124 }
128 125
129 m_objects << obj; 126 _model->addObject(obj);
130 } 127 }
131 128
132 m_progress = i; 129 m_progress = i;
133 130
134 if (m_progressDialog) 131 if (m_progressDialog)

mercurial