src/widgets/headeredit.cpp

Thu, 20 Jun 2019 08:54:35 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 20 Jun 2019 08:54:35 +0300
changeset 1440
265b2e95a8e8
parent 1384
4c134708be05
permissions
-rw-r--r--

uuid things

1302
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1292
diff changeset
1 /*
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1292
diff changeset
2 * LDForge: LDraw parts authoring CAD
1326
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1306
diff changeset
3 * Copyright (C) 2013 - 2018 Teemu Piippo
1302
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1292
diff changeset
4 *
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1292
diff changeset
5 * This program is free software: you can redistribute it and/or modify
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1292
diff changeset
6 * it under the terms of the GNU General Public License as published by
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1292
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1292
diff changeset
8 * (at your option) any later version.
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1292
diff changeset
9 *
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1292
diff changeset
10 * This program is distributed in the hope that it will be useful,
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1292
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1292
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1292
diff changeset
13 * GNU General Public License for more details.
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1292
diff changeset
14 *
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1292
diff changeset
15 * You should have received a copy of the GNU General Public License
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1292
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1292
diff changeset
17 */
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1292
diff changeset
18
1291
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 #include "headeredit.h"
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 #include "ui_headeredit.h"
1384
4c134708be05 some fixes
Teemu Piippo <teemu@hecknology.net>
parents: 1368
diff changeset
21 #include "parser.h"
1291
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 #include "../lddocument.h"
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 #include "../headerhistorymodel.h"
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 static const QStringList categories {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 "",
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 "Animal", "Antenna", "Arch", "Arm", "Bar", "Baseplate", "Belville", "Boat", "Bracket",
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 "Brick", "Canvas", "Car", "Clikits", "Cockpit", "Cone", "Constraction",
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 "Constraction Accessory", "Container", "Conveyor", "Crane", "Cylinder", "Dish", "Door",
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 "Electric", "Exhaust", "Fence", "Figure", "Figure Accessory", "Flag", "Forklift", "Freestyle",
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 "Garage", "Glass", "Grab", "Hinge", "Homemaker", "Hose", "Ladder", "Lever", "Magnet", "Minifig",
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 "Minifig Accessory", "Minifig Footwear", "Minifig Headwear", "Minifig Hipwear",
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 "Minifig Neckwear", "Monorail", "Panel", "Plane", "Plant", "Plate", "Platform", "Propellor",
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 "Rack", "Roadsign", "Rock", "Scala", "Screw", "Sheet", "Slope", "Sphere", "Staircase",
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 "Sticker", "Support", "Tail", "Tap", "Technic", "Tile", "Tipper", "Tractor", "Trailer",
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 "Train", "Turntable", "Tyre", "Vehicle", "Wedge", "Wheel", "Winch", "Window", "Windscreen",
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 "Wing", "Znap",
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 };
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39
1384
4c134708be05 some fixes
Teemu Piippo <teemu@hecknology.net>
parents: 1368
diff changeset
40 LDHeader::FileType headerTypeCast(int index)
4c134708be05 some fixes
Teemu Piippo <teemu@hecknology.net>
parents: 1368
diff changeset
41 {
4c134708be05 some fixes
Teemu Piippo <teemu@hecknology.net>
parents: 1368
diff changeset
42 if (Parser::typeStrings.values().contains(static_cast<LDHeader::FileType>(index)))
4c134708be05 some fixes
Teemu Piippo <teemu@hecknology.net>
parents: 1368
diff changeset
43 return static_cast<LDHeader::FileType>(index);
4c134708be05 some fixes
Teemu Piippo <teemu@hecknology.net>
parents: 1368
diff changeset
44 else
4c134708be05 some fixes
Teemu Piippo <teemu@hecknology.net>
parents: 1368
diff changeset
45 return LDHeader::NoHeader;
4c134708be05 some fixes
Teemu Piippo <teemu@hecknology.net>
parents: 1368
diff changeset
46 }
4c134708be05 some fixes
Teemu Piippo <teemu@hecknology.net>
parents: 1368
diff changeset
47
1291
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48 HeaderEdit::HeaderEdit(QWidget* parent) :
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49 QWidget {parent},
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50 ui {*new Ui_HeaderEdit},
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51 headerHistoryModel {new HeaderHistoryModel {nullptr, this}}
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
53 ui.setupUi(this);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
54
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
55 this->ui.category->addItems(::categories);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
56 this->ui.category->setItemText(0, "(unspecified)");
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
57 this->ui.history->setModel(this->headerHistoryModel);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
58
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
59 connect(
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
60 ui.description,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
61 &QLineEdit::textChanged,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
62 [&](const QString& text)
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
63 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
64 if (this->hasValidHeader())
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
65 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
66 this->m_header->description = text;
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
67 emit descriptionChanged(text);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
68 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
69 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
70 );
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
71 connect(
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
72 ui.author,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
73 &QLineEdit::textChanged,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
74 [&](const QString& text)
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
75 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
76 if (this->hasValidHeader())
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
77 this->m_header->author = text;
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
78 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
79 );
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
80 connect(
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
81 ui.winding,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
82 qOverload<int>(&QComboBox::currentIndexChanged),
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
83 [&](int index)
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
84 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
85 if (this->hasValidHeader())
1306
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1302
diff changeset
86 this->m_model->setWinding(static_cast<Winding>(index));
1291
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
87 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
88 );
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
89 connect(
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
90 ui.license,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
91 qOverload<int>(&QComboBox::currentIndexChanged),
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
92 [&](int index)
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
93 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
94 if (this->m_header)
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
95 this->m_header->license = static_cast<decltype(LDHeader::license)>(index);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
96 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
97 );
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
98 connect(
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
99 ui.category,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
100 qOverload<int>(&QComboBox::currentIndexChanged),
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
101 [&](int index)
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
102 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
103 if (this->hasValidHeader())
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
104 this->m_header->category = ::categories.value(index);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
105 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
106 );
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
107 connect(
1384
4c134708be05 some fixes
Teemu Piippo <teemu@hecknology.net>
parents: 1368
diff changeset
108 ui.type,
4c134708be05 some fixes
Teemu Piippo <teemu@hecknology.net>
parents: 1368
diff changeset
109 qOverload<int>(&QComboBox::currentIndexChanged),
4c134708be05 some fixes
Teemu Piippo <teemu@hecknology.net>
parents: 1368
diff changeset
110 [&](int index)
4c134708be05 some fixes
Teemu Piippo <teemu@hecknology.net>
parents: 1368
diff changeset
111 {
4c134708be05 some fixes
Teemu Piippo <teemu@hecknology.net>
parents: 1368
diff changeset
112 if (this->hasValidHeader())
4c134708be05 some fixes
Teemu Piippo <teemu@hecknology.net>
parents: 1368
diff changeset
113 this->m_header->type = headerTypeCast(index + 1);
4c134708be05 some fixes
Teemu Piippo <teemu@hecknology.net>
parents: 1368
diff changeset
114 }
4c134708be05 some fixes
Teemu Piippo <teemu@hecknology.net>
parents: 1368
diff changeset
115 );
4c134708be05 some fixes
Teemu Piippo <teemu@hecknology.net>
parents: 1368
diff changeset
116 connect(
1291
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
117 ui.alias,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
118 &QCheckBox::stateChanged,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
119 [&](int state)
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
120 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
121 if (this->hasValidHeader())
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
122 assignFlag<LDHeader::Alias>(this->m_header->qualfiers, state == Qt::Checked);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
123 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
124 );
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
125 connect(
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
126 ui.physicalColor,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
127 &QCheckBox::stateChanged,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
128 [&](int state)
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
129 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
130 if (this->hasValidHeader())
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
131 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
132 assignFlag<LDHeader::Physical_Color>(
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
133 this->m_header->qualfiers,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
134 state == Qt::Checked
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
135 );
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
136 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
137 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
138 );
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
139 connect(
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
140 ui.flexibleSection,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
141 &QCheckBox::stateChanged,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
142 [&](int state)
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
143 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
144 if (this->hasValidHeader())
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
145 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
146 assignFlag<LDHeader::Flexible_Section>(
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
147 this->m_header->qualfiers,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
148 state == Qt::Checked
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
149 );
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
150 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
151 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
152 );
1292
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
153 connect(
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
154 ui.historyNew,
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
155 &QPushButton::clicked,
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
156 [&]()
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
157 {
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
158 if (this->hasValidHeader())
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
159 {
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
160 const QModelIndex index = this->ui.history->selectionModel()->currentIndex();
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
161 int row;
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
162
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
163 if (index.isValid())
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
164 row = index.row() + 1;
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
165 else
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
166 row = this->headerHistoryModel->rowCount();
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
167
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
168 this->headerHistoryModel->insertRows(row, 1, {});
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
169 }
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
170 }
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
171 );
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
172 connect(
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
173 ui.historyDelete,
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
174 &QPushButton::clicked,
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
175 [&]()
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
176 {
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
177 const QModelIndex index = this->ui.history->selectionModel()->currentIndex();
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
178
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
179 if (this->hasValidHeader() and index.isValid())
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
180 this->headerHistoryModel->removeRows(index.row(), 1, {});
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
181 }
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
182 );
1368
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
183 connect(
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
184 ui.help,
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
185 &QPlainTextEdit::textChanged,
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
186 [&]()
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
187 {
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
188 if (this->hasValidHeader())
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
189 this->m_header->help = ui.help->document()->toPlainText();
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
190 }
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
191 );
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
192 connect(
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
193 ui.keywords,
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
194 &QPlainTextEdit::textChanged,
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
195 [&]()
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
196 {
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
197 if (this->hasValidHeader())
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
198 this->m_header->keywords = ui.keywords->document()->toPlainText();
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
199 }
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
200 );
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
201 connect(
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
202 ui.cmdline,
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
203 &QLineEdit::textChanged,
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
204 [&]()
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
205 {
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
206 if (this->hasValidHeader())
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
207 this->m_header->cmdline = ui.cmdline->text();
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
208 }
36105978da93 added some missing connections
Teemu Piippo <teemu@hecknology.net>
parents: 1340
diff changeset
209 );
1292
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
210 connect(ui.historyMoveUp, &QPushButton::clicked, [&](){ this->moveRows(-1); });
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
211 connect(ui.historyMoveDown, &QPushButton::clicked, [&](){ this->moveRows(+2); });
1291
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
212 this->setEnabled(this->hasValidHeader());
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
213 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
214
1292
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
215 void HeaderEdit::moveRows(int direction)
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
216 {
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
217 if (this->hasValidHeader())
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
218 {
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
219 const QModelIndex index = this->ui.history->selectionModel()->currentIndex();
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
220 this->headerHistoryModel->moveRows({}, index.row(), 1, {}, index.row() + direction);
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
221 }
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
222 }
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
223
1291
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
224 HeaderEdit::~HeaderEdit()
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
225 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
226 delete this->headerHistoryModel;
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
227 delete &this->ui;
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
228 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
229
1306
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1302
diff changeset
230 void HeaderEdit::setDocument(LDDocument* document)
1291
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
231 {
1306
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1302
diff changeset
232 LDHeader* header = &document->header;
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1302
diff changeset
233 this->m_model = document;
1291
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
234 this->m_header = header;
1340
ea1b3ea9a3ca more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
235 if (document->header.type != LDHeader::NoHeader)
ea1b3ea9a3ca more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
236 {
ea1b3ea9a3ca more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
237 this->ui.description->setText(header->description);
ea1b3ea9a3ca more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
238 this->ui.author->setText(header->author);
ea1b3ea9a3ca more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
239 this->ui.category->setCurrentIndex(::categories.indexOf(header->category));
ea1b3ea9a3ca more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
240 this->ui.license->setCurrentIndex(static_cast<int>(header->license));
ea1b3ea9a3ca more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
241 this->ui.alias->setChecked(header->qualfiers & LDHeader::Alias);
ea1b3ea9a3ca more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
242 this->ui.physicalColor->setChecked(header->qualfiers & LDHeader::Physical_Color);
ea1b3ea9a3ca more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
243 this->ui.flexibleSection->setChecked(header->qualfiers & LDHeader::Flexible_Section);
ea1b3ea9a3ca more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
244 this->ui.cmdline->setText(header->cmdline);
ea1b3ea9a3ca more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
245 this->ui.winding->setCurrentIndex(document->winding());
ea1b3ea9a3ca more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
246 this->ui.keywords->document()->setPlainText(header->keywords);
ea1b3ea9a3ca more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
247 this->ui.help->document()->setPlainText(header->help);
ea1b3ea9a3ca more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
248 this->ui.type->setCurrentIndex(static_cast<int>(document->header.type) - 1);
ea1b3ea9a3ca more work on 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
249 }
1291
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
250 this->headerHistoryModel->setHeader(header);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
251 this->setEnabled(this->hasValidHeader());
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
252 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
253
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
254 bool HeaderEdit::hasValidHeader() const
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
255 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
256 return this->m_header != nullptr and this->m_header->type != LDHeader::NoHeader;
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
257 }

mercurial