Debian Codegraph @

src/Gui/CallTips.h

raw
1 /***************************************************************************
2 * Copyright (c) 2007 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
24 #ifndef GUI_CALLTIPS_H
25 #define GUI_CALLTIPS_H
26
27 #include <QListWidget>
28
29 class QPlainTextEdit;
30
31 namespace Py
32 {
33 class Object;
34 class List;
35 class String;
36 } // namespace Py
37 namespace Gui
38 {
39
40 class CallTip
41 {
42 public:
43 enum Type
44 {
45 Unknown,
46 Module,
47 Class,
48 Method,
49 Member,
50 Property
51 };
52 QString name;
53 QString description;
54 QString parameter;
55 Type type {Unknown};
56 };
57
58 /**
59 * @author Werner Mayer
60 */
61 class CallTipsList: public QListWidget
62 {
63 Q_OBJECT
64
65 public:
66 /// Construction
67 CallTipsList(QPlainTextEdit* parent);
68 /// Destruction
69 ~CallTipsList() override;
70
71 void keyboardSearch(const QString&) override;
72 void showTips(const QString&);
73 void validateCursor();
74
75 protected:
76 bool eventFilter(QObject*, QEvent*) override;
77 void showEvent(QShowEvent*) override;
78 void hideEvent(QHideEvent*) override;
79
80 private Q_SLOTS:
81 void callTipItemActivated(QListWidgetItem* item);
82
83 private:
84 QString extractContext(const QString&) const;
85 QMap<QString, CallTip> extractTips(const QString&) const;
86 void extractTipsFromObject(Py::Object&, Py::List&, QMap<QString, CallTip>&) const;
87 void extractTipsFromProperties(Py::Object&, QMap<QString, CallTip>&) const;
88 QString stripWhiteSpace(const QString&) const;
89 Py::Object getAttrWorkaround(Py::Object&, Py::String&) const;
90
91 private:
92 QPlainTextEdit* textEdit;
93 int cursorPos;
94 mutable bool validObject;
95 bool doCallCompletion;
96 QList<int> hideKeys;
97 QList<int> compKeys;
98 };
99
100 } // namespace Gui
101
102 #endif // GUI_CALLTIPS_H