diff options
author | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2017-05-22 16:44:51 +0200 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2017-05-22 18:24:16 +0200 |
commit | 77faaf1757c2054adf6a13ff1025621bb86a3934 (patch) | |
tree | beced043dde3f9da5927c20112921d4732b2a03e /sources/pyside2/doc/codesnippets/doc/src/snippets/code | |
parent | d4112e4a6ea25aee831da3cd123f139b5f7229bf (diff) |
move everying into sources/pyside2 (dev edition)
in preparation for a subtree merge.
this should not be necessary to do in a separate commit, but git is a
tad stupid about following history correctly without it.
Diffstat (limited to 'sources/pyside2/doc/codesnippets/doc/src/snippets/code')
222 files changed, 20826 insertions, 0 deletions
diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/doc_src_qnamespace.qdoc b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/doc_src_qnamespace.qdoc new file mode 100644 index 000000000..5a9a2f49d --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/doc_src_qnamespace.qdoc @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +QObject::connect: Cannot queue arguments of type 'MyType' +//! [0] + + +//! [1] +# An important event +ImportantEventPriority = Qt.HighEventPriority +# A more important event +MoreImportantEventPriority = ImportantEventPriority + 1 +# A critical event +CriticalEventPriority = 100 * MoreImportantEventPriority +# Not that important +StatusEventPriority = Qt.LowEventPriority +# These are less important than Status events +IdleProcessingDoneEventPriority = StatusEventPriority - 1 +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.gui.text.qtextdocumentwriter.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.gui.text.qtextdocumentwriter.cpp new file mode 100644 index 000000000..19de66485 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.gui.text.qtextdocumentwriter.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + writer = QTextDocumentWriter() + writer.setFormat("odf") # same as writer.setFormat("ODF"); +//! [0] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.qdbus.qdbuspendingcall.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.qdbus.qdbuspendingcall.cpp new file mode 100644 index 000000000..f9f12b147 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.qdbus.qdbuspendingcall.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + QDBusPendingCall async = iface->asyncCall("RemoteMethod", value1, value2); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); + + QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SLOT(callFinishedSlot(QDBusPendingCallWatcher*))); +//! [0] + +} + +//! [1] +void MyClass::callFinishedSlot(QDBusPendingCallWatcher *call) +{ + QDBusPendingReply<QString, QByteArray> reply = *call; + if (reply.isError()) { + showError(); + } else { + QString text = reply.argumentAt<0>(); + QByteArray data = reply.argumentAt<1>(); + showReply(text, data); + } +} +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.qdbus.qdbuspendingreply.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.qdbus.qdbuspendingreply.cpp new file mode 100644 index 000000000..39afcc8f5 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.qdbus.qdbuspendingreply.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + QDBusPendingReply<QString> reply = interface->asyncCall("RemoteMethod"); + reply.waitForFinished(); + if (reply.isError()) + // call failed. Show an error condition. + showError(reply.error()); + else + // use the returned value + useValue(reply.value()); +//! [0] + +//! [2] + QDBusPendingReply<bool, QString> reply = interface->asyncCall("RemoteMethod"); + reply.waitForFinished(); + if (!reply.isError()) { + if (reply.argumentAt<0>()) + showSuccess(reply.argumentAt<1>()); + else + showFailure(reply.argumentAt<1>()); + } +//! [2] +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.scripttools.qscriptenginedebugger.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.scripttools.qscriptenginedebugger.cpp new file mode 100644 index 000000000..2971f244b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.scripttools.qscriptenginedebugger.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + engine = QScriptEngine() + debugger = QScriptEngineDebugger() + debugger.attachTo(engine) +//! [0] + +//! [1] + engine.evaluate("debugger") +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_codecs_qtextcodec.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_codecs_qtextcodec.cpp new file mode 100644 index 000000000..cf6bc2894 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_codecs_qtextcodec.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +encodedString = QByteArray("...") +codec = QTextCodec.codecForName("KOI8-R") +string = codec.toUnicode(encodedString) +//! [0] + + +//! [1] +string = u"..." +codec = QTextCodec.codecForName("KOI8-R") +encodedString = codec.fromUnicode(string) +//! [1] + + +//! [2] +codec = QTextCodec.codecForName("Shift-JIS") +decoder = codec.makeDecoder() + +string = u'' +while new_data_available(): + chunk = get_new_data() + string += decoder.toUnicode(chunk) + +//! [2] + + +//! [3] +def main(): + app = QApplication([]) + QTextCodec.setCodecForTr(QTextCodec.codecForName("eucKR")) + ... +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_codecs_qtextcodecplugin.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_codecs_qtextcodecplugin.cpp new file mode 100644 index 000000000..ce3f07148 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_codecs_qtextcodecplugin.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + +def names(self): + return list = ["IBM01140", "hp15-tw"] + +def createForName(name): + if (name == "IBM01140"): + return Ibm01140Codec() + else if (name == "hp15-tw"): + return Hp15TwCodec() + return None +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qfuture.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qfuture.cpp new file mode 100644 index 000000000..72f998f43 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qfuture.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +QFuture<QString> future = ...; + +QFuture<QString>::const_iterator i; +for (i = future.constBegin(); i != future.constEnd(); ++i) + cout << *i << endl; +//! [0] + + +//! [1] +QFuture<QString> future; +... +QFutureIterator<QString> i(future); +while (i.hasNext()) + qDebug() << i.next(); +//! [1] + + +//! [2] +QFutureIterator<QString> i(future); +i.toBack(); +while (i.hasPrevious()) + qDebug() << i.previous(); +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qfuturesynchronizer.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qfuturesynchronizer.cpp new file mode 100644 index 000000000..7bcf8437f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qfuturesynchronizer.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +void someFunction() +{ + QFutureSynchronizer<void> synchronizer; + + ... + + synchronizer.addFuture(QtConcurrent::run(anotherFunction)); + synchronizer.addFuture(QtConcurrent::map(list, mapFunction)); + + return; // QFutureSynchronizer waits for all futures to finish +} +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qfuturewatcher.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qfuturewatcher.cpp new file mode 100644 index 000000000..c18c98a71 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qfuturewatcher.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +// Instantiate the objects and connect to the finished signal. +MyClass myObject; +QFutureWatcher<int> watcher; +connect(&watcher, SIGNAL(finished()), &myObject, SLOT(handleFinished())); + +// Start the computation. +QFuture<int> future = QtConcurrent::run(...); +watcher.setFuture(future); +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentexception.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentexception.cpp new file mode 100644 index 000000000..e813afd58 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentexception.cpp @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + +class MyException : public QtConcurrent::Exception +{ +public: + void raise() const { throw *this; } + Exception *clone() const { return new MyException(*this); } +}; + +//! [0] + + +//! [1] + +try { + QtConcurrent::blockingMap(list, throwFunction); // throwFunction throws MyException +} catch (MyException &e) { + // handle exception +} + +//! [1] + + +//! [2] + +void MyException::raise() const { throw *this; } + +//! [2] + + +//! [3] + +MyException *MyException::clone() const { return new MyException(*this); } + +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp new file mode 100644 index 000000000..fbfe131ee --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp @@ -0,0 +1,181 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +bool function(const T &t); +//! [0] + + +//! [1] +bool allLowerCase(const QString &string) +{ + return string.lowered() == string; +} + +QStringList strings = ...; +QFuture<QString> lowerCaseStrings = QtConcurrent::filtered(strings, allLowerCase); +//! [1] + + +//! [2] +QStringList strings = ...; +QFuture<void> future = QtConcurrent::filter(strings, allLowerCase); +//! [2] + + +//! [3] +V function(T &result, const U &intermediate) +//! [3] + + +//! [4] +void addToDictionary(QSet<QString> &dictionary, const QString &string) +{ + dictionary.insert(string); +} + +QStringList strings = ...; +QFuture<QSet<QString> > dictionary = QtConcurrent::filteredReduced(strings, allLowerCase, addToDictionary); +//! [4] + + +//! [5] +QStringList strings = ...; +QFuture<QString> lowerCaseStrings = QtConcurrent::filtered(strings.constBegin(), strings.constEnd(), allLowerCase); + +// filter in-place only works on non-const iterators +QFuture<void> future = QtConcurrent::filter(strings.begin(), strings.end(), allLowerCase); + +QFuture<QSet<QString> > dictionary = QtConcurrent::filteredReduced(strings.constBegin(), strings.constEnd(), allLowerCase, addToDictionary); +//! [5] + + +//! [6] +QStringList strings = ...; + +// each call blocks until the entire operation is finished +QStringList lowerCaseStrings = QtConcurrent::blockingFiltered(strings, allLowerCase); + + +QtConcurrent::blockingFilter(strings, allLowerCase); + +QSet<QString> dictionary = QtConcurrent::blockingFilteredReduced(strings, allLowerCase, addToDictionary); +//! [6] + + +//! [7] +// keep only images with an alpha channel +QList<QImage> images = ...; +QFuture<void> alphaImages = QtConcurrent::filter(strings, &QImage::hasAlphaChannel); + +// keep only gray scale images +QList<QImage> images = ...; +QFuture<QImage> grayscaleImages = QtConcurrent::filtered(images, &QImage::isGrayscale); + +// create a set of all printable characters +QList<QChar> characters = ...; +QFuture<QSet<QChar> > set = QtConcurrent::filteredReduced(characters, &QChar::isPrint, &QSet<QChar>::insert); +//! [7] + + +//! [8] +// can mix normal functions and member functions with QtConcurrent::filteredReduced() + +// create a dictionary of all lower cased strings +extern bool allLowerCase(const QString &string); +QStringList strings = ...; +QFuture<QSet<int> > averageWordLength = QtConcurrent::filteredReduced(strings, allLowerCase, QSet<QString>::insert); + +// create a collage of all gray scale images +extern void addToCollage(QImage &collage, const QImage &grayscaleImage); +QList<QImage> images = ...; +QFuture<QImage> collage = QtConcurrent::filteredReduced(images, &QImage::isGrayscale, addToCollage); +//! [8] + + +//! [9] +bool QString::contains(const QRegExp ®exp) const; +//! [9] + + +//! [10] +boost::bind(&QString::contains, QRegExp("^\\S+$")); // matches strings without whitespace +//! [10] + + +//! [11] +bool contains(const QString &string) +//! [11] + + +//! [12] +QStringList strings = ...; +boost::bind(static_cast<bool(QString::*)(const QRegExp&)>( &QString::contains ), QRegExp("..." )); +//! [12] + +//! [13] +struct StartsWith +{ + StartsWith(const QString &string) + : m_string(string) { } + + typedef bool result_type; + + bool operator()(const QString &testString) + { + return testString.startsWith(m_string); + } + + QString m_string; +}; + +QList<QString> strings = ...; +QFuture<QString> fooString = QtConcurrent::filtered(images, StartsWith(QLatin1String("Foo"))); +//! [13] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp new file mode 100644 index 000000000..c422d5a9a --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp @@ -0,0 +1,194 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +U function(const T &t); +//! [0] + + +//! [1] +QImage scaled(const QImage &image) +{ + return image.scaled(100, 100); +} + +QList<QImage> images = ...; +QFuture<QImage> thumbnails = QtConcurrent::mapped(images, scaled); +//! [1] + + +//! [2] +U function(T &t); +//! [2] + + +//! [3] +void scale(QImage &image) +{ + image = image.scaled(100, 100); +} + +QList<QImage> images = ...; +QFuture<void> future = QtConcurrent::map(images, scale); +//! [3] + + +//! [4] +V function(T &result, const U &intermediate) +//! [4] + + +//! [5] +void addToCollage(QImage &collage, const QImage &thumbnail) +{ + QPainter p(&collage); + static QPoint offset = QPoint(0, 0); + p.drawImage(offset, thumbnail); + offset += ...; +} + +QList<QImage> images = ...; +QFuture<QImage> collage = QtConcurrent::mappedReduced(images, scaled, addToCollage); +//! [5] + + +//! [6] +QList<QImage> images = ...; + +QFuture<QImage> thumbnails = QtConcurrent::mapped(images.constBegin(), images.constEnd(), scaled); + +// map in-place only works on non-const iterators +QFuture<void> future = QtConcurrent::map(images.begin(), images.end(), scale); + +QFuture<QImage> collage = QtConcurrent::mappedReduced(images.constBegin(), images.constEnd(), scaled, addToCollage); +//! [6] + + +//! [7] +QList<QImage> images = ...; + +// each call blocks until the entire operation is finished +QList<QImage> future = QtConcurrent::blockingMapped(images, scaled); + +QtConcurrent::blockingMap(images, scale); + +QImage collage = QtConcurrent::blockingMappedReduced(images, scaled, addToCollage); +//! [7] + + +//! [8] +// squeeze all strings in a QStringList +QStringList strings = ...; +QFuture<void> squeezedStrings = QtConcurrent::map(strings, &QString::squeeze); + +// swap the rgb values of all pixels on a list of images +QList<QImage> images = ...; +QFuture<QImage> bgrImages = QtConcurrent::mapped(images, &QImage::rgbSwapped); + +// create a set of the lengths of all strings in a list +QStringList strings = ...; +QFuture<QSet<int> > wordLengths = QtConcurrent::mappedReduced(string, &QString::length, &QSet<int>::insert); +//! [8] + + +//! [9] +// can mix normal functions and member functions with QtConcurrent::mappedReduced() + +// compute the average length of a list of strings +extern void computeAverage(int &average, int length); +QStringList strings = ...; +QFuture<int> averageWordLength = QtConcurrent::mappedReduced(strings, &QString::length, computeAverage); + +// create a set of the color distribution of all images in a list +extern int colorDistribution(const QImage &string); +QList<QImage> images = ...; +QFuture<QSet<int> > totalColorDistribution = QtConcurrent::mappedReduced(images, colorDistribution, QSet<int>::insert); +//! [9] + + +//! [10] +QImage QImage::scaledToWidth(int width, Qt::TransformationMode) const; +//! [10] + + +//! [11] +boost::bind(&QImage::scaledToWidth, 100, Qt::SmoothTransformation) +//! [11] + + +//! [12] +QImage scaledToWith(const QImage &image) +//! [12] + + +//! [13] +QList<QImage> images = ...; +QFuture<QImage> thumbnails = QtConcurrent::mapped(images, boost::bind(&QImage::scaledToWidth, 100 Qt::SmoothTransformation)); +//! [13] + +//! [14] +struct Scaled +{ + Scaled(int size) + : m_size(size) { } + + typedef QImage result_type; + + QImage operator()(const QImage &image) + { + return image.scaled(m_size, m_size); + } + + int m_size; +}; + +QList<QImage> images = ...; +QFuture<QImage> thumbnails = QtConcurrent::mapped(images, Scaled(100)); +//! [14] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentrun.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentrun.cpp new file mode 100644 index 000000000..5dcc8c991 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentrun.cpp @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +extern void aFunction(); +QFuture<void> future = QtConcurrent::run(aFunction); +//! [0] + + +//! [1] +extern void aFunctionWithArguments(int arg1, double arg2, const QString &string); + +int integer = ...; +double floatingPoint = ...; +QString string = ...; + +QFuture<void> future = QtConcurrent::run(aFunctionWithArguments, integer, floatingPoint, string); +//! [1] + + +//! [2] +extern QString functionReturningAString(); +QFuture<QString> future = QtConcurrent::run(functionReturningAString); +... +QString result = future.result(); +//! [2] + + +//! [3] +extern QString someFunction(const QByteArray &input); + +QByteArray bytearray = ...; + +QFuture<QString> future = QtConcurrent::run(someFunction, bytearray); +... +QString result = future.result(); +//! [3] + + +//! [4] +// call 'QStringList QString::split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const' in a separate thread +QString string = ...; +QFuture<QStringList> future = QtConcurrent::run(string, &QString::split, QString(", "), QString::KeepEmptyParts, Qt::CaseSensitive); +... +QStringList result = future.result(); +//! [4] + + +//! [5] +// call 'void QImage::invertPixels(InvertMode mode)' in a separate thread +QImage image = ...; +QFuture<void> future = QtConcurrent::run(image, &QImage::invertPixels, QImage::InvertRgba); +... +future.waitForFinished(); +// At this point, the pixels in 'image' have been inverted +//! [5] + + +//! [6] +void someFunction(int arg1, double arg2); +QFuture<void> future = QtConcurrent::run(boost::bind(someFunction, 1, 2.0)); +... +//! [6] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qthreadpool.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qthreadpool.cpp new file mode 100644 index 000000000..73b713536 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qthreadpool.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +class HelloWorldTask(QRunnable): + def run(self): + print "Hello world from thread", QThread.currentThread() + +hello = HelloWorldTask() +# QThreadPool takes ownership and deletes 'hello' automatically +QThreadPool.globalInstance().start(hello) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_global_qglobal.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_global_qglobal.cpp new file mode 100644 index 000000000..6b39702ac --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_global_qglobal.cpp @@ -0,0 +1,514 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +label.setAlignment(Qt.AlignLeft | Qt.AlignTop) +//! [0] + + +//! [1] +class MyClass +{ +public: + enum Option { + NoOptions = 0x0, + ShowTabs = 0x1, + ShowAll = 0x2, + SqueezeBlank = 0x4 + }; + Q_DECLARE_FLAGS(Options, Option) + ... +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS(MyClass::Options) +//! [1] + +//! [meta-object flags] +Q_FLAGS(Options) +//! [meta-object flags] + +//! [2] +typedef QFlags<Enum> Flags; +//! [2] + + +//! [3] +int myValue = 10; +int minValue = 2; +int maxValue = 6; + +int boundedValue = qBound(minValue, myValue, maxValue); +// boundedValue == 6 +//! [3] + + +//! [4] +if (!driver()->isOpen() || driver()->isOpenError()) { + qWarning("QSqlQuery::exec: database not open"); + return false; +} +//! [4] + + +//! [5] +qint64 value = Q_INT64_C(932838457459459); +//! [5] + + +//! [6] +quint64 value = Q_UINT64_C(932838457459459); +//! [6] + + +//! [7] +void myMsgHandler(QtMsgType, const char *); +//! [7] + + +//! [8] +qint64 value = Q_INT64_C(932838457459459); +//! [8] + + +//! [9] +quint64 value = Q_UINT64_C(932838457459459); +//! [9] + + +//! [10] +myValue = -4 +absoluteValue = qAbs(myValue) +// absoluteValue == 4 +//! [10] + + +//! [11] +valueA = 2.3 +valueB = 2.7 + +roundedValueA = qRound(valueA) +// roundedValueA = 2 +roundedValueB = qRound(valueB) +// roundedValueB = 3 +//! [11] + + +//! [12] +valueA = 42949672960.3 +valueB = 42949672960.7 + +roundedValueA = qRound(valueA) +// roundedValueA = 42949672960 +roundedValueB = qRound(valueB) +// roundedValueB = 42949672961 +//! [12] + + +//! [13] +myValue = 6 +yourValue = 4 + +minValue = qMin(myValue, yourValue) +// minValue == yourValue +//! [13] + + +//! [14] +myValue = 6 +yourValue = 4 + +maxValue = qMax(myValue, yourValue) +// maxValue == myValue +//! [14] + + +//! [15] +myValue = 10 +minValue = 2 +maxValue = 6 + +boundedValue = qBound(minValue, myValue, maxValue) +// boundedValue == 6 +//! [15] + + +//! [16] +#if QT_VERSION >= 0x040100 + QIcon icon = style()->standardIcon(QStyle::SP_TrashIcon); +#else + QPixmap pixmap = style()->standardPixmap(QStyle::SP_TrashIcon); + QIcon icon(pixmap); +#endif +//! [16] + + +//! [17] +// File: div.cpp + +#include <QtGlobal> + +int divide(int a, int b) +{ + Q_ASSERT(b != 0); + return a / b; +} +//! [17] + + +//! [18] +ASSERT: "b == 0" in file div.cpp, line 7 +//! [18] + + +//! [19] +// File: div.cpp + +#include <QtGlobal> + +int divide(int a, int b) +{ + Q_ASSERT_X(b != 0, "divide", "division by zero"); + return a / b; +} +//! [19] + + +//! [20] +ASSERT failure in divide: "division by zero", file div.cpp, line 7 +//! [20] + + +//! [21] +int *a; + +Q_CHECK_PTR(a = new int[80]); // WRONG! + +a = new (nothrow) int[80]; // Right +Q_CHECK_PTR(a); +//! [21] + + +//! [22] +template<typename TInputType> +const TInputType &myMin(const TInputType &value1, const TInputType &value2) +{ + qDebug() << Q_FUNC_INFO << "was called with value1:" << value1 << "value2:" << value2; + + if(value1 < value2) + return value1; + else + return value2; +} +//! [22] + + +//! [23] +#include <qapplication.h> +#include <stdio.h> +#include <stdlib.h> + +void myMessageOutput(QtMsgType type, const char *msg) +{ + switch (type) { + case QtDebugMsg: + fprintf(stderr, "Debug: %s\n", msg); + break; + case QtWarningMsg: + fprintf(stderr, "Warning: %s\n", msg); + break; + case QtCriticalMsg: + fprintf(stderr, "Critical: %s\n", msg); + break; + case QtFatalMsg: + fprintf(stderr, "Fatal: %s\n", msg); + abort(); + } +} + +int main(int argc, char **argv) +{ + qInstallMsgHandler(myMessageOutput); + QApplication app(argc, argv); + ... + return app.exec(); +} +//! [23] + + +//! [24] +qDebug("Items in list: %d", myList.size()); +//! [24] + + +//! [25] +qDebug() << "Brush:" << myQBrush << "Other value:" << i; +//! [25] + + +//! [26] +void f(int c) +{ + if (c > 200) + qWarning("f: bad argument, c == %d", c); +} +//! [26] + + +//! [27] +qWarning() << "Brush:" << myQBrush << "Other value:" +<< i; +//! [27] + + +//! [28] +void load(const QString &fileName) +{ + QFile file(fileName); + if (!file.exists()) + qCritical("File '%s' does not exist!", qPrintable(fileName)); +} +//! [28] + + +//! [29] +qCritical() << "Brush:" << myQBrush << "Other +value:" << i; +//! [29] + + +//! [30] +int divide(int a, int b) +{ + if (b == 0) // program error + qFatal("divide: cannot divide by zero"); + return a / b; +} +//! [30] + + +//! [31] +forever { + ... +} +//! [31] + + +//! [32] +CONFIG += no_keywords +//! [32] + + +//! [33] +CONFIG += no_keywords +//! [33] + + +//! [34] +QString FriendlyConversation::greeting(int type) +{ +static const char *greeting_strings[] = { + QT_TR_NOOP("Hello"), + QT_TR_NOOP("Goodbye") +}; +return tr(greeting_strings[type]); +} +//! [34] + + +//! [35] +static const char *greeting_strings[] = { + QT_TRANSLATE_NOOP("FriendlyConversation", "Hello"), + QT_TRANSLATE_NOOP("FriendlyConversation", "Goodbye") +}; + +QString FriendlyConversation::greeting(int type) +{ + return tr(greeting_strings[type]); +} + +QString global_greeting(int type) +{ + return qApp->translate("FriendlyConversation", + greeting_strings[type]); +} +//! [35] + + +//! [36] + +static { const char *source; const char *comment; } greeting_strings[] = +{ + QT_TRANSLATE_NOOP3("FriendlyConversation", "Hello", + "A really friendly hello"), + QT_TRANSLATE_NOOP3("FriendlyConversation", "Goodbye", + "A really friendly goodbye") +}; + +QString FriendlyConversation::greeting(int type) +{ + return tr(greeting_strings[type].source, + greeting_strings[type].comment); +} + +QString global_greeting(int type) +{ + return qApp->translate("FriendlyConversation", + greeting_strings[type].source, + greeting_strings[type].comment); +} +//! [36] + + +//! [37] +qWarning("%s: %s", qPrintable(key), qPrintable(value)); +//! [37] + + +//! [38] +struct Point2D +{ + int x; + int y; +}; + +Q_DECLARE_TYPEINFO(Point2D, Q_PRIMITIVE_TYPE); +//! [38] + + +//! [39] +class Point2D +{ +public: + Point2D() { data = new int[2]; } + Point2D(const Point2D &other) { ... } + ~Point2D() { delete[] data; } + + Point2D &operator=(const Point2D &other) { ... } + + int x() const { return data[0]; } + int y() const { return data[1]; } + +private: + int *data; +}; + +Q_DECLARE_TYPEINFO(Point2D, Q_MOVABLE_TYPE); +//! [39] + + +//! [40] +#if Q_BYTE_ORDER == Q_BIG_ENDIAN +... +#endif + +or + +#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN +... +#endif + +//! [40] + + +//! [41] + +#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN +... +#endif + +//! [41] + + +//! [42] +#if Q_BYTE_ORDER == Q_BIG_ENDIAN +... +#endif + +//! [42] + +//! [begin namespace macro] +namespace QT_NAMESPACE { +//! [begin namespace macro] + +//! [end namespace macro] +} +//! [end namespace macro] + +//! [43] +class MyClass : public QObject +{ + + private: + Q_DISABLE_COPY(MyClass) +}; + +//! [43] + +//! [44] +class MyClass : public QObject +{ + + private: + MyClass(const MyClass &); + MyClass &operator=(const MyClass &); +}; +//! [44] + +//! [45] + w = QWidget() +//! [45] + +//! [46] + // Instead of comparing with 0.0 + qFuzzyCompare(0.0,1.0e-200); // This will return false + // Compare adding 1 to both values will fix the problem + qFuzzyCompare(1 + 0.0, 1 + 1.0e-200); // This will return true +//! [46] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qabstractfileengine.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qabstractfileengine.cpp new file mode 100644 index 000000000..6a6d019a1 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qabstractfileengine.cpp @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +class ZipEngineHandler(QAbstractFileEngineHandler): + def create(self, fileName): + # ZipEngineHandler returns a ZipEngine for all .zip files + if fileName.toLower().endsWith(".zip"): + return ZipEngine(fileName) + else + return None + +def main(): + app = QApplication(sys.argv) + + engine = ZipEngineHandler() + + window = MainWindow() + window.show() + + return app.exec() +//! [0] + + +//! [1] +def create(fileName): + # ZipEngineHandler returns a ZipEngine for all .zip files + if fileName.lower().endswith(".zip"): + return ZipEngine(fileName) + else + return None +//! [1] + + +//! [2] +# @arg filters QDir.Filters +# @arg filterNames [str, ...] +# @return QAbstractFileEngineIterator +def beginEntryList(filters, filterNames): + return CustomFileEngineIterator(filters, filterNames) +//! [2] + + +//! [3] +class CustomIterator(QAbstractFileEngineIterator): + def __init__(self, nameFilters, filters): + QAbstractFileEngineIterator.__init__(self, nameFilters, filters) + + self.index = 0 + # In a real iterator, these entries are fetched from the + # file system based on the value of path(). + self.entries << "entry1" << "entry2" << "entry3" + + def hasNext(self): + return self.index < self.entries.size() - 1 + + def next(self): + if not self.hasNext(): + return None + index += 1 + return currentFilePath() + + def currentFileName(self): + return self.entries.at(index) +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdatastream.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdatastream.cpp new file mode 100644 index 000000000..dff0b2c7c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdatastream.cpp @@ -0,0 +1,135 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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$ +** +****************************************************************************/ + +void wrapInFunction() +{ + +//! [0] +file_ = QFile("file.dat") +file_.open(QIODevice.WriteOnly) +# we will serialize the data into the file +out = QDataStream(file_) +# serialize a string +out.writeQString("the answer is") +# serialize an integer +out.writeInt32(42) +//! [0] + + +//! [1] +file_ = QFile("file.dat") +file_.open(QIODevice.ReadOnly) +# read the data serialized from the file +i = QDataStream(file_) +string = '' +a = 0 +# extract "the answer is" and 42 +string = i.readQString() +a = i.readInt32() +//! [1] + + +//! [2] +stream.setVersion(QDataStream.Qt_4_0) +//! [2] + + +//! [3] +file_ = QFile("file.xxx") +file_.open(QIODevice.WriteOnly) +out = QDataStream(file_) + +# Write a header with a "magic number" and a version +out.writeInt32(0xA0B0C0D0) +out.writeInt32(123) + +out.setVersion(QDataStream.Qt_4_0) + +// Write the data +out << lots_of_interesting_data +//! [3] + + +//! [4] +file_ = QFile("file.xxx") +file_.open(QIODevice.ReadOnly) +i = QDataStream(file_) + +// Read and check the header +magic = i.readInt32() +if magic != 0xA0B0C0D0: + return XXX_BAD_FILE_FORMAT + +// Read the version +version = i.readInt32() +if version < 100: + return XXX_BAD_FILE_TOO_OLD +if version > 123: + return XXX_BAD_FILE_TOO_NEW + +if version <= 110: + in_.setVersion(QDataStream.Qt_3_2) +else: + in_.setVersion(QDataStream.Qt_4_0) + +// Read the data +in_ >> lots_of_interesting_data +if version >= 120: + in_ >> data_new_in_XXX_version_1_2 +in_ >> other_interesting_data +//! [4] + + +//! [5] +out = QDataStream(file_) +out.setVersion(QDataStream.Qt_4_0) +//! [5] + +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdir.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdir.cpp new file mode 100644 index 000000000..85019de30 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdir.cpp @@ -0,0 +1,179 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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$ +** +****************************************************************************/ + +void wrapInFunction() +{ + +//! [0] +QDir("/home/user/Documents") +QDir("C:/Documents and Settings") +//! [0] + + +//! [1] +QDir("images/landscape.png") +//! [1] + + +//! [2] +QDir("Documents/Letters/Applications").dirName() # "Applications" +QDir().dirName() # "." +//! [2] + + +//! [3] +directory = QDir("Documents/Letters") +path = directory.filePath("contents.txt") +absolutePath = directory.absoluteFilePath("contents.txt") +//! [3] + + +//! [4] +dir = QDir("example") +if not dir.exists(): + print "Cannot find the example directory" +//! [4] + + +//! [5] +dir = QDir.root() # "/" +if not dir.cd("tmp"): # "/tmp" + print "Cannot find the \"/tmp\" directory" +else: + file = QFile(dir.filePath("ex1.txt")) # "/tmp/ex1.txt" + if !file.open(QIODevice.ReadWrite): + print "Cannot create the file %s" % (file.name()) +//! [5] + + +//! [6] +bin = "/local/bin" # where /local/bin is a symlink to /usr/bin +binDir = QDir(bin) +canonicalBin = binDir.canonicalPath() +# canonicalBin now equals "/usr/bin" + +ls = "/local/bin/ls" # where ls is the executable "ls" +lsDir = QDir(ls) +canonicalLs = lsDir.canonicalPath() +# canonicalLS now equals "/usr/bin/ls". +//! [6] + + +//! [7] +dir = QDir("/home/bob") + +s = dir.relativeFilePath("images/file.jpg") # s is "images/file.jpg" +s = dir.relativeFilePath("/home/mary/file.txt") # s is "../mary/file.txt" +//! [7] + + +//! [8] +QDir.setSearchPaths("icons", [QDir.homePath() + "/images"]) +QDir.setSearchPaths("docs", [":/embeddedDocuments"]) +... +pixmap = QPixmap("icons:undo.png") # will look for undo.png in QDir::homePath() + "/images" +file = QFile("docs:design.odf") # will look in the :/embeddedDocuments resource path +//! [8] + + +//! [9] +dir = QDir("/tmp/root_link") +dir = dir.canonicalPath() +if dir.isRoot(): + print "It is a root link" +//! [9] + + +//! [10] +# The current directory is "/usr/local" +d1 = QDir("/usr/local/bin") +d2 = QDir("bin") +if d1 == d2: + print "They're the same" +//! [10] + + +//! [11] +// The current directory is "/usr/local" +d1 = QDir("/usr/local/bin") +d1.setFilter(QDir.Executable) +d2 = QDir("bin") +if d1 != d2: + print "They differ" +//! [11] + + +//! [12] +C:/Documents and Settings/Username +//! [12] + + +//! [13] +Q_INIT_RESOURCE(myapp); +//! [13] + + +//! [14] +def initMyResource(): + Q_INIT_RESOURCE(myapp) + +class MyNamespace + ... + + def myFunction(self): + initMyResource() +//! [14] + + +//! [15] +Q_CLEANUP_RESOURCE(myapp); +//! [15] + +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdiriterator.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdiriterator.cpp new file mode 100644 index 000000000..9d37d9f95 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdiriterator.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +it = QDirIterator("/etc", QDirIterator.Subdirectories) +while it.hasNext(): + print it.next() + + # /etc/. + # /etc/.. + # /etc/X11 + # /etc/X11/fs + # ... + +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qfile.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qfile.cpp new file mode 100644 index 000000000..ea225684c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qfile.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +file = QFile() +QDir.setCurrent("/tmp") +file.setFileName("readme.txt") +QDir.setCurrent("/home") +file.open(QIODevice.ReadOnly) # opens "/home/readme.txt" under Unix +//! [0] + + +//! [1] +def myEncoderFunc(fileName): +//! [1] + + +//! [2] +def myDecoderFunc(localFileName): +//! [2] + + +//! [3] + +def printError(msg): + file = QFile() + file.open(sys.stderr.fileno(), QIODevice.WriteOnly) + file.write(msg, size(msg)) # write to stderr + file.close() +//! [3] + + +//! [4] +CONFIG += console +//! [4] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qfileinfo.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qfileinfo.cpp new file mode 100644 index 000000000..5a53e7ac6 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qfileinfo.cpp @@ -0,0 +1,148 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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$ +** +****************************************************************************/ + +//![newstuff] + fi = QFileInfo("c:/temp/foo") => fi.absoluteFilePath() => "C:/temp/foo" +//![newstuff] + +//! [0] +info1 = QFileInfo("/home/bob/bin/untabify") +info1.isSymLink() # returns true +info1.absoluteFilePath() # returns "/home/bob/bin/untabify" +info1.size() # returns 56201 +info1.symLinkTarget() # returns "/opt/pretty++/bin/untabify" + +info2 = QFileInfo(info1.symLinkTarget()) +info1.isSymLink() # returns False +info1.absoluteFilePath() # returns "/opt/pretty++/bin/untabify" +info1.size() # returns 56201 + +//! [0] + + +//! [1] +info1 = QFileInfo("C:\\Documents and Settings\\Bob\\untabify.lnk") +info1.isSymLink() # returns True +info1.absoluteFilePath() # returns "C:/Documents and Settings/Bob/untabify.lnk" +info1.size() # returns 743 +info1.symLinkTarget() # returns "C:/Pretty++/untabify" + +info2 = QFileInfo(info1.symLinkTarget()) +info1.isSymLink() # returns False +info1.absoluteFilePath() # returns "C:/Pretty++/untabify" +info1.size() # returns 63942 +//! [1] + + +//! [2] +absolute = "/local/bin" +relative = "local/bin" +absFile = QFileInfo(absolute) +relFile = QFileInfo(relative) + +QDir.setCurrent(QDir.rootPath()) +# absFile and relFile now point to the same file + +QDir.setCurrent("/tmp") +# absFile now points to "/local/bin", +# while relFile points to "/tmp/local/bin" +//! [2] + + +//! [3] +fi = QFileInfo("/tmp/archive.tar.gz") +name = fi.fileName() # name = "archive.tar.gz" +//! [3] + + +//! [4] +fi = QFileInfo("/Applications/Safari.app") +bundle = fi.bundleName() # name = "Safari" +//! [4] + + +//! [5] +fi = QFileInfo("/tmp/archive.tar.gz") +base = fi.baseName() # base = "archive" +//! [5] + + +//! [6] +fi = QFileInfo("/tmp/archive.tar.gz") +base = fi.completeBaseName() # base = "archive.tar" +//! [6] + + +//! [7] +fi = QFileInfo("/tmp/archive.tar.gz") +ext = fi.completeSuffix() # ext = "tar.gz" +//! [7] + + +//! [8] +fi = QFileInfo("/tmp/archive.tar.gz") +ext = fi.suffix(); # ext = "gz" +//! [8] + + +//! [9] +info = QFileInfo(fileName) +if info.isSymLink(): + fileName = info.symLinkTarget() +//! [9] + + +//! [10] +fi = QFileInfo("/tmp/archive.tar.gz") +if fi.permission(QFile.WriteUser | QFile.ReadGroup): + print "I can change the file; my group can read the file" +if fi.permission(QFile.WriteGroup | QFile.WriteOther): + print "The group or others can change the file" +//! [10] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qiodevice.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qiodevice.cpp new file mode 100644 index 000000000..0ad210141 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qiodevice.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +gzip = QProcess() +gzip.start("gzip", ["-c"]) +if not gzip.waitForStarted(): + return False + +gzip.write("uncompressed data") + +compressed = QByteArray() +while gzip.waitForReadyRead(): + compressed += gzip.readAll() +//! [0] + + +//! [1] +def bytesAvailable(self): + return buffer.size() + QIODevice.bytesAvailable() +//! [1] + + +//! [2] +file = QFile("box.txt") +if file.open(QFile.ReadOnly): + buf = file.readLine(1024) + if buf.size(): + # the line is available in buf +//! [2] + + +//! [3] +def canReadLine(self): + return buffer.contains('\n') or QIODevice.canReadLine() +//! [3] + + +//! [4] +def isExeFile(file_): + buf = file_.peek(2) + if buf.size() == 2: + return buf[0] == 'M' and buf[1] == 'Z' + return False +//! [4] + + +//! [5] +def isExeFile(file_): + return file_.peek(2) == "MZ" +//! [5] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qprocess.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qprocess.cpp new file mode 100644 index 000000000..5542c796e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qprocess.cpp @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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$ +** +****************************************************************************/ + +def wrapInFunction(): + +//! [0] +builder = QProcess() +builder.setProcessChannelMode(QProcess.MergedChannels) +builder.start("make", ["-j2"]) + +import sys +if not builder.waitForFinished(): + sys.stderr.write("Make failed:" + builder.errorString()) +else + sys.stderr.write("Make output:" + builder.readAll()) +//! [0] + + +//! [1] +more = QProcess() +more.start("more") +more.write("Text to display") +more.closeWriteChannel() +#QProcess will emit readyRead() once "more" starts printing +//! [1] + + +//! [2] +command1 | command2 +//! [2] + + +//! [3] +process1 = QProcess() +process2 = QProcess() + +process1.setStandardOutputProcess(process2) + +process1.start("command1") +process2.start("command2") +//! [3] + + +//! [4] +class SandboxProcess(QProcess): + def setupChildProcess(self) + # Drop all privileges in the child process, and enter + # a chroot jail. + os.setgroups(0, 0) + os.chroot("/etc/safe") + os.chdir("/") + os.setgid(safeGid) + os.setuid(safeUid) + os.umask(0) + +//! [4] + + +//! [5] +process = QProcess() +process.start("del /s *.txt") +# same as process.start("del", ["/s", "*.txt"]) +... +//! [5] + + +//! [6] +process = QProcess() +process.start("dir \"My Documents\"") +//! [6] + + +//! [7] +process = QProcess() +process.start("dir \"\"\"My Documents\"\"\"") +//! [7] + + +//! [8] +environment = QProcess.systemEnvironment() +# environment = [PATH=/usr/bin:/usr/local/bin", +# "USER=greg", "HOME=/home/greg"] +//! [8] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qsettings.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qsettings.cpp new file mode 100644 index 000000000..2297e6894 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qsettings.cpp @@ -0,0 +1,330 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +settings = QSettings("MySoft", "Star Runner") +color = QColor(settings.value("DataPump/bgcolor")) +//! [0] + + +//! [1] +settings = QSettings("MySoft", "Star Runner") +color = palette().background().color() +settings.setValue("DataPump/bgcolor", color) +//! [1] + + +//! [2] +settings = QSettings("/home/petra/misc/myapp.ini", + QSettings.IniFormat) +//! [2] + + +//! [3] +settings = QSettings("/Users/petra/misc/myapp.plist", + QSettings.NativeFormat) +//! [3] + + +//! [4] +settings = QSettings("HKEY_CURRENT_USER\\Software\\Microsoft\\Office", + QSettings.NativeFormat) +//! [4] + + +//! [5] +settings.setValue("11.0/Outlook/Security/DontTrustInstalledFiles", 0) +//! [5] + + +//! [6] +settings.setValue("HKEY_CURRENT_USER\\MySoft\\Star Runner\\Galaxy", "Milkyway") +settings.setValue("HKEY_CURRENT_USER\\MySoft\\Star Runner\\Galaxy\\Sun", "OurStar") +settings.value("HKEY_CURRENT_USER\\MySoft\\Star Runner\\Galaxy\\Default") # returns "Milkyway" +//! [6] + + +//! [7] +#ifdef Q_WS_MAC + settings = QSettings("grenoullelogique.fr", "Squash") +#else + settings = QSettings("Grenoulle Logique", "Squash") +#endif +//! [7] + + +//! [8] +pos = @Point(100 100) +//! [8] + + +//! [9] +windir = C:\Windows +//! [9] + + +//! [10] +settings = QSettings("Moose Tech", "Facturo-Pro") +//! [10] + + +//! [11] +settings = QSettings("Moose Soft", "Facturo-Pro") +//! [11] + + +//! [12] +QCoreApplication.setOrganizationName("Moose Soft") +QCoreApplication.setApplicationName("Facturo-Pro") +settings = QSettings() +//! [12] + + +//! [13] +settings.beginGroup("mainwindow") +settings.setValue("size", win.size()) +settings.setValue("fullScreen", win.isFullScreen()) +settings.endGroup() + +settings.beginGroup("outputpanel") +settings.setValue("visible", panel.isVisible()) +settings.endGroup() +//! [13] + + +//! [14] +settings.beginGroup("alpha") +# settings.group() == "alpha" + +settings.beginGroup("beta") +# settings.group() == "alpha/beta" + +settings.endGroup() +# settings.group() == "alpha" + +settings.endGroup() +# settings.group() == "" +//! [14] + + +//! [15] +class Login: + userName = '' + password = '' + + logins = [] + ... + + settings = QSettings() + size = settings.beginReadArray("logins") + for i in range(size): + settings.setArrayIndex(i) + login = Login() + login.userName = settings.value("userName") + login.password = settings.value("password") + logins.append(login) + + settings.endArray() +//! [15] + + +//! [16] +class Login: + userName = '' + password = '' + + logins = [] + ... + + settings = QSettings() + settings.beginWriteArray("logins") + for i in range(logins.size()): + settings.setArrayIndex(i) + settings.setValue("userName", list.at(i).userName) + settings.setValue("password", list.at(i).password) + + settings.endArray() +//! [16] + + +//! [17] +settings = QSettings() +settings.setValue("fridge/color", Qt.white) +settings.setValue("fridge/size", QSize(32, 96)) +settings.setValue("sofa", True) +settings.setValue("tv", False) + +keys = settings.allKeys(); +# keys: ["fridge/color", "fridge/size", "sofa", "tv"] +//! [17] + + +//! [18] +settings.beginGroup("fridge") +keys = settings.allKeys() +# keys: ["color", "size"] +//! [18] + + +//! [19] +settings = QSettings() +settings.setValue("fridge/color", Qt.white) +settings.setValue("fridge/size", QSize(32, 96)) +settings.setValue("sofa", True) +settings.setValue("tv", False) + +keys = settings.childKeys() +# keys: ["sofa", "tv"] +//! [19] + + +//! [20] +settings.beginGroup("fridge") +keys = settings.childKeys() +# keys: ["color", "size"] +//! [20] + + +//! [21] +settings = QSettings() +settings.setValue("fridge/color", Qt.white) +settings.setValue("fridge/size", QSize(32, 96)); +settings.setValue("sofa", True) +settings.setValue("tv", False) + +groups = settings.childGroups() +# group: ["fridge"] +//! [21] + + +//! [22] +settings.beginGroup("fridge") +groups = settings.childGroups() +# groups: [] +//! [22] + + +//! [23] +settings = QSettings() +settings.setValue("interval", 30) +settings.value("interval") # returns 30 + +settings.setValue("interval", 6.55) +settings.value("interval") # returns 6.55 +//! [23] + + +//! [24] +settings = QSettings() +settings.setValue("ape") +settings.setValue("monkey", 1) +settings.setValue("monkey/sea", 2) +settings.setValue("monkey/doe", 4) + +settings.remove("monkey") +keys = settings.allKeys() +# keys: ["ape"] +//! [24] + + +//! [25] +settings = QSettings() +settings.setValue("ape") +settings.setValue("monkey", 1) +settings.setValue("monkey/sea", 2) +settings.setValue("monkey/doe", 4) + +settings.beginGroup("monkey") +settings.remove("") +settings.endGroup() + +keys = settings.allKeys() +# keys: ["ape"] +//! [25] + + +//! [26] +settings = QSettings() +settings.setValue("animal/snake", 58) +settings.value("animal/snake", 1024) # returns 58 +settings.value("animal/zebra", 1024) # returns 1024 +settings.value("animal/zebra") # returns 0 +//! [26] + + +//! [27] +# @arg device QIODevice +# @arg map QSettings.SettingsMap +# @return bool +def myReadFunc(device, map): +//! [27] + + +//! [28] +# @arg device QIODevice +# @arg map QSettings.SettingsMap +# @return bool +def myWriteFunc(device, map) +//! [28] + + +//! [29] +# @arg device QIODevice +# @arg map QSettings.SettingsMap +# @return bool +def readXmlFile(device, map): +def writeXmlFile(device, map): + +def main(): + XmlFormat = QSettings::registerFormat("xml", readXmlFile, writeXmlFile) + settings = QSettings(XmlFormat, QSettings.UserSettings, + "MySoft", "Star Runner") + ... +//! [29] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qtemporaryfile.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qtemporaryfile.cpp new file mode 100644 index 000000000..067b9a375 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qtemporaryfile.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + # Within a function/method... + + file_ = QTemporaryFile() + if file_.open(): + # file_.fileName() returns the unique file name + + # The QTemporaryFile destructor removes the temporary file + # as it goes out of scope. +//! [0] +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qtextstream.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qtextstream.cpp new file mode 100644 index 000000000..d9efd55f4 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qtextstream.cpp @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +data = QFile("output.txt") +if data.open(QFile.WriteOnly | QFile.Truncate): + out = QTextStream(&data) + out << "Result: " << qSetFieldWidth(10) << left << 3.14 << 2.7 + # writes "Result: 3.14 2.7 " + +//! [0] + + +//! [1] +stream = QTextStream(sys.stdin.fileno()) + +while(True): + line = stream.readLine() + if line.isNull(): + break; +//! [1] + + +//! [2] +in_ = QTextStream("0x50 0x20") +firstNumber = 0 +secondNumber = 0 + +in_ >> firstNumber # firstNumber == 80 +in_ >> dec >> secondNumber # secondNumber == 0 + +ch = None +in_ >> ch # ch == 'x' +//! [2] + + +//! [3] +def main(): + # read numeric arguments (123, 0x20, 4.5...) + for i in sys.argv(): + number = None + QTextStream in_(i) + in_ >> number + ... +//! [3] + + +//! [4] +str = QString() +in_ = QTextStream(sys.stdin.fileno()) +in_ >> str +//! [4] + + +//! [5] +s = QString() +out = QTextStream(s) +out.setFieldWidth(10) +out.setFieldAlignment(QTextStream::AlignCenter) +out.setPadChar('-') +out << "Qt" << "rocks!" +//! [5] + + +//! [6] +----Qt------rocks!-- +//! [6] + + +//! [7] +in_ = QTextStream(file) +ch1 = QChar() +ch2 = QChar() +ch3 = QChar() +in_ >> ch1 >> ch2 >> ch3; +//! [7] + + +//! [8] +out = QTextStream(sys.stdout.fileno()) +out << "Qt rocks!" << endl +//! [8] + + +//! [9] +stream << '\n' << flush +//! [9] + + +//! [10] +out = QTextStream(file) +out.setCodec("UTF-8") +//! [10] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qurl.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qurl.cpp new file mode 100644 index 000000000..bacee95ff --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qurl.cpp @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +url = QUrl("http://www.example.com/List of holidays.xml") +# url.toEncoded() == "http://www.example.com/List%20of%20holidays.xml" +//! [0] + + +//! [1] +url = QUrl.fromEncoded("http://qtsoftware.com/List%20of%20holidays.xml") +//! [1] + + +//! [2] +def checkUrl(url): + if !url.isValid(): + print "Invalid URL: %s" % url.toString() + return False + + return True + +//! [2] + + +//! [3] +ftp = QFtp() +ftp.connectToHost(url.host(), url.port(21)) +//! [3] + + +//! [4] +http://www.example.com/cgi-bin/drawgraph.cgi?type-pie/color-green +//! [4] + + +//! [5] +baseUrl = QUrl("http://qtsoftware.com/support") +relativeUrl = QUrl("../products/solutions") +print baseUrl.resolved(relativeUrl).toString() +# prints "http://qtsoftware.com/products/solutions" +//! [5] + + +//! [6] +ba = QUrl.toPercentEncoding("{a fishy string?}", "{}", "s") +print ba +# prints "{a fi%73hy %73tring%3F}" +//! [6] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qabstracteventdispatcher.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qabstracteventdispatcher.cpp new file mode 100644 index 000000000..a531f22fc --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qabstracteventdispatcher.cpp @@ -0,0 +1,3 @@ +//! [0] +bool myEventFilter(void *message); +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp new file mode 100644 index 000000000..a9480e381 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +beginInsertRows(parent, 2, 4) +//! [0] + + +//! [1] +beginInsertRows(parent, 4, 5) +//! [1] + + +//! [2] +beginRemoveRows(parent, 2, 3) +//! [2] + + +//! [3] +beginInsertColumns(parent, 4, 6) +//! [3] + + +//! [4] +beginInsertColumns(parent, 6, 8) +//! [4] + + +//! [5] +beginRemoveColumns(parent, 4, 6) +//! [5] + + +//! [6] +beginMoveRows(sourceParent, 2, 4, destinationParent, 2) +//! [6] + + +//! [7] +beginMoveRows(sourceParent, 2, 4, destinationParent, 6) +//! [7] + + +//! [8] +beginMoveRows(parent, 2, 2, parent, 0) +//! [8] + + +//! [9] +beginMoveRows(parent, 2, 2, parent, 4) +//! [9] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp new file mode 100644 index 000000000..e5f664cba --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +event = QMouseEvent(QEvent.MouseButtonPress, pos, 0, 0, 0) +QApplication.sendEvent(mainWindow, event) +//! [0] + + +//! [1] +quitButton = QPushButton("Quit") +quitButton.clicked.connect(app.quit) +//! [1] + + +//! [2] +for path in app.libraryPaths(): + do_something(path) +//! [2] + + +//! [3] +myEventFilter(message, result) +//! [3] + + +//! [4] +def cleanup_stuff(): + # do the cleanup stuff + +def init_stuff(): + qAddPostRoutine(cleanup_stuff) +//! [4] + + +//! [5] +class MyPrivateInitStuff : public QObject +{ +public: + static MyPrivateInitStuff *initStuff(QObject *parent) + { + if (!p) + p = new MyPrivateInitStuff(parent); + return p; + } + + ~MyPrivateInitStuff() + { + // cleanup goes here + } + +private: + MyPrivateInitStuff(QObject *parent) + : QObject(parent) + { + // initialization goes here + } + + MyPrivateInitStuff *p; +}; +//! [5] + + +//! [6] +static inline QString tr(const char *sourceText, + const char *comment = 0); +static inline QString trUtf8(const char *sourceText, + const char *comment = 0); +//! [6] + + +//! [7] +class MyMfcView : public CView +{ + Q_DECLARE_TR_FUNCTIONS(MyMfcView) + +public: + MyMfcView(); + ... +}; +//! [7] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp new file mode 100644 index 000000000..71e264832 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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$ +** +****************************************************************************/ + +void wrapInFunction() +{ + +//! [0] +class MyClass: + + Q_CLASSINFO("author", "Sabrina Schweinsteiger") + Q_CLASSINFO("url", "http://doc.moosesoft.co.uk/1.0/") + + ... +//! [0] + + +//! [1] +normType = QMetaObject.normalizedType(" int const *") +# normType is now "const int*" +//! [1] + + +//! [2] +QMetaObject.invokeMethod(pushButton, "animateClick", + Qt.QueuedConnection) +//! [2] + + +//! [3] +QMetaObject.invokeMethod: Unable to handle unregistered datatype 'MyType' +//! [3] + + +//! [4] +retVal = QString() +QMetaObject.invokeMethod(obj, "compute", Qt::DirectConnection, + Q_RETURN_ARG(QString, retVal), + Q_ARG(QString, "sqrt"), + Q_ARG(int, 42), + Q_ARG(double, 9.7)); +//! [4] + + +//! [5] +class MyClass: + Q_CLASSINFO("author", "Sabrina Schweinsteiger") + Q_CLASSINFO("url", "http://doc.moosesoft.co.uk/1.0/") +//! [5] + + +//! [propertyCount] +metaObject = obj.metaObject() +properties = [metaObject.property(i).name() for i in range(metaObject.propertyOffset(), metaObject.propertyCount())] +//! [propertyCount] + + +//! [methodCount] +metaObject = obj.metaObject() +methods = [metaObject.method(i).signature() for i in range(metaObject.methodOffset(), metaObject.methodCount())] +//! [methodCount] + +//! [6] +methodIndex = pushButton.metaObject().indexOfMethod("animateClick()") +method = metaObject.method(methodIndex) +method.invoke(pushButton, Qt.QueuedConnection) +//! [6] + +//! [7] +QMetaMethod.invoke: Unable to handle unregistered datatype 'MyType' +//! [7] + +//! [8] +retVal = QString() +normalizedSignature = QMetaObject.normalizedSignature("compute(QString, int, double)") +methodIndex = obj.metaObject().indexOfMethod(normalizedSignature) +method = metaObject.method(methodIndex) +method.invoke(obj, + Qt.DirectConnection, + Q_RETURN_ARG(QString, retVal), + Q_ARG(QString, "sqrt"), + Q_ARG(int, 42), + Q_ARG(double, 9.7)); +//! [8] + +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp new file mode 100644 index 000000000..62c9ae327 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +struct MyStruct +{ + int i; + ... +}; + +Q_DECLARE_METATYPE(MyStruct) +//! [0] + + +//! [1] +namespace MyNamespace +{ + ... +} + +Q_DECLARE_METATYPE(MyNamespace::MyStruct) +//! [1] + + +//! [2] +MyStruct s; +QVariant var; +var.setValue(s); // copy s into the variant + +... + +// retrieve the value +MyStruct s2 = var.value<MyStruct>(); +//! [2] + + +//! [3] +int id = QMetaType::type("MyClass"); +if (id == 0) { + void *myClassPtr = QMetaType::construct(id); + ... + QMetaType::destroy(id, myClassPtr); + myClassPtr = 0; +} +//! [3] + + +//! [4] +qRegisterMetaType<MyClass>("MyClass"); +//! [4] + + +//! [5] +qRegisterMetaTypeStreamOperators<MyClass>("MyClass"); +//! [5] + + +//! [6] +QDataStream &operator<<(QDataStream &out, const MyClass &myObj); +QDataStream &operator>>(QDataStream &in, MyClass &myObj); +//! [6] + + +//! [7] +int id = qRegisterMetaType<MyStruct>(); +//! [7] + + +//! [8] +int id = qMetaTypeId<QString>(); // id is now QMetaType::QString +id = qMetaTypeId<MyStruct>(); // compile error if MyStruct not declared +//! [8] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmimedata.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmimedata.cpp new file mode 100644 index 000000000..a2e6547f2 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmimedata.cpp @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +def dragEnterEvent(self, event): + if event.mimeData().hasUrls(): + event.acceptProposedAction() + +def dropEvent(self, event): + if event->mimeData().hasUrls(): + for url in event.mimeData().urls(): + ... +//! [0] + + +//! [1] +csvData = QByteArray(...) + +mimeData = QMimeData() +mimeData.setData("text/csv", csvData) +//! [1] + + +//! [2] +def dropEvent(self, event): + myData = event->mimeData() + if myData: + # access myData's data directly (not through QMimeData's API) +} +//! [2] + + +//! [3] +application/x-qt-windows-mime;value="<custom type>" +//! [3] + + +//! [4] +application/x-qt-windows-mime;value="FileGroupDescriptor" +application/x-qt-windows-mime;value="FileContents" +//! [4] + + +//! [5] +if event.mimeData().hasImage(): + image = QImage(event.mimeData().imageData()) + ... +//! [5] + + +//! [6] +mimeData.setImageData(QImage("beautifulfjord.png")) +//! [6] + + +//! [7] +if event.mimeData().hasColor(): + color = QColor(event.mimeData().colorData()) + ... +//! [7] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qobject.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qobject.cpp new file mode 100644 index 000000000..bfe6d1d1a --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qobject.cpp @@ -0,0 +1,369 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +lineEdit = qt_find_obj_child(myWidget, "QLineEdit", "my line edit") +if lineEdit: + lineEdit.setText("Default") +//! [0] + + +//! [1] +obj = QPushButton() +obj.metaObject().className() # returns "QPushButton" + +QPushButton.staticMetaObject.className() # returns "QPushButton" +//! [1] + + +//! [2] +QPushButton.staticMetaObject.className() # returns "QPushButton" + +obj = QPushButton() +obj.metaObject().className() # returns "QPushButton" +//! [2] + + +//! [3] +obj = QTimer() # QTimer inherits QObject + +timer = obj +# timer == (QObject *)obj + +button = obj +# button == 0 +//! [3] + + +//! [4] +timer = QTimer() # QTimer inherits QObject +timer.inherits("QTimer") # returns true +timer.inherits("QObject") # returns true +timer.inherits("QAbstractButton") # returns false + +# QLayout inherits QObject and QLayoutItem +layout = QLayout() +layout.inherits("QObject") # returns true +layout.inherits("QLayoutItem") # returns false +//! [4] + + +//! [5] +print "MyClass::setPrecision(): (%s) invalid precision %f" % \ + (qPrintable(objectName()), newPrecision) +//! [5] + + +//! [6] +class MainWindow(QMainWindow): + def __init__(self): + self.textEdit = QTextEdit() + setCentralWidget(self.textEdit) + textEdit.installEventFilter(self) + + def eventFilter(self, obj, event): + if obj == textEdit: + if event.type() == QEvent.KeyPress: + keyEvent = event + print "Ate key press", keyEvent.key() + return true + else: + return false + else: + # pass the event on to the parent class + return QMainWindow.eventFilter(self, obj, event) +//! [6] + + +//! [7] +myObject.moveToThread(QApplication.instance().thread()) +//! [7] + + +//! [8] +class MyObject(QObject): + def __init__(self, parent): + QObject.__init__(self, parent) + + self.startTimer(50) # 50-millisecond timer + self.startTimer(1000) # 1-second timer + self.startTimer(60000) # 1-minute timer + + + def timerEvent(self, event): + print "Timer ID:", event.timerId() + +//! [8] + + +//! [9] +list = window().queryList("QAbstractButton") +for obj in list: + obj.setEnabled(false) +//! [9] + + +//! [10] +button = parentWidget.findChild(QPushButton, "button1") +//! [10] + + +//! [11] +list = parentWidget.findChild(QListWidget) +//! [11] + + +//! [12] +widgets = parentWidget.findChildren(QWidget, "widgetname") +//! [12] + + +//! [13] +allPButtons = parentWidget.findChildren(QPushButton) +//! [13] + + +//! [14] +monitoredObj.installEventFilter(filterObj) +//! [14] + + +//! [15] +class KeyPressEater(QObject): + def eventFilter(self, obj, event): + if event.type() == QEvent.KeyPress: + print "Ate key press", event.key() + return True + else: + # standard event processing + return QObject.eventFilter(self, obj, event) +//! [15] + + +//! [16] +keyPressEater = KeyPressEater(self) +pushButton = QPushButton(self) +listView = QListView(self) + +pushButton.installEventFilter(keyPressEater) +listView.installEventFilter(keyPressEater) +//! [16] + + +//! [17] +def __init__(self): + senderLabel = QLabel(self.tr("Name:")) + recipientLabel = QLabel(self.tr("Name:", "recipient")) + # ... +//! [17] + + +//! [18] +n = messages.count(); +showMessage(self.tr("%n message(s) saved", "", n)); +//! [18] + + +//! [19] +if n == 1: + self.tr("%n message saved") +else: + self.tr("%n messages saved") +//! [19] + + +//! [20] +label.setText(self.tr("F\374r \310lise")) +//! [20] + + +//! [21] +if receivers(SIGNAL('valueChanged()')) > 0: + data = get_the_value() # expensive operation + self.valueChanged(data) +//! [21] + + +//! [22] +label = QLabel() +scrollBar = QScrollBar() +QObject.connect(scrollBar, SIGNAL('valueChanged()'), + label, SLOT('setNum()')) +//! [22] + + +//! [23] +// WRONG +QObject.connect(scrollBar, SIGNAL('valueChanged()'), + label, SLOT('setNum()')); +//! [23] + + +//! [24] +class MyWidget(QWidget): + def __init__(self): + myButton = QPushButton(self) + connect(myButton, SIGNAL('clicked()'), + self, SIGNAL('buttonClicked()')) +//! [24] + + +//! [25] +QObject.connect: Cannot queue arguments of type 'MyType' +(Make sure 'MyType' is registered using qRegisterMetaType().) +//! [25] + + +//! [26] +disconnect(myObject, 0, 0, 0) +//! [26] + + +//! [27] +myObject.disconnect() +//! [27] + + +//! [28] +disconnect(myObject, SIGNAL('mySignal()'), 0, 0) +//! [28] + + +//! [29] +myObject.disconnect(SIGNAL('mySignal()')) +//! [29] + + +//! [30] +disconnect(myObject, 0, myReceiver, 0) +//! [30] + + +//! [31] +myObject.disconnect(myReceiver) +//! [31] + + +//! [32] +if QLatin1String(signal) == SIGNAL('valueChanged()'): + # signal is valueChanged() +//! [32] + + +//! [33] +def on_<object name>_<signal name>(<signal parameters>) +//! [33] + + +//! [34] +def on_button1_clicked() +//! [34] + + +//! [35] +class MyClass(QObject): + Q_CLASSINFO("Author", "Pierre Gendron") + Q_CLASSINFO("URL", "http://www.my-organization.qc.ca") + +//! [35] + + +//! [36] +Q_PROPERTY(type name + READ getFunction + [WRITE setFunction] + [RESET resetFunction] + [DESIGNABLE bool] + [SCRIPTABLE bool] + [STORED bool] + [USER bool]) +//! [36] + + +//! [37] +Q_PROPERTY(QString title READ title WRITE setTitle USER true) +//! [37] + + +//! [38] +#this not apply for Python +class MyClass(QObject): + + Q_OBJECT + Q_ENUMS(Priority) + +public: + MyClass(QObject *parent = 0); + ~MyClass(); + + enum Priority { High, Low, VeryHigh, VeryLow }; + void setPriority(Priority priority); + Priority priority() const; +}; +//! [38] + + +//! [39] +#this not apply for Python +Q_FLAGS(Options Alignment) +//! [39] + + +//! [40] +//: This name refers to a host name. +hostNameLabel.setText(self.tr("Name:")) + +#: This text refers to a C++ code example. +example = self.tr("Example") +//! [40] + +//! [explicit tr context] +text = QScrollBar.tr("Page up") +//! [explicit tr context] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qsystemsemaphore.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qsystemsemaphore.cpp new file mode 100644 index 000000000..247d10806 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qsystemsemaphore.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +sem = QSystemSemaphore("market", 3, QSystemSemaphore.Create) +# resources available == 3 +sem.acquire() # resources available == 2 +sem.acquire() # resources available == 1 +sem.acquire() # resources available == 0 +sem.release() # resources available == 1 +sem.release(2) # resources available == 3 +//! [0] + + +//! [1] +sem = QSystemSemaphore("market", 5, QSystemSemaphore.Create) +sem.acquire(5) # acquire all 5 resources +sem.release(5) # release the 5 resources +//! [1] + + +//! [2] +sem.release(10) # "create" 10 new resources +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qtimer.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qtimer.cpp new file mode 100644 index 000000000..b34bdd206 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qtimer.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +from PySide2.QtCore import QApplication, QTimer + +def main(): + + app = QApplication([]) + QTimer.singleShot(600000, app, SLOT('quit()')) + ... + return app.exec_() +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_plugin_qlibrary.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_plugin_qlibrary.cpp new file mode 100644 index 000000000..6fe5807b9 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_plugin_qlibrary.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +QLibrary myLib("mylib"); +typedef void (*MyPrototype)(); +MyPrototype myFunction = (MyPrototype) myLib.resolve("mysymbol"); +if (myFunction) + myFunction(); +//! [0] + + +//! [1] +typedef void (*MyPrototype)(); +MyPrototype myFunction = + (MyPrototype) QLibrary::resolve("mylib", "mysymbol"); +if (myFunction) + myFunction(); +//! [1] + + +//! [2] +typedef int (*AvgFunction)(int, int); + +AvgFunction avg = (AvgFunction) library->resolve("avg"); +if (avg) + return avg(5, 8); +else + return -1; +//! [2] + + +//! [3] +extern "C" MY_EXPORT int avg(int a, int b) +{ + return (a + b) / 2; +} +//! [3] + + +//! [4] +#ifdef Q_WS_WIN +#define MY_EXPORT __declspec(dllexport) +#else +#define MY_EXPORT +#endif +//! [4] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_plugin_quuid.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_plugin_quuid.cpp new file mode 100644 index 000000000..3d19de0fe --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_plugin_quuid.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +# {67C8770B-44F1-410A-AB9A-F9B5446F13EE} +IID_MyInterface = QUuid(0x67c8770b, 0x44f1, 0x410a, 0xab, 0x9a, 0xf9, 0xb5, 0x44, 0x6f, 0x13, 0xee) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_statemachine_qstatemachine.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_statemachine_qstatemachine.cpp new file mode 100644 index 000000000..d61013239 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_statemachine_qstatemachine.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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$ +** +****************************************************************************/ + +//! [simple state machine] +button = QPushButton() + +machine = QStateMachine() +s1 = QState() +s1.assignProperty(button, "text", "Click me") + +s2 = QFinalState() +s1.addTransition(button, SIGNAL('clicked()'), s2) + +machine.addState(s1) +machine.addState(s2) +machine.setInitialState(s1) +machine.start() +//! [simple state machine] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qatomic.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qatomic.cpp new file mode 100644 index 000000000..8632c8b4f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qatomic.cpp @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +MySharedType &MySharedType::operator=(const MySharedType &other) +{ + (void) other.data->atomicInt.ref(); + if (!data->atomicInt.deref()) { + // The last reference has been released + delete d; + } + d = other.d; + return *this; +} +//! [0] + + +//! [1] +if (currentValue == expectedValue) { + currentValue = newValue; + return true; +} +return false; +//! [1] + + +//! [2] +int originalValue = currentValue; +currentValue = newValue; +return originalValue; +//! [2] + + +//! [3] +int originalValue = currentValue; +currentValue += valueToAdd; +return originalValue; +//! [3] + + +//! [4] +if (currentValue == expectedValue) { + currentValue = newValue; + return true; +} +return false; +//! [4] + + +//! [5] +T *originalValue = currentValue; +currentValue = newValue; +return originalValue; +//! [5] + + +//! [6] +T *originalValue = currentValue; +currentValue += valueToAdd; +return originalValue; +//! [6] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qmutex.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qmutex.cpp new file mode 100644 index 000000000..b83164d56 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qmutex.cpp @@ -0,0 +1,165 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +number = 6 + +def method1(): + number *= 5 + number /= 4 + +def method2(): + number *= 3 + number /= 2 +//! [0] + + +//! [1] +# method1() +number *= 5 # number is now 30 +number /= 4 # number is now 7 + +# method2() +number *= 3 # number is now 21 +number /= 2 # number is now 10 +//! [1] + + +//! [2] +# Thread 1 calls method1() +number *= 5 # number is now 30 + +# Thread 2 calls method2(). +# +# Most likely Thread 1 has been put to sleep by the operating +# system to allow Thread 2 to run. +number *= 3 # number is now 90 +number /= 2 # number is now 45 + +# Thread 1 finishes executing. +number /= 4 # number is now 11, instead of 10 +//! [2] + + +//! [3] +mutex = QMutex() +number = 6 + +def method1(): + mutex.lock() + number *= 5 + number /= 4 + mutex.unlock() + +def method2(): + mutex.lock() + number *= 3 + number /= 2 + mutex.unlock() +//! [3] + + +//! [4] +def complexFunction(flag): + mutex.lock() + + retVal = 0 + + if flag == 0 or flag == 1: + mutex.unlock() + return moreComplexFunction(flag) + elif flag == 2: + status = anotherFunction() + if status < 0: + mutex.unlock() + return -2 + retVal = status + flag + else: + if flag > 10: + mutex.unlock() + return -1 + + mutex.unlock() + return retVal +//! [4] + + +//! [5] +def complexFunction(flag): + locker = QMutexLocker(mutex) + + retVal = 0 + + if flag == 0 or flag == 1: + return moreComplexFunction(flag) + elif flag == 2: + status = anotherFunction() + if status < 0: + return -2 + retVal = status + flag + else: + if flag > 10: + return -1 + + return retVal +//! [5] + + +//! [6] +class SignalWaiter: + def __init__(mutex): + self.locker = mutex + + def waitForSignal(): + # ... + while not signalled: + waitCondition.wait(self.locker.mutex()) + # ... +//! [6] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qmutexpool.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qmutexpool.cpp new file mode 100644 index 000000000..a5e3952a8 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qmutexpool.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +class Number: + def __init__(n): + self.num = n +//! [0] + + +//! [1] +def calcSquare(number): + locker = QMutexLocker(mutexpool.get(number)) + number.num = number.num * number.num +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qreadwritelock.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qreadwritelock.cpp new file mode 100644 index 000000000..015aadfaf --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qreadwritelock.cpp @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +lock = QReadWriteLock() + +class ReaderThread: + # ... + def run(): + # ... + lock.lockForRead() + read_file() + lock.unlock() + # ... + +class WriterThread: + #... + def run(): + # ... + lock.lockForWrite() + write_file() + lock.unlock() + # ... +//! [0] + + +//! [1] +lock = QReadWriteLock() + +def readData(): + locker = QReadLocker(lock) + # ... + return data +//! [1] + + +//! [2] +lock = QReadWriteLock() + +def readData(): + locker.lockForRead() + # ... + locker.unlock() + return data +//! [2] + + +//! [3] +lock = QReadWriteLock() + +def writeData(data): + locker = QWriteLocker(lock) + # ... +//! [3] + + +//! [4] +lock = QReadWriteLock() + +def writeData(data): + locker.lockForWrite() + # ... + locker.unlock() +//! [4] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qsemaphore.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qsemaphore.cpp new file mode 100644 index 000000000..26cfd6a0e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qsemaphore.cpp @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +sem = QSemaphore(5) # sem.available() == 5 + +sem.acquire(3) # sem.available() == 2 +sem.acquire(2) # sem.available() == 0 +sem.release(5) # sem.available() == 5 +sem.release(5) # sem.available() == 10 + +sem.tryAcquire(1) # sem.available() == 9, returns true +sem.tryAcquire(250) # sem.available() == 9, returns false +//! [0] + + +//! [1] +sem = QSemaphore(5) # a semaphore that guards 5 resources +sem.acquire(5) # acquire all 5 resources +sem.release(5) # release the 5 resources +sem.release(10) # "create" 10 new resources +//! [1] + + +//! [2] +sem = QSemaphore(5) # sem.available() == 5 +sem.tryAcquire(250) # sem.available() == 5, returns false +sem.tryAcquire(3) # sem.available() == 2, returns true +//! [2] + + +//! [3] +sem = QSemaphore(5) # sem.available() == 5 +sem.tryAcquire(250, 1000) # sem.available() == 5, waits 1000 milliseconds and returns false +sem.tryAcquire(3, 30000) # sem.available() == 2, returns true without waiting +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qthread.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qthread.cpp new file mode 100644 index 000000000..c9c702ae4 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qthread.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +class MyThread (QThread): + def run(): + socket = QTcpSocket() + # connect QTcpSocket's signals somewhere meaningful + # ... + socket.connectToHost(hostName, portNumber) + self.exec_() +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp new file mode 100644 index 000000000..5ac95c9c0 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +while True: + mutex.lock() + keyPressed.wait(mutex) + do_something() + mutex.unlock() +//! [0] + + +//! [1] +while True: + getchar() + keyPressed.wakeAll() + +//! [1] + + +//! [2] +while True: + mutex.lock() + keyPressed.wait(&mutex) + count += 1 + mutex.unlock() + + do_something() + + mutex.lock() + count -= 1 + mutex.unlock() +//! [2] + + +//! [3] +while True: + getchar() + + mutex.lock() + # Sleep until there are no busy worker threads + while count > 0: + mutex.unlock() + sleep(1) + mutex.lock() + keyPressed.wakeAll() + mutex.unlock() +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qbitarray.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qbitarray.cpp new file mode 100644 index 000000000..03d953cd4 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qbitarray.cpp @@ -0,0 +1,239 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +ba = QBitArray(200) +//! [0] + + +//! [1] +ba = QBitArray() +ba.resize(3) +ba[0] = True +ba[1] = False +ba[2] = True +//! [1] + + +//! [2] +ba = QBitArray(3) +ba.setBit(0, True) +ba.setBit(1, False) +ba.setBit(2, True) +//! [2] + + +//! [3] +x = QBitArray(5) +x.setBit(3, True) +# x: [ 0, 0, 0, 1, 0 ] + +y = QBitArray(5) +y.setBit(4, True) +# y: [ 0, 0, 0, 0, 1 ] + +x |= y +# x: [ 0, 0, 0, 1, 1 ] +//! [3] + + +//! [4] +QBitArray().isNull() # returns True +QBitArray().isEmpty() # returns True + +QBitArray(0).isNull() # returns False +QBitArray(0).isEmpty() # returns True + +QBitArray(3).isNull() # returns False +QBitArray(3).isEmpty() # returns False +//! [4] + + +//! [5] +QBitArray().isNull() # returns True +QBitArray(0).isNull() # returns False +QBitArray(3).isNull() # returns False +//! [5] + + +//! [6] +ba = QBitArray(8) +ba.fill(True) +# ba: [ 1, 1, 1, 1, 1, 1, 1, 1 ] + +ba.fill(False, 2) +# ba: [ 0, 0 ] +//! [6] + + +//! [7] +a = QBitArray(3) +a[0] = False +a[1] = True +a[2] = a[0] ^ a[1] +//! [7] + + +//! [8] +a = QBitArray(3) +b = QBitArray(2) +a[0] = 1 +a[1] = 0 +a[2] = 1 +# a: [ 1, 0, 1 ] + +b[0] = 1 +b[1] = 0 +# b: [ 1, 1 ] + +a &= b +# a: [ 1, 0, 0 ] +//! [8] + + +//! [9] +a = QBitArray(3) +b = QBitArray(2) +a[0] = 1 +a[1] = 0 +a[2] = 1 +# a: [ 1, 0, 1 ] + +b[0] = 1 +b[1] = 0 +# b: [ 1, 1 ] + +a |= b +# a: [ 1, 1, 1 ] +//! [9] + + +//! [10] +a = QBitArray(3) +b = QBitArray(2) +a[0] = 1 +a[1] = 0 +a[2] = 1 +# a: [ 1, 0, 1 ] + +b[0] = 1 +b[1] = 0 +# b: [ 1, 1 ] + +a ^= b +# a: [ 0, 1, 1 ] +//! [10] + + +//! [11] +a = QBitArray(3) +b = QBitArray() +a[0] = 1 +a[1] = 0 +a[2] = 1 +# a: [ 1, 0, 1 ] + +b = ~a +# b: [ 0, 1, 0 ] +//! [11] + + +//! [12] +a = QBitArray(3) +b = QBitArray(2) +c = QBitArray() +a[0] = 1 +a[1] = 0 +a[2] = 1 +# a: [ 1, 0, 1 ] + +b[0] = 1 +b[1] = 0 +# b: [ 1, 1 ] + +c = a & b +# c: [ 1, 0, 0 ] +//! [12] + + +//! [13] +a = QBitArray(3) +QBitArray b(2) +QBitArray c +a[0] = 1 +a[1] = 0 +a[2] = 1 +# a: [ 1, 0, 1 ] + +b[0] = 1 +b[1] = 0 +# b: [ 1, 1 ] + +c = a | b +# c: [ 1, 1, 1 ] +//! [13] + + +//! [14] +a = QBitArray(3) +b = QBitArray(2) +c = QBitArray() +a[0] = 1 +a[1] = 0 +a[2] = 1 +# a: [ 1, 0, 1 ] + +b[0] = 1 +b[1] = 0 +# b: [ 1, 1 ] + +c = a ^ b +# c: [ 0, 1, 1 ] +//! [14] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qbytearray.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qbytearray.cpp new file mode 100644 index 000000000..5910bc67b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qbytearray.cpp @@ -0,0 +1,402 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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$ +** +****************************************************************************/ + +void wrapInFunction() +{ + +//! [0] +ba = QByteArray("Hello") +//! [0] + + +//! [1] +ba = QByteArray() +ba.resize(5) +ba[0] = 'H' +ba[1] = 'e' +ba[2] = 'l' +ba[3] = 'l' +ba[4] = 'o' +//! [1] + + +//! [2] +for i in range(0, ba.size()): + if ba.at(i) >= 'a' and ba.at(i) <= 'f': + print "Found character in range [a-f]" +//! [2] + + +//! [3] +x = QByteArray("and") +x.prepend("rock ") # x == "rock and" +x.append(" roll") # x == "rock and roll" +x.replace(5, 3, "&") # x == "rock & roll" +//! [3] + + +//! [4] +ba = QByteArray("We must be <b>bold</b>, very <b>bold</b>") +j = 0 +while (j = ba.indexOf("<b>", j)) != -1: + print "Found <b> tag at index position %d" % j + ++j +//! [4] + + +//! [5] +QByteArray().isNull() # returns true +QByteArray().isEmpty() # returns true + +QByteArray("").isNull() # returns false +QByteArray("").isEmpty() # returns true + +QByteArray("abc").isNull() # returns false +QByteArray("abc").isEmpty() # returns false +//! [5] + + +//! [6] +ba = QByteArray("Hello") +n = ba.size() # n == 5 +ba.data()[0] # returns 'H' +ba.data()[4] # returns 'o' +//! [6] + + +//! [7] +QByteArray().isEmpty() # returns true +QByteArray("").isEmpty() # returns true +QByteArray("abc").isEmpty() # returns false +//! [7] + + +//! [8] +ba = QByteArray("Hello world"); +print ba.data(); +//! [8] + + +//! [9] +ba = QByteArray() +for i in range(0, 10): + ba[i] = 'A' + str(i) +# ba == "ABCDEFGHIJ" +//! [9] + + +//! [10] +ba = QByteArray("Stockholm") +ba.truncate(5) # ba == "Stock" +//! [10] + + +//! [11] +ba = QByteArray("STARTTLS\r\n") +ba.chop(2) # ba == "STARTTLS" +//! [11] + + +//! [12] +x = QByteArray("free") +y = QByteArray("dom"); +x += y +# x == "freedom" +//! [12] + + +//! [13] +QByteArray().isNull() # returns true +QByteArray("").isNull() # returns false +QByteArray("abc").isNull() # returns false +//! [13] + + +//! [14] +ba = QByteArray("Istambul") +ba.fill('o') +# ba == "oooooooo" + +ba.fill('X', 2) +# ba == "XX" +//! [14] + + +//! [15] +x = QByteArray("ship") +y = QByteArray("air") +x.prepend(y) +# x == "airship" +//! [15] + + +//! [16] +x = QByteArray("free") +y = QByteArray("dom") +x.append(y) +# x == "freedom" +//! [16] + + +//! [17] +ba = QByteArray("Meal") +ba.insert(1, QByteArray("ontr")) +# ba == "Montreal" +//! [17] + + +//! [18] +ba = QByteArray("Montreal") +ba.remove(1, 4) +# ba == "Meal" +//! [18] + + +//! [19] +x = QByteArray("Say yes!") +y = QByteArray("no") +x.replace(4, 3, y) +# x == "Say no!" +//! [19] + + +//! [20] +ba = QByteArray("colour behaviour flavour neighbour") +ba.replace(QByteArray("ou"), QByteArray("o")) +# ba == "color behavior flavor neighbor" +//! [20] + + +//! [21] +x = QByteArray("sticky question") +y = QByteArray("sti") +x.indexOf(y) # returns 0 +x.indexOf(y, 1) # returns 10 +x.indexOf(y, 10) # returns 10 +x.indexOf(y, 11) # returns -1 +//! [21] + + +//! [22] +ba = QByteArray("ABCBA") +ba.indexOf("B") # returns 1 +ba.indexOf("B", 1) # returns 1 +ba.indexOf("B", 2) # returns 3 +ba.indexOf("X") # returns -1 +//! [22] + + +//! [23] +x = QByteArray("crazy azimuths") +y = QByteArray("azy") +x.lastIndexOf(y) # returns 6 +x.lastIndexOf(y, 6) # returns 6 +x.lastIndexOf(y, 5) # returns 2 +x.lastIndexOf(y, 1) # returns -1 +//! [23] + + +//! [24] +ba = QByteArray("ABCBA") +ba.lastIndexOf("B") # returns 3 +ba.lastIndexOf("B", 3) # returns 3 +ba.lastIndexOf("B", 2) # returns 1 +ba.lastIndexOf("X") # returns -1 +//! [24] + + +//! [25] +url = QByteArray("ftp://ftp.trolltech.com/") +if url.startsWith("ftp:"): + ... +//! [25] + + +//! [26] +url = QByteArray("http://qtsoftware.com/index.html") +if url.endsWith(".html"): + ... +//! [26] + + +//! [27] +x = QByteArray("Pineapple") +y = x.left(4) +# y == "Pine" +//! [27] + + +//! [28] +x = QByteArray("Pineapple") +y = x.right(5) +# y == "apple" +//! [28] + + +//! [29] +x = QByteArray("Five pineapples") +y = x.mid(5, 4) # y == "pine" +z = x.mid(5) # z == "pineapples" +//! [29] + + +//! [30] +x = QByteArray("TROlltECH") +y = x.toLower() +# y == "trolltech" +//! [30] + + +//! [31] +x = QByteArray("TROlltECH") +y = x.toUpper() +# y == "TROLLTECH" +//! [31] + + +//! [32] +ba = QByteArray(" lots\t of\nwhitespace\r\n ") +ba = ba.simplified() +# ba == "lots of whitespace"; +//! [32] + + +//! [33] +ba = QByteArray(" lots\t of\nwhitespace\r\n "); +ba = ba.trimmed(); +# ba == "lots\t of\nwhitespace"; +//! [33] + + +//! [34] +x = QByteArray("apple") +y = x.leftJustified(8, '.') # y == "apple..." +//! [34] + + +//! [35] +x = QByteArray("apple") +y = x.rightJustified(8, '.') # y == "...apple" +//! [35] + + +//! [36] +string = QByteArray("FF") +(hex, ok) = string.toInt(16) # hex == 255, ok == true +(dec, ok) = string.toInt(10) # dec == 0, ok == false +//! [36] + + +//! [37] +string = QByteArray("FF") +(hex, ok) = str.toLong(16); # hex == 255, ok == true +(dec, ok) = str.toLong(10); # dec == 0, ok == false +//! [37] + + +//! [38] +string = QByteArray("1234.56") +(a, ok) = string.toDouble() # a == 1234.56, ok == true +//! [38] + + +//! [39] +text = QByteArray("Qt is great!") +text.toBase64() # returns "UXQgaXMgZ3JlYXQh" +//! [39] + + +//! [40] +ba = QByteArray() +n = 63 +ba.setNum(n) # ba == "63" +ba.setNum(n, 16) # ba == "3f" +//! [40] + + +//! [41] +n = 63; +QByteArray.number(n) # returns "63" +QByteArray.number(n, 16) # returns "3f" +QByteArray.number(n, 16).toUpper() # returns "3F" +//! [41] + + +//! [42] +ba = QByteArray.number(12.3456, 'E', 3) +# ba == 1.235E+01 +//! [42] + + +//! [43] +mydata = '\x00\x00\x03\x84\x78\x9c\x3b\x76'\ + '\xec\x18\xc3\x31\x0a\xf1\xcc\x99'\ + ... + '\x6d\x5b' + +data = QByteArray.fromRawData(mydata) +in_ = QDataStream(data, QIODevice.ReadOnly) +... +//! [43] + + +//! [44] +text = QByteArray.fromBase64("UXQgaXMgZ3JlYXQh") +text.data() # returns "Qt is great!" +//! [44] + + +//! [45] +text = QByteArray.fromHex("517420697320677265617421") +text.data() # returns "Qt is great!" +//! [45] + +} + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qdatetime.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qdatetime.cpp new file mode 100644 index 000000000..f3a230894 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qdatetime.cpp @@ -0,0 +1,156 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +d1 = QDate(1995, 5, 17) # May 17, 1995 +d2 = QDate(1995, 5, 20) # May 20, 1995 +d1.daysTo(d2) # returns 3 +d2.daysTo(d1) # returns -3 +//! [0] + + +//! [1] +date = QDate.fromString("1MM12car2003", "d'MM'MMcaryyyy") +# date is 1 December 2003 +//! [1] + + +//! [2] +date = QDate.fromString("130", "Md") # invalid +//! [2] + + +//! [3] +QDate.fromString("1.30", "M.d") # January 30 1900 +QDate.fromString("20000110", "yyyyMMdd") # January 10, 2000 +QDate.fromString("20000110", "yyyyMd") # January 10, 2000 +//! [3] + + +//! [4] +QDate.isValid(2002, 5, 17) # True +QDate.isValid(2002, 2, 30) # False (Feb 30 does not exist) +QDate.isValid(2004, 2, 29) # True (2004 is a leap year) +QDate.isValid(2000, 2, 29) # True (2000 is a leap year) +QDate.isValid(2006, 2, 29) # False (2006 is not a leap year) +QDate.isValid(2100, 2, 29) # False (2100 is not a leap year) +QDate.isValid(1202, 6, 6) # True (even though 1202 is pre-Gregorian) +//! [4] + + +//! [5] +n = QTime(14, 0, 0) # n == 14:00:00 +t = QTime() +t = n.addSecs(70) # t == 14:01:10 +t = n.addSecs(-70) # t == 13:58:50 +t = n.addSecs(10 * 60 * 60 + 5) # t == 00:00:05 +t = n.addSecs(-15 * 60 * 60) # t == 23:00:00 +//! [5] + + +//! [6] +time = QTime.fromString("1mm12car00", "m'mm'hcarss") +# time is 12:01.00 +//! [6] + + +//! [7] +time = QTime.fromString("00:710", "hh:ms") # invalid +//! [7] + + +//! [8] +time = QTime.fromString("1.30", "m.s") +# time is 00:01:30.000 +//! [8] + + +//! [9] +QTime.isValid(21, 10, 30) # returns True +QTime.isValid(22, 5, 62) # returns False +//! [9] + + +//! [10] +t = QTime() +t.start() +some_lengthy_task() +print ("Time elapsed: %d ms" % t.elapsed()) +//! [10] + + +//! [11] +now = QDateTime.currentDateTime() +xmas(QDate(now.date().year(), 12, 25), QTime(0, 0)) +print("There are %d seconds to Christmas" % now.secsTo(xmas)) +//! [11] + + +//! [12] +time1 = QTime.fromString("131", "HHh") +# time1 is 13:00:00 +time1 = QTime.fromString("1apA", "1amAM") +# time1 is 01:00:00 + +dateTime2 = QDateTime.fromString("M1d1y9800:01:02", + "'M'M'd'd'y'yyhh:mm:ss") +# dateTime is 1 January 1998 00:01:02 +//! [12] + + +//! [13] +dateTime = QDateTime.fromString("130", "Mm") # invalid +//! [13] + + +//! [14] +dateTime = QDateTime.fromString("1.30.1", "M.d.s") +# dateTime is January 30 in 1900 at 00:00:01. +//! [14] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qhash.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qhash.cpp new file mode 100644 index 000000000..b742a51b3 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qhash.cpp @@ -0,0 +1,309 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +QHash<QString, int> hash; +//! [0] + + +//! [1] +hash["one"] = 1; +hash["three"] = 3; +hash["seven"] = 7; +//! [1] + + +//! [2] +hash.insert("twelve", 12); +//! [2] + + +//! [3] +int num1 = hash["thirteen"]; +int num2 = hash.value("thirteen"); +//! [3] + + +//! [4] +int timeout = 30; +if (hash.contains("TIMEOUT")) + timeout = hash.value("TIMEOUT"); +//! [4] + + +//! [5] +int timeout = hash.value("TIMEOUT", 30); +//! [5] + + +//! [6] +// WRONG +QHash<int, QWidget *> hash; +... +for (int i = 0; i < 1000; ++i) { + if (hash[i] == okButton) + cout << "Found button at index " << i << endl; +} +//! [6] + + +//! [7] +QHashIterator<QString, int> i(hash); +while (i.hasNext()) { + i.next(); + cout << i.key() << ": " << i.value() << endl; +} +//! [7] + + +//! [8] +QHash<QString, int>::const_iterator i = hash.constBegin(); +while (i != hash.constEnd()) { + cout << i.key() << ": " << i.value() << endl; + ++i; +} +//! [8] + + +//! [9] +hash.insert("plenty", 100); +hash.insert("plenty", 2000); +// hash.value("plenty") == 2000 +//! [9] + + +//! [10] +QList<int> values = hash.values("plenty"); +for (int i = 0; i < values.size(); ++i) + cout << values.at(i) << endl; +//! [10] + + +//! [11] +QHash<QString, int>::iterator i = hash.find("plenty"); +while (i != hash.end() && i.key() == "plenty") { + cout << i.value() << endl; + ++i; +} +//! [11] + + +//! [12] +QHash<QString, int> hash; +... +foreach (int value, hash) + cout << value << endl; +//! [12] + + +//! [13] +#ifndef EMPLOYEE_H +#define EMPLOYEE_H + +class Employee +{ +public: + Employee() {} + Employee(const QString &name, const QDate &dateOfBirth); + ... + +private: + QString myName; + QDate myDateOfBirth; +}; + +inline bool operator==(const Employee &e1, const Employee &e2) +{ + return e1.name() == e2.name() + && e1.dateOfBirth() == e2.dateOfBirth(); +} + +inline uint qHash(const Employee &key) +{ + return qHash(key.name()) ^ key.dateOfBirth().day(); +} + +#endif // EMPLOYEE_H +//! [13] + + +//! [14] +QHash<QString, int> hash; +hash.reserve(20000); +for (int i = 0; i < 20000; ++i) + hash.insert(keys[i], values[i]); +//! [14] + + +//! [15] +QHash<QObject *, int> objectHash; +... +QHash<QObject *, int>::iterator i = objectHash.find(obj); +while (i != objectHash.end() && i.key() == obj) { + if (i.value() == 0) { + i = objectHash.erase(i); + } else { + ++i; + } +} +//! [15] + + +//! [16] +QHash<QString, int> hash; +... +QHash<QString, int>::const_iterator i = hash.find("HDR"); +while (i != hash.end() && i.key() == "HDR") { + cout << i.value() << endl; + ++i; +} +//! [16] + + +//! [17] +QHash<QString, int> hash; +hash.insert("January", 1); +hash.insert("February", 2); +... +hash.insert("December", 12); + +QHash<QString, int>::iterator i; +for (i = hash.begin(); i != hash.end(); ++i) + cout << i.key() << ": " << i.value() << endl; +//! [17] + + +//! [18] +QHash<QString, int>::iterator i; +for (i = hash.begin(); i != hash.end(); ++i) + i.value() += 2; +//! [18] + + +//! [19] +QHash<QString, int>::iterator i = hash.begin(); +while (i != hash.end()) { + if (i.key().startsWith("_")) + i = hash.erase(i); + else + ++i; +} +//! [19] + + +//! [20] +QHash<QString, int>::iterator i = hash.begin(); +while (i != hash.end()) { + QHash<QString, int>::iterator prev = i; + ++i; + if (prev.key().startsWith("_")) + hash.erase(prev); +} +//! [20] + + +//! [21] +// WRONG +while (i != hash.end()) { + if (i.key().startsWith("_")) + hash.erase(i); + ++i; +} +//! [21] + + +//! [22] +if (i.key() == "Hello") + i.value() = "Bonjour"; +//! [22] + + +//! [23] +QHash<QString, int> hash; +hash.insert("January", 1); +hash.insert("February", 2); +... +hash.insert("December", 12); + +QHash<QString, int>::const_iterator i; +for (i = hash.constBegin(); i != hash.constEnd(); ++i) + cout << i.key() << ": " << i.value() << endl; +//! [23] + + +//! [24] +QMultiHash<QString, int> hash1, hash2, hash3; + +hash1.insert("plenty", 100); +hash1.insert("plenty", 2000); +// hash1.size() == 2 + +hash2.insert("plenty", 5000); +// hash2.size() == 1 + +hash3 = hash1 + hash2; +// hash3.size() == 3 +//! [24] + + +//! [25] +QList<int> values = hash.values("plenty"); +for (int i = 0; i < values.size(); ++i) + cout << values.at(i) << endl; +//! [25] + + +//! [26] +QMultiHash<QString, int>::iterator i = hash.find("plenty"); +while (i != hash.end() && i.key() == "plenty") { + cout << i.value() << endl; + ++i; +} +//! [26] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp new file mode 100644 index 000000000..41dc8f848 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp @@ -0,0 +1,214 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +QLinkedList<int> integerList; +QLinkedList<QTime> timeList; +//! [0] + + +//! [1] +QLinkedList<QString> list; +list << "one" << "two" << "three"; +// list: ["one", "two", "three"] +//! [1] + + +//! [2] +QLinkedList<QWidget *> list; +... +while (!list.isEmpty()) + delete list.takeFirst(); +//! [2] + + +//! [3] +QLinkedList<QString> list; +list.append("one"); +list.append("two"); +list.append("three"); +// list: ["one", "two", "three"] +//! [3] + + +//! [4] +QLinkedList<QString> list; +list.prepend("one"); +list.prepend("two"); +list.prepend("three"); +// list: ["three", "two", "one"] +//! [4] + + +//! [5] +QList<QString> list; +list << "sun" << "cloud" << "sun" << "rain"; +list.removeAll("sun"); +// list: ["cloud", "rain"] +//! [5] + + +//! [6] +QList<QString> list; +list << "sun" << "cloud" << "sun" << "rain"; +list.removeOne("sun"); +// list: ["cloud", "sun", "rain"] +//! [6] + + +//! [7] +QLinkedList<QString> list; +list.append("January"); +list.append("February"); +... +list.append("December"); + +QLinkedList<QString>::iterator i; +for (i = list.begin(); i != list.end(); ++i) + cout << *i << endl; +//! [7] + + +//! [8] +QLinkedList<QString> list; +... +QLinkedList<QString>::iterator it = qFind(list.begin(), + list.end(), "Joel"); +if (it != list.end()) + cout << "Found Joel" << endl; +//! [8] + + +//! [9] +QLinkedList<int>::iterator i; +for (i = list.begin(); i != list.end(); ++i) + *i += 2; +//! [9] + + +//! [10] +QLinkedList<QString> list; +... +QLinkedList<QString>::iterator i = list.begin(); +while (i != list.end()) { + if ((*i).startsWith("_")) + i = list.erase(i); + else + ++i; +} +//! [10] + + +//! [11] +QLinkedList<QString>::iterator i = list.begin(); +while (i != list.end()) { + QLinkedList<QString>::iterator previous = i; + ++i; + if ((*previous).startsWith("_")) + list.erase(previous); +} +//! [11] + + +//! [12] +// WRONG +while (i != list.end()) { + if ((*i).startsWith("_")) + list.erase(i); + ++i; +} +//! [12] + + +//! [13] +if (*it == "Hello") + *it = "Bonjour"; +//! [13] + + +//! [14] +QLinkedList<QString> list; +list.append("January"); +list.append("February"); +... +list.append("December"); + +QLinkedList<QString>::const_iterator i; +for (i = list.constBegin(); i != list.constEnd(); ++i) + cout << *i << endl; +//! [14] + + +//! [15] +QLinkedList<QString> list; +... +QLinkedList<QString>::iterator it = qFind(list.constBegin(), + list.constEnd(), "Joel"); +if (it != list.constEnd()) + cout << "Found Joel" << endl; +//! [15] + + +//! [16] +std::list<double> stdlist; +list.push_back(1.2); +list.push_back(0.5); +list.push_back(3.14); + +QLinkedList<double> list = QLinkedList<double>::fromStdList(stdlist); +//! [16] + + +//! [17] +QLinkedList<double> list; +list << 1.2 << 0.5 << 3.14; + +std::list<double> stdlist = list.toStdList(); +//! [17] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlistdata.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlistdata.cpp new file mode 100644 index 000000000..de65c5e6b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlistdata.cpp @@ -0,0 +1,277 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +QList<int> integerList; +QList<QDate> dateList; +//! [0] + + +//! [1] +QList<QString> list; +list << "one" << "two" << "three"; +// list: ["one", "two", "three"] +//! [1] + + +//! [2] +if (list[0] == "Bob") + list[0] = "Robert"; +//! [2] + + +//! [3] +for (int i = 0; i < list.size(); ++i) { + if (list.at(i) == "Jane") + cout << "Found Jane at position " << i << endl; +} +//! [3] + + +//! [4] +QList<QWidget *> list; +... +while (!list.isEmpty()) + delete list.takeFirst(); +//! [4] + + +//! [5] +int i = list.indexOf("Jane"); +if (i != -1) + cout << "First occurrence of Jane is at position " << i << endl; +//! [5] + + +//! [6] +QList<QString> list; +list.append("one"); +list.append("two"); +list.append("three"); +// list: ["one", "two", "three"] +//! [6] + + +//! [7] +QList<QString> list; +list.prepend("one"); +list.prepend("two"); +list.prepend("three"); +// list: ["three", "two", "one"] +//! [7] + + +//! [8] +QList<QString> list; +list << "alpha" << "beta" << "delta"; +list.insert(2, "gamma"); +// list: ["alpha", "beta", "gamma", "delta"] +//! [8] + + +//! [9] +QList<QString> list; +list << "sun" << "cloud" << "sun" << "rain"; +list.removeAll("sun"); +// list: ["cloud", "rain"] +//! [9] + + +//! [10] +QList<QString> list; +list << "sun" << "cloud" << "sun" << "rain"; +list.removeOne("sun"); +// list: ["cloud", ,"sun", "rain"] +//! [10] + + +//! [11] +QList<QString> list; +list << "A" << "B" << "C" << "D" << "E" << "F"; +list.move(1, 4); +// list: ["A", "C", "D", "E", "B", "F"] +//! [11] + + +//! [12] +QList<QString> list; +list << "A" << "B" << "C" << "D" << "E" << "F"; +list.swap(1, 4); +// list: ["A", "E", "C", "D", "B", "F"] +//! [12] + + +//! [13] +QList<QString> list; +list << "A" << "B" << "C" << "B" << "A"; +list.indexOf("B"); // returns 1 +list.indexOf("B", 1); // returns 1 +list.indexOf("B", 2); // returns 3 +list.indexOf("X"); // returns -1 +//! [13] + + +//! [14] +QList<QString> list; +list << "A" << "B" << "C" << "B" << "A"; +list.lastIndexOf("B"); // returns 3 +list.lastIndexOf("B", 3); // returns 3 +list.lastIndexOf("B", 2); // returns 1 +list.lastIndexOf("X"); // returns -1 +//! [14] + + +//! [15] +QList<QString> list; +list.append("January"); +list.append("February"); +... +list.append("December"); + +QList<QString>::iterator i; +for (i = list.begin(); i != list.end(); ++i) + cout << *i << endl; +//! [15] + + +//! [16] +QList<int>::iterator i; +for (i = list.begin(); i != list.end(); ++i) + *i += 2; +//! [16] + + +//! [17] +QList<QWidget *> list; +... +qDeleteAll(list.begin(), list.end()); +//! [17] + + +//! [18] +if (*it == "Hello") + *it = "Bonjour"; +//! [18] + + +//! [19] +QList<QString> list; +list.append("January"); +list.append("February"); +... +list.append("December"); + +QList<QString>::const_iterator i; +for (i = list.constBegin(); i != list.constEnd(); ++i) + cout << *i << endl; +//! [19] + + +//! [20] +QList<QWidget *> list; +... +qDeleteAll(list.constBegin(), list.constEnd()); +//! [20] + + +//! [21] +QVector<double> vect; +vect << 20.0 << 30.0 << 40.0 << 50.0; + +QList<double> list = QVector<T>::fromVector(vect); +// list: [20.0, 30.0, 40.0, 50.0] +//! [21] + + +//! [22] +QStringList list; +list << "Sven" << "Kim" << "Ola"; + +QVector<QString> vect = list.toVector(); +// vect: ["Sven", "Kim", "Ola"] +//! [22] + + +//! [23] +QSet<double> set; +set << 20.0 << 30.0 << 40.0 << ... << 70.0; + +QList<double> list = QList<double>::fromSet(set); +qSort(list); +//! [23] + + +//! [24] +QStringList list; +list << "Julia" << "Mike" << "Mike" << "Julia" << "Julia"; + +QSet<QString> set = list.toSet(); +set.contains("Julia"); // returns true +set.contains("Mike"); // returns true +set.size(); // returns 2 +//! [24] + + +//! [25] +std::list<double> stdlist; +list.push_back(1.2); +list.push_back(0.5); +list.push_back(3.14); + +QList<double> list = QList<double>::fromStdList(stdlist); +//! [25] + + +//! [26] +QList<double> list; +list << 1.2 << 0.5 << 3.14; + +std::list<double> stdlist = list.toStdList(); +//! [26] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlocale.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlocale.cpp new file mode 100644 index 000000000..4a8de1a86 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlocale.cpp @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +egyptian = QLocale(QLocale.Arabic, QLocale.Egypt) +s1 = egyptian.toString(1.571429E+07, 'e') +s2 = egyptian.toString(10) + +(d, ok) = egyptian.toDouble(s1) +(i, ok) = egyptian.toInt(s2) +//! [0] + + +//! [1] +QLocale.setDefault(QLocale(QLocale.Hebrew, QLocale.Israel)) +hebrew = QLocale() # Constructs a default QLocale +s1 = hebrew.toString(15714.3, 'e') + +QLocale.setDefault(QLocale(QLocale.C)) +c = QLocale() +(d, ok) = c.toDouble("1234,56") # ok == false +(d, ok) = c.toDouble("1234.56") # ok == true, d == 1234.56 + +QLocale.setDefault(QLocale(QLocale.German)) +german = QLocale() +(d, ok) = german.toDouble("1234,56") # ok == true, d == 1234.56 +(d, ok) = german.toDouble("1234.56") # ok == true, d == 1234.56 + +QLocale.setDefault(QLocale(QLocale.English, QLocale.UnitedStates)) +english = QLocale() +string = '%s %s %10x' % (12345, english.toString(12345), 12345) +# string == "12345 12,345 3039" +//! [1] + + +//! [2] +korean = QLocale("ko") +swiss = QLocale("de_CH") +//! [2] + + +//! [3] +c = QLocale(QLocale.C) +(d, ok) = c.toDouble( "1234.56" ) # ok == true, d == 1234.56 +(d, ok) = c.toDouble( "1,234.56" ) # ok == true, d == 1234.56 +(d, ok) = c.toDouble( "1234,56" ) # ok == false + +german = QLocale(QLocale.German) +(d, ok) = german.toDouble( "1234,56" ) # ok == true, d == 1234.56 +(d, ok) = german.toDouble( "1.234,56" ) # ok == true, d == 1234.56 +(d, ok) = german.toDouble( "1234.56" ) # ok == false + +(d, ok) = german.toDouble( "1.234" ) # ok == true, d == 1234.0 +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qmap.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qmap.cpp new file mode 100644 index 000000000..da0b4dad8 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qmap.cpp @@ -0,0 +1,323 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +QMap<QString, int> map; +//! [0] + + +//! [1] +map["one"] = 1; +map["three"] = 3; +map["seven"] = 7; +//! [1] + + +//! [2] +map.insert("twelve", 12); +//! [2] + + +//! [3] +int num1 = map["thirteen"]; +int num2 = map.value("thirteen"); +//! [3] + + +//! [4] +int timeout = 30; +if (map.contains("TIMEOUT")) + timeout = map.value("TIMEOUT"); +//! [4] + + +//! [5] +int timeout = map.value("TIMEOUT", 30); +//! [5] + + +//! [6] +// WRONG +QMap<int, QWidget *> map; +... +for (int i = 0; i < 1000; ++i) { + if (map[i] == okButton) + cout << "Found button at index " << i << endl; +} +//! [6] + + +//! [7] +QMapIterator<QString, int> i(map); +while (i.hasNext()) { + i.next(); + cout << i.key() << ": " << i.value() << endl; +} +//! [7] + + +//! [8] +QMap<QString, int>::const_iterator i = map.constBegin(); +while (i != map.constEnd()) { + cout << i.key() << ": " << i.value() << endl; + ++i; +} +//! [8] + + +//! [9] +map.insert("plenty", 100); +map.insert("plenty", 2000); +// map.value("plenty") == 2000 +//! [9] + + +//! [10] +QList<int> values = map.values("plenty"); +for (int i = 0; i < values.size(); ++i) + cout << values.at(i) << endl; +//! [10] + + +//! [11] +QMap<QString, int>::iterator i = map.find("plenty"); +while (i != map.end() && i.key() == "plenty") { + cout << i.value() << endl; + ++i; +} +//! [11] + + +//! [12] +QMap<QString, int> map; +... +foreach (int value, map) + cout << value << endl; +//! [12] + + +//! [13] +#ifndef EMPLOYEE_H +#define EMPLOYEE_H + +class Employee +{ +public: + Employee() {} + Employee(const QString &name, const QDate &dateOfBirth); + ... + +private: + QString myName; + QDate myDateOfBirth; +}; + +inline bool operator<(const Employee &e1, const Employee &e2) +{ + if (e1.name() != e2.name()) + return e1.name() < e2.name(); + return e1.dateOfBirth() < e2.dateOfBirth(); +} + +#endif // EMPLOYEE_H +//! [13] + + +//! [14] +QMap<QString, int> map; +... +QMap<QString, int>::const_iterator i = map.find("HDR"); +while (i != map.end() && i.key() == "HDR") { + cout << i.value() << endl; + ++i; +} +//! [14] + + +//! [15] +QMap<int, QString> map; +map.insert(1, "one"); +map.insert(5, "five"); +map.insert(10, "ten"); + +map.lowerBound(0); // returns iterator to (1, "one") +map.lowerBound(1); // returns iterator to (1, "one") +map.lowerBound(2); // returns iterator to (5, "five") +map.lowerBound(10); // returns iterator to (10, "ten") +map.lowerBound(999); // returns end() +//! [15] + + +//! [16] +QMap<QString, int> map; +... +QMap<QString, int>::const_iterator i = map.lowerBound("HDR"); +QMap<QString, int>::const_iterator upperBound = map.upperBound("HDR"); +while (i != upperBound) { + cout << i.value() << endl; + ++i; +} +//! [16] + + +//! [17] +QMap<int, QString> map; +map.insert(1, "one"); +map.insert(5, "five"); +map.insert(10, "ten"); + +map.upperBound(0); // returns iterator to (1, "one") +map.upperBound(1); // returns iterator to (5, "five") +map.upperBound(2); // returns iterator to (5, "five") +map.upperBound(10); // returns end() +map.upperBound(999); // returns end() +//! [17] + + +//! [18] +QMap<QString, int> map; +map.insert("January", 1); +map.insert("February", 2); +... +map.insert("December", 12); + +QMap<QString, int>::iterator i; +for (i = map.begin(); i != map.end(); ++i) + cout << i.key() << ": " << i.value() << endl; +//! [18] + + +//! [19] +QMap<QString, int>::iterator i; +for (i = map.begin(); i != map.end(); ++i) + i.value() += 2; +//! [19] + + +//! [20] +QMap<QString, int>::iterator i = map.begin(); +while (i != map.end()) { + if (i.key().startsWith("_")) + i = map.erase(i); + else + ++i; +} +//! [20] + + +//! [21] +QMap<QString, int>::iterator i = map.begin(); +while (i != map.end()) { + QMap<QString, int>::iterator prev = i; + ++i; + if (prev.key().startsWith("_")) + map.erase(prev); +} +//! [21] + + +//! [22] +// WRONG +while (i != map.end()) { + if (i.key().startsWith("_")) + map.erase(i); + ++i; +} +//! [22] + + +//! [23] +if (i.key() == "Hello") + i.value() = "Bonjour"; +//! [23] + + +//! [24] +QMap<QString, int> map; +map.insert("January", 1); +map.insert("February", 2); +... +map.insert("December", 12); + +QMap<QString, int>::const_iterator i; +for (i = map.constBegin(); i != map.constEnd(); ++i) + cout << i.key() << ": " << i.value() << endl; +//! [24] + + +//! [25] +QMultiMap<QString, int> map1, map2, map3; + +map1.insert("plenty", 100); +map1.insert("plenty", 2000); +// map1.size() == 2 + +map2.insert("plenty", 5000); +// map2.size() == 1 + +map3 = map1 + map2; +// map3.size() == 3 +//! [25] + + +//! [26] +QList<int> values = map.values("plenty"); +for (int i = 0; i < values.size(); ++i) + cout << values.at(i) << endl; +//! [26] + + +//! [27] +QMultiMap<QString, int>::iterator i = map.find("plenty"); +while (i != map.end() && i.key() == "plenty") { + cout << i.value() << endl; + ++i; +} +//! [27] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qpoint.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qpoint.cpp new file mode 100644 index 000000000..3b11b62f0 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qpoint.cpp @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +p = QPoint() + +p.setX(p.x() + 1) +p += QPoint(1, 0) +//! [0] + + +//! [1] +p = QPoint(1, 2) +#p.rx()--; // p becomes (0, 2) +//! [1] + + +//! [2] +p = QPoint(1, 2) +#p.ry()++; // p becomes (1, 3) +//! [2] + + +//! [3] +p = QPoint( 3, 7) +q = QPoint(-1, 4) +p += q # p becomes (2, 11) +//! [3] + + +//! [4] +p = QPoint( 3, 7) +q = QPoint(-1, 4) +p -= q # p becomes (4, 3) +//! [4] + + +//! [5] +p = QPoint(-1, 4) +p *= 2.5 # p becomes (-3, 10) +//! [5] + + +//! [6] +p = QPoint(-3, 10) +p /= 2.5 # p becomes (-1, 4) +//! [6] + + +//! [7] + +class MyWidget(QWidget): + + self.oldPosition = QPointer() + + # event : QMouseEvent + def mouseMoveEvent(QMouseEvent event): + point = event.pos() - self.oldPosition + if (point.manhattanLength() > 3): + # the mouse has moved more than 3 pixels since the oldPosition + pass +//! [7] + + +//! [8] +trueLength = sqrt(pow(x(), 2) + pow(y(), 2)) +//! [8] + + +//! [9] +p = QPointF() + +p.setX(p.x() + 1.0) +p += QPointF(1.0, 0.0) +#p.rx()++; +//! [9] + + +//! [10] + p = QPointF(1.1, 2.5) + #p.rx()--; // p becomes (0.1, 2.5) +//! [10] + + +//! [11] +p = QPointF(1.1, 2.5) +#p.ry()++; // p becomes (1.1, 3.5) +//! [11] + + +//! [12] +p = QPointF( 3.1, 7.1) +q = QPointF(-1.0, 4.1) +p += q # p becomes (2.1, 11.2) +//! [12] + + +//! [13] +p = QPointF( 3.1, 7.1) +q = QPointF(-1.0, 4.1) +p -= q # p becomes (4.1, 3.0) +//! [13] + + +//! [14] +p = QPointF(-1.1, 4.1) +p *= 2.5 # p becomes (-2.75, 10.25) +//! [14] + + +//! [15] +p = QPointF(-2.75, 10.25) +p /= 2.5 # p becomes (-1.1, 4.1) +//! [15] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qqueue.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qqueue.cpp new file mode 100644 index 000000000..372cb0d5d --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qqueue.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +QQueue<int> queue; +queue.enqueue(1); +queue.enqueue(2); +queue.enqueue(3); +while (!queue.isEmpty()) + cout << queue.dequeue() << endl; +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qrect.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qrect.cpp new file mode 100644 index 000000000..1154d11a3 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qrect.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +r1 = QRect(100, 200, 11, 16) +r2 = QRect(QPoint(100, 200), QSize(11, 16)) +//! [0] + + +//! [1] +r1 = QRectF(100, 200, 11, 16) +r2 = QRectF(QPoint(100, 200), QSize(11, 16)) +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qregexp.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qregexp.cpp new file mode 100644 index 000000000..338582651 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qregexp.cpp @@ -0,0 +1,225 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +rx = QRegExp("(\\d+)") +txt = "Offsets: 12 14 99 231 7" +lst = [] + +pos = rx.indexIn(txt, 0) + +while pos != -1: + lst.append(rx.cap(1)) + pos += rx.matchedLength() + pos = rx.indexIn(txt, pos) + +# lst: ["12", "14", "99", "231", "7"] +//! [0] + + +//! [1] +rx = QRegExp("*.txt") +rx.setPatternSyntax(QRegExp.Wildcard) +rx.exactMatch("README.txt") # returns True +rx.exactMatch("welcome.txt.bak") # returns False +//! [1] + + +//! [2] +rx = QRegExp("ro+m") +rx.setMinimal(True) +//! [2] + + +//! [3] +mark = QRegExp("\\b" # word boundary + "[Mm]ark" # the word we want to match + ) +//! [3] + + +//! [4] +rx = QRegExp("^\\d\\d?$") # match integers 0 to 99 +rx.indexIn("123") # returns -1 (no match) +rx.indexIn("-6") # returns -1 (no match) +rx.indexIn("6") # returns 0 (matched as position 0) +//! [4] + + +//! [5] +rx = QRegExp("^\\S+$") # match strings without whitespace +rx.indexIn("Hello world") # returns -1 (no match) +rx.indexIn("This_is-OK") # returns 0 (matched at position 0) +//! [5] + + +//! [6] +rx = QRegExp("\\b(mail|letter|correspondence)\\b") +rx.indexIn("I sent you an email") # returns -1 (no match) +rx.indexIn("Please write the letter") # returns 17 +//! [6] + + +//! [7] +captured = rx.cap(1) # captured == "letter" +//! [7] + + +//! [8] +rx = QRegExp("&(?!amp;)") # match ampersands but not & +line1 = QString("This & that") +line1.replace(rx, "&") # line1 == "This & that" +line2 = QString("His & hers & theirs") +line2.replace(rx, "&") # line2 == "His & hers & theirs" +//! [8] + + +//! [9] +txt = QString("One Eric another Eirik, and an Ericsson. How many Eiriks, Eric?") +rx = QRegExp("\\b(Eric|Eirik)\\b") # match Eric or Eirik +pos = 0 # where we are in the string +count = 0 # how many Eric and Eirik's we've counted + +while pos >= 0: + pos = rx.indexIn(txt, pos) + if pos >= 0: + pos += 1 # move along in str + count += 1 # count our Eric or Eirik +//! [9] + + +//! [10] +txt = "Nokia Corporation and/or its subsidiary(-ies)\tqtsoftware.com\tNorway" +rx.setPattern("^([^\t]+)\t([^\t]+)\t([^\t]+)$"); +if rx.indexIn(txt) != -1: + company = rx.cap(1) + web = rx.cap(2) + country = rx.cap(3) +//! [10] + + +//! [11] +field = txt.split("\t") +//! [11] + + +//! [12] +rx = QRegExp("*.html") +rx.setPatternSyntax(QRegExp.Wildcard) +rx.exactMatch("index.html") # returns True +rx.exactMatch("default.htm") # returns False +rx.exactMatch("readme.txt") # returns False +//! [12] + + +//! [13] +txt = QString("offsets: 1.23 .50 71.00 6.00") +rx = QRegExp("\\d*\\.\\d+") # primitive floating point matching +count = 0 +pos = rx.indexIn(txt, 0) +while pos != -1: + count += 1 + pos += rx.matchedLength() + pos = rx.indexIn(txt, pos) + +# pos will be 9, 14, 18 and finally 24; count will end up as 4 +//! [13] + + +//! [14] +rx = QRegExp("(\\d+)(\\s*)(cm|inch(es)?)") +pos = rx.indexIn("Length: 36 inches") +lst = rx.capturedTexts() +# lst is now ("36 inches", "36", " ", "inches", "es") +//! [14] + + +//! [15] +rx = QRegExp("(\\d+)(?:\\s*)(cm|inch(?:es)?)") +pos = rx.indexIn("Length: 36 inches") +lst = rx.capturedTexts() +# lst is now ("36 inches", "36", "inches") +//! [15] + + +//! [16] +for a in rx.capturedTexts(): + myProcessing(a) +//! [16] + + +//! [17] +rxlen = QRegExp("(\\d+)(?:\\s*)(cm|inch)") +pos = rxlen.indexIn("Length: 189cm") +if pos > -1: + value = rxlen.cap(1) # "189" + unit = rxlen.cap(2) # "cm" +//! [17] + + +//! [18] +rx = QRegExp("/([a-z]+)/([a-z]+)") +rx.indexIn("Output /dev/null") # returns 7 (position of /dev/null) +rx.pos(0) # returns 7 (position of /dev/null) +rx.pos(1) # returns 8 (position of dev) +rx.pos(2) # returns 12 (position of null) +//! [18] + + +//! [19] +s1 = QRegExp.escape("bingo") # s1 == "bingo" +s2 = QRegExp.escape("f(x)") # s2 == "f\\(x\\)" +//! [19] + + +//! [20] +rx = QRegExp("(" + QRegExp.escape(name) + "|" + QRegExp.escape(alias) + ")") +//! [20] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qsize.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qsize.cpp new file mode 100644 index 000000000..7897e141c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qsize.cpp @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +t1 = QSize(10, 12) +t1.scale(60, 60, Qt.IgnoreAspectRatio) +# t1 is (60, 60) + +t2 = QSize(10, 12) +t2.scale(60, 60, Qt.KeepAspectRatio) +# t2 is (50, 60) + +t3 = QSize(10, 12) +t3.scale(60, 60, Qt.KeepAspectRatioByExpanding) +# t3 is (60, 72) +//! [0] + + +//! [1] +size = QSize(100, 10) +size.rwidth() += 20 + +#size becomes (120,10) +//! [1] + + +//! [2] +size = QSize(100, 10) +size.rheight() += 5 + +# size becomes (100,15) +//! [2] + + +//! [3] +s = QSize( 3, 7) +r = QSize(-1, 4) +s += r + +# s becomes (2,11) +//! [3] + + +//! [4] +s = QSize( 3, 7) +r = QSize(-1, 4) +s -= r + +# s becomes (4,3) +//! [4] + + +//! [5] +t1 = QSizeF(10, 12) +t1.scale(60, 60, Qt.IgnoreAspectRatio) +# t1 is (60, 60) + +t2 = QSizeF(10, 12) +t2.scale(60, 60, Qt.KeepAspectRatio) +# t2 is (50, 60) + +t3 = QSizeF(10, 12) +t3.scale(60, 60, Qt.KeepAspectRatioByExpanding) +# t3 is (60, 72) +//! [5] + + +//! [6] +size = QSizeF(100.3, 10) +size.rwidth() += 20.5 + +# size becomes (120.8,10) +//! [6] + + +//! [7] +size = QSizeF(100, 10.2) +size.rheight() += 5.5 + +# size becomes (100,15.7) +//! [7] + + +//! [8] +s = QSizeF( 3, 7) +r = QSizeF(-1, 4) +s += r + +# s becomes (2,11) +//! [8] + + +//! [9] +s = QSizeF( 3, 7) +r = QSizeF(-1, 4) +s -= r + +# s becomes (4,3) +//! [9] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qstring.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qstring.cpp new file mode 100644 index 000000000..17ca6bd8d --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qstring.cpp @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +DEFINES += QT_NO_CAST_FROM_ASCII \ + QT_NO_CAST_TO_ASCII +//! [0] + + +//! [1] +url = QLatin1String("http://www.unicode.org/") +//! [1] + + +//! [2] +d = 12.34; +str = QString("delta: %1").arg(d, 0, 'E', 3) +# str == "delta: 1.234E+01" +//! [2] + + +//! [3] +if str == "auto" || str == "extern" || str == "static" || str == "register": + ... +//! [3] + + +//! [4] +if str == QString("auto") || + str == QString("extern") || + str == QString("static") || + str == QString("register"): + ... +//! [4] + + +//! [5] +if str == QLatin1String("auto") || + str == QLatin1String("extern") || + str == QLatin1String("static") || + str == QLatin1String("register"): + ... +//! [5] + + +//! [6] +label = QLabel(QLatin1String("MOD"), self) +//! [6] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qtimeline.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qtimeline.cpp new file mode 100644 index 000000000..a82785b7f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qtimeline.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +... +progressBar = QProgressBar(self) +progressBar.setRange(0, 100) + +# Construct a 1-second timeline with a frame range of 0 - 100 +timeLine = QTimeLine(1000, self) +timeLine.setFrameRange(0, 100) +timeLine.frameChanged[int].connect(progressBar.setValue) + +# Clicking the push button will start the progress bar animation +pushButton = QPushButton(QObject.tr("Start animation"), self) +pushButton.clicked.connect(timeLine.start) +... +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qvector.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qvector.cpp new file mode 100644 index 000000000..d11a1b4bf --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qvector.cpp @@ -0,0 +1,193 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +QVector<int> integerVector; +QVector<QString> stringVector; +//! [0] + + +//! [1] +QVector<QString> vector(200); +//! [1] + + +//! [2] +QVector<QString> vector(200, "Pass"); +//! [2] + + +//! [3] +if (vector[0] == "Liz") + vector[0] = "Elizabeth"; +//! [3] + + +//! [4] +for (int i = 0; i < vector.size(); ++i) { + if (vector.at(i) == "Alfonso") + cout << "Found Alfonso at position " << i << endl; +} +//! [4] + + +//! [5] +int i = vector.indexOf("Harumi"); +if (i != -1) + cout << "First occurrence of Harumi is at position " << i << endl; +//! [5] + + +//! [6] +QVector<int> vector(10); +int *data = vector.data(); +for (int i = 0; i < 10; ++i) + data[i] = 2 * i; +//! [6] + + +//! [7] +QVector<QString> vector(0); +vector.append("one"); +vector.append("two"); +vector.append("three"); +// vector: ["one", "two", "three"] +//! [7] + + +//! [8] +QVector<QString> vector; +vector.prepend("one"); +vector.prepend("two"); +vector.prepend("three"); +// vector: ["three", "two", "one"] +//! [8] + + +//! [9] +QVector<QString> vector; +vector << "alpha" << "beta" << "delta"; +vector.insert(2, "gamma"); +// vector: ["alpha", "beta", "gamma", "delta"] +//! [9] + + +//! [10] +QVector<double> vector; +vector << 2.718 << 1.442 << 0.4342; +vector.insert(1, 3, 9.9); +// vector: [2.718, 9.9, 9.9, 9.9, 1.442, 0.4342] +//! [10] + + +//! [11] +QVector<QString> vector(3); +vector.fill("Yes"); +// vector: ["Yes", "Yes", "Yes"] + +vector.fill("oh", 5); +// vector: ["oh", "oh", "oh", "oh", "oh"] +//! [11] + + +//! [12] +QVector<QString> vector; +vector << "A" << "B" << "C" << "B" << "A"; +vector.indexOf("B"); // returns 1 +vector.indexOf("B", 1); // returns 1 +vector.indexOf("B", 2); // returns 3 +vector.indexOf("X"); // returns -1 +//! [12] + + +//! [13] +QList<QString> vector; +vector << "A" << "B" << "C" << "B" << "A"; +vector.lastIndexOf("B"); // returns 3 +vector.lastIndexOf("B", 3); // returns 3 +vector.lastIndexOf("B", 2); // returns 1 +vector.lastIndexOf("X"); // returns -1 +//! [13] + + +//! [14] +QVector<double> vect; +vect << "red" << "green" << "blue" << "black"; + +QList<double> list = vect.toList(); +// list: ["red", "green", "blue", "black"] +//! [14] + + +//! [15] +QStringList list; +list << "Sven" << "Kim" << "Ola"; + +QVector<QString> vect = QVector<QString>::fromList(list); +// vect: ["Sven", "Kim", "Ola"] +//! [15] + + +//! [16] +std::vector<double> stdvector; +vector.push_back(1.2); +vector.push_back(0.5); +vector.push_back(3.14); + +QVector<double> vector = QVector<double>::fromStdVector(stdvector); +//! [16] + + +//! [17] +QVector<double> vector; +vector << 1.2 << 0.5 << 3.14; + +std::vector<double> stdvector = vector.toStdVector(); +//! [17] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_xml_qxmlstream.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_xml_qxmlstream.cpp new file mode 100644 index 000000000..591712c1e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_xml_qxmlstream.cpp @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +xml = QXmlStreamReader() +... +while not xml.atEnd(): + xml.readNext(); + ... # do processing + +if xml.hasError(): + ... # do error handling + +//! [0] + + +//! [1] +writeStartElement(qualifiedName) +writeCharacters(text) +writeEndElement() +//! [1] + + +//! [2] +writeStartElement(namespaceUri, name) +writeCharacters(text) +writeEndElement() +//! [2] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_accessible_qaccessible.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_accessible_qaccessible.cpp new file mode 100644 index 000000000..95285f91f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_accessible_qaccessible.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +child = QAccessibleInterface() +targetChild = object.navigate(Accessible.Child, 1, child) +if child: + # ... + del child +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qabstractprintdialog.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qabstractprintdialog.cpp new file mode 100644 index 000000000..aa1cc23b6 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qabstractprintdialog.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +printDialog = QPrintDialog(printer, parent) +if printDialog.exec_() == QDialog.Accepted: + # print ... +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp new file mode 100644 index 000000000..f3a472a1c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp @@ -0,0 +1,136 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +fileName = QFileDialog.getOpenFileName(self, + tr("Open Image"), "/home/jana", tr("Image Files (*.png *.jpg *.bmp)")) +//! [0] + + +//! [1] +"Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)" +//! [1] + + +//! [2] +dialog = QFileDialog(self) +dialog.setFileMode(QFileDialog.AnyFile) +//! [2] + + +//! [3] +dialog.setNameFilter(tr("Images (*.png *.xpm *.jpg)")) +//! [3] + + +//! [4] +dialog.setViewMode(QFileDialog.Detail) +//! [4] + + +//! [5] +if dialog.exec_(): + fileNames = dialog.selectedFiles() +//! [5] + + +//! [6] +dialog.setNameFilter("All C++ files (*.cpp *.cc *.C *.cxx *.c++)") +dialog.setNameFilter("*.cpp *.cc *.C *.cxx *.c++") +//! [6] + + +//! [7] +filters = QStringList() +filters << "Image files (*.png *.xpm *.jpg)" + << "Text files (*.txt)" + << "Any files (*)" + +dialog = QFileDialog(this) +dialog.setNameFilters(filters) +dialog.exec_() +//! [7] + + +//! [8] +fileName = QFileDialog.getOpenFileName(self, tr("Open File"), + "/home", + tr("Images (*.png *.xpm *.jpg)")) +//! [8] + + +//! [9] +files = QFileDialog.getOpenFileNames(self, + "Select one or more files to open", + "/home", + "Images (*.png *.xpm *.jpg)") +//! [9] + + +//! [10] +for it in list: + myProcessing(it) + it++ +//! [10] + + +//! [11] +fileName = QFileDialog.getSaveFileName(self, tr("Save F:xile"), + "/home/jana/untitled.png", + tr("Images (*.png *.xpm *.jpg)")) +//! [11] + + +//! [12] +dir = QFileDialog.getExistingDirectory(self, tr("Open Directory"), + "/home", + QFileDialog.ShowDirsOnly + | QFileDialog.DontResolveSymlinks) +//! [12] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qfontdialog.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qfontdialog.cpp new file mode 100644 index 000000000..d32fe6223 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qfontdialog.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + +(ok, font) = QFontDialog.getFont(QFont("Helvetica [Cronyx]", 10), self) +if ok: + # the user clicked OK and font is set to the font the user selected +else: + # the user canceled the dialog; font is set to the initial + # value, in this case Helvetica [Cronyx], 10 +//! [0] + + +//! [1] +myWidget.setFont(QFontDialog.getFont(0, myWidget.font())) +//! [1] + + +//! [2] +(ok, font) = QFontDialog.getFont(QFont("Times", 12), self) +if ok: + # font is set to the font the user selected +else: + # the user canceled the dialog; font is set to the initial + # value, in this case Times, 12. +//! [2] + + +//! [3] +myWidget.setFont(QFontDialog.getFont(0, myWidget.font())) +//! [3] + + +//! [4] + +(ok, font) = QFontDialog.getFont(self) +if ok: + # font is set to the font the user selected +else: + # the user canceled the dialog; font is set to the default + # application font, QApplication.font() +//! [4] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp new file mode 100644 index 000000000..be4586376 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp @@ -0,0 +1,152 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +ret = QMessageBox.warning(self, self.tr("My Application"), + self.tr("The document has been modified.\n" + \ + "Do you want to save your changes?"), + QMessageBox.Save | QMessageBox.Discard + | QMessageBox.Cancel, + QMessageBox.Save) +//! [0] + + +//! [1] +msgBox = QMessageBox() +msgBox.setStandardButtons(QMessageBox.Yes | QMessageBox.No) +result = msgBox.exec_() + +if result == QMessageBox.Yes: + # yes was clicked +elif result == QMessageBox.No: + # no was clicked +else: + # should never be reached +//! [1] + + +//! [2] +msgBox = QMessageBox() +connectButton = msgBox.addButton(self.tr("Connect"), QMessageBox.ActionRole) +abortButton = msgBox.addButton(QMessageBox.Abort) + +msgBox.exec_() + +if msgBox.clickedButton() == connectButton: + # connect +elif msgBox.clickedButton() == abortButton: + # abort +} +//! [2] + + +//! [3] +messageBox = QMessageBox(self) +disconnectButton = messageBox.addButton(self.tr("Disconnect"), + QMessageBox.ActionRole) +... +messageBox.exec_() +if messageBox.clickedButton() == disconnectButton: + ... + +//! [3] + + +//! [4] +#include <QApplication> +#include <QMessageBox> + +int main(int argc, char *argv[]) +{ +# Not Supported by PySide + QT_REQUIRE_VERSION(argc, argv, "4.0.2") + + QApplication app(argc, argv); + ... + return app.exec(); +} +//! [4] + +//! [5] +msgBox = QMessageBox() +msgBox.setText("The document has been modified.") +msgBox.exec_() +//! [5] + +//! [6] +msgBox = QMessageBox() +msgBox.setText("The document has been modified.") +msgBox.setInformativeText("Do you want to save your changes?") +msgBox.setStandardButtons(QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel) +msgBox.setDefaultButton(QMessageBox.Save) +ret = msgBox.exec_() +//! [6] + +//! [7] + +if ret == QMessageBox.Save: + # Save was clicked +elif ret == QMessageBox.Discard: + # Don't save was clicked +elif ret == QMessageBox.Cancel: + # cancel was clicked +else: + # should never be reached + +//! [7] + +//! [9] +msgBox = QMessageBox(self) +msgBox.setText(tr("The document has been modified.\n" + \ + "Do you want to save your changes?")) +msgBox.setStandardButtons(QMessageBox.Save | QMessageBox.Discard + | QMessageBox.Cancel) +msgBox.setDefaultButton(QMessageBox.Save) +//! [9] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qwizard.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qwizard.cpp new file mode 100644 index 000000000..0112271b5 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qwizard.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +def nextId(self): + id = self.currentId() + if id == Page_Intro: + if field("intro.evaluate").toBool(): + return Page_Evaluate + else: + return Page_Register + elif id == Page_Evaluate: + return Page_Conclusion + elif id == Page_Register: + if field("register.upgradeKey").toString().isEmpty(): + return Page_Details + else: + return Page_Conclusion + elif id == Page_Details: + return Page_Conclusion + else: + return -1 +//! [0] + + +//! [1] +class MyWizard(QWizard): + def __init__(self, parent): + QWizard.__ini__(self, parent) + ... + layout = [QWizard.Stretch, QWizard.BackButton, QWizard.CancelButton, QWizard.NextButton, QWizard.FinishButton] + setButtonLayout(layout); + ... +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_effects_qgraphicseffect.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_effects_qgraphicseffect.cpp new file mode 100644 index 000000000..7a04f492a --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_effects_qgraphicseffect.cpp @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +def draw(self, painter): + # Fully opaque draw directly without going through a pixmap. + if qFuzzyCompare(self.opacity, 1): + drawSource(painter) + return + # ... +//! [0] + +//! [1] +def draw(self, painter): + # ... + offset = QPoint() + if self.sourceIsPixmap(): + # No point in drawing in device coordinates (pixmap will be scaled anyways). + pixmap = sourcePixmap(Qt.LogicalCoordinates, offset) + ... + painter.drawPixmap(offset, pixmap) + else: + # Draw pixmap in device coordinates to avoid pixmap scaling + pixmap = sourcePixmap(Qt.DeviceCoordinates, offset) + painter.setWorldTransform(QTransform()) + # ... + painter.drawPixmap(offset, pixmap) + # ... +//! [1] + +//! [2] +# ... +alphaGradient = QLinearGradient(rect.topLeft(), rect.bottomLeft()) +alphaGradient.setColorAt(0.0, Qt.transparent) +alphaGradient.setColorAt(0.5, Qt.black) +alphaGradient.setColorAt(1.0, Qt.transparent) +effect = QGraphicsOpacityEffect() +effect.setOpacityMask(alphaGradient) +# ... +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsgridlayout.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsgridlayout.cpp new file mode 100644 index 000000000..201138e90 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsgridlayout.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +scene = QGraphicsScene() +textEdit = scene.addWidget(QTextEdit()) +pushButton = scene.addWidget(QPushButton()) + +layout = QGraphicsGridLayout() +layout.addItem(textEdit, 0, 0) +layout.addItem(pushButton, 0, 1) + +form = QGraphicsWidget() +form.setLayout(layout) +scene.addItem(form) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp new file mode 100644 index 000000000..67e588075 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp @@ -0,0 +1,249 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +class SimpleItem(QGraphicsItem): + + def boundingRect(self): + penWidth = 1.0 + return QRectF(-10 - penWidth / 2, -10 - penWidth / 2, + 20 + penWidth, 20 + penWidth) + + def paint(self, painter, option, widget): + painter.drawRoundedRect(-10, -10, 20, 20, 5, 5) +//! [0] + + +//! [1] +class CustomItem(QGraphicsItem): + ... + self.Type = QGraphicsItem.UserType + 1 + + def type(self): + # Enable the use of qgraphicsitem_cast with this item. + return self.Type + ... + +//! [1] + + +//! [2] +item.setCursor(Qt.IBeamCursor) +//! [2] + + +//! [3] +item.setCursor(Qt.IBeamCursor) +//! [3] + + +//! [4] +rect = QGraphicsRectItem() +rect.setPos(100, 100) + +rect.sceneTransform().map(QPointF(0, 0)) +# returns QPointF(100, 100) + +rect.sceneTransform().inverted().map(QPointF(100, 100)) +# returns QPointF(0, 0); +//! [4] + + +//! [5] +rect = QGraphicsRectItem() +rect.setPos(100, 100) + +rect.deviceTransform(view.viewportTransform()).map(QPointF(0, 0)) +# returns the item's (0, 0) point in view's viewport coordinates + +rect.deviceTransform(view.viewportTransform()).inverted().map(QPointF(100, 100)) +# returns view's viewport's (100, 100) coordinate in item coordinates +//! [5] + + +//! [6] +# Rotate an item 45 degrees around (0, 0) +item.rotate(45) + +# Rotate an item 45 degrees around (x, y) +item.setTransform(QTransform().translate(x, y).rotate(45).translate(-x, -y)) +//! [6] + + +//! [7] +# Scale an item by 3x2 from its origin +item.scale(3, 2) + +# Scale an item by 3x2 from (x, y) +item.setTransform(QTransform().translate(x, y).scale(3, 2).translate(-x, -y)) +//! [7] + + +//! [8] +def boundingRect(self): + penWidth = 1.0 + return QRectF(-radius - penWidth / 2, -radius - penWidth / 2, + diameter + penWidth, diameter + penWidth) +//! [8] + + +//! [9] +def shape(self): + path = QPainterPath() + path.addEllipse(boundingRect()) + return path +//! [9] + + +//! [10] +def paint(self, painter, option, widget): + painter.drawRoundedRect(-10, -10, 20, 20, 5, 5) +//! [10] + + +//! [11] +ObjectName = 0; + +item = scene.itemAt(100, 50) +if len(item.data(ObjectName)) == 0: + if isinstance(ButtonItem, item): + item.setData(ObjectName, "Button") +//! [11] + + +//! [12] +scene = QGraphicsScene() +ellipse = scene.addEllipse(QRectF(-10, -10, 20, 20)) +line = scene.addLine(QLineF(-10, -10, 20, 20)) + +line.installSceneEventFilter(ellipse) +# line's events are filtered by ellipse's sceneEventFilter() function. + +ellipse.installSceneEventFilter(line) +# ellipse's events are filtered by line's sceneEventFilter() function. +//! [12] + + +//! [13] +def contextMenuEvent(self, event): + menu = QMenu() + removeAction = menu.addAction("Remove") + markAction = menu.addAction("Mark") + selectedAction = menu.exec(event.screenPos()) + // ... +//! [13] + + +//! [14] +def __init__(self): + self.setAcceptDrops(true) + ... + +def dragEnterEvent(self, event): + event.setAccepted(event.mimeData().hasFormat("text/plain")) +//! [14] + + +//! [15] +def itemChange(self, change, value): + if change == ItemPositionChange && scene(): + # value is the new position. + rect = scene().sceneRect() + if !rect.contains(value): + # Keep the item inside the scene rect. + value.setX(qMin(rect.right(), qMax(value.x(), rect.left()))) + value.setY(qMin(rect.bottom(), qMax(value.y(), rect.top()))) + return value + return QGraphicsItem.itemChange(self, change, value) +//! [15] + + +//! [16] +def setRadius(self, newRadius): + if radius != newRadius: + prepareGeometryChange() + radius = newRadius +//! [16] + + +//! [17] +# Group all selected items together +group = scene.createItemGroup(scene.selecteditems()) + +# Destroy the group, and delete the group item +scene.destroyItemGroup(group) +//! [17] + + +//! [QGraphicsItem type] +class CustomItem(QGraphicsItem): + ... + self.Type = QGraphicsItem.UserType + 1 + + def type(self): + # Enable the use of qgraphicsitem_cast with this item. + return self.Type + ... +//! [QGraphicsItem type] + +//! [18] +class QGraphicsPathItem (QAbstractGraphicsShapeItem): + Type = 2 + + def type(self): + return QGraphicsPathItem.Type +# ... +//! [18] + +//! [19] +xform = item.deviceTransform(view.viewportTransform()) +deviceRect = xform.mapRect(rect).toAlignedRect() +view.viewport().scroll(dx, dy, deviceRect) +//! [19] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicslinearlayout.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicslinearlayout.cpp new file mode 100644 index 000000000..77e7c0149 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicslinearlayout.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +scene = QGraphicsScene() +textEdit = scene.addWidget(QTextEdit()) +pushButton = scene.addWidget(QPushButton()) + +layout = QGraphicsLinearLayout() +layout.addItem(textEdit) +layout.addItem(pushButton) + +form = QGraphicsWidget() +form.setLayout(layout) +scene.addItem(form) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsproxywidget.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsproxywidget.cpp new file mode 100644 index 000000000..518af80ce --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsproxywidget.cpp @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +import sys + +QApplication app(sys.argv) + +tabWidget = QTabWidget() + +scene = QGraphicsScene() +proxy = scene.addWidget(tabWidget) + +view = QGraphicsView(scene) +view.show() + +return app.exec_() +//! [0] + +//! [1] +groupBox = QGroupBox("Contact Details") +numberLabel = QLabel("Telephone number") +numberEdit = QLineEdit() + +layout = QFormLayout() +layout.addRow(numberLabel, numberEdit) +groupBox.setLayout(layout) + +scene = QGraphicsScene() +proxy = scene.addWidget(groupBox) + +view = QGraphicsView(scene) +view.show() +//! [1] + +//! [2] +scene = QGraphicsScene() + +edit = QLineEdit() +proxy = scene.addWidget(edit) + +edit.isVisible() // returns true +proxy.isVisible() // also returns true + +edit.hide() + +edit.isVisible() // returns false +proxy.isVisible() // also returns false +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsscene.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsscene.cpp new file mode 100644 index 000000000..0538cbaef --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsscene.cpp @@ -0,0 +1,125 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +scene = QGraphicsScene() +scene.addText("Hello, world!") + +view = QGraphicsView(&scene) +view.show() +//! [0] + + +//! [1] +scene = QGraphicsScene +scene.addItem(... +... +printer = QPrinter(QPrinter.HighResolution) +printer.setPaperSize(QPrinter.A4) + +painter = QPainter(printer) +scene.render(&painter) +//! [1] + + +//! [2] +segmentSize = sceneRect().size() / math.pow(2, depth - 1) +//! [2] + + +//! [3] +scene = QGraphicsScene() +view = QGraphicsView(scene) +view.show() + +# a blue background +scene.setBackgroundBrush(Qt.blue) + +# a gradient background +gradient = QRadialGradient(0, 0, 10) +gradient.setSpread(QGradient.RepeatSpread) +scene.setBackgroundBrush(gradient) +//! [3] + + +//! [4] +scene = QGraphicsScene() +view = QGraphicsView(scene) +view.show() + +# a white semi-transparent foreground +scene.setForegroundBrush(QColor(255, 255, 255, 127)) + +# a grid foreground +scene.setForegroundBrush(QBrush(Qt.lightGray, Qt.CrossPattern)) +//! [4] + + +//! [5] +class TileScene (QGraphicsScene): + # ... + def rectForTile(x, y): + # Return the rectangle for the tile at position (x, y). + return QRectF(x * self.tileWidth, y * self.tileHeight, self.tileWidth, self.tileHeight) + + def setTile(x, y, pixmap): + # Sets or replaces the tile at position (x, y) with pixmap. + if x >= 0 && x < self.numTilesH && y >= 0 && y < self.numTilesV: + self.tiles[y][x] = pixmap + invalidate(rectForTile(x, y), BackgroundLayer) + + def drawBackground(painter, exposed): + # Draws all tiles that intersect the exposed area. + for y in range(0, self.numTilesV: + for x in range(0, self.numTilesH: + rect = rectForTile(x, y) + if exposed.intersects(rect): + painter.drawPixmap(rect.topLeft(), tiles[y][x]) +//! [5] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicssceneevent.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicssceneevent.cpp new file mode 100644 index 000000000..4cf7d8411 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicssceneevent.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + +setDropAction(proposedAction()) + +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsview.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsview.cpp new file mode 100644 index 000000000..5a1c7bb7d --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsview.cpp @@ -0,0 +1,136 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +scene = QGraphicsScene() +scene.addText("Hello, world!") + +view = QGraphicsView(scene) +view.show() +//! [0] + + +//! [1] +scene = QGraphicsScene() +scene.addRect(QRectF(-10, -10, 20, 20)) + +view = QGraphicsView(scene) +view.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform) +view.show() +//! [1] + + +//! [2] +view = QGraphicsView() +view.setBackgroundBrush(QImage(":/images/backgroundtile.png")) +view.setCacheMode(QGraphicsView.CacheBackground) +//! [2] + + +//! [3] +scene = QGraphicsScene() +scene.addText("GraphicsView rotated clockwise") + +view = QGraphicsView(scene) +view.rotate(90) # the text is rendered with a 90 degree clockwise rotation +view.show() +//! [3] + + +//! [4] +scene = QGraphicsScene() +scene.addItem(... +... + +view = QGraphicsView(scene) +view.show() +... + +printer = QPrinter(QPrinter.HighResolution) +printer.setPageSize(QPrinter.A4) +painter = QPainter(printer) + +# print, fitting the viewport contents into a full page +view.render(painter) + +# print the upper half of the viewport into the lower. +# half of the page. +viewport = view.viewport()->rect() +view.render(painter, + QRectF(0, printer.height() / 2, + printer.width(), printer.height() / 2), + viewport.adjusted(0, 0, 0, -viewport.height() / 2)) + +//! [4] + + +//! [5] +def mousePressEvent(self, event): + print "There are", items(event->pos()).size(), "items at position", mapToScene(event->pos()) +//! [5] + + +//! [6] +def mousePressEvent(self, event): + if (item = itemAt(event.pos()): + print "You clicked on item", item + else: + print "You didn't click on an item." +//! [6] + + +//! [7] +scene = QGraphicsScene() +scene.addText("GraphicsView rotated clockwise") + +view = QGraphicsView(scene) +view.rotate(90) # the text is rendered with a 90 degree clockwise rotation +view.show() +//! [7] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicswidget.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicswidget.cpp new file mode 100644 index 000000000..f23f6e176 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicswidget.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +class MyGroupBoxWidget (QStyleOptionGroupBox): + # ... + def initStyleOption(option): + QGraphicsWidget.initStyleOption(self, option) + if isinstance(option, QStyleOptionGroupBox): + # Add group box specific state. + box.flat = isFlat() + # ... +//! [0] + + +//! [1] +setTabOrder(a, b) # a to b +setTabOrder(b, c) # a to b to c +setTabOrder(c, d) # a to b to c to d +//! [1] + + +//! [2] +# WRONG +setTabOrder(c, d) # c to d +setTabOrder(a, b) # a to b AND c to d +setTabOrder(b, c) # a to b to c, but not c to d +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qbitmap.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qbitmap.cpp new file mode 100644 index 000000000..92af1464e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qbitmap.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +uchar arrow_bits[] = { 0x3f, 0x1f, 0x0f, 0x1f, 0x3b, 0x71, 0xe0, 0xc0 }; +QBitmap bm(8, 8, arrow_bits, true); +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qicon.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qicon.cpp new file mode 100644 index 000000000..37c6a1baa --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qicon.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +button = QToolButton() +button.setIcon(QIcon("open.xpm")) +//! [0] + + +//! [1] +button.setIcon(QIcon()) +//! [1] + + +//! [2] +def drawIcon(self, painter, pos): + enabledStatus = QIcon.Normal + if not isEnabled(): + enabledStatus = QIcon::Disabled + + onOff = QIcon.On + if not isOn(): + onOff = QIcon.Off + + pixmap = self.icon.pixmap(QSize(22, 22), enabledStatus, onOff) + painter.drawPixmap(pos, pixmap) +//! [2] + +//! [3] + undoicon = QIcon.fromTheme("edit-undo") +//! [3] + +//! [4] + undoicon = QIcon.fromTheme("edit-undo", QIcon(":/undo.png")) +//! [4] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qimage.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qimage.cpp new file mode 100644 index 000000000..3a3083697 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qimage.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +image = QImage(3, 3, QImage.Format_RGB32) + +value = qRgb(189, 149, 39) # 0xffbd9527 +image.setPixel(1, 1, value) + +value = qRgb(122, 163, 39) # 0xff7aa327 +image.setPixel(0, 1, value) +image.setPixel(1, 0, value) + +value = qRgb(237, 187, 51) # 0xffedba31 +image.setPixel(2, 1, value) +//! [0] + + +//! [1] +image = QImage(3, 3, QImage.Format_Indexed8) +value = qRgb(122, 163, 39) # 0xff7aa327 +image.setColor(0, value) + +value = qRgb(237, 187, 51) # 0xffedba31 +image.setColor(1, value) + +value = qRgb(189, 149, 39) # 0xffbd9527 +image.setColor(2, value) + +image.setPixel(0, 1, 0) +image.setPixel(1, 0, 0) +image.setPixel(1, 1, 2) +image.setPixel(2, 1, 1) +//! [1] + + +//! [2] +start_xpm = ["16 15 8 1", "a c #cec6bd", .... +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qimagereader.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qimagereader.cpp new file mode 100644 index 000000000..bf760794e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qimagereader.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +reader = QImageReader() +reader.setFormat("png") # same as reader.setFormat("PNG") +//! [0] + + +//! [1] +reader = QImageReader("image.png") +# reader.format() == "png" +//! [1] + + +//! [2] +icon = QImage(64, 64, QImage.Format_RGB32) +reader = QImageReader("icon_64x64.bmp") +if reader.read(icon): + # Display icon +//! [2] + + +//! [3] +reader = QImageReader(":/image.png") +if reader.supportsOption(QImageIOHandler.Size): + print "Size:", str(reader.size()) +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qimagewriter.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qimagewriter.cpp new file mode 100644 index 000000000..3e5561329 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qimagewriter.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +writer = QImageWriter() +writer.setFormat("png") # same as writer.setFormat("PNG") +//! [0] + + +//! [1] +image = QImage("some/image.jpeg") +writer = QImageWriter("images/outimage.png", "png") +writer.setText("Author", "John Smith") +writer.write(image) +//! [1] + + +//! [2] +writer = QImageWriter(fileName) +if writer.supportsOption(QImageIOHandler.Description): + writer.setText("Author", "John Smith") +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qmovie.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qmovie.cpp new file mode 100644 index 000000000..03fec9076 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qmovie.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +label = QLabel() +movie = QMovie("animations/fire.gif") + +label.setMovie(movie) +movie.start() +//! [0] + + +//! [1] +movie = QMovie("racecar.gif") +movie.setSpeed(200) // 2x speed +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmap.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmap.cpp new file mode 100644 index 000000000..7acb620cb --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmap.cpp @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +static const char * const start_xpm[]={ + "16 15 8 1", + "a c #cec6bd", +.... +//! [0] + + +//! [1] +myPixmap = QPixmap() +myPixmap.setMask(myPixmap.createHeuristicMask()) +//! [1] + +//! [2] +pixmap = QPixmap("background.png") +exposed = QRegion() +pixmap.scroll(10, 10, pixmap.rect(), exposed) +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmapcache.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmapcache.cpp new file mode 100644 index 000000000..6952941f9 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmapcache.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +pm = QPixmap() +if not QPixmapCache.find("my_big_image", pm): + pm.load("bigimage.png") + QPixmapCache.insert("my_big_image", pm) +painter.drawPixmap(0, 0, pm) +//! [0] + + +//! [1] +pm = QPixmap() +if not QPixmapCache.find("my_big_image", pm): + pm.load("bigimage.png") + QPixmapCache.insert("my_big_image", pm) +painter.drawPixmap(0, 0, pm) +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmapfilter.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmapfilter.cpp new file mode 100644 index 000000000..95b9a866c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmapfilter.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +myFilter = QPixmapColorFilter() +myFilter.setColor(QColor(128, 0, 0)) +myFilter.draw(painter, QPoint(0, 0), originalPixmap) +//! [0] + +//! [1] +myFilter = QPixmapConvolutionFilter() +kernel = [ + 0.0,-1.0, 0.0, + -1.0, 5.0,-1.0, + 0.0,-1.0, 0.0 + ] +myFilter.setConvolutionKernel(kernel, 3, 3) +myFilter.sdraw(painter, QPoint(0, 0), originalPixmap) +//! [1] + +//! [2] +myFilter = QPixmapDropShadowFilter() +myFilter.draw(painter, QPoint(0, 0), originalPixmap) +//! [2] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qabstractitemview.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qabstractitemview.cpp new file mode 100644 index 000000000..9408be93c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qabstractitemview.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +def resizeEvent(self, event): + horizontalScrollBar().setRange(0, realWidth - width()) + ... +//! [0] + +//! [1] +setIndexWidget(index, QLineEdit()) +... +setIndexWidget(index, QTextEdit()) +//! [1] + +//! [2] +m = view->selectionModel() +view->setModel(model()) +del m +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qdatawidgetmapper.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qdatawidgetmapper.cpp new file mode 100644 index 000000000..ba0e31c71 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qdatawidgetmapper.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +mapper = QDataWidgetMapper +mapper.setModel(model) +mapper.addMapping(mySpinBox, 0) +mapper.addMapping(myLineEdit, 1) +mapper.addMapping(myCountryChooser, 2) +mapper.toFirst() +//! [0] + + +//! [1] +mapper = QDataWidgetMapper() +mapper.setModel(myModel) +mapper.addMapping(nameLineEdit, 0) +mapper.addMapping(ageSpinBox, 1) +//! [1] + + +//! [2] +mapper = QDataWidgetMapper() +connect(myTableView.selectionModel(), SIGNAL("currentRowChanged(QModelIndex,QModelIndex)"), + mapper, SLOT(setCurrentModelIndex(QModelIndex))) +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qitemeditorfactory.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qitemeditorfactory.cpp new file mode 100644 index 000000000..22efc1979 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qitemeditorfactory.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +Q_PROPERTY(QColor color READ color WRITE setColor USER true) +//! [0] + + +//! [1] +QItemEditorCreator<MyEditor> *itemCreator = + new QItemEditorCreator<MyEditor>("myProperty"); + +QItemEditorFactory *factory = new QItemEditorFactory; +//! [1] + + +//! [2] +QItemEditorFactory *editorFactory = new QItemEditorFactory; +QItemEditorCreatorBase *creator = new QStandardItemEditorCreator<MyFancyDateTimeEdit>(); +editorFactory->registerEditor(QVariant::DateType, creator); +//! [2] + + +//! [3] +Q_PROPERTY(QColor color READ color WRITE setColor USER true) +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp new file mode 100644 index 000000000..5ab02333f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +selection = QItemSelection(topLeft, bottomRight) +//! [0] + + +//! [1] +selection = QItemSelection() +... +selection.select(topLeft, bottomRight) +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qstandarditemmodel.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qstandarditemmodel.cpp new file mode 100644 index 000000000..47cb1d9d1 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qstandarditemmodel.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +model = QStandardItemModel (4, 4) +for row in range(4): + for column in range(4): + item = QStandardItem("row %d, column %d" % (row, column)) + model.setItem(row, column, item) +//! [0] + + +//! [1] +model = QStandardItemModel() +parentItem = model.invisibleRootItem() +for i in range(4): + item = QStandardItem("item %d" % i) + parentItem.appendRow(item) + parentItem = item +//! [1] + + +//! [2] +treeView = QTreeView(self) +treeView.setModel(myStandardItemModel) +treeView.clicked[QModelIndex].connect(self.clicked) +//! [2] + + +//! [3] +def clicked(self, index): + item = myStandardItemModel.itemFromIndex(index) + # Do stuff with the item ... +//! [3] + + +//! [4] +treeView.scrollTo(item.index()) +//! [4] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qtablewidget.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qtablewidget.cpp new file mode 100644 index 000000000..cd0ee658c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qtablewidget.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +setCellWidget(index, QLineEdit()) +... +setCellWidget(index, QTextEdit()) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qtreewidget.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qtreewidget.cpp new file mode 100644 index 000000000..cc5130949 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qtreewidget.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +treeWidget = QTreeWidget() +treeWidget.setColumnCount(1) +items = [] +for i in range(10): + items.append(QTreeWidgetItem(None, QStringList(QString("item: %1").arg(i)))) +treeWidget.insertTopLevelItems(None, items) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qaction.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qaction.cpp new file mode 100644 index 000000000..5828a9624 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qaction.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +app = QApplication(argv) +app.setAttribute(Qt.AA_DontShowIconsInMenus) # Icons are *no longer shown* in menus +// ... +myAction = QAction() +// ... +myAction.setIcon(SomeIcon) +myAction.setIconVisibleInMenu(True) # Icon *will* be shown in menus for *this* action. +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qapplication.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qapplication.cpp new file mode 100644 index 000000000..d3e371b1e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qapplication.cpp @@ -0,0 +1,177 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +def main(): + if Qt.Q_WS_X11 + useGUI = getenv("DISPLAY") != 0 + else: + useGUI = True + + app = QApplication(sys.argv, useGUI) + + if useGUI: + # start GUI version + ... + else: + # start non-GUI version + ... + return app.exec_() +//! [0] + + +//! [1] +QApplication.setStyle(QWindowsStyle()) +//! [1] + + +//! [2] +def main(): + QApplication.setColorSpec(QApplication.ManyColor) + QApplication app(sys.argv) + ... + return app.exec_() + +//! [2] + + +//! [3] +class MyWidget (QWidget): + # ... + def sizeHint(self): + return QSize(80, 25).expandedTo(QApplication.globalStrut()) +//! [3] + + +//! [4] +def showAllHiddenTopLevelWidgets(): + for widget in QApplication.topLevelWidgets(): + if widget.isHidden(): + widget.show() +//! [4] + + +//! [5] +def updateAllWidgets(): + for widget in QApplication.allWidgets() + widget.update() +//! [5] + + +//! [6] +if __name__ == '__main__': + QApplication.setDesktopSettingsAware(False) + app = QApplication(sys.argv) + # ... + return app.exec_() +//! [6] + + +//! [7] +if (startPos - currentPos).manhattanLength() >= QApplication.startDragDistance(): + startTheDrag() +//! [7] + + +//! [8] +class MyApplication (QApplication): +# ... + def commitData(QSessionManager& manager) + if manager.allowsInteraction(): + ret = QMessageBox.warning( + mainWindow, + QObject.tr("My Application"), + QObject.tr("Save changes to document?"), + QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel) + + if ret == QMessageBox.Save: + manager.release() + if not saveDocument(): + manager.cancel() + elif ret == QMessageBox.Discard: + pass + else: + manager.cancel() + else: + # we did not get permission to interact, then + # do something reasonable instead + pass +//! [8] + + +//! [9] +appname -session id +//! [9] + + +//! [10] +for command in mySession.restartCommand(): + do_something(command) +//! [10] + + +//! [11] +for command in mySession.discardCommand(): + do_something(command) +//! [11] + + +//! [12] +widget = qApp.widgetAt(x, y) +if widget: + widget = widget.window() +//! [12] + + +//! [13] +widget = qApp.widgetAt(point) +if widget: + widget = widget.window() +//! [13] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qapplication_x11.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qapplication_x11.cpp new file mode 100644 index 000000000..c0cfeef50 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qapplication_x11.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) +calculateHugeMandelbrot() # lunch time... +QApplication.restoreOverrideCursor() +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qclipboard.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qclipboard.cpp new file mode 100644 index 000000000..e69152401 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qclipboard.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +clipboard = QApplication.clipboard() +originalText = clipboard.text() +... +clipboard.setText(newText) +//! [0] + + +//! [1] +data = QMimeData() +data.setImageData(image) +clipboard.setMimeData(data, mode) +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qevent.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qevent.cpp new file mode 100644 index 000000000..a52c02c3b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qevent.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +def wheelEvent(self, event): + numDegrees = event.delta() / 8 + numSteps = numDegrees / 15 + + if event->orientation() == Qt.Horizontal: + scrollHorizontally(numSteps) + else: + scrollVertically(numSteps) + event.accept() +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qformlayout.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qformlayout.cpp new file mode 100644 index 000000000..629f74936 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qformlayout.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +formLayout = QFormLayout() +formLayout.addRow(self.tr("&Name:"), nameLineEdit) +formLayout.addRow(self.tr("&Email:"), emailLineEdit) +formLayout.addRow(self.tr("&Age:"), ageSpinBox) +setLayout(formLayout) +//! [0] + + +//! [1] +nameLabel = QLabel(self.tr("&Name:")) +nameLabel.setBuddy(nameLineEdit) + +emailLabel = QLabel(self.tr("&Name:")) +emailLabel.setBuddy(emailLineEdit) + +ageLabel = QLabel(self.tr("&Name:")) +ageLabel.setBuddy(ageSpinBox) + +gridLayout = QGridLayout() +gridLayout.addWidget(nameLabel, 0, 0) +gridLayout.addWidget(nameLineEdit, 0, 1) +gridLayout.addWidget(emailLabel, 1, 0) +gridLayout.addWidget(emailLineEdit, 1, 1) +gridLayout.addWidget(ageLabel, 2, 0) +gridLayout.addWidget(ageSpinBox, 2, 1) +setLayout(gridLayout) +//! [1] + + +//! [2] +formLayout.trowWrapPolicy(QFormLayout.DontWrapRows) +formLayout.setFieldGrowthPolicy(QFormLayout.FieldsStayAtSizeHint) +formLayout.setFormAlignment(Qt.AlignHCenter | Qt.AlignTop) +formLayout.setLabelAlignment(Qt.AlignLeft) +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qkeysequence.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qkeysequence.cpp new file mode 100644 index 000000000..3e07cb3c0 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qkeysequence.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +QKeySequence(QKeySequence.Print) +QKeySequence(tr("Ctrl+P")) +QKeySequence(tr("Ctrl+p")) +QKeySequence(Qt.CTRL + Qt.Key_P) +//! [0] + + +//! [1] +QKeySequence(tr("Ctrl+X, Ctrl+C")) +QKeySequence(Qt.CTRL + Qt.Key_X, Qt.CTRL + Qt.Key_C) +//! [1] + + +//! [2] +file = QMenu(self) +file.addAction(tr("&Open..."), self, SLOT("open()"), + QKeySequence(tr("Ctrl+O", "File|Open"))) +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qlayout.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qlayout.cpp new file mode 100644 index 000000000..7b5e9bad9 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qlayout.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + +def paintLayout(self, painter, item): + layout = item.layout() + + if layout: + for layout_item in layout: + self.paintLayout(painter, layout_item) + + painter.drawRect(item.geometry()) + +def paintEvent(self, event): + painter = QPainter(self) + if self.layout(): + self.paintLayout(painter, self.layout()) + +//! [0] + + +//! [1] +child = layout.takeAt(0) +while child: + ... + del child +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qlayoutitem.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qlayoutitem.cpp new file mode 100644 index 000000000..5b6488ff6 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qlayoutitem.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +def heightForWidth(self, w): + if cache_dirty or cached_width != w: + h = calculateHeightForWidth(w) + self.cached_hfw = h + return h + return cached_hfw +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qshortcut.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qshortcut.cpp new file mode 100644 index 000000000..b954f3cd3 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qshortcut.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +shortcut = QShortcut(QKeySequence(self.tr("Ctrl+O", "File|Open")), + parent) +//! [0] + + +//! [1] +setKey(0) # no signal emitted +setKey(QKeySequence()) # no signal emitted +setKey(0x3b1) # Greek letter alpha +setKey(Qt.Key_D) # 'd', e.g. to delete +setKey('q') # 'q', e.g. to quit +setKey(Qt.CTRL + Qt.Key_P) # Ctrl+P, e.g. to print document +setKey("Ctrl+P") # Ctrl+P, e.g. to print document +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qshortcutmap.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qshortcutmap.cpp new file mode 100644 index 000000000..48f63f6e9 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qshortcutmap.cpp @@ -0,0 +1,3 @@ +//! [0] +key = QKeySequence() +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qsound.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qsound.cpp new file mode 100644 index 000000000..ca5842070 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qsound.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +QSound.play("mysounds/bells.wav") +//! [0] + + +//! [1] +bells = QSound("mysounds/bells.wav") +bells.play() +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qwidget.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qwidget.cpp new file mode 100644 index 000000000..98ff665ea --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qwidget.cpp @@ -0,0 +1,150 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +w.setWindowState(w.windowState() ^ Qt.WindowFullScreen) +//! [0] + + +//! [1] +w.setWindowState(w.windowState() & ~Qt.WindowMinimized | Qt.WindowActive) +//! [1] + + +//! [2] +width = widget.baseSize().width() + i * widget.sizeIncrement().width() +height = widget.baseSize().height() + j * widget.sizeIncrement().height() +//! [2] + + +//! [3] +aWidget.window().setWindowTitle("New Window Title") +//! [3] + + +//! [4] +font = QFont("Helvetica", 12, QFont.Bold) +widget.setFont(font) +//! [4] + + +//! [5] +font = QFont() +font.setBold(false) +widget.setFont(font) +//! [5] + + +//! [6] +widget.setCursor(Qt.IBeamCursor) +//! [6] + + +//! [7] +pixmap = QPixmap(widget.size()) +widget.render(&pixmap) +//! [7] + + +//! [8] +painter = QPainter(self) +... +painter.end() +myWidget.render(self) +//! [8] + + +//! [9] +widget.setTabOrder(a, b) # a to b +widget.setTabOrder(b, c) # a to b to c +widge.tsetTabOrder(c, d) # a to b to c to d +//! [9] + + +//! [10] +# WRONG +widget.setTabOrder(c, d) # c to d +widget.setTabOrder(a, b) # a to b AND c to d +widget.setTabOrder(b, c) # a to b to c, but not c to d +//! [10] + + +//! [11] +class MyWidget(QWidget): + + self.settings = None + + def closeEvent(event): + # event is a QCloseEvent + self.settings = QSettings("MyCompany", "MyApp") + self.settings.setValue("geometry", self.saveGeometry()) + QWidget.closeEvent(self, event) +//! [11] + + +//! [12] +settings = QSettings("MyCompany", "MyApp") +myWidget.restoreGeometry(settings.value("myWidget/geometry").toByteArray()) +//! [12] + + +//! [13] +widget.setUpdatesEnabled(False) +widget.bigVisualChanges() +widget.setUpdatesEnabled(True) +//! [13] + + +//! [14] +... +extern void qt_x11_set_global_double_buffer(bool); +qt_x11_set_global_double_buffer(false); +... +//! [14] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qbrush.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qbrush.cpp new file mode 100644 index 000000000..aef402ffa --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qbrush.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +painter = QPainter(self) + +painter.setBrush(Qt.cyan) +painter.setPen(Qt.darkCyan) +painter.drawRect(0, 0, 100,100) + +painter.setBrush(Qt.NoBrush) +painter.setPen(Qt.darkGreen) +painter.drawRect(40, 40, 100, 100) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qcolor.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qcolor.cpp new file mode 100644 index 000000000..f44597c40 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qcolor.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +# Specify semi-transparent red +painter.setBrush(QColor(255, 0, 0, 127)) +painter.drawRect(0, 0, self.width()/2, self.height()) + +# Specify semi-transparent blue +painter.setBrush(QColor(0, 0, 255, 127)) +painter.drawRect(0, 0, self.width(), self.height()/2) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qdrawutil.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qdrawutil.cpp new file mode 100644 index 000000000..57f8300dd --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qdrawutil.cpp @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +frame = QFrame() +frame.setFrameStyle(QFrame.HLine | QFrame.Sunken) +//! [0] + + +//! [1] +frame = QFrame() +frame.setFrameStyle(QFrame.Box | QFrame.Raised) +//! [1] + + +//! [2] +frame = QFrame() +frame.setFrameStyle( QFrame.Panel | QFrame.Sunken) +//! [2] + + +//! [3] +frame = QFrame() +frame.setFrameStyle(QFrame.WinPanel | QFrame.Raised) +//! [3] + + +//! [4] +frame = QFrame() +frame.setFrameStyle(QFrame.Box | QFrame.Plain) +//! [4] + + +//! [5] +frame = QFrame() +frame.setFrameStyle(QFrame.HLine | QFrame.Sunken) +//! [5] + + +//! [6] +frame = QFrame() +frame.setFrameStyle(QFrame.Box | QFrame.Raised) +//! [6] + + +//! [7] +frame = QFrame() +frame.setFrameStyle( QFrame.Panel | QFrame.Sunken) +//! [7] + + +//! [8] +frame = QFrame() +frame.setFrameStyle(QFrame.WinPanel | QFrame.Raised) +//! [8] + + +//! [9] +frame = QFrame() +frame.setFrameStyle(QFrame.Box | QFrame.Plain) +//! [9] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qmatrix.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qmatrix.cpp new file mode 100644 index 000000000..15a7f7d04 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qmatrix.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +x' = m11*x + m21*y + dx +y' = m22*y + m12*x + dy +//! [0] + + +//! [1] +x' = m11*x + m21*y + dx +y' = m22*y + m12*x + dy +//! [1] + + +//! [2] +x' = m11*x + m21*y + dx +y' = m22*y + m12*x + dy +//! [2] + + +//! [3] +x' = m11*x + m21*y + dx +y' = m22*y + m12*x + dy +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpainter.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpainter.cpp new file mode 100644 index 000000000..e702214f7 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpainter.cpp @@ -0,0 +1,261 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +def paintEvent(self, paintEvent): + painter = QPainter(self) + painter.setPen(Qt.blue) + painter.setFont(QFont("Arial", 30)) + painter.drawText(rect(), Qt.AlignCenter, "Qt") +//! [0] + + +//! [1] +def paintEvent(self, paintEvent): + p = QPainter() + p.begin(self) + p.drawLine(...) # drawing code + p.end() +//! [1] + + +//! [2] +self paintEvent(self, paintEvent): + p = QPainter(self) + p.drawLine(...) # drawing code + +//! [2] + + +//! [3] +painter.begin(0) # impossible - paint device cannot be 0 + +image = QPixmap(0, 0) +painter.begin(&image) # impossible - image.isNull() == true + +painter.begin(myWidget) +painter2.begin(myWidget) # impossible - only one painter at a time +//! [3] + + +//! [4] +def rotate(self, angle): + matrix = QMatrix() + matrix.rotate(angle) + setWorldMatrix(matrix, true) +//! [4] + + +//! [5] +path = QPainterPath() +path.moveTo(20, 80) +path.lineTo(20, 30) +path.cubicTo(80, 0, 50, 50, 80, 80) + +painter = QPainter(self) +painter.drawPath(path) +//! [5] + + +//! [6] +line = QLineF(10.0, 80.0, 90.0, 20.0) + +painter = QPainter(self) +painter.drawLine(line) +//! [6] + + +//! [7] +rectangle = QRectF(10.0, 20.0, 80.0, 60.0) + +painter = QPainter(self) +painter.drawRect(rectangle) +//! [7] + + +//! [8] +rectangle = QRectF(10.0, 20.0, 80.0, 60.0) + +painter = QPainter(self) +painter.drawRoundedRect(rectangle, 20.0, 15.0) +//! [8] + + +//! [9] +rectangle = QRectF(10.0, 20.0, 80.0, 60.0) + +painter = QPainter(self) +painter.drawEllipse(rectangle) +//! [9] + + +//! [10] +rectangle = QRectF(10.0, 20.0, 80.0, 60.0) +startAngle = 30 * 16 +spanAngle = 120 * 16 + +painter = QPainter(self) +painter.drawArc(rectangle, startAngle, spanAngle) +//! [10] + + +//! [11] +rectangle = QRectF(10.0, 20.0, 80.0, 60.0) +startAngle = 30 * 16 +spanAngle = 120 * 16 + +painter = QPainter(self) +painter.drawPie(rectangle, startAngle, spanAngle) +//! [11] + + +//! [12] +rectangle = QRectF(10.0, 20.0, 80.0, 60.0) +startAngle = 30 * 16 +spanAngle = 120 * 16 + +painter = QPainter(self) +painter.drawChord(rect, startAngle, spanAngle) +//! [12] + + +//! [13] +points = [ + QPointF(10.0, 80.0), + QPointF(20.0, 10.0), + QPointF(80.0, 30.0), +] + +painter = QPainter(self) +painter.drawPolyline(points, 3) +//! [13] + + +//! [14] +points = [ + QPointF(10.0, 80.0), + QPointF(20.0, 10.0), + QPointF(80.0, 30.0), + QPointF(90.0, 70.0) +] + +painter = QPainter(self) +painter.drawPolygon(points, 4) +//! [14] + + +//! [15] +points = [ + QPointF(10.0, 80.0), + QPointF(20.0, 10.0), + QPointF(80.0, 30.0), + QPointF(90.0, 70.0) +] + +painter = QPainter(self) +painter.drawConvexPolygon(points, 4) +//! [15] + + +//! [16] +target = QRectF(10.0, 20.0, 80.0, 60.0) +source = QRectF(0.0, 0.0, 70.0, 40.0) +pixmap = QPixmap(":myPixmap.png") + +painter = QPainter(self) +painter.drawPixmap(target, image, source) +//! [16] + + +//! [17] +painter = QPainter(self) +painter.drawText(rect, Qt.AlignCenter, tr("Qt by\nTrolltech")) +//! [17] + + +//! [18] +picture = QPicture() +point = QPointF(10.0, 20.0) +picture.load("drawing.pic") + +painter = QPainter(self) +painter.drawPicture(0, 0, picture) +//! [18] + + +//! [19] +fillRect(rectangle, background()) +//! [19] + + +//! [20] +target = QRectF(10.0, 20.0, 80.0, 60.0) +source = QRectF(0.0, 0.0, 70.0, 40.0) +image = QImage(":/images/myImage.png") + +painter = QPainter(self) +painter.drawImage(target, image, source) +//! [20] + +//! [21] +painter = QPainter(self) +painter.fillRect(0, 0, 128, 128, Qt.green) +painter.beginNativePainting() + +glEnable(GL_SCISSOR_TEST) +glScissor(0, 0, 64, 64) + +glClearColor(1, 0, 0, 1) +glClear(GL_COLOR_BUFFER_BIT) + +glDisable(GL_SCISSOR_TEST) + +painter.endNativePainting() +//! [21] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpainterpath.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpainterpath.cpp new file mode 100644 index 000000000..5ebbefcec --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpainterpath.cpp @@ -0,0 +1,160 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +path = QPainterPath() +path.addRect(20, 20, 60, 60) + +path.moveTo(0, 0) +path.cubicTo(99, 0, 50, 50, 99, 99) +path.cubicTo(0, 99, 50, 50, 0, 0) + +QPainter painter(self) +painter.fillRect(0, 0, 100, 100, Qt.white) +painter.setPen(QPen(QColor(79, 106, 25), 1, Qt.SolidLine, + Qt.FlatCap, Qt.MiterJoin)) +painter.setBrush(QColor(122, 163, 39)) + +painter.drawPath(path) +//! [0] + + +//! [1] +myGradient = QLinearGradient() +myPen = QPen() + +myPath = QPainterPath() +myPath.cubicTo(c1, c2, endPoint) + +painter = QPainter(self) +painter.setBrush(myGradient) +painter.setPen(myPen) +painter.drawPath(myPath) +//! [1] + + +//! [2] +myGradient = QLinearGradient() +myPen = QPen() + +startPoint = QPointF() +center = QPointF() + +myPath = QPainterPath() +myPath.moveTo(center) +myPath.arcTo(boundingRect, startAngle, + sweepLength) + +painter = QPainter(self) +painter.setBrush(myGradient) +painter.setPen(myPen) +painter.drawPath(myPath) +//! [2] + + +//! [3] +myGradient = QLinearGradient() +myPen = QPen() +myRectangle = QRectF() + +myPath = QPainterPath() +myPath.addRect(myRectangle) + +painter = QPainter(self) +painter.setBrush(myGradient) +painter.setPen(myPen) +painter.drawPath(myPath) +//! [3] + + +//! [4] +myGradient = QLinearGradient() +myPen = QPen() +myPolygon = QPolygonF() + +myPath = QPainterPath() +myPath.addPolygon(myPolygon) + +QPainter painter(self) +painter.setBrush(myGradient) +painter.setPen(myPen) +painter.drawPath(myPath) +//! [4] + + +//! [5] +myGradient = QLinearGradient() +myPen = QPen() +boundingRectangle = QRectF() + +myPath = QPainterPath() +myPath.addEllipse(boundingRectangle) + +QPainter painter(self) +painter.setBrush(myGradient) +painter.setPen(myPen) +painter.drawPath(myPath) +//! [5] + + +//! [6] +myGradient = QLinearGradient() +myPen = QPen() +myFont = QFont() +QPointF baseline(x, y) + +myPath = QPainterPath() +myPath.addText(baseline, myFont, tr("Qt")) + +painter QPainter(self) +painter.setBrush(myGradient) +painter.setPen(myPen) +painter.drawPath(myPath) +//! [6] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpen.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpen.cpp new file mode 100644 index 000000000..7f063971d --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpen.cpp @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +painter = QPainter(self) +pen = QPen(Qt.green, 3, Qt.DashDotLine, Qt.RoundCap, Qt.RoundJoin) +painter.setPen(pen) +//! [0] + + +//! [1] +painter = QPainter(self) +pen = QPen() # creates a default pen + +pen.setStyle(Qt.DashDotLine) +pen.setWidth(3) +pen.setBrush(Qt.green) +pen.setCapStyle(Qt.RoundCap) +pen.setJoinStyle(Qt.RoundJoin) + +painter.setPen(pen) +//! [1] + + +//! [2] +pen = QPen() +space = 4; +dashes = [1, space, 3, space, 9, space, 27, space, 9, space] +pen.setDashPattern(dashes) +//! [2] + + +//! [3] +pen = QPen() +space = 4; +dashes = [1, space, 3, space, 9, space, 27, space, 9, space] +pen.setDashPattern(dashes) +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qregion.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qregion.cpp new file mode 100644 index 000000000..301f19499 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qregion.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +class MyWidget (QWidget): + # ... + def paintEvent(self): + r1 = QRegion(QRect(100, 100, 200, 80), QRegion.Ellipse) # r1: elliptic region + ) + r2 = QRect(100, 120, 90, 30) # r2: rectangular region + r3 = r1.intersected(r2) # r3: intersection + + painter = QPainter(self) + painter.setClipRegion(r3) + ... # paint clipped graphics +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qregion_unix.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qregion_unix.cpp new file mode 100644 index 000000000..76f08b156 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qregion_unix.cpp @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +r1 = QRegion(10, 10, 20, 20) +r1.isNull() // false +r1.isEmpty() // false + +r2 = QRegion(40, 40, 20, 20) +r3 = QRegion() +r3.isNull() // true +r3.isEmpty() // true + +r3 = r1.intersected(r2) // r3: intersection of r1 and r2 +r3.isNull() // false +r3.isEmpty() // true + +r3 = r1.united(r2) // r3: union of r1 and r2 +r3.isNull() // false +r3.isEmpty() // false +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qtransform.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qtransform.cpp new file mode 100644 index 000000000..dd063e1f9 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qtransform.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +x' = m11*x + m21*y + dx +y' = m22*y + m12*x + dy +if is not affine: + w' = m13*x + m23*y + m33 + x' /= w' + y' /= w' +//! [0] + + +//! [1] +x' = m11*x + m21*y + dx +y' = m22*y + m12*x + dy +if is not affine: + w' = m13*x + m23*y + m33 + x' /= w' + y' /= w' +//! [1] + + +//! [2] +x' = m11*x + m21*y + dx +y' = m22*y + m12*x + dy +if is not affine: + w' = m13*x + m23*y + m33 + x' /= w' + y' /= w' +//! [2] + + +//! [3] +x' = m11*x + m21*y + dx +y' = m22*y + m12*x + dy +if is not affine: + w' = m13*x + m23*y + m33 + x' /= w' + y' /= w' +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_styles_qstyle.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_styles_qstyle.cpp new file mode 100644 index 000000000..ba8719dc3 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_styles_qstyle.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +python myapplication.py -style motif +//! [0] + + +//! [1] +python myapplication.py -style custom +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_styles_qstyleoption.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_styles_qstyleoption.cpp new file mode 100644 index 000000000..a4354c671 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_styles_qstyleoption.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +def styleHint(self, stylehint, opt, widget, returnData): + if stylehint == SH_RubberBand_Mask: + if isinstance(QStyleHintReturnMask, hint): + ... + ... +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qfont.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qfont.cpp new file mode 100644 index 000000000..0e221a1fe --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qfont.cpp @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +serifFont = QFont("Times", 10, QFont.Bold) +sansFont = QFont("Helvetica [Cronyx]", 12) +//! [0] + + +//! [1] +f = QFont("Helvetica") +//! [1] + + +//! [2] +f = QFont("Helvetica [Cronyx]") +//! [2] + + +//! [3] +info = QFontInfo(f1) +family = info.family() +//! [3] + + +//! [4] +fm = QFontMetrics(f1) +textWidthInPixels = fm.width("How many pixels wide is this text?") +textHeightInPixels = fm.height() +//! [4] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qfontmetrics.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qfontmetrics.cpp new file mode 100644 index 000000000..ef89f1d7f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qfontmetrics.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +font = QFont("times", 24) +fm = QFontMetrics(font) +pixelsWide = fm.width("What's the width of this text?") +pixelsHigh = fm.height() +//! [0] + + +//! [1] +font = QFont("times", 24) +fm = QFontMetricsF(font) +pixelsWide = fm.width("What's the width of this text?") +pixelsHigh = fm.height() +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qsyntaxhighlighter.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qsyntaxhighlighter.cpp new file mode 100644 index 000000000..05300479a --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qsyntaxhighlighter.cpp @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +editor = QTextEdit() +highlighter = MyHighlighter(editor.document()) +//! [0] + + +//! [1] +class MyHighlighter(QSyntaxHighlighter): + def highlightBlock(self, text): + myClassFormat = QTextCharFormat() + myClassFormat.setFontWeight(QFont.Bold) + myClassFormat.setForeground(Qt.darkMagenta) + pattern = QString("\\bMy[A-Za-z]+\\b") + + expression = QRegExp(pattern) + index = text.indexOf(expression) + while index >= 0: + length = expression.matchedLength() + setFormat(index, length, myClassFormat) + index = text.indexOf(expression, index + length) +//! [1] + + +//! [2] +multiLineCommentFormat = QTextCharFormat() +multiLineCommentFormat.setForeground(Qt.red) + +startExpression = QRegExp("/\\*") +endExpression = QRegExp("\\*/") + +setCurrentBlockState(0) + +startIndex = 0 +if previousBlockState() != 1: + startIndex = text.indexOf(startExpression) + +while startIndex >= 0: + endIndex = text.indexOf(endExpression, startIndex) + if endIndex == -1: + setCurrentBlockState(1) + commentLength = text.length() - startIndex + else: + commentLength = endIndex - startIndex + + endExpression.matchedLength() + + setFormat(startIndex, commentLength, multiLineCommentFormat) + startIndex = text.indexOf(startExpression, + startIndex + commentLength) +//! [2] + + +//! [3] +class MyHighlighter(QSyntaxHighlighter): + def highlightBlock(self, text): + myClassFormat = QTextCharFormat() + myClassFormat.setFontWeight(QFont.Bold) + myClassFormat.setForeground(Qt.darkMagenta) + pattern = QString("\\bMy[A-Za-z]+\\b") + + expression = QRegExp(pattern) + index = text.indexOf(expression) + while index >= 0: + length = expression.matchedLength() + setFormat(index, length, myClassFormat) + index = text.indexOf(expression, index + length) +//! [3] + + +//! [4] +class BlockData(QTextBlockUserData): + def __init__(self): + # ... + self.parentheses = [] +//! [4] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextcursor.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextcursor.cpp new file mode 100644 index 000000000..4e3ec2f99 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextcursor.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +cursor.clearSelection() +cursor.movePosition(QTextCursor.NextWord, QTextCursor.KeepAnchor) +cursor.insertText("Hello World") +//! [0] + + +//! [1] +img = ... # A QImage +textDocument.addResource(QTextDocument.ImageResource, QUrl("myimage"), img) +cursor.insertImage("myimage") +//! [1] + + +//! [2] +cursor = QTextCursor(textDocument) +cursor.beginEditBlock() +cursor.insertText("Hello") +cursor.insertText("World") +cursor.endEditBlock() + +textDocument.undo() +//! [2] + + +//! [3] +cursor = QTextCursor(textDocument) +cursor.beginEditBlock() +cursor.insertText("Hello") +cursor.insertText("World") +cursor.endEditBlock() + +... + +cursor.joinPreviousEditBlock() +cursor.insertText("Hey") +cursor.endEditBlock() + +textDocument.undo() +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextdocument.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextdocument.cpp new file mode 100644 index 000000000..626436fea --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextdocument.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +plain = QString("#include <QtCore>") +html = Qt::escape(plain) +# html == "#include <QtCore>" +//! [0] + + +//! [1] +<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body>... +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextlayout.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextlayout.cpp new file mode 100644 index 000000000..2f01083ca --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextlayout.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +leading = fontMetrics.leading() +height = 0 +widthUsed = 0 +textLayout.beginLayout() +while True: + line = textLayout.createLine() + if not line.isValid(): + break + + line.setLineWidth(lineWidth) + height += leading + line.setPosition(QPointF(0, height)) + height += line.height() + widthUsed = qMax(widthUsed, line.naturalTextWidth()) +textLayout.endLayout() +//! [0] + + +//! [1] +painter = QPainter(self) +textLayout.draw(painter, QPoint(0, 0)) +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_util_qcompleter.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_util_qcompleter.cpp new file mode 100644 index 000000000..4010efc95 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_util_qcompleter.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +wordList = ["alpha", "omega", "omicron", "zeta"] + +lineEdit = QLineEdit(self) + +completer = QCompleter(wordList, self) +completer.setCaseSensitivity(Qt.CaseInsensitive) +lineEdit.setCompleter(completer) +//! [0] + + +//! [1] +completer = QCompleter(self) +completer.setModel(QDirModel(completer)) +lineEdit.setCompleter(completer) +//! [1] + + +//! [2] +i = 0 +while completer.setCurrentRow(i): + print "%s is match number %d" % (completer.currentCompletion(), i) + i += 1 +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_util_qdesktopservices.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_util_qdesktopservices.cpp new file mode 100644 index 000000000..b4622a8a9 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_util_qdesktopservices.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +def showHelp(url): + # ... + pass + +QDesktopServices.setUrlHandler("help", showHelp); +//! [0] + +//! [1] +mailto:user@foo.com?subject=Test&body=Just a test +//! [1] + +//! [2] +QDesktopServices.openUrl(QUrl("file:///C:/Documents and Settings/All Users/Desktop", QUrl.TolerantMode)) +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_util_qundostack.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_util_qundostack.cpp new file mode 100644 index 000000000..9d1196790 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_util_qundostack.cpp @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +class AppendText(QUndoCommand): + self.m_document = '' + self.m_text = '' + + def AppendText(self, doc, text): + self.m_document = doc + self.m_text = text + self.setText("append text") + + def undo(self): + self.m_document.chop(self.m_text.length()) + + def redo(self): + self.m_document->append(self.m_text) +//! [0] + + +//! [1] +command1 = MyCommand() +stack.push(command1) +command2 = MyCommand() +stack.push(command2) + +stack.undo() + +command3 = MyCommand() +stack.push(command3) # command2 gets deleted +//! [1] + + +//! [2] +insertRed = QUndoCommand() # an empty command +insertRed.setText("insert red text") + +InsertText(document, idx, text, insertRed) # becomes child of insertRed +SetColor(document, idx, text.length(), Qt.red, insertRed) + +stack.push(insertRed) +//! [2] + + +//! [3] +class AppendText(QUndoCommand): + ... + def mergeWith(self, other): + if other.id() != self.id(): # make sure other is also an AppendText command + return False + m_text += other.m_text + return True +//! [3] + + +//! [4] +stack.beginMacro("insert red text") +stack.push(InsertText(document, idx, text)) +stack.push(SetColor(document, idx, text.length(), Qt.red)) +stack.endMacro() # indexChanged() is emitted +//! [4] + + +//! [5] +insertRed = QUndoCommand() # an empty command +insertRed.setText("insert red text") + +InsertText(document, idx, text, insertRed) # becomes child of insertRed +SetColor(document, idx, text.length(), Qt.red, insertRed) + +stack.push(insertRed) +//! [5] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qabstractbutton.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qabstractbutton.cpp new file mode 100644 index 000000000..d84336a89 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qabstractbutton.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +button = QPushButton(QObject.tr("Ro&ck && Roll"), self) +//! [0] + + +//! [1] +button.setIcon(QIcon(":/images/print.png")) +button.setShortcut(tr("Alt+F7")) +//! [1] + + +//! [2] +class MyWidget (QWidget): + #... + def reactToToggle(checked): + if checked: + // Examine the button states. + ... +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qabstractspinbox.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qabstractspinbox.cpp new file mode 100644 index 000000000..b2b49698e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qabstractspinbox.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +spinBox = QSpinBox(self) +spinBox.setRange(0, 100) +spinBox.setWrapping(True) +spinBox.setValue(100) +spinBox.stepBy(1) +// value is 0 +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qcalendarwidget.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qcalendarwidget.cpp new file mode 100644 index 000000000..c2d6f4c18 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qcalendarwidget.cpp @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +calendar.setGridVisible(True) +//! [0] + + +//! [1] +calendar.setGridVisible(True) +calendar.setMinimumDate(QDate(2006, 6, 19)) +//! [1] + + +//! [2] +calendar.setGridVisible(True) +calendar.setMaximumDate(QDate(2006, 7, 3)) +//! [2] + + +//! [3] + +calendar.setDateRange(min, max) +//! [3] + + +//! [4] + +calendar.setMinimumDate(min) +calendar.setMaximumDate(max) +//! [4] + + +//! [5] +calendar.setGridVisible(True) +//! [5] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qcheckbox.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qcheckbox.cpp new file mode 100644 index 000000000..c8aa50aa2 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qcheckbox.cpp @@ -0,0 +1,3 @@ +//! [0] +checkbox = QCheckBox("C&ase sensitive", self) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qdatetimeedit.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qdatetimeedit.cpp new file mode 100644 index 000000000..c11b58961 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qdatetimeedit.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +dateEdit = QDateTimeEdit(QDate.currentDate()) +dateEdit.setMinimumDate(QDate.currentDate().addDays(-365)) +dateEdit.setMaximumDate(QDate.currentDate().addDays(365)) +dateEdit.setDisplayFormat("yyyy.MM.dd") +//! [0] + + +//! [1] +setDateTimeRange(min, max) +//! [1] + + +//! [2] +setMinimumDateTime(min) +setMaximumDateTime(max) +//! [2] + + +//! [3] +setDateRange(min, max) +//! [3] + + +//! [4] +setMinimumDate(min) +setMaximumDate(max) +//! [4] + + +//! [5] +setTimeRange(min, max) +//! [5] + + +//! [6] +setMinimumTime(min) +setMaximumTime(max) +//! [6] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qdockwidget.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qdockwidget.cpp new file mode 100644 index 000000000..04a9d9df4 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qdockwidget.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +dockWidget = parentWidget() +if dockWidget.features() & QDockWidget.DockWidgetVerticalTitleBar: + # I need to be vertical +else: + # I need to be horizontal +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qframe.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qframe.cpp new file mode 100644 index 000000000..951f9ec01 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qframe.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +label = QLabel() +label.setFrameStyle(QFrame.Panel | QFrame.Raised) +label.setLineWidth(2) + +pbar = QProgressBar() +label.setFrameStyle(QFrame.NoFrame) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qgroupbox.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qgroupbox.cpp new file mode 100644 index 000000000..d236d91dd --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qgroupbox.cpp @@ -0,0 +1,3 @@ +//! [0] +g.setTitle("&User information") +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qlabel.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qlabel.cpp new file mode 100644 index 000000000..0d2c80015 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qlabel.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +label = QLabel(self) +label.setFrameStyle(QFrame.Panel | QFrame.Sunken) +label.setText("first line\nsecond line") +label.setAlignment(Qt.AlignBottom | Qt.AlignRight) +//! [0] + + +//! [1] +phoneEdit = QLineEdit(self) +phoneLabel = QLabel("&Phone:", self) +phoneLabel.setBuddy(phoneEdit) +//! [1] + + +//! [2] +nameEd = QLineEdit(self) +nameLb = QLabel("&Name:", self) +nameLb.setBuddy(nameEd) +phoneEd = QLineEdit(self) +phoneLb = QLabel("&Phone:", self) +phoneLb.setBuddy(phoneEd) +# (layout setup not shown) +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qlineedit.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qlineedit.cpp new file mode 100644 index 000000000..9418f5ea5 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qlineedit.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +def contextMenuEvent(event): + menu = createStandardContextMenu() + menu.addAction(QObject.tr("My Menu Item")) + #... + menu.exec_(event.globalPos()) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qmainwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qmainwindow.cpp new file mode 100644 index 000000000..dfc7e6902 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qmainwindow.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +def closeEvent(self, event): + settings = QSettings("MyCompany", "MyApp") + settings.setValue("geometry", self.saveGeometry()) + settings.setValue("windowState", self.saveState()) + QMainWindow.closeEvent(self, event) +//! [0] + + +//! [1] +def readSettings(self): + settings = QSettings("MyCompany", "MyApp") + restoreGeometry(settings.value("myWidget/geometry")) + restoreState(settings.value("myWidget/windowState")) +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qmenu.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qmenu.cpp new file mode 100644 index 000000000..f5fcc8ca3 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qmenu.cpp @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +exec_(QCursor.pos()) +//! [0] + + +//! [1] +exec_(somewidget.mapToGlobal(QPoint(0,0))) +//! [1] + + +//! [2] +exec_(e.globalPos()) +//! [2] + + +//! [3] +exec_(QCursor.pos()) +//! [3] + + +//! [4] +exec_(somewidget.mapToGlobal(QPoint(0, 0))) +//! [4] + + +//! [5] +exec_(e.globalPos()) +//! [5] + + +//! [6] +menu = QMenu() +at = actions[0] // Assumes actions is not empty +for a in actions: + menu.addAction(a) +menu.exec_(pos, at) +//! [6] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qmenubar.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qmenubar.cpp new file mode 100644 index 000000000..e3e974fe2 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qmenubar.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +menubar.addMenu(fileMenu) +//! [0] + + +//! [1] +menuBar = QMenuBar() +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qplaintextedit.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qplaintextedit.cpp new file mode 100644 index 000000000..dd3d0e3b7 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qplaintextedit.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +class MyQPlainTextEdit(QPlainTextEdit): + def contextMenuEvent(self, event): + menu = createStandardContextMenu() + menu.addAction(tr("My Menu Item")) + # ... + menu.exec_(event.globalPos()) + del menu +//! [0] + + +//! [1] +edit.textCursor().insertText(text) +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qpushbutton.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qpushbutton.cpp new file mode 100644 index 000000000..74b4cf884 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qpushbutton.cpp @@ -0,0 +1,3 @@ +//! [0] +button = QPushButton("&Download", self) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qradiobutton.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qradiobutton.cpp new file mode 100644 index 000000000..dbee86850 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qradiobutton.cpp @@ -0,0 +1,3 @@ +//! [0] +button = QRadioButton("Search from the &cursor", self) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qrubberband.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qrubberband.cpp new file mode 100644 index 000000000..8a689fc74 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qrubberband.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +class Widget: + def mousePressEvent(self, event): + origin = event.pos() + if not self.rubberBand: + self.rubberBand = QRubberBand(QRubberBand.Rectangle, self) + rubberBand.setGeometry(QRect(origin, QSize())) + rubberBand.show() + + def mouseMoveEvent(self, event): + rubberBand.setGeometry(QRect(origin, event.pos()).normalized()) + + def mouseReleaseEvent(self, event): + rubberBand.hide() + # determine selection, for example using QRect.intersects() + # and QRect.contains(). +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qscrollarea.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qscrollarea.cpp new file mode 100644 index 000000000..3ff390b35 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qscrollarea.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +imageLabel = QLabel() +image = QImage("happyguy.png") +imageLabel.setPixmap(QPixmap.fromImage(image)) + +scrollArea = QScrollArea() +scrollArea.setBackgroundRole(QPalette.Dark) +scrollArea.setWidget(imageLabel) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qspinbox.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qspinbox.cpp new file mode 100644 index 000000000..8df536bf2 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qspinbox.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +sb.setPrefix("$") +//! [0] + + +//! [1] +sb.setSuffix(" km") +//! [1] + + +//! [2] +setRange(minimum, maximum) +//! [2] + + +//! [3] +setMinimum(minimum) +setMaximum(maximum) +//! [3] + + +//! [4] +spinbox.setPrefix("$") +//! [4] + + +//! [5] +spinbox.setSuffix(" km") +//! [5] + + +//! [6] +setRange(minimum, maximum) +//! [6] + + +//! [7] +setMinimum(minimum) +setMaximum(maximum) +//! [7] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qsplashscreen.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qsplashscreen.cpp new file mode 100644 index 000000000..6d6ec7ba5 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qsplashscreen.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +pixmap = QPixmap(":/splash.png") +splash = QSplashScreen(pixmap) +splash.show() + +... # Loading some items +splash.showMessage("Loaded modules") + +qApp.processEvents() + +... # Establishing connections +splash.showMessage("Established connections") + +qApp.processEvents() +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qsplitter.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qsplitter.cpp new file mode 100644 index 000000000..b6cf932d8 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qsplitter.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +widget = splitter.widget(index) +policy = widget.sizePolicy() +policy.setHorizontalStretch(stretch) +policy.setVerticalStretch(stretch) +widget.setSizePolicy(policy) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qstatusbar.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qstatusbar.cpp new file mode 100644 index 000000000..8b972b6f2 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qstatusbar.cpp @@ -0,0 +1,3 @@ +//! [0] +statusBar().addWidget(MyReadWriteIndication()) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qtextbrowser.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qtextbrowser.cpp new file mode 100644 index 000000000..cf9382dbc --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qtextbrowser.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +backaction.setToolTip(browser.historyTitle(-1)) +forwardaction.setToolTip(browser.historyTitle(+1)) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qtextedit.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qtextedit.cpp new file mode 100644 index 000000000..fef8b8e34 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qtextedit.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +class MyTextEdit(QTextEdit): + def contextMenuEvent(self, event): + menu = createStandardContextMenu() + menu.addAction(tr("My Menu Item")) + #... + menu.exec_(event->globalPos()) + del menu +//! [0] + + +//! [1] +edit.textCursor().insertText(text) +//! [1] + + +//! [2] +edit.textCursor().insertHtml(fragment) +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qvalidator.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qvalidator.cpp new file mode 100644 index 000000000..b366dc2ab --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qvalidator.cpp @@ -0,0 +1,155 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +validator = QIntValidator(100, 999, self) +edit = QLineEdit(self) + +# the edit lineedit will only accept integers between 100 and 999 +edit.setValidator(validator) +//! [0] + + +//! [1] +pos = 0 +v = QIntValidator(100, 900, self) + +str = "1" +v.validate(str, pos) # returns Intermediate +str = "012" +v.validate(str, pos) # returns Intermediate + +str = "123" +v.validate(str, pos) # returns Acceptable +str = "678" +v.validate(str, pos) # returns Acceptable + +str = "999" +v.validate(str, pos) # returns Intermediate + +str = "1234" +v.validate(str, pos) # returns Invalid +str = "-123" +v.validate(str, pos) # returns Invalid +str = "abc" +v.validate(str, pos) # returns Invalid +str = "12cm" +v.validate(str, pos) # returns Invalid +//! [1] + + +//! [2] +pos = 0 + +s = "abc" +v.validate(s, pos) # returns Invalid + +s = "5" +v.validate(s, pos) # returns Intermediate + +s = "50" +v.validate(s, pos) # returns Acceptable +//! [2] + + +//! [3] +# regexp: optional '-' followed by between 1 and 3 digits +rx = QRegExp("-?\\d{1,3}") +validator = QRegExpValidator(rx, self) + +edit = QLineEdit(self) +edit.setValidator(validator) +//! [3] + + +//! [4] +# integers 1 to 9999 +rx = QRegExp("[1-9]\\d{0,3}") +# the validator treats the regexp as "^[1-9]\\d{0,3}$" +v = QRegExpValidator(rx, 0) +pos = 0 + +s = "0" +v.validate(s, pos) # returns Invalid +s = "12345" +v.validate(s, pos) # returns Invalid +s = "1" +v.validate(s, pos) # returns Acceptable + +rx.setPattern("\\S+") # one or more non-whitespace characters +v.setRegExp(rx) +s = "myfile.txt" +v.validate(s, pos) # Returns Acceptable +s = "my file.txt" +v.validate(s, pos) # Returns Invalid + +# A, B or C followed by exactly five digits followed by W, X, Y or Z +rx.setPattern("[A-C]\\d{5}[W-Z]") +v.setRegExp(rx) +s = "a12345Z" +v.validate(s, pos) # Returns Invalid +s = "A12345Z" +v.validate(s, pos) # Returns Acceptable +s = "B12" +v.validate(s, pos) # Returns Intermediate + +# match most 'readme' files +rx.setPattern("read\\S?me(\.(txt|asc|1st))?") +rx.setCaseSensitive(false) +v.setRegExp(rx) +s = "readme" +v.validate(s, pos) # Returns Acceptable +s = "README.1ST" +v.validate(s, pos) # Returns Acceptable +s = "read me.txt" +v.validate(s, pos) # Returns Invalid +s = "readm" +v.validate(s, pos) # Returns Intermediate +//! [4] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qworkspace.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qworkspace.cpp new file mode 100644 index 000000000..f26999148 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qworkspace.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +class MainWindow(...): + def __init__(self): + self.workspace = QWorkspace() + self.setCentralWidget(workspace) + ... +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qftp.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qftp.cpp new file mode 100644 index 000000000..b227b5797 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qftp.cpp @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +ftp = QFtp(parent) +ftp.connectToHost("ftp.trolltech.com") +ftp.login() +//! [0] + + +//! [1] +ftp.connectToHost("ftp.trolltech.com") # id == 1 +ftp.login() # id == 2 +ftp.cd("qt") # id == 3 +ftp.get("INSTALL") # id == 4 +ftp.close() # id == 5 +//! [1] + + +//! [2] +start(1) +stateChanged(HostLookup) +stateChanged(Connecting) +stateChanged(Connected) +finished(1, false) + +start(2) +stateChanged(LoggedIn) +finished(2, false) + +start(3) +finished(3, false) + +start(4) +dataTransferProgress(0, 3798) +dataTransferProgress(2896, 3798) +readyRead() +dataTransferProgress(3798, 3798) +readyRead() +finished(4, false) + +start(5) +stateChanged(Closing) +stateChanged(Unconnected) +finished(5, false) + +done(false) +//! [2] + + +//! [3] +start(1) +stateChanged(HostLookup) +stateChanged(Connecting) +stateChanged(Connected) +finished(1, false) + +start(2) +finished(2, true) + +done(true) +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qhttp.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qhttp.cpp new file mode 100644 index 000000000..31216fd7f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qhttp.cpp @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +content-type: text/html +//! [0] + + +//! [1] +header.setValue("content-type", "text/html") +contentType = header.value("content-type") +//! [1] + + +//! [2] +header = QHttpRequestHeader("GET", QUrl.toPercentEncoding("/index.html")) +header.setValue("Host", "qtsoftware.com") +http.setHost("qtsoftware.com") +http.request(header) +//! [2] + + +//! [3] +http.setHost("qtsoftware.com") # id == 1 +http.get(QUrl.toPercentEncoding("/index.html")) # id == 2 +//! [3] + + +//! [4] +requestStarted(1) +requestFinished(1, False) + +requestStarted(2) +stateChanged(Connecting) +stateChanged(Sending) +dataSendProgress(77, 77) +stateChanged(Reading) +responseHeaderReceived(responseheader) +dataReadProgress(5388, 0) +readyRead(responseheader) +dataReadProgress(18300, 0) +readyRead(responseheader) +stateChanged(Connected) +requestFinished(2, False) + +done(False) + +stateChanged(Closing) +stateChanged(Unconnected) +//! [4] + + +//! [5] +http.setHost("www.foo.bar") # id == 1 +http.get("/index.html") # id == 2 +http.post("register.html", data) # id == 3 +//! [5] + + +//! [6] +requestStarted(1) +requestFinished(1, False) + +requestStarted(2) +stateChanged(HostLookup) +requestFinished(2, True) + +done(True) + +stateChanged(Unconnected) +//! [6] + + +//! [7] +def getTicks(self): + http = QHttp(self) + self.connect(http, SIGNAL('done(bool)'), self, SLOT('showPage()')) + http.setProxy("proxy.example.com", 3128) + http.setHost("ticker.example.com") + http.get("/ticks.asp") + +def showPage(self): + self.display(http.readAll()) + +//! [7] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp new file mode 100644 index 000000000..0c7afec10 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +manager = QNetworkAccessManager(self) +manager.finished[QNetworkReply].connect(self.replyFinished) + +manager.get(QNetworkRequest(QUrl("http://qt.nokia.com"))) +//! [0] + + +//! [1] +request = QNetworkRequest() +request.setUrl(QUrl("http://qt.nokia.com")) +request.setRawHeader("User-Agent", "MyOwnBrowser 1.0") + +reply = manager.get(request) +reply.readyRead.connect(self.slotReadyRead) +reply.error[QNetworkReply.NetworkError].connect(self..slotError) +reply.sslErrors.connect(self.slotSslErrors) +//! [1] + +//! [2] +manager = QNetworkConfigurationManager() +networkAccessManager.setConfiguration(manager.defaultConfiguration()) +//! [2] + +//! [3] +networkAccessManager.setConfiguration(QNetworkConfiguration()) +//! [3] + +//! [4] +networkAccessManager.setNetworkAccessible(QNetworkAccessManager.NotAccessible) +//! [4] + +//! [5] +networkAccessManager.setNetworkAccessible(QNetworkAccessManager.Accessible) +//! [5] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkdiskcache.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkdiskcache.cpp new file mode 100644 index 000000000..7e2aea326 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkdiskcache.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +manager = QNetworkAccessManager(self) +diskCache = QNetworkDiskCache(self) +diskCache.setCacheDirectory("cacheDir") +manager.setCache(diskCache) +//! [0] + +//! [1] +# do a normal request (preferred from network, as this is the default) +request = QNetworkRequest(QUrl("http://qt.nokia.com")) +manager.get(request) + +# do a request preferred from cache +request2 = QNetworkRequest(QUrl("http://qt.nokia.com")) +request2.setAttribute(QNetworkRequest.CacheLoadControlAttribute, QNetworkRequest.PreferCache) +manager.get(request2) +//! [1] + +//! [2] +@Slot(QNetworkReply) +def replyFinished(reply): + fromCache = reply.attribute(QNetworkRequest.SourceIsFromCacheAttribute) + print("page from cache? %d" % fromCache) +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkrequest.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkrequest.cpp new file mode 100644 index 000000000..9156597b1 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkrequest.cpp @@ -0,0 +1,3 @@ +//! [0] +request.setRawHeader("Last-Modified", "Sun, 06 Nov 1994 08:49:37 GMT") +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_bearer_qnetworkconfigmanager.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_bearer_qnetworkconfigmanager.cpp new file mode 100644 index 000000000..951446fbb --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_bearer_qnetworkconfigmanager.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +mgr = QNetworkConfigurationManager() +activeConfigs = mgr.allConfigurations(QNetworkConfiguration.Active) +if activeConfigs: + assert(mgr.isOnline()) +else: + assert(not mgr.isOnline()) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_kernel_qhostaddress.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_kernel_qhostaddress.cpp new file mode 100644 index 000000000..e6de7bf36 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_kernel_qhostaddress.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +addr = hostAddr.toIPv6Address() +# addr contains 16 unsigned characters + +for i in range(0, 16): + # process addr[i] +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_kernel_qhostinfo.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_kernel_qhostinfo.cpp new file mode 100644 index 000000000..c1971b0ba --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_kernel_qhostinfo.cpp @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +# To find the IP address of qtsoftware.com +QHostInfo.lookupHost("qtsoftware.com", self, SLOT("printResults(QHostInfo)")) + +# To find the host name for 4.2.2.1 +QHostInfo.lookupHost("4.2.2.1", self, SLOT("printResults(QHostInfo)")) +//! [0] + + +//! [1] +info = QHostInfo.fromName("qtsoftware.com") +//! [1] + + +//! [2] +QHostInfo.lookupHost("www.kde.org", self.lookedUp) +//! [2] + + +//! [3] +def lookedUp(host): + if host.error() != QHostInfo.NoError: + print "Lookup failed: %s" % host.errorString() + return + + for address in host.addresses(): + print "Found address: %s" % address.toString() +//! [3] + + +//! [4] +QHostInfo.lookupHost("4.2.2.1", self.lookedUp) +//! [4] + + +//! [5] +info = QHostInfo() +... +if not info.addresses().isEmpty(): + address = info.addresses().first() + # use the first IP address +//! [5] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_kernel_qnetworkproxy.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_kernel_qnetworkproxy.cpp new file mode 100644 index 000000000..681534045 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_kernel_qnetworkproxy.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +proxy = QNetworkProxy() +proxy.setType(QNetworkProxy.Socks5Proxy) +proxy.setHostName("proxy.example.com") +proxy.setPort(1080) +proxy.setUser("username") +proxy.setPassword("password") +QNetworkProxy.setApplicationProxy(proxy) +//! [0] + + +//! [1] +serverSocket.setProxy(QNetworkProxy.NoProxy) +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qabstractsocket.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qabstractsocket.cpp new file mode 100644 index 000000000..f1e271eaf --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qabstractsocket.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +socket.connectToHost("imap", 143) +if socket.waitForConnected(1000): + print "Connected!" +//! [0] + + +//! [1] +socket.disconnectFromHost() + if socket.state() == QAbstractSocket.UnconnectedState or \ + socket.waitForDisconnected(1000): + print "Disconnected!" +//! [1] + + +//! [2] +class SocketClass(...): + def readyReadSlot(self): + # This slot is connected to QAbstractSocket::readyRead() + while not socket.atEnd(): + data = socket.read(100) + ... +//! [2] + + +//! [3] +socket.setProxy(QNetworkProxy.NoProxy) +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qlocalsocket_unix.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qlocalsocket_unix.cpp new file mode 100644 index 000000000..f7815a631 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qlocalsocket_unix.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +socket.connectToServer("market") +if (socket.waitForConnected(1000)) + print("Connected!") +//! [0] + + +//! [1] +socket.disconnectFromServer() +if (socket.waitForDisconnected(1000)) + print("Disconnected!") +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qnativesocketengine.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qnativesocketengine.cpp new file mode 100644 index 000000000..02c4e5032 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qnativesocketengine.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +socketLayer = QNativeSocketEngine() +socketLayer.initialize(QAbstractSocket.TcpSocket, QAbstractSocket.IPv4Protocol) +socketLayer.connectToHost(QHostAddress.LocalHost, 22) +# returns False + +socketLayer.waitForWrite() +socketLayer.connectToHost(QHostAddress.LocalHost, 22) +# returns True +//! [0] + + +//! [1] +socketLayer = QNativeSocketEngine() +socketLayer.bind(QHostAddress.Any, 4000) +socketLayer.listen() +if socketLayer.waitForRead(): + clientSocket = socketLayer.accept() + # a client is connected + +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qtcpserver.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qtcpserver.cpp new file mode 100644 index 000000000..b685462bc --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qtcpserver.cpp @@ -0,0 +1,3 @@ +//! [0] +server.setProxy(QNetworkProxy.NoProxy) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qudpsocket.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qudpsocket.cpp new file mode 100644 index 000000000..d1ecc6754 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qudpsocket.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +def initSocket(self): + udpSocket = QUdpSocket(self) + udpSocket.bind(QHostAddress.LocalHost, 7755) + + self.connect(udpSocket, SIGNAL('readyRead()'), + self, SLOT('readPendingDatagrams()')) + +def readPendingDatagrams(self): + while udpSocket.hasPendingDatagrams(): + datagram = QByteArray() + datagram.resize(udpSocket.pendingDatagramSize()) + + (sender, senderPort) = udpSocket.readDatagram(datagram.data(), datagram.size()) + + processTheDatagram(datagram) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_ssl_qsslcertificate.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_ssl_qsslcertificate.cpp new file mode 100644 index 000000000..234502ec6 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_ssl_qsslcertificate.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +for cert in QSslCertificate.fromPath('C:/ssl/certificate.*.pem', QSsL.Pem, QRegExp.Wildcard): + print cert.issuerInfo(QSslCertificate.Organization) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_ssl_qsslconfiguration.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_ssl_qsslconfiguration.cpp new file mode 100644 index 000000000..0d95b3bbb --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_ssl_qsslconfiguration.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +config = sslSocket.sslConfiguration() +config.setProtocol(QSsl.TlsV1) +sslSocket.setSslConfiguration(config) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_ssl_qsslsocket.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_ssl_qsslsocket.cpp new file mode 100644 index 000000000..865b8ce50 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_ssl_qsslsocket.cpp @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +socket = QSslSocket(self) +QObject.connect(socket, SIGNAL("encrypted()"), self, SLOT("ready()")) + +socket.connectToHostEncrypted("imap.example.com", 993) +//! [0] + + +//! [1] +def incomingConnection(socketDescriptor): + serverSocket = QSslSocket() + if serverSocket.setSocketDescriptor(socketDescriptor): + QObject.connect(serverSocket, SIGNAL("encrypted()"), self, SLOT("ready()")) + serverSocket.startServerEncryption() +//! [1] + + +//! [2] +socket = QSslSocket() +socket.connectToHostEncrypted("http.example.com", 443) +if not socket.waitForEncrypted(): + print socket.errorString() + return false + +socket.write("GET / HTTP/1.0\r\n\r\n") +while socket.waitForReadyRead(): + print socket.readAll().data() +//! [2] + + +//! [3] +socket = QSslSocket() +QObject.connect(socket, SIGNAL("encrypted()"), receiver, SLOT("socketEncrypted()")) + +socket.connectToHostEncrypted("imap", 993) +socket.write("1 CAPABILITY\r\n") +//! [3] + + +//! [4] +socket = QSslSocket() +socket.setCiphers("DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:AES256-SHA") +//! [4] + + +//! [5] +socket.connectToHostEncrypted("imap", 993) +if socket.waitForEncrypted(1000): + print "Encrypted!" +//! [5] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qgl.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qgl.cpp new file mode 100644 index 000000000..64c69aee9 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qgl.cpp @@ -0,0 +1,168 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +fmt = QGLFormat() +fmt.setAlpha(True) +fmt.setStereo(True) +QGLFormat.setDefaultFormat(fmt) +//! [0] + + +//! [1] +fmt = QGLFormat() +fmt.setDoubleBuffer(False) # single buffer +fmt.setDirectRendering(False) # software rendering +myWidget = MyGLWidget(fmt, ...) +//! [1] + + +//! [2] +fmt = QGLFormat() +fmt.setOverlay(True) +fmt.setStereo(True) +myWidget = MyGLWidget(fmt, ...) +if !myWidget.format().stereo(): + # ok, goggles off + if !myWidget.format().hasOverlay(): + print "Cool hardware required" +//! [2] + + +//! [3] +# The rendering in MyGLWidget depends on using +# stencil buffer and alpha channel + +class MyGLWidget(QGLWidget): + def __init__(self, parent): + QGLWidget.__init__(self, QGLFormat(QGL.StencilBuffer | QGL.AlphaChannel), parent) + + if !format().stencil(): + print "Could not get stencil buffer results will be suboptimal" + if !format().alpha(): + print "Could not get alpha channel results will be suboptimal" + ... +//! [3] + + +//! [4] +a = QApplication([]) +f = QGLFormat() +f.setDoubleBuffer(False) +QGLFormat.setDefaultFormat(f) +//! [4] + + +//! [5] +f = QGLFormat.defaultOverlayFormat() +f.setDoubleBuffer(True) +QGLFormat.setDefaultOverlayFormat(f) +//! [5] + + +//! [6] +# ...continued from above +myWidget = MyGLWidget(QGLFormat(QGL.HasOverlay), ...) +if myWidget.format().hasOverlay(): + # Yes, we got an overlay, let's check _its_ format: + olContext = myWidget.overlayContext() + if olContext.format().doubleBuffer(): + # yes, we got a double buffered overlay + else: + # no, only single buffered overlays are available +//! [6] + + +//! [7] +cx = QGLContext() +# ... +f = QGLFormat() +f.setStereo(True) +cx.setFormat(f) +if !cx.create(): + exit() # no OpenGL support, or cannot render on the specified paintdevice +if !cx.format().stereo(): + exit() # could not create stereo context +//! [7] + + +//! [8] +class MyGLDrawer(QGLWidget): + + def __init__(self, parent): + QGLWidget.__init__(self, parent) + pass + + def initializeGL(self): + # Set up the rendering context, define display lists etc.: + ... + glClearColor(0.0, 0.0, 0.0, 0.0) + glEnable(GL_DEPTH_TEST) + ... + + def resizeGL(self, w, h): + # setup viewport, projection etc.: + glViewport(0, 0, w, h) + ... + glFrustum(...) + ... + + def paintGL(self): + # draw the scene: + ... + glRotatef(...) + glMaterialfv(...) + glBegin(GL_QUADS) + glVertex3f(...) + glVertex3f(...) + ... + glEnd() + ... +//! [8] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qglcolormap.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qglcolormap.cpp new file mode 100644 index 000000000..6a087c3a8 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qglcolormap.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +import sys + +from PySide2.QtGui import QApplication, qRgb +from PySide2.QtOpenGL import QGLColormap + +def main(argv): + app = QApplication(argv) + + widget = MySuperGLWidget() # a QGLWidget in color-index mode + colormap = QGLColormap() + + # This will fill the colormap with colors ranging from + # black to white. + for i in range(0, colormap.size()): + colormap.setEntry(i, qRgb(i, i, i)) + + widget.setColormap(colormap) + widget.show() + return app.exec_() + +if __name__ == "__main__": + main(sys.argv) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qglpixelbuffer.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qglpixelbuffer.cpp new file mode 100644 index 000000000..20c1d7431 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qglpixelbuffer.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +pbuffer QGLPixelBuffer(...) +... +pbuffer.makeCurrent() +dynamicTexture = pbuffer.generateDynamicTexture() +pbuffer.bindToDynamicTexture(dynamicTexture) +... +pbuffer.releaseFromDynamicTexture() +//! [0] + + +//! [1] +pbuffer QGLPixelBuffer(...) +... +pbuffer.makeCurrent() +dynamicTexture = pbuffer.generateDynamicTexture() +... +pbuffer.updateDynamicTexture(dynamicTexture) +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qglshaderprogram.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qglshaderprogram.cpp new file mode 100644 index 000000000..2633705df --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qglshaderprogram.cpp @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +shader = QGLShader(QGLShader.Vertex) +shader.compileSourceCode(code) + +program = QGLShaderProgram(context) +program.addShader(shader) +program.link() + +program.bind() +//! [0] + +//! [1] +program.addShaderFromSourceCode(QGLShader.Vertex, + "attribute highp vec4 vertex\n" \ + "attribute mediump mat4 matrix\n" \ + "void main(void)\n" \ + "{\n" \ + " gl_Position = matrix * vertex\n" \ + "}") +program.addShaderFromSourceCode(QGLShader.Fragment, + "uniform mediump vec4 color\n" \ + "void main(void)\n" \ + "{\n" \ + " gl_FragColor = color\n" \ + "}") +program.link() +program.bind() + +vertexLocation = program.attributeLocation("vertex") +matrixLocation = program.attributeLocation("matrix") +colorLocation = program.uniformLocation("color") +//! [1] + +//! [2] +triangleVertices = ( + 60.0f, 10.0f, 0.0f, + 110.0f, 110.0f, 0.0f, + 10.0f, 110.0f, 0.0f) + +color = QColor(0, 255, 0, 255) + +pmvMatrix = QMatrix4x4() +pmvMatrix.ortho(self.rect()) + +program.enableAttributeArray(vertexLocation) +program.setAttributeArray(vertexLocation, triangleVertices, 3) +program.setUniformValue(matrixLocation, pmvMatrix) +program.setUniformValue(colorLocation, color) + +glDrawArrays(GL_TRIANGLES, 0, 3) + +program.disableAttributeArray(vertexLocation) +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_qtestlib_qtestcase.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_qtestlib_qtestcase.cpp new file mode 100644 index 000000000..fbc97b416 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_qtestlib_qtestcase.cpp @@ -0,0 +1,237 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +QVERIFY(1 + 1 == 2) +//! [0] + + +//! [1] +QVERIFY2(1 + 1 == 2, "A breach in basic arithmetic occured.") +//! [1] + + +//! [2] +QCOMPARE(QString("hello").toUpper(), QString("HELLO")) +//! [2] + + +//! [3] +void TestQString.toInt_data() +{ + QTest.addColumn<QString>("aString") + QTest.addColumn<int>("expected") + + QTest.newRow("positive value") << "42" << 42 + QTest.newRow("negative value") << "-42" << -42 + QTest.newRow("zero") << "0" << 0 +} +//! [3] + + +//! [4] +void TestQString.toInt() +{ + QFETCH(QString, aString) + QFETCH(int, expected) + + QCOMPARE(aString.toInt(), expected) +} +//! [4] + + +//! [5] +if (sizeof(int) != 4) + QFAIL("This test has not been ported to this platform yet.") +//! [5] + + +//! [6] +QFETCH(QString, myString) +QCOMPARE(QString("hello").toUpper(), myString) +//! [6] + + +//! [7] +QTEST(QString("hello").toUpper(), "myString") +//! [7] + + +//! [8] +if (!QSqlDatabase.drivers().contains("SQLITE")) + QSKIP("This test requires the SQLITE database driver", SkipAll) +//! [8] + + +//! [9] +QEXPECT_FAIL("", "Will fix in the next release", Continue) +QCOMPARE(i, 42) +QCOMPARE(j, 43) +//! [9] + + +//! [10] +QEXPECT_FAIL("data27", "Oh my, this is soooo broken", Abort) +QCOMPARE(i, 42) +//! [10] + + +//! [11] +class TestQString: public QObject { ... } +QTEST_MAIN(TestQString) +//! [11] + + +//! [12] +#ifdef Q_WS_X11 + QTEST_MAIN(MyX11Test) +#else + // do nothing on non-X11 platforms + QTEST_NOOP_MAIN +#endif +//! [12] + + +//! [13] +QTest.keyClick(myWidget, 'a') +//! [13] + + +//! [14] +QTest.keyClick(myWidget, Qt.Key_Escape) + +QTest.keyClick(myWidget, Qt.Key_Escape, Qt.ShiftModifier, 200) +//! [14] + + +//! [15] +QTest.keyClicks(myWidget, "hello world") +//! [15] + + +//! [16] +namespace QTest { + template<> + char *toString(const MyPoint &point) + { + QByteArray ba = "MyPoint(" + ba += QByteArray.number(point.x()) + ", " + QByteArray.number(point.y()) + ba += ")" + return qstrdup(ba.data()) + } +} +//! [16] + + +//! [17] +int i = 0 +while (myNetworkServerNotResponding() && i++ < 50) + QTest.qWait(250) +//! [17] + + +//! [18] +MyFirstTestObject test1 +QTest.qExec(&test1) + +MySecondTestObject test2 +QTest.qExec(&test2) +//! [18] + + +//! [19] +QDir dir + +QTest.ignoreMessage(QtWarningMsg, "QDir.mkdir: Empty or null file name(s)") +dir.mkdir("") +//! [19] + + +//! [20] +void myTestFunction_data() +{ + QTest.addColumn<QString>("aString") + QTest.newRow("just hello") << QString("hello") + QTest.newRow("a null string") << QString() +} +//! [20] + + +//! [21] +void myTestFunction_data() { + QTest.addColumn<int>("intval") + QTest.addColumn<QString>("str") + QTest.addColumn<double>("dbl") + + QTest.newRow("row1") << 1 << "hello" << 1.5 +} +//! [21] + + +//! [22] +void MyTestClass.cleanup() +{ + if (qstrcmp(currentTestFunction(), "myDatabaseTest") == 0) { + // clean up all database connections + closeAllDatabases() + } +} +//! [22] + + +//! [23] +QTest.qSleep(250) +//! [23] + +//! [24] +widget = QWidget() +widget.show() +QTest.qWaitForWindowShown(widget) +//! [24] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptable.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptable.cpp new file mode 100644 index 000000000..86ac79c8f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptable.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +class MyScriptableObject(QObject, QScriptable): +... + def doSomething(self): + ... + def doSomethingElse(self): + ... +//! [0] + + +//! [1] + +def doSomething(self): + self.context().throwError('Threw an error from a slot') + +def doSomethingElse(self): + return self.thisObject() + +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptclass.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptclass.cpp new file mode 100644 index 000000000..41df2baea --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptclass.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +if extension == Callable: + context = argument + engine = context.engine() + sum = 0 + for i in range(0, context.argumentCount()): + sum += context.argument(i).toNumber() + return sum +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptcontext.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptcontext.cpp new file mode 100644 index 000000000..393c9cd4e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptcontext.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +foo(20.5, "hello", Object()) +//! [0] + + +//! [1] +def Person_prototype_fullName(context, engine): + self = context.selfObject() + result = self.property("firstName").toString() + result += QLatin1String(" ") + result += self.property("lastName").toString() + return result +//! [1] + + +//! [2] +def myInclude(ctx, eng): + fileName = ctx.argument(0).toString() + contents = readTheFile(fileName) + ctx.setActivationObject(ctx.parentContext().activationObject()) + ctx.setThisObject(ctx.parentContext().selfObject()) + return eng.evaluate(contents, fileName) +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptengine.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptengine.cpp new file mode 100644 index 000000000..2f27b446e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptengine.cpp @@ -0,0 +1,320 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +myEngine = QScriptEngine() +three = myEngine.evaluate("1 + 2") +//! [0] + + +//! [1] +fun = myEngine.evaluate("function(a, b) { return a + b }"); +args = QScriptValueList() +args << 1 << 2 +threeAgain = fun.call(QScriptValue(), args) +//! [1] + + +//! [2] +fileName = "helloworld.qs" +scriptFile = QFile(fileName) +if !scriptFile.open(QIODevice.ReadOnly): + # handle error +stream = QTextStream(scriptFile) +contents = stream.readAll() +scriptFile.close() +myEngine.evaluate(contents, fileName) +//! [2] + + +//! [3] +myEngine.globalObject().setProperty("myNumber", 123) +... +myNumberPlusOne = myEngine.evaluate("myNumber + 1") +//! [3] + + +//! [4] +result = myEngine.evaluate(...) +if myEngine.hasUncaughtException(): + line = myEngine.uncaughtExceptionLineNumber() + print "uncaught exception at line", line, ":", result.toString() +//! [4] + + +//! [5] +button = QPushButton() +QScriptValue scriptButton = myEngine.QObject(button) +myEngine.globalObject().setProperty("button", scriptButton) + +myEngine.evaluate("button.checkable = True") + +print scriptButton.property("checkable").toBoolean() +scriptButton.property("show").call() # call the show() slot +//! [5] + + +//! [6] +def myAdd(context, engine): + a = context.argument(0) + b = context.argument(1) + return a.toNumber() + b.toNumber() +//! [6] + + +//! [7] +fun = myEngine.Function(myAdd) +myEngine.globalObject().setProperty("myAdd", fun) +//! [7] + + +//! [8] +result = myEngine.evaluate("myAdd(myNumber, 1)") +//! [8] + + +//! [9] +def Foo(context, engine): + if context.calledAsConstructor(): + # initialize the object + context.selfObject().setProperty("bar", ...) + # ... + # return a non-object value to indicate that the + # selfObject() should be the result of the " Foo()" expression + return engine.undefinedValue() + else: + # not called as " Foo()", just "Foo()" + # create our own object and return that one + object = engine.Object() + object.setPrototype(context.callee().property("prototype")) + object.setProperty("baz", ...) + return object +... + +fooProto = engine.Object() +fooProto.setProperty("whatever", ...) +engine.globalObject().setProperty("Foo", engine->Function(Foo, fooProto)) +//! [9] + + +//! [10] +class Bar: + ... + +def constructBar(context, engine): + bar = Bar() + # initialize from arguments in context, if desired + ... + return engine.toScriptValue(bar) + +class BarPrototype(QObject, QScriptable): +# provide the scriptable interface of self type using slots and properties +... + +... + +# create and register the Bar prototype and constructor in the engine +barPrototypeObject = BarPrototype(...) +barProto = engine.QObject(barPrototypeObject) +engine.setDefaultPrototype(qMetaTypeId(Bar), barProto) +barCtor = engine.Function(constructBar, barProto) +engine.globalObject().setProperty("Bar", barCtor) +//! [10] + + +//! [11] +def getSetFoo(context,engine): + callee = context.callee() + if context.argumentCount() == 1: # writing? + callee.setProperty("value", context.argument(0)) + return callee.property("value") +} + +.... + +object = engine.Object() +object.setProperty("foo", engine.Function(getSetFoo), + QScriptValue.PropertyGetter | QScriptValue::PropertySetter) +//! [11] + + +//! [12] +object = engine.Object() +object.setProperty("foo", engine.Function(getFoo), QScriptValue.PropertyGetter) +object.setProperty("foo", engine.Function(setFoo), QScriptValue.PropertySetter) +//! [12] + + +//! [13] +Q_SCRIPT_DECLARE_QMETAOBJECT(QLineEdit, QWidget*) + +... + +lineEditClass = engine.scriptValueFromQMetaObject(QLineEdit) +engine.globalObject().setProperty("QLineEdit", lineEditClass) +//! [13] + + +//! [14] +if hello && world: + print("hello world") +//! [14] + + +//! [15] +if hello && +//! [15] + + +//! [16] +0 = 0 +//! [16] + + +//! [17] +./test.js +//! [17] + + +//! [18] +foo["bar"] +//! [18] + + +//! [19] +engine = QScriptEngine() +context = engine.pushContext() +context.activationObject().setProperty("myArg", 123) +engine.evaluate("var tmp = myArg + 42") +... +engine.popContext() +//! [19] + + +//! [20] +class MyStruct: + x = 0 + y = 0 +//! [20] + + +//! [21] +Q_DECLARE_METATYPE(MyStruct) +//! [21] + + +//! [22] +def toScriptValue(engine, s): + obj = engine.Object() + obj.setProperty("x", s.x) + obj.setProperty("y", s.y) + return obj + +def fromScriptValue(obj, s): + s.x = obj.property("x").toInt32() + s.y = obj.property("y").toInt32() +//! [22] + + +//! [23] +qScriptRegisterMetaType(engine, toScriptValue, fromScriptValue) +//! [23] + + +//! [24] +s = context.argument(0) +... +s2 = MyStruct() +s2.x = s.x + 10 +s2.y = s.y + 20 +v = engine.toScriptValue(s2) +//! [24] + + +//! [25] +def createMyStruct(cx, engine): + s = MyStruct() + s.x = 123 + s.y = 456 + return engine.toScriptValue(s) +... + +ctor = engine.Function(createMyStruct) +engine.globalObject().setProperty("MyStruct", ctor) +//! [25] + + +//! [26] +Q_DECLARE_METATYPE(QVector<int>) + +... + +qScriptRegisterSequenceMetaType<QVector<int> >(engine) +... +v = engine.evaluate("[5, 1, 3, 2]") +v.sort() +a = engine.toScriptValue(v) +print a.toString() # outputs "[1, 2, 3, 5]" +//! [26] + +//! [27] +def mySpecialQObjectConstructor(context, engine): + parent = context.argument(0).toQObject() + object = QObject(parent) + return engine.QObject(object, QScriptEngine.ScriptOwnership) + +... + +ctor = engine.Function(mySpecialQObjectConstructor) +metaObject = engine.QMetaObject(QObject.staticMetaObject, ctor) +engine.globalObject().setProperty("QObject", metaObject) + +result = engine.evaluate(" QObject()") +//! [27] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptengineagent.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptengineagent.cpp new file mode 100644 index 000000000..c8041d80e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptengineagent.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +var a = Math.random() + 2; +//! [0] + + +//! [1] +function cube(a) { + return a * a * a; +} + +var a = cube(3); +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptvalue.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptvalue.cpp new file mode 100644 index 000000000..a2a780b91 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptvalue.cpp @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +myEngine = QScriptEngine() +myObject = myEngine.newObject() +myOtherObject = myEngine.newObject() +myObject.setProperty("myChild", myOtherObject) +myObject.setProperty("name", "John Doe") +//! [0] + + +//! [1] +val = QScriptValue(myEngine, 123) +myObject.setProperty("myReadOnlyProperty", val, QScriptValue.ReadOnly) +//! [1] + + +//! [2] +engine = QScriptEngine() +engine.evaluate("function fullName() { return this.firstName + ' ' + this.lastName; }") +engine.evaluate("somePerson = { firstName: 'John', lastName: 'Doe' }") + +global_ = engine.globalObject() +fullName = global_.property("fullName") +who = global_.property("somePerson") +print fullName.call(who).toString() # "John Doe" + +engine.evaluate("function cube(x) { return x * x * x; }") +QScriptValue cube = global_.property("cube") +args = QScriptValueList() +args << 3 +print cube.call(QScriptValue(), args).toNumber() # 27 +//! [2] + + +//! [3] + +def myNativeFunction(context, engine): + otherFunction = ... + + return otherFunction.call(context.thisObject(), context.argumentsObject()) + +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptvalueiterator.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptvalueiterator.cpp new file mode 100644 index 000000000..9b899385d --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptvalueiterator.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +object = QScriptValue() +... +it = QScriptValueIterator(object) +while it.hasNext(): + it.next() + print "%s:%s" % (it.name(), it.value().toString()) +//! [0] + + +//! [1] +QScriptValue obj = ... // the object to iterate over +while obj.isObject(): + it = QScriptValueIterator(obj) + while it.hasNext(): + it.next() + print it.name() + obj = obj.prototype() +//! [1] + + +//! [2] +while it.hasNext(): + it.next() + if it.flags() & QScriptValue::SkipInEnumeration: + continue + print "found enumerated property: %s" % it.name() +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqldatabase.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqldatabase.cpp new file mode 100644 index 000000000..632011812 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqldatabase.cpp @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +# WRONG +db = QSqlDatabase.database("sales") +query = QSqlQuery("SELECT NAME, DOB FROM EMPLOYEES", db) +QSqlDatabase.removeDatabase("sales") # will output a warning + +# "db" is now a dangling invalid database connection, +# "query" contains an invalid result set +//! [0] + + +//! [1] +db = QSqlDatabase.database("sales") +query = QSqlQuery("SELECT NAME, DOB FROM EMPLOYEES", db) +# Both "db" and "query" are destroyed because they are out of scope +QSqlDatabase.removeDatabase("sales") # correct +//! [1] + + +//! [2] +class MyDatabaseDriverCreatorBase(QtSql.QSqlDriverCreatorBase): + ... + def createObject(self): + return MyDatabaseDriver() + +mydriver = MyDatabaseDriverCreatorBase() +QtSql.QSqlDatabase.registerSqlDriver("MYDRIVER", mydriver) +db = QtSql.QSqlDatabase.addDatabase("MYDRIVER") +//! [2] + + +//! [3] +... +db = QSqlDatabase.addDatabase("QODBC") +db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=myaccessfile.mdb") +if db.open(): + # success! + pass +... +//! [3] + + +//! [4] +... +# MySQL connection +db.setConnectOptions("CLIENT_SSL=1;CLIENT_IGNORE_SPACE=1") # use an SSL connection to the server +if not db.open(): + db.setConnectOptions() # clears the connect option string + ... +... +# PostgreSQL connection +db.setConnectOptions("requiressl=1") # enable PostgreSQL SSL connections +if not db.open(): + db.setConnectOptions() # clear options + ... +... +# ODBC connection +# set ODBC options +db.setConnectOptions("SQL_ATTR_ACCESS_MODE=SQL_MODE_READ_ONLY;SQL_ATTR_TRACE=SQL_OPT_TRACE_ON") +if not db.open(): + db.setConnectOptions() # don't try to set this option + ... +//! [4] + + +//! [5] +#include "qtdir/src/sql/drivers/psql/qsql_psql.cpp" +//! [5] + + +//! [6] +con = PQconnectdb("host=server user=bart password=simpson dbname=springfield") +drv = QPSQLDriver(con) +db = QSqlDatabase.addDatabase(drv) # becomes the new default connection +query = QSqlQuery() +query.exec_("SELECT NAME, ID FROM STAFF") +... +//! [6] + + +//! [7] +unix:LIBS += -lpq +win32:LIBS += libpqdll.lib +//! [7] + + +//! [8] +db = QSqlDatabase() +print(db.isValid()) # Returns False + +db = QSqlDatabase.database("sales") +print(db.isValid()) # Returns True if "sales" connection exists + +QSqlDatabase.removeDatabase("sales") +print(db.isValid()) # Returns False +//! [8] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqldriver.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqldriver.cpp new file mode 100644 index 000000000..89c68465f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqldriver.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +db = QSqlDatabase.addDatabase("SQLITE3") +v = QVariant(db.driver().handle()) +if v.isValid() && v.typeName() == "sqlite3*": + # v.data() returns a pointer to the handle + sqlite3 *handle = *static_cast<sqlite3 **>(v.data()) + if handle != 0: # check that it is not NULL + doSomething() +//! [0] + + +//! [1] +# Impossible to translate to python +if (v.typeName() == "PGconn*") { + PGconn *handle = *static_cast<PGconn **>(v.data()) + if (handle != 0) ... +} + +if (v.typeName() == "MYSQL*") { + MYSQL *handle = *static_cast<MYSQL **>(v.data()) + if (handle != 0) ... +} +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlerror.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlerror.cpp new file mode 100644 index 000000000..9911add09 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlerror.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +model = QSqlQueryModel() +model.setQuery("select * from myTable") +if model.lastError().isValid(): + print model.lastError() +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlindex.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlindex.cpp new file mode 100644 index 000000000..b2bdd454a --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlindex.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +strlist = myIndex.toStringList() +for i in strlist: + myProcessing(i) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlquery.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlquery.cpp new file mode 100644 index 000000000..9ffac81b8 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlquery.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +SELECT forename, surname FROM people +//! [0] + + +//! [1] +q = QSqlQuery("select * from employees") +rec = q.record() + +print "Number of columns: %d" % rec.count() + +nameCol = rec.indexOf("name") # index of the field "name" +while q.next(): + print q.value(nameCol) # output all names +//! [1] + + +//! [2] +q = QSqlQuery() +q.prepare("insert into myTable values (?, ?)") + +ints = [1, 2, 3, 4] +q.addBindValue(ints) + +names = ["Harald", "Boris", "Trond", ""] +q.addBindValue(names) + +if not q.execBatch(): + print q.lastError() +//! [2] + + +//! [3] +1 Harald +2 Boris +3 Trond +4 NULL +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlresult.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlresult.cpp new file mode 100644 index 000000000..65bbc41e9 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlresult.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +q = QSqlQuery() +q.prepare("insert into test (i1, i2, s) values (?, ?, ?)") + +col1 = [1, 3] +col2 = [2, 4] +col3 = ["hello", "world"] + +q.bindValue(0, col1) +q.bindValue(1, col2) +q.bindValue(2, col3) + +if not q.execBatch(): + print q.lastError() +//! [0] + + +//! [1] +query = QSqlQuery ... +v = query.result().handle() +if v.isValid() and (v.typeName() == "sqlite3_stmt*"): + # v.data() returns a pointer to the handle + handle = v.data() + if handle != 0: # check that it is not NULL + ... +//! [1] + + +//! [2] +if v.typeName() == "PGresult*": + handle = v.data() + if handle != 0 ... + +if v.typeName() == "MYSQL_STMT*": + handle = v.data() + if handle != 0 ... +} +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_models_qsqlquerymodel.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_models_qsqlquerymodel.cpp new file mode 100644 index 000000000..b037221bb --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_models_qsqlquerymodel.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +while myModel.canFetchMore(): + myModel.fetchMore() +//! [0] + + +//! [1] +model = QSqlQueryModel() +model.setQuery("select * from MyTable") +if model.lastError().isValid(): + print model.lastError() +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_svg_qgraphicssvgitem.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_svg_qgraphicssvgitem.cpp new file mode 100644 index 000000000..df2dcbd94 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_svg_qgraphicssvgitem.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +renderer = QSvgRenderer(QLatin1String("SvgCardDeck.svg")) +black = QGraphicsSvgItem() +red = QGraphicsSvgItem() + +black.setSharedRenderer(renderer) +black.setElementId(QLatin1String("black_joker")) + +red.setSharedRenderer(renderer) +red.setElementId(QLatin1String("red_joker")) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xml_dom_qdom.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xml_dom_qdom.cpp new file mode 100644 index 000000000..741a75245 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xml_dom_qdom.cpp @@ -0,0 +1,230 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +doc = QDomDocument() +impl = QDomImplementation() + +# This will create the element, but the resulting XML document will +# be invalid, because '~' is not a valid character in a tag name. +impl.setInvalidDataPolicy(QDomImplementation.AcceptInvalidData) +elt1 = doc.createElement("foo~bar") + +# This will create an element with the tag name "foobar". +impl.setInvalidDataPolicy(QDomImplementation.DropInvalidData) +elt2 = doc.createElement("foo~bar") + +# This will create a null element. +impl.setInvalidDataPolicy(QDomImplementation::ReturnNullNode) +elt3 = doc.createElement("foo~bar") +//! [0] + + +//! [1] +d = QDomDocument() +d.setContent(someXML) +n = d.firstChild() +while !n.isNull(): + if n.isElement(): + e = n.toElement() + print "Element name: %s" % e.tagName() + break + n = n.nextSibling() +//! [1] + + +//! [2] +QDomDocument document +QDomElement element1 = document.documentElement() +QDomElement element2 = element1 +//! [2] + + +//! [3] +QDomElement element3 = document.createElement("MyElement") +QDomElement element4 = document.createElement("MyElement") +//! [3] + + +//! [4] +<body> +<h1>Heading</h1> +<p>Hello <b>you</b></p> +</body> +//! [4] + + +//! [5] +<h1>Heading</h1> +<p>The text...</p> +<h2>Next heading</h2> +//! [5] + + +//! [6] +<h1>Heading</h1> +<p>The text...</p> +<h2>Next heading</h2> +//! [6] + + +//! [7] +<link href="http://qtsoftware.com" color="red" /> +//! [7] + + +//! [8] +e = # some QDomElement... +#... +a = e.attributeNode("href") +print a.value() # prints "http://qtsoftware.com" +a.setValue("http://doc.trolltech.com") # change the node's attribute +a2 = e.attributeNode("href") +print a2.value() # prints "http://doc.trolltech.com" +//! [8] + + +//! [9] +e = # some QDomElement... +#... +s = e.text() +//! [9] + + +//! [10] +text = QString() +element = doc.documentElement() + +n = element.firstChild() +while True: + if not n.isNull() + break + t = n.toText() + if !t.isNull(): + text += t.data() + + n = n.nextSibling() +//! [10] + + +//! [11] +doc = # some QDomDocument ... +root = doc.firstChildElement("database") +elt = root.firstChildElement("entry") +while True: + if not elt.isNull(): + break + # ... + elt = elt.nextSiblingElement("entry") +//! [11] + + +//! [12] +<img src="myimg.png"> +//! [12] + + +//! [13] +<h1>Hello <b>Qt</b> <![CDATA[<xml is cool>]]></h1> +//! [13] + + +//! [14] +Hello Qt <xml is cool> +//! [14] + + +//! [15] +<!-- this is a comment --> +//! [15] + + +//! [16] +doc = QDomDocument("mydocument") +file = QFile("mydocument.xml") +if not file.open(QIODevice::ReadOnly): + return +if not doc.setContent(&file): + file.close() + return +file.close() + +# print out the element names of all elements that are direct children +# of the outermost element. +docElem = doc.documentElement() + +n = docElem.firstChild() +while not n.isNull(): + e = n.toElement() # try to convert the node to an element. + if not e.isNull(): + print e.tagName() # the node really is an element. + n = n.nextSibling() +} + +# Here we append a new element to the end of the document +elem = doc.createElement("img") +elem.setAttribute("src", "myimage.png") +docElem.appendChild(elem) +//! [16] + + +//! [17] +doc = QDomDocument("MyML") +root = doc.createElement("MyML") +doc.appendChild(root) + +tag = doc.createElement("Greeting") +root.appendChild(tag) + +t = doc.createTextNode("Hello World") +tag.appendChild(t) + +xml = doc.toString() +//! [17] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xml_sax_qxml.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xml_sax_qxml.cpp new file mode 100644 index 000000000..9df91ab39 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xml_sax_qxml.cpp @@ -0,0 +1,3 @@ +//! [0] +xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", True) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstracturiresolver.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstracturiresolver.cpp new file mode 100644 index 000000000..990a84968 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstracturiresolver.cpp @@ -0,0 +1,3 @@ +//! [0] +return baseURI.resolved(relative); +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstractxmlforwarditerator.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstractxmlforwarditerator.cpp new file mode 100644 index 000000000..f31ea3f5c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstractxmlforwarditerator.cpp @@ -0,0 +1,3 @@ +//! [0] +OutputType inputToOutputItem(const InputType &inputType) const; +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstractxmlnodemodel.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstractxmlnodemodel.cpp new file mode 100644 index 000000000..6adda1721 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstractxmlnodemodel.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +myInstance = QXmlNodeModelIndex(); +//! [0] + +//! [1] +QFile queryFile(argv[1]); +QFile chemistryData(argv[2]); +QString moleculeName = argv[3]; + +QXmlQuery query; +query.setQuery(&queryFile, QUrl::fromLocalFile(queryFile.fileName())); + +ChemistryNodeModel myNodeModel(query.namePool(), chemistryData); +QXmlNodeModelIndex startNode = myNodeModel.nodeFor(moleculeName); +query.bindVariable("queryRoot", startNode); + +QFile out; +out.open(stdout, QIODevice::WriteOnly); + +QXmlSerializer serializer(query, &out); +query.evaluateTo(&serializer); +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstractxmlreceiver.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstractxmlreceiver.cpp new file mode 100644 index 000000000..e8df709c8 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstractxmlreceiver.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +QXmlQuery query; +query.setQuery("doc('index.html')/html/body/p[1]"); + +QXmlSerializer serializer(query, myOutputDevice); +query.evaluateTo(&serializer); +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qsimplexmlnodemodel.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qsimplexmlnodemodel.cpp new file mode 100644 index 000000000..3007057d1 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qsimplexmlnodemodel.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +QXmlNodeModelIndex MyTreeModel::nextFromSimpleAxis(SimpleAxis axis, const QXmlNodeModelIndex &ni) const +{ + // Convert the QXmlNodeModelIndex to a value that is specific to what we represent. + const MyValue value = toMyValue(ni); + + switch(axis) + { + case Parent: + return toNodeIndex(value.parent()); + case FirstChild: + case PreviousSibling: + case NextSibling: + // and so on + ; + } + return QXmlNodeModelIndex(); +} +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlformatter.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlformatter.cpp new file mode 100644 index 000000000..5df7d059b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlformatter.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +QXmlQuery query; +query.setQuery("doc('index.html')/html/body/p[1]"); + +QXmlFormatter formatter(query, myOutputDevice); +formatter.setIndentationDepth(2); +query.evaluateTo(&formatter); +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlname.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlname.cpp new file mode 100644 index 000000000..60bd6b9c6 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlname.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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$ +** +****************************************************************************/ + +// Fills the bits from begin to end with 1s and leaves the rest as 0. + +template<typename IntegralT> +inline IntegralT bitmask(IntegralT begin, IntegralT end) +{ + IntegralT filled_bits = (1 << (end - begin + 1)) - 1; + return filled_bits << begin; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlquery.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlquery.cpp new file mode 100644 index 000000000..b29136eea --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlquery.cpp @@ -0,0 +1,202 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + QXmlNamePool namePool(query.namePool()); + query.bindVariable(QXmlName(namePool, localName), value); +//! [0] + + +{ +//! [1] + QByteArray myDocument; + QBuffer buffer(&myDocument); // This is a QIODevice. + buffer.open(QIODevice::ReadOnly); + QXmlQuery query; + query.bindVariable("myDocument", &buffer); + query.setQuery("doc($myDocument)"); +//! [1] +} + + +{ + QIODevice *device = 0; +//! [2] + QXmlNamePool namePool(query.namePool()); + query.bindVariable(QXmlName(namePool, localName), device); +//! [2] + +} + +{ + QIODevice *myOutputDevice = 0; +//! [3] + QFile xq("myquery.xq"); + + QXmlQuery query; + query.setQuery(&xq, QUrl::fromLocalFile(xq.fileName())); + + QXmlSerializer serializer(query, myOutputDevice); + query.evaluateTo(&serializer); +//! [3] +} + +{ + QIODevice *myOutputDevice = 0; +//! [4] + QFile xq("myquery.xq"); + QString fileName("the filename"); + QString publisherName("the publisher"); + qlonglong year = 1234; + + QXmlQuery query; + + query.bindVariable("file", QVariant(fileName)); + query.bindVariable("publisher", QVariant(publisherName)); + query.bindVariable("year", QVariant(year)); + + query.setQuery(&xq, QUrl::fromLocalFile(xq.fileName())); + + QXmlSerializer serializer(query, myOutputDevice); + query.evaluateTo(&serializer); +//! [4] +} + +{ +//! [5] + QFile xq("myquery.xq"); + QString fileName("the filename"); + QString publisherName("the publisher"); + qlonglong year = 1234; + + QXmlQuery query; + + query.bindVariable("file", QVariant(fileName)); + query.bindVariable("publisher", QVariant(publisherName)); + query.bindVariable("year", QVariant(year)); + + query.setQuery(&xq, QUrl::fromLocalFile(xq.fileName())); + + QXmlResultItems result; + query.evaluateTo(&result); + QXmlItem item(result.next()); + while (!item.isNull()) { + if (item.isAtomicValue()) { + QVariant v = item.toAtomicValue(); + switch (v.type()) { + case QVariant::LongLong: + // xs:integer + break; + case QVariant::String: + // xs:string + break; + default: + // error + break; + } + } + else if (item.isNode()) { + QXmlNodeModelIndex i = item.toNodeModelIndex(); + // process node + } + item = result.next(); + } +//! [5] +} + +{ +//! [6] + QFile xq("myquery.xq"); + + QXmlQuery query; + query.setQuery(&xq, QUrl::fromLocalFile(xq.fileName())); + + QXmlResultItems result; + query.evaluateTo(&result); + QXmlItem item(result.next()); + while (!item.isNull()) { + if (item.isAtomicValue()) { + QVariant v = item.toAtomicValue(); + switch (v.type()) { + case QVariant::LongLong: + // xs:integer + break; + case QVariant::String: + // xs:string + break; + default: + if (v.userType() == qMetaTypeId<QXmlName>()) { + QXmlName n = qVariantValue<QXmlName>(v); + // process QXmlName n... + } + else { + // error + } + break; + } + } + else if (item.isNode()) { + QXmlNodeModelIndex i = item.toNodeModelIndex(); + // process node + } + item = result.next(); + } +//! [6] +} + +{ + QIODevice *out = 0; +//! [7] + QXmlQuery query(QXmlQuery::XSLT20); + query.setFocus(QUrl("myInput.xml")); + query.setQuery(QUrl("myStylesheet.xsl")); + query.evaluateTo(out); +//! [7] +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlresultitems.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlresultitems.cpp new file mode 100644 index 000000000..733d5c2c7 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlresultitems.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +QXmlQuery query; +query.setQuery("<e/>, 1, 'two'"); +QXmlResultItems result; + +if (query.isValid()) { + query.evaluateTo(&result); + QXmlItem item(result.next()); + while (!item.isNull()) { + // use item + item = result.next(); + } + if (result.hasError()) + /* Runtime error! */; +} +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlserializer.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlserializer.cpp new file mode 100644 index 000000000..e8df709c8 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlserializer.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] +QXmlQuery query; +query.setQuery("doc('index.html')/html/body/p[1]"); + +QXmlSerializer serializer(query, myOutputDevice); +query.evaluateTo(&serializer); +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_assistant_compat_lib_qassistantclient.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_assistant_compat_lib_qassistantclient.cpp new file mode 100644 index 000000000..34554d99e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_assistant_compat_lib_qassistantclient.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + QProcess *process = new QProcess(this); + QString app = QLibraryInfo::location(QLibraryInfo::BinariesPath) + + QLatin1String("/assistant"); + + process->start(app, QStringList() << QLatin1String("-enableRemoteControl")); + if (!process->waitForStarted()) { + QMessageBox::critical(this, tr("Remote Control"), + tr("Could not start Qt Assistant from %1.").arg(app)); + return; + } + + // show index page + QTextStream str(process); + str << QLatin1String("SetSource qthelp://mycompany.com/doc/index.html") + << QLatin1Char('\0') << endl; + } +//! [0] + + +//! [1] + CONFIG += assistant +//! [1] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_extension_default_extensionfactory.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_extension_default_extensionfactory.cpp new file mode 100644 index 000000000..7bd0e9a08 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_extension_default_extensionfactory.cpp @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + QObject *ANewExtensionFactory::createExtension(QObject *object, + const QString &iid, QObject *parent) const + { + if (iid != Q_TYPEID(QDesignerContainerExtension)) + return 0; + + if (MyCustomWidget *widget = qobject_cast<MyCustomWidget*> + (object)) + return new MyContainerExtension(widget, parent); + + return 0; + } +//! [0] + + +//! [1] + QObject *AGeneralExtensionFactory::createExtension(QObject *object, + const QString &iid, QObject *parent) const + { + MyCustomWidget *widget = qobject_cast<MyCustomWidget*>(object); + + if (widget && (iid == Q_TYPEID(QDesignerTaskMenuExtension))) { + return new MyTaskMenuExtension(widget, parent); + + } else if (widget && (iid == Q_TYPEID(QDesignerContainerExtension))) { + return new MyContainerExtension(widget, parent); + + } else { + return 0; + } + } +//! [1] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_extension_extension.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_extension_extension.cpp new file mode 100644 index 000000000..0896b7590 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_extension_extension.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + QDesignerPropertySheetExtension *propertySheet; + QExtensionManager manager = formEditor->extensionManager(); + + propertySheet = qt_extension<QDesignerPropertySheetExtension*>(manager, widget); + + if(propertySheet) {...} +//! [0] + + +//! [1] + Q_DECLARE_EXTENSION_INTERFACE(MyExtension, "com.mycompany.myproduct.myextension") +//! [1] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_extension_qextensionmanager.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_extension_qextensionmanager.cpp new file mode 100644 index 000000000..a03482d56 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_extension_qextensionmanager.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + void MyPlugin::initialize(QDesignerFormEditorInterface *formEditor) + { + if (initialized) + return; + + QExtensionManager *manager = formEditor->extensionManager(); + Q_ASSERT(manager != 0); + + manager->registerExtensions(new MyExtensionFactory(manager), + Q_TYPEID(QDesignerTaskMenuExtension)); + + initialized = true; + } +//! [0] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformeditor.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformeditor.cpp new file mode 100644 index 000000000..d81e7fb0b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformeditor.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + QDesignerObjectInspectorInterface *objectInspector = 0; + objectInspector = formEditor->objectInspector(); + + QDesignerFormWindowManagerInterface *manager = 0; + manager = formEditor->formWindowManager(); + + objectInspector->setFormWindow(manager->formWindow(0)); +//! [0] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindow.cpp new file mode 100644 index 000000000..291f839b1 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindow.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + QDesignerFormWindowInterface *formWindow; + formWindow = QDesignerFormWindowInterface::findFormWindow(myWidget); +//! [0] + + +//! [1] + QList<QDesignerFormWindowInterface *> forms; + QDesignerFormWindowInterface *formWindow; + + QDesignerFormWindowManagerInterface *manager = formEditor->formWindowManager(); + + for (int i = 0; i < manager->formWindowCount(); i++) { + formWindow = manager->formWindow(i); + forms.append(formWindow); + } +//! [1] + + +//! [2] + if (formWindow->isManaged(myWidget)) + formWindow->manageWidget(myWidget->childWidget); +//! [2] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindowcursor.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindowcursor.cpp new file mode 100644 index 000000000..2b59b22b0 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindowcursor.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + QDesignerFormWindowInterface *formWindow = 0; + formWindow = QDesignerFormWindowInterface::findFormWindow(myWidget); + + formWindow->cursor()->setProperty(myWidget, myProperty, newValue); +//! [0] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindowmanager.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindowmanager.cpp new file mode 100644 index 000000000..2bdf62cde --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindowmanager.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + QDesignerFormWindowManagerInterface *manager = 0; + QDesignerFormWindowInterface *formWindow = 0; + + manager = formEditor->formWindowManager(); + formWindow = manager->formWindow(0); + + manager->setActiveFormWindow(formWindow); +//! [0] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractobjectinspector.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractobjectinspector.cpp new file mode 100644 index 000000000..d81e7fb0b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractobjectinspector.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + QDesignerObjectInspectorInterface *objectInspector = 0; + objectInspector = formEditor->objectInspector(); + + QDesignerFormWindowManagerInterface *manager = 0; + manager = formEditor->formWindowManager(); + + objectInspector->setFormWindow(manager->formWindow(0)); +//! [0] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractpropertyeditor.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractpropertyeditor.cpp new file mode 100644 index 000000000..cec019625 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractpropertyeditor.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + QDesignerPropertyEditorInterface *propertyEditor = 0; + propertyEditor = formEditor->propertyEditor(); + + connect(propertyEditor, SIGNAL(propertyChanged(QString, QVariant)), + this, SLOT(checkProperty(QString, QVariant))); +//! [0] + + +//! [1] + void checkProperty(QString property, QVariant value) { + QDesignerPropertyEditorInterface *propertyEditor = 0; + propertyEditor = formEditor->propertyEditor(); + + QObject *object = propertyeditor->object(); + MyCustomWidget *widget = qobject_cast<MyCustomWidget>(object); + + if (widget && property == aProperty && value != expectedValue) + {...} + } +//! [1] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractwidgetbox.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractwidgetbox.cpp new file mode 100644 index 000000000..2093c8e5a --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractwidgetbox.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + QDesignerWidgetBoxInterface *widgetBox = 0: + widgetBox = formEditor->widgetBox(); + + widgetBox->load(); +//! [0] + + +//! [1] + QString originalFile = widgetBox->fileName(); + + widgetBox->setFileName("myWidgetBox.xml"); + widgetBox->save(); +//! [1] + + +//! [2] + widgetBox->setFileName(originalFile); + widgetBox->load(); +//! [2] + + +//! [3] + if (widgetBox->filename() != "myWidgetBox.xml") { + widgetBox->setFileName("myWidgetBox.xml"); + widgetBox->load(); + } +//! [3] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_uilib_abstractformbuilder.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_uilib_abstractformbuilder.cpp new file mode 100644 index 000000000..ba832d63d --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_uilib_abstractformbuilder.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + MyForm::MyForm(QWidget *parent) + : QWidget(parent) + { + QFormBuilder builder; + QFile file(":/forms/myWidget.ui"); + file.open(QFile::ReadOnly); + QWidget *myWidget = builder.load(&file, this); + file.close(); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(myWidget); + setLayout(layout); + } +//! [0] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_uilib_formbuilder.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_uilib_formbuilder.cpp new file mode 100644 index 000000000..7282bb545 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_uilib_formbuilder.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + MyForm::MyForm(QWidget *parent) + : QWidget(parent) + { + QFormBuilder builder; + QFile file(":/forms/myWidget.ui"); + file.open(QFile::ReadOnly); + QWidget *myWidget = builder.load(&file, this); + file.close(); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(myWidget); + setLayout(layout); + } +//! [0] + + +//! [1] + <!DOCTYPE RCC><RCC version="1.0"> + <qresource prefix="/forms"> + <file>mywidget.ui</file> + </qresource> + </RCC> +//! [1] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_patternist_qapplicationargumentparser.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_patternist_qapplicationargumentparser.cpp new file mode 100644 index 000000000..fb39b23ea --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_patternist_qapplicationargumentparser.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + \include main.cpp +//! [0] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qtgradienteditor_qtgradientdialog.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qtgradienteditor_qtgradientdialog.cpp new file mode 100644 index 000000000..6a7045f57 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qtgradienteditor_qtgradientdialog.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + bool ok; + QGradient gradient = QtGradientDialog::getGradient(&ok, QRadialGradient(), this); + if (ok) { + // the user clicked OK and gradient is set to the gradient the user selected + } else { + // the user canceled the dialog; gradient is set to the initial + // value, in this case radial gradient + } +//! [0] + + +//! [1] + bool detailsVisible; + QColor::Spec spec; + QGradient gradient; + + QtGradientDialog dlg(this); + dlg.setDetailsVisible(detailsVisible); + dlg.setSpec(spec); + dlg.setGradient(gradient); + if (dlg.exec() != QDialog::Accepted) + return; + + gradient = dlg.gradient(); + // detailsVisible and spec properties can be changed interactively by the user too, + // we store the values of these properties for the next time QtGradientDialog is executed. + detailsVisible = dlg.detailsVisible(); + spec = dlg.spec(); +//! [1] + + +//! [2] + QtGradientDialog dlg; + dlg.setBackgroundCheckered(true); +//! [2] + + +//! [3] + QtGradientDialog dlg; + dlg.setBackgroundCheckered(false); +//! [3] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qtpropertybrowser_qtpropertybrowser.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qtpropertybrowser_qtpropertybrowser.cpp new file mode 100644 index 000000000..31bd49818 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qtpropertybrowser_qtpropertybrowser.cpp @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + QtSpinBoxFactory *factory; + QSet<QtIntPropertyManager *> managers = factory->propertyManagers(); +//! [0] + + +//! [1] + QtBrowserItem *item; + QList<QtBrowserItem *> childrenItems = item->children(); + + QList<QtProperty *> childrenProperties = item->property()->subProperties(); +//! [1] + + +//! [2] + QtProperty *property1, *property2, *property3; + + property2->addSubProperty(property1); + property3->addSubProperty(property2); + + QtAbstractPropertyBrowser *editor; + + editor->addProperty(property1); + editor->addProperty(property2); + editor->addProperty(property3); +//! [2] + + +//! [3] + QtIntPropertyManager *intManager; + QtDoublePropertyManager *doubleManager; + + QtProperty *myInteger = intManager->addProperty(); + QtProperty *myDouble = doubleManager->addProperty(); + + QtSpinBoxFactory *spinBoxFactory; + QtDoubleSpinBoxFactory *doubleSpinBoxFactory; + + QtAbstractPropertyBrowser *editor; + editor->setFactoryForManager(intManager, spinBoxFactory); + editor->setFactoryForManager(doubleManager, doubleSpinBoxFactory); + + editor->addProperty(myInteger); + editor->addProperty(myDouble); +//! [3] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qtpropertybrowser_qtvariantproperty.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qtpropertybrowser_qtvariantproperty.cpp new file mode 100644 index 000000000..d908e315e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qtpropertybrowser_qtvariantproperty.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + QtVariantPropertyManager *variantPropertyManager; + QtProperty *property; + + variantPropertyManager->setValue(property, 10); +//! [0] + + +//! [1] + QtVariantPropertyManager *variantPropertyManager; + QtVariantProperty *property; + + property->setValue(10); +//! [1] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qttoolbardialog_qttoolbardialog.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qttoolbardialog_qttoolbardialog.cpp new file mode 100644 index 000000000..808a9f35f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qttoolbardialog_qttoolbardialog.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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] + QtToolBarManager *toolBarManager; + + void MyMainWindow::customize() + { + QtToolBarDialog dialog(this); + dialog.setToolBarManager(toolBarManager); + dialog.exec(); + } +//! [0] + + |