Results 1 to 2 of 2

Thread: QTextFrame::iterator richtext QTextDocument problem?

  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QTextFrame::iterator richtext QTextDocument problem?

    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.
    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


    Qt Code:
    1. //////QTextDocument *w3 = fop.GetDoc() [ return QTextDocument->clone() ] XSL-FO format ;
    2. /////QTextFrame *Tframe = w3->rootFrame();
    3.  
    4. int speed = 0;
    5. qDebug() << "### iterator start ############################" << speed;
    6.  
    7. /* QTextFrameFormat QTextFrame::frameFormat() const */
    8.  
    9. QTextFrame::iterator it;
    10. for (it = Tframe->begin(); !(it.atEnd()); ++it) {
    11. speed++; /* to find tree structure */
    12. QTextFrame *childFrame = it.currentFrame();
    13. QTextBlock para = it.currentBlock();
    14.  
    15. if (childFrame) {
    16. qDebug() << "### frame " << speed;
    17.  
    18. } else if (para.isValid()) {
    19. qDebug() << "### block " << speed << " Paragraph ->" << para.text();
    20.  
    21. if (para.charFormat().isValid()) { /* QTextCharFormat */
    22. QTextCharFormat subpara = para.charFormat();
    23.  
    24. qDebug() << "### inline span " << speed;
    25.  
    26. if ( subpara.toImageFormat().isValid() ) {
    27.  
    28. QTextImageFormat Pic = subpara.toImageFormat();
    29. qDebug() << "### image " << speed;
    30.  
    31. } else if ( subpara.toTableFormat().isValid() ) {
    32.  
    33. QTextTableFormat Ta = subpara.toTableFormat();
    34. qDebug() << "### table " << speed;
    35. }
    36.  
    37.  
    38.  
    39. }
    40.  
    41.  
    42.  
    43. }
    44. }
    45. qDebug() << "### iterator end ############################" << speed;
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTextFrame::iterator richtext QTextDocument problem?

    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?..

    Qt Code:
    1. //////QTextDocument *w3 = fop.GetDoc() [ return QTextDocument->clone() ] XSL-FO format ;
    2. /////QTextFrame *Tframe = w3->rootFrame();
    3. int speed = 0;
    4. qDebug() << "### iterator frame start ############################" << speed;
    5.  
    6. /* QTextFrameFormat QTextFrame::frameFormat() const */
    7. QTextFrame::iterator it;
    8. for (it = Tframe->begin(); !(it.atEnd()); ++it) {
    9. speed++; /* to find tree structure */
    10. QTextFrame *childFrame = it.currentFrame();
    11. QTextBlock para = it.currentBlock();
    12.  
    13. if (childFrame) {
    14. qDebug() << "### frame " << speed;
    15.  
    16. } else if (para.isValid()) {
    17. QTextBlockFormat ParentBl = para.blockFormat();
    18. /* PARAGRAPH TAG ..............TAGNR. ENUM 406 */
    19. QDomElement param = bdoc.createElement("fo:block");
    20. /* ##### textblock iterator start QTextBlock ###########################*/
    21. QTextBlock::iterator de;
    22. for (de = para.begin(); !(de.atEnd()); ++de) {
    23. QTextFragment fr = de.fragment();
    24. if (fr.isValid()) {
    25. /* QTextCharFormat */
    26. QTextCharFormat TXTCh = fr.charFormat();
    27. QTextImageFormat Pics = TXTCh.toImageFormat();
    28. QTextTableFormat Tabl = TXTCh.toTableFormat();
    29. QTextListFormat Uls = TXTCh.toListFormat();
    30.  
    31. if (Pics.isValid() && !Pics.name().isEmpty()) {
    32. /* IMAGE TAG internal external............TAGNR. ENUM 417/418 */
    33. /* SVG convert to png transparent ! / original svg base64 encoded data! xml */
    34. QDomElement inlineimage = bdoc.createElement("fo:internal-graphic");
    35. inlineimage.setAttribute ("src",Pics.name());
    36. if (Pics.height() >0) {
    37. inlineimage.setAttribute ("height",Pics.height());
    38. }
    39. if (Pics.width() > 0) {
    40. inlineimage.setAttribute ("width",Pics.width());
    41. }
    42. param.appendChild(inlineimage);
    43. ////////qDebug() << "### image ";
    44. } else if (Tabl.isValid() && Tabl.columns() > 0) {
    45. /* TABLE TAG ............TAGNR. ENUM 407,408,409,410,411,412,413 */
    46. /*fo:table/table-footer/table-header/fo:table-body/
    47.   fo:table-column/fo:table-row/fo:table-cell*/
    48. qDebug() << "### table ";
    49. } else if (TXTCh.isAnchor()) {
    50. param.appendChild(bdoc.createTextNode("\n"));
    51. /* LINK TAG internal-local / external............TAGNR. ENUM 416 */
    52. QDomElement linkers = bdoc.createElement("fo:basic-link");
    53. QStringList hrefs = TXTCh.anchorNames();
    54. if ( TXTCh.anchorHref().startsWith("#") ) {
    55. linkers.setAttribute ("external-destination",TXTCh.anchorHref());
    56. } else {
    57. linkers.setAttribute ("internal-destination",TXTCh.anchorHref());
    58. }
    59. param.appendChild(linkers);
    60. QDomText linktext = bdoc.createTextNode(" \n"+fr.text().trimmed()+" \n");
    61. linkers.appendChild(linktext);
    62. param.appendChild(bdoc.createTextNode("\n"));
    63. /////////qDebug() << "### link " << hrefs;
    64. } else if (Uls.isValid()) {
    65. qDebug() << "### ul list ";
    66. } else {
    67. QDomText Fragitext = bdoc.createTextNode(fr.text());
    68. param.appendChild(Fragitext);
    69. }
    70. ////////qDebug() << "### fragment " << speed << " FRAG->" << fr.text();
    71. }
    72. }
    73. /* ##### textblock iterator end QTextBlock ###########################*/
    74.  
    75. flow.appendChild( param );
    76. }
    77. }
    78. qDebug() << "### iterator frame end ############################" << speed;
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 0
    Last Post: 13th July 2007, 23:45
  2. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 13:45
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 15:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 22:36
  5. Replies: 16
    Last Post: 7th March 2006, 16:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.