summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-04-20 11:19:14 +0200
committerLiang Qi <liang.qi@qt.io>2017-04-20 12:31:27 +0200
commit7950b6b283549c98f1e0f981c84b68071a13b616 (patch)
treecf7281872045ebd57c68e10064ff0f400084aa13 /examples
parent58d2927861d3e57cac4f6db599e209d2bfb17a2c (diff)
parent0794d61c822585530243f638687b8a75f0a15d0c (diff)
Merge remote-tracking branch 'origin/5.9' into dev
Conflicts: src/corelib/tools/qbytearray.h src/corelib/tools/qdatetime.h src/corelib/tools/qstring.h src/corelib/tools/qversionnumber.h src/plugins/platforms/android/qandroidplatformintegration.cpp tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp Change-Id: Iefd92a435e687a76cd593099e40d9a9620a1454d
Diffstat (limited to 'examples')
-rw-r--r--examples/embedded/flightinfo/flightinfo.cpp11
-rw-r--r--examples/widgets/animation/sub-attaq/graphicsscene.cpp9
-rw-r--r--examples/widgets/doc/src/syntaxhighlighter.qdoc19
-rw-r--r--examples/widgets/richtext/syntaxhighlighter/highlighter.cpp37
-rw-r--r--examples/widgets/richtext/syntaxhighlighter/highlighter.h7
-rw-r--r--examples/xml/rsslisting/rsslisting.cpp4
6 files changed, 44 insertions, 43 deletions
diff --git a/examples/embedded/flightinfo/flightinfo.cpp b/examples/embedded/flightinfo/flightinfo.cpp
index e91277db58..f46fc9693f 100644
--- a/examples/embedded/flightinfo/flightinfo.cpp
+++ b/examples/embedded/flightinfo/flightinfo.cpp
@@ -270,19 +270,18 @@ private:
inFlightStatus |= className == "FlightDetailHeaderStatus";
inFlightMap |= className == "flightMap";
if (xml.name() == "td" && !className.isEmpty()) {
- QString cn = className.toString();
- if (cn.contains("fieldTitle")) {
+ if (className.contains("fieldTitle")) {
inFieldName = true;
fieldNames += QString();
fieldValues += QString();
}
- if (cn.contains("fieldValue"))
+ if (className.contains("fieldValue"))
inFieldValue = true;
}
if (xml.name() == "img" && inFlightMap) {
- QString src = xml.attributes().value("src").toString();
- src.prepend("http://mobile.flightview.com/");
- QUrl url = QUrl::fromPercentEncoding(src.toLatin1());
+ const QByteArray encoded
+ = ("http://mobile.flightview.com/" % xml.attributes().value("src")).toLatin1();
+ QUrl url = QUrl::fromPercentEncoding(encoded);
mapReplies.append(m_manager.get(QNetworkRequest(url)));
}
}
diff --git a/examples/widgets/animation/sub-attaq/graphicsscene.cpp b/examples/widgets/animation/sub-attaq/graphicsscene.cpp
index 44bd5dd12f..e0913f99f6 100644
--- a/examples/widgets/animation/sub-attaq/graphicsscene.cpp
+++ b/examples/widgets/animation/sub-attaq/graphicsscene.cpp
@@ -111,14 +111,15 @@ GraphicsScene::GraphicsScene(int x, int y, int width, int height, Mode mode)
if (reader.name() == "submarine") {
SubmarineDescription desc;
desc.name = reader.attributes().value("name").toString();
- desc.points = reader.attributes().value("points").toString().toInt();
- desc.type = reader.attributes().value("type").toString().toInt();
+ desc.points = reader.attributes().value("points").toInt();
+ desc.type = reader.attributes().value("type").toInt();
submarinesData.append(desc);
} else if (reader.name() == "level") {
- currentLevel.id = reader.attributes().value("id").toString().toInt();
+ currentLevel.id = reader.attributes().value("id").toInt();
currentLevel.name = reader.attributes().value("name").toString();
} else if (reader.name() == "subinstance") {
- currentLevel.submarines.append(qMakePair(reader.attributes().value("type").toString().toInt(), reader.attributes().value("nb").toString().toInt()));
+ currentLevel.submarines.append(qMakePair(reader.attributes().value("type").toInt(),
+ reader.attributes().value("nb").toInt()));
}
} else if (reader.tokenType() == QXmlStreamReader::EndElement) {
if (reader.name() == "level") {
diff --git a/examples/widgets/doc/src/syntaxhighlighter.qdoc b/examples/widgets/doc/src/syntaxhighlighter.qdoc
index 0554f7d9d4..8583d86114 100644
--- a/examples/widgets/doc/src/syntaxhighlighter.qdoc
+++ b/examples/widgets/doc/src/syntaxhighlighter.qdoc
@@ -29,8 +29,8 @@
\example richtext/syntaxhighlighter
\title Syntax Highlighter Example
\ingroup examples-richtext
- \brief The Syntax Highligher example shows how to perform
- simple syntax highlighing.
+ \brief The Syntax Highlighter example shows how to perform
+ simple syntax highlighting.
\brief The Syntax Highlighter example shows how to perform simple syntax
highlighting by subclassing the QSyntaxHighlighter class.
@@ -64,8 +64,9 @@
and define your own highlighting rules.
We have chosen to store our highlighting rules using a private
- struct: A rule consists of a QRegExp pattern and a QTextCharFormat
- instance. The various rules are then stored using a QVector.
+ struct: A rule consists of a QRegularExpression pattern and a
+ QTextCharFormat instance. The various rules are then stored using a
+ QVector.
The QTextCharFormat class provides formatting information for
characters in a QTextDocument specifying the visual properties of
@@ -78,7 +79,7 @@
When subclassing the QSyntaxHighlighter class you must pass the
parent parameter to the base class constructor. The parent is the
- text document upon which the syntax highligning will be
+ text document upon which the syntax highlighting will be
applied. In this example, we have also chosen to define our
highlighting rules in the constructor:
@@ -138,11 +139,11 @@
First we apply the syntax highlighting rules that we stored in the
\c highlightingRules vector. For each rule (i.e. for each
HighlightingRule object) we search for the pattern in the given
- textblock using the QString::indexOf() function. When the first
+ text block using the QString::indexOf() function. When the first
occurrence of the pattern is found, we use the
- QRegExp::matchedLength() function to determine the string that
- will be formatted. QRegExp::matchedLength() returns the length of
- the last matched string, or -1 if there was no match.
+ QRegularExpressionMatch::capturedLength() function to determine the string
+ that will be formatted. QRegularExpressionMatch::capturedLength() returns
+ the length of the last matched string, or 0 if there was no match.
To perform the actual formatting the QSyntaxHighlighter class
provides the \l {QSyntaxHighlighter::setFormat()}{setFormat()}
diff --git a/examples/widgets/richtext/syntaxhighlighter/highlighter.cpp b/examples/widgets/richtext/syntaxhighlighter/highlighter.cpp
index 183708bc06..6c420c328a 100644
--- a/examples/widgets/richtext/syntaxhighlighter/highlighter.cpp
+++ b/examples/widgets/richtext/syntaxhighlighter/highlighter.cpp
@@ -68,9 +68,9 @@ Highlighter::Highlighter(QTextDocument *parent)
<< "\\bslots\\b" << "\\bstatic\\b" << "\\bstruct\\b"
<< "\\btemplate\\b" << "\\btypedef\\b" << "\\btypename\\b"
<< "\\bunion\\b" << "\\bunsigned\\b" << "\\bvirtual\\b"
- << "\\bvoid\\b" << "\\bvolatile\\b";
+ << "\\bvoid\\b" << "\\bvolatile\\b" << "\\bbool\\b";
foreach (const QString &pattern, keywordPatterns) {
- rule.pattern = QRegExp(pattern);
+ rule.pattern = QRegularExpression(pattern);
rule.format = keywordFormat;
highlightingRules.append(rule);
//! [0] //! [1]
@@ -80,14 +80,14 @@ Highlighter::Highlighter(QTextDocument *parent)
//! [2]
classFormat.setFontWeight(QFont::Bold);
classFormat.setForeground(Qt::darkMagenta);
- rule.pattern = QRegExp("\\bQ[A-Za-z]+\\b");
+ rule.pattern = QRegularExpression("\\bQ[A-Za-z]+\\b");
rule.format = classFormat;
highlightingRules.append(rule);
//! [2]
//! [3]
singleLineCommentFormat.setForeground(Qt::red);
- rule.pattern = QRegExp("//[^\n]*");
+ rule.pattern = QRegularExpression("//[^\n]*");
rule.format = singleLineCommentFormat;
highlightingRules.append(rule);
@@ -96,7 +96,7 @@ Highlighter::Highlighter(QTextDocument *parent)
//! [4]
quotationFormat.setForeground(Qt::darkGreen);
- rule.pattern = QRegExp("\".*\"");
+ rule.pattern = QRegularExpression("\".*\"");
rule.format = quotationFormat;
highlightingRules.append(rule);
//! [4]
@@ -104,14 +104,14 @@ Highlighter::Highlighter(QTextDocument *parent)
//! [5]
functionFormat.setFontItalic(true);
functionFormat.setForeground(Qt::blue);
- rule.pattern = QRegExp("\\b[A-Za-z0-9_]+(?=\\()");
+ rule.pattern = QRegularExpression("\\b[A-Za-z0-9_]+(?=\\()");
rule.format = functionFormat;
highlightingRules.append(rule);
//! [5]
//! [6]
- commentStartExpression = QRegExp("/\\*");
- commentEndExpression = QRegExp("\\*/");
+ commentStartExpression = QRegularExpression("/\\*");
+ commentEndExpression = QRegularExpression("\\*/");
}
//! [6]
@@ -119,12 +119,10 @@ Highlighter::Highlighter(QTextDocument *parent)
void Highlighter::highlightBlock(const QString &text)
{
foreach (const HighlightingRule &rule, highlightingRules) {
- QRegExp expression(rule.pattern);
- int index = expression.indexIn(text);
- while (index >= 0) {
- int length = expression.matchedLength();
- setFormat(index, length, rule.format);
- index = expression.indexIn(text, index + length);
+ QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text);
+ while (matchIterator.hasNext()) {
+ QRegularExpressionMatch match = matchIterator.next();
+ setFormat(match.capturedStart(), match.capturedLength(), rule.format);
}
}
//! [7] //! [8]
@@ -134,22 +132,23 @@ void Highlighter::highlightBlock(const QString &text)
//! [9]
int startIndex = 0;
if (previousBlockState() != 1)
- startIndex = commentStartExpression.indexIn(text);
+ startIndex = text.indexOf(commentStartExpression);
//! [9] //! [10]
while (startIndex >= 0) {
//! [10] //! [11]
- int endIndex = commentEndExpression.indexIn(text, startIndex);
- int commentLength;
+ QRegularExpressionMatch match = commentEndExpression.match(text, startIndex);
+ int endIndex = match.capturedStart();
+ int commentLength = 0;
if (endIndex == -1) {
setCurrentBlockState(1);
commentLength = text.length() - startIndex;
} else {
commentLength = endIndex - startIndex
- + commentEndExpression.matchedLength();
+ + match.capturedLength();
}
setFormat(startIndex, commentLength, multiLineCommentFormat);
- startIndex = commentStartExpression.indexIn(text, startIndex + commentLength);
+ startIndex = text.indexOf(commentStartExpression, startIndex + commentLength);
}
}
//! [11]
diff --git a/examples/widgets/richtext/syntaxhighlighter/highlighter.h b/examples/widgets/richtext/syntaxhighlighter/highlighter.h
index 39141615fc..0a24224b56 100644
--- a/examples/widgets/richtext/syntaxhighlighter/highlighter.h
+++ b/examples/widgets/richtext/syntaxhighlighter/highlighter.h
@@ -53,6 +53,7 @@
#include <QSyntaxHighlighter>
#include <QTextCharFormat>
+#include <QRegularExpression>
QT_BEGIN_NAMESPACE
class QTextDocument;
@@ -72,13 +73,13 @@ protected:
private:
struct HighlightingRule
{
- QRegExp pattern;
+ QRegularExpression pattern;
QTextCharFormat format;
};
QVector<HighlightingRule> highlightingRules;
- QRegExp commentStartExpression;
- QRegExp commentEndExpression;
+ QRegularExpression commentStartExpression;
+ QRegularExpression commentEndExpression;
QTextCharFormat keywordFormat;
QTextCharFormat classFormat;
diff --git a/examples/xml/rsslisting/rsslisting.cpp b/examples/xml/rsslisting/rsslisting.cpp
index f532148354..d1b4373531 100644
--- a/examples/xml/rsslisting/rsslisting.cpp
+++ b/examples/xml/rsslisting/rsslisting.cpp
@@ -231,9 +231,9 @@ void RSSListing::parseXml()
} else if (xml.isCharacters() && !xml.isWhitespace()) {
if (currentTag == "title")
- titleString += xml.text().toString();
+ titleString += xml.text();
else if (currentTag == "link")
- linkString += xml.text().toString();
+ linkString += xml.text();
}
}
if (xml.error() && xml.error() != QXmlStreamReader::PrematureEndOfDocumentError) {