Debian Codegraph @

src/Gui/Dialogs/DlgPropertyLink.h

raw
1 /***************************************************************************
2 * Copyright (c) 2014 Werner Mayer <wmayer[at]users.sourceforge.net> *
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 #ifndef GUI_DIALOG_DLGPROPERTYLINK_H
24 #define GUI_DIALOG_DLGPROPERTYLINK_H
25
26 #include <QDialog>
27 #include <QPointer>
28 #include <QPushButton>
29 #include <QTimer>
30 #include "Selection.h"
31
32 #define FC_XLINK_VALUE_INDEX 5
33
34 class QTreeWidgetItem;
35
36 namespace Gui
37 {
38 namespace Dialog
39 {
40
41 class Ui_DlgPropertyLink;
42 class DlgPropertyLink: public QDialog, public Gui::SelectionObserver
43 {
44 Q_OBJECT
45
46 public:
47 explicit DlgPropertyLink(QWidget* parent = nullptr);
48 ~DlgPropertyLink() override;
49
50 void accept() override;
51
52 QList<App::SubObjectT> currentLinks() const;
53 QList<App::SubObjectT> originalLinks() const;
54
55 void init(const App::DocumentObjectT& prop, bool tryFilter = true);
56
57 static QString linksToPython(const QList<App::SubObjectT>& links);
58
59 static QList<App::SubObjectT> getLinksFromProperty(const App::PropertyLinkBase* prop);
60
61 static QString formatObject(App::Document* ownerDoc, App::DocumentObject* obj, const char* sub);
62
63 static inline QString formatObject(App::Document* ownerDoc, const App::SubObjectT& sobj)
64 {
65 return formatObject(ownerDoc, sobj.getObject(), sobj.getSubName().c_str());
66 }
67
68 static QString formatLinks(App::Document* ownerDoc, QList<App::SubObjectT> links);
69
70 protected:
71 void showEvent(QShowEvent*) override;
72 void hideEvent(QHideEvent*) override;
73 void closeEvent(QCloseEvent* e) override;
74 void leaveEvent(QEvent*) override;
75 bool eventFilter(QObject* obj, QEvent* ev) override;
76 void keyPressEvent(QKeyEvent* ev) override;
77
78 void detachObserver();
79 void attachObserver();
80
81 void onSelectionChanged(const Gui::SelectionChanges& msg) override;
82
83 private:
84 void onObjectTypeToggled(bool);
85 void onTypeTreeItemSelectionChanged();
86 void onSearchBoxTextChanged(const QString&);
87 void onItemExpanded(QTreeWidgetItem* item);
88 void onItemSelectionChanged();
89 void onItemEntered(QTreeWidgetItem* item);
90 void onItemSearch();
91 void onTimer();
92 void onClicked(QAbstractButton*);
93
94 private:
95 QTreeWidgetItem* createItem(App::DocumentObject* obj, QTreeWidgetItem* parent);
96 QTreeWidgetItem* createTypeItem(Base::Type type);
97 void filterObjects();
98 void filterItem(QTreeWidgetItem* item);
99 bool filterType(QTreeWidgetItem* item);
100 QTreeWidgetItem* findItem(
101 App::DocumentObject* obj,
102 const char* subname = nullptr,
103 bool* found = nullptr
104 );
105 void itemSearch(const QString& text, bool select);
106 QList<App::SubObjectT> getLinkFromItem(QTreeWidgetItem*, bool needSubName = true) const;
107
108 private:
109 Ui_DlgPropertyLink* ui;
110 QTimer* timer;
111 QPushButton* resetButton;
112 QPushButton* refreshButton;
113
114 QPointer<QWidget> parentView;
115 std::vector<App::SubObjectT> savedSelections;
116
117 App::DocumentObjectT objProp;
118 std::set<App::DocumentObject*> inList;
119 std::map<App::Document*, QTreeWidgetItem*> docItems;
120 std::map<App::DocumentObject*, QTreeWidgetItem*> itemMap;
121 std::map<QByteArray, QTreeWidgetItem*> typeItems;
122 std::set<QTreeWidgetItem*> subSelections;
123 QList<QTreeWidgetItem*> selections;
124 std::set<QByteArray> selectedTypes;
125 QList<App::SubObjectT> oldLinks;
126 bool allowSubObject = false;
127 bool singleSelect = false;
128 bool singleParent = false;
129 App::DocumentObject* currentObj = nullptr;
130 QTreeWidgetItem* searchItem = nullptr;
131 QBrush bgBrush;
132 };
133
134 } // namespace Dialog
135 } // namespace Gui
136
137
138 #endif // GUI_DIALOG_DLGPROPERTYLINK_H