Debian Codegraph @

src/Gui/Dialogs/DlgObjectSelection.h

raw
1 /****************************************************************************
2 * Copyright (c) 2018 Zheng Lei (realthunder) <[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 #ifndef GUI_DLGOBJECTSELECTION_H
23 #define GUI_DLGOBJECTSELECTION_H
24
25 #include <QDialog>
26 #include <QTimer>
27 #include <App/DocumentObserver.h>
28 #include <Base/Parameter.h>
29 #include <Base/Bitmask.h>
30
31 class QCheckBox;
32 class QTreeWidgetItem;
33 class QTreeWidget;
34
35 namespace Gui
36 {
37
38 class Ui_DlgObjectSelection;
39
40 /** Dialog for object dependency selection
41 */
42 class GuiExport DlgObjectSelection: public QDialog
43 {
44 Q_OBJECT
45
46 public:
47 /** Constructor
48 *
49 * Creates a dialog for selecting the given objects and their dependent
50 * objects
51 *
52 * @param objs: initial objects
53 * @param parent: optional parent widget
54 * @param fl: optional window flags
55 */
56 DlgObjectSelection(
57 const std::vector<App::DocumentObject*>& objs,
58 QWidget* parent = nullptr,
59 Qt::WindowFlags fl = Qt::WindowFlags()
60 );
61
62 /** Constructor
63 *
64 * Creates a dialog for selecting the given objects and their dependent
65 * objects with exclusions
66 *
67 * @param objs: initial objects
68 * @param excludes: excluded objects. The objects and their dependents will
69 * still be in the list but unchecked.
70 * @param parent: optional parent widget
71 * @param fl: optional window flags
72 */
73 DlgObjectSelection(
74 const std::vector<App::DocumentObject*>& objs,
75 const std::vector<App::DocumentObject*>& excludes,
76 QWidget* parent = nullptr,
77 Qt::WindowFlags fl = Qt::WindowFlags()
78 );
79
80 /// Destructor
81 ~DlgObjectSelection() override;
82
83 /// Options for getSelections()
84 enum class SelectionOptions
85 {
86 /// Invert the selection, i.e. return the unselected objects
87 Invert = 1,
88 /// Sort the returned object in depending order
89 Sort = 2,
90 /// Return the unselected objects sorted in depending order
91 InvertSort = 3,
92 };
93 /// Get the selected objects
94 std::vector<App::DocumentObject*> getSelections(SelectionOptions options = SelectionOptions()) const;
95
96 /// Add a user defined checkbox at the bottom of the dialog
97 void addCheckBox(QCheckBox* box);
98
99 /// Override the prompt message
100 void setMessage(const QString&);
101
102 void accept() override;
103 void reject() override;
104
105 private Q_SLOTS:
106 void onDepItemChanged(QTreeWidgetItem* item, int);
107 void onObjItemChanged(QTreeWidgetItem* item, int);
108 void onItemSelectionChanged();
109 void checkItemChanged();
110 void onAutoDeps(bool);
111 void onItemExpanded(QTreeWidgetItem* item);
112 void onUseOriginalsBtnClicked();
113 void onShowDeps();
114
115 private:
116 QTreeWidgetItem* getItem(
117 App::DocumentObject* obj,
118 std::vector<QTreeWidgetItem*>** items = nullptr,
119 QTreeWidgetItem* parent = nullptr
120 );
121
122 QTreeWidgetItem* createDepItem(QTreeWidget* parent, App::DocumentObject* obj);
123
124 void init(
125 const std::vector<App::DocumentObject*>& objs,
126 const std::vector<App::DocumentObject*>& excludes
127 );
128
129 void setItemState(App::DocumentObject* obj, Qt::CheckState state, bool forced = false);
130 void updateAllItemState();
131
132 private:
133 Ui_DlgObjectSelection* ui;
134 std::vector<App::DocumentObject*> initSels;
135 std::vector<App::DocumentObject*> deps;
136 std::set<App::DocumentObject*> depSet;
137 std::map<App::SubObjectT, std::vector<QTreeWidgetItem*>> itemMap;
138 std::map<App::SubObjectT, QTreeWidgetItem*> depMap;
139 std::map<App::SubObjectT, QTreeWidgetItem*> inMap;
140 std::map<App::SubObjectT, Qt::CheckState> itemChanged;
141 QTreeWidgetItem* allItem = nullptr;
142
143 QPushButton* useOriginalsBtn;
144 bool returnOriginals = false;
145
146 QTimer timer;
147 ParameterGrp::handle hGrp;
148 };
149
150 } // namespace Gui
151
152 ENABLE_BITMASK_OPERATORS(Gui::DlgObjectSelection::SelectionOptions);
153
154 #endif // GUI_DLGOBJECTSELECTION_H