diff options
-rw-r--r-- | src/gui/itemviews/qstandarditemmodel.cpp | 20 | ||||
-rw-r--r-- | src/gui/itemviews/qstandarditemmodel_p.h | 4 | ||||
-rw-r--r-- | src/gui/kernel/qwidget_s60.cpp | 44 | ||||
-rw-r--r-- | tests/auto/exceptionsafety_objects/tst_exceptionsafety_objects.cpp | 16 |
4 files changed, 48 insertions, 36 deletions
diff --git a/src/gui/itemviews/qstandarditemmodel.cpp b/src/gui/itemviews/qstandarditemmodel.cpp index b960fae..25acbc4 100644 --- a/src/gui/itemviews/qstandarditemmodel.cpp +++ b/src/gui/itemviews/qstandarditemmodel.cpp @@ -329,7 +329,6 @@ QStandardItemModelPrivate::QStandardItemModelPrivate() */ QStandardItemModelPrivate::~QStandardItemModelPrivate() { - delete root; delete itemPrototype; qDeleteAll(columnHeaderItems); qDeleteAll(rowHeaderItems); @@ -554,7 +553,7 @@ void QStandardItemModelPrivate::rowsInserted(QStandardItem *parent, int row, int count) { Q_Q(QStandardItemModel); - if (parent == root) + if (parent == root.data()) rowHeaderItems.insert(row, count, 0); q->endInsertRows(); } @@ -566,7 +565,7 @@ void QStandardItemModelPrivate::columnsInserted(QStandardItem *parent, int column, int count) { Q_Q(QStandardItemModel); - if (parent == root) + if (parent == root.data()) columnHeaderItems.insert(column, count, 0); q->endInsertColumns(); } @@ -578,7 +577,7 @@ void QStandardItemModelPrivate::rowsRemoved(QStandardItem *parent, int row, int count) { Q_Q(QStandardItemModel); - if (parent == root) { + if (parent == root.data()) { for (int i = row; i < row + count; ++i) { QStandardItem *oldItem = rowHeaderItems.at(i); if (oldItem) @@ -597,7 +596,7 @@ void QStandardItemModelPrivate::columnsRemoved(QStandardItem *parent, int column, int count) { Q_Q(QStandardItemModel); - if (parent == root) { + if (parent == root.data()) { for (int i = column; i < column + count; ++i) { QStandardItem *oldItem = columnHeaderItems.at(i); if (oldItem) @@ -788,7 +787,7 @@ QStandardItem::~QStandardItem() QStandardItem *QStandardItem::parent() const { Q_D(const QStandardItem); - if (!d->model || (d->model->d_func()->root != d->parent)) + if (!d->model || (d->model->d_func()->root.data() != d->parent)) return d->parent; return 0; } @@ -2083,8 +2082,7 @@ QStandardItemModel::~QStandardItemModel() void QStandardItemModel::clear() { Q_D(QStandardItemModel); - delete d->root; - d->root = new QStandardItem; + d->root.reset(new QStandardItem); d->root->d_func()->setModel(this); qDeleteAll(d->columnHeaderItems); d->columnHeaderItems.clear(); @@ -2231,7 +2229,7 @@ QStandardItem *QStandardItemModel::item(int row, int column) const QStandardItem *QStandardItemModel::invisibleRootItem() const { Q_D(const QStandardItemModel); - return d->root; + return d->root.data(); } /*! @@ -2733,7 +2731,7 @@ QModelIndex QStandardItemModel::index(int row, int column, const QModelIndex &pa bool QStandardItemModel::insertColumns(int column, int count, const QModelIndex &parent) { Q_D(QStandardItemModel); - QStandardItem *item = parent.isValid() ? itemFromIndex(parent) : d->root; + QStandardItem *item = parent.isValid() ? itemFromIndex(parent) : d->root.data(); if (item == 0) return false; return item->d_func()->insertColumns(column, count, QList<QStandardItem*>()); @@ -2745,7 +2743,7 @@ bool QStandardItemModel::insertColumns(int column, int count, const QModelIndex bool QStandardItemModel::insertRows(int row, int count, const QModelIndex &parent) { Q_D(QStandardItemModel); - QStandardItem *item = parent.isValid() ? itemFromIndex(parent) : d->root; + QStandardItem *item = parent.isValid() ? itemFromIndex(parent) : d->root.data(); if (item == 0) return false; return item->d_func()->insertRows(row, count, QList<QStandardItem*>()); diff --git a/src/gui/itemviews/qstandarditemmodel_p.h b/src/gui/itemviews/qstandarditemmodel_p.h index b2b16d1..8be8e9e 100644 --- a/src/gui/itemviews/qstandarditemmodel_p.h +++ b/src/gui/itemviews/qstandarditemmodel_p.h @@ -152,7 +152,7 @@ public: inline QStandardItem *itemFromIndex(const QModelIndex &index) const { Q_Q(const QStandardItemModel); if (!index.isValid()) - return root; + return root.data(); if (index.model() != q) return 0; QStandardItem *parent = static_cast<QStandardItem*>(index.internalPointer()); @@ -177,7 +177,7 @@ public: QVector<QStandardItem*> columnHeaderItems; QVector<QStandardItem*> rowHeaderItems; - QStandardItem *root; + QScopedPointer<QStandardItem> root; const QStandardItem *itemPrototype; int sortRole; }; diff --git a/src/gui/kernel/qwidget_s60.cpp b/src/gui/kernel/qwidget_s60.cpp index ddd2f4c..4336d45 100644 --- a/src/gui/kernel/qwidget_s60.cpp +++ b/src/gui/kernel/qwidget_s60.cpp @@ -299,6 +299,7 @@ void QWidgetPrivate::create_sys(WId window, bool /* initializeWindow */, bool de CCoeControl *destroyw = 0; + createExtra(); if(window) { if (destroyOldWindow) destroyw = data.winid; @@ -311,7 +312,10 @@ void QWidgetPrivate::create_sys(WId window, bool /* initializeWindow */, bool de if (!q->testAttribute(Qt::WA_Moved) && !q->testAttribute(Qt::WA_DontShowOnScreen)) data.crect.moveTopLeft(QPoint(clientRect.iTl.iX, clientRect.iTl.iY)); QSymbianControl *control= q_check_ptr(new QSymbianControl(q)); + id = (WId)control; + setWinId(id); QT_TRAP_THROWING(control->ConstructL(true,desktop)); + if (!desktop) { TInt stackingFlags; if ((q->windowType() & Qt::Popup) == Qt::Popup) { @@ -336,11 +340,6 @@ void QWidgetPrivate::create_sys(WId window, bool /* initializeWindow */, bool de } } - - id = (WId)control; - - setWinId(id); - q->setAttribute(Qt::WA_WState_Created); int x, y, w, h; @@ -348,6 +347,7 @@ void QWidgetPrivate::create_sys(WId window, bool /* initializeWindow */, bool de control->SetRect(TRect(TPoint(x, y), TSize(w, h))); } else if (q->testAttribute(Qt::WA_NativeWindow) || paintOnScreen()) { // create native child widget QSymbianControl *control = new QSymbianControl(q); + setWinId(control); QT_TRAP_THROWING(control->ConstructL(!parentWidget)); TInt stackingFlags; @@ -358,7 +358,6 @@ void QWidgetPrivate::create_sys(WId window, bool /* initializeWindow */, bool de } control->ControlEnv()->AppUi()->AddToStackL(control, ECoeStackPriorityDefault, stackingFlags); - setWinId(control); WId parentw = parentWidget->effectiveWinId(); QT_TRAP_THROWING(control->SetContainerWindowL(*parentw)); @@ -852,7 +851,12 @@ void QWidgetPrivate::createSysExtra() void QWidgetPrivate::deleteSysExtra() { - + // this should only be non-zero if destroy() has not run due to constructor fail + if (data.winid) { + data.winid->ControlEnv()->AppUi()->RemoveFromStack(data.winid); + delete data.winid; + data.winid = 0; + } } QWindowSurface *QWidgetPrivate::createDefaultWindowSurface_sys() @@ -1079,6 +1083,7 @@ void QWidget::destroy(bool destroyWindow, bool destroySubWindows) if (!isWindow() && parentWidget()) parentWidget()->d_func()->invalidateBuffer(geometry()); d->deactivateWidgetCleanup(); + WId id = internalWinId(); if (testAttribute(Qt::WA_WState_Created)) { #ifndef QT_NO_IM @@ -1104,12 +1109,10 @@ void QWidget::destroy(bool destroyWindow, bool destroySubWindows) releaseMouse(); if (QWidgetPrivate::keyboardGrabber == this) releaseKeyboard(); - if (destroyWindow && !(windowType() == Qt::Desktop) && internalWinId()) { - WId id = internalWinId(); + if (destroyWindow && !(windowType() == Qt::Desktop) && id) { if(id->IsFocused()) // Avoid unnecessry calls to FocusChanged() id->SetFocus(false); id->ControlEnv()->AppUi()->RemoveFromStack(id); - CBase::Delete(id); // Hack to activate window under destroyed one. With this activation // the next visible window will get keyboard focus @@ -1117,17 +1120,22 @@ void QWidget::destroy(bool destroyWindow, bool destroySubWindows) if (wid) { QWidget *widget = QWidget::find(wid); QApplication::setActiveWindow(widget); - // Reset global window title for focusing window - widget->d_func()->setWindowTitle_sys(widget->windowTitle()); + if (widget) { + // Reset global window title for focusing window + widget->d_func()->setWindowTitle_sys(widget->windowTitle()); + } } - } + } - QT_TRY { - d->setWinId(0); - } QT_CATCH (const std::bad_alloc &) { - // swallow - destructors must not throw - } + QT_TRY { + d->setWinId(0); + } QT_CATCH (const std::bad_alloc &) { + // swallow - destructors must not throw + } + + if (destroyWindow) { + delete id; } } diff --git a/tests/auto/exceptionsafety_objects/tst_exceptionsafety_objects.cpp b/tests/auto/exceptionsafety_objects/tst_exceptionsafety_objects.cpp index c867899..c2c0685 100644 --- a/tests/auto/exceptionsafety_objects/tst_exceptionsafety_objects.cpp +++ b/tests/auto/exceptionsafety_objects/tst_exceptionsafety_objects.cpp @@ -165,9 +165,9 @@ void tst_ExceptionSafetyObjects::objects_data() // create and destructs an object, and lets each and every allocation // during construction and destruction fail. -static void doOOMTest(AbstractObjectCreator *creator, QObject *parent) +static void doOOMTest(AbstractObjectCreator *creator, QObject *parent, int start=0) { - int currentOOMIndex = 0; + int currentOOMIndex = start; bool caught = false; bool done = false; @@ -278,7 +278,9 @@ void tst_ExceptionSafetyObjects::initTestCase() (void) std::set_new_handler(nh_func); #endif - doOOMTest(new ObjectCreator<SelfTestObject>, 0); + ObjectCreator<SelfTestObject> *selfTest = new ObjectCreator<SelfTestObject>; + doOOMTest(selfTest, 0); + delete selfTest; QCOMPARE(alloc1Failed, 1); QCOMPARE(alloc2Failed, 1); QCOMPARE(alloc3Failed, 2); @@ -292,6 +294,8 @@ void tst_ExceptionSafetyObjects::objects() QFETCH(AbstractObjectCreator *, objectCreator); doOOMTest(objectCreator, 0); + + delete objectCreator; } template <typename T> @@ -391,10 +395,12 @@ void tst_ExceptionSafetyObjects::widgets() { QFETCH(AbstractObjectCreator *, widgetCreator); - doOOMTest(widgetCreator, 0); + doOOMTest(widgetCreator, 0, 00000); QWidget parent; - doOOMTest(widgetCreator, &parent); + doOOMTest(widgetCreator, &parent, 00000); + + delete widgetCreator; // if the test reaches here without crashing, we passed :) QVERIFY(true); |