From 4afd73f94b094d858c000432fcbbb134109d0323 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Tue, 14 Jul 2009 12:56:08 +0200 Subject: doc: Clarified what happens with a null Q3CString. If you call data() on a default constructed Q3CString, it returns a non-null pointer and from then on isNull() returns false. You have to use constData() to prevent the shared class from detaching the null representation and replacing it with an empty representation. Task-number: 210895 --- src/qt3support/tools/q3cstring.cpp | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/qt3support/tools/q3cstring.cpp b/src/qt3support/tools/q3cstring.cpp index 39f1c43..b33b9b6 100644 --- a/src/qt3support/tools/q3cstring.cpp +++ b/src/qt3support/tools/q3cstring.cpp @@ -77,11 +77,23 @@ QT_BEGIN_NAMESPACE and '\0' (NUL byte) terminated; otherwise the results are undefined. - A Q3CString that has not been assigned to anything is \e null, i.e. - both the length and the data pointer is 0. A Q3CString that - references the empty string ("", a single '\0' char) is \e empty. - Both null and empty Q3CStrings are legal parameters to the methods. - Assigning \c{const char *} 0 to Q3CString produces a null Q3CString. + A default constructed Q3CString is \e null, i.e. both the length + and the data pointer are 0 and isNull() returns true. + + \note However, if you ask for the data pointer of a null Q3CString + by calling data(), then because the internal representation of the + null Q3CString is shared, it will be detached and replaced with a + non-shared, empty representation, a non-null data pointer will be + returned, and subsequent calls to isNull() will return false. But + if you ask for the data pointer of a null Q3CString by calling + constData(), the shared internal representation is not detached, a + null data pointer is returned, and subsequent calls to isNull() + will continue to return true. + + A Q3CString that references the empty string ("", a single '\0' + char) is \e empty, i.e. isEmpty() returns true. Both null and + empty Q3CStrings are legal parameters to the methods. Assigning + \c{const char *} 0 to Q3CString produces a null Q3CString. The length() function returns the length of the string; resize() resizes the string and truncate() truncates the string. A string @@ -321,6 +333,16 @@ QT_BEGIN_NAMESPACE Returns true if the string is null, i.e. if data() == 0; otherwise returns false. A null string is also an empty string. + \note If you ask for the data pointer of a null Q3CString by + calling data(), then because the internal representation of the + null Q3CString is shared, it will be detached and replaced with a + non-shared, empty representation, a non-null data pointer will be + returned, and subsequent calls to isNull() will return false. But + if you ask for the data pointer of a null Q3CString by calling + constData(), the shared internal representation is not detached, a + null data pointer is returned, and subsequent calls to isNull() + will continue to return true. + Example: \snippet doc/src/snippets/code/src.qt3support.tools.q3cstring.cpp 1 -- cgit v0.12 From 9210e8cdc83b6812d10f5f5847d05703ef2e5f7c Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Tue, 14 Jul 2009 13:02:37 +0200 Subject: Fixed the qlineedit autotest. The commit 099a32d changed a behavior of qlineedit not to insert text when a modifier is pressed. This commit fixes the appropriate autotest. --- tests/auto/qlineedit/tst_qlineedit.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/auto/qlineedit/tst_qlineedit.cpp b/tests/auto/qlineedit/tst_qlineedit.cpp index 3519afa..7fc8316 100644 --- a/tests/auto/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/qlineedit/tst_qlineedit.cpp @@ -3025,11 +3025,11 @@ void tst_QLineEdit::charWithAltOrCtrlModifier() QTest::keyPress(testWidget, Qt::Key_Plus); QCOMPARE(testWidget->text(), QString("+")); QTest::keyPress(testWidget, Qt::Key_Plus, Qt::ControlModifier); - QCOMPARE(testWidget->text(), QString("++")); + QCOMPARE(testWidget->text(), QString("+")); QTest::keyPress(testWidget, Qt::Key_Plus, Qt::AltModifier); - QCOMPARE(testWidget->text(), QString("+++")); + QCOMPARE(testWidget->text(), QString("+")); QTest::keyPress(testWidget, Qt::Key_Plus, Qt::AltModifier | Qt::ControlModifier); - QCOMPARE(testWidget->text(), QString("++++")); + QCOMPARE(testWidget->text(), QString("+")); } void tst_QLineEdit::leftKeyOnSelectedText() -- cgit v0.12 From a2bad25383e565233a0c2527e04cef9f6b577f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Tue, 14 Jul 2009 13:03:10 +0200 Subject: Make sure QGraphicsScene::update() only requires one event-loop iteration before the views are updated. A full scene update (scene.update()) already supported it because the scene called update() on the views directly. However, partially scene updates (scene.update(rect)) required two event-loop iterations before the views were updated. Auto-test included. --- src/gui/graphicsview/qgraphicsscene.cpp | 14 ++++++------ src/gui/graphicsview/qgraphicsview.cpp | 10 +++------ src/gui/graphicsview/qgraphicsview_p.h | 10 +++++++++ tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp | 27 ++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 15 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index c8e178a..48d8788 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -357,6 +357,9 @@ void QGraphicsScenePrivate::_q_emitUpdated() updateAll = false; for (int i = 0; i < views.size(); ++i) views.at(i)->d_func()->processPendingUpdates(); + // It's important that we update all views before we dispatch, hence two for-loops. + for (int i = 0; i < views.size(); ++i) + views.at(i)->d_func()->dispatchPendingUpdateRequests(); return; } @@ -447,13 +450,8 @@ void QGraphicsScenePrivate::_q_processDirtyItems() } // Immediately dispatch all pending update requests on the views. - for (int i = 0; i < views.size(); ++i) { - QWidget *viewport = views.at(i)->d_func()->viewport; - if (qt_widget_private(viewport)->paintOnScreen()) - QCoreApplication::sendPostedEvents(viewport, QEvent::UpdateRequest); - else - QCoreApplication::sendPostedEvents(viewport->window(), QEvent::UpdateRequest); - } + for (int i = 0; i < views.size(); ++i) + views.at(i)->d_func()->dispatchPendingUpdateRequests(); } /*! @@ -2730,7 +2728,7 @@ void QGraphicsScene::update(const QRectF &rect) if (directUpdates) { // Update all views. for (int i = 0; i < d->views.size(); ++i) - d->views.at(i)->d_func()->updateAll(); + d->views.at(i)->d_func()->fullUpdatePending = true; } } else { if (directUpdates) { diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp index bcfd68c..1cea8db 100644 --- a/src/gui/graphicsview/qgraphicsview.cpp +++ b/src/gui/graphicsview/qgraphicsview.cpp @@ -821,13 +821,9 @@ void QGraphicsViewPrivate::processPendingUpdates() if (!scene) return; - if (fullUpdatePending) { // We have already called viewport->update() - dirtyBoundingRect = QRect(); - dirtyRegion = QRegion(); - return; - } - - if (viewportUpdateMode == QGraphicsView::BoundingRectViewportUpdate) { + if (fullUpdatePending) { + viewport->update(); + } else if (viewportUpdateMode == QGraphicsView::BoundingRectViewportUpdate) { if (optimizationFlags & QGraphicsView::DontAdjustForAntialiasing) viewport->update(dirtyBoundingRect.adjusted(-1, -1, 1, 1)); else diff --git a/src/gui/graphicsview/qgraphicsview_p.h b/src/gui/graphicsview/qgraphicsview_p.h index 0fa8b34..62a2b84 100644 --- a/src/gui/graphicsview/qgraphicsview_p.h +++ b/src/gui/graphicsview/qgraphicsview_p.h @@ -58,6 +58,7 @@ #if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW #include +#include #include "qgraphicssceneevent.h" #include #include @@ -168,6 +169,15 @@ public: dirtyBoundingRect = QRect(); dirtyRegion = QRegion(); } + + inline void dispatchPendingUpdateRequests() + { + if (qt_widget_private(viewport)->paintOnScreen()) + QCoreApplication::sendPostedEvents(viewport, QEvent::UpdateRequest); + else + QCoreApplication::sendPostedEvents(viewport->window(), QEvent::UpdateRequest); + } + bool updateRect(const QRect &rect); bool updateRegion(const QRegion ®ion); bool updateSceneSlotReimplementedChecked; diff --git a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp index e9d6f1d..f7ea4ce 100644 --- a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp @@ -236,6 +236,7 @@ private slots: void contextMenuEvent(); void contextMenuEvent_ItemIgnoresTransformations(); void update(); + void update2(); void views(); void event(); void eventsToDisabledItems(); @@ -2779,6 +2780,32 @@ void tst_QGraphicsScene::update() QCOMPARE(region, QRectF(-100, -100, 200, 200)); } +void tst_QGraphicsScene::update2() +{ + QGraphicsScene scene; + scene.setSceneRect(-200, -200, 200, 200); + CustomView view; + view.setScene(&scene); + view.show(); +#ifdef Q_WS_X11 + qt_x11_wait_for_window_manager(&view); +#endif + QTest::qWait(250); + view.repaints = 0; + + // Make sure QGraphicsScene::update only requires one event-loop iteration + // before the view is updated. + scene.update(); + qApp->processEvents(); + QCOMPARE(view.repaints, 1); + view.repaints = 0; + + // The same for partial scene updates. + scene.update(QRectF(-100, -100, 100, 100)); + qApp->processEvents(); + QCOMPARE(view.repaints, 1); +} + void tst_QGraphicsScene::views() { QGraphicsScene scene; -- cgit v0.12 From ec11bd70c78cbdb07b399b058fabdb16d66072b0 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Tue, 14 Jul 2009 13:05:11 +0200 Subject: QNetworkReply: Add isFinished() method The isFinished() method will return true if the reply has successfully finished or has been aborted. Task-number: 257349 Reviewed-by: Thiago Macieira --- src/network/access/qnetworkreply.cpp | 21 +++++++++++++++++++++ src/network/access/qnetworkreply.h | 2 ++ src/network/access/qnetworkreply_p.h | 2 ++ src/network/access/qnetworkreplyimpl.cpp | 5 +++++ src/network/access/qnetworkreplyimpl_p.h | 2 ++ tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 10 ++++++++++ 6 files changed, 42 insertions(+) diff --git a/src/network/access/qnetworkreply.cpp b/src/network/access/qnetworkreply.cpp index 1b0d9f5..e55c202 100644 --- a/src/network/access/qnetworkreply.cpp +++ b/src/network/access/qnetworkreply.cpp @@ -442,6 +442,27 @@ QNetworkReply::NetworkError QNetworkReply::error() const } /*! + Returns true when the reply has finished or was aborted. + + \sa isRunning() +*/ +bool QNetworkReply::isFinished() const +{ + return d_func()->isFinished(); +} + +/*! + Returns true when the request is still processing and the + reply has not finished or was aborted yet. + + \sa isFinished() +*/ +bool QNetworkReply::isRunning() const +{ + return !isFinished(); +} + +/*! Returns the URL of the content downloaded or uploaded. Note that the URL may be different from that of the original request. diff --git a/src/network/access/qnetworkreply.h b/src/network/access/qnetworkreply.h index 7cb082f..30e89f1 100644 --- a/src/network/access/qnetworkreply.h +++ b/src/network/access/qnetworkreply.h @@ -116,6 +116,8 @@ public: QNetworkAccessManager::Operation operation() const; QNetworkRequest request() const; NetworkError error() const; + bool isFinished() const; + bool isRunning() const; QUrl url() const; // "cooked" headers diff --git a/src/network/access/qnetworkreply_p.h b/src/network/access/qnetworkreply_p.h index c8543f0..b51e3fb 100644 --- a/src/network/access/qnetworkreply_p.h +++ b/src/network/access/qnetworkreply_p.h @@ -75,6 +75,8 @@ public: static inline void setManager(QNetworkReply *reply, QNetworkAccessManager *manager) { reply->d_func()->manager = manager; } + virtual bool isFinished() const { return false; } + Q_DECLARE_PUBLIC(QNetworkReply) }; diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index b11d986..55b8b7f 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -532,6 +532,11 @@ void QNetworkReplyImplPrivate::sslErrors(const QList &errors) #endif } +bool QNetworkReplyImplPrivate::isFinished() const +{ + return (state == Finished || state == Aborted); +} + QNetworkReplyImpl::QNetworkReplyImpl(QObject *parent) : QNetworkReply(*new QNetworkReplyImplPrivate, parent) { diff --git a/src/network/access/qnetworkreplyimpl_p.h b/src/network/access/qnetworkreplyimpl_p.h index 3e89a00..454185a 100644 --- a/src/network/access/qnetworkreplyimpl_p.h +++ b/src/network/access/qnetworkreplyimpl_p.h @@ -152,6 +152,8 @@ public: void redirectionRequested(const QUrl &target); void sslErrors(const QList &errors); + bool isFinished() const; + QNetworkAccessBackend *backend; QIODevice *outgoingData; QRingBuffer *outgoingDataBuffer; diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index cb1cb9b..f2bfb1f 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -1003,6 +1003,7 @@ void tst_QNetworkReply::stateChecking() QCOMPARE(reply->request(), req); QCOMPARE(int(reply->operation()), int(QNetworkAccessManager::GetOperation)); QCOMPARE(reply->error(), QNetworkReply::NoError); + QCOMPARE(reply->isFinished(), false); QCOMPARE(reply->url(), url); reply->abort(); @@ -1324,6 +1325,9 @@ void tst_QNetworkReply::getErrors() QTEST(reply->readAll().isEmpty(), "dataIsEmpty"); + QVERIFY(reply->isFinished()); + QVERIFY(!reply->isRunning()); + QFETCH(int, httpStatusCode); if (httpStatusCode != 0) { QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), httpStatusCode); @@ -3237,6 +3241,8 @@ void tst_QNetworkReply::downloadProgress() connect(reply, SIGNAL(downloadProgress(qint64,qint64)), &QTestEventLoop::instance(), SLOT(exitLoop())); QVERIFY(spy.isValid()); + QVERIFY(!reply->isFinished()); + QVERIFY(reply->isRunning()); QCoreApplication::instance()->processEvents(); if (!server.hasPendingConnections()) @@ -3257,6 +3263,8 @@ void tst_QNetworkReply::downloadProgress() QTestEventLoop::instance().enterLoop(2); QVERIFY(!QTestEventLoop::instance().timeout()); QVERIFY(spy.count() > 0); + QVERIFY(!reply->isFinished()); + QVERIFY(reply->isRunning()); QList args = spy.last(); QCOMPARE(args.at(0).toInt(), i*data.size()); @@ -3270,6 +3278,8 @@ void tst_QNetworkReply::downloadProgress() QTestEventLoop::instance().enterLoop(2); QVERIFY(!QTestEventLoop::instance().timeout()); QVERIFY(spy.count() > 0); + QVERIFY(!reply->isRunning()); + QVERIFY(reply->isFinished()); QList args = spy.last(); QCOMPARE(args.at(0).toInt(), loopCount * data.size()); -- cgit v0.12