|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r77476 - sandbox/icl/libs/xplore/br1/sqlbrowser
From: afojgo_at_[hidden]
Date: 2012-03-22 10:26:55
Author: jofaber
Date: 2012-03-22 10:26:48 EDT (Thu, 22 Mar 2012)
New Revision: 77476
URL: http://svn.boost.org/trac/boost/changeset/77476
Log:
Visualizing the DAG using QTreeView.
Text files modified:
sandbox/icl/libs/xplore/br1/sqlbrowser/CreatorVisitor.h | 6 ++++--
sandbox/icl/libs/xplore/br1/sqlbrowser/Dag.h | 28 ++++++++++++++++++++++++----
sandbox/icl/libs/xplore/br1/sqlbrowser/StringVisitor.h | 8 --------
sandbox/icl/libs/xplore/br1/sqlbrowser/browser.cpp | 11 +++++++----
sandbox/icl/libs/xplore/br1/sqlbrowser/dagitem.cpp | 14 +++++++++-----
sandbox/icl/libs/xplore/br1/sqlbrowser/dagitem.h | 4 ++++
sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.cpp | 13 +++++++++++--
7 files changed, 59 insertions(+), 25 deletions(-)
Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/CreatorVisitor.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/CreatorVisitor.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/CreatorVisitor.h 2012-03-22 10:26:48 EDT (Thu, 22 Mar 2012)
@@ -24,6 +24,7 @@
: p_curItem(curItem), p_result(result), r_attrs(attrs)
{
r_attrs[0].setDagItem(p_curItem); //Root node
+ r_attrs[0].setParentItem(0); //Root node
}
typedef boost::on_discover_vertex event_filter;
@@ -82,7 +83,7 @@
OnExamineEdge(DagItem* curItem, QString* result, Dag::tAttributesMap& names)
: p_curItem(curItem), p_result(result), r_attrs(names)
{
- r_attrs[0].setDagItem(p_curItem); //Root node
+ //CL r_attrs[0].setDagItem(p_curItem); //Root node
}
typedef boost::on_examine_edge event_filter;
@@ -112,6 +113,8 @@
DagItem* newDagItem = new DagItem(itemData, p_curItem);
sourceDagItem->addChild(newDagItem);
r_attrs[target_node].setDagItem(newDagItem);
+ newDagItem->setData(dag::node::posParentId, newDagItem->parent()->data(dag::node::posId));
+ newDagItem->setData(dag::node::posParentName, newDagItem->parent()->data(dag::node::posName));
}
if(boost::out_degree(target(edge, dag), dag)==0)
@@ -131,7 +134,6 @@
OnFinishVertex(DagItem* curItem, QString* result, Dag::tAttributesMap& names)
: p_curItem(curItem), p_result(result), r_attrs(names)
{
- r_attrs[0].setDagItem(p_curItem); //Root node
}
typedef boost::on_finish_vertex event_filter;
Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/Dag.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/Dag.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/Dag.h 2012-03-22 10:26:48 EDT (Thu, 22 Mar 2012)
@@ -12,6 +12,15 @@
#include "dagitem.h"
+inline QString indentation(int depth)
+{
+ QString indent;
+ for(int idx=0; idx < depth; idx++)
+ indent += " ";
+ return indent;
+}
+
+
// An object to collect results on graph traversal.
// The object stores all the information, that shall be associated to graph nodes.
@@ -23,9 +32,8 @@
class NodeAttributes
{
public:
- NodeAttributes(): m_name(), m_depth() {}
- NodeAttributes(const QString& name): m_name(name), m_depth(), p_dagItem() {}
- NodeAttributes(const QString& name, int depth): m_name(name), m_depth(depth), p_dagItem() {}
+ NodeAttributes(): m_nodeId(), m_name(), m_depth() {}
+ NodeAttributes(const QString& name, int id): m_nodeId(id), m_name(name), m_depth(), p_dagItem() {}
void setName(const QString& name) { m_name = name; }
QString name()const { return m_name; }
@@ -33,17 +41,27 @@
void setDepth(int depth){ m_depth = depth; }
int depth()const { return m_depth; }
+ void setNodeId(int nodeId) { m_nodeId = nodeId; }
+ int nodeId()const { return m_nodeId; }
+
void setDagItem(DagItem* dagItem) { p_dagItem = dagItem; }
DagItem* dagItem()const { return p_dagItem; }
+ void setParentItem(DagItem* parentItem) { p_parentItem = parentItem; }
+ DagItem* parentItem()const { return p_parentItem; }
+
int inc(){ return ++m_depth; }
private:
+ int m_nodeId;
QString m_name;
int m_depth;
DagItem* p_dagItem;
+ DagItem* p_parentItem;
};
+//JODO: m_depth/depth() may be removed. It's currently only needed for debugging.
+
namespace dag
{
namespace edge
@@ -62,13 +80,15 @@
{
enum { posId = 0
, posName
+ , posParentId
+ , posParentName
, sizeOf_node
};
}
inline void copyBoostNode2DagItem(const NodeAttributes& src, tVariVector& target)//JODO cpp
{
- target[dag::node::posId] = QVariant(0);
+ target[dag::node::posId] = QVariant(src.nodeId());
target[dag::node::posName] = QVariant(src.name());
}
}//namespace dag
Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/StringVisitor.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/StringVisitor.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/StringVisitor.h 2012-03-22 10:26:48 EDT (Thu, 22 Mar 2012)
@@ -13,14 +13,6 @@
#include "Dag.h"
-inline QString indentation(int depth)
-{
- QString indent;
- for(int idx=0; idx < depth; idx++)
- indent += " ";
- return indent;
-}
-
struct StringVisitor
{
Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/browser.cpp
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/browser.cpp (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/browser.cpp 2012-03-22 10:26:48 EDT (Thu, 22 Mar 2012)
@@ -88,14 +88,17 @@
// Populate the Dag Model from an sql-Query
//JODO dagmo->fromSql(xpQuery);
- dagmo->getEdges(xpQuery);
- dagmo->makeDag();
+
+ dagmo->getEdges(xpQuery); //Read edges from database
+ dagmo->makeDag(); //Make a boost::graph internally
QMessageBox msgBox;
//QString dagStr = dagmo->toString();
//QString dagStr = dagmo->dagToString();
- QString dagStr = dagmo->setupDag();
+ QString dagStr = dagmo->setupDag(); //Build a tree representation from the boost::dag
QString dagStr2 = dagmo->rootItem()->toString();
+
+ //DBG Check structure via generated strings representing the structure.
msgBox.setText(dagStr);
msgBox.exec();
msgBox.setText(dagStr2);
@@ -105,7 +108,7 @@
//REV? model->setQuery(QSqlQuery(sqlEdit->toPlainText(), connectionWidget->currentDatabase()));
ext_table->setModel(model);
- ext_tree->setModel(model);//JOFA
+ ext_tree->setModel(dagmo);//JOFA
//JOFA additions ----------------------------------------------------------
ext_table->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/dagitem.cpp
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/dagitem.cpp (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/dagitem.cpp 2012-03-22 10:26:48 EDT (Thu, 22 Mar 2012)
@@ -150,18 +150,22 @@
QString DagItem::toString()
{
+ return toString(0);
+}
+
+QString DagItem::toString(int depth)
+{
if(childCount()==0)
- return itemData[dag::node::posName].toString() + "\n";
+ return indentation(depth) + itemData[dag::node::posName].toString();
else
{
- QString children = "(";
+ QString children = indentation(depth) + "(";
children += itemData[dag::node::posName].toString() + "\n";
for(int idx=0; idx < childCount(); idx++)
- children += child(idx)->toString() + "\n";
+ children += child(idx)->toString(depth+1) + "\n";
- children += ")";
+ children += indentation(depth) + ")";
return children;
}
}
-
Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/dagitem.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/dagitem.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/dagitem.h 2012-03-22 10:26:48 EDT (Thu, 22 Mar 2012)
@@ -42,6 +42,10 @@
QString toString(); //DBG CL
private:
+ QString toString(int depth); //DBG CL
+
+
+private:
QList<DagItem*> childItems;
tVariVector itemData;
DagItem *parentItem;
Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.cpp
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.cpp (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.cpp 2012-03-22 10:26:48 EDT (Thu, 22 Mar 2012)
@@ -281,6 +281,15 @@
))
);
+ // Here I can change the headers by altering some attributes for root.
+ m_rootItem->setData(dag::node::posName, QVariant("Name"));
+ //JODO It is not possible to do this:
+ //m_rootItem->setData(dag::node::posId, QVariant("Id"));
+ //JODO So: Provide headers as strings before this point.
+
+ m_rootItem->setData(dag::node::posParentId, QVariant(0));
+ m_rootItem->setData(dag::node::posParentName, QVariant("Parent"));
+
return dagAsString;
}
@@ -322,8 +331,8 @@
if(!(source==0 && target==0))
{
boost::add_edge(source, target, m_dag);
- m_nodeAttributes[source] = (*iter)[m_parentName].toString();
- m_nodeAttributes[target] = (*iter)[m_childName].toString();
+ m_nodeAttributes[source] = NodeAttributes((*iter)[m_parentName].toString(), source);
+ m_nodeAttributes[target] = NodeAttributes((*iter)[m_childName].toString(), target);
}
}
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk