Example: migrate treemodelcompleter example to use QRegularExpression
Update the treemodelcompleter example to use the new QRegularExpression class in place of the deprecated QRegExp. Change-Id: I9fa91ca6e847603de37019e4ca86fc69a51a3772 Reviewed-by: Sze Howe Koh <szehowe.koh@gmail.com>
This commit is contained in:
parent
9e933de7f2
commit
2d81968c3b
@ -194,16 +194,17 @@ QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
|
|||||||
if (line.isEmpty() || trimmedLine.isEmpty())
|
if (line.isEmpty() || trimmedLine.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
QRegExp re("^\\s+");
|
QRegularExpression re("^\\s+");
|
||||||
int nonws = re.indexIn(line);
|
QRegularExpressionMatch match = re.match(line);
|
||||||
|
int nonws = match.capturedStart();
|
||||||
int level = 0;
|
int level = 0;
|
||||||
if (nonws == -1) {
|
if (nonws == -1) {
|
||||||
level = 0;
|
level = 0;
|
||||||
} else {
|
} else {
|
||||||
if (line.startsWith("\t")) {
|
if (line.startsWith("\t")) {
|
||||||
level = re.cap(0).length();
|
level = match.capturedLength();
|
||||||
} else {
|
} else {
|
||||||
level = re.cap(0).length()/4;
|
level = match.capturedLength()/4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user