Thu, 07 Feb 2019 15:43:18 +0200
reworked selection model handling
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 |
1326 | 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 | |
1308
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
19 | #include <QDir> |
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> |
1323
05b3e173c900
Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents:
1318
diff
changeset
|
22 | #include <QSettings> |
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | #include "documentmanager.h" |
1145
02264bf0108d
Renamed ldDocument.cpp → lddocument.cpp
Teemu Piippo <teemu@hecknology.net>
parents:
1144
diff
changeset
|
24 | #include "lddocument.h" |
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | #include "partdownloader.h" |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
1264
diff
changeset
|
26 | #include "parser.h" |
1318
568fcfc6da71
removed unnecessary files and includes
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
27 | #include "editHistory.h" |
998 | 28 | |
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | enum |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | { |
998 | 31 | MaxRecentFiles = 10 |
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | }; |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | DocumentManager::DocumentManager (QObject* parent) : |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | QObject (parent), |
998 | 36 | HierarchyElement (parent), |
37 | m_loadingMainFile (false), | |
38 | m_isLoadingLogoedStuds (false), | |
39 | m_logoedStud (nullptr), | |
40 | m_logoedStud2 (nullptr) {} | |
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | DocumentManager::~DocumentManager() |
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 | clear(); |
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 | |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | void DocumentManager::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 | m_documents.clear(); |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | } |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | LDDocument* DocumentManager::getDocumentByName (QString filename) |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | { |
1298
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
54 | if (not filename.isEmpty()) |
998 | 55 | { |
1428
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
56 | auto iterator = findDocumentByName (filename); |
1298
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
57 | |
1428
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
58 | if (iterator == end()) |
1298
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
59 | { |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
60 | bool tmp = m_loadingMainFile; |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
61 | m_loadingMainFile = false; |
1428
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
62 | LDDocument *doc = openDocument(filename, true, true); |
1298
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
63 | m_loadingMainFile = tmp; |
1428
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
64 | return doc; |
1298
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
65 | } |
1428
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
66 | else |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
67 | { |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
68 | return iterator->get(); |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
69 | } |
998 | 70 | } |
1298
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
71 | else |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
72 | { |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
73 | return nullptr; |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
74 | } |
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | } |
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 | void DocumentManager::openMainModel (QString path) |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | { |
1428
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
79 | // If there's already a file with the same name, this file must replace it. Thus, we cannot open this file if the |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
80 | // document this would replace is not safe to close. |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
81 | auto documentToReplace = findDocumentByName(LDDocument::shortenName(path)); |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
82 | if (documentToReplace != end()) |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
83 | { |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
84 | if (not (*documentToReplace)->isSafeToClose()) |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
85 | return; |
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | |
1428
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
87 | (*documentToReplace)->close(); |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
88 | m_documents.erase(documentToReplace); |
997
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 | |
998 | 91 | m_loadingMainFile = true; |
1428
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
92 | LDDocument* file = openDocument(path, false, false); |
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | if (file == nullptr) |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | { |
1288
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
1264
diff
changeset
|
96 | // Tell the user loading failed. |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
1264
diff
changeset
|
97 | setlocale (LC_ALL, "C"); |
d1e45f90654b
Header parsing complete, moved all parsing code into a new class. Documents are now all loaded in one go.
Teemu Piippo <teemu@hecknology.net>
parents:
1264
diff
changeset
|
98 | QMessageBox::critical(m_window, tr("Error"), format(tr("Failed to open %1: %2"), path, strerror (errno))); |
998 | 99 | m_loadingMainFile = false; |
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | return; |
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 | |
1437
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1428
diff
changeset
|
103 | emit mainModelLoaded(file); |
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | addRecentFile (path); |
998 | 105 | m_loadingMainFile = false; |
997
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 | // 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
|
108 | // files on the parts tracker. |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | QStringList unknowns; |
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 | for (LDObject* obj : file->objects()) |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | { |
1264
5f00dfde4901
reimplemented finding of broken document references
Santeri Piippo
parents:
1263
diff
changeset
|
113 | if (obj->type() == LDObjectType::SubfileReference) |
5f00dfde4901
reimplemented finding of broken document references
Santeri Piippo
parents:
1263
diff
changeset
|
114 | { |
5f00dfde4901
reimplemented finding of broken document references
Santeri Piippo
parents:
1263
diff
changeset
|
115 | LDSubfileReference* reference = static_cast<LDSubfileReference*>(obj); |
5f00dfde4901
reimplemented finding of broken document references
Santeri Piippo
parents:
1263
diff
changeset
|
116 | LDDocument* document = reference->fileInfo(this); |
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | |
1264
5f00dfde4901
reimplemented finding of broken document references
Santeri Piippo
parents:
1263
diff
changeset
|
118 | if (document == nullptr) |
5f00dfde4901
reimplemented finding of broken document references
Santeri Piippo
parents:
1263
diff
changeset
|
119 | unknowns << reference->referenceName(); |
5f00dfde4901
reimplemented finding of broken document references
Santeri Piippo
parents:
1263
diff
changeset
|
120 | } |
997
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 | |
1323
05b3e173c900
Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents:
1318
diff
changeset
|
123 | 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
|
124 | { |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | PartDownloader dl (m_window); |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | dl.setSourceType (PartDownloader::PartsTracker); |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | dl.setPrimaryFile (file); |
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 | for (QString const& unknown : unknowns) |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | dl.downloadFromPartsTracker (unknown); |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | dl.exec(); |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | dl.checkIfFinished(); |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | } |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
135 | } |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
136 | |
1428
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
137 | DocumentManager::iterator DocumentManager::findDocumentByName(const QString& name) |
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | { |
1298
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
139 | if (not name.isEmpty()) |
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
140 | { |
1428
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
141 | for (auto it = begin(); it != end(); ++it) |
1298
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
142 | { |
1428
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
143 | if (name == oneOf((*it)->name(), (*it)->defaultName())) |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
144 | return it; |
1298
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
145 | } |
997
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 | |
1428
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
148 | return end(); |
997
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 | |
1308
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
151 | QString DocumentManager::findDocument(QString name) const |
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
152 | { |
1308
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
153 | name = name.replace("\\", "/"); |
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
154 | |
1323
05b3e173c900
Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents:
1318
diff
changeset
|
155 | for (const Library& library : config::libraries()) |
1308
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
156 | { |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
157 | for (const QString& subdirectory : {"parts", "p"}) |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
158 | { |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
159 | QDir dir {library.path + "/" + subdirectory}; |
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
160 | |
1308
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
161 | if (dir.exists(name)) |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
162 | return QDir::cleanPath(dir.filePath(name)); |
997
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 | |
1308
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
166 | return {}; |
997
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 | |
1159
6ad8cdcd88d9
print() is no longer a global function but is tied to HierarchyElement.
Teemu Piippo <teemu@hecknology.net>
parents:
1156
diff
changeset
|
169 | 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
|
170 | { |
6ad8cdcd88d9
print() is no longer a global function but is tied to HierarchyElement.
Teemu Piippo <teemu@hecknology.net>
parents:
1156
diff
changeset
|
171 | print(message); |
6ad8cdcd88d9
print() is no longer a global function but is tied to HierarchyElement.
Teemu Piippo <teemu@hecknology.net>
parents:
1156
diff
changeset
|
172 | } |
6ad8cdcd88d9
print() is no longer a global function but is tied to HierarchyElement.
Teemu Piippo <teemu@hecknology.net>
parents:
1156
diff
changeset
|
173 | |
1428
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
174 | LDDocument* DocumentManager::openDocument(QString path, bool search, bool implicit) |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
175 | { |
1308
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
176 | if (search and not QFileInfo {path}.exists()) |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
177 | { |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
178 | // Convert the file name to lowercase when searching because some parts contain subfile |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
179 | // subfile references with uppercase file names. I'll assume here that the library will |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
180 | // always use lowercase file names for the part files. |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
181 | path = this->findDocument(path.toLower()); |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
182 | } |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
183 | |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
184 | QFile file {path}; |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
185 | |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
186 | if (file.open(QIODevice::ReadOnly)) |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
187 | { |
1428
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
188 | LDDocument* load = createNew(implicit); |
1308
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
189 | |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
190 | // Loading the file shouldn't count as actual edits to the document. |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
191 | load->history()->setIgnoring (true); |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
192 | |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
193 | Parser parser {file}; |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
194 | Winding winding = NoWinding; |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
195 | load->header = parser.parseHeader(winding); |
1367 | 196 | load->setFullPath(path); |
197 | load->setName(LDDocument::shortenName(path)); | |
1308
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
198 | load->setWinding(winding); |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
199 | parser.parseBody(*load); |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
200 | file.close(); |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
201 | |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
202 | if (m_loadingMainFile) |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
203 | { |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
204 | int numWarnings = 0; |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
205 | |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
206 | for (LDObject* object : load->objects()) |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
207 | { |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
208 | if (object->type() == LDObjectType::Error) |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
209 | numWarnings += 1; |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
210 | } |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
211 | |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
212 | m_window->changeDocument(load); |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
213 | print(tr("File %1 opened successfully (%2 errors)."), load->name(), numWarnings); |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
214 | } |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
215 | |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
216 | load->history()->setIgnoring (false); |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
217 | return load; |
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
218 | } |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
219 | else |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
220 | { |
1308
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1306
diff
changeset
|
221 | return nullptr; |
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 | } |
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 | void DocumentManager::addRecentFile (QString path) |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
226 | { |
1323
05b3e173c900
Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents:
1318
diff
changeset
|
227 | QStringList recentFiles = config::recentFiles(); |
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
228 | int idx = recentFiles.indexOf (path); |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
229 | |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
230 | // 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
|
231 | if (idx != -1) |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
232 | { |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1063
diff
changeset
|
233 | 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
|
234 | 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
|
235 | |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
236 | recentFiles.removeAt (idx); |
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 | |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
239 | // 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
|
240 | 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
|
241 | recentFiles.removeAt (0); |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
242 | |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
243 | // Add the file |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
244 | recentFiles << path; |
1323
05b3e173c900
Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents:
1318
diff
changeset
|
245 | config::setRecentFiles (recentFiles); |
05b3e173c900
Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents:
1318
diff
changeset
|
246 | settingsObject().sync(); |
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
247 | m_window->updateRecentFilesMenu(); |
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 | |
1428
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
250 | const DocumentManager::Documents& DocumentManager::allDocuments() const |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
251 | { |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
252 | return m_documents; |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
253 | } |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
254 | |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
255 | DocumentManager::Documents::iterator DocumentManager::begin() |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
256 | { |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
257 | return m_documents.begin(); |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
258 | } |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
259 | |
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
260 | bool DocumentManager::isSafeToCloseAll() |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
261 | { |
1428
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
262 | for (const std::unique_ptr<LDDocument>& document : m_documents) |
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
263 | { |
998 | 264 | if (not document->isSafeToClose()) |
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
265 | return false; |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
266 | } |
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 | return true; |
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 | |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
271 | void DocumentManager::loadLogoedStuds() |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
272 | { |
998 | 273 | 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
|
274 | return; |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
275 | |
998 | 276 | m_isLoadingLogoedStuds = true; |
277 | m_logoedStud = openDocument ("stud-logo.dat", true, true); | |
278 | m_logoedStud2 = openDocument ("stud2-logo.dat", true, true); | |
279 | m_isLoadingLogoedStuds = false; | |
280 | ||
281 | if (m_logoedStud and m_logoedStud2) | |
282 | 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
|
283 | } |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
284 | |
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
|
285 | 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
|
286 | { |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
287 | // Possibly substitute with logoed studs: |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
288 | // stud.dat -> stud-logo.dat |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
289 | // stud2.dat -> stud-logo2.dat |
1323
05b3e173c900
Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents:
1318
diff
changeset
|
290 | 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
|
291 | { |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
292 | // 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
|
293 | loadLogoedStuds(); |
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
294 | |
998 | 295 | if (doc->name() == "stud.dat" and m_logoedStud) |
296 | { | |
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
|
297 | m_logoedStud->inlineContents(model, deep, renderinline); |
998 | 298 | return true; |
299 | } | |
300 | else if (doc->name() == "stud2.dat" and m_logoedStud2) | |
301 | { | |
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
|
302 | m_logoedStud2->inlineContents(model, deep, renderinline); |
998 | 303 | return true; |
304 | } | |
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
305 | } |
998 | 306 | return false; |
997
1b49f34e533d
Commit work done on document manager. Happy 3rd birthday LDForge!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
307 | } |
998 | 308 | |
1428
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
309 | LDDocument* DocumentManager::createNew(bool implicit) |
998 | 310 | { |
1428
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
311 | auto pair = m_documents.emplace(std::make_unique<LDDocument>(this)); |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
312 | emit documentCreated(pair.first->get(), implicit); |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
313 | return pair.first->get(); |
998 | 314 | } |
1428
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
315 | |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
316 | DocumentManager::Documents::iterator DocumentManager::end() |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
317 | { |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
318 | return m_documents.end(); |
ece049033adc
fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents:
1379
diff
changeset
|
319 | } |