Results 1 to 9 of 9

Thread: QTextDocumentFragment GetSelection / insertFragment

  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 QTextDocumentFragment GetSelection / insertFragment

    waht is the equivalent from javascripts => window.getSelection() (mozila)
    on a QTextEdit to get text? i not fount any word ... QTextDocumentFragment on forum....

    para_21 = QTextEdit

    void Tab_Addo::makehrefLink()
    {
    QString ltext ="<a href=\"http://www.qtcentre.org/forum/search.php\" target=\"_blank\">href text</a>";
    QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(ltext);
    para_21->textCursor().insertFragment(fragment);
    qDebug("%s",ltext.toAscii().data());
    }

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextDocumentFragment GetSelection / insertFragment


  3. #3
    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: QTextDocumentFragment GetSelection / insertFragment

    Super ... tanks.... works ....

    You think that is easy insert a model... or so to check html schema from tool http://www.relaxng.org/ Relax NG? (libs exist return text html/xml schema true/false) I work and undestanding relax grammatics...
    20 month experience by Bitflux editor (only gecko browser work... mozilla,netscape,safari...)
    http://cvsdemo.bitfluxeditor.org/exa...TML/index.html .

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextDocumentFragment GetSelection / insertFragment

    Quote Originally Posted by patrik08
    You think that is easy insert a model... or so to check html schema from tool http://www.relaxng.org/ Relax NG? (libs exist return text html/xml schema true/false) I work and undestanding relax grammatics...
    20 month experience by Bitflux editor (only gecko browser work... mozilla,netscape,safari...)
    Could you reword a bit your question? Do you want to validate an XML document? What this has to do with text selected in QTextEdit?

  5. #5
    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: QTextDocumentFragment GetSelection / insertFragment

    The file or class
    qt-x11-opensource-src-4.1.3\src\gui\text\qtexthtmlparser.cpp

    destroy tag...

    If I put :
    ltext ="<a href=\"http://www.qtcentre.org/forum/search.php\" target=\"foo\">href text</a>";
    insertFragment(fragment obj...);
    the qtexthtmlparser.cpp remove [target=\"foo\"] .... and stay only <a href>text</a>...

    the simple parser job can make Relax NG and not qtexthtmlparser.cpp
    On small word I want to write "xhtml" standard and not
    <meta name="qrichtext" content="1" />

    I found setcharformat or so ... but Qt support only old html4 and plain text.....

    How to set my own qtexthtmlparser ... a model view or so?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextDocumentFragment GetSelection / insertFragment

    Quote Originally Posted by patrik08
    If I put :
    ltext ="<a href=\"http://www.qtcentre.org/forum/search.php\" target=\"foo\">href text</a>";
    insertFragment(fragment obj...);
    the qtexthtmlparser.cpp remove [target=\"foo\"] .... and stay only <a href>text</a>...
    That's because Qt's rich text is only a subset of HTML. See here.

    Quote Originally Posted by patrik08
    On small word I want to write "xhtml" standard and not
    <meta name="qrichtext" content="1" />
    You will have to translate Qt's rich text to XHTML somehow. You could try to traverse the document using QTextFrame::iterator and generate XHTML yourself. Another, probably simplier, solution is to use QTextDocument::toHtml() and then clean the document using QDomDocument or XSLT transformation (for the latter you will need some external library).

  7. #7
    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: QTextDocumentFragment GetSelection / insertFragment

    OK .. on my mind is xslt .... is moore easy clean html and write xhtml by a local xml-config...
    preference.....

    I am owner from http://sourceforge.net/projects/qtexcel-xslt/ Projekt....
    But i cant' not describe this projekt on a clean Englisch...

    the freshmeat.net boy say: :-(

    The following notes are in response to your recent freshmeat.net submission:

    You submitted the following as the description for this software:

    "QExcel Converter SQL QT4, Import xml excel/openoffice 2003 format,
    sqlite3 sql text/binary, edit table and export to various Format, Pdf XSL
    format objects Apache fop JAVA(XSL-FO), XML/XSLT , excel, SQL text sqlite3
    dump file and MYSQL SQL to XML/XSL"

    That is not intelligible English, and so I cannot understand it. A
    description for a piece of software must be written in sentences which at
    least attempt to conform to the rules of syntax and grammar which apply to the
    English language. Your contribution cannot be processed until you reply to
    this message via email with a new description for this software.

    This is the result if an Swiss Italian Programmer make opensource pieces....

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextDocumentFragment GetSelection / insertFragment

    Quote Originally Posted by patrik08
    It looks promising. It would be great if one could embed it in his own application to export data or even QTextDocument to ODF or something else. The only problem is that most of QTextDocument's methods are non-virtual, so it isn't very extensible. One solution would be to keep two representations of the document (internal and QTextDocument), but I'm not sure if it will be fast enough.

    Quote Originally Posted by patrik08
    But i cant' not describe this projekt on a clean Englisch...
    Unfortunately English is a lingua franca of the IT.

  9. #9
    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: QTextDocumentFragment GetSelection / insertFragment

    I see much qt people not like the qt4 pdf print action ... to much bugs...
    Landscape not work... QPrinter::Landscape and other...pdf items...


    To convert document html/xml to pdf , rtf , latex , or other format.... is so easy.... xslt .. only need 2-3 file...

    1- The base file xml/html:
    http://qtexcel-xslt.sourceforge.net/...base_start.xml
    2-3- The converter (intermediate convert html .. other convert to xml):
    http://qtexcel-xslt.sourceforge.net/.../xmlsql2fo.xsl

    If the base is clean ony 2 file required...

    Last action bring the fop file result to { Formatting Objects Processor} fop Java.. qprocess..
    (I think a C++ wrapper come released on the next 3-8 months ... so JAVA_HOME not needed.)

    Make fo file .....
    Qt Code:
    1. bool Gui_Starter::Export2PDF( QString pdffile )
    2. { /* tmp pdf RESULT_PDF_FILE */
    3. /* CleanCachexslt(); */ /* clean file if exist */
    4. CleanCachexslt();
    5. bool ok;
    6. int success;
    7. ok = is_file( INCOMMINGFILE );
    8.  
    9. /*int totalt = CountTable();*/
    10.  
    11.  
    12. /* ####### param to xslt converter #####################*/
    13. const char* params[5];
    14. params[0] = NULL;
    15. params[1] = NULL;
    16. params[2] = NULL;
    17. params[3] = NULL;
    18. params[4] = NULL;
    19. success = Convert_XSLT( INCOMMINGFILE , (const xmlChar *)"http://qtexcel-xslt.sourceforge.net/converter/xmlsql2fo.xsl" , params );
    20. if (success < 1 and ok) {
    21. ok=Fopjava( SHORTFILE , RESULT_PDF_FILE );
    22. }
    23.  
    24. QFile fpdf( RESULT_PDF_FILE );
    25. if (!fpdf.copy( pdffile )) {
    26. ok = false;
    27. }
    28. /* ####### param to xslt converter #####################*/
    29. if (ok and success == 0) {
    30. CleanCachexslt();
    31. return true;
    32. } else {
    33. CleanCachexslt();
    34. return false;
    35. }
    36.  
    37. }
    To copy to clipboard, switch view to plain text mode 


    Fop apache http://xmlgraphics.apache.org/fop/

    make pdf....
    Qt Code:
    1. /* external java fop setup & convert */
    2. bool Gui_Starter::Fopjava( QString fofile , QString pdffile )
    3. {
    4.  
    5. #if defined( Q_WS_X11 )
    6. #ifndef JAVA_HOME
    7. #define JAVA_HOME \
    8. QString( "%1/" ).arg( getenv("JAVA_HOME") )
    9. #endif
    10. #endif
    11. #if defined( Q_WS_MACX )
    12. QString JAVA_HOME = "a1234"; /* mac other java handler on fop */
    13. #endif
    14. #if defined(Q_WS_WIN)
    15. #ifndef JAVA_HOME
    16. #define JAVA_HOME \
    17. QString( "%1/" ).arg( getenv("JAVA_HOME") )
    18. #endif
    19. #endif
    20. /* http://xmlgraphics.apache.org/fop/ only java api
    21.   http://mirror.switch.ch/mirror/apache/dist/xmlgraphics/fop/binaries/fop-0.92beta-bin-jdk1.4.zip */
    22.  
    23. QString bindirapp;
    24. #if defined(Q_WS_WIN)
    25. bindirapp = QCoreApplication::applicationDirPath()+"/fop/fop.bat";
    26. #else /* mac linux */
    27. /* test "which fop" */
    28. bindirapp = "/opt/fop/fop";
    29. #endif
    30. if (!is_file(bindirapp)) {
    31. errormsg = "<p>Error...! </p><p>fop apache is not install... </p><p>download a copy from http://xmlgraphics.apache.org/fop/ </p><p>and copy to "+bindirapp+"</p>";
    32. return false;
    33. }
    34.  
    35. if (JAVA_HOME.size() > 3) {
    36.  
    37. QProcess process;
    38. process.setReadChannelMode(QProcess::MergedChannels);
    39. process.start( bindirapp , QStringList() << fofile << pdffile);
    40. if (!process.waitForFinished()) {
    41. errormsg = "Error...! Transormtation! \n" + process.errorString() + "\nprogramm " +bindirapp;
    42. return false;
    43. } else {
    44. errormsg = "Success Transormtation! \n" + process.readAll() + "\nprogramm " +bindirapp;
    45. return true;
    46. }
    47. } else {
    48. errormsg = "Error...! JAVA_HOME not found on your OS";
    49. return false;
    50. }
    51. }
    To copy to clipboard, switch view to plain text mode 


    And ... automatic Landscape/Portrait by column count..

    if moore as 8 cools landscape....

    Qt Code:
    1. <!-- landscape or vertical? -->
    2. <xsl:choose>
    3. <xsl:when test="$bigcolumncount &gt; 8">
    4. <!-- landscape -->
    5. <fo:layout-master-set>
    6. <fo:simple-page-master master-name="simple" page-height="21cm" page-width="30cm"
    7. margin-top="1cm" margin-bottom="0.3cm" margin-left="1.2cm" margin-right="1.2cm">
    8. <fo:region-body margin-bottom="2cm"/>
    9. <fo:region-after extent="16pt"/>
    10. </fo:simple-page-master>
    11. </fo:layout-master-set>
    12. </xsl:when>
    13. <xsl:otherwise>
    14. <!-- vertical -->
    15. <fo:layout-master-set>
    16. <fo:simple-page-master master-name="simple" page-height="29.7cm" page-width="21cm"
    17. margin-top="1cm" margin-bottom="0.3cm" margin-left="1.4cm" margin-right="1.2cm">
    18. <fo:region-body margin-bottom="2cm"/>
    19. <fo:region-after extent="16pt"/>
    20. </fo:simple-page-master>
    21. </fo:layout-master-set>
    22. </xsl:otherwise>
    23. </xsl:choose>
    To copy to clipboard, switch view to plain text mode 

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.