Thu, 15 Mar 2018 18:51:58 +0200
begin work on document loading rework
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 | 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 | |
1287
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
25 | DocumentLoader::DocumentLoader( |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
26 | Model* model, |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
27 | LDHeader& header, |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
28 | bool onForeground, |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
29 | QObject *parent, |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
30 | ) : |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
31 | QObject {parent}, |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
32 | _model {model}, |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
33 | _header {header}, |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
34 | m_isOnForeground {onForeground} {} |
980
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 | bool DocumentLoader::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 | return m_hasAborted; |
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 | |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | bool DocumentLoader::isDone() const |
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 | return m_isDone; |
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 | |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | int DocumentLoader::progress() const |
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 | return m_progress; |
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 | |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | int DocumentLoader::warningCount() const |
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 | return m_warningCount; |
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 | |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | bool DocumentLoader::isOnForeground() const |
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 | return m_isOnForeground; |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | } |
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 | const QVector<LDObject*>& DocumentLoader::objects() const |
980
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | { |
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
|
63 | return _model->objects(); |
980
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 | |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | void DocumentLoader::read (QIODevice* fp) |
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 | if (fp and fp->isOpen()) |
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 | while (not fp->atEnd()) |
1287
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
71 | m_lines << QString::fromUtf8(fp->readLine()).simplified(); |
980
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 | } |
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 | void DocumentLoader::start() |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | { |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | m_isDone = false; |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | m_progress = 0; |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | m_hasAborted = false; |
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 | if (isOnForeground()) |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | { |
1145
02264bf0108d
Renamed ldDocument.cpp → lddocument.cpp
Teemu Piippo <teemu@hecknology.net>
parents:
1123
diff
changeset
|
83 | // 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
|
84 | // 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
|
85 | 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
|
86 | m_progressDialog->setNumLines (countof(m_lines)); |
980
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | m_progressDialog->setModal (true); |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | m_progressDialog->show(); |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | 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
|
90 | 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
|
91 | } |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | else |
1287
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
93 | { |
984 | 94 | m_progressDialog = nullptr; |
1287
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
95 | } |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
96 | |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
97 | // Parse the header |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
98 | while (m_progress < m_lines.size()) |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
99 | { |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
100 | const QString& line = m_lines[m_progress]; |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
101 | |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
102 | if (not line.isEmpty()) |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
103 | { |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
104 | if (line.startsWith("0")) |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
105 | { |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
106 | if (m_progress == 0) |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
107 | { |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
108 | _header.description = line.mid(1).simplified(); |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
109 | } |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
110 | else if (line.startsWith("0 !LDRAW_ORG")) |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
111 | { |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
112 | QStringList tokens = line.mid(strlen("0 !LDRAW_ORG")); |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
113 | } |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
114 | else if (line.startsWith("0 BFC")) |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
115 | { |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
116 | ...; |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
117 | } |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
118 | else |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
119 | { |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
120 | _model->addFromString(line); |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
121 | } |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
122 | m_progress += 1; |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
123 | } |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
124 | else |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
125 | { |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
126 | break; |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
127 | } |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
128 | } |
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
129 | } |
980
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 | // Begin working |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | work (0); |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | } |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
135 | void DocumentLoader::work (int i) |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
136 | { |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
137 | // 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
|
138 | if (hasAborted()) |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
139 | { |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
140 | m_isDone = true; |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
141 | return; |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
142 | } |
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 | // Parse up to 200 lines per iteration |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
145 | int max = i + 200; |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | |
1236
861bf8ebb8ec
BFC INVERTNEXT objects are no longer individual objects
Santeri Piippo
parents:
1159
diff
changeset
|
147 | bool invertNext = false; |
861bf8ebb8ec
BFC INVERTNEXT objects are no longer individual objects
Santeri Piippo
parents:
1159
diff
changeset
|
148 | |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1063
diff
changeset
|
149 | 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
|
150 | { |
1287
f1da43b7f5c6
begin work on document loading rework
Teemu Piippo <teemu@hecknology.net>
parents:
1236
diff
changeset
|
151 | const QString& line = m_lines[i]; |
1236
861bf8ebb8ec
BFC INVERTNEXT objects are no longer individual objects
Santeri Piippo
parents:
1159
diff
changeset
|
152 | |
861bf8ebb8ec
BFC INVERTNEXT objects are no longer individual objects
Santeri Piippo
parents:
1159
diff
changeset
|
153 | if (line == "0 BFC INVERTNEXT") |
861bf8ebb8ec
BFC INVERTNEXT objects are no longer individual objects
Santeri Piippo
parents:
1159
diff
changeset
|
154 | { |
861bf8ebb8ec
BFC INVERTNEXT objects are no longer individual objects
Santeri Piippo
parents:
1159
diff
changeset
|
155 | invertNext = true; |
861bf8ebb8ec
BFC INVERTNEXT objects are no longer individual objects
Santeri Piippo
parents:
1159
diff
changeset
|
156 | continue; |
861bf8ebb8ec
BFC INVERTNEXT objects are no longer individual objects
Santeri Piippo
parents:
1159
diff
changeset
|
157 | } |
980
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
158 | |
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
|
159 | LDObject* obj = _model->addFromString(line); |
980
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
160 | |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
161 | // 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
|
162 | if (obj->type() == LDObjectType::Error) |
980
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
163 | { |
1159
6ad8cdcd88d9
print() is no longer a global function but is tied to HierarchyElement.
Teemu Piippo <teemu@hecknology.net>
parents:
1147
diff
changeset
|
164 | 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
|
165 | ++m_warningCount; |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
166 | } |
1236
861bf8ebb8ec
BFC INVERTNEXT objects are no longer individual objects
Santeri Piippo
parents:
1159
diff
changeset
|
167 | |
861bf8ebb8ec
BFC INVERTNEXT objects are no longer individual objects
Santeri Piippo
parents:
1159
diff
changeset
|
168 | if (invertNext and obj->type() == LDObjectType::SubfileReference) |
861bf8ebb8ec
BFC INVERTNEXT objects are no longer individual objects
Santeri Piippo
parents:
1159
diff
changeset
|
169 | obj->setInverted(true); |
861bf8ebb8ec
BFC INVERTNEXT objects are no longer individual objects
Santeri Piippo
parents:
1159
diff
changeset
|
170 | |
861bf8ebb8ec
BFC INVERTNEXT objects are no longer individual objects
Santeri Piippo
parents:
1159
diff
changeset
|
171 | invertNext = false; |
980
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
172 | } |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
173 | |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
174 | m_progress = i; |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
175 | |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
176 | if (m_progressDialog) |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
177 | m_progressDialog->setProgress (i); |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
178 | |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1063
diff
changeset
|
179 | if (i >= countof(m_lines) - 1) |
980
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
180 | { |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
181 | emit workDone(); |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
182 | m_isDone = true; |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
183 | } |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
184 | else |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
185 | { |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
186 | // 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
|
187 | // 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
|
188 | // |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
189 | // 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
|
190 | // 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
|
191 | // 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
|
192 | if (isOnForeground()) |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
193 | 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
|
194 | else |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
195 | work (i); |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
196 | } |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
197 | } |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
198 | |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
199 | void DocumentLoader::abort() |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
200 | { |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
201 | 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
|
202 | } |