src/documentmanager.cpp

Sat, 03 Mar 2018 17:47:40 +0200

author
Santeri Piippo
date
Sat, 03 Mar 2018 17:47:40 +0200
changeset 1263
0256edecda54
parent 1159
6ad8cdcd88d9
child 1264
5f00dfde4901
permissions
-rw-r--r--

LDSubfileReference now contains the name of the subfile and not a pointer anymore. Some methods now require a DocumentManager* for context on resolving the name.

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
1072
9ce9496427f2 Happy new year 2017!
Teemu Piippo <teemu@hecknology.net>
parents: 1065
diff changeset
3 * Copyright (C) 2013 - 2017 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>
1156
c20ee66b6705 Removed the Critical and Question functions, replaced with direct QMessageBox uses. Removed unused code from mainwindow.h.
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
21 #include <QMessageBox>
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include "documentmanager.h"
1145
02264bf0108d Renamed ldDocument.cpp → lddocument.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1144
diff changeset
23 #include "lddocument.h"
997
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"
1144
4f226fd97826 Renamed glRenderer.cpp → glrenderer.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
27 #include "glrenderer.h"
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
28
1114
ffd49a28f49e Moved some global constants into appropriate namespaces.
Teemu Piippo <teemu@hecknology.net>
parents: 1097
diff changeset
29 const QStringList DocumentManager::specialSubdirectories {"s", "48", "8"};
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 enum
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 {
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
33 MaxRecentFiles = 10
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 };
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 DocumentManager::DocumentManager (QObject* parent) :
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 QObject (parent),
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
38 HierarchyElement (parent),
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
39 m_loadingMainFile (false),
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
40 m_isLoadingLogoedStuds (false),
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
41 m_logoedStud (nullptr),
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
42 m_logoedStud2 (nullptr) {}
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 DocumentManager::~DocumentManager()
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 clear();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 }
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 void DocumentManager::clear()
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 {
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
51 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
52 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 document->close();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 delete document;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 }
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 m_documents.clear();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 }
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 LDDocument* DocumentManager::getDocumentByName (QString filename)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 LDDocument* doc = findDocumentByName (filename);
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
64 if (doc == nullptr)
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
65 {
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
66 bool tmp = m_loadingMainFile;
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
67 m_loadingMainFile = false;
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 doc = openDocument (filename, true, true);
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
69 m_loadingMainFile = tmp;
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
70 }
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 return doc;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 }
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 void DocumentManager::openMainModel (QString path)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 // 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
78 LDDocument* documentToReplace = nullptr;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 LDDocument* file = nullptr;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 QString shortName = LDDocument::shortenName (path);
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
82 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
83 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 if (doc->name() == shortName)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 documentToReplace = doc;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 break;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 }
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 // 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
92 // safe to close.
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 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
94 return;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
96 m_loadingMainFile = true;
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 // 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
99 // 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
100 if (documentToReplace)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 file = documentToReplace;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 file->clear();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 }
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 bool aborted;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 file = openDocument (path, false, false, file, &aborted);
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 if (file == nullptr)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 if (not aborted)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 // Tell the user loading failed.
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114 setlocale (LC_ALL, "C");
1156
c20ee66b6705 Removed the Critical and Question functions, replaced with direct QMessageBox uses. Removed unused code from mainwindow.h.
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
115 QMessageBox::critical(m_window, tr("Error"), 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
116 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
118 m_loadingMainFile = false;
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119 return;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121
1090
ed73c4f48ca4 The current document pointer may no longer be null.
Teemu Piippo <teemu@hecknology.net>
parents: 1086
diff changeset
122 m_window->openDocumentForEditing(file);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 m_window->closeInitialDocument();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 m_window->changeDocument (file);
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 m_window->doFullRefresh();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126 addRecentFile (path);
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
127 m_loadingMainFile = false;
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 // 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
130 // files on the parts tracker.
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 QStringList unknowns;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133 for (LDObject* obj : file->objects())
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 {
1123
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1114
diff changeset
135 if (obj->type() != LDObjectType::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
136 continue;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138 unknowns << static_cast<LDError*> (obj)->fileReferenced();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1016
diff changeset
141 if (m_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
142 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143 PartDownloader dl (m_window);
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 dl.setSourceType (PartDownloader::PartsTracker);
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145 dl.setPrimaryFile (file);
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147 for (QString const& unknown : unknowns)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148 dl.downloadFromPartsTracker (unknown);
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150 dl.exec();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151 dl.checkIfFinished();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153 }
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 LDDocument* DocumentManager::findDocumentByName (QString name)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 {
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
157 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
158 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159 if (isOneOf (name, document->name(), document->defaultName()))
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160 return document;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
163 return nullptr;
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
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166 QString Dirname (QString path)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 int lastpos = path.lastIndexOf (DIRSLASH);
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
169
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170 if (lastpos > 0)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171 return path.left (lastpos);
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
172
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
173 #ifndef _WIN32
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
174 if (path[0] == DIRSLASH_CHAR)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
175 return DIRSLASH;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
176 #endif // _WIN32
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
177
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178 return "";
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
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181 QString Basename (QString path)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183 int lastpos = path.lastIndexOf (DIRSLASH);
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
184
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
185 if (lastpos != -1)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186 return path.mid (lastpos + 1);
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
187
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
188 return path;
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
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191 QString DocumentManager::findDocumentPath (QString relativePath, bool subdirs)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
192 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
193 // LDraw models use backslashes as path separators. Replace those into forward slashes for Qt.
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
194 relativePath.replace ("\\", "/");
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
195
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
196 // 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
197 // part model to override stock LDraw stuff.
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
198 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
199
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
200 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
201 {
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
202 QString partpath = format ("%1/%2", Dirname (document->fullPath()), relativePath);
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
203 QFileInfo fileinfo (partpath);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
204
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
205 if (fileinfo.exists())
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 // Ensure we don't mix subfiles and 48-primitives with non-subfiles and non-48
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
208 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
209
1114
ffd49a28f49e Moved some global constants into appropriate namespaces.
Teemu Piippo <teemu@hecknology.net>
parents: 1097
diff changeset
210 for (QString subdir : specialSubdirectories)
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 if ((partTopDir == subdir) != (relativeTopDir == subdir))
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
213 goto skipthis;
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
214 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
215
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
216 return partpath;
997
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 skipthis:
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
219 continue;
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
220 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
221
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
222 if (QFileInfo::exists (relativePath))
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
223 return relativePath;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
224
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
225 // Try with just the LDraw path first
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1016
diff changeset
226 QString fullPath = format ("%1" DIRSLASH "%2", m_config->lDrawPath(), relativePath);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
227
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
228 if (QFileInfo::exists (fullPath))
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
229 return fullPath;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
230
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
231 if (subdirs)
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 // 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
234 // from the PT to.
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1016
diff changeset
235 QStringList dirs = { m_config->lDrawPath(), m_config->downloadFilePath() };
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
236 for (const QString& topdir : dirs)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
237 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
238 for (const QString& subdir : QStringList ({ "parts", "p" }))
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
239 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
240 fullPath = format ("%1" DIRSLASH "%2" DIRSLASH "%3", topdir, subdir, relativePath);
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
241
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
242 if (QFile::exists (fullPath))
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
243 return fullPath;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
244 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
245 }
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 // Did not find the file.
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
249 return "";
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
250 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
251
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
252 QFile* DocumentManager::openLDrawFile (QString relpath, bool subdirs, QString* pathpointer)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
253 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
254 print ("Opening %1...\n", relpath);
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
255 QString path = findDocumentPath (relpath, subdirs);
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
256
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
257 if (pathpointer)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
258 *pathpointer = path;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
259
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
260 if (path.isEmpty())
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
261 return nullptr;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
262
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
263 QFile* fp = new QFile (path);
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
264
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
265 if (fp->open (QIODevice::ReadOnly))
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
266 return fp;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
267
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
268 fp->deleteLater();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
269 return nullptr;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
270 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
271
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
272 void DocumentManager::loadFileContents(QIODevice* input, Model& model, int* numWarnings, bool* ok)
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
273 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
274 if (numWarnings)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
275 *numWarnings = 0;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
276
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
277 DocumentLoader* loader = new DocumentLoader {&model, m_loadingMainFile};
1159
6ad8cdcd88d9 print() is no longer a global function but is tied to HierarchyElement.
Teemu Piippo <teemu@hecknology.net>
parents: 1156
diff changeset
278 connect(loader, SIGNAL(parseErrorMessage(QString)), this, SLOT(printParseErrorMessage(QString)));
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
279 loader->read(input);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
280 loader->start();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
281
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
282 // 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
283 // 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
284 // 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
285 // 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
286 while (not loader->isDone())
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
287 qApp->processEvents();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
288
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
289 // 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
290 if (ok)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
291 *ok = not loader->hasAborted();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
292 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
293
1159
6ad8cdcd88d9 print() is no longer a global function but is tied to HierarchyElement.
Teemu Piippo <teemu@hecknology.net>
parents: 1156
diff changeset
294 void DocumentManager::printParseErrorMessage(QString message)
6ad8cdcd88d9 print() is no longer a global function but is tied to HierarchyElement.
Teemu Piippo <teemu@hecknology.net>
parents: 1156
diff changeset
295 {
6ad8cdcd88d9 print() is no longer a global function but is tied to HierarchyElement.
Teemu Piippo <teemu@hecknology.net>
parents: 1156
diff changeset
296 print(message);
6ad8cdcd88d9 print() is no longer a global function but is tied to HierarchyElement.
Teemu Piippo <teemu@hecknology.net>
parents: 1156
diff changeset
297 }
6ad8cdcd88d9 print() is no longer a global function but is tied to HierarchyElement.
Teemu Piippo <teemu@hecknology.net>
parents: 1156
diff changeset
298
1016
3b279b5e57d3 Fixed line length warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
299 LDDocument* DocumentManager::openDocument (QString path, bool search, bool implicit, LDDocument* fileToOverride,
3b279b5e57d3 Fixed line length warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
300 bool* aborted)
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
301 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
302 // 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
303 // 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
304 // 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
305 QFile* fp;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
306 QString fullpath;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
307
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
308 if (search)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
309 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
310 fp = openLDrawFile (path.toLower(), true, &fullpath);
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
311 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
312 else
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
313 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
314 fp = new QFile (path);
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
315 fullpath = path;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
316
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
317 if (not fp->open (QIODevice::ReadOnly))
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
318 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
319 delete fp;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
320 return nullptr;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
321 }
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 if (not fp)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
325 return nullptr;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
326
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
327 LDDocument* load = (fileToOverride ? fileToOverride : m_window->newDocument (implicit));
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
328 load->setFullPath (fullpath);
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
329 load->setName (LDDocument::shortenName (load->fullPath()));
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
330
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
331 // Loading the file shouldn't count as actual edits to the document.
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
332 load->history()->setIgnoring (true);
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
333
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
334 int numWarnings;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
335 bool ok;
1079
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1073
diff changeset
336 Model model {this};
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
337 loadFileContents(fp, model, &numWarnings, &ok);
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
338 load->merge(model);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
339 fp->close();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
340 fp->deleteLater();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
341
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
342 if (aborted)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
343 *aborted = ok == false;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
344
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
345 if (not ok)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
346 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
347 load->close();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
348 return nullptr;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
349 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
350
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
351 if (m_loadingMainFile)
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
352 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
353 m_window->changeDocument (load);
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
354 print (tr ("File %1 parsed successfully (%2 errors)."), path, numWarnings);
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
355 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
356
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
357 load->history()->setIgnoring (false);
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
358 return load;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
359 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
360
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
361 void DocumentManager::addRecentFile (QString path)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
362 {
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1016
diff changeset
363 QStringList recentFiles = m_config->recentFiles();
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
364 int idx = recentFiles.indexOf (path);
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
365
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
366 // 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
367 if (idx != -1)
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
368 {
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
369 if (idx == countof(recentFiles) - 1)
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
370 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
371
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
372 recentFiles.removeAt (idx);
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
373 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
374
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
375 // If there's too many recent files, drop one out.
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
376 while (countof(recentFiles) > (MaxRecentFiles - 1))
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
377 recentFiles.removeAt (0);
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
378
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
379 // Add the file
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
380 recentFiles << path;
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1016
diff changeset
381 m_config->setRecentFiles (recentFiles);
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
382 m_window->syncSettings();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
383 m_window->updateRecentFilesMenu();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
384 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
385
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
386 bool DocumentManager::isSafeToCloseAll()
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
387 {
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
388 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
389 {
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
390 if (not document->isSafeToClose())
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
391 return false;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
392 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
393
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
394 return true;
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
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
397 void DocumentManager::loadLogoedStuds()
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
398 {
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
399 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
400 return;
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
401
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
402 m_isLoadingLogoedStuds = true;
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
403 m_logoedStud = openDocument ("stud-logo.dat", true, true);
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
404 m_logoedStud2 = openDocument ("stud2-logo.dat", true, true);
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
405 m_isLoadingLogoedStuds = false;
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
406
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
407 if (m_logoedStud and m_logoedStud2)
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
408 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
409 }
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
410
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
411 bool DocumentManager::preInline (LDDocument* doc, Model& model, bool deep, bool renderinline)
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
412 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
413 // Possibly substitute with logoed studs:
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
414 // stud.dat -> stud-logo.dat
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
415 // stud2.dat -> stud-logo2.dat
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1016
diff changeset
416 if (m_config->useLogoStuds() and renderinline)
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
417 {
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
418 // 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
419 loadLogoedStuds();
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
420
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
421 if (doc->name() == "stud.dat" and m_logoedStud)
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
422 {
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
423 m_logoedStud->inlineContents(model, deep, renderinline);
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
424 return true;
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
425 }
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
426 else if (doc->name() == "stud2.dat" and m_logoedStud2)
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
427 {
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
428 m_logoedStud2->inlineContents(model, deep, renderinline);
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
429 return true;
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
430 }
997
1b49f34e533d Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
431 }
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
432 return false;
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
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
435 LDDocument* DocumentManager::createNew()
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* document = new LDDocument (this);
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
438 m_documents.insert (document);
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
439 return document;
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 997
diff changeset
440 }

mercurial