Fixed/translated some doc. code snippets.

This commit is contained in:
Hugo Parente Lima 2011-02-28 15:41:26 -03:00
commit daffd9831a
14 changed files with 266 additions and 200 deletions

View file

@ -117,8 +117,8 @@ class Login:
for i in range(size): for i in range(size):
settings.setArrayIndex(i) settings.setArrayIndex(i)
login = Login() login = Login()
login.userName = settings.value("userName").toString() login.userName = settings.value("userName")
login.password = settings.value("password").toString() login.password = settings.value("password")
logins.append(login) logins.append(login)
settings.endArray() settings.endArray()
@ -148,8 +148,8 @@ class Login:
settings = QSettings() settings = QSettings()
settings.setValue("fridge/color", Qt.white) settings.setValue("fridge/color", Qt.white)
settings.setValue("fridge/size", QSize(32, 96)) settings.setValue("fridge/size", QSize(32, 96))
settings.setValue("sofa", true) settings.setValue("sofa", True)
settings.setValue("tv", false) settings.setValue("tv", False)
keys = settings.allKeys(); keys = settings.allKeys();
# keys: ["fridge/color", "fridge/size", "sofa", "tv"] # keys: ["fridge/color", "fridge/size", "sofa", "tv"]
@ -167,8 +167,8 @@ keys = settings.allKeys()
settings = QSettings() settings = QSettings()
settings.setValue("fridge/color", Qt.white) settings.setValue("fridge/color", Qt.white)
settings.setValue("fridge/size", QSize(32, 96)) settings.setValue("fridge/size", QSize(32, 96))
settings.setValue("sofa", true) settings.setValue("sofa", True)
settings.setValue("tv", false) settings.setValue("tv", False)
keys = settings.childKeys() keys = settings.childKeys()
# keys: ["sofa", "tv"] # keys: ["sofa", "tv"]
@ -186,8 +186,8 @@ keys = settings.childKeys()
settings = QSettings() settings = QSettings()
settings.setValue("fridge/color", Qt.white) settings.setValue("fridge/color", Qt.white)
settings.setValue("fridge/size", QSize(32, 96)); settings.setValue("fridge/size", QSize(32, 96));
settings.setValue("sofa", true) settings.setValue("sofa", True)
settings.setValue("tv", false) settings.setValue("tv", False)
groups = settings.childGroups() groups = settings.childGroups()
# group: ["fridge"] # group: ["fridge"]
@ -204,10 +204,10 @@ groups = settings.childGroups()
//! [23] //! [23]
settings = QSettings() settings = QSettings()
settings.setValue("interval", 30) settings.setValue("interval", 30)
settings.value("interval").toInt() # returns 30 settings.value("interval") # returns 30
settings.setValue("interval", 6.55) settings.setValue("interval", 6.55)
settings.value("interval").toDouble() # returns 6.55 settings.value("interval") # returns 6.55
//! [23] //! [23]
@ -243,9 +243,9 @@ keys = settings.allKeys()
//! [26] //! [26]
settings = QSettings() settings = QSettings()
settings.setValue("animal/snake", 58) settings.setValue("animal/snake", 58)
settings.value("animal/snake", 1024).toInt() # returns 58 settings.value("animal/snake", 1024) # returns 58
settings.value("animal/zebra", 1024).toInt() # returns 1024 settings.value("animal/zebra", 1024) # returns 1024
settings.value("animal/zebra").toInt() # returns 0 settings.value("animal/zebra") # returns 0
//! [26] //! [26]

View file

@ -102,7 +102,7 @@ def paint(self, painter, option, widget):
ObjectName = 0; ObjectName = 0;
item = scene.itemAt(100, 50) item = scene.itemAt(100, 50)
if item.data(ObjectName).toString().isEmpty(): if len(item.data(ObjectName)) == 0:
if isinstance(ButtonItem, item): if isinstance(ButtonItem, item):
item.setData(ObjectName, "Button") item.setData(ObjectName, "Button")
//! [11] //! [11]
@ -145,13 +145,12 @@ def dragEnterEvent(self, event):
def itemChange(self, change, value): def itemChange(self, change, value):
if change == ItemPositionChange && scene(): if change == ItemPositionChange && scene():
# value is the new position. # value is the new position.
newPos = value.toPointF()
rect = scene()->sceneRect() rect = scene()->sceneRect()
if !rect.contains(newPos): if !rect.contains(value):
# Keep the item inside the scene rect. # Keep the item inside the scene rect.
newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left()))) value.setX(qMin(rect.right(), qMax(value.x(), rect.left())))
newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top()))) value.setY(qMin(rect.bottom(), qMax(value.y(), rect.top())))
return newPos return value
return QGraphicsItem.itemChange(self, change, value) return QGraphicsItem.itemChange(self, change, value)
//! [15] //! [15]

View file

@ -11,7 +11,7 @@ print "Number of columns: %d" % rec.count()
nameCol = rec.indexOf("name") # index of the field "name" nameCol = rec.indexOf("name") # index of the field "name"
while q.next(): while q.next():
print q.value(nameCol).toString() # output all names print q.value(nameCol) # output all names
//! [1] //! [1]
@ -19,12 +19,10 @@ while q.next():
q = QSqlQuery() q = QSqlQuery()
q.prepare("insert into myTable values (?, ?)") q.prepare("insert into myTable values (?, ?)")
QVariantList ints ints = [1, 2, 3, 4]
ints << 1 << 2 << 3 << 4
q.addBindValue(ints) q.addBindValue(ints)
QVariantList names names = ["Harald", "Boris", "Trond", ""]
names << "Harald" << "Boris" << "Trond" << QVariant(QVariant.String)
q.addBindValue(names) q.addBindValue(names)
if not q.execBatch(): if not q.execBatch():

View file

@ -2,9 +2,9 @@
q = QSqlQuery() q = QSqlQuery()
q.prepare("insert into test (i1, i2, s) values (?, ?, ?)") q.prepare("insert into test (i1, i2, s) values (?, ?, ?)")
col1 = QVariant([1, 3]) col1 = [1, 3]
col2 = QVariant([2, 4]) col2 = [2, 4]
col3 = QVariant(["hello", "world"]) col3 = ["hello", "world"]
q.bindValue(0, col1) q.bindValue(0, col1)
q.bindValue(1, col2) q.bindValue(1, col2)

View file

@ -95,13 +95,12 @@ void MainWindow::setupContents()
void MainWindow::setupDockWindow() void MainWindow::setupDockWindow()
{ {
//! [0] //! [0]
contentsWindow = new QDockWidget(tr("Table of Contents"), this); contentsWindow = QDockWidget(tr("Table of Contents"), self)
contentsWindow->setAllowedAreas(Qt::LeftDockWidgetArea contentsWindow.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea)
| Qt::RightDockWidgetArea); addDockWidget(Qt.LeftDockWidgetArea, contentsWindow)
addDockWidget(Qt::LeftDockWidgetArea, contentsWindow);
headingList = new QListWidget(contentsWindow); headingList = QListWidget(contentsWindow)
contentsWindow->setWidget(headingList); contentsWindow.setWidget(headingList)
//! [0] //! [0]
} }

View file

@ -132,23 +132,17 @@ Qt::ItemFlags DragDropListModel::flags(const QModelIndex &index) const
//! [7] //! [7]
//! [8] //! [8]
QMimeData *DragDropListModel::mimeData(const QModelIndexList &indexes) const def mimeData(self, indexes):
{ mimeData = QMimeData()
QMimeData *mimeData = new QMimeData(); encodedData = QByteArray()
QByteArray encodedData; stream = QDataStream(encodedData, QIODevice.WriteOnly)
QDataStream stream(&encodedData, QIODevice::WriteOnly); for index in indexes:
if index.isValid():
stream << data(index, Qt.DisplayRole)
foreach (QModelIndex index, indexes) { mimeData.setData("application/vnd.text.list", encodedData)
if (index.isValid()) {
QString text = data(index, Qt::DisplayRole).toString();
stream << text;
}
}
mimeData->setData("application/vnd.text.list", encodedData);
return mimeData; return mimeData;
}
//! [8] //! [8]
//! [9] //! [9]

View file

@ -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;
}

View file

@ -67,30 +67,29 @@ int main(int argc, char *argv[])
title->setBackgroundRole(QPalette::Base); title->setBackgroundRole(QPalette::Base);
title->setMargin(8); title->setMargin(8);
layout->addWidget(title); layout->addWidget(title);
//! [0] //! [0]
QDirModel *model = new QDirModel; model = QDirModel()
QModelIndex parentIndex = model->index(QDir::currentPath()); parentIndex = model.index(QDir.currentPath())
int numRows = model->rowCount(parentIndex); numRows = model.rowCount(parentIndex)
//! [0] //! [0]
//! [1] //! [1]
for (int row = 0; row < numRows; ++row) { for row in range(numRows):
QModelIndex index = model->index(row, 0, parentIndex); index = model.index(row, 0, parentIndex)
//! [1] //! [1]
//! [2] //! [2]
QString text = model->data(index, Qt::DisplayRole).toString(); text = model.data(index, Qt.DisplayRole)
// Display the text in a widget. // Display the text in a widget.
//! [2] //! [2]
QLabel *label = new QLabel(text, window); label = QLabel(text, window)
layout->addWidget(label); layout.addWidget(label)
//! [3] //! [3]
}
//! [3] //! [3]
window->setWindowTitle("A simple model example"); window.setWindowTitle("A simple model example")
window->show(); window.show()
return app.exec(); return app.exec_()
} }

View file

@ -87,7 +87,7 @@ def QSqlQuery_snippets():
//! [7] //! [7]
query = QSqlQuery("SELECT country FROM artist") query = QSqlQuery("SELECT country FROM artist")
while query.next(): while query.next():
country = query.value(0).toString() country = query.value(0)
doSomething(country) doSomething(country)
//! [7] //! [7]
@ -97,7 +97,7 @@ def QSqlQuery_snippets():
query = QSqlQuery("SELECT * FROM artist") query = QSqlQuery("SELECT * FROM artist")
fieldNo = query.record().indexOf("country") fieldNo = query.record().indexOf("country")
while query.next(): while query.next():
country = query.value(fieldNo).toString() country = query.value(fieldNo)
doSomething(country) doSomething(country)
//! [8] //! [8]
@ -152,7 +152,7 @@ def QSqlQuery_snippets():
query.bindValue(0, "A") query.bindValue(0, "A")
query.bindValue(1, 0, QSql.Out) query.bindValue(1, 0, QSql.Out)
query.exec_() query.exec_()
i = query.boundValue(1).toInt() # i is 65 i = query.boundValue(1) # i is 65
//! [13] //! [13]
query = QSqlQuery() query = QSqlQuery()
@ -162,7 +162,7 @@ def QSqlQuery_snippets():
i = query.boundValues() i = query.boundValues()
while i.hasNext(): while i.hasNext():
i.next() i.next()
print i.key().toAscii().data(), ": ", i.value().toString().toAscii().data() print i.key(), ": ", i.value()
//! [14] //! [14]
# examine with positional binding # examine with positional binding
@ -193,11 +193,11 @@ def QSqlQueryModel_snippets():
//! [21] //! [21]
model = QSqlQueryModel() model = QSqlQueryModel()
model.setQuery("SELECT * FROM employee") model.setQuery("SELECT * FROM employee")
salary = model.record(4).value("salary").toInt() salary = model.record(4).value("salary")
//! [21] //! [21]
//! [22] //! [22]
salary = model.data(model.index(4, 2)).toInt() salary = model.data(model.index(4, 2))
//! [22] //! [22]
for row in range(model.rowCount()): for row in range(model.rowCount()):
@ -238,7 +238,7 @@ def QSqlTableModel_snippets():
//! [25] //! [25]
model = QSqlTableModel() model = QSqlTableModel()
model.setTable("employee") model.setTable("employee")
QString name = model.record(4).value("name").toString() QString name = model.record(4).value("name")
//! [25] //! [25]
def sql_intro_snippets(): def sql_intro_snippets():
@ -273,8 +273,8 @@ def sql_intro_snippets():
//! [32] //! [32]
while query.next(): while query.next():
name = query.value(0).toString() name = query.value(0)
salary = query.value(1).toInt() salary = query.value(1)
print name, salary print name, salary
//! [32] //! [32]
@ -339,7 +339,7 @@ def sql_intro_snippets():
query = QSqlQuery() query = QSqlQuery()
query.exec_("SELECT id FROM employee WHERE name = 'Torild Halvorsen'") query.exec_("SELECT id FROM employee WHERE name = 'Torild Halvorsen'")
if query.next(): if query.next():
employeeId = query.value(0).toInt() employeeId = query.value(0)
query.exec_("INSERT INTO project (id, name, ownerid) " query.exec_("INSERT INTO project (id, name, ownerid) "
"VALUES (201, 'Manhattan Project', " "VALUES (201, 'Manhattan Project', "
+ QString.number(employeeId) + ')') + QString.number(employeeId) + ')')
@ -353,8 +353,8 @@ def sql_intro_snippets():
model.setQuery("SELECT * FROM employee") model.setQuery("SELECT * FROM employee")
for i in range(model.rowCount()): for i in range(model.rowCount()):
_id = model.record(i).value("id").toInt() _id = model.record(i).value("id")
name = model.record(i).value("name").toString() name = model.record(i).value("name")
print _id, name print _id, name
//! [40] //! [40]
@ -370,8 +370,8 @@ def sql_intro_snippets():
model.select() model.select()
for i in range(model.rowCount()): for i in range(model.rowCount()):
name = model.record(i).value("name").toString() name = model.record(i).value("name")
salary = model.record(i).value("salary").toInt() salary = model.record(i).value("salary")
print "%s: %d" % (name, salary) print "%s: %d" % (name, salary)
//! [41] //! [41]
@ -383,7 +383,7 @@ def sql_intro_snippets():
//! [42] //! [42]
for i in range(model.rowCount()): for i in range(model.rowCount()):
record = model.record(i) record = model.record(i)
salary = record.value("salary").toInt() salary = record.value("salary")
salary *= 1.1 salary *= 1.1
record.setValue("salary", salary) record.setValue("salary", salary)
model.setRecord(i, record) model.setRecord(i, record)

View file

@ -52,33 +52,29 @@
#include "model.h" #include "model.h"
//! [0] //! [0]
int main(int argc, char *argv[])
{ app = QApplication(sys.argv)
QApplication app(argc, argv);
// Unindented for quoting purposes: // Unindented for quoting purposes:
//! [1] //! [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] //! [0] //! [1] //! [2] //! [3]
QListView *view = new QListView; view = QListView()
//! [2] //! [2]
view->setWindowTitle("View onto a string list model"); view.setWindowTitle("View onto a string list model")
//! [4] //! [4]
view->setModel(model); view.setModel(model)
//! [3] //! [4] //! [3] //! [4]
model->insertRows(5, 7, QModelIndex()); model.insertRows(5, 7, QModelIndex())
for (int row = 5; row < 12; ++row) { for row in range(5, 12):
QModelIndex index = model->index(row, 0, QModelIndex()); index = model.index(row, 0, QModelIndex())
model->setData(index, QString::number(row+1)); model.setData(index, str(row+1))
}
//! [5] //! [5]
view->show(); view.show()
return app.exec(); sys.exit(app.exec_())
}
//! [5] //! [5]

View file

@ -45,18 +45,14 @@
A simple model that uses a QStringList as its data source. 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 Returns the number of items in the string list as the number of rows
in the model. in the model.
*/ */
//! [0] //! [0]
int StringListModel::rowCount(const QModelIndex &parent) const def rowCount(self, parent):
{ return len(self.stringList)
return stringList.count();
}
//! [0] //! [0]
/*! /*!
@ -67,19 +63,17 @@ int StringListModel::rowCount(const QModelIndex &parent) const
*/ */
//! [1] //! [1]
QVariant StringListModel::data(const QModelIndex &index, int role) const def data(self, index, role):
{ if not index.isValid():
if (!index.isValid()) return None
return QVariant();
if (index.row() >= stringList.size()) if index.row() >= stringList.size():
return QVariant(); return None
if (role == Qt::DisplayRole) if role == Qt.DisplayRole:
return stringList.at(index.row()); return stringList[index.row()]
else else
return QVariant(); return None
}
//! [1] //! [1]
/*! /*!
@ -89,17 +83,14 @@ QVariant StringListModel::data(const QModelIndex &index, int role) const
*/ */
//! [2] //! [2]
QVariant StringListModel::headerData(int section, Qt::Orientation orientation, def headerData(self, section, orientation, role):
int role) const if role != Qt::DisplayRole:
{ return None
if (role != Qt::DisplayRole)
return QVariant();
if (orientation == Qt::Horizontal) if orientation == Qt::Horizontal:
return QString("Column %1").arg(section); return "Column %s" % section
else else:
return QString("Row %1").arg(section); return "Row %s" % section
}
//! [2] //! [2]
/*! /*!
@ -108,13 +99,11 @@ QVariant StringListModel::headerData(int section, Qt::Orientation orientation,
*/ */
//! [3] //! [3]
Qt::ItemFlags StringListModel::flags(const QModelIndex &index) const def flags(self, index):
{ if not index.isValid()
if (!index.isValid()) return Qt.ItemIsEnabled
return Qt::ItemIsEnabled;
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; return QAbstractItemModel.flags(index) | Qt.ItemIsEditable
}
//! [3] //! [3]
/*! /*!
@ -129,17 +118,13 @@ Qt::ItemFlags StringListModel::flags(const QModelIndex &index) const
*/ */
//! [4] //! [4]
bool StringListModel::setData(const QModelIndex &index, def setData(self, index, value, role):
const QVariant &value, int role) if index.isValid() and role == Qt.EditRole:
{ self.stringList[index.row()] = value
if (index.isValid() && role == Qt::EditRole) { self.dataChanged.emit(index, index)
return True;
stringList.replace(index.row(), value.toString());
emit dataChanged(index, index);
return true;
}
//! [4] //! [5] //! [4] //! [5]
return false; return False;
} }
//! [5] //! [5]
@ -148,18 +133,15 @@ bool StringListModel::setData(const QModelIndex &index,
*/ */
//! [6] //! [6]
bool StringListModel::insertRows(int position, int rows, const QModelIndex &parent) def insertRows(self, position, rows, parent):
{ self.beginInsertRows(QModelIndex(), position, position+rows-1)
beginInsertRows(QModelIndex(), position, position+rows-1);
for (int row = 0; row < rows; ++row) { for row in range(0, rows):
stringList.insert(position, ""); self.stringList.insert(position, "")
}
endInsertRows(); self.endInsertRows()
return true; return True;
//! [6] //! [7] //! [6] //! [7]
}
//! [7] //! [7]
/*! /*!
@ -167,16 +149,13 @@ bool StringListModel::insertRows(int position, int rows, const QModelIndex &pare
*/ */
//! [8] //! [8]
bool StringListModel::removeRows(int position, int rows, const QModelIndex &parent) def removeRows(self, position, rows, parent):
{ self.beginRemoveRows(QModelIndex(), position, position+rows-1)
beginRemoveRows(QModelIndex(), position, position+rows-1);
for (int row = 0; row < rows; ++row) { for row in range(0, rows):
stringList.removeAt(position); del self.stringList[position]
}
endRemoveRows(); self.endRemoveRows()
return true; return True;
//! [8] //! [9] //! [8] //! [9]
}
//! [9] //! [9]

View file

@ -39,45 +39,35 @@
** **
****************************************************************************/ ****************************************************************************/
#ifndef MODEL_H
#define MODEL_H
#include <QAbstractListModel>
#include <QObject>
#include <QStringList>
//! [0] //! [0]
class StringListModel : public QAbstractListModel class StringListModel (QAbstractListModel):
{ def __init__(strings, parent = None):
Q_OBJECT QAbstractListModel.__init__(self, parent)
//! [5]
self.stringList = strings
//! [5]
public: def rowCount(self, parent = QModelIndex()):
StringListModel(const QStringList &strings, QObject *parent = 0) # ...
: QAbstractListModel(parent), stringList(strings) {} def data(self, index, role):
# ...
int rowCount(const QModelIndex &parent = QModelIndex()) const; def headerData(self, section, orientation,
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation,
//! [0] //! [1] //! [0] //! [1]
int role = Qt::DisplayRole) const; role = Qt.DisplayRole):
//! [1] //! [1]
//! [2] //! [2]
Qt::ItemFlags flags(const QModelIndex &index) const; def flags(self, index):
bool setData(const QModelIndex &index, const QVariant &value, # ...
def setData(self, index, value,
//! [2] //! [3] //! [2] //! [3]
int role = Qt::EditRole); role = Qt.EditRole)
//! [3] //! [3]
//! [4] //! [4]
bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex()); def insertRows(self, position, rows, index = QModelIndex()):
bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex()); # ...
def removeRows(self, position, rows, index = QModelIndex()):
# ...
//! [4] //! [4]
//! [5]
private:
QStringList stringList;
};
//! [5]
#endif

View file

@ -224,7 +224,7 @@ class CodeStylePage(QWizardPage):
//! [16] //! [16]
def initializePage(self): def initializePage(self):
className = self.field("className") className = self.field("className")
self.macroNameLineEdit.setText(className.toUpper() + "_H") self.macroNameLineEdit.setText(className.upper() + "_H")
baseClass = self.field("baseClass") baseClass = self.field("baseClass")
@ -238,13 +238,13 @@ class CodeStylePage(QWizardPage):
elsif QRegExp("Q[A-Z].*").exactMatch(baseClass): elsif QRegExp("Q[A-Z].*").exactMatch(baseClass):
baseIncludeLineEdit.setText("<" + baseClass + ">") baseIncludeLineEdit.setText("<" + baseClass + ">")
else: else:
baseIncludeLineEdit.setText("\"" + baseClass.toLower() + ".h\"") baseIncludeLineEdit.setText("\"" + baseClass.lower() + ".h\"")
//! [16] //! [16]
//! [17] //! [17]
def initializePage(self): def initializePage(self):
className = field("className").toString() className = field("className")
self.headerLineEdit.setText(className.toLower() + ".h") self.headerLineEdit.setText(className.lower() + ".h")
self.implementationLineEdit.setText(className.toLower() + ".cpp") self.implementationLineEdit.setText(className.lower() + ".cpp")
self.outputDirLineEdit.setText(QDir.convertSeparators(QDir.tempPath())) self.outputDirLineEdit.setText(QDir.convertSeparators(QDir.tempPath()))
//! [17] //! [17]

View file

@ -64,10 +64,10 @@ def filterAcceptsRow(self, sourceRow, sourceParent):
index1 = sourceModel().index(sourceRow, 1, sourceParent) index1 = sourceModel().index(sourceRow, 1, sourceParent)
index2 = sourceModel().index(sourceRow, 2, sourceParent) index2 = sourceModel().index(sourceRow, 2, sourceParent)
return (sourceModel().data(index0).toString().contains(filterRegExp()) regex = filterRegExp()
|| sourceModel().data(index1).toString().contains(filterRegExp())) return (regex.indexIn(sourceModel().data(index0)) != -1
&& dateInRange(sourceModel().data(index2).toDate()) or regex.indexIn(sourceModel().data(index1)) != -1
and dateInRange(sourceModel().data(index2))
//! [3] //! [3]
//! [4] //! [5] //! [4] //! [5]
@ -77,20 +77,18 @@ def lessThan(self, left, right):
//! [4] //! [4]
//! [6] //! [6]
if leftData.type() == QVariant.DateTime: if isinstance(leftData, QDateTime):
return leftData.toDateTime() < rightData.toDateTime() return leftData < rightData
else: else:
emailPattern = QRegExp("([\\w\\.]*@[\\w\\.]*)") emailPattern = QRegExp("([\\w\\.]*@[\\w\\.]*)")
leftString = leftData.toString() if left.column() == 1 && emailPattern.indexIn(leftData) != -1:
if left.column() == 1 && emailPattern.indexIn(leftString) != -1: leftData = emailPattern.cap(1)
leftString = emailPattern.cap(1)
rightString = rightData.toString() if right.column() == 1 && emailPattern.indexIn(rightData) != -1:
if right.column() == 1 && emailPattern.indexIn(rightString) != -1: rightData = emailPattern.cap(1)
rightString = emailPattern.cap(1)
return QString.localeAwareCompare(leftString, rightString) < 0 return leftString < rightString
//! [5] //! [6] //! [5] //! [6]