src/toolsets/filetoolset.cpp

Sun, 01 Apr 2018 11:39:07 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 01 Apr 2018 11:39:07 +0300
changeset 1367
0aab8d972cf6
parent 1326
69a90bd2dba2
child 1428
ece049033adc
permissions
-rw-r--r--

fixed some problems

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 {
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::exit()
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 ::exit(EXIT_SUCCESS);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 void FileToolset::insertFrom()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 {
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
103 QString filePath = QFileDialog::getOpenFileName();
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
104 int position = m_window->suggestInsertPoint();
969
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 if (not filePath.isEmpty())
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
107 {
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
108 QFile file = {filePath};
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
110 if (file.open(QIODevice::ReadOnly))
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
111 {
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
112 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
113 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
114 parser.parseBody(model);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115
1256
3fea6bc1519b removed LDDocument::clearSelection and replaced it with a MainWindow implementation
Santeri Piippo
parents: 1240
diff changeset
116 mainWindow()->clearSelection();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117
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
118 for (LDObject* object : model.objects())
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
119 {
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
120 currentDocument()->insertCopy (position, object);
1257
0d42a1ebd954 more selection rework
Santeri Piippo
parents: 1256
diff changeset
121 mainWindow()->select(currentDocument()->index(position));
0d42a1ebd954 more selection rework
Santeri Piippo
parents: 1256
diff changeset
122 position += 1;
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
123 }
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
125 m_window->refresh();
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
126 }
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
127 else
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
128 {
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
129 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
130 }
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 }
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 void FileToolset::exportTo()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135 {
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 975
diff changeset
136 if (selectedObjects().isEmpty())
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137 return;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
139 QString filePath = QFileDialog::getSaveFileName();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140
1064
4c7a353cf583 Replaced '.length()' with 'length()' where appropriate
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
141 if (filePath.isEmpty())
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142 return;
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143
1064
4c7a353cf583 Replaced '.length()' with 'length()' where appropriate
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
144 QFile file {filePath};
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
146 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
147 {
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
148 for (LDObject* obj : selectedObjects())
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
149 {
1308
dcc8c02530c2 Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
150 file.write(obj->asText().toUtf8());
dcc8c02530c2 Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents: 1288
diff changeset
151 file.write("\r\n");
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
152 }
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153 }
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
154 else
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155 {
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
156 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
157 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
158 }
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 void FileToolset::scanPrimitives()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161 {
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
162 primitives()->startScan();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
163 }
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
164
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165 void FileToolset::openSubfiles()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166 {
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
167 for (LDObject* object : selectedObjects())
969
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 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
170 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
171
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 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
173 m_window->openDocumentForEditing(referenceDocument);
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
174 }
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::downloadFrom()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178 {
1053
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1052
diff changeset
179 PartDownloader* dialog = new PartDownloader {m_window};
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
180 connect(dialog, &PartDownloader::primaryFileDownloaded, [&]()
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
181 {
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
182 m_window->changeDocument (dialog->primaryFile());
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
183 m_window->doFullRefresh();
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
184 m_window->renderer()->resetAngles();
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
185 });
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
186 dialog->exec();
969
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
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189 void FileToolset::makePrimitive()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
190 {
1053
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1052
diff changeset
191 GeneratePrimitiveDialog* dialog = new GeneratePrimitiveDialog {m_window};
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
192
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
193 if (dialog->exec())
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
194 {
1053
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1052
diff changeset
195 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
196 m_window->openDocumentForEditing(primitive);
1052
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
197 m_window->save(primitive, false);
6fd1597b688e Refactor FileToolset
Teemu Piippo <teemu@hecknology.net>
parents: 1051
diff changeset
198 }
969
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
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
201 // 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
202 void FileToolset::help()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
203 {
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
204 // Not yet implemented
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
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
207 void FileToolset::about()
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
208 {
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
209 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
210 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
211 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
212 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
213 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
214 dialog->exec();
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
215 }
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 void FileToolset::aboutQt()
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 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
220 }

mercurial