patrik08
23rd August 2008, 09:28
I need a model tree to save PDF Bookmark like QStandardItemModel
and this model must combine on anchorNames () on a QTextDocument
i need a model to validate anchorNames () at QTextDocument .....
at end i save the tree on this way:
<fo:bookmark-tree>
<fo:bookmark internal-destination="sec0" >
<fo:bookmark-title>Internal dest.0</fo:bookmark-title>
<fo:bookmark internal-destination="sec1" >
<fo:bookmark-title>Internal dest.1</fo:bookmark-title>
</fo:bookmark>
<fo:bookmark internal-destination="sec2" >
<fo:bookmark-title>Internal dest.2</fo:bookmark-title>
</fo:bookmark>
</fo:bookmark>
</fo:bookmark-tree>
I search a way to traverse or iterate all node from model
i find only this here ...
http://troll.no/developer/knowledgebase/faq.2007-10-04.3382815333/?searchterm=qstandarditemmodel
Is here other way?
on read xml-bookmark i make it so...
void BookMarkModelRead::openRootBookmark( const QDomElement e )
{
if (e.tagName() !="fo:bookmark-tree")
{
return;
}
foundTree = true;
model = new QStandardItemModel();
internalLinkFound.clear();
setHeader();
//////////////qDebug() << "### openRootBookmark -> " << e.tagName();
QDomElement child = e.firstChildElement("fo:bookmark");
while (!child.isNull()) {
model->invisibleRootItem()->appendRow(Compose(child,0));
child = child.nextSiblingElement("fo:bookmark");
}
}
QList<QStandardItem *> BookMarkModelRead::Compose( const QDomElement e , const int leveldeep )
{
Q_ASSERT ( e.tagName() == "fo:bookmark" );
treeLoop++;
QList<QStandardItem *> diritto;
QIcon icob = createBookColorIcon( Qt::darkRed );
QString txt = e.firstChildElement("fo:bookmark-title").text();
if (txt.size() < 2) {
txt = tr("No Title found!");
icob = createBookColorIcon( Qt::red );
}
const QString link = e.attribute("internal-destination","null");
internalLinkFound.append(link);
qDebug() << "### read -> " << txt << "-" << treeLoop;
QStandardItem *item0 = new QStandardItem(txt);
item0->setData(leveldeep,Qt::UserRole);
item0->setData(bold_base_font,Qt::FontRole);
item0->setIcon ( icob );
item0->setFlags( flags );
diritto.append(item0);
QStandardItem *item1 = new QStandardItem(link);
item1->setFlags( flags );
item1->setData(leveldeep,Qt::UserRole);
diritto.append(item1);
QStandardItem *item2 = new QStandardItem(QString("%1").arg(leveldeep));
item2->setFlags( Qt::ItemIsEnabled );
item2->setData(leveldeep,Qt::UserRole);
diritto.append(item2);
if (!e.firstChildElement("fo:bookmark").isNull() && leveldeep == 0 ) {
/* one level deep down child */
QDomElement child = e.firstChildElement("fo:bookmark");
while (!child.isNull()) {
if ( child.tagName() == "fo:bookmark") {
const QString nextlink = child.attribute("internal-destination","null");
if (!internalLinkFound.contains(nextlink)) {
diritto.first()->appendRow(Compose(child,leveldeep + 1));
}
}
child = child.nextSiblingElement();
}
} else if (!e.nextSiblingElement("fo:bookmark").isNull() && leveldeep > 0 ) {
/* same level is only next on deep */
}
return diritto;
}
and to read the model it is not possibel?
i can not use QTreeWidget / QTreeWidgetItem why ... i can not set a model at him...
only QTreeView can set a model .... i know only a way to use sqlite3 as model...
Must i use sqlite3 to traverse all tree? QStandardItemModel can not make this job..
the resut... is not possible to read back from QTreeView ...!! onewayQTreeView :-(
http://ppk.ciz.ch/MiniScribus/treebook.png
and this model must combine on anchorNames () on a QTextDocument
i need a model to validate anchorNames () at QTextDocument .....
at end i save the tree on this way:
<fo:bookmark-tree>
<fo:bookmark internal-destination="sec0" >
<fo:bookmark-title>Internal dest.0</fo:bookmark-title>
<fo:bookmark internal-destination="sec1" >
<fo:bookmark-title>Internal dest.1</fo:bookmark-title>
</fo:bookmark>
<fo:bookmark internal-destination="sec2" >
<fo:bookmark-title>Internal dest.2</fo:bookmark-title>
</fo:bookmark>
</fo:bookmark>
</fo:bookmark-tree>
I search a way to traverse or iterate all node from model
i find only this here ...
http://troll.no/developer/knowledgebase/faq.2007-10-04.3382815333/?searchterm=qstandarditemmodel
Is here other way?
on read xml-bookmark i make it so...
void BookMarkModelRead::openRootBookmark( const QDomElement e )
{
if (e.tagName() !="fo:bookmark-tree")
{
return;
}
foundTree = true;
model = new QStandardItemModel();
internalLinkFound.clear();
setHeader();
//////////////qDebug() << "### openRootBookmark -> " << e.tagName();
QDomElement child = e.firstChildElement("fo:bookmark");
while (!child.isNull()) {
model->invisibleRootItem()->appendRow(Compose(child,0));
child = child.nextSiblingElement("fo:bookmark");
}
}
QList<QStandardItem *> BookMarkModelRead::Compose( const QDomElement e , const int leveldeep )
{
Q_ASSERT ( e.tagName() == "fo:bookmark" );
treeLoop++;
QList<QStandardItem *> diritto;
QIcon icob = createBookColorIcon( Qt::darkRed );
QString txt = e.firstChildElement("fo:bookmark-title").text();
if (txt.size() < 2) {
txt = tr("No Title found!");
icob = createBookColorIcon( Qt::red );
}
const QString link = e.attribute("internal-destination","null");
internalLinkFound.append(link);
qDebug() << "### read -> " << txt << "-" << treeLoop;
QStandardItem *item0 = new QStandardItem(txt);
item0->setData(leveldeep,Qt::UserRole);
item0->setData(bold_base_font,Qt::FontRole);
item0->setIcon ( icob );
item0->setFlags( flags );
diritto.append(item0);
QStandardItem *item1 = new QStandardItem(link);
item1->setFlags( flags );
item1->setData(leveldeep,Qt::UserRole);
diritto.append(item1);
QStandardItem *item2 = new QStandardItem(QString("%1").arg(leveldeep));
item2->setFlags( Qt::ItemIsEnabled );
item2->setData(leveldeep,Qt::UserRole);
diritto.append(item2);
if (!e.firstChildElement("fo:bookmark").isNull() && leveldeep == 0 ) {
/* one level deep down child */
QDomElement child = e.firstChildElement("fo:bookmark");
while (!child.isNull()) {
if ( child.tagName() == "fo:bookmark") {
const QString nextlink = child.attribute("internal-destination","null");
if (!internalLinkFound.contains(nextlink)) {
diritto.first()->appendRow(Compose(child,leveldeep + 1));
}
}
child = child.nextSiblingElement();
}
} else if (!e.nextSiblingElement("fo:bookmark").isNull() && leveldeep > 0 ) {
/* same level is only next on deep */
}
return diritto;
}
and to read the model it is not possibel?
i can not use QTreeWidget / QTreeWidgetItem why ... i can not set a model at him...
only QTreeView can set a model .... i know only a way to use sqlite3 as model...
Must i use sqlite3 to traverse all tree? QStandardItemModel can not make this job..
the resut... is not possible to read back from QTreeView ...!! onewayQTreeView :-(
http://ppk.ciz.ch/MiniScribus/treebook.png