Tue, 15 Nov 2016 17:44:54 +0200
Removed the 'once' macro since it's not used
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 |
1014
f0a8ecb6a357
Happy new year 2016!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
3 | * Copyright (C) 2013 - 2016 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 | |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | DocumentLoader::DocumentLoader (bool onForeground, QObject *parent) : |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | QObject (parent), |
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 | |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | const LDObjectList& DocumentLoader::objects() const |
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 | return m_objects; |
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 | { |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | // 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
|
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())); |
980
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | m_progressDialog->setNumLines (m_lines.size()); |
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 | 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 | for (LDObject* obj : m_objects) |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | obj->destroy(); |
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 | m_objects.clear(); |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | m_isDone = true; |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | return; |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | } |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | // Parse up to 200 lines per iteration |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | int max = i + 200; |
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 | for (; i < max and i < (int) m_lines.size(); ++i) |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | { |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | QString line = m_lines[i]; |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | // Trim the trailing newline |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | 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
|
118 | line.chop (1); |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | LDObject* obj = ParseLine (line); |
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 | // 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
|
123 | if (obj->type() == OBJ_Error) |
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 | 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
|
126 | ++m_warningCount; |
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_objects << obj; |
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 | |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | m_progress = i; |
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 | if (m_progressDialog) |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
135 | m_progressDialog->setProgress (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 | if (i >= m_lines.size() - 1) |
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 | emit workDone(); |
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 | } |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
142 | else |
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 | // 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
|
145 | // 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
|
146 | // |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
147 | // 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
|
148 | // 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
|
149 | // 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
|
150 | if (isOnForeground()) |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
151 | 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
|
152 | else |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
153 | work (i); |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
154 | } |
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 | |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
157 | void DocumentLoader::abort() |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
158 | { |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
159 | m_hasAborted = true; |
4a95c6b06ebe
Split LDFileLoader (now LDDocumentLoader) into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
160 | } |