src/documentmanager.cpp

Thu, 04 Jan 2018 21:41:17 +0200

author
Santeri Piippo
date
Thu, 04 Jan 2018 21:41:17 +0200
changeset 1222
34def2630300
parent 1217
314e12e23c3a
child 1224
5a31b6d4bf81
permissions
-rw-r--r--

happy new year 2018

997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
1222
34def2630300 happy new year 2018
Santeri Piippo
parents: 1217
diff changeset
3 * Copyright (C) 2013 - 2018 Teemu Piippo
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
19 #include <QApplication>
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include <QFileInfo>
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include <QFile>
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include "documentmanager.h"
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include "ldDocument.h"
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include "mainwindow.h"
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 #include "partdownloader.h"
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
26 #include "documentloader.h"
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
27 #include "glRenderer.h"
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
28
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
29 ConfigOption(QStringList RecentFiles)
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
30 ConfigOption(bool TryDownloadMissingFiles = false)
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 enum
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 {
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
34 MaxRecentFiles = 10
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 };
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
37 DocumentManager::DocumentManager(QObject* parent) :
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
38 QObject(parent),
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
39 HierarchyElement(parent),
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
40 m_loadingMainFile(false),
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
41 m_isLoadingLogoedStuds(false),
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
42 m_logoedStud(nullptr),
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
43 m_logoedStud2(nullptr) {}
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 DocumentManager::~DocumentManager()
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 clear();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 void DocumentManager::clear()
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 {
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
52 for (LDDocument* document : m_documents)
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 document->close();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 delete document;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 m_documents.clear();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
61 LDDocument* DocumentManager::getDocumentByName(QString filename)
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
63 LDDocument* doc = findDocumentByName(filename);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
65 if (doc == nullptr)
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
66 {
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
67 bool tmp = m_loadingMainFile;
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
68 m_loadingMainFile = false;
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
69 doc = openDocument(filename, true, true);
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
70 m_loadingMainFile = tmp;
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
71 }
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 return doc;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
76 void DocumentManager::openMainModel(QString path)
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 // If there's already a file with the same name, this file must replace it.
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 LDDocument* documentToReplace = nullptr;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 LDDocument* file = nullptr;
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
81 QString shortName = LDDocument::shortenName(path);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
83 for (LDDocument* doc : m_documents)
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 if (doc->name() == shortName)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 documentToReplace = doc;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 break;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 // We cannot open this file if the document this would replace is not
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 // safe to close.
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 if (documentToReplace and not documentToReplace->isSafeToClose())
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 return;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
97 m_loadingMainFile = true;
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 // If we're replacing an existing document, clear the document and
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 // make it ready for being loaded to.
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 if (documentToReplace)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 file = documentToReplace;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 file->clear();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 bool aborted;
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
108 file = openDocument(path, false, false, file, &aborted);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 if (file == nullptr)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 if (not aborted)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114 // Tell the user loading failed.
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
115 setlocale(LC_ALL, "C");
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
116 Critical(format(tr("Failed to open %1: %2"), path, strerror(errno)));
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
119 m_loadingMainFile = false;
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 return;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 file->openForEditing();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 m_window->closeInitialDocument();
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
125 m_window->changeDocument(file);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126 m_window->doFullRefresh();
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
127 addRecentFile(path);
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
128 m_loadingMainFile = false;
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130 // If there were problems loading subfile references, try see if we can find these
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 // files on the parts tracker.
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 QStringList unknowns;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 for (LDObject* obj : file->objects())
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
136 if (obj->type() != OBJ_Error or static_cast<LDError*>(obj)->fileReferenced().isEmpty())
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137 continue;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
139 unknowns << static_cast<LDError*>(obj)->fileReferenced();
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141
1215
77a0270352a3 replaced "Config->" with "config."
Santeri Piippo
parents: 1012
diff changeset
142 if (config.tryDownloadMissingFiles() and not unknowns.isEmpty())
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
144 PartDownloader dl(m_window);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
145 dl.setSourceType(PartDownloader::PartsTracker);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
146 dl.setPrimaryFile(file);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148 for (QString const& unknown : unknowns)
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
149 dl.downloadFromPartsTracker(unknown);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151 dl.exec();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152 dl.checkIfFinished();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153 file->reloadAllSubfiles();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
157 LDDocument* DocumentManager::findDocumentByName(QString name)
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
158 {
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
159 for (LDDocument* document : m_documents)
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
161 if (isOneOf(name, document->name(), document->defaultName()))
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162 return document;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
163 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
164
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165 return nullptr;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
168 QString Dirname(QString path)
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
169 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
170 int lastpos = path.lastIndexOf(DIRSLASH);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
172 if (lastpos > 0)
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
173 return path.left(lastpos);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
174
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
175 #ifndef _WIN32
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
176 if (path[0] == DIRSLASH_CHAR)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
177 return DIRSLASH;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178 #endif // _WIN32
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 return "";
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
183 QString Basename(QString path)
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
184 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
185 int lastpos = path.lastIndexOf(DIRSLASH);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
187 if (lastpos != -1)
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
188 return path.mid(lastpos + 1);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
190 return path;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
192
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
193 QString DocumentManager::findDocumentPath(QString relativePath, bool subdirs)
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
194 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
195 // LDraw models use backslashes as path separators. Replace those into forward slashes for Qt.
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
196 relativePath.replace("\\", "/");
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
197
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
198 // Try find it relative to other currently open documents. We want a file in the immediate vicinity of a current
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
199 // part model to override stock LDraw stuff.
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
200 QString relativeTopDir = Basename(Dirname(relativePath));
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
201
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
202 for (LDDocument* document : m_documents)
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
203 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
204 QString partpath = format("%1/%2", Dirname(document->fullPath()), relativePath);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
205 QFileInfo fileinfo(partpath);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
206
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
207 if (fileinfo.exists())
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
208 {
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
209 // Ensure we don't mix subfiles and 48-primitives with non-subfiles and non-48
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
210 QString partTopDir = Basename(Dirname(partpath));
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
211
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
212 for (QString subdir : g_specialSubdirectories)
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
213 {
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
214 if ((partTopDir == subdir) != (relativeTopDir == subdir))
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
215 goto skipthis;
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
216 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
217
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
218 return partpath;
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
219 }
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
220 skipthis:
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
221 continue;
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
222 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
223
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
224 if (QFileInfo::exists(relativePath))
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
225 return relativePath;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
226
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
227 // Try with just the LDraw path first
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
228 QString fullPath = format("%1" DIRSLASH "%2", config.lDrawPath(), relativePath);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
229
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
230 if (QFileInfo::exists(fullPath))
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
231 return fullPath;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
232
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
233 if (subdirs)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
234 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
235 // Look in sub-directories: parts and p. Also look in the download path, since that's where we download parts
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
236 // from the PT to.
1215
77a0270352a3 replaced "Config->" with "config."
Santeri Piippo
parents: 1012
diff changeset
237 QStringList dirs = { config.lDrawPath(), config.downloadFilePath() };
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
238 for (const QString& topdir : dirs)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
239 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
240 for (const QString& subdir : QStringList({ "parts", "p" }))
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
241 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
242 fullPath = format("%1" DIRSLASH "%2" DIRSLASH "%3", topdir, subdir, relativePath);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
243
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
244 if (QFile::exists(fullPath))
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
245 return fullPath;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
246 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
247 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
248 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
249
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
250 // Did not find the file.
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
251 return "";
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
252 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
253
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
254 QFile* DocumentManager::openLDrawFile(QString relpath, bool subdirs, QString* pathpointer)
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
255 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
256 print("Opening %1...\n", relpath);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
257 QString path = findDocumentPath(relpath, subdirs);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
258
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
259 if (pathpointer)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
260 *pathpointer = path;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
261
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
262 if (path.isEmpty())
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
263 return nullptr;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
264
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
265 QFile* fp = new QFile(path);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
266
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
267 if (fp->open(QIODevice::ReadOnly))
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
268 return fp;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
269
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
270 fp->deleteLater();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
271 return nullptr;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
272 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
273
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
274 LDObjectList DocumentManager::loadFileContents(QFile* fp, int* numWarnings, bool* ok)
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
275 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
276 LDObjectList objs;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
277
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
278 if (numWarnings)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
279 *numWarnings = 0;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
280
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
281 DocumentLoader* loader = new DocumentLoader(m_loadingMainFile);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
282 loader->read(fp);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
283 loader->start();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
284
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
285 // After start() returns, if the loader isn't done yet, it's delaying
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
286 // its next iteration through the event loop. We need to catch this here
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
287 // by telling the event loop to tick, which will tick the file loader again.
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
288 // We keep doing this until the file loader is ready.
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
289 while (not loader->isDone())
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
290 qApp->processEvents();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
291
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
292 // If we wanted the success value, supply that now
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
293 if (ok)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
294 *ok = not loader->hasAborted();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
295
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
296 objs = loader->objects();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
297 delete loader;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
298 return objs;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
299 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
300
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
301 LDDocument* DocumentManager::openDocument(QString path, bool search, bool implicit, LDDocument* fileToOverride, bool* aborted)
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
302 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
303 // Convert the file name to lowercase when searching because some parts contain subfile
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
304 // subfile references with uppercase file names. I'll assume here that the library will always
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
305 // use lowercase file names for the part files.
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
306 QFile* fp;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
307 QString fullpath;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
308
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
309 if (search)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
310 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
311 fp = openLDrawFile(path.toLower(), true, &fullpath);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
312 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
313 else
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
314 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
315 fp = new QFile(path);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
316 fullpath = path;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
317
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
318 if (not fp->open(QIODevice::ReadOnly))
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
319 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
320 delete fp;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
321 return nullptr;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
322 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
323 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
324
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
325 if (not fp)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
326 return nullptr;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
327
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
328 LDDocument* load = (fileToOverride ? fileToOverride : m_window->newDocument(implicit));
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
329 load->setFullPath(fullpath);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
330 load->setName(LDDocument::shortenName(load->fullPath()));
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
331
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
332 // Loading the file shouldn't count as actual edits to the document.
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
333 load->history()->setIgnoring(true);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
334
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
335 int numWarnings;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
336 bool ok;
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
337 LDObjectList objs = loadFileContents(fp, &numWarnings, &ok);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
338 fp->close();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
339 fp->deleteLater();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
340
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
341 if (aborted)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
342 *aborted = ok == false;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
343
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
344 if (not ok)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
345 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
346 load->close();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
347 return nullptr;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
348 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
349
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
350 load->addObjects(objs);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
351
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
352 if (m_loadingMainFile)
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
353 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
354 m_window->changeDocument(load);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
355 m_window->renderer()->setDocument(load);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
356 print(tr("File %1 parsed successfully(%2 errors)."), path, numWarnings);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
357 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
358
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
359 load->history()->setIgnoring(false);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
360 return load;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
361 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
362
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
363 void DocumentManager::addRecentFile(QString path)
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
364 {
1215
77a0270352a3 replaced "Config->" with "config."
Santeri Piippo
parents: 1012
diff changeset
365 QStringList recentFiles = config.recentFiles();
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
366 int idx = recentFiles.indexOf(path);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
367
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
368 // If this file already is in the list, pop it out.
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
369 if (idx != -1)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
370 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
371 if (idx == recentFiles.size() - 1)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
372 return; // first recent file - abort and do nothing
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
373
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
374 recentFiles.removeAt(idx);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
375 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
376
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
377 // If there's too many recent files, drop one out.
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
378 while (recentFiles.size() >(MaxRecentFiles - 1))
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
379 recentFiles.removeAt(0);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
380
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
381 // Add the file
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
382 recentFiles << path;
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
383 config.setRecentFiles(recentFiles);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
384 m_window->syncSettings();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
385 m_window->updateRecentFilesMenu();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
386 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
387
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
388 bool DocumentManager::isSafeToCloseAll()
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
389 {
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
390 for (LDDocument* document : m_documents)
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
391 {
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
392 if (not document->isSafeToClose())
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
393 return false;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
394 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
395
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
396 return true;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
397 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
398
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
399 void DocumentManager::loadLogoedStuds()
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
400 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
401 if (m_isLoadingLogoedStuds or(m_logoedStud and m_logoedStud2))
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
402 return;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
403
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
404 m_isLoadingLogoedStuds = true;
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
405 m_logoedStud = openDocument("stud-logo.dat", true, true);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
406 m_logoedStud2 = openDocument("stud2-logo.dat", true, true);
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
407 m_isLoadingLogoedStuds = false;
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
408
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
409 if (m_logoedStud and m_logoedStud2)
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
410 print(tr("Logoed studs loaded.\n"));
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
411 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
412
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
413 bool DocumentManager::preInline(LDDocument* doc, LDObjectList& objs, bool deep, bool renderinline)
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
414 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
415 // Possibly substitute with logoed studs:
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
416 // stud.dat -> stud-logo.dat
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
417 // stud2.dat -> stud-logo2.dat
1215
77a0270352a3 replaced "Config->" with "config."
Santeri Piippo
parents: 1012
diff changeset
418 if (config.useLogoStuds() and renderinline)
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
419 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
420 // Ensure logoed studs are loaded first
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
421 loadLogoedStuds();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
422
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
423 if (doc->name() == "stud.dat" and m_logoedStud)
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
424 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
425 objs = m_logoedStud->inlineContents(deep, renderinline);
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
426 return true;
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
427 }
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
428 else if (doc->name() == "stud2.dat" and m_logoedStud2)
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
429 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
430 objs = m_logoedStud2->inlineContents(deep, renderinline);
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
431 return true;
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
432 }
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
433 }
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
434 return false;
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
435 }
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
436
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
437 LDDocument* DocumentManager::createNew()
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
438 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
439 LDDocument* document = new LDDocument(this);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
440 m_documents.insert(document);
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
441 return document;
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
442 }

mercurial