diff options
-rw-r--r-- | src/corelib/tools/qscopedpointer.cpp | 4 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsscene.cpp | 6 | ||||
-rw-r--r-- | src/gui/text/qtextdocument.cpp | 9 | ||||
-rw-r--r-- | tests/auto/qgraphicsview/tst_qgraphicsview.cpp | 26 |
4 files changed, 32 insertions, 13 deletions
diff --git a/src/corelib/tools/qscopedpointer.cpp b/src/corelib/tools/qscopedpointer.cpp index e7dd769..b06112d 100644 --- a/src/corelib/tools/qscopedpointer.cpp +++ b/src/corelib/tools/qscopedpointer.cpp @@ -57,7 +57,7 @@ QT_BEGIN_NAMESPACE called resource acquisition is initialization(RAII). QScopedPointer guarantees that the object pointed to will get deleted when - the current scope dissapears. + the current scope disappears. Consider this function which does heap allocations, and have various exit points: @@ -227,7 +227,7 @@ QT_BEGIN_NAMESPACE /*! \class QScopedArrayPointer - + \brief The QScopedArrayPointer class stores a pointer to a dynamically allocated array of objects, and deletes it upon destruction. diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index b368a82..98fc10f 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -808,13 +808,13 @@ void QGraphicsScenePrivate::setFocusItemHelper(QGraphicsItem *item, #endif //QT_NO_IM } - if (item) { + if (item) focusItem = item; + updateInputMethodSensitivityInViews(); + if (item) { QFocusEvent event(QEvent::FocusIn, focusReason); sendEvent(item, &event); } - - updateInputMethodSensitivityInViews(); } /*! diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index f5d322a..1677ee6 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -1679,7 +1679,7 @@ void QTextDocument::print(QPrinter *printer) const return; const QTextDocument *doc = this; - QTextDocument *clonedDoc = 0; + QScopedPointer<QTextDocument> clonedDoc; (void)doc->documentLayout(); // make sure that there is a layout QRectF body = QRectF(QPointF(0, 0), d->pageSize); @@ -1712,7 +1712,7 @@ void QTextDocument::print(QPrinter *printer) const printerPageSize.height() / scaledPageSize.height()); } else { doc = clone(const_cast<QTextDocument *>(this)); - clonedDoc = const_cast<QTextDocument *>(doc); + clonedDoc.reset(const_cast<QTextDocument *>(doc)); for (QTextBlock srcBlock = firstBlock(), dstBlock = clonedDoc->firstBlock(); srcBlock.isValid() && dstBlock.isValid(); @@ -1787,7 +1787,7 @@ void QTextDocument::print(QPrinter *printer) const for (int j = 0; j < pageCopies; ++j) { if (printer->printerState() == QPrinter::Aborted || printer->printerState() == QPrinter::Error) - goto UserCanceled; + return; printPage(page, &p, doc, body, pageNumberPos); if (j < pageCopies - 1) printer->newPage(); @@ -1807,9 +1807,6 @@ void QTextDocument::print(QPrinter *printer) const if ( i < docCopies - 1) printer->newPage(); } - -UserCanceled: - delete clonedDoc; } #endif diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp index 1c19fab..e3c699b 100644 --- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp @@ -3664,6 +3664,22 @@ void tst_QGraphicsView::update() #endif } +class FocusItem : public QGraphicsRectItem +{ +public: + FocusItem() : QGraphicsRectItem(0, 0, 20, 20) { + m_viewHasIMEnabledInFocusInEvent = false; + } + + void focusInEvent(QFocusEvent *event) + { + QGraphicsView *view = scene()->views().first(); + m_viewHasIMEnabledInFocusInEvent = view->testAttribute(Qt::WA_InputMethodEnabled); + } + + bool m_viewHasIMEnabledInFocusInEvent; +}; + void tst_QGraphicsView::inputMethodSensitivity() { QGraphicsScene scene; @@ -3673,7 +3689,7 @@ void tst_QGraphicsView::inputMethodSensitivity() QApplication::setActiveWindow(&view); QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view)); - QGraphicsRectItem *item = new QGraphicsRectItem; + FocusItem *item = new FocusItem; view.setAttribute(Qt::WA_InputMethodEnabled, true); @@ -3702,6 +3718,7 @@ void tst_QGraphicsView::inputMethodSensitivity() scene.setFocusItem(item); QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); + QCOMPARE(item->m_viewHasIMEnabledInFocusInEvent, true); item->setFlag(QGraphicsItem::ItemAcceptsInputMethod, false); QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); @@ -3710,15 +3727,17 @@ void tst_QGraphicsView::inputMethodSensitivity() QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); // introduce another item that is focusable but does not accept input methods - QGraphicsRectItem *item2 = new QGraphicsRectItem; + FocusItem *item2 = new FocusItem; item2->setFlag(QGraphicsItem::ItemIsFocusable); scene.addItem(item2); scene.setFocusItem(item2); QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); + QCOMPARE(item2->m_viewHasIMEnabledInFocusInEvent, false); QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item2)); scene.setFocusItem(item); QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); + QCOMPARE(item->m_viewHasIMEnabledInFocusInEvent, true); QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); view.setScene(0); @@ -3727,10 +3746,12 @@ void tst_QGraphicsView::inputMethodSensitivity() view.setScene(&scene); QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); + QCOMPARE(item->m_viewHasIMEnabledInFocusInEvent, true); QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); scene.setFocusItem(item2); QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); + QCOMPARE(item2->m_viewHasIMEnabledInFocusInEvent, false); QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item2)); view.setScene(0); @@ -3743,6 +3764,7 @@ void tst_QGraphicsView::inputMethodSensitivity() view.setScene(&scene); QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); + QCOMPARE(item->m_viewHasIMEnabledInFocusInEvent, true); QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); } |