Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77780 - sandbox/icl/libs/xplore/br1/sqlbrowser
From: afojgo_at_[hidden]
Date: 2012-04-05 09:52:41


Author: jofaber
Date: 2012-04-05 09:52:40 EDT (Thu, 05 Apr 2012)
New Revision: 77780
URL: http://svn.boost.org/trac/boost/changeset/77780

Log:
Incremental edge inserts.
Text files modified:
   sandbox/icl/libs/xplore/br1/sqlbrowser/browser.cpp | 24 ++++-----------------
   sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.cpp | 44 ++++++++++++++++++++++++++++++++++++++-
   sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.h | 15 ++++++++++++
   3 files changed, 61 insertions(+), 22 deletions(-)

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-04-05 09:52:40 EDT (Thu, 05 Apr 2012)
@@ -115,12 +115,12 @@
     QModelIndex idIndex = index.sibling(index.row(), dag::node::posId);
 
     //create an edge, fill as dummy and append.
- QVector<QVariant> data(dag::edge::sizeOf_edge);
- pDagModel->fillDummyData(data, idIndex.data().toInt());
- pDagModel->appendEdge(data);
- pDagModel->makeDag();
+ QVector<QVariant> edgeData(dag::edge::sizeOf_edge);
+ pDagModel->fillDummyData(edgeData, idIndex.data().toInt());
 
- pDagModel->setupDag();
+ //Insert the dummy edge into DagModel (keeping the Dag consistent also)
+ //CL.. pDagModel->appendEdge(data);
+ pDagModel->insertVertex(edgeData, idIndex);
 }
 
 
@@ -149,20 +149,6 @@
     dagmo->getEdges(xpQuery); //Read edges from database
     dagmo->makeDag(); //Make a boost::graph internally
 
- /*CL DBG Controlling the Dag via string output
- QMessageBox msgBox;
- //QString dagStr = dagmo->toString();
- //QString dagStr = dagmo->dagToString();
- 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);
- msgBox.exec();
- */
-
     QString dagStr = dagmo->setupDag(); //Build a tree representation from the boost::dag
 
     model->setQuery(curQuery);

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-04-05 09:52:40 EDT (Thu, 05 Apr 2012)
@@ -114,7 +114,6 @@
         return QModelIndex();
 }
 
-
 bool DagModel::insertColumns(int position, int columns, const QModelIndex &parent)
 {
     bool success;
@@ -126,6 +125,47 @@
     return success;
 }
 
+void DagModel::insertVertex(QVector<QVariant>& edgeData, const QModelIndex& index)
+{
+ // Insert the vretex (via edge) into the Dag
+ dagInsertVertex(edgeData, index);
+ // Insert the vertex into the DagModel
+ modelInsertVertex(edgeData, index);
+}
+
+void DagModel::dagInsertVertex(QVector<QVariant>& edgeData, const QModelIndex& index)
+{
+ int source = edgeData[m_parentId].toInt();
+ int target = edgeData[m_childId].toInt();
+ if(!(source==0 && target==0))
+ {
+ boost::add_edge(source, target, m_dag);
+ m_nodeAttributes[source] = NodeAttributes(edgeData[m_parentName].toString(), source);
+ m_nodeAttributes[target] = NodeAttributes(edgeData[m_childName].toString(), target);
+ }
+}
+
+void DagModel::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 DagModel::insertRows(int position, int rows, const QModelIndex &parent)
 {
     DagItem *parentItem = getItem(parent);
@@ -455,6 +495,6 @@
     data[m_typeId] = QVariant(1);
     data[m_parentName] = QVariant("Parent Name");
     data[m_childName] = QVariant("Child Name");
- data[m_childType] = QVariant(0);
+ data[m_childType] = QVariant(2);
 }
 

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-04-05 09:52:40 EDT (Thu, 05 Apr 2012)
@@ -85,6 +85,13 @@
     int num_edges()const { return boost::num_edges(m_dag); }
 
 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);
@@ -97,7 +104,13 @@
     // Fill edge with dummy data. JODO CL later
     void fillDummyData(QVector<QVariant>& data, int nodeId);
 
- void appendEdge(QVector<QVariant>& data){ m_edges.append(data);}
+ 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;


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