diff options
author | João Abecasis <joao.abecasis@nokia.com> | 2012-03-08 01:27:27 +0100 |
---|---|---|
committer | João Abecasis <joao.abecasis@nokia.com> | 2012-03-08 01:27:39 +0100 |
commit | 12f221410fbe41d0b2efda4cd3289dfcf9044aa8 (patch) | |
tree | 897cf6bfb1814b0935982ff5975a6cbfb48d6d9e /doc/src | |
parent | 3d19422ef16a230bb11dbbfe4a8cc9667f39bf15 (diff) | |
parent | 6c612c933803ef57ea45e907d0181b40659148ac (diff) |
Merge remote-tracking branch 'origin/master' into api_changes
Change-Id: I89dc2e193bd01624c1fb50484610d516e39b1538
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/examples/widgets/mousebuttons.qdoc | 94 | ||||
-rw-r--r-- | doc/src/images/widgets/mousebutton-buttontester.png | bin | 0 -> 14492 bytes | |||
-rw-r--r-- | doc/src/network/files-and-resources/datastreamformat.qdoc | 5 | ||||
-rw-r--r-- | doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp | 289 |
4 files changed, 388 insertions, 0 deletions
diff --git a/doc/src/examples/widgets/mousebuttons.qdoc b/doc/src/examples/widgets/mousebuttons.qdoc new file mode 100644 index 0000000000..bf63cd5076 --- /dev/null +++ b/doc/src/examples/widgets/mousebuttons.qdoc @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2012 Rick Stockton <rickstockton@reno-computerhelp.com> +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms +** and conditions contained in a signed written agreement between you +** and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example widgets/mousebuttons/buttontester + \title Mouse Button Tester + + \brief The 'Mouse Button Tester' example demonstrates how to reimplement + mouse events within a custom class. You can also use this program to + verify that Qt is actually receiving mouse events from your mouse. + + Many 'gamer' mouse devices are configured with high-numbered "buttons" + sending text shortcuts for certain games. With such a mouse, no mouse + button events occur: The "mouse" sends keystrokes, and the + 'Mouse Button Tester' Window will not see the event. Receving no event, + it will not repaint the Window with new text describing a \button event. + + And so, in addition to it's use as Qt example code, the program may be + useful s a mouse device tester. Note that there is another example + muouse buttons example which provides the same function, written in QML. + + This program (the Widget-based example) consists of three classes, + in addition to the main() parent program: + + \list + \o \c A QPushButton, "Quit". + \o \c ButtonTester. This is derived from Qt's TextArea class, for + purpose of customizing/re-implementing the mouse and wheel event + member functions. + \o \c A simple QVBoxLayout layout. + \endlist + + First we will review the main program, with it's layout and "Quit" + QPushButton. Then we will take a look at the \c ButtonTester class. + + \section1 The Main Program + + Note that the QPushButton, "Quit", is defined directly within the main() + program, rather than another class. This is a correct way of defining a + "Quit" QPushButton: A "Quit" Button defined inside another + class would result in the destructor of that second class being + called twice. This "Quit" Button uses the traditional Signal/Slot + connection to invoke termination of the QApp, which will properly destroy + its child classes \before terminating itself. + + The remainder of the main() program is concerned with defining the layout, + and applying a minimum size to the customized ButtonTester. + + \section1 ButtonTester Class Definition + + The \c ButtonTester class inherits from QTextEdit, and listens for + mouse events on all possible Qt::MouseButton values. It also listens for + wheel events from the mouse, and indicates the direction of wheel motion + ("up", down", "left", or "right"). It prints short debug messages into + the Window, and also on the console QDebug() stream, when mouse button + and wheel events occur. Our reimplementation of mousePressEvent(), + mouseReleaseEvent(), mouseDoubleClickEvent(), and wheelEvent() "drive" + the program; the other functions simply convert the Qt::MouseButton + values into text strings. + + You should call the ignore() function on any mouse event (or other event) + which your widget-based classes do not use and consume. This function + assures that Qt will propagate the event through each parent widget, + until it is used or propagated to the Window Manager. (Qt attempts to do + this automatically, but it is better programming practice to explicitly + invoke the function.) + + \image widgets/mousebutton-buttontester.png +*/ diff --git a/doc/src/images/widgets/mousebutton-buttontester.png b/doc/src/images/widgets/mousebutton-buttontester.png Binary files differnew file mode 100644 index 0000000000..82fcb7617f --- /dev/null +++ b/doc/src/images/widgets/mousebutton-buttontester.png diff --git a/doc/src/network/files-and-resources/datastreamformat.qdoc b/doc/src/network/files-and-resources/datastreamformat.qdoc index 17a0044a69..8ff31371a2 100644 --- a/doc/src/network/files-and-resources/datastreamformat.qdoc +++ b/doc/src/network/files-and-resources/datastreamformat.qdoc @@ -298,6 +298,11 @@ \li Regular expression syntax (quint8) \li Minimal matching (quint8) \endlist + \row \li QRegularExpression + \li \list + \li The regular expression pattern (QString) + \li The pattern options (quint32) + \endlist \row \li QRegion \li \list \li The size of the data, i.e. 8 + 16 * (number of rectangles) (quint32) diff --git a/doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp b/doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp new file mode 100644 index 0000000000..cab89d9c9e --- /dev/null +++ b/doc/src/snippets/code/src_corelib_tools_qregularexpression.cpp @@ -0,0 +1,289 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Giuseppe D'Angelo <dangelog@gmail.com>. +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QRegularExpression re("a pattern"); +//! [0] + + +//! [1] +QRegularExpression re; +re.setPattern("another pattern"); +//! [1] + + +//! [2] +// matches two digits followed by a space and a word +QRegularExpression re("\\d\\d \\w+"); + +// matches a backslash +QRegularExpression re2("\\\\"); +//! [2] + + +//! [3] +QRegularExpression re("a third pattern"); +QString pattern = re.pattern(); // pattern == "a third pattern" +//! [3] + + +//! [4] +// matches "Qt rocks", but also "QT rocks", "QT ROCKS", "qT rOcKs", etc. +QRegularExpression re("Qt rocks", QRegularExpression::CaseInsensitiveOption); +//! [4] + + +//! [5] +QRegularExpression re("^\\d+$"); +re.setPatternOptions(QRegularExpression::MultilineOption); +// re matches any line in the subject string that contains only digits (but at least one) +//! [5] + + +//! [6] +QRegularExpression re = QRegularExpression("^two.*words$", QRegularExpression::MultilineOption + | QRegularExpression::DotMatchesEverythingOption); + +QRegularExpression::PatternOptions options = re.patternOptions(); +// options == QRegularExpression::MultilineOption | QRegularExpression::DotMatchesEverythingOption +//! [6] + + +//! [7] +// match two digits followed by a space and a word +QRegularExpression re("\\d\\d \\w+"); +QRegularExpressionMatch match = re.match("abc123 def"); +bool hasMatch = match.hasMatch(); // true +//! [7] + + +//! [8] +QRegularExpression re("\\d\\d \\w+"); +QRegularExpressionMatch match = re.match("abc123 def"); +if (match.hasMatch()) { + QString matched = match.captured(0); // matched == "23 def" + // ... +} +//! [8] + + +//! [9] +QRegularExpression re("\\d\\d \\w+"); +QRegularExpressionMatch match = re.match("12 abc 45 def", 1); +if (match.hasMatch()) { + QString matched = match.captured(0); // matched == "45 def" + // ... +} +//! [9] + + +//! [10] +QRegularExpression re("^(\\d\\d)/(\\d\\d)/(\\d\\d\\d\\d)$"); +QRegularExpressionMatch match = re.match("08/12/1985"); +if (match.hasMatch()) { + QString day = re.captured(1); // day == "08" + QString month = re.captured(2); // month == "12" + QString year = re.captured(3); // year == "1985" + // ... +} +//! [10] + + +//! [11] +QRegularExpression re("abc(\\d+)def"); +QRegularExpressionMatch match = re.match("XYZabc123defXYZ"); +if (match.hasMatch()) { + int startOffset = re.capturedStart(1); // startOffset == 6 + int endOffset = re.capturedEnd(1); // endOffset == 9 + // ... +} +//! [11] + + +//! [12] +QRegularExpression re("^(?<date>\\d\\d)/(?<month>\\d\\d)/(?<year>\\d\\d\\d\\d)$"); +QRegularExpressionMatch match = re.match("08/12/1985"); +if (match.hasMatch()) { + QString date = match.captured("date"); // date == "08" + QString month = match.captured("month"); // month == "12" + QString year = match.captured("year"); // year == 1985 +} +//! [12] + + +//! [13] +QRegularExpression re("(\\w+)"); +QRegularExpressionMatchIterator i = re.globalMatch("the quick fox"); +//! [13] + + +//! [14] +QStringList words; +while (i.hasNext()) { + QRegularExpressionMatch match = i.next(); + QString word = match.captured(1); + words << word; +} +// words contains "the", "quick", "fox" +//! [14] + + +//! [15] +QString pattern("^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \\d\\d?, \\d\\d\\d\\d$"); +QRegularExpression re(pattern); + +QString input("Jan 21,"); +QRegularExpressionMatch match = re.match(input, 0, QRegularExpressionMatch::PartialPreferCompleteMatch); +bool hasMatch = match.hasMatch(); // false +bool hasPartialMatch = match.hasPartialMatch(); // true +//! [15] + + +//! [16] +QString input("Dec 8, 1985"); +QRegularExpressionMatch match = re.match(input, 0, QRegularExpressionMatch::PartialPreferCompleteMatch); +bool hasMatch = match.hasMatch(); // true +bool hasPartialMatch = match.hasPartialMatch(); // false +//! [16] + + +//! [17] +QRegularExpression re("abc\\w+X|def"); +QRegularExpressionMatch match = re.match("abcdef", 0, QRegularExpressionMatch::PartialPreferCompleteMatch); +bool hasMatch = match.hasMatch(); // true +bool hasPartialMatch = match.hasPartialMatch(); // false +QString captured = match.captured(0); // captured == "def" +//! [17] + + +//! [18] +QRegularExpression re("abc\\w+X|defY"); +QRegularExpressionMatch match = re.match("abcdef", 0, QRegularExpressionMatch::PartialPreferCompleteMatch); +bool hasMatch = match.hasMatch(); // false +bool hasPartialMatch = match.hasPartialMatch(); // true +QString captured = match.captured(0); // captured == "abcdef" +//! [18] + + +//! [19] +QRegularExpression re("abc|ab"); +QRegularExpressionMatch match = re.match("ab", 0, QRegularExpressionMatch::PartialPreferFirstMatch); +bool hasMatch = match.hasMatch(); // false +bool hasPartialMatch = match.hasPartialMatch(); // true +//! [19] + + +//! [20] +QRegularExpression re("abc(def)?"); +QRegularExpressionMatch match = re.match("abc", 0, QRegularExpressionMatch::PartialPreferFirstMatch); +bool hasMatch = match.hasMatch(); // false +bool hasPartialMatch = match.hasPartialMatch(); // true +//! [20] + +//! [21] +QRegularExpression re("(abc)*"); +QRegularExpressionMatch match = re.match("abc", 0, QRegularExpressionMatch::PartialPreferFirstMatch); +bool hasMatch = match.hasMatch(); // false +bool hasPartialMatch = match.hasPartialMatch(); // true +//! [21] + +//! [22] +QRegularExpression invalidRe("(unmatched|parenthesis"); +bool isValid = invalidRe.isValid(); // false +//! [22] + +//! [23] +QRegularExpression invalidRe("(unmatched|parenthesis"); +if (!invalidRe.isValid()) { + QString errorString = invalidRe.errorString(); // errorString == "missing )" + int errorOffset = invalidRe.patternErrorOffset(); // errorOffset == 22 + // ... +} +//! [23] + +//! [24] +QRegularExpression re("^this pattern must match exactly$"); +//! [24] + +//! [25] +QString p("a .*|pattern"); +QRegularExpression re("\\A(?:" + p + ")\\z"); // re matches exactly the pattern string p +//! [25] + +//! [26] +QString escaped = QRegularExpression::escape("a(x) = f(x) + g(x)"); +// escaped == "a\\(x\\)\\ \\=\\ f\\(x\\)\\ \\+\\ g\\(x\\)" +//! [26] + +//! [27] +QString pattern = "(" + QRegularExpression::escape(name) + + "|" + QRegularExpression::escape(nickname) + ")"; +QRegularExpression re(pattern); +//! [27] + +//! [28] +QRegularExpressionMatch match = re.match(...); +for (int i = 0; i <= match.lastCapturedIndex(); ++i) { + QString captured = match.captured(i); + // ... +} +//! [28] + +//! [29] +QRegularExpression("(\d\d) (?<name>\w+)"); +QRegularExpressionMatch match = re.match("23 Jordan"); +if (match.hasMatch()) { + QString number = match.captured(1); // first == "23" + QString name = match.captured("name"); // name == "Jordan" +} +//! [29] + +//! [30] +// extracts the words +QRegularExpression re("(\w+)"); +QString subject("the quick fox"); +QRegularExpressionMatchIterator i = re.globalMatch(subject); +while (i.hasNext()) { + QRegularExpressionMatch match = i.next(); + // ... +} +//! [30] + + |