• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

KHTML

domtreeview.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                                domtreeview.cpp
00003                              -------------------
00004 
00005     copyright            : (C) 2001 - The Kafka Team
00006     email                : kde-kafka@master.kde.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "khtml_part.h"
00019 #include "domtreeview.moc"
00020 #include "xml/dom_nodeimpl.h"
00021 
00022 DOMTreeView::DOMTreeView(QWidget *parent, KHTMLPart *currentpart, const char * name) : KListView(parent, name)
00023 {
00024     setCaption(name);
00025     setRootIsDecorated(true);
00026     addColumn("Name");
00027     addColumn("Value");
00028     addColumn("Renderer");
00029     setSorting(-1);
00030     part = currentpart;
00031     connect(part, SIGNAL(nodeActivated(const DOM::Node &)), this, SLOT(showTree(const DOM::Node &)));
00032     connect(this, SIGNAL(clicked(QListViewItem *)), this, SLOT(slotItemClicked(QListViewItem *)));
00033     m_nodedict.setAutoDelete(true);
00034 }
00035 
00036 DOMTreeView::~DOMTreeView()
00037 {
00038     disconnect(part);
00039 }
00040 
00041 void DOMTreeView::showTree(const DOM::Node &pNode)
00042 {
00043     if(pNode.isNull() || document != pNode.ownerDocument())
00044     {
00045     clear();
00046     m_itemdict.clear();
00047     m_nodedict.clear();
00048     if(pNode.isNull())
00049         return;
00050     else if(pNode.ownerDocument().isNull())
00051         recursive(0, pNode);
00052     else
00053         recursive(0, pNode.ownerDocument());
00054     }
00055     setCurrentItem(m_itemdict[pNode.handle()]);
00056     ensureItemVisible(m_itemdict[pNode.handle()]);
00057 }
00058 
00059 void DOMTreeView::recursive(const DOM::Node &pNode, const DOM::Node &node)
00060 {
00061     QListViewItem *cur_item;
00062     if(pNode.ownerDocument() != document)
00063     {
00064     QString val = node.nodeValue().string();
00065     if ( val.length() > 20 )
00066         val.truncate( 20 );
00067     cur_item = new QListViewItem(static_cast<QListView *>(this), node.nodeName().string(), val );
00068     document = pNode.ownerDocument();
00069     }
00070     else {
00071     QString val = node.nodeValue().string();
00072     if ( val.length() > 20 )
00073         val.truncate( 20 );
00074     cur_item = new QListViewItem(m_itemdict[pNode.handle()], node.nodeName().string(), val);
00075     }
00076 
00077     if(node.handle())
00078     {
00079     m_itemdict.insert(node.handle(), cur_item);
00080     m_nodedict.insert(cur_item, new DOM::Node(node));
00081     }
00082 
00083     DOM::Node cur_child = node.lastChild();
00084     while(!cur_child.isNull())
00085     {
00086     recursive(node, cur_child);
00087     cur_child = cur_child.previousSibling();
00088     }
00089 }
00090 
00091 void DOMTreeView::slotItemClicked(QListViewItem *cur_item)
00092 {
00093     DOM::Node *handle = m_nodedict[cur_item];
00094     if(handle) {
00095     emit part->setActiveNode(*handle);
00096     }
00097 }

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal