# khtml Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# domtreeview.cpp

    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 #include "rendering/render_object.h"
    00022
    00023 DOMTreeView::DOMTreeView(QWidget *parent, KHTMLPart *currentpart, const char * name) : KListView(parent, name)
    00024 {
    00025     setCaption(name);
    00026     setRootIsDecorated(true);
    00027     addColumn("Name");
    00028     addColumn("Value");
    00029     addColumn("Renderer");
    00030     setSorting(-1);
    00031     part = currentpart;
    00032     connect(part, SIGNAL(nodeActivated(const DOM::Node &)), this, SLOT(showTree(const DOM::Node &)));
    00033     connect(this, SIGNAL(clicked(QListViewItem *)), this, SLOT(slotItemClicked(QListViewItem *)));
    00034     m_nodedict.setAutoDelete(true);
    00035 }
    00036
    00037 DOMTreeView::~DOMTreeView()
    00038 {
    00039     disconnect(part);
    00040 }
    00041
    00042 void DOMTreeView::showTree(const DOM::Node &pNode)
    00043 {
    00044     if(pNode.isNull() || document != pNode.ownerDocument())
    00045     {
    00046         clear();
    00047         m_itemdict.clear();
    00048         m_nodedict.clear();
    00049         if(pNode.isNull())
    00050             return;
    00051         else if(pNode.ownerDocument().isNull())
    00052             recursive(0, pNode);
    00053         else
    00054             recursive(0, pNode.ownerDocument());
    00055     }
    00056     setCurrentItem(m_itemdict[pNode.handle()]);
    00057     ensureItemVisible(m_itemdict[pNode.handle()]);
    00058 }
    00059
    00060 void DOMTreeView::recursive(const DOM::Node &pNode, const DOM::Node &node)
    00061 {
    00062     QListViewItem *cur_item;
    00063     if(pNode.ownerDocument() != document)
    00064     {
    00065         khtml::RenderObject *r = node.handle() ? node.handle()->renderer() : 0;
    00066         QString renderer = r ? r->information() : QString::null;
    00067         QString val = node.nodeValue().string();
    00068         if ( val.length() > 20 )
    00069             val.truncate( 20 );
    00070         cur_item = new QListViewItem(static_cast<QListView *>(this), node.nodeName().string(), val, renderer );
    00071         document = pNode.ownerDocument();
    00072     }
    00073     else {
    00074         khtml::RenderObject *r = node.handle() ? node.handle()->renderer() : 0;
    00075         QString renderer = r ? r->information() : QString::null;
    00076         QString val = node.nodeValue().string();
    00077         if ( val.length() > 20 )
    00078             val.truncate( 20 );
    00079         cur_item = new QListViewItem(m_itemdict[pNode.handle()], node.nodeName().string(), val, renderer);
    00080     }
    00081
    00082     if(node.handle())
    00083     {
    00084         m_itemdict.insert(node.handle(), cur_item);
    00085         m_nodedict.insert(cur_item, new DOM::Node(node));
    00086     }
    00087
    00088     DOM::Node cur_child = node.lastChild();
    00089     while(!cur_child.isNull())
    00090     {
    00091         recursive(node, cur_child);
    00092         cur_child = cur_child.previousSibling();
    00093     }
    00094 }
    00095
    00096 void DOMTreeView::slotItemClicked(QListViewItem *cur_item)
    00097 {
    00098     DOM::Node *handle = m_nodedict[cur_item];
    00099     if(handle) {
    00100         emit part->setActiveNode(*handle);
    00101         //kdDebug() << handle->toHTML() << endl;
    00102     }
    00103 }

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:33:49 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001