PDA

View Full Version : QTextFrame::iterator richtext QTextDocument problem?



patrik08
19th July 2007, 22:29
I spend two day to dispay and edit the XSL-Fo format is similar from dock book KDE..
now i can not grab QTextDocument to resave to xml file. :mad:
Question:
Why QTextFrame can not find image or table? inside a QTextFrame::iterator from QTextDocument

Or is image part from fragment? how grab this?

i have one image and one table inside and iterator not find? why .. pleas help .
I not found any sample to iterate QTextDocument http://doc.trolltech.com/4.2/richtext-structure.html





//////QTextDocument *w3 = fop.GetDoc() [ return QTextDocument->clone() ] XSL-FO format ;
/////QTextFrame *Tframe = w3->rootFrame();

int speed = 0;
qDebug() << "### iterator start ############################" << speed;

/* QTextFrameFormat QTextFrame::frameFormat() const */

QTextFrame::iterator it;
for (it = Tframe->begin(); !(it.atEnd()); ++it) {
speed++; /* to find tree structure */
QTextFrame *childFrame = it.currentFrame();
QTextBlock para = it.currentBlock();

if (childFrame) {
qDebug() << "### frame " << speed;

} else if (para.isValid()) {
qDebug() << "### block " << speed << " Paragraph ->" << para.text();

if (para.charFormat().isValid()) { /* QTextCharFormat */
QTextCharFormat subpara = para.charFormat();

qDebug() << "### inline span " << speed;

if ( subpara.toImageFormat().isValid() ) {

QTextImageFormat Pic = subpara.toImageFormat();
qDebug() << "### image " << speed;

} else if ( subpara.toTableFormat().isValid() ) {

QTextTableFormat Ta = subpara.toTableFormat();
qDebug() << "### table " << speed;
}



}



}
}
qDebug() << "### iterator end ############################" << speed;

patrik08
20th July 2007, 01:02
i found now a QTextBlock::iterator ... from qt4-x11-4.2.3/tools/assistant/mainwindow.cpp

but how find now the internal equivalent <span> tag HTML? is this to a fragment?..



//////QTextDocument *w3 = fop.GetDoc() [ return QTextDocument->clone() ] XSL-FO format ;
/////QTextFrame *Tframe = w3->rootFrame();
int speed = 0;
qDebug() << "### iterator frame start ############################" << speed;

/* QTextFrameFormat QTextFrame::frameFormat() const */
QTextFrame::iterator it;
for (it = Tframe->begin(); !(it.atEnd()); ++it) {
speed++; /* to find tree structure */
QTextFrame *childFrame = it.currentFrame();
QTextBlock para = it.currentBlock();

if (childFrame) {
qDebug() << "### frame " << speed;

} else if (para.isValid()) {
QTextBlockFormat ParentBl = para.blockFormat();
/* PARAGRAPH TAG ..............TAGNR. ENUM 406 */
QDomElement param = bdoc.createElement("fo:block");
/* ##### textblock iterator start QTextBlock ###########################*/
QTextBlock::iterator de;
for (de = para.begin(); !(de.atEnd()); ++de) {
QTextFragment fr = de.fragment();
if (fr.isValid()) {
/* QTextCharFormat */
QTextCharFormat TXTCh = fr.charFormat();
QTextImageFormat Pics = TXTCh.toImageFormat();
QTextTableFormat Tabl = TXTCh.toTableFormat();
QTextListFormat Uls = TXTCh.toListFormat();

if (Pics.isValid() && !Pics.name().isEmpty()) {
/* IMAGE TAG internal external............TAGNR. ENUM 417/418 */
/* SVG convert to png transparent ! / original svg base64 encoded data! xml */
QDomElement inlineimage = bdoc.createElement("fo:internal-graphic");
inlineimage.setAttribute ("src",Pics.name());
if (Pics.height() >0) {
inlineimage.setAttribute ("height",Pics.height());
}
if (Pics.width() > 0) {
inlineimage.setAttribute ("width",Pics.width());
}
param.appendChild(inlineimage);
////////qDebug() << "### image ";
} else if (Tabl.isValid() && Tabl.columns() > 0) {
/* TABLE TAG ............TAGNR. ENUM 407,408,409,410,411,412,413 */
/*fo:table/table-footer/table-header/fo:table-body/
fo:table-column/fo:table-row/fo:table-cell*/
qDebug() << "### table ";
} else if (TXTCh.isAnchor()) {
param.appendChild(bdoc.createTextNode("\n"));
/* LINK TAG internal-local / external............TAGNR. ENUM 416 */
QDomElement linkers = bdoc.createElement("fo:basic-link");
QStringList hrefs = TXTCh.anchorNames();
if ( TXTCh.anchorHref().startsWith("#") ) {
linkers.setAttribute ("external-destination",TXTCh.anchorHref());
} else {
linkers.setAttribute ("internal-destination",TXTCh.anchorHref());
}
param.appendChild(linkers);
QDomText linktext = bdoc.createTextNode(" \n"+fr.text().trimmed()+" \n");
linkers.appendChild(linktext);
param.appendChild(bdoc.createTextNode("\n"));
/////////qDebug() << "### link " << hrefs;
} else if (Uls.isValid()) {
qDebug() << "### ul list ";
} else {
QDomText Fragitext = bdoc.createTextNode(fr.text());
param.appendChild(Fragitext);
}
////////qDebug() << "### fragment " << speed << " FRAG->" << fr.text();
}
}
/* ##### textblock iterator end QTextBlock ###########################*/

flow.appendChild( param );
}
}
qDebug() << "### iterator frame end ############################" << speed;