Debian Codegraph @

src/Gui/Dialogs/DlgParameterImp.h

raw
1 /***************************************************************************
2 * Copyright (c) 2002 Jürgen Riegel <[email protected]> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23
24 #ifndef GUI_DIALOG_DLGPARAMETER_H
25 #define GUI_DIALOG_DLGPARAMETER_H
26
27 #include <Base/Parameter.h>
28
29 #include <QDialog>
30 #include <QPointer>
31 #include <QTreeWidget>
32 #include <QTreeWidgetItem>
33
34
35 namespace Gui
36 {
37 namespace Dialog
38 {
39
40 class Ui_DlgParameter;
41 class DlgParameterFind;
42
43 /**
44 * The DlgParameterImp class implements a dialog showing all parameters in a list view.
45 * \author Jürgen Riegel
46 */
47 class GuiExport DlgParameterImp: public QDialog
48 {
49 Q_OBJECT
50
51 public:
52 explicit DlgParameterImp(QWidget* parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags());
53 ~DlgParameterImp() override;
54
55 void accept() override;
56 void reject() override;
57
58 void activateParameterSet(const char*);
59
60 protected:
61 void setupConnections();
62 void onChangeParameterSet(int);
63 void onButtonFindClicked();
64 void onFindGroupTtextChanged(const QString& SearchStr);
65 void onButtonSaveToDiskClicked();
66
67 void onGroupSelected(QTreeWidgetItem*);
68 void onCloseButtonClicked();
69 void onCheckSortToggled(bool);
70
71 protected:
72 void changeEvent(QEvent* e) override;
73 void showEvent(QShowEvent*) override;
74 void closeEvent(QCloseEvent*) override;
75
76 protected:
77 QTreeWidget* paramGroup;
78 QTreeWidget* paramValue;
79 Ui_DlgParameter* ui;
80 QPointer<DlgParameterFind> finder;
81
82 private:
83 QFont defaultFont;
84 QBrush defaultColor;
85 QFont boldFont;
86 QList<QTreeWidgetItem*> foundList;
87 };
88
89 // --------------------------------------------------------------------
90
91 /**
92 * The ParameterGroup class represents the tree structure of the parameters.
93 * The leaves represented by ParameterValueItem are displayed in ParameterValue.
94 * @author Werner Mayer
95 */
96 class ParameterGroup: public QTreeWidget
97 {
98 Q_OBJECT
99
100 public:
101 explicit ParameterGroup(QWidget* parent = nullptr);
102 ~ParameterGroup() override;
103
104 protected:
105 /** Shows the context menu. */
106 void contextMenuEvent(QContextMenuEvent* event) override;
107 /** Triggers the "Del" key. */
108 void keyPressEvent(QKeyEvent* event) override;
109
110 protected Q_SLOTS:
111 /** Removes the underlying parameter group and its sub-groups from the
112 * parameter tree structure.
113 */
114 void onDeleteSelectedItem();
115 /** Creates a sub-group to the current selected parameter group. */
116 void onCreateSubgroup();
117 /** Expands or closes the selected item. If it is open it will be closed and the
118 * other way round.
119 */
120 void onToggleSelectedItem();
121 /** Exports the current selected parameter with all sub-groups to a file. */
122 void onExportToFile();
123 /** Imports a file and inserts the parameter to the current selected parameter node. */
124 void onImportFromFile();
125 /** Changes the name of the leaf of the selected item. */
126 void onRenameSelectedItem();
127
128 protected:
129 void changeEvent(QEvent* e) override;
130
131 private:
132 QMenu* menuEdit;
133 QAction* expandAct;
134 QAction* subGrpAct;
135 QAction* removeAct;
136 QAction* renameAct;
137 QAction* exportAct;
138 QAction* importAct;
139 };
140
141 // --------------------------------------------------------------------
142
143 /**
144 * The ParameterValue class displays all leaves of a parameter group. A leaf is represented
145 * by the ParameterValueItem class.
146 * @author Werner Mayer
147 */
148 class ParameterValue: public QTreeWidget
149 {
150 Q_OBJECT
151
152 public:
153 explicit ParameterValue(QWidget* parent = nullptr);
154 ~ParameterValue() override;
155
156 /** Sets the current parameter group that is displayed. */
157 void setCurrentGroup(const Base::Reference<ParameterGrp>& _hcGrp);
158 /** Returns the current parameter group that is displayed. */
159 Base::Reference<ParameterGrp> currentGroup() const;
160
161 protected:
162 /** Shows the context menu. */
163 void contextMenuEvent(QContextMenuEvent* event) override;
164 /** Invokes onDeleteSelectedItem() if the "Del" key was pressed. */
165 void keyPressEvent(QKeyEvent* event) override;
166 void resizeEvent(QResizeEvent*) override;
167
168 protected Q_SLOTS:
169 /** Changes the value of the leaf of the selected item. */
170 void onChangeSelectedItem(QTreeWidgetItem*, int);
171 void onChangeSelectedItem();
172 /** Remove the underlying leaf from the parameter group. The selected item is also
173 * removed and destroyed.
174 */
175 void onDeleteSelectedItem();
176 /** Changes the name of the leaf of the selected item. */
177 void onRenameSelectedItem();
178 /** Creates and appends a new "text" leaf. */
179 void onCreateTextItem();
180 /** Creates and appends a new "integer" leaf. */
181 void onCreateIntItem();
182 /** Creates and appends a new "unsigned integer" leaf. */
183 void onCreateUIntItem();
184 /** Creates and appends a new "float" leaf. */
185 void onCreateFloatItem();
186 /** Creates and appends a new "boolean" leaf. */
187 void onCreateBoolItem();
188 /** Defines that the first column is editable.
189 * @note We need to reimplement this method as QTreeWidgetItem::flags()
190 * doesn't have an int parameter.
191 */
192 bool edit(const QModelIndex& index, QAbstractItemView::EditTrigger trigger, QEvent* event) override;
193
194 private:
195 QMenu* menuEdit;
196 QMenu* menuNew;
197 QAction* changeAct;
198 QAction* removeAct;
199 QAction* renameAct;
200 QAction* newStrAct;
201 QAction* newFltAct;
202 QAction* newIntAct;
203 QAction* newUlgAct;
204 QAction* newBlnAct;
205 Base::Reference<ParameterGrp> _hcGrp;
206 };
207
208 /** The link between the Tree and the shown Label.
209 * Every (shown) Label in the FCDocument class get it
210 * associated FCTreeLabel which controls the visibility
211 * and the functions of the Label.
212 *
213 * \author Jürgen Riegel
214 */
215 class ParameterGroupItem: public QTreeWidgetItem
216 {
217 public:
218 /// Constructor
219 ParameterGroupItem(ParameterGroupItem* parent, const Base::Reference<ParameterGrp>& hcGrp);
220 ParameterGroupItem(QTreeWidget* parent, const Base::Reference<ParameterGrp>& hcGrp);
221 ~ParameterGroupItem() override;
222
223 void setData(int column, int role, const QVariant& value) override;
224 QVariant data(int column, int role) const override;
225
226 void fillUp();
227 Base::Reference<ParameterGrp> _hcGrp;
228 };
229
230 // --------------------------------------------------------------------
231
232 /**
233 * The ParameterValueItem class represents items that are added to the ParameterValue
234 * listview. Each item represents a leaf in a parameter group and allows interaction
235 * with this leaf, such as modifying its name, its value or even remove it from the
236 * parameter group.
237 * @author Werner Mayer
238 */
239 class ParameterValueItem: public QTreeWidgetItem
240 {
241 public:
242 /// Constructor
243 ParameterValueItem(QTreeWidget* parent, const Base::Reference<ParameterGrp>& hcGrp);
244 ~ParameterValueItem() override;
245
246 /** If the name of the item has changed replace() is invoked. */
247 void setData(int column, int role, const QVariant& value) override;
248 /** Opens an input dialog to change the value. */
249 virtual void changeValue() = 0;
250 /** Append this item as leaf to the parameter group. */
251 virtual void appendToGroup() = 0;
252 /** Remove the leaf from the parameter group. */
253 virtual void removeFromGroup() = 0;
254
255 protected:
256 /** Replaces the name of the leaf from \a oldName to \a newName. */
257 virtual void replace(const QString& oldName, const QString& newName) = 0;
258
259 protected:
260 Base::Reference<ParameterGrp> _hcGrp;
261 };
262
263 /**
264 * The ParameterText class allows interaction with "text" parameter leaves.
265 * @author Werner Mayer
266 */
267 class ParameterText: public ParameterValueItem
268 {
269 public:
270 /// Constructor
271 ParameterText(
272 QTreeWidget* parent,
273 QString label1,
274 const char* value,
275 const Base::Reference<ParameterGrp>& hcGrp
276 );
277 ~ParameterText() override;
278
279 void changeValue() override;
280 void appendToGroup() override;
281 void removeFromGroup() override;
282
283 protected:
284 void replace(const QString& oldName, const QString& newName) override;
285 };
286
287 /**
288 * The ParameterInt class allows interaction with "integer" parameter leaves.
289 * @author Werner Mayer
290 */
291 class ParameterInt: public ParameterValueItem
292 {
293 public:
294 /// Constructor
295 ParameterInt(
296 QTreeWidget* parent,
297 QString label1,
298 long value,
299 const Base::Reference<ParameterGrp>& hcGrp
300 );
301 ~ParameterInt() override;
302
303 void changeValue() override;
304 void appendToGroup() override;
305 void removeFromGroup() override;
306
307 protected:
308 void replace(const QString& oldName, const QString& newName) override;
309 };
310
311 /**
312 * The ParameterUInt class allows interaction with "unsigned integer" parameter leaves.
313 * @author Werner Mayer
314 */
315 class ParameterUInt: public ParameterValueItem
316 {
317 public:
318 /// Constructor
319 ParameterUInt(
320 QTreeWidget* parent,
321 QString label1,
322 unsigned long value,
323 const Base::Reference<ParameterGrp>& hcGrp
324 );
325 ~ParameterUInt() override;
326
327 void changeValue() override;
328 void appendToGroup() override;
329 void removeFromGroup() override;
330
331 protected:
332 void replace(const QString& oldName, const QString& newName) override;
333 };
334
335 /**
336 * The ParameterFloat class allows interaction with "float" parameter leaves.
337 * @author Werner Mayer
338 */
339 class ParameterFloat: public ParameterValueItem
340 {
341 public:
342 /// Constructor
343 ParameterFloat(
344 QTreeWidget* parent,
345 QString label1,
346 double value,
347 const Base::Reference<ParameterGrp>& hcGrp
348 );
349 ~ParameterFloat() override;
350
351 void changeValue() override;
352 void appendToGroup() override;
353 void removeFromGroup() override;
354
355 protected:
356 void replace(const QString& oldName, const QString& newName) override;
357 };
358
359 /**
360 * The ParameterBool class allows interaction with "boolean" parameter leaves.
361 * @author Werner Mayer
362 */
363 class ParameterBool: public ParameterValueItem
364 {
365 public:
366 /// Constructor
367 ParameterBool(
368 QTreeWidget* parent,
369 QString label1,
370 bool value,
371 const Base::Reference<ParameterGrp>& hcGrp
372 );
373 ~ParameterBool() override;
374
375 void changeValue() override;
376 void appendToGroup() override;
377 void removeFromGroup() override;
378
379 protected:
380 void replace(const QString& oldName, const QString& newName) override;
381 };
382
383 } // namespace Dialog
384 } // namespace Gui
385
386 #endif // GUI_DIALOG_DLGPARAMETER_H