src/widgets/headeredit.cpp

Mon, 19 Mar 2018 11:04:18 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 19 Mar 2018 11:04:18 +0200
changeset 1304
bb3f43293cf8
parent 1302
e14d7826373a
child 1306
be85306198a2
permissions
-rw-r--r--

added more comments

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
e14d7826373a added license headers
Teemu Piippo <teemu@hecknology.net>
parents: 1292
diff changeset
3 * Copyright (C) 2013 - 2017 Teemu Piippo
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"
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 #include "../lddocument.h"
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 #include "../headerhistorymodel.h"
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 static const QStringList categories {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 "",
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 "Animal", "Antenna", "Arch", "Arm", "Bar", "Baseplate", "Belville", "Boat", "Bracket",
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 "Brick", "Canvas", "Car", "Clikits", "Cockpit", "Cone", "Constraction",
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 "Constraction Accessory", "Container", "Conveyor", "Crane", "Cylinder", "Dish", "Door",
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 "Electric", "Exhaust", "Fence", "Figure", "Figure Accessory", "Flag", "Forklift", "Freestyle",
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 "Garage", "Glass", "Grab", "Hinge", "Homemaker", "Hose", "Ladder", "Lever", "Magnet", "Minifig",
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 "Minifig Accessory", "Minifig Footwear", "Minifig Headwear", "Minifig Hipwear",
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 "Minifig Neckwear", "Monorail", "Panel", "Plane", "Plant", "Plate", "Platform", "Propellor",
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 "Rack", "Roadsign", "Rock", "Scala", "Screw", "Sheet", "Slope", "Sphere", "Staircase",
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 "Sticker", "Support", "Tail", "Tap", "Technic", "Tile", "Tipper", "Tractor", "Trailer",
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 "Train", "Turntable", "Tyre", "Vehicle", "Wedge", "Wheel", "Winch", "Window", "Windscreen",
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 "Wing", "Znap",
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 };
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 HeaderEdit::HeaderEdit(QWidget* parent) :
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40 QWidget {parent},
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 ui {*new Ui_HeaderEdit},
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 headerHistoryModel {new HeaderHistoryModel {nullptr, this}}
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 ui.setupUi(this);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
46 this->ui.category->addItems(::categories);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47 this->ui.category->setItemText(0, "(unspecified)");
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48 this->ui.history->setModel(this->headerHistoryModel);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50 connect(
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51 ui.description,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52 &QLineEdit::textChanged,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
53 [&](const QString& text)
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 if (this->hasValidHeader())
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
56 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
57 this->m_header->description = text;
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
58 emit descriptionChanged(text);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
59 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
60 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
61 );
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
62 connect(
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
63 ui.author,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
64 &QLineEdit::textChanged,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
65 [&](const QString& text)
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
66 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
67 if (this->hasValidHeader())
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
68 this->m_header->author = text;
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.winding,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
73 qOverload<int>(&QComboBox::currentIndexChanged),
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
74 [&](int index)
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 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
78 this->m_header->winding = static_cast<Winding>(index);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
79 emit windingChanged(this->m_header->winding);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
80 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
81 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
82 );
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
83 connect(
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
84 ui.license,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
85 qOverload<int>(&QComboBox::currentIndexChanged),
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
86 [&](int index)
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 if (this->m_header)
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
89 this->m_header->license = static_cast<decltype(LDHeader::license)>(index);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
90 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
91 );
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
92 connect(
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
93 ui.category,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
94 qOverload<int>(&QComboBox::currentIndexChanged),
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
95 [&](int 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 if (this->hasValidHeader())
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
98 this->m_header->category = ::categories.value(index);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
99 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
100 );
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
101 connect(
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
102 ui.alias,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
103 &QCheckBox::stateChanged,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
104 [&](int state)
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 if (this->hasValidHeader())
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
107 assignFlag<LDHeader::Alias>(this->m_header->qualfiers, state == Qt::Checked);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
108 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
109 );
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
110 connect(
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
111 ui.physicalColor,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
112 &QCheckBox::stateChanged,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
113 [&](int state)
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
114 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
115 if (this->hasValidHeader())
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
116 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
117 assignFlag<LDHeader::Physical_Color>(
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
118 this->m_header->qualfiers,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
119 state == Qt::Checked
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 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
122 }
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 connect(
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
125 ui.flexibleSection,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
126 &QCheckBox::stateChanged,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
127 [&](int state)
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
128 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
129 if (this->hasValidHeader())
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
130 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
131 assignFlag<LDHeader::Flexible_Section>(
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
132 this->m_header->qualfiers,
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
133 state == Qt::Checked
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
134 );
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 );
1292
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
138 connect(
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
139 ui.historyNew,
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
140 &QPushButton::clicked,
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
141 [&]()
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
142 {
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
143 if (this->hasValidHeader())
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
144 {
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
145 const QModelIndex index = this->ui.history->selectionModel()->currentIndex();
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
146 int row;
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
147
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
148 if (index.isValid())
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
149 row = index.row() + 1;
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
150 else
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
151 row = this->headerHistoryModel->rowCount();
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
152
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
153 this->headerHistoryModel->insertRows(row, 1, {});
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
154 }
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
155 }
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 connect(
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
158 ui.historyDelete,
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
159 &QPushButton::clicked,
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
160 [&]()
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
161 {
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
162 const QModelIndex index = this->ui.history->selectionModel()->currentIndex();
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
163
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
164 if (this->hasValidHeader() and index.isValid())
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
165 this->headerHistoryModel->removeRows(index.row(), 1, {});
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
166 }
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 connect(ui.historyMoveUp, &QPushButton::clicked, [&](){ this->moveRows(-1); });
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
169 connect(ui.historyMoveDown, &QPushButton::clicked, [&](){ this->moveRows(+2); });
1291
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
170 this->setEnabled(this->hasValidHeader());
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
171 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
172
1292
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
173 void HeaderEdit::moveRows(int direction)
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
174 {
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
175 if (this->hasValidHeader())
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 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
179 }
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
180 }
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
181
1291
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
182 HeaderEdit::~HeaderEdit()
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
183 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
184 delete this->headerHistoryModel;
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
185 delete &this->ui;
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
186 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
187
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
188 void HeaderEdit::setHeader(LDHeader* header)
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
189 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
190 this->m_header = header;
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
191 this->ui.description->setText(header->description);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
192 this->ui.author->setText(header->author);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
193 this->ui.category->setCurrentIndex(::categories.indexOf(header->category));
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
194 this->ui.license->setCurrentIndex(static_cast<int>(header->license));
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
195 this->ui.alias->setChecked(header->qualfiers & LDHeader::Alias);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
196 this->ui.physicalColor->setChecked(header->qualfiers & LDHeader::Physical_Color);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
197 this->ui.flexibleSection->setChecked(header->qualfiers & LDHeader::Flexible_Section);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
198 this->ui.cmdline->setText(header->cmdline);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
199 this->ui.winding->setCurrentIndex(header->winding);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
200 this->ui.keywords->document()->setPlainText(header->keywords);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
201 this->ui.help->document()->setPlainText(header->help);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
202 this->headerHistoryModel->setHeader(header);
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
203 this->setEnabled(this->hasValidHeader());
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
204 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
205
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
206 LDHeader* HeaderEdit::header() const
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
207 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
208 return this->m_header;
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
209 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
210
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
211 bool HeaderEdit::hasValidHeader() const
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
212 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
213 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
214 }

mercurial