-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistviewstrings.cpp
81 lines (66 loc) · 1.71 KB
/
listviewstrings.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
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
#include "listviewstrings.h"
#include <QRegularExpression>
ListViewStrings::~ListViewStrings()
{
}
QStringListModel *ListViewStrings::getModel()
{
return &model ;
}
ListViewStrings::ListViewStrings(QObject *parent)
{
Q_UNUSED(parent) ;
listtext.clear() ;
listhint.clear() ;
model.setStringList(listtext) ;
}
ListViewStrings::ListViewStrings(ListViewStrings& other)
{
qFatal("FATAL: ListViewStrings copied or not passed to function by ref") ;
}
QModelIndex ListViewStrings::findModelIndex(int idx)
{
return model.index(idx) ;
}
void ListViewStrings::addString(QString resulttext, QString resulthint)
{
listtext.append(resulttext) ;
listhint.append(resulthint) ;
model.setStringList(listtext) ; // Probably not needed
}
void ListViewStrings::clearStrings()
{
listtext.clear() ;
listhint.clear() ;
model.setStringList(listtext) ; // Probably not needed
}
int ListViewStrings::find(QString resulthint)
{
int i ;
for (i=0; i<listhint.size(); i++)
if (listhint.at(i).compare(resulthint)==0) return i ;
return -1 ;
}
// TODO: make this a best match
int ListViewStrings::find(QString resulttext, int startindex)
{
QRegularExpression rx ;
int i=startindex+1 ;
rx.setPattern(".*" + resulttext.toLower() + ".*") ;
while (i<listtext.size()) {
QRegularExpressionMatch match = rx.match(listtext.at(i).toLower()) ;
if (match.hasMatch()) return i ;
i++ ;
}
return -1 ;
}
QString ListViewStrings::stringAt(int index)
{
if (index<0 || index>=listtext.size()) return "" ;
else return listtext.at(index) ;
}
QString ListViewStrings::hintAt(int index)
{
if (index<0 || index>=listhint.size()) return "" ;
else return listhint.at(index) ;
}