diff options
Diffstat (limited to 'src/gui/kernel/qwidget.cpp')
-rw-r--r-- | src/gui/kernel/qwidget.cpp | 74 |
1 files changed, 54 insertions, 20 deletions
diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 4c2fe9d..bfcb02b 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -922,8 +922,8 @@ void QWidget::setAutoFillBackground(bool enabled) */ -QWidgetMapper *QWidgetPrivate::mapper = 0; // widget with wid -QWidgetSet *QWidgetPrivate::uncreatedWidgets = 0; // widgets with no wid +QWidgetMapper *QWidgetPrivate::mapper = 0; // widget with wid +QWidgetSet *QWidgetPrivate::allWidgets = 0; // widgets with no wid /***************************************************************************** @@ -969,7 +969,7 @@ struct QWidgetExceptionCleaner static inline void cleanup(QWidget *that, QWidgetPrivate *d) { #ifndef QT_NO_EXCEPTIONS - QWidgetPrivate::uncreatedWidgets->remove(that); + QWidgetPrivate::allWidgets->remove(that); if (d->focus_next != that) { if (d->focus_next) d->focus_next->d_func()->focus_prev = d->focus_prev; @@ -1121,8 +1121,8 @@ void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f) if (QApplication::type() == QApplication::Tty) qFatal("QWidget: Cannot create a QWidget when no GUI is being used"); - Q_ASSERT(uncreatedWidgets); - uncreatedWidgets->insert(q); + Q_ASSERT(allWidgets); + allWidgets->insert(q); QWidget *desktopWidget = 0; if (parentWidget && parentWidget->windowType() == Qt::Desktop) { @@ -1415,15 +1415,31 @@ QWidget::~QWidget() } #endif - clearFocus(); + QT_TRY { + clearFocus(); + } QT_CATCH(...) { + // swallow this problem because we are in a destructor + } d->setDirtyOpaqueRegion(); - if (isWindow() && isVisible() && internalWinId()) - d->close_helper(QWidgetPrivate::CloseNoEvent); + if (isWindow() && isVisible() && internalWinId()) { + QT_TRY { + d->close_helper(QWidgetPrivate::CloseNoEvent); + } QT_CATCH(...) { + // if we're out of memory, at least hide the window. + QT_TRY { + hide(); + } QT_CATCH(...) { + // and if that also doesn't work, then give up + } + } + } + #if defined(Q_WS_WIN) || defined(Q_WS_X11) - else if (!internalWinId() && isVisible()) + else if (!internalWinId() && isVisible()) { qApp->d_func()->sendSyntheticEnterLeave(this); + } #endif if (QWidgetBackingStore *bs = d->maybeBackingStore()) { @@ -1443,12 +1459,15 @@ QWidget::~QWidget() QApplication::removePostedEvents(this); - destroy(); // platform-dependent cleanup - + QT_TRY { + destroy(); // platform-dependent cleanup + } QT_CATCH(...) { + // if this fails we can't do anything about it but at least we are not allowed to throw. + } --QWidgetPrivate::instanceCounter; - if (QWidgetPrivate::uncreatedWidgets) // might have been deleted by ~QApplication - QWidgetPrivate::uncreatedWidgets->remove(this); + if (QWidgetPrivate::allWidgets) // might have been deleted by ~QApplication + QWidgetPrivate::allWidgets->remove(this); QEvent e(QEvent::Destroy); QCoreApplication::sendEvent(this, &e); @@ -1468,7 +1487,6 @@ void QWidgetPrivate::setWinId(WId id) // set widget identifier bool userDesktopWidget = qt_desktopWidget != 0 && qt_desktopWidget != q && q->windowType() == Qt::Desktop; if (mapper && data.winid && !userDesktopWidget) { mapper->remove(data.winid); - uncreatedWidgets->insert(q); } data.winid = id; @@ -1477,7 +1495,6 @@ void QWidgetPrivate::setWinId(WId id) // set widget identifier #endif if (mapper && id && !userDesktopWidget) { mapper->insert(data.winid, q); - uncreatedWidgets->remove(q); } } @@ -4645,8 +4662,9 @@ void QWidget::setCursor(const QCursor &cursor) #endif { d->createExtra(); + QCursor *newCursor = new QCursor(cursor); delete d->extra->curs; - d->extra->curs = new QCursor(cursor); + d->extra->curs = newCursor; } setAttribute(Qt::WA_SetCursor); d->setCursor_sys(cursor); @@ -5359,6 +5377,17 @@ QString QWidget::windowTitle() const return QString(); } +/*! + Returns a modified window title with the [*] place holder + replaced according to the rules described in QWidget::setWindowTitle + + This function assumes that "[*]" can be quoted by another + "[*]", so it will replace two place holders by one and + a single last one by either "*" or nothing depending on + the modified flag. + + \internal +*/ QString qt_setWindowTitle_helperHelper(const QString &title, const QWidget *widget) { Q_ASSERT(widget); @@ -5370,16 +5399,21 @@ QString qt_setWindowTitle_helperHelper(const QString &title, const QWidget *widg QString cap = title; #endif - QString placeHolder(QLatin1String("[*]")); + if (cap.isEmpty()) + return cap; + + QLatin1String placeHolder("[*]"); + int placeHolderLength = 3; // QLatin1String doesn't have length() int index = cap.indexOf(placeHolder); + // here the magic begins while (index != -1) { - index += placeHolder.length(); + index += placeHolderLength; int count = 1; while (cap.indexOf(placeHolder, index) == index) { ++count; - index += placeHolder.length(); + index += placeHolderLength; } if (count%2) { // odd number of [*] -> replace last one @@ -5394,7 +5428,7 @@ QString qt_setWindowTitle_helperHelper(const QString &title, const QWidget *widg index = cap.indexOf(placeHolder, index); } - cap.replace(QLatin1String("[*][*]"), QLatin1String("[*]")); + cap.replace(QLatin1String("[*][*]"), placeHolder); return cap; } |