Sun, 29 Jan 2017 21:02:11 +0200
More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
1006
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1000
diff
changeset
|
1 | /* |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1000
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
1072 | 3 | * Copyright (C) 2013 - 2017 Teemu Piippo |
1006
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1000
diff
changeset
|
4 | * |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1000
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1000
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1000
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1000
diff
changeset
|
8 | * (at your option) any later version. |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1000
diff
changeset
|
9 | * |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1000
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1000
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1000
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1000
diff
changeset
|
13 | * GNU General Public License for more details. |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1000
diff
changeset
|
14 | * |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1000
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1000
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1000
diff
changeset
|
17 | */ |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1000
diff
changeset
|
18 | |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | #include <QDir> |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | #include "ldpaths.h" |
970
c8aae45afd85
Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
953
diff
changeset
|
21 | #include "mainwindow.h" |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | #include "dialogs/ldrawpathdialog.h" |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | |
970
c8aae45afd85
Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
953
diff
changeset
|
24 | ConfigOption (QString LDrawPath) |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | |
1028
5877e49e9a28
Moved PreferredLicenseText into HierarchyElement and made the config pointer be passed to LDPaths. Now I can finally remove the Config global pointer.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
26 | LDPaths::LDPaths (Configuration *config, QObject* parent) : |
5877e49e9a28
Moved PreferredLicenseText into HierarchyElement and made the config pointer be passed to LDPaths. Now I can finally remove the Config global pointer.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
27 | QObject(parent), |
5877e49e9a28
Moved PreferredLicenseText into HierarchyElement and made the config pointer be passed to LDPaths. Now I can finally remove the Config global pointer.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
28 | m_config(config), |
5877e49e9a28
Moved PreferredLicenseText into HierarchyElement and made the config pointer be passed to LDPaths. Now I can finally remove the Config global pointer.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
29 | m_dialog(nullptr) {} |
5877e49e9a28
Moved PreferredLicenseText into HierarchyElement and made the config pointer be passed to LDPaths. Now I can finally remove the Config global pointer.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
30 | |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | void LDPaths::checkPaths() |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | { |
1028
5877e49e9a28
Moved PreferredLicenseText into HierarchyElement and made the config pointer be passed to LDPaths. Now I can finally remove the Config global pointer.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
34 | QString pathconfig = m_config->lDrawPath(); |
970
c8aae45afd85
Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
953
diff
changeset
|
35 | |
c8aae45afd85
Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
953
diff
changeset
|
36 | if (not configurePaths (pathconfig)) |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | { |
970
c8aae45afd85
Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
953
diff
changeset
|
38 | m_dialog = new LDrawPathDialog (pathconfig, false); |
1028
5877e49e9a28
Moved PreferredLicenseText into HierarchyElement and made the config pointer be passed to LDPaths. Now I can finally remove the Config global pointer.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
39 | connect(m_dialog, &LDrawPathDialog::pathChanged, this, &LDPaths::configurePaths); |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | |
1028
5877e49e9a28
Moved PreferredLicenseText into HierarchyElement and made the config pointer be passed to LDPaths. Now I can finally remove the Config global pointer.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
41 | if (m_dialog->exec() != QDialog::Accepted) |
5877e49e9a28
Moved PreferredLicenseText into HierarchyElement and made the config pointer be passed to LDPaths. Now I can finally remove the Config global pointer.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
42 | exit(1); |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | else |
1028
5877e49e9a28
Moved PreferredLicenseText into HierarchyElement and made the config pointer be passed to LDPaths. Now I can finally remove the Config global pointer.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
44 | m_config->setLDrawPath(m_dialog->path()); |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | } |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | } |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | |
1028
5877e49e9a28
Moved PreferredLicenseText into HierarchyElement and made the config pointer be passed to LDPaths. Now I can finally remove the Config global pointer.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
48 | |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | bool LDPaths::isValid (const QDir& dir) const |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | { |
999
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
51 | if (dir.exists()) |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | { |
999
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
53 | if (dir.isReadable()) |
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
54 | { |
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
55 | QStringList mustHave = { "LDConfig.ldr", "parts", "p" }; |
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
56 | QStringList contents = dir.entryList (mustHave); |
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
57 | |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1063
diff
changeset
|
58 | if (countof(contents) == countof(mustHave)) |
999
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
59 | m_error = ""; |
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
60 | else |
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
61 | m_error = "That is not an LDraw directory! It must<br />have LDConfig.ldr, parts/ and p/."; |
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
62 | } |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | else |
999
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
64 | m_error = "That directory cannot be read."; |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | } |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | else |
999
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
67 | m_error = "That directory does not exist."; |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | return m_error.isEmpty(); |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | } |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | |
1028
5877e49e9a28
Moved PreferredLicenseText into HierarchyElement and made the config pointer be passed to LDPaths. Now I can finally remove the Config global pointer.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
72 | |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | bool LDPaths::configurePaths (QString path) |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | { |
999
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
75 | QDir dir (path); |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | bool ok = isValid (dir); |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | if (ok) |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | { |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | baseDir() = dir; |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | ldConfigPath() = format ("%1" DIRSLASH "LDConfig.ldr", path); |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | partsDir() = QDir (path + DIRSLASH "parts"); |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | primitivesDir() = QDir (path + DIRSLASH "p"); |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | } |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | if (m_dialog) |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | m_dialog->setStatusText (m_error.isEmpty() ? "OK" : m_error, ok); |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | return ok; |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | } |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | |
1028
5877e49e9a28
Moved PreferredLicenseText into HierarchyElement and made the config pointer be passed to LDPaths. Now I can finally remove the Config global pointer.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
92 | |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | QString& LDPaths::ldConfigPath() |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | { |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | static QString value; |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | return value; |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | } |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | |
1028
5877e49e9a28
Moved PreferredLicenseText into HierarchyElement and made the config pointer be passed to LDPaths. Now I can finally remove the Config global pointer.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
99 | |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | QDir& LDPaths::primitivesDir() |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | { |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | static QDir value; |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | return value; |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | } |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | |
1028
5877e49e9a28
Moved PreferredLicenseText into HierarchyElement and made the config pointer be passed to LDPaths. Now I can finally remove the Config global pointer.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
106 | |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | QDir& LDPaths::partsDir() |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | { |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | static QDir value; |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | return value; |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | } |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | |
1028
5877e49e9a28
Moved PreferredLicenseText into HierarchyElement and made the config pointer be passed to LDPaths. Now I can finally remove the Config global pointer.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
113 | |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | QDir& LDPaths::baseDir() |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | { |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | static QDir value; |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | return value; |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | } |