mainwindow.cpp Example File | Qt 4.8 (original) (raw)
xmlpatterns/qobjectxmlmodel/mainwindow.cpp
#include #include
#include "mainwindow.h" #include "qobjectxmlmodel.h" #include "xmlsyntaxhighlighter.h"
MainWindow::MainWindow() { setupUi(this);
new XmlSyntaxHighlighter(wholeTreeOutput->document());
{
[QFont](qfont.html) font("Courier");
font.setFixedPitch(true);
wholeTree->setFont(font);
wholeTreeOutput->setFont(font);
htmlQueryEdit->setFont(font);
}
[QXmlNamePool](qxmlnamepool.html) namePool;
QObjectXmlModel qObjectModel(this, namePool);
[QXmlQuery](qxmlquery.html) query(namePool);
{
query.bindVariable("root", qObjectModel.root());
query.setQuery([QUrl](qurl.html)("qrc:/queries/wholeTree.xq"));
Q_ASSERT(query.isValid());
[QByteArray](qbytearray.html) output;
[QBuffer](qbuffer.html) buffer(&output);
buffer.open([QIODevice](qiodevice.html)::WriteOnly);
[QXmlFormatter](qxmlformatter.html) serializer(query, &buffer);
query.evaluateTo(&serializer);
buffer.close();
{
[QFile](qfile.html) queryFile(":/queries/wholeTree.xq");
queryFile.open([QIODevice](qiodevice.html)::ReadOnly);
wholeTree->setPlainText([QString](qstring.html)::fromUtf8(queryFile.readAll()));
wholeTreeOutput->setPlainText([QString](qstring.html)::fromUtf8(output.constData()));
}
}
{
query.setQuery([QUrl](qurl.html)("qrc:/queries/statisticsInHTML.xq"));
Q_ASSERT(query.isValid());
[QByteArray](qbytearray.html) output;
[QBuffer](qbuffer.html) buffer(&output);
buffer.open([QIODevice](qiodevice.html)::WriteOnly);
[QXmlSerializer](qxmlserializer.html) serializer(query, &buffer);
query.evaluateTo(&serializer);
buffer.close();
{
[QFile](qfile.html) queryFile(":/queries/statisticsInHTML.xq");
queryFile.open([QIODevice](qiodevice.html)::ReadOnly);
htmlQueryEdit->setPlainText([QString](qstring.html)::fromUtf8(queryFile.readAll()));
htmlOutput->setHtml([QString](qstring.html)(output));
}
}}
void MainWindow::on_actionAbout_triggered() { QMessageBox::about(this, tr("About QObject XML Model"), tr("
The QObject XML Model example shows " "how to use XQuery on top of data of your choice " "without converting it to an XML document.
" "In this example a QSimpleXmlNodeModel subclass " "makes it possible to query a QObject tree using " "XQuery and retrieve the result as pointers to " "QObjects, or as XML.
" "A possible use case of this could be to write " "an application that tests a graphical interface " "against Human Interface Guidelines, or that " "queries an application's data which is modeled " "using a QObject tree and dynamic properties.")); }
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.