src/documentloader.cpp

Sun, 29 Jan 2017 15:25:26 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 29 Jan 2017 15:25:26 +0200
changeset 1075
711c5fff384d
parent 1073
a0a0d581309b
child 1079
67c6e5d32e68
permissions
-rw-r--r--

Removed the AddObjectDialog. Garbage code that absolutely needs to be reimplemented.

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 <QFile>
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include "documentloader.h"
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include "ldDocument.h"
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include "ldObject.h"
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include "mainwindow.h"
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include "dialogs/openprogressdialog.h"
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25
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
26 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
27 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
28 _model(model),
980
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 m_warningCount (0),
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 m_isDone (false),
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 m_hasAborted (false),
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 m_isOnForeground (onForeground) {}
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 bool DocumentLoader::hasAborted()
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 return m_hasAborted;
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
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 bool DocumentLoader::isDone() const
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 return m_isDone;
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
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 int DocumentLoader::progress() const
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 return m_progress;
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
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 int DocumentLoader::warningCount() const
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 return m_warningCount;
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
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 bool DocumentLoader::isOnForeground() const
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 return m_isOnForeground;
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 }
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58
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
59 const QVector<LDObject*>& DocumentLoader::objects() const
980
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 {
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
61 return _model->objects();
980
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
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 void DocumentLoader::read (QIODevice* fp)
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 if (fp and fp->isOpen())
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 while (not fp->atEnd())
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 m_lines << QString::fromUtf8 (fp->readLine());
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
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 void DocumentLoader::start()
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 m_isDone = false;
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 m_progress = 0;
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 m_hasAborted = false;
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 if (isOnForeground())
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 // Show a progress dialog if we're loading the main ldDocument.here so we can show progress updates and keep the
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 // 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
83 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
84 m_progressDialog->setNumLines (countof(m_lines));
980
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 m_progressDialog->setModal (true);
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 m_progressDialog->show();
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 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
88 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
89 }
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 else
984
a7b6f987d269 null -> nullptr
Teemu Piippo <crimsondusk64@gmail.com>
parents: 980
diff changeset
91 m_progressDialog = nullptr;
980
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 // Begin working
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 work (0);
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
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 void DocumentLoader::work (int i)
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 // 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
100 if (hasAborted())
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 m_isDone = true;
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 return;
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
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 // Parse up to 200 lines per iteration
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 int max = i + 200;
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
109 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
110 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 QString line = m_lines[i];
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 // Trim the trailing newline
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114 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
115 line.chop (1);
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 LDObject* obj = ParseLine (line);
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119 // Check for parse errors and warn about them
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 if (obj->type() == OBJ_Error)
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 print ("Couldn't parse line #%1: %2", progress() + 1, static_cast<LDError*> (obj)->reason());
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 ++m_warningCount;
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
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
126 _model->addObject(obj);
980
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
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 m_progress = i;
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 if (m_progressDialog)
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 m_progressDialog->setProgress (i);
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
134 if (i >= countof(m_lines) - 1)
980
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 emit workDone();
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137 m_isDone = true;
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138 }
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 else
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 // 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
142 // 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
143 //
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 // 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
145 // 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
146 // 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
147 if (isOnForeground())
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148 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
149 else
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150 work (i);
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151 }
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
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154 void DocumentLoader::abort()
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155 {
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 m_hasAborted = true;
4a95c6b06ebe Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157 }

mercurial