src/toolsets/filetoolset.cpp

Sun, 29 Jan 2017 15:05:14 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 29 Jan 2017 15:05:14 +0200
changeset 1073
a0a0d581309b
parent 1072
9ce9496427f2
child 1079
67c6e5d32e68
permissions
-rw-r--r--

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.
The LDObject::destroy method is also now gone. The model decides when objects are destroyed and calls the destructor directly. The end result removes a lot of cruft and adds structure to LDObject relations.

Notes:
- Inlining does not currently work (nothing simply gets inlined in)
- More work is required to ensure that each object actually goes into a model

969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
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
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #include <QFileDialog>
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include <QMessageBox>
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include "../dialogs.h"
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include "../glRenderer.h"
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include "../ldDocument.h"
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include "../mainwindow.h"
994
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
25 #include "../partdownloader.h"
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 #include "../primitives.h"
975
24ba5aa3393f Move ConfigDialog into src/dialogs/ subfolder
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
27 #include "../dialogs/configdialog.h"
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 #include "../dialogs/ldrawpathdialog.h"
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 #include "../dialogs/newpartdialog.h"
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
30 #include "../dialogs/generateprimitivedialog.h"
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 994
diff changeset
31 #include "../documentmanager.h"
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 #include "filetoolset.h"
1051
28ab6cad2c32 Moved the about dialog into the file toolset and removed the mail button (the forums are better for this anyway)
Teemu Piippo <teemu@hecknology.net>
parents: 1039
diff changeset
33 #include "ui_about.h"
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
35 FileToolset::FileToolset(MainWindow* parent)
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
36 : Toolset(parent) {}
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 void FileToolset::newPart()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 {
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
40 NewPartDialog* dialog = new NewPartDialog {m_window};
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
42 if (dialog->exec() == QDialog::Accepted)
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 {
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 975
diff changeset
44 m_window->createBlankDocument();
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
45 dialog->fillHeader(currentDocument());
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 m_window->doFullRefresh();
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 void FileToolset::newFile()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 {
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 975
diff changeset
52 m_window->createBlankDocument();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 void FileToolset::open()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 {
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
57 QString name = QFileDialog::getOpenFileName(m_window, "Open File", "", "LDraw files (*.dat *.ldr)");
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
59 if (not name.isEmpty())
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
60 m_documents->openMainModel (name);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 void FileToolset::save()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 {
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
65 m_window->save(currentDocument(), false);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 void FileToolset::saveAs()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 {
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
70 m_window->save(currentDocument(), true);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 void FileToolset::saveAll()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 {
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
75 for (LDDocument* document : m_documents->allDocuments())
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
76 m_window->save(document, false);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 void FileToolset::close()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 {
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
81 if (currentDocument()->isSafeToClose())
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
82 currentDocument()->close();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 void FileToolset::closeAll()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 {
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 994
diff changeset
87 if (m_documents->isSafeToCloseAll())
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 994
diff changeset
88 m_documents->clear();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 void FileToolset::settings()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 {
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
93 (new ConfigDialog {m_window})->exec();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 void FileToolset::setLDrawPath()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 {
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
98 LDrawPathDialog* dialog = new LDrawPathDialog {m_config->lDrawPath(), true};
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
99
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
100 if (dialog->exec())
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: 1014
diff changeset
101 m_config->setLDrawPath (dialog->path());
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 void FileToolset::exit()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 {
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
106 ::exit(EXIT_SUCCESS);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 void FileToolset::insertFrom()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 {
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
111 QString filePath = QFileDialog::getOpenFileName();
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
112 int position = m_window->suggestInsertPoint();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
114 if (not filePath.isEmpty())
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
115 {
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
116 QFile file = {filePath};
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
118 if (file.open(QIODevice::ReadOnly))
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
119 {
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
120 // TODO: shouldn't need to go to the document manager to parse a file
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
121 Model model;
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
122 m_documents->loadFileContents(&file, model, nullptr, nullptr);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
124 currentDocument()->clearSelection();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125
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
126 for (LDObject* object : model.objects())
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
127 {
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
128 currentDocument()->insertObject (position, object);
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
129 currentDocument()->addToSelection(object);
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
130 m_window->renderer()->compileObject (object);
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
131 position++;
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
132 }
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
134 m_window->refresh();
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
135 m_window->scrollToSelection();
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
136 }
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
137 else
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
138 {
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
139 Critical(format("Couldn't open %1 (%2)", filePath, file.errorString()));
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
140 }
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 void FileToolset::exportTo()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145 {
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 975
diff changeset
146 if (selectedObjects().isEmpty())
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147 return;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
149 QString filePath = QFileDialog::getSaveFileName();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150
1064
4c7a353cf583 Replaced '.length()' with 'length()' where appropriate
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
151 if (filePath.isEmpty())
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152 return;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153
1064
4c7a353cf583 Replaced '.length()' with 'length()' where appropriate
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
154 QFile file {filePath};
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
156 if (file.open(QIODevice::WriteOnly | QIODevice::Text))
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157 {
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
158 for (LDObject* obj : selectedObjects())
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
159 {
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
160 QString contents = obj->asText();
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
161 QByteArray data = contents.toUtf8();
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1064
diff changeset
162 file.write(data, countof(data));
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
163 file.write("\r\n", 2);
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
164 }
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165 }
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
166 else
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167 {
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
168 Critical(format("Unable to open %1 for writing (%2)", filePath, file.errorString()));
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
169 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
172 void FileToolset::scanPrimitives()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
173 {
1018
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1017
diff changeset
174 primitives()->startScan();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
175 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
176
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
177 void FileToolset::openSubfiles()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178 {
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
179 for (LDObject* object : selectedObjects())
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 {
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
181 LDSubfileReference* reference = dynamic_cast<LDSubfileReference*>(object);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
183 if (reference and reference->fileInfo()->isCache())
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
184 reference->fileInfo()->openForEditing();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
185 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
187
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
188 void FileToolset::downloadFrom()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189 {
1053
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1052
diff changeset
190 PartDownloader* dialog = new PartDownloader {m_window};
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
191 connect(dialog, &PartDownloader::primaryFileDownloaded, [&]()
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
192 {
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
193 m_window->changeDocument (dialog->primaryFile());
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
194 m_window->doFullRefresh();
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
195 m_window->renderer()->resetAngles();
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
196 });
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
197 dialog->exec();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
198 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
199
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
200 void FileToolset::makePrimitive()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
201 {
1053
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1052
diff changeset
202 GeneratePrimitiveDialog* dialog = new GeneratePrimitiveDialog {m_window};
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
203
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
204 if (dialog->exec())
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
205 {
1053
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1052
diff changeset
206 LDDocument* primitive = primitives()->generatePrimitive(dialog->primitiveModel());
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
207 primitive->openForEditing();
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
208 m_window->save(primitive, false);
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
209 }
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
210 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
211
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
212 // These are not exactly file tools but I don't want to make another toolset just for 3 very small actions
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
213 void FileToolset::help()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
214 {
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
215 // Not yet implemented
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
216 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
217
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
218 void FileToolset::about()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
219 {
1051
28ab6cad2c32 Moved the about dialog into the file toolset and removed the mail button (the forums are better for this anyway)
Teemu Piippo <teemu@hecknology.net>
parents: 1039
diff changeset
220 QDialog *dialog = new QDialog(m_window);
28ab6cad2c32 Moved the about dialog into the file toolset and removed the mail button (the forums are better for this anyway)
Teemu Piippo <teemu@hecknology.net>
parents: 1039
diff changeset
221 Ui::AboutUI ui;
28ab6cad2c32 Moved the about dialog into the file toolset and removed the mail button (the forums are better for this anyway)
Teemu Piippo <teemu@hecknology.net>
parents: 1039
diff changeset
222 ui.setupUi(dialog);
28ab6cad2c32 Moved the about dialog into the file toolset and removed the mail button (the forums are better for this anyway)
Teemu Piippo <teemu@hecknology.net>
parents: 1039
diff changeset
223 ui.versionInfo->setText(APPNAME " " + QString (fullVersionString()));
28ab6cad2c32 Moved the about dialog into the file toolset and removed the mail button (the forums are better for this anyway)
Teemu Piippo <teemu@hecknology.net>
parents: 1039
diff changeset
224 dialog->setWindowTitle(format(tr("About %1"), APPNAME));
28ab6cad2c32 Moved the about dialog into the file toolset and removed the mail button (the forums are better for this anyway)
Teemu Piippo <teemu@hecknology.net>
parents: 1039
diff changeset
225 dialog->exec();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
226 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
227
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
228 void FileToolset::aboutQt()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
229 {
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
230 QMessageBox::aboutQt (m_window);
1051
28ab6cad2c32 Moved the about dialog into the file toolset and removed the mail button (the forums are better for this anyway)
Teemu Piippo <teemu@hecknology.net>
parents: 1039
diff changeset
231 }

mercurial