Greetings

I've made serveral attempts but im failing big time. I last tried this serveral months ago, only to simply give up and work on some library code.

I want a make a persistant TreeView widget across a network conection. To do that, I need to use a 'flat source' (ie: QTableView data), to provide an initial update, and successive edits/drag + drop operations. The easiest data source is a flat source because its serializable and diff'able.

I've tried field delegates that alter a foreign source and an sql backend that doesn't fire change events etc.

My problem is that I can't seem to find a "one model fits all" backend to both QTreeModel and QTableModels. I've been able to successfully build a tree from a flat source using pointer and non-pointer methods, but both mean I create an in memory tree stucture, which is hard to update/alter.

My data is something along the lines of:

Qt Code:
  1. QVector<QVariant*> headerData;
  2. headerData << new QVariant(tr("Display"));
  3. headerData << new QVariant(tr("Name"));
  4. headerData << new QVariant(tr("Parent"));
  5. rootItem = new TreeItem(headerData);
  6.  
  7. QVector<QVariant *> rootNodeData;
  8. rootNodeData << new QVariant(tr("This is the root node"));
  9. rootNodeData << new QVariant(tr("ROOT"));
  10. rootNodeData << new QVariant(tr("."));
  11.  
  12. rootItem->insertChildren(rootItem->childCount(), 1, rootNodeData);
  13. rootNode = rootItem->child(0);
To copy to clipboard, switch view to plain text mode 

Some sample data

Qt Code:
  1. TreeData * r1 = new TreeData();
  2. r1->setString("Display", "Display txt");
  3. r1->setString("Name", "Parent1");
  4. r1->setString("Parent", "ROOT");
  5.  
  6. TreeData * r2 = new TreeData();
  7. r2->setString("Display", "this is parent 2");
  8. r2->setString("Name", "Parent2");
  9. r2->setString("Parent", "ROOT");
  10.  
  11. TreeData * c1 = new TreeData();
  12. c1->setString("Display", "First child");
  13. c1->setString("Name", "Child1");
  14. c1->setString("Parent", "Parent1");
  15.  
  16. TreeData * c2 = new TreeData();
  17. c2->setString("Display", "This is the child of child1");
  18. c2->setString("Name", "Child2");
  19. c2->setString("Parent", "Child1");
  20.  
  21. QVector<TreeData*> treeDataVec;
  22. treeDataVec << r1;
  23. treeDataVec << r2;
  24. treeDataVec << c1;
  25. treeDataVec << c2;
To copy to clipboard, switch view to plain text mode 

Recursively populate children by "Parent" <-> "Name"

Qt Code:
  1. foreach (TreeData * td, treeData)
  2. {
  3. QString parentName = QString(td->getString("Parent").c_str());
  4.  
  5. TreeItem * currentRoot = recursiveFindByName(parentName, rootNode);
  6. if (!currentRoot)
  7. currentRoot = rootNode;
  8.  
  9. QString thisNodeName = currentRoot->data(1).toString();;
  10.  
  11. QVector<QVariant*> data;
  12. data << new QVariant(QString(td->getString("Display").c_str()));
  13. data << new QVariant(QString(td->getString("Name").c_str()));
  14. data << new QVariant(QString(td->getString("Parent").c_str()));
  15.  
  16. currentRoot->insertChildren(currentRoot->childCount(), 1, data);
  17. }
To copy to clipboard, switch view to plain text mode 

But this isn't very drag and drop friendly. What I really need is to use a model proxy. Can someone provide an example of this? Does it reduce down to a flat source that I can simply assign to a QTableView and alter in realtime, with the updates reflected in the Tree heirarchy?

Thanks

mawt