src/toolsets/filetoolset.cpp

Wed, 26 Dec 2018 16:38:38 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 26 Dec 2018 16:38:38 +0200
changeset 1432
4cc687851fbb
parent 1428
ece049033adc
permissions
-rw-r--r--

Refactored the color toolbar editing into a new model/view system

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
1326
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1308
diff changeset
3 * Copyright (C) 2013 - 2018 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>
1103
ac7db4c076c3 Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents: 1090
diff changeset
21 #include "../canvas.h"
1145
02264bf0108d Renamed ldDocument.cpp → lddocument.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1116
diff changeset
22 #include "../lddocument.h"
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include "../mainwindow.h"
994
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
24 #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: 1269
diff changeset
25 #include "../parser.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"
1164
eabcd749759a Moved all UI files from ui/ into src/dialogs/.
Teemu Piippo <teemu@hecknology.net>
parents: 1156
diff changeset
33 #include "ui_aboutdialog.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 {
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: 1326
diff changeset
75 for (auto& document : *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: 1326
diff changeset
76 m_window->save(document.get(), 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 {
1432
4cc687851fbb Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
93 ConfigDialog dialog {m_window};
4cc687851fbb Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
94 connect(&dialog, &ConfigDialog::settingsChanged, m_window, &MainWindow::settingsChanged);
4cc687851fbb Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
95 dialog.exec();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 void FileToolset::exit()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 {
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
100 ::exit(EXIT_SUCCESS);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 }
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 void FileToolset::insertFrom()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 {
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
105 QString filePath = QFileDialog::getOpenFileName();
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
106 int position = m_window->suggestInsertPoint();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
108 if (not filePath.isEmpty())
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
109 {
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
110 QFile file = {filePath};
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
112 if (file.open(QIODevice::ReadOnly))
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
113 {
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
114 Model model {m_documents};
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: 1269
diff changeset
115 Parser parser {file};
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: 1269
diff changeset
116 parser.parseBody(model);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117
1256
3fea6bc1519b removed LDDocument::clearSelection and replaced it with a MainWindow implementation
Santeri Piippo
parents: 1240
diff changeset
118 mainWindow()->clearSelection();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119
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
120 for (LDObject* object : model.objects())
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
121 {
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1263
diff changeset
122 currentDocument()->insertCopy (position, object);
1257
0d42a1ebd954 more selection rework
Santeri Piippo
parents: 1256
diff changeset
123 mainWindow()->select(currentDocument()->index(position));
0d42a1ebd954 more selection rework
Santeri Piippo
parents: 1256
diff changeset
124 position += 1;
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
125 }
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
127 m_window->refresh();
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
128 }
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
129 else
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
130 {
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
131 QMessageBox::critical(m_window, tr("Error"), format(tr("Couldn't open %1 (%2)"), filePath, file.errorString()));
1052
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 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
136 void FileToolset::exportTo()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137 {
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 975
diff changeset
138 if (selectedObjects().isEmpty())
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 return;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
141 QString filePath = QFileDialog::getSaveFileName();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142
1064
4c7a353cf583 Replaced '.length()' with 'length()' where appropriate
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
143 if (filePath.isEmpty())
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 return;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145
1064
4c7a353cf583 Replaced '.length()' with 'length()' where appropriate
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
146 QFile file {filePath};
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
148 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
149 {
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
150 for (LDObject* obj : selectedObjects())
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
151 {
1308
dcc8c02530c2 Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
152 file.write(obj->asText().toUtf8());
dcc8c02530c2 Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
153 file.write("\r\n");
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
154 }
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 else
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157 {
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
158 QMessageBox::critical(m_window, tr("Error"), format(tr("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
159 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162 void FileToolset::scanPrimitives()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
163 {
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
164 primitives()->startScan();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167 void FileToolset::openSubfiles()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 {
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
169 for (LDObject* object : selectedObjects())
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170 {
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
171 LDSubfileReference* reference = dynamic_cast<LDSubfileReference*>(object);
1263
0256edecda54 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.
Santeri Piippo
parents: 1257
diff changeset
172 LDDocument* referenceDocument = reference ? reference->fileInfo(m_documents) : nullptr;
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
173
1263
0256edecda54 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.
Santeri Piippo
parents: 1257
diff changeset
174 if (referenceDocument and referenceDocument->isFrozen())
0256edecda54 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.
Santeri Piippo
parents: 1257
diff changeset
175 m_window->openDocumentForEditing(referenceDocument);
969
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 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179 void FileToolset::downloadFrom()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 {
1053
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1052
diff changeset
181 PartDownloader* dialog = new PartDownloader {m_window};
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
182 connect(dialog, &PartDownloader::primaryFileDownloaded, [&]()
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
183 {
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
184 m_window->changeDocument (dialog->primaryFile());
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
185 m_window->doFullRefresh();
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
186 m_window->renderer()->resetAngles();
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
187 });
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
188 dialog->exec();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
190
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191 void FileToolset::makePrimitive()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
192 {
1053
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1052
diff changeset
193 GeneratePrimitiveDialog* dialog = new GeneratePrimitiveDialog {m_window};
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
194
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
195 if (dialog->exec())
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
196 {
1053
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1052
diff changeset
197 LDDocument* primitive = primitives()->generatePrimitive(dialog->primitiveModel());
1090
ed73c4f48ca4 The current document pointer may no longer be null.
Teemu Piippo <teemu@hecknology.net>
parents: 1079
diff changeset
198 m_window->openDocumentForEditing(primitive);
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
199 m_window->save(primitive, false);
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
200 }
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
201 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
202
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
203 // 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
204 void FileToolset::help()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
205 {
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
206 // Not yet implemented
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
207 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
208
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
209 void FileToolset::about()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
210 {
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
211 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
212 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
213 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
214 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
215 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
216 dialog->exec();
969
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
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
219 void FileToolset::aboutQt()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
220 {
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
221 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
222 }

mercurial