aboutsummaryrefslogtreecommitdiffstats
path: root/doc/codesnippets/doc/src/snippets/code
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2011-03-02 17:49:28 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:54:02 -0300
commit70e12fad1ef4ab4129c77da033cfd08716d381ae (patch)
tree73964e03af7177fb5f18271eecc8a63dd217ed08 /doc/codesnippets/doc/src/snippets/code
parent8b83ec73fa255aacca54f9766aa787adf2ac1bc0 (diff)
Added some missing code snippets to PySide documentation.
Diffstat (limited to 'doc/codesnippets/doc/src/snippets/code')
-rw-r--r--doc/codesnippets/doc/src/snippets/code/doc_src_qnamespace.qdoc18
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp17
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_gui_image_qicon.cpp16
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmap.cpp6
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpainter.cpp16
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp35
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_qtestlib_qtestcase.cpp114
7 files changed, 149 insertions, 73 deletions
diff --git a/doc/codesnippets/doc/src/snippets/code/doc_src_qnamespace.qdoc b/doc/codesnippets/doc/src/snippets/code/doc_src_qnamespace.qdoc
new file mode 100644
index 000000000..6bd0bcea5
--- /dev/null
+++ b/doc/codesnippets/doc/src/snippets/code/doc_src_qnamespace.qdoc
@@ -0,0 +1,18 @@
+
+//! [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/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp b/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp
index 4fc5541c2..c2c1647b6 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp
@@ -145,7 +145,7 @@ def dragEnterEvent(self, event):
def itemChange(self, change, value):
if change == ItemPositionChange && scene():
# value is the new position.
- rect = scene()->sceneRect()
+ rect = scene().sceneRect()
if !rect.contains(value):
# Keep the item inside the scene rect.
value.setX(qMin(rect.right(), qMax(value.x(), rect.left())))
@@ -182,3 +182,18 @@ class CustomItem(QGraphicsItem):
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/doc/codesnippets/doc/src/snippets/code/src_gui_image_qicon.cpp b/doc/codesnippets/doc/src/snippets/code/src_gui_image_qicon.cpp
index 5e8f1da4b..efe7be4ac 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_gui_image_qicon.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_gui_image_qicon.cpp
@@ -12,15 +12,21 @@ button.setIcon(QIcon())
//! [2]
def drawIcon(self, painter, pos):
enabledStatus = QIcon.Normal
- if !isEnabled():
+ if not isEnabled():
enabledStatus = QIcon::Disabled
onOff = QIcon.On
- if !isOn():
+ if not isOn():
onOff = QIcon.Off
- pixmap = icon.pixmap(QSize(22, 22),
- enabledStatus,
- onOff)
+ 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/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmap.cpp b/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmap.cpp
index baa533794..b76c7d3a5 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmap.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmap.cpp
@@ -10,3 +10,9 @@ static const char * const start_xpm[]={
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/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpainter.cpp b/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpainter.cpp
index dca129280..c9b7d911a 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpainter.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpainter.cpp
@@ -193,3 +193,19 @@ 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/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp b/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp
index 73b58c1fd..9d0ed1ce3 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp
@@ -1,21 +1,36 @@
//! [0]
manager = QNetworkAccessManager(self)
-connect(manager, SIGNAL(finished("QNetworkReply*")),
- self, SLOT(replyFinished("QNetworkReply*")))
+manager.finished[QNetworkReply].connect(self.replyFinished)
-manager.get(QNetworkRequest(QUrl("http://qtsoftware.com")))
+manager.get(QNetworkRequest(QUrl("http://qt.nokia.com")))
//! [0]
//! [1]
-QNetworkRequest request
-request.setUrl(QUrl("http://qtsoftware.com"))
+request = QNetworkRequest()
+request.setUrl(QUrl("http://qt.nokia.com"))
request.setRawHeader("User-Agent", "MyOwnBrowser 1.0")
reply = manager.get(request)
-connect(reply, SIGNAL("readyRead()"), self, SLOT("slotReadyRead()"))
-connect(reply, SIGNAL(error("QNetworkReply.NetworkError")),
- self, SLOT(slotError("QNetworkReply.NetworkError")))
-connect(reply, SIGNAL(sslErrors("QList<QSslError>")),
- self, SLOT(slotSslErrors("QList<QSslError>")))
+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/doc/codesnippets/doc/src/snippets/code/src_qtestlib_qtestcase.cpp b/doc/codesnippets/doc/src/snippets/code/src_qtestlib_qtestcase.cpp
index c143e334d..aed652695 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_qtestlib_qtestcase.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_qtestlib_qtestcase.cpp
@@ -1,84 +1,81 @@
-void wrapInFunction()
-{
-
//! [0]
-QVERIFY(1 + 1 == 2);
+QVERIFY(1 + 1 == 2)
//! [0]
//! [1]
-QVERIFY2(1 + 1 == 2, "A breach in basic arithmetic occured.");
+QVERIFY2(1 + 1 == 2, "A breach in basic arithmetic occured.")
//! [1]
//! [2]
-QCOMPARE(QString("hello").toUpper(), QString("HELLO"));
+QCOMPARE(QString("hello").toUpper(), QString("HELLO"))
//! [2]
//! [3]
-void TestQString::toInt_data()
+void TestQString.toInt_data()
{
- QTest::addColumn<QString>("aString");
- QTest::addColumn<int>("expected");
+ 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;
+ QTest.newRow("positive value") << "42" << 42
+ QTest.newRow("negative value") << "-42" << -42
+ QTest.newRow("zero") << "0" << 0
}
//! [3]
//! [4]
-void TestQString::toInt()
+void TestQString.toInt()
{
- QFETCH(QString, aString);
- QFETCH(int, expected);
+ QFETCH(QString, aString)
+ QFETCH(int, expected)
- QCOMPARE(aString.toInt(), expected);
+ QCOMPARE(aString.toInt(), expected)
}
//! [4]
//! [5]
if (sizeof(int) != 4)
- QFAIL("This test has not been ported to this platform yet.");
+ QFAIL("This test has not been ported to this platform yet.")
//! [5]
//! [6]
-QFETCH(QString, myString);
-QCOMPARE(QString("hello").toUpper(), myString);
+QFETCH(QString, myString)
+QCOMPARE(QString("hello").toUpper(), myString)
//! [6]
//! [7]
-QTEST(QString("hello").toUpper(), "myString");
+QTEST(QString("hello").toUpper(), "myString")
//! [7]
//! [8]
-if (!QSqlDatabase::drivers().contains("SQLITE"))
- QSKIP("This test requires the SQLITE database driver", SkipAll);
+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);
+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);
+QEXPECT_FAIL("data27", "Oh my, this is soooo broken", Abort)
+QCOMPARE(i, 42)
//! [10]
//! [11]
-class TestQString: public QObject { ... };
+class TestQString: public QObject { ... }
QTEST_MAIN(TestQString)
//! [11]
@@ -94,19 +91,19 @@ QTEST_MAIN(TestQString)
//! [13]
-QTest::keyClick(myWidget, 'a');
+QTest.keyClick(myWidget, 'a')
//! [13]
//! [14]
-QTest::keyClick(myWidget, Qt::Key_Escape);
+QTest.keyClick(myWidget, Qt.Key_Escape)
-QTest::keyClick(myWidget, Qt::Key_Escape, Qt::ShiftModifier, 200);
+QTest.keyClick(myWidget, Qt.Key_Escape, Qt.ShiftModifier, 200)
//! [14]
//! [15]
-QTest::keyClicks(myWidget, "hello world");
+QTest.keyClicks(myWidget, "hello world")
//! [15]
@@ -115,74 +112,77 @@ 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());
+ QByteArray ba = "MyPoint("
+ ba += QByteArray.number(point.x()) + ", " + QByteArray.number(point.y())
+ ba += ")"
+ return qstrdup(ba.data())
}
}
//! [16]
//! [17]
-int i = 0;
+int i = 0
while (myNetworkServerNotResponding() && i++ < 50)
- QTest::qWait(250);
+ QTest.qWait(250)
//! [17]
//! [18]
-MyFirstTestObject test1;
-QTest::qExec(&test1);
+MyFirstTestObject test1
+QTest.qExec(&test1)
-MySecondTestObject test2;
-QTest::qExec(&test2);
+MySecondTestObject test2
+QTest.qExec(&test2)
//! [18]
//! [19]
-QDir dir;
+QDir dir
-QTest::ignoreMessage(QtWarningMsg, "QDir::mkdir: Empty or null file name(s)");
-dir.mkdir("");
+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();
+ 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.addColumn<int>("intval")
+ QTest.addColumn<QString>("str")
+ QTest.addColumn<double>("dbl")
- QTest::newRow("row1") << 1 << "hello" << 1.5;
+ QTest.newRow("row1") << 1 << "hello" << 1.5
}
//! [21]
//! [22]
-void MyTestClass::cleanup()
+void MyTestClass.cleanup()
{
if (qstrcmp(currentTestFunction(), "myDatabaseTest") == 0) {
// clean up all database connections
- closeAllDatabases();
+ closeAllDatabases()
}
}
//! [22]
//! [23]
-QTest::qSleep(250);
+QTest.qSleep(250)
//! [23]
-}
-
+//! [24]
+widget = QWidget()
+widget.show()
+QTest.qWaitForWindowShown(widget)
+//! [24]