src/gui/text/qtextdocument.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
--- a/src/gui/text/qtextdocument.cpp	Tue Jan 26 12:42:25 2010 +0200
+++ b/src/gui/text/qtextdocument.cpp	Tue Feb 02 00:43:10 2010 +0200
@@ -64,6 +64,7 @@
 
 #include "qtextdocument_p.h"
 #include <private/qprinter_p.h>
+#include <private/qabstracttextdocumentlayout_p.h>
 
 #include <limits.h>
 
@@ -140,7 +141,7 @@
 
 /*!
     Converts the plain text string \a plain to a HTML string with
-    HTML metacharacters \c{<}, \c{>}, and \c{&} replaced by HTML
+    HTML metacharacters \c{<}, \c{>}, \c{&}, and \c{"} replaced by HTML
     entities.
 
     Example:
@@ -162,6 +163,8 @@
             rich += QLatin1String("&gt;");
         else if (plain.at(i) == QLatin1Char('&'))
             rich += QLatin1String("&amp;");
+        else if (plain.at(i) == QLatin1Char('"'))
+            rich += QLatin1String("&quot;");
         else
             rich += plain.at(i);
     }
@@ -956,6 +959,8 @@
 
 /*!
     Returns true if undo is available; otherwise returns false.
+
+    \sa isRedoAvailable(), availableUndoSteps()
 */
 bool QTextDocument::isUndoAvailable() const
 {
@@ -965,6 +970,8 @@
 
 /*!
     Returns true if redo is available; otherwise returns false.
+
+    \sa isUndoAvailable(), availableRedoSteps()
 */
 bool QTextDocument::isRedoAvailable() const
 {
@@ -972,6 +979,29 @@
     return d->isRedoAvailable();
 }
 
+/*! \since 4.6
+
+    Returns the number of available undo steps.
+
+    \sa isUndoAvailable()
+*/
+int QTextDocument::availableUndoSteps() const
+{
+    Q_D(const QTextDocument);
+    return d->availableUndoSteps();
+}
+
+/*! \since 4.6
+
+    Returns the number of available redo steps.
+
+    \sa isRedoAvailable()
+*/
+int QTextDocument::availableRedoSteps() const
+{
+    Q_D(const QTextDocument);
+    return d->availableRedoSteps();
+}
 
 /*! \since 4.4
 
@@ -1693,6 +1723,9 @@
         QAbstractTextDocumentLayout *layout = doc->documentLayout();
         layout->setPaintDevice(p.device());
 
+        // copy the custom object handlers
+        layout->d_func()->handlers = documentLayout()->d_func()->handlers;
+
         int dpiy = p.device()->logicalDpiY();
         int margin = 0;
         if (printer->fullPage() && !printer->d_func()->hasCustomPageMargins) {
@@ -1734,6 +1767,12 @@
     fromPage = qMax(1, fromPage);
     toPage = qMin(doc->pageCount(), toPage);
 
+    if (toPage < fromPage) {
+        // if the user entered a page range outside the actual number
+        // of printable pages, just return
+        return;
+    }
+
     if (printer->pageOrder() == QPrinter::LastPageFirst) {
         int tmp = fromPage;
         fromPage = toPage;
@@ -2038,7 +2077,7 @@
     html += QLatin1Char(' ');
     html += QLatin1String(attribute);
     html += QLatin1String("=\"");
-    html += value;
+    html += Qt::escape(value);
     html += QLatin1Char('"');
 }
 
@@ -2302,12 +2341,12 @@
 {
     html += QLatin1String(" font-family:");
 
-    QLatin1Char quote('\'');
-    if (family.contains(quote))
-        quote = QLatin1Char('\"');
+    QLatin1String quote("\'");
+    if (family.contains(QLatin1Char('\'')))
+        quote = QLatin1String("&quot;");
 
     html += quote;
-    html += family;
+    html += Qt::escape(family);
     html += quote;
     html += QLatin1Char(';');
 }
@@ -2341,13 +2380,13 @@
         const QString name = format.anchorName();
         if (!name.isEmpty()) {
             html += QLatin1String("<a name=\"");
-            html += name;
+            html += Qt::escape(name);
             html += QLatin1String("\"></a>");
         }
         const QString href = format.anchorHref();
         if (!href.isEmpty()) {
             html += QLatin1String("<a href=\"");
-            html += href;
+            html += Qt::escape(href);
             html += QLatin1String("\">");
             closeAnchor = true;
         }