summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2011-02-28 15:41:26 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2011-03-01 15:52:11 -0300
commitdaffd9831add06d88feda34b09199a2ec5eb1c02 (patch)
tree0d1e00d65e80cfe639a3cfb11736734e03cb6b4b
parent9c212632512df3bcf6803fd41add3af40ca57e58 (diff)
downloadpyside-daffd9831add06d88feda34b09199a2ec5eb1c02.tar.gz
pyside-daffd9831add06d88feda34b09199a2ec5eb1c02.tar.xz
pyside-daffd9831add06d88feda34b09199a2ec5eb1c02.zip
Fixed/translated some doc. code snippets.
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_io_qsettings.cpp26
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp11
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlquery.cpp8
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlresult.cpp6
-rw-r--r--doc/codesnippets/doc/src/snippets/dockwidgets/mainwindow.cpp11
-rw-r--r--doc/codesnippets/doc/src/snippets/qlistview-dnd/model.cpp22
-rw-r--r--doc/codesnippets/doc/src/snippets/qxmlschema/main.cpp114
-rw-r--r--doc/codesnippets/doc/src/snippets/simplemodel-use/main.cpp25
-rw-r--r--doc/codesnippets/doc/src/snippets/sqldatabase/sqldatabase.cpp30
-rw-r--r--doc/codesnippets/doc/src/snippets/stringlistmodel/main.cpp30
-rw-r--r--doc/codesnippets/doc/src/snippets/stringlistmodel/model.cpp101
-rw-r--r--doc/codesnippets/doc/src/snippets/stringlistmodel/model.h50
-rw-r--r--doc/codesnippets/examples/dialogs/classwizard/classwizard.cpp10
-rw-r--r--doc/codesnippets/examples/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp24
14 files changed, 267 insertions, 201 deletions
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qsettings.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qsettings.cpp
index f07dc8b..213d257 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qsettings.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qsettings.cpp
@@ -117,8 +117,8 @@ class Login:
for i in range(size):
settings.setArrayIndex(i)
login = Login()
- login.userName = settings.value("userName").toString()
- login.password = settings.value("password").toString()
+ login.userName = settings.value("userName")
+ login.password = settings.value("password")
logins.append(login)
settings.endArray()
@@ -148,8 +148,8 @@ class Login:
settings = QSettings()
settings.setValue("fridge/color", Qt.white)
settings.setValue("fridge/size", QSize(32, 96))
-settings.setValue("sofa", true)
-settings.setValue("tv", false)
+settings.setValue("sofa", True)
+settings.setValue("tv", False)
keys = settings.allKeys();
# keys: ["fridge/color", "fridge/size", "sofa", "tv"]
@@ -167,8 +167,8 @@ keys = settings.allKeys()
settings = QSettings()
settings.setValue("fridge/color", Qt.white)
settings.setValue("fridge/size", QSize(32, 96))
-settings.setValue("sofa", true)
-settings.setValue("tv", false)
+settings.setValue("sofa", True)
+settings.setValue("tv", False)
keys = settings.childKeys()
# keys: ["sofa", "tv"]
@@ -186,8 +186,8 @@ keys = settings.childKeys()
settings = QSettings()
settings.setValue("fridge/color", Qt.white)
settings.setValue("fridge/size", QSize(32, 96));
-settings.setValue("sofa", true)
-settings.setValue("tv", false)
+settings.setValue("sofa", True)
+settings.setValue("tv", False)
groups = settings.childGroups()
# group: ["fridge"]
@@ -204,10 +204,10 @@ groups = settings.childGroups()
//! [23]
settings = QSettings()
settings.setValue("interval", 30)
-settings.value("interval").toInt() # returns 30
+settings.value("interval") # returns 30
settings.setValue("interval", 6.55)
-settings.value("interval").toDouble() # returns 6.55
+settings.value("interval") # returns 6.55
//! [23]
@@ -243,9 +243,9 @@ keys = settings.allKeys()
//! [26]
settings = QSettings()
settings.setValue("animal/snake", 58)
-settings.value("animal/snake", 1024).toInt() # returns 58
-settings.value("animal/zebra", 1024).toInt() # returns 1024
-settings.value("animal/zebra").toInt() # returns 0
+settings.value("animal/snake", 1024) # returns 58
+settings.value("animal/zebra", 1024) # returns 1024
+settings.value("animal/zebra") # returns 0
//! [26]
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 1f1ff39..4fc5541 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
@@ -102,7 +102,7 @@ def paint(self, painter, option, widget):
ObjectName = 0;
item = scene.itemAt(100, 50)
-if item.data(ObjectName).toString().isEmpty():
+if len(item.data(ObjectName)) == 0:
if isinstance(ButtonItem, item):
item.setData(ObjectName, "Button")
//! [11]
@@ -145,13 +145,12 @@ def dragEnterEvent(self, event):
def itemChange(self, change, value):
if change == ItemPositionChange && scene():
# value is the new position.
- newPos = value.toPointF()
rect = scene()->sceneRect()
- if !rect.contains(newPos):
+ if !rect.contains(value):
# Keep the item inside the scene rect.
- newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left())))
- newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top())))
- return newPos
+ 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]
diff --git a/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlquery.cpp b/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlquery.cpp
index 769f0be..8ad4c2e 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlquery.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlquery.cpp
@@ -11,7 +11,7 @@ print "Number of columns: %d" % rec.count()
nameCol = rec.indexOf("name") # index of the field "name"
while q.next():
- print q.value(nameCol).toString() # output all names
+ print q.value(nameCol) # output all names
//! [1]
@@ -19,12 +19,10 @@ while q.next():
q = QSqlQuery()
q.prepare("insert into myTable values (?, ?)")
-QVariantList ints
-ints << 1 << 2 << 3 << 4
+ints = [1, 2, 3, 4]
q.addBindValue(ints)
-QVariantList names
-names << "Harald" << "Boris" << "Trond" << QVariant(QVariant.String)
+names = ["Harald", "Boris", "Trond", ""]
q.addBindValue(names)
if not q.execBatch():
diff --git a/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlresult.cpp b/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlresult.cpp
index 81d6656..2223242 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlresult.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlresult.cpp
@@ -2,9 +2,9 @@
q = QSqlQuery()
q.prepare("insert into test (i1, i2, s) values (?, ?, ?)")
-col1 = QVariant([1, 3])
-col2 = QVariant([2, 4])
-col3 = QVariant(["hello", "world"])
+col1 = [1, 3]
+col2 = [2, 4]
+col3 = ["hello", "world"]
q.bindValue(0, col1)
q.bindValue(1, col2)
diff --git a/doc/codesnippets/doc/src/snippets/dockwidgets/mainwindow.cpp b/doc/codesnippets/doc/src/snippets/dockwidgets/mainwindow.cpp
index ffbf327..7bd0426 100644
--- a/doc/codesnippets/doc/src/snippets/dockwidgets/mainwindow.cpp
+++ b/doc/codesnippets/doc/src/snippets/dockwidgets/mainwindow.cpp
@@ -95,13 +95,12 @@ void MainWindow::setupContents()
void MainWindow::setupDockWindow()
{
//! [0]
- contentsWindow = new QDockWidget(tr("Table of Contents"), this);
- contentsWindow->setAllowedAreas(Qt::LeftDockWidgetArea
- | Qt::RightDockWidgetArea);
- addDockWidget(Qt::LeftDockWidgetArea, contentsWindow);
+ contentsWindow = QDockWidget(tr("Table of Contents"), self)
+ contentsWindow.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea)
+ addDockWidget(Qt.LeftDockWidgetArea, contentsWindow)
- headingList = new QListWidget(contentsWindow);
- contentsWindow->setWidget(headingList);
+ headingList = QListWidget(contentsWindow)
+ contentsWindow.setWidget(headingList)
//! [0]
}
diff --git a/doc/codesnippets/doc/src/snippets/qlistview-dnd/model.cpp b/doc/codesnippets/doc/src/snippets/qlistview-dnd/model.cpp
index 1b91309..6deea9f 100644
--- a/doc/codesnippets/doc/src/snippets/qlistview-dnd/model.cpp
+++ b/doc/codesnippets/doc/src/snippets/qlistview-dnd/model.cpp
@@ -132,23 +132,17 @@ Qt::ItemFlags DragDropListModel::flags(const QModelIndex &index) const
//! [7]
//! [8]
-QMimeData *DragDropListModel::mimeData(const QModelIndexList &indexes) const
-{
- QMimeData *mimeData = new QMimeData();
- QByteArray encodedData;
-
- QDataStream stream(&encodedData, QIODevice::WriteOnly);
+def mimeData(self, indexes):
+ mimeData = QMimeData()
+ encodedData = QByteArray()
+ stream = QDataStream(encodedData, QIODevice.WriteOnly)
- foreach (QModelIndex index, indexes) {
- if (index.isValid()) {
- QString text = data(index, Qt::DisplayRole).toString();
- stream << text;
- }
- }
+ for index in indexes:
+ if index.isValid():
+ stream << data(index, Qt.DisplayRole)
- mimeData->setData("application/vnd.text.list", encodedData);
+ mimeData.setData("application/vnd.text.list", encodedData)
return mimeData;
-}
//! [8]
//! [9]
diff --git a/doc/codesnippets/doc/src/snippets/qxmlschema/main.cpp b/doc/codesnippets/doc/src/snippets/qxmlschema/main.cpp
new file mode 100644
index 0000000..16e8336
--- /dev/null
+++ b/doc/codesnippets/doc/src/snippets/qxmlschema/main.cpp
@@ -0,0 +1,114 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore>
+#include <QtXmlPatterns>
+
+class Schema
+{
+ public:
+ void loadFromUrl() const;
+ void loadFromFile() const;
+ void loadFromData() const;
+};
+
+void Schema::loadFromUrl() const
+{
+//! [0]
+ url = QUrl("http://www.schema-example.org/myschema.xsd")
+
+ schema = QXmlSchema()
+ if schema.load(url):
+ qDebug("schema is valid")
+ else:
+ qDebug("schema is invalid")
+//! [0]
+}
+
+void Schema::loadFromFile() const
+{
+//! [1]
+ file = QFile("myschema.xsd")
+ file.open(QIODevice.ReadOnly)
+
+ schema = QXmlSchema()
+ schema.load(file, QUrl.fromLocalFile(file.fileName()))
+
+ if schema.isValid():
+ qDebug("schema is valid")
+ else:
+ qDebug("schema is invalid")
+//! [1]
+}
+
+void Schema::loadFromData() const
+{
+//! [2]
+ data = QByteArray("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ + "<xsd:schema"
+ + " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""
+ + " xmlns=\"http://qt.nokia.com/xmlschematest\""
+ + " targetNamespace=\"http://qt.nokia.com/xmlschematest\""
+ + " version=\"1.0\""
+ + " elementFormDefault=\"qualified\">"
+ + "</xsd:schema>" )
+
+ schema = QXmlSchema()
+ schema.load(data)
+
+ if schema.isValid():
+ qDebug("schema is valid")
+ else:
+ qDebug("schema is invalid")
+//! [2]
+}
+
+int main(int argc, char **argv)
+{
+ QCoreApplication app(argc, argv);
+
+ Schema schema;
+
+ schema.loadFromUrl();
+ schema.loadFromFile();
+ schema.loadFromData();
+
+ return 0;
+}
diff --git a/doc/codesnippets/doc/src/snippets/simplemodel-use/main.cpp b/doc/codesnippets/doc/src/snippets/simplemodel-use/main.cpp
index ebaee4a..bf9c3f5 100644
--- a/doc/codesnippets/doc/src/snippets/simplemodel-use/main.cpp
+++ b/doc/codesnippets/doc/src/snippets/simplemodel-use/main.cpp
@@ -67,30 +67,29 @@ int main(int argc, char *argv[])
title->setBackgroundRole(QPalette::Base);
title->setMargin(8);
layout->addWidget(title);
-
+
//! [0]
- QDirModel *model = new QDirModel;
- QModelIndex parentIndex = model->index(QDir::currentPath());
- int numRows = model->rowCount(parentIndex);
+ model = QDirModel()
+ parentIndex = model.index(QDir.currentPath())
+ numRows = model.rowCount(parentIndex)
//! [0]
//! [1]
- for (int row = 0; row < numRows; ++row) {
- QModelIndex index = model->index(row, 0, parentIndex);
+ for row in range(numRows):
+ index = model.index(row, 0, parentIndex)
//! [1]
//! [2]
- QString text = model->data(index, Qt::DisplayRole).toString();
+ text = model.data(index, Qt.DisplayRole)
// Display the text in a widget.
//! [2]
- QLabel *label = new QLabel(text, window);
- layout->addWidget(label);
+ label = QLabel(text, window)
+ layout.addWidget(label)
//! [3]
- }
//! [3]
- window->setWindowTitle("A simple model example");
- window->show();
- return app.exec();
+ window.setWindowTitle("A simple model example")
+ window.show()
+ return app.exec_()
}
diff --git a/doc/codesnippets/doc/src/snippets/sqldatabase/sqldatabase.cpp b/doc/codesnippets/doc/src/snippets/sqldatabase/sqldatabase.cpp
index e21cb9c..4014cc8 100644
--- a/doc/codesnippets/doc/src/snippets/sqldatabase/sqldatabase.cpp
+++ b/doc/codesnippets/doc/src/snippets/sqldatabase/sqldatabase.cpp
@@ -87,7 +87,7 @@ def QSqlQuery_snippets():
//! [7]
query = QSqlQuery("SELECT country FROM artist")
while query.next():
- country = query.value(0).toString()
+ country = query.value(0)
doSomething(country)
//! [7]
@@ -97,7 +97,7 @@ def QSqlQuery_snippets():
query = QSqlQuery("SELECT * FROM artist")
fieldNo = query.record().indexOf("country")
while query.next():
- country = query.value(fieldNo).toString()
+ country = query.value(fieldNo)
doSomething(country)
//! [8]
@@ -152,7 +152,7 @@ def QSqlQuery_snippets():
query.bindValue(0, "A")
query.bindValue(1, 0, QSql.Out)
query.exec_()
- i = query.boundValue(1).toInt() # i is 65
+ i = query.boundValue(1) # i is 65
//! [13]
query = QSqlQuery()
@@ -162,7 +162,7 @@ def QSqlQuery_snippets():
i = query.boundValues()
while i.hasNext():
i.next()
- print i.key().toAscii().data(), ": ", i.value().toString().toAscii().data()
+ print i.key(), ": ", i.value()
//! [14]
# examine with positional binding
@@ -193,11 +193,11 @@ def QSqlQueryModel_snippets():
//! [21]
model = QSqlQueryModel()
model.setQuery("SELECT * FROM employee")
- salary = model.record(4).value("salary").toInt()
+ salary = model.record(4).value("salary")
//! [21]
//! [22]
- salary = model.data(model.index(4, 2)).toInt()
+ salary = model.data(model.index(4, 2))
//! [22]
for row in range(model.rowCount()):
@@ -238,7 +238,7 @@ def QSqlTableModel_snippets():
//! [25]
model = QSqlTableModel()
model.setTable("employee")
- QString name = model.record(4).value("name").toString()
+ QString name = model.record(4).value("name")
//! [25]
def sql_intro_snippets():
@@ -273,8 +273,8 @@ def sql_intro_snippets():
//! [32]
while query.next():
- name = query.value(0).toString()
- salary = query.value(1).toInt()
+ name = query.value(0)
+ salary = query.value(1)
print name, salary
//! [32]
@@ -339,7 +339,7 @@ def sql_intro_snippets():
query = QSqlQuery()
query.exec_("SELECT id FROM employee WHERE name = 'Torild Halvorsen'")
if query.next():
- employeeId = query.value(0).toInt()
+ employeeId = query.value(0)
query.exec_("INSERT INTO project (id, name, ownerid) "
"VALUES (201, 'Manhattan Project', "
+ QString.number(employeeId) + ')')
@@ -353,8 +353,8 @@ def sql_intro_snippets():
model.setQuery("SELECT * FROM employee")
for i in range(model.rowCount()):
- _id = model.record(i).value("id").toInt()
- name = model.record(i).value("name").toString()
+ _id = model.record(i).value("id")
+ name = model.record(i).value("name")
print _id, name
//! [40]
@@ -370,8 +370,8 @@ def sql_intro_snippets():
model.select()
for i in range(model.rowCount()):
- name = model.record(i).value("name").toString()
- salary = model.record(i).value("salary").toInt()
+ name = model.record(i).value("name")
+ salary = model.record(i).value("salary")
print "%s: %d" % (name, salary)
//! [41]
@@ -383,7 +383,7 @@ def sql_intro_snippets():
//! [42]
for i in range(model.rowCount()):
record = model.record(i)
- salary = record.value("salary").toInt()
+ salary = record.value("salary")
salary *= 1.1
record.setValue("salary", salary)
model.setRecord(i, record)
diff --git a/doc/codesnippets/doc/src/snippets/stringlistmodel/main.cpp b/doc/codesnippets/doc/src/snippets/stringlistmodel/main.cpp
index 17d6be8..d285eb8 100644
--- a/doc/codesnippets/doc/src/snippets/stringlistmodel/main.cpp
+++ b/doc/codesnippets/doc/src/snippets/stringlistmodel/main.cpp
@@ -52,33 +52,29 @@
#include "model.h"
//! [0]
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
+
+app = QApplication(sys.argv)
// Unindented for quoting purposes:
//! [1]
-QStringList numbers;
-numbers << "One" << "Two" << "Three" << "Four" << "Five";
+numbers = ["One", "Two", "Three", "Four", "Five"]
-QAbstractItemModel *model = new StringListModel(numbers);
+model = StringListModel(numbers)
//! [0] //! [1] //! [2] //! [3]
-QListView *view = new QListView;
+view = QListView()
//! [2]
-view->setWindowTitle("View onto a string list model");
+view.setWindowTitle("View onto a string list model")
//! [4]
-view->setModel(model);
+view.setModel(model)
//! [3] //! [4]
- model->insertRows(5, 7, QModelIndex());
+ model.insertRows(5, 7, QModelIndex())
- for (int row = 5; row < 12; ++row) {
- QModelIndex index = model->index(row, 0, QModelIndex());
- model->setData(index, QString::number(row+1));
- }
+ for row in range(5, 12):
+ index = model.index(row, 0, QModelIndex())
+ model.setData(index, str(row+1))
//! [5]
- view->show();
- return app.exec();
-}
+ view.show()
+ sys.exit(app.exec_())
//! [5]
diff --git a/doc/codesnippets/doc/src/snippets/stringlistmodel/model.cpp b/doc/codesnippets/doc/src/snippets/stringlistmodel/model.cpp
index 124c328..659f02d 100644
--- a/doc/codesnippets/doc/src/snippets/stringlistmodel/model.cpp
+++ b/doc/codesnippets/doc/src/snippets/stringlistmodel/model.cpp
@@ -45,18 +45,14 @@
A simple model that uses a QStringList as its data source.
*/
-#include "model.h"
-
/*!
Returns the number of items in the string list as the number of rows
in the model.
*/
//! [0]
-int StringListModel::rowCount(const QModelIndex &parent) const
-{
- return stringList.count();
-}
+def rowCount(self, parent):
+ return len(self.stringList)
//! [0]
/*!
@@ -67,19 +63,17 @@ int StringListModel::rowCount(const QModelIndex &parent) const
*/
//! [1]
-QVariant StringListModel::data(const QModelIndex &index, int role) const
-{
- if (!index.isValid())
- return QVariant();
+def data(self, index, role):
+ if not index.isValid():
+ return None
- if (index.row() >= stringList.size())
- return QVariant();
+ if index.row() >= stringList.size():
+ return None
- if (role == Qt::DisplayRole)
- return stringList.at(index.row());
+ if role == Qt.DisplayRole:
+ return stringList[index.row()]
else
- return QVariant();
-}
+ return None
//! [1]
/*!
@@ -89,17 +83,14 @@ QVariant StringListModel::data(const QModelIndex &index, int role) const
*/
//! [2]
-QVariant StringListModel::headerData(int section, Qt::Orientation orientation,
- int role) const
-{
- if (role != Qt::DisplayRole)
- return QVariant();
-
- if (orientation == Qt::Horizontal)
- return QString("Column %1").arg(section);
- else
- return QString("Row %1").arg(section);
-}
+def headerData(self, section, orientation, role):
+ if role != Qt::DisplayRole:
+ return None
+
+ if orientation == Qt::Horizontal:
+ return "Column %s" % section
+ else:
+ return "Row %s" % section
//! [2]
/*!
@@ -108,13 +99,11 @@ QVariant StringListModel::headerData(int section, Qt::Orientation orientation,
*/
//! [3]
-Qt::ItemFlags StringListModel::flags(const QModelIndex &index) const
-{
- if (!index.isValid())
- return Qt::ItemIsEnabled;
+def flags(self, index):
+ if not index.isValid()
+ return Qt.ItemIsEnabled
- return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
-}
+ return QAbstractItemModel.flags(index) | Qt.ItemIsEditable
//! [3]
/*!
@@ -129,17 +118,13 @@ Qt::ItemFlags StringListModel::flags(const QModelIndex &index) const
*/
//! [4]
-bool StringListModel::setData(const QModelIndex &index,
- const QVariant &value, int role)
-{
- if (index.isValid() && role == Qt::EditRole) {
-
- stringList.replace(index.row(), value.toString());
- emit dataChanged(index, index);
- return true;
- }
+def setData(self, index, value, role):
+ if index.isValid() and role == Qt.EditRole:
+ self.stringList[index.row()] = value
+ self.dataChanged.emit(index, index)
+ return True;
//! [4] //! [5]
- return false;
+ return False;
}
//! [5]
@@ -148,18 +133,15 @@ bool StringListModel::setData(const QModelIndex &index,
*/
//! [6]
-bool StringListModel::insertRows(int position, int rows, const QModelIndex &parent)
-{
- beginInsertRows(QModelIndex(), position, position+rows-1);
+def insertRows(self, position, rows, parent):
+ self.beginInsertRows(QModelIndex(), position, position+rows-1)
- for (int row = 0; row < rows; ++row) {
- stringList.insert(position, "");
- }
+ for row in range(0, rows):
+ self.stringList.insert(position, "")
- endInsertRows();
- return true;
+ self.endInsertRows()
+ return True;
//! [6] //! [7]
-}
//! [7]
/*!
@@ -167,16 +149,13 @@ bool StringListModel::insertRows(int position, int rows, const QModelIndex &pare
*/
//! [8]
-bool StringListModel::removeRows(int position, int rows, const QModelIndex &parent)
-{
- beginRemoveRows(QModelIndex(), position, position+rows-1);
+def removeRows(self, position, rows, parent):
+ self.beginRemoveRows(QModelIndex(), position, position+rows-1)
- for (int row = 0; row < rows; ++row) {
- stringList.removeAt(position);
- }
+ for row in range(0, rows):
+ del self.stringList[position]
- endRemoveRows();
- return true;
+ self.endRemoveRows()
+ return True;
//! [8] //! [9]
-}
//! [9]
diff --git a/doc/codesnippets/doc/src/snippets/stringlistmodel/model.h b/doc/codesnippets/doc/src/snippets/stringlistmodel/model.h
index 30f7611..0a0b0c3 100644
--- a/doc/codesnippets/doc/src/snippets/stringlistmodel/model.h
+++ b/doc/codesnippets/doc/src/snippets/stringlistmodel/model.h
@@ -39,45 +39,35 @@
**
****************************************************************************/
-#ifndef MODEL_H
-#define MODEL_H
-
-#include <QAbstractListModel>
-#include <QObject>
-#include <QStringList>
-
//! [0]
-class StringListModel : public QAbstractListModel
-{
- Q_OBJECT
-
-public:
- StringListModel(const QStringList &strings, QObject *parent = 0)
- : QAbstractListModel(parent), stringList(strings) {}
+class StringListModel (QAbstractListModel):
+ def __init__(strings, parent = None):
+ QAbstractListModel.__init__(self, parent)
+//! [5]
+ self.stringList = strings
+//! [5]
- int rowCount(const QModelIndex &parent = QModelIndex()) const;
- QVariant data(const QModelIndex &index, int role) const;
- QVariant headerData(int section, Qt::Orientation orientation,
+ def rowCount(self, parent = QModelIndex()):
+ # ...
+ def data(self, index, role):
+ # ...
+ def headerData(self, section, orientation,
//! [0] //! [1]
- int role = Qt::DisplayRole) const;
+ role = Qt.DisplayRole):
//! [1]
//! [2]
- Qt::ItemFlags flags(const QModelIndex &index) const;
- bool setData(const QModelIndex &index, const QVariant &value,
+ def flags(self, index):
+ # ...
+ def setData(self, index, value,
//! [2] //! [3]
- int role = Qt::EditRole);
+ role = Qt.EditRole)
//! [3]
//! [4]
- bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex());
- bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex());
+ def insertRows(self, position, rows, index = QModelIndex()):
+ # ...
+ def removeRows(self, position, rows, index = QModelIndex()):
+ # ...
//! [4]
-//! [5]
-private:
- QStringList stringList;
-};
-//! [5]
-
-#endif
diff --git a/doc/codesnippets/examples/dialogs/classwizard/classwizard.cpp b/doc/codesnippets/examples/dialogs/classwizard/classwizard.cpp
index 0d5c221..bf88928 100644
--- a/doc/codesnippets/examples/dialogs/classwizard/classwizard.cpp
+++ b/doc/codesnippets/examples/dialogs/classwizard/classwizard.cpp
@@ -224,7 +224,7 @@ class CodeStylePage(QWizardPage):
//! [16]
def initializePage(self):
className = self.field("className")
- self.macroNameLineEdit.setText(className.toUpper() + "_H")
+ self.macroNameLineEdit.setText(className.upper() + "_H")
baseClass = self.field("baseClass")
@@ -238,13 +238,13 @@ class CodeStylePage(QWizardPage):
elsif QRegExp("Q[A-Z].*").exactMatch(baseClass):
baseIncludeLineEdit.setText("<" + baseClass + ">")
else:
- baseIncludeLineEdit.setText("\"" + baseClass.toLower() + ".h\"")
+ baseIncludeLineEdit.setText("\"" + baseClass.lower() + ".h\"")
//! [16]
//! [17]
def initializePage(self):
- className = field("className").toString()
- self.headerLineEdit.setText(className.toLower() + ".h")
- self.implementationLineEdit.setText(className.toLower() + ".cpp")
+ className = field("className")
+ self.headerLineEdit.setText(className.lower() + ".h")
+ self.implementationLineEdit.setText(className.lower() + ".cpp")
self.outputDirLineEdit.setText(QDir.convertSeparators(QDir.tempPath()))
//! [17]
diff --git a/doc/codesnippets/examples/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp b/doc/codesnippets/examples/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp
index da1c2dd..028a5e7 100644
--- a/doc/codesnippets/examples/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp
+++ b/doc/codesnippets/examples/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp
@@ -64,10 +64,10 @@ def filterAcceptsRow(self, sourceRow, sourceParent):
index1 = sourceModel().index(sourceRow, 1, sourceParent)
index2 = sourceModel().index(sourceRow, 2, sourceParent)
- return (sourceModel().data(index0).toString().contains(filterRegExp())
- || sourceModel().data(index1).toString().contains(filterRegExp()))
- && dateInRange(sourceModel().data(index2).toDate())
-
+ regex = filterRegExp()
+ return (regex.indexIn(sourceModel().data(index0)) != -1
+ or regex.indexIn(sourceModel().data(index1)) != -1
+ and dateInRange(sourceModel().data(index2))
//! [3]
//! [4] //! [5]
@@ -77,20 +77,18 @@ def lessThan(self, left, right):
//! [4]
//! [6]
- if leftData.type() == QVariant.DateTime:
- return leftData.toDateTime() < rightData.toDateTime()
+ if isinstance(leftData, QDateTime):
+ return leftData < rightData
else:
emailPattern = QRegExp("([\\w\\.]*@[\\w\\.]*)")
- leftString = leftData.toString()
- if left.column() == 1 && emailPattern.indexIn(leftString) != -1:
- leftString = emailPattern.cap(1)
+ if left.column() == 1 && emailPattern.indexIn(leftData) != -1:
+ leftData = emailPattern.cap(1)
- rightString = rightData.toString()
- if right.column() == 1 && emailPattern.indexIn(rightString) != -1:
- rightString = emailPattern.cap(1)
+ if right.column() == 1 && emailPattern.indexIn(rightData) != -1:
+ rightData = emailPattern.cap(1)
- return QString.localeAwareCompare(leftString, rightString) < 0
+ return leftString < rightString
//! [5] //! [6]