summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan-Arve Sæther <jan-arve.saether@nokia.com>2009-10-28 09:58:16 (GMT)
committerJan-Arve Sæther <jan-arve.saether@nokia.com>2009-10-28 09:58:16 (GMT)
commit42fdaf078b9332e13d260df00359e8adc8522872 (patch)
tree6a1d7b675b788372720e928e4e2aba77bfcad552
parent262d0df3b166fecb3502e81b2ab85cadd71ae70f (diff)
parenta925ba1ab6316a155f2ac61f898c52f07a1340b4 (diff)
downloadQt-42fdaf078b9332e13d260df00359e8adc8522872.zip
Qt-42fdaf078b9332e13d260df00359e8adc8522872.tar.gz
Qt-42fdaf078b9332e13d260df00359e8adc8522872.tar.bz2
Merge branch '4.6' of scm.dev.nokia.troll.no:qt/qt-widget-team into 4.6
-rw-r--r--dist/changes-4.6.03
-rw-r--r--src/corelib/kernel/qobject.cpp7
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp2
-rw-r--r--src/gui/text/qtextdocument.cpp18
-rw-r--r--src/gui/widgets/qsplitter.cpp17
-rw-r--r--tests/auto/qgraphicsobject/tst_qgraphicsobject.cpp42
-rw-r--r--tests/auto/qsplitter/tst_qsplitter.cpp34
-rw-r--r--tests/auto/qtextdocument/qtextdocument.pro1
-rw-r--r--tests/auto/qtextdocument/tst_qtextdocument.cpp56
9 files changed, 160 insertions, 20 deletions
diff --git a/dist/changes-4.6.0 b/dist/changes-4.6.0
index 7f723da..ba2b051 100644
--- a/dist/changes-4.6.0
+++ b/dist/changes-4.6.0
@@ -35,6 +35,9 @@ information about a particular change.
* Added QVariant::toFloat() and QVariant::toReal()
* Added QVariant(float) constructor
+ - Qt::escape
+ * now escape the double quote (&quot;)
+
****************************************************************************
* Platform Specific Changes *
****************************************************************************
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index 7be19b3..5303975 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -835,14 +835,7 @@ QObject::QObject(QObjectPrivate &dd, QObject *parent)
QObject::~QObject()
{
Q_D(QObject);
- if (d->wasDeleted) {
-#if defined(QT_DEBUG)
- qWarning("QObject: Double deletion detected");
-#endif
- return;
- }
d->wasDeleted = true;
-
d->blockSig = 0; // unblock signals so we always emit destroyed()
if (!d->isWidget) {
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index c38365b..0107fba 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -1286,6 +1286,8 @@ QGraphicsItem::QGraphicsItem(QGraphicsItemPrivate &dd, QGraphicsItem *parent,
*/
QGraphicsItem::~QGraphicsItem()
{
+ if (d_ptr->isObject)
+ QObjectPrivate::get(static_cast<QGraphicsObject *>(this))->wasDeleted = true;
d_ptr->inDestructor = 1;
d_ptr->removeExtraItemCache();
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp
index a8956b8..6978b6c 100644
--- a/src/gui/text/qtextdocument.cpp
+++ b/src/gui/text/qtextdocument.cpp
@@ -140,7 +140,7 @@ bool Qt::mightBeRichText(const QString& text)
/*!
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 +162,8 @@ QString Qt::escape(const QString& plain)
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);
}
@@ -2038,7 +2040,7 @@ void QTextHtmlExporter::emitAttribute(const char *attribute, const QString &valu
html += QLatin1Char(' ');
html += QLatin1String(attribute);
html += QLatin1String("=\"");
- html += value;
+ html += Qt::escape(value);
html += QLatin1Char('"');
}
@@ -2302,12 +2304,12 @@ void QTextHtmlExporter::emitFontFamily(const QString &family)
{
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 +2343,13 @@ void QTextHtmlExporter::emitFragment(const QTextFragment &fragment)
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;
}
diff --git a/src/gui/widgets/qsplitter.cpp b/src/gui/widgets/qsplitter.cpp
index e3121ae..520a802 100644
--- a/src/gui/widgets/qsplitter.cpp
+++ b/src/gui/widgets/qsplitter.cpp
@@ -360,13 +360,26 @@ void QSplitterPrivate::recalc(bool update)
before a hidden widget must be hidden.
*/
bool first = true;
+ bool allInvisible = n != 0;
for (int i = 0; i < n ; ++i) {
QSplitterLayoutStruct *s = list.at(i);
- s->handle->setHidden(first || s->widget->isHidden());
- if (!s->widget->isHidden())
+ bool widgetHidden = s->widget->isHidden();
+ if (allInvisible && !widgetHidden && !s->collapsed)
+ allInvisible = false;
+ s->handle->setHidden(first || widgetHidden);
+ if (!widgetHidden)
first = false;
}
+ if (allInvisible)
+ for (int i = 0; i < n ; ++i) {
+ QSplitterLayoutStruct *s = list.at(i);
+ if (!s->widget->isHidden()) {
+ s->collapsed = false;
+ break;
+ }
+ }
+
int fi = 2 * q->frameWidth();
int maxl = fi;
int minl = fi;
diff --git a/tests/auto/qgraphicsobject/tst_qgraphicsobject.cpp b/tests/auto/qgraphicsobject/tst_qgraphicsobject.cpp
index a9fd55a..194665d 100644
--- a/tests/auto/qgraphicsobject/tst_qgraphicsobject.cpp
+++ b/tests/auto/qgraphicsobject/tst_qgraphicsobject.cpp
@@ -46,6 +46,7 @@
#include <qgraphicssceneevent.h>
#include <qgraphicsview.h>
#include <qstyleoption.h>
+#include <private/qobject_p.h>
#include "../../shared/util.h"
class tst_QGraphicsObject : public QObject {
@@ -65,6 +66,7 @@ private slots:
void opacity();
void enabled();
void visible();
+ void deleted();
};
@@ -249,6 +251,46 @@ void tst_QGraphicsObject::visible()
QVERIFY(object.property("visible") == true);
}
+class DeleteTester : public QGraphicsObject
+{
+public:
+ DeleteTester(bool *w, bool *pw, QGraphicsItem *parent = 0)
+ : QGraphicsObject(parent), wasDeleted(w), parentWasDeleted(pw)
+ { }
+
+ ~DeleteTester()
+ {
+ *wasDeleted = QObjectPrivate::get(this)->wasDeleted;
+ if (QGraphicsItem *p = parentItem()) {
+ if (QGraphicsObject *o = p->toGraphicsObject())
+ *parentWasDeleted = QObjectPrivate::get(o)->wasDeleted;
+ }
+ }
+
+ void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0)
+ { }
+ QRectF boundingRect() const
+ { return QRectF(); }
+
+ bool *wasDeleted;
+ bool *parentWasDeleted;
+};
+
+void tst_QGraphicsObject::deleted()
+{
+ bool item1_parentWasDeleted = false;
+ bool item1_wasDeleted = false;
+ bool item2_parentWasDeleted = false;
+ bool item2_wasDeleted = false;
+ DeleteTester *item1 = new DeleteTester(&item1_wasDeleted, &item1_parentWasDeleted);
+ DeleteTester *item2 = new DeleteTester(&item2_wasDeleted, &item2_parentWasDeleted, item1);
+ delete item1;
+
+ QVERIFY(!item1_wasDeleted); // destructor not called yet
+ QVERIFY(!item1_parentWasDeleted); // no parent
+ QVERIFY(!item2_wasDeleted); // destructor not called yet
+ QVERIFY(item2_parentWasDeleted);
+}
QTEST_MAIN(tst_QGraphicsObject)
#include "tst_qgraphicsobject.moc"
diff --git a/tests/auto/qsplitter/tst_qsplitter.cpp b/tests/auto/qsplitter/tst_qsplitter.cpp
index cf16421..b832f3a 100644
--- a/tests/auto/qsplitter/tst_qsplitter.cpp
+++ b/tests/auto/qsplitter/tst_qsplitter.cpp
@@ -102,6 +102,8 @@ private slots:
void task187373_addAbstractScrollAreas();
void task187373_addAbstractScrollAreas_data();
void task169702_sizes();
+ void taskQTBUG_4101_ensureOneNonCollapsedWidget_data();
+ void taskQTBUG_4101_ensureOneNonCollapsedWidget();
private:
void removeThirdWidget();
@@ -1281,6 +1283,8 @@ class MyFriendlySplitter : public QSplitter
public:
MyFriendlySplitter(QWidget *parent = 0) : QSplitter(parent) {}
void setRubberBand(int pos) { QSplitter::setRubberBand(pos); }
+
+ friend class tst_QSplitter;
};
void tst_QSplitter::rubberBandNotInSplitter()
@@ -1403,5 +1407,35 @@ void tst_QSplitter::task169702_sizes()
QCOMPARE(testW->size().height(), testW->minimumSizeHint().height());
}
+void tst_QSplitter::taskQTBUG_4101_ensureOneNonCollapsedWidget_data()
+{
+ QTest::addColumn<bool>("testingHide");
+
+ QTest::newRow("last non collapsed hidden") << true;
+ QTest::newRow("last non collapsed deleted") << false;
+}
+
+void tst_QSplitter::taskQTBUG_4101_ensureOneNonCollapsedWidget()
+{
+ QFETCH(bool, testingHide);
+
+ MyFriendlySplitter s;
+ QLabel *l;
+ for (int i = 0; i < 5; ++i) {
+ l = new QLabel(QString("Label ") + QChar('A' + i));
+ l->setAlignment(Qt::AlignCenter);
+ s.addWidget(l);
+ s.moveSplitter(0, i); // Collapse all the labels except the last one.
+ }
+
+ s.show();
+ if (testingHide)
+ l->hide();
+ else
+ delete l;
+ QTest::qWait(100);
+ QVERIFY(s.sizes().at(0) > 0);
+}
+
QTEST_MAIN(tst_QSplitter)
#include "tst_qsplitter.moc"
diff --git a/tests/auto/qtextdocument/qtextdocument.pro b/tests/auto/qtextdocument/qtextdocument.pro
index d3ec45d..1e44a9c 100644
--- a/tests/auto/qtextdocument/qtextdocument.pro
+++ b/tests/auto/qtextdocument/qtextdocument.pro
@@ -1,4 +1,5 @@
load(qttest_p4)
+QT += xml
HEADERS += common.h
SOURCES += tst_qtextdocument.cpp
diff --git a/tests/auto/qtextdocument/tst_qtextdocument.cpp b/tests/auto/qtextdocument/tst_qtextdocument.cpp
index f393393..5237438 100644
--- a/tests/auto/qtextdocument/tst_qtextdocument.cpp
+++ b/tests/auto/qtextdocument/tst_qtextdocument.cpp
@@ -59,6 +59,7 @@
#include <qfontmetrics.h>
#include <qimage.h>
#include <qtextlayout.h>
+#include <QDomDocument>
#include "common.h"
@@ -175,6 +176,8 @@ private slots:
void testUndoBlocks();
void receiveCursorPositionChangedAfterContentsChange();
+ void escape_data();
+ void escape();
private:
void backgroundImage_checkExpectedHtml(const QTextDocument &doc);
@@ -576,7 +579,7 @@ void tst_QTextDocument::task240325()
}
void tst_QTextDocument::stylesheetFont_data()
-{
+{
QTest::addColumn<QString>("stylesheet");
QTest::addColumn<QFont>("font");
@@ -732,7 +735,7 @@ void tst_QTextDocument::toHtml_data()
cursor.insertText("Blah", fmt);
QTest::newRow("font-family-with-quotes1") << QTextDocumentFragment(&doc)
- << QString("<p DEFAULTBLOCKSTYLE><span style=\" font-family:\"Foo's Family\";\">Blah</span></p>");
+ << QString("<p DEFAULTBLOCKSTYLE><span style=\" font-family:&quot;Foo's Family&quot;;\">Blah</span></p>");
}
{
@@ -743,7 +746,7 @@ void tst_QTextDocument::toHtml_data()
cursor.insertText("Blah", fmt);
QTest::newRow("font-family-with-quotes2") << QTextDocumentFragment(&doc)
- << QString("<p DEFAULTBLOCKSTYLE><span style=\" font-family:'Foo\"s Family';\">Blah</span></p>");
+ << QString("<p DEFAULTBLOCKSTYLE><span style=\" font-family:'Foo&quot;s Family';\">Blah</span></p>");
}
{
@@ -974,6 +977,30 @@ void tst_QTextDocument::toHtml_data()
{
CREATE_DOC_AND_CURSOR();
+ QTextCharFormat fmt;
+ fmt.setAnchor(true);
+ fmt.setAnchorHref("http://www.kde.org/?a=1&b=2");
+ cursor.insertText("Blah", fmt);
+
+ QTest::newRow("href anchor with &") << QTextDocumentFragment(&doc)
+ << QString("<p DEFAULTBLOCKSTYLE><a href=\"http://www.kde.org/?a=1&amp;b=2\">Blah</a></p>");
+ }
+
+ {
+ CREATE_DOC_AND_CURSOR();
+
+ QTextCharFormat fmt;
+ fmt.setAnchor(true);
+ fmt.setAnchorHref("http://www.kde.org/?a='&b=\"");
+ cursor.insertText("Blah", fmt);
+
+ QTest::newRow("href anchor with ' and \"") << QTextDocumentFragment(&doc)
+ << QString("<p DEFAULTBLOCKSTYLE><a href=\"http://www.kde.org/?a='&amp;b=&quot;\">Blah</a></p>");
+ }
+
+ {
+ CREATE_DOC_AND_CURSOR();
+
cursor.insertTable(2, 2);
QTest::newRow("simpletable") << QTextDocumentFragment(&doc)
@@ -1541,6 +1568,9 @@ void tst_QTextDocument::toHtml()
QString output = doc->toHtml();
QCOMPARE(output, expectedOutput);
+
+ QDomDocument document;
+ QVERIFY2(document.setContent(output), "Output was not valid XML");
}
void tst_QTextDocument::toHtml2()
@@ -2652,5 +2682,25 @@ void tst_QTextDocument::receiveCursorPositionChangedAfterContentsChange()
QCOMPARE(rec.first, QString("contentsChanged"));
}
+void tst_QTextDocument::escape_data()
+{
+ QTest::addColumn<QString>("original");
+ QTest::addColumn<QString>("expected");
+
+ QTest::newRow("1") << "Hello World\n" << "Hello World\n";
+ QTest::newRow("2") << "#include <QtCore>" << "#include &lt;QtCore&gt;";
+ QTest::newRow("3") << "<p class=\"cool\"><a href=\"http://example.com/?foo=bar&amp;bar=foo\">plop --&gt; </a></p>"
+ << "&lt;p class=&quot;cool&quot;&gt;&lt;a href=&quot;http://example.com/?foo=bar&amp;amp;bar=foo&quot;&gt;plop --&amp;gt; &lt;/a&gt;&lt;/p&gt;";
+ QTest::newRow("4") << QString::fromUtf8("<\320\222\321\201>") << QString::fromUtf8("&lt;\320\222\321\201&gt;");
+}
+
+void tst_QTextDocument::escape()
+{
+ QFETCH(QString, original);
+ QFETCH(QString, expected);
+
+ QCOMPARE(Qt::escape(original), expected);
+}
+
QTEST_MAIN(tst_QTextDocument)
#include "tst_qtextdocument.moc"