diff options
author | Timothy Pearson <[email protected]> | 2011-11-08 12:31:36 -0600 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2011-11-08 12:31:36 -0600 |
commit | d796c9dd933ab96ec83b9a634feedd5d32e1ba3f (patch) | |
tree | 6e3dcca4f77e20ec8966c666aac7c35bd4704053 /examples/xml/outliner/outlinetree.cpp | |
download | tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.tar.gz tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.zip |
Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731
Diffstat (limited to 'examples/xml/outliner/outlinetree.cpp')
-rw-r--r-- | examples/xml/outliner/outlinetree.cpp | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/examples/xml/outliner/outlinetree.cpp b/examples/xml/outliner/outlinetree.cpp new file mode 100644 index 000000000..69b92358b --- /dev/null +++ b/examples/xml/outliner/outlinetree.cpp @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for TQt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include "outlinetree.h" +#include <qfile.h> +#include <qmessagebox.h> + +OutlineTree::OutlineTree( const TQString fileName, TQWidget *parent, const char *name ) + : TQListView( parent, name ) +{ + // div. configuration of the list view + addColumn( "Outlines" ); + setSorting( -1 ); + setRootIsDecorated( TRUE ); + + // read the XML file and create DOM tree + TQFile opmlFile( fileName ); + if ( !opmlFile.open( IO_ReadOnly ) ) { + TQMessageBox::critical( 0, + tr( "Critical Error" ), + tr( "Cannot open file %1" ).arg( fileName ) ); + return; + } + if ( !domTree.setContent( &opmlFile ) ) { + TQMessageBox::critical( 0, + tr( "Critical Error" ), + tr( "Parsing error for file %1" ).arg( fileName ) ); + opmlFile.close(); + return; + } + opmlFile.close(); + + // get the header information from the DOM + TQDomElement root = domTree.documentElement(); + TQDomNode node; + node = root.firstChild(); + while ( !node.isNull() ) { + if ( node.isElement() && node.nodeName() == "head" ) { + TQDomElement header = node.toElement(); + getHeaderInformation( header ); + break; + } + node = node.nextSibling(); + } + // create the tree view out of the DOM + node = root.firstChild(); + while ( !node.isNull() ) { + if ( node.isElement() && node.nodeName() == "body" ) { + TQDomElement body = node.toElement(); + buildTree( 0, body ); + break; + } + node = node.nextSibling(); + } +} + +OutlineTree::~OutlineTree() +{ +} + +void OutlineTree::getHeaderInformation( const TQDomElement &header ) +{ + // visit all children of the header element and look if you can make + // something with it + TQDomNode node = header.firstChild(); + while ( !node.isNull() ) { + if ( node.isElement() ) { + // case for the different header entries + if ( node.nodeName() == "title" ) { + TQDomText textChild = node.firstChild().toText(); + if ( !textChild.isNull() ) { + setColumnText( 0, textChild.nodeValue() ); + } + } + } + node = node.nextSibling(); + } +} + +void OutlineTree::buildTree( TQListViewItem *parentItem, const TQDomElement &parentElement ) +{ + TQListViewItem *thisItem = 0; + TQDomNode node = parentElement.firstChild(); + while ( !node.isNull() ) { + if ( node.isElement() && node.nodeName() == "outline" ) { + // add a new list view item for the outline + if ( parentItem == 0 ) + thisItem = new TQListViewItem( this, thisItem ); + else + thisItem = new TQListViewItem( parentItem, thisItem ); + thisItem->setText( 0, node.toElement().attribute( "text" ) ); + // recursive build of the tree + buildTree( thisItem, node.toElement() ); + } + node = node.nextSibling(); + } +} |