Qt

 view release on metacpan or  search on metacpan

qtgui/examples/xmlpatterns/qobjectxmlmodel/MainWindow.pm  view on Meta::CPAN

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);



( run in 0.906 second using v1.01-cache-2.11-cpan-4ab04211f4c )