Ok i found a way to build a dom tree .. from a QStandardItemModel
a static function to retry child item
{
QList<QStandardItem*> rList;
if (!in.isValid()) {
return rList;
}
if (qi->rowCount() == 0) {
return rList;
}
for (int e = 0; e < qi->rowCount(); ++e) {
if (iz) {
rList << iz;
}
}
return rList;
}
static QList<QStandardItem*> childList( QStandardItem *qi )
{
QStandardItemModel *pm = qi->model();
QList<QStandardItem*> rList;
QModelIndex in = qi->index();
if (!in.isValid()) {
return rList;
}
if (qi->rowCount() == 0) {
return rList;
}
for (int e = 0; e < qi->rowCount(); ++e) {
QModelIndex si = pm->index(e,qi->column(),in);
QStandardItem *iz = pm->itemFromIndex(si);
if (iz) {
rList << iz;
}
}
return rList;
}
To copy to clipboard, switch view to plain text mode
and a class to build a xml
void BookTree::subIterate()
{
if (!pm) {
return;
}
int rw = 0;
int cw = 0;
int ctot = 0;
const int cools = pm->columnCount();
const int rows = pm->rowCount();
qDebug() << "-- iter ---------------------------------------------------------";
for (int i = 0; i < cools; ++i) {
const QString htxt
= pm
->headerData
(i,Qt
::Horizontal,Qt
::DisplayRole).
toString();
const QString htxt1
= pm
->headerData
(i,Qt
::Vertical,Qt
::DisplayRole).
toString();
line << qMax(htxt,htxt1);
}
QList<QStandardItem*> list;
for (int e = 0; e < rows; ++e) {
list.clear();
list = childList(ix_1);
ctot = list.size();
int level = 0;
qDebug() << "# lev." << level <<" line " << e << " txt " << ix_1->text() << " child " << ctot;
if (ctot !=0) {
level++;
list.clear();
ctot = 0;
list = childList(ix);
ctot = list.size();
qDebug() << "# lev." << level <<" line " << e << " txt " << ix->text() << " child " << ctot;
}
}
}
qDebug() << "-- iter ---------------------------------------------------------";
}
void BookTree::subIterate()
{
QStandardItemModel *pm = qobject_cast<QStandardItemModel *>(model());
if (!pm) {
return;
}
QStringList line;
int rw = 0;
int cw = 0;
int ctot = 0;
const int cools = pm->columnCount();
const int rows = pm->rowCount();
qDebug() << "-- iter ---------------------------------------------------------";
for (int i = 0; i < cools; ++i) {
const QString htxt = pm->headerData(i,Qt::Horizontal,Qt::DisplayRole).toString();
const QString htxt1 = pm->headerData(i,Qt::Vertical,Qt::DisplayRole).toString();
line << qMax(htxt,htxt1);
}
QList<QStandardItem*> list;
for (int e = 0; e < rows; ++e) {
QStandardItem *ix_1 = pm->item(e,0);
QStandardItem *ix_2 = pm->item(e,1);
list.clear();
list = childList(ix_1);
ctot = list.size();
int level = 0;
qDebug() << "# lev." << level <<" line " << e << " txt " << ix_1->text() << " child " << ctot;
if (ctot !=0) {
level++;
foreach (QStandardItem *ix,list) {
list.clear();
ctot = 0;
list = childList(ix);
ctot = list.size();
qDebug() << "# lev." << level <<" line " << e << " txt " << ix->text() << " child " << ctot;
}
}
}
qDebug() << "-- iter ---------------------------------------------------------";
}
To copy to clipboard, switch view to plain text mode
now i must only transform the tree model -> flat like table to validate link...
Bookmarks