20 #include "lddocument.h" |
20 #include "lddocument.h" |
21 #include "linetypes/modelobject.h" |
21 #include "linetypes/modelobject.h" |
22 #include "mainwindow.h" |
22 #include "mainwindow.h" |
23 #include "dialogs/openprogressdialog.h" |
23 #include "dialogs/openprogressdialog.h" |
24 |
24 |
25 DocumentLoader::DocumentLoader (Model* model, bool onForeground, QObject *parent) : |
25 DocumentLoader::DocumentLoader( |
26 QObject (parent), |
26 Model* model, |
27 _model(model), |
27 LDHeader& header, |
28 m_warningCount (0), |
28 bool onForeground, |
29 m_isDone (false), |
29 QObject *parent, |
30 m_hasAborted (false), |
30 ) : |
31 m_isOnForeground (onForeground) {} |
31 QObject {parent}, |
|
32 _model {model}, |
|
33 _header {header}, |
|
34 m_isOnForeground {onForeground} {} |
32 |
35 |
33 bool DocumentLoader::hasAborted() |
36 bool DocumentLoader::hasAborted() |
34 { |
37 { |
35 return m_hasAborted; |
38 return m_hasAborted; |
36 } |
39 } |
63 void DocumentLoader::read (QIODevice* fp) |
66 void DocumentLoader::read (QIODevice* fp) |
64 { |
67 { |
65 if (fp and fp->isOpen()) |
68 if (fp and fp->isOpen()) |
66 { |
69 { |
67 while (not fp->atEnd()) |
70 while (not fp->atEnd()) |
68 m_lines << QString::fromUtf8 (fp->readLine()); |
71 m_lines << QString::fromUtf8(fp->readLine()).simplified(); |
69 } |
72 } |
70 } |
73 } |
71 |
74 |
72 void DocumentLoader::start() |
75 void DocumentLoader::start() |
73 { |
76 { |
85 m_progressDialog->show(); |
88 m_progressDialog->show(); |
86 connect (this, SIGNAL (workDone()), m_progressDialog, SLOT (accept())); |
89 connect (this, SIGNAL (workDone()), m_progressDialog, SLOT (accept())); |
87 connect (m_progressDialog, SIGNAL (rejected()), this, SLOT (abort())); |
90 connect (m_progressDialog, SIGNAL (rejected()), this, SLOT (abort())); |
88 } |
91 } |
89 else |
92 else |
|
93 { |
90 m_progressDialog = nullptr; |
94 m_progressDialog = nullptr; |
|
95 } |
|
96 |
|
97 // Parse the header |
|
98 while (m_progress < m_lines.size()) |
|
99 { |
|
100 const QString& line = m_lines[m_progress]; |
|
101 |
|
102 if (not line.isEmpty()) |
|
103 { |
|
104 if (line.startsWith("0")) |
|
105 { |
|
106 if (m_progress == 0) |
|
107 { |
|
108 _header.description = line.mid(1).simplified(); |
|
109 } |
|
110 else if (line.startsWith("0 !LDRAW_ORG")) |
|
111 { |
|
112 QStringList tokens = line.mid(strlen("0 !LDRAW_ORG")); |
|
113 } |
|
114 else if (line.startsWith("0 BFC")) |
|
115 { |
|
116 ...; |
|
117 } |
|
118 else |
|
119 { |
|
120 _model->addFromString(line); |
|
121 } |
|
122 m_progress += 1; |
|
123 } |
|
124 else |
|
125 { |
|
126 break; |
|
127 } |
|
128 } |
|
129 } |
91 |
130 |
92 // Begin working |
131 // Begin working |
93 work (0); |
132 work (0); |
94 } |
133 } |
95 |
134 |
107 |
146 |
108 bool invertNext = false; |
147 bool invertNext = false; |
109 |
148 |
110 for (; i < max and i < (int) countof(m_lines); ++i) |
149 for (; i < max and i < (int) countof(m_lines); ++i) |
111 { |
150 { |
112 QString line = m_lines[i].trimmed(); |
151 const QString& line = m_lines[i]; |
113 |
|
114 // Trim the trailing newline |
|
115 while (line.endsWith ("\n") or line.endsWith ("\r")) |
|
116 line.chop(1); |
|
117 |
152 |
118 if (line == "0 BFC INVERTNEXT") |
153 if (line == "0 BFC INVERTNEXT") |
119 { |
154 { |
120 invertNext = true; |
155 invertNext = true; |
121 continue; |
156 continue; |