/
ExpressionCompleter.h
109 lines (90 loc) · 2.62 KB
/
ExpressionCompleter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#ifndef EXPRESSIONCOMPLETER_H
#define EXPRESSIONCOMPLETER_H
#include <QObject>
#include <QCompleter>
#include <QLineEdit>
#include <QPlainTextEdit>
#include <set>
#include <memory>
#include <App/DocumentObserver.h>
class QStandardItem;
namespace App {
class Document;
class DocumentObject;
class Property;
class ObjectIdentifier;
}
namespace Gui {
/**
* @brief The ExpressionCompleter class extends the QCompleter class to provide a completer model of documentobject names and properties.
*/
class GuiExport ExpressionCompleter : public QCompleter
{
Q_OBJECT
public:
ExpressionCompleter(const App::DocumentObject * currentDocObj,
QObject *parent = 0, bool noProperty = false);
void getPrefixRange(int &start, int &end) const {
start = prefixStart;
end = prefixEnd;
}
void updatePrefixEnd(int end) {
prefixEnd = end;
}
void setDocumentObject(const App::DocumentObject*);
void setNoProperty(bool enabled=true);
public Q_SLOTS:
void slotUpdate(const QString &prefix, int pos);
private:
void init();
virtual QString pathFromIndex ( const QModelIndex & index ) const;
virtual QStringList splitPath ( const QString & path ) const;
int prefixStart = 0;
int prefixEnd = 0;
App::DocumentObjectT currentObj;
bool noProperty;
};
class GuiExport ExpressionLineEdit : public QLineEdit {
Q_OBJECT
public:
ExpressionLineEdit(QWidget *parent = 0, bool noProperty=false);
void setDocumentObject(const App::DocumentObject *currentDocObj);
bool completerActive() const;
void hideCompleter();
void setNoProperty(bool enabled=true);
void setMatchExact(bool enabled=true);
Q_SIGNALS:
void textChanged2(QString text, int pos);
public Q_SLOTS:
void slotTextChanged(const QString & text);
void slotCompleteText(const QString & completionPrefix);
protected:
void keyPressEvent(QKeyEvent * event);
private:
ExpressionCompleter * completer;
bool block;
bool noProperty;
bool matchExact;
};
class GuiExport ExpressionTextEdit : public QPlainTextEdit {
Q_OBJECT
public:
ExpressionTextEdit(QWidget *parent = 0);
void setDocumentObject(const App::DocumentObject *currentDocObj);
bool completerActive() const;
void hideCompleter();
void setMatchExact(bool enabled=true);
protected:
void keyPressEvent(QKeyEvent * event);
Q_SIGNALS:
void textChanged2(QString text, int pos);
public Q_SLOTS:
void slotTextChanged();
void slotCompleteText(const QString & completionPrefix);
private:
ExpressionCompleter * completer;
bool block;
bool matchExact;
};
}
#endif // EXPRESSIONCOMPLETER_H