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
|
package MainWindow;
use strict;
use warnings;
use QtCore4;
use QtGui4;
use QtXml4;
use QtCore4::isa qw( Qt::MainWindow );
use QtCore4::slots
openFile => [];
use DomModel;
sub model() {
return this->{model};
}
sub setModel($) {
return this->{model} = shift;
}
sub fileMenu() {
return this->{fileMenu};
}
sub setFileMenu($) {
return this->{fileMenu} = shift;
}
sub xmlPath() {
return this->{xmlPath};
}
sub setXmlPath($) {
return this->{xmlPath} = shift;
}
sub view() {
return this->{view};
}
sub setView($) {
return this->{view} = shift;
}
sub NEW
{
my ( $class ) = @_;
$class->SUPER::NEW();
this->setFileMenu( this->menuBar()->addMenu(this->tr('&File')) );
this->fileMenu->addAction(this->tr('&Open...'), this, SLOT 'openFile()',
Qt::KeySequence(this->tr('Ctrl+O')));
this->fileMenu->addAction(this->tr('E&xit'), this, SLOT 'close()',
Qt::KeySequence(this->tr('Ctrl+Q')));
this->setModel( DomModel(Qt::DomDocument(), this) );
this->setView( Qt::TreeView(this) );
this->view->setModel(this->model);
this->setCentralWidget(this->view);
this->setWindowTitle(this->tr('Simple DOM Model'));
}
sub openFile
{
my $filePath = Qt::FileDialog::getOpenFileName(this, this->tr('Open File'),
this->xmlPath, this->tr('XML files (*.xml);;HTML files (*.html);;' .
'SVG files (*.svg);;User Interface files (*.ui)'));
if ($filePath) {
my $file = Qt::File($filePath);
if ($file->open(Qt::IODevice::ReadOnly())) {
my $document = Qt::DomDocument();
if ($document->setContent($file)) {
my $newModel = DomModel($document, this);
this->view->setModel($newModel);
this->setModel( $newModel );
this->setXmlPath( $filePath );
}
$file->close();
}
}
}
1;
|