1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
package MainWindow;
use strict;
use warnings;
use QtCore4;
use QtGui4;
use QtXmlPatterns4;
use Ui_MainWindow;
use QObjectXmlModel;
use QtCore4::isa qw( Qt::MainWindow );
use QtCore4::slots
on_actionAbout_triggered => [];
use lib '../shared';
#use XmlSyntaxHighlighter;
sub ui() {
return this->{ui};
}
sub NEW
{
my ($class) = @_;
$class->SUPER::NEW();
this->{ui} = Ui_MainWindow->setupUi(this);
#XmlSyntaxHighlighter(ui->wholeTreeOutput->document());
# Setup the font.
{
my $font = Qt::Font('Courier');
$font->setFixedPitch(1);
ui->wholeTree->setFont($font);
ui->wholeTreeOutput->setFont($font);
ui->htmlQueryEdit->setFont($font);
}
my $namePool = Qt::XmlNamePool();
my $qObjectModel = QObjectXmlModel(this, $namePool);
my $query = Qt::XmlQuery($namePool);
# The Qt::Object tree as XML view.
{
$query->bindVariable('root', Qt::XmlItem($qObjectModel->root()));
$query->setQuery(Qt::Url('qrc:/queries/wholeTree.xq'));
die '$query is invalid' unless $query->isValid();
my $output = Qt::ByteArray();
my $buffer = Qt::Buffer($output);
$buffer->open(Qt::IODevice::WriteOnly());
# Let's the use the formatter, so it's a bit easier to read.
my $serializer = Qt::XmlFormatter($query, $buffer);
$query->evaluateTo($serializer);
$buffer->close();
{
my $queryFile = Qt::File(':/queries/wholeTree.xq');
$queryFile->open(Qt::IODevice::ReadOnly());
ui()->wholeTree->setPlainText($queryFile->readAll()->constData());
ui()->wholeTreeOutput->setPlainText($output->constData());
}
}
# The Qt::Object occurrence statistics as HTML view.
{
$query->setQuery(Qt::Url('qrc:/queries/statisticsInHTML.xq'));
die '$query is invalid' unless $query->isValid();
my $output = Qt::ByteArray();
my $buffer = Qt::Buffer($output);
$buffer->open(Qt::IODevice::WriteOnly());
# Let's the use the serializer, so we gain a bit of speed.
my $serializer = Qt::XmlSerializer($query, $buffer);
$query->evaluateTo($serializer);
$buffer->close();
{
my $queryFile = Qt::File(':/queries/statisticsInHTML.xq');
$queryFile->open(Qt::IODevice::ReadOnly());
ui()->htmlQueryEdit->setPlainText($queryFile->readAll()->constData());
ui()->htmlOutput->setHtml($output->constData());
}
}
}
sub on_actionAbout_triggered
{
Qt::MessageBox::about(this,
this->tr('About Qt::Object XML Model'),
this->tr('<p>The <b>Qt::Object XML Model</b> example shows ' .
'how to use XQuery on top of data of your choice ' .
'without converting it to an XML document.</p>' .
'<p>In this example a Qt::SimpleXmlNodeModel subclass ' .
'makes it possible to query a Qt::Object tree using ' .
'XQuery and retrieve the result as pointers to ' .
'Qt::Objects, or as XML.</p>' .
'<p>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 Qt::Object tree and dynamic properties.'));
}
1;
|