summaryrefslogtreecommitdiffstats
path: root/khtml/domtreeview.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitce4a32fe52ef09d8f5ff1dd22c001110902b60a2 (patch)
tree5ac38a06f3dde268dc7927dc155896926aaf7012 /khtml/domtreeview.cpp
downloadtdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.tar.gz
tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'khtml/domtreeview.cpp')
-rw-r--r--khtml/domtreeview.cpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/khtml/domtreeview.cpp b/khtml/domtreeview.cpp
new file mode 100644
index 000000000..e5516edfd
--- /dev/null
+++ b/khtml/domtreeview.cpp
@@ -0,0 +1,97 @@
+/***************************************************************************
+ domtreeview.cpp
+ -------------------
+
+ copyright : (C) 2001 - The Kafka Team
+ email : kde-kafka@master.kde.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "khtml_part.h"
+#include "domtreeview.moc"
+#include "xml/dom_nodeimpl.h"
+
+DOMTreeView::DOMTreeView(QWidget *parent, KHTMLPart *currentpart, const char * name) : KListView(parent, name)
+{
+ setCaption(name);
+ setRootIsDecorated(true);
+ addColumn("Name");
+ addColumn("Value");
+ addColumn("Renderer");
+ setSorting(-1);
+ part = currentpart;
+ connect(part, SIGNAL(nodeActivated(const DOM::Node &)), this, SLOT(showTree(const DOM::Node &)));
+ connect(this, SIGNAL(clicked(QListViewItem *)), this, SLOT(slotItemClicked(QListViewItem *)));
+ m_nodedict.setAutoDelete(true);
+}
+
+DOMTreeView::~DOMTreeView()
+{
+ disconnect(part);
+}
+
+void DOMTreeView::showTree(const DOM::Node &pNode)
+{
+ if(pNode.isNull() || document != pNode.ownerDocument())
+ {
+ clear();
+ m_itemdict.clear();
+ m_nodedict.clear();
+ if(pNode.isNull())
+ return;
+ else if(pNode.ownerDocument().isNull())
+ recursive(0, pNode);
+ else
+ recursive(0, pNode.ownerDocument());
+ }
+ setCurrentItem(m_itemdict[pNode.handle()]);
+ ensureItemVisible(m_itemdict[pNode.handle()]);
+}
+
+void DOMTreeView::recursive(const DOM::Node &pNode, const DOM::Node &node)
+{
+ QListViewItem *cur_item;
+ if(pNode.ownerDocument() != document)
+ {
+ QString val = node.nodeValue().string();
+ if ( val.length() > 20 )
+ val.truncate( 20 );
+ cur_item = new QListViewItem(static_cast<QListView *>(this), node.nodeName().string(), val );
+ document = pNode.ownerDocument();
+ }
+ else {
+ QString val = node.nodeValue().string();
+ if ( val.length() > 20 )
+ val.truncate( 20 );
+ cur_item = new QListViewItem(m_itemdict[pNode.handle()], node.nodeName().string(), val);
+ }
+
+ if(node.handle())
+ {
+ m_itemdict.insert(node.handle(), cur_item);
+ m_nodedict.insert(cur_item, new DOM::Node(node));
+ }
+
+ DOM::Node cur_child = node.lastChild();
+ while(!cur_child.isNull())
+ {
+ recursive(node, cur_child);
+ cur_child = cur_child.previousSibling();
+ }
+}
+
+void DOMTreeView::slotItemClicked(QListViewItem *cur_item)
+{
+ DOM::Node *handle = m_nodedict[cur_item];
+ if(handle) {
+ emit part->setActiveNode(*handle);
+ }
+}