summaryrefslogtreecommitdiffstats
path: root/examples/xml/outliner
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-11-08 12:31:36 -0600
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-11-08 12:31:36 -0600
commitd796c9dd933ab96ec83b9a634feedd5d32e1ba3f (patch)
tree6e3dcca4f77e20ec8966c666aac7c35bd4704053 /examples/xml/outliner
downloadtqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.tar.gz
tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.zip
Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731
Diffstat (limited to 'examples/xml/outliner')
-rw-r--r--examples/xml/outliner/main.cpp22
-rw-r--r--examples/xml/outliner/outliner.doc40
-rw-r--r--examples/xml/outliner/outliner.pro11
-rw-r--r--examples/xml/outliner/outlinetree.cpp103
-rw-r--r--examples/xml/outliner/outlinetree.h30
-rw-r--r--examples/xml/outliner/todos.opml55
6 files changed, 261 insertions, 0 deletions
diff --git a/examples/xml/outliner/main.cpp b/examples/xml/outliner/main.cpp
new file mode 100644
index 000000000..c4b1491e3
--- /dev/null
+++ b/examples/xml/outliner/main.cpp
@@ -0,0 +1,22 @@
+/****************************************************************************
+**
+** 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 <qapplication.h>
+#include "outlinetree.h"
+
+int main( int argc, char **argv )
+{
+ TQApplication a( argc, argv );
+
+ OutlineTree outline( "todos.opml" );
+ a.setMainWidget( &outline );
+ outline.show();
+
+ return a.exec();
+}
diff --git a/examples/xml/outliner/outliner.doc b/examples/xml/outliner/outliner.doc
new file mode 100644
index 000000000..c21043dd6
--- /dev/null
+++ b/examples/xml/outliner/outliner.doc
@@ -0,0 +1,40 @@
+/*
+*/
+
+/*! \page outliner-example.html
+
+ \ingroup xml-examples
+
+ \title Outliner to show use of DOM
+
+ This example presents a small outliner program to show the basic usage of
+ the \link xml.html#dom DOM classes \endlink. The format of the outlines
+ is the OPML format as described in http://www.opml.org/spec.
+
+ This example shows how to load a DOM tree from an XML file and how to
+ traverse it.
+
+ <hr>
+
+ Sample XML file (todos.opml):
+
+ \include xml/outliner/todos.opml
+
+ <hr>
+
+ Header file (outlinetree.h):
+
+ \include xml/outliner/outlinetree.h
+
+ <hr>
+
+ Implementation (outlinetree.cpp):
+
+ \include xml/outliner/outlinetree.cpp
+
+ <hr>
+
+ Main (main.cpp):
+
+ \include xml/outliner/main.cpp
+*/
diff --git a/examples/xml/outliner/outliner.pro b/examples/xml/outliner/outliner.pro
new file mode 100644
index 000000000..1dcdc44bd
--- /dev/null
+++ b/examples/xml/outliner/outliner.pro
@@ -0,0 +1,11 @@
+TEMPLATE = app
+TARGET = outliner
+
+CONFIG += qt warn_on release
+
+REQUIRES = xml large-config
+
+HEADERS = outlinetree.h
+SOURCES = main.cpp \
+ outlinetree.cpp
+INTERFACES =
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();
+ }
+}
diff --git a/examples/xml/outliner/outlinetree.h b/examples/xml/outliner/outlinetree.h
new file mode 100644
index 000000000..c6a22ad9d
--- /dev/null
+++ b/examples/xml/outliner/outlinetree.h
@@ -0,0 +1,30 @@
+/****************************************************************************
+**
+** 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.
+**
+*****************************************************************************/
+
+#ifndef OUTLINETREE_H
+#define OUTLINETREE_H
+
+#include <qlistview.h>
+#include <qdom.h>
+
+class OutlineTree : public TQListView
+{
+ Q_OBJECT
+
+public:
+ OutlineTree( const TQString fileName, TQWidget *parent = 0, const char *name = 0 );
+ ~OutlineTree();
+
+private:
+ TQDomDocument domTree;
+ void getHeaderInformation( const TQDomElement &header );
+ void buildTree( TQListViewItem *parentItem, const TQDomElement &parentElement );
+};
+
+#endif // OUTLINETREE_H
diff --git a/examples/xml/outliner/todos.opml b/examples/xml/outliner/todos.opml
new file mode 100644
index 000000000..62793900a
--- /dev/null
+++ b/examples/xml/outliner/todos.opml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<opml version="1.0">
+ <head>
+ <title>Todo List</title>
+ <dateCreated>Tue, 31 Oct 2000 17:00:17 CET</dateCreated>
+ <dateModified>Tue, 31 Oct 2000 17:00:17 CET</dateModified>
+ <ownerName>Arthur Dent</ownerName>
+ <ownerEmail>info@trolltech.com</ownerEmail>
+ </head>
+ <body>
+ <outline text="Background">
+ <outline text="This is an example todo list."/>
+ </outline>
+ <outline text="Books to read">
+ <outline text="Science Fiction">
+ <outline text="Philip K. Dick">
+ <outline text="Do Androids Dream of Electical Sheep?"/>
+ <outline text="The Three Stigmata of Palmer Eldritch"/>
+ </outline>
+ <outline text="Robert A. Heinlein">
+ <outline text="Stranger in a Strange Land"/>
+ </outline>
+ <outline text="Isaac Asimov">
+ <outline text="Foundation and Empire"/>
+ </outline>
+ </outline>
+ <outline text="Qt Books (in English)">
+ <outline text="Blanchette &amp; Summerfield: C++ GUI Programming with Qt 3"/>
+ <outline text="Dalheimer: Programming with Qt"/>
+ <outline text="Griffith: KDE 2/Qt Programming Bible"/>
+ <outline text="Hughes: Linux Rapid Application Development"/>
+ <outline text="Solin: Qt Programming in 24 hours"/>
+ <outline text="Ward: Qt 2 Programming for Linux and Windows 2000"/>
+ </outline>
+ </outline>
+ <outline text="Shopping list">
+ <outline text="General">
+ <outline text="Towel"/>
+ <outline text="Hair dryer"/>
+ <outline text="Underpants"/>
+ </outline>
+ <outline text="For Sunday">
+ <outline text="Beef"/>
+ <outline text="Rice"/>
+ <outline text="Carrots"/>
+ <outline text="Beans"/>
+ <outline text="Beer"/>
+ <outline text="Wine"/>
+ <outline text="Orange juice"/>
+ </outline>
+ </outline>
+ <outline text="Write a letter to Ford">
+ </outline>
+ </body>
+</opml>