summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc/snippets/code
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/doc/snippets/code')
-rw-r--r--src/corelib/doc/snippets/code/doc_src_properties.cpp21
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp34
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp7
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_kernel_qmath.cpp63
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_tools_qpoint.cpp14
5 files changed, 137 insertions, 2 deletions
diff --git a/src/corelib/doc/snippets/code/doc_src_properties.cpp b/src/corelib/doc/snippets/code/doc_src_properties.cpp
index 9a25918d47..7a70200cce 100644
--- a/src/corelib/doc/snippets/code/doc_src_properties.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_properties.cpp
@@ -40,8 +40,8 @@
//! [0]
Q_PROPERTY(type name
- READ getFunction
- [WRITE setFunction]
+ (READ getFunction [WRITE setFunction] |
+ MEMBER memberName [(READ getFunction | WRITE setFunction)])
[RESET resetFunction]
[NOTIFY notifySignal]
[REVISION int]
@@ -130,3 +130,20 @@ object->setProperty("priority", "VeryHigh");
//! [7]
Q_CLASSINFO("Version", "3.0.0")
//! [7]
+
+//! [8]
+ Q_PROPERTY(QColor color MEMBER m_color NOTIFY colorChanged)
+ Q_PROPERTY(qreal spacing MEMBER m_spacing NOTIFY spacingChanged)
+ Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged)
+ ...
+signals:
+ void colorChanged();
+ void spacingChanged();
+ void textChanged(const QString &newText);
+
+private:
+ QColor m_color;
+ qreal m_spacing;
+ QString m_text;
+//! [8]
+
diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp
index 2f81b15752..c448c75206 100644
--- a/src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp
@@ -97,3 +97,37 @@ beginResetModel();
myData.clear();
endResetModel();
//! [11]
+
+//! [12]
+class CustomDataProxy : public QSortFilterProxyModel
+{
+ Q_OBJECT
+public:
+ CustomDataProxy(QObject *parent)
+ : QSortFilterProxyModel(parent)
+ {
+ }
+
+ ...
+
+ QVariant data(const QModelIndex &index, int role)
+ {
+ if (role != Qt::BackgroundRole)
+ return QSortFilterProxyModel::data(index, role);
+
+ if (m_customData.contains(index.row()))
+ return m_customData.value(index.row());
+ return QSortFilterProxyModel::data(index, role);
+ }
+
+private slots:
+ void resetInternalData()
+ {
+ m_customData.clear();
+ }
+
+private:
+ QHash<int, QVariant> m_customData;
+};
+//! [12]
+
diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp
index cbb5a9db5d..c349a6dbba 100644
--- a/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp
@@ -57,7 +57,14 @@ foreach (const QString &path, app.libraryPaths())
//! [3]
+// Called once QCoreApplication exists
+static void preRoutineMyDebugTool()
+{
+ MyDebugTool* tool = new MyDebugTool(QCoreApplication::instance());
+ QCoreApplication::instance()->installEventFilter(tool);
+}
+Q_COREAPP_STARTUP_FUNCTION(preRoutineMyDebugTool)
//! [3]
diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qmath.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qmath.cpp
new file mode 100644
index 0000000000..71a2a09a7d
--- /dev/null
+++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qmath.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Laszlo Papp <lpapp@kde.org>
+** Contact: http://www.qt-project.org/legal
+**
+** 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 Digia Plc 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]
+float degrees = 180.0f
+float radians = qDegreesToRadians(degrees)
+//! [0]
+
+
+//! [1]
+double degrees = 180.0
+double radians = qDegreesToRadians(degrees)
+//! [1]
+
+
+//! [2]
+float radians = float(M_PI)
+float degrees = qRadiansToDegrees(radians)
+//! [2]
+
+
+//! [3]
+double radians = M_PI
+double degrees = qRadiansToDegrees(radians)
+//! [3]
+
diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qpoint.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qpoint.cpp
index a83fd9a71f..8c6751cbaa 100644
--- a/src/corelib/doc/snippets/code/src_corelib_tools_qpoint.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_tools_qpoint.cpp
@@ -79,6 +79,13 @@ p *= 2.5; // p becomes (-3, 10)
//! [5]
+//! [16]
+QPoint p( 3, 7);
+QPoint q(-1, 4);
+int lengthSquared = QPoint::dotProduct(p, q); // lengthSquared becomes 25
+//! [16]
+
+
//! [6]
QPoint p(-3, 10);
p /= 2.5; // p becomes (-1, 4)
@@ -147,3 +154,10 @@ p *= 2.5; // p becomes (-2.75, 10.25)
QPointF p(-2.75, 10.25);
p /= 2.5; // p becomes (-1.1, 4.1)
//! [15]
+
+
+//! [17]
+QPointF p( 3.1, 7.1);
+QPointF q(-1.0, 4.1);
+int lengthSquared = QPointF::dotProduct(p, q); // lengthSquared becomes 26.01
+//! [17]