summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/codesnippets/doc/src/snippets/qxmlschemavalidator/main.cpp63
-rw-r--r--doc/codesnippets/examples/declarative/cppextensions/imageprovider/imageprovider.cpp33
-rw-r--r--doc/codesnippets/examples/declarative/cppextensions/plugins/plugin.cpp19
3 files changed, 115 insertions, 0 deletions
diff --git a/doc/codesnippets/doc/src/snippets/qxmlschemavalidator/main.cpp b/doc/codesnippets/doc/src/snippets/qxmlschemavalidator/main.cpp
new file mode 100644
index 0000000..5c15482
--- /dev/null
+++ b/doc/codesnippets/doc/src/snippets/qxmlschemavalidator/main.cpp
@@ -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]
diff --git a/doc/codesnippets/examples/declarative/cppextensions/imageprovider/imageprovider.cpp b/doc/codesnippets/examples/declarative/cppextensions/imageprovider/imageprovider.cpp
new file mode 100644
index 0000000..7be620b
--- /dev/null
+++ b/doc/codesnippets/examples/declarative/cppextensions/imageprovider/imageprovider.cpp
@@ -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]
diff --git a/doc/codesnippets/examples/declarative/cppextensions/plugins/plugin.cpp b/doc/codesnippets/examples/declarative/cppextensions/plugins/plugin.cpp
new file mode 100644
index 0000000..eef2ad7
--- /dev/null
+++ b/doc/codesnippets/examples/declarative/cppextensions/plugins/plugin.cpp
@@ -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]