Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r79893 - in sandbox/icl/libs/xplore/br1/sqlbrowser: . Dag data/qsql
From: afojgo_at_[hidden]
Date: 2012-08-06 13:34:02


Author: jofaber
Date: 2012-08-06 13:34:00 EDT (Mon, 06 Aug 2012)
New Revision: 79893
URL: http://svn.boost.org/trac/boost/changeset/79893

Log:
Refactoring data access layer.
Removed:
   sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel2.cpp
   sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel2.h
Binary files modified:
   sandbox/icl/libs/xplore/br1/sqlbrowser/objects1.db
   sandbox/icl/libs/xplore/br1/sqlbrowser/objects1_abbeyRd.db
Text files modified:
   sandbox/icl/libs/xplore/br1/sqlbrowser/CreatorVisitor2.h | 36 +++++--------------
   sandbox/icl/libs/xplore/br1/sqlbrowser/Dag/DbBasedGraph.h | 4 +-
   sandbox/icl/libs/xplore/br1/sqlbrowser/Dag/DbType.h | 11 ++++-
   sandbox/icl/libs/xplore/br1/sqlbrowser/browser.cpp | 11 ++++-
   sandbox/icl/libs/xplore/br1/sqlbrowser/browser.h | 2
   sandbox/icl/libs/xplore/br1/sqlbrowser/dagitem.cpp | 32 ++++++++--------
   sandbox/icl/libs/xplore/br1/sqlbrowser/dagitem.h | 14 ++++--
   sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.cpp | 74 +++++++++++++++++----------------------
   sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.h | 18 +++-----
   sandbox/icl/libs/xplore/br1/sqlbrowser/data/qsql/QSqlCreator.h | 8 ++-
   sandbox/icl/libs/xplore/br1/sqlbrowser/sqlbrowser4.pro | 7 +--
   11 files changed, 103 insertions(+), 114 deletions(-)

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/CreatorVisitor2.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/CreatorVisitor2.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/CreatorVisitor2.h 2012-08-06 13:34:00 EDT (Mon, 06 Aug 2012)
@@ -41,25 +41,9 @@
         template<class Vertex, class Graph>
         void operator()(Vertex node, Graph& dag)
         {
- // "Visitation by descent". All nodes are reached through this function on
- // descend, which is always done first for "depth first search. Therefore
- // we can create all nodes for the Qt DagModel in this functor:
- //
- // Create a DagItem. The node that has been visited last should be the parent.
- // While we are descending, we build a chain going "down".
-
+ // "Visitation by descent". All nodes are reached through this function on descend.
             tVariVector itemData(dag::node::sizeOf_node); // ItemData node(id, name, ..)
- // will only by a part of the data from sql that represented
- // edges. Via r_attrs we only obtain associated node data
- // from the boost::graph
- //JODO dag::copyBoostNode2DagItem(r_attrs[node], itemData);
- //CL itemData[dag::node::posId] = QVariant(dag[node].key());
- //CL itemData[dag::node::posName] = QVariant(dag[node].name());
-
- dbg_str = QString("(%1)[%2] %3").arg(node).arg(dag[node].key()).arg(dag[node].name());
 
- // Discoverage is always on the way down. So we should maintain the invariant
- // p_curItem should be initialized to the DagModel's DatItem* rootItem
             Q_ASSERT(r_attrs[node].dagItem() != 0);
 
             if(boost::out_degree(node, dag) > 0)
@@ -67,7 +51,7 @@
                 *p_result += indentation(r_attrs[node].depth()) + "(";
                 *p_result += dag[node].name();
                 *p_result += QString(" d:%1").arg(r_attrs[node].depth());
- *p_result += " -> " + (p_curItem==0 ? QString("{}") : p_curItem->data()[dag::node::posName].toString());
+ *p_result += " -> " + (p_curItem==0 ? QString("{}") : (*(p_curItem->data()))[dag::node::posName].toString());
                 *p_result += "\n";
             }
         }
@@ -75,7 +59,6 @@
         DagItem* p_curItem;
         QString* p_result;
         Vertex2AttributesMap& r_attrs;
- QString dbg_str;
     };
 
     struct OnExamineEdge : public boost::base_visitor<OnExamineEdge>
@@ -105,16 +88,17 @@
             if(p_curItem != sourceDagItem)
                 p_curItem = sourceDagItem;
 
- if(targetDagItem)
- ; //CL sourceDagItem->addChild(targetDagItem);
- else
+ if(targetDagItem == 0)
             {
                 tVariVector itemData(dag::node::sizeOf_node);
- //JODO dag::copyBoostNode2DagItem(r_attrs[target_node], itemData);
- itemData[dag::node::posId] = QVariant(dag[target_node].key());
- itemData[dag::node::posName] = QVariant(dag[target_node].name());
+ itemData[dag::node::posId] = QVariant( QString("%1 %2").arg(dag[source_node].name()).arg(dag[edge].typeShortName()) );
+ itemData[dag::node::posName] = QVariant( dag[target_node].name());
+ //itemData[dag::node::posName] = QVariant(dag[target_node].name());
+ //JODO Dag::copyVertex2DagItem(r_attrs[target_node], itemData);
+
+ //CL 6 DagItem* newDagItem = new DagItem(itemData, p_curItem);
+ DagItem* newDagItem = new DagItem(makeShared<tVariVector>(itemData), p_curItem);
 
- 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));

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/Dag/DbBasedGraph.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/Dag/DbBasedGraph.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/Dag/DbBasedGraph.h 2012-08-06 13:34:00 EDT (Mon, 06 Aug 2012)
@@ -20,7 +20,7 @@
 #include "CreatorVisitor2.h"
 
 class QSqlQuery;
-class DagModel2;
+class DagModel;
 
 namespace dag { namespace db
 {
@@ -171,7 +171,7 @@
         return tygraAsString;
     }
 
- tString makeDagModel(DagModel2* dagmo)
+ tString makeDagModel(DagModel* dagmo)
     {
         typedef DbBasedGraph::vertex_descriptor vertex_descriptor;
         //Add an associative color map type.

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/Dag/DbType.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/Dag/DbType.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/Dag/DbType.h 2012-08-06 13:34:00 EDT (Mon, 06 Aug 2012)
@@ -136,12 +136,13 @@
 public:
     EdgeType(){}
 
- EdgeType(tKey iKey, tKey iSrc, tKey iRel, tKey iTrg, const tString& aName)
+ EdgeType(tKey iKey, tKey iSrc, tKey iRel, tKey iTrg, const tString& aName, const tString& shortName)
         : m_iKey(iKey)
         , m_iRefSourceType(iSrc)
         , m_iRefRelationType(iRel)
         , m_iRefTargetType(iTrg)
         , m_aName(aName)
+ , m_shortName(shortName)
     {}
 
     QString toString()const
@@ -151,6 +152,7 @@
     tKey sourceKey()const { return m_iRefSourceType; }
     tKey targetKey()const { return m_iRefTargetType; }
     QString typeName()const { return m_aName; }
+ QString typeShortName()const { return m_shortName; }
 
 private:
     tKey m_iKey;
@@ -158,6 +160,7 @@
     tKey m_iRefRelationType;
     tKey m_iRefTargetType;
     tString m_aName;
+ tString m_shortName;
 };
 
 
@@ -213,10 +216,10 @@
 
     Edge(): m_key(), m_refEdgeType(), m_refSourceVertex(), m_refTargetVertex(){};
 
- explicit Edge(tKey key, tKey refEdgeType, tKey sourceKey, tKey targetKey, QString typeName)
+ explicit Edge(tKey key, tKey refEdgeType, tKey sourceKey, tKey targetKey, QString typeName, QString typeShortName)
         : m_key(key), m_refEdgeType(refEdgeType)
         , m_refSourceVertex(sourceKey), m_refTargetVertex(targetKey)
- , m_edgeTypeName(typeName)
+ , m_edgeTypeName(typeName), m_edgeTypeShortName(typeShortName)
     {};
 
     tKey key()const { m_key; }
@@ -224,6 +227,7 @@
     tKey refSourceVertex()const { return m_refSourceVertex; }
     tKey refTargetVertex()const { return m_refTargetVertex; }
     QString typeName()const { return m_edgeTypeName; }
+ QString typeShortName()const { return m_edgeTypeShortName; }
 
     tKey sourceKey()const { return m_refSourceVertex; }
     tKey targetKey()const { return m_refTargetVertex; }
@@ -237,6 +241,7 @@
     tKey m_refSourceVertex;
     tKey m_refTargetVertex;
     QString m_edgeTypeName;
+ QString m_edgeTypeShortName;
     //JODO Object m_object; //The object that is referec my m_key.
 };
 

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-08-06 13:34:00 EDT (Mon, 06 Aug 2012)
@@ -43,7 +43,6 @@
 #include "browser.h"
 #include "qsqlconnectiondialog.h"
 #include "dagmodel.h"
-#include "dagmodel2.h"
 
 #include <QtGui>
 #include <QtSql>
@@ -251,10 +250,16 @@
     util::launchMsgBox(ogra.depthFirstString());
 
     //--------------------------------------------------------------------------
- DagModel2* dagmo = new DagModel2(); // Dag-Model
+ DagModel* dagmo = new DagModel(); // Dag-Model
     QString dbg_dagString = ogra.makeDagModel(dagmo);
     util::launchMsgBox(dbg_dagString);
+ dagmo->setHeaderData(0, Qt::Horizontal, "");
+ dagmo->setHeaderData(1, Qt::Horizontal, "Object");
+ dagmo->setHeaderData(2, Qt::Horizontal, "Type");
     ext_tree->setModel(dagmo);
+ ext_tree->resizeColumnToContents(0);
+ ext_tree->resizeColumnToContents(1);
+ ext_tree->resizeColumnToContents(2);
     //--------------------------------------------------------------------------
 
     if(success)
@@ -320,6 +325,7 @@
     return success;
 }
 
+/*CL after refa
 void Browser::rexec()
 {
     QSqlQueryModel *model = new QSqlQueryModel(ext_table);
@@ -373,6 +379,7 @@
 
     updateActions();
 }
+*/
 
 QSqlError Browser::addConnection(const QString &driver, const QString &dbName, const QString &host,
                             const QString &user, const QString &passwd, int port)

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/browser.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/browser.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/browser.h 2012-08-06 13:34:00 EDT (Mon, 06 Aug 2012)
@@ -73,7 +73,7 @@
 
 public slots:
     void exec();
- void rexec();
+ //CL after refa: void rexec();
     bool runScript();
     bool execMulti(QSqlQuery& query, const QString& script);
     QSqlTableModel* showTable(const QString &table);

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-08-06 13:34:00 EDT (Mon, 06 Aug 2012)
@@ -14,14 +14,13 @@
 #include "Dag.h"
 #include "dagitem.h"
 
-DagItem::DagItem(const QVector<QVariant> &data, DagItem *parent)
+DagItem::DagItem(const tSharedData& data, DagItem *parent)
+ : parentItem(parent), itemData(data)
 {
- parentItem = parent;
- itemData = data;
 }
 
 /*JODO First step: Treat the dag like a tree. Introduce multiple parents later.
-DagItem::DagItem(const QVector<QVariant> &data, QList<DagItem*>& parents, int parentIdx)
+DagItem::DagItem(const tVariVector &data, QList<DagItem*>& parents, int parentIdx)
 {
     Q_ASSERT(0 < parents.size())
     Q_ASSERT(0 <= parentIdx && parentIdx < parents.size());
@@ -60,13 +59,13 @@
 
 int DagItem::columnCount() const
 {
- return itemData.count();
+ return itemData->count();
 }
 
 
 QVariant DagItem::data(int column) const
 {
- return itemData.value(column);
+ return itemData->value(column);
 }
 
 
@@ -76,8 +75,9 @@
         return false;
 
     for (int row = 0; row < count; ++row) {
- QVector<QVariant> data(columns);
- DagItem *item = new DagItem(data, this);
+ tVariVector data(columns);
+ //CL 2 DagItem *item = new DagItem(data, this);
+ DagItem *item = new DagItem(makeShared<tVariVector>(data), this);
         childItems.insert(position, item);
     }
 
@@ -92,11 +92,11 @@
 
 bool DagItem::insertColumns(int position, int columns)
 {
- if (position < 0 || position > itemData.size())
+ if (position < 0 || position > itemData->size())
         return false;
 
     for (int column = 0; column < columns; ++column)
- itemData.insert(position, QVariant());
+ itemData->insert(position, QVariant());
 
     foreach (DagItem *child, childItems)
         child->insertColumns(position, columns);
@@ -125,11 +125,11 @@
 
 bool DagItem::removeColumns(int position, int columns)
 {
- if (position < 0 || position + columns > itemData.size())
+ if (position < 0 || position + columns > itemData->size())
         return false;
 
     for (int column = 0; column < columns; ++column)
- itemData.remove(position);
+ itemData->remove(position);
 
     foreach (DagItem *child, childItems)
         child->removeColumns(position, columns);
@@ -140,10 +140,10 @@
 
 bool DagItem::setData(int column, const QVariant &value)
 {
- if (column < 0 || column >= itemData.size())
+ if (column < 0 || column >= itemData->size())
         return false;
 
- itemData[column] = value;
+ (*itemData)[column] = value;
     return true;
 }
 
@@ -156,11 +156,11 @@
 QString DagItem::toString(int depth)
 {
     if(childCount()==0)
- return indentation(depth) + itemData[dag::node::posName].toString();
+ return indentation(depth) + (*itemData)[dag::node::posName].toString();
     else
     {
         QString children = indentation(depth) + "(";
- children += itemData[dag::node::posName].toString() + "\n";
+ children += (*itemData)[dag::node::posName].toString() + "\n";
 
         for(int idx=0; idx < childCount(); idx++)
             children += child(idx)->toString(depth+1) + "\n";

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-08-06 13:34:00 EDT (Mon, 06 Aug 2012)
@@ -6,12 +6,17 @@
 #ifndef DAGITEM_H
 #define DAGITEM_H
 
+#include <boost/shared_ptr.hpp>
 #include <QList>
 #include <QVariant>
 #include <QVector>
 
+#include "util/SharedPtr.h"
+
 
 typedef QVector<QVariant> tVariVector;
+typedef boost::shared_ptr<tVariVector> tSharedData;
+
 
 class DagItem
 {
@@ -19,7 +24,7 @@
 
     static const int NodeType_Object = 2;
 
- DagItem(const tVariVector &data, DagItem *parent = 0);
+ DagItem(const tSharedData& data, DagItem *parent = 0);
     ~DagItem();
 
     DagItem *child(int number);
@@ -35,11 +40,10 @@
     bool setData(int column, const QVariant &value);
 
     void addChild(DagItem* child);
- bool isLeaf(int TypeId)const { return itemData[TypeId] == NodeType_Object; }
+ bool isLeaf(int TypeId)const { return (*itemData)[TypeId] == NodeType_Object; }
     DagItem* clone(DagItem* parent);
 
-
- tVariVector data()const { return itemData; }
+ tSharedData data()const { return itemData; }
 
     QString toString(); //DBG CL
 
@@ -49,7 +53,7 @@
 
 private:
     QList<DagItem*> childItems;
- tVariVector itemData;
+ tSharedData 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-08-06 13:34:00 EDT (Mon, 06 Aug 2012)
@@ -13,6 +13,9 @@
 
 using namespace boost;
 
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
 DagModel::DagModel(QObject *parent)
     : QAbstractItemModel(parent)
 {
@@ -20,31 +23,6 @@
 }
 
 
-/* JODO
-DagModel::DagModel(const QStringList &headers, const QString &data,
- QObject *parent)
- : QAbstractItemModel(parent)
-{
- QVector<QVariant> rootData;
- foreach (QString header, headers)
- rootData << header;
-
- m_rootItem = new DagItem(rootData);
- setupModelData(data.split(QString("\n")), m_rootItem);
-}
-*/
-
-DagItem* DagModel::createDagItem()
-{
- QVector<QVariant> rootData;
- rootData.resize(dag::node::sizeOf_node);
- rootData[dag::node::posId] = QVariant(0);
- rootData[dag::node::posName] = QVariant("NIL");
- return new DagItem(rootData);
-}
-
-
-
 DagModel::~DagModel()
 {
     delete m_rootItem;
@@ -56,6 +34,14 @@
     return m_rootItem->columnCount();
 }
 
+DagItem* DagModel::createDagItem()
+{
+ tVariVector rootData;
+ rootData.resize(dag::node::sizeOf_node);
+ rootData[dag::node::posId] = QVariant(0);
+ rootData[dag::node::posName] = QVariant("NIL");
+ return new DagItem(makeShared<tVariVector>(rootData));
+}
 
 QVariant DagModel::data(const QModelIndex &index, int role) const
 {
@@ -125,7 +111,7 @@
     return success;
 }
 
-void DagModel::insertVertex(QVector<QVariant>& edgeData, const QModelIndex& index)
+void DagModel::insertVertex(tVariVector& edgeData, const QModelIndex& index)
 {
     // Insert the vretex (via edge) into the Dag
     dagInsertVertex(edgeData, index);
@@ -133,21 +119,21 @@
     modelInsertVertex(edgeData, index);
 }
 
-void DagModel::dagInsertVertex(QVector<QVariant>& edgeData, const QModelIndex& index)
+void DagModel::dagInsertVertex(tVariVector& edgeData, const QModelIndex& index)
 {
     int source = edgeData[m_parentId].toInt();
     int target = edgeData[m_childId].toInt();
     if(!(source==0 && target==0))
     {
         //JOFA MEMO: Build the graph: Add edges.
- boost::add_edge(source, target, m_dag);
+ m_dag.add_edge(source, target);
         //JOFA MEMO: Fill the associated objects. Aka. decorate the graph.
         m_aVertexAttributes[source] = VertexAttributes(source, edgeData[m_parentName].toString());
         m_aVertexAttributes[target] = VertexAttributes(target, edgeData[m_childName].toString());
     }
 }
 
-void DagModel::modelInsertVertex(QVector<QVariant>& edgeData, const QModelIndex& index)
+void DagModel::modelInsertVertex(tVariVector& edgeData, const QModelIndex& index)
 {
     // Create a new vertex or DagItem and append it a the node inicated by 'index'
     // PRE: index is valid and points to the parent node of insertion.
@@ -163,7 +149,8 @@
     childData[dag::node::posParentId] = edgeData[dag::edge::posParentId];
     childData[dag::node::posName] = edgeData[dag::edge::posChildName];
     childData[dag::node::posParentName] = edgeData[dag::edge::posParentName];
- DagItem* childNode = new DagItem(childData, parentNode);
+ //CL 4 DagItem* childNode = new DagItem(childData, parentNode);
+ DagItem* childNode = new DagItem(makeShared<tVariVector>(childData), parentNode);
 
     parentNode->addChild(childNode);
 }
@@ -282,7 +269,7 @@
         if (!lineData.isEmpty()) {
             // Read the column data from the rest of the line.
             QStringList columnStrings = lineData.split("\t", QString::SkipEmptyParts);
- QVector<QVariant> columnData;
+ tVariVector columnData;
             for (int column = 0; column < columnStrings.count(); ++column)
                 columnData << columnStrings[column];
 
@@ -315,7 +302,7 @@
 QString DagModel::setupDag()
 {
     QString dagAsString; //JODO CL
-
+ /*
     boost::depth_first_search(
         m_dag
       , boost::visitor(make_dfs_visitor(boost::make_list(
@@ -334,7 +321,7 @@
 
     m_rootItem->setData(dag::node::posParentId, QVariant(0));
     m_rootItem->setData(dag::node::posParentName, QVariant("Parent"));
-
+ */
     return dagAsString;
 }
 
@@ -343,7 +330,7 @@
     while(query.next())
     {
         //create an edge
- QVector<QVariant> data;
+ tVariVector data;
         //fill node
         fillData(data, query);
         m_edges.append(data);
@@ -365,6 +352,7 @@
     }
 }
 
+/*CL
 void DagModel::makeDag()
 {
     m_dag.clear();
@@ -383,11 +371,13 @@
         }
     }
 }
+*/
 
 QString DagModel::dagToString()
 {
     QString dagAsString;
-
+ m_dag.depthFirstString();
+/*
     boost::depth_first_search(
         m_dag
       , boost::visitor(make_dfs_visitor(boost::make_list(
@@ -398,7 +388,7 @@
                                             )
                       ))
     );
-
+*/
     return dagAsString;
 }
 
@@ -418,12 +408,14 @@
     else
     {
         //create a node
- QVector<QVariant> data;
+ tVariVector data;
         //fill node
         fillData(data, query);
 
- DagItem* curNode = (depth==0) ? new DagItem(data, 0) //curNode==m_rootItem
- : new DagItem(data, parent);
+ //DagItem* curNode = (depth==0) ? new DagItem(data, 0) //curNode==m_rootItem
+ //CL 5 : new DagItem(data, parent);
+ DagItem* curNode = (depth==0) ? new DagItem(makeShared<tVariVector>(data), 0) //curNode==m_rootItem
+ : new DagItem(makeShared<tVariVector>(data), parent);
         if(depth == 0)
             m_rootItem = curNode;
 
@@ -470,7 +462,7 @@
 }
 
 
-void DagModel::fillData(QVector<QVariant>& data, QSqlQuery& query)
+void DagModel::fillData(tVariVector& data, QSqlQuery& query)
 {
     QSqlRecord rec = query.record();
     data.resize(rec.count());
@@ -490,7 +482,7 @@
     data[m_childType] = query.value(m_childType);
 }
 
-void DagModel::fillDummyData(QVector<QVariant>& data, int nodeId)
+void DagModel::fillDummyData(tVariVector& data, int nodeId)
 {
     data[m_parentId] = QVariant(nodeId);
     data[m_childId] = QVariant(num_edges());

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.h 2012-08-06 13:34:00 EDT (Mon, 06 Aug 2012)
@@ -8,17 +8,12 @@
 
 #include <map>
 
-#include <boost/graph/graph_traits.hpp>
-#include <boost/graph/adjacency_list.hpp>
-#include <boost/graph/depth_first_search.hpp>
-#include <boost/graph/graph_utility.hpp>
-
 #include <QAbstractItemModel>
 #include <QModelIndex>
 #include <QVariant>
 
 #include "Dag.h"
-
+#include "Dag/ObjectGraph.h"
 
 
 class QSqlQuery;
@@ -65,7 +60,7 @@
     void getEdges(QSqlQuery& query);
     void fromSql(QSqlQuery& query);
 
- void makeDag();
+ //CL void makeDag();
 
     QString dagToString();
     QString setupDag();
@@ -79,8 +74,8 @@
 
     DagItem* rootItem()const { return m_rootItem; } //CL DBG
 
+ int num_edges()const { return m_dag.num_edges(); }
     //--------------------------------------------------------------------------
- int num_edges()const { return boost::num_edges(m_dag); }
 
 private:
     DagItem* item(const QModelIndex& index)const
@@ -126,9 +121,10 @@
 
     //==========================================================================
     // Graph
- Dag::type m_dag;
- Dag::tAttributesMap m_aVertexAttributes;
- Dag::tParentMap m_parentMap;
+ //CL Dag::type m_dag;
+ dag::db::ObjectGraph m_dag;
+ Dag::tAttributesMap m_aVertexAttributes;
+ Dag::tParentMap m_parentMap;
 };
 
 #endif

Deleted: sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel2.cpp
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel2.cpp 2012-08-06 13:34:00 EDT (Mon, 06 Aug 2012)
+++ (empty file)
@@ -1,491 +0,0 @@
-/****************************************************************************
-**
-**
-****************************************************************************/
-
-#include <QtGui>
-#include <QtSql>
-
-#include "dagitem.h"
-#include "dagmodel2.h"
-#include "StringVisitor.h"
-#include "CreatorVisitor.h"
-
-using namespace boost;
-
-
-//------------------------------------------------------------------------------
-//------------------------------------------------------------------------------
-DagModel2::DagModel2(QObject *parent)
- : QAbstractItemModel(parent)
-{
- m_rootItem = createDagItem();
-}
-
-
-DagModel2::~DagModel2()
-{
- delete m_rootItem;
-}
-
-
-int DagModel2::columnCount(const QModelIndex & /* parent */) const
-{
- return m_rootItem->columnCount();
-}
-
-DagItem* DagModel2::createDagItem()
-{
- QVector<QVariant> rootData;
- rootData.resize(dag::node::sizeOf_node);
- rootData[dag::node::posId] = QVariant(0);
- rootData[dag::node::posName] = QVariant("NIL");
- return new DagItem(rootData);
-}
-
-QVariant DagModel2::data(const QModelIndex &index, int role) const
-{
- if (!index.isValid())
- return QVariant();
-
- if (role != Qt::DisplayRole && role != Qt::EditRole)
- return QVariant();
-
- DagItem *item = getItem(index);
-
- return item->data(index.column());
-}
-
-
-Qt::ItemFlags DagModel2::flags(const QModelIndex &index) const
-{
- if (!index.isValid())
- return 0;
-
- return Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
-}
-
-
-DagItem *DagModel2::getItem(const QModelIndex &index) const
-{
- if (index.isValid()) {
- DagItem *item = static_cast<DagItem*>(index.internalPointer());
- if (item) return item;
- }
- return m_rootItem;
-}
-
-
-QVariant DagModel2::headerData(int section, Qt::Orientation orientation,
- int role) const
-{
- if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
- return m_rootItem->data(section);
-
- return QVariant();
-}
-
-
-QModelIndex DagModel2::index(int row, int column, const QModelIndex &parent) const
-{
- if (parent.isValid() && parent.column() != 0)
- return QModelIndex();
-
- DagItem *parentItem = getItem(parent);
-
- DagItem *childItem = parentItem->child(row);
- if (childItem)
- return createIndex(row, column, childItem);
- else
- return QModelIndex();
-}
-
-bool DagModel2::insertColumns(int position, int columns, const QModelIndex &parent)
-{
- bool success;
-
- beginInsertColumns(parent, position, position + columns - 1);
- success = m_rootItem->insertColumns(position, columns);
- endInsertColumns();
-
- return success;
-}
-
-void DagModel2::insertVertex(QVector<QVariant>& edgeData, const QModelIndex& index)
-{
- // Insert the vretex (via edge) into the Dag
- dagInsertVertex(edgeData, index);
- // Insert the vertex into the DagModel2
- modelInsertVertex(edgeData, index);
-}
-
-void DagModel2::dagInsertVertex(QVector<QVariant>& edgeData, const QModelIndex& index)
-{
- int source = edgeData[m_parentId].toInt();
- int target = edgeData[m_childId].toInt();
- if(!(source==0 && target==0))
- {
- //JOFA MEMO: Build the graph: Add edges.
- m_dag.add_edge(source, target);
- //JOFA MEMO: Fill the associated objects. Aka. decorate the graph.
- m_aVertexAttributes[source] = VertexAttributes(source, edgeData[m_parentName].toString());
- m_aVertexAttributes[target] = VertexAttributes(target, edgeData[m_childName].toString());
- }
-}
-
-void DagModel2::modelInsertVertex(QVector<QVariant>& edgeData, const QModelIndex& index)
-{
- // Create a new vertex or DagItem and append it a the node inicated by 'index'
- // PRE: index is valid and points to the parent node of insertion.
-
- //fill node data. The target node is 'new'
- fillDummyData(edgeData, index.data().toInt());
-
- DagItem* parentNode = item(index);
- Q_ASSERT(parentNode != 0);
-
- tVariVector childData(dag::node::sizeOf_node);
- childData[dag::node::posId] = edgeData[dag::edge::posChildId];
- childData[dag::node::posParentId] = edgeData[dag::edge::posParentId];
- childData[dag::node::posName] = edgeData[dag::edge::posChildName];
- childData[dag::node::posParentName] = edgeData[dag::edge::posParentName];
- DagItem* childNode = new DagItem(childData, parentNode);
-
- parentNode->addChild(childNode);
-}
-
-bool DagModel2::insertRows(int position, int rows, const QModelIndex &parent)
-{
- DagItem *parentItem = getItem(parent);
- bool success;
-
- beginInsertRows(parent, position, position + rows - 1);
- success = parentItem->insertChildren(position, rows, m_rootItem->columnCount());
- endInsertRows();
-
- return success;
-}
-
-
-QModelIndex DagModel2::parent(const QModelIndex &index) const
-{
- if (!index.isValid())
- return QModelIndex();
-
- DagItem *childItem = getItem(index);
- DagItem *parentItem = childItem->parent();
-
- if (parentItem == m_rootItem)
- return QModelIndex();
-
- return createIndex(parentItem->childNumber(), 0, parentItem);
-}
-
-
-bool DagModel2::removeColumns(int position, int columns, const QModelIndex &parent)
-{
- bool success;
-
- beginRemoveColumns(parent, position, position + columns - 1);
- success = m_rootItem->removeColumns(position, columns);
- endRemoveColumns();
-
- if (m_rootItem->columnCount() == 0)
- removeRows(0, rowCount());
-
- return success;
-}
-
-bool DagModel2::removeRows(int position, int rows, const QModelIndex &parent)
-{
- DagItem *parentItem = getItem(parent);
- bool success = true;
-
- beginRemoveRows(parent, position, position + rows - 1);
- success = parentItem->removeChildren(position, rows);
- endRemoveRows();
-
- return success;
-}
-
-
-int DagModel2::rowCount(const QModelIndex &parent) const
-{
- DagItem *parentItem = getItem(parent);
-
- return parentItem->childCount();
-}
-
-
-bool DagModel2::setData(const QModelIndex &index, const QVariant &value,
- int role)
-{
- if (role != Qt::EditRole)
- return false;
-
- DagItem *item = getItem(index);
- bool result = item->setData(index.column(), value);
-
- if (result)
- emit dataChanged(index, index);
-
- return result;
-}
-
-bool DagModel2::setHeaderData(int section, Qt::Orientation orientation,
- const QVariant &value, int role)
-{
- if (role != Qt::EditRole || orientation != Qt::Horizontal)
- return false;
-
- bool result = m_rootItem->setData(section, value);
-
- if (result)
- emit headerDataChanged(orientation, section, section);
-
- return result;
-}
-
-void DagModel2::setupModelData(const QStringList &lines, DagItem *parent)
-{
- QList<DagItem*> parents;
- QList<int> indentations;
- parents << parent;
- indentations << 0;
-
- int number = 0;
-
- while (number < lines.count()) {
- int position = 0;
- while (position < lines[number].length()) {
- if (lines[number].mid(position, 1) != " ")
- break;
- position++;
- }
-
- QString lineData = lines[number].mid(position).trimmed();
-
- if (!lineData.isEmpty()) {
- // Read the column data from the rest of the line.
- QStringList columnStrings = lineData.split("\t", QString::SkipEmptyParts);
- QVector<QVariant> columnData;
- for (int column = 0; column < columnStrings.count(); ++column)
- columnData << columnStrings[column];
-
- if (position > indentations.last()) {
- // The last child of the current parent is now the new parent
- // unless the current parent has no children.
-
- if (parents.last()->childCount() > 0) {
- parents << parents.last()->child(parents.last()->childCount()-1);
- indentations << position;
- }
- } else {
- while (position < indentations.last() && parents.count() > 0) {
- parents.pop_back();
- indentations.pop_back();
- }
- }
-
- // Append a new item to the current parent's list of children.
- DagItem *parent = parents.last();
- parent->insertChildren(parent->childCount(), 1, m_rootItem->columnCount());
- for (int column = 0; column < columnData.size(); ++column)
- parent->child(parent->childCount() - 1)->setData(column, columnData[column]);
- }
-
- number++;
- }
-}
-
-QString DagModel2::setupDag()
-{
- QString dagAsString; //JODO CL
- /*
- boost::depth_first_search(
- m_dag
- , boost::visitor(make_dfs_visitor(boost::make_list(
- CreatorVisitor::OnDiscoverVertex(m_rootItem, &dagAsString, m_aVertexAttributes)
- , CreatorVisitor::OnExamineEdge (m_rootItem, &dagAsString, m_aVertexAttributes)
- , CreatorVisitor::OnFinishVertex (m_rootItem, &dagAsString, m_aVertexAttributes)
- )
- ))
- );
-
- // 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;
-}
-
-void DagModel2::getEdges(QSqlQuery& query)
-{
- while(query.next())
- {
- //create an edge
- QVector<QVariant> data;
- //fill node
- fillData(data, query);
- m_edges.append(data);
- }
-}
-
-
-
-//JODO Populate a DagModel2 from an sql-query that provides the DAG as
-// (ParentId -> ChildId), ParentName, ChildName, ChildType
-void DagModel2::fromSql(QSqlQuery& query)
-{
- if(!query.next())
- return;
- else
- {
- //We skip the first record and its NIL information.
- fromSql(query, m_rootItem, 0);
- }
-}
-
-/*CL
-void DagModel2::makeDag()
-{
- m_dag.clear();
-
- m_aVertexAttributes = get(Dag::vertex_attr_tag(), m_dag);
-
- for(tEdgeList::iterator iter = m_edges.begin(); iter != m_edges.end(); iter++)
- {
- int source = (*iter)[m_parentId].toInt();
- int target = (*iter)[m_childId].toInt();
- if(!(source==0 && target==0))
- {
- boost::add_edge(source, target, m_dag);
- m_aVertexAttributes[source] = VertexAttributes(source, (*iter)[m_parentName].toString());
- m_aVertexAttributes[target] = VertexAttributes(target, (*iter)[m_childName].toString());
- }
- }
-}
-*/
-
-QString DagModel2::dagToString()
-{
- QString dagAsString;
- m_dag.depthFirstString();
-/*
- boost::depth_first_search(
- m_dag
- , boost::visitor(make_dfs_visitor(boost::make_list(
- StringVisitor::OnDiscoverVertex(&dagAsString, m_aVertexAttributes)
- , StringVisitor::OnExamineEdge(&dagAsString, m_aVertexAttributes, m_parentMap)
- , StringVisitor::OnFinishVertex(&dagAsString, m_aVertexAttributes)
- //, boost::record_predecessors(parentMap.begin(), boost::on_tree_edge())
- )
- ))
- );
-*/
- return dagAsString;
-}
-
-
-
-// The result indicates: False: No more data. True: Data available.
-DagItem* DagModel2::fromSql(QSqlQuery& query, DagItem* parent, int depth)
-{
- // The function assumes, that the dags "expanded tree" exists in
- // pre-order (the order, that is finally presented). This makes the
- // traversal specifically simple.
- Q_ASSERT(parent != NULL);
-
- // Get the next record
- if(!query.next())
- return NULL;
- else
- {
- //create a node
- QVector<QVariant> data;
- //fill node
- fillData(data, query);
-
- DagItem* curNode = (depth==0) ? new DagItem(data, 0) //curNode==m_rootItem
- : new DagItem(data, parent);
- if(depth == 0)
- m_rootItem = curNode;
-
- //if the new node is not a leaf, create children.
- if(!curNode->isLeaf(m_typeId))
- {
- //While records available: Read children.
- DagItem* curChild;
- while((curChild = fromSql(query, curNode, depth+1)) != NULL)
- {
- curNode->addChild(curChild);
- }
- }
-
- return curNode;
- }
-}
-
-
-//JOFA Iteration example: The container as String
-QString DagModel2::toString()const
-{
- return nodeToString(m_rootItem, 0);
-}
-
-QString DagModel2::nodeToString(DagItem* node, int depth)const
-{
- if(node->childCount()==0)
- return tr("%1(%2)\n").arg(indentation(depth), depth); //Print only structure and depth.
- else
- {
- QString indent = indentation(depth);
-
- QVariant childNameV = node->data(m_childName);
- QString childName = childNameV.toString();
- QString nodeRepr( tr("%1[%2\n").arg(indentation(depth), childName) );
-
- for(int idx=0; idx<node->childCount(); idx++)
- nodeRepr += nodeToString(node->child(idx), depth+1);
-
- nodeRepr += tr("%1]\n").arg(indentation(depth));
- return nodeRepr;
- }
-}
-
-
-void DagModel2::fillData(QVector<QVariant>& data, QSqlQuery& query)
-{
- QSqlRecord rec = query.record();
- data.resize(rec.count());
-
- m_parentId = rec.indexOf("ParentId");
- m_childId = rec.indexOf("ChildId");
- m_typeId = rec.indexOf("TypeId");
- m_parentName = rec.indexOf("Parent");
- m_childName = rec.indexOf("Child");
- m_childType = rec.indexOf("Type");
-
- data[m_parentId] = query.value(m_parentId);
- data[m_childId] = query.value(m_childId);
- data[m_typeId] = query.value(m_typeId);
- data[m_parentName] = query.value(m_parentName);
- data[m_childName] = query.value(m_childName);
- data[m_childType] = query.value(m_childType);
-}
-
-void DagModel2::fillDummyData(QVector<QVariant>& data, int nodeId)
-{
- data[m_parentId] = QVariant(nodeId);
- data[m_childId] = QVariant(num_edges());
- data[m_typeId] = QVariant(1);
- data[m_parentName] = QVariant("Parent Name");
- data[m_childName] = QVariant("Child Name");
- data[m_childType] = QVariant(2);
-}
-

Deleted: sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel2.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel2.h 2012-08-06 13:34:00 EDT (Mon, 06 Aug 2012)
+++ (empty file)
@@ -1,130 +0,0 @@
-/****************************************************************************
-**
-**
-****************************************************************************/
-
-#ifndef DAGMODEL2_H
-#define DAGMODEL2_H
-
-#include <map>
-
-#include <QAbstractItemModel>
-#include <QModelIndex>
-#include <QVariant>
-
-#include "Dag.h"
-#include "Dag/ObjectGraph.h"
-
-
-class QSqlQuery;
-class DagItem;
-
-class DagModel2 : public QAbstractItemModel
-{
- Q_OBJECT
-
-public:
- //DagModel2(const QStringList &headers, const QString &data,
- // QObject *parent = 0);
- DagModel2(QObject *parent = 0);
- ~DagModel2();
-
- QVariant data(const QModelIndex &index, int role) const;
- QVariant headerData(int section, Qt::Orientation orientation,
- int role = Qt::DisplayRole) const;
-
- QModelIndex index(int row, int column,
- const QModelIndex &parent = QModelIndex()) const;
- QModelIndex parent(const QModelIndex &index) const;
-
- int rowCount(const QModelIndex &parent = QModelIndex()) const;
- int columnCount(const QModelIndex &parent = QModelIndex()) const;
-
- Qt::ItemFlags flags(const QModelIndex &index) const;
- bool setData(const QModelIndex &index, const QVariant &value,
- int role = Qt::EditRole);
- bool setHeaderData(int section, Qt::Orientation orientation,
- const QVariant &value, int role = Qt::EditRole);
-
- bool insertColumns(int position, int columns,
- const QModelIndex &parent = QModelIndex());
- bool removeColumns(int position, int columns,
- const QModelIndex &parent = QModelIndex());
- bool insertRows(int position, int rows,
- const QModelIndex &parent = QModelIndex());
- bool removeRows(int position, int rows,
- const QModelIndex &parent = QModelIndex());
-
- //--------------------------------------------------------------------------
- //JOFA Populating a DAG from an Sql-query
- void getEdges(QSqlQuery& query);
- void fromSql(QSqlQuery& query);
-
- //CL void makeDag();
-
- QString dagToString();
- QString setupDag();
-
- DagItem* fromSql(QSqlQuery& query, DagItem* node, int depth);
-
- //JOFA Iteration example: The container as String
- QString toString()const;
-
- QString nodeToString(DagItem* node, int depth)const;
-
- DagItem* rootItem()const { return m_rootItem; } //CL DBG
-
- int num_edges()const { return m_dag.num_edges(); }
- //--------------------------------------------------------------------------
-
-private:
- DagItem* item(const QModelIndex& index)const
- {
- if (!index.isValid())
- return 0;
- return static_cast<DagItem*>(index.internalPointer());
- }
-
- DagItem* createDagItem();
-
- void setupModelData(const QStringList &lines, DagItem *parent);
-
- DagItem *getItem(const QModelIndex &index) const;
-
- void fillData(QVector<QVariant>& data, QSqlQuery& query);
-
-public:
- // Fill edge with dummy data. JODO CL later
- void fillDummyData(QVector<QVariant>& data, int nodeId);
-
- void appendEdge(QVector<QVariant>& data){ m_edges.append(data);}//CL
-
- void insertVertex(QVector<QVariant>& edgeData, const QModelIndex& index);
-
-private:
- void dagInsertVertex(QVector<QVariant>& edgeData, const QModelIndex& index);
- void modelInsertVertex(QVector<QVariant>& edgeData, const QModelIndex& index);
-
-private:
- DagItem *m_rootItem;
-
- int m_parentId ;
- int m_childId ;
- int m_typeId ;
- int m_parentName;
- int m_childName ;
- int m_childType ;
-
- typedef QVector<QVariant> tEdgeData;
- typedef QList<tEdgeData> tEdgeList;
- tEdgeList m_edges;
-
- //==========================================================================
- // Graph
- //CL Dag::type m_dag;
- dag::db::ObjectGraph m_dag;
- Dag::tAttributesMap m_aVertexAttributes;
- Dag::tParentMap m_parentMap;
-};
-
-#endif

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/data/qsql/QSqlCreator.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/data/qsql/QSqlCreator.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/data/qsql/QSqlCreator.h 2012-08-06 13:34:00 EDT (Mon, 06 Aug 2012)
@@ -30,7 +30,7 @@
 class QSqlCreator<dag::db::EdgeType, QSqlSelector>
 {
 public:
- enum { eKey=0, eRefSourceType, eRefRelationType, eRefTargetType, eName };
+ enum { eKey=0, eRefSourceType, eRefRelationType, eRefTargetType, eName, eShortName };
 
     typedef QSqlCreator type;
     typedef dag::db::EdgeType tObject;
@@ -52,6 +52,7 @@
                                  ,(*it).field(eRefRelationType).value().toInt()
                                  ,(*it).field(eRefTargetType).value().toInt()
                                  ,(*it).field(eName).value().toString()
+ ,(*it).field(eShortName).value().toString()
                                 );
     }
 };
@@ -103,7 +104,7 @@
 class QSqlCreator<dag::db::Edge, QSqlSelector>
 {
 public:
- enum { e_key=0, e_refEdgeType, e_refSourceVertex, e_refTargetVertex, e_edgeTypeName };
+ enum { e_key=0, e_refEdgeType, e_refSourceVertex, e_refTargetVertex, e_edgeTypeName, e_edgeTypeShortName };
 
     typedef QSqlCreator type;
     typedef dag::db::Edge tObject;
@@ -115,7 +116,7 @@
     static SqlQuery::tRepr createQuery()
     {
         return
- "select Edge.key, Edge.refEdgeType, Edge.refSourceVertex, Edge.refTargetVertex, EdgeType.name from Edge "
+ "select Edge.key, Edge.refEdgeType, Edge.refSourceVertex, Edge.refTargetVertex, EdgeType.name, EdgeType.shortname from Edge "
             " left outer join EdgeType on Edge.refEdgeType = EdgeType.key " ;
     }
 
@@ -126,6 +127,7 @@
                              ,(*it).field(e_refSourceVertex).value().toInt()
                              ,(*it).field(e_refTargetVertex).value().toInt()
                              ,(*it).field(e_edgeTypeName).value().toString()
+ ,(*it).field(e_edgeTypeShortName).value().toString()
                             );
     }
 };

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/objects1.db
==============================================================================
Binary files. No diff available.

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/objects1_abbeyRd.db
==============================================================================
Binary files. No diff available.

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/sqlbrowser4.pro
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/sqlbrowser4.pro (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/sqlbrowser4.pro 2012-08-06 13:34:00 EDT (Mon, 06 Aug 2012)
@@ -37,8 +37,8 @@
     Dag/ObjectGraph.h \
     Dag/DbBasedGraph.h \
     data/concept/DbBasedGraph.h \
- dagmodel2.h \
- CreatorVisitor2.h
+ CreatorVisitor2.h \
+ util/SharedPtr.h
 SOURCES = main.cpp browser.cpp connectionwidget.cpp qsqlconnectiondialog.cpp \
     exttableview.cpp \
     dagitem.cpp \
@@ -49,8 +49,7 @@
     gen/NumberGenerator.cpp \
     gen/DbGenerator.cpp \
     util/TestBoxes.cpp \
- data/concept/TypeGraphFunc.cpp \
- dagmodel2.cpp
+ data/concept/TypeGraphFunc.cpp
 
 FORMS = browserwidget.ui qsqlconnectiondialog.ui
 build_all:!build_pass {


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