Last code snippets....
This commit is contained in:
parent
bd43c1e0b2
commit
73f21eb1bb
3 changed files with 115 additions and 0 deletions
|
|
@ -0,0 +1,63 @@
|
||||||
|
|
||||||
|
def validateFromUrl():
|
||||||
|
//! [0]
|
||||||
|
schema = getSchema()
|
||||||
|
|
||||||
|
url = QUrl("http://www.schema-example.org/test.xml")
|
||||||
|
|
||||||
|
validator = QXmlSchemaValidator(schema)
|
||||||
|
if validator.validate(url):
|
||||||
|
print "instance document is valid"
|
||||||
|
else:
|
||||||
|
print "instance document is invalid"
|
||||||
|
//! [0]
|
||||||
|
|
||||||
|
def validateFromFile():
|
||||||
|
//! [1]
|
||||||
|
schema = getSchema()
|
||||||
|
|
||||||
|
file = QFile("test.xml")
|
||||||
|
file.open(QIODevice.ReadOnly)
|
||||||
|
|
||||||
|
validator = QXmlSchemaValidator(schema)
|
||||||
|
if validator.validate(file, QUrl.fromLocalFile(file.fileName())):
|
||||||
|
print "instance document is valid"
|
||||||
|
else:
|
||||||
|
print "instance document is invalid"
|
||||||
|
//! [1]
|
||||||
|
}
|
||||||
|
|
||||||
|
def validateFromData():
|
||||||
|
//! [2]
|
||||||
|
schema = getSchema()
|
||||||
|
|
||||||
|
data = QByteArray("<?xml version=\"1.0\" encoding=\"UTF-8\"?><test></test>")
|
||||||
|
|
||||||
|
buffer = QBuffer(data)
|
||||||
|
buffer.open(QIODevice.ReadOnly)
|
||||||
|
|
||||||
|
QXmlSchemaValidator validator(schema)
|
||||||
|
if validator.validate(buffer):
|
||||||
|
print "instance document is valid"
|
||||||
|
else:
|
||||||
|
print "instance document is invalid"
|
||||||
|
//! [2]
|
||||||
|
|
||||||
|
def validateComplete():
|
||||||
|
//! [3]
|
||||||
|
schemaUrl = QUrl("file:///home/user/schema.xsd")
|
||||||
|
|
||||||
|
schema = QXmlSchema()
|
||||||
|
schema.load(schemaUrl)
|
||||||
|
|
||||||
|
if schema.isValid():
|
||||||
|
file = QFile("test.xml")
|
||||||
|
file.open(QIODevice.ReadOnly)
|
||||||
|
|
||||||
|
validator = QXmlSchemaValidator(schema)
|
||||||
|
if validator.validate(file, QUrl.fromLocalFile(file.fileName())):
|
||||||
|
print "instance document is valid"
|
||||||
|
else:
|
||||||
|
print "instance document is invalid"
|
||||||
|
}
|
||||||
|
//! [3]
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
//![0]
|
||||||
|
class ColorImageProvider (QDeclarativeImageProvider):
|
||||||
|
def __init__(self):
|
||||||
|
QDeclarativeImageProvider.__init__(self, QDeclarativeImageProvider.Pixmap)
|
||||||
|
|
||||||
|
def requestPixmap(id, size, requestedSize):
|
||||||
|
width = 100
|
||||||
|
height = 50
|
||||||
|
|
||||||
|
if size:
|
||||||
|
size.setWidth(width)
|
||||||
|
size.setHeight(height)
|
||||||
|
|
||||||
|
if requestedSize.width() > 0:
|
||||||
|
width = requestedSize.width()
|
||||||
|
if requestedSize.height() > 0:
|
||||||
|
height = requestedSize.height()
|
||||||
|
|
||||||
|
pixmap = QPixmap(width, height)
|
||||||
|
pixmap.fill(QColor(id).rgba())
|
||||||
|
//![0]
|
||||||
|
# write the color name
|
||||||
|
painter = QPainter(pixmap)
|
||||||
|
f = painter.font()
|
||||||
|
f.setPixelSize(20)
|
||||||
|
painter.setFont(f)
|
||||||
|
painter.setPen(Qt.black)
|
||||||
|
if requestedSize.isValid():
|
||||||
|
painter.scale(requestedSize.width() / width, requestedSize.height() / height)
|
||||||
|
painter.drawText(QRectF(0, 0, width, height), Qt.AlignCenter, id)
|
||||||
|
//![1]
|
||||||
|
return pixmap
|
||||||
|
//![1]
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
|
||||||
|
//![0]
|
||||||
|
class TimeModel (QObject):
|
||||||
|
hour = Property(int, getHour, notify = timeChanged)
|
||||||
|
minute = Property(int, getMinute, notify = timeChanged)
|
||||||
|
//![0]
|
||||||
|
|
||||||
|
//![plugin]
|
||||||
|
class QExampleQmlPlugin (QDeclarativeExtensionPlugin):
|
||||||
|
|
||||||
|
def registerTypes(self, uri):
|
||||||
|
assert(uri == "com.nokia.TimeExample")
|
||||||
|
qmlRegisterType(TimeModel, uri, 1, 0, "Time")
|
||||||
|
//![plugin]
|
||||||
|
|
||||||
|
//![export]
|
||||||
|
# This isn't supported by PySide yet.
|
||||||
|
# Q_EXPORT_PLUGIN2(qmlqtimeexampleplugin, QExampleQmlPlugin);
|
||||||
|
//![export]
|
||||||
Loading…
Add table
Add a link
Reference in a new issue