-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtreemodelcompleter.cpp
43 lines (36 loc) · 968 Bytes
/
treemodelcompleter.cpp
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
#include "treemodelcompleter.h"
TreeModelCompleter::TreeModelCompleter(QObject *parent)
: QCompleter(parent)
{
}
TreeModelCompleter::TreeModelCompleter(QAbstractItemModel *model, QObject *parent)
: QCompleter(model, parent)
{
}
void TreeModelCompleter::setSeparator(const QString &separator)
{
sep = separator;
}
QString TreeModelCompleter::separator() const
{
return sep;
}
QStringList TreeModelCompleter::splitPath(const QString &path) const
{
if (sep.isNull()) {
return QCompleter::splitPath(path);
}
return path.split(sep);
}
QString TreeModelCompleter::pathFromIndex(const QModelIndex &index) const
{
if (sep.isNull()) {
return QCompleter::pathFromIndex(index);
}
// navigate up and accumulate data
QStringList dataList;
for (QModelIndex i = index; i.isValid(); i = i.parent()) {
dataList.prepend(model()->data(i, completionRole()).toString());
}
return dataList.join(sep);
}