PDA

View Full Version : QTextDocumentFragment GetSelection / insertFragment



patrik08
26th May 2006, 15:21
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());
}

jacek
26th May 2006, 15:35
Use QTextCursor::selectedText() or QTextCursor::selection().

patrik08
26th May 2006, 15:58
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/examples/inlineXHTML/index.html .

jacek
26th May 2006, 17:07
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?

patrik08
26th May 2006, 17:33
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?

jacek
26th May 2006, 18:25
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 (http://doc.trolltech.com/4.1/richtext-html-subset.html).


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

patrik08
26th May 2006, 18:38
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....

jacek
26th May 2006, 19:16
I am owner from http://sourceforge.net/projects/qtexcel-xslt/ Projekt....
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.


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

patrik08
26th May 2006, 20:20
I see much qt people not like the qt4 pdf print action ... to much bugs...
Landscape not work... QPrinter::Landscape (http://www.trolltech.com/developer/task-tracker/index_html?method=entry&id=99066) 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/converter/base_start.xml
2-3- The converter (intermediate convert html .. other convert to xml):
http://qtexcel-xslt.sourceforge.net/converter/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 .....


bool Gui_Starter::Export2PDF( QString pdffile )
{ /* tmp pdf RESULT_PDF_FILE */
/* CleanCachexslt(); */ /* clean file if exist */
CleanCachexslt();
bool ok;
int success;
ok = is_file( INCOMMINGFILE );

/*int totalt = CountTable();*/


/* ####### param to xslt converter #####################*/
const char* params[5];
params[0] = NULL;
params[1] = NULL;
params[2] = NULL;
params[3] = NULL;
params[4] = NULL;
success = Convert_XSLT( INCOMMINGFILE , (const xmlChar *)"http://qtexcel-xslt.sourceforge.net/converter/xmlsql2fo.xsl" , params );
if (success < 1 and ok) {
ok=Fopjava( SHORTFILE , RESULT_PDF_FILE );
}

QFile fpdf( RESULT_PDF_FILE );
if (!fpdf.copy( pdffile )) {
ok = false;
}
/* ####### param to xslt converter #####################*/
if (ok and success == 0) {
CleanCachexslt();
return true;
} else {
CleanCachexslt();
return false;
}

}


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

make pdf....

/* external java fop setup & convert */
bool Gui_Starter::Fopjava( QString fofile , QString pdffile )
{

#if defined( Q_WS_X11 )
#ifndef JAVA_HOME
#define JAVA_HOME \
QString( "%1/" ).arg( getenv("JAVA_HOME") )
#endif
#endif
#if defined( Q_WS_MACX )
QString JAVA_HOME = "a1234"; /* mac other java handler on fop */
#endif
#if defined(Q_WS_WIN)
#ifndef JAVA_HOME
#define JAVA_HOME \
QString( "%1/" ).arg( getenv("JAVA_HOME") )
#endif
#endif
/* http://xmlgraphics.apache.org/fop/ only java api
http://mirror.switch.ch/mirror/apache/dist/xmlgraphics/fop/binaries/fop-0.92beta-bin-jdk1.4.zip */

QString bindirapp;
#if defined(Q_WS_WIN)
bindirapp = QCoreApplication::applicationDirPath()+"/fop/fop.bat";
#else /* mac linux */
/* test "which fop" */
bindirapp = "/opt/fop/fop";
#endif
if (!is_file(bindirapp)) {
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>";
return false;
}

if (JAVA_HOME.size() > 3) {

QProcess process;
process.setReadChannelMode(QProcess::MergedChannel s);
process.start( bindirapp , QStringList() << fofile << pdffile);
if (!process.waitForFinished()) {
errormsg = "Error...! Transormtation! \n" + process.errorString() + "\nprogramm " +bindirapp;
return false;
} else {
errormsg = "Success Transormtation! \n" + process.readAll() + "\nprogramm " +bindirapp;
return true;
}
} else {
errormsg = "Error...! JAVA_HOME not found on your OS";
return false;
}
}


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

if moore as 8 cools landscape....


<!-- landscape or vertical? -->
<xsl:choose>
<xsl:when test="$bigcolumncount &gt; 8">
<!-- landscape -->
<fo:layout-master-set>
<fo:simple-page-master master-name="simple" page-height="21cm" page-width="30cm"
margin-top="1cm" margin-bottom="0.3cm" margin-left="1.2cm" margin-right="1.2cm">
<fo:region-body margin-bottom="2cm"/>
<fo:region-after extent="16pt"/>
</fo:simple-page-master>
</fo:layout-master-set>
</xsl:when>
<xsl:otherwise>
<!-- vertical -->
<fo:layout-master-set>
<fo:simple-page-master master-name="simple" page-height="29.7cm" page-width="21cm"
margin-top="1cm" margin-bottom="0.3cm" margin-left="1.4cm" margin-right="1.2cm">
<fo:region-body margin-bottom="2cm"/>
<fo:region-after extent="16pt"/>
</fo:simple-page-master>
</fo:layout-master-set>
</xsl:otherwise>
</xsl:choose>