Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r76542 - sandbox/icl/libs/xplore/br1/sqlbrowser
From: afojgo_at_[hidden]
Date: 2012-01-16 12:02:21


Author: jofaber
Date: 2012-01-16 12:02:20 EST (Mon, 16 Jan 2012)
New Revision: 76542
URL: http://svn.boost.org/trac/boost/changeset/76542

Log:
Populating a DAG model from sql.
Binary files modified:
   sandbox/icl/libs/xplore/br1/sqlbrowser/objects1.db
Text files modified:
   sandbox/icl/libs/xplore/br1/sqlbrowser/ExtensibleObjectModel.sql | 16 +++---
   sandbox/icl/libs/xplore/br1/sqlbrowser/browser.cpp | 22 ++++++++-
   sandbox/icl/libs/xplore/br1/sqlbrowser/dagitem.cpp | 5 ++
   sandbox/icl/libs/xplore/br1/sqlbrowser/dagitem.h | 2
   sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.cpp | 93 +++++++++++++++++++++++++++------------
   sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.h | 8 ++-
   6 files changed, 102 insertions(+), 44 deletions(-)

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/ExtensibleObjectModel.sql
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/ExtensibleObjectModel.sql (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/ExtensibleObjectModel.sql 2012-01-16 12:02:20 EST (Mon, 16 Jan 2012)
@@ -30,10 +30,10 @@
 insert into Dag values (0, 1); -- (0:ROOT, 1:Songs)
 insert into Dag values (1, 2); -- (1:Songs, 2:Blues)
 insert into Dag values (2, 4); -- (2:Blues, 4:St.Louis Blues)
-insert into Dag values (2, 6); -- (2:Blues, 4:Blue Bossa)
+insert into Dag values (2, 6); -- (2:Blues, 6:Blue Bossa)
 insert into Dag values (1, 3); -- (1:Songs, 3:Latin)
-insert into Dag values (3, 5); -- (3:Latin, 4:Oye Come Va)
-insert into Dag values (3, 6); -- (3:Latin, 4:Blue Bossa)
+insert into Dag values (3, 5); -- (3:Latin, 5:Oye Come Va)
+insert into Dag values (3, 6); -- (3:Latin, 6:Blue Bossa)
 
 -- -----------------------------------------------------------------------------
 select Objects.name as Object, Types.name as Type, Dag.Child as ChildId, Dag.Parent as PatentId,
@@ -44,9 +44,9 @@
 
 -- -----------------------------------------------------------------------------
 -- The Dag in orderly fashion (parent->chiled) starting from root
-select Dag.Parent as PatentId, Dag.Child as ChildId,
+select Dag.Parent as ParentId, Dag.Child as ChildId,
   (select Objects.name from Objects where Objects.id = Dag.Parent) as Parent,
- Objects.name as Object, Types.name as Type
+ Objects.name as Child, Types.name as Type
   from Dag
   inner join Objects on Dag.Child = Objects.id
   inner join Types on Objects.TypeOf = Types.id
@@ -55,10 +55,10 @@
 
 -- ----------------------------------------------------------------------------
 create view Collections as
-select Dag.Parent as PatentId, Dag.Child as ChildId,
+select Dag.Parent as ParentId, Dag.Child as ChildId, Types.Id as TypeId,
   (select Objects.name from Objects where Objects.id = Dag.Parent) as Parent,
- Objects.name as Object, Types.name as Type
+ Objects.name as Child, Types.name as Type
   from Dag
- inner join Objects on Dag.Child = Objects.id
+ inner join Objects on Dag.Child = Objects.id
   inner join Types on Objects.TypeOf = Types.id
 

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-01-16 12:02:20 EST (Mon, 16 Jan 2012)
@@ -42,6 +42,7 @@
 #include "exttableview.h"
 #include "browser.h"
 #include "qsqlconnectiondialog.h"
+#include "dagmodel.h"
 
 #include <QtGui>
 #include <QtSql>
@@ -73,7 +74,22 @@
 void Browser::exec()
 {
     QSqlQueryModel *model = new QSqlQueryModel(ext_table);
- model->setQuery(QSqlQuery(sqlEdit->toPlainText(), connectionWidget->currentDatabase()));
+
+
+ QSqlQuery curQuery = QSqlQuery(sqlEdit->toPlainText(), connectionWidget->currentDatabase());
+
+ QStringList headers;
+ headers << tr("Title") << tr("Description");
+ DagModel* dagmo = new DagModel(headers);
+
+ QSqlQuery xpQuery = QSqlQuery("", connectionWidget->currentDatabase());
+ QString dbg_query = QString(sqlEdit->toPlainText());
+ xpQuery.exec(sqlEdit->toPlainText());
+ int dbg_size = xpQuery.size();
+ dagmo->fromSql(xpQuery);
+
+ model->setQuery(curQuery);
+ //REV? model->setQuery(QSqlQuery(sqlEdit->toPlainText(), connectionWidget->currentDatabase()));
 
     ext_table->setModel(model);
     ext_tree->setModel(model);//JOFA
@@ -81,7 +97,7 @@
     //JOFA additions ----------------------------------------------------------
     ext_table->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
 
- ext_table->setSortingEnabled(true);
+ //ext_table->setSortingEnabled(true);
     ext_table->setAlternatingRowColors(true);
     ext_table->resizeColumnsToContents();
     //JOFA additions ----------------------------------------------------------
@@ -200,7 +216,7 @@
     ext_table->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
 
     //JOFA additions ----------------------------------------------------------
- ext_table->setSortingEnabled(true);
+ //ext_table->setSortingEnabled(true);
     ext_table->setAlternatingRowColors(true);
     ext_table->resizeColumnsToContents();
     //JOFA additions ----------------------------------------------------------

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-01-16 12:02:20 EST (Mon, 16 Jan 2012)
@@ -83,6 +83,11 @@
     return true;
 }
 
+void DagItem::addChild(DagItem* child)
+{
+ childItems.push_back(child);
+}
+
 
 bool DagItem::insertColumns(int position, int columns)
 {

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-01-16 12:02:20 EST (Mon, 16 Jan 2012)
@@ -29,6 +29,8 @@
     int childNumber() const;
     bool setData(int column, const QVariant &value);
 
+ void addChild(DagItem* child);
+
 private:
     QList<DagItem*> childItems;
     QVector<QVariant> itemData;

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-01-16 12:02:20 EST (Mon, 16 Jan 2012)
@@ -9,7 +9,19 @@
 #include "dagitem.h"
 #include "dagmodel.h"
 
+DagModel::DagModel(const QStringList &headers, //const QString &data,
+ QObject *parent)
+ : QAbstractItemModel(parent)
+{
+ QVector<QVariant> rootData;
+ foreach (QString header, headers)
+ rootData << header;
 
+ //rootItem = new DagItem(rootData);
+ //setupModelData(data.split(QString("\n")), rootItem);
+}
+
+/* JODO
 DagModel::DagModel(const QStringList &headers, const QString &data,
                      QObject *parent)
     : QAbstractItemModel(parent)
@@ -21,7 +33,7 @@
     rootItem = new DagItem(rootData);
     setupModelData(data.split(QString("\n")), rootItem);
 }
-
+*/
 
 DagModel::~DagModel()
 {
@@ -248,55 +260,76 @@
     }
 }
 
-/*
 //JODO Populate a DagModel from an sql-query that provides the DAG as
 // (ParentId -> ChildId), ParentName, ChildName, ChildType
-void DagModel::fromSql(const QSqlQuery& query)
+void DagModel::fromSql(QSqlQuery& query)
 {
- //JODO create root node
     if(!query.next())
         return;
     else
     {
- //JODO fill root with info
+ //We skip the first record and its NIL information.
         fromSql(query, rootItem, 0);
     }
 }
 
-void DagModel::fromSql(const QSqlQuery& query, DagItem* parent, int depth)
+
+// The result indicates: False: No more data. True: Data available.
+DagItem* DagModel::fromSql(QSqlQuery& query, DagItem* parent, int depth)
 {
- Q_ASSERT(node != NULL);
+ // 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;
- else if(query.value(0).toInt() == parent->nodeId())
- { //Same node as before. Add a child. Recursing down
- DagItem* newChild = addChild(parent, query); //Fill Data
- //Ok, wont work. Building the DAG and traversing order of
- //the representing order of the db-data must match.
- }
+ return NULL;
     else
- { //Next
+ {
+ //create a node
+ QVector<QVariant> data;
+ //JODO REFA Function
+ int fieldCount = 6; //JODO retrieve from QSql
+ data.resize(fieldCount);
+
+ QSqlRecord rec = query.record();
+ int parentId = rec.indexOf("ParentId");
+ int childId = rec.indexOf("ChildId");
+ int typeId = rec.indexOf("TypeId");
+ int parentName = rec.indexOf("Parent");
+ int childName = rec.indexOf("Child");
+ int childType = rec.indexOf("Type");
+
+ int dbg_parentId = query.value(parentId).toInt();
+ int dbg_childId = query.value(childId).toInt();
+ int dbg_typeId = query.value(typeId).toInt();
+
+ data[parentId] = query.value(parentId);
+ data[childId] = query.value(childId);
+ data[typeId] = query.value(typeId);
+ data[parentName] = query.value(parentName);
+ data[childName] = query.value(childName);
+ data[childType] = query.value(childType);
+
+ DagItem* curNode = new DagItem(data, parent);
+ //if the new node is not a leaf, create children.
+ //JODO if(!curNode->IsLeaf())
+ if(data[typeId] != 2)
+ {
+ //While records available: Read children.
+ DagItem* curChild;
+ while((curChild = fromSql(query, curNode, depth+1)) != NULL)
+ {
+ curNode->addChild(curChild);
+ }
+ }
 
+ return curNode;
     }
 }
-*/
 
-/*
-void DagModel::fromSql(const QSqlQuery& query, DagItem* parent, int depth)
-{
- Q_ASSERT(node != NULL);
 
- if(!query.next())
- return;
- else
- {
- create a node
- if(! the new node is terminal)
- addChildren(query, newNode, depth+1);
- }
-}
-*/
 
 
 //JOFA Iteration example: The container as String

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-01-16 12:02:20 EST (Mon, 16 Jan 2012)
@@ -22,7 +22,9 @@
     Q_OBJECT
 
 public:
- DagModel(const QStringList &headers, const QString &data,
+ //DagModel(const QStringList &headers, const QString &data,
+ // QObject *parent = 0);
+ DagModel(const QStringList &headers, //const QString &data,
               QObject *parent = 0);
     ~DagModel();
 
@@ -54,9 +56,9 @@
 
 
     //JOFA Populating a DAG from an Sql-query
- void fromSql(const QSqlQuery& query);
+ void fromSql(QSqlQuery& query);
 
- void fromSql(const QSqlQuery& query, DagItem* node, int depth);
+ DagItem* fromSql(QSqlQuery& query, DagItem* node, int depth);
 
     //JOFA Iteration example: The container as String
     QString toString()const;

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


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