Wed, 14 Mar 2018 12:18:52 +0200
moved emit calls
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
1072 | 3 | * Copyright (C) 2013 - 2017 Teemu Piippo |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | * |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | * |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | * |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
1039 | 19 | #include <QApplication> |
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:
1149
diff
changeset
|
20 | #include <QMessageBox> |
1145
02264bf0108d
Renamed ldDocument.cpp → lddocument.cpp
Teemu Piippo <teemu@hecknology.net>
parents:
1141
diff
changeset
|
21 | #include "lddocument.h" |
962
a4b463a7ee82
Rename MainWindow files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
958
diff
changeset
|
22 | #include "mainwindow.h" |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | #include "primitives.h" |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | #include "miscallenous.h" |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | #include "colors.h" |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
952
diff
changeset
|
26 | #include "ldpaths.h" |
998 | 27 | #include "documentmanager.h" |
1117
efcb47c64a72
Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents:
1090
diff
changeset
|
28 | #include "linetypes/comment.h" |
1141
7dc2c981937e
Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
1139
diff
changeset
|
29 | #include "linetypes/conditionaledge.h" |
7dc2c981937e
Split LDConditionalEdge and LDEdgeLine into new source pairs
Teemu Piippo <teemu@hecknology.net>
parents:
1139
diff
changeset
|
30 | #include "linetypes/edgeline.h" |
1117
efcb47c64a72
Moved LDComment and LDEmpty into their own source file pairs.
Teemu Piippo <teemu@hecknology.net>
parents:
1090
diff
changeset
|
31 | #include "linetypes/empty.h" |
1149
502c866b8512
Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
1148
diff
changeset
|
32 | #include "linetypes/quadrilateral.h" |
1148
96cb15a7611f
Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
1145
diff
changeset
|
33 | #include "linetypes/triangle.h" |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
34 | |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
35 | PrimitiveManager::PrimitiveManager(QObject* parent) : |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
36 | QAbstractItemModel {parent}, |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
37 | HierarchyElement {parent}, |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
38 | m_activeScanner {nullptr}, |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
39 | m_unmatched {nullptr} {} |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
40 | |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
41 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
42 | PrimitiveScanner* PrimitiveManager::activeScanner() |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | { |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
44 | return m_activeScanner; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
47 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
48 | QString PrimitiveManager::getPrimitivesCfgPath() const |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
970
diff
changeset
|
49 | { |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
970
diff
changeset
|
50 | return qApp->applicationDirPath() + DIRSLASH "prims.cfg"; |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
970
diff
changeset
|
51 | } |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
970
diff
changeset
|
52 | |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
53 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
54 | void PrimitiveManager::loadPrimitives() |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | // Try to load prims.cfg |
1054 | 57 | QFile primitivesFile = {getPrimitivesCfgPath()}; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | |
1054 | 59 | if (not primitivesFile.open (QIODevice::ReadOnly)) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | // No prims.cfg, build it |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
62 | startScan(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | else |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | { |
1054 | 66 | while (not primitivesFile.atEnd()) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | { |
1054 | 68 | QString line = primitivesFile.readLine().simplified(); |
69 | int space = line.indexOf(" "); | |
790
fe1b83f6ba82
- added primitives toolbox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
784
diff
changeset
|
70 | |
1054 | 71 | if (space != -1) |
72 | { | |
73 | Primitive info; | |
74 | info.name = line.left(space); | |
75 | info.title = line.mid(space + 1); | |
76 | m_primitives.append(info); | |
77 | } | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
80 | populateCategories(); |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
81 | print(tr("%1 primitives loaded.") + "\n", countof(m_primitives)); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
85 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
86 | void PrimitiveManager::startScan() |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | { |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
88 | if (m_activeScanner == nullptr) |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
89 | { |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
90 | loadCategories(); |
1054 | 91 | m_activeScanner = new PrimitiveScanner {this}; |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
92 | m_activeScanner->work(); |
1054 | 93 | connect(m_activeScanner, &PrimitiveScanner::workDone, this, [&]() |
94 | { | |
95 | if (m_activeScanner) | |
96 | { | |
1284 | 97 | emit layoutAboutToBeChanged(); |
1054 | 98 | m_primitives = m_activeScanner->scannedPrimitives(); |
99 | populateCategories(); | |
1284 | 100 | emit layoutChanged(); |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
101 | print(tr("%1 primitives scanned"), countof(m_primitives)); |
1054 | 102 | delete m_activeScanner; |
103 | m_activeScanner = nullptr; | |
104 | } | |
105 | }); | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
106 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
110 | void PrimitiveManager::clearCategories() |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
111 | { |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
112 | for (PrimitiveCategory* category : m_categories) |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
113 | delete category; |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
114 | |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
115 | m_categories.clear(); |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
116 | } |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
117 | |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
118 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
119 | void PrimitiveManager::populateCategories() |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | { |
791
b1eae3a56eda
- sort primitive categories alphabetically
Santeri Piippo <crimsondusk64@gmail.com>
parents:
790
diff
changeset
|
121 | loadCategories(); |
b1eae3a56eda
- sort primitive categories alphabetically
Santeri Piippo <crimsondusk64@gmail.com>
parents:
790
diff
changeset
|
122 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
123 | for (PrimitiveCategory* category : m_categories) |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
124 | category->primitives.clear(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
126 | for (Primitive& primitive : m_primitives) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
128 | bool matched = false; |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
129 | primitive.category = nullptr; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | // Go over the categories and their regexes, if and when there's a match, |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | // the primitive's category is set to the category the regex beloings to. |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
133 | for (PrimitiveCategory* category : m_categories) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | { |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
135 | for (PrimitiveCategory::RegexEntry& entry : category->patterns) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
136 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
137 | switch (entry.type) |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | { |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
139 | case PrimitiveCategory::FilenamePattern: |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
140 | // f-regex, check against filename |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
141 | matched = entry.regex.exactMatch (primitive.name); |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
142 | break; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
143 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
144 | case PrimitiveCategory::TitlePattern: |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
145 | // t-regex, check against title |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
146 | matched = entry.regex.exactMatch (primitive.title); |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
147 | break; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
148 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
150 | if (matched) |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
151 | { |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
152 | primitive.category = category; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
153 | break; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
154 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
155 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
156 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
157 | // Drop off if a category was decided on. |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
158 | if (primitive.category) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
159 | break; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
160 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
161 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
162 | // If there was a match, add the primitive to the category. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
163 | // Otherwise, add it to the list of unmatched primitives. |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
164 | if (primitive.category) |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
165 | primitive.category->primitives << primitive; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
166 | else |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
167 | m_unmatched->primitives << primitive; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
168 | } |
791
b1eae3a56eda
- sort primitive categories alphabetically
Santeri Piippo <crimsondusk64@gmail.com>
parents:
790
diff
changeset
|
169 | |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
170 | // Sort the categories. Note that we only do this here because we needed the original order for pattern matching. |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
171 | qSort (m_categories.begin(), m_categories.end(), |
1054 | 172 | [](PrimitiveCategory* const& one, PrimitiveCategory* const& other) -> bool |
791
b1eae3a56eda
- sort primitive categories alphabetically
Santeri Piippo <crimsondusk64@gmail.com>
parents:
790
diff
changeset
|
173 | { |
1054 | 174 | return one->name() < other->name(); |
791
b1eae3a56eda
- sort primitive categories alphabetically
Santeri Piippo <crimsondusk64@gmail.com>
parents:
790
diff
changeset
|
175 | }); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
176 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
177 | |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
178 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
179 | void PrimitiveManager::loadCategories() |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
180 | { |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
181 | clearCategories(); |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
970
diff
changeset
|
182 | QString path = ":/data/primitive-categories.cfg"; |
1054 | 183 | QFile categoriesFile = {path}; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
184 | |
1054 | 185 | if (not categoriesFile.open (QIODevice::ReadOnly)) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
186 | { |
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:
1149
diff
changeset
|
187 | QString message = format(tr("Failed to open primitive categories: %1"), categoriesFile.errorString()); |
c20ee66b6705
Removed the Critical and Question functions, replaced with direct QMessageBox uses. Removed unused code from mainwindow.h.
Teemu Piippo <teemu@hecknology.net>
parents:
1149
diff
changeset
|
188 | QMessageBox::critical(m_window, tr("Cannot open categories"), message); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
189 | return; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
190 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
191 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
192 | PrimitiveCategory* category = nullptr; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
193 | |
1054 | 194 | while (not categoriesFile.atEnd()) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
195 | { |
1054 | 196 | QString line = QString::fromUtf8(categoriesFile.readLine()).trimmed(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
197 | |
1064
4c7a353cf583
Replaced '.length()' with 'length()' where appropriate
Teemu Piippo <teemu@hecknology.net>
parents:
1063
diff
changeset
|
198 | if (line.isEmpty() or line[0] == '#') |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
199 | continue; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
200 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
201 | int colon = line.indexOf (":"); |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
202 | if (colon == -1) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
203 | { |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
204 | if (category and category->isValidToInclude()) |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
205 | { |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
206 | m_categories << category; |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
207 | } |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
208 | else if (category) |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
209 | { |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
210 | print (tr ("Warning: Category \"%1\" left without patterns"), category->name()); |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
211 | delete category; |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
212 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
213 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
214 | category = new PrimitiveCategory (line); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
215 | } |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
216 | else if (category) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
217 | { |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
218 | QString typechar = line.left (colon); |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
219 | PrimitiveCategory::PatternType type = PrimitiveCategory::FilenamePattern; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
220 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
221 | if (typechar == "f") |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
222 | { |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
223 | type = PrimitiveCategory::FilenamePattern; |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
224 | } |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
225 | else if (typechar == "t") |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
226 | { |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
227 | type = PrimitiveCategory::TitlePattern; |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
228 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
229 | else |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
230 | { |
1054 | 231 | print(tr("Warning: unknown pattern type \"%1\" on line \"%2\""), typechar, line); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
232 | continue; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
233 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
234 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
235 | QRegExp regex (line.mid (colon + 1)); |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
236 | PrimitiveCategory::RegexEntry entry = { regex, type }; |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
237 | category->patterns << entry; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
238 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
239 | else |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
240 | { |
1054 | 241 | print("Warning: Rules given before the first category name"); |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
242 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
243 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
244 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
245 | if (category->isValidToInclude()) |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
246 | m_categories << category; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
247 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
248 | // Add a category for unmatched primitives. |
1054 | 249 | // Note: if this function is called the second time, m_unmatched has been |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
250 | // deleted at the beginning of the function and is dangling at this point. |
1054 | 251 | m_unmatched = new PrimitiveCategory {tr("Other")}; |
252 | m_categories.append(m_unmatched); | |
253 | categoriesFile.close(); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
254 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
255 | |
1080
6dac2d52bd9a
Removed the LDSpawn function and replaced its last use cases.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
256 | void PrimitiveModel::generateBody(Model& model) const |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
257 | { |
1053 | 258 | QVector<int> conditionalLineSegments; |
259 | QVector<QLineF> circle = makeCircle(segments, divisions, 1); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
260 | |
1053 | 261 | for (int i = 0; i < segments; ++i) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
262 | { |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
263 | double x0 = circle[i].x1(); |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
264 | double x1 = circle[i].x2(); |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
265 | double z0 = circle[i].y1(); |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
266 | double z1 = circle[i].y2(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
267 | |
1053 | 268 | switch (type) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
269 | { |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
270 | case Circle: |
1080
6dac2d52bd9a
Removed the LDSpawn function and replaced its last use cases.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
271 | { |
1139
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1117
diff
changeset
|
272 | LDEdgeLine* line = model.emplace<LDEdgeLine>(); |
1053 | 273 | line->setVertex(0, Vertex {x0, 0.0f, z0}); |
274 | line->setVertex(1, Vertex {x1, 0.0f, z1}); | |
275 | line->setColor(EdgeColor); | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
276 | } |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
277 | break; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
278 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
279 | case Cylinder: |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
280 | case Ring: |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
281 | case Cone: |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
282 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
283 | double x2, x3, z2, z3; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
284 | double y0, y1, y2, y3; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
285 | |
1053 | 286 | if (type == Cylinder) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
287 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
288 | x2 = x1; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
289 | x3 = x0; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
290 | z2 = z1; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
291 | z3 = z0; |
1054 | 292 | y0 = y1 = 0.0; |
293 | y2 = y3 = 1.0; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
294 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
295 | else |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
296 | { |
1053 | 297 | x2 = x1 * (ringNumber + 1); |
298 | x3 = x0 * (ringNumber + 1); | |
299 | z2 = z1 * (ringNumber + 1); | |
300 | z3 = z0 * (ringNumber + 1); | |
301 | x0 *= ringNumber; | |
302 | x1 *= ringNumber; | |
303 | z0 *= ringNumber; | |
304 | z1 *= ringNumber; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
305 | |
1053 | 306 | if (type == Ring) |
1054 | 307 | { |
308 | y0 = y1 = y2 = y3 = 0.0; | |
309 | } | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
310 | else |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
311 | { |
1054 | 312 | y0 = y1 = 1.0; |
313 | y2 = y3 = 0.0; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
314 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
315 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
316 | |
1053 | 317 | Vertex v0 = {x0, y0, z0}; |
318 | Vertex v1 = {x1, y1, z1}; | |
319 | Vertex v2 = {x2, y2, z2}; | |
320 | Vertex v3 = {x3, y3, z3}; | |
1261
5d2c9d36da9d
Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents:
1156
diff
changeset
|
321 | |
5d2c9d36da9d
Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents:
1156
diff
changeset
|
322 | if (type == Cylinder) |
5d2c9d36da9d
Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents:
1156
diff
changeset
|
323 | qSwap(v1, v3); |
5d2c9d36da9d
Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents:
1156
diff
changeset
|
324 | |
1139
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1117
diff
changeset
|
325 | LDQuadrilateral* quad = model.emplace<LDQuadrilateral>(v0, v1, v2, v3); |
1054 | 326 | quad->setColor(MainColor); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
327 | |
1053 | 328 | if (type == Cylinder or type == Cone) |
329 | conditionalLineSegments.append(i); | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
330 | } |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
331 | break; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
332 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
333 | case Disc: |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
334 | case DiscNegative: |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
335 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
336 | double x2, z2; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
337 | |
1053 | 338 | if (type == Disc) |
339 | { | |
340 | x2 = z2 = 0.0; | |
341 | } | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
342 | else |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
343 | { |
1053 | 344 | x2 = (x0 >= 0.0) ? 1.0 : -1.0; |
345 | z2 = (z0 >= 0.0) ? 1.0 : -1.0; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
346 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
347 | |
1053 | 348 | Vertex v0 = {x0, 0.0, z0}; |
349 | Vertex v1 = {x1, 0.0, z1}; | |
350 | Vertex v2 = {x2, 0.0, z2}; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
351 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
352 | // Disc negatives need to go the other way around, otherwise |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
353 | // they'll end up upside-down. |
1080
6dac2d52bd9a
Removed the LDSpawn function and replaced its last use cases.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
354 | LDTriangle* segment = model.emplace<LDTriangle>(); |
1053 | 355 | segment->setColor(MainColor); |
356 | segment->setVertex(type == Disc ? 0 : 2, v0); | |
357 | segment->setVertex(1, v1); | |
358 | segment->setVertex(type == Disc ? 2 : 0, v2); | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
359 | } |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
360 | break; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
361 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
362 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
363 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
364 | // If this is not a full circle, we need a conditional line at the other |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
365 | // end, too. |
1053 | 366 | if (segments < divisions and not conditionalLineSegments.isEmpty()) |
367 | conditionalLineSegments << segments; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
368 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
369 | for (int i : conditionalLineSegments) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
370 | { |
1053 | 371 | Vertex v0 = {getRadialPoint(i, divisions, cos), 0.0f, getRadialPoint(i, divisions, sin)}; |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
372 | Vertex v1; |
1053 | 373 | Vertex v2 = {getRadialPoint(i + 1, divisions, cos), 0.0f, getRadialPoint(i + 1, divisions, sin)}; |
374 | Vertex v3 = {getRadialPoint(i - 1, divisions, cos), 0.0f, getRadialPoint(i - 1, divisions, sin)}; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
375 | |
1053 | 376 | if (type == Cylinder) |
768
29e6c5552388
- initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
757
diff
changeset
|
377 | { |
1053 | 378 | v1 = {v0[X], 1.0f, v0[Z]}; |
768
29e6c5552388
- initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
757
diff
changeset
|
379 | } |
1053 | 380 | else if (type == Cone) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
381 | { |
1053 | 382 | v1 = {v0[X] * (ringNumber + 1), 0.0, v0[Z] * (ringNumber + 1)}; |
383 | v0 = {v0[X] * ringNumber, 1.0, v0[Z] * ringNumber}; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
384 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
385 | |
1139
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1117
diff
changeset
|
386 | LDConditionalEdge* line = model.emplace<LDConditionalEdge>(); |
1053 | 387 | line->setColor(EdgeColor); |
388 | line->setVertex(0, v0); | |
389 | line->setVertex(1, v1); | |
390 | line->setVertex(2, v2); | |
391 | line->setVertex(3, v3); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
392 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
393 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
394 | |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
395 | |
1053 | 396 | QString PrimitiveModel::typeName() const |
397 | { | |
398 | return typeName(type); | |
399 | } | |
400 | ||
401 | ||
402 | QString PrimitiveModel::typeName(PrimitiveModel::Type type) | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
403 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
404 | // Not translated as primitives are in English. |
1053 | 405 | const char* names[] = {"Circle", "Cylinder", "Disc", "Disc Negative", "Ring", "Cone"}; |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
406 | |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
407 | if (type >= 0 and type < countof(names)) |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
408 | return names[type]; |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
409 | else |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
410 | return "Unknown"; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
411 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
412 | |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
413 | |
1053 | 414 | QString PrimitiveModel::makeFileName() const |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
415 | { |
1053 | 416 | int numerator = segments; |
417 | int denominator = divisions; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
418 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
419 | // Simplify the fractional part, but the denominator must be at least 4. |
1053 | 420 | simplify(numerator, denominator); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
421 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
422 | if (denominator < 4) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
423 | { |
1053 | 424 | int factor = 4 / denominator; |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
425 | numerator *= factor; |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
426 | denominator *= factor; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
427 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
428 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
429 | // Compose some general information: prefix, fraction, root, ring number |
1053 | 430 | QString prefix = (divisions == LowResolution) ? "" : format ("%1/", divisions); |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
431 | QString frac = format ("%1-%2", numerator, denominator); |
1053 | 432 | static const char* roots[] = {"edge", "cyli", "disc", "ndis", "ring", "con"}; |
433 | QString root = roots[type]; | |
434 | QString numberString = (type == Ring or type == Cone) ? format ("%1", ringNumber) : ""; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
435 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
436 | // Truncate the root if necessary (7-16rin4.dat for instance). |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
437 | // However, always keep the root at least 2 characters. |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
438 | int extra = (countof(frac) + countof(numberString) + countof(root)) - 8; |
1053 | 439 | root.chop(qBound(0, extra, 2)); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
440 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
441 | // Stick them all together and return the result. |
1053 | 442 | return prefix + frac + root + numberString + ".dat"; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
443 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
444 | |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
445 | |
1053 | 446 | LDDocument* PrimitiveManager::generatePrimitive(const PrimitiveModel& spec) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
447 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
448 | // Make the description |
1019
a2e4286adb0d
Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1018
diff
changeset
|
449 | QString fraction = QString::number ((float) spec.segments / spec.divisions); |
1053 | 450 | QString fileName = spec.makeFileName(); |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
451 | QString description; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
452 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
453 | // Ensure that there's decimals, even if they're 0. |
1054 | 454 | if (fraction.indexOf(".") == -1) |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
455 | fraction += ".0"; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
456 | |
1053 | 457 | if (spec.type == PrimitiveModel::Ring or spec.type == PrimitiveModel::Cone) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
458 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
459 | QString spacing = |
1019
a2e4286adb0d
Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1018
diff
changeset
|
460 | (spec.ringNumber < 10) ? " " : |
a2e4286adb0d
Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1018
diff
changeset
|
461 | (spec.ringNumber < 100) ? " " : ""; |
1054 | 462 | description = format("%1 %2%3 x %4", PrimitiveModel::typeName(spec.type), spacing, spec.ringNumber, fraction); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
463 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
464 | else |
1054 | 465 | description = format("%1 %2", PrimitiveModel::typeName(spec.type), fraction); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
466 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
467 | // Prepend "Hi-Res" if 48/ primitive. |
1019
a2e4286adb0d
Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1018
diff
changeset
|
468 | if (spec.divisions == HighResolution) |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
469 | description.insert (0, "Hi-Res "); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
470 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
471 | LDDocument* document = m_window->newDocument(); |
1053 | 472 | document->setDefaultName(fileName); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
473 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
474 | QString author = APPNAME; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
475 | QString license = ""; |
1019
a2e4286adb0d
Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1018
diff
changeset
|
476 | bool hires = (spec.divisions == HighResolution); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
477 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
478 | if (not m_config->defaultName().isEmpty()) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
479 | { |
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:
1026
diff
changeset
|
480 | license = preferredLicenseText(); |
1054 | 481 | author = format("%1 [%2]", m_config->defaultName(), m_config->defaultUser()); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
482 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
483 | |
1090
ed73c4f48ca4
The current document pointer may no longer be null.
Teemu Piippo <teemu@hecknology.net>
parents:
1086
diff
changeset
|
484 | document->setFrozen(false); |
1053 | 485 | document->history()->setIgnoring(false); |
1080
6dac2d52bd9a
Removed the LDSpawn function and replaced its last use cases.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
486 | document->emplace<LDComment>(description); |
6dac2d52bd9a
Removed the LDSpawn function and replaced its last use cases.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
487 | document->emplace<LDComment>(format("Name: %1", fileName)); |
6dac2d52bd9a
Removed the LDSpawn function and replaced its last use cases.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
488 | document->emplace<LDComment>(format("Author: %1", author)); |
6dac2d52bd9a
Removed the LDSpawn function and replaced its last use cases.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
489 | document->emplace<LDComment>(format("!LDRAW_ORG Unofficial_%1Primitive", hires ? "48_" : "")); |
6dac2d52bd9a
Removed the LDSpawn function and replaced its last use cases.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
490 | document->emplace<LDComment>(license); |
6dac2d52bd9a
Removed the LDSpawn function and replaced its last use cases.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
491 | document->emplace<LDEmpty>(); |
6dac2d52bd9a
Removed the LDSpawn function and replaced its last use cases.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
492 | document->emplace<LDBfc>(BfcStatement::CertifyCCW); |
6dac2d52bd9a
Removed the LDSpawn function and replaced its last use cases.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
493 | document->emplace<LDEmpty>(); |
6dac2d52bd9a
Removed the LDSpawn function and replaced its last use cases.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
494 | spec.generateBody(*document); |
978
4603d8fd063e
Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents:
971
diff
changeset
|
495 | document->addHistoryStep(); |
4603d8fd063e
Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents:
971
diff
changeset
|
496 | return document; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
497 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
498 | |
1053 | 499 | /* |
500 | * PrimitiveManager :: getPrimitive | |
501 | * | |
502 | * Gets a primitive by the given model. If the primitive cannot be found, it will be automatically generated. | |
503 | */ | |
504 | LDDocument* PrimitiveManager::getPrimitive(const PrimitiveModel& model) | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
505 | { |
1053 | 506 | QString name = model.makeFileName(); |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
507 | LDDocument* document = m_window->documents()->getDocumentByName (name); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
508 | |
1090
ed73c4f48ca4
The current document pointer may no longer be null.
Teemu Piippo <teemu@hecknology.net>
parents:
1086
diff
changeset
|
509 | if (not document) |
ed73c4f48ca4
The current document pointer may no longer be null.
Teemu Piippo <teemu@hecknology.net>
parents:
1086
diff
changeset
|
510 | { |
ed73c4f48ca4
The current document pointer may no longer be null.
Teemu Piippo <teemu@hecknology.net>
parents:
1086
diff
changeset
|
511 | document = generatePrimitive(model); |
ed73c4f48ca4
The current document pointer may no longer be null.
Teemu Piippo <teemu@hecknology.net>
parents:
1086
diff
changeset
|
512 | m_window->openDocumentForEditing(document); |
ed73c4f48ca4
The current document pointer may no longer be null.
Teemu Piippo <teemu@hecknology.net>
parents:
1086
diff
changeset
|
513 | } |
ed73c4f48ca4
The current document pointer may no longer be null.
Teemu Piippo <teemu@hecknology.net>
parents:
1086
diff
changeset
|
514 | |
ed73c4f48ca4
The current document pointer may no longer be null.
Teemu Piippo <teemu@hecknology.net>
parents:
1086
diff
changeset
|
515 | return document; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
516 | } |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
517 | |
1053 | 518 | /* |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
519 | * Returns the amount of columns in the primitives tree (1) |
1053 | 520 | */ |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
521 | int PrimitiveManager::columnCount(const QModelIndex&) const |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
522 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
523 | return 1; |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
524 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
525 | |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
526 | /* |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
527 | * For an index that points to a primitive, returns the category that contains it |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
528 | */ |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
529 | static PrimitiveCategory* categoryForPrimitiveIndex(const QModelIndex& primitiveIndex) |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
530 | { |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
531 | return static_cast<PrimitiveCategory*>(primitiveIndex.internalPointer()); |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
532 | } |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
533 | |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
534 | /* |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
535 | * Returns data from the tree model. |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
536 | */ |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
537 | QVariant PrimitiveManager::data(const QModelIndex& index, int role) const |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
538 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
539 | if (index.isValid()) |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
540 | { |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
541 | if (categoryForPrimitiveIndex(index) != nullptr) |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
542 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
543 | // Index points to a primitive, return primitive information. |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
544 | Primitive& primitive = categoryForPrimitiveIndex(index)->primitives[index.row()]; |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
545 | |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
546 | switch(role) |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
547 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
548 | case Qt::DisplayRole: |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
549 | return format("%1 - %2", primitive.name, primitive.title); |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
550 | case Qt::DecorationRole: |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
551 | return MainWindow::getIcon("subfilereference"); |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
552 | default: |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
553 | return {}; |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
554 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
555 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
556 | else |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
557 | { |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
558 | // Index points to a category, return category information. |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
559 | PrimitiveCategory* category = this->m_categories[index.row()]; |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
560 | |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
561 | switch (role) |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
562 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
563 | case Qt::DisplayRole: |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
564 | return category->name(); |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
565 | case Qt::DecorationRole: |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
566 | return MainWindow::getIcon("folder"); |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
567 | default: |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
568 | return {}; |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
569 | } |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
570 | } |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
571 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
572 | else |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
573 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
574 | // Index is invalid. |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
575 | return {}; |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
576 | } |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
577 | } |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
578 | |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
579 | /* |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
580 | * For a row and parent index, returns a child index. |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
581 | */ |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
582 | QModelIndex PrimitiveManager::index(int row, int, const QModelIndex& parent) const |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
583 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
584 | if (parent.isValid()) |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
585 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
586 | if (categoryForPrimitiveIndex(parent)) |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
587 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
588 | // Parent is a primitive index. Primitives cannot have children so return an |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
589 | // invalid index. |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
590 | return {}; |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
591 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
592 | else |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
593 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
594 | // Parent is a category, return an index to a primitive |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
595 | PrimitiveCategory* category = m_categories[parent.row()]; |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
596 | |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
597 | // Create an index inside the category |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
598 | if (row >= 0 and row < category->primitives.size()) |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
599 | return this->createIndex(row, 0, category); |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
600 | else |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
601 | return {}; |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
602 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
603 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
604 | else |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
605 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
606 | // Create a top-level index pointing to a category |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
607 | if (row >= 0 and row < this->m_categories.size()) |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
608 | return this->createIndex(row, 0, nullptr); |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
609 | else |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
610 | return {}; |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
611 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
612 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
613 | |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
614 | /* |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
615 | * For a primitive index, find the category index that contains it. |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
616 | */ |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
617 | QModelIndex PrimitiveManager::parent(const QModelIndex &index) const |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
618 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
619 | int row = this->m_categories.indexOf(categoryForPrimitiveIndex(index)); |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
620 | |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
621 | if (row != -1) |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
622 | return this->createIndex(row, 0, nullptr); |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
623 | else |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
624 | return {}; |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
625 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
626 | |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
627 | /* |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
628 | * Returns the amount of rows contained inside the given index. |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
629 | */ |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
630 | int PrimitiveManager::rowCount(const QModelIndex& parent) const |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
631 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
632 | if (parent.isValid()) |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
633 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
634 | if (categoryForPrimitiveIndex(parent)) |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
635 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
636 | // Primitives don't have child nodes, so return 0. |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
637 | return 0; |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
638 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
639 | else |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
640 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
641 | // For categories, return the amount of primitives contained. |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
642 | return this->m_categories[parent.row()]->primitives.size(); |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
643 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
644 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
645 | else |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
646 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
647 | // For top-level, return the amount of categories. |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
648 | return this->m_categories.size(); |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
649 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
650 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
651 | |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
652 | /* |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
653 | * Returns a static "Primitives" text for the header. |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
654 | */ |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
655 | QVariant PrimitiveManager::headerData(int section, Qt::Orientation, int role) const |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
656 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
657 | if (section == 0 and role == Qt::DisplayRole) |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
658 | return tr("Primitives"); |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
659 | else |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
660 | return {}; |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
661 | } |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
662 | |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
663 | // |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
664 | // --------------------------------------------------------------------------------------------------------------------- |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
665 | // |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
666 | |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
667 | |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
668 | PrimitiveCategory::PrimitiveCategory (QString name, QObject* parent) : |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
669 | QObject (parent), |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
670 | m_name (name) {} |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
671 | |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
672 | |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
673 | bool PrimitiveCategory::isValidToInclude() |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
674 | { |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
675 | return not patterns.isEmpty(); |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
676 | } |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
677 | |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
678 | |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
679 | QString PrimitiveCategory::name() const |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
680 | { |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
681 | return m_name; |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
682 | } |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
683 | |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
684 | |
1055
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
685 | /* |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
686 | * PrimitiveScanner :: PrimitiveScanner |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
687 | * |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
688 | * Constructs a primitive scanner. |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
689 | */ |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
690 | PrimitiveScanner::PrimitiveScanner(PrimitiveManager* parent) : |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
691 | QObject(parent), |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
692 | HierarchyElement(parent), |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
693 | m_manager(parent), |
1021
f40c792c9334
Replaced GetRecursiveFilenames with QDirIterator
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1020
diff
changeset
|
694 | m_iterator(LDPaths::primitivesDir(), QDirIterator::Subdirectories) |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
695 | { |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
696 | m_basePathLength = countof(LDPaths::primitivesDir().absolutePath()); |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
697 | print("Scanning primitives..."); |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
698 | } |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
699 | |
1055
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
700 | /* |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
701 | * PrimitiveScanner :: scannedPrimitives |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
702 | * |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
703 | * Returns a vector containing all the primitives found. |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
704 | */ |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
705 | const QVector<Primitive> &PrimitiveScanner::scannedPrimitives() const |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
706 | { |
1055
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
707 | return m_scannedPrimitives; |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
708 | } |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
709 | |
1055
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
710 | /* |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
711 | * PrimitiveScanner :: work |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
712 | * |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
713 | * Does one step of work, processes up to 100 primitives. |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
714 | * If the scanner does not finish work by this function call, it will ask the event loop to call this method again. |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
715 | */ |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
716 | void PrimitiveScanner::work() |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
717 | { |
1021
f40c792c9334
Replaced GetRecursiveFilenames with QDirIterator
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1020
diff
changeset
|
718 | for (int i = 0; m_iterator.hasNext() and i < 100; ++i) |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
719 | { |
1021
f40c792c9334
Replaced GetRecursiveFilenames with QDirIterator
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1020
diff
changeset
|
720 | QString filename = m_iterator.next(); |
1055
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
721 | QFile file = {filename}; |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
722 | |
1055
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
723 | if (file.open (QIODevice::ReadOnly)) |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
724 | { |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
725 | Primitive primitive; |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
726 | primitive.name = filename.mid(m_basePathLength + 1); // make full path relative |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
727 | primitive.name.replace('/', '\\'); // use DOS backslashes, they're expected |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
728 | primitive.category = nullptr; |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
729 | primitive.title = QString::fromUtf8(file.readLine().simplified()); |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
730 | |
1055
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
731 | if (primitive.title[0] == '0') |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
732 | { |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
733 | primitive.title.remove(0, 1); // remove 0 |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
734 | primitive.title = primitive.title.simplified(); |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
735 | } |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
736 | |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
737 | m_scannedPrimitives << primitive; |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
738 | } |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
739 | } |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
740 | |
1021
f40c792c9334
Replaced GetRecursiveFilenames with QDirIterator
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1020
diff
changeset
|
741 | if (not m_iterator.hasNext()) |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
742 | { |
1055
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
743 | // If there are no more primitives to iterate, we're done. Now save this information into a cache file. |
1283
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
744 | std::sort( |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
745 | m_scannedPrimitives.begin(), |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
746 | m_scannedPrimitives.end(), |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
747 | [](const Primitive& one, const Primitive& other) -> bool |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
748 | { |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
749 | return one.title < other.title; |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
750 | } |
3c3a5eb965f7
added an MVC interface to the primitives tree
Teemu Piippo <teemu@hecknology.net>
parents:
1261
diff
changeset
|
751 | ); |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
752 | QString path = m_manager->getPrimitivesCfgPath(); |
1055
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
753 | QFile configFile = {path}; |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
754 | |
1055
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
755 | if (configFile.open(QIODevice::WriteOnly | QIODevice::Text)) |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
756 | { |
1055
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
757 | for (Primitive& primitive : m_scannedPrimitives) |
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
758 | fprint(configFile, "%1 %2\r\n", primitive.name, primitive.title); |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
759 | |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
760 | configFile.close(); |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
761 | } |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
762 | else |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
763 | { |
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:
1149
diff
changeset
|
764 | QMessageBox::critical(m_window, tr("Error"), format("Couldn't write primitive list %1: %2", path, configFile.errorString())); |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
765 | } |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
766 | |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
767 | emit workDone(); |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
768 | } |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
769 | else |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
770 | { |
1055
c28d07a583ac
Cleaned up PrimitiveScanner
Teemu Piippo <teemu@hecknology.net>
parents:
1054
diff
changeset
|
771 | // Otherwise, defer to event loop, pick up the work later. |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
772 | QMetaObject::invokeMethod (this, "work", Qt::QueuedConnection); |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
773 | } |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
774 | } |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
775 | |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
776 | |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
777 | // |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
778 | // --------------------------------------------------------------------------------------------------------------------- |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
779 | // |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
780 | |
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
781 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
782 | PrimitiveTreeItem::PrimitiveTreeItem (QTreeWidgetItem* parent, Primitive* info) : |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
783 | QTreeWidgetItem (parent), |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
784 | m_primitive (info) {} |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
785 | |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
786 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
787 | PrimitiveTreeItem::PrimitiveTreeItem (QTreeWidget* parent, Primitive* info) : |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
788 | QTreeWidgetItem (parent), |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
789 | m_primitive (info) {} |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
790 | |
1020
815a040d4039
Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
791 | |
1018
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
792 | Primitive* PrimitiveTreeItem::primitive() const |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
793 | { |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
794 | return m_primitive; |
49358df9495b
Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
795 | } |