src/documentloader.cpp

Sun, 05 Mar 2017 01:57:56 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 05 Mar 2017 01:57:56 +0200
changeset 1184
393babf1319d
parent 1159
6ad8cdcd88d9
child 1186
eae8b3bce545
child 1236
861bf8ebb8ec
permissions
-rw-r--r--

Polar grid is now togglable.

980
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
1072
9ce9496427f2 Happy new year 2017!
Teemu Piippo <teemu@hecknology.net>
parents: 1065
diff changeset
3 * Copyright (C) 2013 - 2017 Teemu Piippo
980
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #include "documentloader.h"
1145
02264bf0108d Renamed ldDocument.cpp → lddocument.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
20 #include "lddocument.h"
1147
a26568aa3cce Renamed ldObject.cpp → linetypes/modelobject.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
21 #include "linetypes/modelobject.h"
980
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include "mainwindow.h"
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include "dialogs/openprogressdialog.h"
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
25 DocumentLoader::DocumentLoader (Model* model, bool onForeground, QObject *parent) :
980
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 QObject (parent),
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
27 _model(model),
980
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 m_warningCount (0),
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 m_isDone (false),
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 m_hasAborted (false),
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 m_isOnForeground (onForeground) {}
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 bool DocumentLoader::hasAborted()
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 return m_hasAborted;
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 }
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 bool DocumentLoader::isDone() const
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 return m_isDone;
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 }
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 int DocumentLoader::progress() const
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 return m_progress;
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 }
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 int DocumentLoader::warningCount() const
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 return m_warningCount;
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 }
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 bool DocumentLoader::isOnForeground() const
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 return m_isOnForeground;
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 }
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
58 const QVector<LDObject*>& DocumentLoader::objects() const
980
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 {
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
60 return _model->objects();
980
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 }
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 void DocumentLoader::read (QIODevice* fp)
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 if (fp and fp->isOpen())
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 while (not fp->atEnd())
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 m_lines << QString::fromUtf8 (fp->readLine());
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 }
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 }
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 void DocumentLoader::start()
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 m_isDone = false;
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 m_progress = 0;
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 m_hasAborted = false;
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 if (isOnForeground())
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 {
1145
02264bf0108d Renamed ldDocument.cpp → lddocument.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
80 // Show a progress dialog if we're loading the main lddocument.here so we can show progress updates and keep the
980
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 // WM posted that we're still here.
1023
9450ac3cd930 Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
82 m_progressDialog = new OpenProgressDialog(qobject_cast<QWidget*>(parent()));
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
83 m_progressDialog->setNumLines (countof(m_lines));
980
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 m_progressDialog->setModal (true);
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 m_progressDialog->show();
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 connect (this, SIGNAL (workDone()), m_progressDialog, SLOT (accept()));
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 connect (m_progressDialog, SIGNAL (rejected()), this, SLOT (abort()));
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 }
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 else
984
a7b6f987d269 null -> nullptr
Teemu Piippo <crimsondusk64@gmail.com>
parents: 980
diff changeset
90 m_progressDialog = nullptr;
980
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 // Begin working
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 work (0);
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 }
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 void DocumentLoader::work (int i)
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 // User wishes to abort, so stop here now.
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 if (hasAborted())
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 m_isDone = true;
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 return;
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 }
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 // Parse up to 200 lines per iteration
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 int max = i + 200;
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
108 for (; i < max and i < (int) countof(m_lines); ++i)
980
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 QString line = m_lines[i];
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 // Trim the trailing newline
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 while (line.endsWith ("\n") or line.endsWith ("\r"))
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114 line.chop (1);
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115
1079
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1073
diff changeset
116 LDObject* obj = _model->addFromString(line);
980
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 // Check for parse errors and warn about them
1123
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1086
diff changeset
119 if (obj->type() == LDObjectType::Error)
980
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 {
1159
6ad8cdcd88d9 print() is no longer a global function but is tied to HierarchyElement.
Teemu Piippo <teemu@hecknology.net>
parents: 1147
diff changeset
121 emit parseErrorMessage(format(tr("Couldn't parse line #%1: %2"), progress() + 1, static_cast<LDError*> (obj)->reason()));
980
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 ++m_warningCount;
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 }
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 }
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126 m_progress = i;
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 if (m_progressDialog)
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 m_progressDialog->setProgress (i);
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
131 if (i >= countof(m_lines) - 1)
980
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133 emit workDone();
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 m_isDone = true;
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135 }
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
136 else
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138 // If we have a dialog to show progress output to, we cannot just call work() again immediately as the dialog
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 // needs to be updated as well. Thus, we take a detour through the event loop by using the meta-object system.
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140 //
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141 // This terminates the loop here and control goes back to the function which called the file loader. It will
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142 // keep processing the event loop until we're ready (see loadFileContents), thus the event loop will eventually
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143 // catch the invokation we throw here and send us back.
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 if (isOnForeground())
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145 QMetaObject::invokeMethod (this, "work", Qt::QueuedConnection, Q_ARG (int, i));
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146 else
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147 work (i);
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148 }
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149 }
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151 void DocumentLoader::abort()
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153 m_hasAborted = true;
1159
6ad8cdcd88d9 print() is no longer a global function but is tied to HierarchyElement.
Teemu Piippo <teemu@hecknology.net>
parents: 1147
diff changeset
154 }

mercurial