|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r77314 - sandbox/icl/libs/xplore/br1/sqlbrowser
From: afojgo_at_[hidden]
Date: 2012-03-12 13:14:36
Author: jofaber
Date: 2012-03-12 13:14:35 EDT (Mon, 12 Mar 2012)
New Revision: 77314
URL: http://svn.boost.org/trac/boost/changeset/77314
Log:
Populating a DAG model from sql. Tweaks.
Text files modified:
sandbox/icl/libs/xplore/br1/sqlbrowser/dagitem.h | 3 ++
sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.cpp | 53 +++++++++++++++++----------------------
sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.h | 10 +++++++
3 files changed, 36 insertions(+), 30 deletions(-)
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-12 13:14:35 EDT (Mon, 12 Mar 2012)
@@ -14,6 +14,8 @@
class DagItem
{
public:
+ static const int NodeType_Object = 2;
+
DagItem(const QVector<QVariant> &data, DagItem *parent = 0);
~DagItem();
@@ -30,6 +32,7 @@
bool setData(int column, const QVariant &value);
void addChild(DagItem* child);
+ bool isLeaf(int TypeId)const { return itemData[TypeId] == NodeType_Object; }
private:
QList<DagItem*> childItems;
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-12 13:14:35 EDT (Mon, 12 Mar 2012)
@@ -289,28 +289,8 @@
{
//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);
+ //fill node
+ fillData(data, query);
DagItem* curNode = (depth==0) ? new DagItem(data, 0) //curNode==rootItem
: new DagItem(data, parent);
@@ -318,16 +298,12 @@
rootItem = curNode;
//if the new node is not a leaf, create children.
- //JODO if(!curNode->IsLeaf())
- if(data[typeId] != 2)
+ if(!curNode->isLeaf(m_typeId))
{
//While records available: Read children.
DagItem* curChild;
while((curChild = fromSql(query, curNode, depth+1)) != NULL)
- {
curNode->addChild(curChild);
- int dbg_childCount = curNode->childCount(); //CL
- }
}
return curNode;
@@ -335,8 +311,6 @@
}
-
-
//JOFA Iteration example: The container as String
QString DagModel::toString()const
{
@@ -347,7 +321,6 @@
{
if(node->childCount()==0)
return tr("(%1)").arg(depth); //Print only structure and depth.
- //return tr("(%1)").arg(node->data(0));
else
{
QString nodeRepr(tr("["));
@@ -360,3 +333,23 @@
}
+void DagModel::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);
+}
+
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-03-12 13:14:35 EDT (Mon, 12 Mar 2012)
@@ -70,7 +70,17 @@
void setupModelData(const QStringList &lines, DagItem *parent);
DagItem *getItem(const QModelIndex &index) const;
+ void fillData(QVector<QVariant>& data, QSqlQuery& query);
+
DagItem *rootItem;
+
+ int m_parentId ;
+ int m_childId ;
+ int m_typeId ;
+ int m_parentName;
+ int m_childName ;
+ int m_childType ;
+
};
#endif
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