From 23b78dc988d9e5cf9e846510b0525166222b184c Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Wed, 29 Apr 2009 12:48:07 +0200 Subject: MSVC refuses to compile if variables get defined in a case block without braces. I think that is a useful feature. --- src/gui/styles/qs60style.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index 58dcb98..059198d 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -2157,12 +2157,13 @@ QRect QS60Style::subControlRect(ComplexControl control, const QStyleOptionComple ret = QCommonStyle::subControlRect(control, option, scontrol, widget); switch (scontrol) { case SC_GroupBoxCheckBox: //fallthrough - case SC_GroupBoxLabel: + case SC_GroupBoxLabel: { //slightly indent text and boxes, so that dialog border does not mess with them. const int horizontalSpacing = QS60StylePrivate::pixelMetric(QStyle::PM_LayoutHorizontalSpacing); const int bottomMargin = QS60StylePrivate::pixelMetric(QStyle::PM_LayoutBottomMargin); ret.adjust(2,horizontalSpacing-3,0,0); + } break; case SC_GroupBoxFrame: { const QRect textBox = subControlRect(control, option, SC_GroupBoxLabel, widget); -- cgit v0.12 From e7864bbc420151aee1facc6383fd8c7fd9a63d13 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Thu, 30 Apr 2009 14:42:10 +0200 Subject: Initial skeleton of what is to become the cross platform softkey API. Current version is very experimental and can and will change very radically. Also functionality on this early version is very limited. API can only set single Back button on S60 platform. Work is somewhat based in softkey experiment done in Brisbane. Major difference is that this implementation will only be API through which softkeys will be adapted and will not have any kind of visualization in itself --- src/gui/softkeys/main.cpp | 42 +++++++++++ src/gui/softkeys/qsoftkeyaction.cpp | 139 ++++++++++++++++++++++++++++++++++++ src/gui/softkeys/qsoftkeyaction.h | 59 +++++++++++++++ src/gui/softkeys/qsoftkeystack.cpp | 93 ++++++++++++++++++++++++ src/gui/softkeys/qsoftkeystack.h | 74 +++++++++++++++++++ src/gui/softkeys/softkeys.pro | 13 ++++ 6 files changed, 420 insertions(+) create mode 100644 src/gui/softkeys/main.cpp create mode 100644 src/gui/softkeys/qsoftkeyaction.cpp create mode 100644 src/gui/softkeys/qsoftkeyaction.h create mode 100644 src/gui/softkeys/qsoftkeystack.cpp create mode 100644 src/gui/softkeys/qsoftkeystack.h create mode 100644 src/gui/softkeys/softkeys.pro diff --git a/src/gui/softkeys/main.cpp b/src/gui/softkeys/main.cpp new file mode 100644 index 0000000..4f452d6 --- /dev/null +++ b/src/gui/softkeys/main.cpp @@ -0,0 +1,42 @@ + +#include +#include +#include +#include +#include "qsoftkeystack.h" + +class MainWindow : public QMainWindow +{ + Q_OBJECT +public: + MainWindow(QWidget *parent = 0); + ~MainWindow() {} +}; + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) +{ + QWidget *central = new QWidget(this); + QVBoxLayout *layout = new QVBoxLayout(central); + + QPushButton *button = new QPushButton("Hello"); + layout->addWidget(button); + + QSoftKeyStack *stack = new QSoftKeyStack(central); + QSoftKeyAction action(central); + action.setRole(QSoftKeyAction::Back); + int role = action.role(); + stack->push(&action); + + setCentralWidget(central); +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow mw; + mw.show(); + return app.exec(); +} + +#include "main.moc" diff --git a/src/gui/softkeys/qsoftkeyaction.cpp b/src/gui/softkeys/qsoftkeyaction.cpp new file mode 100644 index 0000000..ac6cb01 --- /dev/null +++ b/src/gui/softkeys/qsoftkeyaction.cpp @@ -0,0 +1,139 @@ +/**************************************************************************** +** +** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +****************************************************************************/ + +#include "qsoftkeyaction.h" + +/*! + \class QSoftKeyAction + \brief The QSoftKeyAction class defines a special kind of QAction that may also be displayed in a QSoftKeyBar. +*/ + +class QSoftKeyActionPrivate +{ +public: + QSoftKeyActionPrivate(QSoftKeyAction::StandardRole role = QSoftKeyAction::Custom) + { + this->role = role; + } + + QSoftKeyAction::StandardRole role; + QString roleName; +}; + +/*! + \enum QSoftKeyAction::StandardRole + This enum defines the standard role for a QSoftKeyAction. + + \value Options + \value Select + \value Back + \value Next + \value Previous + \value Ok + \value Cancel + \value Edit + \value View + \value BackSpace + \value EndEdit + \value RevertEdit + \value Deselect + \value Finish + \value Custom +*/ + +QSoftKeyAction::QSoftKeyAction(QObject *parent) + : QAction(parent) +{ + d = new QSoftKeyActionPrivate(); +} + +QSoftKeyAction::QSoftKeyAction(QSoftKeyAction::StandardRole role, QObject *parent) + : QAction(parent) +{ + d = new QSoftKeyActionPrivate(role); +} + +QSoftKeyAction::QSoftKeyAction(const QString &text, QObject* parent) + : QAction(text, parent) +{ + d = new QSoftKeyActionPrivate(); +} + +QSoftKeyAction::QSoftKeyAction(QSoftKeyAction::StandardRole role, const QString &text, QObject* parent) + : QAction(text, parent) +{ + d = new QSoftKeyActionPrivate(role); +} + +QSoftKeyAction::QSoftKeyAction(const QIcon &icon, const QString &text, QObject* parent) + : QAction(icon, text, parent) +{ + d = new QSoftKeyActionPrivate(); +} + +QSoftKeyAction::QSoftKeyAction(QSoftKeyAction::StandardRole role, const QIcon &icon, const QString &text, QObject* parent) + : QAction(icon, text, parent) +{ + d = new QSoftKeyActionPrivate(role); +} + +QSoftKeyAction::~QSoftKeyAction() +{ + delete d; +} + +/*! + Returns the standard role associated with this action, or Custom + if the role is defined by roleName(). + + \sa setRole(), roleName() +*/ +QSoftKeyAction::StandardRole QSoftKeyAction::role() const +{ + return d->role; +} + +/*! + Returns the custom role name if role() is Custom, or an empty + string otherwise. + + \sa role(), setRole() +*/ +QString QSoftKeyAction::roleName() const +{ + return d->roleName; +} + +/*! + Sets the standard role associated with this action to \a role, + and also sets roleName() to the empty string. + + \sa role(), roleName() +*/ +void QSoftKeyAction::setRole(QSoftKeyAction::StandardRole role) +{ + d->role = role; + d->roleName = QString(); + emit changed(); +} + +/*! + Sets the custom roleName() associated with this action to \a role, + and also sets role() to Custom. + + \sa role(), roleName() +*/ +void QSoftKeyAction::setRole(const QString& role) +{ + d->role = QSoftKeyAction::Custom; + d->roleName = role; + emit changed(); +} diff --git a/src/gui/softkeys/qsoftkeyaction.h b/src/gui/softkeys/qsoftkeyaction.h new file mode 100644 index 0000000..67401e2 --- /dev/null +++ b/src/gui/softkeys/qsoftkeyaction.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +****************************************************************************/ + +#ifndef QSOFTKEYACTION_H +#define QSOFTKEYACTION_H + +#include + +class QSoftKeyActionPrivate; + +class QSoftKeyAction : public QAction +{ + Q_OBJECT +public: + enum StandardRole + { + Options, + Select, + Back, + Next, + Previous, + Ok, + Cancel, + Edit, + View, + BackSpace, + EndEdit, + RevertEdit, + Deselect, + Finish, + Custom + }; + + QSoftKeyAction(QObject *parent); + QSoftKeyAction(QSoftKeyAction::StandardRole role, QObject *parent); + QSoftKeyAction(const QString &text, QObject* parent); + QSoftKeyAction(QSoftKeyAction::StandardRole role, const QString &text, QObject* parent); + QSoftKeyAction(const QIcon &icon, const QString &text, QObject* parent); + QSoftKeyAction(QSoftKeyAction::StandardRole role, const QIcon &icon, const QString &text, QObject* parent); + ~QSoftKeyAction(); + + QSoftKeyAction::StandardRole role() const; + QString roleName() const; + + void setRole(QSoftKeyAction::StandardRole role); + void setRole(const QString& role); + + QSoftKeyActionPrivate *d; +}; + +#endif // QSOFTKEYACTION_H diff --git a/src/gui/softkeys/qsoftkeystack.cpp b/src/gui/softkeys/qsoftkeystack.cpp new file mode 100644 index 0000000..669198b --- /dev/null +++ b/src/gui/softkeys/qsoftkeystack.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include + +#include "qsoftkeystack.h" + +QSoftKeyStackPrivate::QSoftKeyStackPrivate() +{ + +} + +QSoftKeyStackPrivate::~QSoftKeyStackPrivate() +{ + +} + +void QSoftKeyStackPrivate::setNativeSoftKeys() +{ + QSoftkeySet top = softKeyStack.top(); + CCoeAppUi* appui = CEikonEnv::Static()->AppUi(); + CAknAppUi* aknAppUi = static_cast (appui); + CEikButtonGroupContainer* nativeContainer = aknAppUi->Cba(); + int role = top.at(0)->role(); + + switch( top.at(0)->role() ) + { + case(QSoftKeyAction::Back): + { + nativeContainer->SetCommandSetL(R_AVKON_SOFTKEYS_BACK); + } + break; + default: + { + } + } +} + +void QSoftKeyStackPrivate::push(QSoftKeyAction *softKey) +{ + QSoftkeySet softkeys; + softkeys.append( softKey ); + softKeyStack.push(softkeys); + setNativeSoftKeys(); + +} +void QSoftKeyStackPrivate::push( QList softkeys) +{ + +} + +void QSoftKeyStackPrivate::pop() +{ + softKeyStack.pop(); +} + +EXPORT_C QSoftKeyStack::QSoftKeyStack(QWidget *parent) +{ + d = new QSoftKeyStackPrivate(); +} + +QSoftKeyStack::~QSoftKeyStack() +{ + delete d; +} + +void QSoftKeyStack::push(QSoftKeyAction *softKey) +{ + d->push(softKey); +} + +void QSoftKeyStack::push(QList softKeys) +{ + d->push(softKeys); +} + +void QSoftKeyStack::pop() +{ + d->pop(); +} + diff --git a/src/gui/softkeys/qsoftkeystack.h b/src/gui/softkeys/qsoftkeystack.h new file mode 100644 index 0000000..d725954 --- /dev/null +++ b/src/gui/softkeys/qsoftkeystack.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +****************************************************************************/ + +#ifndef QSOFTKEYSTACK_H +#define QSOFTKEYSTACK_H + +#include +#include +#include + +#include "qsoftkeyaction.h" + +#define QSoftkeySet QList + +class QSoftKeyStackPrivate : public QObject + { + Q_OBJECT + public: + IMPORT_C QSoftKeyStackPrivate(); + ~QSoftKeyStackPrivate(); + +public: + void push(QSoftKeyAction *softKey); + void push(QList softKeys); + void pop(); + +private: + void setNativeSoftKeys(); + +private: + QStack softKeyStack; + }; + + + +/*class QSoftkeySet + { + const QList softkeys; + }; + + +class QSoftkeySet + { + const QList softkeys; + }; +*/ +class QSoftKeyStack : public QObject +{ + Q_OBJECT +public: + IMPORT_C QSoftKeyStack(QWidget *parent); + ~QSoftKeyStack(); +public: + void push(QSoftKeyAction *softKey); + void push(QList softkeys); + void pop(); +protected: + +private Q_SLOTS: + +private: + QSoftKeyStackPrivate *d; + +}; + +#endif // QSOFTKEYSTACK_H diff --git a/src/gui/softkeys/softkeys.pro b/src/gui/softkeys/softkeys.pro new file mode 100644 index 0000000..88a813e --- /dev/null +++ b/src/gui/softkeys/softkeys.pro @@ -0,0 +1,13 @@ +TEMPLATE = app +TARGET = softkeys + +HEADERS += \ + qsoftkeystack.h \ + qsoftkeyaction.h + +SOURCES += \ + main.cpp \ + qsoftkeyaction.cpp \ + qsoftkeystack.cpp + +iCONFIG += qt debug warn_on -- cgit v0.12 From d24c24b6c0c840d7bbea5e8b81e1faaea6b5fede Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Mon, 4 May 2009 11:18:34 +0200 Subject: Very rough implementation of setting multiple buttons. Current implementation is missing loads of needed functionality but is enough to start testing the initial API --- src/gui/softkeys/qsoftkeystack.cpp | 42 ++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/src/gui/softkeys/qsoftkeystack.cpp b/src/gui/softkeys/qsoftkeystack.cpp index 669198b..158d382 100644 --- a/src/gui/softkeys/qsoftkeystack.cpp +++ b/src/gui/softkeys/qsoftkeystack.cpp @@ -15,6 +15,9 @@ #include #include +#include "private/qcore_symbian_p.h" + + #include "qsoftkeystack.h" QSoftKeyStackPrivate::QSoftKeyStackPrivate() @@ -29,41 +32,50 @@ QSoftKeyStackPrivate::~QSoftKeyStackPrivate() void QSoftKeyStackPrivate::setNativeSoftKeys() { - QSoftkeySet top = softKeyStack.top(); CCoeAppUi* appui = CEikonEnv::Static()->AppUi(); CAknAppUi* aknAppUi = static_cast (appui); CEikButtonGroupContainer* nativeContainer = aknAppUi->Cba(); - int role = top.at(0)->role(); + nativeContainer->SetCommandSetL(R_AVKON_SOFTKEYS_EMPTY_WITH_IDS); + if(softKeyStack.isEmpty()) + return; + + QSoftkeySet top = softKeyStack.top(); - switch( top.at(0)->role() ) + // FIX THIS + // veryWeirdMagic is needes as s60 5th edition sdk always panics if cba is set with index 1, this hops over it + // This needs further investigation why so that the hack can be removed + int veryWeirdMagic = 0; + for (int index=0;indexSetCommandSetL(R_AVKON_SOFTKEYS_BACK); - } - break; - default: - { - } + QSoftKeyAction* softKeyAction = top.at(index); + HBufC* text = qt_QString2HBufCNewL(softKeyAction->text()); + CleanupStack::PushL(text); + nativeContainer->SetCommandL(index+veryWeirdMagic, softKeyAction->role(), *text); + CleanupStack::PopAndDestroy(); + if (veryWeirdMagic==0) + veryWeirdMagic=1; } } void QSoftKeyStackPrivate::push(QSoftKeyAction *softKey) { - QSoftkeySet softkeys; - softkeys.append( softKey ); - softKeyStack.push(softkeys); + QSoftkeySet softKeySet; + softKeySet.append( softKey ); + softKeyStack.push(softKeySet); setNativeSoftKeys(); } void QSoftKeyStackPrivate::push( QList softkeys) { - + QSoftkeySet softKeySet(softkeys); + softKeyStack.push(softKeySet); + setNativeSoftKeys(); } void QSoftKeyStackPrivate::pop() { softKeyStack.pop(); + setNativeSoftKeys(); } EXPORT_C QSoftKeyStack::QSoftKeyStack(QWidget *parent) -- cgit v0.12 From 3a336c63f9eef19d99b114bda9ff375f84c99234 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Mon, 4 May 2009 11:19:47 +0200 Subject: More code to test the stack implementatioMore code to test the stack implementationn --- src/gui/softkeys/main.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/gui/softkeys/main.cpp b/src/gui/softkeys/main.cpp index 4f452d6..fd82ce5 100644 --- a/src/gui/softkeys/main.cpp +++ b/src/gui/softkeys/main.cpp @@ -23,11 +23,24 @@ MainWindow::MainWindow(QWidget *parent) layout->addWidget(button); QSoftKeyStack *stack = new QSoftKeyStack(central); - QSoftKeyAction action(central); - action.setRole(QSoftKeyAction::Back); - int role = action.role(); - stack->push(&action); - + QSoftKeyAction action1(central); + action1.setText(QString("text1")); + action1.setRole(QSoftKeyAction::Ok); + QSoftKeyAction action2(central); + action2.setText(QString("text2")); + action2.setRole(QSoftKeyAction::Back); + QSoftKeyAction action3(central); + action3.setText(QString("text3")); + action3.setRole(QSoftKeyAction::Cancel); + + QList myActionList; + myActionList.append(&action1); + myActionList.append(&action2); + myActionList.append(&action3); + stack->push(myActionList); + stack->pop(); + stack->push(&action1); + setCentralWidget(central); } -- cgit v0.12 From b83e03ce82c84eaaf08ac1df154dcaa88691063d Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Mon, 4 May 2009 13:17:52 +0200 Subject: Changed way how softkey command is mapped --- src/gui/softkeys/qsoftkeystack.cpp | 2 +- src/gui/softkeys/qsoftkeystack.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gui/softkeys/qsoftkeystack.cpp b/src/gui/softkeys/qsoftkeystack.cpp index 158d382..6cbcddd 100644 --- a/src/gui/softkeys/qsoftkeystack.cpp +++ b/src/gui/softkeys/qsoftkeystack.cpp @@ -50,7 +50,7 @@ void QSoftKeyStackPrivate::setNativeSoftKeys() QSoftKeyAction* softKeyAction = top.at(index); HBufC* text = qt_QString2HBufCNewL(softKeyAction->text()); CleanupStack::PushL(text); - nativeContainer->SetCommandL(index+veryWeirdMagic, softKeyAction->role(), *text); + nativeContainer->SetCommandL(index+veryWeirdMagic, SOFTKEYSTART+index, *text); CleanupStack::PopAndDestroy(); if (veryWeirdMagic==0) veryWeirdMagic=1; diff --git a/src/gui/softkeys/qsoftkeystack.h b/src/gui/softkeys/qsoftkeystack.h index d725954..98c2632 100644 --- a/src/gui/softkeys/qsoftkeystack.h +++ b/src/gui/softkeys/qsoftkeystack.h @@ -19,7 +19,8 @@ #include "qsoftkeyaction.h" #define QSoftkeySet QList - +#define SOFTKEYSTART 5000 +#define SOFTKEYEND 5004 class QSoftKeyStackPrivate : public QObject { Q_OBJECT -- cgit v0.12 From 93a61a4cbe092dce8e5d221858d6b613fa258f07 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Mon, 4 May 2009 14:26:13 +0200 Subject: Skeleton implementation allowing us to conviniently change place where softkeys are visualized on the screen. Added mapping to native and Qt id's for QSoftKeyActions. Added rudimentary implementation for reordering QSoftKeyActions. --- src/gui/softkeys/qsoftkeyaction.cpp | 22 ++++++++++++++++++++++ src/gui/softkeys/qsoftkeyaction.h | 4 ++++ src/gui/softkeys/qsoftkeystack.cpp | 33 +++++++++++++++++++++++++-------- src/gui/softkeys/qsoftkeystack.h | 3 ++- 4 files changed, 53 insertions(+), 9 deletions(-) diff --git a/src/gui/softkeys/qsoftkeyaction.cpp b/src/gui/softkeys/qsoftkeyaction.cpp index ac6cb01..bfa8330 100644 --- a/src/gui/softkeys/qsoftkeyaction.cpp +++ b/src/gui/softkeys/qsoftkeyaction.cpp @@ -26,6 +26,8 @@ public: QSoftKeyAction::StandardRole role; QString roleName; + int nativePosition; + int qtContextKey; }; /*! @@ -137,3 +139,23 @@ void QSoftKeyAction::setRole(const QString& role) d->roleName = role; emit changed(); } + +int QSoftKeyAction::nativePosition() +{ + return d->nativePosition; +} + +void QSoftKeyAction::setNativePosition(int position) +{ + d->nativePosition = position; +} + +int QSoftKeyAction::qtContextKey() +{ + return d->qtContextKey; +} + +void QSoftKeyAction::setQtContextKey(int key) +{ + d->qtContextKey = key; +} diff --git a/src/gui/softkeys/qsoftkeyaction.h b/src/gui/softkeys/qsoftkeyaction.h index 67401e2..85f5bc7 100644 --- a/src/gui/softkeys/qsoftkeyaction.h +++ b/src/gui/softkeys/qsoftkeyaction.h @@ -52,6 +52,10 @@ public: void setRole(QSoftKeyAction::StandardRole role); void setRole(const QString& role); + int nativePosition(); + void setNativePosition(int position); + int qtContextKey(); + void setQtContextKey(int position); QSoftKeyActionPrivate *d; }; diff --git a/src/gui/softkeys/qsoftkeystack.cpp b/src/gui/softkeys/qsoftkeystack.cpp index 6cbcddd..bd9a636 100644 --- a/src/gui/softkeys/qsoftkeystack.cpp +++ b/src/gui/softkeys/qsoftkeystack.cpp @@ -30,6 +30,29 @@ QSoftKeyStackPrivate::~QSoftKeyStackPrivate() } +void QSoftKeyStackPrivate::mapSoftKeys(QSoftkeySet& top) +{ + if( top.count() == 1) + { + top.at(0)->setNativePosition(2); + top.at(0)->setQtContextKey(Qt::Key_Context2); + } + else + { + // FIX THIS + // veryWeirdMagic is needes as s60 5th edition sdk always panics if cba is set with index 1, this hops over it + // This needs further investigation why so that the hack can be removed + int veryWeirdMagic = 0; + for (int index=0;indexsetNativePosition(index+veryWeirdMagic); + top.at(index)->setQtContextKey(Qt::Key_Context1+index); + if (veryWeirdMagic==0) + veryWeirdMagic=1; + } + } +} + void QSoftKeyStackPrivate::setNativeSoftKeys() { CCoeAppUi* appui = CEikonEnv::Static()->AppUi(); @@ -40,20 +63,14 @@ void QSoftKeyStackPrivate::setNativeSoftKeys() return; QSoftkeySet top = softKeyStack.top(); - - // FIX THIS - // veryWeirdMagic is needes as s60 5th edition sdk always panics if cba is set with index 1, this hops over it - // This needs further investigation why so that the hack can be removed - int veryWeirdMagic = 0; + mapSoftKeys(top); for (int index=0;indextext()); CleanupStack::PushL(text); - nativeContainer->SetCommandL(index+veryWeirdMagic, SOFTKEYSTART+index, *text); + nativeContainer->SetCommandL(softKeyAction->nativePosition(), SOFTKEYSTART+softKeyAction->qtContextKey(), *text); CleanupStack::PopAndDestroy(); - if (veryWeirdMagic==0) - veryWeirdMagic=1; } } diff --git a/src/gui/softkeys/qsoftkeystack.h b/src/gui/softkeys/qsoftkeystack.h index 98c2632..add4ab9 100644 --- a/src/gui/softkeys/qsoftkeystack.h +++ b/src/gui/softkeys/qsoftkeystack.h @@ -20,7 +20,7 @@ #define QSoftkeySet QList #define SOFTKEYSTART 5000 -#define SOFTKEYEND 5004 +#define SOFTKEYEND 5005 class QSoftKeyStackPrivate : public QObject { Q_OBJECT @@ -34,6 +34,7 @@ public: void pop(); private: + void mapSoftKeys(QSoftkeySet& top); void setNativeSoftKeys(); private: -- cgit v0.12 From cfe8216b0fd5270d4dc90d5cf3df62e12d0c35b3 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Mon, 4 May 2009 14:30:41 +0200 Subject: Changed mapping of softkey id's --- src/gui/softkeys/qsoftkeystack.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/softkeys/qsoftkeystack.h b/src/gui/softkeys/qsoftkeystack.h index add4ab9..b96bf60 100644 --- a/src/gui/softkeys/qsoftkeystack.h +++ b/src/gui/softkeys/qsoftkeystack.h @@ -20,7 +20,8 @@ #define QSoftkeySet QList #define SOFTKEYSTART 5000 -#define SOFTKEYEND 5005 +#define SOFTKEYEND 5000+Qt::Key_Context4 + class QSoftKeyStackPrivate : public QObject { Q_OBJECT -- cgit v0.12 From 2e76d2bfedce77064fde85573f5267032ce7979e Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Mon, 4 May 2009 16:17:15 +0200 Subject: Added proper headers --- src/gui/softkeys/main.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/gui/softkeys/main.cpp b/src/gui/softkeys/main.cpp index fd82ce5..e5a7065 100644 --- a/src/gui/softkeys/main.cpp +++ b/src/gui/softkeys/main.cpp @@ -1,3 +1,13 @@ +/**************************************************************************** +** +** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +****************************************************************************/ #include #include -- cgit v0.12 From 4bf005f424ed4aa86f3539ee3018bf11779550cd Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Mon, 11 May 2009 13:58:24 +0200 Subject: Refactored implementation so that it works with multiple QMainWindows --- src/gui/widgets/qmenu_symbian.cpp | 59 +++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/src/gui/widgets/qmenu_symbian.cpp b/src/gui/widgets/qmenu_symbian.cpp index 9e53df5..4c8b4ae 100644 --- a/src/gui/widgets/qmenu_symbian.cpp +++ b/src/gui/widgets/qmenu_symbian.cpp @@ -32,8 +32,10 @@ QT_BEGIN_NAMESPACE // ### FIX/Document this, we need some safe range of menu id's for Qt that don't clash with AIW ones +typedef QHash MenuBarHash; +Q_GLOBAL_STATIC(MenuBarHash, menubars) + #define QT_FIRST_MENU_ITEM 32000 -static QList s60_menubars; struct SymbianMenuItem { @@ -47,6 +49,15 @@ static QList symbianMenus; static QList nativeMenuBars; static uint qt_symbian_menu_static_cmd_id = QT_FIRST_MENU_ITEM; +bool menuExists() +{ + QWidget *w = qApp->activeWindow(); + QMenuBarPrivate *mb = menubars()->value(w); + if (!mb) + return false; + return true; +} + // ### FIX THIS, copy/paste of original (faulty) stripped text implementation. // Implementation should be removed from QAction implementation to some generic place static QString qt_strippedText_copy_from_qaction(QString s) @@ -167,7 +178,7 @@ static void setSoftkeys() { CEikButtonGroupContainer* cba = CEikonEnv::Static()->AppUiFactory()->Cba(); if (cba){ - if (s60_menubars.count()>0) + if (menuExists()) cba->SetCommandSetL(R_AVKON_SOFTKEYS_OPTIONS_EXIT); else cba->SetCommandSetL(R_AVKON_SOFTKEYS_EXIT); @@ -176,24 +187,23 @@ static void setSoftkeys() static void rebuildMenu() { - qt_symbian_menu_static_cmd_id = QT_FIRST_MENU_ITEM; - deleteAll( &symbianMenus ); - if (s60_menubars.count()==0) - return; - for (int i = 0; i < s60_menubars.last()->actions.size(); ++i) { - QSymbianMenuAction *symbianActionTopLevel = new QSymbianMenuAction; - symbianActionTopLevel->action = s60_menubars.last()->actions.at(i); - symbianActionTopLevel->parent = 0; - symbianActionTopLevel->command = qt_symbian_menu_static_cmd_id++; - qt_symbian_insert_action(symbianActionTopLevel, &symbianMenus); + QMenuBarPrivate *mb = 0; + setSoftkeys(); + QWidget *w = qApp->activeWindow(); + if (w) + { + mb = menubars()->value(w); + qt_symbian_menu_static_cmd_id = QT_FIRST_MENU_ITEM; + deleteAll( &symbianMenus ); + if (!mb) + return; + mb->symbian_menubar->rebuild(); } - - return; } Q_GUI_EXPORT void qt_symbian_show_toplevel( CEikMenuPane* menuPane) { - if (s60_menubars.count()==0) + if (!menuExists()) return; rebuildMenu(); for (int i = 0; i < symbianMenus.count(); ++i) @@ -251,6 +261,7 @@ void QMenuBarPrivate::symbianCreateMenuBar(QWidget *parent) { Q_Q(QMenuBar); if (parent && parent->isWindow()){ + menubars()->insert(q->window(), this); symbian_menubar = new QSymbianMenuBarPrivate(this); nativeMenuBars.append(q); } @@ -261,7 +272,7 @@ void QMenuBarPrivate::symbianDestroyMenuBar() Q_Q(QMenuBar); int index = nativeMenuBars.indexOf(q); nativeMenuBars.removeAt(index); - s60_menubars.removeLast(); + menubars()->remove(q->window()); rebuildMenu(); if (symbian_menubar) delete symbian_menubar; @@ -271,7 +282,6 @@ void QMenuBarPrivate::symbianDestroyMenuBar() QMenuBarPrivate::QSymbianMenuBarPrivate::QSymbianMenuBarPrivate(QMenuBarPrivate *menubar) { d = menubar; - s60_menubars.append(menubar); } QMenuBarPrivate::QSymbianMenuBarPrivate::~QSymbianMenuBarPrivate() @@ -364,10 +374,17 @@ void QMenuBarPrivate::QSymbianMenuBarPrivate::removeAction(QSymbianMenuAction *a void QMenuBarPrivate::QSymbianMenuBarPrivate::rebuild() { setSoftkeys(); - if (s60_menubars.count()==0) + qt_symbian_menu_static_cmd_id = QT_FIRST_MENU_ITEM; + deleteAll( &symbianMenus ); + if (!d) return; - - rebuildMenu(); - } + for (int i = 0; i < d->actions.size(); ++i) { + QSymbianMenuAction *symbianActionTopLevel = new QSymbianMenuAction; + symbianActionTopLevel->action = d->actions.at(i); + symbianActionTopLevel->parent = 0; + symbianActionTopLevel->command = qt_symbian_menu_static_cmd_id++; + qt_symbian_insert_action(symbianActionTopLevel, &symbianMenus); + } +} #endif //QT_NO_MENUBAR -- cgit v0.12 From 61b111228d0abf66130b229fcb6c5e2a54faecbf Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Tue, 12 May 2009 15:24:43 +0200 Subject: Removed setting native softkeys from menu implementation as from now on the menu softkey will be set by the brand new softkey stack. --- src/gui/widgets/qmenu_symbian.cpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/gui/widgets/qmenu_symbian.cpp b/src/gui/widgets/qmenu_symbian.cpp index aee55b9..1dc727c 100644 --- a/src/gui/widgets/qmenu_symbian.cpp +++ b/src/gui/widgets/qmenu_symbian.cpp @@ -173,21 +173,9 @@ void deleteAll(QList *items) } } -static void setSoftkeys() -{ - CEikButtonGroupContainer* cba = CEikonEnv::Static()->AppUiFactory()->Cba(); - if (cba){ - if (menuExists()) - cba->SetCommandSetL(R_AVKON_SOFTKEYS_OPTIONS_EXIT); - else - cba->SetCommandSetL(R_AVKON_SOFTKEYS_EXIT); - } -} - static void rebuildMenu() { QMenuBarPrivate *mb = 0; - setSoftkeys(); QWidget *w = qApp->activeWindow(); if (w) { @@ -372,7 +360,6 @@ void QMenuBarPrivate::QSymbianMenuBarPrivate::removeAction(QSymbianMenuAction *a void QMenuBarPrivate::QSymbianMenuBarPrivate::rebuild() { - setSoftkeys(); qt_symbian_menu_static_cmd_id = QT_FIRST_MENU_ITEM; deleteAll( &symbianMenus ); if (!d) -- cgit v0.12 From 9ef6e374126ba212bccbf3cf61f86f8412099c49 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Tue, 12 May 2009 15:31:18 +0200 Subject: Initial naive implementation for menu softkey --- src/gui/softkeys/main.cpp | 29 ++++++++++++++++++++--------- src/gui/softkeys/qsoftkeyaction.h | 1 + 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/gui/softkeys/main.cpp b/src/gui/softkeys/main.cpp index e5a7065..a61e512 100644 --- a/src/gui/softkeys/main.cpp +++ b/src/gui/softkeys/main.cpp @@ -11,8 +11,8 @@ #include #include -#include -#include +#include + #include "qsoftkeystack.h" class MainWindow : public QMainWindow @@ -26,22 +26,26 @@ public: MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { - QWidget *central = new QWidget(this); - QVBoxLayout *layout = new QVBoxLayout(central); - QPushButton *button = new QPushButton("Hello"); - layout->addWidget(button); + QWidget *central = new QWidget(this); + + QMenuBar* menuBar = new QMenuBar(this); + menuBar->addAction("MyMenuItem1"); + this->setMenuBar(menuBar); QSoftKeyStack *stack = new QSoftKeyStack(central); QSoftKeyAction action1(central); - action1.setText(QString("text1")); + action1.setText(QString("Ok")); action1.setRole(QSoftKeyAction::Ok); QSoftKeyAction action2(central); - action2.setText(QString("text2")); + action2.setText(QString("Back")); action2.setRole(QSoftKeyAction::Back); QSoftKeyAction action3(central); - action3.setText(QString("text3")); + action3.setText(QString("Cancel")); action3.setRole(QSoftKeyAction::Cancel); + QSoftKeyAction action4(central); + action4.setText(QString("Menu")); + action4.setRole(QSoftKeyAction::Menu); QList myActionList; myActionList.append(&action1); @@ -50,6 +54,13 @@ MainWindow::MainWindow(QWidget *parent) stack->push(myActionList); stack->pop(); stack->push(&action1); + stack->pop(); + + QList myActionList2; + myActionList2.append(&action4); + myActionList2.append(&action1); + stack->push(myActionList2); + setCentralWidget(central); } diff --git a/src/gui/softkeys/qsoftkeyaction.h b/src/gui/softkeys/qsoftkeyaction.h index 85f5bc7..76be8ee 100644 --- a/src/gui/softkeys/qsoftkeyaction.h +++ b/src/gui/softkeys/qsoftkeyaction.h @@ -36,6 +36,7 @@ public: RevertEdit, Deselect, Finish, + Menu, Custom }; -- cgit v0.12 From 21d8da6365281426c50d6d5b8393d833e16d4096 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Tue, 12 May 2009 16:17:35 +0200 Subject: Added handling of softkey with the role of menu --- src/gui/softkeys/qsoftkeystack.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/gui/softkeys/qsoftkeystack.cpp b/src/gui/softkeys/qsoftkeystack.cpp index bd9a636..c1d6e98 100644 --- a/src/gui/softkeys/qsoftkeystack.cpp +++ b/src/gui/softkeys/qsoftkeystack.cpp @@ -64,12 +64,18 @@ void QSoftKeyStackPrivate::setNativeSoftKeys() QSoftkeySet top = softKeyStack.top(); mapSoftKeys(top); + for (int index=0;indextext()); CleanupStack::PushL(text); - nativeContainer->SetCommandL(softKeyAction->nativePosition(), SOFTKEYSTART+softKeyAction->qtContextKey(), *text); + if (softKeyAction->role() == QSoftKeyAction::Menu) { + nativeContainer->SetCommandL(softKeyAction->nativePosition(), EAknSoftkeyOptions, *text); + } + else { + nativeContainer->SetCommandL(softKeyAction->nativePosition(), SOFTKEYSTART+softKeyAction->qtContextKey(), *text); + } CleanupStack::PopAndDestroy(); } } -- cgit v0.12 From 27ace2c1eb1faecf01b6229cf7ebb7534a1c6125 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Tue, 12 May 2009 18:48:22 +0200 Subject: Qt-ifications. Mostly license headers and coding conventions. --- src/gui/softkeys/qsoftkeyaction.cpp | 48 ++++++++++++--- src/gui/softkeys/qsoftkeyaction.h | 60 ++++++++++++++----- src/gui/softkeys/qsoftkeystack.cpp | 104 ++++++++++++--------------------- src/gui/softkeys/qsoftkeystack.h | 91 ++++++++++++++--------------- src/gui/softkeys/qsoftkeystack_p.h | 86 +++++++++++++++++++++++++++ src/gui/softkeys/qsoftkeystack_s60.cpp | 100 +++++++++++++++++++++++++++++++ src/gui/softkeys/softkeys.pro | 2 + 7 files changed, 355 insertions(+), 136 deletions(-) create mode 100644 src/gui/softkeys/qsoftkeystack_p.h create mode 100644 src/gui/softkeys/qsoftkeystack_s60.cpp diff --git a/src/gui/softkeys/qsoftkeyaction.cpp b/src/gui/softkeys/qsoftkeyaction.cpp index bfa8330..1d21376 100644 --- a/src/gui/softkeys/qsoftkeyaction.cpp +++ b/src/gui/softkeys/qsoftkeyaction.cpp @@ -1,11 +1,41 @@ /**************************************************************************** ** -** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) ** -** This file is part of the $MODULE$ of the Qt Toolkit. +** This file is part of the QtGui module of the Qt Toolkit. ** -** $TROLLTECH_DUAL_LICENSE$ +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -57,7 +87,7 @@ QSoftKeyAction::QSoftKeyAction(QObject *parent) d = new QSoftKeyActionPrivate(); } -QSoftKeyAction::QSoftKeyAction(QSoftKeyAction::StandardRole role, QObject *parent) +QSoftKeyAction::QSoftKeyAction(StandardRole role, QObject *parent) : QAction(parent) { d = new QSoftKeyActionPrivate(role); @@ -69,7 +99,7 @@ QSoftKeyAction::QSoftKeyAction(const QString &text, QObject* parent) d = new QSoftKeyActionPrivate(); } -QSoftKeyAction::QSoftKeyAction(QSoftKeyAction::StandardRole role, const QString &text, QObject* parent) +QSoftKeyAction::QSoftKeyAction(StandardRole role, const QString &text, QObject* parent) : QAction(text, parent) { d = new QSoftKeyActionPrivate(role); @@ -81,7 +111,7 @@ QSoftKeyAction::QSoftKeyAction(const QIcon &icon, const QString &text, QObject* d = new QSoftKeyActionPrivate(); } -QSoftKeyAction::QSoftKeyAction(QSoftKeyAction::StandardRole role, const QIcon &icon, const QString &text, QObject* parent) +QSoftKeyAction::QSoftKeyAction(StandardRole role, const QIcon &icon, const QString &text, QObject* parent) : QAction(icon, text, parent) { d = new QSoftKeyActionPrivate(role); @@ -120,7 +150,7 @@ QString QSoftKeyAction::roleName() const \sa role(), roleName() */ -void QSoftKeyAction::setRole(QSoftKeyAction::StandardRole role) +void QSoftKeyAction::setRole(StandardRole role) { d->role = role; d->roleName = QString(); @@ -140,7 +170,7 @@ void QSoftKeyAction::setRole(const QString& role) emit changed(); } -int QSoftKeyAction::nativePosition() +int QSoftKeyAction::nativePosition() const { return d->nativePosition; } @@ -150,7 +180,7 @@ void QSoftKeyAction::setNativePosition(int position) d->nativePosition = position; } -int QSoftKeyAction::qtContextKey() +int QSoftKeyAction::qtContextKey() const { return d->qtContextKey; } diff --git a/src/gui/softkeys/qsoftkeyaction.h b/src/gui/softkeys/qsoftkeyaction.h index 76be8ee..e735376 100644 --- a/src/gui/softkeys/qsoftkeyaction.h +++ b/src/gui/softkeys/qsoftkeyaction.h @@ -1,27 +1,57 @@ /**************************************************************************** ** -** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) ** -** This file is part of the $MODULE$ of the Qt Toolkit. +** This file is part of the QtGui module of the Qt Toolkit. ** -** $TROLLTECH_DUAL_LICENSE$ +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ ** ****************************************************************************/ #ifndef QSOFTKEYACTION_H #define QSOFTKEYACTION_H -#include +#include "QtGui/qaction.h" + +QT_BEGIN_NAMESPACE class QSoftKeyActionPrivate; class QSoftKeyAction : public QAction { - Q_OBJECT public: - enum StandardRole - { + enum StandardRole { Options, Select, Back, @@ -41,24 +71,26 @@ public: }; QSoftKeyAction(QObject *parent); - QSoftKeyAction(QSoftKeyAction::StandardRole role, QObject *parent); + QSoftKeyAction(StandardRole role, QObject *parent); QSoftKeyAction(const QString &text, QObject* parent); - QSoftKeyAction(QSoftKeyAction::StandardRole role, const QString &text, QObject* parent); + QSoftKeyAction(StandardRole role, const QString &text, QObject* parent); QSoftKeyAction(const QIcon &icon, const QString &text, QObject* parent); - QSoftKeyAction(QSoftKeyAction::StandardRole role, const QIcon &icon, const QString &text, QObject* parent); + QSoftKeyAction(StandardRole role, const QIcon &icon, const QString &text, QObject* parent); ~QSoftKeyAction(); - QSoftKeyAction::StandardRole role() const; + StandardRole role() const; QString roleName() const; - void setRole(QSoftKeyAction::StandardRole role); + void setRole(StandardRole role); void setRole(const QString& role); - int nativePosition(); + int nativePosition() const; void setNativePosition(int position); - int qtContextKey(); + int qtContextKey() const; void setQtContextKey(int position); QSoftKeyActionPrivate *d; }; +QT_END_NAMESPACE + #endif // QSOFTKEYACTION_H diff --git a/src/gui/softkeys/qsoftkeystack.cpp b/src/gui/softkeys/qsoftkeystack.cpp index c1d6e98..a8bd3a9 100644 --- a/src/gui/softkeys/qsoftkeystack.cpp +++ b/src/gui/softkeys/qsoftkeystack.cpp @@ -1,24 +1,46 @@ /**************************************************************************** ** -** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) ** -** This file is part of the $MODULE$ of the Qt Toolkit. +** This file is part of the QtGui module of the Qt Toolkit. ** -** $TROLLTECH_DUAL_LICENSE$ +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ ** ****************************************************************************/ -#include -#include -#include -#include -#include - -#include "private/qcore_symbian_p.h" - - #include "qsoftkeystack.h" +#include "qsoftkeystack_p.h" QSoftKeyStackPrivate::QSoftKeyStackPrivate() { @@ -30,65 +52,15 @@ QSoftKeyStackPrivate::~QSoftKeyStackPrivate() } -void QSoftKeyStackPrivate::mapSoftKeys(QSoftkeySet& top) -{ - if( top.count() == 1) - { - top.at(0)->setNativePosition(2); - top.at(0)->setQtContextKey(Qt::Key_Context2); - } - else - { - // FIX THIS - // veryWeirdMagic is needes as s60 5th edition sdk always panics if cba is set with index 1, this hops over it - // This needs further investigation why so that the hack can be removed - int veryWeirdMagic = 0; - for (int index=0;indexsetNativePosition(index+veryWeirdMagic); - top.at(index)->setQtContextKey(Qt::Key_Context1+index); - if (veryWeirdMagic==0) - veryWeirdMagic=1; - } - } -} - -void QSoftKeyStackPrivate::setNativeSoftKeys() -{ - CCoeAppUi* appui = CEikonEnv::Static()->AppUi(); - CAknAppUi* aknAppUi = static_cast (appui); - CEikButtonGroupContainer* nativeContainer = aknAppUi->Cba(); - nativeContainer->SetCommandSetL(R_AVKON_SOFTKEYS_EMPTY_WITH_IDS); - if(softKeyStack.isEmpty()) - return; - - QSoftkeySet top = softKeyStack.top(); - mapSoftKeys(top); - - for (int index=0;indextext()); - CleanupStack::PushL(text); - if (softKeyAction->role() == QSoftKeyAction::Menu) { - nativeContainer->SetCommandL(softKeyAction->nativePosition(), EAknSoftkeyOptions, *text); - } - else { - nativeContainer->SetCommandL(softKeyAction->nativePosition(), SOFTKEYSTART+softKeyAction->qtContextKey(), *text); - } - CleanupStack::PopAndDestroy(); - } -} - void QSoftKeyStackPrivate::push(QSoftKeyAction *softKey) { QSoftkeySet softKeySet; - softKeySet.append( softKey ); + softKeySet.append(softKey); softKeyStack.push(softKeySet); setNativeSoftKeys(); } -void QSoftKeyStackPrivate::push( QList softkeys) +void QSoftKeyStackPrivate::push(const QList &softkeys) { QSoftkeySet softKeySet(softkeys); softKeyStack.push(softKeySet); @@ -101,7 +73,7 @@ void QSoftKeyStackPrivate::pop() setNativeSoftKeys(); } -EXPORT_C QSoftKeyStack::QSoftKeyStack(QWidget *parent) +QSoftKeyStack::QSoftKeyStack(QWidget *parent) { d = new QSoftKeyStackPrivate(); } @@ -116,7 +88,7 @@ void QSoftKeyStack::push(QSoftKeyAction *softKey) d->push(softKey); } -void QSoftKeyStack::push(QList softKeys) +void QSoftKeyStack::push(const QList &softKeys) { d->push(softKeys); } diff --git a/src/gui/softkeys/qsoftkeystack.h b/src/gui/softkeys/qsoftkeystack.h index b96bf60..90df43d 100644 --- a/src/gui/softkeys/qsoftkeystack.h +++ b/src/gui/softkeys/qsoftkeystack.h @@ -1,77 +1,74 @@ /**************************************************************************** ** -** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) ** -** This file is part of the $MODULE$ of the Qt Toolkit. +** This file is part of the QtGui module of the Qt Toolkit. ** -** $TROLLTECH_DUAL_LICENSE$ +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ ** ****************************************************************************/ #ifndef QSOFTKEYSTACK_H #define QSOFTKEYSTACK_H -#include -#include -#include +#include "QtGui/qwidget.h" +#include "QtGui/qaction.h" +#include "qstack.h" #include "qsoftkeyaction.h" -#define QSoftkeySet QList -#define SOFTKEYSTART 5000 -#define SOFTKEYEND 5000+Qt::Key_Context4 +QT_BEGIN_NAMESPACE -class QSoftKeyStackPrivate : public QObject - { - Q_OBJECT - public: - IMPORT_C QSoftKeyStackPrivate(); - ~QSoftKeyStackPrivate(); - -public: - void push(QSoftKeyAction *softKey); - void push(QList softKeys); - void pop(); - -private: - void mapSoftKeys(QSoftkeySet& top); - void setNativeSoftKeys(); - -private: - QStack softKeyStack; - }; - - - -/*class QSoftkeySet - { - const QList softkeys; - }; +#define QSoftkeySet QList +class QSoftKeyStackPrivate; -class QSoftkeySet - { - const QList softkeys; - }; -*/ class QSoftKeyStack : public QObject { - Q_OBJECT public: - IMPORT_C QSoftKeyStack(QWidget *parent); + QSoftKeyStack(QWidget *parent); ~QSoftKeyStack(); + public: void push(QSoftKeyAction *softKey); - void push(QList softkeys); + void push(const QList &softkeys); void pop(); -protected: - -private Q_SLOTS: private: QSoftKeyStackPrivate *d; - }; +QT_END_NAMESPACE + #endif // QSOFTKEYSTACK_H diff --git a/src/gui/softkeys/qsoftkeystack_p.h b/src/gui/softkeys/qsoftkeystack_p.h new file mode 100644 index 0000000..8e029af --- /dev/null +++ b/src/gui/softkeys/qsoftkeystack_p.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSOFTKEYSTACK_P_H +#define QSOFTKEYSTACK_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "QtGui/qwidget.h" +#include "QtGui/qaction.h" +#include "qstack.h" + +#include "qsoftkeyaction.h" + +QT_BEGIN_NAMESPACE + +#define QSoftkeySet QList + +class QSoftKeyStackPrivate : public QObject +{ +public: + QSoftKeyStackPrivate(); + ~QSoftKeyStackPrivate(); + + void push(QSoftKeyAction *softKey); + void push(const QList &softKeys); + void pop(); + +private: + void mapSoftKeys(const QSoftkeySet &top); + void setNativeSoftKeys(); + +private: + QStack softKeyStack; +}; + +QT_END_NAMESPACE + +#endif // QSOFTKEYSTACK_P_H diff --git a/src/gui/softkeys/qsoftkeystack_s60.cpp b/src/gui/softkeys/qsoftkeystack_s60.cpp new file mode 100644 index 0000000..ce4f116 --- /dev/null +++ b/src/gui/softkeys/qsoftkeystack_s60.cpp @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include + +#include "private/qcore_symbian_p.h" + +#include "qsoftkeystack_p.h" + +#define SOFTKEYSTART 5000 +#define SOFTKEYEND (5000 + Qt::Key_Context4) + +void QSoftKeyStackPrivate::mapSoftKeys(const QSoftkeySet &top) +{ + if (top.count() == 1) { + top.at(0)->setNativePosition(2); + top.at(0)->setQtContextKey(Qt::Key_Context2); + } + else { + // FIX THIS + // veryWeirdMagic is needes as s60 5th edition sdk always panics if cba is set with index 1, this hops over it + // This needs further investigation why so that the hack can be removed + int veryWeirdMagic = 0; + for (int index = 0; index < top.count(); index++) { + top.at(index)->setNativePosition(index + veryWeirdMagic); + top.at(index)->setQtContextKey(Qt::Key_Context1 + index); + if (veryWeirdMagic == 0) + veryWeirdMagic = 1; + } + } +} + +void QSoftKeyStackPrivate::setNativeSoftKeys() +{ + CCoeAppUi* appui = CEikonEnv::Static()->AppUi(); + CAknAppUi* aknAppUi = static_cast (appui); + CEikButtonGroupContainer* nativeContainer = aknAppUi->Cba(); + nativeContainer->SetCommandSetL(R_AVKON_SOFTKEYS_EMPTY_WITH_IDS); + if (softKeyStack.isEmpty()) + return; + + const QSoftkeySet top = softKeyStack.top(); + mapSoftKeys(top); + + for (int index = 0; index < top.count(); index++) { + const QSoftKeyAction* softKeyAction = top.at(index); + HBufC* text = qt_QString2HBufCNewL(softKeyAction->text()); + CleanupStack::PushL(text); + if (softKeyAction->role() == QSoftKeyAction::Menu) { + nativeContainer->SetCommandL(softKeyAction->nativePosition(), EAknSoftkeyOptions, *text); + } else { + nativeContainer->SetCommandL(softKeyAction->nativePosition(), SOFTKEYSTART + softKeyAction->qtContextKey(), *text); + } + CleanupStack::PopAndDestroy(); + } +} + + diff --git a/src/gui/softkeys/softkeys.pro b/src/gui/softkeys/softkeys.pro index 88a813e..6bb584e 100644 --- a/src/gui/softkeys/softkeys.pro +++ b/src/gui/softkeys/softkeys.pro @@ -3,11 +3,13 @@ TARGET = softkeys HEADERS += \ qsoftkeystack.h \ + qsoftkeystack_p.h \ qsoftkeyaction.h SOURCES += \ main.cpp \ qsoftkeyaction.cpp \ + qsoftkeystack_s60.cpp \ qsoftkeystack.cpp iCONFIG += qt debug warn_on -- cgit v0.12 From 282a724b26b734aa4d9406567f5ec4ca96e8c320 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Tue, 12 May 2009 18:49:38 +0200 Subject: Removed redundancies --- src/gui/softkeys/softkeys.pro | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/gui/softkeys/softkeys.pro b/src/gui/softkeys/softkeys.pro index 6bb584e..e9e700c 100644 --- a/src/gui/softkeys/softkeys.pro +++ b/src/gui/softkeys/softkeys.pro @@ -1,6 +1,3 @@ -TEMPLATE = app -TARGET = softkeys - HEADERS += \ qsoftkeystack.h \ qsoftkeystack_p.h \ @@ -11,5 +8,3 @@ SOURCES += \ qsoftkeyaction.cpp \ qsoftkeystack_s60.cpp \ qsoftkeystack.cpp - -iCONFIG += qt debug warn_on -- cgit v0.12 From 10a294b71d0ccaddb48b1396352a744fdd0de6bf Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Tue, 12 May 2009 19:57:13 +0200 Subject: Moved SoftkeyStack files into src/widgets Corrected PImpl-ing and cleaned up headers --- src/gui/softkeys/qsoftkeyaction.cpp | 191 ------------------------------- src/gui/softkeys/qsoftkeyaction.h | 96 ---------------- src/gui/softkeys/qsoftkeystack.cpp | 100 ----------------- src/gui/softkeys/qsoftkeystack.h | 74 ------------ src/gui/softkeys/qsoftkeystack_p.h | 86 -------------- src/gui/softkeys/qsoftkeystack_s60.cpp | 100 ----------------- src/gui/widgets/qsoftkeyaction.cpp | 198 +++++++++++++++++++++++++++++++++ src/gui/widgets/qsoftkeyaction.h | 101 +++++++++++++++++ src/gui/widgets/qsoftkeystack.cpp | 102 +++++++++++++++++ src/gui/widgets/qsoftkeystack.h | 75 +++++++++++++ src/gui/widgets/qsoftkeystack_p.h | 86 ++++++++++++++ src/gui/widgets/qsoftkeystack_s60.cpp | 100 +++++++++++++++++ 12 files changed, 662 insertions(+), 647 deletions(-) delete mode 100644 src/gui/softkeys/qsoftkeyaction.cpp delete mode 100644 src/gui/softkeys/qsoftkeyaction.h delete mode 100644 src/gui/softkeys/qsoftkeystack.cpp delete mode 100644 src/gui/softkeys/qsoftkeystack.h delete mode 100644 src/gui/softkeys/qsoftkeystack_p.h delete mode 100644 src/gui/softkeys/qsoftkeystack_s60.cpp create mode 100644 src/gui/widgets/qsoftkeyaction.cpp create mode 100644 src/gui/widgets/qsoftkeyaction.h create mode 100644 src/gui/widgets/qsoftkeystack.cpp create mode 100644 src/gui/widgets/qsoftkeystack.h create mode 100644 src/gui/widgets/qsoftkeystack_p.h create mode 100644 src/gui/widgets/qsoftkeystack_s60.cpp diff --git a/src/gui/softkeys/qsoftkeyaction.cpp b/src/gui/softkeys/qsoftkeyaction.cpp deleted file mode 100644 index 1d21376..0000000 --- a/src/gui/softkeys/qsoftkeyaction.cpp +++ /dev/null @@ -1,191 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qsoftkeyaction.h" - -/*! - \class QSoftKeyAction - \brief The QSoftKeyAction class defines a special kind of QAction that may also be displayed in a QSoftKeyBar. -*/ - -class QSoftKeyActionPrivate -{ -public: - QSoftKeyActionPrivate(QSoftKeyAction::StandardRole role = QSoftKeyAction::Custom) - { - this->role = role; - } - - QSoftKeyAction::StandardRole role; - QString roleName; - int nativePosition; - int qtContextKey; -}; - -/*! - \enum QSoftKeyAction::StandardRole - This enum defines the standard role for a QSoftKeyAction. - - \value Options - \value Select - \value Back - \value Next - \value Previous - \value Ok - \value Cancel - \value Edit - \value View - \value BackSpace - \value EndEdit - \value RevertEdit - \value Deselect - \value Finish - \value Custom -*/ - -QSoftKeyAction::QSoftKeyAction(QObject *parent) - : QAction(parent) -{ - d = new QSoftKeyActionPrivate(); -} - -QSoftKeyAction::QSoftKeyAction(StandardRole role, QObject *parent) - : QAction(parent) -{ - d = new QSoftKeyActionPrivate(role); -} - -QSoftKeyAction::QSoftKeyAction(const QString &text, QObject* parent) - : QAction(text, parent) -{ - d = new QSoftKeyActionPrivate(); -} - -QSoftKeyAction::QSoftKeyAction(StandardRole role, const QString &text, QObject* parent) - : QAction(text, parent) -{ - d = new QSoftKeyActionPrivate(role); -} - -QSoftKeyAction::QSoftKeyAction(const QIcon &icon, const QString &text, QObject* parent) - : QAction(icon, text, parent) -{ - d = new QSoftKeyActionPrivate(); -} - -QSoftKeyAction::QSoftKeyAction(StandardRole role, const QIcon &icon, const QString &text, QObject* parent) - : QAction(icon, text, parent) -{ - d = new QSoftKeyActionPrivate(role); -} - -QSoftKeyAction::~QSoftKeyAction() -{ - delete d; -} - -/*! - Returns the standard role associated with this action, or Custom - if the role is defined by roleName(). - - \sa setRole(), roleName() -*/ -QSoftKeyAction::StandardRole QSoftKeyAction::role() const -{ - return d->role; -} - -/*! - Returns the custom role name if role() is Custom, or an empty - string otherwise. - - \sa role(), setRole() -*/ -QString QSoftKeyAction::roleName() const -{ - return d->roleName; -} - -/*! - Sets the standard role associated with this action to \a role, - and also sets roleName() to the empty string. - - \sa role(), roleName() -*/ -void QSoftKeyAction::setRole(StandardRole role) -{ - d->role = role; - d->roleName = QString(); - emit changed(); -} - -/*! - Sets the custom roleName() associated with this action to \a role, - and also sets role() to Custom. - - \sa role(), roleName() -*/ -void QSoftKeyAction::setRole(const QString& role) -{ - d->role = QSoftKeyAction::Custom; - d->roleName = role; - emit changed(); -} - -int QSoftKeyAction::nativePosition() const -{ - return d->nativePosition; -} - -void QSoftKeyAction::setNativePosition(int position) -{ - d->nativePosition = position; -} - -int QSoftKeyAction::qtContextKey() const -{ - return d->qtContextKey; -} - -void QSoftKeyAction::setQtContextKey(int key) -{ - d->qtContextKey = key; -} diff --git a/src/gui/softkeys/qsoftkeyaction.h b/src/gui/softkeys/qsoftkeyaction.h deleted file mode 100644 index e735376..0000000 --- a/src/gui/softkeys/qsoftkeyaction.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSOFTKEYACTION_H -#define QSOFTKEYACTION_H - -#include "QtGui/qaction.h" - -QT_BEGIN_NAMESPACE - -class QSoftKeyActionPrivate; - -class QSoftKeyAction : public QAction -{ -public: - enum StandardRole { - Options, - Select, - Back, - Next, - Previous, - Ok, - Cancel, - Edit, - View, - BackSpace, - EndEdit, - RevertEdit, - Deselect, - Finish, - Menu, - Custom - }; - - QSoftKeyAction(QObject *parent); - QSoftKeyAction(StandardRole role, QObject *parent); - QSoftKeyAction(const QString &text, QObject* parent); - QSoftKeyAction(StandardRole role, const QString &text, QObject* parent); - QSoftKeyAction(const QIcon &icon, const QString &text, QObject* parent); - QSoftKeyAction(StandardRole role, const QIcon &icon, const QString &text, QObject* parent); - ~QSoftKeyAction(); - - StandardRole role() const; - QString roleName() const; - - void setRole(StandardRole role); - void setRole(const QString& role); - int nativePosition() const; - void setNativePosition(int position); - int qtContextKey() const; - void setQtContextKey(int position); - - QSoftKeyActionPrivate *d; -}; - -QT_END_NAMESPACE - -#endif // QSOFTKEYACTION_H diff --git a/src/gui/softkeys/qsoftkeystack.cpp b/src/gui/softkeys/qsoftkeystack.cpp deleted file mode 100644 index a8bd3a9..0000000 --- a/src/gui/softkeys/qsoftkeystack.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qsoftkeystack.h" -#include "qsoftkeystack_p.h" - -QSoftKeyStackPrivate::QSoftKeyStackPrivate() -{ - -} - -QSoftKeyStackPrivate::~QSoftKeyStackPrivate() -{ - -} - -void QSoftKeyStackPrivate::push(QSoftKeyAction *softKey) -{ - QSoftkeySet softKeySet; - softKeySet.append(softKey); - softKeyStack.push(softKeySet); - setNativeSoftKeys(); - -} -void QSoftKeyStackPrivate::push(const QList &softkeys) -{ - QSoftkeySet softKeySet(softkeys); - softKeyStack.push(softKeySet); - setNativeSoftKeys(); -} - -void QSoftKeyStackPrivate::pop() -{ - softKeyStack.pop(); - setNativeSoftKeys(); -} - -QSoftKeyStack::QSoftKeyStack(QWidget *parent) -{ - d = new QSoftKeyStackPrivate(); -} - -QSoftKeyStack::~QSoftKeyStack() -{ - delete d; -} - -void QSoftKeyStack::push(QSoftKeyAction *softKey) -{ - d->push(softKey); -} - -void QSoftKeyStack::push(const QList &softKeys) -{ - d->push(softKeys); -} - -void QSoftKeyStack::pop() -{ - d->pop(); -} - diff --git a/src/gui/softkeys/qsoftkeystack.h b/src/gui/softkeys/qsoftkeystack.h deleted file mode 100644 index 90df43d..0000000 --- a/src/gui/softkeys/qsoftkeystack.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSOFTKEYSTACK_H -#define QSOFTKEYSTACK_H - -#include "QtGui/qwidget.h" -#include "QtGui/qaction.h" -#include "qstack.h" - -#include "qsoftkeyaction.h" - -QT_BEGIN_NAMESPACE - -#define QSoftkeySet QList - -class QSoftKeyStackPrivate; - -class QSoftKeyStack : public QObject -{ -public: - QSoftKeyStack(QWidget *parent); - ~QSoftKeyStack(); - -public: - void push(QSoftKeyAction *softKey); - void push(const QList &softkeys); - void pop(); - -private: - QSoftKeyStackPrivate *d; -}; - -QT_END_NAMESPACE - -#endif // QSOFTKEYSTACK_H diff --git a/src/gui/softkeys/qsoftkeystack_p.h b/src/gui/softkeys/qsoftkeystack_p.h deleted file mode 100644 index 8e029af..0000000 --- a/src/gui/softkeys/qsoftkeystack_p.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSOFTKEYSTACK_P_H -#define QSOFTKEYSTACK_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "QtGui/qwidget.h" -#include "QtGui/qaction.h" -#include "qstack.h" - -#include "qsoftkeyaction.h" - -QT_BEGIN_NAMESPACE - -#define QSoftkeySet QList - -class QSoftKeyStackPrivate : public QObject -{ -public: - QSoftKeyStackPrivate(); - ~QSoftKeyStackPrivate(); - - void push(QSoftKeyAction *softKey); - void push(const QList &softKeys); - void pop(); - -private: - void mapSoftKeys(const QSoftkeySet &top); - void setNativeSoftKeys(); - -private: - QStack softKeyStack; -}; - -QT_END_NAMESPACE - -#endif // QSOFTKEYSTACK_P_H diff --git a/src/gui/softkeys/qsoftkeystack_s60.cpp b/src/gui/softkeys/qsoftkeystack_s60.cpp deleted file mode 100644 index ce4f116..0000000 --- a/src/gui/softkeys/qsoftkeystack_s60.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include -#include - -#include "private/qcore_symbian_p.h" - -#include "qsoftkeystack_p.h" - -#define SOFTKEYSTART 5000 -#define SOFTKEYEND (5000 + Qt::Key_Context4) - -void QSoftKeyStackPrivate::mapSoftKeys(const QSoftkeySet &top) -{ - if (top.count() == 1) { - top.at(0)->setNativePosition(2); - top.at(0)->setQtContextKey(Qt::Key_Context2); - } - else { - // FIX THIS - // veryWeirdMagic is needes as s60 5th edition sdk always panics if cba is set with index 1, this hops over it - // This needs further investigation why so that the hack can be removed - int veryWeirdMagic = 0; - for (int index = 0; index < top.count(); index++) { - top.at(index)->setNativePosition(index + veryWeirdMagic); - top.at(index)->setQtContextKey(Qt::Key_Context1 + index); - if (veryWeirdMagic == 0) - veryWeirdMagic = 1; - } - } -} - -void QSoftKeyStackPrivate::setNativeSoftKeys() -{ - CCoeAppUi* appui = CEikonEnv::Static()->AppUi(); - CAknAppUi* aknAppUi = static_cast (appui); - CEikButtonGroupContainer* nativeContainer = aknAppUi->Cba(); - nativeContainer->SetCommandSetL(R_AVKON_SOFTKEYS_EMPTY_WITH_IDS); - if (softKeyStack.isEmpty()) - return; - - const QSoftkeySet top = softKeyStack.top(); - mapSoftKeys(top); - - for (int index = 0; index < top.count(); index++) { - const QSoftKeyAction* softKeyAction = top.at(index); - HBufC* text = qt_QString2HBufCNewL(softKeyAction->text()); - CleanupStack::PushL(text); - if (softKeyAction->role() == QSoftKeyAction::Menu) { - nativeContainer->SetCommandL(softKeyAction->nativePosition(), EAknSoftkeyOptions, *text); - } else { - nativeContainer->SetCommandL(softKeyAction->nativePosition(), SOFTKEYSTART + softKeyAction->qtContextKey(), *text); - } - CleanupStack::PopAndDestroy(); - } -} - - diff --git a/src/gui/widgets/qsoftkeyaction.cpp b/src/gui/widgets/qsoftkeyaction.cpp new file mode 100644 index 0000000..51b80bc --- /dev/null +++ b/src/gui/widgets/qsoftkeyaction.cpp @@ -0,0 +1,198 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qsoftkeyaction.h" + +/*! + \class QSoftKeyAction + \brief The QSoftKeyAction class defines a special kind of QAction that may also be displayed in a QSoftKeyBar. +*/ + +class QSoftKeyActionPrivate +{ +public: + QSoftKeyActionPrivate(QSoftKeyAction::StandardRole role = QSoftKeyAction::Custom) + { + this->role = role; + } + + QSoftKeyAction::StandardRole role; + QString roleName; + int nativePosition; + int qtContextKey; +}; + +/*! + \enum QSoftKeyAction::StandardRole + This enum defines the standard role for a QSoftKeyAction. + + \value Options + \value Select + \value Back + \value Next + \value Previous + \value Ok + \value Cancel + \value Edit + \value View + \value BackSpace + \value EndEdit + \value RevertEdit + \value Deselect + \value Finish + \value Custom +*/ + +QSoftKeyAction::QSoftKeyAction(QObject *parent) + : QAction(parent) +{ +} + +QSoftKeyAction::QSoftKeyAction(StandardRole role, QObject *parent) + : QAction(parent) +{ + Q_D(QSoftKeyAction); + d->role = role; +} + +QSoftKeyAction::QSoftKeyAction(const QString &text, QObject* parent) + : QAction(text, parent) +{ +} + +QSoftKeyAction::QSoftKeyAction(StandardRole role, const QString &text, QObject* parent) + : QAction(text, parent) +{ + Q_D(QSoftKeyAction); + d->role = role; +} + +QSoftKeyAction::QSoftKeyAction(const QIcon &icon, const QString &text, QObject* parent) + : QAction(icon, text, parent) +{ +} + +QSoftKeyAction::QSoftKeyAction(StandardRole role, const QIcon &icon, const QString &text, QObject* parent) + : QAction(icon, text, parent) +{ + Q_D(QSoftKeyAction); + d->role = role; +} + +QSoftKeyAction::~QSoftKeyAction() +{ +} + +/*! + Returns the standard role associated with this action, or Custom + if the role is defined by roleName(). + + \sa setRole(), roleName() +*/ +QSoftKeyAction::StandardRole QSoftKeyAction::role() const +{ + Q_D(const QSoftKeyAction); + return d->role; +} + +/*! + Returns the custom role name if role() is Custom, or an empty + string otherwise. + + \sa role(), setRole() +*/ +QString QSoftKeyAction::roleName() const +{ + Q_D(const QSoftKeyAction); + return d->roleName; +} + +/*! + Sets the standard role associated with this action to \a role, + and also sets roleName() to the empty string. + + \sa role(), roleName() +*/ +void QSoftKeyAction::setRole(StandardRole role) +{ + Q_D(QSoftKeyAction); + d->role = role; + d->roleName = QString(); + emit changed(); +} + +/*! + Sets the custom roleName() associated with this action to \a role, + and also sets role() to Custom. + + \sa role(), roleName() +*/ +void QSoftKeyAction::setRole(const QString& role) +{ + Q_D(QSoftKeyAction); + d->role = Custom; + d->roleName = role; + emit changed(); +} + +int QSoftKeyAction::nativePosition() const +{ + Q_D(const QSoftKeyAction); + return d->nativePosition; +} + +void QSoftKeyAction::setNativePosition(int position) +{ + Q_D(QSoftKeyAction); + d->nativePosition = position; +} + +int QSoftKeyAction::qtContextKey() const +{ + Q_D(const QSoftKeyAction); + return d->qtContextKey; +} + +void QSoftKeyAction::setQtContextKey(int key) +{ + Q_D(QSoftKeyAction); + d->qtContextKey = key; +} diff --git a/src/gui/widgets/qsoftkeyaction.h b/src/gui/widgets/qsoftkeyaction.h new file mode 100644 index 0000000..fc5baf1 --- /dev/null +++ b/src/gui/widgets/qsoftkeyaction.h @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSOFTKEYACTION_H +#define QSOFTKEYACTION_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Gui) + +class QSoftKeyActionPrivate; + +class Q_GUI_EXPORT QSoftKeyAction : public QAction +{ + Q_DECLARE_PRIVATE(QSoftKeyAction) +public: + enum StandardRole { + Options, + Select, + Back, + Next, + Previous, + Ok, + Cancel, + Edit, + View, + BackSpace, + EndEdit, + RevertEdit, + Deselect, + Finish, + Menu, + Custom + }; + + QSoftKeyAction(QObject *parent); + QSoftKeyAction(StandardRole role, QObject *parent); + QSoftKeyAction(const QString &text, QObject *parent); + QSoftKeyAction(StandardRole role, const QString &text, QObject *parent); + QSoftKeyAction(const QIcon &icon, const QString &text, QObject *parent); + QSoftKeyAction(StandardRole role, const QIcon &icon, const QString &text, QObject *parent); + ~QSoftKeyAction(); + + StandardRole role() const; + QString roleName() const; + + void setRole(StandardRole role); + void setRole(const QString &role); + int nativePosition() const; + void setNativePosition(int position); + int qtContextKey() const; + void setQtContextKey(int position); +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QSOFTKEYACTION_H diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp new file mode 100644 index 0000000..1054852 --- /dev/null +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qsoftkeystack.h" +#include "qsoftkeystack_p.h" + +QSoftKeyStackPrivate::QSoftKeyStackPrivate() +{ + +} + +QSoftKeyStackPrivate::~QSoftKeyStackPrivate() +{ + +} + +void QSoftKeyStackPrivate::push(QSoftKeyAction *softKey) +{ + QSoftkeySet softKeySet; + softKeySet.append(softKey); + softKeyStack.push(softKeySet); + setNativeSoftKeys(); + +} +void QSoftKeyStackPrivate::push(const QList &softkeys) +{ + QSoftkeySet softKeySet(softkeys); + softKeyStack.push(softKeySet); + setNativeSoftKeys(); +} + +void QSoftKeyStackPrivate::pop() +{ + softKeyStack.pop(); + setNativeSoftKeys(); +} + +QSoftKeyStack::QSoftKeyStack(QWidget *parent) + : QObject(parent) +{ +} + +QSoftKeyStack::~QSoftKeyStack() +{ +} + +void QSoftKeyStack::push(QSoftKeyAction *softKey) +{ + Q_D(QSoftKeyStack); + d->push(softKey); +} + +void QSoftKeyStack::push(const QList &softKeys) +{ + Q_D(QSoftKeyStack); + d->push(softKeys); +} + +void QSoftKeyStack::pop() +{ + Q_D(QSoftKeyStack); + d->pop(); +} + diff --git a/src/gui/widgets/qsoftkeystack.h b/src/gui/widgets/qsoftkeystack.h new file mode 100644 index 0000000..a9137d2 --- /dev/null +++ b/src/gui/widgets/qsoftkeystack.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSOFTKEYSTACK_H +#define QSOFTKEYSTACK_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Gui) + +#define QSoftkeySet QList + +class QSoftKeyStackPrivate; +class QSoftKeyAction; + +class Q_GUI_EXPORT QSoftKeyStack : public QObject +{ + Q_DECLARE_PRIVATE(QSoftKeyStack) +public: + QSoftKeyStack(QWidget *parent); + ~QSoftKeyStack(); + +public: + void push(QSoftKeyAction *softKey); + void push(const QList &softkeys); + void pop(); +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QSOFTKEYSTACK_H diff --git a/src/gui/widgets/qsoftkeystack_p.h b/src/gui/widgets/qsoftkeystack_p.h new file mode 100644 index 0000000..2e3fde1 --- /dev/null +++ b/src/gui/widgets/qsoftkeystack_p.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSOFTKEYSTACK_P_H +#define QSOFTKEYSTACK_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "QtGui/qwidget.h" +#include "QtGui/qaction.h" +#include "qstack.h" + +#include "qsoftkeyaction.h" + +QT_BEGIN_NAMESPACE + +#define QSoftkeySet QList + +class QSoftKeyStackPrivate : public QObject +{ +public: + QSoftKeyStackPrivate(); + ~QSoftKeyStackPrivate(); + + void push(QSoftKeyAction *softKey); + void push(const QList &softKeys); + void pop(); + +private: + void mapSoftKeys(const QSoftkeySet &top); + void setNativeSoftKeys(); + +private: + QStack softKeyStack; +}; + +QT_END_NAMESPACE + +#endif // QSOFTKEYSTACK_P_H diff --git a/src/gui/widgets/qsoftkeystack_s60.cpp b/src/gui/widgets/qsoftkeystack_s60.cpp new file mode 100644 index 0000000..ce4f116 --- /dev/null +++ b/src/gui/widgets/qsoftkeystack_s60.cpp @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include + +#include "private/qcore_symbian_p.h" + +#include "qsoftkeystack_p.h" + +#define SOFTKEYSTART 5000 +#define SOFTKEYEND (5000 + Qt::Key_Context4) + +void QSoftKeyStackPrivate::mapSoftKeys(const QSoftkeySet &top) +{ + if (top.count() == 1) { + top.at(0)->setNativePosition(2); + top.at(0)->setQtContextKey(Qt::Key_Context2); + } + else { + // FIX THIS + // veryWeirdMagic is needes as s60 5th edition sdk always panics if cba is set with index 1, this hops over it + // This needs further investigation why so that the hack can be removed + int veryWeirdMagic = 0; + for (int index = 0; index < top.count(); index++) { + top.at(index)->setNativePosition(index + veryWeirdMagic); + top.at(index)->setQtContextKey(Qt::Key_Context1 + index); + if (veryWeirdMagic == 0) + veryWeirdMagic = 1; + } + } +} + +void QSoftKeyStackPrivate::setNativeSoftKeys() +{ + CCoeAppUi* appui = CEikonEnv::Static()->AppUi(); + CAknAppUi* aknAppUi = static_cast (appui); + CEikButtonGroupContainer* nativeContainer = aknAppUi->Cba(); + nativeContainer->SetCommandSetL(R_AVKON_SOFTKEYS_EMPTY_WITH_IDS); + if (softKeyStack.isEmpty()) + return; + + const QSoftkeySet top = softKeyStack.top(); + mapSoftKeys(top); + + for (int index = 0; index < top.count(); index++) { + const QSoftKeyAction* softKeyAction = top.at(index); + HBufC* text = qt_QString2HBufCNewL(softKeyAction->text()); + CleanupStack::PushL(text); + if (softKeyAction->role() == QSoftKeyAction::Menu) { + nativeContainer->SetCommandL(softKeyAction->nativePosition(), EAknSoftkeyOptions, *text); + } else { + nativeContainer->SetCommandL(softKeyAction->nativePosition(), SOFTKEYSTART + softKeyAction->qtContextKey(), *text); + } + CleanupStack::PopAndDestroy(); + } +} + + -- cgit v0.12 From f8de827f56c6548490681fd3b5c252853f6fffb6 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Tue, 12 May 2009 21:14:49 +0200 Subject: Adapted example code --- src/gui/softkeys/main.cpp | 6 +----- src/gui/softkeys/softkeys.pro | 10 +--------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/gui/softkeys/main.cpp b/src/gui/softkeys/main.cpp index a61e512..c305d19 100644 --- a/src/gui/softkeys/main.cpp +++ b/src/gui/softkeys/main.cpp @@ -9,11 +9,7 @@ ** ****************************************************************************/ -#include -#include -#include - -#include "qsoftkeystack.h" +#include class MainWindow : public QMainWindow { diff --git a/src/gui/softkeys/softkeys.pro b/src/gui/softkeys/softkeys.pro index e9e700c..a16103e 100644 --- a/src/gui/softkeys/softkeys.pro +++ b/src/gui/softkeys/softkeys.pro @@ -1,10 +1,2 @@ -HEADERS += \ - qsoftkeystack.h \ - qsoftkeystack_p.h \ - qsoftkeyaction.h - SOURCES += \ - main.cpp \ - qsoftkeyaction.cpp \ - qsoftkeystack_s60.cpp \ - qsoftkeystack.cpp + main.cpp -- cgit v0.12 From a32fa3b48f2e58b409e27a465e99f5ef915ed3ed Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Tue, 12 May 2009 21:15:46 +0200 Subject: Adding qsoftkey* to widgets.pri. Currently, only for S60. It will spread as soon as it builds cross platform. --- src/gui/widgets/widgets.pri | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/gui/widgets/widgets.pri b/src/gui/widgets/widgets.pri index fc57944..c9e68a1 100644 --- a/src/gui/widgets/widgets.pri +++ b/src/gui/widgets/widgets.pri @@ -162,5 +162,14 @@ wince*: { } symbian*: { - SOURCES += widgets/qmenu_symbian.cpp + HEADERS += \ + widgets/qsoftkeyaction.h \ + widgets/qsoftkeystack.h \ + widgets/qsoftkeystack_p.h + + SOURCES += \ + widgets/qmenu_symbian.cpp \ + widgets/qsoftkeyaction.cpp \ + widgets/qsoftkeystack.cpp \ + widgets/qsoftkeystack_s60.cpp } -- cgit v0.12 From af612206adc919e3c13b7856f9f7c020ef9c3a7b Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Wed, 13 May 2009 14:52:25 +0200 Subject: Fixed pImpl, the private object were not created. --- src/gui/widgets/qsoftkeyaction.cpp | 21 ++++++++++++++------- src/gui/widgets/qsoftkeyaction.h | 5 ++++- src/gui/widgets/qsoftkeystack.cpp | 2 +- src/gui/widgets/qsoftkeystack.h | 6 ++++-- src/gui/widgets/qsoftkeystack_p.h | 6 +++--- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/gui/widgets/qsoftkeyaction.cpp b/src/gui/widgets/qsoftkeyaction.cpp index 51b80bc..583cf65 100644 --- a/src/gui/widgets/qsoftkeyaction.cpp +++ b/src/gui/widgets/qsoftkeyaction.cpp @@ -40,13 +40,14 @@ ****************************************************************************/ #include "qsoftkeyaction.h" +#include /*! \class QSoftKeyAction \brief The QSoftKeyAction class defines a special kind of QAction that may also be displayed in a QSoftKeyBar. */ -class QSoftKeyActionPrivate +class QSoftKeyActionPrivate : public QActionPrivate { public: QSoftKeyActionPrivate(QSoftKeyAction::StandardRole role = QSoftKeyAction::Custom) @@ -82,37 +83,43 @@ public: */ QSoftKeyAction::QSoftKeyAction(QObject *parent) - : QAction(parent) + : QAction(*new QSoftKeyActionPrivate(), parent) { } QSoftKeyAction::QSoftKeyAction(StandardRole role, QObject *parent) - : QAction(parent) + : QAction(*new QSoftKeyActionPrivate(), parent) { Q_D(QSoftKeyAction); d->role = role; } QSoftKeyAction::QSoftKeyAction(const QString &text, QObject* parent) - : QAction(text, parent) + : QAction(*new QSoftKeyActionPrivate(), parent) { + setText(text); } QSoftKeyAction::QSoftKeyAction(StandardRole role, const QString &text, QObject* parent) - : QAction(text, parent) + : QAction(*new QSoftKeyActionPrivate(), parent) { + setText(text); Q_D(QSoftKeyAction); d->role = role; } QSoftKeyAction::QSoftKeyAction(const QIcon &icon, const QString &text, QObject* parent) - : QAction(icon, text, parent) + : QAction(*new QSoftKeyActionPrivate(), parent) { + setIcon(icon); + setText(text); } QSoftKeyAction::QSoftKeyAction(StandardRole role, const QIcon &icon, const QString &text, QObject* parent) - : QAction(icon, text, parent) + : QAction(*new QSoftKeyActionPrivate(), parent) { + setIcon(icon); + setText(text); Q_D(QSoftKeyAction); d->role = role; } diff --git a/src/gui/widgets/qsoftkeyaction.h b/src/gui/widgets/qsoftkeyaction.h index fc5baf1..26fa601 100644 --- a/src/gui/widgets/qsoftkeyaction.h +++ b/src/gui/widgets/qsoftkeyaction.h @@ -54,7 +54,6 @@ class QSoftKeyActionPrivate; class Q_GUI_EXPORT QSoftKeyAction : public QAction { - Q_DECLARE_PRIVATE(QSoftKeyAction) public: enum StandardRole { Options, @@ -92,6 +91,10 @@ public: void setNativePosition(int position); int qtContextKey() const; void setQtContextKey(int position); + +private: + Q_DECLARE_PRIVATE(QSoftKeyAction) + Q_DISABLE_COPY(QSoftKeyAction) }; QT_END_NAMESPACE diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index 1054852..687b236 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -74,7 +74,7 @@ void QSoftKeyStackPrivate::pop() } QSoftKeyStack::QSoftKeyStack(QWidget *parent) - : QObject(parent) + : QObject(*new QSoftKeyStackPrivate, parent) { } diff --git a/src/gui/widgets/qsoftkeystack.h b/src/gui/widgets/qsoftkeystack.h index a9137d2..66edab0 100644 --- a/src/gui/widgets/qsoftkeystack.h +++ b/src/gui/widgets/qsoftkeystack.h @@ -57,15 +57,17 @@ class QSoftKeyAction; class Q_GUI_EXPORT QSoftKeyStack : public QObject { - Q_DECLARE_PRIVATE(QSoftKeyStack) public: QSoftKeyStack(QWidget *parent); ~QSoftKeyStack(); -public: void push(QSoftKeyAction *softKey); void push(const QList &softkeys); void pop(); + +private: + Q_DECLARE_PRIVATE(QSoftKeyStack) + Q_DISABLE_COPY(QSoftKeyStack) }; QT_END_NAMESPACE diff --git a/src/gui/widgets/qsoftkeystack_p.h b/src/gui/widgets/qsoftkeystack_p.h index 2e3fde1..1e8d0d1 100644 --- a/src/gui/widgets/qsoftkeystack_p.h +++ b/src/gui/widgets/qsoftkeystack_p.h @@ -53,9 +53,9 @@ // We mean it. // -#include "QtGui/qwidget.h" -#include "QtGui/qaction.h" + #include "qstack.h" +#include #include "qsoftkeyaction.h" @@ -63,7 +63,7 @@ QT_BEGIN_NAMESPACE #define QSoftkeySet QList -class QSoftKeyStackPrivate : public QObject +class QSoftKeyStackPrivate : public QObjectPrivate { public: QSoftKeyStackPrivate(); -- cgit v0.12 From a28a4bccad5d885bf3ac5f58a8febb8d59fffe0f Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Wed, 13 May 2009 16:25:24 +0200 Subject: Added Methods to set and access QSoftKeyStack from QMainWindow. --- src/gui/softkeys/main.cpp | 8 ++++++ src/gui/widgets/qmainwindow.cpp | 47 +++++++++++++++++++++++++++++++++++ src/gui/widgets/qmainwindow.h | 11 ++++++-- src/gui/widgets/qsoftkeyaction.h | 1 + src/gui/widgets/qsoftkeystack_s60.cpp | 17 +++++++------ 5 files changed, 75 insertions(+), 9 deletions(-) diff --git a/src/gui/softkeys/main.cpp b/src/gui/softkeys/main.cpp index c305d19..6a75c40 100644 --- a/src/gui/softkeys/main.cpp +++ b/src/gui/softkeys/main.cpp @@ -30,6 +30,8 @@ MainWindow::MainWindow(QWidget *parent) this->setMenuBar(menuBar); QSoftKeyStack *stack = new QSoftKeyStack(central); + setSoftKeyStack(stack); + QSoftKeyAction action1(central); action1.setText(QString("Ok")); action1.setRole(QSoftKeyAction::Ok); @@ -43,6 +45,11 @@ MainWindow::MainWindow(QWidget *parent) action4.setText(QString("Menu")); action4.setRole(QSoftKeyAction::Menu); + QSoftKeyAction action5(central); + action5.setText(QString("ContextMenu")); + action5.setRole(QSoftKeyAction::ContextMenu); + + QList myActionList; myActionList.append(&action1); myActionList.append(&action2); @@ -55,6 +62,7 @@ MainWindow::MainWindow(QWidget *parent) QList myActionList2; myActionList2.append(&action4); myActionList2.append(&action1); + myActionList2.append(&action5); stack->push(myActionList2); diff --git a/src/gui/widgets/qmainwindow.cpp b/src/gui/widgets/qmainwindow.cpp index 502c1e9..43bc098 100644 --- a/src/gui/widgets/qmainwindow.cpp +++ b/src/gui/widgets/qmainwindow.cpp @@ -66,6 +66,10 @@ extern OSWindowRef qt_mac_window_for(const QWidget *); // qwidget_mac.cpp QT_END_NAMESPACE #endif +#ifndef QT_NO_SOFTKEYSTACK +#include +#endif + QT_BEGIN_NAMESPACE class QMainWindowPrivate : public QWidgetPrivate @@ -80,6 +84,9 @@ public: #if !defined(QT_NO_DOCKWIDGET) && !defined(QT_NO_CURSOR) , hasOldCursor(false) , cursorAdjusted(false) #endif +#ifndef QT_NO_SOFTKEYSTACK + , softKeyStack(0) +#endif { } QMainWindowLayout *layout; QSize iconSize; @@ -99,6 +106,10 @@ public: uint hasOldCursor : 1; uint cursorAdjusted : 1; #endif + +#ifndef QT_NO_SOFTKEYSTACK + QSoftKeyStack* softKeyStack; +#endif }; void QMainWindowPrivate::init() @@ -514,6 +525,42 @@ void QMainWindow::setMenuWidget(QWidget *menuBar) } #endif // QT_NO_MENUBAR +#ifndef QT_NO_SOFTKEYSTACK +/*! + Returns the softkey stack for the main window. This function creates + and returns an empty soft key stack if the stack does not exist. + + \sa softKeyStack() +*/ +QSoftKeyStack *QMainWindow::softKeyStack() const +{ + if (!d_func()->softKeyStack) { + QMainWindow *self = const_cast(this); + QSoftKeyStack* softKeyStack = new QSoftKeyStack(self); + self->setSoftKeyStack(softKeyStack); + } + return d_func()->softKeyStack; +} + +/*! + Sets the softkey stackfor the main window to \a softKeyStack. + + Note: QMainWindow takes ownership of the \a softKeyStack pointer and + deletes it at the appropriate time. + + \sa softKeyStack() +*/ +void QMainWindow::setSoftKeyStack(QSoftKeyStack *softKeyStack) +{ + Q_D(QMainWindow); + if (d->softKeyStack && d->softKeyStack != softKeyStack) { + QSoftKeyStack *oldSoftKeyStack = d->softKeyStack; + delete oldSoftKeyStack; + } + d->softKeyStack = softKeyStack; +} +#endif // QT_NO_SOFTKEYSTACK + #ifndef QT_NO_STATUSBAR /*! Returns the status bar for the main window. This function creates diff --git a/src/gui/widgets/qmainwindow.h b/src/gui/widgets/qmainwindow.h index 9983c7a..e2dcd5e 100644 --- a/src/gui/widgets/qmainwindow.h +++ b/src/gui/widgets/qmainwindow.h @@ -59,7 +59,9 @@ class QMenuBar; class QStatusBar; class QToolBar; class QMenu; - +#ifndef QT_NO_SOFTKEYSTACK +class QSoftKeyStack; +#endif class Q_GUI_EXPORT QMainWindow : public QWidget { Q_OBJECT @@ -129,7 +131,12 @@ public: QWidget *menuWidget() const; void setMenuWidget(QWidget *menubar); #endif - + +#ifndef QT_NO_SOFTKEYSTACK + QSoftKeyStack *softKeyStack() const; + void setSoftKeyStack(QSoftKeyStack *softKeyStack); +#endif + #ifndef QT_NO_STATUSBAR QStatusBar *statusBar() const; void setStatusBar(QStatusBar *statusbar); diff --git a/src/gui/widgets/qsoftkeyaction.h b/src/gui/widgets/qsoftkeyaction.h index 26fa601..4ce5c5b 100644 --- a/src/gui/widgets/qsoftkeyaction.h +++ b/src/gui/widgets/qsoftkeyaction.h @@ -71,6 +71,7 @@ public: Deselect, Finish, Menu, + ContextMenu, Custom }; diff --git a/src/gui/widgets/qsoftkeystack_s60.cpp b/src/gui/widgets/qsoftkeystack_s60.cpp index ce4f116..35835f6 100644 --- a/src/gui/widgets/qsoftkeystack_s60.cpp +++ b/src/gui/widgets/qsoftkeystack_s60.cpp @@ -86,14 +86,17 @@ void QSoftKeyStackPrivate::setNativeSoftKeys() for (int index = 0; index < top.count(); index++) { const QSoftKeyAction* softKeyAction = top.at(index); - HBufC* text = qt_QString2HBufCNewL(softKeyAction->text()); - CleanupStack::PushL(text); - if (softKeyAction->role() == QSoftKeyAction::Menu) { - nativeContainer->SetCommandL(softKeyAction->nativePosition(), EAknSoftkeyOptions, *text); - } else { - nativeContainer->SetCommandL(softKeyAction->nativePosition(), SOFTKEYSTART + softKeyAction->qtContextKey(), *text); + if (softKeyAction->role() != QSoftKeyAction::ContextMenu) { + + HBufC* text = qt_QString2HBufCNewL(softKeyAction->text()); + CleanupStack::PushL(text); + if (softKeyAction->role() == QSoftKeyAction::Menu) { + nativeContainer->SetCommandL(softKeyAction->nativePosition(), EAknSoftkeyOptions, *text); + } else { + nativeContainer->SetCommandL(softKeyAction->nativePosition(), SOFTKEYSTART + softKeyAction->qtContextKey(), *text); + } + CleanupStack::PopAndDestroy(); } - CleanupStack::PopAndDestroy(); } } -- cgit v0.12 From 062e913e56a104f7d794cd4a7cecebbd33ead5a9 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Wed, 13 May 2009 19:27:24 +0200 Subject: QSoftKeyStack::handleSoftKeyPress(int command) will be called whenever a softkey is pressed. --- src/gui/widgets/qsoftkeystack.h | 2 ++ src/gui/widgets/qsoftkeystack_p.h | 5 +++++ src/gui/widgets/qsoftkeystack_s60.cpp | 9 +++++---- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/gui/widgets/qsoftkeystack.h b/src/gui/widgets/qsoftkeystack.h index 66edab0..ca06072 100644 --- a/src/gui/widgets/qsoftkeystack.h +++ b/src/gui/widgets/qsoftkeystack.h @@ -65,6 +65,8 @@ public: void push(const QList &softkeys); void pop(); + void handleSoftKeyPress(int command); + private: Q_DECLARE_PRIVATE(QSoftKeyStack) Q_DISABLE_COPY(QSoftKeyStack) diff --git a/src/gui/widgets/qsoftkeystack_p.h b/src/gui/widgets/qsoftkeystack_p.h index 1e8d0d1..77ae553 100644 --- a/src/gui/widgets/qsoftkeystack_p.h +++ b/src/gui/widgets/qsoftkeystack_p.h @@ -58,9 +58,14 @@ #include #include "qsoftkeyaction.h" +#include "qsoftkeystack.h" QT_BEGIN_NAMESPACE +// The following 2 defines may only be needed for s60. To be seen. +#define SOFTKEYSTART 5000 +#define SOFTKEYEND (5000 + Qt::Key_Context4) + #define QSoftkeySet QList class QSoftKeyStackPrivate : public QObjectPrivate diff --git a/src/gui/widgets/qsoftkeystack_s60.cpp b/src/gui/widgets/qsoftkeystack_s60.cpp index 35835f6..9e90fdf 100644 --- a/src/gui/widgets/qsoftkeystack_s60.cpp +++ b/src/gui/widgets/qsoftkeystack_s60.cpp @@ -49,9 +49,6 @@ #include "qsoftkeystack_p.h" -#define SOFTKEYSTART 5000 -#define SOFTKEYEND (5000 + Qt::Key_Context4) - void QSoftKeyStackPrivate::mapSoftKeys(const QSoftkeySet &top) { if (top.count() == 1) { @@ -100,4 +97,8 @@ void QSoftKeyStackPrivate::setNativeSoftKeys() } } - +void QSoftKeyStack::handleSoftKeyPress(int command) +{ + // Do the magic, here. + // Map the command back to actual softkey on the top of the stack and handle it +} -- cgit v0.12 From 3cd818783435ceb1314aba9a94f575ab52bd3d0f Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Wed, 13 May 2009 19:28:56 +0200 Subject: If the command is in a magic range pass it along to a currently active QMainWindow's softKeyStack. --- src/gui/kernel/qapplication_s60.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/gui/kernel/qapplication_s60.cpp b/src/gui/kernel/qapplication_s60.cpp index 72c2855..c0b4dc5 100644 --- a/src/gui/kernel/qapplication_s60.cpp +++ b/src/gui/kernel/qapplication_s60.cpp @@ -28,6 +28,9 @@ #include "private/qwindowsurface_s60_p.h" #include "qpaintengine.h" #include "qmenubar.h" +#include "qmainwindow.h" +#include "qsoftkeystack.h" +#include "private/qsoftkeystack_p.h" #include "apgwgnam.h" // For CApaWindowGroupName #include // For CMdaAudioToneUtility @@ -1019,8 +1022,14 @@ void QApplication::s60HandleCommandL(int command) qApp->exit(); break; default: - // For now assume all unknown menu items are Qt menu items - QMenuBar::symbianCommands(command); + if (command >= SOFTKEYSTART && command <= SOFTKEYEND) { + const QMainWindow *activeMainWindow = + qobject_cast(QApplication::activeWindow()); + if (activeMainWindow) + activeMainWindow->softKeyStack()->handleSoftKeyPress(command); + } else { + QMenuBar::symbianCommands(command); + } break; } } -- cgit v0.12 From b60c4838f3a40609136c45e4832b50007dc2be37 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Wed, 13 May 2009 19:29:12 +0200 Subject: Less meat. --- src/gui/kernel/qapplication_s60.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gui/kernel/qapplication_s60.cpp b/src/gui/kernel/qapplication_s60.cpp index c0b4dc5..8cf2f8f 100644 --- a/src/gui/kernel/qapplication_s60.cpp +++ b/src/gui/kernel/qapplication_s60.cpp @@ -1017,9 +1017,8 @@ void QApplication::s60HandleCommandL(int command) { switch (command) { case EEikCmdExit: - case EAknSoftkeyBack: case EAknSoftkeyExit: - qApp->exit(); + exit(); break; default: if (command >= SOFTKEYSTART && command <= SOFTKEYEND) { -- cgit v0.12 From 99d848f54c34aaa935d67ec406352bbafef03ae9 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Thu, 14 May 2009 21:27:30 +0200 Subject: Use the new QMainWindow::softKeyStack() --- src/gui/softkeys/main.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/gui/softkeys/main.cpp b/src/gui/softkeys/main.cpp index 6a75c40..e69156a 100644 --- a/src/gui/softkeys/main.cpp +++ b/src/gui/softkeys/main.cpp @@ -23,15 +23,16 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { - QWidget *central = new QWidget(this); + QWidget *central = new QWidget(this); + central->setLayout(new QVBoxLayout); + central->layout()->addWidget(new QPushButton); + central->layout()->addWidget(new QPushButton); + central->layout()->addWidget(new QPushButton); QMenuBar* menuBar = new QMenuBar(this); menuBar->addAction("MyMenuItem1"); this->setMenuBar(menuBar); - QSoftKeyStack *stack = new QSoftKeyStack(central); - setSoftKeyStack(stack); - QSoftKeyAction action1(central); action1.setText(QString("Ok")); action1.setRole(QSoftKeyAction::Ok); @@ -54,16 +55,16 @@ MainWindow::MainWindow(QWidget *parent) myActionList.append(&action1); myActionList.append(&action2); myActionList.append(&action3); - stack->push(myActionList); - stack->pop(); - stack->push(&action1); - stack->pop(); + softKeyStack()->push(myActionList); + softKeyStack()->pop(); + softKeyStack()->push(&action1); + softKeyStack()->pop(); QList myActionList2; myActionList2.append(&action4); myActionList2.append(&action1); myActionList2.append(&action5); - stack->push(myActionList2); + softKeyStack()->push(myActionList2); setCentralWidget(central); -- cgit v0.12 From 285ce9a19f2dd16f0aca650b52ac25daf6656b09 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Thu, 14 May 2009 21:28:30 +0200 Subject: Connecting to focusChanged in order to ask the freshly focussed widget for its actions. --- src/gui/widgets/qsoftkeystack.cpp | 26 ++++++++++++++++++++++++++ src/gui/widgets/qsoftkeystack.h | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index 687b236..61f7b64 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -41,6 +41,8 @@ #include "qsoftkeystack.h" #include "qsoftkeystack_p.h" +#include "qapplication.h" +#include "qmainwindow.h" QSoftKeyStackPrivate::QSoftKeyStackPrivate() { @@ -76,6 +78,7 @@ void QSoftKeyStackPrivate::pop() QSoftKeyStack::QSoftKeyStack(QWidget *parent) : QObject(*new QSoftKeyStackPrivate, parent) { + connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), SLOT(handleFocusChanged(QWidget*, QWidget*))); } QSoftKeyStack::~QSoftKeyStack() @@ -100,3 +103,26 @@ void QSoftKeyStack::pop() d->pop(); } +void QSoftKeyStack::handleFocusChanged(QWidget *old, QWidget *now) +{ + if (!now) + return; + bool nowInOurMainWindow = false; + const QMainWindow *ourMainWindow = qobject_cast(parent()); + Q_ASSERT(ourMainWindow); + + // "ourMainWindow" in parent chain of "now"? Isn't there a helper in Qt for this? + QWidget *nowParent = now; + while (nowParent = nowParent->parentWidget()) { + if (nowParent == ourMainWindow) { + nowInOurMainWindow = true; + break; + } + } + + if (!nowInOurMainWindow) + return; + + QList actions = now->actions(); + // Do something with these actions. +} diff --git a/src/gui/widgets/qsoftkeystack.h b/src/gui/widgets/qsoftkeystack.h index ca06072..d126b32 100644 --- a/src/gui/widgets/qsoftkeystack.h +++ b/src/gui/widgets/qsoftkeystack.h @@ -57,6 +57,7 @@ class QSoftKeyAction; class Q_GUI_EXPORT QSoftKeyStack : public QObject { + Q_OBJECT public: QSoftKeyStack(QWidget *parent); ~QSoftKeyStack(); @@ -67,6 +68,9 @@ public: void handleSoftKeyPress(int command); +private Q_SLOTS: + void handleFocusChanged(QWidget *old, QWidget *now); + private: Q_DECLARE_PRIVATE(QSoftKeyStack) Q_DISABLE_COPY(QSoftKeyStack) -- cgit v0.12 From c0e517977eefb579628c66716fa6bfcf5058f6b1 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Fri, 15 May 2009 12:05:37 +0200 Subject: Added method to return top of the stack --- src/gui/widgets/qsoftkeystack.cpp | 11 +++++++++++ src/gui/widgets/qsoftkeystack.h | 1 + src/gui/widgets/qsoftkeystack_p.h | 3 ++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index 61f7b64..fc6e107 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -75,6 +75,11 @@ void QSoftKeyStackPrivate::pop() setNativeSoftKeys(); } +const QSoftkeySet& QSoftKeyStackPrivate::top() +{ + return softKeyStack.top(); +} + QSoftKeyStack::QSoftKeyStack(QWidget *parent) : QObject(*new QSoftKeyStackPrivate, parent) { @@ -103,6 +108,12 @@ void QSoftKeyStack::pop() d->pop(); } +const QSoftkeySet& QSoftKeyStack::top() +{ + Q_D(QSoftKeyStack); + return d->top(); +} + void QSoftKeyStack::handleFocusChanged(QWidget *old, QWidget *now) { if (!now) diff --git a/src/gui/widgets/qsoftkeystack.h b/src/gui/widgets/qsoftkeystack.h index d126b32..c9a05c3 100644 --- a/src/gui/widgets/qsoftkeystack.h +++ b/src/gui/widgets/qsoftkeystack.h @@ -65,6 +65,7 @@ public: void push(QSoftKeyAction *softKey); void push(const QList &softkeys); void pop(); + const QSoftkeySet& top(); void handleSoftKeyPress(int command); diff --git a/src/gui/widgets/qsoftkeystack_p.h b/src/gui/widgets/qsoftkeystack_p.h index 77ae553..06e9253 100644 --- a/src/gui/widgets/qsoftkeystack_p.h +++ b/src/gui/widgets/qsoftkeystack_p.h @@ -77,7 +77,8 @@ public: void push(QSoftKeyAction *softKey); void push(const QList &softKeys); void pop(); - + const QSoftkeySet& top(); + private: void mapSoftKeys(const QSoftkeySet &top); void setNativeSoftKeys(); -- cgit v0.12 From c5417af885d7e9ff52f0b27526516dd39a788288 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Mon, 18 May 2009 10:52:17 +0200 Subject: Initial implementation for context menus --- src/gui/widgets/qmenu_symbian.cpp | 45 ++++++++++++++++++++++++++++++--------- src/gui/widgets/qmenubar_p.h | 1 + src/gui/widgets/qsoftkeyaction.h | 2 +- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/gui/widgets/qmenu_symbian.cpp b/src/gui/widgets/qmenu_symbian.cpp index 1dc727c..b9633b5 100644 --- a/src/gui/widgets/qmenu_symbian.cpp +++ b/src/gui/widgets/qmenu_symbian.cpp @@ -26,7 +26,8 @@ #include #include #include - +#include +#include #ifndef QT_NO_MENUBAR QT_BEGIN_NAMESPACE @@ -47,6 +48,7 @@ struct SymbianMenuItem static QList symbianMenus; static QList nativeMenuBars; static uint qt_symbian_menu_static_cmd_id = QT_FIRST_MENU_ITEM; +static QWidget* widgetWithContextMenu=0; bool menuExists() { @@ -177,6 +179,22 @@ static void rebuildMenu() { QMenuBarPrivate *mb = 0; QWidget *w = qApp->activeWindow(); + QMainWindow *mainWindow = qobject_cast(w); + QSoftKeyStack* softKeyStack = mainWindow->softKeyStack(); + const QSoftkeySet& softKeyTop = softKeyStack->top(); + + int index=0; + bool found=false; + while( indexrole(); + if(softAction->role() == QSoftKeyAction::ContextMenu) { + widgetWithContextMenu = softAction->parentWidget(); + found=true; + } + index++; + } if (w) { mb = menubars()->value(w); @@ -186,7 +204,8 @@ static void rebuildMenu() return; mb->symbian_menubar->rebuild(); } - } + widgetWithContextMenu = 0; +} Q_GUI_EXPORT void qt_symbian_show_toplevel( CEikMenuPane* menuPane) { @@ -358,21 +377,27 @@ void QMenuBarPrivate::QSymbianMenuBarPrivate::removeAction(QSymbianMenuAction *a rebuild(); } -void QMenuBarPrivate::QSymbianMenuBarPrivate::rebuild() +void QMenuBarPrivate::QSymbianMenuBarPrivate::InsertNativeMenuItems(const QList &actions) { - qt_symbian_menu_static_cmd_id = QT_FIRST_MENU_ITEM; - deleteAll( &symbianMenus ); - if (!d) - return; - for (int i = 0; i < d->actions.size(); ++i) { + for (int i = 0; i action = d->actions.at(i); + symbianActionTopLevel->action = actions.at(i); symbianActionTopLevel->parent = 0; symbianActionTopLevel->command = qt_symbian_menu_static_cmd_id++; qt_symbian_insert_action(symbianActionTopLevel, &symbianMenus); - } + } } +void QMenuBarPrivate::QSymbianMenuBarPrivate::rebuild() +{ + qt_symbian_menu_static_cmd_id = QT_FIRST_MENU_ITEM; + deleteAll( &symbianMenus ); + if (d) + InsertNativeMenuItems(d->actions); + + if (widgetWithContextMenu) + InsertNativeMenuItems(widgetWithContextMenu->actions()); + } QT_END_NAMESPACE #endif //QT_NO_MENUBAR diff --git a/src/gui/widgets/qmenubar_p.h b/src/gui/widgets/qmenubar_p.h index d562cd9..1b9bac7 100644 --- a/src/gui/widgets/qmenubar_p.h +++ b/src/gui/widgets/qmenubar_p.h @@ -257,6 +257,7 @@ public: } return 0; } + void InsertNativeMenuItems(const QList &actions); } *symbian_menubar; bool symbianCommands(int command); diff --git a/src/gui/widgets/qsoftkeyaction.h b/src/gui/widgets/qsoftkeyaction.h index 4ce5c5b..43c4ea7 100644 --- a/src/gui/widgets/qsoftkeyaction.h +++ b/src/gui/widgets/qsoftkeyaction.h @@ -56,7 +56,7 @@ class Q_GUI_EXPORT QSoftKeyAction : public QAction { public: enum StandardRole { - Options, + Options=0, Select, Back, Next, -- cgit v0.12 From 620cfd6a8d4fc84f5626b7eac3b70882620d5ef1 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Mon, 18 May 2009 10:52:50 +0200 Subject: Refactored test code and added test case for context sensitive menu --- src/gui/softkeys/main.cpp | 69 ++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/src/gui/softkeys/main.cpp b/src/gui/softkeys/main.cpp index e69156a..b0d5ae1 100644 --- a/src/gui/softkeys/main.cpp +++ b/src/gui/softkeys/main.cpp @@ -16,59 +16,72 @@ class MainWindow : public QMainWindow Q_OBJECT public: MainWindow(QWidget *parent = 0); - ~MainWindow() {} + ~MainWindow(); + QAction* context1; + QAction* context2; + QAction* context3; + QSoftKeyAction *action1; + QSoftKeyAction *action2; + QSoftKeyAction *action3; + QSoftKeyAction *action4; + QSoftKeyAction *action5; }; MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent) + : QMainWindow(parent), + context1(0), context2(0), context3(0), + action1(0),action2(0),action3(0),action4(0),action5(0) + { - QWidget *central = new QWidget(this); central->setLayout(new QVBoxLayout); central->layout()->addWidget(new QPushButton); central->layout()->addWidget(new QPushButton); central->layout()->addWidget(new QPushButton); - + context1 = new QAction(QString("Context1"), central); + context2 = new QAction(QString("Context2"), central); + context3 = new QAction(QString("Context3"), context2); + central->addAction(context1); + central->addAction(context2); QMenuBar* menuBar = new QMenuBar(this); menuBar->addAction("MyMenuItem1"); this->setMenuBar(menuBar); - QSoftKeyAction action1(central); - action1.setText(QString("Ok")); - action1.setRole(QSoftKeyAction::Ok); - QSoftKeyAction action2(central); - action2.setText(QString("Back")); - action2.setRole(QSoftKeyAction::Back); - QSoftKeyAction action3(central); - action3.setText(QString("Cancel")); - action3.setRole(QSoftKeyAction::Cancel); - QSoftKeyAction action4(central); - action4.setText(QString("Menu")); - action4.setRole(QSoftKeyAction::Menu); - - QSoftKeyAction action5(central); - action5.setText(QString("ContextMenu")); - action5.setRole(QSoftKeyAction::ContextMenu); - + action1 = new QSoftKeyAction(QSoftKeyAction::Ok, QString("Ok"), central); + action2 = new QSoftKeyAction(QSoftKeyAction::Back, QString("Back"), central); + action3 = new QSoftKeyAction(QSoftKeyAction::Cancel, QString("Cancel"), central); + action4 = new QSoftKeyAction(QSoftKeyAction::Menu, QString("Menu"), central); + action5 = new QSoftKeyAction(QSoftKeyAction::ContextMenu,QString("ContextMenu"), central); + QList myActionList; - myActionList.append(&action1); - myActionList.append(&action2); - myActionList.append(&action3); + myActionList.append(action1); + myActionList.append(action2); + myActionList.append(action3); softKeyStack()->push(myActionList); softKeyStack()->pop(); - softKeyStack()->push(&action1); + softKeyStack()->push(action1); softKeyStack()->pop(); QList myActionList2; - myActionList2.append(&action4); - myActionList2.append(&action1); - myActionList2.append(&action5); + myActionList2.append(action4); + myActionList2.append(action5); softKeyStack()->push(myActionList2); setCentralWidget(central); } +MainWindow::~MainWindow() +{ + delete context1; + delete context2; + delete context3; + delete action1; + delete action2; + delete action3; + delete action4; + delete action5; +} int main(int argc, char *argv[]) { -- cgit v0.12 From 1e2b8d3d63c05bc81f2024959480235489a479a7 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Mon, 18 May 2009 11:00:52 +0200 Subject: Added test case for submenus inside context sensitive menu --- src/gui/softkeys/main.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/gui/softkeys/main.cpp b/src/gui/softkeys/main.cpp index b0d5ae1..e89c737 100644 --- a/src/gui/softkeys/main.cpp +++ b/src/gui/softkeys/main.cpp @@ -17,6 +17,7 @@ class MainWindow : public QMainWindow public: MainWindow(QWidget *parent = 0); ~MainWindow(); + QMenu *contextMenu; QAction* context1; QAction* context2; QAction* context3; @@ -29,24 +30,30 @@ public: MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), + contextMenu(0), context1(0), context2(0), context3(0), action1(0),action2(0),action3(0),action4(0),action5(0) { QWidget *central = new QWidget(this); + contextMenu = new QMenu(); + central->setLayout(new QVBoxLayout); central->layout()->addWidget(new QPushButton); central->layout()->addWidget(new QPushButton); central->layout()->addWidget(new QPushButton); context1 = new QAction(QString("Context1"), central); context2 = new QAction(QString("Context2"), central); - context3 = new QAction(QString("Context3"), context2); + + context3 = new QAction(QString("Context3"), contextMenu); central->addAction(context1); central->addAction(context2); QMenuBar* menuBar = new QMenuBar(this); menuBar->addAction("MyMenuItem1"); this->setMenuBar(menuBar); - + context2->setMenu(contextMenu); + contextMenu->addAction(context3); + action1 = new QSoftKeyAction(QSoftKeyAction::Ok, QString("Ok"), central); action2 = new QSoftKeyAction(QSoftKeyAction::Back, QString("Back"), central); action3 = new QSoftKeyAction(QSoftKeyAction::Cancel, QString("Cancel"), central); @@ -81,6 +88,7 @@ MainWindow::~MainWindow() delete action3; delete action4; delete action5; + delete contextMenu; } int main(int argc, char *argv[]) -- cgit v0.12 From bfe64f383c418b37a71ad2b395dc207d47916a90 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Mon, 18 May 2009 13:53:59 +0200 Subject: Fixed SOFTKEYEND definition to be of right value --- src/gui/widgets/qsoftkeystack_p.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/widgets/qsoftkeystack_p.h b/src/gui/widgets/qsoftkeystack_p.h index 06e9253..a8ab2d5 100644 --- a/src/gui/widgets/qsoftkeystack_p.h +++ b/src/gui/widgets/qsoftkeystack_p.h @@ -64,7 +64,7 @@ QT_BEGIN_NAMESPACE // The following 2 defines may only be needed for s60. To be seen. #define SOFTKEYSTART 5000 -#define SOFTKEYEND (5000 + Qt::Key_Context4) +#define SOFTKEYEND (5000 + Qt::Key_Context4-Qt::Key_Context1) #define QSoftkeySet QList -- cgit v0.12 From 906c9646b448aeaaeba89bf66e9fc4ce2bb305c9 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Mon, 18 May 2009 13:54:32 +0200 Subject: Catch actions coming from context sensitive menu items --- src/gui/softkeys/main.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/gui/softkeys/main.cpp b/src/gui/softkeys/main.cpp index e89c737..6adbb2d 100644 --- a/src/gui/softkeys/main.cpp +++ b/src/gui/softkeys/main.cpp @@ -15,6 +15,12 @@ class MainWindow : public QMainWindow { Q_OBJECT public: + +private slots: + void context1Slot(); + void context3Slot(); +public: + MainWindow(QWidget *parent = 0); ~MainWindow(); QMenu *contextMenu; @@ -54,6 +60,8 @@ MainWindow::MainWindow(QWidget *parent) context2->setMenu(contextMenu); contextMenu->addAction(context3); + connect(context1, SIGNAL(triggered()), this, SLOT(context1Slot())); + connect(context3, SIGNAL(triggered()), this, SLOT(context3Slot())); action1 = new QSoftKeyAction(QSoftKeyAction::Ok, QString("Ok"), central); action2 = new QSoftKeyAction(QSoftKeyAction::Back, QString("Back"), central); action3 = new QSoftKeyAction(QSoftKeyAction::Cancel, QString("Cancel"), central); @@ -91,6 +99,13 @@ MainWindow::~MainWindow() delete contextMenu; } +void MainWindow::context1Slot() + { + } +void MainWindow::context3Slot() + { + } + int main(int argc, char *argv[]) { QApplication app(argc, argv); -- cgit v0.12 From e4010084c0dcf05f417e5aca6c8c0ad1767599ca Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Mon, 18 May 2009 14:20:45 +0200 Subject: Implemented handling keypresses coming from software keys --- src/gui/widgets/qsoftkeystack.cpp | 6 ++++++ src/gui/widgets/qsoftkeystack_p.h | 1 + src/gui/widgets/qsoftkeystack_s60.cpp | 15 +++++++++++---- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index fc6e107..14daecd 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -137,3 +137,9 @@ void QSoftKeyStack::handleFocusChanged(QWidget *old, QWidget *now) QList actions = now->actions(); // Do something with these actions. } + +void QSoftKeyStack::handleSoftKeyPress(int command) +{ + Q_D(QSoftKeyStack); + d->handleSoftKeyPress(command); +} diff --git a/src/gui/widgets/qsoftkeystack_p.h b/src/gui/widgets/qsoftkeystack_p.h index a8ab2d5..2469648 100644 --- a/src/gui/widgets/qsoftkeystack_p.h +++ b/src/gui/widgets/qsoftkeystack_p.h @@ -78,6 +78,7 @@ public: void push(const QList &softKeys); void pop(); const QSoftkeySet& top(); + void handleSoftKeyPress(int command); private: void mapSoftKeys(const QSoftkeySet &top); diff --git a/src/gui/widgets/qsoftkeystack_s60.cpp b/src/gui/widgets/qsoftkeystack_s60.cpp index 9e90fdf..a6b885e 100644 --- a/src/gui/widgets/qsoftkeystack_s60.cpp +++ b/src/gui/widgets/qsoftkeystack_s60.cpp @@ -90,15 +90,22 @@ void QSoftKeyStackPrivate::setNativeSoftKeys() if (softKeyAction->role() == QSoftKeyAction::Menu) { nativeContainer->SetCommandL(softKeyAction->nativePosition(), EAknSoftkeyOptions, *text); } else { - nativeContainer->SetCommandL(softKeyAction->nativePosition(), SOFTKEYSTART + softKeyAction->qtContextKey(), *text); + nativeContainer->SetCommandL(softKeyAction->nativePosition(), SOFTKEYSTART + softKeyAction->qtContextKey()-Qt::Key_Context1, *text); } CleanupStack::PopAndDestroy(); } } } -void QSoftKeyStack::handleSoftKeyPress(int command) +void QSoftKeyStackPrivate::handleSoftKeyPress(int command) { - // Do the magic, here. - // Map the command back to actual softkey on the top of the stack and handle it + const QSoftkeySet top = softKeyStack.top(); + int index = command-SOFTKEYSTART; + if( index<0 || index>=top.count()){ + // ### FIX THIS, add proper error handling, now fail quietly + return; + } + + top.at(index)->activate(QAction::Trigger); } + -- cgit v0.12 From 3d49f6854f35f19866c4076d551228aa63f38e3d Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Mon, 18 May 2009 14:21:44 +0200 Subject: Added slot that is triggered when back softkey is pressed --- src/gui/softkeys/main.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/gui/softkeys/main.cpp b/src/gui/softkeys/main.cpp index 6adbb2d..a92e2c2 100644 --- a/src/gui/softkeys/main.cpp +++ b/src/gui/softkeys/main.cpp @@ -19,6 +19,7 @@ public: private slots: void context1Slot(); void context3Slot(); + void softKeySlot(); public: MainWindow(QWidget *parent = 0); @@ -68,7 +69,8 @@ MainWindow::MainWindow(QWidget *parent) action4 = new QSoftKeyAction(QSoftKeyAction::Menu, QString("Menu"), central); action5 = new QSoftKeyAction(QSoftKeyAction::ContextMenu,QString("ContextMenu"), central); - + connect(action2, SIGNAL(triggered()), this, SLOT(softKeySlot())); + QList myActionList; myActionList.append(action1); myActionList.append(action2); @@ -80,6 +82,7 @@ MainWindow::MainWindow(QWidget *parent) QList myActionList2; myActionList2.append(action4); + myActionList2.append(action2); myActionList2.append(action5); softKeyStack()->push(myActionList2); @@ -106,6 +109,11 @@ void MainWindow::context3Slot() { } +void MainWindow::softKeySlot() +{ + +} + int main(int argc, char *argv[]) { QApplication app(argc, argv); -- cgit v0.12 From b64e097303707161d0db663db06fdf239d40d4a2 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Tue, 19 May 2009 12:39:49 +0200 Subject: added Q_OBJECT macro --- src/gui/widgets/qsoftkeyaction.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gui/widgets/qsoftkeyaction.h b/src/gui/widgets/qsoftkeyaction.h index 43c4ea7..77aeac0 100644 --- a/src/gui/widgets/qsoftkeyaction.h +++ b/src/gui/widgets/qsoftkeyaction.h @@ -54,6 +54,7 @@ class QSoftKeyActionPrivate; class Q_GUI_EXPORT QSoftKeyAction : public QAction { + Q_OBJECT public: enum StandardRole { Options=0, -- cgit v0.12 From ad475e3b8935b1314382e2d2c6a7d09ace98b550 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Tue, 19 May 2009 14:44:47 +0200 Subject: First hacky approach to context menus. This was commited so stuff relied on context menus can be implemented concurrently while making the internals of context menu implementation cleaner. --- src/gui/widgets/qmenu_symbian.cpp | 30 +++++++++++++++++++++++------- src/gui/widgets/qsoftkeystack.cpp | 19 +++++++++++++++++++ 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/gui/widgets/qmenu_symbian.cpp b/src/gui/widgets/qmenu_symbian.cpp index b9633b5..1cff1bf 100644 --- a/src/gui/widgets/qmenu_symbian.cpp +++ b/src/gui/widgets/qmenu_symbian.cpp @@ -49,6 +49,9 @@ static QList symbianMenus; static QList nativeMenuBars; static uint qt_symbian_menu_static_cmd_id = QT_FIRST_MENU_ITEM; static QWidget* widgetWithContextMenu=0; +static QList contextMenuActionList; +static QAction contextAction(0); +static int contexMenuCommand=0; bool menuExists() { @@ -177,6 +180,7 @@ void deleteAll(QList *items) static void rebuildMenu() { + widgetWithContextMenu = 0; QMenuBarPrivate *mb = 0; QWidget *w = qApp->activeWindow(); QMainWindow *mainWindow = qobject_cast(w); @@ -185,8 +189,7 @@ static void rebuildMenu() int index=0; bool found=false; - while( indexrole(); if(softAction->role() == QSoftKeyAction::ContextMenu) { @@ -195,8 +198,8 @@ static void rebuildMenu() } index++; } - if (w) - { + + if (w) { mb = menubars()->value(w); qt_symbian_menu_static_cmd_id = QT_FIRST_MENU_ITEM; deleteAll( &symbianMenus ); @@ -204,7 +207,6 @@ static void rebuildMenu() return; mb->symbian_menubar->rebuild(); } - widgetWithContextMenu = 0; } Q_GUI_EXPORT void qt_symbian_show_toplevel( CEikMenuPane* menuPane) @@ -233,6 +235,11 @@ void QMenu::symbianCommands(int command) void QMenuBar::symbianCommands(int command) { + if (command == contexMenuCommand) { + QContextMenuEvent* event = new QContextMenuEvent(QContextMenuEvent::Keyboard, QPoint(0,0)); + QCoreApplication::postEvent(widgetWithContextMenu, event); + } + int size = nativeMenuBars.size(); for (int i = 0; i < nativeMenuBars.size(); ++i) { bool result = nativeMenuBars.at(i)->d_func()->symbianCommands(command); @@ -388,16 +395,25 @@ void QMenuBarPrivate::QSymbianMenuBarPrivate::InsertNativeMenuItems(const QList< } } + + void QMenuBarPrivate::QSymbianMenuBarPrivate::rebuild() { + contexMenuCommand = 0; qt_symbian_menu_static_cmd_id = QT_FIRST_MENU_ITEM; deleteAll( &symbianMenus ); if (d) InsertNativeMenuItems(d->actions); - if (widgetWithContextMenu) - InsertNativeMenuItems(widgetWithContextMenu->actions()); + contextMenuActionList.clear(); + if (widgetWithContextMenu) { + contexMenuCommand = qt_symbian_menu_static_cmd_id; + contextAction.setText(QString("Actions")); + contextMenuActionList.append(&contextAction); + InsertNativeMenuItems(contextMenuActionList); } + +} QT_END_NAMESPACE #endif //QT_NO_MENUBAR diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index 14daecd..f702530 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -118,6 +118,24 @@ void QSoftKeyStack::handleFocusChanged(QWidget *old, QWidget *now) { if (!now) return; + QWidget *w = qApp->activeWindow(); + QMainWindow *mainWindow = qobject_cast(w); + QSoftKeyStack* softKeyStack = mainWindow->softKeyStack(); + if (old) + softKeyStack->pop(); + + Qt::ContextMenuPolicy policy = now->contextMenuPolicy(); + if (policy != Qt::NoContextMenu && policy != Qt::PreventContextMenu ) { + QList actionList; + QSoftKeyAction* menu = new QSoftKeyAction(QSoftKeyAction::Menu, QString("Menu"), now); + QSoftKeyAction* contextMenu = new QSoftKeyAction(QSoftKeyAction::ContextMenu, QString("ContextMenu"), now); + actionList.append(menu); + actionList.append(contextMenu); + softKeyStack->push(actionList); + } + +/* if (!now) + return; bool nowInOurMainWindow = false; const QMainWindow *ourMainWindow = qobject_cast(parent()); Q_ASSERT(ourMainWindow); @@ -136,6 +154,7 @@ void QSoftKeyStack::handleFocusChanged(QWidget *old, QWidget *now) QList actions = now->actions(); // Do something with these actions. +*/ } void QSoftKeyStack::handleSoftKeyPress(int command) -- cgit v0.12 From d2a9a4c38df32aed0bbcc21c0f971e1cf799226a Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Tue, 19 May 2009 14:45:55 +0200 Subject: Changed stylesheets example to create softkeystack. This commit should probably be reverted before merging to master --- examples/widgets/stylesheet/mainwindow.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/widgets/stylesheet/mainwindow.cpp b/examples/widgets/stylesheet/mainwindow.cpp index a1307a8..a0a38ad 100644 --- a/examples/widgets/stylesheet/mainwindow.cpp +++ b/examples/widgets/stylesheet/mainwindow.cpp @@ -46,6 +46,9 @@ MainWindow::MainWindow() { + QSoftKeyStack* stack = new QSoftKeyStack(this); + setSoftKeyStack(stack); + ui.setupUi(this); ui.nameLabel->setProperty("class", "mandatory QLabel"); -- cgit v0.12 From 3cfd4e97aa8f5e8c7b9eda9d7847b3f236d3efb5 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Tue, 19 May 2009 15:03:41 +0200 Subject: experiment with QMainWindow --- src/gui/widgets/qsoftkeystack.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index f702530..cd17171 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -120,6 +120,8 @@ void QSoftKeyStack::handleFocusChanged(QWidget *old, QWidget *now) return; QWidget *w = qApp->activeWindow(); QMainWindow *mainWindow = qobject_cast(w); + if( !mainWindow) + return; QSoftKeyStack* softKeyStack = mainWindow->softKeyStack(); if (old) softKeyStack->pop(); -- cgit v0.12 From eb4c00a469f473a33103652ed977eabb4fb9ce9b Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Tue, 19 May 2009 19:13:39 +0200 Subject: Testing 'dictionary' if it contains a value before using operator[]. T & QMap::operator[]: "If the map contains no item with key key, the function inserts a default-constructed value into the map with key key, and returns a reference to it" How many occurences of 'dictionary["foo"].startsWith("bar")' has that file by the way? --- tools/configure/configureapp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/configure/configureapp.cpp b/tools/configure/configureapp.cpp index 2c20d51..a879e5d 100644 --- a/tools/configure/configureapp.cpp +++ b/tools/configure/configureapp.cpp @@ -1886,14 +1886,14 @@ bool Configure::checkAvailability(const QString &part) else if (part == "SQL_DB2") available = findFile("sqlcli.h") && findFile("sqlcli1.h") && findFile("db2cli.lib"); else if (part == "SQL_SQLITE") - if (dictionary["XQMAKESPEC"].startsWith("symbian")) + if (dictionary.contains("XQMAKESPEC") && dictionary["XQMAKESPEC"].startsWith("symbian")) available = false; // In Symbian we only support system sqlite option else available = true; // Built in, we have a fork else if (part == "SQL_SQLITE_LIB") { if (dictionary[ "SQL_SQLITE_LIB" ] == "system") { // Symbian has multiple .lib/.dll files we need to find - if (dictionary["XQMAKESPEC"].startsWith("symbian")) { + if (dictionary.contains("XQMAKESPEC") && dictionary["XQMAKESPEC"].startsWith("symbian")) { available = true; // There is sqlite_symbian plugin which exports the necessary stuff dictionary[ "QT_LFLAGS_SQLITE" ] += "-lsqlite3"; } else { -- cgit v0.12 From 38c0b9100b5636e7f92185159cac5a5addbe4264 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Tue, 19 May 2009 19:14:55 +0200 Subject: Fresh build with commit eb4c00a469f473a33103652ed977eabb4fb9ce9b (MSVC 2008, No MS runtimes, UPXed) --- configure.exe | Bin 856064 -> 535040 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/configure.exe b/configure.exe index 5710503..30383d8 100755 Binary files a/configure.exe and b/configure.exe differ -- cgit v0.12 From 26e6d20ef0abee7b2d721637d6eaea67e932b907 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Tue, 19 May 2009 19:58:57 +0200 Subject: Stub for backgroundTexture() --- src/gui/styles/qs60style_simulated.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/gui/styles/qs60style_simulated.cpp b/src/gui/styles/qs60style_simulated.cpp index 17c1ebe..5a88f9a 100644 --- a/src/gui/styles/qs60style_simulated.cpp +++ b/src/gui/styles/qs60style_simulated.cpp @@ -191,6 +191,25 @@ QVariant QS60StylePrivate::styleProperty_specific(const char *name) const return styleProperty(name); } +QPixmap QS60StylePrivate::backgroundTexture() +{ + static QPixmap result; + // Poor mans caching. + Making sure that there is always only one background image in memory at a time + +/* + TODO: 1) Hold the background QPixmap as pointer in a static class member. + Also add a deleteBackground() function and call that in ~QS60StylePrivate() + 2) Don't cache the background at all as soon as we have native pixmap support +*/ + + if (!m_backgroundValid) { + result = QPixmap(); + result = part(QS60StyleEnums::SP_QsnBgScreen, QApplication::activeWindow()->size()); + m_backgroundValid = true; + } + return result; +} + bool QS60StylePrivate::isTouchSupported() { #ifdef QT_KEYPAD_NAVIGATION -- cgit v0.12 From 1588c0fe43f2173e026d7b52bdea0cf85b18ea1d Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Tue, 19 May 2009 20:14:07 +0200 Subject: Softkeys also for non-S60. Currently only as stub. Will eventually go into a separate implementation file. --- src/gui/widgets/qsoftkeystack.cpp | 11 +++++++++++ src/gui/widgets/widgets.pri | 18 +++++++----------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index cd17171..32a2df9 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -164,3 +164,14 @@ void QSoftKeyStack::handleSoftKeyPress(int command) Q_D(QSoftKeyStack); d->handleSoftKeyPress(command); } + +#if !defined(Q_WS_S60) +void QSoftKeyStackPrivate::handleSoftKeyPress(int command) +{ + Q_UNUSED(command) +} + +void QSoftKeyStackPrivate::setNativeSoftKeys() +{ +} +#endif // !defined(Q_WS_S60) \ No newline at end of file diff --git a/src/gui/widgets/widgets.pri b/src/gui/widgets/widgets.pri index c9e68a1..0c0641a 100644 --- a/src/gui/widgets/widgets.pri +++ b/src/gui/widgets/widgets.pri @@ -78,8 +78,10 @@ HEADERS += \ widgets/qtoolbararealayout_p.h \ widgets/qplaintextedit.h \ widgets/qplaintextedit_p.h \ - widgets/qprintpreviewwidget.h - + widgets/qprintpreviewwidget.h \ + widgets/qsoftkeyaction.h \ + widgets/qsoftkeystack.h \ + widgets/qsoftkeystack_p.h SOURCES += \ widgets/qabstractbutton.cpp \ widgets/qabstractslider.cpp \ @@ -138,8 +140,9 @@ SOURCES += \ widgets/qwidgetanimator.cpp \ widgets/qtoolbararealayout.cpp \ widgets/qplaintextedit.cpp \ - widgets/qprintpreviewwidget.cpp - + widgets/qprintpreviewwidget.cpp \ + widgets/qsoftkeyaction.cpp \ + widgets/qsoftkeystack.cpp !embedded:mac { HEADERS += widgets/qmacnativewidget_mac.h \ @@ -162,14 +165,7 @@ wince*: { } symbian*: { - HEADERS += \ - widgets/qsoftkeyaction.h \ - widgets/qsoftkeystack.h \ - widgets/qsoftkeystack_p.h - SOURCES += \ widgets/qmenu_symbian.cpp \ - widgets/qsoftkeyaction.cpp \ - widgets/qsoftkeystack.cpp \ widgets/qsoftkeystack_s60.cpp } -- cgit v0.12 From ade1bdc75245bb233022b1cc0358b89df2180466 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Tue, 19 May 2009 20:14:58 +0200 Subject: Not using deprecated QString constructor --- src/gui/widgets/qsoftkeystack.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index 32a2df9..ae58e8d 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -129,8 +129,8 @@ void QSoftKeyStack::handleFocusChanged(QWidget *old, QWidget *now) Qt::ContextMenuPolicy policy = now->contextMenuPolicy(); if (policy != Qt::NoContextMenu && policy != Qt::PreventContextMenu ) { QList actionList; - QSoftKeyAction* menu = new QSoftKeyAction(QSoftKeyAction::Menu, QString("Menu"), now); - QSoftKeyAction* contextMenu = new QSoftKeyAction(QSoftKeyAction::ContextMenu, QString("ContextMenu"), now); + QSoftKeyAction* menu = new QSoftKeyAction(QSoftKeyAction::Menu, QString::fromLatin1("Menu"), now); + QSoftKeyAction* contextMenu = new QSoftKeyAction(QSoftKeyAction::ContextMenu, QString::fromLatin1("ContextMenu"), now); actionList.append(menu); actionList.append(contextMenu); softKeyStack->push(actionList); -- cgit v0.12 From ce7444677bdcdb14a167f9f87c4487d0d341c314 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Wed, 20 May 2009 16:32:08 +0200 Subject: Part cache key nitpick --- src/gui/styles/qs60style.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index 1e2a889..a1ede1d 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -186,7 +186,7 @@ QPixmap QS60StylePrivate::cachedPart(QS60StyleEnums::SkinParts part, { QPixmap result; const QString cacheKey = - QString::fromLatin1("S60Style: SkinParts=%1 QSize=%2|%3 SkinElementFlags=%4") + QString::fromLatin1("S60Style: SkinParts=%1 QSize=%2|%3 SkinPartFlags=%4") .arg((int)part).arg(size.width()).arg(size.height()).arg((int)flags); if (!QPixmapCache::find(cacheKey, result)) { result = QS60StylePrivate::part(part, size, flags); -- cgit v0.12 From 164d3de4329019d34b10a802be16ea35aaafc5da Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Wed, 20 May 2009 16:32:33 +0200 Subject: Fixes --- src/gui/styles/qs60style_simulated.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/gui/styles/qs60style_simulated.cpp b/src/gui/styles/qs60style_simulated.cpp index 5a88f9a..f10da2b 100644 --- a/src/gui/styles/qs60style_simulated.cpp +++ b/src/gui/styles/qs60style_simulated.cpp @@ -204,7 +204,8 @@ QPixmap QS60StylePrivate::backgroundTexture() if (!m_backgroundValid) { result = QPixmap(); - result = part(QS60StyleEnums::SP_QsnBgScreen, QApplication::activeWindow()->size()); + const QSize size = QApplication::activeWindow()?QApplication::activeWindow()->size():QSize(100, 100); + result = part(QS60StyleEnums::SP_QsnBgScreen, size); m_backgroundValid = true; } return result; @@ -285,8 +286,10 @@ QStringList QS60Style::colorListKeys() void QS60Style::setS60Theme(const QHash &parts, const QHash, QColor> &colors) { + Q_D(QS60Style); QS60StyleModeSpecifics::m_partPictures = parts; QS60StyleModeSpecifics::m_colors = colors; + d->clearCaches(); } QT_END_NAMESPACE -- cgit v0.12 From e7f7d1f20ed691a274dcf07801baa17f7a8aabf9 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Fri, 22 May 2009 13:18:59 +0200 Subject: Added helper softKeyStackOfWidget. It returns the stack of the MainWindow of a widget (which might want to push its actions to the stack) --- src/gui/widgets/qsoftkeystack.cpp | 16 ++++++++++++++++ src/gui/widgets/qsoftkeystack.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index ae58e8d..723b9bf 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -165,6 +165,22 @@ void QSoftKeyStack::handleSoftKeyPress(int command) d->handleSoftKeyPress(command); } +QMainWindow *QSoftKeyStack::mainWindowOfWidget(QWidget *widget) +{ + QWidget *widgetParent = widget; + while (widgetParent = widgetParent->parentWidget()) + if (QMainWindow *mainWindow = qobject_cast(widgetParent)) + return mainWindow; + + return 0; +} + +QSoftKeyStack *QSoftKeyStack::softKeyStackOfWidget(QWidget *widget) +{ + QMainWindow *mainWindow = mainWindowOfWidget(widget); + return mainWindow ? mainWindow->softKeyStack() : 0; +} + #if !defined(Q_WS_S60) void QSoftKeyStackPrivate::handleSoftKeyPress(int command) { diff --git a/src/gui/widgets/qsoftkeystack.h b/src/gui/widgets/qsoftkeystack.h index c9a05c3..7c955da 100644 --- a/src/gui/widgets/qsoftkeystack.h +++ b/src/gui/widgets/qsoftkeystack.h @@ -69,6 +69,9 @@ public: void handleSoftKeyPress(int command); + static QMainWindow *mainWindowOfWidget(QWidget *widget); + static QSoftKeyStack *softKeyStackOfWidget(QWidget *widget); + private Q_SLOTS: void handleFocusChanged(QWidget *old, QWidget *now); -- cgit v0.12 From b52451f6074446ec77f3bca712cdaeae46a50066 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Fri, 22 May 2009 13:44:56 +0200 Subject: compile --- src/gui/widgets/qsoftkeystack.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gui/widgets/qsoftkeystack.h b/src/gui/widgets/qsoftkeystack.h index 7c955da..2a63ab8 100644 --- a/src/gui/widgets/qsoftkeystack.h +++ b/src/gui/widgets/qsoftkeystack.h @@ -54,6 +54,7 @@ QT_MODULE(Gui) class QSoftKeyStackPrivate; class QSoftKeyAction; +class QMainWindow; class Q_GUI_EXPORT QSoftKeyStack : public QObject { -- cgit v0.12 From b23dc7fb8bc8de6617684249411b5399f1d06631 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Fri, 22 May 2009 13:45:49 +0200 Subject: Cleanup. --- src/gui/widgets/qsoftkeystack.cpp | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index 723b9bf..05fe397 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -134,29 +134,7 @@ void QSoftKeyStack::handleFocusChanged(QWidget *old, QWidget *now) actionList.append(menu); actionList.append(contextMenu); softKeyStack->push(actionList); - } - -/* if (!now) - return; - bool nowInOurMainWindow = false; - const QMainWindow *ourMainWindow = qobject_cast(parent()); - Q_ASSERT(ourMainWindow); - - // "ourMainWindow" in parent chain of "now"? Isn't there a helper in Qt for this? - QWidget *nowParent = now; - while (nowParent = nowParent->parentWidget()) { - if (nowParent == ourMainWindow) { - nowInOurMainWindow = true; - break; - } } - - if (!nowInOurMainWindow) - return; - - QList actions = now->actions(); - // Do something with these actions. -*/ } void QSoftKeyStack::handleSoftKeyPress(int command) @@ -190,4 +168,4 @@ void QSoftKeyStackPrivate::handleSoftKeyPress(int command) void QSoftKeyStackPrivate::setNativeSoftKeys() { } -#endif // !defined(Q_WS_S60) \ No newline at end of file +#endif // !defined(Q_WS_S60) -- cgit v0.12 From a4fd37805642f092942b7a761cd50991cc6d7d34 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Mon, 25 May 2009 18:14:39 +0200 Subject: Providing a translated default text for standard roles. --- src/gui/widgets/qsoftkeyaction.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/gui/widgets/qsoftkeyaction.cpp b/src/gui/widgets/qsoftkeyaction.cpp index 583cf65..302850c 100644 --- a/src/gui/widgets/qsoftkeyaction.cpp +++ b/src/gui/widgets/qsoftkeyaction.cpp @@ -55,12 +55,40 @@ public: this->role = role; } + static QString roleText(QSoftKeyAction::StandardRole role); + QSoftKeyAction::StandardRole role; QString roleName; int nativePosition; int qtContextKey; }; +QString QSoftKeyActionPrivate::roleText(QSoftKeyAction::StandardRole role) +{ + switch (role) { + case QSoftKeyAction::Options: + return QSoftKeyAction::tr("Options"); + case QSoftKeyAction::Select: + return QSoftKeyAction::tr("Select"); + case QSoftKeyAction::Back: + return QSoftKeyAction::tr("Back"); + case QSoftKeyAction::Next: + return QSoftKeyAction::tr("Next"); + case QSoftKeyAction::Previous: + return QSoftKeyAction::tr("Previous"); + case QSoftKeyAction::Ok: + return QSoftKeyAction::tr("Ok"); + case QSoftKeyAction::Cancel: + return QSoftKeyAction::tr("Cancel"); + case QSoftKeyAction::Edit: + return QSoftKeyAction::tr("Edit"); + case QSoftKeyAction::View: + return QSoftKeyAction::tr("View"); + default: + return QString(); + }; +} + /*! \enum QSoftKeyAction::StandardRole This enum defines the standard role for a QSoftKeyAction. @@ -92,6 +120,7 @@ QSoftKeyAction::QSoftKeyAction(StandardRole role, QObject *parent) { Q_D(QSoftKeyAction); d->role = role; + setText(QSoftKeyActionPrivate::roleText(role)); } QSoftKeyAction::QSoftKeyAction(const QString &text, QObject* parent) -- cgit v0.12 From 62743959699d78a63057e98b43fe3c79ace87234 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Tue, 26 May 2009 14:32:50 +0200 Subject: Implemented popandPush method. This is needed to optimize popping and pushing. This avoid unnecessary screen redraw and setting of native softkeys. One such case occurs when focused widge changes. --- src/gui/widgets/qsoftkeystack.cpp | 54 ++++++++++++++++++++++++++++++++++++--- src/gui/widgets/qsoftkeystack.h | 2 ++ src/gui/widgets/qsoftkeystack_p.h | 2 ++ 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index 05fe397..a7fa3f1 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -44,6 +44,22 @@ #include "qapplication.h" #include "qmainwindow.h" +static bool isSame(const QSoftkeySet& a, const QSoftkeySet& b) +{ + bool isSame=true; + if ( a.count() != b.count()) + return false; + int index=0; + while (indexrole() != b.at(index)->role()) + return false; + if (a.at(index)->text().compare(b.at(index)->text())!=0) + return false; + index++; + } + return true; +} + QSoftKeyStackPrivate::QSoftKeyStackPrivate() { @@ -75,6 +91,25 @@ void QSoftKeyStackPrivate::pop() setNativeSoftKeys(); } +void QSoftKeyStackPrivate::popandPush(QSoftKeyAction *softKey) +{ + QSoftkeySet oldSoftKeySet = softKeyStack.pop(); + QSoftkeySet newSoftKeySet; + newSoftKeySet.append(newSoftKeySet); + softKeyStack.push(newSoftKeySet); + if( !isSame(oldSoftKeySet, newSoftKeySet)) + setNativeSoftKeys(); +} + +void QSoftKeyStackPrivate::popandPush(const QList &softkeys) +{ + QSoftkeySet oldSoftKeySet = softKeyStack.pop(); + QSoftkeySet newSoftKeySet(softkeys); + softKeyStack.push(newSoftKeySet); + if( !isSame(oldSoftKeySet, newSoftKeySet)) + setNativeSoftKeys(); +} + const QSoftkeySet& QSoftKeyStackPrivate::top() { return softKeyStack.top(); @@ -108,6 +143,18 @@ void QSoftKeyStack::pop() d->pop(); } +void QSoftKeyStack::popandPush(QSoftKeyAction *softKey) +{ + Q_D(QSoftKeyStack); + d->popandPush(softKey); +} + +void QSoftKeyStack::popandPush(const QList &softkeys) +{ + Q_D(QSoftKeyStack); + d->popandPush(softkeys); +} + const QSoftkeySet& QSoftKeyStack::top() { Q_D(QSoftKeyStack); @@ -123,8 +170,6 @@ void QSoftKeyStack::handleFocusChanged(QWidget *old, QWidget *now) if( !mainWindow) return; QSoftKeyStack* softKeyStack = mainWindow->softKeyStack(); - if (old) - softKeyStack->pop(); Qt::ContextMenuPolicy policy = now->contextMenuPolicy(); if (policy != Qt::NoContextMenu && policy != Qt::PreventContextMenu ) { @@ -133,7 +178,10 @@ void QSoftKeyStack::handleFocusChanged(QWidget *old, QWidget *now) QSoftKeyAction* contextMenu = new QSoftKeyAction(QSoftKeyAction::ContextMenu, QString::fromLatin1("ContextMenu"), now); actionList.append(menu); actionList.append(contextMenu); - softKeyStack->push(actionList); + if (old) + softKeyStack->popandPush(actionList); + else + softKeyStack->push(actionList); } } diff --git a/src/gui/widgets/qsoftkeystack.h b/src/gui/widgets/qsoftkeystack.h index 2a63ab8..10d9153 100644 --- a/src/gui/widgets/qsoftkeystack.h +++ b/src/gui/widgets/qsoftkeystack.h @@ -66,6 +66,8 @@ public: void push(QSoftKeyAction *softKey); void push(const QList &softkeys); void pop(); + void popandPush(QSoftKeyAction *softKey); + void popandPush(const QList &softkeys); const QSoftkeySet& top(); void handleSoftKeyPress(int command); diff --git a/src/gui/widgets/qsoftkeystack_p.h b/src/gui/widgets/qsoftkeystack_p.h index 2469648..57475bd 100644 --- a/src/gui/widgets/qsoftkeystack_p.h +++ b/src/gui/widgets/qsoftkeystack_p.h @@ -77,6 +77,8 @@ public: void push(QSoftKeyAction *softKey); void push(const QList &softKeys); void pop(); + void popandPush(QSoftKeyAction *softKey); + void popandPush(const QList &softkeys); const QSoftkeySet& top(); void handleSoftKeyPress(int command); -- cgit v0.12 From ba552dae4daab3db8596e20f8491393e4479e7b0 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Tue, 26 May 2009 14:40:36 +0200 Subject: Added method isEmpty() to interface. This can be used to query if stack actually has any items in it --- src/gui/widgets/qsoftkeystack.cpp | 11 +++++++++++ src/gui/widgets/qsoftkeystack.h | 1 + src/gui/widgets/qsoftkeystack_p.h | 1 + 3 files changed, 13 insertions(+) diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index a7fa3f1..0054c6b 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -115,6 +115,11 @@ const QSoftkeySet& QSoftKeyStackPrivate::top() return softKeyStack.top(); } +bool QSoftKeyStackPrivate::isEmpty() +{ + return softKeyStack.isEmpty(); +} + QSoftKeyStack::QSoftKeyStack(QWidget *parent) : QObject(*new QSoftKeyStackPrivate, parent) { @@ -161,6 +166,12 @@ const QSoftkeySet& QSoftKeyStack::top() return d->top(); } +bool QSoftKeyStack::isEmpty() +{ + Q_D(QSoftKeyStack); + return d->isEmpty(); +} + void QSoftKeyStack::handleFocusChanged(QWidget *old, QWidget *now) { if (!now) diff --git a/src/gui/widgets/qsoftkeystack.h b/src/gui/widgets/qsoftkeystack.h index 10d9153..2606bd1 100644 --- a/src/gui/widgets/qsoftkeystack.h +++ b/src/gui/widgets/qsoftkeystack.h @@ -69,6 +69,7 @@ public: void popandPush(QSoftKeyAction *softKey); void popandPush(const QList &softkeys); const QSoftkeySet& top(); + bool isEmpty(); void handleSoftKeyPress(int command); diff --git a/src/gui/widgets/qsoftkeystack_p.h b/src/gui/widgets/qsoftkeystack_p.h index 57475bd..b698178 100644 --- a/src/gui/widgets/qsoftkeystack_p.h +++ b/src/gui/widgets/qsoftkeystack_p.h @@ -80,6 +80,7 @@ public: void popandPush(QSoftKeyAction *softKey); void popandPush(const QList &softkeys); const QSoftkeySet& top(); + bool isEmpty(); void handleSoftKeyPress(int command); private: -- cgit v0.12 From a86927b9463d15893d45c11af912b70383c4ee2d Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Tue, 26 May 2009 14:41:14 +0200 Subject: Fixed crash when building menu while softkeystack is empty --- src/gui/widgets/qmenu_symbian.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/gui/widgets/qmenu_symbian.cpp b/src/gui/widgets/qmenu_symbian.cpp index 1cff1bf..491c78e 100644 --- a/src/gui/widgets/qmenu_symbian.cpp +++ b/src/gui/widgets/qmenu_symbian.cpp @@ -185,20 +185,21 @@ static void rebuildMenu() QWidget *w = qApp->activeWindow(); QMainWindow *mainWindow = qobject_cast(w); QSoftKeyStack* softKeyStack = mainWindow->softKeyStack(); - const QSoftkeySet& softKeyTop = softKeyStack->top(); - - int index=0; - bool found=false; - while( indexrole(); - if(softAction->role() == QSoftKeyAction::ContextMenu) { - widgetWithContextMenu = softAction->parentWidget(); - found=true; - } - index++; + if (!softKeyStack->isEmpty()) { + const QSoftkeySet& softKeyTop = softKeyStack->top(); + int index=0; + bool found=false; + while( indexrole(); + if(softAction->role() == QSoftKeyAction::ContextMenu) { + widgetWithContextMenu = softAction->parentWidget(); + found=true; + } + index++; + } } - + if (w) { mb = menubars()->value(w); qt_symbian_menu_static_cmd_id = QT_FIRST_MENU_ITEM; -- cgit v0.12 From 3cded6c4a90233e214447f769efc4a3524df6872 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Tue, 26 May 2009 16:08:12 +0200 Subject: Bugfix for mapping keys when there is only one softkey in the stack --- src/gui/widgets/qsoftkeystack_s60.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/widgets/qsoftkeystack_s60.cpp b/src/gui/widgets/qsoftkeystack_s60.cpp index a6b885e..e9ca13a 100644 --- a/src/gui/widgets/qsoftkeystack_s60.cpp +++ b/src/gui/widgets/qsoftkeystack_s60.cpp @@ -53,7 +53,7 @@ void QSoftKeyStackPrivate::mapSoftKeys(const QSoftkeySet &top) { if (top.count() == 1) { top.at(0)->setNativePosition(2); - top.at(0)->setQtContextKey(Qt::Key_Context2); + top.at(0)->setQtContextKey(Qt::Key_Context1); } else { // FIX THIS -- cgit v0.12 From 52071c71ddfde1354e6c17737660a3d161d0bc89 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Tue, 26 May 2009 20:59:55 +0200 Subject: Introducing QKeyEventSoftKey helper class. It maps softkeys to actual key events. Making it easy and non-intrusive to add softkey usage to existing widgets. --- src/gui/widgets/qsoftkeystack.cpp | 24 ++++++++++++++++++++++++ src/gui/widgets/qsoftkeystack_p.h | 14 ++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index 0054c6b..3591dc1 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -43,6 +43,7 @@ #include "qsoftkeystack_p.h" #include "qapplication.h" #include "qmainwindow.h" +#include "qevent.h" static bool isSame(const QSoftkeySet& a, const QSoftkeySet& b) { @@ -228,3 +229,26 @@ void QSoftKeyStackPrivate::setNativeSoftKeys() { } #endif // !defined(Q_WS_S60) + +QKeyEventSoftKey::QKeyEventSoftKey(QSoftKeyAction *softKeyAction, Qt::Key key, QObject *parent) + : QObject(parent) + , m_softKeyAction(softKeyAction) + , m_key(key) +{ +} + +void QKeyEventSoftKey::addSoftKey(QSoftKeyAction::StandardRole standardRole, Qt::Key key, QWidget *actionWidget) +{ + QSoftKeyStack *stack = QSoftKeyStack::softKeyStackOfWidget(actionWidget); + if (!stack) + return; + QSoftKeyAction *action = new QSoftKeyAction(standardRole, actionWidget); + QKeyEventSoftKey *softKey = new QKeyEventSoftKey(action, key, actionWidget); + connect(action, SIGNAL(triggered()), softKey, SLOT(sendKeyEvent())); + stack->push(action); +} + +void QKeyEventSoftKey::sendKeyEvent() +{ + QApplication::postEvent(parent(), new QKeyEvent(QEvent::KeyPress, m_key, Qt::NoModifier)); +} diff --git a/src/gui/widgets/qsoftkeystack_p.h b/src/gui/widgets/qsoftkeystack_p.h index b698178..e728cbb 100644 --- a/src/gui/widgets/qsoftkeystack_p.h +++ b/src/gui/widgets/qsoftkeystack_p.h @@ -70,6 +70,7 @@ QT_BEGIN_NAMESPACE class QSoftKeyStackPrivate : public QObjectPrivate { + Q_DECLARE_PUBLIC(QSoftKeyStack); public: QSoftKeyStackPrivate(); ~QSoftKeyStackPrivate(); @@ -91,6 +92,19 @@ private: QStack softKeyStack; }; +class QKeyEventSoftKey : QObject +{ + Q_OBJECT +public: + QKeyEventSoftKey(QSoftKeyAction *softKeyAction, Qt::Key key, QObject *parent); + static void addSoftKey(QSoftKeyAction::StandardRole standardRole, Qt::Key key, QWidget *actionWidget); +private: + QSoftKeyAction *m_softKeyAction; + Qt::Key m_key; +private Q_SLOTS: + void sendKeyEvent(); +}; + QT_END_NAMESPACE #endif // QSOFTKEYSTACK_P_H -- cgit v0.12 From f414d09532e6add26c70dc485743f414ee6bc118 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Tue, 26 May 2009 21:02:04 +0200 Subject: Platforms that do not yet have a softkey adaptation layer will show the softkeys in a toolbar inside the respective QMainWindow. This is a kind-of-usable stub and definitely useful for debugging. --- src/gui/widgets/qsoftkeystack.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index 3591dc1..ac58d2a 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -45,6 +45,10 @@ #include "qmainwindow.h" #include "qevent.h" +#if !defined(Q_WS_S60) +#include "qtoolbar.h" +#endif + static bool isSame(const QSoftkeySet& a, const QSoftkeySet& b) { bool isSame=true; @@ -225,8 +229,38 @@ void QSoftKeyStackPrivate::handleSoftKeyPress(int command) Q_UNUSED(command) } +QToolBar* softKeyToolBar(QMainWindow *mainWindow) +{ + Q_ASSERT(mainWindow); + const QString toolBarName = QString::fromLatin1("SoftKeyToolBarForDebugging"); + QToolBar *result = 0; + foreach (QObject *child, mainWindow->children()) { + result = qobject_cast(child); + if (result && result->objectName() == toolBarName) + return result; + } + result = mainWindow->addToolBar(toolBarName); + result->setObjectName(toolBarName); + return result; +} + void QSoftKeyStackPrivate::setNativeSoftKeys() { + Q_Q(QSoftKeyStack); + QMainWindow *parent = qobject_cast(q->parent()); + if (!parent) + return; + QToolBar* toolbar = softKeyToolBar(parent); + toolbar->clear(); + foreach (const QSoftkeySet &set, softKeyStack) { + foreach (QSoftKeyAction *skAction, set) + toolbar->addAction(skAction); + toolbar->addSeparator(); + } + if (toolbar->actions().isEmpty()) { + parent->removeToolBar(toolbar); + delete toolbar; + } } #endif // !defined(Q_WS_S60) -- cgit v0.12 From 6b35dbafe0c42f26335d94d5fae43bf13c6b3584 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Tue, 26 May 2009 21:03:31 +0200 Subject: KeyPadNavigation: showing a 'Back' softkey while in editfocus. --- src/gui/itemviews/qabstractitemview.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index 159a997..6e24c85 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -61,6 +61,9 @@ #ifndef QT_NO_ACCESSIBILITY #include #endif +#ifdef QT_KEYPAD_NAVIGATION +#include +#endif QT_BEGIN_NAMESPACE @@ -2003,16 +2006,19 @@ void QAbstractItemView::keyPressEvent(QKeyEvent *event) if (QApplication::keypadNavigationEnabled()) { if (!hasEditFocus()) { setEditFocus(true); + QKeyEventSoftKey::addSoftKey(QSoftKeyAction::Back, Qt::Key_Back, this); return; } } break; case Qt::Key_Back: - case Qt::Key_Context2: // TODO: aportale, remove KEYPAD_NAVIGATION_HACK when softkey support is there - if (QApplication::keypadNavigationEnabled() && hasEditFocus()) + if (QApplication::keypadNavigationEnabled() && hasEditFocus()) { + if (QSoftKeyStack *stack = QSoftKeyStack::softKeyStackOfWidget(this)) + stack->pop(); setEditFocus(false); - else + } else { event->ignore(); + } return; default: if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { -- cgit v0.12 From 9d5308b95bed09e72203eb53ced1a57c21744c71 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Wed, 27 May 2009 09:48:33 +0200 Subject: Added handling for a case when menu is being rebuilt and menu is not inside a QMainWindow. --- src/gui/widgets/qmenu_symbian.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/gui/widgets/qmenu_symbian.cpp b/src/gui/widgets/qmenu_symbian.cpp index 491c78e..1ed3505 100644 --- a/src/gui/widgets/qmenu_symbian.cpp +++ b/src/gui/widgets/qmenu_symbian.cpp @@ -184,19 +184,21 @@ static void rebuildMenu() QMenuBarPrivate *mb = 0; QWidget *w = qApp->activeWindow(); QMainWindow *mainWindow = qobject_cast(w); - QSoftKeyStack* softKeyStack = mainWindow->softKeyStack(); - if (!softKeyStack->isEmpty()) { - const QSoftkeySet& softKeyTop = softKeyStack->top(); - int index=0; - bool found=false; - while( indexrole(); - if(softAction->role() == QSoftKeyAction::ContextMenu) { - widgetWithContextMenu = softAction->parentWidget(); - found=true; - } - index++; + if (mainWindow) { + QSoftKeyStack* softKeyStack = mainWindow->softKeyStack(); + if (!softKeyStack->isEmpty()) { + const QSoftkeySet& softKeyTop = softKeyStack->top(); + int index=0; + bool found=false; + while( indexrole(); + if(softAction->role() == QSoftKeyAction::ContextMenu) { + widgetWithContextMenu = softAction->parentWidget(); + found=true; + } + index++; + } } } -- cgit v0.12 From 5e38702684529cf7c3d1ab8ac6cd14900ca20b89 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Wed, 27 May 2009 10:43:32 +0200 Subject: Added method bool hasSoftKeyStack() so that user can check if QMainWindow has a softkeystack or not. Making method QSoftKeyStack *softKeyStack() const return 0 when there is no softkeystack was also evaluated. Returning 0 was discarded as it would make softKeyStack() behave differently than statusBar() and menuBar() methods. It would be bad API design to have methods in same class behave differently. --- src/gui/widgets/qmainwindow.cpp | 15 ++++++++++++++- src/gui/widgets/qmainwindow.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/gui/widgets/qmainwindow.cpp b/src/gui/widgets/qmainwindow.cpp index e12b879..618023e 100644 --- a/src/gui/widgets/qmainwindow.cpp +++ b/src/gui/widgets/qmainwindow.cpp @@ -543,7 +543,7 @@ QSoftKeyStack *QMainWindow::softKeyStack() const } /*! - Sets the softkey stackfor the main window to \a softKeyStack. + Sets the softkey stack for the main window to \a softKeyStack. Note: QMainWindow takes ownership of the \a softKeyStack pointer and deletes it at the appropriate time. @@ -559,6 +559,19 @@ void QMainWindow::setSoftKeyStack(QSoftKeyStack *softKeyStack) } d->softKeyStack = softKeyStack; } + +/*! + Returns true if QMainWindow has a softkeystack and false otherwise + + \sa softKeyStack() +*/ +bool QMainWindow::hasSoftKeyStack() +{ + Q_D(QMainWindow); + if (d->softKeyStack ) + return true; + return false; +} #endif // QT_NO_SOFTKEYSTACK #ifndef QT_NO_STATUSBAR diff --git a/src/gui/widgets/qmainwindow.h b/src/gui/widgets/qmainwindow.h index e2dcd5e..01b275e 100644 --- a/src/gui/widgets/qmainwindow.h +++ b/src/gui/widgets/qmainwindow.h @@ -135,6 +135,7 @@ public: #ifndef QT_NO_SOFTKEYSTACK QSoftKeyStack *softKeyStack() const; void setSoftKeyStack(QSoftKeyStack *softKeyStack); + bool hasSoftKeyStack(); #endif #ifndef QT_NO_STATUSBAR -- cgit v0.12 From f7c182fa3d6526b05403b0374f29b30aed9995e0 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Wed, 27 May 2009 11:38:55 +0200 Subject: Changed menu adaptation to handle case where no softkeystack is instantiated better --- src/gui/widgets/qmenu_symbian.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/widgets/qmenu_symbian.cpp b/src/gui/widgets/qmenu_symbian.cpp index 1ed3505..1577977 100644 --- a/src/gui/widgets/qmenu_symbian.cpp +++ b/src/gui/widgets/qmenu_symbian.cpp @@ -184,7 +184,7 @@ static void rebuildMenu() QMenuBarPrivate *mb = 0; QWidget *w = qApp->activeWindow(); QMainWindow *mainWindow = qobject_cast(w); - if (mainWindow) { + if ((mainWindow) && mainWindow->hasSoftKeyStack()) { QSoftKeyStack* softKeyStack = mainWindow->softKeyStack(); if (!softKeyStack->isEmpty()) { const QSoftkeySet& softKeyTop = softKeyStack->top(); -- cgit v0.12 From 51d580aef7fce99a7c531fa35e50637ec8704a5d Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Wed, 27 May 2009 21:43:02 +0200 Subject: QSoftKeyStack::softKeyStackOfWidget only returns a stack if has one. No implicit creation happens. --- src/gui/widgets/qsoftkeystack.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index ac58d2a..50d7939 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -220,7 +220,7 @@ QMainWindow *QSoftKeyStack::mainWindowOfWidget(QWidget *widget) QSoftKeyStack *QSoftKeyStack::softKeyStackOfWidget(QWidget *widget) { QMainWindow *mainWindow = mainWindowOfWidget(widget); - return mainWindow ? mainWindow->softKeyStack() : 0; + return (mainWindow && mainWindow->hasSoftKeyStack()) ? mainWindow->softKeyStack() : 0; } #if !defined(Q_WS_S60) -- cgit v0.12 From 8c7098210e6dfa7886d6e33918899a211019b699 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Wed, 27 May 2009 22:47:19 +0200 Subject: Moved the soft key command relay acrobatics from QApplication to QSoftKeyStackPrivate. Removed QSoftKeyStack::handleSoftKeyPress and made QSoftKeyStackPrivate::handleSoftKeyPress static, so that it can be called from QApplication. --- src/gui/kernel/qapplication_s60.cpp | 12 +++--------- src/gui/widgets/qsoftkeystack.cpp | 6 ------ src/gui/widgets/qsoftkeystack.h | 2 -- src/gui/widgets/qsoftkeystack_p.h | 2 +- src/gui/widgets/qsoftkeystack_s60.cpp | 12 ++++++++++-- 5 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/gui/kernel/qapplication_s60.cpp b/src/gui/kernel/qapplication_s60.cpp index ad1c842..138ba8c 100644 --- a/src/gui/kernel/qapplication_s60.cpp +++ b/src/gui/kernel/qapplication_s60.cpp @@ -29,8 +29,6 @@ #include "private/qwindowsurface_s60_p.h" #include "qpaintengine.h" #include "qmenubar.h" -#include "qmainwindow.h" -#include "qsoftkeystack.h" #include "private/qsoftkeystack_p.h" #include "apgwgnam.h" // For CApaWindowGroupName @@ -1041,14 +1039,10 @@ void QApplication::s60HandleCommandL(int command) exit(); break; default: - if (command >= SOFTKEYSTART && command <= SOFTKEYEND) { - const QMainWindow *activeMainWindow = - qobject_cast(QApplication::activeWindow()); - if (activeMainWindow) - activeMainWindow->softKeyStack()->handleSoftKeyPress(command); - } else { + if (command >= SOFTKEYSTART && command <= SOFTKEYEND) + QSoftKeyStackPrivate::handleSoftKeyPress(command); + else QMenuBar::symbianCommands(command); - } break; } } diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index 50d7939..c68fe19 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -201,12 +201,6 @@ void QSoftKeyStack::handleFocusChanged(QWidget *old, QWidget *now) } } -void QSoftKeyStack::handleSoftKeyPress(int command) -{ - Q_D(QSoftKeyStack); - d->handleSoftKeyPress(command); -} - QMainWindow *QSoftKeyStack::mainWindowOfWidget(QWidget *widget) { QWidget *widgetParent = widget; diff --git a/src/gui/widgets/qsoftkeystack.h b/src/gui/widgets/qsoftkeystack.h index 2606bd1..423da66 100644 --- a/src/gui/widgets/qsoftkeystack.h +++ b/src/gui/widgets/qsoftkeystack.h @@ -71,8 +71,6 @@ public: const QSoftkeySet& top(); bool isEmpty(); - void handleSoftKeyPress(int command); - static QMainWindow *mainWindowOfWidget(QWidget *widget); static QSoftKeyStack *softKeyStackOfWidget(QWidget *widget); diff --git a/src/gui/widgets/qsoftkeystack_p.h b/src/gui/widgets/qsoftkeystack_p.h index e728cbb..75d7ad4 100644 --- a/src/gui/widgets/qsoftkeystack_p.h +++ b/src/gui/widgets/qsoftkeystack_p.h @@ -82,7 +82,7 @@ public: void popandPush(const QList &softkeys); const QSoftkeySet& top(); bool isEmpty(); - void handleSoftKeyPress(int command); + static void handleSoftKeyPress(int command); private: void mapSoftKeys(const QSoftkeySet &top); diff --git a/src/gui/widgets/qsoftkeystack_s60.cpp b/src/gui/widgets/qsoftkeystack_s60.cpp index e9ca13a..8dfd5dd 100644 --- a/src/gui/widgets/qsoftkeystack_s60.cpp +++ b/src/gui/widgets/qsoftkeystack_s60.cpp @@ -48,6 +48,8 @@ #include "private/qcore_symbian_p.h" #include "qsoftkeystack_p.h" +#include "qapplication.h" +#include "qmainwindow.h" void QSoftKeyStackPrivate::mapSoftKeys(const QSoftkeySet &top) { @@ -99,9 +101,15 @@ void QSoftKeyStackPrivate::setNativeSoftKeys() void QSoftKeyStackPrivate::handleSoftKeyPress(int command) { - const QSoftkeySet top = softKeyStack.top(); + const QMainWindow *activeMainWindow = + qobject_cast(QApplication::activeWindow()); + if (!activeMainWindow) + return; + QSoftKeyStackPrivate *d_ptr = activeMainWindow->softKeyStack()->d_func(); + + const QSoftkeySet top = d_ptr->softKeyStack.top(); int index = command-SOFTKEYSTART; - if( index<0 || index>=top.count()){ + if (index < 0 || index >= top.count()) { // ### FIX THIS, add proper error handling, now fail quietly return; } -- cgit v0.12 From 0bd369dd52561d4654697b09a89141e96305e837 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Fri, 29 May 2009 09:58:33 +0200 Subject: Implemented better way to detect when to add automagically a menu button to softkeys --- src/gui/widgets/qsoftkeystack.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index c68fe19..984922e 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -185,15 +185,20 @@ void QSoftKeyStack::handleFocusChanged(QWidget *old, QWidget *now) QMainWindow *mainWindow = qobject_cast(w); if( !mainWindow) return; + if (!mainWindow->hasSoftKeyStack()) + return; QSoftKeyStack* softKeyStack = mainWindow->softKeyStack(); - - Qt::ContextMenuPolicy policy = now->contextMenuPolicy(); - if (policy != Qt::NoContextMenu && policy != Qt::PreventContextMenu ) { + if( mainWindow->menuWidget() ) + { QList actionList; QSoftKeyAction* menu = new QSoftKeyAction(QSoftKeyAction::Menu, QString::fromLatin1("Menu"), now); - QSoftKeyAction* contextMenu = new QSoftKeyAction(QSoftKeyAction::ContextMenu, QString::fromLatin1("ContextMenu"), now); actionList.append(menu); - actionList.append(contextMenu); + + Qt::ContextMenuPolicy policy = now->contextMenuPolicy(); + if (policy != Qt::NoContextMenu && policy != Qt::PreventContextMenu ) { + QSoftKeyAction* contextMenu = new QSoftKeyAction(QSoftKeyAction::ContextMenu, QString::fromLatin1("ContextMenu"), now); + actionList.append(contextMenu); + } if (old) softKeyStack->popandPush(actionList); else -- cgit v0.12 From 8506cc8ce89c23fbfe27f9fb4d4e0cd7c90e9b24 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Fri, 29 May 2009 16:23:06 +0200 Subject: Making hasSoftKeyStack() const. +coding conventions. --- src/gui/widgets/qmainwindow.cpp | 14 ++++++-------- src/gui/widgets/qmainwindow.h | 5 ++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/gui/widgets/qmainwindow.cpp b/src/gui/widgets/qmainwindow.cpp index 618023e..6843d4e 100644 --- a/src/gui/widgets/qmainwindow.cpp +++ b/src/gui/widgets/qmainwindow.cpp @@ -67,7 +67,7 @@ QT_END_NAMESPACE #endif #ifndef QT_NO_SOFTKEYSTACK -#include +#include #endif QT_BEGIN_NAMESPACE @@ -85,7 +85,7 @@ public: , hasOldCursor(false) , cursorAdjusted(false) #endif #ifndef QT_NO_SOFTKEYSTACK - , softKeyStack(0) + , softKeyStack(0) #endif { } QMainWindowLayout *layout; @@ -108,7 +108,7 @@ public: #endif #ifndef QT_NO_SOFTKEYSTACK - QSoftKeyStack* softKeyStack; + QSoftKeyStack *softKeyStack; #endif }; @@ -565,12 +565,10 @@ void QMainWindow::setSoftKeyStack(QSoftKeyStack *softKeyStack) \sa softKeyStack() */ -bool QMainWindow::hasSoftKeyStack() +bool QMainWindow::hasSoftKeyStack() const { - Q_D(QMainWindow); - if (d->softKeyStack ) - return true; - return false; + Q_D(const QMainWindow); + return d->softKeyStack != 0; } #endif // QT_NO_SOFTKEYSTACK diff --git a/src/gui/widgets/qmainwindow.h b/src/gui/widgets/qmainwindow.h index 01b275e..81457d6 100644 --- a/src/gui/widgets/qmainwindow.h +++ b/src/gui/widgets/qmainwindow.h @@ -59,9 +59,8 @@ class QMenuBar; class QStatusBar; class QToolBar; class QMenu; -#ifndef QT_NO_SOFTKEYSTACK class QSoftKeyStack; -#endif + class Q_GUI_EXPORT QMainWindow : public QWidget { Q_OBJECT @@ -135,7 +134,7 @@ public: #ifndef QT_NO_SOFTKEYSTACK QSoftKeyStack *softKeyStack() const; void setSoftKeyStack(QSoftKeyStack *softKeyStack); - bool hasSoftKeyStack(); + bool hasSoftKeyStack() const; #endif #ifndef QT_NO_STATUSBAR -- cgit v0.12 From 42fbf668b6da3251aea2ce27a25882437b9a4a06 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Fri, 29 May 2009 16:40:27 +0200 Subject: Pulled helper menuActionList() out of QSoftKeyStack::handleFocusChanged. It is also needed in other places. --- src/gui/widgets/qsoftkeystack.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index 984922e..c07dd9e 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -177,6 +177,21 @@ bool QSoftKeyStack::isEmpty() return d->isEmpty(); } +QList menuActionList(QWidget *widget) +{ + QList result; + + QSoftKeyAction* menu = new QSoftKeyAction(QSoftKeyAction::Menu, QString::fromLatin1("Menu"), widget); + result.append(menu); + const Qt::ContextMenuPolicy policy = widget->contextMenuPolicy(); + if (policy != Qt::NoContextMenu && policy != Qt::PreventContextMenu ) { + QSoftKeyAction* contextMenu = new QSoftKeyAction(QSoftKeyAction::ContextMenu, QString::fromLatin1("ContextMenu"), widget); + result.append(contextMenu); + } + + return result; +} + void QSoftKeyStack::handleFocusChanged(QWidget *old, QWidget *now) { if (!now) @@ -188,17 +203,8 @@ void QSoftKeyStack::handleFocusChanged(QWidget *old, QWidget *now) if (!mainWindow->hasSoftKeyStack()) return; QSoftKeyStack* softKeyStack = mainWindow->softKeyStack(); - if( mainWindow->menuWidget() ) - { - QList actionList; - QSoftKeyAction* menu = new QSoftKeyAction(QSoftKeyAction::Menu, QString::fromLatin1("Menu"), now); - actionList.append(menu); - - Qt::ContextMenuPolicy policy = now->contextMenuPolicy(); - if (policy != Qt::NoContextMenu && policy != Qt::PreventContextMenu ) { - QSoftKeyAction* contextMenu = new QSoftKeyAction(QSoftKeyAction::ContextMenu, QString::fromLatin1("ContextMenu"), now); - actionList.append(contextMenu); - } + if (mainWindow->menuWidget()) { + QList actionList = menuActionList(now); if (old) softKeyStack->popandPush(actionList); else -- cgit v0.12 From dc599015e702320cbb868855ba76f37d264dc074 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Fri, 29 May 2009 17:08:32 +0200 Subject: Append and push the softKey instead of the empty list --- src/gui/widgets/qsoftkeystack.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index c07dd9e..0c5648e 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -100,7 +100,7 @@ void QSoftKeyStackPrivate::popandPush(QSoftKeyAction *softKey) { QSoftkeySet oldSoftKeySet = softKeyStack.pop(); QSoftkeySet newSoftKeySet; - newSoftKeySet.append(newSoftKeySet); + newSoftKeySet.append(softKey); softKeyStack.push(newSoftKeySet); if( !isSame(oldSoftKeySet, newSoftKeySet)) setNativeSoftKeys(); -- cgit v0.12 From afef05497be340509ffb604ab23d7d036bc363ea Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Fri, 29 May 2009 18:33:30 +0200 Subject: Implemented QKeyEventSoftKey::removeSoftkey and using it in QAbstractItemView::keyPressEvent to remove the "Back" key. --- src/gui/itemviews/qabstractitemview.cpp | 3 +-- src/gui/widgets/qsoftkeystack.cpp | 11 ++++++++++- src/gui/widgets/qsoftkeystack_p.h | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index 6e24c85..565bc28 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -2013,8 +2013,7 @@ void QAbstractItemView::keyPressEvent(QKeyEvent *event) break; case Qt::Key_Back: if (QApplication::keypadNavigationEnabled() && hasEditFocus()) { - if (QSoftKeyStack *stack = QSoftKeyStack::softKeyStackOfWidget(this)) - stack->pop(); + QKeyEventSoftKey::removeSoftkey(this); setEditFocus(false); } else { event->ignore(); diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index 0c5648e..db9b7a2 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -284,7 +284,16 @@ void QKeyEventSoftKey::addSoftKey(QSoftKeyAction::StandardRole standardRole, Qt: QSoftKeyAction *action = new QSoftKeyAction(standardRole, actionWidget); QKeyEventSoftKey *softKey = new QKeyEventSoftKey(action, key, actionWidget); connect(action, SIGNAL(triggered()), softKey, SLOT(sendKeyEvent())); - stack->push(action); + stack->popandPush(action); +} + +void QKeyEventSoftKey::removeSoftkey(QWidget *focussedWidget) +{ + QSoftKeyStack *stack = QSoftKeyStack::softKeyStackOfWidget(focussedWidget); + if (!stack) + return; + QList actionList = menuActionList(focussedWidget); + stack->popandPush(actionList); } void QKeyEventSoftKey::sendKeyEvent() diff --git a/src/gui/widgets/qsoftkeystack_p.h b/src/gui/widgets/qsoftkeystack_p.h index 75d7ad4..c9d7f8d 100644 --- a/src/gui/widgets/qsoftkeystack_p.h +++ b/src/gui/widgets/qsoftkeystack_p.h @@ -98,6 +98,7 @@ class QKeyEventSoftKey : QObject public: QKeyEventSoftKey(QSoftKeyAction *softKeyAction, Qt::Key key, QObject *parent); static void addSoftKey(QSoftKeyAction::StandardRole standardRole, Qt::Key key, QWidget *actionWidget); + static void removeSoftkey(QWidget *focussedWidget); private: QSoftKeyAction *m_softKeyAction; Qt::Key m_key; -- cgit v0.12 From 824e8c4decf952b93279dc2c8c58e5d8dc0aa509 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Sat, 30 May 2009 18:48:27 +0200 Subject: Delete the actions in the popped SoftKeySets. --- src/gui/widgets/qsoftkeystack.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index db9b7a2..494471e 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -79,10 +79,9 @@ void QSoftKeyStackPrivate::push(QSoftKeyAction *softKey) { QSoftkeySet softKeySet; softKeySet.append(softKey); - softKeyStack.push(softKeySet); - setNativeSoftKeys(); - + push(softKeySet); } + void QSoftKeyStackPrivate::push(const QList &softkeys) { QSoftkeySet softKeySet(softkeys); @@ -92,18 +91,15 @@ void QSoftKeyStackPrivate::push(const QList &softkeys) void QSoftKeyStackPrivate::pop() { - softKeyStack.pop(); + qDeleteAll(softKeyStack.pop()); setNativeSoftKeys(); } void QSoftKeyStackPrivate::popandPush(QSoftKeyAction *softKey) { - QSoftkeySet oldSoftKeySet = softKeyStack.pop(); QSoftkeySet newSoftKeySet; newSoftKeySet.append(softKey); - softKeyStack.push(newSoftKeySet); - if( !isSame(oldSoftKeySet, newSoftKeySet)) - setNativeSoftKeys(); + popandPush(newSoftKeySet); } void QSoftKeyStackPrivate::popandPush(const QList &softkeys) @@ -111,8 +107,14 @@ void QSoftKeyStackPrivate::popandPush(const QList &softkeys) QSoftkeySet oldSoftKeySet = softKeyStack.pop(); QSoftkeySet newSoftKeySet(softkeys); softKeyStack.push(newSoftKeySet); - if( !isSame(oldSoftKeySet, newSoftKeySet)) +#ifdef Q_WS_S60 + // Don't flicker on Symbian. + // Platforms that use QActions as native SoftKeys must always call setNativeSoftKeys + // Otherwise the following deletion of oldSoftKeySet would remove the softkeys + if (!isSame(oldSoftKeySet, newSoftKeySet)) +#endif setNativeSoftKeys(); + qDeleteAll(oldSoftKeySet); } const QSoftkeySet& QSoftKeyStackPrivate::top() -- cgit v0.12 From cde524b88f9db46588773d20bf5c36b4e31d234a Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Sat, 30 May 2009 18:49:53 +0200 Subject: Make sure that the QKeyEventSoftKey gets deleted when the action gets deleted. --- src/gui/widgets/qsoftkeystack.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index 494471e..7946f4a 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -286,6 +286,7 @@ void QKeyEventSoftKey::addSoftKey(QSoftKeyAction::StandardRole standardRole, Qt: QSoftKeyAction *action = new QSoftKeyAction(standardRole, actionWidget); QKeyEventSoftKey *softKey = new QKeyEventSoftKey(action, key, actionWidget); connect(action, SIGNAL(triggered()), softKey, SLOT(sendKeyEvent())); + connect(action, SIGNAL(destroyed()), softKey, SLOT(deleteLater())); stack->popandPush(action); } -- cgit v0.12 From 19f36cfed2c64160c17d0b8a6ed8a3b90dbf0d4b Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Mon, 1 Jun 2009 19:04:24 +0200 Subject: warnings-- --- src/gui/widgets/qsoftkeystack.cpp | 3 +-- src/gui/widgets/qsoftkeystack_p.h | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index 7946f4a..9a5a66c 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -216,8 +216,7 @@ void QSoftKeyStack::handleFocusChanged(QWidget *old, QWidget *now) QMainWindow *QSoftKeyStack::mainWindowOfWidget(QWidget *widget) { - QWidget *widgetParent = widget; - while (widgetParent = widgetParent->parentWidget()) + for (QWidget *widgetParent = widget; widgetParent; widgetParent = widgetParent->parentWidget()) if (QMainWindow *mainWindow = qobject_cast(widgetParent)) return mainWindow; diff --git a/src/gui/widgets/qsoftkeystack_p.h b/src/gui/widgets/qsoftkeystack_p.h index c9d7f8d..4532515 100644 --- a/src/gui/widgets/qsoftkeystack_p.h +++ b/src/gui/widgets/qsoftkeystack_p.h @@ -70,7 +70,7 @@ QT_BEGIN_NAMESPACE class QSoftKeyStackPrivate : public QObjectPrivate { - Q_DECLARE_PUBLIC(QSoftKeyStack); + Q_DECLARE_PUBLIC(QSoftKeyStack) public: QSoftKeyStackPrivate(); ~QSoftKeyStackPrivate(); -- cgit v0.12 From 988f6ae93c771fe94f12a0307d34c14edd5f2c3b Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Mon, 1 Jun 2009 19:06:04 +0200 Subject: Using softkeys for the Cancel/Back buttons during keypad navigation --- src/gui/widgets/qcombobox.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp index 16e2f39..59b740f 100644 --- a/src/gui/widgets/qcombobox.cpp +++ b/src/gui/widgets/qcombobox.cpp @@ -75,6 +75,9 @@ #ifndef QT_NO_EFFECTS # include #endif +#ifdef QT_KEYPAD_NAVIGATION +# include +#endif QT_BEGIN_NAMESPACE extern QHash *qt_app_fonts_hash(); @@ -628,6 +631,9 @@ bool QComboBoxPrivateContainer::eventFilter(QObject *o, QEvent *e) case Qt::Key_Select: #endif if (view->currentIndex().isValid() && (view->currentIndex().flags() & Qt::ItemIsEnabled) ) { +#ifdef QT_KEYPAD_NAVIGATION + QKeyEventSoftKey::removeSoftkey(this); +#endif combo->hidePopup(); emit itemSelected(view->currentIndex()); } @@ -640,7 +646,7 @@ bool QComboBoxPrivateContainer::eventFilter(QObject *o, QEvent *e) case Qt::Key_Escape: #ifdef QT_KEYPAD_NAVIGATION case Qt::Key_Back: - case Qt::Key_Context2: // TODO: aportale, KEYPAD_NAVIGATION_HACK when softkey support is there + QKeyEventSoftKey::removeSoftkey(this); #endif combo->hidePopup(); return true; @@ -2435,6 +2441,7 @@ void QComboBox::showPopup() #ifdef QT_KEYPAD_NAVIGATION if (QApplication::keypadNavigationEnabled()) view()->setEditFocus(true); + QKeyEventSoftKey::addSoftKey(QSoftKeyAction::Cancel, Qt::Key_Back, this); #endif } -- cgit v0.12 From b2d43b06d1c1debcd42afbc7dfd85c4991c670d5 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Wed, 3 Jun 2009 12:49:29 +0200 Subject: Added automatic creation for symbian os if softkeystack is enabled. This circumvents the need to go and change every example to explicitly start using softkeystack --- src/gui/widgets/qmainwindow.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/gui/widgets/qmainwindow.cpp b/src/gui/widgets/qmainwindow.cpp index 6843d4e..37b1398 100644 --- a/src/gui/widgets/qmainwindow.cpp +++ b/src/gui/widgets/qmainwindow.cpp @@ -121,6 +121,9 @@ void QMainWindowPrivate::init() explicitIconSize = false; q->setAttribute(Qt::WA_Hover); +#if defined(Q_OS_SYMBIAN) && !defined(QT_NO_SOFTKEYSTACK) + softKeyStack = new QSoftKeyStack(q); +#endif } /* -- cgit v0.12 From c1af1b23442f6d879d3f7eb8c193935f9887244a Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Wed, 3 Jun 2009 17:16:59 +0200 Subject: Fix merge --- src/gui/kernel/qapplication_s60.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gui/kernel/qapplication_s60.cpp b/src/gui/kernel/qapplication_s60.cpp index 542ad43..3921331 100644 --- a/src/gui/kernel/qapplication_s60.cpp +++ b/src/gui/kernel/qapplication_s60.cpp @@ -1,5 +1,5 @@ /**************************************************************************** -** +1** ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) ** @@ -1102,7 +1102,6 @@ void QApplication::symbianResourceChange(int type) #endif default: ->>>>>>> master:src/gui/kernel/qapplication_s60.cpp break; } } -- cgit v0.12 From 4e7ab98ebd48cc1d5fa7643290e34ee166b9ab03 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Wed, 3 Jun 2009 19:30:39 +0200 Subject: Adding and removing a 'Cancel' SoftKey --- src/gui/widgets/qmenu.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp index 6be0f19..c4db539 100644 --- a/src/gui/widgets/qmenu.cpp +++ b/src/gui/widgets/qmenu.cpp @@ -60,6 +60,9 @@ #ifndef QT_NO_WHATSTHIS # include #endif +#ifdef QT_KEYPAD_NAVIGATION +# include +#endif #include "qmenu_p.h" #include "qmenubar_p.h" @@ -578,8 +581,14 @@ void QMenuPrivate::setCurrentAction(QAction *action, int popup, SelectionReason //when the action has no QWidget, the QMenu itself should // get the focus // Since the menu is a pop-up, it uses the popup reason. - if (!q->hasFocus()) + if (!q->hasFocus()) { q->setFocus(Qt::PopupFocusReason); +#ifdef QT_KEYPAD_NAVIGATION + // TODO: aportale, remove KEYPAD_NAVIGATION_HACK when softkey stack + // handles focus related and user related actions separately... + QKeyEventSoftKey::addSoftKey(QSoftKeyAction::Cancel, Qt::Key_Back, q); +#endif + } } } } else { //action is a separator @@ -1937,6 +1946,9 @@ void QMenu::popup(const QPoint &p, QAction *atAction) #ifndef QT_NO_ACCESSIBILITY QAccessible::updateAccessibility(this, 0, QAccessible::PopupMenuStart); #endif +#ifdef QT_KEYPAD_NAVIGATION + QKeyEventSoftKey::addSoftKey(QSoftKeyAction::Cancel, Qt::Key_Back, this); +#endif } /*! @@ -2587,7 +2599,7 @@ void QMenu::keyPressEvent(QKeyEvent *e) case Qt::Key_Escape: #ifdef QT_KEYPAD_NAVIGATION case Qt::Key_Back: - case Qt::Key_Context2: // TODO: aportale, remove KEYPAD_NAVIGATION_HACK when softkey support is there + QKeyEventSoftKey::removeSoftkey(this); #endif key_consumed = true; if (d->tornoff) { -- cgit v0.12 From dfffbd4d134f9b8adc75b2c33c31a2ee859903e6 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Fri, 5 Jun 2009 17:02:56 +0200 Subject: Initial version of softkey implementation that doesn't use softkeystack but instead softkeys are stored in QWidgets. --- src/gui/kernel/qwidget.cpp | 35 +++++++++++++- src/gui/kernel/qwidget.h | 4 ++ src/gui/kernel/qwidget_p.h | 4 ++ src/gui/kernel/qwidget_s60.cpp | 91 +++++++++++++++++++++++++++++++++++ src/gui/widgets/qmainwindow.cpp | 11 +++-- src/gui/widgets/qsoftkeystack.cpp | 2 + src/gui/widgets/qsoftkeystack_s60.cpp | 1 + 7 files changed, 144 insertions(+), 4 deletions(-) diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 955ac8b..157a18e 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -5715,9 +5715,12 @@ bool QWidget::hasFocus() const void QWidget::setFocus(Qt::FocusReason reason) { + Q_D(QWidget); + d->setNativeSoftKeys(softKeys()); + if (!isEnabled()) return; - + QWidget *f = this; while (f->d_func()->extra && f->d_func()->extra->focus_proxy) f = f->d_func()->extra->focus_proxy; @@ -11509,6 +11512,36 @@ void QWidget::clearMask() setMask(QRegion()); } +const QList& QWidget::softKeys() const +{ + Q_D(const QWidget); + if( d->softKeys.count() > 0) + return d->softKeys; + + if (isWindow() || !parentWidget()) + return d->softKeys; + + return parentWidget()->softKeys(); +} + +void QWidget::setSoftKeys(QSoftKeyAction *softKey) +{ + Q_D(QWidget); + qDeleteAll(d->softKeys); + d->softKeys.append(softKey); +// d->setNativeSoftKeys(softkeys); +} + +void QWidget::setSoftKeys(const QList &softKeys) +{ + Q_D(QWidget); + qDeleteAll(d->softKeys); + for(int i = 0; i < softKeys.count(); i++) + d->softKeys.append(softKeys.at(i)); + + // d->setNativeSoftKeys(softkeys); +} + /*! \fn const QX11Info &QWidget::x11Info() const Returns information about the configuration of the X display used to display the widget. diff --git a/src/gui/kernel/qwidget.h b/src/gui/kernel/qwidget.h index 0dd470d..516d69a 100644 --- a/src/gui/kernel/qwidget.h +++ b/src/gui/kernel/qwidget.h @@ -70,6 +70,7 @@ class QWSRegionManager; class QStyle; class QAction; class QVariant; +class QSoftKeyAction; class QActionEvent; class QMouseEvent; @@ -554,6 +555,9 @@ public: void removeAction(QAction *action); QList actions() const; #endif + const QList& softKeys() const; + void setSoftKeys(QSoftKeyAction *softKey); + void setSoftKeys(const QList &softKeys); QWidget *parentWidget() const; diff --git a/src/gui/kernel/qwidget_p.h b/src/gui/kernel/qwidget_p.h index d5f1b98..90d9c93 100644 --- a/src/gui/kernel/qwidget_p.h +++ b/src/gui/kernel/qwidget_p.h @@ -85,6 +85,7 @@ class CCoeControl; class CAknTitlePane; class CAknContextPane; #endif +class QSoftKeyAction; QT_BEGIN_NAMESPACE @@ -102,6 +103,7 @@ class QPixmap; class QWidgetBackingStore; class QGraphicsProxyWidget; class QWidgetItemV2; +class QSoftKeyAction; class QStyle; @@ -224,6 +226,7 @@ public: explicit QWidgetPrivate(int version = QObjectPrivateVersion); ~QWidgetPrivate(); + void setNativeSoftKeys(const QList &softkeys); QWExtra *extraData() const; QTLWExtra *topData() const; QTLWExtra *maybeTopData() const; @@ -511,6 +514,7 @@ public: #ifndef QT_NO_ACTION QList actions; #endif + QList softKeys; QLayout *layout; QWidgetItemV2 *widgetItem; #if !defined(QT_NO_IM) diff --git a/src/gui/kernel/qwidget_s60.cpp b/src/gui/kernel/qwidget_s60.cpp index 11cb974..c39dbf4 100644 --- a/src/gui/kernel/qwidget_s60.cpp +++ b/src/gui/kernel/qwidget_s60.cpp @@ -52,6 +52,9 @@ #include +#include +#include "qsoftkeyaction.h" + QT_BEGIN_NAMESPACE extern bool qt_nograb(); @@ -59,6 +62,83 @@ extern bool qt_nograb(); QWidget *QWidgetPrivate::mouseGrabber = 0; QWidget *QWidgetPrivate::keyboardGrabber = 0; +#define QSoftkeySet QList +// The following 2 defines may only be needed for s60. To be seen. +#define SOFTKEYSTART 5000 +#define SOFTKEYEND (5000 + Qt::Key_Context4-Qt::Key_Context1) + +static void mapSoftKeys(const QSoftkeySet &softkeys) +{ + if (softkeys.count() == 1 && softkeys.at(0)->role()==QSoftKeyAction::Menu) { + softkeys.at(0)->setNativePosition(0); + softkeys.at(0)->setQtContextKey(Qt::Key_Context1); + } + else if(softkeys.count() == 1 && softkeys.at(0)->role()!=QSoftKeyAction::Menu) { + softkeys.at(0)->setNativePosition(2); + softkeys.at(0)->setQtContextKey(Qt::Key_Context1); + } + else { + // FIX THIS + // veryWeirdMagic is needes as s60 5th edition sdk always panics if cba is set with index 1, this hops over it + // This needs further investigation why so that the hack can be removed + int veryWeirdMagic = 0; + for (int index = 0; index < softkeys.count(); index++) { + softkeys.at(index)->setNativePosition(index + veryWeirdMagic); + softkeys.at(index)->setQtContextKey(Qt::Key_Context1 + index); + if (veryWeirdMagic == 0) + veryWeirdMagic = 1; + } + } +} + +static bool isSame(const QList& a, const QList& b) +{ + bool isSame=true; + if ( a.count() != b.count()) + return false; + int index=0; + while (indexrole() != b.at(index)->role()) + return false; + if (a.at(index)->text().compare(b.at(index)->text())!=0) + return false; + index++; + } + return true; +} + + +void QWidgetPrivate::setNativeSoftKeys(const QList &softkeys) +{ + if (QApplication::focusWidget()) { + QList old = QApplication::focusWidget()->softKeys(); + if (isSame(old, softkeys )) + return; + } + + CCoeAppUi* appui = CEikonEnv::Static()->AppUi(); + CAknAppUi* aknAppUi = static_cast (appui); + CEikButtonGroupContainer* nativeContainer = aknAppUi->Cba(); + nativeContainer->SetCommandSetL(R_AVKON_SOFTKEYS_EMPTY_WITH_IDS); + + mapSoftKeys(softkeys); + + for (int index = 0; index < softkeys.count(); index++) { + const QSoftKeyAction* softKeyAction = softkeys.at(index); + if (softKeyAction->role() != QSoftKeyAction::ContextMenu) { + + HBufC* text = qt_QString2HBufCNewL(softKeyAction->text()); + CleanupStack::PushL(text); + if (softKeyAction->role() == QSoftKeyAction::Menu) { + nativeContainer->SetCommandL(softKeyAction->nativePosition(), EAknSoftkeyOptions, *text); + } else { + nativeContainer->SetCommandL(softKeyAction->nativePosition(), SOFTKEYSTART + softKeyAction->qtContextKey()-Qt::Key_Context1, *text); + } + CleanupStack::PopAndDestroy(); + } + } +} + void QWidgetPrivate::setWSGeometry(bool dontShow) { @@ -1003,5 +1083,16 @@ void QWidget::activateWindow() rw->SetOrdinalPosition(0); } } +/* +void QWidget::setSoftKeys(QSoftKeyAction *softKey) +{ + Q_D(QWidget); + d-> +} +void QWidget::setSoftKeys(const QList &softkeys) +{ + Q_D(QWidget); +} +*/ QT_END_NAMESPACE diff --git a/src/gui/widgets/qmainwindow.cpp b/src/gui/widgets/qmainwindow.cpp index 37b1398..20270b4 100644 --- a/src/gui/widgets/qmainwindow.cpp +++ b/src/gui/widgets/qmainwindow.cpp @@ -69,6 +69,7 @@ QT_END_NAMESPACE #ifndef QT_NO_SOFTKEYSTACK #include #endif +#include QT_BEGIN_NAMESPACE @@ -121,9 +122,9 @@ void QMainWindowPrivate::init() explicitIconSize = false; q->setAttribute(Qt::WA_Hover); -#if defined(Q_OS_SYMBIAN) && !defined(QT_NO_SOFTKEYSTACK) - softKeyStack = new QSoftKeyStack(q); -#endif +//#if defined(Q_OS_SYMBIAN) && !defined(QT_NO_SOFTKEYSTACK) +// softKeyStack = new QSoftKeyStack(q); +//#endif } /* @@ -495,6 +496,10 @@ void QMainWindow::setMenuBar(QMenuBar *menuBar) oldMenuBar->deleteLater(); } d->layout->setMenuBar(menuBar); + if (menuBar) { + QSoftKeyAction* menu = new QSoftKeyAction(QSoftKeyAction::Menu, QString::fromLatin1("Menu"), this); + setSoftKeys(menu); + } } /*! diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index 9a5a66c..6c00d35 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -196,6 +196,7 @@ QList menuActionList(QWidget *widget) void QSoftKeyStack::handleFocusChanged(QWidget *old, QWidget *now) { + return; if (!now) return; QWidget *w = qApp->activeWindow(); @@ -252,6 +253,7 @@ QToolBar* softKeyToolBar(QMainWindow *mainWindow) void QSoftKeyStackPrivate::setNativeSoftKeys() { + return; Q_Q(QSoftKeyStack); QMainWindow *parent = qobject_cast(q->parent()); if (!parent) diff --git a/src/gui/widgets/qsoftkeystack_s60.cpp b/src/gui/widgets/qsoftkeystack_s60.cpp index 8dfd5dd..a315a3b 100644 --- a/src/gui/widgets/qsoftkeystack_s60.cpp +++ b/src/gui/widgets/qsoftkeystack_s60.cpp @@ -73,6 +73,7 @@ void QSoftKeyStackPrivate::mapSoftKeys(const QSoftkeySet &top) void QSoftKeyStackPrivate::setNativeSoftKeys() { + return; CCoeAppUi* appui = CEikonEnv::Static()->AppUi(); CAknAppUi* aknAppUi = static_cast (appui); CEikButtonGroupContainer* nativeContainer = aknAppUi->Cba(); -- cgit v0.12 From b8d6e02fc73fec1c1bc6b5b21e80104be61b946e Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Sat, 6 Jun 2009 13:09:26 +0200 Subject: Added SoftKeyRole --- src/gui/kernel/qaction.cpp | 25 +++++++++++++++++++++++++ src/gui/kernel/qaction.h | 9 +++++++++ src/gui/kernel/qaction_p.h | 1 + 3 files changed, 35 insertions(+) diff --git a/src/gui/kernel/qaction.cpp b/src/gui/kernel/qaction.cpp index abb17d7..e32416a 100644 --- a/src/gui/kernel/qaction.cpp +++ b/src/gui/kernel/qaction.cpp @@ -1348,6 +1348,31 @@ QAction::MenuRole QAction::menuRole() const } /*! + \property QAction::softKeyRole + \brief the action's softkey role + \since 4.6 + + This indicates what softkey action this action is. Usually used on mobile + platforms to map QActions no hardware keys. + + The softkey role can be changed any time. +*/ +void QAction::setSoftKeyRole(SoftKeyRole softKeyRole) +{ + Q_D(QAction); + if (d->softKeyRole == softKeyRole) + return; + + d->softKeyRole = softKeyRole; + d->sendDataChanged(); +} + +QAction::SoftKeyRole QAction::softKeyRole() const +{ + Q_D(const QAction); + return d->softKeyRole; +} +/*! \property QAction::iconVisibleInMenu \brief Whether or not an action should show an icon in a menu \since 4.4 diff --git a/src/gui/kernel/qaction.h b/src/gui/kernel/qaction.h index d7bf8c3..e9c64c8 100644 --- a/src/gui/kernel/qaction.h +++ b/src/gui/kernel/qaction.h @@ -67,6 +67,7 @@ class Q_GUI_EXPORT QAction : public QObject Q_DECLARE_PRIVATE(QAction) Q_ENUMS(MenuRole) + Q_ENUMS(SoftKeyRole) Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable) Q_PROPERTY(bool checked READ isChecked WRITE setChecked DESIGNABLE isCheckable NOTIFY toggled) Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled) @@ -84,11 +85,16 @@ class Q_GUI_EXPORT QAction : public QObject #endif Q_PROPERTY(bool visible READ isVisible WRITE setVisible) Q_PROPERTY(MenuRole menuRole READ menuRole WRITE setMenuRole) + Q_PROPERTY(SoftKeyRole softKeyRole READ softKeyRole WRITE setSoftKeyRole) Q_PROPERTY(bool iconVisibleInMenu READ isIconVisibleInMenu WRITE setIconVisibleInMenu) public: enum MenuRole { NoRole, TextHeuristicRole, ApplicationSpecificRole, AboutQtRole, AboutRole, PreferencesRole, QuitRole }; + enum SoftKeyRole { Options, Select, Back, Next, Previous, Ok, Cancel, Edit, + View, BackSpace, EndEdit, RevertEdit, Deselect, Finish, Menu, + ContextMenu, Custom, SoftKey1, SoftKey2, SoftKey3, SoftKey4 }; + explicit QAction(QObject* parent); QAction(const QString &text, QObject* parent); QAction(const QIcon &icon, const QString &text, QObject* parent); @@ -168,6 +174,9 @@ public: void setMenuRole(MenuRole menuRole); MenuRole menuRole() const; + void setSoftKeyRole(SoftKeyRole softKeyRole); + SoftKeyRole softKeyRole() const; + void setIconVisibleInMenu(bool visible); bool isIconVisibleInMenu() const; diff --git a/src/gui/kernel/qaction_p.h b/src/gui/kernel/qaction_p.h index 0617ef5..6051d9a 100644 --- a/src/gui/kernel/qaction_p.h +++ b/src/gui/kernel/qaction_p.h @@ -102,6 +102,7 @@ public: uint separator : 1; uint fontSet : 1; QAction::MenuRole menuRole; + QAction::SoftKeyRole softKeyRole; int iconVisibleInMenu : 3; // Only has values -1, 0, and 1 QList widgets; #ifndef QT_NO_GRAPHICSVIEW -- cgit v0.12 From f87e69fcb26387e8d22546778bb1f5d43ba8e200 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Sat, 6 Jun 2009 14:11:10 +0200 Subject: Renamed SoftKeyRoles to be more descriptive --- src/gui/kernel/qaction.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/gui/kernel/qaction.h b/src/gui/kernel/qaction.h index e9c64c8..6725f42 100644 --- a/src/gui/kernel/qaction.h +++ b/src/gui/kernel/qaction.h @@ -91,9 +91,11 @@ class Q_GUI_EXPORT QAction : public QObject public: enum MenuRole { NoRole, TextHeuristicRole, ApplicationSpecificRole, AboutQtRole, AboutRole, PreferencesRole, QuitRole }; - enum SoftKeyRole { Options, Select, Back, Next, Previous, Ok, Cancel, Edit, - View, BackSpace, EndEdit, RevertEdit, Deselect, Finish, Menu, - ContextMenu, Custom, SoftKey1, SoftKey2, SoftKey3, SoftKey4 }; + enum SoftKeyRole { OptionsSoftKey, SelectSoftKey, BackSoftKey, NextSoftKey, PreviousSoftKey, + OkSoftKey, CancelSoftKey, EditSoftKey, ViewSoftKey, BackSpaceSoftKey, + EndEditSoftKey, RevertEditSoftKey, DeselectSoftKey, FinishSoftKey, + MenuSoftKey, ContextMenuSoftKey, Key1SoftKey, Key2SoftKey, + Key3SoftKey, Key4SoftKey, CustomSoftKey }; explicit QAction(QObject* parent); QAction(const QString &text, QObject* parent); -- cgit v0.12 From 449d4b00c6e3d8a277821e5fb5837e3da2e6b920 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Sat, 6 Jun 2009 14:11:53 +0200 Subject: Replaced usage of QSoftKeyActions with QActions+SoftKeyRoles --- src/gui/kernel/qwidget.cpp | 6 +++--- src/gui/kernel/qwidget.h | 7 +++---- src/gui/kernel/qwidget_p.h | 5 ++--- src/gui/kernel/qwidget_s60.cpp | 33 +++++++++++++++++++-------------- src/gui/widgets/qmainwindow.cpp | 3 ++- 5 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 157a18e..e18b66b 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -11512,7 +11512,7 @@ void QWidget::clearMask() setMask(QRegion()); } -const QList& QWidget::softKeys() const +const QList& QWidget::softKeys() const { Q_D(const QWidget); if( d->softKeys.count() > 0) @@ -11524,7 +11524,7 @@ const QList& QWidget::softKeys() const return parentWidget()->softKeys(); } -void QWidget::setSoftKeys(QSoftKeyAction *softKey) +void QWidget::setSoftKeys(QAction *softKey) { Q_D(QWidget); qDeleteAll(d->softKeys); @@ -11532,7 +11532,7 @@ void QWidget::setSoftKeys(QSoftKeyAction *softKey) // d->setNativeSoftKeys(softkeys); } -void QWidget::setSoftKeys(const QList &softKeys) +void QWidget::setSoftKeys(const QList &softKeys) { Q_D(QWidget); qDeleteAll(d->softKeys); diff --git a/src/gui/kernel/qwidget.h b/src/gui/kernel/qwidget.h index 516d69a..36a30ac 100644 --- a/src/gui/kernel/qwidget.h +++ b/src/gui/kernel/qwidget.h @@ -70,7 +70,6 @@ class QWSRegionManager; class QStyle; class QAction; class QVariant; -class QSoftKeyAction; class QActionEvent; class QMouseEvent; @@ -555,9 +554,9 @@ public: void removeAction(QAction *action); QList actions() const; #endif - const QList& softKeys() const; - void setSoftKeys(QSoftKeyAction *softKey); - void setSoftKeys(const QList &softKeys); + const QList& softKeys() const; + void setSoftKeys(QAction *softKey); + void setSoftKeys(const QList &softKeys); QWidget *parentWidget() const; diff --git a/src/gui/kernel/qwidget_p.h b/src/gui/kernel/qwidget_p.h index 90d9c93..645b13d 100644 --- a/src/gui/kernel/qwidget_p.h +++ b/src/gui/kernel/qwidget_p.h @@ -85,7 +85,6 @@ class CCoeControl; class CAknTitlePane; class CAknContextPane; #endif -class QSoftKeyAction; QT_BEGIN_NAMESPACE @@ -226,7 +225,7 @@ public: explicit QWidgetPrivate(int version = QObjectPrivateVersion); ~QWidgetPrivate(); - void setNativeSoftKeys(const QList &softkeys); + void setNativeSoftKeys(const QList &softkeys); QWExtra *extraData() const; QTLWExtra *topData() const; QTLWExtra *maybeTopData() const; @@ -514,7 +513,7 @@ public: #ifndef QT_NO_ACTION QList actions; #endif - QList softKeys; + QList softKeys; QLayout *layout; QWidgetItemV2 *widgetItem; #if !defined(QT_NO_IM) diff --git a/src/gui/kernel/qwidget_s60.cpp b/src/gui/kernel/qwidget_s60.cpp index c39dbf4..a23469e 100644 --- a/src/gui/kernel/qwidget_s60.cpp +++ b/src/gui/kernel/qwidget_s60.cpp @@ -53,7 +53,6 @@ #include #include -#include "qsoftkeyaction.h" QT_BEGIN_NAMESPACE @@ -62,18 +61,18 @@ extern bool qt_nograb(); QWidget *QWidgetPrivate::mouseGrabber = 0; QWidget *QWidgetPrivate::keyboardGrabber = 0; -#define QSoftkeySet QList +#define QSoftkeySet QList // The following 2 defines may only be needed for s60. To be seen. #define SOFTKEYSTART 5000 #define SOFTKEYEND (5000 + Qt::Key_Context4-Qt::Key_Context1) static void mapSoftKeys(const QSoftkeySet &softkeys) { - if (softkeys.count() == 1 && softkeys.at(0)->role()==QSoftKeyAction::Menu) { +/* if (softkeys.count() == 1 && softkeys.at(0)->menuRole()==QAction::MenuSoftKey) { softkeys.at(0)->setNativePosition(0); softkeys.at(0)->setQtContextKey(Qt::Key_Context1); } - else if(softkeys.count() == 1 && softkeys.at(0)->role()!=QSoftKeyAction::Menu) { + else if(softkeys.count() == 1 && softkeys.at(0)->menuRole()!=QAction::MenuSoftKey) { softkeys.at(0)->setNativePosition(2); softkeys.at(0)->setQtContextKey(Qt::Key_Context1); } @@ -89,16 +88,17 @@ static void mapSoftKeys(const QSoftkeySet &softkeys) veryWeirdMagic = 1; } } +*/ } -static bool isSame(const QList& a, const QList& b) +static bool isSame(const QList& a, const QList& b) { bool isSame=true; if ( a.count() != b.count()) return false; int index=0; while (indexrole() != b.at(index)->role()) + if (a.at(index)->softKeyRole() != b.at(index)->softKeyRole()) return false; if (a.at(index)->text().compare(b.at(index)->text())!=0) return false; @@ -108,10 +108,10 @@ static bool isSame(const QList& a, const QList } -void QWidgetPrivate::setNativeSoftKeys(const QList &softkeys) +void QWidgetPrivate::setNativeSoftKeys(const QList &softkeys) { if (QApplication::focusWidget()) { - QList old = QApplication::focusWidget()->softKeys(); + QList old = QApplication::focusWidget()->softKeys(); if (isSame(old, softkeys )) return; } @@ -122,20 +122,25 @@ void QWidgetPrivate::setNativeSoftKeys(const QList &softkeys) nativeContainer->SetCommandSetL(R_AVKON_SOFTKEYS_EMPTY_WITH_IDS); mapSoftKeys(softkeys); - + int placeInScreen=0; + for (int index = 0; index < softkeys.count(); index++) { - const QSoftKeyAction* softKeyAction = softkeys.at(index); - if (softKeyAction->role() != QSoftKeyAction::ContextMenu) { + const QAction* softKeyAction = softkeys.at(index); + if (softKeyAction->softKeyRole() != QAction::ContextMenuSoftKey) { HBufC* text = qt_QString2HBufCNewL(softKeyAction->text()); CleanupStack::PushL(text); - if (softKeyAction->role() == QSoftKeyAction::Menu) { - nativeContainer->SetCommandL(softKeyAction->nativePosition(), EAknSoftkeyOptions, *text); + if (softKeyAction->softKeyRole() == QAction::MenuSoftKey) { + nativeContainer->SetCommandL(placeInScreen, EAknSoftkeyOptions, *text); } else { - nativeContainer->SetCommandL(softKeyAction->nativePosition(), SOFTKEYSTART + softKeyAction->qtContextKey()-Qt::Key_Context1, *text); + nativeContainer->SetCommandL(placeInScreen, SOFTKEYSTART + index, *text); } CleanupStack::PopAndDestroy(); + placeInScreen++; } + if (placeInScreen==1) + placeInScreen=2; + } } diff --git a/src/gui/widgets/qmainwindow.cpp b/src/gui/widgets/qmainwindow.cpp index 20270b4..a12c32b 100644 --- a/src/gui/widgets/qmainwindow.cpp +++ b/src/gui/widgets/qmainwindow.cpp @@ -497,7 +497,8 @@ void QMainWindow::setMenuBar(QMenuBar *menuBar) } d->layout->setMenuBar(menuBar); if (menuBar) { - QSoftKeyAction* menu = new QSoftKeyAction(QSoftKeyAction::Menu, QString::fromLatin1("Menu"), this); + QAction* menu = new QAction(QString::fromLatin1("Menu"), this); + menu->setSoftKeyRole(QAction::MenuSoftKey); setSoftKeys(menu); } } -- cgit v0.12 From 4dd8985db4653a3f4f406f4fe7c910ffd02643b3 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Sat, 6 Jun 2009 14:29:00 +0200 Subject: Added mapping from native hardware keys to softkeys. This enables the QActions with softKeyRole to be triggered --- src/gui/kernel/qapplication_s60.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/gui/kernel/qapplication_s60.cpp b/src/gui/kernel/qapplication_s60.cpp index 94e59b3..2c7fc02 100644 --- a/src/gui/kernel/qapplication_s60.cpp +++ b/src/gui/kernel/qapplication_s60.cpp @@ -1064,8 +1064,15 @@ void QApplication::symbianHandleCommand(int command) exit(); break; default: - if (command >= SOFTKEYSTART && command <= SOFTKEYEND) - QSoftKeyStackPrivate::handleSoftKeyPress(command); + if (command >= SOFTKEYSTART && command <= SOFTKEYEND) { + int index= command-SOFTKEYSTART; + QWidget* focused = QApplication::focusWidget(); + const QList& softKeys = focused->softKeys(); + if (index>=softKeys.count()) { + // Assert horrible state error + } + softKeys.at(index)->activate(QAction::Trigger); + } else QMenuBarPrivate::symbianCommands(command); break; -- cgit v0.12 From d0432c7d7c06c83ccaa2266217e5b1823fa8dba6 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Sat, 6 Jun 2009 14:30:32 +0200 Subject: Replaced usage of QSoftKeyStack with QActions having SoftKeyRole --- src/gui/widgets/qmainwindow.cpp | 62 ----------------------------------------- src/gui/widgets/qmainwindow.h | 9 +----- 2 files changed, 1 insertion(+), 70 deletions(-) diff --git a/src/gui/widgets/qmainwindow.cpp b/src/gui/widgets/qmainwindow.cpp index a12c32b..90c5db9 100644 --- a/src/gui/widgets/qmainwindow.cpp +++ b/src/gui/widgets/qmainwindow.cpp @@ -66,11 +66,6 @@ extern OSWindowRef qt_mac_window_for(const QWidget *); // qwidget_mac.cpp QT_END_NAMESPACE #endif -#ifndef QT_NO_SOFTKEYSTACK -#include -#endif -#include - QT_BEGIN_NAMESPACE class QMainWindowPrivate : public QWidgetPrivate @@ -85,9 +80,6 @@ public: #if !defined(QT_NO_DOCKWIDGET) && !defined(QT_NO_CURSOR) , hasOldCursor(false) , cursorAdjusted(false) #endif -#ifndef QT_NO_SOFTKEYSTACK - , softKeyStack(0) -#endif { } QMainWindowLayout *layout; QSize iconSize; @@ -107,10 +99,6 @@ public: uint hasOldCursor : 1; uint cursorAdjusted : 1; #endif - -#ifndef QT_NO_SOFTKEYSTACK - QSoftKeyStack *softKeyStack; -#endif }; void QMainWindowPrivate::init() @@ -122,9 +110,6 @@ void QMainWindowPrivate::init() explicitIconSize = false; q->setAttribute(Qt::WA_Hover); -//#if defined(Q_OS_SYMBIAN) && !defined(QT_NO_SOFTKEYSTACK) -// softKeyStack = new QSoftKeyStack(q); -//#endif } /* @@ -534,53 +519,6 @@ void QMainWindow::setMenuWidget(QWidget *menuBar) } #endif // QT_NO_MENUBAR -#ifndef QT_NO_SOFTKEYSTACK -/*! - Returns the softkey stack for the main window. This function creates - and returns an empty soft key stack if the stack does not exist. - - \sa softKeyStack() -*/ -QSoftKeyStack *QMainWindow::softKeyStack() const -{ - if (!d_func()->softKeyStack) { - QMainWindow *self = const_cast(this); - QSoftKeyStack* softKeyStack = new QSoftKeyStack(self); - self->setSoftKeyStack(softKeyStack); - } - return d_func()->softKeyStack; -} - -/*! - Sets the softkey stack for the main window to \a softKeyStack. - - Note: QMainWindow takes ownership of the \a softKeyStack pointer and - deletes it at the appropriate time. - - \sa softKeyStack() -*/ -void QMainWindow::setSoftKeyStack(QSoftKeyStack *softKeyStack) -{ - Q_D(QMainWindow); - if (d->softKeyStack && d->softKeyStack != softKeyStack) { - QSoftKeyStack *oldSoftKeyStack = d->softKeyStack; - delete oldSoftKeyStack; - } - d->softKeyStack = softKeyStack; -} - -/*! - Returns true if QMainWindow has a softkeystack and false otherwise - - \sa softKeyStack() -*/ -bool QMainWindow::hasSoftKeyStack() const -{ - Q_D(const QMainWindow); - return d->softKeyStack != 0; -} -#endif // QT_NO_SOFTKEYSTACK - #ifndef QT_NO_STATUSBAR /*! Returns the status bar for the main window. This function creates diff --git a/src/gui/widgets/qmainwindow.h b/src/gui/widgets/qmainwindow.h index 81457d6..9983c7a 100644 --- a/src/gui/widgets/qmainwindow.h +++ b/src/gui/widgets/qmainwindow.h @@ -59,7 +59,6 @@ class QMenuBar; class QStatusBar; class QToolBar; class QMenu; -class QSoftKeyStack; class Q_GUI_EXPORT QMainWindow : public QWidget { @@ -130,13 +129,7 @@ public: QWidget *menuWidget() const; void setMenuWidget(QWidget *menubar); #endif - -#ifndef QT_NO_SOFTKEYSTACK - QSoftKeyStack *softKeyStack() const; - void setSoftKeyStack(QSoftKeyStack *softKeyStack); - bool hasSoftKeyStack() const; -#endif - + #ifndef QT_NO_STATUSBAR QStatusBar *statusBar() const; void setStatusBar(QStatusBar *statusbar); -- cgit v0.12 From 934ebcd3e3c1c568ac8371dbb1d96cd06385883d Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Sat, 6 Jun 2009 14:31:22 +0200 Subject: Disabled context sensitive menu because it would cause compilation failure. Context menu will be enabled again once the QAction SoftKeyRole implementation is in state where context menu can be properly supported --- src/gui/widgets/qmenu_symbian.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/widgets/qmenu_symbian.cpp b/src/gui/widgets/qmenu_symbian.cpp index f27e580..df95061 100644 --- a/src/gui/widgets/qmenu_symbian.cpp +++ b/src/gui/widgets/qmenu_symbian.cpp @@ -214,7 +214,7 @@ static void rebuildMenu() QMenuBarPrivate *mb = 0; QWidget *w = qApp->activeWindow(); QMainWindow *mainWindow = qobject_cast(w); - if ((mainWindow) && mainWindow->hasSoftKeyStack()) { + /* if ((mainWindow) && mainWindow->hasSoftKeyStack()) { QSoftKeyStack* softKeyStack = mainWindow->softKeyStack(); if (!softKeyStack->isEmpty()) { const QSoftkeySet& softKeyTop = softKeyStack->top(); @@ -231,7 +231,7 @@ static void rebuildMenu() } } } - +*/ if (w) { mb = menubars()->value(w); qt_symbian_menu_static_cmd_id = QT_FIRST_MENU_ITEM; -- cgit v0.12 From 7749376ff1536c703d223e16506eed1a61132a41 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Sat, 6 Jun 2009 16:17:01 +0200 Subject: Removed QSoftKeyStack and replaced places using it with the new improved softkey interface in QWidget --- src/gui/itemviews/qabstractitemview.cpp | 5 +- src/gui/kernel/qapplication_s60.cpp | 1 - src/gui/kernel/qwidget.cpp | 3 +- src/gui/kernel/qwidget_p.h | 1 - src/gui/widgets/qcombobox.cpp | 7 +- src/gui/widgets/qmenu.cpp | 8 +- src/gui/widgets/qmenu_symbian.cpp | 2 - src/gui/widgets/qsoftkeyaction.cpp | 234 ------------------------ src/gui/widgets/qsoftkeyaction.h | 106 ----------- src/gui/widgets/qsoftkeystack.cpp | 306 -------------------------------- src/gui/widgets/qsoftkeystack.h | 89 ---------- src/gui/widgets/qsoftkeystack_p.h | 111 ------------ src/gui/widgets/qsoftkeystack_s60.cpp | 120 ------------- src/gui/widgets/widgets.pri | 8 +- 14 files changed, 10 insertions(+), 991 deletions(-) delete mode 100644 src/gui/widgets/qsoftkeyaction.cpp delete mode 100644 src/gui/widgets/qsoftkeyaction.h delete mode 100644 src/gui/widgets/qsoftkeystack.cpp delete mode 100644 src/gui/widgets/qsoftkeystack.h delete mode 100644 src/gui/widgets/qsoftkeystack_p.h delete mode 100644 src/gui/widgets/qsoftkeystack_s60.cpp diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index 565bc28..187e2cd 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -61,9 +61,6 @@ #ifndef QT_NO_ACCESSIBILITY #include #endif -#ifdef QT_KEYPAD_NAVIGATION -#include -#endif QT_BEGIN_NAMESPACE @@ -2006,7 +2003,7 @@ void QAbstractItemView::keyPressEvent(QKeyEvent *event) if (QApplication::keypadNavigationEnabled()) { if (!hasEditFocus()) { setEditFocus(true); - QKeyEventSoftKey::addSoftKey(QSoftKeyAction::Back, Qt::Key_Back, this); + QKeyEventSoftKey::addSoftKey(QAction::Back, Qt::Key_Back, this); return; } } diff --git a/src/gui/kernel/qapplication_s60.cpp b/src/gui/kernel/qapplication_s60.cpp index 2c7fc02..6ee7899 100644 --- a/src/gui/kernel/qapplication_s60.cpp +++ b/src/gui/kernel/qapplication_s60.cpp @@ -58,7 +58,6 @@ #endif #include "private/qwindowsurface_s60_p.h" #include "qpaintengine.h" -#include "private/qsoftkeystack_p.h" #include "private/qmenubar_p.h" #include "apgwgnam.h" // For CApaWindowGroupName diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index e18b66b..0a7fea3 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -11528,7 +11528,8 @@ void QWidget::setSoftKeys(QAction *softKey) { Q_D(QWidget); qDeleteAll(d->softKeys); - d->softKeys.append(softKey); + if (softKey) + d->softKeys.append(softKey); // d->setNativeSoftKeys(softkeys); } diff --git a/src/gui/kernel/qwidget_p.h b/src/gui/kernel/qwidget_p.h index 645b13d..9a606dc 100644 --- a/src/gui/kernel/qwidget_p.h +++ b/src/gui/kernel/qwidget_p.h @@ -102,7 +102,6 @@ class QPixmap; class QWidgetBackingStore; class QGraphicsProxyWidget; class QWidgetItemV2; -class QSoftKeyAction; class QStyle; diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp index 59b740f..aa90909 100644 --- a/src/gui/widgets/qcombobox.cpp +++ b/src/gui/widgets/qcombobox.cpp @@ -63,7 +63,7 @@ #include #include #include - +#include #ifdef Q_WS_X11 #include #endif @@ -75,9 +75,6 @@ #ifndef QT_NO_EFFECTS # include #endif -#ifdef QT_KEYPAD_NAVIGATION -# include -#endif QT_BEGIN_NAMESPACE extern QHash *qt_app_fonts_hash(); @@ -2441,7 +2438,7 @@ void QComboBox::showPopup() #ifdef QT_KEYPAD_NAVIGATION if (QApplication::keypadNavigationEnabled()) view()->setEditFocus(true); - QKeyEventSoftKey::addSoftKey(QSoftKeyAction::Cancel, Qt::Key_Back, this); + QKeyEventSoftKey::addSoftKey(QAction::CancelSoftKey, Qt::Key_Back, this); #endif } diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp index c4db539..d713081 100644 --- a/src/gui/widgets/qmenu.cpp +++ b/src/gui/widgets/qmenu.cpp @@ -60,9 +60,7 @@ #ifndef QT_NO_WHATSTHIS # include #endif -#ifdef QT_KEYPAD_NAVIGATION -# include -#endif +#include #include "qmenu_p.h" #include "qmenubar_p.h" @@ -586,7 +584,7 @@ void QMenuPrivate::setCurrentAction(QAction *action, int popup, SelectionReason #ifdef QT_KEYPAD_NAVIGATION // TODO: aportale, remove KEYPAD_NAVIGATION_HACK when softkey stack // handles focus related and user related actions separately... - QKeyEventSoftKey::addSoftKey(QSoftKeyAction::Cancel, Qt::Key_Back, q); + QKeyEventSoftKey::addSoftKey(QAction::CancelSoftKey, Qt::Key_Back, q); #endif } } @@ -1947,7 +1945,7 @@ void QMenu::popup(const QPoint &p, QAction *atAction) QAccessible::updateAccessibility(this, 0, QAccessible::PopupMenuStart); #endif #ifdef QT_KEYPAD_NAVIGATION - QKeyEventSoftKey::addSoftKey(QSoftKeyAction::Cancel, Qt::Key_Back, this); + QKeyEventSoftKey::addSoftKey(QAction::CancelSoftKey, Qt::Key_Back, this); #endif } diff --git a/src/gui/widgets/qmenu_symbian.cpp b/src/gui/widgets/qmenu_symbian.cpp index df95061..e422882 100644 --- a/src/gui/widgets/qmenu_symbian.cpp +++ b/src/gui/widgets/qmenu_symbian.cpp @@ -56,8 +56,6 @@ #include #include #include -#include -#include #ifndef QT_NO_MENUBAR QT_BEGIN_NAMESPACE diff --git a/src/gui/widgets/qsoftkeyaction.cpp b/src/gui/widgets/qsoftkeyaction.cpp deleted file mode 100644 index 302850c..0000000 --- a/src/gui/widgets/qsoftkeyaction.cpp +++ /dev/null @@ -1,234 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qsoftkeyaction.h" -#include - -/*! - \class QSoftKeyAction - \brief The QSoftKeyAction class defines a special kind of QAction that may also be displayed in a QSoftKeyBar. -*/ - -class QSoftKeyActionPrivate : public QActionPrivate -{ -public: - QSoftKeyActionPrivate(QSoftKeyAction::StandardRole role = QSoftKeyAction::Custom) - { - this->role = role; - } - - static QString roleText(QSoftKeyAction::StandardRole role); - - QSoftKeyAction::StandardRole role; - QString roleName; - int nativePosition; - int qtContextKey; -}; - -QString QSoftKeyActionPrivate::roleText(QSoftKeyAction::StandardRole role) -{ - switch (role) { - case QSoftKeyAction::Options: - return QSoftKeyAction::tr("Options"); - case QSoftKeyAction::Select: - return QSoftKeyAction::tr("Select"); - case QSoftKeyAction::Back: - return QSoftKeyAction::tr("Back"); - case QSoftKeyAction::Next: - return QSoftKeyAction::tr("Next"); - case QSoftKeyAction::Previous: - return QSoftKeyAction::tr("Previous"); - case QSoftKeyAction::Ok: - return QSoftKeyAction::tr("Ok"); - case QSoftKeyAction::Cancel: - return QSoftKeyAction::tr("Cancel"); - case QSoftKeyAction::Edit: - return QSoftKeyAction::tr("Edit"); - case QSoftKeyAction::View: - return QSoftKeyAction::tr("View"); - default: - return QString(); - }; -} - -/*! - \enum QSoftKeyAction::StandardRole - This enum defines the standard role for a QSoftKeyAction. - - \value Options - \value Select - \value Back - \value Next - \value Previous - \value Ok - \value Cancel - \value Edit - \value View - \value BackSpace - \value EndEdit - \value RevertEdit - \value Deselect - \value Finish - \value Custom -*/ - -QSoftKeyAction::QSoftKeyAction(QObject *parent) - : QAction(*new QSoftKeyActionPrivate(), parent) -{ -} - -QSoftKeyAction::QSoftKeyAction(StandardRole role, QObject *parent) - : QAction(*new QSoftKeyActionPrivate(), parent) -{ - Q_D(QSoftKeyAction); - d->role = role; - setText(QSoftKeyActionPrivate::roleText(role)); -} - -QSoftKeyAction::QSoftKeyAction(const QString &text, QObject* parent) - : QAction(*new QSoftKeyActionPrivate(), parent) -{ - setText(text); -} - -QSoftKeyAction::QSoftKeyAction(StandardRole role, const QString &text, QObject* parent) - : QAction(*new QSoftKeyActionPrivate(), parent) -{ - setText(text); - Q_D(QSoftKeyAction); - d->role = role; -} - -QSoftKeyAction::QSoftKeyAction(const QIcon &icon, const QString &text, QObject* parent) - : QAction(*new QSoftKeyActionPrivate(), parent) -{ - setIcon(icon); - setText(text); -} - -QSoftKeyAction::QSoftKeyAction(StandardRole role, const QIcon &icon, const QString &text, QObject* parent) - : QAction(*new QSoftKeyActionPrivate(), parent) -{ - setIcon(icon); - setText(text); - Q_D(QSoftKeyAction); - d->role = role; -} - -QSoftKeyAction::~QSoftKeyAction() -{ -} - -/*! - Returns the standard role associated with this action, or Custom - if the role is defined by roleName(). - - \sa setRole(), roleName() -*/ -QSoftKeyAction::StandardRole QSoftKeyAction::role() const -{ - Q_D(const QSoftKeyAction); - return d->role; -} - -/*! - Returns the custom role name if role() is Custom, or an empty - string otherwise. - - \sa role(), setRole() -*/ -QString QSoftKeyAction::roleName() const -{ - Q_D(const QSoftKeyAction); - return d->roleName; -} - -/*! - Sets the standard role associated with this action to \a role, - and also sets roleName() to the empty string. - - \sa role(), roleName() -*/ -void QSoftKeyAction::setRole(StandardRole role) -{ - Q_D(QSoftKeyAction); - d->role = role; - d->roleName = QString(); - emit changed(); -} - -/*! - Sets the custom roleName() associated with this action to \a role, - and also sets role() to Custom. - - \sa role(), roleName() -*/ -void QSoftKeyAction::setRole(const QString& role) -{ - Q_D(QSoftKeyAction); - d->role = Custom; - d->roleName = role; - emit changed(); -} - -int QSoftKeyAction::nativePosition() const -{ - Q_D(const QSoftKeyAction); - return d->nativePosition; -} - -void QSoftKeyAction::setNativePosition(int position) -{ - Q_D(QSoftKeyAction); - d->nativePosition = position; -} - -int QSoftKeyAction::qtContextKey() const -{ - Q_D(const QSoftKeyAction); - return d->qtContextKey; -} - -void QSoftKeyAction::setQtContextKey(int key) -{ - Q_D(QSoftKeyAction); - d->qtContextKey = key; -} diff --git a/src/gui/widgets/qsoftkeyaction.h b/src/gui/widgets/qsoftkeyaction.h deleted file mode 100644 index 77aeac0..0000000 --- a/src/gui/widgets/qsoftkeyaction.h +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSOFTKEYACTION_H -#define QSOFTKEYACTION_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -class QSoftKeyActionPrivate; - -class Q_GUI_EXPORT QSoftKeyAction : public QAction -{ - Q_OBJECT -public: - enum StandardRole { - Options=0, - Select, - Back, - Next, - Previous, - Ok, - Cancel, - Edit, - View, - BackSpace, - EndEdit, - RevertEdit, - Deselect, - Finish, - Menu, - ContextMenu, - Custom - }; - - QSoftKeyAction(QObject *parent); - QSoftKeyAction(StandardRole role, QObject *parent); - QSoftKeyAction(const QString &text, QObject *parent); - QSoftKeyAction(StandardRole role, const QString &text, QObject *parent); - QSoftKeyAction(const QIcon &icon, const QString &text, QObject *parent); - QSoftKeyAction(StandardRole role, const QIcon &icon, const QString &text, QObject *parent); - ~QSoftKeyAction(); - - StandardRole role() const; - QString roleName() const; - - void setRole(StandardRole role); - void setRole(const QString &role); - int nativePosition() const; - void setNativePosition(int position); - int qtContextKey() const; - void setQtContextKey(int position); - -private: - Q_DECLARE_PRIVATE(QSoftKeyAction) - Q_DISABLE_COPY(QSoftKeyAction) -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QSOFTKEYACTION_H diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp deleted file mode 100644 index 6c00d35..0000000 --- a/src/gui/widgets/qsoftkeystack.cpp +++ /dev/null @@ -1,306 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qsoftkeystack.h" -#include "qsoftkeystack_p.h" -#include "qapplication.h" -#include "qmainwindow.h" -#include "qevent.h" - -#if !defined(Q_WS_S60) -#include "qtoolbar.h" -#endif - -static bool isSame(const QSoftkeySet& a, const QSoftkeySet& b) -{ - bool isSame=true; - if ( a.count() != b.count()) - return false; - int index=0; - while (indexrole() != b.at(index)->role()) - return false; - if (a.at(index)->text().compare(b.at(index)->text())!=0) - return false; - index++; - } - return true; -} - -QSoftKeyStackPrivate::QSoftKeyStackPrivate() -{ - -} - -QSoftKeyStackPrivate::~QSoftKeyStackPrivate() -{ - -} - -void QSoftKeyStackPrivate::push(QSoftKeyAction *softKey) -{ - QSoftkeySet softKeySet; - softKeySet.append(softKey); - push(softKeySet); -} - -void QSoftKeyStackPrivate::push(const QList &softkeys) -{ - QSoftkeySet softKeySet(softkeys); - softKeyStack.push(softKeySet); - setNativeSoftKeys(); -} - -void QSoftKeyStackPrivate::pop() -{ - qDeleteAll(softKeyStack.pop()); - setNativeSoftKeys(); -} - -void QSoftKeyStackPrivate::popandPush(QSoftKeyAction *softKey) -{ - QSoftkeySet newSoftKeySet; - newSoftKeySet.append(softKey); - popandPush(newSoftKeySet); -} - -void QSoftKeyStackPrivate::popandPush(const QList &softkeys) -{ - QSoftkeySet oldSoftKeySet = softKeyStack.pop(); - QSoftkeySet newSoftKeySet(softkeys); - softKeyStack.push(newSoftKeySet); -#ifdef Q_WS_S60 - // Don't flicker on Symbian. - // Platforms that use QActions as native SoftKeys must always call setNativeSoftKeys - // Otherwise the following deletion of oldSoftKeySet would remove the softkeys - if (!isSame(oldSoftKeySet, newSoftKeySet)) -#endif - setNativeSoftKeys(); - qDeleteAll(oldSoftKeySet); -} - -const QSoftkeySet& QSoftKeyStackPrivate::top() -{ - return softKeyStack.top(); -} - -bool QSoftKeyStackPrivate::isEmpty() -{ - return softKeyStack.isEmpty(); -} - -QSoftKeyStack::QSoftKeyStack(QWidget *parent) - : QObject(*new QSoftKeyStackPrivate, parent) -{ - connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), SLOT(handleFocusChanged(QWidget*, QWidget*))); -} - -QSoftKeyStack::~QSoftKeyStack() -{ -} - -void QSoftKeyStack::push(QSoftKeyAction *softKey) -{ - Q_D(QSoftKeyStack); - d->push(softKey); -} - -void QSoftKeyStack::push(const QList &softKeys) -{ - Q_D(QSoftKeyStack); - d->push(softKeys); -} - -void QSoftKeyStack::pop() -{ - Q_D(QSoftKeyStack); - d->pop(); -} - -void QSoftKeyStack::popandPush(QSoftKeyAction *softKey) -{ - Q_D(QSoftKeyStack); - d->popandPush(softKey); -} - -void QSoftKeyStack::popandPush(const QList &softkeys) -{ - Q_D(QSoftKeyStack); - d->popandPush(softkeys); -} - -const QSoftkeySet& QSoftKeyStack::top() -{ - Q_D(QSoftKeyStack); - return d->top(); -} - -bool QSoftKeyStack::isEmpty() -{ - Q_D(QSoftKeyStack); - return d->isEmpty(); -} - -QList menuActionList(QWidget *widget) -{ - QList result; - - QSoftKeyAction* menu = new QSoftKeyAction(QSoftKeyAction::Menu, QString::fromLatin1("Menu"), widget); - result.append(menu); - const Qt::ContextMenuPolicy policy = widget->contextMenuPolicy(); - if (policy != Qt::NoContextMenu && policy != Qt::PreventContextMenu ) { - QSoftKeyAction* contextMenu = new QSoftKeyAction(QSoftKeyAction::ContextMenu, QString::fromLatin1("ContextMenu"), widget); - result.append(contextMenu); - } - - return result; -} - -void QSoftKeyStack::handleFocusChanged(QWidget *old, QWidget *now) -{ - return; - if (!now) - return; - QWidget *w = qApp->activeWindow(); - QMainWindow *mainWindow = qobject_cast(w); - if( !mainWindow) - return; - if (!mainWindow->hasSoftKeyStack()) - return; - QSoftKeyStack* softKeyStack = mainWindow->softKeyStack(); - if (mainWindow->menuWidget()) { - QList actionList = menuActionList(now); - if (old) - softKeyStack->popandPush(actionList); - else - softKeyStack->push(actionList); - } -} - -QMainWindow *QSoftKeyStack::mainWindowOfWidget(QWidget *widget) -{ - for (QWidget *widgetParent = widget; widgetParent; widgetParent = widgetParent->parentWidget()) - if (QMainWindow *mainWindow = qobject_cast(widgetParent)) - return mainWindow; - - return 0; -} - -QSoftKeyStack *QSoftKeyStack::softKeyStackOfWidget(QWidget *widget) -{ - QMainWindow *mainWindow = mainWindowOfWidget(widget); - return (mainWindow && mainWindow->hasSoftKeyStack()) ? mainWindow->softKeyStack() : 0; -} - -#if !defined(Q_WS_S60) -void QSoftKeyStackPrivate::handleSoftKeyPress(int command) -{ - Q_UNUSED(command) -} - -QToolBar* softKeyToolBar(QMainWindow *mainWindow) -{ - Q_ASSERT(mainWindow); - const QString toolBarName = QString::fromLatin1("SoftKeyToolBarForDebugging"); - QToolBar *result = 0; - foreach (QObject *child, mainWindow->children()) { - result = qobject_cast(child); - if (result && result->objectName() == toolBarName) - return result; - } - result = mainWindow->addToolBar(toolBarName); - result->setObjectName(toolBarName); - return result; -} - -void QSoftKeyStackPrivate::setNativeSoftKeys() -{ - return; - Q_Q(QSoftKeyStack); - QMainWindow *parent = qobject_cast(q->parent()); - if (!parent) - return; - QToolBar* toolbar = softKeyToolBar(parent); - toolbar->clear(); - foreach (const QSoftkeySet &set, softKeyStack) { - foreach (QSoftKeyAction *skAction, set) - toolbar->addAction(skAction); - toolbar->addSeparator(); - } - if (toolbar->actions().isEmpty()) { - parent->removeToolBar(toolbar); - delete toolbar; - } -} -#endif // !defined(Q_WS_S60) - -QKeyEventSoftKey::QKeyEventSoftKey(QSoftKeyAction *softKeyAction, Qt::Key key, QObject *parent) - : QObject(parent) - , m_softKeyAction(softKeyAction) - , m_key(key) -{ -} - -void QKeyEventSoftKey::addSoftKey(QSoftKeyAction::StandardRole standardRole, Qt::Key key, QWidget *actionWidget) -{ - QSoftKeyStack *stack = QSoftKeyStack::softKeyStackOfWidget(actionWidget); - if (!stack) - return; - QSoftKeyAction *action = new QSoftKeyAction(standardRole, actionWidget); - QKeyEventSoftKey *softKey = new QKeyEventSoftKey(action, key, actionWidget); - connect(action, SIGNAL(triggered()), softKey, SLOT(sendKeyEvent())); - connect(action, SIGNAL(destroyed()), softKey, SLOT(deleteLater())); - stack->popandPush(action); -} - -void QKeyEventSoftKey::removeSoftkey(QWidget *focussedWidget) -{ - QSoftKeyStack *stack = QSoftKeyStack::softKeyStackOfWidget(focussedWidget); - if (!stack) - return; - QList actionList = menuActionList(focussedWidget); - stack->popandPush(actionList); -} - -void QKeyEventSoftKey::sendKeyEvent() -{ - QApplication::postEvent(parent(), new QKeyEvent(QEvent::KeyPress, m_key, Qt::NoModifier)); -} diff --git a/src/gui/widgets/qsoftkeystack.h b/src/gui/widgets/qsoftkeystack.h deleted file mode 100644 index 423da66..0000000 --- a/src/gui/widgets/qsoftkeystack.h +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSOFTKEYSTACK_H -#define QSOFTKEYSTACK_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#define QSoftkeySet QList - -class QSoftKeyStackPrivate; -class QSoftKeyAction; -class QMainWindow; - -class Q_GUI_EXPORT QSoftKeyStack : public QObject -{ - Q_OBJECT -public: - QSoftKeyStack(QWidget *parent); - ~QSoftKeyStack(); - - void push(QSoftKeyAction *softKey); - void push(const QList &softkeys); - void pop(); - void popandPush(QSoftKeyAction *softKey); - void popandPush(const QList &softkeys); - const QSoftkeySet& top(); - bool isEmpty(); - - static QMainWindow *mainWindowOfWidget(QWidget *widget); - static QSoftKeyStack *softKeyStackOfWidget(QWidget *widget); - -private Q_SLOTS: - void handleFocusChanged(QWidget *old, QWidget *now); - -private: - Q_DECLARE_PRIVATE(QSoftKeyStack) - Q_DISABLE_COPY(QSoftKeyStack) -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QSOFTKEYSTACK_H diff --git a/src/gui/widgets/qsoftkeystack_p.h b/src/gui/widgets/qsoftkeystack_p.h deleted file mode 100644 index 4532515..0000000 --- a/src/gui/widgets/qsoftkeystack_p.h +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSOFTKEYSTACK_P_H -#define QSOFTKEYSTACK_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - - -#include "qstack.h" -#include - -#include "qsoftkeyaction.h" -#include "qsoftkeystack.h" - -QT_BEGIN_NAMESPACE - -// The following 2 defines may only be needed for s60. To be seen. -#define SOFTKEYSTART 5000 -#define SOFTKEYEND (5000 + Qt::Key_Context4-Qt::Key_Context1) - -#define QSoftkeySet QList - -class QSoftKeyStackPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QSoftKeyStack) -public: - QSoftKeyStackPrivate(); - ~QSoftKeyStackPrivate(); - - void push(QSoftKeyAction *softKey); - void push(const QList &softKeys); - void pop(); - void popandPush(QSoftKeyAction *softKey); - void popandPush(const QList &softkeys); - const QSoftkeySet& top(); - bool isEmpty(); - static void handleSoftKeyPress(int command); - -private: - void mapSoftKeys(const QSoftkeySet &top); - void setNativeSoftKeys(); - -private: - QStack softKeyStack; -}; - -class QKeyEventSoftKey : QObject -{ - Q_OBJECT -public: - QKeyEventSoftKey(QSoftKeyAction *softKeyAction, Qt::Key key, QObject *parent); - static void addSoftKey(QSoftKeyAction::StandardRole standardRole, Qt::Key key, QWidget *actionWidget); - static void removeSoftkey(QWidget *focussedWidget); -private: - QSoftKeyAction *m_softKeyAction; - Qt::Key m_key; -private Q_SLOTS: - void sendKeyEvent(); -}; - -QT_END_NAMESPACE - -#endif // QSOFTKEYSTACK_P_H diff --git a/src/gui/widgets/qsoftkeystack_s60.cpp b/src/gui/widgets/qsoftkeystack_s60.cpp deleted file mode 100644 index a315a3b..0000000 --- a/src/gui/widgets/qsoftkeystack_s60.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include -#include - -#include "private/qcore_symbian_p.h" - -#include "qsoftkeystack_p.h" -#include "qapplication.h" -#include "qmainwindow.h" - -void QSoftKeyStackPrivate::mapSoftKeys(const QSoftkeySet &top) -{ - if (top.count() == 1) { - top.at(0)->setNativePosition(2); - top.at(0)->setQtContextKey(Qt::Key_Context1); - } - else { - // FIX THIS - // veryWeirdMagic is needes as s60 5th edition sdk always panics if cba is set with index 1, this hops over it - // This needs further investigation why so that the hack can be removed - int veryWeirdMagic = 0; - for (int index = 0; index < top.count(); index++) { - top.at(index)->setNativePosition(index + veryWeirdMagic); - top.at(index)->setQtContextKey(Qt::Key_Context1 + index); - if (veryWeirdMagic == 0) - veryWeirdMagic = 1; - } - } -} - -void QSoftKeyStackPrivate::setNativeSoftKeys() -{ - return; - CCoeAppUi* appui = CEikonEnv::Static()->AppUi(); - CAknAppUi* aknAppUi = static_cast (appui); - CEikButtonGroupContainer* nativeContainer = aknAppUi->Cba(); - nativeContainer->SetCommandSetL(R_AVKON_SOFTKEYS_EMPTY_WITH_IDS); - if (softKeyStack.isEmpty()) - return; - - const QSoftkeySet top = softKeyStack.top(); - mapSoftKeys(top); - - for (int index = 0; index < top.count(); index++) { - const QSoftKeyAction* softKeyAction = top.at(index); - if (softKeyAction->role() != QSoftKeyAction::ContextMenu) { - - HBufC* text = qt_QString2HBufCNewL(softKeyAction->text()); - CleanupStack::PushL(text); - if (softKeyAction->role() == QSoftKeyAction::Menu) { - nativeContainer->SetCommandL(softKeyAction->nativePosition(), EAknSoftkeyOptions, *text); - } else { - nativeContainer->SetCommandL(softKeyAction->nativePosition(), SOFTKEYSTART + softKeyAction->qtContextKey()-Qt::Key_Context1, *text); - } - CleanupStack::PopAndDestroy(); - } - } -} - -void QSoftKeyStackPrivate::handleSoftKeyPress(int command) -{ - const QMainWindow *activeMainWindow = - qobject_cast(QApplication::activeWindow()); - if (!activeMainWindow) - return; - QSoftKeyStackPrivate *d_ptr = activeMainWindow->softKeyStack()->d_func(); - - const QSoftkeySet top = d_ptr->softKeyStack.top(); - int index = command-SOFTKEYSTART; - if (index < 0 || index >= top.count()) { - // ### FIX THIS, add proper error handling, now fail quietly - return; - } - - top.at(index)->activate(QAction::Trigger); -} - diff --git a/src/gui/widgets/widgets.pri b/src/gui/widgets/widgets.pri index 0c0641a..150eed7 100644 --- a/src/gui/widgets/widgets.pri +++ b/src/gui/widgets/widgets.pri @@ -79,9 +79,7 @@ HEADERS += \ widgets/qplaintextedit.h \ widgets/qplaintextedit_p.h \ widgets/qprintpreviewwidget.h \ - widgets/qsoftkeyaction.h \ - widgets/qsoftkeystack.h \ - widgets/qsoftkeystack_p.h + widgets/qkeyeventsoftkey.h \ SOURCES += \ widgets/qabstractbutton.cpp \ widgets/qabstractslider.cpp \ @@ -141,8 +139,7 @@ SOURCES += \ widgets/qtoolbararealayout.cpp \ widgets/qplaintextedit.cpp \ widgets/qprintpreviewwidget.cpp \ - widgets/qsoftkeyaction.cpp \ - widgets/qsoftkeystack.cpp + widgets/qkeyeventsoftkey.cpp \ !embedded:mac { HEADERS += widgets/qmacnativewidget_mac.h \ @@ -167,5 +164,4 @@ wince*: { symbian*: { SOURCES += \ widgets/qmenu_symbian.cpp \ - widgets/qsoftkeystack_s60.cpp } -- cgit v0.12 From fcb5ca1ef0a1c1639624d951b03750abc631e60d Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Sat, 6 Jun 2009 16:18:14 +0200 Subject: Added helper class to make adding/removing softkeys easier --- src/gui/widgets/qkeyeventsoftkey.cpp | 78 ++++++++++++++++++++++++++++++++++++ src/gui/widgets/qkeyeventsoftkey.h | 71 ++++++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+) create mode 100644 src/gui/widgets/qkeyeventsoftkey.cpp create mode 100644 src/gui/widgets/qkeyeventsoftkey.h diff --git a/src/gui/widgets/qkeyeventsoftkey.cpp b/src/gui/widgets/qkeyeventsoftkey.cpp new file mode 100644 index 0000000..e836dfe --- /dev/null +++ b/src/gui/widgets/qkeyeventsoftkey.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qkeyeventsoftkey.h" + +QT_BEGIN_NAMESPACE + +QKeyEventSoftKey::QKeyEventSoftKey(QAction *softKeyAction, Qt::Key key, QObject *parent) + : QObject(parent) + , m_softKeyAction(softKeyAction) + , m_key(key) +{ + +} + +void QKeyEventSoftKey::addSoftKey(QAction::SoftKeyRole standardRole, Qt::Key key, QWidget *actionWidget) +{ + QAction *action = new QAction(actionWidget); + action->setSoftKeyRole(standardRole); + QKeyEventSoftKey *softKey = new QKeyEventSoftKey(action, key, actionWidget); + connect(action, SIGNAL(triggered()), softKey, SLOT(sendKeyEvent())); + connect(action, SIGNAL(destroyed()), softKey, SLOT(deleteLater())); + actionWidget->setSoftKeys(action); +} + +void QKeyEventSoftKey::removeSoftkey(QWidget *focussedWidget) +{ + focussedWidget->setSoftKeys(0); +} + +void QKeyEventSoftKey::sendKeyEvent() +{ + QApplication::postEvent(parent(), new QKeyEvent(QEvent::KeyPress, m_key, Qt::NoModifier)); +} + +QT_END_NAMESPACE + +#include "moc_qkeyeventsoftkey.cpp" + +#endif // QT_NO_ACTION diff --git a/src/gui/widgets/qkeyeventsoftkey.h b/src/gui/widgets/qkeyeventsoftkey.h new file mode 100644 index 0000000..92cf0df --- /dev/null +++ b/src/gui/widgets/qkeyeventsoftkey.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QKEYEVENSOFTKEY_H +#define QKEYEVENSOFTKEY_H + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Gui) + +#include "qaction.h" + +class QKeyEventSoftKey : QObject +{ + Q_OBJECT +public: + QKeyEventSoftKey(QAction *softKeyAction, Qt::Key key, QObject *parent); + static void addSoftKey(QAction::StandardRole standardRole, Qt::Key key, QWidget *actionWidget); + static void removeSoftkey(QWidget *focussedWidget); +private: + QAction *m_softKeyAction; + Qt::Key m_key; +private Q_SLOTS: + void sendKeyEvent(); +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif //QKEYEVENSOFTKEY_H -- cgit v0.12 From 93922e26a2411c0f11e7cdc49b306823e23cda8b Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Sat, 6 Jun 2009 18:40:00 +0200 Subject: Fixes to make gui compile after clean configure. Removal of QSoftKeyStack broke compilation on clean environment... --- examples/widgets/stylesheet/mainwindow.cpp | 3 --- src/gui/itemviews/qabstractitemview.cpp | 3 ++- src/gui/kernel/qwidget_p.h | 3 +++ src/gui/kernel/qwidget_s60.cpp | 3 --- src/gui/widgets/qkeyeventsoftkey.cpp | 3 ++- src/gui/widgets/qkeyeventsoftkey.h | 8 +++++--- src/gui/widgets/widgets.pri | 12 ++++++------ 7 files changed, 18 insertions(+), 17 deletions(-) diff --git a/examples/widgets/stylesheet/mainwindow.cpp b/examples/widgets/stylesheet/mainwindow.cpp index a0a38ad..a1307a8 100644 --- a/examples/widgets/stylesheet/mainwindow.cpp +++ b/examples/widgets/stylesheet/mainwindow.cpp @@ -46,9 +46,6 @@ MainWindow::MainWindow() { - QSoftKeyStack* stack = new QSoftKeyStack(this); - setSoftKeyStack(stack); - ui.setupUi(this); ui.nameLabel->setProperty("class", "mandatory QLabel"); diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index 187e2cd..69e630e 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -61,6 +61,7 @@ #ifndef QT_NO_ACCESSIBILITY #include #endif +#include QT_BEGIN_NAMESPACE @@ -2003,7 +2004,7 @@ void QAbstractItemView::keyPressEvent(QKeyEvent *event) if (QApplication::keypadNavigationEnabled()) { if (!hasEditFocus()) { setEditFocus(true); - QKeyEventSoftKey::addSoftKey(QAction::Back, Qt::Key_Back, this); + QKeyEventSoftKey::addSoftKey(QAction::BackSoftKey, Qt::Key_Back, this); return; } } diff --git a/src/gui/kernel/qwidget_p.h b/src/gui/kernel/qwidget_p.h index 9a606dc..2119849 100644 --- a/src/gui/kernel/qwidget_p.h +++ b/src/gui/kernel/qwidget_p.h @@ -84,6 +84,9 @@ class RDrawableWindow; class CCoeControl; class CAknTitlePane; class CAknContextPane; +// The following 2 defines may only be needed for s60. To be seen. +#define SOFTKEYSTART 5000 +#define SOFTKEYEND (5000 + Qt::Key_Context4-Qt::Key_Context1) #endif QT_BEGIN_NAMESPACE diff --git a/src/gui/kernel/qwidget_s60.cpp b/src/gui/kernel/qwidget_s60.cpp index a23469e..4e03206 100644 --- a/src/gui/kernel/qwidget_s60.cpp +++ b/src/gui/kernel/qwidget_s60.cpp @@ -62,9 +62,6 @@ QWidget *QWidgetPrivate::mouseGrabber = 0; QWidget *QWidgetPrivate::keyboardGrabber = 0; #define QSoftkeySet QList -// The following 2 defines may only be needed for s60. To be seen. -#define SOFTKEYSTART 5000 -#define SOFTKEYEND (5000 + Qt::Key_Context4-Qt::Key_Context1) static void mapSoftKeys(const QSoftkeySet &softkeys) { diff --git a/src/gui/widgets/qkeyeventsoftkey.cpp b/src/gui/widgets/qkeyeventsoftkey.cpp index e836dfe..08f5c6f 100644 --- a/src/gui/widgets/qkeyeventsoftkey.cpp +++ b/src/gui/widgets/qkeyeventsoftkey.cpp @@ -39,6 +39,8 @@ ** ****************************************************************************/ +#include "qapplication.h" +#include "qevent.h" #include "qkeyeventsoftkey.h" QT_BEGIN_NAMESPACE @@ -75,4 +77,3 @@ QT_END_NAMESPACE #include "moc_qkeyeventsoftkey.cpp" -#endif // QT_NO_ACTION diff --git a/src/gui/widgets/qkeyeventsoftkey.h b/src/gui/widgets/qkeyeventsoftkey.h index 92cf0df..fd69907 100644 --- a/src/gui/widgets/qkeyeventsoftkey.h +++ b/src/gui/widgets/qkeyeventsoftkey.h @@ -42,20 +42,22 @@ #ifndef QKEYEVENSOFTKEY_H #define QKEYEVENSOFTKEY_H +#include +#include "QtGui/qaction.h" QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(Gui) -#include "qaction.h" -class QKeyEventSoftKey : QObject + +class Q_GUI_EXPORT QKeyEventSoftKey : QObject { Q_OBJECT public: QKeyEventSoftKey(QAction *softKeyAction, Qt::Key key, QObject *parent); - static void addSoftKey(QAction::StandardRole standardRole, Qt::Key key, QWidget *actionWidget); + static void addSoftKey(QAction::SoftKeyRole standardRole, Qt::Key key, QWidget *actionWidget); static void removeSoftkey(QWidget *focussedWidget); private: QAction *m_softKeyAction; diff --git a/src/gui/widgets/widgets.pri b/src/gui/widgets/widgets.pri index 150eed7..d0f981c 100644 --- a/src/gui/widgets/widgets.pri +++ b/src/gui/widgets/widgets.pri @@ -25,6 +25,7 @@ HEADERS += \ widgets/qframe.h \ widgets/qframe_p.h \ widgets/qgroupbox.h \ + widgets/qkeyeventsoftkey.h \ widgets/qlabel.h \ widgets/qlabel_p.h \ widgets/qlcdnumber.h \ @@ -78,8 +79,8 @@ HEADERS += \ widgets/qtoolbararealayout_p.h \ widgets/qplaintextedit.h \ widgets/qplaintextedit_p.h \ - widgets/qprintpreviewwidget.h \ - widgets/qkeyeventsoftkey.h \ + widgets/qprintpreviewwidget.h + SOURCES += \ widgets/qabstractbutton.cpp \ widgets/qabstractslider.cpp \ @@ -97,6 +98,7 @@ SOURCES += \ widgets/qfontcombobox.cpp \ widgets/qframe.cpp \ widgets/qgroupbox.cpp \ + widgets/qkeyeventsoftkey.cpp \ widgets/qlabel.cpp \ widgets/qlcdnumber.cpp \ widgets/qlineedit.cpp \ @@ -138,8 +140,7 @@ SOURCES += \ widgets/qwidgetanimator.cpp \ widgets/qtoolbararealayout.cpp \ widgets/qplaintextedit.cpp \ - widgets/qprintpreviewwidget.cpp \ - widgets/qkeyeventsoftkey.cpp \ + widgets/qprintpreviewwidget.cpp !embedded:mac { HEADERS += widgets/qmacnativewidget_mac.h \ @@ -162,6 +163,5 @@ wince*: { } symbian*: { - SOURCES += \ - widgets/qmenu_symbian.cpp \ + SOURCES += widgets/qmenu_symbian.cpp } -- cgit v0.12 From 9420db9284f20e28239d1c6e8a4cccf7707c014e Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Sat, 6 Jun 2009 18:50:17 +0200 Subject: Fixed bug that caused the softkeys list not to be cleared after the softkeys in the list were deleted --- src/gui/kernel/qwidget.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 0a7fea3..7a8b143 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -11528,6 +11528,7 @@ void QWidget::setSoftKeys(QAction *softKey) { Q_D(QWidget); qDeleteAll(d->softKeys); + d->softKeys.clear(); if (softKey) d->softKeys.append(softKey); // d->setNativeSoftKeys(softkeys); @@ -11537,6 +11538,7 @@ void QWidget::setSoftKeys(const QList &softKeys) { Q_D(QWidget); qDeleteAll(d->softKeys); + d->softKeys.clear(); for(int i = 0; i < softKeys.count(); i++) d->softKeys.append(softKeys.at(i)); -- cgit v0.12 From ef0f6267822c782f0b555e15ddab24c41c51d2e8 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Sat, 6 Jun 2009 19:37:37 +0200 Subject: Added support for setting softkeys dynamically --- src/gui/kernel/qwidget.cpp | 6 ++++-- src/gui/kernel/qwidget_s60.cpp | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 7a8b143..e82fbd2 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -11531,7 +11531,8 @@ void QWidget::setSoftKeys(QAction *softKey) d->softKeys.clear(); if (softKey) d->softKeys.append(softKey); -// d->setNativeSoftKeys(softkeys); + if (QApplication::focusWidget() == this) + d->setNativeSoftKeys(this->softKeys()); } void QWidget::setSoftKeys(const QList &softKeys) @@ -11542,7 +11543,8 @@ void QWidget::setSoftKeys(const QList &softKeys) for(int i = 0; i < softKeys.count(); i++) d->softKeys.append(softKeys.at(i)); - // d->setNativeSoftKeys(softkeys); + if (QApplication::focusWidget() == this) + d->setNativeSoftKeys(this->softKeys()); } /*! \fn const QX11Info &QWidget::x11Info() const diff --git a/src/gui/kernel/qwidget_s60.cpp b/src/gui/kernel/qwidget_s60.cpp index 4e03206..cb2fc8f 100644 --- a/src/gui/kernel/qwidget_s60.cpp +++ b/src/gui/kernel/qwidget_s60.cpp @@ -107,7 +107,8 @@ static bool isSame(const QList& a, const QList& b) void QWidgetPrivate::setNativeSoftKeys(const QList &softkeys) { - if (QApplication::focusWidget()) { + Q_Q(QWidget); + if (QApplication::focusWidget() && q!=QApplication::focusWidget()) { QList old = QApplication::focusWidget()->softKeys(); if (isSame(old, softkeys )) return; -- cgit v0.12 From 5edc6f4e88aa7896be0e69a6bcf2365adb6b70b4 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Sat, 6 Jun 2009 19:38:17 +0200 Subject: Added implementation to get default role names --- src/gui/widgets/qkeyeventsoftkey.cpp | 26 ++++++++++++++++++++++++++ src/gui/widgets/qkeyeventsoftkey.h | 1 + 2 files changed, 27 insertions(+) diff --git a/src/gui/widgets/qkeyeventsoftkey.cpp b/src/gui/widgets/qkeyeventsoftkey.cpp index 08f5c6f..bb236cc 100644 --- a/src/gui/widgets/qkeyeventsoftkey.cpp +++ b/src/gui/widgets/qkeyeventsoftkey.cpp @@ -53,10 +53,36 @@ QKeyEventSoftKey::QKeyEventSoftKey(QAction *softKeyAction, Qt::Key key, QObject } +QString QKeyEventSoftKey::roleText(QAction::SoftKeyRole role) +{ + switch (role) { + case QAction::OptionsSoftKey: + return QAction::tr("Options"); + case QAction::SelectSoftKey: + return QAction::tr("Select"); + case QAction::BackSoftKey: + return QAction::tr("Back"); + case QAction::NextSoftKey: + return QAction::tr("Next"); + case QAction::PreviousSoftKey: + return QAction::tr("Previous"); + case QAction::OkSoftKey: + return QAction::tr("Ok"); + case QAction::CancelSoftKey: + return QAction::tr("Cancel"); + case QAction::EditSoftKey: + return QAction::tr("Edit"); + case QAction::ViewSoftKey: + return QAction::tr("View"); + default: + return QString(); + }; +} void QKeyEventSoftKey::addSoftKey(QAction::SoftKeyRole standardRole, Qt::Key key, QWidget *actionWidget) { QAction *action = new QAction(actionWidget); action->setSoftKeyRole(standardRole); + action->setText(roleText(standardRole)); QKeyEventSoftKey *softKey = new QKeyEventSoftKey(action, key, actionWidget); connect(action, SIGNAL(triggered()), softKey, SLOT(sendKeyEvent())); connect(action, SIGNAL(destroyed()), softKey, SLOT(deleteLater())); diff --git a/src/gui/widgets/qkeyeventsoftkey.h b/src/gui/widgets/qkeyeventsoftkey.h index fd69907..83449c7 100644 --- a/src/gui/widgets/qkeyeventsoftkey.h +++ b/src/gui/widgets/qkeyeventsoftkey.h @@ -57,6 +57,7 @@ class Q_GUI_EXPORT QKeyEventSoftKey : QObject Q_OBJECT public: QKeyEventSoftKey(QAction *softKeyAction, Qt::Key key, QObject *parent); + static QString roleText(QAction::SoftKeyRole role); static void addSoftKey(QAction::SoftKeyRole standardRole, Qt::Key key, QWidget *actionWidget); static void removeSoftkey(QWidget *focussedWidget); private: -- cgit v0.12 From 267891cb23e0e751873f9a6cf5dd951287c0e5e5 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Sat, 6 Jun 2009 19:38:52 +0200 Subject: Changed combobox to use popup as a parent when setting softkeys. This enables the softkeys to actually be visible on the screen --- src/gui/widgets/qcombobox.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp index aa90909..01fcf34 100644 --- a/src/gui/widgets/qcombobox.cpp +++ b/src/gui/widgets/qcombobox.cpp @@ -2438,7 +2438,7 @@ void QComboBox::showPopup() #ifdef QT_KEYPAD_NAVIGATION if (QApplication::keypadNavigationEnabled()) view()->setEditFocus(true); - QKeyEventSoftKey::addSoftKey(QAction::CancelSoftKey, Qt::Key_Back, this); + QKeyEventSoftKey::addSoftKey(QAction::CancelSoftKey, Qt::Key_Back, view()); #endif } -- cgit v0.12 From 7661082e4c1851ab2fd6409d8689dc8b08d793b9 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Sun, 7 Jun 2009 23:21:47 +0200 Subject: Make the linker happy on non-Q_WS_S60 --- src/gui/kernel/qwidget.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index e82fbd2..69e2d84 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -4880,6 +4880,13 @@ void QWidget::render(QPainter *painter, const QPoint &targetOffset, d->extra->inRenderWithPainter = false; } +#if !defined(Q_WS_S60) +void QWidgetPrivate::setNativeSoftKeys(const QList &softkeys) +{ + Q_UNUSED(softkeys) +} +#endif // !defined(Q_WS_S60) + bool QWidgetPrivate::isAboutToShow() const { if (data.in_show) -- cgit v0.12 From 5d749ad1b67a8d5ba77800567ffa473f5ad1d9f5 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Mon, 8 Jun 2009 09:49:05 +0200 Subject: Fixed parsing error when doing configure+compile in clean environment --- src/gui/widgets/widgets.pri | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/gui/widgets/widgets.pri b/src/gui/widgets/widgets.pri index d0f981c..f395c76 100644 --- a/src/gui/widgets/widgets.pri +++ b/src/gui/widgets/widgets.pri @@ -25,7 +25,6 @@ HEADERS += \ widgets/qframe.h \ widgets/qframe_p.h \ widgets/qgroupbox.h \ - widgets/qkeyeventsoftkey.h \ widgets/qlabel.h \ widgets/qlabel_p.h \ widgets/qlcdnumber.h \ @@ -79,8 +78,8 @@ HEADERS += \ widgets/qtoolbararealayout_p.h \ widgets/qplaintextedit.h \ widgets/qplaintextedit_p.h \ - widgets/qprintpreviewwidget.h - + widgets/qprintpreviewwidget.h \ + widgets/qkeyeventsoftkey.h SOURCES += \ widgets/qabstractbutton.cpp \ widgets/qabstractslider.cpp \ @@ -98,7 +97,6 @@ SOURCES += \ widgets/qfontcombobox.cpp \ widgets/qframe.cpp \ widgets/qgroupbox.cpp \ - widgets/qkeyeventsoftkey.cpp \ widgets/qlabel.cpp \ widgets/qlcdnumber.cpp \ widgets/qlineedit.cpp \ @@ -140,7 +138,8 @@ SOURCES += \ widgets/qwidgetanimator.cpp \ widgets/qtoolbararealayout.cpp \ widgets/qplaintextedit.cpp \ - widgets/qprintpreviewwidget.cpp + widgets/qprintpreviewwidget.cpp \ + widgets/qkeyeventsoftkey.cpp !embedded:mac { HEADERS += widgets/qmacnativewidget_mac.h \ -- cgit v0.12 From 8938f242414cc67f8a4081222857bfeb16bb5f37 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Mon, 8 Jun 2009 10:33:38 +0200 Subject: Implemented context sensitive menu item --- src/gui/widgets/qmenu_symbian.cpp | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/gui/widgets/qmenu_symbian.cpp b/src/gui/widgets/qmenu_symbian.cpp index e422882..ed2ea46 100644 --- a/src/gui/widgets/qmenu_symbian.cpp +++ b/src/gui/widgets/qmenu_symbian.cpp @@ -90,6 +90,16 @@ bool menuExists() return true; } +static bool hasContextMenu(QWidget* widget) +{ + if (!widget) + return false; + const Qt::ContextMenuPolicy policy = widget->contextMenuPolicy(); + if (policy != Qt::NoContextMenu && policy != Qt::PreventContextMenu ) { + return true; + } + return false; +} // ### FIX THIS, copy/paste of original (faulty) stripped text implementation. // Implementation should be removed from QAction implementation to some generic place static QString qt_strippedText_copy_from_qaction(QString s) @@ -212,24 +222,12 @@ static void rebuildMenu() QMenuBarPrivate *mb = 0; QWidget *w = qApp->activeWindow(); QMainWindow *mainWindow = qobject_cast(w); - /* if ((mainWindow) && mainWindow->hasSoftKeyStack()) { - QSoftKeyStack* softKeyStack = mainWindow->softKeyStack(); - if (!softKeyStack->isEmpty()) { - const QSoftkeySet& softKeyTop = softKeyStack->top(); - int index=0; - bool found=false; - while( indexrole(); - if(softAction->role() == QSoftKeyAction::ContextMenu) { - widgetWithContextMenu = softAction->parentWidget(); - found=true; - } - index++; - } - } + QWidget* focusWidget = QApplication::focusWidget(); + if (focusWidget) { + if (hasContextMenu(focusWidget)) + widgetWithContextMenu = focusWidget; } -*/ + if (w) { mb = menubars()->value(w); qt_symbian_menu_static_cmd_id = QT_FIRST_MENU_ITEM; -- cgit v0.12 From 5b0f60b7eae6daac9ef45726cdc8cde18bcb69f9 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Mon, 8 Jun 2009 10:47:00 +0200 Subject: Set empty buttons by default --- src/s60main/qts60mainappui.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/s60main/qts60mainappui.cpp b/src/s60main/qts60mainappui.cpp index 47312af..7d38f33 100644 --- a/src/s60main/qts60mainappui.cpp +++ b/src/s60main/qts60mainappui.cpp @@ -68,6 +68,9 @@ void CQtS60MainAppUi::ConstructL() // even these flags are defined BaseConstructL(CAknAppUi::EAknEnableSkin); + CEikButtonGroupContainer* nativeContainer = Cba(); + nativeContainer->SetCommandSetL(R_AVKON_SOFTKEYS_EMPTY_WITH_IDS); + // Create async callback to call Qt main, // this is required to give S60 app FW to finish starting correctly TCallBack callBack( OpenCMainStaticCallBack, this ); -- cgit v0.12 From fb8dccabd68a854c50adfc3f1e77badc3ff50ec8 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Mon, 8 Jun 2009 12:00:42 +0200 Subject: Removed QSoftkeySet as it wasn't used anymore --- src/gui/kernel/qwidget_s60.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/gui/kernel/qwidget_s60.cpp b/src/gui/kernel/qwidget_s60.cpp index cb2fc8f..858320c 100644 --- a/src/gui/kernel/qwidget_s60.cpp +++ b/src/gui/kernel/qwidget_s60.cpp @@ -61,9 +61,7 @@ extern bool qt_nograb(); QWidget *QWidgetPrivate::mouseGrabber = 0; QWidget *QWidgetPrivate::keyboardGrabber = 0; -#define QSoftkeySet QList - -static void mapSoftKeys(const QSoftkeySet &softkeys) +static void mapSoftKeys(const QList &softkeys) { /* if (softkeys.count() == 1 && softkeys.at(0)->menuRole()==QAction::MenuSoftKey) { softkeys.at(0)->setNativePosition(0); -- cgit v0.12 From 46cb3a09f4eedb2d4c612a6d73e9e0f14237350c Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Mon, 8 Jun 2009 17:08:26 +0200 Subject: Fixes from code review --- src/gui/kernel/qaction.cpp | 3 ++- src/gui/kernel/qaction.h | 1 - src/gui/kernel/qapplication_s60.cpp | 6 ++--- src/gui/kernel/qwidget.cpp | 39 ++++++++++++++++++++++++-------- src/gui/kernel/qwidget.h | 2 +- src/gui/kernel/qwidget_p.h | 6 ++--- src/gui/kernel/qwidget_s60.cpp | 7 +++--- src/gui/widgets/qkeyeventsoftkey.cpp | 44 ++++++++++++++++++------------------ src/gui/widgets/qkeyeventsoftkey.h | 4 ++-- src/gui/widgets/qmainwindow.cpp | 2 +- src/gui/widgets/qmenu_symbian.cpp | 11 ++++----- src/gui/widgets/qmenubar_p.h | 2 +- 12 files changed, 70 insertions(+), 57 deletions(-) diff --git a/src/gui/kernel/qaction.cpp b/src/gui/kernel/qaction.cpp index e32416a..8263cbc 100644 --- a/src/gui/kernel/qaction.cpp +++ b/src/gui/kernel/qaction.cpp @@ -1353,7 +1353,7 @@ QAction::MenuRole QAction::menuRole() const \since 4.6 This indicates what softkey action this action is. Usually used on mobile - platforms to map QActions no hardware keys. + platforms to map QActions to hardware keys. The softkey role can be changed any time. */ @@ -1372,6 +1372,7 @@ QAction::SoftKeyRole QAction::softKeyRole() const Q_D(const QAction); return d->softKeyRole; } + /*! \property QAction::iconVisibleInMenu \brief Whether or not an action should show an icon in a menu diff --git a/src/gui/kernel/qaction.h b/src/gui/kernel/qaction.h index 6725f42..8791a5c 100644 --- a/src/gui/kernel/qaction.h +++ b/src/gui/kernel/qaction.h @@ -96,7 +96,6 @@ public: EndEditSoftKey, RevertEditSoftKey, DeselectSoftKey, FinishSoftKey, MenuSoftKey, ContextMenuSoftKey, Key1SoftKey, Key2SoftKey, Key3SoftKey, Key4SoftKey, CustomSoftKey }; - explicit QAction(QObject* parent); QAction(const QString &text, QObject* parent); QAction(const QIcon &icon, const QString &text, QObject* parent); diff --git a/src/gui/kernel/qapplication_s60.cpp b/src/gui/kernel/qapplication_s60.cpp index 6ee7899..0ae4c00 100644 --- a/src/gui/kernel/qapplication_s60.cpp +++ b/src/gui/kernel/qapplication_s60.cpp @@ -1,5 +1,5 @@ /**************************************************************************** -1** +** ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) ** @@ -1067,9 +1067,7 @@ void QApplication::symbianHandleCommand(int command) int index= command-SOFTKEYSTART; QWidget* focused = QApplication::focusWidget(); const QList& softKeys = focused->softKeys(); - if (index>=softKeys.count()) { - // Assert horrible state error - } + Q_ASSERT(indexactivate(QAction::Trigger); } else diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 9d4f176..3a22ee9 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -4881,7 +4881,7 @@ void QWidget::render(QPainter *painter, const QPoint &targetOffset, } #if !defined(Q_WS_S60) -void QWidgetPrivate::setNativeSoftKeys(const QList &softkeys) +void QWidgetPrivate::setSoftKeys_sys(const QList &softkeys) { Q_UNUSED(softkeys) } @@ -5723,7 +5723,7 @@ bool QWidget::hasFocus() const void QWidget::setFocus(Qt::FocusReason reason) { Q_D(QWidget); - d->setNativeSoftKeys(softKeys()); + d->setSoftKeys_sys(softKeys()); if (!isEnabled()) return; @@ -11520,19 +11520,33 @@ void QWidget::clearMask() setMask(QRegion()); } +/*! + Returns the (possibly empty) list of this widget's softkeys. + Returned list cannot be changed. Softkeys should be added + and removed via method called setSoftKeys + + \sa setSoftKey(), setSoftKeys() +*/ const QList& QWidget::softKeys() const { Q_D(const QWidget); if( d->softKeys.count() > 0) return d->softKeys; - if (isWindow() || !parentWidget()) return d->softKeys; - + return parentWidget()->softKeys(); } -void QWidget::setSoftKeys(QAction *softKey) +/*! + Sets the softkey \a softkey to this widget's list of softkeys, + Setting 0 as softkey will clear all the existing softkeys set + to the widget + A QWidget can have 0 or more softkeys + + \sa softKeys(), setSoftKeys() +*/ +void QWidget::setSoftKey(QAction *softKey) { Q_D(QWidget); qDeleteAll(d->softKeys); @@ -11540,19 +11554,24 @@ void QWidget::setSoftKeys(QAction *softKey) if (softKey) d->softKeys.append(softKey); if (QApplication::focusWidget() == this) - d->setNativeSoftKeys(this->softKeys()); + d->setSoftKeys_sys(this->softKeys()); } +/*! + Sets the list of softkeys \a softkeys to this widget's list of softkeys, + A QWidget can have 0 or more softkeys + + \sa softKeys(), setSoftKey() +*/ void QWidget::setSoftKeys(const QList &softKeys) { Q_D(QWidget); qDeleteAll(d->softKeys); d->softKeys.clear(); - for(int i = 0; i < softKeys.count(); i++) - d->softKeys.append(softKeys.at(i)); - + d->softKeys = softKeys; + if (QApplication::focusWidget() == this) - d->setNativeSoftKeys(this->softKeys()); + d->setSoftKeys_sys(this->softKeys()); } /*! \fn const QX11Info &QWidget::x11Info() const diff --git a/src/gui/kernel/qwidget.h b/src/gui/kernel/qwidget.h index 36a30ac..3f9caee 100644 --- a/src/gui/kernel/qwidget.h +++ b/src/gui/kernel/qwidget.h @@ -555,7 +555,7 @@ public: QList actions() const; #endif const QList& softKeys() const; - void setSoftKeys(QAction *softKey); + void setSoftKey(QAction *softKey); void setSoftKeys(const QList &softKeys); QWidget *parentWidget() const; diff --git a/src/gui/kernel/qwidget_p.h b/src/gui/kernel/qwidget_p.h index 2119849..084439c 100644 --- a/src/gui/kernel/qwidget_p.h +++ b/src/gui/kernel/qwidget_p.h @@ -85,8 +85,8 @@ class CCoeControl; class CAknTitlePane; class CAknContextPane; // The following 2 defines may only be needed for s60. To be seen. -#define SOFTKEYSTART 5000 -#define SOFTKEYEND (5000 + Qt::Key_Context4-Qt::Key_Context1) +const int SOFTKEYSTART=5000; +const int SOFTKEYEND=5004; #endif QT_BEGIN_NAMESPACE @@ -227,7 +227,7 @@ public: explicit QWidgetPrivate(int version = QObjectPrivateVersion); ~QWidgetPrivate(); - void setNativeSoftKeys(const QList &softkeys); + void setSoftKeys_sys(const QList &softkeys); QWExtra *extraData() const; QTLWExtra *topData() const; QTLWExtra *maybeTopData() const; diff --git a/src/gui/kernel/qwidget_s60.cpp b/src/gui/kernel/qwidget_s60.cpp index 858320c..2a83fc7 100644 --- a/src/gui/kernel/qwidget_s60.cpp +++ b/src/gui/kernel/qwidget_s60.cpp @@ -86,9 +86,8 @@ static void mapSoftKeys(const QList &softkeys) */ } -static bool isSame(const QList& a, const QList& b) +static bool isEqual(const QList& a, const QList& b) { - bool isSame=true; if ( a.count() != b.count()) return false; int index=0; @@ -103,12 +102,12 @@ static bool isSame(const QList& a, const QList& b) } -void QWidgetPrivate::setNativeSoftKeys(const QList &softkeys) +void QWidgetPrivate::setSoftKeys_sys(const QList &softkeys) { Q_Q(QWidget); if (QApplication::focusWidget() && q!=QApplication::focusWidget()) { QList old = QApplication::focusWidget()->softKeys(); - if (isSame(old, softkeys )) + if (isEqual(old, softkeys )) return; } diff --git a/src/gui/widgets/qkeyeventsoftkey.cpp b/src/gui/widgets/qkeyeventsoftkey.cpp index bb236cc..f5f10fc 100644 --- a/src/gui/widgets/qkeyeventsoftkey.cpp +++ b/src/gui/widgets/qkeyeventsoftkey.cpp @@ -56,26 +56,26 @@ QKeyEventSoftKey::QKeyEventSoftKey(QAction *softKeyAction, Qt::Key key, QObject QString QKeyEventSoftKey::roleText(QAction::SoftKeyRole role) { switch (role) { - case QAction::OptionsSoftKey: - return QAction::tr("Options"); - case QAction::SelectSoftKey: - return QAction::tr("Select"); - case QAction::BackSoftKey: - return QAction::tr("Back"); - case QAction::NextSoftKey: - return QAction::tr("Next"); - case QAction::PreviousSoftKey: - return QAction::tr("Previous"); - case QAction::OkSoftKey: - return QAction::tr("Ok"); - case QAction::CancelSoftKey: - return QAction::tr("Cancel"); - case QAction::EditSoftKey: - return QAction::tr("Edit"); - case QAction::ViewSoftKey: - return QAction::tr("View"); - default: - return QString(); + case QAction::OptionsSoftKey: + return QAction::tr("Options"); + case QAction::SelectSoftKey: + return QAction::tr("Select"); + case QAction::BackSoftKey: + return QAction::tr("Back"); + case QAction::NextSoftKey: + return QAction::tr("Next"); + case QAction::PreviousSoftKey: + return QAction::tr("Previous"); + case QAction::OkSoftKey: + return QAction::tr("Ok"); + case QAction::CancelSoftKey: + return QAction::tr("Cancel"); + case QAction::EditSoftKey: + return QAction::tr("Edit"); + case QAction::ViewSoftKey: + return QAction::tr("View"); + default: + return QString(); }; } void QKeyEventSoftKey::addSoftKey(QAction::SoftKeyRole standardRole, Qt::Key key, QWidget *actionWidget) @@ -86,12 +86,12 @@ void QKeyEventSoftKey::addSoftKey(QAction::SoftKeyRole standardRole, Qt::Key key QKeyEventSoftKey *softKey = new QKeyEventSoftKey(action, key, actionWidget); connect(action, SIGNAL(triggered()), softKey, SLOT(sendKeyEvent())); connect(action, SIGNAL(destroyed()), softKey, SLOT(deleteLater())); - actionWidget->setSoftKeys(action); + actionWidget->setSoftKey(action); } void QKeyEventSoftKey::removeSoftkey(QWidget *focussedWidget) { - focussedWidget->setSoftKeys(0); + focussedWidget->setSoftKey(0); } void QKeyEventSoftKey::sendKeyEvent() diff --git a/src/gui/widgets/qkeyeventsoftkey.h b/src/gui/widgets/qkeyeventsoftkey.h index 83449c7..0b95efb 100644 --- a/src/gui/widgets/qkeyeventsoftkey.h +++ b/src/gui/widgets/qkeyeventsoftkey.h @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#ifndef QKEYEVENSOFTKEY_H -#define QKEYEVENSOFTKEY_H +#ifndef QKEYEVENTSOFTKEY_H +#define QKEYEVENTSOFTKEY_H #include #include "QtGui/qaction.h" diff --git a/src/gui/widgets/qmainwindow.cpp b/src/gui/widgets/qmainwindow.cpp index 90c5db9..2f3b412 100644 --- a/src/gui/widgets/qmainwindow.cpp +++ b/src/gui/widgets/qmainwindow.cpp @@ -484,7 +484,7 @@ void QMainWindow::setMenuBar(QMenuBar *menuBar) if (menuBar) { QAction* menu = new QAction(QString::fromLatin1("Menu"), this); menu->setSoftKeyRole(QAction::MenuSoftKey); - setSoftKeys(menu); + setSoftKey(menu); } } diff --git a/src/gui/widgets/qmenu_symbian.cpp b/src/gui/widgets/qmenu_symbian.cpp index ed2ea46..49bcc21 100644 --- a/src/gui/widgets/qmenu_symbian.cpp +++ b/src/gui/widgets/qmenu_symbian.cpp @@ -40,8 +40,6 @@ #include "qmenu.h" #include "qapplication.h" -#include "qmainwindow.h" -#include "qtoolbar.h" #include "qevent.h" #include "qstyle.h" #include "qdebug.h" @@ -221,13 +219,12 @@ static void rebuildMenu() widgetWithContextMenu = 0; QMenuBarPrivate *mb = 0; QWidget *w = qApp->activeWindow(); - QMainWindow *mainWindow = qobject_cast(w); QWidget* focusWidget = QApplication::focusWidget(); if (focusWidget) { if (hasContextMenu(focusWidget)) widgetWithContextMenu = focusWidget; } - + if (w) { mb = menubars()->value(w); qt_symbian_menu_static_cmd_id = QT_FIRST_MENU_ITEM; @@ -389,7 +386,7 @@ void QMenuBarPrivate::QSymbianMenuBarPrivate::removeAction(QSymbianMenuAction *a rebuild(); } -void QMenuBarPrivate::QSymbianMenuBarPrivate::InsertNativeMenuItems(const QList &actions) +void QMenuBarPrivate::QSymbianMenuBarPrivate::insertNativeMenuItems(const QList &actions) { for (int i = 0; i actions); + insertNativeMenuItems(d->actions); contextMenuActionList.clear(); if (widgetWithContextMenu) { contexMenuCommand = qt_symbian_menu_static_cmd_id; contextAction.setText(QString("Actions")); contextMenuActionList.append(&contextAction); - InsertNativeMenuItems(contextMenuActionList); + insertNativeMenuItems(contextMenuActionList); } } diff --git a/src/gui/widgets/qmenubar_p.h b/src/gui/widgets/qmenubar_p.h index 429605a..9e7d511 100644 --- a/src/gui/widgets/qmenubar_p.h +++ b/src/gui/widgets/qmenubar_p.h @@ -257,7 +257,7 @@ public: } return 0; } - void InsertNativeMenuItems(const QList &actions); + void insertNativeMenuItems(const QList &actions); } *symbian_menubar; static void symbianCommands(int command); -- cgit v0.12 From 9bdd939c508dfe784402c5c3e85e26d135f7643c Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Tue, 9 Jun 2009 14:40:56 +0200 Subject: Fixes from code review --- src/gui/itemviews/qabstractitemview.cpp | 6 +- src/gui/kernel/qwidget_s60.cpp | 41 ----------- src/gui/widgets/qactiontokeyeventmapper.cpp | 103 +++++++++++++++++++++++++++ src/gui/widgets/qactiontokeyeventmapper_p.h | 70 +++++++++++++++++++ src/gui/widgets/qcombobox.cpp | 8 +-- src/gui/widgets/qkeyeventsoftkey.cpp | 105 ---------------------------- src/gui/widgets/qkeyeventsoftkey.h | 74 -------------------- src/gui/widgets/qmenu.cpp | 8 +-- src/gui/widgets/widgets.pri | 4 +- 9 files changed, 186 insertions(+), 233 deletions(-) create mode 100644 src/gui/widgets/qactiontokeyeventmapper.cpp create mode 100644 src/gui/widgets/qactiontokeyeventmapper_p.h delete mode 100644 src/gui/widgets/qkeyeventsoftkey.cpp delete mode 100644 src/gui/widgets/qkeyeventsoftkey.h diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index 69e630e..af84ea6 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -61,7 +61,7 @@ #ifndef QT_NO_ACCESSIBILITY #include #endif -#include +#include QT_BEGIN_NAMESPACE @@ -2004,14 +2004,14 @@ void QAbstractItemView::keyPressEvent(QKeyEvent *event) if (QApplication::keypadNavigationEnabled()) { if (!hasEditFocus()) { setEditFocus(true); - QKeyEventSoftKey::addSoftKey(QAction::BackSoftKey, Qt::Key_Back, this); + QActionToKeyEventMapper::addSoftKey(QAction::BackSoftKey, Qt::Key_Back, this); return; } } break; case Qt::Key_Back: if (QApplication::keypadNavigationEnabled() && hasEditFocus()) { - QKeyEventSoftKey::removeSoftkey(this); + QActionToKeyEventMapper::removeSoftkey(this); setEditFocus(false); } else { event->ignore(); diff --git a/src/gui/kernel/qwidget_s60.cpp b/src/gui/kernel/qwidget_s60.cpp index 2a83fc7..cc6f794 100644 --- a/src/gui/kernel/qwidget_s60.cpp +++ b/src/gui/kernel/qwidget_s60.cpp @@ -61,31 +61,6 @@ extern bool qt_nograb(); QWidget *QWidgetPrivate::mouseGrabber = 0; QWidget *QWidgetPrivate::keyboardGrabber = 0; -static void mapSoftKeys(const QList &softkeys) -{ -/* if (softkeys.count() == 1 && softkeys.at(0)->menuRole()==QAction::MenuSoftKey) { - softkeys.at(0)->setNativePosition(0); - softkeys.at(0)->setQtContextKey(Qt::Key_Context1); - } - else if(softkeys.count() == 1 && softkeys.at(0)->menuRole()!=QAction::MenuSoftKey) { - softkeys.at(0)->setNativePosition(2); - softkeys.at(0)->setQtContextKey(Qt::Key_Context1); - } - else { - // FIX THIS - // veryWeirdMagic is needes as s60 5th edition sdk always panics if cba is set with index 1, this hops over it - // This needs further investigation why so that the hack can be removed - int veryWeirdMagic = 0; - for (int index = 0; index < softkeys.count(); index++) { - softkeys.at(index)->setNativePosition(index + veryWeirdMagic); - softkeys.at(index)->setQtContextKey(Qt::Key_Context1 + index); - if (veryWeirdMagic == 0) - veryWeirdMagic = 1; - } - } -*/ -} - static bool isEqual(const QList& a, const QList& b) { if ( a.count() != b.count()) @@ -110,15 +85,12 @@ void QWidgetPrivate::setSoftKeys_sys(const QList &softkeys) if (isEqual(old, softkeys )) return; } - CCoeAppUi* appui = CEikonEnv::Static()->AppUi(); CAknAppUi* aknAppUi = static_cast (appui); CEikButtonGroupContainer* nativeContainer = aknAppUi->Cba(); nativeContainer->SetCommandSetL(R_AVKON_SOFTKEYS_EMPTY_WITH_IDS); - mapSoftKeys(softkeys); int placeInScreen=0; - for (int index = 0; index < softkeys.count(); index++) { const QAction* softKeyAction = softkeys.at(index); if (softKeyAction->softKeyRole() != QAction::ContextMenuSoftKey) { @@ -135,7 +107,6 @@ void QWidgetPrivate::setSoftKeys_sys(const QList &softkeys) } if (placeInScreen==1) placeInScreen=2; - } } @@ -1083,16 +1054,4 @@ void QWidget::activateWindow() rw->SetOrdinalPosition(0); } } -/* -void QWidget::setSoftKeys(QSoftKeyAction *softKey) -{ - Q_D(QWidget); - d-> -} - -void QWidget::setSoftKeys(const QList &softkeys) -{ - Q_D(QWidget); -} -*/ QT_END_NAMESPACE diff --git a/src/gui/widgets/qactiontokeyeventmapper.cpp b/src/gui/widgets/qactiontokeyeventmapper.cpp new file mode 100644 index 0000000..5cce415 --- /dev/null +++ b/src/gui/widgets/qactiontokeyeventmapper.cpp @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qapplication.h" +#include "qevent.h" +#include "QActionToKeyEventMapper_p.h" + +QT_BEGIN_NAMESPACE + +QActionToKeyEventMapper::QActionToKeyEventMapper(QAction *softKeyAction, Qt::Key key, QObject *parent) + : QObject(parent) + , m_softKeyAction(softKeyAction) + , m_key(key) +{ + +} + +QString QActionToKeyEventMapper::roleText(QAction::SoftKeyRole role) +{ + switch (role) { + case QAction::OptionsSoftKey: + return QAction::tr("Options"); + case QAction::SelectSoftKey: + return QAction::tr("Select"); + case QAction::BackSoftKey: + return QAction::tr("Back"); + case QAction::NextSoftKey: + return QAction::tr("Next"); + case QAction::PreviousSoftKey: + return QAction::tr("Previous"); + case QAction::OkSoftKey: + return QAction::tr("Ok"); + case QAction::CancelSoftKey: + return QAction::tr("Cancel"); + case QAction::EditSoftKey: + return QAction::tr("Edit"); + case QAction::ViewSoftKey: + return QAction::tr("View"); + default: + return QString(); + }; +} +void QActionToKeyEventMapper::addSoftKey(QAction::SoftKeyRole standardRole, Qt::Key key, QWidget *actionWidget) +{ + QAction *action = new QAction(actionWidget); + action->setSoftKeyRole(standardRole); + action->setText(roleText(standardRole)); + QActionToKeyEventMapper *softKey = new QActionToKeyEventMapper(action, key, actionWidget); + connect(action, SIGNAL(triggered()), softKey, SLOT(sendKeyEvent())); + connect(action, SIGNAL(destroyed()), softKey, SLOT(deleteLater())); + actionWidget->setSoftKey(action); +} + +void QActionToKeyEventMapper::removeSoftkey(QWidget *focussedWidget) +{ + focussedWidget->setSoftKey(0); +} + +void QActionToKeyEventMapper::sendKeyEvent() +{ + QApplication::postEvent(parent(), new QKeyEvent(QEvent::KeyPress, m_key, Qt::NoModifier)); +} + +QT_END_NAMESPACE + diff --git a/src/gui/widgets/qactiontokeyeventmapper_p.h b/src/gui/widgets/qactiontokeyeventmapper_p.h new file mode 100644 index 0000000..da336e8 --- /dev/null +++ b/src/gui/widgets/qactiontokeyeventmapper_p.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QACTIONTOKEYEVENTMAPPER_P_H +#define QACTIONTOKEYEVENTMAPPER_P_H + +#include +#include "QtGui/qaction.h" +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QActionToKeyEventMapper : public QObject +{ + Q_OBJECT +public: + QActionToKeyEventMapper(QAction *softKeyAction, Qt::Key key, QObject *parent); + static QString roleText(QAction::SoftKeyRole role); + static void addSoftKey(QAction::SoftKeyRole standardRole, Qt::Key key, QWidget *actionWidget); + static void removeSoftkey(QWidget *focussedWidget); +private: + QAction *m_softKeyAction; + Qt::Key m_key; +private Q_SLOTS: + void sendKeyEvent(); +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif //QACTIONTOKEYEVENTMAPPER_H diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp index 01fcf34..2da5cd0 100644 --- a/src/gui/widgets/qcombobox.cpp +++ b/src/gui/widgets/qcombobox.cpp @@ -63,7 +63,7 @@ #include #include #include -#include +#include #ifdef Q_WS_X11 #include #endif @@ -629,7 +629,7 @@ bool QComboBoxPrivateContainer::eventFilter(QObject *o, QEvent *e) #endif if (view->currentIndex().isValid() && (view->currentIndex().flags() & Qt::ItemIsEnabled) ) { #ifdef QT_KEYPAD_NAVIGATION - QKeyEventSoftKey::removeSoftkey(this); + QActionToKeyEventMapper::removeSoftkey(this); #endif combo->hidePopup(); emit itemSelected(view->currentIndex()); @@ -643,7 +643,7 @@ bool QComboBoxPrivateContainer::eventFilter(QObject *o, QEvent *e) case Qt::Key_Escape: #ifdef QT_KEYPAD_NAVIGATION case Qt::Key_Back: - QKeyEventSoftKey::removeSoftkey(this); + QActionToKeyEventMapper::removeSoftkey(this); #endif combo->hidePopup(); return true; @@ -2438,7 +2438,7 @@ void QComboBox::showPopup() #ifdef QT_KEYPAD_NAVIGATION if (QApplication::keypadNavigationEnabled()) view()->setEditFocus(true); - QKeyEventSoftKey::addSoftKey(QAction::CancelSoftKey, Qt::Key_Back, view()); + QActionToKeyEventMapper::addSoftKey(QAction::CancelSoftKey, Qt::Key_Back, view()); #endif } diff --git a/src/gui/widgets/qkeyeventsoftkey.cpp b/src/gui/widgets/qkeyeventsoftkey.cpp deleted file mode 100644 index f5f10fc..0000000 --- a/src/gui/widgets/qkeyeventsoftkey.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qapplication.h" -#include "qevent.h" -#include "qkeyeventsoftkey.h" - -QT_BEGIN_NAMESPACE - -QKeyEventSoftKey::QKeyEventSoftKey(QAction *softKeyAction, Qt::Key key, QObject *parent) - : QObject(parent) - , m_softKeyAction(softKeyAction) - , m_key(key) -{ - -} - -QString QKeyEventSoftKey::roleText(QAction::SoftKeyRole role) -{ - switch (role) { - case QAction::OptionsSoftKey: - return QAction::tr("Options"); - case QAction::SelectSoftKey: - return QAction::tr("Select"); - case QAction::BackSoftKey: - return QAction::tr("Back"); - case QAction::NextSoftKey: - return QAction::tr("Next"); - case QAction::PreviousSoftKey: - return QAction::tr("Previous"); - case QAction::OkSoftKey: - return QAction::tr("Ok"); - case QAction::CancelSoftKey: - return QAction::tr("Cancel"); - case QAction::EditSoftKey: - return QAction::tr("Edit"); - case QAction::ViewSoftKey: - return QAction::tr("View"); - default: - return QString(); - }; -} -void QKeyEventSoftKey::addSoftKey(QAction::SoftKeyRole standardRole, Qt::Key key, QWidget *actionWidget) -{ - QAction *action = new QAction(actionWidget); - action->setSoftKeyRole(standardRole); - action->setText(roleText(standardRole)); - QKeyEventSoftKey *softKey = new QKeyEventSoftKey(action, key, actionWidget); - connect(action, SIGNAL(triggered()), softKey, SLOT(sendKeyEvent())); - connect(action, SIGNAL(destroyed()), softKey, SLOT(deleteLater())); - actionWidget->setSoftKey(action); -} - -void QKeyEventSoftKey::removeSoftkey(QWidget *focussedWidget) -{ - focussedWidget->setSoftKey(0); -} - -void QKeyEventSoftKey::sendKeyEvent() -{ - QApplication::postEvent(parent(), new QKeyEvent(QEvent::KeyPress, m_key, Qt::NoModifier)); -} - -QT_END_NAMESPACE - -#include "moc_qkeyeventsoftkey.cpp" - diff --git a/src/gui/widgets/qkeyeventsoftkey.h b/src/gui/widgets/qkeyeventsoftkey.h deleted file mode 100644 index 0b95efb..0000000 --- a/src/gui/widgets/qkeyeventsoftkey.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QKEYEVENTSOFTKEY_H -#define QKEYEVENTSOFTKEY_H - -#include -#include "QtGui/qaction.h" -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - - - -class Q_GUI_EXPORT QKeyEventSoftKey : QObject -{ - Q_OBJECT -public: - QKeyEventSoftKey(QAction *softKeyAction, Qt::Key key, QObject *parent); - static QString roleText(QAction::SoftKeyRole role); - static void addSoftKey(QAction::SoftKeyRole standardRole, Qt::Key key, QWidget *actionWidget); - static void removeSoftkey(QWidget *focussedWidget); -private: - QAction *m_softKeyAction; - Qt::Key m_key; -private Q_SLOTS: - void sendKeyEvent(); -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif //QKEYEVENSOFTKEY_H diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp index d713081..3486574 100644 --- a/src/gui/widgets/qmenu.cpp +++ b/src/gui/widgets/qmenu.cpp @@ -60,7 +60,7 @@ #ifndef QT_NO_WHATSTHIS # include #endif -#include +#include #include "qmenu_p.h" #include "qmenubar_p.h" @@ -584,7 +584,7 @@ void QMenuPrivate::setCurrentAction(QAction *action, int popup, SelectionReason #ifdef QT_KEYPAD_NAVIGATION // TODO: aportale, remove KEYPAD_NAVIGATION_HACK when softkey stack // handles focus related and user related actions separately... - QKeyEventSoftKey::addSoftKey(QAction::CancelSoftKey, Qt::Key_Back, q); + QActionToKeyEventMapper::addSoftKey(QAction::CancelSoftKey, Qt::Key_Back, q); #endif } } @@ -1945,7 +1945,7 @@ void QMenu::popup(const QPoint &p, QAction *atAction) QAccessible::updateAccessibility(this, 0, QAccessible::PopupMenuStart); #endif #ifdef QT_KEYPAD_NAVIGATION - QKeyEventSoftKey::addSoftKey(QAction::CancelSoftKey, Qt::Key_Back, this); + QActionToKeyEventMapper::addSoftKey(QAction::CancelSoftKey, Qt::Key_Back, this); #endif } @@ -2597,7 +2597,7 @@ void QMenu::keyPressEvent(QKeyEvent *e) case Qt::Key_Escape: #ifdef QT_KEYPAD_NAVIGATION case Qt::Key_Back: - QKeyEventSoftKey::removeSoftkey(this); + QActionToKeyEventMapper::removeSoftkey(this); #endif key_consumed = true; if (d->tornoff) { diff --git a/src/gui/widgets/widgets.pri b/src/gui/widgets/widgets.pri index f395c76..9e226e2 100644 --- a/src/gui/widgets/widgets.pri +++ b/src/gui/widgets/widgets.pri @@ -79,7 +79,7 @@ HEADERS += \ widgets/qplaintextedit.h \ widgets/qplaintextedit_p.h \ widgets/qprintpreviewwidget.h \ - widgets/qkeyeventsoftkey.h + widgets/qactiontokeyeventmapper_p.h SOURCES += \ widgets/qabstractbutton.cpp \ widgets/qabstractslider.cpp \ @@ -139,7 +139,7 @@ SOURCES += \ widgets/qtoolbararealayout.cpp \ widgets/qplaintextedit.cpp \ widgets/qprintpreviewwidget.cpp \ - widgets/qkeyeventsoftkey.cpp + widgets/qactiontokeyeventmapper.cpp !embedded:mac { HEADERS += widgets/qmacnativewidget_mac.h \ -- cgit v0.12 From 4df7621c7ab1b38416002430377a451a4c416100 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Tue, 9 Jun 2009 17:50:13 +0200 Subject: Itemviews have go their focus frame back. Got lost with dc177883bf98a68e61c9a9cda7e1ba9464079275 --- src/gui/styles/qs60style.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index 6d24d54..3236928 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -1880,11 +1880,11 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, } break; #endif //QT_NO_TOOLBAR - case CE_ShapedFrame: { - const QTextEdit *txt = qobject_cast(widget); - if (txt) + case CE_ShapedFrame: + if (qobject_cast(widget)) QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_Editor, painter, option->rect, flags); - } + if (option->state & State_HasFocus) + drawPrimitive(PE_FrameFocusRect, option, painter, widget); break; default: QCommonStyle::drawControl(element, option, painter, widget); -- cgit v0.12 From 37524a8b9ffa41f960fcc595039def4ae4167f3e Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Wed, 10 Jun 2009 12:02:27 +0200 Subject: Call DrawDeferred() after setting softkeys SDK 3.1 and maybe also 3.2 need an extra invitation. RevvBy: maluukka --- src/gui/kernel/qwidget_s60.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gui/kernel/qwidget_s60.cpp b/src/gui/kernel/qwidget_s60.cpp index cc6f794..a912b64 100644 --- a/src/gui/kernel/qwidget_s60.cpp +++ b/src/gui/kernel/qwidget_s60.cpp @@ -108,6 +108,7 @@ void QWidgetPrivate::setSoftKeys_sys(const QList &softkeys) if (placeInScreen==1) placeInScreen=2; } + nativeContainer->DrawDeferred(); // 3.1 needs an extra invitation } void QWidgetPrivate::setWSGeometry(bool dontShow) -- cgit v0.12 From 29189c3112cbfb24d9e5855240e352af18088db9 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Wed, 10 Jun 2009 12:06:31 +0200 Subject: Better handling for setting softkeys --- src/gui/kernel/qwidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 3a22ee9..eaa9491 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -11570,7 +11570,7 @@ void QWidget::setSoftKeys(const QList &softKeys) d->softKeys.clear(); d->softKeys = softKeys; - if (QApplication::focusWidget() == this) + if ((QApplication::focusWidget() == this) || (QApplication::focusWidget()==0)) d->setSoftKeys_sys(this->softKeys()); } -- cgit v0.12 From 5d924cb69ea03921a9b4bc5f701063cf45ded508 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Wed, 10 Jun 2009 12:07:36 +0200 Subject: Skeleton implementation for softkeys example --- src/gui/softkeys/main.cpp | 108 +----------------------------------------- src/gui/softkeys/softkeys.cpp | 61 ++++++++++++++++++++++++ src/gui/softkeys/softkeys.h | 79 ++++++++++++++++++++++++++++++ src/gui/softkeys/softkeys.pro | 4 +- 4 files changed, 145 insertions(+), 107 deletions(-) create mode 100644 src/gui/softkeys/softkeys.cpp create mode 100644 src/gui/softkeys/softkeys.h diff --git a/src/gui/softkeys/main.cpp b/src/gui/softkeys/main.cpp index a92e2c2..a355f93 100644 --- a/src/gui/softkeys/main.cpp +++ b/src/gui/softkeys/main.cpp @@ -10,116 +10,12 @@ ****************************************************************************/ #include - -class MainWindow : public QMainWindow -{ - Q_OBJECT -public: - -private slots: - void context1Slot(); - void context3Slot(); - void softKeySlot(); -public: - - MainWindow(QWidget *parent = 0); - ~MainWindow(); - QMenu *contextMenu; - QAction* context1; - QAction* context2; - QAction* context3; - QSoftKeyAction *action1; - QSoftKeyAction *action2; - QSoftKeyAction *action3; - QSoftKeyAction *action4; - QSoftKeyAction *action5; -}; - -MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent), - contextMenu(0), - context1(0), context2(0), context3(0), - action1(0),action2(0),action3(0),action4(0),action5(0) - -{ - QWidget *central = new QWidget(this); - contextMenu = new QMenu(); - - central->setLayout(new QVBoxLayout); - central->layout()->addWidget(new QPushButton); - central->layout()->addWidget(new QPushButton); - central->layout()->addWidget(new QPushButton); - context1 = new QAction(QString("Context1"), central); - context2 = new QAction(QString("Context2"), central); - - context3 = new QAction(QString("Context3"), contextMenu); - central->addAction(context1); - central->addAction(context2); - QMenuBar* menuBar = new QMenuBar(this); - menuBar->addAction("MyMenuItem1"); - this->setMenuBar(menuBar); - context2->setMenu(contextMenu); - contextMenu->addAction(context3); - - connect(context1, SIGNAL(triggered()), this, SLOT(context1Slot())); - connect(context3, SIGNAL(triggered()), this, SLOT(context3Slot())); - action1 = new QSoftKeyAction(QSoftKeyAction::Ok, QString("Ok"), central); - action2 = new QSoftKeyAction(QSoftKeyAction::Back, QString("Back"), central); - action3 = new QSoftKeyAction(QSoftKeyAction::Cancel, QString("Cancel"), central); - action4 = new QSoftKeyAction(QSoftKeyAction::Menu, QString("Menu"), central); - action5 = new QSoftKeyAction(QSoftKeyAction::ContextMenu,QString("ContextMenu"), central); - - connect(action2, SIGNAL(triggered()), this, SLOT(softKeySlot())); - - QList myActionList; - myActionList.append(action1); - myActionList.append(action2); - myActionList.append(action3); - softKeyStack()->push(myActionList); - softKeyStack()->pop(); - softKeyStack()->push(action1); - softKeyStack()->pop(); - - QList myActionList2; - myActionList2.append(action4); - myActionList2.append(action2); - myActionList2.append(action5); - softKeyStack()->push(myActionList2); - - - setCentralWidget(central); -} -MainWindow::~MainWindow() -{ - delete context1; - delete context2; - delete context3; - delete action1; - delete action2; - delete action3; - delete action4; - delete action5; - delete contextMenu; -} - -void MainWindow::context1Slot() - { - } -void MainWindow::context3Slot() - { - } - -void MainWindow::softKeySlot() -{ - -} +#include "softkeys.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); MainWindow mw; - mw.show(); + mw.showMaximized(); return app.exec(); } - -#include "main.moc" diff --git a/src/gui/softkeys/softkeys.cpp b/src/gui/softkeys/softkeys.cpp new file mode 100644 index 0000000..edf38b9 --- /dev/null +++ b/src/gui/softkeys/softkeys.cpp @@ -0,0 +1,61 @@ +#include "softkeys.h" + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) +{ + fileMenu = menuBar()->addMenu(tr("&File")); + openDialogAct = new QAction(tr("&Open Dialog"), this); + addSoftKeysAct = new QAction(tr("&Add Softkeys"), this); + clearSoftKeysAct = new QAction(tr("&Clear Softkeys"), this); + fileMenu->addAction(openDialogAct); + fileMenu->addAction(addSoftKeysAct); + fileMenu->addAction(clearSoftKeysAct); + connect(openDialogAct, SIGNAL(triggered()), this, SLOT(openDialog())); + connect(addSoftKeysAct, SIGNAL(triggered()), this, SLOT(addSoftKeys())); + connect(clearSoftKeysAct, SIGNAL(triggered()), this, SLOT(clearSoftKeys())); + QWidget *central = new QWidget(this); + central->setLayout(new QVBoxLayout); +// central->setFocus(); + setCentralWidget(central); + QPushButton button1; +// QAction* menuAction = +} + +MainWindow::~MainWindow() +{ +} + +void MainWindow::openDialog() +{ + QFileDialog::getOpenFileName(this); +} + +void MainWindow::addSoftKeys() +{ + ok = new QAction(tr("Ok"), this); + ok->setSoftKeyRole(QAction::OkSoftKey); + connect(ok, SIGNAL(triggered()), this, SLOT(okPressed())); + + cancel = new QAction(tr("Cancel"), this); + cancel->setSoftKeyRole(QAction::OkSoftKey); + connect(cancel, SIGNAL(triggered()), this, SLOT(cancelPressed())); + + QList softkeys; + softkeys.append(ok); + softkeys.append(cancel); + setSoftKeys(softkeys); + +} + +void MainWindow::clearSoftKeys() +{ + setSoftKey(0); +} + +void MainWindow::okPressed() +{ +} + +void MainWindow::cancelPressed() +{ +} diff --git a/src/gui/softkeys/softkeys.h b/src/gui/softkeys/softkeys.h new file mode 100644 index 0000000..2bc74ba --- /dev/null +++ b/src/gui/softkeys/softkeys.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SOFTKEYS_H +#define SOFTKEYS_H + +#include + +class MainWindow : public QMainWindow +{ + Q_OBJECT +public: + +private slots: + void openDialog(); + void addSoftKeys(); + void clearSoftKeys(); + void okPressed(); + void cancelPressed(); +public: + MainWindow(QWidget *parent = 0); + ~MainWindow(); +private: + QMenu* fileMenu; + QAction* openDialogAct; + QAction* addSoftKeysAct; + QAction* clearSoftKeysAct; + QAction* ok; + QAction* cancel; +}; + +//! [0] +class SoftKey : public QWidget +{ + Q_OBJECT +public: + SoftKey(QWidget *parent = 0); +}; +//! [0] + +#endif diff --git a/src/gui/softkeys/softkeys.pro b/src/gui/softkeys/softkeys.pro index a16103e..4cb8672 100644 --- a/src/gui/softkeys/softkeys.pro +++ b/src/gui/softkeys/softkeys.pro @@ -1,2 +1,4 @@ +HEADERS = softkeys.h SOURCES += \ - main.cpp + main.cpp \ + softkeys.cpp \ No newline at end of file -- cgit v0.12 From 39c796e57be1830133e6189abe8f796b6846904f Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Wed, 10 Jun 2009 12:08:47 +0200 Subject: Moved softkeys example to a better place --- examples/widgets/softkeys/main.cpp | 21 +++++++++ examples/widgets/softkeys/softkeys.cpp | 61 ++++++++++++++++++++++++++ examples/widgets/softkeys/softkeys.h | 79 ++++++++++++++++++++++++++++++++++ examples/widgets/softkeys/softkeys.pro | 4 ++ src/gui/softkeys/main.cpp | 21 --------- src/gui/softkeys/softkeys.cpp | 61 -------------------------- src/gui/softkeys/softkeys.h | 79 ---------------------------------- src/gui/softkeys/softkeys.pro | 4 -- 8 files changed, 165 insertions(+), 165 deletions(-) create mode 100644 examples/widgets/softkeys/main.cpp create mode 100644 examples/widgets/softkeys/softkeys.cpp create mode 100644 examples/widgets/softkeys/softkeys.h create mode 100644 examples/widgets/softkeys/softkeys.pro delete mode 100644 src/gui/softkeys/main.cpp delete mode 100644 src/gui/softkeys/softkeys.cpp delete mode 100644 src/gui/softkeys/softkeys.h delete mode 100644 src/gui/softkeys/softkeys.pro diff --git a/examples/widgets/softkeys/main.cpp b/examples/widgets/softkeys/main.cpp new file mode 100644 index 0000000..a355f93 --- /dev/null +++ b/examples/widgets/softkeys/main.cpp @@ -0,0 +1,21 @@ +/**************************************************************************** +** +** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +****************************************************************************/ + +#include +#include "softkeys.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow mw; + mw.showMaximized(); + return app.exec(); +} diff --git a/examples/widgets/softkeys/softkeys.cpp b/examples/widgets/softkeys/softkeys.cpp new file mode 100644 index 0000000..edf38b9 --- /dev/null +++ b/examples/widgets/softkeys/softkeys.cpp @@ -0,0 +1,61 @@ +#include "softkeys.h" + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) +{ + fileMenu = menuBar()->addMenu(tr("&File")); + openDialogAct = new QAction(tr("&Open Dialog"), this); + addSoftKeysAct = new QAction(tr("&Add Softkeys"), this); + clearSoftKeysAct = new QAction(tr("&Clear Softkeys"), this); + fileMenu->addAction(openDialogAct); + fileMenu->addAction(addSoftKeysAct); + fileMenu->addAction(clearSoftKeysAct); + connect(openDialogAct, SIGNAL(triggered()), this, SLOT(openDialog())); + connect(addSoftKeysAct, SIGNAL(triggered()), this, SLOT(addSoftKeys())); + connect(clearSoftKeysAct, SIGNAL(triggered()), this, SLOT(clearSoftKeys())); + QWidget *central = new QWidget(this); + central->setLayout(new QVBoxLayout); +// central->setFocus(); + setCentralWidget(central); + QPushButton button1; +// QAction* menuAction = +} + +MainWindow::~MainWindow() +{ +} + +void MainWindow::openDialog() +{ + QFileDialog::getOpenFileName(this); +} + +void MainWindow::addSoftKeys() +{ + ok = new QAction(tr("Ok"), this); + ok->setSoftKeyRole(QAction::OkSoftKey); + connect(ok, SIGNAL(triggered()), this, SLOT(okPressed())); + + cancel = new QAction(tr("Cancel"), this); + cancel->setSoftKeyRole(QAction::OkSoftKey); + connect(cancel, SIGNAL(triggered()), this, SLOT(cancelPressed())); + + QList softkeys; + softkeys.append(ok); + softkeys.append(cancel); + setSoftKeys(softkeys); + +} + +void MainWindow::clearSoftKeys() +{ + setSoftKey(0); +} + +void MainWindow::okPressed() +{ +} + +void MainWindow::cancelPressed() +{ +} diff --git a/examples/widgets/softkeys/softkeys.h b/examples/widgets/softkeys/softkeys.h new file mode 100644 index 0000000..2bc74ba --- /dev/null +++ b/examples/widgets/softkeys/softkeys.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SOFTKEYS_H +#define SOFTKEYS_H + +#include + +class MainWindow : public QMainWindow +{ + Q_OBJECT +public: + +private slots: + void openDialog(); + void addSoftKeys(); + void clearSoftKeys(); + void okPressed(); + void cancelPressed(); +public: + MainWindow(QWidget *parent = 0); + ~MainWindow(); +private: + QMenu* fileMenu; + QAction* openDialogAct; + QAction* addSoftKeysAct; + QAction* clearSoftKeysAct; + QAction* ok; + QAction* cancel; +}; + +//! [0] +class SoftKey : public QWidget +{ + Q_OBJECT +public: + SoftKey(QWidget *parent = 0); +}; +//! [0] + +#endif diff --git a/examples/widgets/softkeys/softkeys.pro b/examples/widgets/softkeys/softkeys.pro new file mode 100644 index 0000000..4cb8672 --- /dev/null +++ b/examples/widgets/softkeys/softkeys.pro @@ -0,0 +1,4 @@ +HEADERS = softkeys.h +SOURCES += \ + main.cpp \ + softkeys.cpp \ No newline at end of file diff --git a/src/gui/softkeys/main.cpp b/src/gui/softkeys/main.cpp deleted file mode 100644 index a355f93..0000000 --- a/src/gui/softkeys/main.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the $MODULE$ of the Qt Toolkit. -** -** $TROLLTECH_DUAL_LICENSE$ -** -****************************************************************************/ - -#include -#include "softkeys.h" - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - MainWindow mw; - mw.showMaximized(); - return app.exec(); -} diff --git a/src/gui/softkeys/softkeys.cpp b/src/gui/softkeys/softkeys.cpp deleted file mode 100644 index edf38b9..0000000 --- a/src/gui/softkeys/softkeys.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "softkeys.h" - -MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent) -{ - fileMenu = menuBar()->addMenu(tr("&File")); - openDialogAct = new QAction(tr("&Open Dialog"), this); - addSoftKeysAct = new QAction(tr("&Add Softkeys"), this); - clearSoftKeysAct = new QAction(tr("&Clear Softkeys"), this); - fileMenu->addAction(openDialogAct); - fileMenu->addAction(addSoftKeysAct); - fileMenu->addAction(clearSoftKeysAct); - connect(openDialogAct, SIGNAL(triggered()), this, SLOT(openDialog())); - connect(addSoftKeysAct, SIGNAL(triggered()), this, SLOT(addSoftKeys())); - connect(clearSoftKeysAct, SIGNAL(triggered()), this, SLOT(clearSoftKeys())); - QWidget *central = new QWidget(this); - central->setLayout(new QVBoxLayout); -// central->setFocus(); - setCentralWidget(central); - QPushButton button1; -// QAction* menuAction = -} - -MainWindow::~MainWindow() -{ -} - -void MainWindow::openDialog() -{ - QFileDialog::getOpenFileName(this); -} - -void MainWindow::addSoftKeys() -{ - ok = new QAction(tr("Ok"), this); - ok->setSoftKeyRole(QAction::OkSoftKey); - connect(ok, SIGNAL(triggered()), this, SLOT(okPressed())); - - cancel = new QAction(tr("Cancel"), this); - cancel->setSoftKeyRole(QAction::OkSoftKey); - connect(cancel, SIGNAL(triggered()), this, SLOT(cancelPressed())); - - QList softkeys; - softkeys.append(ok); - softkeys.append(cancel); - setSoftKeys(softkeys); - -} - -void MainWindow::clearSoftKeys() -{ - setSoftKey(0); -} - -void MainWindow::okPressed() -{ -} - -void MainWindow::cancelPressed() -{ -} diff --git a/src/gui/softkeys/softkeys.h b/src/gui/softkeys/softkeys.h deleted file mode 100644 index 2bc74ba..0000000 --- a/src/gui/softkeys/softkeys.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef SOFTKEYS_H -#define SOFTKEYS_H - -#include - -class MainWindow : public QMainWindow -{ - Q_OBJECT -public: - -private slots: - void openDialog(); - void addSoftKeys(); - void clearSoftKeys(); - void okPressed(); - void cancelPressed(); -public: - MainWindow(QWidget *parent = 0); - ~MainWindow(); -private: - QMenu* fileMenu; - QAction* openDialogAct; - QAction* addSoftKeysAct; - QAction* clearSoftKeysAct; - QAction* ok; - QAction* cancel; -}; - -//! [0] -class SoftKey : public QWidget -{ - Q_OBJECT -public: - SoftKey(QWidget *parent = 0); -}; -//! [0] - -#endif diff --git a/src/gui/softkeys/softkeys.pro b/src/gui/softkeys/softkeys.pro deleted file mode 100644 index 4cb8672..0000000 --- a/src/gui/softkeys/softkeys.pro +++ /dev/null @@ -1,4 +0,0 @@ -HEADERS = softkeys.h -SOURCES += \ - main.cpp \ - softkeys.cpp \ No newline at end of file -- cgit v0.12 From 8c265860b41214daade7c8a28237c1e07ea71a3c Mon Sep 17 00:00:00 2001 From: axis Date: Tue, 9 Jun 2009 14:35:40 +0200 Subject: Fixed the mouse handler of FEP when in inline edit mode. We now commit the text if the mouse handler is invoked. This prevents the case where the VK cannot be brought up because the widget is the only focusable widget and is stuck in inline edit mode. --- src/gui/inputmethod/qcoefepinputcontext_p.h | 2 +- src/gui/inputmethod/qcoefepinputcontext_s60.cpp | 71 ++++++------------------- 2 files changed, 18 insertions(+), 55 deletions(-) diff --git a/src/gui/inputmethod/qcoefepinputcontext_p.h b/src/gui/inputmethod/qcoefepinputcontext_p.h index c2677b1..b33489e 100644 --- a/src/gui/inputmethod/qcoefepinputcontext_p.h +++ b/src/gui/inputmethod/qcoefepinputcontext_p.h @@ -92,7 +92,7 @@ public: TCoeInputCapabilities inputCapabilities(); private: - void commitCurrentString(); + void commitCurrentString(bool triggeredBySymbian); void updateHints(); void applyHints(Qt::InputMethodHints hints); void applyFormat(QList *attributes); diff --git a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp index 0a5fd22..1dfb012 100644 --- a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp +++ b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp @@ -123,9 +123,7 @@ void QCoeFepInputContext::update() void QCoeFepInputContext::setFocusWidget(QWidget *w) { - commitCurrentString(); - - CCoeEnv::Static()->Fep()->CancelTransaction(); + commitCurrentString(false); QInputContext::setFocusWidget(w); @@ -292,56 +290,17 @@ bool QCoeFepInputContext::filterEvent(const QEvent *event) void QCoeFepInputContext::mouseHandler( int x, QMouseEvent *event) { Q_ASSERT(m_isEditing); + Q_ASSERT(focusWidget()); - if (!m_pointerHandler) { - QInputContext::mouseHandler(x, event); - } - - TPointerEvent::TType type; - TUint modifiers = 0; - - if (event->type() == QEvent::MouseButtonPress) { - if (event->button() == Qt::LeftButton) { - type = TPointerEvent::EButton1Down; - } else if (event->button() == Qt::RightButton) { - type = TPointerEvent::EButton3Down; - } else if (event->button() == Qt::MidButton) { - type = TPointerEvent::EButton2Down; - } else { - return; - } - } else if (event->type() == QEvent::MouseButtonRelease) { - if (event->button() == Qt::LeftButton) { - type = TPointerEvent::EButton1Up; - } else if (event->button() == Qt::RightButton) { - type = TPointerEvent::EButton3Up; - } else if (event->button() == Qt::MidButton) { - type = TPointerEvent::EButton2Up; - } else { - return; - } - } else if (event->type() == QEvent::MouseMove) { - type = TPointerEvent::EMove; - } else if (event->type() == QEvent::DragMove) { - type = TPointerEvent::EDrag; - } else { - return; - } + if (event->type() == QEvent::MouseButtonPress && event->button() == Qt::LeftButton) { + commitCurrentString(false); + int pos = focusWidget()->inputMethodQuery(Qt::ImCursorPosition).toInt(); - if (event->modifiers() & Qt::ShiftModifier) { - modifiers |= EModifierShift; - } - if (event->modifiers() & Qt::AltModifier) { - modifiers |= EModifierAlt; + QList attributes; + attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, pos + x, 0, QVariant()); + QInputMethodEvent event("", attributes); + sendEvent(event); } - if (event->modifiers() & Qt::ControlModifier) { - modifiers |= EModifierCtrl; - } - if (event->modifiers() & Qt::KeypadModifier) { - modifiers |= EModifierKeypad; - } - - m_pointerHandler->HandlePointerEventInInlineTextL(type, modifiers, x); } TCoeInputCapabilities QCoeFepInputContext::inputCapabilities() @@ -712,12 +671,10 @@ void QCoeFepInputContext::GetScreenCoordinatesForFepL(TPoint& aLeftSideOfBaseLin void QCoeFepInputContext::DoCommitFepInlineEditL() { - commitCurrentString(); - - m_isEditing = false; + commitCurrentString(true); } -void QCoeFepInputContext::commitCurrentString() +void QCoeFepInputContext::commitCurrentString(bool triggeredBySymbian) { if (m_preeditString.size() == 0) { return; @@ -728,6 +685,12 @@ void QCoeFepInputContext::commitCurrentString() event.setCommitString(m_preeditString, 0, 0);//m_preeditString.size()); m_preeditString.clear(); sendEvent(event); + + m_isEditing = false; + + if (!triggeredBySymbian) { + CCoeEnv::Static()->Fep()->CancelTransaction(); + } } MCoeFepAwareTextEditor_Extension1* QCoeFepInputContext::Extension1(TBool& aSetToTrue) -- cgit v0.12 From 7604f8087f88171ef933d8ae08f501467e647338 Mon Sep 17 00:00:00 2001 From: Robert Griebl Date: Wed, 10 Jun 2009 13:46:23 +0200 Subject: Make Qt exception safer. Squashed commit of the branch haralds-haralds-qt-s60-topics/topic/exceptions, which also contains the full history. Rev-By: Harald Fernengel Rev-By: Ralf Engels --- configure.exe | Bin 868352 -> 868352 bytes .../code/src_corelib_tools_qscopedpointer.cpp | 64 +++ mkspecs/features/symbian/platform_paths.prf | 15 +- mkspecs/features/symbian/stl.prf | 27 +- src/3rdparty/harfbuzz/src/harfbuzz-shaper.cpp | 8 + src/3rdparty/phonon/phonon/abstractmediastream.cpp | 1 - src/3rdparty/phonon/phonon/abstractmediastream.h | 2 +- src/3rdparty/phonon/phonon/abstractmediastream_p.h | 2 +- src/corelib/codecs/qisciicodec.cpp | 1 - src/corelib/codecs/qtextcodec.cpp | 21 +- src/corelib/concurrent/qthreadpool.cpp | 6 +- src/corelib/global/qglobal.cpp | 143 ++++- src/corelib/global/qglobal.h | 97 +++- src/corelib/global/qlibraryinfo.cpp | 28 +- src/corelib/io/qabstractfileengine.cpp | 3 - src/corelib/io/qabstractfileengine.h | 4 +- src/corelib/io/qdebug.h | 7 +- src/corelib/io/qdir.cpp | 3 +- src/corelib/io/qdir.h | 3 +- src/corelib/io/qfile.cpp | 5 +- src/corelib/io/qfileinfo.cpp | 2 - src/corelib/io/qfileinfo.h | 3 +- src/corelib/io/qfilesystemwatcher_symbian.cpp | 8 +- src/corelib/io/qfsfileengine_unix.cpp | 24 +- src/corelib/io/qiodevice.h | 3 +- src/corelib/io/qprocess_symbian.cpp | 1 + src/corelib/io/qresource.cpp | 1 - src/corelib/io/qresource.h | 2 +- src/corelib/io/qsettings.cpp | 68 +-- src/corelib/io/qsettings.h | 2 +- src/corelib/io/qsettings_p.h | 2 +- src/corelib/io/qtextstream.cpp | 3 - src/corelib/io/qtextstream.h | 3 +- src/corelib/kernel/qcore_symbian_p.cpp | 19 +- src/corelib/kernel/qcore_symbian_p.h | 4 +- src/corelib/kernel/qcoreapplication.cpp | 91 +-- src/corelib/kernel/qcoreapplication.h | 2 + src/corelib/kernel/qeventdispatcher_symbian.cpp | 195 ++++--- src/corelib/kernel/qeventdispatcher_symbian_p.h | 3 + src/corelib/kernel/qeventdispatcher_unix.cpp | 21 +- src/corelib/kernel/qeventdispatcher_unix_p.h | 1 + src/corelib/kernel/qobject.cpp | 44 +- src/corelib/kernel/qobject.h | 3 +- src/corelib/kernel/qsharedmemory_symbian.cpp | 14 +- src/corelib/kernel/qsystemsemaphore.cpp | 3 +- src/corelib/kernel/qsystemsemaphore.h | 3 +- src/corelib/kernel/qsystemsemaphore_symbian.cpp | 7 +- src/corelib/plugin/qlibrary.cpp | 7 +- src/corelib/thread/qthread.cpp | 15 +- src/corelib/thread/qthread_unix.cpp | 9 +- src/corelib/thread/qthread_win.cpp | 9 +- src/corelib/thread/qthreadstorage.cpp | 14 +- src/corelib/tools/qbitarray.cpp | 2 + src/corelib/tools/qbytearray.cpp | 55 +- src/corelib/tools/qdatetime.cpp | 14 +- src/corelib/tools/qdatetime.h | 3 +- src/corelib/tools/qharfbuzz.cpp | 1 + src/corelib/tools/qhash.cpp | 78 ++- src/corelib/tools/qhash.h | 39 +- src/corelib/tools/qlinkedlist.h | 44 +- src/corelib/tools/qlist.h | 101 +++- src/corelib/tools/qlistdata.cpp | 22 +- src/corelib/tools/qlocale.cpp | 3 + src/corelib/tools/qmap.cpp | 35 +- src/corelib/tools/qmap.h | 35 +- src/corelib/tools/qpodlist_p.h | 192 +------ src/corelib/tools/qregexp.cpp | 25 +- src/corelib/tools/qringbuffer_p.h | 5 +- src/corelib/tools/qscopedpointer.cpp | 132 +++++ src/corelib/tools/qscopedpointer.h | 199 +++++++ src/corelib/tools/qshareddata.cpp | 2 +- src/corelib/tools/qsharedpointer.cpp | 9 +- src/corelib/tools/qstring.cpp | 138 ++--- src/corelib/tools/qtextboundaryfinder.cpp | 10 +- src/corelib/tools/qvarlengtharray.h | 80 +-- src/corelib/tools/qvector.cpp | 1 + src/corelib/tools/qvector.h | 98 ++-- src/corelib/tools/tools.pri | 3 +- src/corelib/xml/qxmlstream.cpp | 5 +- src/corelib/xml/qxmlstream.h | 5 +- src/dbus/qdbusabstractadaptor.cpp | 2 +- src/dbus/qdbuscontext.h | 2 +- src/gui/dialogs/dialogs.pri | 1 + src/gui/dialogs/qdialog.cpp | 10 +- src/gui/dialogs/qfiledialog.cpp | 21 +- src/gui/dialogs/qfiledialog_p.h | 29 +- src/gui/dialogs/qfileinfogatherer.cpp | 28 +- src/gui/dialogs/qfscompleter_p.h | 81 +++ src/gui/dialogs/qpagesetupdialog_win.cpp | 2 +- src/gui/dialogs/qprintdialog_unix.cpp | 4 +- src/gui/dialogs/qprintpreviewdialog.cpp | 13 +- src/gui/dialogs/qprintpreviewdialog.h | 2 +- src/gui/embedded/qsoundqss_qws.cpp | 36 +- src/gui/embedded/qwindowsystem_qws.cpp | 44 +- src/gui/embedded/qwscursor_qws.cpp | 2 +- src/gui/graphicsview/qgraphicsitem.cpp | 6 +- src/gui/graphicsview/qgraphicsitem.h | 3 +- src/gui/graphicsview/qgraphicslayoutitem.cpp | 1 - src/gui/graphicsview/qgraphicslayoutitem.h | 3 +- src/gui/graphicsview/qgraphicsproxywidget.h | 2 +- src/gui/graphicsview/qgraphicsscene.cpp | 10 +- src/gui/graphicsview/qgraphicssceneevent.cpp | 1 - src/gui/graphicsview/qgraphicssceneevent.h | 3 +- src/gui/graphicsview/qgraphicsview.cpp | 2 +- src/gui/graphicsview/qgraphicswidget.cpp | 2 +- src/gui/graphicsview/qgraphicswidget.h | 2 +- src/gui/image/qimage.cpp | 17 +- src/gui/image/qimageiohandler.cpp | 1 - src/gui/image/qimageiohandler.h | 3 +- src/gui/image/qpicture.cpp | 17 +- src/gui/image/qpicture.h | 4 +- src/gui/image/qpicture_p.h | 2 +- src/gui/image/qpixmap_s60.cpp | 1 + src/gui/image/qpixmapcache.cpp | 7 +- src/gui/itemviews/qabstractitemview_p.h | 2 +- src/gui/itemviews/qfileiconprovider.cpp | 1 - src/gui/itemviews/qfileiconprovider.h | 5 +- src/gui/itemviews/qstandarditemmodel.cpp | 2 - src/gui/itemviews/qstandarditemmodel.h | 2 +- src/gui/itemviews/qtreewidget.cpp | 2 +- src/gui/itemviews/qtreewidgetitemiterator.cpp | 3 +- src/gui/itemviews/qtreewidgetitemiterator.h | 3 +- src/gui/kernel/qapplication.cpp | 8 +- src/gui/kernel/qapplication_p.h | 2 + src/gui/kernel/qapplication_qws.cpp | 27 +- src/gui/kernel/qapplication_s60.cpp | 7 + src/gui/kernel/qcursor_qws.cpp | 6 +- src/gui/kernel/qeventdispatcher_s60.cpp | 24 +- src/gui/kernel/qshortcutmap.cpp | 5 +- src/gui/kernel/qshortcutmap_p.h | 3 +- src/gui/kernel/qsound_s60.cpp | 7 +- src/gui/kernel/qt_s60_p.h | 1 + src/gui/kernel/qwidget.cpp | 46 +- src/gui/kernel/qwidget.h | 1 + src/gui/kernel/qwidget_mac.mm | 2 +- src/gui/kernel/qwidget_qws.cpp | 3 +- src/gui/painting/qbrush.cpp | 113 ++-- src/gui/painting/qbrush.h | 6 +- src/gui/painting/qdrawhelper.cpp | 4 +- src/gui/painting/qpaintengine.cpp | 1 - src/gui/painting/qpaintengine.h | 3 +- src/gui/painting/qpaintengine_raster.cpp | 168 +++--- src/gui/painting/qpainter.cpp | 61 +- src/gui/painting/qpainter.h | 5 +- src/gui/painting/qpainterpath.cpp | 21 +- src/gui/painting/qpainterpath.h | 9 +- src/gui/painting/qprinter.cpp | 1 - src/gui/painting/qprinter.h | 5 +- src/gui/painting/qprinterinfo.h | 3 +- src/gui/painting/qprinterinfo_mac.cpp | 32 +- src/gui/painting/qprinterinfo_unix.cpp | 33 +- src/gui/painting/qprinterinfo_win.cpp | 30 +- src/gui/painting/qrasterizer.cpp | 7 +- src/gui/painting/qregion.cpp | 160 +++--- src/gui/painting/qwindowsurface_raster.cpp | 2 - src/gui/painting/qwindowsurface_raster_p.h | 2 +- src/gui/styles/qs60style.h | 4 +- src/gui/text/qfont.cpp | 62 +- src/gui/text/qfont.h | 3 +- src/gui/text/qfontdatabase.cpp | 41 +- src/gui/text/qfontdatabase_qws.cpp | 81 ++- src/gui/text/qfontengine.cpp | 22 +- src/gui/text/qfontengine_ft.cpp | 84 +-- src/gui/text/qfontengine_ft_p.h | 1 + src/gui/text/qfontengine_qpf.cpp | 31 +- src/gui/text/qfontengine_qpf_p.h | 1 + src/gui/text/qfontmetrics.cpp | 8 +- src/gui/text/qfragmentmap_p.h | 8 +- src/gui/text/qtextengine.cpp | 10 +- src/gui/text/qtextlayout.cpp | 2 +- src/gui/text/qtextoption.cpp | 10 +- src/gui/text/qtexttable.cpp | 15 +- src/gui/text/qzip.cpp | 10 +- src/gui/widgets/qabstractscrollarea.cpp | 23 +- src/gui/widgets/qabstractscrollarea_p.h | 2 +- src/gui/widgets/qmacnativewidget_mac.h | 2 +- src/gui/widgets/qmenu_symbian.cpp | 7 +- src/gui/widgets/qmenudata.h | 2 + src/gui/widgets/qprintpreviewwidget.cpp | 13 +- src/gui/widgets/qprintpreviewwidget.h | 2 +- src/network/access/qftp.cpp | 12 +- src/network/access/qhttp.cpp | 1 - src/network/access/qhttp.h | 3 +- src/network/access/qhttpnetworkconnection.cpp | 6 +- src/network/access/qhttpnetworkconnection_p.h | 4 +- src/network/access/qnetworkaccesshttpbackend.cpp | 12 +- src/network/access/qnetworkaccessmanager.cpp | 2 +- src/network/access/qnetworkdiskcache.cpp | 42 +- src/network/access/qnetworkrequest.cpp | 3 +- src/network/kernel/qhostaddress.cpp | 5 +- src/network/kernel/qhostaddress.h | 3 +- src/network/kernel/qhostinfo.cpp | 20 +- src/network/kernel/qhostinfo.h | 3 +- src/network/kernel/qhostinfo_unix.cpp | 2 + src/network/kernel/qnetworkinterface.cpp | 5 +- src/network/kernel/qnetworkinterface.h | 3 +- src/network/kernel/qnetworkinterface_win.cpp | 11 +- src/network/socket/qlocalsocket_unix.cpp | 2 +- src/network/socket/qsocks5socketengine.cpp | 4 +- src/network/socket/qtcpserver.cpp | 7 +- src/network/ssl/qsslcertificate.cpp | 13 +- src/network/ssl/qsslcertificate.h | 2 +- src/network/ssl/qsslcipher.cpp | 5 +- src/network/ssl/qsslcipher.h | 3 +- src/network/ssl/qsslerror.cpp | 5 +- src/network/ssl/qsslerror.h | 2 +- src/network/ssl/qsslkey.cpp | 17 +- src/network/ssl/qsslkey.h | 3 +- src/opengl/qgl.cpp | 5 +- src/opengl/qgl.h | 3 +- src/opengl/qglframebufferobject.cpp | 1 - src/opengl/qglframebufferobject.h | 2 +- src/opengl/qglpaintdevice_qws.cpp | 2 - src/opengl/qglpaintdevice_qws_p.h | 3 +- src/opengl/qglpixelbuffer.cpp | 1 - src/opengl/qglpixelbuffer.h | 2 +- src/opengl/qpaintengine_opengl.cpp | 2 +- src/phonon/phonon.pro | 3 +- src/plugins/imageformats/mng/qmnghandler.cpp | 2 - src/plugins/imageformats/mng/qmnghandler.h | 3 +- src/plugins/s60/src/qlocale_3_2.cpp | 1 + src/qt3support/itemviews/q3table.cpp | 1 + src/qt3support/other/q3accel.cpp | 2 +- src/qt3support/painting/q3painter.h | 2 + src/s60main/qts60main.cpp | 1 + src/s60main/qts60main_mcrt0.cpp | 10 +- src/s60main/qts60mainapplication.cpp | 1 + src/s60main/qts60mainappui.cpp | 8 +- src/s60main/qts60maindocument.cpp | 1 + src/script/qscriptable.cpp | 2 - src/script/qscriptable.h | 4 +- src/script/qscriptclass.cpp | 2 - src/script/qscriptclass.h | 3 +- src/script/qscriptclasspropertyiterator.cpp | 2 - src/script/qscriptclasspropertyiterator.h | 3 +- src/script/qscriptcontext.cpp | 2 - src/script/qscriptcontext.h | 3 +- src/script/qscriptcontextinfo.cpp | 23 +- src/script/qscriptcontextinfo.h | 3 +- src/script/qscriptengine.cpp | 20 +- src/script/qscriptengine.h | 5 +- src/script/qscriptengineagent.cpp | 2 - src/script/qscriptengineagent.h | 3 +- src/script/qscriptstring.cpp | 48 +- src/script/qscriptstring.h | 5 +- src/script/qscriptvalue.cpp | 76 +-- src/script/qscriptvalue.h | 8 +- src/script/qscriptvalue_p.h | 2 +- src/script/qscriptvalueiterator.cpp | 18 +- src/script/qscriptvalueiterator.h | 4 +- .../debugging/qscriptbreakpointdata.cpp | 5 +- .../debugging/qscriptbreakpointdata_p.h | 4 +- .../debugging/qscriptdebuggerbackend.cpp | 1 - .../debugging/qscriptdebuggerbackend_p.h | 2 +- .../debugging/qscriptdebuggercommand.cpp | 5 +- .../debugging/qscriptdebuggercommand_p.h | 4 +- .../debugging/qscriptdebuggercommandexecutor.cpp | 1 - .../debugging/qscriptdebuggercommandexecutor_p.h | 3 +- .../debugging/qscriptdebuggerconsole.cpp | 1 - .../debugging/qscriptdebuggerconsole_p.h | 3 +- .../debugging/qscriptdebuggerconsolecommand.cpp | 1 - .../debugging/qscriptdebuggerconsolecommand_p.h | 4 +- .../qscriptdebuggerconsolecommandgroupdata.cpp | 14 +- .../qscriptdebuggerconsolecommandgroupdata_p.h | 4 +- .../qscriptdebuggerconsolecommandmanager.cpp | 1 - .../qscriptdebuggerconsolecommandmanager_p.h | 4 +- src/scripttools/debugging/qscriptdebuggerevent.cpp | 5 +- src/scripttools/debugging/qscriptdebuggerevent_p.h | 3 +- .../debugging/qscriptdebuggerfrontend.cpp | 1 - .../debugging/qscriptdebuggerfrontend_p.h | 4 +- src/scripttools/debugging/qscriptdebuggerjob.cpp | 1 - src/scripttools/debugging/qscriptdebuggerjob_p.h | 3 +- .../debugging/qscriptdebuggerresponse.cpp | 5 +- .../debugging/qscriptdebuggerresponse_p.h | 4 +- src/scripttools/debugging/qscriptdebuggervalue.cpp | 16 +- src/scripttools/debugging/qscriptdebuggervalue_p.h | 4 +- .../debugging/qscriptdebuggervalueproperty.cpp | 14 +- .../debugging/qscriptdebuggervalueproperty_p.h | 3 +- src/scripttools/debugging/qscriptscriptdata.cpp | 20 +- src/scripttools/debugging/qscriptscriptdata_p.h | 4 +- .../debugging/qscriptstdmessagehandler.cpp | 1 - .../debugging/qscriptstdmessagehandler_p.h | 4 +- src/scripttools/debugging/qscriptvalueproperty.cpp | 14 +- src/scripttools/debugging/qscriptvalueproperty_p.h | 3 +- src/svg/qgraphicssvgitem.h | 6 +- src/svg/qsvggenerator.cpp | 1 - src/svg/qsvggenerator.h | 3 +- src/testlib/3rdparty/cycle_p.h | 2 + src/testlib/qtestcase.cpp | 10 +- src/xml/dom/qdom.cpp | 88 ++- src/xml/sax/qxml.cpp | 81 +-- src/xml/sax/qxml.h | 5 +- src/xmlpatterns/api/qabstractxmlnodemodel.cpp | 1 - src/xmlpatterns/api/qabstractxmlnodemodel.h | 3 +- src/xmlpatterns/api/qabstractxmlreceiver.cpp | 1 - src/xmlpatterns/api/qabstractxmlreceiver.h | 3 +- src/xmlpatterns/api/qxmlresultitems.cpp | 1 - src/xmlpatterns/api/qxmlresultitems.h | 3 +- tests/auto/auto.pro | 1 + tests/auto/collections/tst_collections.cpp | 6 + tests/auto/exceptionsafety/tst_exceptionsafety.cpp | 628 ++++++++++++++++++++- tests/auto/network-settings.h | 42 +- tests/auto/qbitarray/tst_qbitarray.cpp | 27 + tests/auto/qeventloop/tst_qeventloop.cpp | 2 + tests/auto/qfiledialog/tst_qfiledialog.cpp | 9 +- tests/auto/qfontdatabase/tst_qfontdatabase.cpp | 2 +- tests/auto/qglobal/tst_qglobal.cpp | 62 ++ tests/auto/qitemdelegate/tst_qitemdelegate.cpp | 7 +- tests/auto/qscopedpointer/.gitignore | 1 + tests/auto/qscopedpointer/qscopedpointer.pro | 3 + tests/auto/qscopedpointer/tst_qscopedpointer.cpp | 282 +++++++++ tests/auto/qtcpsocket/tst_qtcpsocket.cpp | 4 +- tests/auto/qudpsocket/tst_qudpsocket.cpp | 2 +- tools/configure/configureapp.cpp | 4 +- .../components/formeditor/brushmanagerproxy.cpp | 4 +- .../src/components/formeditor/brushmanagerproxy.h | 2 +- .../src/components/formeditor/qtbrushmanager.cpp | 5 +- .../src/components/formeditor/qtbrushmanager.h | 2 +- tools/designer/src/lib/shared/iconselector.cpp | 5 +- tools/designer/src/lib/shared/iconselector_p.h | 4 +- .../src/lib/shared/qtresourceeditordialog.cpp | 5 +- .../src/lib/shared/qtresourceeditordialog_p.h | 3 +- tools/designer/src/lib/shared/qtresourcemodel.cpp | 2 - tools/designer/src/lib/shared/qtresourcemodel_p.h | 5 +- tools/designer/src/lib/shared/qtresourceview.cpp | 4 - tools/designer/src/lib/shared/qtresourceview_p.h | 4 +- tools/designer/src/uitools/quiloader.cpp | 1 - tools/designer/src/uitools/quiloader.h | 3 +- tools/shared/qtgradienteditor/qtcolorbutton.cpp | 4 +- tools/shared/qtgradienteditor/qtcolorbutton.h | 2 +- tools/shared/qtgradienteditor/qtcolorline.cpp | 4 +- tools/shared/qtgradienteditor/qtcolorline.h | 2 +- tools/shared/qtgradienteditor/qtgradientdialog.cpp | 4 +- tools/shared/qtgradienteditor/qtgradientdialog.h | 2 +- tools/shared/qtgradienteditor/qtgradienteditor.cpp | 4 +- tools/shared/qtgradienteditor/qtgradienteditor.h | 2 +- .../qtgradienteditor/qtgradientstopscontroller.cpp | 4 +- .../qtgradienteditor/qtgradientstopscontroller.h | 2 +- .../qtgradienteditor/qtgradientstopsmodel.cpp | 7 +- .../shared/qtgradienteditor/qtgradientstopsmodel.h | 4 +- .../qtgradienteditor/qtgradientstopswidget.cpp | 4 +- .../qtgradienteditor/qtgradientstopswidget.h | 2 +- tools/shared/qtgradienteditor/qtgradientwidget.cpp | 4 +- tools/shared/qtgradienteditor/qtgradientwidget.h | 2 +- .../qtpropertybrowser/qtbuttonpropertybrowser.cpp | 4 +- .../qtpropertybrowser/qtbuttonpropertybrowser.h | 2 +- tools/shared/qtpropertybrowser/qteditorfactory.cpp | 54 +- tools/shared/qtpropertybrowser/qteditorfactory.h | 30 +- .../qtgroupboxpropertybrowser.cpp | 4 +- .../qtpropertybrowser/qtgroupboxpropertybrowser.h | 2 +- .../shared/qtpropertybrowser/qtpropertybrowser.cpp | 14 +- tools/shared/qtpropertybrowser/qtpropertybrowser.h | 8 +- .../shared/qtpropertybrowser/qtpropertymanager.cpp | 128 ++--- tools/shared/qtpropertybrowser/qtpropertymanager.h | 44 +- .../qtpropertybrowser/qttreepropertybrowser.cpp | 4 +- .../qtpropertybrowser/qttreepropertybrowser.h | 2 +- .../shared/qtpropertybrowser/qtvariantproperty.cpp | 12 +- tools/shared/qtpropertybrowser/qtvariantproperty.h | 6 +- tools/shared/qttoolbardialog/qttoolbardialog.cpp | 14 +- tools/shared/qttoolbardialog/qttoolbardialog.h | 4 +- 360 files changed, 4165 insertions(+), 2217 deletions(-) create mode 100644 doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp create mode 100644 src/corelib/tools/qscopedpointer.cpp create mode 100644 src/corelib/tools/qscopedpointer.h create mode 100644 src/gui/dialogs/qfscompleter_p.h create mode 100644 tests/auto/qscopedpointer/.gitignore create mode 100644 tests/auto/qscopedpointer/qscopedpointer.pro create mode 100644 tests/auto/qscopedpointer/tst_qscopedpointer.cpp diff --git a/configure.exe b/configure.exe index 7d8861e..c90e029 100755 Binary files a/configure.exe and b/configure.exe differ diff --git a/doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp b/doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp new file mode 100644 index 0000000..05377dd --- /dev/null +++ b/doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp @@ -0,0 +1,64 @@ +//! [0] +void myFunction(bool useSubClass) +{ + MyClass *p = useSubClass ? new MyClass() : new MySubClass; + QIODevice *device = handsOverOwnership(); + QIODevi + + if (m_value > 3) { + delete p; + delete device; + return; + } + + try { + process(device); + } + catch (...) { + delete p; + delete device; + throw; + } + + delete p; + delete device; +} +//! [0] + +//! [1] +void myFunction(bool useSubClass) +{ + QScopedPointer p(useSubClass ? new MyClass() : new MySubClass); + QScopedPointer device(handsOverOwnership()); + + if (m_value > 3) + return; + + process(device); +} +//! [1] + +//! [2] + const QWidget *const p = new QWidget(); + // is equivalent to: + const QScopedPointer p(new QWidget()); + + QWidget *const p = new QWidget(); + // is equivalent to: + const QScopedPointer p(new QWidget()); + + QWidget *const p = new QWidget(); + // is equivalent to: + const QScopedPointer p(new QWidget()); + + const QWidget *p = new QWidget(); + // is equivalent to: + QScopedPointer p(new QWidget()); + +//! [2] + +//! [3] +if (scopedPointer) { + ... +} +//! [3] diff --git a/mkspecs/features/symbian/platform_paths.prf b/mkspecs/features/symbian/platform_paths.prf index 31ba09e..c9972cc 100644 --- a/mkspecs/features/symbian/platform_paths.prf +++ b/mkspecs/features/symbian/platform_paths.prf @@ -214,8 +214,12 @@ exists($${EPOCROOT}epoc32/include/platform_paths.prf) { OS_LAYER_SSL_SYSTEMINCLUDE = $$OS_LAYER_PUBLIC_EXPORT_PATH(stdapis/openssl) - OS_LAYER_STDCPP_SYSTEMINCLUDE = $$OS_LAYER_PUBLIC_EXPORT_PATH(stdapis/stlport) - + exists($$OS_LAYER_PUBLIC_EXPORT_PATH(stdapis/stlportv5)) { + OS_LAYER_STDCPP_SYSTEMINCLUDE = $$OS_LAYER_PUBLIC_EXPORT_PATH(stdapis/stlportv5) + } else { + OS_LAYER_STDCPP_SYSTEMINCLUDE = $$OS_LAYER_PUBLIC_EXPORT_PATH(stdapis/stlport) + } + OS_LAYER_BOOST_SYSTEMINCLUDE = $$OS_LAYER_PUBLIC_EXPORT_PATH(stdapis/boost) OS_LAYER_DBUS_SYSTEMINCLUDE = $$OS_LAYER_PUBLIC_EXPORT_PATH(stdapis/dbus-1.0) \ @@ -413,7 +417,12 @@ exists($${EPOCROOT}epoc32/include/platform_paths.prf) { OS_LAYER_SSL_SYSTEMINCLUDE = $$OS_LAYER_PUBLIC_EXPORT_PATH(stdapis/openssl) - OS_LAYER_STDCPP_SYSTEMINCLUDE = $$OS_LAYER_PUBLIC_EXPORT_PATH(stdapis/stlport) + # stlportv5 is preferred over stlport as it has the throwing version of operator new + exists($$OS_LAYER_PUBLIC_EXPORT_PATH(stdapis/stlportv5)) { + OS_LAYER_STDCPP_SYSTEMINCLUDE = $$OS_LAYER_PUBLIC_EXPORT_PATH(stdapis/stlportv5) + } else { + OS_LAYER_STDCPP_SYSTEMINCLUDE = $$OS_LAYER_PUBLIC_EXPORT_PATH(stdapis/stlport) + } OS_LAYER_BOOST_SYSTEMINCLUDE = $$OS_LAYER_PUBLIC_EXPORT_PATH(stdapis/boost) diff --git a/mkspecs/features/symbian/stl.prf b/mkspecs/features/symbian/stl.prf index b91d783..f01cc18 100644 --- a/mkspecs/features/symbian/stl.prf +++ b/mkspecs/features/symbian/stl.prf @@ -9,11 +9,30 @@ DEFINES *= $$STLLIB_USAGE_DEFINES # Legacy support requires some hardcoded stdapis paths. # Note: Also the new header is used from STL when it is enabled -INCLUDEPATH += \ - $${EPOCROOT}epoc32/include/stdapis/stlport \ - $$OS_LAYER_STDCPP_SYSTEMINCLUDE -LIBS *= -llibstdcpp.dll +INCLUDEPATH += $$OS_LAYER_STDCPP_SYSTEMINCLUDE \ + $${EPOCROOT}epoc32/include/stdapis/stlport # Remove mkspecs/common/symbian/stl-off from beginning of includepath # in order to use new and delete operators from STL INCLUDEPATH -= $$[QT_INSTALL_PREFIX]/mkspecs/common/symbian/stl-off + +# libstdcppv5 is preferred over libstdcpp as it has/uses the throwing version of operator new +exists($${EPOCROOT}epoc32/release/armv5/urel/libstdcppv5.dll ) { + LIBS *= -llibstdcppv5.dll + + # STDCPP turns on standard C++ new behaviour in SBSv2 + MMP_RULES += "STDCPP" + + # defining __SYMBIAN_STDCPP_SUPPORT__ turns on standard C++ new behaviour pre SBSv2 + DEFINES += "__SYMBIAN_STDCPP_SUPPORT__" + + # operator new is actually supplied in stdnew.lib for hardware builds + eabiStdNewLibBlock = \ + "$${LITERAL_HASH}ifdef EABI" \ + "LIBRARY stdnew.lib" \ + "$${LITERAL_HASH}endif" + + MMP_RULES += eabiStdNewLibBlock +} else { + LIBS *= -llibstdcpp.dll +} diff --git a/src/3rdparty/harfbuzz/src/harfbuzz-shaper.cpp b/src/3rdparty/harfbuzz/src/harfbuzz-shaper.cpp index 36b9282..2e3ef38 100644 --- a/src/3rdparty/harfbuzz/src/harfbuzz-shaper.cpp +++ b/src/3rdparty/harfbuzz/src/harfbuzz-shaper.cpp @@ -935,7 +935,13 @@ static HB_Stream getTableStream(void *font, HB_GetFontTableFunc tableFunc, HB_Ta if (error) return 0; stream = (HB_Stream)malloc(sizeof(HB_StreamRec)); + if (!stream) + return 0; stream->base = (HB_Byte*)malloc(length); + if (!stream->base) { + free(stream); + return 0; + } error = tableFunc(font, tag, stream->base, &length); if (error) { _hb_close_stream(stream); @@ -950,6 +956,8 @@ static HB_Stream getTableStream(void *font, HB_GetFontTableFunc tableFunc, HB_Ta HB_Face HB_NewFace(void *font, HB_GetFontTableFunc tableFunc) { HB_Face face = (HB_Face )malloc(sizeof(HB_FaceRec)); + if (!face) + return 0; face->isSymbolFont = false; face->gdef = 0; diff --git a/src/3rdparty/phonon/phonon/abstractmediastream.cpp b/src/3rdparty/phonon/phonon/abstractmediastream.cpp index a661702..5b860f3 100644 --- a/src/3rdparty/phonon/phonon/abstractmediastream.cpp +++ b/src/3rdparty/phonon/phonon/abstractmediastream.cpp @@ -49,7 +49,6 @@ AbstractMediaStream::AbstractMediaStream(AbstractMediaStreamPrivate &dd, QObject AbstractMediaStream::~AbstractMediaStream() { - delete d_ptr; } qint64 AbstractMediaStream::streamSize() const diff --git a/src/3rdparty/phonon/phonon/abstractmediastream.h b/src/3rdparty/phonon/phonon/abstractmediastream.h index 0daa92a..c4cde85 100644 --- a/src/3rdparty/phonon/phonon/abstractmediastream.h +++ b/src/3rdparty/phonon/phonon/abstractmediastream.h @@ -214,7 +214,7 @@ class PHONON_EXPORT AbstractMediaStream : public QObject virtual void seekStream(qint64 offset); AbstractMediaStream(AbstractMediaStreamPrivate &dd, QObject *parent); - AbstractMediaStreamPrivate *d_ptr; + QScopedPointer d_ptr; }; } // namespace Phonon diff --git a/src/3rdparty/phonon/phonon/abstractmediastream_p.h b/src/3rdparty/phonon/phonon/abstractmediastream_p.h index a9d6489..0e87c4d 100644 --- a/src/3rdparty/phonon/phonon/abstractmediastream_p.h +++ b/src/3rdparty/phonon/phonon/abstractmediastream_p.h @@ -45,6 +45,7 @@ class PHONON_EXPORT AbstractMediaStreamPrivate : private MediaNodeDestructionHan public: void setStreamInterface(StreamInterface *); void setMediaObjectPrivate(MediaObjectPrivate *); + ~AbstractMediaStreamPrivate(); protected: AbstractMediaStreamPrivate() @@ -56,7 +57,6 @@ class PHONON_EXPORT AbstractMediaStreamPrivate : private MediaNodeDestructionHan errorType(NoError) { } - ~AbstractMediaStreamPrivate(); virtual void setStreamSize(qint64 newSize); virtual void setStreamSeekable(bool s); diff --git a/src/corelib/codecs/qisciicodec.cpp b/src/corelib/codecs/qisciicodec.cpp index dd2bc8d..5619580 100644 --- a/src/corelib/codecs/qisciicodec.cpp +++ b/src/corelib/codecs/qisciicodec.cpp @@ -38,7 +38,6 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ - #include "qisciicodec_p.h" #include "qlist.h" diff --git a/src/corelib/codecs/qtextcodec.cpp b/src/corelib/codecs/qtextcodec.cpp index 6e8ffa1..cfb62c7 100644 --- a/src/corelib/codecs/qtextcodec.cpp +++ b/src/corelib/codecs/qtextcodec.cpp @@ -92,6 +92,11 @@ # define QT_NO_SETLOCALE #endif +#if 0 // ### TODO - remove me! +// enabling this is not exception safe! +#define Q_DEBUG_TEXTCODEC +#endif + QT_BEGIN_NAMESPACE #ifndef QT_NO_TEXTCODECPLUGIN @@ -165,7 +170,9 @@ static QTextCodec *createForMib(int mib) } static QList *all = 0; +#ifdef Q_DEBUG_TEXTCODEC static bool destroying_is_ok = false; +#endif static QTextCodec *localeMapper = 0; QTextCodec *QTextCodec::cftr = 0; @@ -187,15 +194,21 @@ QTextCodecCleanup::~QTextCodecCleanup() if (!all) return; +#ifdef Q_DEBUG_TEXTCODEC destroying_is_ok = true; +#endif - while (all->size()) - delete all->takeFirst(); + for (QList::const_iterator it = all->constBegin() + ; it != all->constEnd(); ++it) { + delete *it; + } delete all; all = 0; localeMapper = 0; +#ifdef Q_DEBUG_TEXTCODEC destroying_is_ok = false; +#endif } Q_GLOBAL_STATIC(QTextCodecCleanup, createQTextCodecCleanup) @@ -659,8 +672,10 @@ static void setup() if (all) return; +#ifdef Q_DEBUG_TEXTCODEC if (destroying_is_ok) qWarning("QTextCodec: Creating new codec during codec cleanup"); +#endif all = new QList; // create the cleanup object to cleanup all codecs on exit (void) createQTextCodecCleanup(); @@ -915,8 +930,10 @@ QTextCodec::QTextCodec() */ QTextCodec::~QTextCodec() { +#ifdef Q_DEBUG_TEXTCODEC if (!destroying_is_ok) qWarning("QTextCodec::~QTextCodec: Called by application"); +#endif if (all) all->removeAll(this); } diff --git a/src/corelib/concurrent/qthreadpool.cpp b/src/corelib/concurrent/qthreadpool.cpp index 30edfd4..8913b56 100644 --- a/src/corelib/concurrent/qthreadpool.cpp +++ b/src/corelib/concurrent/qthreadpool.cpp @@ -246,14 +246,14 @@ bool QThreadPoolPrivate::tooManyThreadsActive() const */ void QThreadPoolPrivate::startThread(QRunnable *runnable) { - QThreadPoolThread *thread = new QThreadPoolThread(this); - allThreads.insert(thread); + QScopedPointer thread(new QThreadPoolThread(this)); + allThreads.insert(thread.data()); ++activeThreads; if (runnable->autoDelete()) ++runnable->ref; thread->runnable = runnable; - thread->start(); + thread.take()->start(); } /*! \internal diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index ca243e7..484c618 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -1929,6 +1929,15 @@ void qt_check_pointer(const char *n, int l) qWarning("In file %s, line %d: Out of memory", n, l); } +/* \internal + Allows you to throw an exception without including + Called internally from Q_CHECK_PTR on certain OS combinations +*/ +void qBadAlloc() +{ + QT_THROW(std::bad_alloc()); +} + /* The Q_ASSERT macro calls this function when the test fails. */ @@ -2177,7 +2186,11 @@ void qt_message_output(QtMsgType msgType, const char *buf) #if defined(Q_OS_SYMBIAN) __DEBUGGER(); // on the emulator, get the debugger to kick in if there's one around - User::Invariant(); // Panic the current thread + TBuf<256> tmp; + TPtrC8 ptr(reinterpret_cast(buf)); + TInt len = Min(tmp.MaxLength(), ptr.Length()); + tmp.Copy(ptr.Left(len)); + User::Panic(tmp, 0); // Panic the current thread #elif (defined(Q_OS_UNIX) || defined(Q_CC_MINGW)) abort(); // trap; generates core dump #else @@ -2186,6 +2199,48 @@ void qt_message_output(QtMsgType msgType, const char *buf) } } +#if !defined(QT_NO_EXCEPTIONS) +/*! + \internal + Uses a local buffer to output the message. Not locale safe + cuts off + everything after character 1023, but will work in out of memory situations. +*/ +static void qEmergencyOut(QtMsgType msgType, const char *msg, va_list ap) +{ + char emergency_buf[1024] = { '\0' }; + emergency_buf[1023] = '\0'; + if (msg) + qvsnprintf(emergency_buf, 1023, msg, ap); + qt_message_output(msgType, emergency_buf); +} +#endif + +/*! + \internal +*/ +static void qt_message(QtMsgType msgType, const char *msg, va_list ap) +{ +#if !defined(QT_NO_EXCEPTIONS) + if (std::uncaught_exception()) { + qEmergencyOut(msgType, msg, ap); + return; + } +#endif + QByteArray buf; + if (msg) { + QT_TRY { + buf = QString().vsprintf(msg, ap).toLocal8Bit(); + } QT_CATCH(const std::bad_alloc &) { +#if !defined(QT_NO_EXCEPTIONS) + qEmergencyOut(msgType, msg, ap); + // don't rethrow - we use qWarning and friends in destructors. + return; +#endif + } + } + qt_message_output(msgType, buf.constData()); +} + #undef qDebug /*! \relates @@ -2223,14 +2278,10 @@ void qt_message_output(QtMsgType msgType, const char *buf) */ void qDebug(const char *msg, ...) { - QString buf; va_list ap; - va_start(ap, msg); // use variable arg list - if (msg) - buf.vsprintf(msg, ap); + va_start(ap, msg); // use variable arg list + qt_message(QtDebugMsg, msg, ap); va_end(ap); - - qt_message_output(QtDebugMsg, buf.toLocal8Bit().constData()); } #undef qWarning @@ -2267,14 +2318,10 @@ void qDebug(const char *msg, ...) */ void qWarning(const char *msg, ...) { - QString buf; va_list ap; va_start(ap, msg); // use variable arg list - if (msg) - buf.vsprintf(msg, ap); + qt_message(QtWarningMsg, msg, ap); va_end(ap); - - qt_message_output(QtWarningMsg, buf.toLocal8Bit().constData()); } /*! @@ -2307,15 +2354,12 @@ void qWarning(const char *msg, ...) */ void qCritical(const char *msg, ...) { - QString buf; va_list ap; va_start(ap, msg); // use variable arg list - if (msg) - buf.vsprintf(msg, ap); + qt_message(QtCriticalMsg, msg, ap); va_end(ap); - - qt_message_output(QtCriticalMsg, buf.toLocal8Bit().constData()); } + #ifdef QT3_SUPPORT void qSystemWarning(const char *msg, int code) { qCritical("%s (%s)", msg, qt_error_string(code).toLocal8Bit().constData()); } @@ -2323,6 +2367,8 @@ void qSystemWarning(const char *msg, int code) void qErrnoWarning(const char *msg, ...) { + // qt_error_string() will allocate anyway, so we don't have + // to be careful here (like we do in plain qWarning()) QString buf; va_list ap; va_start(ap, msg); @@ -2335,6 +2381,8 @@ void qErrnoWarning(const char *msg, ...) void qErrnoWarning(int code, const char *msg, ...) { + // qt_error_string() will allocate anyway, so we don't have + // to be careful here (like we do in plain qWarning()) QString buf; va_list ap; va_start(ap, msg); @@ -2371,14 +2419,10 @@ void qErrnoWarning(int code, const char *msg, ...) */ void qFatal(const char *msg, ...) { - QString buf; va_list ap; va_start(ap, msg); // use variable arg list - if (msg) - buf.vsprintf(msg, ap); + qt_message(QtFatalMsg, msg, ap); va_end(ap); - - qt_message_output(QtFatalMsg, buf.toLocal8Bit().constData()); } // getenv is declared as deprecated in VS2005. This function @@ -3166,4 +3210,59 @@ bool QInternal::callFunction(InternalFunction func, void **args) \sa Q_DECL_EXPORT */ +#if defined(Q_OS_SYMBIAN) + +#include + +const char* QSymbianLeaveException::what() const throw() +{ + static const char str[] = "Symbian leave exception %d"; + static char msg[sizeof(str)+12]; + sprintf(msg, str, error); + return msg; +} + +void qt_translateSymbianErrorToException(int error) +{ + if (error >= KErrNone) + return; // do nothing - not an exception + switch (error) { + case KErrNoMemory: + throw std::bad_alloc(); + default: + throw QSymbianLeaveException(error); + } +} + +void qt_translateExceptionToSymbianErrorL(const std::exception& aThrow) +{ + User::Leave(qt_translateExceptionToSymbianError(aThrow)); +} + +int qt_translateExceptionToSymbianError(const std::exception& aThrow) +{ + const std::type_info& atype = typeid(aThrow); + int err = KErrGeneral; + + if(atype == typeid (std::bad_alloc)) + err = KErrNoMemory; + else if(atype == typeid(QSymbianLeaveException)) + err = static_cast(aThrow).error; + else if(atype == typeid(std::invalid_argument)) + err = KErrArgument; + else if(atype == typeid(std::out_of_range)) + // std::out_of_range is of type logic_error which by definition means that it is + // "presumably detectable before the program executes". + // std::out_of_range is used to report an argument is not within the expected range. + // The description of KErrArgument says an argument is out of range. Hence the mapping. + err = KErrArgument; + else if(atype == typeid(std::overflow_error)) + err = KErrOverflow; + else if(atype == typeid(std::underflow_error)) + err = KErrUnderflow; + + return err; +} +#endif + QT_END_NAMESPACE diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index b075db6..030840e 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -1301,6 +1301,32 @@ class QDataStream; # define Q_AUTOTEST_EXPORT #endif +inline void qt_noop() {} + +/* These wrap try/catch so we can switch off exceptions later. + + Beware - do not use more than one QT_CATCH per QT_TRY, and do not use + the exception instance in the catch block. + If you can't live with those constraints, don't use these macros. + Use the QT_NO_EXCEPTIONS macro to protect your code instead. +*/ + +#ifdef QT_BOOTSTRAPPED +# define QT_NO_EXCEPTIONS +#endif + +#ifdef QT_NO_EXCEPTIONS +# define QT_TRY if (true) +# define QT_CATCH(A) else +# define QT_THROW(A) qt_noop() +# define QT_RETHROW qt_noop() +#else +# define QT_TRY try +# define QT_CATCH(A) catch (A) +# define QT_THROW(A) throw A +# define QT_RETHROW throw +#endif + /* System information */ @@ -1554,8 +1580,6 @@ inline QNoDebug qDebug(); #endif -inline void qt_noop() {} - Q_CORE_EXPORT void qt_assert(const char *assertion, const char *file, int line); #if !defined(Q_ASSERT) @@ -1581,11 +1605,16 @@ Q_CORE_EXPORT void qt_assert_x(const char *where, const char *what, const char * #endif Q_CORE_EXPORT void qt_check_pointer(const char *, int); +Q_CORE_EXPORT void qBadAlloc(); -#ifndef QT_NO_DEBUG -# define Q_CHECK_PTR(p) do {if(!(p))qt_check_pointer(__FILE__,__LINE__);} while (0) +#ifdef QT_NO_EXCEPTIONS +# if defined(QT_NO_DEBUG) +# define Q_CHECK_PTR(p) qt_noop(); +# else +# define Q_CHECK_PTR(p) do {if(!(p))qt_check_pointer(__FILE__,__LINE__);} while (0) +# endif #else -# define Q_CHECK_PTR(p) +# define Q_CHECK_PTR(p) do { if (!(p)) qBadAlloc(); } while (0) #endif #if (defined(Q_CC_GNU) && !defined(Q_OS_SOLARIS)) || defined(Q_CC_HPACC) @@ -1734,12 +1763,12 @@ public: static TYPE *NAME() \ { \ if (!this_##NAME.pointer && !this_##NAME.destroyed) { \ - TYPE *x = new TYPE; \ + QScopedPointer x(new TYPE); \ INITIALIZER; \ - if (!this_##NAME.pointer.testAndSetOrdered(0, x)) \ - delete x; \ - else \ + if (this_##NAME.pointer.testAndSetOrdered(0, x.data())) { \ static QGlobalStaticDeleter cleanup(this_##NAME); \ + x.take(); \ + } \ } \ return this_##NAME.pointer; \ } @@ -2193,8 +2222,8 @@ inline const QForeachContainer *qForeachContainer(const QForeachContainerBase #endif #define Q_DECLARE_PRIVATE(Class) \ - inline Class##Private* d_func() { return reinterpret_cast(d_ptr); } \ - inline const Class##Private* d_func() const { return reinterpret_cast(d_ptr); } \ + inline Class##Private* d_func() { return reinterpret_cast(d_ptr.data()); } \ + inline const Class##Private* d_func() const { return reinterpret_cast(d_ptr.data()); } \ friend class Class##Private; #define Q_DECLARE_PRIVATE_D(Dptr, Class) \ @@ -2242,7 +2271,9 @@ inline const QForeachContainer *qForeachContainer(const QForeachContainerBase Class(const Class &); \ Class &operator=(const Class &); #else -# define Q_DISABLE_COPY(Class) +# define Q_DISABLE_COPY(Class) \ + Class(const Class &); \ + Class &operator=(const Class &); #endif class QByteArray; @@ -2434,6 +2465,48 @@ QT_LICENSED_MODULE(DBus) # define QT_NO_CONCURRENT_FILTER #endif +#if defined(Q_OS_SYMBIAN) + +#include +class QSymbianLeaveException : public std::exception +{ +public: + QSymbianLeaveException(int err) : error(err){ } + const char* what() const throw(); +public: + int error; +}; + +Q_CORE_EXPORT void qt_translateSymbianErrorToException(int error); +Q_CORE_EXPORT void qt_translateExceptionToSymbianErrorL(const std::exception& ex); +Q_CORE_EXPORT int qt_translateExceptionToSymbianError(const std::exception& ex); + +#define QT_TRANSLATE_SYMBIAN_LEAVE_TO_EXCEPTION(f) \ + { \ + TInt error; \ + TRAP(error, f); \ + if (error) \ + qt_translateSymbianErrorToException(error); \ + } + +#define QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_ERROR(err, f) \ + { \ + err = KErrNone; \ + try { \ + f; \ + } catch (const std::exception &ex) { \ + err = qt_translateExceptionToSymbianError(ex); \ + } \ + } + +#define QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_LEAVE(f) \ + { \ + TInt err; \ + QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_ERROR(err, f) \ + User::LeaveIfError(err); \ + } +#endif + QT_END_NAMESPACE QT_END_HEADER diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index 29e356e..5e4b9bd 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -40,11 +40,11 @@ ****************************************************************************/ #include "qdir.h" -#include "qfile.h" +#include "qfile.h" #include "qconfig.h" #include "qsettings.h" #include "qlibraryinfo.h" -#include "qpointer.h" +#include "qscopedpointer.h" #ifdef QT_BUILD_QMAKE QT_BEGIN_NAMESPACE @@ -67,8 +67,7 @@ QT_BEGIN_NAMESPACE struct QLibrarySettings { QLibrarySettings(); - ~QLibrarySettings() { delete static_cast(settings); } - QSettings *settings; + QScopedPointer settings; }; Q_GLOBAL_STATIC(QLibrarySettings, qt_library_settings) @@ -79,32 +78,19 @@ public: static void cleanup() { QLibrarySettings *ls = qt_library_settings(); - if (ls) { - delete static_cast(ls->settings); - ls->settings = 0; - } + if (ls) + ls->settings.reset(0); } static QSettings *configuration() { -#ifdef QT_NO_THREAD - // This recursion guard should be a temporary solution; the recursive - // dependency should be found and removed. - static bool initializing = false; - if (initializing) - return 0; - initializing = true; -#endif QLibrarySettings *ls = qt_library_settings(); -#ifdef QT_NO_THREAD - initializing = false; -#endif - return ls ? static_cast(qt_library_settings()->settings) : (QSettings*)0; + return ls ? ls->settings.data() : 0; } }; QLibrarySettings::QLibrarySettings() + : settings(QLibraryInfoPrivate::findConfiguration()) { - settings = QLibraryInfoPrivate::findConfiguration(); #ifndef QT_BUILD_QMAKE qAddPostRoutine(QLibraryInfoPrivate::cleanup); #endif diff --git a/src/corelib/io/qabstractfileengine.cpp b/src/corelib/io/qabstractfileengine.cpp index bedc121..63d4944 100644 --- a/src/corelib/io/qabstractfileengine.cpp +++ b/src/corelib/io/qabstractfileengine.cpp @@ -352,8 +352,6 @@ QAbstractFileEngine::QAbstractFileEngine(QAbstractFileEnginePrivate &dd) : d_ptr */ QAbstractFileEngine::~QAbstractFileEngine() { - delete d_ptr; - d_ptr = 0; } /*! @@ -881,7 +879,6 @@ QAbstractFileEngineIterator::QAbstractFileEngineIterator(QDir::Filters filters, */ QAbstractFileEngineIterator::~QAbstractFileEngineIterator() { - delete d; } /*! diff --git a/src/corelib/io/qabstractfileengine.h b/src/corelib/io/qabstractfileengine.h index d742467..5b75343 100644 --- a/src/corelib/io/qabstractfileengine.h +++ b/src/corelib/io/qabstractfileengine.h @@ -193,7 +193,7 @@ protected: QAbstractFileEngine(); QAbstractFileEngine(QAbstractFileEnginePrivate &); - QAbstractFileEnginePrivate *d_ptr; + QScopedPointer d_ptr; private: Q_DECLARE_PRIVATE(QAbstractFileEngine) Q_DISABLE_COPY(QAbstractFileEngine) @@ -237,7 +237,7 @@ private: friend class QDirIterator; friend class QDirIteratorPrivate; void setPath(const QString &path); - QAbstractFileEngineIteratorPrivate *d; + QScopedPointer d; }; QT_END_NAMESPACE diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index 8334146..60dc688 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -79,8 +79,11 @@ public: inline QDebug &operator=(const QDebug &other); inline ~QDebug() { if (!--stream->ref) { - if(stream->message_output) - qt_message_output(stream->type, stream->buffer.toLocal8Bit().data()); + if(stream->message_output) { + QT_TRY { + qt_message_output(stream->type, stream->buffer.toLocal8Bit().data()); + } QT_CATCH(std::bad_alloc) { /* We're out of memory - give up. */ } + } delete stream; } } diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index 901641c..e1cc7ac 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -83,6 +83,7 @@ class QDirPrivate QDir *q_ptr; Q_DECLARE_PUBLIC(QDir) + friend class QScopedPointer; protected: QDirPrivate(QDir*, const QDir *copy=0); ~QDirPrivate(); @@ -573,8 +574,6 @@ QDir::QDir(const QDir &dir) : d_ptr(new QDirPrivate(this, &dir)) QDir::~QDir() { - delete d_ptr; - d_ptr = 0; } /*! diff --git a/src/corelib/io/qdir.h b/src/corelib/io/qdir.h index c4f6b1a..ac80094 100644 --- a/src/corelib/io/qdir.h +++ b/src/corelib/io/qdir.h @@ -45,6 +45,7 @@ #include #include #include +#include QT_BEGIN_HEADER @@ -57,7 +58,7 @@ class QDirPrivate; class Q_CORE_EXPORT QDir { protected: - QDirPrivate *d_ptr; + QScopedPointer d_ptr; private: Q_DECLARE_PRIVATE(QDir) public: diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp index 551485d..1e3d5a3 100644 --- a/src/corelib/io/qfile.cpp +++ b/src/corelib/io/qfile.cpp @@ -109,6 +109,7 @@ QFilePrivate::openExternalFile(int flags, int fd) return false; #else delete fileEngine; + fileEngine = 0; QFSFileEngine *fe = new QFSFileEngine; fe->setFileName(fileName); fileEngine = fe; @@ -125,6 +126,7 @@ QFilePrivate::openExternalFile(int flags, FILE *fh) return false; #else delete fileEngine; + fileEngine = 0; QFSFileEngine *fe = new QFSFileEngine; fe->setFileName(fileName); fileEngine = fe; @@ -410,9 +412,6 @@ QFile::QFile(QFilePrivate &dd, QObject *parent) QFile::~QFile() { close(); -#ifdef QT_NO_QOBJECT - delete d_ptr; -#endif } /*! diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp index 96e0f82..b36fb69 100644 --- a/src/corelib/io/qfileinfo.cpp +++ b/src/corelib/io/qfileinfo.cpp @@ -439,8 +439,6 @@ QFileInfo::QFileInfo(const QFileInfo &fileinfo) : d_ptr(new QFileInfoPrivate(&fi QFileInfo::~QFileInfo() { - delete d_ptr; - d_ptr = 0; } /*! diff --git a/src/corelib/io/qfileinfo.h b/src/corelib/io/qfileinfo.h index 97997a3..6c01f63 100644 --- a/src/corelib/io/qfileinfo.h +++ b/src/corelib/io/qfileinfo.h @@ -44,6 +44,7 @@ #include #include +#include QT_BEGIN_HEADER @@ -165,7 +166,7 @@ public: #endif protected: - QFileInfoPrivate *d_ptr; + QScopedPointer d_ptr; private: Q_DECLARE_PRIVATE(QFileInfo) }; diff --git a/src/corelib/io/qfilesystemwatcher_symbian.cpp b/src/corelib/io/qfilesystemwatcher_symbian.cpp index b1a6188..aeb19db 100644 --- a/src/corelib/io/qfilesystemwatcher_symbian.cpp +++ b/src/corelib/io/qfilesystemwatcher_symbian.cpp @@ -80,7 +80,7 @@ void CNotifyChangeEvent::RunL() if (iStatus.Int() == KErrNone){ fsSession.NotifyChange(ENotifyAll, iStatus, watchedPath); SetActive(); - engine->emitPathChanged(this); + QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_LEAVE(engine->emitPathChanged(this)); } else { qWarning("CNotifyChangeEvent::RunL() - Failed to order change notifications: %d", iStatus.Int()); } @@ -262,9 +262,9 @@ void QSymbianFileSystemWatcherEngine::run() void QSymbianFileSystemWatcherEngine::addNativeListener(const QString &directoryPath) { QMutexLocker locker(&mutex); - HBufC* buffer = qt_QString2HBufCNewL(QDir::toNativeSeparators(directoryPath)); - currentEvent = CNotifyChangeEvent::New(fsSession, *buffer, this); - delete buffer; + QString nativeDir(QDir::toNativeSeparators(directoryPath)); + TPtrC ptr(qt_QString2TPtrC(nativeDir)); + currentEvent = CNotifyChangeEvent::New(fsSession, ptr, this); syncCondition.wakeOne(); } diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp index e595f15..45e547f 100644 --- a/src/corelib/io/qfsfileengine_unix.cpp +++ b/src/corelib/io/qfsfileengine_unix.cpp @@ -404,23 +404,21 @@ bool QFSFileEngine::copy(const QString &newName) TInt err = rfs.Connect(); if (err == KErrNone) { CFileMan* fm = NULL; - HBufC* oldBuf = NULL; - HBufC* newBuf = NULL; + QString oldNative(QDir::toNativeSeparators(d->filePath)); + TPtrC oldPtr(qt_QString2TPtrC(oldNative)); + QFileInfo fi(newName); + QString absoluteNewName = fi.absolutePath() + QDir::separator() + fi.fileName(); + QString newNative(QDir::toNativeSeparators(absoluteNewName)); + TPtrC newPtr(qt_QString2TPtrC(newNative)); TRAP (err, fm = CFileMan::NewL(rfs); - oldBuf = qt_QString2HBufCNewL(QDir::toNativeSeparators(d->filePath)); RFile rfile; - err = rfile.Open(rfs, *oldBuf, EFileShareReadersOrWriters); + err = rfile.Open(rfs, oldPtr, EFileShareReadersOrWriters); if (err == KErrNone) { - QFileInfo fi(newName); - QString absoluteNewName = fi.absolutePath() + QDir::separator() + fi.fileName(); - newBuf = qt_QString2HBufCNewL(QDir::toNativeSeparators(absoluteNewName)); - err = fm->Copy(rfile, *newBuf); + err = fm->Copy(rfile, newPtr); rfile.Close(); } ) // End TRAP - delete oldBuf; - delete newBuf; delete fm; rfs.Close(); } @@ -675,10 +673,10 @@ static bool _q_isSymbianHidden(const QString &path, bool isDir) if (isDir && absPath.at(absPath.size()-1) != QChar('/')) { absPath += QChar('/'); } - HBufC* buffer = qt_QString2HBufCNewL(QDir::toNativeSeparators(absPath)); + QString native(QDir::toNativeSeparators(absPath)); + TPtrC ptr(qt_QString2TPtrC(native)); TUint attributes; - err = rfs.Att(*buffer, attributes); - delete buffer; + err = rfs.Att(ptr, attributes); rfs.Close(); if (err == KErrNone && (attributes & KEntryAttHidden)) { retval = true; diff --git a/src/corelib/io/qiodevice.h b/src/corelib/io/qiodevice.h index 76d47ca..ad87125 100644 --- a/src/corelib/io/qiodevice.h +++ b/src/corelib/io/qiodevice.h @@ -46,6 +46,7 @@ #include #else #include +#include #endif #include @@ -160,7 +161,7 @@ protected: void setErrorString(const QString &errorString); #ifdef QT_NO_QOBJECT - QIODevicePrivate *d_ptr; + QScopedPointer d_ptr; #endif private: diff --git a/src/corelib/io/qprocess_symbian.cpp b/src/corelib/io/qprocess_symbian.cpp index a59976c..26e7cdc 100644 --- a/src/corelib/io/qprocess_symbian.cpp +++ b/src/corelib/io/qprocess_symbian.cpp @@ -56,6 +56,7 @@ User::Panic(KQProcessPanic, panicReason); \ } +#include #include #include #include diff --git a/src/corelib/io/qresource.cpp b/src/corelib/io/qresource.cpp index 1f77caa..0cbcc41 100644 --- a/src/corelib/io/qresource.cpp +++ b/src/corelib/io/qresource.cpp @@ -334,7 +334,6 @@ QResource::QResource(const QString &file, const QLocale &locale) : d_ptr(new QRe */ QResource::~QResource() { - delete d_ptr; } /*! diff --git a/src/corelib/io/qresource.h b/src/corelib/io/qresource.h index 1e9b2d5..f260b68 100644 --- a/src/corelib/io/qresource.h +++ b/src/corelib/io/qresource.h @@ -91,7 +91,7 @@ protected: QStringList children() const; protected: - QResourcePrivate *d_ptr; + QScopedPointer d_ptr; private: Q_DECLARE_PRIVATE(QResource) diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index 6152518..afaaf28 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -1106,10 +1106,10 @@ static QString getPath(QSettings::Format format, QSettings::Scope scope) QString homePath = QDir::homePath(); QString systemPath; - globalMutex()->lock(); + QMutexLocker locker(globalMutex()); PathHash *pathHash = pathHashFunc(); bool loadSystemPath = pathHash->isEmpty(); - globalMutex()->unlock(); + locker.unlock(); if (loadSystemPath) { /* @@ -1121,7 +1121,7 @@ static QString getPath(QSettings::Format format, QSettings::Scope scope) systemPath += QLatin1Char('/'); } - QMutexLocker locker(globalMutex()); + locker.relock(); if (pathHash->isEmpty()) { /* Lazy initialization of pathHash. We initialize the @@ -1181,9 +1181,6 @@ QConfFileSettingsPrivate::QConfFileSettingsPrivate(QSettings::Format format, int i; initFormat(); - for (i = 0; i < NumConfFiles; ++i) - confFiles[i] = 0; - QString org = organization; if (org.isEmpty()) { setStatus(QSettings::AccessError); @@ -1196,14 +1193,14 @@ QConfFileSettingsPrivate::QConfFileSettingsPrivate(QSettings::Format format, if (scope == QSettings::UserScope) { QString userPath = getPath(format, QSettings::UserScope); if (!application.isEmpty()) - confFiles[F_User | F_Application] = QConfFile::fromName(userPath + appFile, true); - confFiles[F_User | F_Organization] = QConfFile::fromName(userPath + orgFile, true); + confFiles[F_User | F_Application].reset(QConfFile::fromName(userPath + appFile, true)); + confFiles[F_User | F_Organization].reset(QConfFile::fromName(userPath + orgFile, true)); } QString systemPath = getPath(format, QSettings::SystemScope); if (!application.isEmpty()) - confFiles[F_System | F_Application] = QConfFile::fromName(systemPath + appFile, false); - confFiles[F_System | F_Organization] = QConfFile::fromName(systemPath + orgFile, false); + confFiles[F_System | F_Application].reset(QConfFile::fromName(systemPath + appFile, false)); + confFiles[F_System | F_Organization].reset(QConfFile::fromName(systemPath + orgFile, false)); for (i = 0; i < NumConfFiles; ++i) { if (confFiles[i]) { @@ -1222,9 +1219,7 @@ QConfFileSettingsPrivate::QConfFileSettingsPrivate(const QString &fileName, { initFormat(); - confFiles[0] = QConfFile::fromName(fileName, true); - for (int i = 1; i < NumConfFiles; ++i) - confFiles[i] = 0; + confFiles[0].reset(QConfFile::fromName(fileName, true)); initAccess(); } @@ -1241,19 +1236,27 @@ QConfFileSettingsPrivate::~QConfFileSettingsPrivate() usedHash->remove(confFiles[i]->name); if (confFiles[i]->size == 0) { - delete confFiles[i]; + delete confFiles[i].take(); } else if (unusedCache) { - // compute a better size? - unusedCache->insert(confFiles[i]->name, confFiles[i], + QT_TRY { + // compute a better size? + unusedCache->insert(confFiles[i]->name, confFiles[i].data(), 10 + (confFiles[i]->originalKeys.size() / 4)); + confFiles[i].take(); + } QT_CATCH(...) { + // out of memory. Do not cache the file. + delete confFiles[i].take(); + } } } + // prevent the ScopedPointer to deref it again. + confFiles[i].take(); } } void QConfFileSettingsPrivate::remove(const QString &key) { - QConfFile *confFile = confFiles[spec]; + QConfFile *confFile = confFiles[spec].data(); if (!confFile) return; @@ -1280,7 +1283,7 @@ void QConfFileSettingsPrivate::remove(const QString &key) void QConfFileSettingsPrivate::set(const QString &key, const QVariant &value) { - QConfFile *confFile = confFiles[spec]; + QConfFile *confFile = confFiles[spec].data(); if (!confFile) return; @@ -1297,7 +1300,7 @@ bool QConfFileSettingsPrivate::get(const QString &key, QVariant *value) const bool found = false; for (int i = 0; i < NumConfFiles; ++i) { - if (QConfFile *confFile = confFiles[i]) { + if (QConfFile *confFile = confFiles[i].data()) { QMutexLocker locker(&confFile->mutex); if (!confFile->addedKeys.isEmpty()) { @@ -1332,7 +1335,7 @@ QStringList QConfFileSettingsPrivate::children(const QString &prefix, ChildSpec int startPos = prefix.size(); for (int i = 0; i < NumConfFiles; ++i) { - if (QConfFile *confFile = confFiles[i]) { + if (QConfFile *confFile = confFiles[i].data()) { QMutexLocker locker(&confFile->mutex); if (thePrefix.isEmpty()) { @@ -1365,7 +1368,7 @@ QStringList QConfFileSettingsPrivate::children(const QString &prefix, ChildSpec void QConfFileSettingsPrivate::clear() { - QConfFile *confFile = confFiles[spec]; + QConfFile *confFile = confFiles[spec].data(); if (!confFile) return; @@ -1381,7 +1384,7 @@ void QConfFileSettingsPrivate::sync() // error we just try to go on and make the best of it for (int i = 0; i < NumConfFiles; ++i) { - QConfFile *confFile = confFiles[i]; + QConfFile *confFile = confFiles[i].data(); if (confFile) { QMutexLocker locker(&confFile->mutex); syncConfFile(i); @@ -1396,7 +1399,7 @@ void QConfFileSettingsPrivate::flush() QString QConfFileSettingsPrivate::fileName() const { - QConfFile *confFile = confFiles[spec]; + QConfFile *confFile = confFiles[spec].data(); if (!confFile) return QString(); return confFile->name; @@ -1407,7 +1410,7 @@ bool QConfFileSettingsPrivate::isWritable() const if (format > QSettings::IniFormat && !writeFunc) return false; - QConfFile *confFile = confFiles[spec]; + QConfFile *confFile = confFiles[spec].data(); if (!confFile) return false; @@ -1416,7 +1419,7 @@ bool QConfFileSettingsPrivate::isWritable() const void QConfFileSettingsPrivate::syncConfFile(int confFileNo) { - QConfFile *confFile = confFiles[confFileNo]; + QConfFile *confFile = confFiles[confFileNo].data(); bool readOnly = confFile->addedKeys.isEmpty() && confFile->removedKeys.isEmpty(); bool ok; @@ -2759,11 +2762,13 @@ QSettings::QSettings(const QString &fileName, Format format) QSettings::~QSettings() { Q_D(QSettings); - if (d->pendingChanges) - d->flush(); -#ifdef QT_NO_QOBJECT - delete d; -#endif + if (d->pendingChanges) { + QT_TRY { + d->flush(); + } QT_CATCH(...) { + ; // ok. then don't flush but at least don't throw in the destructor + } + } } /*! @@ -3566,8 +3571,7 @@ void QSettings::setPath_helper(Scope scope, const QString &organization, const Q QSettingsPrivate *oldPriv = d; QSettingsPrivate *newPriv = QSettingsPrivate::create(oldPriv->format, scope, organization, application); static_cast(*newPriv) = static_cast(*oldPriv); // copy the QObject stuff over (hack) - delete oldPriv; - d_ptr = newPriv; + d_ptr.reset(newPriv); } /*! \fn bool QSettings::writeEntry(const QString &key, bool value) diff --git a/src/corelib/io/qsettings.h b/src/corelib/io/qsettings.h index cbb24ba..41bce89 100644 --- a/src/corelib/io/qsettings.h +++ b/src/corelib/io/qsettings.h @@ -78,7 +78,7 @@ class Q_CORE_EXPORT QSettings #ifndef QT_NO_QOBJECT Q_OBJECT #else - QSettingsPrivate *d_ptr; + QScopedPointer d_ptr; #endif Q_DECLARE_PRIVATE(QSettings) diff --git a/src/corelib/io/qsettings_p.h b/src/corelib/io/qsettings_p.h index dd72fd9..1bdbf2c 100644 --- a/src/corelib/io/qsettings_p.h +++ b/src/corelib/io/qsettings_p.h @@ -300,7 +300,7 @@ private: void ensureAllSectionsParsed(QConfFile *confFile) const; void ensureSectionParsed(QConfFile *confFile, const QSettingsKey &key) const; - QConfFile *confFiles[NumConfFiles]; + QScopedSharedPointer confFiles[NumConfFiles]; QSettings::ReadFunc readFunc; QSettings::WriteFunc writeFunc; QString extension; diff --git a/src/corelib/io/qtextstream.cpp b/src/corelib/io/qtextstream.cpp index 1167671..9382fae 100644 --- a/src/corelib/io/qtextstream.cpp +++ b/src/corelib/io/qtextstream.cpp @@ -1112,9 +1112,6 @@ QTextStream::~QTextStream() #endif if (!d->writeBuffer.isEmpty()) d->flushWriteBuffer(); - - delete d; - d_ptr = 0; } /*! diff --git a/src/corelib/io/qtextstream.h b/src/corelib/io/qtextstream.h index 6302d34..cfacec6 100644 --- a/src/corelib/io/qtextstream.h +++ b/src/corelib/io/qtextstream.h @@ -46,6 +46,7 @@ #include #include #include +#include #ifndef QT_NO_TEXTCODEC # ifdef QT3_SUPPORT @@ -256,7 +257,7 @@ private: Q_DISABLE_COPY(QTextStream) - QTextStreamPrivate *d_ptr; + QScopedPointer d_ptr; }; Q_DECLARE_OPERATORS_FOR_FLAGS(QTextStream::NumberFlags) diff --git a/src/corelib/kernel/qcore_symbian_p.cpp b/src/corelib/kernel/qcore_symbian_p.cpp index 4f18490..101ed44 100644 --- a/src/corelib/kernel/qcore_symbian_p.cpp +++ b/src/corelib/kernel/qcore_symbian_p.cpp @@ -39,9 +39,11 @@ ** ****************************************************************************/ +#include #include #include #include "qcore_symbian_p.h" +#include QT_BEGIN_NAMESPACE @@ -51,18 +53,17 @@ QT_BEGIN_NAMESPACE must be deleted by the caller. */ -Q_CORE_EXPORT HBufC* qt_QString2HBufCNewL(const QString& aString) +Q_CORE_EXPORT HBufC* qt_QString2HBufC(const QString& aString) { HBufC *buffer; #ifdef QT_NO_UNICODE TPtrC8 ptr(reinterpret_cast(aString.toLocal8Bit().constData())); - buffer = HBufC8::NewL(ptr.Length()); - buffer->Des().Copy(ptr); #else - TPtrC16 ptr(reinterpret_cast(aString.utf16())); - buffer = HBufC16::NewL(ptr.Length()); - buffer->Des().Copy(ptr); + TPtrC16 ptr(qt_QString2TPtrC(aString)); #endif + buffer = HBufC::New(ptr.Length()); + Q_CHECK_PTR(buffer); + buffer->Des().Copy(ptr); return buffer; } @@ -82,7 +83,8 @@ QHBufC::QHBufC() QHBufC::QHBufC(const QHBufC &src) { - m_hBufC = src.m_hBufC->AllocL(); + m_hBufC = src.m_hBufC->Alloc(); + Q_CHECK_PTR(m_hBufC); } /*! @@ -97,7 +99,7 @@ QHBufC::QHBufC(HBufC *src) QHBufC::QHBufC(const QString &src) { - m_hBufC = qt_QString2HBufCNewL(src); + m_hBufC = qt_QString2HBufC(src); } QHBufC::~QHBufC() @@ -172,4 +174,5 @@ Q_CORE_EXPORT TLibraryFunction qt_resolveS60PluginFunc(int ordinal) return qt_s60_plugin_resolver()->resolve(ordinal); } + QT_END_NAMESPACE diff --git a/src/corelib/kernel/qcore_symbian_p.h b/src/corelib/kernel/qcore_symbian_p.h index 3b974c3..bd8f304 100644 --- a/src/corelib/kernel/qcore_symbian_p.h +++ b/src/corelib/kernel/qcore_symbian_p.h @@ -63,7 +63,7 @@ QT_BEGIN_HEADER QT_BEGIN_NAMESPACE -Q_CORE_EXPORT HBufC* qt_QString2HBufCNewL(const QString& aString); +Q_CORE_EXPORT HBufC* qt_QString2HBufC(const QString& aString); Q_CORE_EXPORT QString qt_TDesC2QStringL(const TDesC& aDescriptor); inline QString qt_TDes2QStringL(const TDes& aDescriptor) { return qt_TDesC2QStringL(aDescriptor); } @@ -91,7 +91,7 @@ static inline TRect qt_QRect2TRect(const QRect& qr) // Returned TPtrC is valid as long as the given parameter is valid and unmodified static inline TPtrC qt_QString2TPtrC( const QString& string ) { - return reinterpret_cast(string.utf16()); + return TPtrC16(static_cast(string.utf16()), string.length()); } class Q_CORE_EXPORT QHBufC diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index d99164b..5c3fd76 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -63,8 +63,10 @@ #include #ifdef Q_OS_SYMBIAN +# include # include # include "qeventdispatcher_symbian_p.h" +# include "private/qcore_symbian_p.h" #elif defined(Q_OS_UNIX) # if !defined(QT_NO_GLIB) # include "qeventdispatcher_glib_p.h" @@ -88,6 +90,21 @@ QT_BEGIN_NAMESPACE +class QLockedMutexUnlocker +{ +public: + inline explicit QLockedMutexUnlocker(QMutex *m) + : mtx(m) + { } + inline ~QLockedMutexUnlocker() { unlock(); } + inline void unlock() { if (mtx) mtx->unlock(); mtx = 0; } + +private: + Q_DISABLE_COPY(QLockedMutexUnlocker) + + QMutex *mtx; +}; + #if defined(Q_WS_WIN) || defined(Q_WS_MAC) extern QString qAppFileName(); #endif @@ -159,7 +176,14 @@ void qRemovePostRoutine(QtCleanUpFunction p) void Q_CORE_EXPORT qt_call_post_routines() { - QVFuncList *list = postRList(); + QVFuncList *list = 0; + QT_TRY { + list = postRList(); + } QT_CATCH(const std::bad_alloc &) { + // ignore - if we can't allocate a post routine list, + // there's a high probability that there's no post + // routine to be executed :) + } if (!list) return; while (!list->isEmpty()) @@ -248,24 +272,26 @@ QCoreApplicationPrivate::QCoreApplicationPrivate(int &aargc, char **aargv) QCoreApplicationPrivate::~QCoreApplicationPrivate() { + if (threadData) { #ifndef QT_NO_THREAD - void *data = &threadData->tls; - QThreadStorageData::finish((void **)data); + void *data = &threadData->tls; + QThreadStorageData::finish((void **)data); #endif - // need to clear the state of the mainData, just in case a new QCoreApplication comes along. - QMutexLocker locker(&threadData->postEventList.mutex); - for (int i = 0; i < threadData->postEventList.size(); ++i) { - const QPostEvent &pe = threadData->postEventList.at(i); - if (pe.event) { - --pe.receiver->d_func()->postedEvents; - pe.event->posted = false; - delete pe.event; + // need to clear the state of the mainData, just in case a new QCoreApplication comes along. + QMutexLocker locker(&threadData->postEventList.mutex); + for (int i = 0; i < threadData->postEventList.size(); ++i) { + const QPostEvent &pe = threadData->postEventList.at(i); + if (pe.event) { + --pe.receiver->d_func()->postedEvents; + pe.event->posted = false; + delete pe.event; + } } + threadData->postEventList.clear(); + threadData->postEventList.recursion = 0; + threadData->quitNow = false; } - threadData->postEventList.clear(); - threadData->postEventList.recursion = 0; - threadData->quitNow = false; } void QCoreApplicationPrivate::createEventDispatcher() @@ -544,7 +570,14 @@ QCoreApplication::~QCoreApplication() #if !defined(QT_NO_THREAD) #if !defined(QT_NO_CONCURRENT) // Synchronize and stop the global thread pool threads. - QThreadPool::globalInstance()->waitForDone(); + QThreadPool *globalThreadPool = 0; + QT_TRY { + globalThreadPool = QThreadPool::globalInstance(); + } QT_CATCH (...) { + // swallow the exception, since destructors shouldn't throw + } + if (globalThreadPool) + globalThreadPool->waitForDone(); #endif QThread::cleanup(); #endif @@ -626,26 +659,13 @@ bool QCoreApplication::notifyInternal(QObject *receiver, QEvent *event) d->inEventHandler = true; #endif -#if defined(Q_OS_SYMBIAN) -// __UHEAP_MARK; - TInt error; - bool returnValue = false; - TRAP(error, returnValue = notify(receiver, event)); - if (error != KErrNone) { - qWarning(QString("Symbian OS error: %1").arg(error).toAscii().constData()); - } -// __UHEAP_MARKEND; -#elif defined(QT_NO_EXCEPTIONS) - bool returnValue = notify(receiver, event); -#else bool returnValue; - try { + QT_TRY { returnValue = notify(receiver, event); - } catch(...) { + } QT_CATCH (...) { --threadData->loopLevel; - throw; + QT_RETHROW; } -#endif #ifdef QT_JAMBI_BUILD // Restore the previous state if the object was not deleted.. @@ -1066,15 +1086,14 @@ void QCoreApplication::postEvent(QObject *receiver, QEvent *event, int priority) data->postEventList.mutex.lock(); } + QLockedMutexUnlocker locker(&data->postEventList.mutex); + // if this is one of the compressible events, do compression if (receiver->d_func()->postedEvents && self && self->compressEvent(event, receiver, &data->postEventList)) { - data->postEventList.mutex.unlock(); return; } - event->posted = true; - ++receiver->d_func()->postedEvents; if (event->type() == QEvent::DeferredDelete && data == QThreadData::current()) { // remember the current running eventloop for DeferredDelete // events posted in the receiver's thread @@ -1095,8 +1114,10 @@ void QCoreApplication::postEvent(QObject *receiver, QEvent *event, int priority) QPostEventList::iterator at = qUpperBound(begin, end, priority); data->postEventList.insert(at, QPostEvent(receiver, event, priority)); } + event->posted = true; + ++receiver->d_func()->postedEvents; data->canWait = false; - data->postEventList.mutex.unlock(); + locker.unlock(); if (data->eventDispatcher) data->eventDispatcher->wakeUp(); diff --git a/src/corelib/kernel/qcoreapplication.h b/src/corelib/kernel/qcoreapplication.h index 65733ac..095d501 100644 --- a/src/corelib/kernel/qcoreapplication.h +++ b/src/corelib/kernel/qcoreapplication.h @@ -195,6 +195,8 @@ private: void init(); static QCoreApplication *self; + + Q_DISABLE_COPY(QCoreApplication) friend class QEventDispatcherUNIXPrivate; friend class QApplication; diff --git a/src/corelib/kernel/qeventdispatcher_symbian.cpp b/src/corelib/kernel/qeventdispatcher_symbian.cpp index c5d91c2..423fbaa 100644 --- a/src/corelib/kernel/qeventdispatcher_symbian.cpp +++ b/src/corelib/kernel/qeventdispatcher_symbian.cpp @@ -193,7 +193,7 @@ void QWakeUpActiveObject::RunL() { iStatus = KRequestPending; SetActive(); - m_dispatcher->wakeUpWasCalled(); + QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_LEAVE(m_dispatcher->wakeUpWasCalled()); } QTimerActiveObject::QTimerActiveObject(QEventDispatcherSymbian *dispatcher, SymbianTimerInfo *timerInfo) @@ -222,9 +222,15 @@ void QTimerActiveObject::DoCancel() void QTimerActiveObject::RunL() { - if (!okToRun()) - return; + int error; + QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_ERROR(error, Run()); + if (error < 0) { + CActiveScheduler::Current()->Error(error); // stop and report here, as this timer will be deleted on scope exit + } +} +void QTimerActiveObject::Run() +{ if (m_timerInfo->interval > 0) { // Start a new timer immediately so that we don't lose time. iStatus = KRequestPending; @@ -240,7 +246,7 @@ void QTimerActiveObject::RunL() SymbianTimerInfoPtr timerInfoPtr(m_timerInfo); m_timerInfo->dispatcher->timerFired(m_timerInfo->timerId); - + iStatus = KRequestPending; SetActive(); TRequestStatus *status = &iStatus; @@ -304,7 +310,7 @@ void QCompleteDeferredAOs::RunL() iStatus = KRequestPending; SetActive(); - m_dispatcher->reactivateDeferredActiveObjects(); + QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_LEAVE(m_dispatcher->reactivateDeferredActiveObjects()); } QSelectThread::QSelectThread() @@ -577,7 +583,7 @@ void QSocketActiveObject::RunL() if (!okToRun()) return; - m_dispatcher->socketFired(this); + QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_LEAVE(m_dispatcher->socketFired(this)); } void QSocketActiveObject::deleteLater() @@ -633,101 +639,108 @@ void QEventDispatcherSymbian::closingDown() bool QEventDispatcherSymbian::processEvents ( QEventLoop::ProcessEventsFlags flags ) { - Q_D(QAbstractEventDispatcher); + bool handledAnyEvent = false; + QT_TRY { + Q_D(QAbstractEventDispatcher); + // It is safe if this counter overflows. The main importance is that each // iteration count is different from the last. m_iterationCount++; - RThread &thread = d->threadData->symbian_thread_handle; - - bool block; - if (flags & QEventLoop::WaitForMoreEvents) { - block = true; - emit aboutToBlock(); - } else { - block = false; - } - - bool handledAnyEvent = false; - - bool oldNoSocketEventsValue = m_noSocketEvents; - if (flags & QEventLoop::ExcludeSocketNotifiers) { - m_noSocketEvents = true; - } else { - m_noSocketEvents = false; - handledAnyEvent = sendDeferredSocketEvents(); - } - - bool handledSymbianEvent = false; - m_interrupt = false; - - /* - * This QTime variable is used to measure the time it takes to finish - * the event loop. If we take too long in the loop, other processes - * may be starved and killed. After the first event has completed, we - * take the current time, and if the remaining events take longer than - * a preset time, we temporarily lower the priority to force a context - * switch. For applications that do not take unecessarily long in the - * event loop, the priority will not be altered. - */ - QTime time; - enum { - FirstRun, - SubsequentRun, - TimeStarted - } timeState = FirstRun; - - TProcessPriority priority; - - while (1) { - if (block) { - // This is where Qt will spend most of its time. - CActiveScheduler::Current()->WaitForAnyRequest(); + RThread &thread = d->threadData->symbian_thread_handle; + + bool block; + if (flags & QEventLoop::WaitForMoreEvents) { + block = true; + emit aboutToBlock(); } else { - if (thread.RequestCount() == 0) { - break; - } - // This one should return without delay. - CActiveScheduler::Current()->WaitForAnyRequest(); - } - - if (timeState == SubsequentRun) { - time.start(); - timeState = TimeStarted; - } - - TInt error; - handledSymbianEvent = CActiveScheduler::RunIfReady(error, CActive::EPriorityIdle); - if (error) { - qWarning("CActiveScheduler::RunIfReady() returned error: %i\n", error); - CActiveScheduler::Current()->Error(error); + block = false; } - if (!handledSymbianEvent) { - qFatal("QEventDispatcherSymbian::processEvents(): Caught Symbian stray signal"); - } - handledAnyEvent = true; - if (m_interrupt) { - break; + + bool oldNoSocketEventsValue = m_noSocketEvents; + if (flags & QEventLoop::ExcludeSocketNotifiers) { + m_noSocketEvents = true; + } else { + m_noSocketEvents = false; + handledAnyEvent = sendDeferredSocketEvents(); } - block = false; + + bool handledSymbianEvent = false; + m_interrupt = false; + + /* + * This QTime variable is used to measure the time it takes to finish + * the event loop. If we take too long in the loop, other processes + * may be starved and killed. After the first event has completed, we + * take the current time, and if the remaining events take longer than + * a preset time, we temporarily lower the priority to force a context + * switch. For applications that do not take unecessarily long in the + * event loop, the priority will not be altered. + */ + QTime time; + enum { + FirstRun, + SubsequentRun, + TimeStarted + } timeState = FirstRun; + + TProcessPriority priority; + + while (1) { + if (block) { + // This is where Qt will spend most of its time. + CActiveScheduler::Current()->WaitForAnyRequest(); + } else { + if (thread.RequestCount() == 0) { + break; + } + // This one should return without delay. + CActiveScheduler::Current()->WaitForAnyRequest(); + } + + if (timeState == SubsequentRun) { + time.start(); + timeState = TimeStarted; + } + + TInt error; + handledSymbianEvent = CActiveScheduler::RunIfReady(error, CActive::EPriorityIdle); + if (error) { + qWarning("CActiveScheduler::RunIfReady() returned error: %i\n", error); + CActiveScheduler::Current()->Error(error); + } + + if (!handledSymbianEvent) { + qFatal("QEventDispatcherSymbian::processEvents(): Caught Symbian stray signal"); + } + handledAnyEvent = true; + if (m_interrupt) { + break; + } + block = false; if (timeState == TimeStarted && time.elapsed() > 100) { - priority = m_processHandle.Priority(); - m_processHandle.SetPriority(EPriorityLow); - time.start(); - // Slight chance of race condition in the next lines, but nothing fatal - // will happen, just wrong priority. - if (m_processHandle.Priority() == EPriorityLow) { - m_processHandle.SetPriority(priority); + priority = m_processHandle.Priority(); + m_processHandle.SetPriority(EPriorityLow); + time.start(); + // Slight chance of race condition in the next lines, but nothing fatal + // will happen, just wrong priority. + if (m_processHandle.Priority() == EPriorityLow) { + m_processHandle.SetPriority(priority); + } } - } - if (timeState == FirstRun) - timeState = SubsequentRun; - }; - - emit awake(); - - m_noSocketEvents = oldNoSocketEventsValue; + if (timeState == FirstRun) + timeState = SubsequentRun; + }; + + emit awake(); + + m_noSocketEvents = oldNoSocketEventsValue; + } QT_CATCH (const std::exception& ex) { +#ifndef QT_NO_EXCEPTIONS + CActiveScheduler::Current()->Error(qt_translateExceptionToSymbianError(ex)); +#endif + } return handledAnyEvent; } diff --git a/src/corelib/kernel/qeventdispatcher_symbian_p.h b/src/corelib/kernel/qeventdispatcher_symbian_p.h index 64ea282..3593055 100644 --- a/src/corelib/kernel/qeventdispatcher_symbian_p.h +++ b/src/corelib/kernel/qeventdispatcher_symbian_p.h @@ -136,6 +136,9 @@ public: protected: void DoCancel(); void RunL(); + +private: + void Run(); private: SymbianTimerInfo *m_timerInfo; diff --git a/src/corelib/kernel/qeventdispatcher_unix.cpp b/src/corelib/kernel/qeventdispatcher_unix.cpp index f7293d4..ea8299c 100644 --- a/src/corelib/kernel/qeventdispatcher_unix.cpp +++ b/src/corelib/kernel/qeventdispatcher_unix.cpp @@ -184,7 +184,7 @@ int QEventDispatcherUNIXPrivate::doSelect(QEventLoop::ProcessEventsFlags flags, continue; for (int i = 0; i < list.size(); ++i) { - QSockNot *sn = list.at(i); + QSockNot *sn = list[i]; FD_ZERO(&fdset); FD_SET(sn->fd, &fdset); @@ -241,7 +241,7 @@ int QEventDispatcherUNIXPrivate::doSelect(QEventLoop::ProcessEventsFlags flags, for (int i=0; i<3; i++) { QSockNotType::List &list = sn_vec[i].list; for (int j = 0; j < list.size(); ++j) { - QSockNot *sn = list.at(j); + QSockNot *sn = list[j]; if (FD_ISSET(sn->fd, &sn_vec[i].select_fds)) q->setSocketNotifierPending(sn->obj); } @@ -599,7 +599,10 @@ QEventDispatcherUNIX::QEventDispatcherUNIX(QEventDispatcherUNIXPrivate &dd, QObj { } QEventDispatcherUNIX::~QEventDispatcherUNIX() -{ } +{ + Q_D(QEventDispatcherUNIX); + d->threadData->eventDispatcher = 0; +} int QEventDispatcherUNIX::select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, timeval *timeout) @@ -706,8 +709,8 @@ QSockNotType::QSockNotType() QSockNotType::~QSockNotType() { - while (!list.isEmpty()) - delete list.takeFirst(); + for (int i = 0; i < list.size(); ++i) + delete list[i]; } /***************************************************************************** @@ -743,7 +746,7 @@ void QEventDispatcherUNIX::registerSocketNotifier(QSocketNotifier *notifier) int i; for (i = 0; i < list.size(); ++i) { - QSockNot *p = list.at(i); + QSockNot *p = list[i]; if (p->fd < sockfd) break; if (p->fd == sockfd) { @@ -781,7 +784,7 @@ void QEventDispatcherUNIX::unregisterSocketNotifier(QSocketNotifier *notifier) QSockNot *sn = 0; int i; for (i = 0; i < list.size(); ++i) { - sn = list.at(i); + sn = list[i]; if(sn->obj == notifier && sn->fd == sockfd) break; } @@ -799,7 +802,7 @@ void QEventDispatcherUNIX::unregisterSocketNotifier(QSocketNotifier *notifier) for (int i=0; i<3; i++) { if (!d->sn_vec[i].list.isEmpty()) d->sn_highest = qMax(d->sn_highest, // list is fd-sorted - d->sn_vec[i].list.first()->fd); + d->sn_vec[i].list[0]->fd); } } } @@ -823,7 +826,7 @@ void QEventDispatcherUNIX::setSocketNotifierPending(QSocketNotifier *notifier) QSockNot *sn = 0; int i; for (i = 0; i < list.size(); ++i) { - sn = list.at(i); + sn = list[i]; if(sn->obj == notifier && sn->fd == sockfd) break; } diff --git a/src/corelib/kernel/qeventdispatcher_unix_p.h b/src/corelib/kernel/qeventdispatcher_unix_p.h index 41329cf..816add5 100644 --- a/src/corelib/kernel/qeventdispatcher_unix_p.h +++ b/src/corelib/kernel/qeventdispatcher_unix_p.h @@ -57,6 +57,7 @@ #include "QtCore/qlist.h" #include "private/qabstracteventdispatcher_p.h" #include "private/qpodlist_p.h" +#include "QtCore/qvarlengtharray.h" #include #include diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 860180e..ac505e1 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -392,7 +392,9 @@ void QMetaObject::removeGuard(QObject **ptr) if (!*ptr) return; GuardHash *hash = guardHash(); - if (!hash) + /* check that the hash is empty - otherwise we might detach + the shared_null hash, which will alloc, which is not nice */ + if (!hash || hash->isEmpty()) return; QMutexLocker locker(guardHashLock()); GuardHash::iterator it = hash->find(*ptr); @@ -434,9 +436,19 @@ void QMetaObject::changeGuard(QObject **ptr, QObject *o) */ void QObjectPrivate::clearGuards(QObject *object) { - GuardHash *hash = guardHash(); - if (hash) { - QMutexLocker locker(guardHashLock()); + GuardHash *hash = 0; + QMutex *mutex = 0; + QT_TRY { + hash = guardHash(); + mutex = guardHashLock(); + } QT_CATCH(const std::bad_alloc &) { + // do nothing in case of OOM - code below is safe + } + + /* check that the hash is empty - otherwise we might detach + the shared_null hash, which will alloc, which is not nice */ + if (hash && !hash->isEmpty()) { + QMutexLocker locker(mutex); GuardHash::iterator it = hash->find(object); const GuardHash::iterator end = hash->end(); while (it.key() == object && it != end) { @@ -754,7 +766,14 @@ QObject::~QObject() QObjectPrivate::clearGuards(this); } - emit destroyed(this); + QT_TRY { + emit destroyed(this); + } QT_CATCH(...) { + // all the signal/slots connections are still in place - if we don't + // quit now, we will crash pretty soon. + qWarning("Detected an unexpected exception in ~QObject while emitting destroyed()."); + QT_RETHROW; + } { QMutexLocker locker(&d->threadData->mutex); @@ -853,9 +872,6 @@ QObject::~QObject() objectName().isNull() ? "unnamed" : qPrintable(objectName())); } #endif - - delete d; - d_ptr = 0; } @@ -1098,11 +1114,11 @@ bool QObject::event(QEvent *e) #if defined(QT_NO_EXCEPTIONS) mce->placeMetaCall(this); #else - try { + QT_TRY { mce->placeMetaCall(this); - } catch (...) { + } QT_CATCH(...) { QObjectPrivate::resetCurrentSender(this, ¤tSender, previousSender); - throw; + QT_RETHROW; } #endif QObjectPrivate::resetCurrentSender(this, ¤tSender, previousSender); @@ -3102,9 +3118,9 @@ void QMetaObject::activate(QObject *sender, int from_signal_index, int to_signal #if defined(QT_NO_EXCEPTIONS) receiver->qt_metacall(QMetaObject::InvokeMetaMethod, method, argv ? argv : empty_argv); #else - try { + QT_TRY { receiver->qt_metacall(QMetaObject::InvokeMetaMethod, method, argv ? argv : empty_argv); - } catch (...) { + } QT_CATCH(...) { locker.relock(); QObjectPrivate::resetCurrentSender(receiver, ¤tSender, previousSender); @@ -3113,7 +3129,7 @@ void QMetaObject::activate(QObject *sender, int from_signal_index, int to_signal Q_ASSERT(connectionLists->inUse >= 0); if (connectionLists->orphaned && !connectionLists->inUse) delete connectionLists; - throw; + QT_RETHROW; } #endif diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h index dbec0a6..8d5c4e3 100644 --- a/src/corelib/kernel/qobject.h +++ b/src/corelib/kernel/qobject.h @@ -51,6 +51,7 @@ #ifdef QT_INCLUDE_COMPAT #include #endif +#include QT_BEGIN_HEADER @@ -286,7 +287,7 @@ protected: QObject(QObjectPrivate &dd, QObject *parent = 0); protected: - QObjectData *d_ptr; + QScopedPointer d_ptr; static const QMetaObject staticQtMetaObject; diff --git a/src/corelib/kernel/qsharedmemory_symbian.cpp b/src/corelib/kernel/qsharedmemory_symbian.cpp index b3b50e3..d05f9f3 100644 --- a/src/corelib/kernel/qsharedmemory_symbian.cpp +++ b/src/corelib/kernel/qsharedmemory_symbian.cpp @@ -116,11 +116,9 @@ bool QSharedMemoryPrivate::create(int size) return false; } - HBufC* buffer = qt_QString2HBufCNewL(safeKey); + TPtrC ptr(qt_QString2TPtrC(safeKey)); - TInt err = chunk.CreateGlobal(*buffer, size, size); - - delete buffer; + TInt err = chunk.CreateGlobal(ptr, size, size); setErrorString(function, err); @@ -147,15 +145,11 @@ bool QSharedMemoryPrivate::attach(QSharedMemory::AccessMode mode) return false; } - HBufC* buffer = qt_QString2HBufCNewL(safeKey); + TPtrC ptr(qt_QString2TPtrC(safeKey)); TInt err = KErrNoMemory; - if (buffer) { - err = chunk.OpenGlobal(*buffer, false); - } - - delete buffer; + err = chunk.OpenGlobal(ptr, false); if (err != KErrNone) { setErrorString(function, err); diff --git a/src/corelib/kernel/qsystemsemaphore.cpp b/src/corelib/kernel/qsystemsemaphore.cpp index 7e09a6e..fb9385a 100644 --- a/src/corelib/kernel/qsystemsemaphore.cpp +++ b/src/corelib/kernel/qsystemsemaphore.cpp @@ -170,8 +170,8 @@ QT_BEGIN_NAMESPACE \sa acquire(), key() */ QSystemSemaphore::QSystemSemaphore(const QString &key, int initialValue, AccessMode mode) + : d(new QSystemSemaphorePrivate) { - d = new QSystemSemaphorePrivate; setKey(key, initialValue, mode); } @@ -193,7 +193,6 @@ QSystemSemaphore::QSystemSemaphore(const QString &key, int initialValue, AccessM QSystemSemaphore::~QSystemSemaphore() { d->cleanHandle(); - delete d; } /*! diff --git a/src/corelib/kernel/qsystemsemaphore.h b/src/corelib/kernel/qsystemsemaphore.h index 5a02072..3cafebf 100644 --- a/src/corelib/kernel/qsystemsemaphore.h +++ b/src/corelib/kernel/qsystemsemaphore.h @@ -43,6 +43,7 @@ #define QSYSTEMSEMAPHORE_H #include +#include QT_BEGIN_HEADER @@ -89,7 +90,7 @@ public: private: Q_DISABLE_COPY(QSystemSemaphore) - QSystemSemaphorePrivate *d; + QScopedPointer d; }; #endif // QT_NO_SYSTEMSEMAPHORE diff --git a/src/corelib/kernel/qsystemsemaphore_symbian.cpp b/src/corelib/kernel/qsystemsemaphore_symbian.cpp index cd5c3ff..8179046 100644 --- a/src/corelib/kernel/qsystemsemaphore_symbian.cpp +++ b/src/corelib/kernel/qsystemsemaphore_symbian.cpp @@ -90,13 +90,12 @@ int QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode) if (key.isEmpty()) return 0; QString safeName = makeKeyFileName(); - HBufC* name = qt_QString2HBufCNewL(safeName); + TPtrC name(qt_QString2TPtrC(safeName)); int err; - err = semaphore.OpenGlobal(*name,EOwnerProcess); + err = semaphore.OpenGlobal(name,EOwnerProcess); if (err == KErrNotFound){ - err = semaphore.CreateGlobal(*name,initialValue, EOwnerProcess); + err = semaphore.CreateGlobal(name,initialValue, EOwnerProcess); } - delete name; if (err){ setErrorString(QLatin1String("QSystemSemaphore::handle"),err); return 0; diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp index 420dd1d..0ca0169 100644 --- a/src/corelib/plugin/qlibrary.cpp +++ b/src/corelib/plugin/qlibrary.cpp @@ -611,10 +611,10 @@ bool QLibraryPrivate::isPlugin(QSettings *settings) .arg(fileName); QStringList reg; #ifndef QT_NO_SETTINGS - bool madeSettings = false; + QScopedPointer madeSettings; if (!settings) { settings = new QSettings(QSettings::UserScope, QLatin1String("Trolltech")); - madeSettings = true; + madeSettings.reset(settings); } reg = settings->value(regkey).toStringList(); #endif @@ -708,8 +708,7 @@ bool QLibraryPrivate::isPlugin(QSettings *settings) #endif } #ifndef QT_NO_SETTINGS - if (madeSettings) - delete settings; + madeSettings.reset(); #endif if (!success) { diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp index cb44a25..f1bdc64 100644 --- a/src/corelib/thread/qthread.cpp +++ b/src/corelib/thread/qthread.cpp @@ -163,9 +163,9 @@ QAdoptedThread::~QAdoptedThread() QThread *QAdoptedThread::createThreadForAdoption() { - QThread *t = new QAdoptedThread(0); - t->moveToThread(t); - return t; + QScopedPointer t(new QAdoptedThread(0)); + t->moveToThread(t.data()); + return t.take(); } void QAdoptedThread::run() @@ -483,10 +483,10 @@ uint QThread::stackSize() const int QThread::exec() { Q_D(QThread); - d->mutex.lock(); + QMutexLocker locker(&d->mutex); d->data->quitNow = false; QEventLoop eventLoop; - d->mutex.unlock(); + locker.unlock(); int returnCode = eventLoop.exec(); return returnCode; } @@ -734,8 +734,9 @@ QThreadData* QThreadData::current() { static QThreadData *data = 0; // reinterpret_cast(pthread_getspecific(current_thread_data_key)); if (!data) { - data = new QThreadData; - data->thread = new QAdoptedThread(data); + QScopedPointer newdata(new QThreadData); + newdata->thread = new QAdoptedThread(newdata.data()); + data = newdata.take(); data->deref(); } return data; diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index 567c936..d2a824a 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -124,7 +124,14 @@ QThreadData *QThreadData::current() } else { data = new QThreadData; pthread_setspecific(current_thread_data_key, data); - data->thread = new QAdoptedThread(data); + QT_TRY { + data->thread = new QAdoptedThread(data); + } QT_CATCH(...) { + pthread_setspecific(current_thread_data_key, 0); + data->deref(); + data = 0; + QT_RETHROW; + } data->deref(); } if (!QCoreApplicationPrivate::theMainThread) diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp index 7094e3d..76e551e 100644 --- a/src/corelib/thread/qthread_win.cpp +++ b/src/corelib/thread/qthread_win.cpp @@ -112,7 +112,14 @@ QThreadData *QThreadData::current() // This needs to be called prior to new AdoptedThread() to // avoid recursion. TlsSetValue(qt_current_thread_data_tls_index, threadData); - threadData->thread = new QAdoptedThread(threadData); + QT_TRY { + threadData->thread = new QAdoptedThread(threadData); + } QT_CATCH(...) { + TlsSetValue(qt_current_thread_data_tls_index, 0); + threadData->deref(); + threadData = 0; + QT_RETHROW; + } threadData->deref(); } diff --git a/src/corelib/thread/qthreadstorage.cpp b/src/corelib/thread/qthreadstorage.cpp index 35c55c1..4657009 100644 --- a/src/corelib/thread/qthreadstorage.cpp +++ b/src/corelib/thread/qthreadstorage.cpp @@ -101,12 +101,14 @@ void **QThreadStorageData::get() const qWarning("QThreadStorage::get: QThreadStorage can only be used with threads started with QThread"); return 0; } - QMap::iterator it = data->tls.find(id); + QMap::const_iterator it = data->tls.constFind(id); DEBUG_MSG("QThreadStorageData: Returning storage %d, data %p, for thread %p", id, it != data->tls.end() ? it.value() : 0, data->thread); - return it != data->tls.end() && it.value() != 0 ? &it.value() : 0; + // const_cast below is a bit evil - but we have to make sure not to detach here + // otherwise we'll go bonkers in oom situations + return it != data->tls.constEnd() && it.value() != 0 ? const_cast(&it.value()) : 0; } void **QThreadStorageData::set(void *p) @@ -129,9 +131,9 @@ void **QThreadStorageData::set(void *p) void *q = it.value(); it.value() = 0; - mutex()->lock(); + QMutexLocker locker(mutex()); void (*destructor)(void *) = destructors()->value(id); - mutex()->unlock(); + locker.unlock(); destructor(q); } @@ -167,9 +169,9 @@ void QThreadStorageData::finish(void **p) continue; } - mutex()->lock(); + QMutexLocker locker(mutex()); void (*destructor)(void *) = destructors()->value(id); - mutex()->unlock(); + locker.unlock(); if (!destructor) { if (QThread::currentThread()) diff --git a/src/corelib/tools/qbitarray.cpp b/src/corelib/tools/qbitarray.cpp index a947ab5..7168a9a 100644 --- a/src/corelib/tools/qbitarray.cpp +++ b/src/corelib/tools/qbitarray.cpp @@ -209,6 +209,8 @@ void QBitArray::resize(int size) uchar* c = reinterpret_cast(d.data()); if (size > (s << 3)) memset(c + s, 0, d.size() - s); + else if ( size % 8) + *(c+1+size/8) &= (1 << (size%8)) - 1; *c = d.size()*8 - size; } } diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index 6aa35f3..ae6561f 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -1233,14 +1233,11 @@ QByteArray::QByteArray(const char *str) } else { int len = qstrlen(str); d = static_cast(qMalloc(sizeof(Data)+len)); - if (!d) { - d = &shared_null; - } else { - d->ref = 0;; - d->alloc = d->size = len; - d->data = d->array; - memcpy(d->array, str, len+1); // include null terminator - } + Q_CHECK_PTR(d); + d->ref = 0;; + d->alloc = d->size = len; + d->data = d->array; + memcpy(d->array, str, len+1); // include null terminator } d->ref.ref(); } @@ -1264,15 +1261,12 @@ QByteArray::QByteArray(const char *data, int size) d = &shared_empty; } else { d = static_cast(qMalloc(sizeof(Data) + size)); - if (!d) { - d = &shared_null; - } else { - d->ref = 0; - d->alloc = d->size = size; - d->data = d->array; - memcpy(d->array, data, size); - d->array[size] = '\0'; - } + Q_CHECK_PTR(d); + d->ref = 0; + d->alloc = d->size = size; + d->data = d->array; + memcpy(d->array, data, size); + d->array[size] = '\0'; } d->ref.ref(); } @@ -1290,15 +1284,12 @@ QByteArray::QByteArray(int size, char ch) d = &shared_null; } else { d = static_cast(qMalloc(sizeof(Data)+size)); - if (!d) { - d = &shared_null; - } else { - d->ref = 0; - d->alloc = d->size = size; - d->data = d->array; - d->array[size] = '\0'; - memset(d->array, ch, size); - } + Q_CHECK_PTR(d); + d->ref = 0; + d->alloc = d->size = size; + d->data = d->array; + d->array[size] = '\0'; + memset(d->array, ch, size); } d->ref.ref(); } @@ -1334,8 +1325,7 @@ void QByteArray::resize(int size) // QByteArray a(sz); // Data *x = static_cast(qMalloc(sizeof(Data)+size)); - if (!x) - return; + Q_CHECK_PTR(x); x->ref = 1; x->alloc = x->size = size; x->data = x->array; @@ -1377,8 +1367,7 @@ void QByteArray::realloc(int alloc) { if (d->ref != 1 || d->data != d->array) { Data *x = static_cast(qMalloc(sizeof(Data) + alloc)); - if (!x) - return; + Q_CHECK_PTR(x); x->size = qMin(alloc, d->size); ::memcpy(x->array, d->data, x->size); x->array[x->size] = '\0'; @@ -1390,8 +1379,7 @@ void QByteArray::realloc(int alloc) d = x; } else { Data *x = static_cast(qRealloc(d, sizeof(Data) + alloc)); - if (!x) - return; + Q_CHECK_PTR(x); x->alloc = alloc; x->data = x->array; d = x; @@ -1812,11 +1800,13 @@ QByteArray &QByteArray::replace(const char *before, int bsize, const char *after const char *b = before; if (after >= d->data && after < d->data + d->size) { char *copy = (char *)malloc(asize); + Q_CHECK_PTR(copy); memcpy(copy, after, asize); a = copy; } if (before >= d->data && before < d->data + d->size) { char *copy = (char *)malloc(bsize); + Q_CHECK_PTR(copy); memcpy(copy, before, bsize); b = copy; } @@ -3738,6 +3728,7 @@ QByteArray QByteArray::number(double n, char f, int prec) QByteArray QByteArray::fromRawData(const char *data, int size) { Data *x = static_cast(qMalloc(sizeof(Data))); + Q_CHECK_PTR(x); if (data) { x->data = const_cast(data); } else { diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index 781514c..b43891c 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -2200,8 +2200,8 @@ int QTime::elapsed() const \sa isValid() */ QDateTime::QDateTime() + : d(new QDateTimePrivate) { - d = new QDateTimePrivate; } @@ -2211,8 +2211,8 @@ QDateTime::QDateTime() */ QDateTime::QDateTime(const QDate &date) + : d(new QDateTimePrivate) { - d = new QDateTimePrivate; d->date = date; d->time = QTime(0, 0, 0); } @@ -2225,8 +2225,8 @@ QDateTime::QDateTime(const QDate &date) */ QDateTime::QDateTime(const QDate &date, const QTime &time, Qt::TimeSpec spec) + : d(new QDateTimePrivate) { - d = new QDateTimePrivate; d->date = date; d->time = date.isValid() && !time.isValid() ? QTime(0, 0, 0) : time; d->spec = (spec == Qt::UTC) ? QDateTimePrivate::UTC : QDateTimePrivate::LocalUnknown; @@ -2237,8 +2237,8 @@ QDateTime::QDateTime(const QDate &date, const QTime &time, Qt::TimeSpec spec) */ QDateTime::QDateTime(const QDateTime &other) + : d(other.d.data()) { - d = other.d; d->ref.ref(); } @@ -2247,8 +2247,6 @@ QDateTime::QDateTime(const QDateTime &other) */ QDateTime::~QDateTime() { - if (!d->ref.deref()) - delete d; } /*! @@ -2258,7 +2256,7 @@ QDateTime::~QDateTime() QDateTime &QDateTime::operator=(const QDateTime &other) { - qAtomicAssign(d, other.d); + d.assign(other.d.data()); return *this; } @@ -3298,7 +3296,7 @@ QDateTime QDateTime::fromString(const QString &string, const QString &format) */ void QDateTime::detach() { - qAtomicDetach(d); + d.detach(); } /***************************************************************************** diff --git a/src/corelib/tools/qdatetime.h b/src/corelib/tools/qdatetime.h index 3278297..cf4246d 100644 --- a/src/corelib/tools/qdatetime.h +++ b/src/corelib/tools/qdatetime.h @@ -44,6 +44,7 @@ #include #include +#include QT_BEGIN_HEADER @@ -284,7 +285,7 @@ public: private: friend class QDateTimePrivate; void detach(); - QDateTimePrivate *d; + QScopedSharedPointer d; #ifndef QT_NO_DATASTREAM friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QDateTime &); diff --git a/src/corelib/tools/qharfbuzz.cpp b/src/corelib/tools/qharfbuzz.cpp index 1940209..923eda4 100644 --- a/src/corelib/tools/qharfbuzz.cpp +++ b/src/corelib/tools/qharfbuzz.cpp @@ -126,6 +126,7 @@ char *HB_TextCodec_ConvertFromUnicode(void *codec, const HB_UChar16 *unicode, hb QByteArray data = reinterpret_cast(codec)->fromUnicode((const QChar *)unicode, length); // ### suboptimal char *output = (char *)malloc(data.length() + 1); + Q_CHECK_PTR(output); memcpy(output, data.constData(), data.length() + 1); if (outputLength) *outputLength = data.length(); diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index 2313e0e..a703621 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -171,7 +171,9 @@ QHashData QHashData::shared_null = { void *QHashData::allocateNode() { - return qMalloc(nodeSize); + void *ptr = qMalloc(nodeSize); + Q_CHECK_PTR(ptr); + return ptr; } void QHashData::freeNode(void *node) @@ -181,6 +183,13 @@ void QHashData::freeNode(void *node) QHashData *QHashData::detach_helper(void (*node_duplicate)(Node *, void *), int nodeSize) { + return detach_helper( node_duplicate, 0, nodeSize ); +} + +QHashData *QHashData::detach_helper(void (*node_duplicate)(Node *, void *), + void (*node_delete)(Node *), + int nodeSize) +{ union { QHashData *d; Node *e; @@ -197,18 +206,43 @@ QHashData *QHashData::detach_helper(void (*node_duplicate)(Node *, void *), int d->sharable = true; if (numBuckets) { - d->buckets = new Node *[numBuckets]; + QT_TRY { + d->buckets = new Node *[numBuckets]; + } QT_CATCH(...) { + // restore a consistent state for d + d->numBuckets = 0; + // roll back + d->free_helper(node_delete); + QT_RETHROW; + } + Node *this_e = reinterpret_cast(this); for (int i = 0; i < numBuckets; ++i) { Node **nextNode = &d->buckets[i]; Node *oldNode = buckets[i]; while (oldNode != this_e) { - Node *dup = static_cast(allocateNode()); - node_duplicate(oldNode, dup); - dup->h = oldNode->h; - *nextNode = dup; - nextNode = &dup->next; - oldNode = oldNode->next; + QT_TRY { + Node *dup = static_cast(allocateNode()); + + QT_TRY { + node_duplicate(oldNode, dup); + } QT_CATCH(...) { + freeNode( dup ); + QT_RETHROW; + } + + dup->h = oldNode->h; + *nextNode = dup; + nextNode = &dup->next; + oldNode = oldNode->next; + } QT_CATCH(...) { + // restore a consistent state for d + *nextNode = e; + d->numBuckets = i+1; + // roll back + d->free_helper(node_delete); + QT_RETHROW; + } } *nextNode = e; } @@ -216,6 +250,26 @@ QHashData *QHashData::detach_helper(void (*node_duplicate)(Node *, void *), int return d; } +void QHashData::free_helper(void (*node_delete)(Node *)) +{ + if (node_delete) { + Node *this_e = reinterpret_cast(this); + Node **bucket = reinterpret_cast(this->buckets); + + int n = numBuckets; + while (n--) { + Node *cur = *bucket++; + while (cur != this_e) { + Node *next = cur->next; + node_delete(cur); + cur = next; + } + } + } + delete [] buckets; + delete this; +} + QHashData::Node *QHashData::nextNode(Node *node) { union { @@ -298,9 +352,10 @@ void QHashData::rehash(int hint) Node **oldBuckets = buckets; int oldNumBuckets = numBuckets; + int nb = primeForNumBits(hint); + buckets = new Node *[nb]; numBits = hint; - numBuckets = primeForNumBits(hint); - buckets = new Node *[numBuckets]; + numBuckets = nb; for (int i = 0; i < numBuckets; ++i) buckets[i] = e; @@ -327,8 +382,7 @@ void QHashData::rehash(int hint) void QHashData::destroyAndFree() { - delete [] buckets; - delete this; + free_helper(0); } #ifdef QT_QHASH_DEBUG diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 41b4794..b3f82e9 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -129,12 +129,15 @@ struct Q_CORE_EXPORT QHashData void *allocateNode(); void freeNode(void *node); - QHashData *detach_helper(void (*node_duplicate)(Node *, void *), int nodeSize); + QHashData *detach_helper(void (*node_duplicate)(Node *, void *), int nodeSize); // ### Qt5 remove me + QHashData *detach_helper(void (*node_duplicate)(Node *, void *), void (*node_delete)(Node *), + int nodeSize); void mightGrow(); bool willGrow(); void hasShrunk(); void rehash(int hint); - void destroyAndFree(); + void free_helper(void (*node_delete)(Node *)); + void destroyAndFree(); // ### Qt5 remove me Node *firstNode(); #ifdef QT_QHASH_DEBUG void dump(); @@ -476,21 +479,30 @@ private: Node **findNode(const Key &key, uint *hp = 0) const; Node *createNode(uint h, const Key &key, const T &value, Node **nextNode); void deleteNode(Node *node); + static void deleteNode(QHashData::Node *node); static void duplicateNode(QHashData::Node *originalNode, void *newNode); }; + template Q_INLINE_TEMPLATE void QHash::deleteNode(Node *node) { + deleteNode(reinterpret_cast(node)); +} + + +template +Q_INLINE_TEMPLATE void QHash::deleteNode(QHashData::Node *node) +{ #ifdef Q_CC_BOR - node->~QHashNode(); + concrete(node)->~QHashNode(); #elif defined(QT_NO_PARTIAL_TEMPLATE_SPECIALIZATION) - node->~QHashNode(); + concrete(node)->~QHashNode(); #else - node->~Node(); + concrete(node)->~Node(); #endif - d->freeNode(node); + qFree(node); } template @@ -538,18 +550,7 @@ Q_INLINE_TEMPLATE QHash &QHash::unite(const QHash &other template Q_OUTOFLINE_TEMPLATE void QHash::freeData(QHashData *x) { - Node *e_for_x = reinterpret_cast(x); - Node **bucket = reinterpret_cast(x->buckets); - int n = x->numBuckets; - while (n--) { - Node *cur = *bucket++; - while (cur != e_for_x) { - Node *next = cur->next; - deleteNode(cur); - cur = next; - } - } - x->destroyAndFree(); + x->free_helper(deleteNode); } template @@ -561,7 +562,7 @@ Q_INLINE_TEMPLATE void QHash::clear() template Q_OUTOFLINE_TEMPLATE void QHash::detach_helper() { - QHashData *x = d->detach_helper(duplicateNode, + QHashData *x = d->detach_helper(duplicateNode, deleteNode, QTypeInfo::isDummy ? sizeof(DummyNode) : sizeof(Node)); if (!d->ref.deref()) freeData(d); diff --git a/src/corelib/tools/qlinkedlist.h b/src/corelib/tools/qlinkedlist.h index 6a85386..79311bc 100644 --- a/src/corelib/tools/qlinkedlist.h +++ b/src/corelib/tools/qlinkedlist.h @@ -265,15 +265,22 @@ void QLinkedList::detach_helper() x.d->ref = 1; x.d->size = d->size; x.d->sharable = true; - Node *i = e->n, *j = x.e; - while (i != e) { - j->n = new Node(i->t); - j->n->p = j; - i = i->n; - j = j->n; + Node *original = e->n; + Node *copy = x.e; + while (original != e) { + QT_TRY { + copy->n = new Node(original->t); + copy->n->p = copy; + original = original->n; + copy = copy->n; + } QT_CATCH(...) { + copy->n = x.e; + free(x.d); + QT_RETHROW; + } } - j->n = x.e; - x.e->p = j; + copy->n = x.e; + x.e->p = copy; if (!d->ref.deref()) free(d); d = x.d; @@ -474,14 +481,21 @@ QLinkedList &QLinkedList::operator+=(const QLinkedList &l) detach(); int n = l.d->size; d->size += n; - Node *o = l.e->n; + Node *original = l.e->n; while (n--) { - Node *i = new Node(o->t); - o = o->n; - i->n = e; - i->p = e->p; - i->p->n = i; - e->p = i; + QT_TRY { + Node *copy = new Node(original->t); + original = original->n; + copy->n = e; + copy->p = e->p; + copy->p->n = copy; + e->p = copy; + } QT_CATCH(...) { + // restore the original list + while (n++size) + removeLast(); + QT_RETHROW; + } } return *this; } diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 3c21ec1..89e082b 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -117,6 +117,7 @@ public: inline int size() const { return p.size(); } inline void detach() { if (d->ref != 1) detach_helper(); } + inline void detachShared() { if (d->ref != 1 && d != &QListData::shared_null) detach_helper(); } inline bool isDetached() const { return d->ref == 1; } inline void setSharable(bool sharable) { if (!sharable) detach(); d->sharable = sharable; } @@ -352,12 +353,27 @@ Q_INLINE_TEMPLATE void QList::node_destruct(Node *n) template Q_INLINE_TEMPLATE void QList::node_copy(Node *from, Node *to, Node *src) { - if (QTypeInfo::isLarge || QTypeInfo::isStatic) - while(from != to) - (from++)->v = new T(*reinterpret_cast((src++)->v)); - else if (QTypeInfo::isComplex) - while(from != to) - new (from++) T(*reinterpret_cast(src++)); + Node *current = from; + if (QTypeInfo::isLarge || QTypeInfo::isStatic) { + QT_TRY { + while(current != to) + (current++)->v = new T(*reinterpret_cast((src++)->v)); + } QT_CATCH(...) { + while (current != from) + delete reinterpret_cast(current--); + QT_RETHROW; + } + } + else if (QTypeInfo::isComplex) { + QT_TRY { + while(current != to) + new (current++) T(*reinterpret_cast(src++)); + } QT_CATCH(...) { + while (current != from) + (reinterpret_cast(current--))->~T(); + QT_RETHROW; + } + } } template @@ -384,8 +400,16 @@ Q_INLINE_TEMPLATE QList &QList::operator=(const QList &l) } template inline typename QList::iterator QList::insert(iterator before, const T &t) -{ Node *n = reinterpret_cast(p.insert(before.i-reinterpret_cast(p.begin()))); - node_construct(n,t); return n; } +{ + Node *n = reinterpret_cast(p.insert(before.i - reinterpret_cast(p.begin()))); + QT_TRY { + node_construct(n, t); + } QT_CATCH(...) { + p.remove(before.i - reinterpret_cast(p.begin())); + QT_RETHROW; + } + return n; +} template inline typename QList::iterator QList::erase(iterator it) { node_destruct(it.i); @@ -423,10 +447,22 @@ Q_OUTOFLINE_TEMPLATE void QList::append(const T &t) { detach(); if (QTypeInfo::isLarge || QTypeInfo::isStatic) { - node_construct(reinterpret_cast(p.append()), t); + Node *n = reinterpret_cast(p.append()); + QT_TRY { + node_construct(n, t); + } QT_CATCH(...) { + --d->end; + QT_RETHROW; + } } else { const T cpy(t); - node_construct(reinterpret_cast(p.append()), cpy); + Node *n = reinterpret_cast(p.append()); + QT_TRY { + node_construct(n, cpy); + } QT_CATCH(...) { + --d->end; + QT_RETHROW; + } } } @@ -435,10 +471,22 @@ inline void QList::prepend(const T &t) { detach(); if (QTypeInfo::isLarge || QTypeInfo::isStatic) { - node_construct(reinterpret_cast(p.prepend()), t); + Node *n = reinterpret_cast(p.prepend()); + QT_TRY { + node_construct(n, t); + } QT_CATCH(...) { + ++d->begin; + QT_RETHROW; + } } else { const T cpy(t); - node_construct(reinterpret_cast(p.prepend()), cpy); + Node *n = reinterpret_cast(p.prepend()); + QT_TRY { + node_construct(n, cpy); + } QT_CATCH(...) { + ++d->begin; + QT_RETHROW; + } } } @@ -447,10 +495,22 @@ inline void QList::insert(int i, const T &t) { detach(); if (QTypeInfo::isLarge || QTypeInfo::isStatic) { - node_construct(reinterpret_cast(p.insert(i)), t); + Node *n = reinterpret_cast(p.insert(i)); + QT_TRY { + node_construct(n, t); + } QT_CATCH(...) { + p.remove(i); + QT_RETHROW; + } } else { const T cpy(t); - node_construct(reinterpret_cast(p.insert(i)), cpy); + Node *n = reinterpret_cast(p.insert(i)); + QT_TRY { + node_construct(n, cpy); + } QT_CATCH(...) { + p.remove(i); + QT_RETHROW; + } } } @@ -522,7 +582,14 @@ Q_OUTOFLINE_TEMPLATE void QList::detach_helper() { Node *n = reinterpret_cast(p.begin()); QListData::Data *x = p.detach2(); - node_copy(reinterpret_cast(p.begin()), reinterpret_cast(p.end()), n); + QT_TRY { + node_copy(reinterpret_cast(p.begin()), reinterpret_cast(p.end()), n); + } QT_CATCH(...) { + qFree(d); + d = x; + QT_RETHROW; + } + if (!x->ref.deref()) free(x); } @@ -572,7 +639,7 @@ Q_OUTOFLINE_TEMPLATE void QList::clear() template Q_OUTOFLINE_TEMPLATE int QList::removeAll(const T &_t) { - detach(); + detachShared(); const T t = _t; int removedCount=0, i=0; Node *n; @@ -590,7 +657,7 @@ Q_OUTOFLINE_TEMPLATE int QList::removeAll(const T &_t) template Q_OUTOFLINE_TEMPLATE bool QList::removeOne(const T &_t) { - detach(); + detachShared(); int index = indexOf(_t); if (index != -1) { removeAt(index); diff --git a/src/corelib/tools/qlistdata.cpp b/src/corelib/tools/qlistdata.cpp index 34a5d80..efdde64 100644 --- a/src/corelib/tools/qlistdata.cpp +++ b/src/corelib/tools/qlistdata.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ +#include #include "qlist.h" #include "qtools_p.h" #include @@ -71,8 +72,7 @@ static int grow(int size) QListData::Data *QListData::detach() { Data *x = static_cast(qMalloc(DataHeaderSize + d->alloc * sizeof(void *))); - if (!x) - qFatal("QList: Out of memory"); + Q_CHECK_PTR(x); ::memcpy(x, d, DataHeaderSize + d->alloc * sizeof(void *)); x->alloc = d->alloc; @@ -91,10 +91,10 @@ QListData::Data *QListData::detach() QListData::Data *QListData::detach2() { Data *x = d; - d = static_cast(qMalloc(DataHeaderSize + x->alloc * sizeof(void *))); - if (!d) - qFatal("QList: Out of memory"); + Data* t = static_cast(qMalloc(DataHeaderSize + x->alloc * sizeof(void *))); + Q_CHECK_PTR(t); + d = t; ::memcpy(d, x, DataHeaderSize + x->alloc * sizeof(void *)); d->alloc = x->alloc; d->ref = 1; @@ -109,8 +109,7 @@ void QListData::realloc(int alloc) { Q_ASSERT(d->ref == 1); Data *x = static_cast(qRealloc(d, DataHeaderSize + alloc * sizeof(void *))); - if (!x) - qFatal("QList: Out of memory"); + Q_CHECK_PTR(x); d = x; d->alloc = alloc; @@ -514,6 +513,15 @@ void **QListData::erase(void **xi) \internal */ +/*! \fn void QList::detachShared() + + \internal + + like detach(), but does nothing if we're shared_null. + This prevents needless mallocs, and makes QList more exception safe + in case of cleanup work done in destructors on empty lists. +*/ + /*! \fn bool QList::isDetached() const \internal diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index 4d042ae..4317933 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -5124,6 +5124,7 @@ static Bigint *Balloc(int k) x = 1 << k; rv = static_cast(MALLOC(sizeof(Bigint) + (x-1)*sizeof(Long))); + Q_CHECK_PTR(rv); rv->k = k; rv->maxwds = x; rv->sign = rv->wds = 0; @@ -6788,6 +6789,7 @@ static char *_qdtoa( NEEDS_VOLATILE double d, int mode, int ndigits, int *decpt, i = 1; } *resultp = static_cast(malloc(i + 1)); + Q_CHECK_PTR(resultp); s = s0 = *resultp; if (ilim >= 0 && ilim <= Quick_max && try_quick) { @@ -7209,6 +7211,7 @@ Q_CORE_EXPORT char *qdtoa( double d, int mode, int ndigits, int *decpt, int *sig n = i + 1; } *resultp = static_cast(malloc(n + 1)); + Q_CHECK_PTR(resultp); qstrncpy(*resultp, res, n + 1); return *resultp; } diff --git a/src/corelib/tools/qmap.cpp b/src/corelib/tools/qmap.cpp index 07df28d..ceaf370 100644 --- a/src/corelib/tools/qmap.cpp +++ b/src/corelib/tools/qmap.cpp @@ -59,6 +59,7 @@ QMapData QMapData::shared_null = { QMapData *QMapData::createData() { QMapData *d = new QMapData; + Q_CHECK_PTR(d); Node *e = reinterpret_cast(d); e->backward = e; e->forward[0] = e; @@ -84,6 +85,15 @@ void QMapData::continueFreeData(int offset) delete this; } +/*! + Creates a new node inside the data structure. + + \a update is an array with pointers to the node after which the new node + should be inserted. Because of the strange skip list data structure there + could be several pointers to this node on different levels. + \a offset is an amount of bytes that needs to reserved just before the + QMapData::Node structure. +*/ QMapData::Node *QMapData::node_create(Node *update[], int offset) { int level = 0; @@ -94,10 +104,6 @@ QMapData::Node *QMapData::node_create(Node *update[], int offset) mask <<= Sparseness; } - ++randomBits; - if (level == 3 && !insertInOrder) - randomBits = qrand(); - if (level > topLevel) { Node *e = reinterpret_cast(this); level = ++topLevel; @@ -105,7 +111,13 @@ QMapData::Node *QMapData::node_create(Node *update[], int offset) update[level] = e; } + ++randomBits; + if (level == 3 && !insertInOrder) + randomBits = qrand(); + void *concreteNode = qMalloc(offset + sizeof(Node) + level * sizeof(Node *)); + Q_CHECK_PTR(concreteNode); + Node *abstractNode = reinterpret_cast(reinterpret_cast(concreteNode) + offset); abstractNode->backward = update[0]; @@ -116,6 +128,7 @@ QMapData::Node *QMapData::node_create(Node *update[], int offset) update[i]->forward[i] = abstractNode; update[i] = abstractNode; } + // update[level+1]=reinterpret_cast(this); ++size; return abstractNode; } @@ -146,7 +159,7 @@ uint QMapData::adjust_ptr(Node *node) void QMapData::dump() { - qDebug("Map data (ref = %d, size = %d, randomBits = %#.8x)", ref.atomic, size, randomBits); + qDebug("Map data (ref = %d, size = %d, randomBits = %#.8x)", int(ref), size, randomBits); QString preOutput; QVector output(topLevel + 1); @@ -158,12 +171,12 @@ void QMapData::dump() Node *update[LastLevel + 1]; for (int i = 0; i <= topLevel; ++i) { - str.sprintf("%d: [%.8x] -", i, adjust_ptr(forward[i])); + str.sprintf("%d: [%.8x] -", i, adjust_ptr(reinterpret_cast(forward[i]))); output[i] += str; - update[i] = forward[i]; + update[i] = reinterpret_cast(forward[i]); } - Node *node = forward[0]; + Node *node = reinterpret_cast(forward[0]); while (node != e) { int level = 0; while (level < topLevel && update[level + 1] == node) @@ -178,13 +191,13 @@ void QMapData::dump() update[i] = node->forward[i]; } for (int j = level + 1; j <= topLevel; ++j) - output[j] += "---------------"; + output[j] += QString("---------------"); node = node->forward[0]; } - qDebug(preOutput.ascii()); + qDebug("%s", preOutput.ascii()); for (int i = 0; i <= topLevel; ++i) - qDebug(output[i].ascii()); + qDebug("%s", output[i].ascii()); } #endif diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index 0215a78..bd9ba74 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -416,9 +416,29 @@ Q_INLINE_TEMPLATE typename QMapData::Node * QMap::node_create(QMapData *adt, QMapData::Node *aupdate[], const Key &akey, const T &avalue) { QMapData::Node *abstractNode = adt->node_create(aupdate, payload()); - Node *concreteNode = concrete(abstractNode); - new (&concreteNode->key) Key(akey); - new (&concreteNode->value) T(avalue); + QT_TRY { + Node *concreteNode = concrete(abstractNode); + new (&concreteNode->key) Key(akey); + QT_TRY { + new (&concreteNode->value) T(avalue); + } QT_CATCH(...) { + concreteNode->key.~Key(); + QT_RETHROW; + } + } QT_CATCH(...) { + adt->node_delete(aupdate, payload(), abstractNode); + QT_RETHROW; + } + + // clean up the update array for further insertions + /* + for (int i = 0; i <= d->topLevel; ++i) { + if ( aupdate[i]==reinterpret_cast(adt) || aupdate[i]->forward[i] != abstractNode) + break; + aupdate[i] = abstractNode; + } +*/ + return abstractNode; } @@ -704,8 +724,13 @@ Q_OUTOFLINE_TEMPLATE void QMap::detach_helper() QMapData::Node *cur = e->forward[0]; update[0] = x.e; while (cur != e) { - Node *concreteNode = concrete(cur); - node_create(x.d, update, concreteNode->key, concreteNode->value); + QT_TRY { + Node *concreteNode = concrete(cur); + node_create(x.d, update, concreteNode->key, concreteNode->value); + } QT_CATCH(...) { + freeData(x.d); + QT_RETHROW; + } cur = cur->forward[0]; } x.d->insertInOrder = false; diff --git a/src/corelib/tools/qpodlist_p.h b/src/corelib/tools/qpodlist_p.h index 9708f8d..9e6d19b 100644 --- a/src/corelib/tools/qpodlist_p.h +++ b/src/corelib/tools/qpodlist_p.h @@ -53,9 +53,7 @@ // We mean it. // -#include -#include -#include +#include QT_BEGIN_HEADER @@ -63,87 +61,29 @@ QT_BEGIN_NAMESPACE QT_MODULE(Core) -template -class QPodList +template +class QPodList : public QVarLengthArray { + using QVarLengthArray::s; + using QVarLengthArray::a; + using QVarLengthArray::ptr; + using QVarLengthArray::realloc; public: - inline explicit QPodList(int size = 0); + inline explicit QPodList(int size = 0) + : QVarLengthArray(size) + {} - inline QPodList(const QPodList &other) - : a(Prealloc), s(0), ptr(reinterpret_cast(array)) + inline void insert(int idx, const T &t) { - append(other.constData(), other.size()); - } - - inline ~QPodList() { - if (ptr != reinterpret_cast(array)) - qFree(ptr); - } - inline QPodList &operator=(const QPodList &other) - { - if (this != &other) { - clear(); - append(other.constData(), other.size()); - } - return *this; - } - - inline int size() const { return s; } - inline int count() const { return s; } - inline bool isEmpty() const { return (s == 0); } - inline void resize(int size); - inline void clear() { resize(0); } - - inline int capacity() const { return a; } - inline void reserve(int size); - - inline T &operator[](int idx) { - Q_ASSERT(idx >= 0 && idx < s); - return ptr[idx]; - } - inline const T &operator[](int idx) const { - Q_ASSERT(idx >= 0 && idx < s); - return ptr[idx]; - } - - inline const T &at(int idx) const { - Q_ASSERT(idx >= 0 && idx < s); - return ptr[idx]; - } - - inline const T &first() const { - return at(0); - } - - inline T& append() { - const int idx = s++; - if (s == a) - realloc(s, s<<1); - return ptr[idx]; - } - inline void append(const T &t) { - append() = t; - } - - inline T& insert(int idx) { - Q_ASSERT(idx >= 0 && idx <= s); const int sz = s++; if (s == a) - realloc(s, s<<1); + realloc(s, s << 1); ::memmove(ptr + idx + 1, ptr + idx, (sz - idx) * sizeof(T)); - return ptr[idx]; - } - inline void insert(int idx, const T &t) { - insert(idx) = t; + ptr[idx] = t; } - inline void removeAt(int idx) { - Q_ASSERT(idx >= 0 && idx < s); - ::memmove(ptr + idx, ptr + idx + 1, (s - idx - 1) * sizeof(T)); - --s; - } - - inline void removeAll(const T &t) { + inline void removeAll(const T &t) + { int i = 0; for (int j = 0; j < s; ++j) { if (ptr[j] != t) @@ -152,110 +92,22 @@ public: s = i; } - inline int indexOf(const T &t, int from = 0) const { - if (from < 0) - from = qMax(from + s, 0); - if (from < s) { - const T *n = ptr + from - 1; - const T *e = ptr + s; - while (++n != e) - if (*n == t) - return n - ptr; - } - return -1; - } - - inline bool contains(const T &t) const { - return indexOf(t) >= 0; + inline void removeAt(int idx) + { + Q_ASSERT(idx >= 0 && idx < s); + ::memmove(ptr + idx, ptr + idx + 1, (s - idx - 1) * sizeof(T)); + --s; } - inline T takeFirst() { + inline T takeFirst() + { Q_ASSERT(s > 0); T tmp = ptr[0]; removeAt(0); return tmp; } - - inline T *data() { return ptr; } - inline const T *data() const { return ptr; } - inline const T * constData() const { return ptr; } - -private: - void append(const T *buf, int size); - void realloc(int size, int alloc); - - int a; - int s; - T *ptr; - union { - // ### Qt 5: Use 'Prealloc * sizeof(T)' as array size - char array[sizeof(qint64) * (((Prealloc * sizeof(T)) / sizeof(qint64)) + 1)]; - qint64 q_for_alignment_1; - double q_for_alignment_2; - }; }; -template -Q_INLINE_TEMPLATE QPodList::QPodList(int asize) - : s(asize) { - if (s > Prealloc) { - ptr = reinterpret_cast(qMalloc(s * sizeof(T))); - a = s; - } else { - ptr = reinterpret_cast(array); - a = Prealloc; - } -} - -template -Q_INLINE_TEMPLATE void QPodList::resize(int asize) -{ realloc(asize, qMax(asize, a)); } - -template -Q_INLINE_TEMPLATE void QPodList::reserve(int asize) -{ if (asize > a) realloc(s, asize); } - -template -Q_OUTOFLINE_TEMPLATE void QPodList::append(const T *abuf, int asize) -{ - Q_ASSERT(abuf); - if (asize <= 0) - return; - - const int idx = s; - const int news = s + asize; - if (news >= a) - realloc(news, news<<1); - else - s = news; - - qMemCopy(&ptr[idx], abuf, asize * sizeof(T)); -} - -template -Q_OUTOFLINE_TEMPLATE void QPodList::realloc(int asize, int aalloc) -{ - Q_ASSERT(aalloc >= asize); - T *oldPtr = ptr; - int osize = s; - s = asize; - - if (aalloc != a) { - ptr = reinterpret_cast(qMalloc(aalloc * sizeof(T))); - if (ptr) { - a = aalloc; - qMemCopy(ptr, oldPtr, osize * sizeof(T)); - } else { - ptr = oldPtr; - s = 0; - asize = 0; - } - } - - if (oldPtr != reinterpret_cast(array) && oldPtr != ptr) - qFree(oldPtr); -} - QT_END_NAMESPACE QT_END_HEADER diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/tools/qregexp.cpp index e1c3921..f357956 100644 --- a/src/corelib/tools/qregexp.cpp +++ b/src/corelib/tools/qregexp.cpp @@ -1297,14 +1297,20 @@ void QRegExpMatchState::prepareForMatch(QRegExpEngine *eng) int ns = eng->s.size(); // number of states int ncap = eng->ncap; #ifndef QT_NO_REGEXP_OPTIM - slideTabSize = qMax(eng->minl + 1, 16); + int newSlideTabSize = qMax(eng->minl + 1, 16); #else - slideTabSize = 0; + int newSlideTabSize = 0; #endif int numCaptures = eng->numCaptures(); - capturedSize = 2 + 2 * numCaptures; - bigArray = (int *)realloc(bigArray, ((3 + 4 * ncap) * ns + 4 * ncap + slideTabSize + capturedSize)*sizeof(int)); + int newCapturedSize = 2 + 2 * numCaptures; + bigArray = (int *)realloc(bigArray, ((3 + 4 * ncap) * ns + 4 * ncap + newSlideTabSize + newCapturedSize)*sizeof(int)); + Q_CHECK_PTR(bigArray); + // set all internal variables only _after_ bigArray is realloc'ed + // to prevent a broken regexp in oom case + + slideTabSize = newSlideTabSize; + capturedSize = newCapturedSize; inNextStack = bigArray; memset(inNextStack, -1, ns * sizeof(int)); curStack = inNextStack + ns; @@ -3281,10 +3287,15 @@ static void derefEngine(QRegExpEngine *eng, const QRegExpEngineKey &key) #if !defined(QT_NO_REGEXP_OPTIM) if (globalEngineCache()) { QMutexLocker locker(mutex()); - globalEngineCache()->insert(key, eng, 4 + key.pattern.length() / 4); - } - else + QT_TRY { + globalEngineCache()->insert(key, eng, 4 + key.pattern.length() / 4); + } QT_CATCH(const std::bad_alloc &) { + // in case of an exception (e.g. oom), just delete the engine + delete eng; + } + } else { delete eng; + } #else Q_UNUSED(key); delete eng; diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h index 3a0901d..ac33353 100644 --- a/src/corelib/tools/qringbuffer_p.h +++ b/src/corelib/tools/qringbuffer_p.h @@ -199,9 +199,8 @@ public: inline void clear() { if(!buffers.isEmpty()) { - QByteArray tmp = buffers[0]; - buffers.clear(); - buffers << tmp; + // remove all but the first + buffers.erase(buffers.begin() + 1, buffers.end()); if (buffers.at(0).size() != basicBlockSize) buffers[0].resize(basicBlockSize); } diff --git a/src/corelib/tools/qscopedpointer.cpp b/src/corelib/tools/qscopedpointer.cpp new file mode 100644 index 0000000..8150a18 --- /dev/null +++ b/src/corelib/tools/qscopedpointer.cpp @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +****************************************************************************/ + +/*! + \class QScopedPointer + \brief The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon destruction. + \since 4.6 + \reentrant + \ingroup misc + + Managing heap allocated objects manually is hard and error prone, with the + common result that code leaks memory and is hard to maintain. + QScopedPointer is a small utility class that heavily simplifies this by + assigning stack-based memory ownership to heap allocations, more generally + called resource acquisition is initialization(RAII). + + QScopedPointer guarantees that the object pointed to will get deleted when + the current scope dissapears, and it also has no way of releasing + ownership, hence clearly communicating the lifetime and ownership of the + object. These guarantees are convenient when reading the code. + + Consider this function which does heap allocations, and have various exit points: + + \snippet doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp 0 + + It's encumbered by the manual delete calls. With QScopedPointer, the code + can be simplified to: + + \snippet doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp 1 + + The code the compiler generates for QScopedPointer is the same as when + writing it manually. Code that makes use of \a delete are candidates for + QScopedPointer usage(and if not, possibly another type of smart pointer + such as QSharedPointer). QScopedPointer intentionally has no copy + constructor or assignment operator, such that ownership and lifetime is + clearly communicated. + + The const qualification on a regular C++ pointer can also be expressed with + a QScopedPointer: + + \snippet doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp 2 + + \note QScopedPointer does not work with arrays. + + \sa QSharedPointer +*/ + +/*! + \fn QScopedPointer::QScopedPointer(T *p = 0) + + Constructs this QScopedPointer instance and sets its pointer to \a p. +*/ + +/*! + \fn QScopedPointer::~QScopedPointer() + + Destroys this QScopedPointer object. Delete the object its pointer points + to. +*/ + +/*! + \fn T *QScopedPointer::data() const + + Returns the value of the pointer referenced by this object. QScopedPointer + still owns the object pointed to. +*/ + +/*! + \fn T &QScopedPointer::operator*() const + + Provides access to the scoped pointer's object. + + If the contained pointer is \c null, behavior is undefined. + \sa isNull() +*/ + +/*! + \fn T *QScopedPointer::operator->() const + + Provides access to the scoped pointer's object. + + If the contained pointer is \c null, behavior is undefined. + + \sa isNull() +*/ + +/*! + \fn QScopedPointer::operator bool() const + + Returns \c true if this object is not \c null. This function is suitable + for use in \tt if-constructs, like: + + \snippet doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp 3 + + \sa isNull() +*/ + +/*! + \fn bool QScopedPointer::isNull() const + + Returns \c true if this object is holding a pointer that is \c null. +*/ + +/*! + \fn void QScopedPointer::reset(T *other = 0) + + Deletes the existing object its pointing to if any, and sets its pointer to + \a other. QScopedPointer now owns \a other and will delete it in its + destructor. + + If \a other is equal to the value returned by data(), behavior is + undefined. +*/ + +/*! + \fn T *QScopedPointer::take() + + Returns the value of the pointer referenced by this object. The pointer of this + QScopedPointer object will be reset to \c null. +*/ + +QT_END_NAMESPACE + +#endif diff --git a/src/corelib/tools/qscopedpointer.h b/src/corelib/tools/qscopedpointer.h new file mode 100644 index 0000000..fc8f9e2 --- /dev/null +++ b/src/corelib/tools/qscopedpointer.h @@ -0,0 +1,199 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSCOPEDPOINTER_H +#define QSCOPEDPOINTER_H + +#include + +QT_BEGIN_HEADER +QT_BEGIN_NAMESPACE +QT_MODULE(Core) + +template +class QScopedPointer +{ +public: + explicit inline QScopedPointer(T *p = 0) : d(p) + { + } + + inline ~QScopedPointer() + { + delete d; + } + + inline T &operator*() const + { + return *d; + } + + inline T *operator->() const + { + return d; + } + + inline bool operator==(const QScopedPointer &other) const + { + return d == other.d; + } + + inline bool operator!=(const QScopedPointer &other) const + { + return d != other.d; + } + + inline operator bool() const + { + return d; + } + + inline T *data() const + { + return d; + } + + inline bool isNull() const + { + return !d; + } + + inline void reset(T *other = 0) + { + T *oldD = d; + d = other; + delete oldD; + } + + inline T *take() + { + T *oldD = d; + d = 0; + return oldD; + } + +protected: + T *d; + +private: + Q_DISABLE_COPY(QScopedPointer) +}; + +/* internal class - allows special handling for resetting and cleaning the pointer */ +template +class QScopedCustomPointer : public QScopedPointer +{ +public: + inline QScopedCustomPointer(T *p = 0) + : QScopedPointer(p) + { + } + + inline ~QScopedCustomPointer() + { + T *oldD = this->d; + this->d = 0; + CustomHandler::cleanup(oldD); + } + + inline void reset(T *other = 0) + { + CustomHandler::reset(this->d, other); + } + + inline T *&data_ptr() + { + return this->d; + } +}; + +/* Internal helper class - a handler for QShared* classes, to be used in QScopedCustomPointer */ +template +class QScopedSharedPointerHandler +{ +public: + static inline void cleanup(T *d) + { + if (d && !d->ref.deref()) + delete d; + } + + static inline void reset(T *&d, T *other) + { + T *oldD = d; + d = other; + cleanup(oldD); + } +}; + +/* Internal. This should really have been a typedef, but you can't have a templated typedef :) + This class is basically a scoped pointer pointing to a ref-counted object + */ +template +class QScopedSharedPointer : public QScopedCustomPointer > +{ +public: + inline QScopedSharedPointer(T *p = 0) + : QScopedCustomPointer >(p) + { + } + + inline void detach() + { + qAtomicDetach(this->d); + } + + inline void assign(T *other) + { + if (this->d == other) + return; + if (other) + other->ref.ref(); + T *oldD = this->d; + this->d = other; + QScopedSharedPointerHandler::cleanup(oldD); + } +}; + +QT_END_NAMESPACE +QT_END_HEADER + +#endif // QSCOPEDPOINTER_H diff --git a/src/corelib/tools/qshareddata.cpp b/src/corelib/tools/qshareddata.cpp index 2b879ea..03bc964 100644 --- a/src/corelib/tools/qshareddata.cpp +++ b/src/corelib/tools/qshareddata.cpp @@ -231,7 +231,7 @@ QT_BEGIN_NAMESPACE In the member function documentation, \e{d pointer} always refers to the internal pointer to the shared data object. - \sa QSharedData, QExplicitlySharedDataPointer + \sa QSharedData, QExplicitlySharedDataPointer, QScopedPointer, QSharedPointer */ /*! \fn T& QSharedDataPointer::operator*() diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp index c3a989e..dee06f0 100644 --- a/src/corelib/tools/qsharedpointer.cpp +++ b/src/corelib/tools/qsharedpointer.cpp @@ -102,13 +102,18 @@ except that it only detaches if QExplicitlySharedDataPointer::detach() is explicitly called. + QScopedPointer simply holds a pointer to a heap allocated object and + deletes it in its destructor. This class is useful when an object needs to + be heap allocated and deleted, but no more. QScopedPointer is lightweight, + it makes no use of additional structure or reference counting. + Finally, QPointer holds a pointer to a QObject-derived object, but it does so weakly. QPointer is similar, in that behaviour, to QWeakPointer: it does not allow you to prevent the object from being destroyed. All you can do is query whether it has been destroyed or not. - \sa QSharedDataPointer, QWeakPointer + \sa QSharedDataPointer, QWeakPointer, QScopedPointer */ /*! @@ -130,7 +135,7 @@ must first create a QSharedPointer object and verify if the pointer is null or not. - \sa QSharedPointer + \sa QSharedPointer, QScopedPointer */ /*! diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index c3649e3..e61a568 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -846,6 +846,7 @@ QString::QString(const QChar *unicode, int size) d->ref.ref(); } else { d = (Data*) qMalloc(sizeof(Data)+size*sizeof(QChar)); + Q_CHECK_PTR(d); d->ref = 1; d->alloc = d->size = size; d->clean = d->asciiCache = d->simpletext = d->righttoleft = d->capacity = 0; @@ -869,6 +870,7 @@ QString::QString(int size, QChar ch) d->ref.ref(); } else { d = (Data*) qMalloc(sizeof(Data)+size*sizeof(QChar)); + Q_CHECK_PTR(d); d->ref = 1; d->alloc = d->size = size; d->clean = d->asciiCache = d->simpletext = d->righttoleft = d->capacity = 0; @@ -894,7 +896,9 @@ QString::QString(int size, QChar ch) */ QString::QString(QChar ch) { - d = (Data *)qMalloc(sizeof(Data) + sizeof(QChar)); + void *buf = qMalloc(sizeof(Data) + sizeof(QChar)); + Q_CHECK_PTR(buf); + d = reinterpret_cast(buf); d->ref = 1; d->alloc = d->size = 1; d->clean = d->asciiCache = d->simpletext = d->righttoleft = d->capacity = 0; @@ -1064,8 +1068,7 @@ void QString::realloc(int alloc) { if (d->ref != 1 || d->data != d->array) { Data *x = static_cast(qMalloc(sizeof(Data) + alloc * sizeof(QChar))); - if (!x) - return; + Q_CHECK_PTR(x); x->size = qMin(alloc, d->size); ::memcpy(x->array, d->data, x->size * sizeof(QChar)); x->array[x->size] = 0; @@ -1088,8 +1091,7 @@ void QString::realloc(int alloc) } #endif Data *x = static_cast(qRealloc(d, sizeof(Data) + alloc * sizeof(QChar))); - if (!x) - return; + Q_CHECK_PTR(x); x->alloc = alloc; x->data = x->array; d = x; @@ -1246,6 +1248,7 @@ QString& QString::insert(int i, const QChar *unicode, int size) if (s >= d->data && s < d->data + d->alloc) { // Part of me - take a copy ushort *tmp = static_cast(qMalloc(size * sizeof(QChar))); + Q_CHECK_PTR(tmp); memcpy(tmp, s, size * sizeof(QChar)); insert(i, reinterpret_cast(tmp), size); qFree(tmp); @@ -1600,51 +1603,69 @@ QString &QString::replace(const QString &before, const QString &after, Qt::CaseS */ void QString::replace_helper(uint *indices, int nIndices, int blen, const QChar *after, int alen) { - if (blen == alen) { - detach(); - for (int i = 0; i < nIndices; ++i) - memcpy(d->data + indices[i], after, alen * sizeof(QChar)); - } else if (alen < blen) { + // copy *after in case it lies inside our own d->data area + // (which we could possibly invalidate via a realloc or corrupt via memcpy operations.) + QChar *afterBuffer = const_cast(after); + if (after >= reinterpret_cast(d->data) && after < reinterpret_cast(d->data) + d->size) { + afterBuffer = static_cast(qMalloc(alen*sizeof(QChar))); + Q_CHECK_PTR(afterBuffer); + ::memcpy(afterBuffer, after, alen*sizeof(QChar)); + } + + QT_TRY { detach(); - uint to = indices[0]; - if (alen) - memcpy(d->data+to, after, alen*sizeof(QChar)); - to += alen; - uint movestart = indices[0] + blen; - for (int i = 1; i < nIndices; ++i) { - int msize = indices[i] - movestart; - if (msize > 0) { - memmove(d->data + to, d->data + movestart, msize * sizeof(QChar)); - to += msize; + if (blen == alen) { + // replace in place + for (int i = 0; i < nIndices; ++i) + memcpy(d->data + indices[i], afterBuffer, alen * sizeof(QChar)); + } else if (alen < blen) { + // replace from front + uint to = indices[0]; + if (alen) + memcpy(d->data+to, after, alen*sizeof(QChar)); + to += alen; + uint movestart = indices[0] + blen; + for (int i = 1; i < nIndices; ++i) { + int msize = indices[i] - movestart; + if (msize > 0) { + memmove(d->data + to, d->data + movestart, msize * sizeof(QChar)); + to += msize; + } + if (alen) { + memcpy(d->data + to, afterBuffer, alen*sizeof(QChar)); + to += alen; + } + movestart = indices[i] + blen; } - if (alen) { - memcpy(d->data + to, after, alen*sizeof(QChar)); - to += alen; + int msize = d->size - movestart; + if (msize > 0) + memmove(d->data + to, d->data + movestart, msize * sizeof(QChar)); + resize(d->size - nIndices*(blen-alen)); + } else { + // replace from back + int adjust = nIndices*(alen-blen); + int newLen = d->size + adjust; + int moveend = d->size; + resize(newLen); + + while (nIndices) { + --nIndices; + int movestart = indices[nIndices] + blen; + int insertstart = indices[nIndices] + nIndices*(alen-blen); + int moveto = insertstart + alen; + memmove(d->data + moveto, d->data + movestart, + (moveend - movestart)*sizeof(QChar)); + memcpy(d->data + insertstart, afterBuffer, alen*sizeof(QChar)); + moveend = movestart-blen; } - movestart = indices[i] + blen; - } - int msize = d->size - movestart; - if (msize > 0) - memmove(d->data + to, d->data + movestart, msize * sizeof(QChar)); - resize(d->size - nIndices*(blen-alen)); - } else { - // we have a table of replacement positions, use them for fast replacing - int adjust = nIndices*(alen-blen); - int newLen = d->size + adjust; - int moveend = d->size; - resize(newLen); - - while (nIndices) { - --nIndices; - int movestart = indices[nIndices] + blen; - int insertstart = indices[nIndices] + nIndices*(alen-blen); - int moveto = insertstart + alen; - memmove(d->data + moveto, d->data + movestart, - (moveend - movestart)*sizeof(QChar)); - memcpy(d->data + insertstart, after, alen*sizeof(QChar)); - moveend = movestart-blen; } + } QT_CATCH(const std::bad_alloc &) { + if (afterBuffer != after) + qFree(afterBuffer); + QT_RETHROW; } + if (afterBuffer != after) + qFree(afterBuffer); } /*! @@ -1672,21 +1693,7 @@ QString &QString::replace(const QChar *before, int blen, if (alen == 0 && blen == 0) return *this; - // protect against before or after being part of this - const QChar *a = after; - const QChar *b = before; - if (after >= (const QChar *)d->data && after < (const QChar *)d->data + d->size) { - QChar *copy = (QChar *)malloc(alen*sizeof(QChar)); - memcpy(copy, after, alen*sizeof(QChar)); - a = copy; - } - if (before >= (const QChar *)d->data && before < (const QChar *)d->data + d->size) { - QChar *copy = (QChar *)malloc(blen*sizeof(QChar)); - memcpy(copy, before, blen*sizeof(QChar)); - b = copy; - } - - QStringMatcher matcher(b, blen, cs); + QStringMatcher matcher(before, blen, cs); int index = 0; while (1) { @@ -1705,7 +1712,7 @@ QString &QString::replace(const QChar *before, int blen, if (!pos) break; - replace_helper(indices, pos, blen, a, alen); + replace_helper(indices, pos, blen, after, alen); if (index == -1) break; @@ -1713,11 +1720,6 @@ QString &QString::replace(const QChar *before, int blen, index += pos*(alen-blen); } - if (a != after) - ::free((QChar *)a); - if (b != before) - ::free((QChar *)b); - return *this; } @@ -3450,6 +3452,7 @@ QString::Data *QString::fromLatin1_helper(const char *str, int size) if (size < 0) size = qstrlen(str); d = static_cast(qMalloc(sizeof(Data) + size * sizeof(QChar))); + Q_CHECK_PTR(d); d->ref = 1; d->alloc = d->size = size; d->clean = d->asciiCache = d->simpletext = d->righttoleft = d->capacity = 0; @@ -3457,7 +3460,7 @@ QString::Data *QString::fromLatin1_helper(const char *str, int size) ushort *i = d->data; d->array[size] = '\0'; while (size--) - *i++ = (uchar)*str++; + *i++ = (uchar)*str++; } return d; } @@ -6867,6 +6870,7 @@ void QString::updateProperties() const QString QString::fromRawData(const QChar *unicode, int size) { Data *x = static_cast(qMalloc(sizeof(Data))); + Q_CHECK_PTR(x); if (unicode) { x->data = (ushort *)unicode; } else { diff --git a/src/corelib/tools/qtextboundaryfinder.cpp b/src/corelib/tools/qtextboundaryfinder.cpp index 8a8e95b..5ca6a11 100644 --- a/src/corelib/tools/qtextboundaryfinder.cpp +++ b/src/corelib/tools/qtextboundaryfinder.cpp @@ -176,6 +176,7 @@ QTextBoundaryFinder::QTextBoundaryFinder(const QTextBoundaryFinder &other) , freePrivate(true) { d = (QTextBoundaryFinderPrivate *) malloc(length*sizeof(HB_CharAttributes)); + Q_CHECK_PTR(d); memcpy(d, other.d, length*sizeof(HB_CharAttributes)); } @@ -193,8 +194,11 @@ QTextBoundaryFinder &QTextBoundaryFinder::operator=(const QTextBoundaryFinder &o length = other.length; pos = other.pos; freePrivate = true; - - d = (QTextBoundaryFinderPrivate *) realloc(d, length*sizeof(HB_CharAttributes)); + + QTextBoundaryFinderPrivate *newD = (QTextBoundaryFinderPrivate *) + realloc(d, length*sizeof(HB_CharAttributes)); + Q_CHECK_PTR(newD); + d = newD; memcpy(d, other.d, length*sizeof(HB_CharAttributes)); return *this; @@ -221,6 +225,7 @@ QTextBoundaryFinder::QTextBoundaryFinder(BoundaryType type, const QString &strin , freePrivate(true) { d = (QTextBoundaryFinderPrivate *) malloc(length*sizeof(HB_CharAttributes)); + Q_CHECK_PTR(d); init(t, chars, length, d->attributes); } @@ -248,6 +253,7 @@ QTextBoundaryFinder::QTextBoundaryFinder(BoundaryType type, const QChar *chars, freePrivate = false; } else { d = (QTextBoundaryFinderPrivate *) malloc(length*sizeof(HB_CharAttributes)); + Q_CHECK_PTR(d); freePrivate = true; } init(t, chars, length, d->attributes); diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index e2f60ed..b41240e 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -52,6 +52,9 @@ QT_BEGIN_NAMESPACE QT_MODULE(Core) +template +class QPodList; + // Prealloc = 256 by default, specified in qcontainerfwd.h template class QVarLengthArray @@ -122,6 +125,7 @@ public: inline const T * constData() const { return ptr; } private: + friend class QPodList; void realloc(int size, int alloc); int a; @@ -140,6 +144,7 @@ Q_INLINE_TEMPLATE QVarLengthArray::QVarLengthArray(int asize) : s(asize) { if (s > Prealloc) { ptr = reinterpret_cast(qMalloc(s * sizeof(T))); + Q_CHECK_PTR(ptr); a = s; } else { ptr = reinterpret_cast(array); @@ -161,25 +166,24 @@ Q_INLINE_TEMPLATE void QVarLengthArray::reserve(int asize) { if (asize > a) realloc(s, asize); } template -Q_OUTOFLINE_TEMPLATE void QVarLengthArray::append(const T *abuf, int asize) +Q_OUTOFLINE_TEMPLATE void QVarLengthArray::append(const T *abuf, int increment) { Q_ASSERT(abuf); - if (asize <= 0) + if (increment <= 0) return; - const int idx = s; - const int news = s + asize; - if (news >= a) - realloc(s, qMax(s<<1, news)); - s = news; + const int asize = s + increment; + + if (asize >= a) + realloc(s, qMax(s*2, asize)); if (QTypeInfo::isComplex) { - T *i = ptr + idx; - T *j = i + asize; - while (i < j) - new (i++) T(*abuf++); + // call constructor for new objects (which can throw) + while (s < asize) + new (ptr+(s++)) T(*abuf++); } else { - qMemCopy(&ptr[idx], abuf, asize * sizeof(T)); + qMemCopy(&ptr[s], abuf, increment * sizeof(T)); + s = asize; } } @@ -189,46 +193,58 @@ Q_OUTOFLINE_TEMPLATE void QVarLengthArray::realloc(int asize, int a Q_ASSERT(aalloc >= asize); T *oldPtr = ptr; int osize = s; - s = asize; + // s = asize; if (aalloc != a) { ptr = reinterpret_cast(qMalloc(aalloc * sizeof(T))); + Q_CHECK_PTR(ptr); if (ptr) { + s = 0; a = aalloc; if (QTypeInfo::isStatic) { - T *i = ptr + osize; - T *j = oldPtr + osize; - while (i != ptr) { - new (--i) T(*--j); - j->~T(); + QT_TRY { + while (s < asize) { + new (ptr+s) T(*(oldPtr+s)); + (oldPtr+s)->~T(); + s++; + } + } QT_CATCH(...) { + // clean up all the old objects and then free the old ptr + int sClean = s; + while (sClean < osize) + (oldPtr+(sClean++))->~T(); + if (oldPtr != reinterpret_cast(array) && oldPtr != ptr) + qFree(oldPtr); + QT_RETHROW; } } else { - qMemCopy(ptr, oldPtr, osize * sizeof(T)); + qMemCopy(ptr, oldPtr, qMin(asize, osize) * sizeof(T)); + s = asize; } } else { ptr = oldPtr; - s = 0; - asize = 0; + return; } } if (QTypeInfo::isComplex) { - if (asize < osize) { - T *i = oldPtr + osize; - T *j = oldPtr + asize; - while (i-- != j) - i->~T(); - } else { - T *i = ptr + asize; - T *j = ptr + osize; - while (i != j) - new (--i) T; - } + while (osize > asize) + (oldPtr+(--osize))->~T(); + if( oldPtr == ptr ) + s = osize; } if (oldPtr != reinterpret_cast(array) && oldPtr != ptr) qFree(oldPtr); + + if (QTypeInfo::isComplex) { + // call default constructor for new objects (which can throw) + while (s < asize) + new (ptr+(s++)) T; + } else { + s = asize; + } } QT_END_NAMESPACE diff --git a/src/corelib/tools/qvector.cpp b/src/corelib/tools/qvector.cpp index 6b26b2e..04e9ace 100644 --- a/src/corelib/tools/qvector.cpp +++ b/src/corelib/tools/qvector.cpp @@ -50,6 +50,7 @@ QVectorData QVectorData::shared_null = { Q_BASIC_ATOMIC_INITIALIZER(1), 0, 0, tr QVectorData *QVectorData::malloc(int sizeofTypedData, int size, int sizeofT, QVectorData *init) { QVectorData* p = (QVectorData *)qMalloc(sizeofTypedData + (size - 1) * sizeofT); + Q_CHECK_PTR(p); ::memcpy(p, init, sizeofTypedData + (qMin(size, init->alloc) - 1) * sizeofT); return p; } diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 1f047b8..610b8e7 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -77,6 +77,7 @@ struct Q_CORE_EXPORT QVectorData static QVectorData shared_null; // ### Qt 5: rename to 'allocate()'. The current name causes problems for // some debugges when the QVector is member of a class within an unnamed namespace. + // ### Qt 5: can be removed completely. (Ralf) static QVectorData *malloc(int sizeofTypedData, int size, int sizeofT, QVectorData *init); static int grow(int sizeofTypedData, int size, int sizeofT, bool excessive); }; @@ -379,7 +380,9 @@ QVector &QVector::operator=(const QVector &v) template inline QVectorData *QVector::malloc(int aalloc) { - return static_cast(qMalloc(sizeOfTypedData() + (aalloc - 1) * sizeof(T))); + QVectorData *data = static_cast(qMalloc(sizeOfTypedData() + (aalloc - 1) * sizeof(T))); + Q_CHECK_PTR(data); + return data; } template @@ -428,74 +431,79 @@ void QVector::free(Data *x) template void QVector::realloc(int asize, int aalloc) { - T *j, *i, *b; + T *pOld; + T *pNew; union { QVectorData *p; Data *d; } x; x.d = d; - if (QTypeInfo::isComplex && aalloc == d->alloc && d->ref == 1) { - // pure resize - i = d->array + d->size; - j = d->array + asize; - if (i > j) { - while (i-- != j) - i->~T(); - } else { - while (j-- != i) - new (j) T; + if (QTypeInfo::isComplex && asize < d->size && d->ref == 1 ) { + // call the destructor on all objects that need to be + // destroyed when shrinking + pOld = d->array + d->size; + pNew = d->array + asize; + while (asize < d->size) { + (--pOld)->~T(); + d->size--; } - d->size = asize; - return; } if (aalloc != d->alloc || d->ref != 1) { // (re)allocate memory if (QTypeInfo::isStatic) { x.p = malloc(aalloc); + Q_CHECK_PTR(x.p); + x.d->size = 0; } else if (d->ref != 1) { - x.p = QVectorData::malloc(sizeOfTypedData(), aalloc, sizeof(T), p); - } else { + x.p = malloc(aalloc); + Q_CHECK_PTR(x.p); if (QTypeInfo::isComplex) { - // call the destructor on all objects that need to be - // destroyed when shrinking - if (asize < d->size) { - j = d->array + asize; - i = d->array + d->size; - while (i-- != j) - i->~T(); - i = d->array + asize; - } + x.d->size = 0; + } else { + ::memcpy(x.p, p, sizeOfTypedData() + (qMin(aalloc, p->alloc) - 1) * sizeof(T)); + x.d->size = d->size; + } + } else { + QT_TRY { + QVectorData *mem = static_cast(qRealloc(p, sizeOfTypedData() + (aalloc - 1) * sizeof(T))); + Q_CHECK_PTR(mem); + x.p = p = mem; + x.d->size = d->size; + } QT_CATCH (const std::bad_alloc &) { + if (aalloc > d->alloc) // ignore the error in case we are just shrinking. + QT_RETHROW; } - x.p = p = static_cast(qRealloc(p, sizeOfTypedData() + (aalloc - 1) * sizeof(T))); } x.d->ref = 1; + x.d->alloc = aalloc; x.d->sharable = true; x.d->capacity = d->capacity; - } + if (QTypeInfo::isComplex) { - if (asize < d->size) { - j = d->array + asize; - i = x.d->array + asize; - } else { - // construct all new objects when growing - i = x.d->array + asize; - j = x.d->array + d->size; - while (i != j) - new (--i) T; - j = d->array + d->size; - } - if (i != j) { + QT_TRY { + pOld = d->array + x.d->size; + pNew = x.d->array + x.d->size; // copy objects from the old array into the new array - b = x.d->array; - while (i != b) - new (--i) T(*--j); + while (x.d->size < qMin(asize, d->size)) { + new (pNew++) T(*pOld++); + x.d->size++; + } + // construct all new objects when growing + while (x.d->size < asize) { + new (pNew++) T; + x.d->size++; + } + } QT_CATCH (...) { + free(x.d); + QT_RETHROW; } - } else if (asize > d->size) { + + } else if (asize > x.d->size) { // initialize newly allocated memory to 0 - qMemSet(x.d->array + d->size, 0, (asize - d->size) * sizeof(T)); + qMemSet(x.d->array + x.d->size, 0, (asize - x.d->size) * sizeof(T)); } x.d->size = asize; - x.d->alloc = aalloc; + if (d != x.d) { if (!d->ref.deref()) free(d); diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri index c2381ce..8d27100 100644 --- a/src/corelib/tools/tools.pri +++ b/src/corelib/tools/tools.pri @@ -36,7 +36,8 @@ HEADERS += \ tools/qtimeline.h \ tools/qunicodetables_p.h \ tools/qvarlengtharray.h \ - tools/qvector.h + tools/qvector.h \ + tools/qscopedpointer.h SOURCES += \ diff --git a/src/corelib/xml/qxmlstream.cpp b/src/corelib/xml/qxmlstream.cpp index ff1a01f..6fe6ebf 100644 --- a/src/corelib/xml/qxmlstream.cpp +++ b/src/corelib/xml/qxmlstream.cpp @@ -429,7 +429,6 @@ QXmlStreamReader::~QXmlStreamReader() Q_D(QXmlStreamReader); if (d->deleteDevice) delete d->device; - delete d; } /*! \fn bool QXmlStreamReader::hasError() const @@ -819,7 +818,9 @@ inline void QXmlStreamReaderPrivate::reallocateStack() { stack_size <<= 1; sym_stack = reinterpret_cast (qRealloc(sym_stack, stack_size * sizeof(Value))); + Q_CHECK_PTR(sym_stack); state_stack = reinterpret_cast (qRealloc(state_stack, stack_size * sizeof(int))); + Q_CHECK_PTR(sym_stack); } @@ -3131,8 +3132,6 @@ QXmlStreamWriter::QXmlStreamWriter(QString *string) */ QXmlStreamWriter::~QXmlStreamWriter() { - Q_D(QXmlStreamWriter); - delete d; } diff --git a/src/corelib/xml/qxmlstream.h b/src/corelib/xml/qxmlstream.h index 2ba7972..6903d56 100644 --- a/src/corelib/xml/qxmlstream.h +++ b/src/corelib/xml/qxmlstream.h @@ -48,6 +48,7 @@ #include #include +#include QT_BEGIN_HEADER @@ -392,7 +393,7 @@ public: private: Q_DISABLE_COPY(QXmlStreamReader) Q_DECLARE_PRIVATE(QXmlStreamReader) - QXmlStreamReaderPrivate *d_ptr; + QScopedPointer d_ptr; }; #endif // QT_NO_XMLSTREAMREADER @@ -465,7 +466,7 @@ public: private: Q_DISABLE_COPY(QXmlStreamWriter) Q_DECLARE_PRIVATE(QXmlStreamWriter) - QXmlStreamWriterPrivate *d_ptr; + QScopedPointer d_ptr; }; #endif // QT_NO_XMLSTREAMWRITER diff --git a/src/dbus/qdbusabstractadaptor.cpp b/src/dbus/qdbusabstractadaptor.cpp index 883aabf..350f1aa 100644 --- a/src/dbus/qdbusabstractadaptor.cpp +++ b/src/dbus/qdbusabstractadaptor.cpp @@ -264,7 +264,7 @@ void QDBusAdaptorConnector::polish() void QDBusAdaptorConnector::relaySlot(void **argv) { - QObjectPrivate *d = static_cast(d_ptr); + QObjectPrivate *d = static_cast(d_ptr.data()); relay(d->currentSender->sender, d->currentSender->signal, argv); } diff --git a/src/dbus/qdbuscontext.h b/src/dbus/qdbuscontext.h index 3d043cf..6ece5b6 100644 --- a/src/dbus/qdbuscontext.h +++ b/src/dbus/qdbuscontext.h @@ -74,7 +74,7 @@ public: private: QDBusContextPrivate *d_ptr; - Q_DECLARE_PRIVATE(QDBusContext) + friend class QDBusContextPrivate; }; QT_END_NAMESPACE diff --git a/src/gui/dialogs/dialogs.pri b/src/gui/dialogs/dialogs.pri index 92347a7..b9fad41 100644 --- a/src/gui/dialogs/dialogs.pri +++ b/src/gui/dialogs/dialogs.pri @@ -7,6 +7,7 @@ HEADERS += \ dialogs/qabstractpagesetupdialog_p.h \ dialogs/qcolordialog.h \ dialogs/qcolordialog_p.h \ + dialogs/qfscompleter_p.h \ dialogs/qdialog.h \ dialogs/qdialog_p.h \ dialogs/qerrormessage.h \ diff --git a/src/gui/dialogs/qdialog.cpp b/src/gui/dialogs/qdialog.cpp index ef562f4..cecbb87 100644 --- a/src/gui/dialogs/qdialog.cpp +++ b/src/gui/dialogs/qdialog.cpp @@ -296,9 +296,13 @@ QDialog::QDialog(QDialogPrivate &dd, QWidget *parent, Qt::WindowFlags f) QDialog::~QDialog() { - // Need to hide() here, as our (to-be) overridden hide() - // will not be called in ~QWidget. - hide(); + QT_TRY { + // Need to hide() here, as our (to-be) overridden hide() + // will not be called in ~QWidget. + hide(); + } QT_CATCH(...) { + // we're in the destructor - just swallow the exception + } } /*! diff --git a/src/gui/dialogs/qfiledialog.cpp b/src/gui/dialogs/qfiledialog.cpp index aab79d0..60d3034 100644 --- a/src/gui/dialogs/qfiledialog.cpp +++ b/src/gui/dialogs/qfiledialog.cpp @@ -356,7 +356,6 @@ QFileDialog::~QFileDialog() settings.beginGroup(QLatin1String("Qt")); settings.setValue(QLatin1String("filedialog"), saveState()); #endif - delete d->qFileDialogUi; d->deleteNativeDialog_sys(); } @@ -488,6 +487,10 @@ void QFileDialog::changeEvent(QEvent *e) QDialog::changeEvent(e); } +QFileDialogPrivate::~QFileDialogPrivate() +{ +} + void QFileDialogPrivate::retranslateWindowTitle() { Q_Q(QFileDialog); @@ -2121,7 +2124,7 @@ void QFileDialogPrivate::createWidgets() q, SLOT(_q_rowsInserted(const QModelIndex &))); model->setReadOnly(false); - qFileDialogUi = new Ui_QFileDialog(); + qFileDialogUi.reset(new Ui_QFileDialog()); qFileDialogUi->setupUi(q); QList initialBookmarks; @@ -2147,7 +2150,7 @@ void QFileDialogPrivate::createWidgets() qFileDialogUi->fileNameLabel->setBuddy(qFileDialogUi->fileNameEdit); #endif #ifndef QT_NO_COMPLETER - completer = new QFSCompletor(model, q); + completer = new QFSCompleter(model, q); qFileDialogUi->fileNameEdit->setCompleter(completer); QObject::connect(qFileDialogUi->fileNameEdit, SIGNAL(textChanged(QString)), q, SLOT(_q_autoCompleteFileName(QString))); @@ -2205,9 +2208,9 @@ void QFileDialogPrivate::createWidgets() treeHeader->addAction(showHeader); } - QItemSelectionModel *selModel = qFileDialogUi->treeView->selectionModel(); + QScopedPointer selModel(qFileDialogUi->treeView->selectionModel()); qFileDialogUi->treeView->setSelectionModel(qFileDialogUi->listView->selectionModel()); - delete selModel; + QObject::connect(qFileDialogUi->treeView, SIGNAL(activated(QModelIndex)), q, SLOT(_q_enterDirectory(QModelIndex))); QObject::connect(qFileDialogUi->treeView, SIGNAL(customContextMenuRequested(QPoint)), @@ -2289,9 +2292,9 @@ void QFileDialog::setProxyModel(QAbstractProxyModel *proxyModel) connect(d->model, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(_q_rowsInserted(const QModelIndex &))); } - QItemSelectionModel *selModel = d->qFileDialogUi->treeView->selectionModel(); + QScopedPointer selModel(d->qFileDialogUi->treeView->selectionModel()); d->qFileDialogUi->treeView->setSelectionModel(d->qFileDialogUi->listView->selectionModel()); - delete selModel; + d->setRootIndex(idx); // reconnect selection @@ -3172,7 +3175,7 @@ void QFileDialogLineEdit::keyPressEvent(QKeyEvent *e) #ifndef QT_NO_COMPLETER -QString QFSCompletor::pathFromIndex(const QModelIndex &index) const +QString QFSCompleter::pathFromIndex(const QModelIndex &index) const { const QFileSystemModel *dirModel; if (proxyModel) @@ -3187,7 +3190,7 @@ QString QFSCompletor::pathFromIndex(const QModelIndex &index) const return index.data(QFileSystemModel::FilePathRole).toString(); } -QStringList QFSCompletor::splitPath(const QString &path) const +QStringList QFSCompleter::splitPath(const QString &path) const { if (path.isEmpty()) return QStringList(completionPrefix()); diff --git a/src/gui/dialogs/qfiledialog_p.h b/src/gui/dialogs/qfiledialog_p.h index de7e332..99f61f0 100644 --- a/src/gui/dialogs/qfiledialog_p.h +++ b/src/gui/dialogs/qfiledialog_p.h @@ -76,6 +76,7 @@ #include #include #include "qsidebar_p.h" +#include "qfscompleter_p.h" #if defined (Q_OS_UNIX) #include @@ -91,25 +92,6 @@ class QCompleter; class QHBoxLayout; class Ui_QFileDialog; -#ifndef QT_NO_COMPLETER -/*! - QCompleter that can deal with QFileSystemModel - */ -class QFSCompletor : public QCompleter { -public: - QFSCompletor(QFileSystemModel *model, QObject *parent = 0) : QCompleter(model, parent), proxyModel(0), sourceModel(model) - { -#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) - setCaseSensitivity(Qt::CaseInsensitive); -#endif - } - QString pathFromIndex(const QModelIndex &index) const; - QStringList splitPath(const QString& path) const; - - QAbstractProxyModel *proxyModel; - QFileSystemModel *sourceModel; -}; -#endif // QT_NO_COMPLETER struct QFileDialogArgs { @@ -275,7 +257,7 @@ public: // data QStringList watching; QFileSystemModel *model; - QFSCompletor *completer; + QFSCompleter *completer; QFileDialog::FileMode fileMode; QFileDialog::AcceptMode acceptMode; @@ -357,7 +339,7 @@ public: void mac_nativeDialogModalHelp(); #endif - Ui_QFileDialog *qFileDialogUi; + QScopedPointer qFileDialogUi; QString acceptLabel; @@ -366,6 +348,11 @@ public: QByteArray signalToDisconnectOnClose; QFileDialog::Options opts; + + ~QFileDialogPrivate(); + +private: + Q_DISABLE_COPY(QFileDialogPrivate) }; class QFileDialogLineEdit : public QLineEdit diff --git a/src/gui/dialogs/qfileinfogatherer.cpp b/src/gui/dialogs/qfileinfogatherer.cpp index a2abe54..119164d 100644 --- a/src/gui/dialogs/qfileinfogatherer.cpp +++ b/src/gui/dialogs/qfileinfogatherer.cpp @@ -83,10 +83,10 @@ QFileInfoGatherer::QFileInfoGatherer(QObject *parent) */ QFileInfoGatherer::~QFileInfoGatherer() { - mutex.lock(); + QMutexLocker locker(&mutex); abort = true; condition.wakeOne(); - mutex.unlock(); + locker.unlock(); wait(); } @@ -94,9 +94,8 @@ void QFileInfoGatherer::setResolveSymlinks(bool enable) { Q_UNUSED(enable); #ifdef Q_OS_WIN - mutex.lock(); + QMutexLocker locker(&mutex); m_resolveSymlinks = enable; - mutex.unlock(); #endif } @@ -107,9 +106,8 @@ bool QFileInfoGatherer::resolveSymlinks() const void QFileInfoGatherer::setIconProvider(QFileIconProvider *provider) { - mutex.lock(); + QMutexLocker locker(&mutex); m_iconProvider = provider; - mutex.unlock(); } QFileIconProvider *QFileInfoGatherer::iconProvider() const @@ -124,12 +122,11 @@ QFileIconProvider *QFileInfoGatherer::iconProvider() const */ void QFileInfoGatherer::fetchExtendedInformation(const QString &path, const QStringList &files) { - mutex.lock(); + QMutexLocker locker(&mutex); // See if we already have this dir/file in our que int loc = this->path.lastIndexOf(path); while (loc > 0) { if (this->files.at(loc) == files) { - mutex.unlock(); return; } loc = this->path.lastIndexOf(path, loc - 1); @@ -137,7 +134,6 @@ void QFileInfoGatherer::fetchExtendedInformation(const QString &path, const QStr this->path.push(path); this->files.push(files); condition.wakeAll(); - mutex.unlock(); } /*! @@ -160,10 +156,9 @@ void QFileInfoGatherer::updateFile(const QString &filePath) void QFileInfoGatherer::clear() { #ifndef QT_NO_FILESYSTEMWATCHER - mutex.lock(); + QMutexLocker locker(&mutex); watcher->removePaths(watcher->files()); watcher->removePaths(watcher->directories()); - mutex.unlock(); #endif } @@ -175,9 +170,8 @@ void QFileInfoGatherer::clear() void QFileInfoGatherer::removePath(const QString &path) { #ifndef QT_NO_FILESYSTEMWATCHER - mutex.lock(); + QMutexLocker locker(&mutex); watcher->removePath(path); - mutex.unlock(); #endif } @@ -198,9 +192,8 @@ void QFileInfoGatherer::run() { forever { bool updateFiles = false; - mutex.lock(); + QMutexLocker locker(&mutex); if (abort) { - mutex.unlock(); return; } if (this->path.isEmpty()) @@ -214,8 +207,9 @@ void QFileInfoGatherer::run() this->files.pop_front(); updateFiles = true; } - mutex.unlock(); - if (updateFiles) getFileInfos(path, list); + locker.unlock(); + if (updateFiles) + getFileInfos(path, list); } } diff --git a/src/gui/dialogs/qfscompleter_p.h b/src/gui/dialogs/qfscompleter_p.h new file mode 100644 index 0000000..37d9c74 --- /dev/null +++ b/src/gui/dialogs/qfscompleter_p.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QCOMPLETOR_P_H +#define QCOMPLETOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qcompleter.h" +#include + +#ifndef QT_NO_COMPLETER +/*! + QCompleter that can deal with QFileSystemModel + */ +class QFSCompleter : public QCompleter { +public: + QFSCompleter(QFileSystemModel *model, QObject *parent = 0) + : QCompleter(model, parent), proxyModel(0), sourceModel(model) + { +#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) + setCaseSensitivity(Qt::CaseInsensitive); +#endif + } + QString pathFromIndex(const QModelIndex &index) const; + QStringList splitPath(const QString& path) const; + + QAbstractProxyModel *proxyModel; + QFileSystemModel *sourceModel; +}; +#endif // QT_NO_COMPLETER + +#endif // QCOMPLETOR_P_H + diff --git a/src/gui/dialogs/qpagesetupdialog_win.cpp b/src/gui/dialogs/qpagesetupdialog_win.cpp index 4bb571c..bdce8ab 100644 --- a/src/gui/dialogs/qpagesetupdialog_win.cpp +++ b/src/gui/dialogs/qpagesetupdialog_win.cpp @@ -71,7 +71,7 @@ int QPageSetupDialog::exec() return Rejected; QWin32PrintEngine *engine = static_cast(d->printer->paintEngine()); - QWin32PrintEnginePrivate *ep = static_cast(engine->d_ptr); + QWin32PrintEnginePrivate *ep = static_cast(engine->d_ptr.data()); PAGESETUPDLG psd; memset(&psd, 0, sizeof(PAGESETUPDLG)); diff --git a/src/gui/dialogs/qprintdialog_unix.cpp b/src/gui/dialogs/qprintdialog_unix.cpp index 87a4e65..17d0047 100644 --- a/src/gui/dialogs/qprintdialog_unix.cpp +++ b/src/gui/dialogs/qprintdialog_unix.cpp @@ -44,7 +44,6 @@ #ifndef QT_NO_PRINTDIALOG #include "private/qabstractprintdialog_p.h" -#include "qfiledialog_p.h" #include #include "qprintdialog.h" #include "qfiledialog.h" @@ -55,6 +54,7 @@ #include +#include "qfscompleter_p.h" #include "ui_qprintpropertieswidget.h" #include "ui_qprintsettingsoutput.h" #include "ui_qprintwidget.h" @@ -696,7 +696,7 @@ QUnixPrintWidgetPrivate::QUnixPrintWidgetPrivate(QUnixPrintWidget *p) QFileSystemModel *fsm = new QFileSystemModel(widget.filename); fsm->setRootPath(QDir::homePath()); #if !defined(QT_NO_COMPLETER) && !defined(QT_NO_FILEDIALOG) - widget.filename->setCompleter(new QFSCompletor(fsm, widget.filename)); + widget.filename->setCompleter(new QFSCompleter(fsm, widget.filename)); #endif #endif _q_printerChanged(currentPrinterIndex); diff --git a/src/gui/dialogs/qprintpreviewdialog.cpp b/src/gui/dialogs/qprintpreviewdialog.cpp index c00bd14..61949d8 100644 --- a/src/gui/dialogs/qprintpreviewdialog.cpp +++ b/src/gui/dialogs/qprintpreviewdialog.cpp @@ -42,6 +42,7 @@ #include "qprintpreviewdialog.h" #include "qprintpreviewwidget.h" #include +#include "private/qdialog_p.h" #include #include @@ -128,12 +129,12 @@ private: }; } // anonymous namespace -class QPrintPreviewDialogPrivate +class QPrintPreviewDialogPrivate : public QDialogPrivate { Q_DECLARE_PUBLIC(QPrintPreviewDialog) public: - QPrintPreviewDialogPrivate(QPrintPreviewDialog *q) - : q_ptr(q), printDialog(0), ownPrinter(false), + QPrintPreviewDialogPrivate() + : printDialog(0), ownPrinter(false), initialized(false) {} // private slots @@ -158,7 +159,6 @@ public: void updatePageNumLabel(); void updateZoomFactor(); - QPrintPreviewDialog *q_ptr; QPrintDialog *printDialog; QPrintPreviewWidget *preview; QPrinter *printer; @@ -680,7 +680,7 @@ void QPrintPreviewDialogPrivate::_q_zoomFactorChanged() \sa QWidget::setWindowFlags() */ QPrintPreviewDialog::QPrintPreviewDialog(QPrinter* printer, QWidget *parent, Qt::WindowFlags flags) - : QDialog(parent, flags), d_ptr(new QPrintPreviewDialogPrivate(this)) + : QDialog(*new QPrintPreviewDialogPrivate, parent, flags) { Q_D(QPrintPreviewDialog); d->init(printer); @@ -694,7 +694,7 @@ QPrintPreviewDialog::QPrintPreviewDialog(QPrinter* printer, QWidget *parent, Qt: system default printer. */ QPrintPreviewDialog::QPrintPreviewDialog(QWidget *parent, Qt::WindowFlags f) - : QDialog(parent, f), d_ptr(new QPrintPreviewDialogPrivate(this)) + : QDialog(*new QPrintPreviewDialogPrivate, parent, f) { Q_D(QPrintPreviewDialog); d->init(); @@ -709,7 +709,6 @@ QPrintPreviewDialog::~QPrintPreviewDialog() if (d->ownPrinter) delete d->printer; delete d->printDialog; - delete d_ptr; } /*! diff --git a/src/gui/dialogs/qprintpreviewdialog.h b/src/gui/dialogs/qprintpreviewdialog.h index c3a4d57..49262db 100644 --- a/src/gui/dialogs/qprintpreviewdialog.h +++ b/src/gui/dialogs/qprintpreviewdialog.h @@ -94,7 +94,7 @@ private: Q_PRIVATE_SLOT(d_func(), void _q_previewChanged()) Q_PRIVATE_SLOT(d_func(), void _q_zoomFactorChanged()) - QPrintPreviewDialogPrivate *d_ptr; + void *dummy; // ### Qt 5 - remove me }; diff --git a/src/gui/embedded/qsoundqss_qws.cpp b/src/gui/embedded/qsoundqss_qws.cpp index 283bbd3..ed988ca 100644 --- a/src/gui/embedded/qsoundqss_qws.cpp +++ b/src/gui/embedded/qsoundqss_qws.cpp @@ -1036,24 +1036,28 @@ void QWSSoundServerPrivate::stopFile(int wid, int sid) void QWSSoundServerPrivate::stopAll(int wid) { QWSSoundServerProvider *bucket; - QList::Iterator it = active.begin(); - while (it != active.end()) { - bucket = *it; - if (bucket->groupId() == wid) { - it = active.erase(it); - delete bucket; - } else { - ++it; + if (!active.isEmpty()) { + QList::Iterator it = active.begin(); + while (it != active.end()) { + bucket = *it; + if (bucket->groupId() == wid) { + it = active.erase(it); + delete bucket; + } else { + ++it; + } } } - it = inactive.begin(); - while (it != inactive.end()) { - bucket = *it; - if (bucket->groupId() == wid) { - it = inactive.erase(it); - delete bucket; - } else { - ++it; + if (!inactive.isEmpty()) { + QList::Iterator it = inactive.begin(); + while (it != inactive.end()) { + bucket = *it; + if (bucket->groupId() == wid) { + it = inactive.erase(it); + delete bucket; + } else { + ++it; + } } } } diff --git a/src/gui/embedded/qwindowsystem_qws.cpp b/src/gui/embedded/qwindowsystem_qws.cpp index fdcd193..e3d56ad 100644 --- a/src/gui/embedded/qwindowsystem_qws.cpp +++ b/src/gui/embedded/qwindowsystem_qws.cpp @@ -1304,7 +1304,13 @@ QWSServer::QWSServer(int flags, QObject *parent) : QObject(*new QWSServerPrivate, parent) { Q_D(QWSServer); - d->initServer(flags); + QT_TRY { + d->initServer(flags); + } QT_CATCH(...) { + qwsServer = 0; + qwsServerPrivate = 0; + QT_RETHROW; + } } #ifdef QT3_SUPPORT @@ -1750,21 +1756,23 @@ void QWSServerPrivate::cleanupFonts(bool force) #if defined(QWS_DEBUG_FONTCLEANUP) qDebug() << "cleanupFonts()"; #endif - QMap::Iterator it = fontReferenceCount.begin(); - while (it != fontReferenceCount.end()) { - if (it.value() && !force) { - ++it; - continue; - } + if (!fontReferenceCount.isEmpty()) { + QMap::Iterator it = fontReferenceCount.begin(); + while (it != fontReferenceCount.end()) { + if (it.value() && !force) { + ++it; + continue; + } - const QByteArray &fontName = it.key(); + const QByteArray &fontName = it.key(); #if defined(QWS_DEBUG_FONTCLEANUP) - qDebug() << "removing unused font file" << fontName; + qDebug() << "removing unused font file" << fontName; #endif - QFile::remove(QFile::decodeName(fontName)); - sendFontRemovedEvent(fontName); + QFile::remove(QFile::decodeName(fontName)); + sendFontRemovedEvent(fontName); - it = fontReferenceCount.erase(it); + it = fontReferenceCount.erase(it); + } } if (crashedClientIds.isEmpty()) @@ -3966,7 +3974,8 @@ void QWSServerPrivate::openDisplay() void QWSServerPrivate::closeDisplay() { - qt_screen->shutdownDevice(); + if (qt_screen) + qt_screen->shutdownDevice(); } /*! @@ -4065,9 +4074,14 @@ void QWSServer::startup(int flags) void QWSServer::closedown() { - unlink(qws_qtePipeFilename().toLatin1().constData()); - delete qwsServer; + QScopedPointer server(qwsServer); qwsServer = 0; + QT_TRY { + unlink(qws_qtePipeFilename().toLatin1().constData()); + } QT_CATCH(const std::bad_alloc &) { + // ### TODO - what to do when we run out of memory + // when calling toLatin1? + } } void QWSServerPrivate::emergency_cleanup() diff --git a/src/gui/embedded/qwscursor_qws.cpp b/src/gui/embedded/qwscursor_qws.cpp index 3a5bd2c..b25e9b1 100644 --- a/src/gui/embedded/qwscursor_qws.cpp +++ b/src/gui/embedded/qwscursor_qws.cpp @@ -531,7 +531,7 @@ void QWSCursor::set(const uchar *data, const uchar *mask, cursor = QImage(width,height, QImage::Format_Indexed8); - if (!width || !height || !data || !mask) + if (!width || !height || !data || !mask || cursor.isNull()) return; cursor.setNumColors(3); diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index ed1891c..596326b 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -875,8 +875,6 @@ QGraphicsItem::~QGraphicsItem() if (d_ptr->scene) d_ptr->scene->d_func()->_q_removeItemLater(this); - delete d_ptr; - qt_dataStore()->data.remove(this); } @@ -2732,7 +2730,7 @@ QTransform QGraphicsItem::itemTransform(const QGraphicsItem *other, bool *ok) co QTransform x; const QGraphicsItem *p = child; do { - const QGraphicsItemPrivate *pd = p->d_ptr; + const QGraphicsItemPrivate *pd = p->d_ptr.data(); if (pd->hasTransform) x *= p->transform(); if (!pd->pos.isNull()) @@ -3070,7 +3068,7 @@ QRectF QGraphicsItem::sceneBoundingRect() const const QGraphicsItem *parentItem = this; const QGraphicsItemPrivate *itemd; do { - itemd = parentItem->d_ptr; + itemd = parentItem->d_ptr.data(); if (itemd->hasTransform) break; offset += itemd->pos; diff --git a/src/gui/graphicsview/qgraphicsitem.h b/src/gui/graphicsview/qgraphicsitem.h index b98882d..25678a6 100644 --- a/src/gui/graphicsview/qgraphicsitem.h +++ b/src/gui/graphicsview/qgraphicsitem.h @@ -46,6 +46,7 @@ #include #include #include +#include #include #include @@ -380,7 +381,7 @@ protected: protected: QGraphicsItem(QGraphicsItemPrivate &dd, QGraphicsItem *parent, QGraphicsScene *scene); - QGraphicsItemPrivate *d_ptr; + QScopedPointer d_ptr; void addToIndex(); void removeFromIndex(); diff --git a/src/gui/graphicsview/qgraphicslayoutitem.cpp b/src/gui/graphicsview/qgraphicslayoutitem.cpp index b46e05e..c291763 100644 --- a/src/gui/graphicsview/qgraphicslayoutitem.cpp +++ b/src/gui/graphicsview/qgraphicslayoutitem.cpp @@ -307,7 +307,6 @@ QGraphicsLayoutItem::~QGraphicsLayoutItem() } } } - delete d_ptr; } /*! diff --git a/src/gui/graphicsview/qgraphicslayoutitem.h b/src/gui/graphicsview/qgraphicslayoutitem.h index 31f5d90..d667c4f 100644 --- a/src/gui/graphicsview/qgraphicslayoutitem.h +++ b/src/gui/graphicsview/qgraphicslayoutitem.h @@ -42,6 +42,7 @@ #ifndef QGRAPHICSLAYOUTITEM_H #define QGRAPHICSLAYOUTITEM_H +#include #include #include @@ -112,7 +113,7 @@ protected: QGraphicsLayoutItem(QGraphicsLayoutItemPrivate &dd); virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const = 0; - QGraphicsLayoutItemPrivate *d_ptr; + QScopedPointer d_ptr; private: QSizeF *effectiveSizeHints(const QSizeF &constraint) const; diff --git a/src/gui/graphicsview/qgraphicsproxywidget.h b/src/gui/graphicsview/qgraphicsproxywidget.h index b2c3c8f..f006319 100644 --- a/src/gui/graphicsview/qgraphicsproxywidget.h +++ b/src/gui/graphicsview/qgraphicsproxywidget.h @@ -127,7 +127,7 @@ protected Q_SLOTS: private: Q_DISABLE_COPY(QGraphicsProxyWidget) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QGraphicsProxyWidget) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QGraphicsProxyWidget) Q_PRIVATE_SLOT(d_func(), void _q_removeWidgetSlot()) friend class QWidget; diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index b89e352..5114351 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -1824,8 +1824,8 @@ void QGraphicsScenePrivate::invalidateSortCache() inline bool qt_closestLeaf(const QGraphicsItem *item1, const QGraphicsItem *item2) { // Return true if sibling item1 is on top of item2. - const QGraphicsItemPrivate *d1 = item1->d_ptr; - const QGraphicsItemPrivate *d2 = item2->d_ptr; + const QGraphicsItemPrivate *d1 = item1->d_ptr.data(); + const QGraphicsItemPrivate *d2 = item2->d_ptr.data(); bool f1 = d1->flags & QGraphicsItem::ItemStacksBehindParent; bool f2 = d2->flags & QGraphicsItem::ItemStacksBehindParent; if (f1 != f2) return f2; @@ -1852,8 +1852,8 @@ inline bool qt_closestItemFirst(const QGraphicsItem *item1, const QGraphicsItem bool QGraphicsScenePrivate::closestItemFirst_withoutCache(const QGraphicsItem *item1, const QGraphicsItem *item2) { // Siblings? Just check their z-values. - const QGraphicsItemPrivate *d1 = item1->d_ptr; - const QGraphicsItemPrivate *d2 = item2->d_ptr; + const QGraphicsItemPrivate *d1 = item1->d_ptr.data(); + const QGraphicsItemPrivate *d2 = item2->d_ptr.data(); if (d1->parent == d2->parent) return qt_closestLeaf(item1, item2); @@ -4687,7 +4687,7 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte const QStyleOptionGraphicsItem *option, QWidget *widget, bool painterStateProtection) { - QGraphicsItemPrivate *itemd = item->d_ptr; + QGraphicsItemPrivate *itemd = item->d_ptr.data(); QGraphicsItem::CacheMode cacheMode = QGraphicsItem::CacheMode(itemd->cacheMode); // Render directly, using no cache. diff --git a/src/gui/graphicsview/qgraphicssceneevent.cpp b/src/gui/graphicsview/qgraphicssceneevent.cpp index 0ffd2b1..ad57aac 100644 --- a/src/gui/graphicsview/qgraphicssceneevent.cpp +++ b/src/gui/graphicsview/qgraphicssceneevent.cpp @@ -313,7 +313,6 @@ QGraphicsSceneEvent::QGraphicsSceneEvent(QGraphicsSceneEventPrivate &dd, Type ty */ QGraphicsSceneEvent::~QGraphicsSceneEvent() { - delete d_ptr; } /*! diff --git a/src/gui/graphicsview/qgraphicssceneevent.h b/src/gui/graphicsview/qgraphicssceneevent.h index be50e96..4ebe3df 100644 --- a/src/gui/graphicsview/qgraphicssceneevent.h +++ b/src/gui/graphicsview/qgraphicssceneevent.h @@ -44,6 +44,7 @@ #include #include +#include QT_BEGIN_HEADER @@ -70,7 +71,7 @@ public: protected: QGraphicsSceneEvent(QGraphicsSceneEventPrivate &dd, Type type = None); - QGraphicsSceneEventPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QGraphicsSceneEvent) }; diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp index 8137f8e..96e9a96 100644 --- a/src/gui/graphicsview/qgraphicsview.cpp +++ b/src/gui/graphicsview/qgraphicsview.cpp @@ -753,7 +753,7 @@ QRect QGraphicsViewPrivate::mapToViewRect(const QGraphicsItem *item, const QRect const QGraphicsItem *parentItem = item; const QGraphicsItemPrivate *itemd; do { - itemd = parentItem->d_ptr; + itemd = parentItem->d_ptr.data(); if (itemd->hasTransform) break; offset += itemd->pos; diff --git a/src/gui/graphicsview/qgraphicswidget.cpp b/src/gui/graphicsview/qgraphicswidget.cpp index 7781258..aa2b9bf 100644 --- a/src/gui/graphicsview/qgraphicswidget.cpp +++ b/src/gui/graphicsview/qgraphicswidget.cpp @@ -366,7 +366,7 @@ void QGraphicsWidget::resize(const QSizeF &size) void QGraphicsWidget::setGeometry(const QRectF &rect) { QGraphicsWidgetPrivate *wd = QGraphicsWidget::d_func(); - QGraphicsLayoutItemPrivate *d = QGraphicsLayoutItem::d_ptr; + QGraphicsLayoutItemPrivate *d = QGraphicsLayoutItem::d_ptr.data(); QRectF newGeom; QPointF oldPos = d->geom.topLeft(); if (!wd->inSetPos) { diff --git a/src/gui/graphicsview/qgraphicswidget.h b/src/gui/graphicsview/qgraphicswidget.h index 34f1c5f..49de542 100644 --- a/src/gui/graphicsview/qgraphicswidget.h +++ b/src/gui/graphicsview/qgraphicswidget.h @@ -225,7 +225,7 @@ protected: private: Q_DISABLE_COPY(QGraphicsWidget) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QGraphicsWidget) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QGraphicsWidget) friend class QGraphicsScene; friend class QGraphicsScenePrivate; friend class QGraphicsView; diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 70d4e2c..34ad99c 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -185,6 +185,13 @@ static int depthForFormat(QImage::Format format) return depth; } +/*! \fn QImageData * QImageData::create(const QSize &size, QImage::Format format, int numColors) + + \internal + + Creates a new image data. + Returns 0 if invalid parameters are give or anything else failed. +*/ QImageData * QImageData::create(const QSize &size, QImage::Format format, int numColors) { if (!size.isValid() || numColors < 0 || format == QImage::Format_Invalid) @@ -223,7 +230,7 @@ QImageData * QImageData::create(const QSize &size, QImage::Format format, int nu || INT_MAX/sizeof(uchar *) < uint(height)) return 0; - QImageData *d = new QImageData; + QScopedPointer d(new QImageData); d->colortable.resize(numColors); if (depth == 1) { d->colortable[0] = QColor(Qt::black).rgba(); @@ -246,12 +253,11 @@ QImageData * QImageData::create(const QSize &size, QImage::Format format, int nu d->data = (uchar *)malloc(d->nbytes); if (!d->data) { - delete d; return 0; } d->ref.ref(); - return d; + return d.take(); } @@ -1621,6 +1627,7 @@ int QImage::numColors() const /*! Returns a pointer to the scanline pointer table. This is the beginning of the data block for the image. + Returns 0 in case of an error. Use the bits() or scanLine() function instead. */ @@ -1636,6 +1643,8 @@ uchar **QImage::jumpTable() if (!d->jumptable) { d->jumptable = (uchar **)malloc(d->height*sizeof(uchar *)); + if (!d->jumptable) + return 0; uchar *data = d->data; int height = d->height; uchar **p = d->jumptable; @@ -1656,6 +1665,8 @@ const uchar * const *QImage::jumpTable() const return 0; if (!d->jumptable) { d->jumptable = (uchar **)malloc(d->height*sizeof(uchar *)); + if (!d->jumptable) + return 0; uchar *data = d->data; int height = d->height; uchar **p = d->jumptable; diff --git a/src/gui/image/qimageiohandler.cpp b/src/gui/image/qimageiohandler.cpp index a47c69e..f432f87 100644 --- a/src/gui/image/qimageiohandler.cpp +++ b/src/gui/image/qimageiohandler.cpp @@ -272,7 +272,6 @@ QImageIOHandler::QImageIOHandler(QImageIOHandlerPrivate &dd) */ QImageIOHandler::~QImageIOHandler() { - delete d_ptr; } /*! diff --git a/src/gui/image/qimageiohandler.h b/src/gui/image/qimageiohandler.h index 3b654f3..34de715 100644 --- a/src/gui/image/qimageiohandler.h +++ b/src/gui/image/qimageiohandler.h @@ -44,6 +44,7 @@ #include #include +#include QT_BEGIN_HEADER @@ -109,7 +110,7 @@ public: protected: QImageIOHandler(QImageIOHandlerPrivate &dd); - QImageIOHandlerPrivate *d_ptr; + QScopedPointer d_ptr; private: Q_DISABLE_COPY(QImageIOHandler) }; diff --git a/src/gui/image/qpicture.cpp b/src/gui/image/qpicture.cpp index 92023e0..8528173 100644 --- a/src/gui/image/qpicture.cpp +++ b/src/gui/image/qpicture.cpp @@ -132,7 +132,6 @@ QPicture::QPicture(int formatVersion) { Q_D(QPicture); d_ptr->q_ptr = this; - d->paintEngine = 0; if (formatVersion == 0) qWarning("QPicture: invalid format version 0"); @@ -155,7 +154,7 @@ QPicture::QPicture(int formatVersion) */ QPicture::QPicture(const QPicture &pic) - : QPaintDevice(), d_ptr(pic.d_ptr) + : QPaintDevice(), d_ptr(pic.d_ptr.data()) { d_func()->ref.ref(); } @@ -173,10 +172,6 @@ QPicture::QPicture(QPicturePrivate &dptr) */ QPicture::~QPicture() { - if (!d_func()->ref.deref()) { - delete d_func()->paintEngine; - delete d_func(); - } } /*! @@ -1030,9 +1025,7 @@ void QPicture::detach_helper() x->formatMinor = d->formatMinor; x->brect = d->brect; x->override_rect = d->override_rect; - if (!d->ref.deref()) - delete d; - d_ptr = x; + d_ptr.reset(x); } /*! @@ -1041,7 +1034,7 @@ void QPicture::detach_helper() */ QPicture& QPicture::operator=(const QPicture &p) { - qAtomicAssign(d_ptr, p.d_ptr); + d_ptr.assign(p.d_ptr.data()); return *this; } @@ -1135,8 +1128,8 @@ bool QPicturePrivate::checkFormat() QPaintEngine *QPicture::paintEngine() const { if (!d_func()->paintEngine) - const_cast(this)->d_func()->paintEngine = new QPicturePaintEngine; - return d_func()->paintEngine; + const_cast(this)->d_func()->paintEngine.reset(new QPicturePaintEngine); + return d_func()->paintEngine.data(); } /***************************************************************************** diff --git a/src/gui/image/qpicture.h b/src/gui/image/qpicture.h index fe86e8d..7de1f79 100644 --- a/src/gui/image/qpicture.h +++ b/src/gui/image/qpicture.h @@ -106,7 +106,7 @@ private: bool exec(QPainter *p, QDataStream &ds, int i); void detach_helper(); - QPicturePrivate *d_ptr; + QScopedSharedPointer d_ptr; friend class QPicturePaintEngine; friend class Q3Picture; friend class QAlphaPaintEngine; @@ -114,7 +114,7 @@ private: public: typedef QPicturePrivate* DataPtr; - inline DataPtr &data_ptr() { return d_ptr; } + inline DataPtr &data_ptr() { return d_ptr.data_ptr(); } }; Q_DECLARE_SHARED(QPicture) diff --git a/src/gui/image/qpicture_p.h b/src/gui/image/qpicture_p.h index a3fd34f..e0c3117 100644 --- a/src/gui/image/qpicture_p.h +++ b/src/gui/image/qpicture_p.h @@ -156,7 +156,7 @@ public: int formatMinor; QRect brect; QRect override_rect; - QPaintEngine *paintEngine; + QScopedPointer paintEngine; bool in_memory_only; QList image_list; QList pixmap_list; diff --git a/src/gui/image/qpixmap_s60.cpp b/src/gui/image/qpixmap_s60.cpp index 3ea50ff..132e26e 100644 --- a/src/gui/image/qpixmap_s60.cpp +++ b/src/gui/image/qpixmap_s60.cpp @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include #include #include diff --git a/src/gui/image/qpixmapcache.cpp b/src/gui/image/qpixmapcache.cpp index c9973d0..4f71e09 100644 --- a/src/gui/image/qpixmapcache.cpp +++ b/src/gui/image/qpixmapcache.cpp @@ -323,7 +323,12 @@ void QPixmapCache::remove(const QString &key) void QPixmapCache::clear() { - pm_cache()->clear(); + QT_TRY { + pm_cache()->clear(); + } QT_CATCH(const std::bad_alloc &) { + // if we ran out of memory during pm_cache(), it's no leak, + // so just ignore it. + } } QT_END_NAMESPACE diff --git a/src/gui/itemviews/qabstractitemview_p.h b/src/gui/itemviews/qabstractitemview_p.h index 16bd1ab..c4bf4db 100644 --- a/src/gui/itemviews/qabstractitemview_p.h +++ b/src/gui/itemviews/qabstractitemview_p.h @@ -304,7 +304,7 @@ public: */ inline bool isPersistent(const QModelIndex &index) const { - return static_cast(model->d_ptr)->persistent.indexes.contains(index); + return static_cast(model->d_ptr.data())->persistent.indexes.contains(index); } QModelIndexList selectedDraggableIndexes() const; diff --git a/src/gui/itemviews/qfileiconprovider.cpp b/src/gui/itemviews/qfileiconprovider.cpp index ac62551..af4d42a 100644 --- a/src/gui/itemviews/qfileiconprovider.cpp +++ b/src/gui/itemviews/qfileiconprovider.cpp @@ -180,7 +180,6 @@ QFileIconProvider::QFileIconProvider() QFileIconProvider::~QFileIconProvider() { - delete d_ptr; } /*! diff --git a/src/gui/itemviews/qfileiconprovider.h b/src/gui/itemviews/qfileiconprovider.h index 7928552..a6152ea 100644 --- a/src/gui/itemviews/qfileiconprovider.h +++ b/src/gui/itemviews/qfileiconprovider.h @@ -42,8 +42,9 @@ #ifndef QFILEICONPROVIDER_H #define QFILEICONPROVIDER_H -#include #include +#include +#include QT_BEGIN_HEADER @@ -67,7 +68,7 @@ public: private: Q_DECLARE_PRIVATE(QFileIconProvider) - QFileIconProviderPrivate *d_ptr; + QScopedPointer d_ptr; Q_DISABLE_COPY(QFileIconProvider) }; diff --git a/src/gui/itemviews/qstandarditemmodel.cpp b/src/gui/itemviews/qstandarditemmodel.cpp index 61e410d..4ec00bb 100644 --- a/src/gui/itemviews/qstandarditemmodel.cpp +++ b/src/gui/itemviews/qstandarditemmodel.cpp @@ -778,8 +778,6 @@ QStandardItem &QStandardItem::operator=(const QStandardItem &other) */ QStandardItem::~QStandardItem() { - Q_D(QStandardItem); - delete d; } /*! diff --git a/src/gui/itemviews/qstandarditemmodel.h b/src/gui/itemviews/qstandarditemmodel.h index f24f0ab..66d7576 100644 --- a/src/gui/itemviews/qstandarditemmodel.h +++ b/src/gui/itemviews/qstandarditemmodel.h @@ -240,7 +240,7 @@ protected: QStandardItem(const QStandardItem &other); QStandardItem(QStandardItemPrivate &dd); QStandardItem &operator=(const QStandardItem &other); - QStandardItemPrivate *d_ptr; + QScopedPointer d_ptr; void emitDataChanged(); diff --git a/src/gui/itemviews/qtreewidget.cpp b/src/gui/itemviews/qtreewidget.cpp index 6103225..0f2a27c 100644 --- a/src/gui/itemviews/qtreewidget.cpp +++ b/src/gui/itemviews/qtreewidget.cpp @@ -853,7 +853,7 @@ void QTreeModel::sortItems(QList *items, int column, Qt::SortO items->replace(r, item); for (int c = 0; c < colCount; ++c) { QModelIndex from = createIndex(oldRow, c, item); - if (static_cast(d_ptr)->persistent.indexes.contains(from)) { + if (static_cast(d_ptr.data())->persistent.indexes.contains(from)) { QModelIndex to = createIndex(r, c, item); fromList << from; toList << to; diff --git a/src/gui/itemviews/qtreewidgetitemiterator.cpp b/src/gui/itemviews/qtreewidgetitemiterator.cpp index 3e30e03..7e167b9 100644 --- a/src/gui/itemviews/qtreewidgetitemiterator.cpp +++ b/src/gui/itemviews/qtreewidgetitemiterator.cpp @@ -97,7 +97,7 @@ QTreeWidgetItemIterator::QTreeWidgetItemIterator(QTreeWidget *widget, IteratorFl Q_ASSERT(widget); QTreeModel *model = qobject_cast(widget->model()); Q_ASSERT(model); - d_ptr = new QTreeWidgetItemIteratorPrivate(this, model); + d_ptr.reset(new QTreeWidgetItemIteratorPrivate(this, model)); model->iterators.append(this); if (!model->rootItem->children.isEmpty()) current = model->rootItem->children.first(); if (current && !matchesFlags(current)) @@ -150,7 +150,6 @@ QTreeWidgetItemIterator::QTreeWidgetItemIterator(QTreeWidgetItem *item, Iterator QTreeWidgetItemIterator::~QTreeWidgetItemIterator() { d_func()->m_model->iterators.removeAll(this); - delete d_ptr; } /*! diff --git a/src/gui/itemviews/qtreewidgetitemiterator.h b/src/gui/itemviews/qtreewidgetitemiterator.h index 8a76c69..535339d 100644 --- a/src/gui/itemviews/qtreewidgetitemiterator.h +++ b/src/gui/itemviews/qtreewidgetitemiterator.h @@ -43,6 +43,7 @@ #define QTREEWIDGETITEMITERATOR_H #include +#include QT_BEGIN_HEADER @@ -105,7 +106,7 @@ public: private: bool matchesFlags(const QTreeWidgetItem *item) const; - QTreeWidgetItemIteratorPrivate *d_ptr; + QScopedPointer d_ptr; QTreeWidgetItem *current; IteratorFlags flags; Q_DECLARE_PRIVATE(QTreeWidgetItemIterator) diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index eaaeb4b..aa6d21e 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -1006,7 +1006,8 @@ QApplication::~QApplication() if (QWidgetPrivate::mapper) { QWidgetMapper * myMapper = QWidgetPrivate::mapper; QWidgetPrivate::mapper = 0; - for (QWidgetMapper::Iterator it = myMapper->begin(); it != myMapper->end(); ++it) { + for (QWidgetMapper::ConstIterator it = myMapper->constBegin(); + it != myMapper->constEnd(); ++it) { register QWidget *w = *it; if (!w->parent()) // window w->destroy(true, true); @@ -1018,7 +1019,7 @@ QApplication::~QApplication() if (QWidgetPrivate::uncreatedWidgets) { QWidgetSet *mySet = QWidgetPrivate::uncreatedWidgets; QWidgetPrivate::uncreatedWidgets = 0; - for (QWidgetSet::Iterator it = mySet->begin(); it != mySet->end(); ++it) { + for (QWidgetSet::ConstIterator it = mySet->constBegin(); it != mySet->constEnd(); ++it) { register QWidget *w = *it; if (!w->parent()) // window w->destroy(true, true); @@ -4993,8 +4994,7 @@ void QApplication::setInputContext(QInputContext *inputContext) qWarning("QApplication::setInputContext: called with 0 input context"); return; } - if (d->inputContext) - delete d->inputContext; + delete d->inputContext; d->inputContext = inputContext; } diff --git a/src/gui/kernel/qapplication_p.h b/src/gui/kernel/qapplication_p.h index a6fc602..35a532a 100644 --- a/src/gui/kernel/qapplication_p.h +++ b/src/gui/kernel/qapplication_p.h @@ -100,6 +100,7 @@ extern QSysInfo::MacVersion qt_macver; #if defined(Q_WS_QWS) class QWSManager; class QDirectPainter; +struct QWSServerCleaner { ~QWSServerCleaner(); }; #endif #ifndef QT_NO_TABLET @@ -382,6 +383,7 @@ public: #ifdef Q_WS_QWS QPointer last_manager; + QWSServerCleaner qwsServerCleaner; # ifndef QT_NO_DIRECTPAINTER QMap *directPainters; # endif diff --git a/src/gui/kernel/qapplication_qws.cpp b/src/gui/kernel/qapplication_qws.cpp index 018440f..aeebde4 100644 --- a/src/gui/kernel/qapplication_qws.cpp +++ b/src/gui/kernel/qapplication_qws.cpp @@ -159,6 +159,8 @@ bool qws_overrideCursor = false; #ifndef QT_NO_QWS_MANAGER #include "qdecorationfactory_qws.h" +extern Q_GUI_EXPORT QWSServer *qwsServer; + QT_BEGIN_NAMESPACE QT_USE_NAMESPACE @@ -485,8 +487,13 @@ QList *qt_get_server_queue() void qt_server_enqueue(const QWSCommand *command) { QWSCommand *copy = QWSCommand::factory(command->type); - copy->copyFrom(command); - outgoing.append(copy); + QT_TRY { + copy->copyFrom(command); + outgoing.append(copy); + } QT_CATCH(...) { + delete copy; + QT_RETHROW; + } } QWSDisplay::Data::Data(QObject* parent, bool singleProcess) @@ -2295,7 +2302,7 @@ void qt_init(QApplicationPrivate *priv, int type) qws_decoration = QApplication::qwsSetDecoration(decoration); #endif // QT_NO_QWS_MANAGER #ifndef QT_NO_QWS_INPUTMETHODS - qApp->setInputContext(new QWSInputContext); + qApp->setInputContext(new QWSInputContext(qApp)); #endif } @@ -3542,10 +3549,10 @@ bool QETWidget::translateKeyEvent(const QWSKeyEvent *event, bool grab) /* grab i #if defined QT3_SUPPORT && !defined(QT_NO_SHORTCUT) if (type == QEvent::KeyPress && !grab - && static_cast(qApp->d_ptr)->use_compat()) { + && static_cast(qApp->d_ptr.data())->use_compat()) { // send accel events if the keyboard is not grabbed QKeyEvent a(type, code, state, text, autor, int(text.length())); - if (static_cast(qApp->d_ptr)->qt_tryAccelEvent(this, &a)) + if (static_cast(qApp->d_ptr.data())->qt_tryAccelEvent(this, &a)) return true; } #else @@ -3745,4 +3752,14 @@ void QApplication::setArgs(int c, char **v) d->argv = v; } +/* \internal + This is used to clean up the qws server + in case the QApplication constructor threw an exception + */ +QWSServerCleaner::~QWSServerCleaner() +{ + if (qwsServer && qws_single_process) + QWSServer::closedown(); +} + QT_END_NAMESPACE diff --git a/src/gui/kernel/qapplication_s60.cpp b/src/gui/kernel/qapplication_s60.cpp index 2f7bdcf..976d9f6 100644 --- a/src/gui/kernel/qapplication_s60.cpp +++ b/src/gui/kernel/qapplication_s60.cpp @@ -441,6 +441,13 @@ void QSymbianControl::sendMouseEvent(QWidget *widget, QMouseEvent *mEvent) TKeyResponse QSymbianControl::OfferKeyEventL(const TKeyEvent& keyEvent, TEventCode type) { + TKeyResponse r = EKeyWasNotConsumed; + QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_LEAVE(r = OfferKeyEvent(keyEvent, type)); + return r; +} + +TKeyResponse QSymbianControl::OfferKeyEvent(const TKeyEvent& keyEvent, TEventCode type) +{ switch (type) { //case EEventKeyDown: // <-- Intentionally left out. See below. case EEventKeyUp: diff --git a/src/gui/kernel/qcursor_qws.cpp b/src/gui/kernel/qcursor_qws.cpp index 097b982..99800a8 100644 --- a/src/gui/kernel/qcursor_qws.cpp +++ b/src/gui/kernel/qcursor_qws.cpp @@ -66,7 +66,11 @@ QCursorData::~QCursorData() { delete bm; delete bmm; - QPaintDevice::qwsDisplay()->destroyCursor(id); + QT_TRY { + QPaintDevice::qwsDisplay()->destroyCursor(id); + } QT_CATCH(const std::bad_alloc &) { + // do nothing. + } } diff --git a/src/gui/kernel/qeventdispatcher_s60.cpp b/src/gui/kernel/qeventdispatcher_s60.cpp index 6ac2863..fcf572e 100644 --- a/src/gui/kernel/qeventdispatcher_s60.cpp +++ b/src/gui/kernel/qeventdispatcher_s60.cpp @@ -62,18 +62,22 @@ bool QEventDispatcherS60::processEvents ( QEventLoop::ProcessEventsFlags flags ) { bool ret = false; - bool oldNoInputEventsValue = m_noInputEvents; - if (flags & QEventLoop::ExcludeUserInputEvents) { - m_noInputEvents = true; - } else { - m_noInputEvents = false; - ret = sendDeferredInputEvents() || ret; + QT_TRY { + bool oldNoInputEventsValue = m_noInputEvents; + if (flags & QEventLoop::ExcludeUserInputEvents) { + m_noInputEvents = true; + } else { + m_noInputEvents = false; + ret = sendDeferredInputEvents() || ret; + } + + ret = QEventDispatcherSymbian::processEvents(flags) || ret; + + m_noInputEvents = oldNoInputEventsValue; + } QT_CATCH (const std::exception& ex) { + CActiveScheduler::Current()->Error(qt_translateExceptionToSymbianError(ex)); } - ret = QEventDispatcherSymbian::processEvents(flags) || ret; - - m_noInputEvents = oldNoInputEventsValue; - return ret; } diff --git a/src/gui/kernel/qshortcutmap.cpp b/src/gui/kernel/qshortcutmap.cpp index 86894b4..7a19252 100644 --- a/src/gui/kernel/qshortcutmap.cpp +++ b/src/gui/kernel/qshortcutmap.cpp @@ -148,9 +148,8 @@ public: QShortcutMap constructor. */ QShortcutMap::QShortcutMap() + : d_ptr(new QShortcutMapPrivate(this)) { - d_ptr = new QShortcutMapPrivate(this); - Q_ASSERT(d_ptr != 0); resetState(); } @@ -159,8 +158,6 @@ QShortcutMap::QShortcutMap() */ QShortcutMap::~QShortcutMap() { - delete d_ptr; - d_ptr = 0; } /*! \internal diff --git a/src/gui/kernel/qshortcutmap_p.h b/src/gui/kernel/qshortcutmap_p.h index 3fe9546..28ee1f0 100644 --- a/src/gui/kernel/qshortcutmap_p.h +++ b/src/gui/kernel/qshortcutmap_p.h @@ -55,6 +55,7 @@ #include "QtGui/qkeysequence.h" #include "QtCore/qvector.h" +#include "QtCore/qscopedpointer.h" QT_BEGIN_NAMESPACE @@ -104,7 +105,7 @@ private: #ifndef QT_NO_ACTION bool correctContext(Qt::ShortcutContext context,QAction *a, QWidget *active_window) const; #endif - QShortcutMapPrivate *d_ptr; + QScopedPointer d_ptr; QKeySequence::SequenceMatch find(QKeyEvent *e); QKeySequence::SequenceMatch matches(const QKeySequence &seq1, const QKeySequence &seq2) const; diff --git a/src/gui/kernel/qsound_s60.cpp b/src/gui/kernel/qsound_s60.cpp index 7eb6463..00fc2fe 100644 --- a/src/gui/kernel/qsound_s60.cpp +++ b/src/gui/kernel/qsound_s60.cpp @@ -146,10 +146,11 @@ QAuServer* qt_new_audio_server() QAuBucketS60::QAuBucketS60( QAuServerS60 *server, QSound *sound ) : m_sound( sound ), m_server( server ), m_prepared(false), m_playCalled(false) { + QString filepath = QFileInfo( m_sound->fileName() ).absoluteFilePath(); + filepath = QDir::toNativeSeparators(filepath); + TPtrC filepathPtr(qt_QString2TPtrC(filepath)); TRAPD(err, m_playUtility = CMdaAudioPlayerUtility::NewL(*this); - QString filepath = QFileInfo( m_sound->fileName() ).absoluteFilePath(); - filepath = QDir::toNativeSeparators(filepath); - m_playUtility->OpenFileL(qt_QString2TPtrC(filepath))); + m_playUtility->OpenFileL(filepathPtr)); if(err){ m_server->playCompleted(this, err); } diff --git a/src/gui/kernel/qt_s60_p.h b/src/gui/kernel/qt_s60_p.h index d2fa5da..2d47a14 100644 --- a/src/gui/kernel/qt_s60_p.h +++ b/src/gui/kernel/qt_s60_p.h @@ -147,6 +147,7 @@ protected: void FocusChanged(TDrawNow aDrawNow); private: + TKeyResponse OfferKeyEvent(const TKeyEvent& aKeyEvent,TEventCode aType); TKeyResponse sendKeyEvent(QWidget *widget, QKeyEvent *keyEvent); void sendMouseEvent(QWidget *widget, QMouseEvent *mEvent); void HandleLongTapEventL( const TPoint& aPenEventLocation, const TPoint& aPenEventScreenLocation ); diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index b376f20..09299dc 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -172,7 +172,8 @@ extern bool qt_sendSpontaneousEvent(QObject*, QEvent*); // qapplication.cpp extern QDesktopWidget *qt_desktopWidget; // qapplication.cpp QWidgetPrivate::QWidgetPrivate(int version) : - QObjectPrivate(version), extra(0), focus_child(0) + QObjectPrivate(version), extra(0), + focus_next(0), focus_prev(0), focus_child(0) ,layout(0), widgetItem(0) ,leftmargin(0), topmargin(0), rightmargin(0), bottommargin(0) ,leftLayoutItemMargin(0), topLayoutItemMargin(0), rightLayoutItemMargin(0) @@ -927,6 +928,23 @@ QRegion qt_dirtyRegion(QWidget *widget) \endlist */ +struct QWidgetExceptionCleaner +{ + /* this cleans up when the constructor throws an exception */ + static inline void cleanup(QWidget *that, QWidgetPrivate *d) + { +#ifndef QT_NO_EXCEPTIONS + QWidgetPrivate::uncreatedWidgets->remove(that); + if (d->focus_next != that) { + if (d->focus_next) + d->focus_next->d_func()->focus_prev = d->focus_prev; + if (d->focus_prev) + d->focus_prev->d_func()->focus_next = d->focus_next; + } +#endif + } +}; + /*! Constructs a widget which is a child of \a parent, with widget flags set to \a f. @@ -956,7 +974,12 @@ QRegion qt_dirtyRegion(QWidget *widget) QWidget::QWidget(QWidget *parent, Qt::WindowFlags f) : QObject(*new QWidgetPrivate, 0), QPaintDevice() { - d_func()->init(parent, f); + QT_TRY { + d_func()->init(parent, f); + } QT_CATCH(...) { + QWidgetExceptionCleaner::cleanup(this, d_func()); + QT_RETHROW; + } } #ifdef QT3_SUPPORT @@ -967,8 +990,13 @@ QWidget::QWidget(QWidget *parent, Qt::WindowFlags f) QWidget::QWidget(QWidget *parent, const char *name, Qt::WindowFlags f) : QObject(*new QWidgetPrivate, 0), QPaintDevice() { - d_func()->init(parent , f); - setObjectName(QString::fromAscii(name)); + QT_TRY { + d_func()->init(parent , f); + setObjectName(QString::fromAscii(name)); + } QT_CATCH(...) { + QWidgetExceptionCleaner::cleanup(this, d_func()); + QT_RETHROW; + } } #endif @@ -977,7 +1005,13 @@ QWidget::QWidget(QWidget *parent, const char *name, Qt::WindowFlags f) QWidget::QWidget(QWidgetPrivate &dd, QWidget* parent, Qt::WindowFlags f) : QObject(dd, 0), QPaintDevice() { - d_func()->init(parent, f); + Q_D(QWidget); + QT_TRY { + d->init(parent, f); + } QT_CATCH(...) { + QWidgetExceptionCleaner::cleanup(this, d_func()); + QT_RETHROW; + } } /*! @@ -5068,7 +5102,7 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP #ifndef QT_NO_SCROLLAREA QAbstractScrollArea *scrollArea = qobject_cast(q->parent()); if (scrollArea && scrollArea->viewport() == q) { - QObjectData *scrollPrivate = static_cast(scrollArea)->d_ptr; + QObjectData *scrollPrivate = static_cast(scrollArea)->d_ptr.data(); QAbstractScrollAreaPrivate *priv = static_cast(scrollPrivate); scrollAreaOffset = priv->contentsOffset(); p.translate(-scrollAreaOffset); diff --git a/src/gui/kernel/qwidget.h b/src/gui/kernel/qwidget.h index 0dd470d..1b67ba7 100644 --- a/src/gui/kernel/qwidget.h +++ b/src/gui/kernel/qwidget.h @@ -728,6 +728,7 @@ private: friend class QGraphicsProxyWidget; friend class QGraphicsProxyWidgetPrivate; friend class QStyleSheetStyle; + friend class QWidgetExceptionCleaner; #ifdef Q_WS_MAC friend class QCoreGraphicsPaintEnginePrivate; diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm index b2256cd..e2197c6 100644 --- a/src/gui/kernel/qwidget_mac.mm +++ b/src/gui/kernel/qwidget_mac.mm @@ -1215,7 +1215,7 @@ OSStatus QWidgetPrivate::qt_widget_event(EventHandlerCallRef er, EventRef event, QAbstractScrollArea *scrollArea = qobject_cast(widget->parent()); QPoint scrollAreaOffset; if (scrollArea && scrollArea->viewport() == widget) { - QAbstractScrollAreaPrivate *priv = static_cast(static_cast(scrollArea)->d_ptr); + QAbstractScrollAreaPrivate *priv = static_cast(static_cast(scrollArea)->d_ptr.data()); scrollAreaOffset = priv->contentsOffset(); p.translate(-scrollAreaOffset); } diff --git a/src/gui/kernel/qwidget_qws.cpp b/src/gui/kernel/qwidget_qws.cpp index 1445f57..0073d3f 100644 --- a/src/gui/kernel/qwidget_qws.cpp +++ b/src/gui/kernel/qwidget_qws.cpp @@ -652,7 +652,8 @@ void QWidgetPrivate::hide_sys() q->releaseMouse(); // requestWindowRegion(QRegion()); - extra->topextra->backingStore->releaseBuffer(); + if (extra->topextra->backingStore) + extra->topextra->backingStore->releaseBuffer(); QWidget::qwsDisplay()->requestFocus(data.winid,false); diff --git a/src/gui/painting/qbrush.cpp b/src/gui/painting/qbrush.cpp index 854d0aa..c22791a 100644 --- a/src/gui/painting/qbrush.cpp +++ b/src/gui/painting/qbrush.cpp @@ -221,7 +221,7 @@ bool qHasPixmapTexture(const QBrush& brush) { if (brush.style() != Qt::TexturePattern) return false; - QTexturedBrushData *tx_data = static_cast(brush.d); + QTexturedBrushData *tx_data = static_cast(brush.d.data()); return tx_data->m_has_pixmap_texture; } @@ -230,6 +230,37 @@ struct QGradientBrushData : public QBrushData QGradient gradient; }; +struct QBrushDataPointerHandler +{ + static inline void deleteData(QBrushData *d) + { + switch (d->style) { + case Qt::TexturePattern: + delete static_cast(d); + break; + case Qt::LinearGradientPattern: + case Qt::RadialGradientPattern: + case Qt::ConicalGradientPattern: + delete static_cast(d); + break; + default: + delete d; + } + } + + static inline void cleanup(QBrushData *d) + { + if (d && !d->ref.deref()) { + deleteData(d); + } + } + + static inline void reset(QBrushData *&d, QBrushData *other) + { + cleanup(d); + d = other; + } +}; /*! \class QBrush @@ -364,20 +395,20 @@ void QBrush::init(const QColor &color, Qt::BrushStyle style) { switch(style) { case Qt::NoBrush: - d = nullBrushInstance(); + d.data_ptr() = nullBrushInstance(); d->ref.ref(); if (d->color != color) setColor(color); return; case Qt::TexturePattern: - d = new QTexturedBrushData; + d.data_ptr() = new QTexturedBrushData; break; case Qt::LinearGradientPattern: case Qt::RadialGradientPattern: case Qt::ConicalGradientPattern: - d = new QGradientBrushData; + d.data_ptr() = new QGradientBrushData; break; default: - d = new QBrushData; + d.data_ptr() = new QBrushData; break; } d->ref = 1; @@ -391,8 +422,8 @@ void QBrush::init(const QColor &color, Qt::BrushStyle style) */ QBrush::QBrush() + : d(nullBrushInstance()) { - d = nullBrushInstance(); Q_ASSERT(d); d->ref.ref(); } @@ -435,7 +466,7 @@ QBrush::QBrush(Qt::BrushStyle style) if (qbrush_check_type(style)) init(Qt::black, style); else { - d = nullBrushInstance(); + d.data_ptr() = nullBrushInstance(); d->ref.ref(); } } @@ -451,7 +482,7 @@ QBrush::QBrush(const QColor &color, Qt::BrushStyle style) if (qbrush_check_type(style)) init(color, style); else { - d = nullBrushInstance(); + d.data_ptr() = nullBrushInstance(); d->ref.ref(); } } @@ -468,7 +499,7 @@ QBrush::QBrush(Qt::GlobalColor color, Qt::BrushStyle style) if (qbrush_check_type(style)) init(color, style); else { - d = nullBrushInstance(); + d.data_ptr() = nullBrushInstance(); d->ref.ref(); } } @@ -510,8 +541,8 @@ QBrush::QBrush(Qt::GlobalColor color, const QPixmap &pixmap) */ QBrush::QBrush(const QBrush &other) + : d(other.d.data()) { - d = other.d; d->ref.ref(); } @@ -535,7 +566,7 @@ QBrush::QBrush(const QGradient &gradient) }; init(QColor(), enum_table[gradient.type()]); - QGradientBrushData *grad = static_cast(d); + QGradientBrushData *grad = static_cast(d.data()); grad->gradient = gradient; } @@ -545,24 +576,11 @@ QBrush::QBrush(const QGradient &gradient) QBrush::~QBrush() { - if (!d->ref.deref()) - cleanUp(d); } void QBrush::cleanUp(QBrushData *x) { - switch (x->style) { - case Qt::TexturePattern: - delete static_cast(x); - break; - case Qt::LinearGradientPattern: - case Qt::RadialGradientPattern: - case Qt::ConicalGradientPattern: - delete static_cast(x); - break; - default: - delete x; - } + QBrushDataPointerHandler::deleteData(x); } @@ -571,38 +589,36 @@ void QBrush::detach(Qt::BrushStyle newStyle) if (newStyle == d->style && d->ref == 1) return; - QBrushData *x; + QScopedPointer x; switch(newStyle) { case Qt::TexturePattern: { QTexturedBrushData *tbd = new QTexturedBrushData; if (d->style == Qt::TexturePattern) { - QTexturedBrushData *data = static_cast(d); + QTexturedBrushData *data = static_cast(d.data()); if (data->m_has_pixmap_texture) tbd->setPixmap(data->pixmap()); else tbd->setImage(data->image()); } - x = tbd; + x.reset(tbd); break; } case Qt::LinearGradientPattern: case Qt::RadialGradientPattern: case Qt::ConicalGradientPattern: - x = new QGradientBrushData; - static_cast(x)->gradient = - static_cast(d)->gradient; + x.reset(new QGradientBrushData); + static_cast(x.data())->gradient = + static_cast(d.data())->gradient; break; default: - x = new QBrushData; + x.reset(new QBrushData); break; } x->ref = 1; x->style = newStyle; x->color = d->color; x->transform = d->transform; - if (!d->ref.deref()) - cleanUp(d); - d = x; + d.reset(x.take()); } @@ -615,10 +631,11 @@ void QBrush::detach(Qt::BrushStyle newStyle) QBrush &QBrush::operator=(const QBrush &b) { + if (this == &b) + return *this; + b.d->ref.ref(); - if (!d->ref.deref()) - cleanUp(d); - d = b.d; + d.reset(b.d.data()); return *this; } @@ -713,7 +730,7 @@ QPixmap *QBrush::pixmap() const { if (d->style != Qt::TexturePattern) return 0; - QTexturedBrushData *data = static_cast(d); + QTexturedBrushData *data = static_cast(d.data()); QPixmap &pixmap = data->pixmap(); return pixmap.isNull() ? 0 : &pixmap; } @@ -730,7 +747,7 @@ QPixmap *QBrush::pixmap() const QPixmap QBrush::texture() const { return d->style == Qt::TexturePattern - ? ((QTexturedBrushData*) d)->pixmap() + ? (static_cast(d.data()))->pixmap() : QPixmap(); } @@ -748,7 +765,7 @@ void QBrush::setTexture(const QPixmap &pixmap) { if (!pixmap.isNull()) { detach(Qt::TexturePattern); - QTexturedBrushData *data = static_cast(d); + QTexturedBrushData *data = static_cast(d.data()); data->setPixmap(pixmap); } else { detach(Qt::NoBrush); @@ -771,7 +788,7 @@ void QBrush::setTexture(const QPixmap &pixmap) QImage QBrush::textureImage() const { return d->style == Qt::TexturePattern - ? ((QTexturedBrushData *) d)->image() + ? (static_cast(d.data()))->image() : QImage(); } @@ -796,7 +813,7 @@ void QBrush::setTextureImage(const QImage &image) { if (!image.isNull()) { detach(Qt::TexturePattern); - QTexturedBrushData *data = static_cast(d); + QTexturedBrushData *data = static_cast(d.data()); data->setImage(image); } else { detach(Qt::NoBrush); @@ -812,7 +829,7 @@ const QGradient *QBrush::gradient() const if (d->style == Qt::LinearGradientPattern || d->style == Qt::RadialGradientPattern || d->style == Qt::ConicalGradientPattern) { - return &static_cast(d)->gradient; + return &static_cast(d.data())->gradient; } return 0; } @@ -923,16 +940,16 @@ bool QBrush::operator==(const QBrush &b) const if (b.d->style == d->style && b.d->color == d->color) { switch (d->style) { case Qt::TexturePattern: { - QPixmap &us = ((QTexturedBrushData *) d)->pixmap(); - QPixmap &them = ((QTexturedBrushData *) b.d)->pixmap(); + QPixmap &us = (static_cast(d.data()))->pixmap(); + QPixmap &them = (static_cast(b.d.data()))->pixmap(); return ((us.isNull() && them.isNull()) || us.cacheKey() == them.cacheKey()); } case Qt::LinearGradientPattern: case Qt::RadialGradientPattern: case Qt::ConicalGradientPattern: { - QGradientBrushData *d1 = static_cast(d); - QGradientBrushData *d2 = static_cast(b.d); + QGradientBrushData *d1 = static_cast(d.data()); + QGradientBrushData *d2 = static_cast(b.d.data()); return d1->gradient == d2->gradient; } default: diff --git a/src/gui/painting/qbrush.h b/src/gui/painting/qbrush.h index d6d0da3..b3aa04d 100644 --- a/src/gui/painting/qbrush.h +++ b/src/gui/painting/qbrush.h @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -61,6 +62,7 @@ struct QBrushData; class QPixmap; class QGradient; class QVariant; +struct QBrushDataPointerHandler; class Q_GUI_EXPORT QBrush { @@ -126,13 +128,13 @@ private: friend bool qHasPixmapTexture(const QBrush& brush); void detach(Qt::BrushStyle newStyle); void init(const QColor &color, Qt::BrushStyle bs); - QBrushData *d; + QScopedCustomPointer d; void cleanUp(QBrushData *x); public: inline bool isDetached() const; typedef QBrushData * DataPtr; - inline DataPtr &data_ptr() { return d; } + inline DataPtr &data_ptr() { return d.data_ptr(); } }; inline void QBrush::setColor(Qt::GlobalColor acolor) diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp index ed4dd57..0b5e5bb 100644 --- a/src/gui/painting/qdrawhelper.cpp +++ b/src/gui/painting/qdrawhelper.cpp @@ -7426,8 +7426,8 @@ void qt_build_pow_tables() { } #else for (int i=0; i<256; ++i) { - qt_pow_rgb_gamma[i] = uchar(qRound(pow(i / 255.0, smoothing) * 255)); - qt_pow_rgb_invgamma[i] = uchar(qRound(pow(i / 255.0, 1 / smoothing) * 255)); + qt_pow_rgb_gamma[i] = uchar(qRound(pow(i / qreal(255), smoothing) * 255)); + qt_pow_rgb_invgamma[i] = uchar(qRound(pow(i / qreal(255), 1 / smoothing) * 255)); } #endif diff --git a/src/gui/painting/qpaintengine.cpp b/src/gui/painting/qpaintengine.cpp index 7de1ec4..c5be802 100644 --- a/src/gui/painting/qpaintengine.cpp +++ b/src/gui/painting/qpaintengine.cpp @@ -713,7 +713,6 @@ QPaintEngine::QPaintEngine(QPaintEnginePrivate &dptr, PaintEngineFeatures caps) */ QPaintEngine::~QPaintEngine() { - delete d_ptr; } /*! diff --git a/src/gui/painting/qpaintengine.h b/src/gui/painting/qpaintengine.h index 520f71f..6f56adb 100644 --- a/src/gui/painting/qpaintengine.h +++ b/src/gui/painting/qpaintengine.h @@ -44,6 +44,7 @@ #include #include +#include #include QT_BEGIN_HEADER @@ -239,7 +240,7 @@ protected: uint selfDestruct : 1; uint extended : 1; - QPaintEnginePrivate *d_ptr; + QScopedPointer d_ptr; private: void setAutoDestruct(bool autoDestr) { selfDestruct = autoDestr; } diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index 95b4100..ada3ebf 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -349,6 +349,7 @@ void QRasterPaintEngine::init() #else (unsigned char *) malloc(d->rasterPoolSize); #endif + Q_CHECK_PTR(d->rasterPoolBase); // The antialiasing raster. d->grayRaster = new QT_FT_Raster; @@ -3904,7 +3905,7 @@ static void qt_merge_clip(const QClipData *c1, const QClipData *c2, QClipData *r // find required length int max = qMax(c1_spans[c1_count - 1].x + c1_spans[c1_count - 1].len, - c2_spans[c2_count - 1].x + c2_spans[c2_count - 1].len); + c2_spans[c2_count - 1].x + c2_spans[c2_count - 1].len); buffer.resize(max); memset(buffer.data(), 0, buffer.size() * sizeof(short)); @@ -3958,7 +3959,7 @@ void QRasterPaintEnginePrivate::initializeRasterizer(QSpanData *data) const QClipData *c = clip(); if (c) { const QRect r(QPoint(c->xmin, c->ymin), - QPoint(c->xmax, c->ymax)); + QPoint(c->xmax, c->ymax)); clipRect = clipRect.intersected(r); blend = data->blend; } else { @@ -4066,6 +4067,7 @@ void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline, #else (unsigned char *) malloc(rasterPoolSize); #endif + Q_CHECK_PTR(rasterPoolBase); // note: we just freed the old rasterPoolBase. I hope it's not fatal. qt_ft_grays_raster.raster_done(*grayRaster); qt_ft_grays_raster.raster_new(0, grayRaster); @@ -4301,93 +4303,107 @@ void QClipData::initialize() return; m_clipLines = (ClipLine *)calloc(sizeof(ClipLine), clipSpanHeight); - m_spans = (QSpan *)malloc(clipSpanHeight*sizeof(QSpan)); - - if (hasRectClip) { - int y = 0; - while (y < ymin) { - m_clipLines[y].spans = 0; - m_clipLines[y].count = 0; - ++y; - } + Q_CHECK_PTR(m_clipLines); + QT_TRY { + m_spans = (QSpan *)malloc(clipSpanHeight*sizeof(QSpan)); + Q_CHECK_PTR(m_spans); + + QT_TRY { + if (hasRectClip) { + int y = 0; + while (y < ymin) { + m_clipLines[y].spans = 0; + m_clipLines[y].count = 0; + ++y; + } - const int len = clipRect.width(); - count = 0; - while (y < ymax) { - QSpan *span = m_spans + count; - span->x = xmin; - span->len = len; - span->y = y; - span->coverage = 255; - ++count; - - m_clipLines[y].spans = span; - m_clipLines[y].count = 1; - ++y; - } + const int len = clipRect.width(); + count = 0; + while (y < ymax) { + QSpan *span = m_spans + count; + span->x = xmin; + span->len = len; + span->y = y; + span->coverage = 255; + ++count; - while (y < clipSpanHeight) { - m_clipLines[y].spans = 0; - m_clipLines[y].count = 0; - ++y; - } - } else if (hasRegionClip) { + m_clipLines[y].spans = span; + m_clipLines[y].count = 1; + ++y; + } - const QVector rects = clipRegion.rects(); - const int numRects = rects.size(); + while (y < clipSpanHeight) { + m_clipLines[y].spans = 0; + m_clipLines[y].count = 0; + ++y; + } + } else if (hasRegionClip) { + + const QVector rects = clipRegion.rects(); + const int numRects = rects.size(); + + { // resize + const int maxSpans = (ymax - ymin) * numRects; + if (maxSpans > allocated) { + QSpan *newSpans = (QSpan *)realloc(m_spans, maxSpans * sizeof(QSpan)); + Q_CHECK_PTR(newSpans); + m_spans = newSpans; + allocated = maxSpans; + } + } - { // resize - const int maxSpans = (ymax - ymin) * numRects; - if (maxSpans > allocated) { - m_spans = (QSpan *)realloc(m_spans, maxSpans * sizeof(QSpan)); - allocated = maxSpans; - } - } + int y = 0; + int firstInBand = 0; + while (firstInBand < numRects) { + const int currMinY = rects.at(firstInBand).y(); + const int currMaxY = currMinY + rects.at(firstInBand).height(); - int y = 0; - int firstInBand = 0; - while (firstInBand < numRects) { - const int currMinY = rects.at(firstInBand).y(); - const int currMaxY = currMinY + rects.at(firstInBand).height(); + while (y < currMinY) { + m_clipLines[y].spans = 0; + m_clipLines[y].count = 0; + ++y; + } - while (y < currMinY) { - m_clipLines[y].spans = 0; - m_clipLines[y].count = 0; - ++y; - } + int lastInBand = firstInBand; + while (lastInBand + 1 < numRects && rects.at(lastInBand+1).top() == y) + ++lastInBand; - int lastInBand = firstInBand; - while (lastInBand + 1 < numRects && rects.at(lastInBand+1).top() == y) - ++lastInBand; + while (y < currMaxY) { - while (y < currMaxY) { + m_clipLines[y].spans = m_spans + count; + m_clipLines[y].count = lastInBand - firstInBand + 1; - m_clipLines[y].spans = m_spans + count; - m_clipLines[y].count = lastInBand - firstInBand + 1; + for (int r = firstInBand; r <= lastInBand; ++r) { + const QRect &currRect = rects.at(r); + QSpan *span = m_spans + count; + span->x = currRect.x(); + span->len = currRect.width(); + span->y = y; + span->coverage = 255; + ++count; + } + ++y; + } - for (int r = firstInBand; r <= lastInBand; ++r) { - const QRect &currRect = rects.at(r); - QSpan *span = m_spans + count; - span->x = currRect.x(); - span->len = currRect.width(); - span->y = y; - span->coverage = 255; - ++count; + firstInBand = lastInBand + 1; } - ++y; - } - firstInBand = lastInBand + 1; - } + Q_ASSERT(count <= allocated); - Q_ASSERT(count <= allocated); + while (y < clipSpanHeight) { + m_clipLines[y].spans = 0; + m_clipLines[y].count = 0; + ++y; + } - while (y < clipSpanHeight) { - m_clipLines[y].spans = 0; - m_clipLines[y].count = 0; - ++y; + } + } QT_CATCH(...) { + free(m_spans); + QT_RETHROW; } - + } QT_CATCH(...) { + free(m_clipLines); + QT_RETHROW; } } @@ -4764,8 +4780,10 @@ static void qt_span_clip(int count, const QSpan *spans, void *userData) &newspans, newClip->allocated - newClip->count); newClip->count = newspans - newClip->m_spans; if (spans < end) { + QSpan *newSpan = (QSpan *)realloc(newClip->m_spans, newClip->allocated*2*sizeof(QSpan)); + Q_CHECK_PTR(newSpan); + newClip->m_spans = newSpan; newClip->allocated *= 2; - newClip->m_spans = (QSpan *)realloc(newClip->m_spans, newClip->allocated*sizeof(QSpan)); } } } diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index cc48d24..0caf13b 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -83,6 +83,21 @@ static const qreal aliasedCoordinateDelta = 0.5 - 0.015625; bool qt_show_painter_debug_output = true; #endif +class QPainterPrivateCleaner +{ +public: + static inline void cleanup(QPainterPrivate *d) + { + delete d; + } + + static inline void reset(QPainterPrivate *&d, QPainterPrivate *other) + { + delete d; + d = other; + } +}; + extern QPixmap qt_pixmapForBrush(int style, bool invert); void qt_format_text(const QFont &font, @@ -259,14 +274,17 @@ bool QPainterPrivate::attachPainterPrivate(QPainter *q, QPaintDevice *pdev) // in 99% of all cases). E.g: A renders B which renders C which renders D. sp->d_ptr->d_ptrs_size = 4; sp->d_ptr->d_ptrs = (QPainterPrivate **)malloc(4 * sizeof(QPainterPrivate *)); + Q_CHECK_PTR(sp->d_ptr->d_ptrs); } else if (sp->d_ptr->refcount - 1 == sp->d_ptr->d_ptrs_size) { // However, to support corner cases we grow the array dynamically if needed. sp->d_ptr->d_ptrs_size <<= 1; const int newSize = sp->d_ptr->d_ptrs_size * sizeof(QPainterPrivate *); - sp->d_ptr->d_ptrs = (QPainterPrivate **)realloc(sp->d_ptr->d_ptrs, newSize); + QPainterPrivate ** newPointers = (QPainterPrivate **)realloc(sp->d_ptr->d_ptrs, newSize); + Q_CHECK_PTR(newPointers); + sp->d_ptr->d_ptrs = newPointers; } - sp->d_ptr->d_ptrs[++sp->d_ptr->refcount - 2] = q->d_ptr; - q->d_ptr = sp->d_ptr; + sp->d_ptr->d_ptrs[++sp->d_ptr->refcount - 2] = q->d_ptr.data(); + q->d_ptr.data_ptr() = sp->d_ptr.data(); Q_ASSERT(q->d_ptr->state); @@ -315,7 +333,7 @@ void QPainterPrivate::detachPainterPrivate(QPainter *q) d_ptrs[refcount - 1] = 0; q->restore(); - q->d_ptr = original; + q->d_ptr.data_ptr() = original; if (emulationEngine) { extended = emulationEngine->real_engine; @@ -1374,8 +1392,8 @@ void QPainterPrivate::updateState(QPainterState *newState) */ QPainter::QPainter() + : d_ptr(new QPainterPrivate(this)) { - d_ptr = new QPainterPrivate(this); } /*! @@ -1407,7 +1425,7 @@ QPainter::QPainter(QPaintDevice *pd) { Q_ASSERT(pd != 0); if (!QPainterPrivate::attachPainterPrivate(this, pd)) { - d_ptr = new QPainterPrivate(this); + d_ptr.reset(new QPainterPrivate(this)); begin(pd); } Q_ASSERT(d_ptr); @@ -1419,11 +1437,14 @@ QPainter::QPainter(QPaintDevice *pd) QPainter::~QPainter() { d_ptr->inDestructor = true; - if (isActive()) - end(); - else if (d_ptr->refcount > 1) - d_ptr->detachPainterPrivate(this); - + QT_TRY { + if (isActive()) + end(); + else if (d_ptr->refcount > 1) + d_ptr->detachPainterPrivate(this); + } QT_CATCH(...) { + // don't throw anything in the destructor. + } if (d_ptr) { // Make sure we haven't messed things up. Q_ASSERT(d_ptr->inDestructor); @@ -1431,7 +1452,6 @@ QPainter::~QPainter() Q_ASSERT(d_ptr->refcount == 1); if (d_ptr->d_ptrs) free(d_ptr->d_ptrs); - delete d_ptr; } } @@ -7417,8 +7437,21 @@ QPaintDevice *QPainter::redirected(const QPaintDevice *device, QPoint *offset) void qt_painter_removePaintDevice(QPaintDevice *dev) { - QMutexLocker locker(globalRedirectionsMutex()); - if(QPaintDeviceRedirectionList *redirections = globalRedirections()) { + QMutex *mutex = 0; + QT_TRY { + mutex = globalRedirectionsMutex(); + } QT_CATCH(...) { + // ignore the missing mutex, since we could be called from + // a destructor, and destructors shall not throw + } + QMutexLocker locker(mutex); + QPaintDeviceRedirectionList *redirections = 0; + QT_TRY { + redirections = globalRedirections(); + } QT_CATCH(...) { + // do nothing - code below is safe with redirections being 0. + } + if (redirections) { for (int i = 0; i < redirections->size(); ) { if(redirections->at(i) == dev || redirections->at(i).replacement == dev) redirections->removeAt(i); diff --git a/src/gui/painting/qpainter.h b/src/gui/painting/qpainter.h index f3df7a3..d8c6980 100644 --- a/src/gui/painting/qpainter.h +++ b/src/gui/painting/qpainter.h @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -78,6 +79,8 @@ class QTextItem; class QMatrix; class QTransform; +class QPainterPrivateCleaner; + class Q_GUI_EXPORT QPainter { Q_DECLARE_PRIVATE(QPainter) @@ -497,7 +500,7 @@ private: Q_DISABLE_COPY(QPainter) friend class Q3Painter; - QPainterPrivate *d_ptr; + QScopedCustomPointer d_ptr; friend class QFontEngine; friend class QFontEngineBox; diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp index 1b2c4e3..12dbc62 100644 --- a/src/gui/painting/qpainterpath.cpp +++ b/src/gui/painting/qpainterpath.cpp @@ -506,10 +506,10 @@ QPainterPath::QPainterPath() \sa operator=() */ QPainterPath::QPainterPath(const QPainterPath &other) - : d_ptr(other.d_ptr) + : d_ptr(other.d_ptr.data()) { - if (d_func()) - d_func()->ref.ref(); + if (d_ptr) + d_ptr->ref.ref(); } /*! @@ -530,9 +530,7 @@ QPainterPath::QPainterPath(const QPointF &startPoint) void QPainterPath::detach_helper() { QPainterPathPrivate *data = new QPainterPathData(*d_func()); - if (d_ptr && !d_ptr->ref.deref()) - delete d_ptr; - d_ptr = data; + d_ptr.reset(data); } /*! @@ -544,9 +542,7 @@ void QPainterPath::ensureData_helper() data->elements.reserve(16); QPainterPath::Element e = { 0, 0, QPainterPath::MoveToElement }; data->elements << e; - if (d_ptr && !d_ptr->ref.deref()) - delete d_ptr; - d_ptr = data; + d_ptr.reset(data); Q_ASSERT(d_ptr != 0); } @@ -563,9 +559,7 @@ QPainterPath &QPainterPath::operator=(const QPainterPath &other) QPainterPathPrivate *data = other.d_func(); if (data) data->ref.ref(); - if (d_ptr && !d_ptr->ref.deref()) - delete d_ptr; - d_ptr = data; + d_ptr.reset(data); } return *this; } @@ -575,8 +569,6 @@ QPainterPath &QPainterPath::operator=(const QPainterPath &other) */ QPainterPath::~QPainterPath() { - if (d_func() && !d_func()->ref.deref()) - delete d_func(); } /*! @@ -2408,7 +2400,6 @@ QPainterPathStroker::QPainterPathStroker() */ QPainterPathStroker::~QPainterPathStroker() { - delete d_ptr; } diff --git a/src/gui/painting/qpainterpath.h b/src/gui/painting/qpainterpath.h index 6cd2af8..0513593 100644 --- a/src/gui/painting/qpainterpath.h +++ b/src/gui/painting/qpainterpath.h @@ -47,6 +47,7 @@ #include #include #include +#include QT_BEGIN_HEADER @@ -195,7 +196,7 @@ public: QPainterPath &operator-=(const QPainterPath &other); private: - QPainterPathPrivate *d_ptr; + QScopedSharedPointer d_ptr; inline void ensureData() { if (!d_ptr) ensureData_helper(); } void ensureData_helper(); @@ -205,7 +206,7 @@ private: void computeBoundingRect() const; void computeControlPointRect() const; - QPainterPathData *d_func() const { return reinterpret_cast(d_ptr); } + QPainterPathData *d_func() const { return reinterpret_cast(d_ptr.data()); } friend class QPainterPathData; friend class QPainterPathStroker; @@ -229,6 +230,8 @@ public: friend class QPainterPathStrokerPrivate; friend class QMatrix; friend class QTransform; + friend class QScopedSharedPointer; + friend class QScopedSharedPointerHandler; #ifndef QT_NO_DATASTREAM friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &); friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &); @@ -279,7 +282,7 @@ public: private: friend class QX11PaintEngine; - QPainterPathStrokerPrivate *d_ptr; + QScopedPointer d_ptr; }; inline void QPainterPath::moveTo(qreal x, qreal y) diff --git a/src/gui/painting/qprinter.cpp b/src/gui/painting/qprinter.cpp index ed72077..ba6baa6 100644 --- a/src/gui/painting/qprinter.cpp +++ b/src/gui/painting/qprinter.cpp @@ -712,7 +712,6 @@ QPrinter::~QPrinter() #ifndef QT_NO_PRINTPREVIEWWIDGET delete d->previewEngine; #endif - delete d; } /*! diff --git a/src/gui/painting/qprinter.h b/src/gui/painting/qprinter.h index 949c8f9..24e867b 100644 --- a/src/gui/painting/qprinter.h +++ b/src/gui/painting/qprinter.h @@ -42,8 +42,9 @@ #ifndef QPRINTER_H #define QPRINTER_H -#include #include +#include +#include QT_BEGIN_HEADER @@ -288,7 +289,7 @@ private: Q_DISABLE_COPY(QPrinter) - QPrinterPrivate *d_ptr; + QScopedPointer d_ptr; friend class QPrintDialogPrivate; friend class QAbstractPrintDialog; diff --git a/src/gui/painting/qprinterinfo.h b/src/gui/painting/qprinterinfo.h index b826306..d188d73 100644 --- a/src/gui/painting/qprinterinfo.h +++ b/src/gui/painting/qprinterinfo.h @@ -53,6 +53,7 @@ QT_MODULE(Gui) #ifndef QT_NO_PRINTER class QPrinterInfoPrivate; +class QPrinterInfoPrivateCleanup; class Q_GUI_EXPORT QPrinterInfo { Q_DECLARE_PRIVATE(QPrinterInfo) @@ -76,7 +77,7 @@ public: private: QPrinterInfo(const QString& name); - QPrinterInfoPrivate* d_ptr; + QScopedCustomPointer d_ptr; }; #endif // QT_NO_PRINTER diff --git a/src/gui/painting/qprinterinfo_mac.cpp b/src/gui/painting/qprinterinfo_mac.cpp index ecd4b5b..ae689f4 100644 --- a/src/gui/painting/qprinterinfo_mac.cpp +++ b/src/gui/painting/qprinterinfo_mac.cpp @@ -65,6 +65,22 @@ private: static QPrinterInfoPrivate nullQPrinterInfoPrivate; +class QPrinterInfoPrivateCleanup +{ +public: + static inline void cleanup(QPrinterInfoPrivate *d) + { + if (d != &nullQPrinterInfoPrivate) + delete d; + } + + static inline void reset(QPrinterInfoPrivate *&d, QPrinterInfoPrivate *other) + { + cleanup(d); + d = other; + } +}; + extern QPrinter::PaperSize qSizeFTopaperSize(const QSizeF& size); ///////////////////////////////////////////////////////////////////////////// @@ -106,8 +122,8 @@ QPrinterInfo QPrinterInfo::defaultPrinter(){ ///////////////////////////////////////////////////////////////////////////// QPrinterInfo::QPrinterInfo(const QPrinter& prn) + : d_ptr(&nullQPrinterInfoPrivate) { - d_ptr = &nullQPrinterInfoPrivate; QList list = availablePrinters(); for (int c = 0; c < list.size(); ++c) { if (prn.printerName() == list[c].printerName()) { @@ -115,39 +131,33 @@ QPrinterInfo::QPrinterInfo(const QPrinter& prn) return; } } - - *this = QPrinterInfo(); } QPrinterInfo::~QPrinterInfo() { - if (d_ptr != &nullQPrinterInfoPrivate) - delete d_ptr; } QPrinterInfo::QPrinterInfo() + : d_ptr(&nullQPrinterInfoPrivate) { - d_ptr = &nullQPrinterInfoPrivate; } QPrinterInfo::QPrinterInfo(const QString& name) + : d_ptr(new QPrinterInfoPrivate(name)) { - d_ptr = new QPrinterInfoPrivate(name); d_ptr->q_ptr = this; } QPrinterInfo::QPrinterInfo(const QPrinterInfo& src) + : d_ptr(&nullQPrinterInfoPrivate) { - d_ptr = &nullQPrinterInfoPrivate; *this = src; } QPrinterInfo& QPrinterInfo::operator=(const QPrinterInfo& src) { Q_ASSERT(d_ptr); - if (d_ptr != &nullQPrinterInfoPrivate) - delete d_ptr; - d_ptr = new QPrinterInfoPrivate(*src.d_ptr); + d_ptr.reset(new QPrinterInfoPrivate(*src.d_ptr)); d_ptr->q_ptr = this; return *this; } diff --git a/src/gui/painting/qprinterinfo_unix.cpp b/src/gui/painting/qprinterinfo_unix.cpp index 0f33ea7..55e3226 100644 --- a/src/gui/painting/qprinterinfo_unix.cpp +++ b/src/gui/painting/qprinterinfo_unix.cpp @@ -82,6 +82,22 @@ private: static QPrinterInfoPrivate nullQPrinterInfoPrivate; +class QPrinterInfoPrivateCleanup +{ +public: + static inline void cleanup(QPrinterInfoPrivate *d) + { + if (d != &nullQPrinterInfoPrivate) + delete d; + } + + static inline void reset(QPrinterInfoPrivate *&d, QPrinterInfoPrivate *other) + { + cleanup(d); + d = other; + } +}; + ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// @@ -867,19 +883,19 @@ QPrinterInfo QPrinterInfo::defaultPrinter() } QPrinterInfo::QPrinterInfo() + : d_ptr(&nullQPrinterInfoPrivate) { - d_ptr = &nullQPrinterInfoPrivate; } QPrinterInfo::QPrinterInfo(const QPrinterInfo& src) + : d_ptr(&nullQPrinterInfoPrivate) { - d_ptr = &nullQPrinterInfoPrivate; *this = src; } QPrinterInfo::QPrinterInfo(const QPrinter& printer) + : d_ptr(new QPrinterInfoPrivate(printer.printerName())) { - d_ptr = new QPrinterInfoPrivate(printer.printerName()); Q_D(QPrinterInfo); d->q_ptr = this; @@ -929,28 +945,23 @@ QPrinterInfo::QPrinterInfo(const QPrinter& printer) #endif // Printer not found. - delete d; - d_ptr = &nullQPrinterInfoPrivate; + d_ptr.reset(&nullQPrinterInfoPrivate); } QPrinterInfo::QPrinterInfo(const QString& name) + : d_ptr(new QPrinterInfoPrivate(name)) { - d_ptr = new QPrinterInfoPrivate(name); d_ptr->q_ptr = this; } QPrinterInfo::~QPrinterInfo() { - if (d_ptr != &nullQPrinterInfoPrivate) - delete d_ptr; } QPrinterInfo& QPrinterInfo::operator=(const QPrinterInfo& src) { Q_ASSERT(d_ptr); - if (d_ptr != &nullQPrinterInfoPrivate) - delete d_ptr; - d_ptr = new QPrinterInfoPrivate(*src.d_ptr); + d_ptr.reset(new QPrinterInfoPrivate(*src.d_ptr)); d_ptr->q_ptr = this; return *this; } diff --git a/src/gui/painting/qprinterinfo_win.cpp b/src/gui/painting/qprinterinfo_win.cpp index 7cd3cf3..7607391 100644 --- a/src/gui/painting/qprinterinfo_win.cpp +++ b/src/gui/painting/qprinterinfo_win.cpp @@ -69,6 +69,22 @@ private: static QPrinterInfoPrivate nullQPrinterInfoPrivate; +class QPrinterInfoPrivateCleanup +{ +public: + static inline void cleanup(QPrinterInfoPrivate *d) + { + if (d != &nullQPrinterInfoPrivate) + delete d; + } + + static inline void reset(QPrinterInfoPrivate *&d, QPrinterInfoPrivate *other) + { + cleanup(d); + d = other; + } +}; + ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// @@ -155,25 +171,25 @@ QPrinterInfo QPrinterInfo::defaultPrinter() ///////////////////////////////////////////////////////////////////////////// QPrinterInfo::QPrinterInfo() + : d_ptr(&nullQPrinterInfoPrivate) { - d_ptr = &nullQPrinterInfoPrivate; } QPrinterInfo::QPrinterInfo(const QString& name) + : d_ptr(new QPrinterInfoPrivate(name)) { - d_ptr = new QPrinterInfoPrivate(name); d_ptr->q_ptr = this; } QPrinterInfo::QPrinterInfo(const QPrinterInfo& src) + : d_ptr(&nullQPrinterInfoPrivate) { - d_ptr = &nullQPrinterInfoPrivate; *this = src; } QPrinterInfo::QPrinterInfo(const QPrinter& prn) + : d_ptr(&nullQPrinterInfoPrivate) { - d_ptr = &nullQPrinterInfoPrivate; QList list = availablePrinters(); for (int c = 0; c < list.size(); ++c) { if (prn.printerName() == list[c].printerName()) { @@ -187,16 +203,12 @@ QPrinterInfo::QPrinterInfo(const QPrinter& prn) QPrinterInfo::~QPrinterInfo() { - if (d_ptr != &nullQPrinterInfoPrivate) - delete d_ptr; } QPrinterInfo& QPrinterInfo::operator=(const QPrinterInfo& src) { Q_ASSERT(d_ptr); - if (d_ptr != &nullQPrinterInfoPrivate) - delete d_ptr; - d_ptr = new QPrinterInfoPrivate(*src.d_ptr); + d_ptr.reset(new QPrinterInfoPrivate(*src.d_ptr)); d_ptr->q_ptr = this; return *this; } diff --git a/src/gui/painting/qrasterizer.cpp b/src/gui/painting/qrasterizer.cpp index 583885c..3c06bb4 100644 --- a/src/gui/painting/qrasterizer.cpp +++ b/src/gui/painting/qrasterizer.cpp @@ -436,8 +436,11 @@ void QScanConverter::end() inline void QScanConverter::allocate(int size) { if (m_alloc < size) { - m_alloc = qMax(size, 2 * m_alloc); - m_intersections = (Intersection *)realloc(m_intersections, m_alloc * sizeof(Intersection)); + int newAlloc = qMax(size, 2 * m_alloc); + Intersection *newIntersections = (Intersection *)realloc(m_intersections, newAlloc * sizeof(Intersection)); + Q_CHECK_PTR(newIntersections); + m_alloc = newAlloc; + m_intersections = newIntersections; } } diff --git a/src/gui/painting/qregion.cpp b/src/gui/painting/qregion.cpp index c88af7c..65964de 100644 --- a/src/gui/painting/qregion.cpp +++ b/src/gui/painting/qregion.cpp @@ -3167,6 +3167,7 @@ static void InsertEdgeInET(EdgeTable *ET, EdgeTableEntry *ETE, int scanline, { tmpSLLBlock = (ScanLineListBlock *)malloc(sizeof(ScanLineListBlock)); + Q_CHECK_PTR(tmpSLLBlock); (*SLLBlock)->next = tmpSLLBlock; tmpSLLBlock->next = (ScanLineListBlock *)NULL; *SLLBlock = tmpSLLBlock; @@ -3553,6 +3554,8 @@ static void PtsToRegion(register int numFullPtBlocks, register int iCurPtBlock, * Scan converts a polygon by returning a run-length * encoding of the resultant bitmap -- the run-length * encoding is in the form of an array of rectangles. + * + * Can return 0 in case of errors. */ static QRegionPrivate *PolygonRegion(const QPoint *Pts, int Count, int rule) //Point *Pts; /* the pts */ @@ -3624,75 +3627,28 @@ static QRegionPrivate *PolygonRegion(const QPoint *Pts, int Count, int rule) } - if (rule == EvenOddRule) { - /* - * for each scanline - */ - for (y = ET.ymin; y < ET.ymax; ++y) { - - /* - * Add a new edge to the active edge table when we - * get to the next edge. - */ - if (pSLL && y == pSLL->scanline) { - loadAET(&AET, pSLL->edgelist); - pSLL = pSLL->next; - } - pPrevAET = &AET; - pAET = AET.next; - + QT_TRY { + if (rule == EvenOddRule) { /* - * for each active edge + * for each scanline */ - while (pAET) { - pts->setX(pAET->bres.minor_axis); - pts->setY(y); - ++pts; - ++iPts; + for (y = ET.ymin; y < ET.ymax; ++y) { /* - * send out the buffer + * Add a new edge to the active edge table when we + * get to the next edge. */ - if (iPts == NUMPTSTOBUFFER) { - tmpPtBlock = (POINTBLOCK *)malloc(sizeof(POINTBLOCK)); - tmpPtBlock->pts = reinterpret_cast(tmpPtBlock->data); - curPtBlock->next = tmpPtBlock; - curPtBlock = tmpPtBlock; - pts = curPtBlock->pts; - ++numFullPtBlocks; - iPts = 0; + if (pSLL && y == pSLL->scanline) { + loadAET(&AET, pSLL->edgelist); + pSLL = pSLL->next; } - EVALUATEEDGEEVENODD(pAET, pPrevAET, y) - } - InsertionSort(&AET); - } - } else { - /* - * for each scanline - */ - for (y = ET.ymin; y < ET.ymax; ++y) { - /* - * Add a new edge to the active edge table when we - * get to the next edge. - */ - if (pSLL && y == pSLL->scanline) { - loadAET(&AET, pSLL->edgelist); - computeWAET(&AET); - pSLL = pSLL->next; - } - pPrevAET = &AET; - pAET = AET.next; - pWETE = pAET; + pPrevAET = &AET; + pAET = AET.next; - /* - * for each active edge - */ - while (pAET) { /* - * add to the buffer only those edges that - * are in the Winding active edge table. + * for each active edge */ - if (pWETE == pAET) { + while (pAET) { pts->setX(pAET->bres.minor_axis); pts->setY(y); ++pts; @@ -3702,7 +3658,8 @@ static QRegionPrivate *PolygonRegion(const QPoint *Pts, int Count, int rule) * send out the buffer */ if (iPts == NUMPTSTOBUFFER) { - tmpPtBlock = static_cast(malloc(sizeof(POINTBLOCK))); + tmpPtBlock = (POINTBLOCK *)malloc(sizeof(POINTBLOCK)); + Q_CHECK_PTR(tmpPtBlock); tmpPtBlock->pts = reinterpret_cast(tmpPtBlock->data); curPtBlock->next = tmpPtBlock; curPtBlock = tmpPtBlock; @@ -3710,21 +3667,81 @@ static QRegionPrivate *PolygonRegion(const QPoint *Pts, int Count, int rule) ++numFullPtBlocks; iPts = 0; } - pWETE = pWETE->nextWETE; + EVALUATEEDGEEVENODD(pAET, pPrevAET, y) } - EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET) + InsertionSort(&AET); } - + } else { /* - * recompute the winding active edge table if - * we just resorted or have exited an edge. + * for each scanline */ - if (InsertionSort(&AET) || fixWAET) { - computeWAET(&AET); - fixWAET = false; + for (y = ET.ymin; y < ET.ymax; ++y) { + /* + * Add a new edge to the active edge table when we + * get to the next edge. + */ + if (pSLL && y == pSLL->scanline) { + loadAET(&AET, pSLL->edgelist); + computeWAET(&AET); + pSLL = pSLL->next; + } + pPrevAET = &AET; + pAET = AET.next; + pWETE = pAET; + + /* + * for each active edge + */ + while (pAET) { + /* + * add to the buffer only those edges that + * are in the Winding active edge table. + */ + if (pWETE == pAET) { + pts->setX(pAET->bres.minor_axis); + pts->setY(y); + ++pts; + ++iPts; + + /* + * send out the buffer + */ + if (iPts == NUMPTSTOBUFFER) { + tmpPtBlock = static_cast(malloc(sizeof(POINTBLOCK))); + tmpPtBlock->pts = reinterpret_cast(tmpPtBlock->data); + curPtBlock->next = tmpPtBlock; + curPtBlock = tmpPtBlock; + pts = curPtBlock->pts; + ++numFullPtBlocks; + iPts = 0; + } + pWETE = pWETE->nextWETE; + } + EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET) + } + + /* + * recompute the winding active edge table if + * we just resorted or have exited an edge. + */ + if (InsertionSort(&AET) || fixWAET) { + computeWAET(&AET); + fixWAET = false; + } } } + } QT_CATCH(...) { + FreeStorage(SLLBlock.next); + PtsToRegion(numFullPtBlocks, iPts, &FirstPtBlock, region); + for (curPtBlock = FirstPtBlock.next; --numFullPtBlocks >= 0;) { + tmpPtBlock = curPtBlock->next; + free(curPtBlock); + curPtBlock = tmpPtBlock; + } + free(pETEs); + return 0; // this function returns 0 in case of an error } + FreeStorage(SLLBlock.next); PtsToRegion(numFullPtBlocks, iPts, &FirstPtBlock, region); for (curPtBlock = FirstPtBlock.next; --numFullPtBlocks >= 0;) { @@ -3923,11 +3940,10 @@ QRegion &QRegion::operator=(const QRegion &r) /*! \internal */ - QRegion QRegion::copy() const { QRegion r; - QRegionData *x = new QRegionData; + QScopedPointer x(new QRegionData); x->ref = 1; #if defined(Q_WS_X11) x->rgn = 0; @@ -3941,7 +3957,7 @@ QRegion QRegion::copy() const x->qt_rgn = new QRegionPrivate; if (!r.d->ref.deref()) cleanUp(r.d); - r.d = x; + r.d = x.take(); return r; } diff --git a/src/gui/painting/qwindowsurface_raster.cpp b/src/gui/painting/qwindowsurface_raster.cpp index 0a6a04e..97178a6 100644 --- a/src/gui/painting/qwindowsurface_raster.cpp +++ b/src/gui/painting/qwindowsurface_raster.cpp @@ -115,8 +115,6 @@ QRasterWindowSurface::~QRasterWindowSurface() #endif if (d_ptr->image) delete d_ptr->image; - - delete d_ptr; } diff --git a/src/gui/painting/qwindowsurface_raster_p.h b/src/gui/painting/qwindowsurface_raster_p.h index 2a3535f..c10bec3 100644 --- a/src/gui/painting/qwindowsurface_raster_p.h +++ b/src/gui/painting/qwindowsurface_raster_p.h @@ -112,7 +112,7 @@ public: private: void prepareBuffer(QImage::Format format, QWidget *widget); Q_DECLARE_PRIVATE(QRasterWindowSurface) - QRasterWindowSurfacePrivate *d_ptr; + QScopedPointer d_ptr; }; QT_END_NAMESPACE diff --git a/src/gui/styles/qs60style.h b/src/gui/styles/qs60style.h index 21cdd1c..d8e9a40 100644 --- a/src/gui/styles/qs60style.h +++ b/src/gui/styles/qs60style.h @@ -90,12 +90,12 @@ public: #endif // !Q_WS_S60 #ifdef Q_WS_S60 -public slots: +public Q_SLOTS: void handleDynamicLayoutVariantSwitch(); void handleSkinChange(); #endif // Q_WS_S60 -protected slots: +protected Q_SLOTS: QIcon standardIconImplementation( StandardPixmap standardIcon, const QStyleOption * option = 0, const QWidget * widget = 0 ) const; diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp index dd50d12..e324db6 100644 --- a/src/gui/text/qfont.cpp +++ b/src/gui/text/qfont.cpp @@ -314,7 +314,7 @@ QFontPrivate *QFontPrivate::smallCapsFontPrivate() const font.setPointSizeF(pointSize * .7); else font.setPixelSize((font.pixelSize() * 7 + 5) / 10); - scFont = font.d; + scFont = font.d.data(); if (scFont != this) scFont->ref.ref(); return scFont; @@ -721,12 +721,11 @@ QFont::QFont(const QFont &font, QPaintDevice *pd) const int screen = 0; #endif if (font.d->dpi != dpi || font.d->screen != screen ) { - d = new QFontPrivate(*font.d); + d.reset(new QFontPrivate(*font.d)); d->dpi = dpi; d->screen = screen; } else { - d = font.d; - d->ref.ref(); + d.assign(font.d.data()); } #ifdef Q_WS_WIN if (pd->devType() == QInternal::Printer && pd->getDC()) @@ -740,8 +739,7 @@ QFont::QFont(const QFont &font, QPaintDevice *pd) QFont::QFont(QFontPrivate *data) : resolve_mask(QFont::AllPropertiesResolved) { - d = data; - d->ref.ref(); + d.assign(data); } /*! \internal @@ -753,13 +751,13 @@ void QFont::detach() if (d->engineData) d->engineData->ref.deref(); d->engineData = 0; - if (d->scFont && d->scFont != d) + if (d->scFont && d->scFont != d.data()) d->scFont->ref.deref(); d->scFont = 0; return; } - qAtomicDetach(d); + d.detach(); } /*! @@ -768,9 +766,9 @@ void QFont::detach() \sa QApplication::setFont(), QApplication::font() */ QFont::QFont() - :d(QApplication::font().d), resolve_mask(0) + :resolve_mask(0) { - d->ref.ref(); + d.assign(QApplication::font().d.data()); } /*! @@ -790,8 +788,8 @@ QFont::QFont() setStyleHint() QApplication::font() */ QFont::QFont(const QString &family, int pointSize, int weight, bool italic) - :d(new QFontPrivate) { + d.reset(new QFontPrivate()); resolve_mask = QFont::FamilyResolved; if (pointSize <= 0) { @@ -822,8 +820,7 @@ QFont::QFont(const QString &family, int pointSize, int weight, bool italic) */ QFont::QFont(const QFont &font) { - d = font.d; - d->ref.ref(); + d.assign(font.d.data()); resolve_mask = font.resolve_mask; } @@ -832,8 +829,6 @@ QFont::QFont(const QFont &font) */ QFont::~QFont() { - if (!d->ref.deref()) - delete d; } /*! @@ -841,7 +836,7 @@ QFont::~QFont() */ QFont &QFont::operator=(const QFont &font) { - qAtomicAssign(d, font.d); + d.assign(font.d.data()); resolve_mask = font.resolve_mask; return *this; } @@ -1724,7 +1719,7 @@ QFont QFont::resolve(const QFont &other) const QFont font(*this); font.detach(); - font.d->resolve(resolve_mask, other.d); + font.d->resolve(resolve_mask, other.d.data()); return font; } @@ -2177,11 +2172,11 @@ QDataStream &operator<<(QDataStream &s, const QFont &font) s << (quint8) font.d->request.styleStrategy; s << (quint8) 0 << (quint8) font.d->request.weight - << get_font_bits(s.version(), font.d); + << get_font_bits(s.version(), font.d.data()); if (s.version() >= QDataStream::Qt_4_3) s << (quint16)font.d->request.stretch; if (s.version() >= QDataStream::Qt_4_4) - s << get_extended_font_bits(font.d); + s << get_extended_font_bits(font.d.data()); if (s.version() >= QDataStream::Qt_4_5) { s << font.d->letterSpacing.value(); s << font.d->wordSpacing.value(); @@ -2200,10 +2195,8 @@ QDataStream &operator<<(QDataStream &s, const QFont &font) */ QDataStream &operator>>(QDataStream &s, QFont &font) { - if (!font.d->ref.deref()) - delete font.d; - - font.d = new QFontPrivate; + font.d.assign(0); + font.d.reset(new QFontPrivate); font.resolve_mask = QFont::AllPropertiesResolved; quint8 styleHint, styleStrategy = QFont::PreferDefault, charSet, weight, bits; @@ -2244,7 +2237,7 @@ QDataStream &operator>>(QDataStream &s, QFont &font) font.d->request.styleStrategy = styleStrategy; font.d->request.weight = weight; - set_font_bits(s.version(), bits, font.d); + set_font_bits(s.version(), bits, font.d.data()); if (s.version() >= QDataStream::Qt_4_3) { quint16 stretch; @@ -2255,7 +2248,7 @@ QDataStream &operator>>(QDataStream &s, QFont &font) if (s.version() >= QDataStream::Qt_4_4) { quint8 extendedBits; s >> extendedBits; - set_extended_font_bits(extendedBits, font.d); + set_extended_font_bits(extendedBits, font.d.data()); } if (s.version() >= QDataStream::Qt_4_5) { int value; @@ -2337,7 +2330,7 @@ QDataStream &operator>>(QDataStream &s, QFont &font) that is not screen-compatible. */ QFontInfo::QFontInfo(const QFont &font) - : d(font.d) + : d(font.d.data()) { d->ref.ref(); } /*! @@ -2610,7 +2603,14 @@ QFontCache *QFontCache::instance() void QFontCache::cleanup() { - theFontCache()->setLocalData(0); + QThreadStorage *cache = 0; + QT_TRY { + cache = theFontCache(); + } QT_CATCH (const std::bad_alloc &) { + // no cache - just ignore + } + if (cache && cache->hasLocalData()) + cache->setLocalData(0); } #endif // QT_NO_THREAD @@ -2623,8 +2623,8 @@ QFontCache::QFontCache() QFontCache::~QFontCache() { { - EngineDataCache::Iterator it = engineDataCache.begin(), - end = engineDataCache.end(); + EngineDataCache::ConstIterator it = engineDataCache.constBegin(), + end = engineDataCache.constEnd(); while (it != end) { if (it.value()->ref == 0) delete it.value(); @@ -2634,8 +2634,8 @@ QFontCache::~QFontCache() ++it; } } - EngineCache::Iterator it = engineCache.begin(), - end = engineCache.end(); + EngineCache::ConstIterator it = engineCache.constBegin(), + end = engineCache.constEnd(); while (it != end) { if (--it.value().data->cache_count == 0) { if (it.value().data->ref == 0) { diff --git a/src/gui/text/qfont.h b/src/gui/text/qfont.h index eec83b5..a513b7a 100644 --- a/src/gui/text/qfont.h +++ b/src/gui/text/qfont.h @@ -44,6 +44,7 @@ #include #include +#include #if defined(Q_WS_X11) || defined(Q_WS_QWS) typedef struct FT_FaceRec_* FT_Face; @@ -312,7 +313,7 @@ private: friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &); #endif - QFontPrivate *d; + QScopedSharedPointer d; uint resolve_mask; }; diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index 9426fef..416017d 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -167,10 +167,13 @@ QtFontEncoding *QtFontSize::encodingID(int id, uint xpoint, uint xres, if (!add) return 0; - if (!(count % 4)) - encodings = (QtFontEncoding *) + if (!(count % 4)) { + QtFontEncoding *newEncodings = (QtFontEncoding *) realloc(encodings, (((count+4) >> 2) << 2) * sizeof(QtFontEncoding)); + Q_CHECK_PTR(newEncodings); + encodings = newEncodings; + } encodings[count].encoding = id; encodings[count].xpoint = xpoint; encodings[count].xres = xres; @@ -274,10 +277,13 @@ QtFontSize *QtFontStyle::pixelSize(unsigned short size, bool add) if (!add) return 0; - if (!(count % 8)) - pixelSizes = (QtFontSize *) + if (!(count % 8)) { + QtFontSize *newPixelSizes = (QtFontSize *) realloc(pixelSizes, (((count+8) >> 3) << 3) * sizeof(QtFontSize)); + Q_CHECK_PTR(newPixelSizes); + pixelSizes = newPixelSizes; + } pixelSizes[count].pixelSize = size; #ifdef Q_WS_X11 pixelSizes[count].count = 0; @@ -328,12 +334,16 @@ QtFontStyle *QtFontFoundry::style(const QtFontStyle::Key &key, bool create) return 0; // qDebug("adding key (weight=%d, style=%d, oblique=%d stretch=%d) at %d", key.weight, key.style, key.oblique, key.stretch, pos); - if (!(count % 8)) - styles = (QtFontStyle **) + if (!(count % 8)) { + QtFontStyle **newStyles = (QtFontStyle **) realloc(styles, (((count+8) >> 3) << 3) * sizeof(QtFontStyle *)); + Q_CHECK_PTR(newStyles); + styles = newStyles; + } + QtFontStyle *style = new QtFontStyle(key); memmove(styles + pos + 1, styles + pos, (count-pos)*sizeof(QtFontStyle *)); - styles[pos] = new QtFontStyle(key); + styles[pos] = style; count++; return styles[pos]; } @@ -438,10 +448,13 @@ QtFontFoundry *QtFontFamily::foundry(const QString &f, bool create) if (!create) return 0; - if (!(count % 8)) - foundries = (QtFontFoundry **) + if (!(count % 8)) { + QtFontFoundry **newFoundries = (QtFontFoundry **) realloc(foundries, (((count+8) >> 3) << 3) * sizeof(QtFontFoundry *)); + Q_CHECK_PTR(newFoundries); + foundries = newFoundries; + } foundries[count] = new QtFontFoundry(f); return foundries[count++]; @@ -684,13 +697,17 @@ QtFontFamily *QFontDatabasePrivate::family(const QString &f, bool create) pos++; // qDebug("adding family %s at %d total=%d", f.latin1(), pos, count); - if (!(count % 8)) - families = (QtFontFamily **) + if (!(count % 8)) { + QtFontFamily **newFamilies = (QtFontFamily **) realloc(families, (((count+8) >> 3) << 3) * sizeof(QtFontFamily *)); + Q_CHECK_PTR(newFamilies); + families = newFamilies; + } + QtFontFamily *family = new QtFontFamily(f); memmove(families + pos + 1, families + pos, (count-pos)*sizeof(QtFontFamily *)); - families[pos] = new QtFontFamily(f); + families[pos] = family; count++; return families[pos]; } diff --git a/src/gui/text/qfontdatabase_qws.cpp b/src/gui/text/qfontdatabase_qws.cpp index 33b0728..978ff8e 100644 --- a/src/gui/text/qfontdatabase_qws.cpp +++ b/src/gui/text/qfontdatabase_qws.cpp @@ -566,8 +566,8 @@ QFontEngine *loadSingleEngine(int script, const QFontPrivate *fp, QFontEngineQPF *fe = new QFontEngineQPF(request, res.data(), res.size()); if (fe->isValid()) return fe; - qDebug() << "fontengine is not valid! " << size->fileName; delete fe; + qDebug() << "fontengine is not valid! " << size->fileName; } else { qDebug() << "Resource not valid" << size->fileName; } @@ -577,8 +577,8 @@ QFontEngine *loadSingleEngine(int script, const QFontPrivate *fp, QFontEngineQPF *fe = new QFontEngineQPF(request, f); if (fe->isValid()) return fe; - qDebug() << "fontengine is not valid!"; delete fe; // will close f + qDebug() << "fontengine is not valid!"; } #endif } else @@ -592,70 +592,67 @@ QFontEngine *loadSingleEngine(int script, const QFontPrivate *fp, static bool dontShareFonts = !qgetenv("QWS_NO_SHARE_FONTS").isEmpty(); bool shareFonts = !dontShareFonts; - QFontEngine *engine = 0; + QScopedPointer engine; #ifndef QT_NO_LIBRARY QFontEngineFactoryInterface *factory = qobject_cast(loader()->instance(foundry->name)); - if (factory) { - QFontEngineInfo info; - info.setFamily(request.family); - info.setPixelSize(request.pixelSize); - info.setStyle(QFont::Style(request.style)); - info.setWeight(request.weight); - // #### antialiased - - QAbstractFontEngine *customEngine = factory->create(info); - if (customEngine) { - engine = new QProxyFontEngine(customEngine, def); - - if (shareFonts) { - QVariant hint = customEngine->fontProperty(QAbstractFontEngine::CacheGlyphsHint); - if (hint.isValid()) - shareFonts = hint.toBool(); - else - shareFonts = (pixelSize < 64); - } + if (factory) { + QFontEngineInfo info; + info.setFamily(request.family); + info.setPixelSize(request.pixelSize); + info.setStyle(QFont::Style(request.style)); + info.setWeight(request.weight); + // #### antialiased + + QAbstractFontEngine *customEngine = factory->create(info); + if (customEngine) { + engine.reset(new QProxyFontEngine(customEngine, def)); + + if (shareFonts) { + QVariant hint = customEngine->fontProperty(QAbstractFontEngine::CacheGlyphsHint); + if (hint.isValid()) + shareFonts = hint.toBool(); + else + shareFonts = (pixelSize < 64); } + } } #endif // QT_NO_LIBRARY - if (!engine && !file.isEmpty() && QFile::exists(file) || privateDb()->isApplicationFont(file)) { + if ((engine.isNull() && !file.isEmpty() && QFile::exists(file)) || privateDb()->isApplicationFont(file)) { QFontEngine::FaceId faceId; faceId.filename = file.toLocal8Bit(); faceId.index = size->fileIndex; #ifndef QT_NO_FREETYPE - QFontEngineFT *fte = new QFontEngineFT(def); + QScopedPointer fte(new QFontEngineFT(def)); if (fte->init(faceId, style->antialiased, style->antialiased ? QFontEngineFT::Format_A8 : QFontEngineFT::Format_Mono)) { #ifdef QT_NO_QWS_QPF2 - return fte; + return fte.take(); #else - engine = fte; // try to distinguish between bdf and ttf fonts we can pre-render // and don't try to share outline fonts shareFonts = shareFonts && !fte->defaultGlyphs()->outline_drawing && !fte->getSfntTable(MAKE_TAG('h', 'e', 'a', 'd')).isEmpty(); + engine.reset(fte.take()); #endif - } else { - delete fte; } #endif // QT_NO_FREETYPE } - if (engine) { + if (!engine.isNull()) { #if !defined(QT_NO_QWS_QPF2) && !defined(QT_FONTS_ARE_RESOURCES) if (shareFonts) { - QFontEngineQPF *fe = new QFontEngineQPF(def, -1, engine); - engine = 0; + QScopedPointer fe(new QFontEngineQPF(def, -1, engine.data())); + engine.take(); if (fe->isValid()) - return fe; + return fe.take(); qWarning("Initializing QFontEngineQPF failed for %s", qPrintable(file)); - engine = fe->takeRenderingEngine(); - delete fe; + engine.reset(fe->takeRenderingEngine()); } #endif - return engine; + return engine.take(); } } else { @@ -682,20 +679,22 @@ QFontEngine *loadEngine(int script, const QFontPrivate *fp, QtFontFamily *family, QtFontFoundry *foundry, QtFontStyle *style, QtFontSize *size) { - QFontEngine *fe = loadSingleEngine(script, fp, request, family, foundry, - style, size); - if (fe + QScopedPointer engine(loadSingleEngine(script, fp, request, family, foundry, + style, size)); + if (!engine.isNull() && script == QUnicodeTables::Common - && !(request.styleStrategy & QFont::NoFontMerging) && !fe->symbol) { + && !(request.styleStrategy & QFont::NoFontMerging) && !engine->symbol) { QStringList fallbacks = privateDb()->fallbackFamilies; if (family && !family->fallbackFamilies.isEmpty()) fallbacks = family->fallbackFamilies; - fe = new QFontEngineMultiQWS(fe, script, fallbacks); + QFontEngine *fe = new QFontEngineMultiQWS(engine.data(), script, fallbacks); + engine.take(); + engine.reset(fe); } - return fe; + return engine.take(); } static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt) diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp index c2c23ee..2f96984 100644 --- a/src/gui/text/qfontengine.cpp +++ b/src/gui/text/qfontengine.cpp @@ -191,18 +191,20 @@ QFontEngine::QFontEngine() QFontEngine::~QFontEngine() { - for (GlyphPointerHash::iterator it = m_glyphPointerHash.begin(), end = m_glyphPointerHash.end(); - it != end; ++it) { - for (QList::iterator it2 = it.value().begin(), end2 = it.value().end(); - it2 != end2; ++it2) - delete *it2; + for (GlyphPointerHash::const_iterator it = m_glyphPointerHash.constBegin(), + end = m_glyphPointerHash.constEnd(); it != end; ++it) { + for (QList::const_iterator it2 = it.value().constBegin(), + end2 = it.value().constEnd(); it2 != end2; ++it2) { + delete *it2; + } } m_glyphPointerHash.clear(); - for (GlyphIntHash::iterator it = m_glyphIntHash.begin(), end = m_glyphIntHash.end(); - it != end; ++it) { - for (QList::iterator it2 = it.value().begin(), end2 = it.value().end(); - it2 != end2; ++it2) - delete *it2; + for (GlyphIntHash::const_iterator it = m_glyphIntHash.constBegin(), + end = m_glyphIntHash.constEnd(); it != end; ++it) { + for (QList::const_iterator it2 = it.value().constBegin(), + end2 = it.value().constEnd(); it2 != end2; ++it2) { + delete *it2; + } } m_glyphIntHash.clear(); qHBFreeFace(hbFace); diff --git a/src/gui/text/qfontengine_ft.cpp b/src/gui/text/qfontengine_ft.cpp index 6f5ee1f..f1dac96 100644 --- a/src/gui/text/qfontengine_ft.cpp +++ b/src/gui/text/qfontengine_ft.cpp @@ -193,6 +193,9 @@ HB_Error QFreetypeFace::getPointInOutline(HB_Glyph glyph, int flags, hb_uint32 p /* * One font file can contain more than one font (bold/italic for example) * find the right one and return it. + * + * Returns the freetype face or 0 in case of an empty file or any other problems + * (like not being able to open the file) */ QFreetypeFace *QFreetypeFace::getFace(const QFontEngine::FaceId &face_id) { @@ -205,7 +208,7 @@ QFreetypeFace *QFreetypeFace::getFace(const QFontEngine::FaceId &face_id) QFreetypeFace *freetype = freetypeData->faces.value(face_id, 0); if (!freetype) { - freetype = new QFreetypeFace; + QScopedPointer newFreetype(new QFreetypeFace); FT_Face face; QFile file(QString::fromUtf8(face_id.filename)); if (face_id.filename.startsWith(":qmemoryfonts/")) { @@ -214,84 +217,82 @@ QFreetypeFace *QFreetypeFace::getFace(const QFontEngine::FaceId &face_id) QByteArray idx = face_id.filename; idx.remove(0, 14); // remove ':qmemoryfonts/' bool ok = false; - freetype->fontData = qt_fontdata_from_index(idx.toInt(&ok)); + newFreetype->fontData = qt_fontdata_from_index(idx.toInt(&ok)); if (!ok) - freetype->fontData = QByteArray(); + newFreetype->fontData = QByteArray(); } else if (!(file.fileEngine()->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::LocalDiskFlag)) { if (!file.open(QIODevice::ReadOnly)) { - delete freetype; return 0; } - freetype->fontData = file.readAll(); + newFreetype->fontData = file.readAll(); } - if (!freetype->fontData.isEmpty()) { - if (FT_New_Memory_Face(freetypeData->library, (const FT_Byte *)freetype->fontData.constData(), freetype->fontData.size(), face_id.index, &face)) { - delete freetype; + if (!newFreetype->fontData.isEmpty()) { + if (FT_New_Memory_Face(freetypeData->library, (const FT_Byte *)newFreetype->fontData.constData(), newFreetype->fontData.size(), face_id.index, &face)) { return 0; } } else if (FT_New_Face(freetypeData->library, face_id.filename, face_id.index, &face)) { - delete freetype; return 0; } - freetype->face = face; - - freetype->hbFace = qHBNewFace(face, hb_getSFntTable); - freetype->ref = 0; - freetype->xsize = 0; - freetype->ysize = 0; - freetype->matrix.xx = 0x10000; - freetype->matrix.yy = 0x10000; - freetype->matrix.xy = 0; - freetype->matrix.yx = 0; - freetype->unicode_map = 0; - freetype->symbol_map = 0; + newFreetype->face = face; + + newFreetype->hbFace = qHBNewFace(face, hb_getSFntTable); + newFreetype->ref = 0; + newFreetype->xsize = 0; + newFreetype->ysize = 0; + newFreetype->matrix.xx = 0x10000; + newFreetype->matrix.yy = 0x10000; + newFreetype->matrix.xy = 0; + newFreetype->matrix.yx = 0; + newFreetype->unicode_map = 0; + newFreetype->symbol_map = 0; #ifndef QT_NO_FONTCONFIG - freetype->charset = 0; + newFreetype->charset = 0; #endif - memset(freetype->cmapCache, 0, sizeof(freetype->cmapCache)); + memset(newFreetype->cmapCache, 0, sizeof(newFreetype->cmapCache)); - for (int i = 0; i < freetype->face->num_charmaps; ++i) { - FT_CharMap cm = freetype->face->charmaps[i]; + for (int i = 0; i < newFreetype->face->num_charmaps; ++i) { + FT_CharMap cm = newFreetype->face->charmaps[i]; switch(cm->encoding) { case FT_ENCODING_UNICODE: - freetype->unicode_map = cm; + newFreetype->unicode_map = cm; break; case FT_ENCODING_APPLE_ROMAN: case FT_ENCODING_ADOBE_LATIN_1: - if (!freetype->unicode_map || freetype->unicode_map->encoding != FT_ENCODING_UNICODE) - freetype->unicode_map = cm; + if (!newFreetype->unicode_map || newFreetype->unicode_map->encoding != FT_ENCODING_UNICODE) + newFreetype->unicode_map = cm; break; case FT_ENCODING_ADOBE_CUSTOM: case FT_ENCODING_MS_SYMBOL: - if (!freetype->symbol_map) - freetype->symbol_map = cm; + if (!newFreetype->symbol_map) + newFreetype->symbol_map = cm; break; default: break; } } - if (!FT_IS_SCALABLE(freetype->face) && freetype->face->num_fixed_sizes == 1) - FT_Set_Char_Size (face, X_SIZE(freetype->face, 0), Y_SIZE(freetype->face, 0), 0, 0); + if (!FT_IS_SCALABLE(newFreetype->face) && newFreetype->face->num_fixed_sizes == 1) + FT_Set_Char_Size (face, X_SIZE(newFreetype->face, 0), Y_SIZE(newFreetype->face, 0), 0, 0); # if 0 FcChar8 *name; FcPatternGetString(pattern, FC_FAMILY, 0, &name); qDebug("%s: using maps: default: %x unicode: %x, symbol: %x", name, - freetype->face->charmap ? freetype->face->charmap->encoding : 0, - freetype->unicode_map ? freetype->unicode_map->encoding : 0, - freetype->symbol_map ? freetype->symbol_map->encoding : 0); + newFreetype->face->charmap ? newFreetype->face->charmap->encoding : 0, + newFreetype->unicode_map ? newFreetype->unicode_map->encoding : 0, + newFreetype->symbol_map ? newFreetype->symbol_map->encoding : 0); for (int i = 0; i < 256; i += 8) qDebug(" %x: %d %d %d %d %d %d %d %d", i, - FcCharSetHasChar(freetype->charset, i), FcCharSetHasChar(freetype->charset, i), - FcCharSetHasChar(freetype->charset, i), FcCharSetHasChar(freetype->charset, i), - FcCharSetHasChar(freetype->charset, i), FcCharSetHasChar(freetype->charset, i), - FcCharSetHasChar(freetype->charset, i), FcCharSetHasChar(freetype->charset, i)); + FcCharSetHasChar(newFreetype->charset, i), FcCharSetHasChar(newFreetype->charset, i), + FcCharSetHasChar(newFreetype->charset, i), FcCharSetHasChar(newFreetype->charset, i), + FcCharSetHasChar(newFreetype->charset, i), FcCharSetHasChar(newFreetype->charset, i), + FcCharSetHasChar(newFreetype->charset, i), FcCharSetHasChar(newFreetype->charset, i)); #endif - FT_Set_Charmap(freetype->face, freetype->unicode_map); - freetypeData->faces.insert(face_id, freetype); + FT_Set_Charmap(newFreetype->face, newFreetype->unicode_map); + freetypeData->faces.insert(face_id, newFreetype.data()); + freetype = newFreetype.take(); } freetype->ref.ref(); return freetype; @@ -608,6 +609,7 @@ QFontEngineFT::QFontEngineFT(const QFontDef &fd) kerning_pairs_loaded = false; transform = false; antialias = true; + freetype = 0; default_load_flags = 0; default_hint_style = HintNone; subpixelType = Subpixel_None; diff --git a/src/gui/text/qfontengine_ft_p.h b/src/gui/text/qfontengine_ft_p.h index 649d78b..b67895b 100644 --- a/src/gui/text/qfontengine_ft_p.h +++ b/src/gui/text/qfontengine_ft_p.h @@ -119,6 +119,7 @@ struct QFreetypeFace static void addBitmapToPath(FT_GlyphSlot slot, const QFixedPoint &point, QPainterPath *path, bool = false); private: + friend class QScopedPointer; QFreetypeFace() : _lock(QMutex::Recursive) {} ~QFreetypeFace() {} QAtomicInt ref; diff --git a/src/gui/text/qfontengine_qpf.cpp b/src/gui/text/qfontengine_qpf.cpp index e9fcac4..435a102 100644 --- a/src/gui/text/qfontengine_qpf.cpp +++ b/src/gui/text/qfontengine_qpf.cpp @@ -325,21 +325,21 @@ QFontEngineQPF::QFontEngineQPF(const QFontDef &def, int fileDescriptor, QFontEng fileName.replace(QLatin1Char(' '), QLatin1Char('_')); fileName.prepend(qws_fontCacheDir()); - const QByteArray encodedName = QFile::encodeName(fileName); - if (::access(encodedName, F_OK) == 0) { + encodedFileName = QFile::encodeName(fileName); + if (::access(encodedFileName, F_OK) == 0) { #if defined(DEBUG_FONTENGINE) qDebug() << "found existing qpf:" << fileName; #endif - if (::access(encodedName, W_OK | R_OK) == 0) - fd = ::open(encodedName, O_RDWR); - else if (::access(encodedName, R_OK) == 0) - fd = ::open(encodedName, O_RDONLY); + if (::access(encodedFileName, W_OK | R_OK) == 0) + fd = ::open(encodedFileName, O_RDWR); + else if (::access(encodedFileName, R_OK) == 0) + fd = ::open(encodedFileName, O_RDONLY); } else { #if defined(DEBUG_FONTENGINE) qDebug() << "creating qpf on the fly:" << fileName; #endif if (::access(QFile::encodeName(qws_fontCacheDir()), W_OK) == 0) { - fd = ::open(encodedName, O_RDWR | O_EXCL | O_CREAT, 0644); + fd = ::open(encodedFileName, O_RDWR | O_EXCL | O_CREAT, 0644); QBuffer buffer; buffer.open(QIODevice::ReadWrite); @@ -474,15 +474,21 @@ QFontEngineQPF::QFontEngineQPF(const QFontDef &def, int fileDescriptor, QFontEng #endif #if defined(Q_WS_QWS) if (isValid() && renderingFontEngine) - qt_fbdpy->sendFontCommand(QWSFontCommand::StartedUsingFont, QFile::encodeName(fileName)); + qt_fbdpy->sendFontCommand(QWSFontCommand::StartedUsingFont, encodedFileName); #endif } QFontEngineQPF::~QFontEngineQPF() { #if defined(Q_WS_QWS) - if (isValid() && renderingFontEngine) - qt_fbdpy->sendFontCommand(QWSFontCommand::StoppedUsingFont, QFile::encodeName(fileName)); + if (isValid() && renderingFontEngine) { + QT_TRY { + qt_fbdpy->sendFontCommand(QWSFontCommand::StoppedUsingFont, encodedFileName); + } QT_CATCH(...) { + qDebug("QFontEngineQPF::~QFontEngineQPF: Out of memory"); + // ignore. + } + } #endif delete renderingFontEngine; if (fontData) @@ -1128,6 +1134,11 @@ void QPFGenerator::writeTaggedQFixed(QFontEngineQPF::HeaderTag tag, QFixed value #endif // QT_NO_QWS_QPF2 +/* + Creates a new multi qws engine. + + This function takes ownership of the QFontEngine, increasing it's refcount. +*/ QFontEngineMultiQWS::QFontEngineMultiQWS(QFontEngine *fe, int _script, const QStringList &fallbacks) : QFontEngineMulti(fallbacks.size() + 1), fallbackFamilies(fallbacks), script(_script) diff --git a/src/gui/text/qfontengine_qpf_p.h b/src/gui/text/qfontengine_qpf_p.h index a9b87ff..629f5c6 100644 --- a/src/gui/text/qfontengine_qpf_p.h +++ b/src/gui/text/qfontengine_qpf_p.h @@ -243,6 +243,7 @@ private: quint32 glyphDataOffset; quint32 glyphDataSize; QString fileName; + QByteArray encodedFileName; bool readOnly; QFreetypeFace *freetype; diff --git a/src/gui/text/qfontmetrics.cpp b/src/gui/text/qfontmetrics.cpp index 87da628..991fed7 100644 --- a/src/gui/text/qfontmetrics.cpp +++ b/src/gui/text/qfontmetrics.cpp @@ -164,7 +164,7 @@ extern int qt_defaultDpi(); metrics that are compatible with a certain paint device. */ QFontMetrics::QFontMetrics(const QFont &font) - : d(font.d) + : d(font.d.data()) { d->ref.ref(); } @@ -196,7 +196,7 @@ QFontMetrics::QFontMetrics(const QFont &font, QPaintDevice *paintdevice) d->dpi = dpi; d->screen = screen; } else { - d = font.d; + d = font.d.data(); d->ref.ref(); } @@ -1006,7 +1006,7 @@ QFontMetricsF &QFontMetricsF::operator=(const QFontMetrics &other) metrics that are compatible with a certain paint device. */ QFontMetricsF::QFontMetricsF(const QFont &font) - : d(font.d) + : d(font.d.data()) { d->ref.ref(); } @@ -1038,7 +1038,7 @@ QFontMetricsF::QFontMetricsF(const QFont &font, QPaintDevice *paintdevice) d->dpi = dpi; d->screen = screen; } else { - d = font.d; + d = font.d.data(); d->ref.ref(); } diff --git a/src/gui/text/qfragmentmap_p.h b/src/gui/text/qfragmentmap_p.h index 737a717..0f0e0ff 100644 --- a/src/gui/text/qfragmentmap_p.h +++ b/src/gui/text/qfragmentmap_p.h @@ -214,6 +214,7 @@ private: template QFragmentMapData::QFragmentMapData() + : fragments(0) { init(); } @@ -222,6 +223,7 @@ template void QFragmentMapData::init() { fragments = (Fragment *)malloc(64*fragmentSize); + Q_CHECK_PTR(fragments); head->tag = (((quint32)'p') << 24) | (((quint32)'m') << 16) | (((quint32)'a') << 8) | 'p'; //TAG('p', 'm', 'a', 'p'); head->root = 0; head->freelist = 1; @@ -247,7 +249,9 @@ uint QFragmentMapData::createFragment() // need to create some free space uint needed = qAllocMore((freePos+1)*fragmentSize, 0); Q_ASSERT(needed/fragmentSize > head->allocated); - fragments = (Fragment *)realloc(fragments, needed); + Fragment *newFragments = (Fragment *)realloc(fragments, needed); + Q_CHECK_PTR(newFragments); + fragments = newFragments; head->allocated = needed/fragmentSize; F(freePos).right = 0; } @@ -787,6 +791,8 @@ public: QFragmentMap() {} ~QFragmentMap() { + if (!data.fragments) + return; // in case of out-of-memory, we won't have fragments for (Iterator it = begin(); !it.atEnd(); ++it) it.value()->free(); } diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index d41d414..0c55ce5 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -2069,10 +2069,12 @@ void QTextEngine::LayoutData::reallocate(int totalGlyphs) int newAllocated = space_charAttributes + space_glyphs + space_logClusters; Q_ASSERT(newAllocated >= allocated); - void **old_mem = memory; - memory = (void **)::realloc(memory_on_stack ? 0 : old_mem, newAllocated*sizeof(void *)); - if (memory_on_stack && memory) - memcpy(memory, old_mem, allocated*sizeof(void *)); + void **newMem = memory; + newMem = (void **)::realloc(memory_on_stack ? 0 : memory, newAllocated*sizeof(void *)); + Q_CHECK_PTR(newMem); + if (memory_on_stack && newMem) + memcpy(newMem, memory, allocated*sizeof(void *)); + memory = newMem; memory_on_stack = false; void **m = memory; diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index fa624ef..6c67a68 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -367,7 +367,7 @@ QTextLayout::QTextLayout(const QString& text, const QFont &font, QPaintDevice *p QFont f(font); if (paintdevice) f = QFont(font, paintdevice); - d = new QTextEngine((text.isNull() ? (const QString&)QString::fromLatin1("") : text), f.d); + d = new QTextEngine((text.isNull() ? (const QString&)QString::fromLatin1("") : text), f.d.data()); } /*! diff --git a/src/gui/text/qtextoption.cpp b/src/gui/text/qtextoption.cpp index e1b9844..0f24d9b 100644 --- a/src/gui/text/qtextoption.cpp +++ b/src/gui/text/qtextoption.cpp @@ -117,7 +117,13 @@ QTextOption &QTextOption::operator=(const QTextOption &o) { if (this == &o) return *this; - delete d; d = 0; + + QTextOptionPrivate* dNew = 0; + if (o.d) + dNew = new QTextOptionPrivate(*o.d); + delete d; + d = dNew; + align = o.align; wordWrap = o.wordWrap; design = o.design; @@ -125,8 +131,6 @@ QTextOption &QTextOption::operator=(const QTextOption &o) unused = o.unused; f = o.f; tab = o.tab; - if (o.d) - d = new QTextOptionPrivate(*o.d); return *this; } diff --git a/src/gui/text/qtexttable.cpp b/src/gui/text/qtexttable.cpp index 48708c9..edba2c4 100644 --- a/src/gui/text/qtexttable.cpp +++ b/src/gui/text/qtexttable.cpp @@ -432,6 +432,13 @@ void QTextTablePrivate::fragmentRemoved(const QChar &type, uint fragment) QTextFramePrivate::fragmentRemoved(type, fragment); } +/*! + /fn void QTextTablePrivate::update() const + + This function is usually called when the table is "dirty". + It seems to update all kind of table information. + +*/ void QTextTablePrivate::update() const { Q_Q(const QTextTable); @@ -439,7 +446,9 @@ void QTextTablePrivate::update() const nRows = (cells.size() + nCols-1)/nCols; // qDebug(">>>> QTextTablePrivate::update, nRows=%d, nCols=%d", nRows, nCols); - grid = (int *)realloc(grid, nRows*nCols*sizeof(int)); + int* newGrid = (int *)realloc(grid, nRows*nCols*sizeof(int)); + Q_CHECK_PTR(newGrid); + grid = newGrid; memset(grid, 0, nRows*nCols*sizeof(int)); QTextDocumentPrivate *p = pieceTable; @@ -463,7 +472,9 @@ void QTextTablePrivate::update() const cellIndices[i] = cell; if (r + rowspan > nRows) { - grid = (int *)realloc(grid, sizeof(int)*(r + rowspan)*nCols); + newGrid = (int *)realloc(grid, sizeof(int)*(r + rowspan)*nCols); + Q_CHECK_PTR(newGrid); + grid = newGrid; memset(grid + (nRows*nCols), 0, sizeof(int)*(r+rowspan-nRows)*nCols); nRows = r + rowspan; } diff --git a/src/gui/text/qzip.cpp b/src/gui/text/qzip.cpp index c6c2e69..04f081e 100644 --- a/src/gui/text/qzip.cpp +++ b/src/gui/text/qzip.cpp @@ -695,7 +695,7 @@ void QZipWriterPrivate::addEntry(EntryType type, const QString &fileName, const */ QZipReader::QZipReader(const QString &archive, QIODevice::OpenMode mode) { - QFile *f = new QFile(archive); + QScopedPointer f(new QFile(archive)); f->open(mode); QZipReader::Status status; if (f->error() == QFile::NoError) @@ -711,7 +711,8 @@ QZipReader::QZipReader(const QString &archive, QIODevice::OpenMode mode) status = FileError; } - d = new QZipReaderPrivate(f, /*ownDevice=*/true); + d = new QZipReaderPrivate(f.data(), /*ownDevice=*/true); + f.take(); d->status = status; } @@ -969,7 +970,7 @@ void QZipReader::close() */ QZipWriter::QZipWriter(const QString &fileName, QIODevice::OpenMode mode) { - QFile *f = new QFile(fileName); + QScopedPointer f(new QFile(fileName)); f->open(mode); QZipWriter::Status status; if (f->error() == QFile::NoError) @@ -985,7 +986,8 @@ QZipWriter::QZipWriter(const QString &fileName, QIODevice::OpenMode mode) status = QZipWriter::FileError; } - d = new QZipWriterPrivate(f, /*ownDevice=*/true); + d = new QZipWriterPrivate(f.data(), /*ownDevice=*/true); + f.take(); d->status = status; } diff --git a/src/gui/widgets/qabstractscrollarea.cpp b/src/gui/widgets/qabstractscrollarea.cpp index 9886969..1ff56e8 100644 --- a/src/gui/widgets/qabstractscrollarea.cpp +++ b/src/gui/widgets/qabstractscrollarea.cpp @@ -281,8 +281,8 @@ void QAbstractScrollAreaPrivate::init() scrollBarContainers[Qt::Vertical]->setVisible(false); QObject::connect(vbar, SIGNAL(valueChanged(int)), q, SLOT(_q_vslide(int))); QObject::connect(vbar, SIGNAL(rangeChanged(int,int)), q, SLOT(_q_showOrHideScrollBars()), Qt::QueuedConnection); - viewportFilter = new QAbstractScrollAreaFilter(this); - viewport->installEventFilter(viewportFilter); + viewportFilter.reset(new QAbstractScrollAreaFilter(this)); + viewport->installEventFilter(viewportFilter.data()); viewport->setFocusProxy(q); q->setFocusPolicy(Qt::WheelFocus); q->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); @@ -471,7 +471,12 @@ QAbstractScrollArea::QAbstractScrollArea(QAbstractScrollAreaPrivate &dd, QWidget :QFrame(dd, parent) { Q_D(QAbstractScrollArea); - d->init(); + QT_TRY { + d->init(); + } QT_CATCH(...) { + d->viewportFilter.reset(); + QT_RETHROW; + } } /*! @@ -483,7 +488,12 @@ QAbstractScrollArea::QAbstractScrollArea(QWidget *parent) :QFrame(*new QAbstractScrollAreaPrivate, parent) { Q_D(QAbstractScrollArea); - d->init(); + QT_TRY { + d->init(); + } QT_CATCH(...) { + d->viewportFilter.reset(); + QT_RETHROW; + } } @@ -493,7 +503,8 @@ QAbstractScrollArea::QAbstractScrollArea(QWidget *parent) QAbstractScrollArea::~QAbstractScrollArea() { Q_D(QAbstractScrollArea); - delete d->viewportFilter; + // reset it here, otherwise we'll have a dangling pointer in ~QWidget + d->viewportFilter.reset(); } @@ -517,7 +528,7 @@ void QAbstractScrollArea::setViewport(QWidget *widget) d->viewport = widget; d->viewport->setParent(this); d->viewport->setFocusProxy(this); - d->viewport->installEventFilter(d->viewportFilter); + d->viewport->installEventFilter(d->viewportFilter.data()); d->layoutChildren(); if (isVisible()) d->viewport->show(); diff --git a/src/gui/widgets/qabstractscrollarea_p.h b/src/gui/widgets/qabstractscrollarea_p.h index e4c47e9..999bdfc 100644 --- a/src/gui/widgets/qabstractscrollarea_p.h +++ b/src/gui/widgets/qabstractscrollarea_p.h @@ -98,7 +98,7 @@ public: inline bool viewportEvent(QEvent *event) { return q_func()->viewportEvent(event); } - QObject *viewportFilter; + QScopedPointer viewportFilter; }; class QAbstractScrollAreaFilter : public QObject diff --git a/src/gui/widgets/qmacnativewidget_mac.h b/src/gui/widgets/qmacnativewidget_mac.h index 4db65e0..d36d74f 100644 --- a/src/gui/widgets/qmacnativewidget_mac.h +++ b/src/gui/widgets/qmacnativewidget_mac.h @@ -64,7 +64,7 @@ protected: bool event(QEvent *ev); private: - Q_DECLARE_PRIVATE_D(QWidget::d_ptr, QMacNativeWidget) + Q_DECLARE_PRIVATE(QMacNativeWidget) }; QT_END_NAMESPACE diff --git a/src/gui/widgets/qmenu_symbian.cpp b/src/gui/widgets/qmenu_symbian.cpp index 48c2cf6..0e5261c 100644 --- a/src/gui/widgets/qmenu_symbian.cpp +++ b/src/gui/widgets/qmenu_symbian.cpp @@ -149,14 +149,14 @@ static void qt_symbian_insert_action(QSymbianMenuAction* action, QListaction->text()); - HBufC* menuItemText = qt_QString2HBufCNewL(text); + TPtrC menuItemText(qt_QString2TPtrC(text)); if (action->action->menu()) { SymbianMenuItem* menuItem = new SymbianMenuItem(); menuItem->menuItemData.iCascadeId = action->command; menuItem->menuItemData.iCommandId = action->command; menuItem->menuItemData.iFlags = 0; - menuItem->menuItemData.iText = *menuItemText; + menuItem->menuItemData.iText = menuItemText; menuItem->action = action->action; if (action->action->menu()->actions().size() == 0 || !action->action->isEnabled() ) menuItem->menuItemData.iFlags |= EEikMenuItemDimmed; @@ -177,7 +177,7 @@ static void qt_symbian_insert_action(QSymbianMenuAction* action, QListmenuItemData.iCascadeId = 0; menuItem->menuItemData.iCommandId = action->command; menuItem->menuItemData.iFlags = 0; - menuItem->menuItemData.iText = *menuItemText; + menuItem->menuItemData.iText = menuItemText; menuItem->action = action->action; if (!action->action->isEnabled()){ menuItem->menuItemData.iFlags += EEikMenuItemDimmed; @@ -191,7 +191,6 @@ static void qt_symbian_insert_action(QSymbianMenuAction* action, QListappend(menuItem); } - delete menuItemText; } } diff --git a/src/gui/widgets/qmenudata.h b/src/gui/widgets/qmenudata.h index 24d960a..d570f20 100644 --- a/src/gui/widgets/qmenudata.h +++ b/src/gui/widgets/qmenudata.h @@ -67,6 +67,8 @@ private: friend class QMenuBar; void setId(int); void setSignalValue(int); + + Q_DISABLE_COPY(QMenuItem); }; QT_END_NAMESPACE diff --git a/src/gui/widgets/qprintpreviewwidget.cpp b/src/gui/widgets/qprintpreviewwidget.cpp index 16334b8..80c1271 100644 --- a/src/gui/widgets/qprintpreviewwidget.cpp +++ b/src/gui/widgets/qprintpreviewwidget.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qprintpreviewwidget.h" +#include "private/qwidget_p.h" #include #include @@ -170,12 +171,12 @@ protected: } // anonymous namespace -class QPrintPreviewWidgetPrivate +class QPrintPreviewWidgetPrivate : public QWidgetPrivate { Q_DECLARE_PUBLIC(QPrintPreviewWidget) public: - QPrintPreviewWidgetPrivate(QPrintPreviewWidget *q) - : q_ptr(q), scene(0), curPage(1), + QPrintPreviewWidgetPrivate() + : scene(0), curPage(1), viewMode(QPrintPreviewWidget::SinglePageView), zoomMode(QPrintPreviewWidget::FitInView), zoomFactor(1), initialized(false), fitting(true) @@ -194,7 +195,6 @@ public: void setZoomFactor(qreal zoomFactor); int calcCurrentPage(); - QPrintPreviewWidget *q_ptr; GraphicsView *graphicsView; QGraphicsScene *scene; @@ -518,7 +518,7 @@ void QPrintPreviewWidgetPrivate::setZoomFactor(qreal _zoomFactor) \sa QWidget::setWindowFlags() */ QPrintPreviewWidget::QPrintPreviewWidget(QPrinter *printer, QWidget *parent, Qt::WindowFlags flags) - : QWidget(parent, flags), d_ptr(new QPrintPreviewWidgetPrivate(this)) + : QWidget(*new QPrintPreviewWidgetPrivate, parent, flags) { Q_D(QPrintPreviewWidget); d->printer = printer; @@ -534,7 +534,7 @@ QPrintPreviewWidget::QPrintPreviewWidget(QPrinter *printer, QWidget *parent, Qt: preview. */ QPrintPreviewWidget::QPrintPreviewWidget(QWidget *parent, Qt::WindowFlags flags) - : QWidget(parent, flags), d_ptr(new QPrintPreviewWidgetPrivate(this)) + : QWidget(*new QPrintPreviewWidgetPrivate, parent, flags) { Q_D(QPrintPreviewWidget); d->printer = new QPrinter; @@ -551,7 +551,6 @@ QPrintPreviewWidget::~QPrintPreviewWidget() Q_D(QPrintPreviewWidget); if (d->ownPrinter) delete d->printer; - delete d_ptr; } /*! diff --git a/src/gui/widgets/qprintpreviewwidget.h b/src/gui/widgets/qprintpreviewwidget.h index 27110a4..9f7ea6e 100644 --- a/src/gui/widgets/qprintpreviewwidget.h +++ b/src/gui/widgets/qprintpreviewwidget.h @@ -111,7 +111,7 @@ Q_SIGNALS: void previewChanged(); private: - QPrintPreviewWidgetPrivate *d_ptr; + void *dummy; // ### remove in Qt 5.0 Q_PRIVATE_SLOT(d_func(), void _q_fit()) Q_PRIVATE_SLOT(d_func(), void _q_updateCurrentPage()) }; diff --git a/src/network/access/qftp.cpp b/src/network/access/qftp.cpp index 569d2fd..c54c420 100644 --- a/src/network/access/qftp.cpp +++ b/src/network/access/qftp.cpp @@ -314,8 +314,10 @@ void QFtpDTP::connectToHost(const QString & host, quint16 port) { bytesFromSocket.clear(); - if (socket) + if (socket) { delete socket; + socket = 0; + } socket = new QTcpSocket(this); socket->setObjectName(QLatin1String("QFtpDTP Passive state socket")); connect(socket, SIGNAL(connected()), SLOT(socketConnected())); @@ -1658,11 +1660,12 @@ QFtp::QFtp(QObject *parent, const char *name) */ int QFtp::connectToHost(const QString &host, quint16 port) { - d_func()->pi.transferConnectionExtended = true; QStringList cmds; cmds << host; cmds << QString::number((uint)port); - return d_func()->addCommand(new QFtpCommand(ConnectToHost, cmds)); + int id = d_func()->addCommand(new QFtpCommand(ConnectToHost, cmds)); + d_func()->pi.transferConnectionExtended = true; + return id; } /*! @@ -1721,9 +1724,10 @@ int QFtp::close() */ int QFtp::setTransferMode(TransferMode mode) { + int id = d_func()->addCommand(new QFtpCommand(SetTransferMode, QStringList())); d_func()->pi.transferConnectionExtended = true; d_func()->transferMode = mode; - return d_func()->addCommand(new QFtpCommand(SetTransferMode, QStringList())); + return id; } /*! diff --git a/src/network/access/qhttp.cpp b/src/network/access/qhttp.cpp index 30befb3..332c67b 100644 --- a/src/network/access/qhttp.cpp +++ b/src/network/access/qhttp.cpp @@ -624,7 +624,6 @@ QHttpHeader::QHttpHeader(QHttpHeaderPrivate &dd, const QHttpHeader &header) */ QHttpHeader::~QHttpHeader() { - delete d_ptr; } /*! diff --git a/src/network/access/qhttp.h b/src/network/access/qhttp.h index 771176a..d575644 100644 --- a/src/network/access/qhttp.h +++ b/src/network/access/qhttp.h @@ -46,6 +46,7 @@ #include #include #include +#include QT_BEGIN_HEADER @@ -108,7 +109,7 @@ protected: QHttpHeader(QHttpHeaderPrivate &dd, const QString &str = QString()); QHttpHeader(QHttpHeaderPrivate &dd, const QHttpHeader &header); - QHttpHeaderPrivate *d_ptr; + QScopedPointer d_ptr; private: Q_DECLARE_PRIVATE(QHttpHeader) diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index ae518df..cec9c87 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -77,8 +77,10 @@ QHttpNetworkConnectionPrivate::QHttpNetworkConnectionPrivate(const QString &host QHttpNetworkConnectionPrivate::~QHttpNetworkConnectionPrivate() { for (int i = 0; i < channelCount; ++i) { - channels[i].socket->close(); - delete channels[i].socket; + if (channels[i].socket) { + channels[i].socket->close(); + delete channels[i].socket; + } } } diff --git a/src/network/access/qhttpnetworkconnection_p.h b/src/network/access/qhttpnetworkconnection_p.h index 09bd459..0f80bd9 100644 --- a/src/network/access/qhttpnetworkconnection_p.h +++ b/src/network/access/qhttpnetworkconnection_p.h @@ -244,8 +244,8 @@ public: #ifndef QT_NO_OPENSSL bool ignoreSSLErrors; #endif - Channel() :state(IdleState), reply(0), written(0), bytesTotal(0), resendCurrent(false), reconnectAttempts(2), - authMehtod(QAuthenticatorPrivate::None), proxyAuthMehtod(QAuthenticatorPrivate::None) + Channel() : socket(0), state(IdleState), reply(0), written(0), bytesTotal(0), resendCurrent(false), + reconnectAttempts(2), authMehtod(QAuthenticatorPrivate::None), proxyAuthMehtod(QAuthenticatorPrivate::None) #ifndef QT_NO_OPENSSL , ignoreSSLErrors(false) #endif diff --git a/src/network/access/qnetworkaccesshttpbackend.cpp b/src/network/access/qnetworkaccesshttpbackend.cpp index f214699..4874d9d 100644 --- a/src/network/access/qnetworkaccesshttpbackend.cpp +++ b/src/network/access/qnetworkaccesshttpbackend.cpp @@ -605,6 +605,7 @@ void QNetworkAccessHttpBackend::open() QNetworkAccessCache *cache = QNetworkAccessManagerPrivate::getCache(this); if ((http = static_cast(cache->requestEntryNow(cacheKey))) == 0) { // no entry in cache; create an object + //### thiago: can we try/catch/ignore this???? http = new QNetworkAccessHttpBackendCache(url.host(), url.port(), encrypt); #ifndef QT_NO_NETWORKPROXY @@ -732,10 +733,15 @@ void QNetworkAccessHttpBackend::replyFinished() // store the SSL configuration now // once we call finished(), we won't have access to httpReply anymore QSslConfiguration sslConfig = httpReply->sslConfiguration(); - if (pendingSslConfiguration) + if (pendingSslConfiguration) { *pendingSslConfiguration = sslConfig; - else if (!sslConfig.isNull()) - pendingSslConfiguration = new QSslConfiguration(sslConfig); + } else if (!sslConfig.isNull()) { + QT_TRY { + pendingSslConfiguration = new QSslConfiguration(sslConfig); + } QT_CATCH(...) { + qWarning("QNetworkAccess: could not allocate a QSslConfiguration object for a SSL connection."); + } + } #endif finished(); diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index bcbeef1..38e8af9 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -748,8 +748,8 @@ void QNetworkAccessManagerPrivate::createCookieJar() const if (!cookieJarCreated) { // keep the ugly hack in here QNetworkAccessManagerPrivate *that = const_cast(this); - that->cookieJarCreated = true; that->cookieJar = new QNetworkCookieJar(that->q_func()); + that->cookieJarCreated = true; } } diff --git a/src/network/access/qnetworkdiskcache.cpp b/src/network/access/qnetworkdiskcache.cpp index 44a8298..daa2335 100644 --- a/src/network/access/qnetworkdiskcache.cpp +++ b/src/network/access/qnetworkdiskcache.cpp @@ -43,6 +43,7 @@ #include "qnetworkdiskcache.h" #include "qnetworkdiskcache_p.h" +#include "QtCore/qscopedpointer.h" #include #include @@ -180,8 +181,7 @@ QIODevice *QNetworkDiskCache::prepare(const QNetworkCacheMetaData &metaData) break; } } - - QCacheItem *cacheItem = new QCacheItem; + QScopedPointer cacheItem(new QCacheItem); cacheItem->metaData = metaData; QIODevice *device = 0; @@ -190,16 +190,20 @@ QIODevice *QNetworkDiskCache::prepare(const QNetworkCacheMetaData &metaData) device = &(cacheItem->data); } else { QString templateName = d->tmpCacheFileName(); - cacheItem->file = new QTemporaryFile(templateName, &cacheItem->data); - if (!cacheItem->file->open()) { + QT_TRY { + cacheItem->file = new QTemporaryFile(templateName, &cacheItem->data); + } QT_CATCH(...) { + cacheItem->file = 0; + } + if (!cacheItem->file || !cacheItem->file->open()) { qWarning() << "QNetworkDiskCache::prepare() unable to open temporary file"; - delete cacheItem; + cacheItem.reset(); return 0; } cacheItem->writeHeader(cacheItem->file); device = cacheItem->file; } - d->inserting[device] = cacheItem; + d->inserting[device] = cacheItem.take(); return device; } @@ -358,31 +362,28 @@ QIODevice *QNetworkDiskCache::data(const QUrl &url) qDebug() << "QNetworkDiskCache::data()" << url; #endif Q_D(QNetworkDiskCache); - QBuffer *buffer = 0; + QScopedPointer buffer; if (!url.isValid()) - return buffer; + return 0; if (d->lastItem.metaData.url() == url && d->lastItem.data.isOpen()) { - buffer = new QBuffer; + buffer.reset(new QBuffer); buffer->setData(d->lastItem.data.data()); } else { - QFile *file = new QFile(d->cacheFileName(url)); - if (!file->open(QFile::ReadOnly | QIODevice::Unbuffered)) { - delete file; + QScopedPointer file(new QFile(d->cacheFileName(url))); + if (!file->open(QFile::ReadOnly | QIODevice::Unbuffered)) return 0; - } - if (!d->lastItem.read(file, true)) { + + if (!d->lastItem.read(file.data(), true)) { file->close(); remove(url); - delete file; return 0; } if (d->lastItem.data.isOpen()) { // compressed - buffer = new QBuffer; + buffer.reset(new QBuffer); buffer->setData(d->lastItem.data.data()); - delete file; } else { - buffer = new QBuffer; + buffer.reset(new QBuffer); // ### verify that QFile uses the fd size and not the file name qint64 size = file->size() - file->pos(); const uchar *p = 0; @@ -390,16 +391,15 @@ QIODevice *QNetworkDiskCache::data(const QUrl &url) p = file->map(file->pos(), size); #endif if (p) { - file->setParent(buffer); buffer->setData((const char *)p, size); + file.take()->setParent(buffer.data()); } else { buffer->setData(file->readAll()); - delete file; } } } buffer->open(QBuffer::ReadOnly); - return buffer; + return buffer.take(); } /*! diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp index 4f9ea52..2ff561a 100644 --- a/src/network/access/qnetworkrequest.cpp +++ b/src/network/access/qnetworkrequest.cpp @@ -216,10 +216,9 @@ public: url = other.url; #ifndef QT_NO_OPENSSL + sslConfiguration = 0; if (other.sslConfiguration) sslConfiguration = new QSslConfiguration(*other.sslConfiguration); - else - sslConfiguration = 0; #endif } diff --git a/src/network/kernel/qhostaddress.cpp b/src/network/kernel/qhostaddress.cpp index b225c17..a3634ce 100644 --- a/src/network/kernel/qhostaddress.cpp +++ b/src/network/kernel/qhostaddress.cpp @@ -523,7 +523,7 @@ QHostAddress::QHostAddress(const struct sockaddr *sockaddr) Constructs a copy of the given \a address. */ QHostAddress::QHostAddress(const QHostAddress &address) - : d(new QHostAddressPrivate(*address.d)) + : d(new QHostAddressPrivate(*address.d.data())) { } @@ -559,7 +559,6 @@ QHostAddress::QHostAddress(SpecialAddress address) */ QHostAddress::~QHostAddress() { - delete d; } /*! @@ -568,7 +567,7 @@ QHostAddress::~QHostAddress() */ QHostAddress &QHostAddress::operator=(const QHostAddress &address) { - *d = *address.d; + *d.data() = *address.d.data(); return *this; } diff --git a/src/network/kernel/qhostaddress.h b/src/network/kernel/qhostaddress.h index 02a6f97..857b4af 100644 --- a/src/network/kernel/qhostaddress.h +++ b/src/network/kernel/qhostaddress.h @@ -44,6 +44,7 @@ #include #include +#include #include struct sockaddr; @@ -130,7 +131,7 @@ public: static QPair parseSubnet(const QString &subnet); protected: - QHostAddressPrivate *d; + QScopedPointer d; }; inline bool operator ==(QHostAddress::SpecialAddress address1, const QHostAddress &address2) diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp index ca4124d..1858e02 100644 --- a/src/network/kernel/qhostinfo.cpp +++ b/src/network/kernel/qhostinfo.cpp @@ -42,6 +42,7 @@ #include "qhostinfo.h" #include "qhostinfo_p.h" +#include "QtCore/qscopedpointer.h" #include #include #include @@ -165,24 +166,24 @@ int QHostInfo::lookupHost(const QString &name, QObject *receiver, // Support for IDNA QString lookup = QString::fromLatin1(QUrl::toAce(name)); - QHostInfoResult *result = new QHostInfoResult; - result->autoDelete = false; - QObject::connect(result, SIGNAL(resultsReady(QHostInfo)), + QScopedPointer result(new QHostInfoResult); + result.data()->autoDelete = false; + QObject::connect(result.data(), SIGNAL(resultsReady(QHostInfo)), receiver, member); - int id = result->lookupId = theIdCounter.fetchAndAddRelaxed(1); + int id = result.data()->lookupId = theIdCounter.fetchAndAddRelaxed(1); if (lookup.isEmpty()) { QHostInfo info(id); info.setError(QHostInfo::HostNotFound); info.setErrorString(QObject::tr("No host name given")); - QMetaObject::invokeMethod(result, "emitResultsReady", Qt::QueuedConnection, + QMetaObject::invokeMethod(result.data(), "emitResultsReady", Qt::QueuedConnection, Q_ARG(QHostInfo, info)); - result->autoDelete = true; + result.take()->autoDelete = true; return id; } QHostInfoAgent *agent = theAgent(); - agent->addHostName(lookup, result); + agent->addHostName(lookup, result.take()); #if !defined QT_NO_THREAD if (!agent->isRunning()) @@ -327,7 +328,7 @@ QHostInfo::QHostInfo(int id) Constructs a copy of \a other. */ QHostInfo::QHostInfo(const QHostInfo &other) - : d(new QHostInfoPrivate(*other.d)) + : d(new QHostInfoPrivate(*other.d.data())) { } @@ -337,7 +338,7 @@ QHostInfo::QHostInfo(const QHostInfo &other) */ QHostInfo &QHostInfo::operator=(const QHostInfo &other) { - *d = *other.d; + *d.data() = *other.d.data(); return *this; } @@ -346,7 +347,6 @@ QHostInfo &QHostInfo::operator=(const QHostInfo &other) */ QHostInfo::~QHostInfo() { - delete d; } /*! diff --git a/src/network/kernel/qhostinfo.h b/src/network/kernel/qhostinfo.h index 084ec89..c68b111 100644 --- a/src/network/kernel/qhostinfo.h +++ b/src/network/kernel/qhostinfo.h @@ -43,6 +43,7 @@ #define QHOSTINFO_H #include +#include #include QT_BEGIN_HEADER @@ -91,7 +92,7 @@ public: static QString localDomainName(); private: - QHostInfoPrivate *d; + QScopedPointer d; }; QT_END_NAMESPACE diff --git a/src/network/kernel/qhostinfo_unix.cpp b/src/network/kernel/qhostinfo_unix.cpp index 3271deb..f5d7166 100644 --- a/src/network/kernel/qhostinfo_unix.cpp +++ b/src/network/kernel/qhostinfo_unix.cpp @@ -320,6 +320,8 @@ QString QHostInfo::localDomainName() if (local_res_ninit) { // using thread-safe version res_state_ptr state = res_state_ptr(qMalloc(sizeof(*state))); + if (!state) + qBadAlloc(); memset(state, 0, sizeof(*state)); local_res_ninit(state); QString domainName = QUrl::fromAce(state->defdname); diff --git a/src/network/kernel/qnetworkinterface.cpp b/src/network/kernel/qnetworkinterface.cpp index ff3624e..f8fff88 100644 --- a/src/network/kernel/qnetworkinterface.cpp +++ b/src/network/kernel/qnetworkinterface.cpp @@ -170,7 +170,7 @@ QNetworkAddressEntry::QNetworkAddressEntry() object \a other. */ QNetworkAddressEntry::QNetworkAddressEntry(const QNetworkAddressEntry &other) - : d(new QNetworkAddressEntryPrivate(*other.d)) + : d(new QNetworkAddressEntryPrivate(*other.d.data())) { } @@ -179,7 +179,7 @@ QNetworkAddressEntry::QNetworkAddressEntry(const QNetworkAddressEntry &other) */ QNetworkAddressEntry &QNetworkAddressEntry::operator=(const QNetworkAddressEntry &other) { - *d = *other.d; + *d.data() = *other.d.data(); return *this; } @@ -188,7 +188,6 @@ QNetworkAddressEntry &QNetworkAddressEntry::operator=(const QNetworkAddressEntry */ QNetworkAddressEntry::~QNetworkAddressEntry() { - delete d; } /*! diff --git a/src/network/kernel/qnetworkinterface.h b/src/network/kernel/qnetworkinterface.h index 09fbd0f..dd16550 100644 --- a/src/network/kernel/qnetworkinterface.h +++ b/src/network/kernel/qnetworkinterface.h @@ -43,6 +43,7 @@ #define QNETWORKINTERFACE_H #include +#include #include #ifndef QT_NO_NETWORKINTERFACE @@ -79,7 +80,7 @@ public: void setBroadcast(const QHostAddress &newBroadcast); private: - QNetworkAddressEntryPrivate *d; + QScopedPointer d; }; class QNetworkInterfacePrivate; diff --git a/src/network/kernel/qnetworkinterface_win.cpp b/src/network/kernel/qnetworkinterface_win.cpp index de97629..c783c33 100644 --- a/src/network/kernel/qnetworkinterface_win.cpp +++ b/src/network/kernel/qnetworkinterface_win.cpp @@ -115,6 +115,8 @@ static QHash ipv4Netmasks() if (retval == ERROR_BUFFER_OVERFLOW) { // need more memory pAdapter = (IP_ADAPTER_INFO *)qMalloc(bufSize); + if (!pAdapter) + return ipv4netmasks; // try again if (ptrGetAdaptersInfo(pAdapter, &bufSize) != ERROR_SUCCESS) { qFree(pAdapter); @@ -156,7 +158,8 @@ static QList interfaceListingWinXP() if (retval == ERROR_BUFFER_OVERFLOW) { // need more memory pAdapter = (IP_ADAPTER_ADDRESSES *)qMalloc(bufSize); - + if (!pAdapter) + return interfaces; // try again if (ptrGetAdaptersAddresses(AF_UNSPEC, flags, NULL, pAdapter, &bufSize) != ERROR_SUCCESS) { qFree(pAdapter); @@ -236,7 +239,8 @@ static QList interfaceListingWin2k() if (retval == ERROR_BUFFER_OVERFLOW) { // need more memory pAdapter = (IP_ADAPTER_INFO *)qMalloc(bufSize); - + if (!pAdapter) + return interfaces; // try again if (ptrGetAdaptersInfo(pAdapter, &bufSize) != ERROR_SUCCESS) { qFree(pAdapter); @@ -306,7 +310,8 @@ QString QHostInfo::localDomainName() pinfo = &info; if (ptrGetNetworkParams(pinfo, &bufSize) == ERROR_BUFFER_OVERFLOW) { pinfo = (FIXED_INFO *)qMalloc(bufSize); - + if (!pinfo) + return QString(); // try again if (ptrGetNetworkParams(pinfo, &bufSize) != ERROR_SUCCESS) { qFree(pinfo); diff --git a/src/network/socket/qlocalsocket_unix.cpp b/src/network/socket/qlocalsocket_unix.cpp index 9e3cbde..03723cf 100644 --- a/src/network/socket/qlocalsocket_unix.cpp +++ b/src/network/socket/qlocalsocket_unix.cpp @@ -305,7 +305,7 @@ void QLocalSocketPrivate::_q_connectToSocket() case EAGAIN: // Try again later, all of the sockets listening are full if (!delayConnect) { - delayConnect = new QSocketNotifier(connectingSocket, QSocketNotifier::Write); + delayConnect = new QSocketNotifier(connectingSocket, QSocketNotifier::Write, q); q->connect(delayConnect, SIGNAL(activated(int)), q, SLOT(_q_connectToSocket())); } if (!connectTimer) { diff --git a/src/network/socket/qsocks5socketengine.cpp b/src/network/socket/qsocks5socketengine.cpp index b6b0e89..98666c2 100644 --- a/src/network/socket/qsocks5socketengine.cpp +++ b/src/network/socket/qsocks5socketengine.cpp @@ -1834,9 +1834,9 @@ QSocks5SocketEngineHandler::createSocketEngine(QAbstractSocket::SocketType socke QSOCKS5_DEBUG << "not proxying"; return 0; } - QSocks5SocketEngine *engine = new QSocks5SocketEngine(parent); + QScopedPointer engine(new QSocks5SocketEngine(parent)); engine->setProxy(proxy); - return engine; + return engine.take(); } QAbstractSocketEngine *QSocks5SocketEngineHandler::createSocketEngine(int socketDescriptor, QObject *parent) diff --git a/src/network/socket/qtcpserver.cpp b/src/network/socket/qtcpserver.cpp index c1fedc3..1978ee2 100644 --- a/src/network/socket/qtcpserver.cpp +++ b/src/network/socket/qtcpserver.cpp @@ -354,7 +354,12 @@ void QTcpServer::close() if (d->socketEngine) { d->socketEngine->close(); - d->socketEngine->deleteLater(); + QT_TRY { + d->socketEngine->deleteLater(); + } QT_CATCH(const std::bad_alloc &) { + // in out of memory situations, the socketEngine + // will be deleted in ~QTcpServer (it's a child-object of this) + } d->socketEngine = 0; } diff --git a/src/network/ssl/qsslcertificate.cpp b/src/network/ssl/qsslcertificate.cpp index 7b554dc..c4aa43e 100644 --- a/src/network/ssl/qsslcertificate.cpp +++ b/src/network/ssl/qsslcertificate.cpp @@ -155,7 +155,7 @@ QSslCertificate::QSslCertificate(const QByteArray &data, QSsl::EncodingFormat fo /*! Constructs an identical copy of \a other. */ -QSslCertificate::QSslCertificate(const QSslCertificate &other) : d(other.d) +QSslCertificate::QSslCertificate(const QSslCertificate &other) : d(other.d.data()) { d->ref.ref(); } @@ -165,8 +165,6 @@ QSslCertificate::QSslCertificate(const QSslCertificate &other) : d(other.d) */ QSslCertificate::~QSslCertificate() { - if (!d->ref.deref()) - delete d; } /*! @@ -175,7 +173,7 @@ QSslCertificate::~QSslCertificate() */ QSslCertificate &QSslCertificate::operator=(const QSslCertificate &other) { - qAtomicAssign(d, other.d); + d.assign(other.d.data()); return *this; } @@ -241,12 +239,7 @@ void QSslCertificate::clear() { if (isNull()) return; - if (d->ref == 1) - delete d; - else - d->ref.deref(); - - d = new QSslCertificatePrivate; + d.reset(new QSslCertificatePrivate); } /*! diff --git a/src/network/ssl/qsslcertificate.h b/src/network/ssl/qsslcertificate.h index d4597cd..19152fb 100644 --- a/src/network/ssl/qsslcertificate.h +++ b/src/network/ssl/qsslcertificate.h @@ -118,7 +118,7 @@ public: Qt::HANDLE handle() const; private: - QSslCertificatePrivate *d; + QScopedSharedPointer d; friend class QSslCertificatePrivate; friend class QSslSocketBackendPrivate; }; diff --git a/src/network/ssl/qsslcipher.cpp b/src/network/ssl/qsslcipher.cpp index 7fec2df..a72879d 100644 --- a/src/network/ssl/qsslcipher.cpp +++ b/src/network/ssl/qsslcipher.cpp @@ -103,7 +103,7 @@ QSslCipher::QSslCipher(const QString &name, QSsl::SslProtocol protocol) QSslCipher::QSslCipher(const QSslCipher &other) : d(new QSslCipherPrivate) { - *d = *other.d; + *d.data() = *other.d.data(); } /*! @@ -111,7 +111,6 @@ QSslCipher::QSslCipher(const QSslCipher &other) */ QSslCipher::~QSslCipher() { - delete d; } /*! @@ -120,7 +119,7 @@ QSslCipher::~QSslCipher() */ QSslCipher &QSslCipher::operator=(const QSslCipher &other) { - *d = *other.d; + *d.data() = *other.d.data(); return *this; } diff --git a/src/network/ssl/qsslcipher.h b/src/network/ssl/qsslcipher.h index 404dc3d..d9ac7a9 100644 --- a/src/network/ssl/qsslcipher.h +++ b/src/network/ssl/qsslcipher.h @@ -44,6 +44,7 @@ #define QSSLCIPHER_H #include +#include #include QT_BEGIN_HEADER @@ -78,7 +79,7 @@ public: QSsl::SslProtocol protocol() const; private: - QSslCipherPrivate *d; + QScopedPointer d; friend class QSslSocketBackendPrivate; }; diff --git a/src/network/ssl/qsslerror.cpp b/src/network/ssl/qsslerror.cpp index 3096fee..280c659 100644 --- a/src/network/ssl/qsslerror.cpp +++ b/src/network/ssl/qsslerror.cpp @@ -140,7 +140,7 @@ QSslError::QSslError(SslError error, const QSslCertificate &certificate) QSslError::QSslError(const QSslError &other) : d(new QSslErrorPrivate) { - *d = *other.d; + *d.data() = *other.d.data(); } /*! @@ -148,7 +148,6 @@ QSslError::QSslError(const QSslError &other) */ QSslError::~QSslError() { - delete d; } /*! @@ -158,7 +157,7 @@ QSslError::~QSslError() */ QSslError &QSslError::operator=(const QSslError &other) { - *d = *other.d; + *d.data() = *other.d.data(); return *this; } diff --git a/src/network/ssl/qsslerror.h b/src/network/ssl/qsslerror.h index 50cc142..8b8ebff 100644 --- a/src/network/ssl/qsslerror.h +++ b/src/network/ssl/qsslerror.h @@ -105,7 +105,7 @@ public: QSslCertificate certificate() const; private: - QSslErrorPrivate *d; + QScopedPointer d; }; #ifndef QT_NO_DEBUG_STREAM diff --git a/src/network/ssl/qsslkey.cpp b/src/network/ssl/qsslkey.cpp index 8d550c0..d076112 100644 --- a/src/network/ssl/qsslkey.cpp +++ b/src/network/ssl/qsslkey.cpp @@ -269,7 +269,7 @@ QSslKey::QSslKey(QIODevice *device, QSsl::KeyAlgorithm algorithm, QSsl::Encoding /*! Constructs an identical copy of \a other. */ -QSslKey::QSslKey(const QSslKey &other) : d(other.d) +QSslKey::QSslKey(const QSslKey &other) : d(other.d.data()) { d->ref.ref(); } @@ -279,8 +279,6 @@ QSslKey::QSslKey(const QSslKey &other) : d(other.d) */ QSslKey::~QSslKey() { - if (!d->ref.deref()) - delete d; } /*! @@ -291,7 +289,7 @@ QSslKey::~QSslKey() */ QSslKey &QSslKey::operator=(const QSslKey &other) { - qAtomicAssign(d, other.d); + d.assign(other.d.data()); return *this; } @@ -312,10 +310,13 @@ bool QSslKey::isNull() const */ void QSslKey::clear() { - if (!d->ref.deref()) { - delete d; - d = new QSslKeyPrivate; - } + d.reset(new QSslKeyPrivate); + + //### old code: is this really correct??? + //if (!d->ref.deref()) { + // delete d; + // d = new QSslKeyPrivate; + //} } /*! diff --git a/src/network/ssl/qsslkey.h b/src/network/ssl/qsslkey.h index 45d03f7..d5d60a6 100644 --- a/src/network/ssl/qsslkey.h +++ b/src/network/ssl/qsslkey.h @@ -45,6 +45,7 @@ #include #include +#include #include QT_BEGIN_HEADER @@ -92,7 +93,7 @@ public: inline bool operator!=(const QSslKey &key) const { return !operator==(key); } private: - QSslKeyPrivate *d; + QScopedSharedPointer d; friend class QSslCertificate; }; diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index ca5c732..cd7a7f0 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -1484,8 +1484,8 @@ Q_OPENGL_EXPORT QGLShareRegister* qgl_share_reg() */ QGLContext::QGLContext(const QGLFormat &format, QPaintDevice *device) + : d_ptr(new QGLContextPrivate(this)) { - d_ptr = new QGLContextPrivate(this); Q_D(QGLContext); d->init(device, format); } @@ -1507,8 +1507,8 @@ QGLContext::QGLContext(const QGLFormat &format, QPaintDevice *device) \sa format(), isValid() */ QGLContext::QGLContext(const QGLFormat &format) + : d_ptr(new QGLContextPrivate(this)) { - d_ptr = new QGLContextPrivate(this); Q_D(QGLContext); d->init(0, format); } @@ -1539,7 +1539,6 @@ QGLContext::~QGLContext() QGLSignalProxy::instance()->emitAboutToDestroyContext(this); reset(); - delete d; } void QGLContextPrivate::cleanup() diff --git a/src/opengl/qgl.h b/src/opengl/qgl.h index 01b1d6f..b7b2f36 100644 --- a/src/opengl/qgl.h +++ b/src/opengl/qgl.h @@ -45,6 +45,7 @@ #include #include #include +#include QT_BEGIN_HEADER @@ -348,7 +349,7 @@ protected: static QGLContext* currentCtx; private: - QGLContextPrivate* d_ptr; + QScopedPointer d_ptr; friend class QGLPixelBuffer; friend class QGLPixelBufferPrivate; diff --git a/src/opengl/qglframebufferobject.cpp b/src/opengl/qglframebufferobject.cpp index c362b7e..6e908e2 100644 --- a/src/opengl/qglframebufferobject.cpp +++ b/src/opengl/qglframebufferobject.cpp @@ -448,7 +448,6 @@ QGLFramebufferObject::~QGLFramebufferObject() glDeleteRenderbuffersEXT(1, &d->depth_stencil_buffer); glDeleteFramebuffersEXT(1, &d->fbo); } - delete d_ptr; } /*! diff --git a/src/opengl/qglframebufferobject.h b/src/opengl/qglframebufferobject.h index a9e1b2f..fea8920 100644 --- a/src/opengl/qglframebufferobject.h +++ b/src/opengl/qglframebufferobject.h @@ -116,7 +116,7 @@ protected: private: Q_DISABLE_COPY(QGLFramebufferObject) - QGLFramebufferObjectPrivate *d_ptr; + QScopedPointer d_ptr; friend class QGLDrawable; }; diff --git a/src/opengl/qglpaintdevice_qws.cpp b/src/opengl/qglpaintdevice_qws.cpp index 18905ab..60a1238 100644 --- a/src/opengl/qglpaintdevice_qws.cpp +++ b/src/opengl/qglpaintdevice_qws.cpp @@ -68,8 +68,6 @@ QWSGLPaintDevice::QWSGLPaintDevice(QWidget *widget) : QWSGLPaintDevice::~QWSGLPaintDevice() { - Q_D(QWSGLPaintDevice); - delete d; } QPaintEngine* QWSGLPaintDevice::paintEngine() const diff --git a/src/opengl/qglpaintdevice_qws_p.h b/src/opengl/qglpaintdevice_qws_p.h index 369de7f..a471b1b 100644 --- a/src/opengl/qglpaintdevice_qws_p.h +++ b/src/opengl/qglpaintdevice_qws_p.h @@ -53,6 +53,7 @@ // We mean it. // +#include #include QT_BEGIN_NAMESPACE @@ -76,7 +77,7 @@ public: private: friend class QWSGLWindowSurface; - QWSGLPaintDevicePrivate *d_ptr; + QScopedPointer d_ptr; }; diff --git a/src/opengl/qglpixelbuffer.cpp b/src/opengl/qglpixelbuffer.cpp index 5f74f26..8ff2e1d 100644 --- a/src/opengl/qglpixelbuffer.cpp +++ b/src/opengl/qglpixelbuffer.cpp @@ -186,7 +186,6 @@ QGLPixelBuffer::~QGLPixelBuffer() delete d->qctx; if (current && current != d->qctx) current->makeCurrent(); - delete d_ptr; } /*! \fn bool QGLPixelBuffer::makeCurrent() diff --git a/src/opengl/qglpixelbuffer.h b/src/opengl/qglpixelbuffer.h index 0131570..8264c22 100644 --- a/src/opengl/qglpixelbuffer.h +++ b/src/opengl/qglpixelbuffer.h @@ -107,7 +107,7 @@ protected: private: Q_DISABLE_COPY(QGLPixelBuffer) - QGLPixelBufferPrivate *d_ptr; + QScopedPointer d_ptr; friend class QGLDrawable; friend class QGLWindowSurface; }; diff --git a/src/opengl/qpaintengine_opengl.cpp b/src/opengl/qpaintengine_opengl.cpp index 5a212f5..c9fbc7e 100644 --- a/src/opengl/qpaintengine_opengl.cpp +++ b/src/opengl/qpaintengine_opengl.cpp @@ -5625,7 +5625,7 @@ void QOpenGLPaintEngine::fill(const QVectorPath &path, const QBrush &brush) QPainter *p = painter(); QBrush oldBrush = p->brush(); p->setBrush(brush); - qt_draw_helper(p->d_ptr, painterPathFromVectorPath(path), QPainterPrivate::FillDraw); + qt_draw_helper(p->d_ptr.data(), painterPathFromVectorPath(path), QPainterPrivate::FillDraw); p->setBrush(oldBrush); return; } diff --git a/src/phonon/phonon.pro b/src/phonon/phonon.pro index b38adb8..221304d 100644 --- a/src/phonon/phonon.pro +++ b/src/phonon/phonon.pro @@ -119,8 +119,7 @@ symbian: { # would bring in link dependencies, and we don't need that for # numeric_limits, hence we here merely ensure we bring in the necessary # header. - INCLUDEPATH *= $${EPOCROOT}epoc32/include/stdapis/stlport \ - $$OS_LAYER_STDCPP_SYSTEMINCLUDE + INCLUDEPATH *= $$OS_LAYER_STDCPP_SYSTEMINCLUDE # Without this setting, code using numeric_limits will fail # for winscw, although armv5 works fine no matter what. diff --git a/src/plugins/imageformats/mng/qmnghandler.cpp b/src/plugins/imageformats/mng/qmnghandler.cpp index 19cc16d..7fabcd9 100644 --- a/src/plugins/imageformats/mng/qmnghandler.cpp +++ b/src/plugins/imageformats/mng/qmnghandler.cpp @@ -375,8 +375,6 @@ QMngHandler::QMngHandler() QMngHandler::~QMngHandler() { - Q_D(QMngHandler); - delete d; } /*! \reimp */ diff --git a/src/plugins/imageformats/mng/qmnghandler.h b/src/plugins/imageformats/mng/qmnghandler.h index 909be2d..ce2ec6f 100644 --- a/src/plugins/imageformats/mng/qmnghandler.h +++ b/src/plugins/imageformats/mng/qmnghandler.h @@ -42,6 +42,7 @@ #ifndef QMNGHANDLER_H #define QMNGHANDLER_H +#include #include QT_BEGIN_NAMESPACE @@ -74,7 +75,7 @@ class QMngHandler : public QImageIOHandler private: Q_DECLARE_PRIVATE(QMngHandler) - QMngHandlerPrivate *d_ptr; + QScopedPointer d_ptr; }; QT_END_NAMESPACE diff --git a/src/plugins/s60/src/qlocale_3_2.cpp b/src/plugins/s60/src/qlocale_3_2.cpp index ab3040b..7a3a7e5 100644 --- a/src/plugins/s60/src/qlocale_3_2.cpp +++ b/src/plugins/s60/src/qlocale_3_2.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ +#include #include #include diff --git a/src/qt3support/itemviews/q3table.cpp b/src/qt3support/itemviews/q3table.cpp index 658b0ad..458f5a5 100644 --- a/src/qt3support/itemviews/q3table.cpp +++ b/src/qt3support/itemviews/q3table.cpp @@ -166,6 +166,7 @@ private: QTimer *stretchTimer, *widgetStretchTimer; Q3TableHeaderPrivate *d; + Q_DISABLE_COPY(Q3TableHeader) }; #ifdef _WS_QWS_ diff --git a/src/qt3support/other/q3accel.cpp b/src/qt3support/other/q3accel.cpp index a570a70..2358092 100644 --- a/src/qt3support/other/q3accel.cpp +++ b/src/qt3support/other/q3accel.cpp @@ -206,7 +206,7 @@ bool Q_COMPAT_EXPORT qt_tryComposeUnicode(QWidget* w, QKeyEvent* e){ void Q3AccelManager::setFuncPtr() { if (qApp->d_func()->qt_compat_used) return; - QApplicationPrivate *data = static_cast(qApp->d_ptr); + QApplicationPrivate *data = static_cast(qApp->d_ptr.data()); data->qt_tryAccelEvent = qt_tryAccelEvent; data->qt_tryComposeUnicode = qt_tryComposeUnicode; data->qt_dispatchAccelEvent = qt_dispatchAccelEvent; diff --git a/src/qt3support/painting/q3painter.h b/src/qt3support/painting/q3painter.h index 6fd17cb..c301ee7 100644 --- a/src/qt3support/painting/q3painter.h +++ b/src/qt3support/painting/q3painter.h @@ -82,6 +82,8 @@ public: private: QRect adjustedRectangle(const QRect &r); + + Q_DISABLE_COPY(Q3Painter) }; void inline Q3Painter::drawRect(const QRect &r) diff --git a/src/s60main/qts60main.cpp b/src/s60main/qts60main.cpp index 965c02b..d7daf4a 100644 --- a/src/s60main/qts60main.cpp +++ b/src/s60main/qts60main.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ // INCLUDE FILES +#include #include #include "qts60mainapplication.h" diff --git a/src/s60main/qts60main_mcrt0.cpp b/src/s60main/qts60main_mcrt0.cpp index b7bf1a3..49a47bd 100644 --- a/src/s60main/qts60main_mcrt0.cpp +++ b/src/s60main/qts60main_mcrt0.cpp @@ -79,7 +79,15 @@ GLDEF_C TInt QtMainWrapper() CleanupArrayDelete::PushL(argv); CleanupArrayDelete::PushL(envp); //Call user(application)'s main - int ret = CALLMAIN(argc,argv,envp); + int ret = 0; + try + { + ret = CALLMAIN(argc, argv, envp); + } + catch (...) + { + User::Leave(KErrGeneral); + } CleanupStack::PopAndDestroy(2,argv); return ret; } diff --git a/src/s60main/qts60mainapplication.cpp b/src/s60main/qts60mainapplication.cpp index 680243f..2fada3d 100644 --- a/src/s60main/qts60mainapplication.cpp +++ b/src/s60main/qts60mainapplication.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ // INCLUDE FILES +#include #include "qts60maindocument.h" #include "qts60mainapplication.h" #include diff --git a/src/s60main/qts60mainappui.cpp b/src/s60main/qts60mainappui.cpp index 47312af..50f7572 100644 --- a/src/s60main/qts60mainappui.cpp +++ b/src/s60main/qts60mainappui.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ // INCLUDE FILES +#include #include #include #include @@ -123,7 +124,9 @@ void CQtS60MainAppUi::HandleWsEventL(const TWsEvent& aEvent, CCoeControl *contro { int result = 0; if (qApp) - result = qApp->s60ProcessEvent(const_cast(&aEvent)); + QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_LEAVE( + result = qApp->s60ProcessEvent(const_cast(&aEvent)) + ); if (result <= 0) CAknAppUi::HandleWsEventL(aEvent, control); @@ -162,7 +165,8 @@ TInt CQtS60MainAppUi::OpenCMainStaticCallBack( TAny* aObject ) // void CQtS60MainAppUi::OpenCMainCallBack() { - TInt ret = QtMainWrapper(); + TInt ret; + TRAPD(err, ret = QtMainWrapper()); Exit(); } diff --git a/src/s60main/qts60maindocument.cpp b/src/s60main/qts60maindocument.cpp index b4a2e66..eb7ea42 100644 --- a/src/s60main/qts60maindocument.cpp +++ b/src/s60main/qts60maindocument.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ // INCLUDE FILES +#include #include "qts60mainappui.h" #include "qts60maindocument.h" diff --git a/src/script/qscriptable.cpp b/src/script/qscriptable.cpp index a6401d6..56291d8 100644 --- a/src/script/qscriptable.cpp +++ b/src/script/qscriptable.cpp @@ -118,8 +118,6 @@ QScriptable::QScriptable() */ QScriptable::~QScriptable() { - delete d_ptr; - d_ptr = 0; } /*! diff --git a/src/script/qscriptable.h b/src/script/qscriptable.h index f990db2..d09b945 100644 --- a/src/script/qscriptable.h +++ b/src/script/qscriptable.h @@ -46,6 +46,8 @@ #ifndef QT_NO_SCRIPT +#include + QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -73,7 +75,7 @@ public: QScriptValue argument(int index) const; private: - QScriptablePrivate *d_ptr; + QScopedPointer d_ptr; Q_DISABLE_COPY(QScriptable) Q_DECLARE_PRIVATE(QScriptable) diff --git a/src/script/qscriptclass.cpp b/src/script/qscriptclass.cpp index 14b8add..535a530 100644 --- a/src/script/qscriptclass.cpp +++ b/src/script/qscriptclass.cpp @@ -457,8 +457,6 @@ QScriptClass::QScriptClass(QScriptEngine *engine, QScriptClassPrivate &dd) */ QScriptClass::~QScriptClass() { - delete d_ptr; - d_ptr = 0; } /*! diff --git a/src/script/qscriptclass.h b/src/script/qscriptclass.h index 9c06ea2..77e9b08 100644 --- a/src/script/qscriptclass.h +++ b/src/script/qscriptclass.h @@ -47,6 +47,7 @@ #ifndef QT_NO_SCRIPT #include +#include #include QT_BEGIN_HEADER @@ -103,7 +104,7 @@ public: protected: QScriptClass(QScriptEngine *engine, QScriptClassPrivate &dd); - QScriptClassPrivate *d_ptr; + QScopedPointer d_ptr; private: Q_DECLARE_PRIVATE(QScriptClass) diff --git a/src/script/qscriptclasspropertyiterator.cpp b/src/script/qscriptclasspropertyiterator.cpp index 96f34d5..f328e14 100644 --- a/src/script/qscriptclasspropertyiterator.cpp +++ b/src/script/qscriptclasspropertyiterator.cpp @@ -111,8 +111,6 @@ QScriptClassPropertyIterator::QScriptClassPropertyIterator(const QScriptValue &o */ QScriptClassPropertyIterator::~QScriptClassPropertyIterator() { - delete d_ptr; - d_ptr = 0; } /*! diff --git a/src/script/qscriptclasspropertyiterator.h b/src/script/qscriptclasspropertyiterator.h index 2041a65..05d49d8 100644 --- a/src/script/qscriptclasspropertyiterator.h +++ b/src/script/qscriptclasspropertyiterator.h @@ -46,6 +46,7 @@ #ifndef QT_NO_SCRIPT +#include #include QT_BEGIN_HEADER @@ -80,7 +81,7 @@ public: protected: QScriptClassPropertyIterator(const QScriptValue &object, QScriptClassPropertyIteratorPrivate &dd); - QScriptClassPropertyIteratorPrivate *d_ptr; + QScopedPointer d_ptr; private: Q_DECLARE_PRIVATE(QScriptClassPropertyIterator) diff --git a/src/script/qscriptcontext.cpp b/src/script/qscriptcontext.cpp index 020601b..0b72342 100644 --- a/src/script/qscriptcontext.cpp +++ b/src/script/qscriptcontext.cpp @@ -219,8 +219,6 @@ QScriptContext::QScriptContext(): */ QScriptContext::~QScriptContext() { - delete d_ptr; - d_ptr = 0; } /*! diff --git a/src/script/qscriptcontext.h b/src/script/qscriptcontext.h index 1e1f987..25a2198 100644 --- a/src/script/qscriptcontext.h +++ b/src/script/qscriptcontext.h @@ -46,6 +46,7 @@ #ifndef QT_NO_SCRIPT +#include #include QT_BEGIN_HEADER @@ -111,7 +112,7 @@ public: private: QScriptContext(); - QScriptContextPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QScriptContext) Q_DISABLE_COPY(QScriptContext) diff --git a/src/script/qscriptcontextinfo.cpp b/src/script/qscriptcontextinfo.cpp index 260d19f..0fa5c62 100644 --- a/src/script/qscriptcontextinfo.cpp +++ b/src/script/qscriptcontextinfo.cpp @@ -204,13 +204,12 @@ QScriptContextInfoPrivate::~QScriptContextInfoPrivate() previously created QScriptContextInfo. */ QScriptContextInfo::QScriptContextInfo(const QScriptContext *context) + : d_ptr(0) { if (context) { - d_ptr = new QScriptContextInfoPrivate(context); + d_ptr.data_ptr() = new QScriptContextInfoPrivate(context); d_ptr->q_ptr = this; d_ptr->ref.ref(); - } else { - d_ptr = 0; } } @@ -218,7 +217,7 @@ QScriptContextInfo::QScriptContextInfo(const QScriptContext *context) Constructs a new QScriptContextInfo from the \a other info. */ QScriptContextInfo::QScriptContextInfo(const QScriptContextInfo &other) - : d_ptr(other.d_ptr) + : d_ptr(other.d_ptr.data()) { if (d_ptr) d_ptr->ref.ref(); @@ -239,10 +238,6 @@ QScriptContextInfo::QScriptContextInfo() */ QScriptContextInfo::~QScriptContextInfo() { - if (d_ptr && !d_ptr->ref.deref()) { - delete d_ptr; - d_ptr = 0; - } } /*! @@ -251,15 +246,7 @@ QScriptContextInfo::~QScriptContextInfo() */ QScriptContextInfo &QScriptContextInfo::operator=(const QScriptContextInfo &other) { - if (d_ptr == other.d_ptr) - return *this; - if (d_ptr && !d_ptr->ref.deref()) { - delete d_ptr; - d_ptr = 0; - } - d_ptr = other.d_ptr; - if (d_ptr) - d_ptr->ref.ref(); + d_ptr.assign(other.d_ptr.data()); return *this; } @@ -510,7 +497,7 @@ QDataStream &operator<<(QDataStream &out, const QScriptContextInfo &info) Q_SCRIPT_EXPORT QDataStream &operator>>(QDataStream &in, QScriptContextInfo &info) { if (!info.d_ptr) { - info.d_ptr = new QScriptContextInfoPrivate(); + info.d_ptr.data_ptr() = new QScriptContextInfoPrivate(); info.d_ptr->ref.ref(); } diff --git a/src/script/qscriptcontextinfo.h b/src/script/qscriptcontextinfo.h index a683733..20b6607 100644 --- a/src/script/qscriptcontextinfo.h +++ b/src/script/qscriptcontextinfo.h @@ -48,6 +48,7 @@ #include #include +#include QT_BEGIN_HEADER @@ -104,7 +105,7 @@ public: bool operator!=(const QScriptContextInfo &other) const; private: - QScriptContextInfoPrivate *d_ptr; + QScopedSharedPointer d_ptr; Q_DECLARE_PRIVATE(QScriptContextInfo) }; diff --git a/src/script/qscriptengine.cpp b/src/script/qscriptengine.cpp index d8908ed..2a36104 100644 --- a/src/script/qscriptengine.cpp +++ b/src/script/qscriptengine.cpp @@ -330,10 +330,6 @@ QScriptEngine::~QScriptEngine() Q_D(QScriptEngine); d->m_frameRepository.release(currentContext()); d->objectAllocator.destruct(); -#ifdef QT_NO_QOBJECT - delete d_ptr; - d_ptr = 0; -#endif } /*! @@ -1777,7 +1773,7 @@ QScriptValue QScriptEngine::objectById(qint64 id) const Constructs a new QScriptSyntaxCheckResult from the \a other result. */ QScriptSyntaxCheckResult::QScriptSyntaxCheckResult(const QScriptSyntaxCheckResult &other) - : d_ptr(other.d_ptr) + : d_ptr(other.d_ptr.data()) { if (d_ptr) d_ptr->ref.ref(); @@ -1806,10 +1802,6 @@ QScriptSyntaxCheckResult::QScriptSyntaxCheckResult() */ QScriptSyntaxCheckResult::~QScriptSyntaxCheckResult() { - if (d_ptr && !d_ptr->ref.deref()) { - delete d_ptr; - d_ptr = 0; - } } /*! @@ -1863,15 +1855,7 @@ QString QScriptSyntaxCheckResult::errorMessage() const */ QScriptSyntaxCheckResult &QScriptSyntaxCheckResult::operator=(const QScriptSyntaxCheckResult &other) { - if (d_ptr == other.d_ptr) - return *this; - if (d_ptr && !d_ptr->ref.deref()) { - delete d_ptr; - d_ptr = 0; - } - d_ptr = other.d_ptr; - if (d_ptr) - d_ptr->ref.ref(); + d_ptr.assign(other.d_ptr.data()); return *this; } diff --git a/src/script/qscriptengine.h b/src/script/qscriptengine.h index afd551b..c55caac 100644 --- a/src/script/qscriptengine.h +++ b/src/script/qscriptengine.h @@ -47,6 +47,7 @@ #ifndef QT_NO_SCRIPT #include +#include #ifndef QT_NO_QOBJECT #include @@ -114,7 +115,7 @@ public: private: QScriptSyntaxCheckResult(); QScriptSyntaxCheckResult(QScriptSyntaxCheckResultPrivate *d); - QScriptSyntaxCheckResultPrivate *d_ptr; + QScopedSharedPointer d_ptr; Q_DECLARE_PRIVATE(QScriptSyntaxCheckResult) friend class QScriptEnginePrivate; @@ -282,7 +283,7 @@ private: protected: #ifdef QT_NO_QOBJECT - QScriptEnginePrivate *d_ptr; + QScopedPointer d_ptr; QScriptEngine(QScriptEnginePrivate &dd); #else diff --git a/src/script/qscriptengineagent.cpp b/src/script/qscriptengineagent.cpp index bda94ae..c3eaf96 100644 --- a/src/script/qscriptengineagent.cpp +++ b/src/script/qscriptengineagent.cpp @@ -173,8 +173,6 @@ QScriptEngineAgent::QScriptEngineAgent(QScriptEngineAgentPrivate &dd, QScriptEng */ QScriptEngineAgent::~QScriptEngineAgent() { - delete d_ptr; - d_ptr = 0; } /*! diff --git a/src/script/qscriptengineagent.h b/src/script/qscriptengineagent.h index 3334bc0..461d756 100644 --- a/src/script/qscriptengineagent.h +++ b/src/script/qscriptengineagent.h @@ -47,6 +47,7 @@ #ifndef QT_NO_SCRIPT #include +#include QT_BEGIN_HEADER @@ -96,7 +97,7 @@ public: protected: QScriptEngineAgent(QScriptEngineAgentPrivate &dd, QScriptEngine *engine); - QScriptEngineAgentPrivate *d_ptr; + QScopedPointer d_ptr; private: Q_DECLARE_PRIVATE(QScriptEngineAgent) diff --git a/src/script/qscriptstring.cpp b/src/script/qscriptstring.cpp index 69b0796..e7591e1 100644 --- a/src/script/qscriptstring.cpp +++ b/src/script/qscriptstring.cpp @@ -54,6 +54,29 @@ QT_BEGIN_NAMESPACE +/*! \internal */ +struct QScriptStringPrivatePointerHandler +{ + static inline void cleanup(QScriptStringPrivate *d) + { + if (!d || d->ref.deref()) + return; + + if (d->nameId) { + d->engine->uninternString(d); + } else { + // the engine has already been deleted + delete d; + } + } + + static inline void reset(QScriptStringPrivate *&d, QScriptStringPrivate *other) + { + cleanup(d); + d = other; + } +}; + /*! \since 4.4 \class QScriptString @@ -108,8 +131,8 @@ QScriptStringPrivate *QScriptStringPrivate::get(const QScriptString &q) void QScriptStringPrivate::init(QScriptString &q, QScriptStringPrivate *d) { Q_ASSERT(q.d_ptr == 0); - q.d_ptr = d; - q.d_ptr->ref.ref(); + q.d_ptr.data_ptr() = d; + d->ref.ref(); } /*! @@ -124,7 +147,7 @@ QScriptString::QScriptString() Constructs a new QScriptString that is a copy of \a other. */ QScriptString::QScriptString(const QScriptString &other) - : d_ptr(other.d_ptr) + : d_ptr(other.d_ptr.data()) { if (d_ptr) d_ptr->ref.ref(); @@ -135,15 +158,6 @@ QScriptString::QScriptString(const QScriptString &other) */ QScriptString::~QScriptString() { - if (d_ptr && !d_ptr->ref.deref()) { - if (isValid()) { - d_ptr->engine->uninternString(d_ptr); - } else { - // the engine has already been deleted - delete d_ptr; - } - d_ptr = 0; - } } /*! @@ -153,15 +167,7 @@ QScriptString &QScriptString::operator=(const QScriptString &other) { if (d_ptr == other.d_ptr) return *this; - if (d_ptr && !d_ptr->ref.deref()) { - if (isValid()) { - d_ptr->engine->uninternString(d_ptr); - } else { - // the engine has already been deleted - delete d_ptr; - } - } - d_ptr = other.d_ptr; + d_ptr.reset(other.d_ptr.data()); if (d_ptr) d_ptr->ref.ref(); return *this; diff --git a/src/script/qscriptstring.h b/src/script/qscriptstring.h index d2fecd8..f68be0c 100644 --- a/src/script/qscriptstring.h +++ b/src/script/qscriptstring.h @@ -46,6 +46,8 @@ #ifndef QT_NO_SCRIPT +#include + QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -54,6 +56,7 @@ QT_MODULE(Script) class QScriptEngine; class QScriptStringPrivate; +struct QScriptStringPrivatePointerHandler; class Q_SCRIPT_EXPORT QScriptString { @@ -73,7 +76,7 @@ public: operator QString() const; private: - QScriptStringPrivate *d_ptr; + QScopedCustomPointer d_ptr; Q_DECLARE_PRIVATE(QScriptString) }; diff --git a/src/script/qscriptvalue.cpp b/src/script/qscriptvalue.cpp index a253985..4282248 100644 --- a/src/script/qscriptvalue.cpp +++ b/src/script/qscriptvalue.cpp @@ -57,6 +57,28 @@ QT_BEGIN_NAMESPACE +/*! \internal + */ +struct QScriptValuePrivatePointerHandler +{ + static inline void cleanup(QScriptValuePrivate *d) + { + if (!d || d->ref.deref()) + return; + if (d->engine) { + QScriptEnginePrivate::get(d->engine)->unregisterValue(d); + } else { + delete d; + } + } + + static inline void reset(QScriptValuePrivate *&d, QScriptValuePrivate *other) + { + cleanup(d); + d = other; + } +}; + /*! \since 4.3 \class QScriptValue @@ -194,14 +216,6 @@ QScriptValue::QScriptValue() */ QScriptValue::~QScriptValue() { - if (d_ptr && !d_ptr->ref.deref()) { - if (engine()) { - QScriptEnginePrivate::get(engine())->unregisterValue(d_ptr); - } else { - delete d_ptr; - } - d_ptr = 0; - } } /*! @@ -212,7 +226,7 @@ QScriptValue::~QScriptValue() the new script value (i.e., the object itself is not copied). */ QScriptValue::QScriptValue(const QScriptValue &other) - : d_ptr(other.d_ptr) + : d_ptr(other.d_ptr.data()) { if (d_ptr) d_ptr->ref.ref(); @@ -225,13 +239,12 @@ QScriptValue::QScriptValue(const QScriptValue &other) registers it with the script \a engine. */ QScriptValue::QScriptValue(QScriptEngine *engine, QScriptValue::SpecialValue value) + : d_ptr(0) { if (engine) { QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(engine); - d_ptr = eng_p->registerValue(QScriptValueImpl(value)); + d_ptr.data_ptr() = eng_p->registerValue(QScriptValueImpl(value)); d_ptr->ref.ref(); - } else { - d_ptr = 0; } } @@ -244,13 +257,12 @@ QScriptValue::QScriptValue(QScriptEngine *engine, QScriptValue::SpecialValue val registers it with the script \a engine. */ QScriptValue::QScriptValue(QScriptEngine *engine, bool val) + : d_ptr(0) { if (engine) { QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(engine); - d_ptr = eng_p->registerValue(QScriptValueImpl(val)); + d_ptr.data_ptr() = eng_p->registerValue(QScriptValueImpl(val)); d_ptr->ref.ref(); - } else { - d_ptr = 0; } } @@ -262,13 +274,12 @@ QScriptValue::QScriptValue(QScriptEngine *engine, bool val) registers it with the script \a engine. */ QScriptValue::QScriptValue(QScriptEngine *engine, int val) + : d_ptr(0) { if (engine) { QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(engine); - d_ptr = eng_p->registerValue(QScriptValueImpl(val)); + d_ptr.data_ptr() = eng_p->registerValue(QScriptValueImpl(val)); d_ptr->ref.ref(); - } else { - d_ptr = 0; } } @@ -280,13 +291,12 @@ QScriptValue::QScriptValue(QScriptEngine *engine, int val) registers it with the script \a engine. */ QScriptValue::QScriptValue(QScriptEngine *engine, uint val) + : d_ptr(0) { if (engine) { QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(engine); - d_ptr = eng_p->registerValue(QScriptValueImpl(val)); + d_ptr.data_ptr() = eng_p->registerValue(QScriptValueImpl(val)); d_ptr->ref.ref(); - } else { - d_ptr = 0; } } @@ -298,13 +308,12 @@ QScriptValue::QScriptValue(QScriptEngine *engine, uint val) registers it with the script \a engine. */ QScriptValue::QScriptValue(QScriptEngine *engine, qsreal val) + : d_ptr(0) { if (engine) { QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(engine); - d_ptr = eng_p->registerValue(QScriptValueImpl(val)); + d_ptr.data_ptr() = eng_p->registerValue(QScriptValueImpl(val)); d_ptr->ref.ref(); - } else { - d_ptr = 0; } } @@ -316,15 +325,14 @@ QScriptValue::QScriptValue(QScriptEngine *engine, qsreal val) registers it with the script \a engine. */ QScriptValue::QScriptValue(QScriptEngine *engine, const QString &val) + : d_ptr(0) { if (engine) { QScriptValueImpl v; QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(engine); eng_p->newString(&v, val); - d_ptr = eng_p->registerValue(v); + d_ptr.data_ptr() = eng_p->registerValue(v); d_ptr->ref.ref(); - } else { - d_ptr = 0; } } @@ -338,15 +346,14 @@ QScriptValue::QScriptValue(QScriptEngine *engine, const QString &val) #ifndef QT_NO_CAST_FROM_ASCII QScriptValue::QScriptValue(QScriptEngine *engine, const char *val) + : d_ptr(0) { if (engine) { QScriptValueImpl v; QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(engine); eng_p->newString(&v, QString::fromAscii(val)); - d_ptr = eng_p->registerValue(v); + d_ptr.data_ptr() = eng_p->registerValue(v); d_ptr->ref.ref(); - } else { - d_ptr = 0; } } #endif @@ -464,14 +471,7 @@ QScriptValue &QScriptValue::operator=(const QScriptValue &other) { if (d_ptr == other.d_ptr) return *this; - if (d_ptr && !d_ptr->ref.deref()) { - if (engine()) { - QScriptEnginePrivate::get(engine())->unregisterValue(d_ptr); - } else { - delete d_ptr; - } - } - d_ptr = other.d_ptr; + d_ptr.reset(other.d_ptr.data()); if (d_ptr) d_ptr->ref.ref(); return *this; diff --git a/src/script/qscriptvalue.h b/src/script/qscriptvalue.h index 306da53..76b1186 100644 --- a/src/script/qscriptvalue.h +++ b/src/script/qscriptvalue.h @@ -47,6 +47,7 @@ #ifndef QT_NO_SCRIPT #include +#include QT_BEGIN_HEADER @@ -71,6 +72,7 @@ typedef QList QScriptValueList; typedef double qsreal; class QScriptValuePrivate; +struct QScriptValuePrivatePointerHandler; class Q_SCRIPT_EXPORT QScriptValue { public: @@ -216,12 +218,12 @@ public: private: // force compile error, prevent QScriptValue(bool) to be called - inline QScriptValue(void *) { Q_ASSERT(false); } + inline QScriptValue(void *); // force compile error, prevent QScriptValue(QScriptEngine*, bool) to be called - inline QScriptValue(QScriptEngine *, void *) { Q_ASSERT(false); } + inline QScriptValue(QScriptEngine *, void *); private: - QScriptValuePrivate *d_ptr; + QScopedCustomPointer d_ptr; Q_DECLARE_PRIVATE(QScriptValue) }; diff --git a/src/script/qscriptvalue_p.h b/src/script/qscriptvalue_p.h index 8463ed2..6528464 100644 --- a/src/script/qscriptvalue_p.h +++ b/src/script/qscriptvalue_p.h @@ -91,7 +91,7 @@ inline QScriptValueImpl QScriptValuePrivate::valueOf(const QScriptValue &value) inline void QScriptValuePrivate::init(QScriptValue &value, QScriptValuePrivate *p) { - value.d_ptr = p; + value.d_ptr.data_ptr() = p; value.d_ptr->ref.ref(); } diff --git a/src/script/qscriptvalueiterator.cpp b/src/script/qscriptvalueiterator.cpp index 1a60632..2cf5575 100644 --- a/src/script/qscriptvalueiterator.cpp +++ b/src/script/qscriptvalueiterator.cpp @@ -115,12 +115,11 @@ QScriptValueIteratorPrivate::~QScriptValueIteratorPrivate() first property). */ QScriptValueIterator::QScriptValueIterator(const QScriptValue &object) + : d_ptr(0) { QScriptValueImpl val = QScriptValuePrivate::valueOf(object); - if (!val.isObject()) { - d_ptr = 0; - } else { - d_ptr = new QScriptValueIteratorPrivate(); + if (val.isObject()) { + d_ptr.reset(new QScriptValueIteratorPrivate()); d_ptr->it = new QScriptValueIteratorImpl(val); } } @@ -130,10 +129,6 @@ QScriptValueIterator::QScriptValueIterator(const QScriptValue &object) */ QScriptValueIterator::~QScriptValueIterator() { - if (d_ptr) { - delete d_ptr; - d_ptr = 0; - } } /*! @@ -311,13 +306,10 @@ void QScriptValueIterator::remove() */ QScriptValueIterator& QScriptValueIterator::operator=(QScriptValue &object) { - if (d_ptr) { - delete d_ptr; - d_ptr = 0; - } + d_ptr.reset(); QScriptValueImpl val = QScriptValuePrivate::valueOf(object); if (val.isObject()) { - d_ptr = new QScriptValueIteratorPrivate(); + d_ptr.reset(new QScriptValueIteratorPrivate()); d_ptr->it = new QScriptValueIteratorImpl(val); } return *this; diff --git a/src/script/qscriptvalueiterator.h b/src/script/qscriptvalueiterator.h index 91561e8..082158d 100644 --- a/src/script/qscriptvalueiterator.h +++ b/src/script/qscriptvalueiterator.h @@ -46,6 +46,8 @@ #ifndef QT_NO_SCRIPT +#include + QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -84,7 +86,7 @@ public: QScriptValueIterator& operator=(QScriptValue &value); private: - QScriptValueIteratorPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QScriptValueIterator) Q_DISABLE_COPY(QScriptValueIterator) diff --git a/src/scripttools/debugging/qscriptbreakpointdata.cpp b/src/scripttools/debugging/qscriptbreakpointdata.cpp index 9762ca4..50e597e 100644 --- a/src/scripttools/debugging/qscriptbreakpointdata.cpp +++ b/src/scripttools/debugging/qscriptbreakpointdata.cpp @@ -136,7 +136,6 @@ QScriptBreakpointData::QScriptBreakpointData(const QScriptBreakpointData &other) */ QScriptBreakpointData::~QScriptBreakpointData() { - delete d_ptr; } /*! @@ -355,7 +354,7 @@ bool QScriptBreakpointData::operator!=(const QScriptBreakpointData &other) const */ QDataStream &operator<<(QDataStream &out, const QScriptBreakpointData &data) { - const QScriptBreakpointDataPrivate *d = data.d_ptr; + const QScriptBreakpointDataPrivate *d = data.d_ptr.data(); out << d->scriptId; out << d->fileName; out << d->lineNumber; @@ -377,7 +376,7 @@ QDataStream &operator<<(QDataStream &out, const QScriptBreakpointData &data) */ QDataStream &operator>>(QDataStream &in, QScriptBreakpointData &data) { - QScriptBreakpointDataPrivate *d = data.d_ptr; + QScriptBreakpointDataPrivate *d = data.d_ptr.data(); in >> d->scriptId; in >> d->fileName; in >> d->lineNumber; diff --git a/src/scripttools/debugging/qscriptbreakpointdata_p.h b/src/scripttools/debugging/qscriptbreakpointdata_p.h index c1ff033..6cfceed 100644 --- a/src/scripttools/debugging/qscriptbreakpointdata_p.h +++ b/src/scripttools/debugging/qscriptbreakpointdata_p.h @@ -54,7 +54,7 @@ // #include - +#include #include QT_BEGIN_NAMESPACE @@ -114,7 +114,7 @@ public: bool operator!=(const QScriptBreakpointData &other) const; private: - QScriptBreakpointDataPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QScriptBreakpointData) }; diff --git a/src/scripttools/debugging/qscriptdebuggerbackend.cpp b/src/scripttools/debugging/qscriptdebuggerbackend.cpp index 3c29130..46d8497 100644 --- a/src/scripttools/debugging/qscriptdebuggerbackend.cpp +++ b/src/scripttools/debugging/qscriptdebuggerbackend.cpp @@ -385,7 +385,6 @@ QScriptDebuggerBackend::QScriptDebuggerBackend() QScriptDebuggerBackend::~QScriptDebuggerBackend() { detach(); - delete d_ptr; } /*! diff --git a/src/scripttools/debugging/qscriptdebuggerbackend_p.h b/src/scripttools/debugging/qscriptdebuggerbackend_p.h index 6d593a6..d9ec307 100644 --- a/src/scripttools/debugging/qscriptdebuggerbackend_p.h +++ b/src/scripttools/debugging/qscriptdebuggerbackend_p.h @@ -144,7 +144,7 @@ protected: protected: QScriptDebuggerBackend(QScriptDebuggerBackendPrivate &dd); - QScriptDebuggerBackendPrivate *d_ptr; + QScopedPointer d_ptr; private: Q_DECLARE_PRIVATE(QScriptDebuggerBackend) diff --git a/src/scripttools/debugging/qscriptdebuggercommand.cpp b/src/scripttools/debugging/qscriptdebuggercommand.cpp index c40bfc4..98bb3b3 100644 --- a/src/scripttools/debugging/qscriptdebuggercommand.cpp +++ b/src/scripttools/debugging/qscriptdebuggercommand.cpp @@ -118,7 +118,6 @@ QScriptDebuggerCommand::QScriptDebuggerCommand(const QScriptDebuggerCommand &oth */ QScriptDebuggerCommand::~QScriptDebuggerCommand() { - delete d_ptr; } /*! @@ -646,7 +645,7 @@ QScriptDebuggerCommand QScriptDebuggerCommand::clearExceptionsCommand() */ QDataStream &operator<<(QDataStream &out, const QScriptDebuggerCommand &command) { - const QScriptDebuggerCommandPrivate *d = command.d_ptr; + const QScriptDebuggerCommandPrivate *d = command.d_ptr.data(); out << (quint32)d->type; out << (qint32)d->attributes.size(); QHash::const_iterator it; @@ -666,7 +665,7 @@ QDataStream &operator<<(QDataStream &out, const QScriptDebuggerCommand &command) */ QDataStream &operator>>(QDataStream &in, QScriptDebuggerCommand &command) { - QScriptDebuggerCommandPrivate *d = command.d_ptr; + QScriptDebuggerCommandPrivate *d = command.d_ptr.data(); quint32 type; in >> type; diff --git a/src/scripttools/debugging/qscriptdebuggercommand_p.h b/src/scripttools/debugging/qscriptdebuggercommand_p.h index 260e3ec..363738f 100644 --- a/src/scripttools/debugging/qscriptdebuggercommand_p.h +++ b/src/scripttools/debugging/qscriptdebuggercommand_p.h @@ -54,7 +54,7 @@ // #include - +#include #include #include @@ -250,7 +250,7 @@ public: static QScriptDebuggerCommand clearExceptionsCommand(); private: - QScriptDebuggerCommandPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QScriptDebuggerCommand) }; diff --git a/src/scripttools/debugging/qscriptdebuggercommandexecutor.cpp b/src/scripttools/debugging/qscriptdebuggercommandexecutor.cpp index 1be8c5f..e75ff99 100644 --- a/src/scripttools/debugging/qscriptdebuggercommandexecutor.cpp +++ b/src/scripttools/debugging/qscriptdebuggercommandexecutor.cpp @@ -98,7 +98,6 @@ QScriptDebuggerCommandExecutor::QScriptDebuggerCommandExecutor() QScriptDebuggerCommandExecutor::~QScriptDebuggerCommandExecutor() { - delete d_ptr; } /*! diff --git a/src/scripttools/debugging/qscriptdebuggercommandexecutor_p.h b/src/scripttools/debugging/qscriptdebuggercommandexecutor_p.h index 8fff5e5..da7de76 100644 --- a/src/scripttools/debugging/qscriptdebuggercommandexecutor_p.h +++ b/src/scripttools/debugging/qscriptdebuggercommandexecutor_p.h @@ -54,6 +54,7 @@ // #include +#include QT_BEGIN_NAMESPACE @@ -74,7 +75,7 @@ public: protected: QScriptDebuggerCommandExecutor(QScriptDebuggerCommandExecutorPrivate &dd); - QScriptDebuggerCommandExecutorPrivate *d_ptr; + QScopedPointer d_ptr; private: Q_DECLARE_PRIVATE(QScriptDebuggerCommandExecutor) diff --git a/src/scripttools/debugging/qscriptdebuggerconsole.cpp b/src/scripttools/debugging/qscriptdebuggerconsole.cpp index 70bb8b1..09a32db 100644 --- a/src/scripttools/debugging/qscriptdebuggerconsole.cpp +++ b/src/scripttools/debugging/qscriptdebuggerconsole.cpp @@ -199,7 +199,6 @@ QScriptDebuggerConsole::QScriptDebuggerConsole() QScriptDebuggerConsole::~QScriptDebuggerConsole() { - delete d_ptr; } void QScriptDebuggerConsole::loadScriptedCommands(const QString &scriptsPath, diff --git a/src/scripttools/debugging/qscriptdebuggerconsole_p.h b/src/scripttools/debugging/qscriptdebuggerconsole_p.h index b5ebf44..a8c4163 100644 --- a/src/scripttools/debugging/qscriptdebuggerconsole_p.h +++ b/src/scripttools/debugging/qscriptdebuggerconsole_p.h @@ -54,6 +54,7 @@ // #include +#include #include "qscriptdebuggerconsolehistorianinterface_p.h" @@ -109,7 +110,7 @@ public: void bumpSessionId(); private: - QScriptDebuggerConsolePrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QScriptDebuggerConsole) Q_DISABLE_COPY(QScriptDebuggerConsole) diff --git a/src/scripttools/debugging/qscriptdebuggerconsolecommand.cpp b/src/scripttools/debugging/qscriptdebuggerconsolecommand.cpp index 6cbf58c..8e4bc06 100644 --- a/src/scripttools/debugging/qscriptdebuggerconsolecommand.cpp +++ b/src/scripttools/debugging/qscriptdebuggerconsolecommand.cpp @@ -72,7 +72,6 @@ QScriptDebuggerConsoleCommand::QScriptDebuggerConsoleCommand() QScriptDebuggerConsoleCommand::~QScriptDebuggerConsoleCommand() { - delete d_ptr; } QScriptDebuggerConsoleCommand::QScriptDebuggerConsoleCommand(QScriptDebuggerConsoleCommandPrivate &dd) diff --git a/src/scripttools/debugging/qscriptdebuggerconsolecommand_p.h b/src/scripttools/debugging/qscriptdebuggerconsolecommand_p.h index fbf285f..2ce3315 100644 --- a/src/scripttools/debugging/qscriptdebuggerconsolecommand_p.h +++ b/src/scripttools/debugging/qscriptdebuggerconsolecommand_p.h @@ -54,7 +54,7 @@ // #include - +#include #include QT_BEGIN_NAMESPACE @@ -91,7 +91,7 @@ public: protected: QScriptDebuggerConsoleCommand(QScriptDebuggerConsoleCommandPrivate &dd); - QScriptDebuggerConsoleCommandPrivate *d_ptr; + QScopedPointer d_ptr; private: Q_DECLARE_PRIVATE(QScriptDebuggerConsoleCommand) diff --git a/src/scripttools/debugging/qscriptdebuggerconsolecommandgroupdata.cpp b/src/scripttools/debugging/qscriptdebuggerconsolecommandgroupdata.cpp index 9cfac97..1d43dd0 100644 --- a/src/scripttools/debugging/qscriptdebuggerconsolecommandgroupdata.cpp +++ b/src/scripttools/debugging/qscriptdebuggerconsolecommandgroupdata.cpp @@ -90,7 +90,7 @@ QScriptDebuggerConsoleCommandGroupData::QScriptDebuggerConsoleCommandGroupData( QScriptDebuggerConsoleCommandGroupData::QScriptDebuggerConsoleCommandGroupData( const QScriptDebuggerConsoleCommandGroupData &other) - : d_ptr(other.d_ptr) + : d_ptr(other.d_ptr.data()) { if (d_ptr) d_ptr->ref.ref(); @@ -98,22 +98,12 @@ QScriptDebuggerConsoleCommandGroupData::QScriptDebuggerConsoleCommandGroupData( QScriptDebuggerConsoleCommandGroupData::~QScriptDebuggerConsoleCommandGroupData() { - if (d_ptr && !d_ptr->ref.deref()) { - delete d_ptr; - d_ptr = 0; - } } QScriptDebuggerConsoleCommandGroupData &QScriptDebuggerConsoleCommandGroupData::operator=( const QScriptDebuggerConsoleCommandGroupData &other) { - if (d_ptr == other.d_ptr) - return *this; - if (d_ptr && !d_ptr->ref.deref()) - delete d_ptr; - d_ptr = other.d_ptr; - if (d_ptr) - d_ptr->ref.ref(); + d_ptr.assign(other.d_ptr.data()); return *this; } diff --git a/src/scripttools/debugging/qscriptdebuggerconsolecommandgroupdata_p.h b/src/scripttools/debugging/qscriptdebuggerconsolecommandgroupdata_p.h index c32277f..9b0e281 100644 --- a/src/scripttools/debugging/qscriptdebuggerconsolecommandgroupdata_p.h +++ b/src/scripttools/debugging/qscriptdebuggerconsolecommandgroupdata_p.h @@ -54,7 +54,7 @@ // #include - +#include #include QT_BEGIN_NAMESPACE @@ -82,7 +82,7 @@ public: const QScriptDebuggerConsoleCommandGroupData &other); private: - QScriptDebuggerConsoleCommandGroupDataPrivate *d_ptr; + QScopedSharedPointer d_ptr; private: Q_DECLARE_PRIVATE(QScriptDebuggerConsoleCommandGroupData) diff --git a/src/scripttools/debugging/qscriptdebuggerconsolecommandmanager.cpp b/src/scripttools/debugging/qscriptdebuggerconsolecommandmanager.cpp index ef9687e..f22efc5 100644 --- a/src/scripttools/debugging/qscriptdebuggerconsolecommandmanager.cpp +++ b/src/scripttools/debugging/qscriptdebuggerconsolecommandmanager.cpp @@ -105,7 +105,6 @@ QScriptDebuggerConsoleCommandManager::QScriptDebuggerConsoleCommandManager() QScriptDebuggerConsoleCommandManager::~QScriptDebuggerConsoleCommandManager() { - delete d_ptr; } /*! diff --git a/src/scripttools/debugging/qscriptdebuggerconsolecommandmanager_p.h b/src/scripttools/debugging/qscriptdebuggerconsolecommandmanager_p.h index b5c9842..cebb999 100644 --- a/src/scripttools/debugging/qscriptdebuggerconsolecommandmanager_p.h +++ b/src/scripttools/debugging/qscriptdebuggerconsolecommandmanager_p.h @@ -54,7 +54,7 @@ // #include - +#include #include #include @@ -86,7 +86,7 @@ public: QStringList completions(const QString &prefix) const; private: - QScriptDebuggerConsoleCommandManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QScriptDebuggerConsoleCommandManager) }; diff --git a/src/scripttools/debugging/qscriptdebuggerevent.cpp b/src/scripttools/debugging/qscriptdebuggerevent.cpp index 9d971a9..418e8fa 100644 --- a/src/scripttools/debugging/qscriptdebuggerevent.cpp +++ b/src/scripttools/debugging/qscriptdebuggerevent.cpp @@ -97,7 +97,6 @@ QScriptDebuggerEvent::QScriptDebuggerEvent(const QScriptDebuggerEvent &other) QScriptDebuggerEvent::~QScriptDebuggerEvent() { - delete d_ptr; } QScriptDebuggerEvent &QScriptDebuggerEvent::operator=(const QScriptDebuggerEvent &other) @@ -276,7 +275,7 @@ bool QScriptDebuggerEvent::operator!=(const QScriptDebuggerEvent &other) const */ QDataStream &operator<<(QDataStream &out, const QScriptDebuggerEvent &event) { - const QScriptDebuggerEventPrivate *d = event.d_ptr; + const QScriptDebuggerEventPrivate *d = event.d_ptr.data(); out << (quint32)d->type; out << (qint32)d->attributes.size(); QHash::const_iterator it; @@ -296,7 +295,7 @@ QDataStream &operator<<(QDataStream &out, const QScriptDebuggerEvent &event) */ QDataStream &operator>>(QDataStream &in, QScriptDebuggerEvent &event) { - QScriptDebuggerEventPrivate *d = event.d_ptr; + QScriptDebuggerEventPrivate *d = event.d_ptr.data(); quint32 type; in >> type; diff --git a/src/scripttools/debugging/qscriptdebuggerevent_p.h b/src/scripttools/debugging/qscriptdebuggerevent_p.h index d9c073c..0cfde4f 100644 --- a/src/scripttools/debugging/qscriptdebuggerevent_p.h +++ b/src/scripttools/debugging/qscriptdebuggerevent_p.h @@ -57,6 +57,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -137,7 +138,7 @@ public: bool operator!=(const QScriptDebuggerEvent &other) const; private: - QScriptDebuggerEventPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QScriptDebuggerEvent) }; diff --git a/src/scripttools/debugging/qscriptdebuggerfrontend.cpp b/src/scripttools/debugging/qscriptdebuggerfrontend.cpp index ced20b1..4d0a8b4 100644 --- a/src/scripttools/debugging/qscriptdebuggerfrontend.cpp +++ b/src/scripttools/debugging/qscriptdebuggerfrontend.cpp @@ -143,7 +143,6 @@ QScriptDebuggerFrontend::QScriptDebuggerFrontend() QScriptDebuggerFrontend::~QScriptDebuggerFrontend() { - delete d_ptr; } QScriptDebuggerFrontend::QScriptDebuggerFrontend(QScriptDebuggerFrontendPrivate &dd) diff --git a/src/scripttools/debugging/qscriptdebuggerfrontend_p.h b/src/scripttools/debugging/qscriptdebuggerfrontend_p.h index a763463..bed0f85 100644 --- a/src/scripttools/debugging/qscriptdebuggerfrontend_p.h +++ b/src/scripttools/debugging/qscriptdebuggerfrontend_p.h @@ -54,7 +54,7 @@ // #include - +#include #include #include "qscriptdebuggercommandschedulerinterface_p.h" @@ -90,7 +90,7 @@ protected: protected: QScriptDebuggerFrontend(QScriptDebuggerFrontendPrivate &dd); - QScriptDebuggerFrontendPrivate *d_ptr; + QScopedPointer d_ptr; private: Q_DECLARE_PRIVATE(QScriptDebuggerFrontend) diff --git a/src/scripttools/debugging/qscriptdebuggerjob.cpp b/src/scripttools/debugging/qscriptdebuggerjob.cpp index 109c805..20d17bb 100644 --- a/src/scripttools/debugging/qscriptdebuggerjob.cpp +++ b/src/scripttools/debugging/qscriptdebuggerjob.cpp @@ -85,7 +85,6 @@ QScriptDebuggerJob::QScriptDebuggerJob(QScriptDebuggerJobPrivate &dd) QScriptDebuggerJob::~QScriptDebuggerJob() { - delete d_ptr; } void QScriptDebuggerJob::finish() diff --git a/src/scripttools/debugging/qscriptdebuggerjob_p.h b/src/scripttools/debugging/qscriptdebuggerjob_p.h index e84d6d5..2f7305f 100644 --- a/src/scripttools/debugging/qscriptdebuggerjob_p.h +++ b/src/scripttools/debugging/qscriptdebuggerjob_p.h @@ -54,6 +54,7 @@ // #include +#include QT_BEGIN_NAMESPACE @@ -76,7 +77,7 @@ public: protected: QScriptDebuggerJob(QScriptDebuggerJobPrivate &dd); - QScriptDebuggerJobPrivate *d_ptr; + QScopedPointer d_ptr; private: Q_DECLARE_PRIVATE(QScriptDebuggerJob) diff --git a/src/scripttools/debugging/qscriptdebuggerresponse.cpp b/src/scripttools/debugging/qscriptdebuggerresponse.cpp index 82bfff2..bf24846 100644 --- a/src/scripttools/debugging/qscriptdebuggerresponse.cpp +++ b/src/scripttools/debugging/qscriptdebuggerresponse.cpp @@ -101,7 +101,6 @@ QScriptDebuggerResponse::QScriptDebuggerResponse(const QScriptDebuggerResponse & QScriptDebuggerResponse::~QScriptDebuggerResponse() { - delete d_ptr; } QScriptDebuggerResponse &QScriptDebuggerResponse::operator=(const QScriptDebuggerResponse &other) @@ -320,7 +319,7 @@ bool QScriptDebuggerResponse::operator!=(const QScriptDebuggerResponse &other) c */ QDataStream &operator<<(QDataStream &out, const QScriptDebuggerResponse &response) { - const QScriptDebuggerResponsePrivate *d = response.d_ptr; + const QScriptDebuggerResponsePrivate *d = response.d_ptr.data(); out << (quint32)d->error; out << d->result; out << d->async; @@ -336,7 +335,7 @@ QDataStream &operator<<(QDataStream &out, const QScriptDebuggerResponse &respons */ QDataStream &operator>>(QDataStream &in, QScriptDebuggerResponse &response) { - QScriptDebuggerResponsePrivate *d = response.d_ptr; + QScriptDebuggerResponsePrivate *d = response.d_ptr.data(); quint32 error; in >> error; diff --git a/src/scripttools/debugging/qscriptdebuggerresponse_p.h b/src/scripttools/debugging/qscriptdebuggerresponse_p.h index dd65ffd..4fa1731 100644 --- a/src/scripttools/debugging/qscriptdebuggerresponse_p.h +++ b/src/scripttools/debugging/qscriptdebuggerresponse_p.h @@ -54,7 +54,7 @@ // #include - +#include #include #include @@ -127,7 +127,7 @@ public: bool operator!=(const QScriptDebuggerResponse &other) const; private: - QScriptDebuggerResponsePrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QScriptDebuggerResponse) }; diff --git a/src/scripttools/debugging/qscriptdebuggervalue.cpp b/src/scripttools/debugging/qscriptdebuggervalue.cpp index bb41ee8..b92cbd2 100644 --- a/src/scripttools/debugging/qscriptdebuggervalue.cpp +++ b/src/scripttools/debugging/qscriptdebuggervalue.cpp @@ -94,7 +94,7 @@ QScriptDebuggerValue::QScriptDebuggerValue(const QScriptValue &value) : d_ptr(0) { if (value.isValid()) { - d_ptr = new QScriptDebuggerValuePrivate; + d_ptr.reset(new QScriptDebuggerValuePrivate); if (value.isUndefined()) d_ptr->type = UndefinedValue; else if (value.isNull()) @@ -157,7 +157,7 @@ QScriptDebuggerValue::QScriptDebuggerValue(ValueType type) } QScriptDebuggerValue::QScriptDebuggerValue(const QScriptDebuggerValue &other) - : d_ptr(other.d_ptr) + : d_ptr(other.d_ptr.data()) { if (d_ptr) d_ptr->ref.ref(); @@ -165,21 +165,11 @@ QScriptDebuggerValue::QScriptDebuggerValue(const QScriptDebuggerValue &other) QScriptDebuggerValue::~QScriptDebuggerValue() { - if (d_ptr && !d_ptr->ref.deref()) { - delete d_ptr; - d_ptr = 0; - } } QScriptDebuggerValue &QScriptDebuggerValue::operator=(const QScriptDebuggerValue &other) { - if (d_ptr == other.d_ptr) - return *this; - if (d_ptr && !d_ptr->ref.deref()) - delete d_ptr; - d_ptr = other.d_ptr; - if (d_ptr) - d_ptr->ref.ref(); + d_ptr.assign(other.d_ptr.data()); return *this; } diff --git a/src/scripttools/debugging/qscriptdebuggervalue_p.h b/src/scripttools/debugging/qscriptdebuggervalue_p.h index 0142de0..c082bf3 100644 --- a/src/scripttools/debugging/qscriptdebuggervalue_p.h +++ b/src/scripttools/debugging/qscriptdebuggervalue_p.h @@ -54,7 +54,7 @@ // #include - +#include #include QT_BEGIN_NAMESPACE @@ -103,7 +103,7 @@ public: bool operator!=(const QScriptDebuggerValue &other) const; private: - QScriptDebuggerValuePrivate *d_ptr; + QScopedSharedPointer d_ptr; Q_DECLARE_PRIVATE(QScriptDebuggerValue) }; diff --git a/src/scripttools/debugging/qscriptdebuggervalueproperty.cpp b/src/scripttools/debugging/qscriptdebuggervalueproperty.cpp index 723e304..63f820b 100644 --- a/src/scripttools/debugging/qscriptdebuggervalueproperty.cpp +++ b/src/scripttools/debugging/qscriptdebuggervalueproperty.cpp @@ -105,7 +105,7 @@ QScriptDebuggerValueProperty::QScriptDebuggerValueProperty(const QString &name, Constructs a QScriptDebuggerValueProperty that is a copy of the \a other property. */ QScriptDebuggerValueProperty::QScriptDebuggerValueProperty(const QScriptDebuggerValueProperty &other) - : d_ptr(other.d_ptr) + : d_ptr(other.d_ptr.data()) { if (d_ptr) d_ptr->ref.ref(); @@ -116,10 +116,6 @@ QScriptDebuggerValueProperty::QScriptDebuggerValueProperty(const QScriptDebugger */ QScriptDebuggerValueProperty::~QScriptDebuggerValueProperty() { - if (d_ptr && !d_ptr->ref.deref()) { - delete d_ptr; - d_ptr = 0; - } } /*! @@ -127,13 +123,7 @@ QScriptDebuggerValueProperty::~QScriptDebuggerValueProperty() */ QScriptDebuggerValueProperty &QScriptDebuggerValueProperty::operator=(const QScriptDebuggerValueProperty &other) { - if (d_ptr == other.d_ptr) - return *this; - if (d_ptr && !d_ptr->ref.deref()) - delete d_ptr; - d_ptr = other.d_ptr; - if (d_ptr) - d_ptr->ref.ref(); + d_ptr.assign(other.d_ptr.data()); return *this; } diff --git a/src/scripttools/debugging/qscriptdebuggervalueproperty_p.h b/src/scripttools/debugging/qscriptdebuggervalueproperty_p.h index f67bafd..be27ebd 100644 --- a/src/scripttools/debugging/qscriptdebuggervalueproperty_p.h +++ b/src/scripttools/debugging/qscriptdebuggervalueproperty_p.h @@ -55,6 +55,7 @@ #include #include +#include #include QT_BEGIN_NAMESPACE @@ -85,7 +86,7 @@ public: bool isValid() const; private: - QScriptDebuggerValuePropertyPrivate *d_ptr; + QScopedSharedPointer d_ptr; Q_DECLARE_PRIVATE(QScriptDebuggerValueProperty) }; diff --git a/src/scripttools/debugging/qscriptscriptdata.cpp b/src/scripttools/debugging/qscriptscriptdata.cpp index 068748f..a4f8cd7 100644 --- a/src/scripttools/debugging/qscriptscriptdata.cpp +++ b/src/scripttools/debugging/qscriptscriptdata.cpp @@ -98,7 +98,7 @@ QScriptScriptData::QScriptScriptData(const QString &contents, const QString &fil } QScriptScriptData::QScriptScriptData(const QScriptScriptData &other) - : d_ptr(other.d_ptr) + : d_ptr(other.d_ptr.data()) { if (d_ptr) d_ptr->ref.ref(); @@ -106,21 +106,11 @@ QScriptScriptData::QScriptScriptData(const QScriptScriptData &other) QScriptScriptData::~QScriptScriptData() { - if (d_ptr && !d_ptr->ref.deref()) { - delete d_ptr; - d_ptr = 0; - } } QScriptScriptData &QScriptScriptData::operator=(const QScriptScriptData &other) { - if (d_ptr == other.d_ptr) - return *this; - if (d_ptr && !d_ptr->ref.deref()) - delete d_ptr; - d_ptr = other.d_ptr; - if (d_ptr) - d_ptr->ref.ref(); + d_ptr.assign(other.d_ptr.data()); return *this; } @@ -191,7 +181,7 @@ bool QScriptScriptData::operator!=(const QScriptScriptData &other) const QDataStream &operator<<(QDataStream &out, const QScriptScriptData &data) { - const QScriptScriptDataPrivate *d = data.d_ptr; + const QScriptScriptDataPrivate *d = data.d_ptr.data(); if (d) { out << d->contents; out << d->fileName; @@ -207,10 +197,10 @@ QDataStream &operator<<(QDataStream &out, const QScriptScriptData &data) QDataStream &operator>>(QDataStream &in, QScriptScriptData &data) { if (!data.d_ptr) { - data.d_ptr = new QScriptScriptDataPrivate(); + data.d_ptr.reset(new QScriptScriptDataPrivate()); data.d_ptr->ref.ref(); } - QScriptScriptDataPrivate *d = data.d_ptr; + QScriptScriptDataPrivate *d = data.d_ptr.data(); in >> d->contents; in >> d->fileName; qint32 ln; diff --git a/src/scripttools/debugging/qscriptscriptdata_p.h b/src/scripttools/debugging/qscriptscriptdata_p.h index 50cad32..e871c2c 100644 --- a/src/scripttools/debugging/qscriptscriptdata_p.h +++ b/src/scripttools/debugging/qscriptscriptdata_p.h @@ -54,7 +54,7 @@ // #include - +#include #include #include @@ -91,7 +91,7 @@ public: bool operator!=(const QScriptScriptData &other) const; private: - QScriptScriptDataPrivate *d_ptr; + QScopedSharedPointer d_ptr; Q_DECLARE_PRIVATE(QScriptScriptData) }; diff --git a/src/scripttools/debugging/qscriptstdmessagehandler.cpp b/src/scripttools/debugging/qscriptstdmessagehandler.cpp index 4e0f12c..6742554 100644 --- a/src/scripttools/debugging/qscriptstdmessagehandler.cpp +++ b/src/scripttools/debugging/qscriptstdmessagehandler.cpp @@ -66,7 +66,6 @@ QScriptStdMessageHandler::QScriptStdMessageHandler() QScriptStdMessageHandler::~QScriptStdMessageHandler() { - delete d_ptr; } void QScriptStdMessageHandler::message(QtMsgType type, const QString &text, diff --git a/src/scripttools/debugging/qscriptstdmessagehandler_p.h b/src/scripttools/debugging/qscriptstdmessagehandler_p.h index 8b75f6a..06d680b 100644 --- a/src/scripttools/debugging/qscriptstdmessagehandler_p.h +++ b/src/scripttools/debugging/qscriptstdmessagehandler_p.h @@ -53,6 +53,8 @@ // We mean it. // +#include + #include "qscriptmessagehandlerinterface_p.h" QT_BEGIN_NAMESPACE @@ -71,7 +73,7 @@ public: const QVariant &data = QVariant()); private: - QScriptStdMessageHandlerPrivate *d_ptr; + QScopedPointer d_ptr; private: Q_DECLARE_PRIVATE(QScriptStdMessageHandler) diff --git a/src/scripttools/debugging/qscriptvalueproperty.cpp b/src/scripttools/debugging/qscriptvalueproperty.cpp index 245edc3..75cfdd7 100644 --- a/src/scripttools/debugging/qscriptvalueproperty.cpp +++ b/src/scripttools/debugging/qscriptvalueproperty.cpp @@ -95,7 +95,7 @@ QScriptValueProperty::QScriptValueProperty(const QString &name, Constructs a QScriptValueProperty that is a copy of the \a other property. */ QScriptValueProperty::QScriptValueProperty(const QScriptValueProperty &other) - : d_ptr(other.d_ptr) + : d_ptr(other.d_ptr.data()) { if (d_ptr) d_ptr->ref.ref(); @@ -106,10 +106,6 @@ QScriptValueProperty::QScriptValueProperty(const QScriptValueProperty &other) */ QScriptValueProperty::~QScriptValueProperty() { - if (d_ptr && !d_ptr->ref.deref()) { - delete d_ptr; - d_ptr = 0; - } } /*! @@ -117,13 +113,7 @@ QScriptValueProperty::~QScriptValueProperty() */ QScriptValueProperty &QScriptValueProperty::operator=(const QScriptValueProperty &other) { - if (d_ptr == other.d_ptr) - return *this; - if (d_ptr && !d_ptr->ref.deref()) - delete d_ptr; - d_ptr = other.d_ptr; - if (d_ptr) - d_ptr->ref.ref(); + d_ptr.assign(other.d_ptr.data()); return *this; } diff --git a/src/scripttools/debugging/qscriptvalueproperty_p.h b/src/scripttools/debugging/qscriptvalueproperty_p.h index 938ab83..ca6980f 100644 --- a/src/scripttools/debugging/qscriptvalueproperty_p.h +++ b/src/scripttools/debugging/qscriptvalueproperty_p.h @@ -55,6 +55,7 @@ #include #include +#include #include QT_BEGIN_NAMESPACE @@ -81,7 +82,7 @@ public: bool isValid() const; private: - QScriptValuePropertyPrivate *d_ptr; + QScopedSharedPointer d_ptr; Q_DECLARE_PRIVATE(QScriptValueProperty) }; diff --git a/src/svg/qgraphicssvgitem.h b/src/svg/qgraphicssvgitem.h index c6ab0f7..940ce9b 100644 --- a/src/svg/qgraphicssvgitem.h +++ b/src/svg/qgraphicssvgitem.h @@ -41,8 +41,8 @@ #ifndef QGRAPHICSSVGITEM_H #define QGRAPHICSSVGITEM_H -#include #include +#include #ifndef QT_NO_GRAPHICSSVGITEM @@ -89,9 +89,9 @@ private: // Q_DECLARE_PRIVATE_WITH_BASE(QGraphicsSvgItem, QObject) inline QGraphicsSvgItemPrivate *d_func() - { return reinterpret_cast(QObject::d_ptr); } + { return reinterpret_cast(QObject::d_ptr.data()); } inline const QGraphicsSvgItemPrivate *d_func() const - { return reinterpret_cast(QObject::d_ptr); } + { return reinterpret_cast(QObject::d_ptr.data()); } friend class QGraphicsSvgItemPrivate; Q_PRIVATE_SLOT(d_func(), void _q_repaintItem()) diff --git a/src/svg/qsvggenerator.cpp b/src/svg/qsvggenerator.cpp index fd4c875..5052ec7 100644 --- a/src/svg/qsvggenerator.cpp +++ b/src/svg/qsvggenerator.cpp @@ -567,7 +567,6 @@ QSvgGenerator::~QSvgGenerator() if (d->owns_iodevice) delete d->engine->outputDevice(); delete d->engine; - delete d_ptr; } /*! diff --git a/src/svg/qsvggenerator.h b/src/svg/qsvggenerator.h index 723a220..1d24324 100644 --- a/src/svg/qsvggenerator.h +++ b/src/svg/qsvggenerator.h @@ -49,6 +49,7 @@ #include #include #include +#include QT_BEGIN_HEADER @@ -100,7 +101,7 @@ protected: int metric(QPaintDevice::PaintDeviceMetric metric) const; private: - QSvgGeneratorPrivate *d_ptr; + QScopedPointer d_ptr; }; QT_END_NAMESPACE diff --git a/src/testlib/3rdparty/cycle_p.h b/src/testlib/3rdparty/cycle_p.h index 547fdc1..a292423 100644 --- a/src/testlib/3rdparty/cycle_p.h +++ b/src/testlib/3rdparty/cycle_p.h @@ -190,6 +190,7 @@ INLINE_ELAPSED(__inline__) #endif /* Visual C++ -- thanks to Morten Nissov for his help with this */ +#if defined(_MSC_VER) #if _MSC_VER >= 1200 && (_M_IX86 >= 500 || (defined(_WIN32_WCE) && defined(_X86_))) && !defined(HAVE_TICK_COUNTER) #include typedef LARGE_INTEGER CycleCounterTicks; @@ -215,6 +216,7 @@ static __inline double elapsed(CycleCounterTicks t1, CycleCounterTicks t0) #define HAVE_TICK_COUNTER #define TIME_MIN 5000.0 /* unreliable pentium IV cycle counter */ #endif +#endif #if _MSC_VER >= 1400 && defined(_WIN32_WCE) && !defined(HAVE_TICK_COUNTER) #include diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index b676012..38e63cf 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -1437,7 +1437,7 @@ int QTest::qExec(QObject *testObject, int argc, char **argv) } #endif - #ifndef QT_NO_EXCEPTIONS +#ifndef QT_NO_EXCEPTIONS } catch (...) { QTestResult::addFailure("Caught unhandled exception", __FILE__, __LINE__); if (QTestResult::currentTestFunction()) { @@ -1451,13 +1451,13 @@ int QTest::qExec(QObject *testObject, int argc, char **argv) IOPMAssertionRelease(powerID); } #endif - #ifdef Q_OS_WIN +//# ifdef Q_OS_WIN // rethrow exception to make debugging easier throw; - #endif - return -1; +//# endif + return 1; } - #endif +# endif currentTestObject = 0; #ifdef QT_MAC_USE_COCOA diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp index 550abc9..5e2c74b 100644 --- a/src/xml/dom/qdom.cpp +++ b/src/xml/dom/qdom.cpp @@ -512,8 +512,8 @@ public: bool setContent(QXmlInputSource *source, QXmlReader *reader, QString *errorMsg, int *errorLine, int *errorColumn); // Attributes - QDomDocumentTypePrivate* doctype() { return type; }; - QDomImplementationPrivate* implementation() { return impl; }; + QDomDocumentTypePrivate* doctype() { return type.data(); }; + QDomImplementationPrivate* implementation() { return impl.data(); }; QDomElementPrivate* documentElement(); // Factories @@ -537,8 +537,8 @@ public: void clear(); // Variables - QDomImplementationPrivate* impl; - QDomDocumentTypePrivate* type; + QScopedSharedPointer impl; + QScopedSharedPointer type; void saveDocument(QTextStream& stream, const int indent, QDomNode::EncodingPolicy encUsed) const; @@ -3060,7 +3060,7 @@ QDomNamedNodeMapPrivate::~QDomNamedNodeMapPrivate() QDomNamedNodeMapPrivate* QDomNamedNodeMapPrivate::clone(QDomNodePrivate* p) { - QDomNamedNodeMapPrivate* m = new QDomNamedNodeMapPrivate(p); + QScopedPointer m(new QDomNamedNodeMapPrivate(p)); m->readonly = readonly; m->appendToParent = appendToParent; @@ -3073,7 +3073,7 @@ QDomNamedNodeMapPrivate* QDomNamedNodeMapPrivate::clone(QDomNodePrivate* p) // we are no longer interested in ownership m->ref.deref(); - return m; + return m.take(); } void QDomNamedNodeMapPrivate::clearMap() @@ -3499,13 +3499,18 @@ QDomDocumentTypePrivate::~QDomDocumentTypePrivate() void QDomDocumentTypePrivate::init() { entities = new QDomNamedNodeMapPrivate(this); - notations = new QDomNamedNodeMapPrivate(this); - publicId.clear(); - systemId.clear(); - internalSubset.clear(); - - entities->setAppendToParent(true); - notations->setAppendToParent(true); + QT_TRY { + notations = new QDomNamedNodeMapPrivate(this); + publicId.clear(); + systemId.clear(); + internalSubset.clear(); + + entities->setAppendToParent(true); + notations->setAppendToParent(true); + } QT_CATCH(...) { + delete entities; + QT_RETHROW; + } } QDomNodePrivate* QDomDocumentTypePrivate::cloneNode(bool deep) @@ -6148,8 +6153,8 @@ QDomDocumentPrivate::QDomDocumentPrivate() : QDomNodePrivate(0), nodeListTime(1) { - impl = new QDomImplementationPrivate; - type = new QDomDocumentTypePrivate(this, this); + impl.reset(new QDomImplementationPrivate); + type.reset(new QDomDocumentTypePrivate(this, this)); name = QLatin1String("#document"); } @@ -6158,8 +6163,8 @@ QDomDocumentPrivate::QDomDocumentPrivate(const QString& aname) : QDomNodePrivate(0), nodeListTime(1) { - impl = new QDomImplementationPrivate; - type = new QDomDocumentTypePrivate(this, this); + impl.reset(new QDomImplementationPrivate); + type.reset(new QDomDocumentTypePrivate(this, this)); type->name = aname; name = QLatin1String("#document"); @@ -6169,12 +6174,11 @@ QDomDocumentPrivate::QDomDocumentPrivate(QDomDocumentTypePrivate* dt) : QDomNodePrivate(0), nodeListTime(1) { - impl = new QDomImplementationPrivate; + impl.reset(new QDomImplementationPrivate); if (dt != 0) { - type = dt; - type->ref.ref(); + type.assign(dt); } else { - type = new QDomDocumentTypePrivate(this, this); + type.reset(new QDomDocumentTypePrivate(this, this)); } name = QLatin1String("#document"); @@ -6184,31 +6188,19 @@ QDomDocumentPrivate::QDomDocumentPrivate(QDomDocumentPrivate* n, bool deep) : QDomNodePrivate(n, deep), nodeListTime(1) { - impl = n->impl->clone(); - // Reference count is down to 0, so we set it to 1 here. - impl->ref.ref(); - type = (QDomDocumentTypePrivate*)n->type->cloneNode(); + impl.assign(n->impl->clone()); + type.assign((QDomDocumentTypePrivate*)n->type->cloneNode()); type->setParent(this); - // Reference count is down to 0, so we set it to 1 here. - type->ref.ref(); } QDomDocumentPrivate::~QDomDocumentPrivate() { - if (!impl->ref.deref()) - delete impl; - if (!type->ref.deref()) - delete type; } void QDomDocumentPrivate::clear() { - if (!impl->ref.deref()) - delete impl; - if (!type->ref.deref()) - delete type; - impl = 0; - type = 0; + impl.assign(0); + type.assign(0); QDomNodePrivate::clear(); } @@ -6229,8 +6221,8 @@ bool QDomDocumentPrivate::setContent(QXmlInputSource *source, bool namespaceProc bool QDomDocumentPrivate::setContent(QXmlInputSource *source, QXmlReader *reader, QString *errorMsg, int *errorLine, int *errorColumn) { clear(); - impl = new QDomImplementationPrivate; - type = new QDomDocumentTypePrivate(this, this); + impl.reset(new QDomImplementationPrivate); + type.reset(new QDomDocumentTypePrivate(this, this)); bool namespaceProcessing = reader->feature(QLatin1String("http://xml.org/sax/features/namespaces")) && !reader->feature(QLatin1String("http://xml.org/sax/features/namespace-prefixes")); @@ -7448,20 +7440,22 @@ bool QDomHandler::characters(const QString& ch) if (node == doc) return false; - QDomNodePrivate *n; + QScopedPointer n; if (cdata) { - n = doc->createCDATASection(ch); + n.reset(doc->createCDATASection(ch)); } else if (!entityName.isEmpty()) { - QDomEntityPrivate* e = new QDomEntityPrivate(doc, 0, entityName, - QString(), QString(), QString()); + QScopedPointer e(new QDomEntityPrivate(doc, 0, entityName, + QString(), QString(), QString())); e->value = ch; - doc->doctype()->appendChild(e); - n = doc->createEntityReference(entityName); + doc->doctype()->appendChild(e.data()); + e.take(); + n.reset(doc->createEntityReference(entityName)); } else { - n = doc->createTextNode(ch); + n.reset(doc->createTextNode(ch)); } n->setLocation(locator->lineNumber(), locator->columnNumber()); - node->appendChild(n); + node->appendChild(n.data()); + n.take(); return true; } diff --git a/src/xml/sax/qxml.cpp b/src/xml/sax/qxml.cpp index ba68636..1655642 100644 --- a/src/xml/sax/qxml.cpp +++ b/src/xml/sax/qxml.cpp @@ -262,10 +262,11 @@ class QXmlDefaultHandlerPrivate class QXmlSimpleReaderPrivate { +public: + ~QXmlSimpleReaderPrivate(); private: // functions - QXmlSimpleReaderPrivate(); - ~QXmlSimpleReaderPrivate(); + QXmlSimpleReaderPrivate(QXmlSimpleReader *reader); void initIncrementalParsing(); // used to determine if elements are correctly nested @@ -350,7 +351,7 @@ private: bool contentCharDataRead; // helper classes - QXmlLocator *locator; + QScopedPointer locator; QXmlNamespaceSupport namespaceSupport; // error string @@ -545,8 +546,8 @@ private: QXmlParseException::QXmlParseException(const QString& name, int c, int l, const QString& p, const QString& s) + : d(new QXmlParseExceptionPrivate) { - d = new QXmlParseExceptionPrivate; d->msg = name; d->column = c; d->line = l; @@ -559,7 +560,6 @@ QXmlParseException::QXmlParseException(const QString& name, int c, int l, */ QXmlParseException::~QXmlParseException() { - delete d; } /*! @@ -928,8 +928,9 @@ void QXmlNamespaceSupport::popContext() */ void QXmlNamespaceSupport::reset() { + QXmlNamespaceSupportPrivate *newD = new QXmlNamespaceSupportPrivate; delete d; - d = new QXmlNamespaceSupportPrivate; + d = newD; } @@ -1260,18 +1261,23 @@ void QXmlInputSource::init() { d = new QXmlInputSourcePrivate; - d->inputDevice = 0; - d->inputStream = 0; + QT_TRY { + d->inputDevice = 0; + d->inputStream = 0; - setData(QString()); + setData(QString()); #ifndef QT_NO_TEXTCODEC - d->encMapper = 0; + d->encMapper = 0; #endif - d->nextReturnedEndOfData = true; // first call to next() will call fetchData() + d->nextReturnedEndOfData = true; // first call to next() will call fetchData() - d->encodingDeclBytes.clear(); - d->encodingDeclChars.clear(); - d->lookingForEncodingDecl = true; + d->encodingDeclBytes.clear(); + d->encodingDeclChars.clear(); + d->lookingForEncodingDecl = true; + } QT_CATCH(...) { + delete(d); + QT_RETHROW; + } } /*! @@ -2715,9 +2721,24 @@ inline void QXmlSimpleReaderPrivate::refClear() refValueLen = 0; refArrayPos = 0; } -QXmlSimpleReaderPrivate::QXmlSimpleReaderPrivate() +QXmlSimpleReaderPrivate::QXmlSimpleReaderPrivate(QXmlSimpleReader *reader) { + q_ptr = reader; parseStack = 0; + + locator.reset(new QXmlSimpleReaderLocator(reader)); + entityRes = 0; + dtdHnd = 0; + contentHnd = 0; + errorHnd = 0; + lexicalHnd = 0; + declHnd = 0; + + // default feature settings + useNamespaces = true; + useNamespacePrefixes = false; + reportWhitespaceCharData = true; + reportEntities = false; } QXmlSimpleReaderPrivate::~QXmlSimpleReaderPrivate() @@ -2727,8 +2748,10 @@ QXmlSimpleReaderPrivate::~QXmlSimpleReaderPrivate() void QXmlSimpleReaderPrivate::initIncrementalParsing() { - delete parseStack; - parseStack = new QStack; + if( parseStack ) + parseStack->clear(); + else + parseStack = new QStack; } /********************************************* @@ -3101,25 +3124,8 @@ static NameChar determineNameChar(QChar ch) */ QXmlSimpleReader::QXmlSimpleReader() + : d_ptr(new QXmlSimpleReaderPrivate(this)) { - d_ptr = new QXmlSimpleReaderPrivate(); - Q_D(QXmlSimpleReader); - d->q_ptr = this; - - d->locator = new QXmlSimpleReaderLocator(this); - - d->entityRes = 0; - d->dtdHnd = 0; - d->contentHnd = 0; - d->errorHnd = 0; - d->lexicalHnd = 0; - d->declHnd = 0; - - // default feature settings - d->useNamespaces = true; - d->useNamespacePrefixes = false; - d->reportWhitespaceCharData = true; - d->reportEntities = false; } /*! @@ -3127,9 +3133,6 @@ QXmlSimpleReader::QXmlSimpleReader() */ QXmlSimpleReader::~QXmlSimpleReader() { - Q_D(QXmlSimpleReader); - delete d->locator; - delete d; } /*! @@ -3412,7 +3415,7 @@ bool QXmlSimpleReader::parse(const QXmlInputSource *input, bool incremental) // call the handler if (d->contentHnd) { - d->contentHnd->setDocumentLocator(d->locator); + d->contentHnd->setDocumentLocator(d->locator.data()); if (!d->contentHnd->startDocument()) { d->reportParseError(d->contentHnd->errorString()); d->tags.clear(); diff --git a/src/xml/sax/qxml.h b/src/xml/sax/qxml.h index e0165d3..8e3eb25 100644 --- a/src/xml/sax/qxml.h +++ b/src/xml/sax/qxml.h @@ -47,6 +47,7 @@ #include #include #include +#include QT_BEGIN_HEADER @@ -202,7 +203,7 @@ public: QString message() const; private: - QXmlParseExceptionPrivate *d; + QScopedPointer d; }; @@ -271,7 +272,7 @@ public: private: Q_DISABLE_COPY(QXmlSimpleReader) Q_DECLARE_PRIVATE(QXmlSimpleReader) - QXmlSimpleReaderPrivate* d_ptr; + QScopedPointer d_ptr; friend class QXmlSimpleReaderLocator; }; diff --git a/src/xmlpatterns/api/qabstractxmlnodemodel.cpp b/src/xmlpatterns/api/qabstractxmlnodemodel.cpp index 0caa8c4..12ce6a7 100644 --- a/src/xmlpatterns/api/qabstractxmlnodemodel.cpp +++ b/src/xmlpatterns/api/qabstractxmlnodemodel.cpp @@ -302,7 +302,6 @@ QAbstractXmlNodeModel::QAbstractXmlNodeModel(QAbstractXmlNodeModelPrivate *d) : */ QAbstractXmlNodeModel::~QAbstractXmlNodeModel() { - delete d_ptr; } /*! diff --git a/src/xmlpatterns/api/qabstractxmlnodemodel.h b/src/xmlpatterns/api/qabstractxmlnodemodel.h index 6c9574c..9b5b3dd 100644 --- a/src/xmlpatterns/api/qabstractxmlnodemodel.h +++ b/src/xmlpatterns/api/qabstractxmlnodemodel.h @@ -44,6 +44,7 @@ #include #include +#include QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -339,7 +340,7 @@ protected: return QXmlNodeModelIndex::create(data, this, additionalData); } - QAbstractXmlNodeModelPrivate *d_ptr; + QScopedPointer d_ptr; private: friend class QPatternist::ItemMappingIterator >; friend class QPatternist::SequenceMappingIterator; diff --git a/src/xmlpatterns/api/qabstractxmlreceiver.cpp b/src/xmlpatterns/api/qabstractxmlreceiver.cpp index ddd01e4..4253ce0 100644 --- a/src/xmlpatterns/api/qabstractxmlreceiver.cpp +++ b/src/xmlpatterns/api/qabstractxmlreceiver.cpp @@ -224,7 +224,6 @@ QAbstractXmlReceiver::QAbstractXmlReceiver() : d_ptr(0) */ QAbstractXmlReceiver::~QAbstractXmlReceiver() { - delete d_ptr; } /*! diff --git a/src/xmlpatterns/api/qabstractxmlreceiver.h b/src/xmlpatterns/api/qabstractxmlreceiver.h index 355576a..270b9da 100644 --- a/src/xmlpatterns/api/qabstractxmlreceiver.h +++ b/src/xmlpatterns/api/qabstractxmlreceiver.h @@ -43,6 +43,7 @@ #define QABSTRACTXMLRECEIVER_H #include +#include #include QT_BEGIN_HEADER @@ -90,7 +91,7 @@ public: protected: QAbstractXmlReceiver(QAbstractXmlReceiverPrivate *d); - QAbstractXmlReceiverPrivate *d_ptr; + QScopedPointer d_ptr; void sendAsNode(const QPatternist::Item &outputItem); private: diff --git a/src/xmlpatterns/api/qxmlresultitems.cpp b/src/xmlpatterns/api/qxmlresultitems.cpp index a2253c9..652d931 100644 --- a/src/xmlpatterns/api/qxmlresultitems.cpp +++ b/src/xmlpatterns/api/qxmlresultitems.cpp @@ -85,7 +85,6 @@ QXmlResultItems::QXmlResultItems() : d_ptr(new QXmlResultItemsPrivate()) */ QXmlResultItems::~QXmlResultItems() { - delete d_ptr; } /*! diff --git a/src/xmlpatterns/api/qxmlresultitems.h b/src/xmlpatterns/api/qxmlresultitems.h index aeb7d2c..5484616 100644 --- a/src/xmlpatterns/api/qxmlresultitems.h +++ b/src/xmlpatterns/api/qxmlresultitems.h @@ -43,6 +43,7 @@ #define QXMLRESULTITEMS #include +#include QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -66,7 +67,7 @@ public: private: friend class QXmlQuery; Q_DECLARE_PRIVATE(QXmlResultItems) - QXmlResultItemsPrivate *d_ptr; + QScopedPointer d_ptr; Q_DISABLE_COPY(QXmlResultItems) }; diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 0092d49..178351b 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -231,6 +231,7 @@ SUBDIRS += _networkselftest \ qprogressbar \ qprogressdialog \ qpushbutton \ + qscopedpointer \ qqueue \ qradiobutton \ qreadlocker \ diff --git a/tests/auto/collections/tst_collections.cpp b/tests/auto/collections/tst_collections.cpp index c05d8da..cbd72dc 100644 --- a/tests/auto/collections/tst_collections.cpp +++ b/tests/auto/collections/tst_collections.cpp @@ -1364,6 +1364,9 @@ void tst_Collections::byteArray() ba1 = "FooFoo"; ba1.replace(char('F'), ba1); QCOMPARE(ba1, QByteArray("FooFooooFooFoooo")); + ba1 = "FooFoo"; + ba1.replace(char('o'), ba1); + QCOMPARE(ba1, QByteArray("FFooFooFooFooFFooFooFooFoo")); ba1.replace(ba1, "xxx"); QCOMPARE(ba1, QByteArray("xxx")); @@ -2354,6 +2357,9 @@ void tst_Collections::qstring() str1 = "FooFoo"; str1.replace(char('F'), str1); QCOMPARE(str1, QString("FooFooooFooFoooo")); + str1 = "FooFoo"; + str1.replace(char('o'), str1); + QCOMPARE(str1, QString("FFooFooFooFooFFooFooFooFoo")); str1 = "Foo"; str1.replace("Foo", str1); diff --git a/tests/auto/exceptionsafety/tst_exceptionsafety.cpp b/tests/auto/exceptionsafety/tst_exceptionsafety.cpp index 9c4f78d..8ed2913 100644 --- a/tests/auto/exceptionsafety/tst_exceptionsafety.cpp +++ b/tests/auto/exceptionsafety/tst_exceptionsafety.cpp @@ -52,9 +52,16 @@ class tst_ExceptionSafety: public QObject Q_OBJECT private slots: void exceptionInSlot(); + void exceptionVector(); + void exceptionHash(); + void exceptionMap(); + void exceptionList(); + void exceptionLinkedList(); + void exceptionEventLoop(); + void exceptionSignalSlot(); }; -class Emitter: public QObject +class Emitter : public QObject { Q_OBJECT public: @@ -63,13 +70,111 @@ signals: void testSignal(); }; -class ExceptionThrower: public QObject +class ExceptionThrower : public QObject { Q_OBJECT public slots: void thrower() { throw 5; } }; +class Receiver : public QObject +{ + Q_OBJECT +public: + Receiver() + : received(0) {} + int received; + +public slots: + void receiver() { ++received; } +}; + +enum ThrowType { ThrowNot = 0, ThrowAtCreate = 1, ThrowAtCopy = 2, ThrowLater = 3, ThrowAtComparison = 4 }; + +ThrowType throwType = ThrowNot; // global flag to indicate when an exception should be throw. Will be reset when the exception has been generated. + +int objCounter = 0; + +/*! Class that does not throw any exceptions. Used as baseclass for all the other ones. + */ +template +class FlexibleThrower +{ + public: + FlexibleThrower() : _value(-1) { + if( throwType == ThrowAtCreate ) { + throwType = ThrowNot; + throw ThrowAtCreate; + } + objCounter++; + } + + FlexibleThrower( short value ) : _value(value) { + if( throwType == ThrowAtCreate ) { + throwType = ThrowNot; + throw ThrowAtCreate; + } + objCounter++; + } + + FlexibleThrower(FlexibleThrower const& other ) { + // qDebug("cc"); + + if( throwType == ThrowAtCopy ) { + throwType = ThrowNot; + throw ThrowAtCopy; + + } else if( throwType == ThrowLater ) { + throwType = ThrowAtCopy; + } + + objCounter++; + _value = other.value(); + } + + ~FlexibleThrower() { objCounter--; } + + bool operator==(const FlexibleThrower &t) const + { + // qDebug("vv == %d %d", value(), t.value()); + if( throwType == ThrowAtComparison ) { + throwType = ThrowNot; + throw ThrowAtComparison; + } + return value()==t.value(); + } + + bool operator<(const FlexibleThrower &t) const + { + // qDebug("vv < %d %d", value(), t.value()); + if( throwType == ThrowAtComparison ) { + throwType = ThrowNot; + throw ThrowAtComparison; + } + return value()& t) +{ + // qDebug("ha"); + if( throwType == ThrowAtComparison ) { + throwType = ThrowNot; + throw ThrowAtComparison; + } + return (uint)t.value(); +} + +typedef FlexibleThrower<2> FlexibleThrowerSmall; +typedef QMap MyMap; +typedef QHash MyHash; + // connect a signal to a slot that throws an exception // run this through valgrind to make sure it doesn't corrupt void tst_ExceptionSafety::exceptionInSlot() @@ -86,6 +191,525 @@ void tst_ExceptionSafety::exceptionInSlot() } } +void tst_ExceptionSafety::exceptionList() { + + { + QList list; + QList list2; + QList list3; + + for( int i = 0; i<10; i++ ) + list.append( FlexibleThrowerSmall(i) ); + + try { + throwType = ThrowAtCopy; + list.append( FlexibleThrowerSmall(10)); + } catch (...) { + } + QCOMPARE( list.size(), 10 ); + + try { + throwType = ThrowAtCopy; + list.prepend( FlexibleThrowerSmall(10)); + } catch (...) { + } + QCOMPARE( list.at(0).value(), 0 ); + QCOMPARE( list.size(), 10 ); + + try { + throwType = ThrowAtCopy; + list.insert( 8, FlexibleThrowerSmall(10)); + } catch (...) { + } + QCOMPARE( list.at(7).value(), 7 ); + QCOMPARE( list.at(8).value(), 8 ); + QCOMPARE( list.size(), 10 ); + + try { + throwType = ThrowAtCopy; + FlexibleThrowerSmall t = list.takeAt( 6 ); + } catch (...) { + } + QCOMPARE( list.at(6).value(), 6 ); + QCOMPARE( list.at(7).value(), 7 ); + QCOMPARE( list.size(), 10 ); + + try { + throwType = ThrowAtCopy; + list3 = list; + } catch (...) { + } + QCOMPARE( list.at(0).value(), 0 ); + QCOMPARE( list.at(7).value(), 7 ); + QCOMPARE( list.size(), 10 ); + QCOMPARE( list3.at(0).value(), 0 ); + QCOMPARE( list3.at(7).value(), 7 ); + QCOMPARE( list3.size(), 10 ); + + try { + throwType = ThrowAtCopy; + list3.append( FlexibleThrowerSmall(11) ); + } catch (...) { + } + QCOMPARE( list.at(0).value(), 0 ); + QCOMPARE( list.at(7).value(), 7 ); + QCOMPARE( list.size(), 10 ); + QCOMPARE( list3.at(0).value(), 0 ); + QCOMPARE( list3.at(7).value(), 7 ); + QCOMPARE( list3.size(), 10 ); + + try { + list2.clear(); + list2.append( FlexibleThrowerSmall(11)); + throwType = ThrowAtCopy; + list3 = list+list2; + } catch (...) { + } + QCOMPARE( list.at(0).value(), 0 ); + QCOMPARE( list.at(7).value(), 7 ); + QCOMPARE( list.size(), 10 ); + + // check that copy on write works atomar + list2.clear(); + list2.append( FlexibleThrowerSmall(11)); + list3 = list+list2; + try { + throwType = ThrowAtCreate; + list3[7]=FlexibleThrowerSmall(12); + } catch (...) { + } + QCOMPARE( list.at(7).value(), 7 ); + QCOMPARE( list.size(), 10 ); + QCOMPARE( list3.at(7).value(), 7 ); + QCOMPARE( list3.size(), 11 ); + + } + QCOMPARE(objCounter, 0 ); // check that every object has been freed +} + +void tst_ExceptionSafety::exceptionLinkedList() { + + { + QLinkedList list; + QLinkedList list2; + QLinkedList list3; + + for( int i = 0; i<10; i++ ) + list.append( FlexibleThrowerSmall(i) ); + + try { + throwType = ThrowAtCopy; + list.append( FlexibleThrowerSmall(10)); + } catch (...) { + } + QCOMPARE( list.size(), 10 ); + + try { + throwType = ThrowAtCopy; + list.prepend( FlexibleThrowerSmall(10)); + } catch (...) { + } + QCOMPARE( list.first().value(), 0 ); + QCOMPARE( list.size(), 10 ); + + try { + throwType = ThrowAtCopy; + list3 = list; + list3.append( FlexibleThrowerSmall(11) ); + } catch (...) { + } + QCOMPARE( list.first().value(), 0 ); + QCOMPARE( list.size(), 10 ); + QCOMPARE( list3.size(), 10 ); + } + QCOMPARE(objCounter, 0 ); // check that every object has been freed +} + +void tst_ExceptionSafety::exceptionVector() { + + { + QVector vector; + QVector vector2; + QVector vector3; + + for (int i = 0; i<10; i++) + vector.append( FlexibleThrowerSmall(i) ); + + try { + throwType = ThrowAtCopy; + vector.append( FlexibleThrowerSmall(10)); + } catch (...) { + } + QCOMPARE( vector.size(), 10 ); + + try { + throwType = ThrowAtCopy; + vector.prepend( FlexibleThrowerSmall(10)); + } catch (...) { + } + QCOMPARE( vector.at(0).value(), 0 ); + QCOMPARE( vector.size(), 10 ); + + try { + throwType = ThrowAtCopy; + vector.insert( 8, FlexibleThrowerSmall(10)); + } catch (...) { + } + QCOMPARE( vector.at(7).value(), 7 ); + QCOMPARE( vector.at(8).value(), 8 ); + QCOMPARE( vector.size(), 10 ); + + try { + throwType = ThrowAtCopy; + vector3 = vector; + } catch (...) { + } + QCOMPARE( vector.at(0).value(), 0 ); + QCOMPARE( vector.at(7).value(), 7 ); + QCOMPARE( vector.size(), 10 ); + QCOMPARE( vector3.at(0).value(), 0 ); + QCOMPARE( vector3.at(7).value(), 7 ); + QCOMPARE( vector3.size(), 10 ); + + try { + throwType = ThrowAtCopy; + vector3.append( FlexibleThrowerSmall(11) ); + } catch (...) { + } + QCOMPARE( vector.at(0).value(), 0 ); + QCOMPARE( vector.at(7).value(), 7 ); + QCOMPARE( vector.size(), 10 ); + QCOMPARE( vector3.at(0).value(), 0 ); + QCOMPARE( vector3.at(7).value(), 7 ); + + try { + vector2.clear(); + vector2.append( FlexibleThrowerSmall(11)); + throwType = ThrowAtCopy; + vector3 = vector+vector2; + } catch (...) { + } + QCOMPARE( vector.at(0).value(), 0 ); + QCOMPARE( vector.at(7).value(), 7 ); + QCOMPARE( vector.size(), 10 ); + + // check that copy on write works atomar + vector2.clear(); + vector2.append( FlexibleThrowerSmall(11)); + vector3 = vector+vector2; + try { + throwType = ThrowAtCreate; + vector3[7]=FlexibleThrowerSmall(12); + } catch (...) { + } + QCOMPARE( vector.at(7).value(), 7 ); + QCOMPARE( vector.size(), 10 ); + QCOMPARE( vector3.at(7).value(), 7 ); + QCOMPARE( vector3.size(), 11 ); + + try { + throwType = ThrowAtCreate; + vector.resize(15); + } catch (...) { + } + QCOMPARE( vector.at(7).value(), 7 ); + QCOMPARE( vector.size(), 10 ); + + try { + throwType = ThrowAtCreate; + vector.resize(15); + } catch (...) { + } + QCOMPARE( vector.at(7).value(), 7 ); + QCOMPARE( vector.size(), 10 ); + + try { + throwType = ThrowLater; + vector.fill(FlexibleThrowerSmall(1), 15); + } catch (...) { + } + QCOMPARE( vector.at(0).value(), 0 ); + QCOMPARE( vector.size(), 10 ); + + + } + QCOMPARE(objCounter, 0 ); // check that every object has been freed +} + + +void tst_ExceptionSafety::exceptionMap() { + + { + MyMap map; + MyMap map2; + MyMap map3; + + throwType = ThrowNot; + for (int i = 0; i<10; i++) + map[ FlexibleThrowerSmall(i) ] = FlexibleThrowerSmall(i); + + return; // further test are deactivated until Map is fixed. + + for( int i = ThrowAtCopy; i<=ThrowAtComparison; i++ ) { + try { + throwType = (ThrowType)i; + map[ FlexibleThrowerSmall(10) ] = FlexibleThrowerSmall(10); + } catch(...) { + } + QCOMPARE( map.size(), 10 ); + QCOMPARE( map[ FlexibleThrowerSmall(1) ], FlexibleThrowerSmall(1) ); + } + + map2 = map; + try { + throwType = ThrowLater; + map2[ FlexibleThrowerSmall(10) ] = FlexibleThrowerSmall(10); + } catch(...) { + } + /* qDebug("%d %d", map.size(), map2.size() ); + for( int i=0; i(ThrowEventId)) + { + } +}; + +class NoThrowEvent : public QEvent +{ +public: + NoThrowEvent() + : QEvent(static_cast(NoThrowEventId)) + {} +}; + +class TestObject : public QObject +{ +public: + TestObject() + : throwEventCount(0), noThrowEventCount(0) {} + + int throwEventCount; + int noThrowEventCount; + +protected: + bool event(QEvent *event) + { + if (int(event->type()) == ThrowEventId) { + throw ++throwEventCount; + } else if (int(event->type()) == NoThrowEventId) { + ++noThrowEventCount; + } + return QObject::event(event); + } +}; + +void tst_ExceptionSafety::exceptionEventLoop() +{ + // send an event that throws + TestObject obj; + ThrowEvent throwEvent; + try { + qApp->sendEvent(&obj, &throwEvent); + } catch (int code) { + QCOMPARE(code, 1); + } + QCOMPARE(obj.throwEventCount, 1); + + // post an event that throws + qApp->postEvent(&obj, new ThrowEvent); + + try { + qApp->processEvents(); + } catch (int code) { + QCOMPARE(code, 2); + } + QCOMPARE(obj.throwEventCount, 2); + + // post a normal event, then a throwing event, then a normal event + // run this in valgrind to ensure that it doesn't leak. + + qApp->postEvent(&obj, new NoThrowEvent); + qApp->postEvent(&obj, new ThrowEvent); + qApp->postEvent(&obj, new NoThrowEvent); + + try { + qApp->processEvents(); + } catch (int code) { + QCOMPARE(code, 3); + } + // here, we should have received on non-throwing event and one throwing one + QCOMPARE(obj.throwEventCount, 3); + QCOMPARE(obj.noThrowEventCount, 1); + + // spin the event loop again + qApp->processEvents(); + + // now, we should have received the second non-throwing event + QCOMPARE(obj.noThrowEventCount, 2); +} + +void tst_ExceptionSafety::exceptionSignalSlot() +{ + Emitter e; + ExceptionThrower thrower; + Receiver r1; + Receiver r2; + + // connect a signal to a normal object, a thrower and a normal object again + connect(&e, SIGNAL(testSignal()), &r1, SLOT(receiver())); + connect(&e, SIGNAL(testSignal()), &thrower, SLOT(thrower())); + connect(&e, SIGNAL(testSignal()), &r2, SLOT(receiver())); + + int code = 0; + try { + e.emitTestSignal(); + } catch (int c) { + code = c; + } + + // 5 is the magic number that's thrown by thrower + QCOMPARE(code, 5); + + // assumption: slots are called in the connection order + QCOMPARE(r1.received, 1); + QCOMPARE(r2.received, 0); +} + QTEST_MAIN(tst_ExceptionSafety) #include "tst_exceptionsafety.moc" #endif // QT_NO_EXCEPTIONS diff --git a/tests/auto/network-settings.h b/tests/auto/network-settings.h index 22d8886..0924c57 100644 --- a/tests/auto/network-settings.h +++ b/tests/auto/network-settings.h @@ -59,27 +59,28 @@ // network tests. WINPCAP connectivity uses Symbian OS IP stack, // correspondingly as HW does. When using WINPCAP disable this define //#define SYMBIAN_WINSOCK_CONNECTIVITY -#endif - class QtNetworkSettingsRecord { - public: - QtNetworkSettingsRecord() { } +class QtNetworkSettingsRecord { +public: + QtNetworkSettingsRecord() { } + + QtNetworkSettingsRecord(const QString& recName, const QString& recVal) + : strRecordName(recName), strRecordValue(recVal) { } - QtNetworkSettingsRecord(const QString& recName, const QString& recVal) - : strRecordName(recName), strRecordValue(recVal) { } + QtNetworkSettingsRecord(const QtNetworkSettingsRecord & other) + : strRecordName(other.strRecordName), strRecordValue(other.strRecordValue) { } - QtNetworkSettingsRecord(const QtNetworkSettingsRecord & other) - : strRecordName(other.strRecordName), strRecordValue(other.strRecordValue) { } + ~QtNetworkSettingsRecord() { } - ~QtNetworkSettingsRecord() { } + const QString& recordName() const { return strRecordName; } + const QString& recordValue() const { return strRecordValue; } - const QString& recordName() const { return strRecordName; } - const QString& recordValue() const { return strRecordValue; } +private: + QString strRecordName; + QString strRecordValue; +}; - private: - QString strRecordName; - QString strRecordValue; - }; +#endif class QtNetworkSettings { @@ -171,6 +172,7 @@ public: static QByteArray expectedReplySSL() { +#ifdef Q_OS_SYMBIAN loadTestSettings(); if(QtNetworkSettings::entries.contains("imap.expectedreplyssl")) { @@ -180,12 +182,12 @@ public: imapExpectedReplySsl.append('\r').append('\n'); } return imapExpectedReplySsl.data(); - } else { - QByteArray expected( "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID AUTH=PLAIN SASL-IR] " ); - expected = expected.append(QtNetworkSettings::serverLocalName().toAscii()); - expected = expected.append(" Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n"); - return expected; } +#endif + QByteArray expected( "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID AUTH=PLAIN SASL-IR] " ); + expected = expected.append(QtNetworkSettings::serverLocalName().toAscii()); + expected = expected.append(" Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n"); + return expected; } static QByteArray expectedReplyFtp() diff --git a/tests/auto/qbitarray/tst_qbitarray.cpp b/tests/auto/qbitarray/tst_qbitarray.cpp index 12fbdc3..244183e 100644 --- a/tests/auto/qbitarray/tst_qbitarray.cpp +++ b/tests/auto/qbitarray/tst_qbitarray.cpp @@ -108,6 +108,8 @@ private slots: void invertOnNull() const; void operator_noteq_data(); void operator_noteq(); + + void resize(); }; Q_DECLARE_METATYPE(QBitArray) @@ -628,5 +630,30 @@ void tst_QBitArray::operator_noteq() QCOMPARE(b, res); } +void tst_QBitArray::resize() +{ + // -- check that a resize handles the bits correctly + QBitArray a = QStringToQBitArray(QString("11")); + a.resize(10); + QVERIFY(a.size() == 10); + QCOMPARE( a, QStringToQBitArray(QString("1100000000")) ); + + a.setBit(9); + a.resize(9); + // now the bit in a should have been gone: + QCOMPARE( a, QStringToQBitArray(QString("110000000")) ); + + // grow the array back and check the new bit + a.resize(10); + QCOMPARE( a, QStringToQBitArray(QString("1100000000")) ); + + // other test with and + a.resize(9); + QBitArray b = QStringToQBitArray(QString("1111111111")); + b &= a; + QCOMPARE( b, QStringToQBitArray(QString("1100000000")) ); + +} + QTEST_APPLESS_MAIN(tst_QBitArray) #include "tst_qbitarray.moc" diff --git a/tests/auto/qeventloop/tst_qeventloop.cpp b/tests/auto/qeventloop/tst_qeventloop.cpp index a4017b8..ed95402 100644 --- a/tests/auto/qeventloop/tst_qeventloop.cpp +++ b/tests/auto/qeventloop/tst_qeventloop.cpp @@ -243,8 +243,10 @@ public slots: // Let all the events occur twice so we know they reactivated after // each occurrence. if (++timerCount >= 2) { +#ifdef Q_OS_SYMBIAN // This will hopefully run last, so stop the active scheduler. CActiveScheduler::Stop(); +#endif } } void zeroTimerSlot() diff --git a/tests/auto/qfiledialog/tst_qfiledialog.cpp b/tests/auto/qfiledialog/tst_qfiledialog.cpp index b4fd0c5..5f0776f 100644 --- a/tests/auto/qfiledialog/tst_qfiledialog.cpp +++ b/tests/auto/qfiledialog/tst_qfiledialog.cpp @@ -465,10 +465,11 @@ void tst_QFiledialog::completer() if (!tmp.exists(tempPath)) QVERIFY(tmp.mkdir("QFileDialogTestDir")); QList files; + QT_TRY { for (int i = 0; i < 10; ++i) { - QTemporaryFile *file = new QTemporaryFile(tempPath + "/rXXXXXX"); + QScopedPointer file(new QTemporaryFile(tempPath + "/rXXXXXX")); file->open(); - files.append(file); + files.append(file.take()); } // ### flesh this out more @@ -559,6 +560,10 @@ void tst_QFiledialog::completer() // ### FIXME: This will fail on Symbian on some tests and some environments until the file engine and QFileSystemModel // are fixed to properly capitalize paths, so that some folders are not duplicated in QFileSystemModel. QTRY_COMPARE(cModel->rowCount(), expected); + } QT_CATCH(...) { + qDeleteAll(files); + QT_RETHROW; + } qDeleteAll(files); } diff --git a/tests/auto/qfontdatabase/tst_qfontdatabase.cpp b/tests/auto/qfontdatabase/tst_qfontdatabase.cpp index a006462..cb5790d 100644 --- a/tests/auto/qfontdatabase/tst_qfontdatabase.cpp +++ b/tests/auto/qfontdatabase/tst_qfontdatabase.cpp @@ -242,7 +242,7 @@ void tst_QFontDatabase::addAppFont() QVERIFY(QFontDatabase::removeApplicationFont(id)); QCOMPARE(fontDbChangedSpy.count(), 2); - QVERIFY(db.families() == oldFamilies);¨ + QVERIFY(db.families() == oldFamilies); #endif } diff --git a/tests/auto/qglobal/tst_qglobal.cpp b/tests/auto/qglobal/tst_qglobal.cpp index 88fbcd2..b4d42e4 100644 --- a/tests/auto/qglobal/tst_qglobal.cpp +++ b/tests/auto/qglobal/tst_qglobal.cpp @@ -50,6 +50,7 @@ private slots: void qInternalCallbacks(); void for_each(); void qassert(); + void qtry(); }; void tst_QGlobal::qIsNull() @@ -190,5 +191,66 @@ void tst_QGlobal::qassert() QVERIFY(passed); } +void tst_QGlobal::qtry() +{ + int i = 0; + QT_TRY { + i = 1; + QT_THROW(42); + i = 2; + } QT_CATCH(int) { + QCOMPARE(i, 1); + i = 7; + } +#ifdef QT_NO_EXCEPTIONS + QCOMPARE(i, 2); +#else + QCOMPARE(i, 7); +#endif + + // check propper if/else scoping + i = 0; + if (true) + QT_TRY { + i = 2; + QT_THROW(42); + i = 4; + } QT_CATCH(int) { + QCOMPARE(i, 2); + i = 4; + } + else + QCOMPARE(i, 0); + QCOMPARE(i, 4); + + i = 0; + if (false) + QT_TRY { + i = 2; + QT_THROW(42); + i = 4; + } QT_CATCH(int) { + QCOMPARE(i, 2); + i = 2; + } + else + i = 8; + QCOMPARE(i, 8); + + i = 0; + if (false) + i = 42; + else + QT_TRY { + i = 2; + QT_THROW(42); + i = 4; + } QT_CATCH(int) { + QCOMPARE(i, 2); + i = 4; + } + QCOMPARE(i, 4); +} + QTEST_MAIN(tst_QGlobal) #include "tst_qglobal.moc" diff --git a/tests/auto/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/qitemdelegate/tst_qitemdelegate.cpp index 615ac01..955760a 100644 --- a/tests/auto/qitemdelegate/tst_qitemdelegate.cpp +++ b/tests/auto/qitemdelegate/tst_qitemdelegate.cpp @@ -1115,13 +1115,16 @@ void tst_QItemDelegate::enterKey() QList lineEditors = qFindChildren(view.viewport(), QString::fromLatin1("TheEditor")); QCOMPARE(lineEditors.count(), 1); - QWidget *editor = lineEditors.at(0); + QPointer editor = lineEditors.at(0); QCOMPARE(editor->hasFocus(), true); QTest::keyClick(editor, Qt::Key(key)); QApplication::processEvents(); - QCOMPARE(editor->hasFocus(), expectedFocus); + if (widget == 2 || widget == 3) { + QVERIFY(!editor.isNull()); + QCOMPARE(editor->hasFocus(), expectedFocus); + } } diff --git a/tests/auto/qscopedpointer/.gitignore b/tests/auto/qscopedpointer/.gitignore new file mode 100644 index 0000000..9f2324c --- /dev/null +++ b/tests/auto/qscopedpointer/.gitignore @@ -0,0 +1 @@ +tst_qscopedpointer diff --git a/tests/auto/qscopedpointer/qscopedpointer.pro b/tests/auto/qscopedpointer/qscopedpointer.pro new file mode 100644 index 0000000..13d8425 --- /dev/null +++ b/tests/auto/qscopedpointer/qscopedpointer.pro @@ -0,0 +1,3 @@ +load(qttest_p4) +SOURCES += tst_qscopedpointer.cpp +QT -= gui diff --git a/tests/auto/qscopedpointer/tst_qscopedpointer.cpp b/tests/auto/qscopedpointer/tst_qscopedpointer.cpp new file mode 100644 index 0000000..0e005c3 --- /dev/null +++ b/tests/auto/qscopedpointer/tst_qscopedpointer.cpp @@ -0,0 +1,282 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +****************************************************************************/ + +#include +#include + +/*! + \class tst_QScopedPointer + \internal + \since 4.6 + \brief Tests class QScopedPointer. + + */ +class tst_QScopedPointer : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void defaultConstructor() const; + void dataOnDefaultConstructed() const; + void useSubClassInConstructor() const; + void dataOnValue() const; + void dataSignature() const; + void reset() const; + void dereferenceOperator() const; + void dereferenceOperatorSignature() const; + void pointerOperator() const; + void pointerOperatorSignature() const; + void negationOperator() const; + void negationOperatorSignature() const; + void operatorBool() const; + void operatorBoolSignature() const; + void isNull() const; + void isNullSignature() const; + void objectSize() const; + // TODO instansiate on const object +}; + +void tst_QScopedPointer::defaultConstructor() const +{ + /* Check that the members, one, is correctly initialized. */ + QScopedPointer p; + QCOMPARE(p.data(), static_cast(0)); +} + +void tst_QScopedPointer::dataOnDefaultConstructed() const +{ + QScopedPointer p; + + QCOMPARE(p.data(), static_cast(0)); +} + +class MyClass +{ +}; + +class MySubClass : public MyClass +{ +}; + +void tst_QScopedPointer::useSubClassInConstructor() const +{ + /* Use a syntax which users typically would do. */ + QScopedPointer p(new MyClass()); +} + +void tst_QScopedPointer::dataOnValue() const +{ + int *const rawPointer = new int(5); + QScopedPointer p(rawPointer); + + QCOMPARE(p.data(), rawPointer); +} + +void tst_QScopedPointer::dataSignature() const +{ + const QScopedPointer p; + /* data() should be const. */ + p.data(); +} + +void tst_QScopedPointer::reset() const +{ + /* Call reset() on a default constructed value. */ + { + QScopedPointer p; + p.reset(); + QCOMPARE(p.data(), static_cast(0)); + } + + /* Call reset() on an active value. */ + { + QScopedPointer p(new int(3)); + p.reset(); + QCOMPARE(p.data(), static_cast(0)); + } + + /* Call reset() with a value, on an active value. */ + { + QScopedPointer p(new int(3)); + + int *const value = new int(9); + p.reset(value); + QCOMPARE(*p.data(), 9); + } + + /* Call reset() with a value, on default constructed value. */ + { + QScopedPointer p; + + int *const value = new int(9); + p.reset(value); + QCOMPARE(*p.data(), 9); + } +} + +class AbstractClass +{ +public: + virtual ~AbstractClass() + { + } + + virtual int member() const = 0; +}; + +class SubClass : public AbstractClass +{ +public: + virtual int member() const + { + return 5; + } +}; + +void tst_QScopedPointer::dereferenceOperator() const +{ + /* Dereference a basic value. */ + { + QScopedPointer p(new int(5)); + + const int value2 = *p; + QCOMPARE(value2, 5); + } + + /* Dereference a pointer to an abstract class. This verifies + * that the operator returns a reference, when compiling + * with MSVC 2005. */ + { + QScopedPointer p(new SubClass()); + + QCOMPARE((*p).member(), 5); + } +} + +void tst_QScopedPointer::dereferenceOperatorSignature() const +{ + /* The operator should be const. */ + { + const QScopedPointer p(new int(5)); + *p; + } + + /* A reference should be returned, not a value. */ + { + const QScopedPointer p(new int(5)); + Q_UNUSED(static_cast(*p)); + } + + /* Instantiated on a const object, the returned object is a const reference. */ + { + const QScopedPointer p(new int(5)); + Q_UNUSED(static_cast(*p)); + } +} + +class AnyForm +{ +public: + int value; +}; + +void tst_QScopedPointer::pointerOperator() const +{ + QScopedPointer p(new AnyForm()); + p->value = 5; + + QCOMPARE(p->value, 5); +} + +void tst_QScopedPointer::pointerOperatorSignature() const +{ + /* The operator should be const. */ + const QScopedPointer p(new AnyForm); + p->value = 5; + + QVERIFY(p->value); +} + +void tst_QScopedPointer::negationOperator() const +{ + /* Invoke on default constructed value. */ + { + QScopedPointer p; + QVERIFY(!p); + } + + /* Invoke on a value. */ + { + QScopedPointer p(new int(2)); + QCOMPARE(!p, false); + } +} + +void tst_QScopedPointer::negationOperatorSignature() const +{ + /* The signature should be const. */ + const QScopedPointer p; + !p; + + /* The return value should be bool. */ + static_cast(!p); +} + +void tst_QScopedPointer::operatorBool() const +{ + /* Invoke on default constructed value. */ + { + QScopedPointer p; + QCOMPARE(bool(p), false); + } + + /* Invoke on active value. */ + { + QScopedPointer p(new int(3)); + QVERIFY(p); + } +} + +void tst_QScopedPointer::operatorBoolSignature() const +{ + /* The signature should be const and return bool. */ + const QScopedPointer p; + + static_cast(p); +} + +void tst_QScopedPointer::isNull() const +{ + /* Invoke on default constructed value. */ + { + QScopedPointer p; + QVERIFY(p.isNull()); + } + + /* Invoke on a set value. */ + { + QScopedPointer p(new int(69)); + QVERIFY(!p.isNull()); + } +} + +void tst_QScopedPointer::isNullSignature() const +{ + const QScopedPointer p(new int(69)); + + /* The signature should be const and return bool. */ + static_cast(p.isNull()); +} + +void tst_QScopedPointer::objectSize() const +{ + /* The size of QScopedPointer should be the same as one pointer. */ + QCOMPARE(sizeof(QScopedPointer), sizeof(void *)); +} + +QTEST_MAIN(tst_QScopedPointer) +#include "tst_qscopedpointer.moc" diff --git a/tests/auto/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/qtcpsocket/tst_qtcpsocket.cpp index f2ea2d9..cf16abb 100644 --- a/tests/auto/qtcpsocket/tst_qtcpsocket.cpp +++ b/tests/auto/qtcpsocket/tst_qtcpsocket.cpp @@ -81,10 +81,8 @@ #ifndef TEST_QNETWORK_PROXY //#define TEST_QNETWORK_PROXY #endif -#if defined(TEST_QNETWORK_PROXY) || defined (Q_CC_RVCT) // RVCT compiles also unused inline methods # include -#endif #ifdef Q_OS_LINUX #include @@ -1185,7 +1183,7 @@ void tst_QTcpSocket::readLine() char buffer[1024]; int expectedReplySize = QtNetworkSettings::expectedReplyIMAP().size(); - ASSERT(expectedReplySize >= 3); + Q_ASSERT(expectedReplySize >= 3); QCOMPARE(socket->readLine(buffer, sizeof(buffer)), qint64(expectedReplySize)); QCOMPARE((int) buffer[expectedReplySize-2], (int) '\r'); diff --git a/tests/auto/qudpsocket/tst_qudpsocket.cpp b/tests/auto/qudpsocket/tst_qudpsocket.cpp index 621acbb..e9bf51b 100644 --- a/tests/auto/qudpsocket/tst_qudpsocket.cpp +++ b/tests/auto/qudpsocket/tst_qudpsocket.cpp @@ -853,4 +853,4 @@ void tst_QUdpSocket::zeroLengthDatagram() } QTEST_MAIN(tst_QUdpSocket) -#include "test/tmp/tst_qudpsocket.moc" +#include "tst_qudpsocket.moc" diff --git a/tools/configure/configureapp.cpp b/tools/configure/configureapp.cpp index 81ddf4a..945a0f0 100644 --- a/tools/configure/configureapp.cpp +++ b/tools/configure/configureapp.cpp @@ -1407,8 +1407,8 @@ void Configure::applySpecSpecifics() dictionary[ "OPENGL" ] = "no"; dictionary[ "OPENSSL" ] = "yes"; dictionary[ "STL" ] = "yes"; - dictionary[ "EXCEPTIONS" ] = "no"; - dictionary[ "RTTI" ] = "no"; + dictionary[ "EXCEPTIONS" ] = "yes"; + dictionary[ "RTTI" ] = "yes"; dictionary[ "ARCHITECTURE" ] = "symbian"; dictionary[ "3DNOW" ] = "no"; dictionary[ "SSE" ] = "no"; diff --git a/tools/designer/src/components/formeditor/brushmanagerproxy.cpp b/tools/designer/src/components/formeditor/brushmanagerproxy.cpp index b1c056e..86880f3 100644 --- a/tools/designer/src/components/formeditor/brushmanagerproxy.cpp +++ b/tools/designer/src/components/formeditor/brushmanagerproxy.cpp @@ -146,14 +146,12 @@ QString BrushManagerProxyPrivate::uniqueBrushFileName(const QString &brushName) BrushManagerProxy::BrushManagerProxy(QDesignerFormEditorInterface *core, QObject *parent) - : QObject(parent) + : QObject(parent), d_ptr(new BrushManagerProxyPrivate(this, core)) { - d_ptr = new BrushManagerProxyPrivate(this, core); } BrushManagerProxy::~BrushManagerProxy() { - delete d_ptr; } void BrushManagerProxy::setBrushManager(QtBrushManager *manager) diff --git a/tools/designer/src/components/formeditor/brushmanagerproxy.h b/tools/designer/src/components/formeditor/brushmanagerproxy.h index cbe50ae..43bcf29 100644 --- a/tools/designer/src/components/formeditor/brushmanagerproxy.h +++ b/tools/designer/src/components/formeditor/brushmanagerproxy.h @@ -63,7 +63,7 @@ public: void setBrushManager(QtBrushManager *manager); private: - BrushManagerProxyPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(BrushManagerProxy) Q_DISABLE_COPY(BrushManagerProxy) Q_PRIVATE_SLOT(d_func(), void brushAdded(const QString &, const QBrush &)) diff --git a/tools/designer/src/components/formeditor/qtbrushmanager.cpp b/tools/designer/src/components/formeditor/qtbrushmanager.cpp index c28c6b9..3ac9851 100644 --- a/tools/designer/src/components/formeditor/qtbrushmanager.cpp +++ b/tools/designer/src/components/formeditor/qtbrushmanager.cpp @@ -57,16 +57,13 @@ public: }; QtBrushManager::QtBrushManager(QObject *parent) - : QDesignerBrushManagerInterface(parent) + : QDesignerBrushManagerInterface(parent), d_ptr(new QtBrushManagerPrivate) { - d_ptr = new QtBrushManagerPrivate; d_ptr->q_ptr = this; - } QtBrushManager::~QtBrushManager() { - delete d_ptr; } QBrush QtBrushManager::brush(const QString &name) const diff --git a/tools/designer/src/components/formeditor/qtbrushmanager.h b/tools/designer/src/components/formeditor/qtbrushmanager.h index f8f1b8a..0855175 100644 --- a/tools/designer/src/components/formeditor/qtbrushmanager.h +++ b/tools/designer/src/components/formeditor/qtbrushmanager.h @@ -77,7 +77,7 @@ signals: void currentBrushChanged(const QString &name, const QBrush &brush); private: - QtBrushManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtBrushManager) Q_DISABLE_COPY(QtBrushManager) }; diff --git a/tools/designer/src/lib/shared/iconselector.cpp b/tools/designer/src/lib/shared/iconselector.cpp index 02a3dee..302a077 100644 --- a/tools/designer/src/lib/shared/iconselector.cpp +++ b/tools/designer/src/lib/shared/iconselector.cpp @@ -157,7 +157,6 @@ LanguageResourceDialog::LanguageResourceDialog(QDesignerResourceBrowserInterface LanguageResourceDialog::~LanguageResourceDialog() { - delete d_ptr; } void LanguageResourceDialog::setCurrentPath(const QString &filePath) @@ -427,9 +426,8 @@ void IconSelectorPrivate::slotResetAllActivated() // ------------- IconSelector IconSelector::IconSelector(QWidget *parent) : - QWidget(parent) + QWidget(parent), d_ptr(new IconSelectorPrivate()) { - d_ptr = new IconSelectorPrivate(); d_ptr->q_ptr = this; d_ptr->m_stateComboBox = new QComboBox(this); @@ -500,7 +498,6 @@ IconSelector::IconSelector(QWidget *parent) : IconSelector::~IconSelector() { - delete d_ptr; } void IconSelector::setIcon(const PropertySheetIconValue &icon) diff --git a/tools/designer/src/lib/shared/iconselector_p.h b/tools/designer/src/lib/shared/iconselector_p.h index 6b70cd2..de4c54f 100644 --- a/tools/designer/src/lib/shared/iconselector_p.h +++ b/tools/designer/src/lib/shared/iconselector_p.h @@ -87,7 +87,7 @@ public: QString currentPath() const; private: - class LanguageResourceDialogPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(LanguageResourceDialog) Q_DISABLE_COPY(LanguageResourceDialog) Q_PRIVATE_SLOT(d_func(), void slotAccepted()) @@ -120,7 +120,7 @@ public: signals: void iconChanged(const PropertySheetIconValue &icon); private: - class IconSelectorPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(IconSelector) Q_DISABLE_COPY(IconSelector) diff --git a/tools/designer/src/lib/shared/qtresourceeditordialog.cpp b/tools/designer/src/lib/shared/qtresourceeditordialog.cpp index adddf72..bd6be95 100644 --- a/tools/designer/src/lib/shared/qtresourceeditordialog.cpp +++ b/tools/designer/src/lib/shared/qtresourceeditordialog.cpp @@ -1949,9 +1949,8 @@ bool QtResourceEditorDialogPrivate::saveQrcFile(const QtQrcFileData &qrcFileData } QtResourceEditorDialog::QtResourceEditorDialog(QDesignerFormEditorInterface *core, QDesignerDialogGuiInterface *dlgGui, QWidget *parent) - : QDialog(parent) + : QDialog(parent), d_ptr(new QtResourceEditorDialogPrivate()) { - d_ptr = new QtResourceEditorDialogPrivate(); d_ptr->q_ptr = this; d_ptr->m_ui.setupUi(this); d_ptr->m_qrcManager = new QtQrcManager(this); @@ -2085,8 +2084,6 @@ QtResourceEditorDialog::~QtResourceEditorDialog() settings->setValue(QLatin1String(SplitterPosition), d_ptr->m_ui.splitter->saveState()); settings->setValue(QLatin1String(Geometry), geometry()); settings->endGroup(); - - delete d_ptr; } QtResourceModel *QtResourceEditorDialog::model() const diff --git a/tools/designer/src/lib/shared/qtresourceeditordialog_p.h b/tools/designer/src/lib/shared/qtresourceeditordialog_p.h index f2531d9..aa768e9 100644 --- a/tools/designer/src/lib/shared/qtresourceeditordialog_p.h +++ b/tools/designer/src/lib/shared/qtresourceeditordialog_p.h @@ -53,6 +53,7 @@ #ifndef QTRESOURCEEDITOR_H #define QTRESOURCEEDITOR_H +#include #include QT_BEGIN_NAMESPACE @@ -83,7 +84,7 @@ private: QtResourceEditorDialog(QDesignerFormEditorInterface *core, QDesignerDialogGuiInterface *dlgGui, QWidget *parent = 0); ~QtResourceEditorDialog(); - class QtResourceEditorDialogPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtResourceEditorDialog) Q_DISABLE_COPY(QtResourceEditorDialog) diff --git a/tools/designer/src/lib/shared/qtresourcemodel.cpp b/tools/designer/src/lib/shared/qtresourcemodel.cpp index e6152be..89615c8 100644 --- a/tools/designer/src/lib/shared/qtresourcemodel.cpp +++ b/tools/designer/src/lib/shared/qtresourcemodel.cpp @@ -141,7 +141,6 @@ QtResourceSet::QtResourceSet(QtResourceModel *model) : QtResourceSet::~QtResourceSet() { - delete d_ptr; } QStringList QtResourceSet::activeQrcPaths() const @@ -489,7 +488,6 @@ QtResourceModel::~QtResourceModel() while (it.hasNext()) removeResourceSet(it.next()); blockSignals(false); - delete d_ptr; } QStringList QtResourceModel::loadedQrcFiles() const diff --git a/tools/designer/src/lib/shared/qtresourcemodel_p.h b/tools/designer/src/lib/shared/qtresourcemodel_p.h index 726db29..61d6763 100644 --- a/tools/designer/src/lib/shared/qtresourcemodel_p.h +++ b/tools/designer/src/lib/shared/qtresourcemodel_p.h @@ -56,6 +56,7 @@ #include "shared_global_p.h" #include #include +#include QT_BEGIN_NAMESPACE @@ -87,7 +88,7 @@ private: ~QtResourceSet(); friend class QtResourceModel; - class QtResourceSetPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtResourceSet) Q_DISABLE_COPY(QtResourceSet) }; @@ -132,7 +133,7 @@ signals: private: friend class QtResourceSet; - class QtResourceModelPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtResourceModel) Q_DISABLE_COPY(QtResourceModel) diff --git a/tools/designer/src/lib/shared/qtresourceview.cpp b/tools/designer/src/lib/shared/qtresourceview.cpp index d956491..22439a2 100644 --- a/tools/designer/src/lib/shared/qtresourceview.cpp +++ b/tools/designer/src/lib/shared/qtresourceview.cpp @@ -499,8 +499,6 @@ QtResourceView::~QtResourceView() { if (!d_ptr->m_settingsKey.isEmpty()) d_ptr->saveSettings(); - - delete d_ptr; } bool QtResourceView::event(QEvent *event) @@ -737,8 +735,6 @@ QtResourceViewDialog::~QtResourceViewDialog() settings->setValue(QLatin1String(Geometry), geometry()); settings->endGroup(); - - delete d_ptr; } QString QtResourceViewDialog::selectedResource() const diff --git a/tools/designer/src/lib/shared/qtresourceview_p.h b/tools/designer/src/lib/shared/qtresourceview_p.h index 33162c5..1d3a1b0 100644 --- a/tools/designer/src/lib/shared/qtresourceview_p.h +++ b/tools/designer/src/lib/shared/qtresourceview_p.h @@ -102,7 +102,7 @@ protected: private: - class QtResourceViewPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtResourceView) Q_DISABLE_COPY(QtResourceView) Q_PRIVATE_SLOT(d_func(), void slotResourceSetActivated(QtResourceSet *)) @@ -129,7 +129,7 @@ public: void setResourceEditingEnabled(bool enable); private: - class QtResourceViewDialogPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtResourceViewDialog) Q_DISABLE_COPY(QtResourceViewDialog) Q_PRIVATE_SLOT(d_func(), void slotResourceSelected(const QString &)) diff --git a/tools/designer/src/uitools/quiloader.cpp b/tools/designer/src/uitools/quiloader.cpp index 2a66095..9e904d4 100644 --- a/tools/designer/src/uitools/quiloader.cpp +++ b/tools/designer/src/uitools/quiloader.cpp @@ -648,7 +648,6 @@ QUiLoader::QUiLoader(QObject *parent) */ QUiLoader::~QUiLoader() { - delete d_ptr; } /*! diff --git a/tools/designer/src/uitools/quiloader.h b/tools/designer/src/uitools/quiloader.h index 6543ba8..90403bf 100644 --- a/tools/designer/src/uitools/quiloader.h +++ b/tools/designer/src/uitools/quiloader.h @@ -43,6 +43,7 @@ #define QUILOADER_H #include +#include QT_BEGIN_HEADER @@ -90,7 +91,7 @@ public: bool isTranslationEnabled() const; private: - QUiLoaderPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QUiLoader) Q_DISABLE_COPY(QUiLoader) }; diff --git a/tools/shared/qtgradienteditor/qtcolorbutton.cpp b/tools/shared/qtgradienteditor/qtcolorbutton.cpp index 6926f60..49581bd 100644 --- a/tools/shared/qtgradienteditor/qtcolorbutton.cpp +++ b/tools/shared/qtgradienteditor/qtcolorbutton.cpp @@ -121,9 +121,8 @@ QPixmap QtColorButtonPrivate::generatePixmap() const /////////////// QtColorButton::QtColorButton(QWidget *parent) - : QToolButton(parent) + : QToolButton(parent), d_ptr(new QtColorButtonPrivate) { - d_ptr = new QtColorButtonPrivate; d_ptr->q_ptr = this; d_ptr->m_dragging = false; d_ptr->m_backgroundCheckered = true; @@ -136,7 +135,6 @@ QtColorButton::QtColorButton(QWidget *parent) QtColorButton::~QtColorButton() { - delete d_ptr; } void QtColorButton::setColor(const QColor &color) diff --git a/tools/shared/qtgradienteditor/qtcolorbutton.h b/tools/shared/qtgradienteditor/qtcolorbutton.h index fb91452..9e4f357 100644 --- a/tools/shared/qtgradienteditor/qtcolorbutton.h +++ b/tools/shared/qtgradienteditor/qtcolorbutton.h @@ -75,7 +75,7 @@ protected: void dropEvent(QDropEvent *event); #endif private: - class QtColorButtonPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtColorButton) Q_DISABLE_COPY(QtColorButton) Q_PRIVATE_SLOT(d_func(), void slotEditColor()) diff --git a/tools/shared/qtgradienteditor/qtcolorline.cpp b/tools/shared/qtgradienteditor/qtcolorline.cpp index 337726c..b0b0ee0 100644 --- a/tools/shared/qtgradienteditor/qtcolorline.cpp +++ b/tools/shared/qtgradienteditor/qtcolorline.cpp @@ -999,9 +999,8 @@ void QtColorLinePrivate::mouseDoubleClickEvent(QMouseEvent *event) //////////////////////////////////////////////////// QtColorLine::QtColorLine(QWidget *parent) - : QWidget(parent) + : QWidget(parent), d_ptr(new QtColorLinePrivate) { - d_ptr = new QtColorLinePrivate; d_ptr->q_ptr = this; setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); @@ -1009,7 +1008,6 @@ QtColorLine::QtColorLine(QWidget *parent) QtColorLine::~QtColorLine() { - delete d_ptr; } QSize QtColorLine::minimumSizeHint() const diff --git a/tools/shared/qtgradienteditor/qtcolorline.h b/tools/shared/qtgradienteditor/qtcolorline.h index d5535b1..16169d1 100644 --- a/tools/shared/qtgradienteditor/qtcolorline.h +++ b/tools/shared/qtgradienteditor/qtcolorline.h @@ -114,7 +114,7 @@ protected: private: - class QtColorLinePrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtColorLine) Q_DISABLE_COPY(QtColorLine) }; diff --git a/tools/shared/qtgradienteditor/qtgradientdialog.cpp b/tools/shared/qtgradienteditor/qtgradientdialog.cpp index 032cb16..001709c 100644 --- a/tools/shared/qtgradienteditor/qtgradientdialog.cpp +++ b/tools/shared/qtgradienteditor/qtgradientdialog.cpp @@ -200,10 +200,9 @@ void QtGradientDialogPrivate::slotAboutToShowDetails(bool details, int extension */ QtGradientDialog::QtGradientDialog(QWidget *parent) - : QDialog(parent) + : QDialog(parent), d_ptr(new QtGradientDialogPrivate()) { // setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); - d_ptr = new QtGradientDialogPrivate(); d_ptr->q_ptr = this; d_ptr->m_ui.setupUi(this); QPushButton *button = d_ptr->m_ui.buttonBox->button(QDialogButtonBox::Ok); @@ -222,7 +221,6 @@ QtGradientDialog::QtGradientDialog(QWidget *parent) QtGradientDialog::~QtGradientDialog() { - delete d_ptr; } /*! diff --git a/tools/shared/qtgradienteditor/qtgradientdialog.h b/tools/shared/qtgradienteditor/qtgradientdialog.h index d3bafc9..819ad21 100644 --- a/tools/shared/qtgradienteditor/qtgradientdialog.h +++ b/tools/shared/qtgradienteditor/qtgradientdialog.h @@ -76,7 +76,7 @@ public: static QGradient getGradient(bool *ok, QWidget *parent = 0, const QString &caption = QString()); private: - class QtGradientDialogPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtGradientDialog) Q_DISABLE_COPY(QtGradientDialog) Q_PRIVATE_SLOT(d_func(), void slotAboutToShowDetails(bool details, int extensionWidthHint)) diff --git a/tools/shared/qtgradienteditor/qtgradienteditor.cpp b/tools/shared/qtgradienteditor/qtgradienteditor.cpp index 9eca9d8..0a7eee0 100644 --- a/tools/shared/qtgradienteditor/qtgradienteditor.cpp +++ b/tools/shared/qtgradienteditor/qtgradienteditor.cpp @@ -727,9 +727,8 @@ void QtGradientEditorPrivate::setAngleConical(qreal angle) } QtGradientEditor::QtGradientEditor(QWidget *parent) - : QWidget(parent) + : QWidget(parent), d_ptr(new QtGradientEditorPrivate()) { - d_ptr = new QtGradientEditorPrivate(); d_ptr->q_ptr = this; d_ptr->m_type = QGradient::RadialGradient; d_ptr->m_ui.setupUi(this); @@ -835,7 +834,6 @@ QtGradientEditor::~QtGradientEditor() { if (d_ptr->m_hiddenWidget) delete d_ptr->m_hiddenWidget; - delete d_ptr; } void QtGradientEditor::setGradient(const QGradient &grad) diff --git a/tools/shared/qtgradienteditor/qtgradienteditor.h b/tools/shared/qtgradienteditor/qtgradienteditor.h index 9974065..7dc75195 100644 --- a/tools/shared/qtgradienteditor/qtgradienteditor.h +++ b/tools/shared/qtgradienteditor/qtgradienteditor.h @@ -78,7 +78,7 @@ signals: void aboutToShowDetails(bool details, int extenstionWidthHint); private: - class QtGradientEditorPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtGradientEditor) Q_DISABLE_COPY(QtGradientEditor) Q_PRIVATE_SLOT(d_func(), void slotGradientStopsChanged(const QGradientStops &stops)) diff --git a/tools/shared/qtgradienteditor/qtgradientstopscontroller.cpp b/tools/shared/qtgradienteditor/qtgradientstopscontroller.cpp index cbc53db..0e9521c 100644 --- a/tools/shared/qtgradienteditor/qtgradientstopscontroller.cpp +++ b/tools/shared/qtgradienteditor/qtgradientstopscontroller.cpp @@ -594,9 +594,8 @@ void QtGradientStopsControllerPrivate::slotZoomChanged(double zoom) } QtGradientStopsController::QtGradientStopsController(QObject *parent) - : QObject(parent) + : QObject(parent), d_ptr(new QtGradientStopsControllerPrivate()) { - d_ptr = new QtGradientStopsControllerPrivate(); d_ptr->q_ptr = this; d_ptr->m_spec = QColor::Hsv; @@ -675,7 +674,6 @@ void QtGradientStopsController::setUi(Ui::QtGradientEditor *ui) QtGradientStopsController::~QtGradientStopsController() { - delete d_ptr; } void QtGradientStopsController::setGradientStops(const QGradientStops &stops) diff --git a/tools/shared/qtgradienteditor/qtgradientstopscontroller.h b/tools/shared/qtgradienteditor/qtgradientstopscontroller.h index 9f16fb0..37f2e01 100644 --- a/tools/shared/qtgradienteditor/qtgradientstopscontroller.h +++ b/tools/shared/qtgradienteditor/qtgradientstopscontroller.h @@ -70,7 +70,7 @@ signals: void gradientStopsChanged(const QGradientStops &stops); private: - class QtGradientStopsControllerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtGradientStopsController) Q_DISABLE_COPY(QtGradientStopsController) Q_PRIVATE_SLOT(d_func(), void slotHsvClicked()) diff --git a/tools/shared/qtgradienteditor/qtgradientstopsmodel.cpp b/tools/shared/qtgradienteditor/qtgradientstopsmodel.cpp index a632c0f..6260870 100644 --- a/tools/shared/qtgradienteditor/qtgradientstopsmodel.cpp +++ b/tools/shared/qtgradienteditor/qtgradientstopsmodel.cpp @@ -78,8 +78,8 @@ void QtGradientStop::setPosition(qreal position) } QtGradientStop::QtGradientStop(QtGradientStopsModel *model) + : d_ptr(new QtGradientStopPrivate()) { - d_ptr = new QtGradientStopPrivate(); d_ptr->m_position = 0; d_ptr->m_color = Qt::white; d_ptr->m_model = model; @@ -87,7 +87,6 @@ QtGradientStop::QtGradientStop(QtGradientStopsModel *model) QtGradientStop::~QtGradientStop() { - delete d_ptr; } class QtGradientStopsModelPrivate @@ -104,9 +103,8 @@ public: QtGradientStopsModel::QtGradientStopsModel(QObject *parent) - : QObject(parent) + : QObject(parent), d_ptr(new QtGradientStopsModelPrivate) { - d_ptr = new QtGradientStopsModelPrivate; d_ptr->q_ptr = this; d_ptr->m_current = 0; } @@ -114,7 +112,6 @@ QtGradientStopsModel::QtGradientStopsModel(QObject *parent) QtGradientStopsModel::~QtGradientStopsModel() { clear(); - delete d_ptr; } QtGradientStopsModel::PositionStopMap QtGradientStopsModel::stops() const diff --git a/tools/shared/qtgradienteditor/qtgradientstopsmodel.h b/tools/shared/qtgradienteditor/qtgradientstopsmodel.h index d4e6b3c..2c04c8f 100644 --- a/tools/shared/qtgradienteditor/qtgradientstopsmodel.h +++ b/tools/shared/qtgradienteditor/qtgradientstopsmodel.h @@ -64,7 +64,7 @@ private: friend class QtGradientStopsModel; QtGradientStop(QtGradientStopsModel *model = 0); ~QtGradientStop(); - class QtGradientStopPrivate *d_ptr; + QScopedPointer d_ptr; }; class QtGradientStopsModel : public QObject @@ -111,7 +111,7 @@ signals: void currentStopChanged(QtGradientStop *stop); private: - class QtGradientStopsModelPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtGradientStopsModel) Q_DISABLE_COPY(QtGradientStopsModel) }; diff --git a/tools/shared/qtgradienteditor/qtgradientstopswidget.cpp b/tools/shared/qtgradienteditor/qtgradientstopswidget.cpp index adaf57d..570bd6f 100644 --- a/tools/shared/qtgradienteditor/qtgradientstopswidget.cpp +++ b/tools/shared/qtgradienteditor/qtgradientstopswidget.cpp @@ -360,9 +360,8 @@ void QtGradientStopsWidgetPrivate::slotResetZoom() } QtGradientStopsWidget::QtGradientStopsWidget(QWidget *parent) - : QAbstractScrollArea(parent) + : QAbstractScrollArea(parent), d_ptr(new QtGradientStopsWidgetPrivate) { - d_ptr = new QtGradientStopsWidgetPrivate; d_ptr->q_ptr = this; d_ptr->m_backgroundCheckered = true; d_ptr->m_model = 0; @@ -391,7 +390,6 @@ QtGradientStopsWidget::QtGradientStopsWidget(QWidget *parent) QtGradientStopsWidget::~QtGradientStopsWidget() { - delete d_ptr; } QSize QtGradientStopsWidget::sizeHint() const diff --git a/tools/shared/qtgradienteditor/qtgradientstopswidget.h b/tools/shared/qtgradienteditor/qtgradientstopswidget.h index aafea8b..79d6576 100644 --- a/tools/shared/qtgradienteditor/qtgradientstopswidget.h +++ b/tools/shared/qtgradienteditor/qtgradientstopswidget.h @@ -91,7 +91,7 @@ protected: #endif private: - QtGradientStopsWidgetPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtGradientStopsWidget) Q_DISABLE_COPY(QtGradientStopsWidget) Q_PRIVATE_SLOT(d_func(), void slotStopAdded(QtGradientStop *stop)) diff --git a/tools/shared/qtgradienteditor/qtgradientwidget.cpp b/tools/shared/qtgradienteditor/qtgradientwidget.cpp index 3f6b48d..4b70cc2 100644 --- a/tools/shared/qtgradienteditor/qtgradientwidget.cpp +++ b/tools/shared/qtgradienteditor/qtgradientwidget.cpp @@ -232,9 +232,8 @@ void QtGradientWidgetPrivate::setupDrag(QtGradientStop *stop, int x) //////////////////////////// QtGradientWidget::QtGradientWidget(QWidget *parent) - : QWidget(parent) + : QWidget(parent), d_ptr(new QtGradientWidgetPrivate) { - d_ptr = new QtGradientWidgetPrivate; d_ptr->q_ptr = this; d_ptr->m_backgroundCheckered = true; d_ptr->m_handleSize = 20.0; @@ -253,7 +252,6 @@ QtGradientWidget::QtGradientWidget(QWidget *parent) QtGradientWidget::~QtGradientWidget() { - delete d_ptr; } QSize QtGradientWidget::sizeHint() const diff --git a/tools/shared/qtgradienteditor/qtgradientwidget.h b/tools/shared/qtgradienteditor/qtgradientwidget.h index 4dc740b..d994534 100644 --- a/tools/shared/qtgradienteditor/qtgradientwidget.h +++ b/tools/shared/qtgradienteditor/qtgradientwidget.h @@ -110,7 +110,7 @@ protected: void mouseDoubleClickEvent(QMouseEvent *e); private: - class QtGradientWidgetPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtGradientWidget) Q_DISABLE_COPY(QtGradientWidget) }; diff --git a/tools/shared/qtpropertybrowser/qtbuttonpropertybrowser.cpp b/tools/shared/qtpropertybrowser/qtbuttonpropertybrowser.cpp index 09394e7..3ccc423 100644 --- a/tools/shared/qtpropertybrowser/qtbuttonpropertybrowser.cpp +++ b/tools/shared/qtpropertybrowser/qtbuttonpropertybrowser.cpp @@ -547,9 +547,8 @@ void QtButtonPropertyBrowserPrivate::updateItem(WidgetItem *item) Creates a property browser with the given \a parent. */ QtButtonPropertyBrowser::QtButtonPropertyBrowser(QWidget *parent) - : QtAbstractPropertyBrowser(parent) + : QtAbstractPropertyBrowser(parent), d_ptr(new QtButtonPropertyBrowserPrivate) { - d_ptr = new QtButtonPropertyBrowserPrivate; d_ptr->q_ptr = this; d_ptr->init(this); @@ -570,7 +569,6 @@ QtButtonPropertyBrowser::~QtButtonPropertyBrowser() const QMap::ConstIterator icend = d_ptr->m_itemToIndex.constEnd(); for (QMap::ConstIterator it = d_ptr->m_itemToIndex.constBegin(); it != icend; ++it) delete it.key(); - delete d_ptr; } /*! diff --git a/tools/shared/qtpropertybrowser/qtbuttonpropertybrowser.h b/tools/shared/qtpropertybrowser/qtbuttonpropertybrowser.h index 0238f5c..bac9d95 100644 --- a/tools/shared/qtpropertybrowser/qtbuttonpropertybrowser.h +++ b/tools/shared/qtpropertybrowser/qtbuttonpropertybrowser.h @@ -71,7 +71,7 @@ protected: private: - QtButtonPropertyBrowserPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtButtonPropertyBrowser) Q_DISABLE_COPY(QtButtonPropertyBrowser) Q_PRIVATE_SLOT(d_func(), void slotUpdate()) diff --git a/tools/shared/qtpropertybrowser/qteditorfactory.cpp b/tools/shared/qtpropertybrowser/qteditorfactory.cpp index a2e3917..01d955a 100644 --- a/tools/shared/qtpropertybrowser/qteditorfactory.cpp +++ b/tools/shared/qtpropertybrowser/qteditorfactory.cpp @@ -227,9 +227,8 @@ void QtSpinBoxFactoryPrivate::slotSetValue(int value) Creates a factory with the given \a parent. */ QtSpinBoxFactory::QtSpinBoxFactory(QObject *parent) - : QtAbstractEditorFactory(parent) + : QtAbstractEditorFactory(parent), d_ptr(new QtSpinBoxFactoryPrivate()) { - d_ptr = new QtSpinBoxFactoryPrivate(); d_ptr->q_ptr = this; } @@ -240,7 +239,6 @@ QtSpinBoxFactory::QtSpinBoxFactory(QObject *parent) QtSpinBoxFactory::~QtSpinBoxFactory() { qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; } /*! @@ -383,9 +381,8 @@ void QtSliderFactoryPrivate::slotSetValue(int value) Creates a factory with the given \a parent. */ QtSliderFactory::QtSliderFactory(QObject *parent) - : QtAbstractEditorFactory(parent) + : QtAbstractEditorFactory(parent), d_ptr(new QtSliderFactoryPrivate()) { - d_ptr = new QtSliderFactoryPrivate(); d_ptr->q_ptr = this; } @@ -396,7 +393,6 @@ QtSliderFactory::QtSliderFactory(QObject *parent) QtSliderFactory::~QtSliderFactory() { qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; } /*! @@ -539,9 +535,8 @@ void QtScrollBarFactoryPrivate::slotSetValue(int value) Creates a factory with the given \a parent. */ QtScrollBarFactory::QtScrollBarFactory(QObject *parent) - : QtAbstractEditorFactory(parent) + : QtAbstractEditorFactory(parent), d_ptr(new QtScrollBarFactoryPrivate()) { - d_ptr = new QtScrollBarFactoryPrivate(); d_ptr->q_ptr = this; } @@ -552,7 +547,6 @@ QtScrollBarFactory::QtScrollBarFactory(QObject *parent) QtScrollBarFactory::~QtScrollBarFactory() { qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; } /*! @@ -661,9 +655,8 @@ void QtCheckBoxFactoryPrivate::slotSetValue(bool value) Creates a factory with the given \a parent. */ QtCheckBoxFactory::QtCheckBoxFactory(QObject *parent) - : QtAbstractEditorFactory(parent) + : QtAbstractEditorFactory(parent), d_ptr(new QtCheckBoxFactoryPrivate()) { - d_ptr = new QtCheckBoxFactoryPrivate(); d_ptr->q_ptr = this; } @@ -674,7 +667,6 @@ QtCheckBoxFactory::QtCheckBoxFactory(QObject *parent) QtCheckBoxFactory::~QtCheckBoxFactory() { qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; } /*! @@ -836,9 +828,8 @@ void QtDoubleSpinBoxFactoryPrivate::slotSetValue(double value) Creates a factory with the given \a parent. */ QtDoubleSpinBoxFactory::QtDoubleSpinBoxFactory(QObject *parent) - : QtAbstractEditorFactory(parent) + : QtAbstractEditorFactory(parent), d_ptr(new QtDoubleSpinBoxFactoryPrivate()) { - d_ptr = new QtDoubleSpinBoxFactoryPrivate(); d_ptr->q_ptr = this; } @@ -849,7 +840,6 @@ QtDoubleSpinBoxFactory::QtDoubleSpinBoxFactory(QObject *parent) QtDoubleSpinBoxFactory::~QtDoubleSpinBoxFactory() { qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; } /*! @@ -991,9 +981,8 @@ void QtLineEditFactoryPrivate::slotSetValue(const QString &value) Creates a factory with the given \a parent. */ QtLineEditFactory::QtLineEditFactory(QObject *parent) - : QtAbstractEditorFactory(parent) + : QtAbstractEditorFactory(parent), d_ptr(new QtLineEditFactoryPrivate()) { - d_ptr = new QtLineEditFactoryPrivate(); d_ptr->q_ptr = this; } @@ -1004,7 +993,6 @@ QtLineEditFactory::QtLineEditFactory(QObject *parent) QtLineEditFactory::~QtLineEditFactory() { qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; } /*! @@ -1134,9 +1122,8 @@ void QtDateEditFactoryPrivate::slotSetValue(const QDate &value) Creates a factory with the given \a parent. */ QtDateEditFactory::QtDateEditFactory(QObject *parent) - : QtAbstractEditorFactory(parent) + : QtAbstractEditorFactory(parent), d_ptr(new QtDateEditFactoryPrivate()) { - d_ptr = new QtDateEditFactoryPrivate(); d_ptr->q_ptr = this; } @@ -1147,7 +1134,6 @@ QtDateEditFactory::QtDateEditFactory(QObject *parent) QtDateEditFactory::~QtDateEditFactory() { qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; } /*! @@ -1252,9 +1238,8 @@ void QtTimeEditFactoryPrivate::slotSetValue(const QTime &value) Creates a factory with the given \a parent. */ QtTimeEditFactory::QtTimeEditFactory(QObject *parent) - : QtAbstractEditorFactory(parent) + : QtAbstractEditorFactory(parent), d_ptr(new QtTimeEditFactoryPrivate()) { - d_ptr = new QtTimeEditFactoryPrivate(); d_ptr->q_ptr = this; } @@ -1265,7 +1250,6 @@ QtTimeEditFactory::QtTimeEditFactory(QObject *parent) QtTimeEditFactory::~QtTimeEditFactory() { qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; } /*! @@ -1367,9 +1351,8 @@ void QtDateTimeEditFactoryPrivate::slotSetValue(const QDateTime &value) Creates a factory with the given \a parent. */ QtDateTimeEditFactory::QtDateTimeEditFactory(QObject *parent) - : QtAbstractEditorFactory(parent) + : QtAbstractEditorFactory(parent), d_ptr(new QtDateTimeEditFactoryPrivate()) { - d_ptr = new QtDateTimeEditFactoryPrivate(); d_ptr->q_ptr = this; } @@ -1380,7 +1363,6 @@ QtDateTimeEditFactory::QtDateTimeEditFactory(QObject *parent) QtDateTimeEditFactory::~QtDateTimeEditFactory() { qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; } /*! @@ -1481,9 +1463,8 @@ void QtKeySequenceEditorFactoryPrivate::slotSetValue(const QKeySequence &value) Creates a factory with the given \a parent. */ QtKeySequenceEditorFactory::QtKeySequenceEditorFactory(QObject *parent) - : QtAbstractEditorFactory(parent) + : QtAbstractEditorFactory(parent), d_ptr(new QtKeySequenceEditorFactoryPrivate()) { - d_ptr = new QtKeySequenceEditorFactoryPrivate(); d_ptr->q_ptr = this; } @@ -1494,7 +1475,6 @@ QtKeySequenceEditorFactory::QtKeySequenceEditorFactory(QObject *parent) QtKeySequenceEditorFactory::~QtKeySequenceEditorFactory() { qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; } /*! @@ -1765,9 +1745,8 @@ void QtCharEditorFactoryPrivate::slotSetValue(const QChar &value) Creates a factory with the given \a parent. */ QtCharEditorFactory::QtCharEditorFactory(QObject *parent) - : QtAbstractEditorFactory(parent) + : QtAbstractEditorFactory(parent), d_ptr(new QtCharEditorFactoryPrivate()) { - d_ptr = new QtCharEditorFactoryPrivate(); d_ptr->q_ptr = this; } @@ -1778,7 +1757,6 @@ QtCharEditorFactory::QtCharEditorFactory(QObject *parent) QtCharEditorFactory::~QtCharEditorFactory() { qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; } /*! @@ -1929,9 +1907,8 @@ void QtEnumEditorFactoryPrivate::slotSetValue(int value) Creates a factory with the given \a parent. */ QtEnumEditorFactory::QtEnumEditorFactory(QObject *parent) - : QtAbstractEditorFactory(parent) + : QtAbstractEditorFactory(parent), d_ptr(new QtEnumEditorFactoryPrivate()) { - d_ptr = new QtEnumEditorFactoryPrivate(); d_ptr->q_ptr = this; } @@ -1942,7 +1919,6 @@ QtEnumEditorFactory::QtEnumEditorFactory(QObject *parent) QtEnumEditorFactory::~QtEnumEditorFactory() { qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; } /*! @@ -2094,9 +2070,8 @@ void QtCursorEditorFactoryPrivate::slotEditorDestroyed(QObject *object) Creates a factory with the given \a parent. */ QtCursorEditorFactory::QtCursorEditorFactory(QObject *parent) - : QtAbstractEditorFactory(parent) + : QtAbstractEditorFactory(parent), d_ptr(new QtCursorEditorFactoryPrivate()) { - d_ptr = new QtCursorEditorFactoryPrivate(); d_ptr->q_ptr = this; d_ptr->m_enumEditorFactory = new QtEnumEditorFactory(this); @@ -2111,7 +2086,6 @@ QtCursorEditorFactory::QtCursorEditorFactory(QObject *parent) */ QtCursorEditorFactory::~QtCursorEditorFactory() { - delete d_ptr; } /*! @@ -2328,7 +2302,6 @@ QtColorEditorFactory::QtColorEditorFactory(QObject *parent) : QtColorEditorFactory::~QtColorEditorFactory() { qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; } /*! @@ -2542,7 +2515,6 @@ QtFontEditorFactory::QtFontEditorFactory(QObject *parent) : QtFontEditorFactory::~QtFontEditorFactory() { qDeleteAll(d_ptr->m_editorToProperty.keys()); - delete d_ptr; } /*! diff --git a/tools/shared/qtpropertybrowser/qteditorfactory.h b/tools/shared/qtpropertybrowser/qteditorfactory.h index d86f9f6..f5a1605 100644 --- a/tools/shared/qtpropertybrowser/qteditorfactory.h +++ b/tools/shared/qtpropertybrowser/qteditorfactory.h @@ -60,7 +60,7 @@ protected: QWidget *parent); void disconnectPropertyManager(QtIntPropertyManager *manager); private: - QtSpinBoxFactoryPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtSpinBoxFactory) Q_DISABLE_COPY(QtSpinBoxFactory) Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, int)) @@ -84,7 +84,7 @@ protected: QWidget *parent); void disconnectPropertyManager(QtIntPropertyManager *manager); private: - QtSliderFactoryPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtSliderFactory) Q_DISABLE_COPY(QtSliderFactory) Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, int)) @@ -108,7 +108,7 @@ protected: QWidget *parent); void disconnectPropertyManager(QtIntPropertyManager *manager); private: - QtScrollBarFactoryPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtScrollBarFactory) Q_DISABLE_COPY(QtScrollBarFactory) Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, int)) @@ -132,7 +132,7 @@ protected: QWidget *parent); void disconnectPropertyManager(QtBoolPropertyManager *manager); private: - QtCheckBoxFactoryPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtCheckBoxFactory) Q_DISABLE_COPY(QtCheckBoxFactory) Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, bool)) @@ -154,7 +154,7 @@ protected: QWidget *parent); void disconnectPropertyManager(QtDoublePropertyManager *manager); private: - QtDoubleSpinBoxFactoryPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtDoubleSpinBoxFactory) Q_DISABLE_COPY(QtDoubleSpinBoxFactory) Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, double)) @@ -179,7 +179,7 @@ protected: QWidget *parent); void disconnectPropertyManager(QtStringPropertyManager *manager); private: - QtLineEditFactoryPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtLineEditFactory) Q_DISABLE_COPY(QtLineEditFactory) Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, const QString &)) @@ -202,7 +202,7 @@ protected: QWidget *parent); void disconnectPropertyManager(QtDatePropertyManager *manager); private: - QtDateEditFactoryPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtDateEditFactory) Q_DISABLE_COPY(QtDateEditFactory) Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, const QDate &)) @@ -226,7 +226,7 @@ protected: QWidget *parent); void disconnectPropertyManager(QtTimePropertyManager *manager); private: - QtTimeEditFactoryPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtTimeEditFactory) Q_DISABLE_COPY(QtTimeEditFactory) Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, const QTime &)) @@ -248,7 +248,7 @@ protected: QWidget *parent); void disconnectPropertyManager(QtDateTimePropertyManager *manager); private: - QtDateTimeEditFactoryPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtDateTimeEditFactory) Q_DISABLE_COPY(QtDateTimeEditFactory) Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, const QDateTime &)) @@ -270,7 +270,7 @@ protected: QWidget *parent); void disconnectPropertyManager(QtKeySequencePropertyManager *manager); private: - QtKeySequenceEditorFactoryPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtKeySequenceEditorFactory) Q_DISABLE_COPY(QtKeySequenceEditorFactory) Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, const QKeySequence &)) @@ -292,7 +292,7 @@ protected: QWidget *parent); void disconnectPropertyManager(QtCharPropertyManager *manager); private: - QtCharEditorFactoryPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtCharEditorFactory) Q_DISABLE_COPY(QtCharEditorFactory) Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, const QChar &)) @@ -314,7 +314,7 @@ protected: QWidget *parent); void disconnectPropertyManager(QtEnumPropertyManager *manager); private: - QtEnumEditorFactoryPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtEnumEditorFactory) Q_DISABLE_COPY(QtEnumEditorFactory) Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, int)) @@ -340,7 +340,7 @@ protected: QWidget *parent); void disconnectPropertyManager(QtCursorPropertyManager *manager); private: - QtCursorEditorFactoryPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtCursorEditorFactory) Q_DISABLE_COPY(QtCursorEditorFactory) Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, const QCursor &)) @@ -362,7 +362,7 @@ protected: QWidget *parent); void disconnectPropertyManager(QtColorPropertyManager *manager); private: - QtColorEditorFactoryPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtColorEditorFactory) Q_DISABLE_COPY(QtColorEditorFactory) Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, const QColor &)) @@ -384,7 +384,7 @@ protected: QWidget *parent); void disconnectPropertyManager(QtFontPropertyManager *manager); private: - QtFontEditorFactoryPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtFontEditorFactory) Q_DISABLE_COPY(QtFontEditorFactory) Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, const QFont &)) diff --git a/tools/shared/qtpropertybrowser/qtgroupboxpropertybrowser.cpp b/tools/shared/qtpropertybrowser/qtgroupboxpropertybrowser.cpp index 9ac9744..4b44f97 100644 --- a/tools/shared/qtpropertybrowser/qtgroupboxpropertybrowser.cpp +++ b/tools/shared/qtpropertybrowser/qtgroupboxpropertybrowser.cpp @@ -476,9 +476,8 @@ void QtGroupBoxPropertyBrowserPrivate::updateItem(WidgetItem *item) Creates a property browser with the given \a parent. */ QtGroupBoxPropertyBrowser::QtGroupBoxPropertyBrowser(QWidget *parent) - : QtAbstractPropertyBrowser(parent) + : QtAbstractPropertyBrowser(parent), d_ptr(new QtGroupBoxPropertyBrowserPrivate) { - d_ptr = new QtGroupBoxPropertyBrowserPrivate; d_ptr->q_ptr = this; d_ptr->init(this); @@ -499,7 +498,6 @@ QtGroupBoxPropertyBrowser::~QtGroupBoxPropertyBrowser() const QMap::ConstIterator icend = d_ptr->m_itemToIndex.constEnd(); for (QMap::ConstIterator it = d_ptr->m_itemToIndex.constBegin(); it != icend; ++it) delete it.key(); - delete d_ptr; } /*! diff --git a/tools/shared/qtpropertybrowser/qtgroupboxpropertybrowser.h b/tools/shared/qtpropertybrowser/qtgroupboxpropertybrowser.h index 6d1b2b1..6f48b8f 100644 --- a/tools/shared/qtpropertybrowser/qtgroupboxpropertybrowser.h +++ b/tools/shared/qtpropertybrowser/qtgroupboxpropertybrowser.h @@ -63,7 +63,7 @@ protected: private: - QtGroupBoxPropertyBrowserPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtGroupBoxPropertyBrowser) Q_DISABLE_COPY(QtGroupBoxPropertyBrowser) Q_PRIVATE_SLOT(d_func(), void slotUpdate()) diff --git a/tools/shared/qtpropertybrowser/qtpropertybrowser.cpp b/tools/shared/qtpropertybrowser/qtpropertybrowser.cpp index cca082d..0f4b197 100644 --- a/tools/shared/qtpropertybrowser/qtpropertybrowser.cpp +++ b/tools/shared/qtpropertybrowser/qtpropertybrowser.cpp @@ -142,8 +142,8 @@ public: \sa QtAbstractPropertyManager::addProperty() */ QtProperty::QtProperty(QtAbstractPropertyManager *manager) + : d_ptr(new QtPropertyPrivate(manager)) { - d_ptr = new QtPropertyPrivate(manager); d_ptr->q_ptr = this; } @@ -177,7 +177,6 @@ QtProperty::~QtProperty() QtProperty *property = itParent.next(); property->d_ptr->m_subItems.removeAll(this); } - delete d_ptr; } /*! @@ -638,9 +637,8 @@ void QtAbstractPropertyManagerPrivate::propertyInserted(QtProperty *property, Creates an abstract property manager with the given \a parent. */ QtAbstractPropertyManager::QtAbstractPropertyManager(QObject *parent) - : QObject(parent) + : QObject(parent), d_ptr(new QtAbstractPropertyManagerPrivate) { - d_ptr = new QtAbstractPropertyManagerPrivate; d_ptr->q_ptr = this; } @@ -652,7 +650,6 @@ QtAbstractPropertyManager::QtAbstractPropertyManager(QObject *parent) QtAbstractPropertyManager::~QtAbstractPropertyManager() { clear(); - delete d_ptr; } /*! @@ -1167,14 +1164,13 @@ QtAbstractPropertyBrowser *QtBrowserItem::browser() const } QtBrowserItem::QtBrowserItem(QtAbstractPropertyBrowser *browser, QtProperty *property, QtBrowserItem *parent) + : d_ptr(new QtBrowserItemPrivate(browser, property, parent)) { - d_ptr = new QtBrowserItemPrivate(browser, property, parent); d_ptr->q_ptr = this; } QtBrowserItem::~QtBrowserItem() { - delete d_ptr; } @@ -1646,9 +1642,8 @@ void QtAbstractPropertyBrowserPrivate::slotPropertyDataChanged(QtProperty *prope Creates an abstract property browser with the given \a parent. */ QtAbstractPropertyBrowser::QtAbstractPropertyBrowser(QWidget *parent) - : QWidget(parent) + : QWidget(parent), d_ptr(new QtAbstractPropertyBrowserPrivate) { - d_ptr = new QtAbstractPropertyBrowserPrivate; d_ptr->q_ptr = this; } @@ -1671,7 +1666,6 @@ QtAbstractPropertyBrowser::~QtAbstractPropertyBrowser() QListIterator itItem(indexes); while (itItem.hasNext()) d_ptr->clearIndex(itItem.next()); - delete d_ptr; } /*! diff --git a/tools/shared/qtpropertybrowser/qtpropertybrowser.h b/tools/shared/qtpropertybrowser/qtpropertybrowser.h index 20ffb81..5a878bb 100644 --- a/tools/shared/qtpropertybrowser/qtpropertybrowser.h +++ b/tools/shared/qtpropertybrowser/qtpropertybrowser.h @@ -85,7 +85,7 @@ protected: void propertyChanged(); private: friend class QtAbstractPropertyManager; - QtPropertyPrivate *d_ptr; + QScopedPointer d_ptr; }; class QtAbstractPropertyManagerPrivate; @@ -118,7 +118,7 @@ protected: virtual QtProperty *createProperty(); private: friend class QtProperty; - QtAbstractPropertyManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtAbstractPropertyManager) Q_DISABLE_COPY(QtAbstractPropertyManager) }; @@ -235,7 +235,7 @@ public: private: explicit QtBrowserItem(QtAbstractPropertyBrowser *browser, QtProperty *property, QtBrowserItem *parent); ~QtBrowserItem(); - QtBrowserItemPrivate *d_ptr; + QScopedPointer d_ptr; friend class QtAbstractPropertyBrowserPrivate; }; @@ -292,7 +292,7 @@ private: bool addFactory(QtAbstractPropertyManager *abstractManager, QtAbstractEditorFactoryBase *abstractFactory); - QtAbstractPropertyBrowserPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtAbstractPropertyBrowser) Q_DISABLE_COPY(QtAbstractPropertyBrowser) Q_PRIVATE_SLOT(d_func(), void slotPropertyInserted(QtProperty *, diff --git a/tools/shared/qtpropertybrowser/qtpropertymanager.cpp b/tools/shared/qtpropertybrowser/qtpropertymanager.cpp index 47b8c9b..df74b6e 100644 --- a/tools/shared/qtpropertybrowser/qtpropertymanager.cpp +++ b/tools/shared/qtpropertybrowser/qtpropertymanager.cpp @@ -677,9 +677,8 @@ public: Creates a manager with the given \a parent. */ QtIntPropertyManager::QtIntPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) + : QtAbstractPropertyManager(parent), d_ptr(new QtIntPropertyManagerPrivate) { - d_ptr = new QtIntPropertyManagerPrivate; d_ptr->q_ptr = this; } @@ -689,7 +688,6 @@ QtIntPropertyManager::QtIntPropertyManager(QObject *parent) QtIntPropertyManager::~QtIntPropertyManager() { clear(); - delete d_ptr; } /*! @@ -762,7 +760,7 @@ QString QtIntPropertyManager::valueText(const QtProperty *property) const void QtIntPropertyManager::setValue(QtProperty *property, int val) { void (QtIntPropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, int) = 0; - setValueInRange(this, d_ptr, + setValueInRange(this, d_ptr.data(), &QtIntPropertyManager::propertyChanged, &QtIntPropertyManager::valueChanged, property, val, setSubPropertyValue); @@ -779,7 +777,7 @@ void QtIntPropertyManager::setValue(QtProperty *property, int val) */ void QtIntPropertyManager::setMinimum(QtProperty *property, int minVal) { - setMinimumValue(this, d_ptr, + setMinimumValue(this, d_ptr.data(), &QtIntPropertyManager::propertyChanged, &QtIntPropertyManager::valueChanged, &QtIntPropertyManager::rangeChanged, @@ -797,7 +795,7 @@ void QtIntPropertyManager::setMinimum(QtProperty *property, int minVal) */ void QtIntPropertyManager::setMaximum(QtProperty *property, int maxVal) { - setMaximumValue(this, d_ptr, + setMaximumValue(this, d_ptr.data(), &QtIntPropertyManager::propertyChanged, &QtIntPropertyManager::valueChanged, &QtIntPropertyManager::rangeChanged, @@ -821,7 +819,7 @@ void QtIntPropertyManager::setMaximum(QtProperty *property, int maxVal) void QtIntPropertyManager::setRange(QtProperty *property, int minVal, int maxVal) { void (QtIntPropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, int, int, int) = 0; - setBorderValues(this, d_ptr, + setBorderValues(this, d_ptr.data(), &QtIntPropertyManager::propertyChanged, &QtIntPropertyManager::valueChanged, &QtIntPropertyManager::rangeChanged, @@ -968,9 +966,8 @@ public: Creates a manager with the given \a parent. */ QtDoublePropertyManager::QtDoublePropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) + : QtAbstractPropertyManager(parent), d_ptr(new QtDoublePropertyManagerPrivate) { - d_ptr = new QtDoublePropertyManagerPrivate; d_ptr->q_ptr = this; } @@ -980,7 +977,6 @@ QtDoublePropertyManager::QtDoublePropertyManager(QObject *parent) QtDoublePropertyManager::~QtDoublePropertyManager() { clear(); - delete d_ptr; } /*! @@ -1063,7 +1059,7 @@ QString QtDoublePropertyManager::valueText(const QtProperty *property) const void QtDoublePropertyManager::setValue(QtProperty *property, double val) { void (QtDoublePropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, double) = 0; - setValueInRange(this, d_ptr, + setValueInRange(this, d_ptr.data(), &QtDoublePropertyManager::propertyChanged, &QtDoublePropertyManager::valueChanged, property, val, setSubPropertyValue); @@ -1140,7 +1136,7 @@ void QtDoublePropertyManager::setDecimals(QtProperty *property, int prec) */ void QtDoublePropertyManager::setMinimum(QtProperty *property, double minVal) { - setMinimumValue(this, d_ptr, + setMinimumValue(this, d_ptr.data(), &QtDoublePropertyManager::propertyChanged, &QtDoublePropertyManager::valueChanged, &QtDoublePropertyManager::rangeChanged, @@ -1158,7 +1154,7 @@ void QtDoublePropertyManager::setMinimum(QtProperty *property, double minVal) */ void QtDoublePropertyManager::setMaximum(QtProperty *property, double maxVal) { - setMaximumValue(this, d_ptr, + setMaximumValue(this, d_ptr.data(), &QtDoublePropertyManager::propertyChanged, &QtDoublePropertyManager::valueChanged, &QtDoublePropertyManager::rangeChanged, @@ -1182,7 +1178,7 @@ void QtDoublePropertyManager::setMaximum(QtProperty *property, double maxVal) void QtDoublePropertyManager::setRange(QtProperty *property, double minVal, double maxVal) { void (QtDoublePropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, double, double, double) = 0; - setBorderValues(this, d_ptr, + setBorderValues(this, d_ptr.data(), &QtDoublePropertyManager::propertyChanged, &QtDoublePropertyManager::valueChanged, &QtDoublePropertyManager::rangeChanged, @@ -1273,9 +1269,8 @@ public: Creates a manager with the given \a parent. */ QtStringPropertyManager::QtStringPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) + : QtAbstractPropertyManager(parent), d_ptr(new QtStringPropertyManagerPrivate) { - d_ptr = new QtStringPropertyManagerPrivate; d_ptr->q_ptr = this; } @@ -1285,7 +1280,6 @@ QtStringPropertyManager::QtStringPropertyManager(QObject *parent) QtStringPropertyManager::~QtStringPropertyManager() { clear(); - delete d_ptr; } /*! @@ -1437,9 +1431,8 @@ public: Creates a manager with the given \a parent. */ QtBoolPropertyManager::QtBoolPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) + : QtAbstractPropertyManager(parent), d_ptr(new QtBoolPropertyManagerPrivate) { - d_ptr = new QtBoolPropertyManagerPrivate; d_ptr->q_ptr = this; } @@ -1449,7 +1442,6 @@ QtBoolPropertyManager::QtBoolPropertyManager(QObject *parent) QtBoolPropertyManager::~QtBoolPropertyManager() { clear(); - delete d_ptr; } /*! @@ -1630,9 +1622,8 @@ public: Creates a manager with the given \a parent. */ QtDatePropertyManager::QtDatePropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) + : QtAbstractPropertyManager(parent), d_ptr(new QtDatePropertyManagerPrivate) { - d_ptr = new QtDatePropertyManagerPrivate; d_ptr->q_ptr = this; QLocale loc; @@ -1645,7 +1636,6 @@ QtDatePropertyManager::QtDatePropertyManager(QObject *parent) QtDatePropertyManager::~QtDatePropertyManager() { clear(); - delete d_ptr; } /*! @@ -1706,7 +1696,7 @@ QString QtDatePropertyManager::valueText(const QtProperty *property) const void QtDatePropertyManager::setValue(QtProperty *property, const QDate &val) { void (QtDatePropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, const QDate &) = 0; - setValueInRange(this, d_ptr, + setValueInRange(this, d_ptr.data(), &QtDatePropertyManager::propertyChanged, &QtDatePropertyManager::valueChanged, property, val, setSubPropertyValue); @@ -1723,7 +1713,7 @@ void QtDatePropertyManager::setValue(QtProperty *property, const QDate &val) */ void QtDatePropertyManager::setMinimum(QtProperty *property, const QDate &minVal) { - setMinimumValue(this, d_ptr, + setMinimumValue(this, d_ptr.data(), &QtDatePropertyManager::propertyChanged, &QtDatePropertyManager::valueChanged, &QtDatePropertyManager::rangeChanged, @@ -1741,7 +1731,7 @@ void QtDatePropertyManager::setMinimum(QtProperty *property, const QDate &minVal */ void QtDatePropertyManager::setMaximum(QtProperty *property, const QDate &maxVal) { - setMaximumValue(this, d_ptr, + setMaximumValue(this, d_ptr.data(), &QtDatePropertyManager::propertyChanged, &QtDatePropertyManager::valueChanged, &QtDatePropertyManager::rangeChanged, @@ -1766,7 +1756,7 @@ void QtDatePropertyManager::setRange(QtProperty *property, const QDate &minVal, { void (QtDatePropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, const QDate &, const QDate &, const QDate &) = 0; - setBorderValues(this, d_ptr, + setBorderValues(this, d_ptr.data(), &QtDatePropertyManager::propertyChanged, &QtDatePropertyManager::valueChanged, &QtDatePropertyManager::rangeChanged, @@ -1835,9 +1825,8 @@ public: Creates a manager with the given \a parent. */ QtTimePropertyManager::QtTimePropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) + : QtAbstractPropertyManager(parent), d_ptr(new QtTimePropertyManagerPrivate) { - d_ptr = new QtTimePropertyManagerPrivate; d_ptr->q_ptr = this; QLocale loc; @@ -1850,7 +1839,6 @@ QtTimePropertyManager::QtTimePropertyManager(QObject *parent) QtTimePropertyManager::~QtTimePropertyManager() { clear(); - delete d_ptr; } /*! @@ -1950,9 +1938,8 @@ public: Creates a manager with the given \a parent. */ QtDateTimePropertyManager::QtDateTimePropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) + : QtAbstractPropertyManager(parent), d_ptr(new QtDateTimePropertyManagerPrivate) { - d_ptr = new QtDateTimePropertyManagerPrivate; d_ptr->q_ptr = this; QLocale loc; @@ -1967,7 +1954,6 @@ QtDateTimePropertyManager::QtDateTimePropertyManager(QObject *parent) QtDateTimePropertyManager::~QtDateTimePropertyManager() { clear(); - delete d_ptr; } /*! @@ -2068,9 +2054,8 @@ public: Creates a manager with the given \a parent. */ QtKeySequencePropertyManager::QtKeySequencePropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) + : QtAbstractPropertyManager(parent), d_ptr(new QtKeySequencePropertyManagerPrivate) { - d_ptr = new QtKeySequencePropertyManagerPrivate; d_ptr->q_ptr = this; } @@ -2080,7 +2065,6 @@ QtKeySequencePropertyManager::QtKeySequencePropertyManager(QObject *parent) QtKeySequencePropertyManager::~QtKeySequencePropertyManager() { clear(); - delete d_ptr; } /*! @@ -2179,9 +2163,8 @@ public: Creates a manager with the given \a parent. */ QtCharPropertyManager::QtCharPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) + : QtAbstractPropertyManager(parent), d_ptr(new QtCharPropertyManagerPrivate) { - d_ptr = new QtCharPropertyManagerPrivate; d_ptr->q_ptr = this; } @@ -2191,7 +2174,6 @@ QtCharPropertyManager::QtCharPropertyManager(QObject *parent) QtCharPropertyManager::~QtCharPropertyManager() { clear(); - delete d_ptr; } /*! @@ -2347,9 +2329,8 @@ void QtLocalePropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) Creates a manager with the given \a parent. */ QtLocalePropertyManager::QtLocalePropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) + : QtAbstractPropertyManager(parent), d_ptr(new QtLocalePropertyManagerPrivate) { - d_ptr = new QtLocalePropertyManagerPrivate; d_ptr->q_ptr = this; d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this); @@ -2366,7 +2347,6 @@ QtLocalePropertyManager::QtLocalePropertyManager(QObject *parent) QtLocalePropertyManager::~QtLocalePropertyManager() { clear(); - delete d_ptr; } /*! @@ -2586,9 +2566,8 @@ void QtPointPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) Creates a manager with the given \a parent. */ QtPointPropertyManager::QtPointPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) + : QtAbstractPropertyManager(parent), d_ptr(new QtPointPropertyManagerPrivate) { - d_ptr = new QtPointPropertyManagerPrivate; d_ptr->q_ptr = this; d_ptr->m_intPropertyManager = new QtIntPropertyManager(this); @@ -2604,7 +2583,6 @@ QtPointPropertyManager::QtPointPropertyManager(QObject *parent) QtPointPropertyManager::~QtPointPropertyManager() { clear(); - delete d_ptr; } /*! @@ -2818,9 +2796,8 @@ void QtPointFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) Creates a manager with the given \a parent. */ QtPointFPropertyManager::QtPointFPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) + : QtAbstractPropertyManager(parent), d_ptr(new QtPointFPropertyManagerPrivate) { - d_ptr = new QtPointFPropertyManagerPrivate; d_ptr->q_ptr = this; d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this); @@ -2836,7 +2813,6 @@ QtPointFPropertyManager::QtPointFPropertyManager(QObject *parent) QtPointFPropertyManager::~QtPointFPropertyManager() { clear(); - delete d_ptr; } /*! @@ -3131,9 +3107,8 @@ void QtSizePropertyManagerPrivate::setRange(QtProperty *property, Creates a manager with the given \a parent. */ QtSizePropertyManager::QtSizePropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) + : QtAbstractPropertyManager(parent), d_ptr(new QtSizePropertyManagerPrivate) { - d_ptr = new QtSizePropertyManagerPrivate; d_ptr->q_ptr = this; d_ptr->m_intPropertyManager = new QtIntPropertyManager(this); @@ -3149,7 +3124,6 @@ QtSizePropertyManager::QtSizePropertyManager(QObject *parent) QtSizePropertyManager::~QtSizePropertyManager() { clear(); - delete d_ptr; } /*! @@ -3226,7 +3200,7 @@ QString QtSizePropertyManager::valueText(const QtProperty *property) const */ void QtSizePropertyManager::setValue(QtProperty *property, const QSize &val) { - setValueInRange(this, d_ptr, + setValueInRange(this, d_ptr.data(), &QtSizePropertyManager::propertyChanged, &QtSizePropertyManager::valueChanged, property, val, &QtSizePropertyManagerPrivate::setValue); @@ -3243,7 +3217,7 @@ void QtSizePropertyManager::setValue(QtProperty *property, const QSize &val) */ void QtSizePropertyManager::setMinimum(QtProperty *property, const QSize &minVal) { - setBorderValue(this, d_ptr, + setBorderValue(this, d_ptr.data(), &QtSizePropertyManager::propertyChanged, &QtSizePropertyManager::valueChanged, &QtSizePropertyManager::rangeChanged, @@ -3264,7 +3238,7 @@ void QtSizePropertyManager::setMinimum(QtProperty *property, const QSize &minVal */ void QtSizePropertyManager::setMaximum(QtProperty *property, const QSize &maxVal) { - setBorderValue(this, d_ptr, + setBorderValue(this, d_ptr.data(), &QtSizePropertyManager::propertyChanged, &QtSizePropertyManager::valueChanged, &QtSizePropertyManager::rangeChanged, @@ -3290,7 +3264,7 @@ void QtSizePropertyManager::setMaximum(QtProperty *property, const QSize &maxVal */ void QtSizePropertyManager::setRange(QtProperty *property, const QSize &minVal, const QSize &maxVal) { - setBorderValues(this, d_ptr, + setBorderValues(this, d_ptr.data(), &QtSizePropertyManager::propertyChanged, &QtSizePropertyManager::valueChanged, &QtSizePropertyManager::rangeChanged, @@ -3487,9 +3461,8 @@ void QtSizeFPropertyManagerPrivate::setRange(QtProperty *property, Creates a manager with the given \a parent. */ QtSizeFPropertyManager::QtSizeFPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) + : QtAbstractPropertyManager(parent), d_ptr(new QtSizeFPropertyManagerPrivate) { - d_ptr = new QtSizeFPropertyManagerPrivate; d_ptr->q_ptr = this; d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this); @@ -3505,7 +3478,6 @@ QtSizeFPropertyManager::QtSizeFPropertyManager(QObject *parent) QtSizeFPropertyManager::~QtSizeFPropertyManager() { clear(); - delete d_ptr; } /*! @@ -3593,7 +3565,7 @@ QString QtSizeFPropertyManager::valueText(const QtProperty *property) const */ void QtSizeFPropertyManager::setValue(QtProperty *property, const QSizeF &val) { - setValueInRange(this, d_ptr, + setValueInRange(this, d_ptr.data(), &QtSizeFPropertyManager::propertyChanged, &QtSizeFPropertyManager::valueChanged, property, val, &QtSizeFPropertyManagerPrivate::setValue); @@ -3644,7 +3616,7 @@ void QtSizeFPropertyManager::setDecimals(QtProperty *property, int prec) */ void QtSizeFPropertyManager::setMinimum(QtProperty *property, const QSizeF &minVal) { - setBorderValue(this, d_ptr, + setBorderValue(this, d_ptr.data(), &QtSizeFPropertyManager::propertyChanged, &QtSizeFPropertyManager::valueChanged, &QtSizeFPropertyManager::rangeChanged, @@ -3665,7 +3637,7 @@ void QtSizeFPropertyManager::setMinimum(QtProperty *property, const QSizeF &minV */ void QtSizeFPropertyManager::setMaximum(QtProperty *property, const QSizeF &maxVal) { - setBorderValue(this, d_ptr, + setBorderValue(this, d_ptr.data(), &QtSizeFPropertyManager::propertyChanged, &QtSizeFPropertyManager::valueChanged, &QtSizeFPropertyManager::rangeChanged, @@ -3691,7 +3663,7 @@ void QtSizeFPropertyManager::setMaximum(QtProperty *property, const QSizeF &maxV */ void QtSizeFPropertyManager::setRange(QtProperty *property, const QSizeF &minVal, const QSizeF &maxVal) { - setBorderValues(this, d_ptr, + setBorderValues(this, d_ptr.data(), &QtSizeFPropertyManager::propertyChanged, &QtSizeFPropertyManager::valueChanged, &QtSizeFPropertyManager::rangeChanged, @@ -3903,9 +3875,8 @@ void QtRectPropertyManagerPrivate::setConstraint(QtProperty *property, Creates a manager with the given \a parent. */ QtRectPropertyManager::QtRectPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) + : QtAbstractPropertyManager(parent), d_ptr(new QtRectPropertyManagerPrivate) { - d_ptr = new QtRectPropertyManagerPrivate; d_ptr->q_ptr = this; d_ptr->m_intPropertyManager = new QtIntPropertyManager(this); @@ -3921,7 +3892,6 @@ QtRectPropertyManager::QtRectPropertyManager(QObject *parent) QtRectPropertyManager::~QtRectPropertyManager() { clear(); - delete d_ptr; } /*! @@ -4325,9 +4295,8 @@ void QtRectFPropertyManagerPrivate::setConstraint(QtProperty *property, Creates a manager with the given \a parent. */ QtRectFPropertyManager::QtRectFPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) + : QtAbstractPropertyManager(parent), d_ptr(new QtRectFPropertyManagerPrivate) { - d_ptr = new QtRectFPropertyManagerPrivate; d_ptr->q_ptr = this; d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this); @@ -4343,7 +4312,6 @@ QtRectFPropertyManager::QtRectFPropertyManager(QObject *parent) QtRectFPropertyManager::~QtRectFPropertyManager() { clear(); - delete d_ptr; } /*! @@ -4710,9 +4678,8 @@ public: Creates a manager with the given \a parent. */ QtEnumPropertyManager::QtEnumPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) + : QtAbstractPropertyManager(parent), d_ptr(new QtEnumPropertyManagerPrivate) { - d_ptr = new QtEnumPropertyManagerPrivate; d_ptr->q_ptr = this; } @@ -4722,7 +4689,6 @@ QtEnumPropertyManager::QtEnumPropertyManager(QObject *parent) QtEnumPropertyManager::~QtEnumPropertyManager() { clear(); - delete d_ptr; } /*! @@ -5022,9 +4988,8 @@ void QtFlagPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) Creates a manager with the given \a parent. */ QtFlagPropertyManager::QtFlagPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) + : QtAbstractPropertyManager(parent), d_ptr(new QtFlagPropertyManagerPrivate) { - d_ptr = new QtFlagPropertyManagerPrivate; d_ptr->q_ptr = this; d_ptr->m_boolPropertyManager = new QtBoolPropertyManager(this); @@ -5040,7 +5005,6 @@ QtFlagPropertyManager::QtFlagPropertyManager(QObject *parent) QtFlagPropertyManager::~QtFlagPropertyManager() { clear(); - delete d_ptr; } /*! @@ -5350,9 +5314,8 @@ void QtSizePolicyPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *prope Creates a manager with the given \a parent. */ QtSizePolicyPropertyManager::QtSizePolicyPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) + : QtAbstractPropertyManager(parent), d_ptr(new QtSizePolicyPropertyManagerPrivate) { - d_ptr = new QtSizePolicyPropertyManagerPrivate; d_ptr->q_ptr = this; d_ptr->m_intPropertyManager = new QtIntPropertyManager(this); @@ -5374,7 +5337,6 @@ QtSizePolicyPropertyManager::QtSizePolicyPropertyManager(QObject *parent) QtSizePolicyPropertyManager::~QtSizePolicyPropertyManager() { clear(); - delete d_ptr; } /*! @@ -5762,9 +5724,8 @@ void QtFontPropertyManagerPrivate::slotFontDatabaseDelayedChange() Creates a manager with the given \a parent. */ QtFontPropertyManager::QtFontPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) + : QtAbstractPropertyManager(parent), d_ptr(new QtFontPropertyManagerPrivate) { - d_ptr = new QtFontPropertyManagerPrivate; d_ptr->q_ptr = this; QObject::connect(qApp, SIGNAL(fontDatabaseChanged()), this, SLOT(slotFontDatabaseChanged())); @@ -5792,7 +5753,6 @@ QtFontPropertyManager::QtFontPropertyManager(QObject *parent) QtFontPropertyManager::~QtFontPropertyManager() { clear(); - delete d_ptr; } /*! @@ -6140,9 +6100,8 @@ void QtColorPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) Creates a manager with the given \a parent. */ QtColorPropertyManager::QtColorPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) + : QtAbstractPropertyManager(parent), d_ptr(new QtColorPropertyManagerPrivate) { - d_ptr = new QtColorPropertyManagerPrivate; d_ptr->q_ptr = this; d_ptr->m_intPropertyManager = new QtIntPropertyManager(this); @@ -6159,7 +6118,6 @@ QtColorPropertyManager::QtColorPropertyManager(QObject *parent) QtColorPropertyManager::~QtColorPropertyManager() { clear(); - delete d_ptr; } /*! @@ -6364,9 +6322,8 @@ public: Creates a manager with the given \a parent. */ QtCursorPropertyManager::QtCursorPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) + : QtAbstractPropertyManager(parent), d_ptr(new QtCursorPropertyManagerPrivate) { - d_ptr = new QtCursorPropertyManagerPrivate; d_ptr->q_ptr = this; } @@ -6376,7 +6333,6 @@ QtCursorPropertyManager::QtCursorPropertyManager(QObject *parent) QtCursorPropertyManager::~QtCursorPropertyManager() { clear(); - delete d_ptr; } /*! diff --git a/tools/shared/qtpropertybrowser/qtpropertymanager.h b/tools/shared/qtpropertybrowser/qtpropertymanager.h index 2fb69bf..46ff485 100644 --- a/tools/shared/qtpropertybrowser/qtpropertymanager.h +++ b/tools/shared/qtpropertybrowser/qtpropertymanager.h @@ -94,7 +94,7 @@ protected: virtual void initializeProperty(QtProperty *property); virtual void uninitializeProperty(QtProperty *property); private: - QtIntPropertyManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtIntPropertyManager) Q_DISABLE_COPY(QtIntPropertyManager) }; @@ -120,7 +120,7 @@ protected: virtual void initializeProperty(QtProperty *property); virtual void uninitializeProperty(QtProperty *property); private: - QtBoolPropertyManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtBoolPropertyManager) Q_DISABLE_COPY(QtBoolPropertyManager) }; @@ -157,7 +157,7 @@ protected: virtual void initializeProperty(QtProperty *property); virtual void uninitializeProperty(QtProperty *property); private: - QtDoublePropertyManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtDoublePropertyManager) Q_DISABLE_COPY(QtDoublePropertyManager) }; @@ -185,7 +185,7 @@ protected: virtual void initializeProperty(QtProperty *property); virtual void uninitializeProperty(QtProperty *property); private: - QtStringPropertyManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtStringPropertyManager) Q_DISABLE_COPY(QtStringPropertyManager) }; @@ -216,7 +216,7 @@ protected: virtual void initializeProperty(QtProperty *property); virtual void uninitializeProperty(QtProperty *property); private: - QtDatePropertyManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtDatePropertyManager) Q_DISABLE_COPY(QtDatePropertyManager) }; @@ -241,7 +241,7 @@ protected: virtual void initializeProperty(QtProperty *property); virtual void uninitializeProperty(QtProperty *property); private: - QtTimePropertyManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtTimePropertyManager) Q_DISABLE_COPY(QtTimePropertyManager) }; @@ -266,7 +266,7 @@ protected: virtual void initializeProperty(QtProperty *property); virtual void uninitializeProperty(QtProperty *property); private: - QtDateTimePropertyManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtDateTimePropertyManager) Q_DISABLE_COPY(QtDateTimePropertyManager) }; @@ -291,7 +291,7 @@ protected: virtual void initializeProperty(QtProperty *property); virtual void uninitializeProperty(QtProperty *property); private: - QtKeySequencePropertyManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtKeySequencePropertyManager) Q_DISABLE_COPY(QtKeySequencePropertyManager) }; @@ -316,7 +316,7 @@ protected: virtual void initializeProperty(QtProperty *property); virtual void uninitializeProperty(QtProperty *property); private: - QtCharPropertyManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtCharPropertyManager) Q_DISABLE_COPY(QtCharPropertyManager) }; @@ -344,7 +344,7 @@ protected: virtual void initializeProperty(QtProperty *property); virtual void uninitializeProperty(QtProperty *property); private: - QtLocalePropertyManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtLocalePropertyManager) Q_DISABLE_COPY(QtLocalePropertyManager) Q_PRIVATE_SLOT(d_func(), void slotEnumChanged(QtProperty *, int)) @@ -373,7 +373,7 @@ protected: virtual void initializeProperty(QtProperty *property); virtual void uninitializeProperty(QtProperty *property); private: - QtPointPropertyManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtPointPropertyManager) Q_DISABLE_COPY(QtPointPropertyManager) Q_PRIVATE_SLOT(d_func(), void slotIntChanged(QtProperty *, int)) @@ -405,7 +405,7 @@ protected: virtual void initializeProperty(QtProperty *property); virtual void uninitializeProperty(QtProperty *property); private: - QtPointFPropertyManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtPointFPropertyManager) Q_DISABLE_COPY(QtPointFPropertyManager) Q_PRIVATE_SLOT(d_func(), void slotDoubleChanged(QtProperty *, double)) @@ -440,7 +440,7 @@ protected: virtual void initializeProperty(QtProperty *property); virtual void uninitializeProperty(QtProperty *property); private: - QtSizePropertyManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtSizePropertyManager) Q_DISABLE_COPY(QtSizePropertyManager) Q_PRIVATE_SLOT(d_func(), void slotIntChanged(QtProperty *, int)) @@ -478,7 +478,7 @@ protected: virtual void initializeProperty(QtProperty *property); virtual void uninitializeProperty(QtProperty *property); private: - QtSizeFPropertyManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtSizeFPropertyManager) Q_DISABLE_COPY(QtSizeFPropertyManager) Q_PRIVATE_SLOT(d_func(), void slotDoubleChanged(QtProperty *, double)) @@ -510,7 +510,7 @@ protected: virtual void initializeProperty(QtProperty *property); virtual void uninitializeProperty(QtProperty *property); private: - QtRectPropertyManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtRectPropertyManager) Q_DISABLE_COPY(QtRectPropertyManager) Q_PRIVATE_SLOT(d_func(), void slotIntChanged(QtProperty *, int)) @@ -545,7 +545,7 @@ protected: virtual void initializeProperty(QtProperty *property); virtual void uninitializeProperty(QtProperty *property); private: - QtRectFPropertyManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtRectFPropertyManager) Q_DISABLE_COPY(QtRectFPropertyManager) Q_PRIVATE_SLOT(d_func(), void slotDoubleChanged(QtProperty *, double)) @@ -579,7 +579,7 @@ protected: virtual void initializeProperty(QtProperty *property); virtual void uninitializeProperty(QtProperty *property); private: - QtEnumPropertyManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtEnumPropertyManager) Q_DISABLE_COPY(QtEnumPropertyManager) }; @@ -609,7 +609,7 @@ protected: virtual void initializeProperty(QtProperty *property); virtual void uninitializeProperty(QtProperty *property); private: - QtFlagPropertyManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtFlagPropertyManager) Q_DISABLE_COPY(QtFlagPropertyManager) Q_PRIVATE_SLOT(d_func(), void slotBoolChanged(QtProperty *, bool)) @@ -639,7 +639,7 @@ protected: virtual void initializeProperty(QtProperty *property); virtual void uninitializeProperty(QtProperty *property); private: - QtSizePolicyPropertyManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtSizePolicyPropertyManager) Q_DISABLE_COPY(QtSizePolicyPropertyManager) Q_PRIVATE_SLOT(d_func(), void slotIntChanged(QtProperty *, int)) @@ -672,7 +672,7 @@ protected: virtual void initializeProperty(QtProperty *property); virtual void uninitializeProperty(QtProperty *property); private: - QtFontPropertyManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtFontPropertyManager) Q_DISABLE_COPY(QtFontPropertyManager) Q_PRIVATE_SLOT(d_func(), void slotIntChanged(QtProperty *, int)) @@ -706,7 +706,7 @@ protected: virtual void initializeProperty(QtProperty *property); virtual void uninitializeProperty(QtProperty *property); private: - QtColorPropertyManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtColorPropertyManager) Q_DISABLE_COPY(QtColorPropertyManager) Q_PRIVATE_SLOT(d_func(), void slotIntChanged(QtProperty *, int)) @@ -736,7 +736,7 @@ protected: virtual void initializeProperty(QtProperty *property); virtual void uninitializeProperty(QtProperty *property); private: - QtCursorPropertyManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtCursorPropertyManager) Q_DISABLE_COPY(QtCursorPropertyManager) }; diff --git a/tools/shared/qtpropertybrowser/qttreepropertybrowser.cpp b/tools/shared/qtpropertybrowser/qttreepropertybrowser.cpp index 1ad3f6b..77af2d4 100644 --- a/tools/shared/qtpropertybrowser/qttreepropertybrowser.cpp +++ b/tools/shared/qtpropertybrowser/qttreepropertybrowser.cpp @@ -726,9 +726,8 @@ void QtTreePropertyBrowserPrivate::editItem(QtBrowserItem *browserItem) Creates a property browser with the given \a parent. */ QtTreePropertyBrowser::QtTreePropertyBrowser(QWidget *parent) - : QtAbstractPropertyBrowser(parent) + : QtAbstractPropertyBrowser(parent), d_ptr(new QtTreePropertyBrowserPrivate) { - d_ptr = new QtTreePropertyBrowserPrivate; d_ptr->q_ptr = this; d_ptr->init(this); @@ -747,7 +746,6 @@ QtTreePropertyBrowser::QtTreePropertyBrowser(QWidget *parent) */ QtTreePropertyBrowser::~QtTreePropertyBrowser() { - delete d_ptr; } /*! diff --git a/tools/shared/qtpropertybrowser/qttreepropertybrowser.h b/tools/shared/qtpropertybrowser/qttreepropertybrowser.h index 813e050..8f21588 100644 --- a/tools/shared/qtpropertybrowser/qttreepropertybrowser.h +++ b/tools/shared/qtpropertybrowser/qttreepropertybrowser.h @@ -118,7 +118,7 @@ protected: private: - QtTreePropertyBrowserPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtTreePropertyBrowser) Q_DISABLE_COPY(QtTreePropertyBrowser) diff --git a/tools/shared/qtpropertybrowser/qtvariantproperty.cpp b/tools/shared/qtpropertybrowser/qtvariantproperty.cpp index f712ba6..8931419 100644 --- a/tools/shared/qtpropertybrowser/qtvariantproperty.cpp +++ b/tools/shared/qtpropertybrowser/qtvariantproperty.cpp @@ -188,9 +188,8 @@ public: \sa QtVariantPropertyManager */ QtVariantProperty::QtVariantProperty(QtVariantPropertyManager *manager) - : QtProperty(manager), d_ptr(new QtVariantPropertyPrivate(manager)) + : QtProperty(manager), d_ptr(new QtVariantPropertyPrivate(manager)) { - } /*! @@ -200,7 +199,6 @@ QtVariantProperty::QtVariantProperty(QtVariantPropertyManager *manager) */ QtVariantProperty::~QtVariantProperty() { - delete d_ptr; } /*! @@ -912,9 +910,8 @@ void QtVariantPropertyManagerPrivate::slotFlagNamesChanged(QtProperty *property, Creates a manager with the given \a parent. */ QtVariantPropertyManager::QtVariantPropertyManager(QObject *parent) - : QtAbstractPropertyManager(parent) + : QtAbstractPropertyManager(parent), d_ptr(new QtVariantPropertyManagerPrivate) { - d_ptr = new QtVariantPropertyManagerPrivate; d_ptr->q_ptr = this; d_ptr->m_creatingProperty = false; @@ -1234,7 +1231,6 @@ QtVariantPropertyManager::QtVariantPropertyManager(QObject *parent) QtVariantPropertyManager::~QtVariantPropertyManager() { clear(); - delete d_ptr; } /*! @@ -1929,9 +1925,8 @@ public: Creates a factory with the given \a parent. */ QtVariantEditorFactory::QtVariantEditorFactory(QObject *parent) - : QtAbstractEditorFactory(parent) + : QtAbstractEditorFactory(parent), d_ptr(new QtVariantEditorFactoryPrivate()) { - d_ptr = new QtVariantEditorFactoryPrivate(); d_ptr->q_ptr = this; d_ptr->m_spinBoxFactory = new QtSpinBoxFactory(this); @@ -1993,7 +1988,6 @@ QtVariantEditorFactory::QtVariantEditorFactory(QObject *parent) */ QtVariantEditorFactory::~QtVariantEditorFactory() { - delete d_ptr; } /*! diff --git a/tools/shared/qtpropertybrowser/qtvariantproperty.h b/tools/shared/qtpropertybrowser/qtvariantproperty.h index 9253809..2576f30 100644 --- a/tools/shared/qtpropertybrowser/qtvariantproperty.h +++ b/tools/shared/qtpropertybrowser/qtvariantproperty.h @@ -67,7 +67,7 @@ protected: QtVariantProperty(QtVariantPropertyManager *manager); private: friend class QtVariantPropertyManager; - class QtVariantPropertyPrivate *d_ptr; + QScopedPointer d_ptr; }; class QtVariantPropertyManager : public QtAbstractPropertyManager @@ -111,7 +111,7 @@ protected: virtual void uninitializeProperty(QtProperty *property); virtual QtProperty *createProperty(); private: - class QtVariantPropertyManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, int)) Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, int, int)) Q_PRIVATE_SLOT(d_func(), void slotSingleStepChanged(QtProperty *, int)) @@ -165,7 +165,7 @@ protected: QWidget *parent); void disconnectPropertyManager(QtVariantPropertyManager *manager); private: - class QtVariantEditorFactoryPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtVariantEditorFactory) Q_DISABLE_COPY(QtVariantEditorFactory) }; diff --git a/tools/shared/qttoolbardialog/qttoolbardialog.cpp b/tools/shared/qttoolbardialog/qttoolbardialog.cpp index f15c4bc..5ace584 100644 --- a/tools/shared/qttoolbardialog/qttoolbardialog.cpp +++ b/tools/shared/qttoolbardialog/qttoolbardialog.cpp @@ -119,7 +119,7 @@ signals: void toolBarChanged(QToolBar *toolBar, const QList &actions); private: - QtFullToolBarManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtFullToolBarManager) Q_DISABLE_COPY(QtFullToolBarManager) }; @@ -443,15 +443,13 @@ QToolBar *QtFullToolBarManagerPrivate::toolBarByName(const QString &toolBarName) ////////////////////////////// QtFullToolBarManager::QtFullToolBarManager(QObject *parent) - : QObject(parent) + : QObject(parent), d_ptr(new QtFullToolBarManagerPrivate) { - d_ptr = new QtFullToolBarManagerPrivate; d_ptr->q_ptr = this; } QtFullToolBarManager::~QtFullToolBarManager() { - delete d_ptr; } void QtFullToolBarManager::setMainWindow(QMainWindow *mainWindow) @@ -831,9 +829,8 @@ public: Creates a toolbar manager with the given \a parent. */ QtToolBarManager::QtToolBarManager(QObject *parent) - : QObject(parent) + : QObject(parent), d_ptr(new QtToolBarManagerPrivate) { - d_ptr = new QtToolBarManagerPrivate; d_ptr->q_ptr = this; d_ptr->manager = new QtFullToolBarManager(this); @@ -844,7 +841,6 @@ QtToolBarManager::QtToolBarManager(QObject *parent) */ QtToolBarManager::~QtToolBarManager() { - delete d_ptr; } /*! @@ -1781,9 +1777,8 @@ void QtToolBarListWidget::dropEvent(QDropEvent *event) window \a flags. */ QtToolBarDialog::QtToolBarDialog(QWidget *parent, Qt::WindowFlags flags) - : QDialog(parent, flags) + : QDialog(parent, flags), d_ptr(new QtToolBarDialogPrivate) { - d_ptr = new QtToolBarDialogPrivate; d_ptr->q_ptr = this; d_ptr->ui.setupUi(this); d_ptr->separatorText = tr("< S E P A R A T O R >"); @@ -1834,7 +1829,6 @@ QtToolBarDialog::QtToolBarDialog(QWidget *parent, Qt::WindowFlags flags) QtToolBarDialog::~QtToolBarDialog() { d_ptr->clearOld(); - delete d_ptr; } /*! diff --git a/tools/shared/qttoolbardialog/qttoolbardialog.h b/tools/shared/qttoolbardialog/qttoolbardialog.h index 879b437..a0734d2 100644 --- a/tools/shared/qttoolbardialog/qttoolbardialog.h +++ b/tools/shared/qttoolbardialog/qttoolbardialog.h @@ -88,7 +88,7 @@ public: private: friend class QtToolBarDialog; - QtToolBarManagerPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtToolBarManager) Q_DISABLE_COPY(QtToolBarManager) }; @@ -112,7 +112,7 @@ protected: private: - QtToolBarDialogPrivate *d_ptr; + QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtToolBarDialog) Q_DISABLE_COPY(QtToolBarDialog) -- cgit v0.12 From 5d66ca1218360d910294e817a339b728deb17479 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Wed, 10 Jun 2009 13:54:05 +0200 Subject: Added softkeys example --- examples/widgets/widgets.pro | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/widgets/widgets.pro b/examples/widgets/widgets.pro index 018cc0c..399a3ac 100644 --- a/examples/widgets/widgets.pro +++ b/examples/widgets/widgets.pro @@ -29,7 +29,8 @@ symbian: SUBDIRS = \ lineedits \ shapedclock \ tetrix \ - wiggly + wiggly \ + softkeys contains(styles, motif): SUBDIRS += styles -- cgit v0.12 From c7ddb3e5801118fb23a42272c16c660ba3bdb570 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Wed, 10 Jun 2009 13:58:26 +0200 Subject: Added proper UID --- examples/widgets/softkeys/softkeys.pro | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/examples/widgets/softkeys/softkeys.pro b/examples/widgets/softkeys/softkeys.pro index 4cb8672..9a0feea 100644 --- a/examples/widgets/softkeys/softkeys.pro +++ b/examples/widgets/softkeys/softkeys.pro @@ -1,4 +1,14 @@ HEADERS = softkeys.h SOURCES += \ main.cpp \ - softkeys.cpp \ No newline at end of file + softkeys.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/softkeys +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS softkeys.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/softkeys +INSTALLS += target sources + +include($$QT_SOURCE_TREE/examples/examplebase.pri) + +symbian:TARGET.UID3 = 0xA000CF6B -- cgit v0.12 From 1fddb14c4d0ee82ac66c89061e8a20932f961883 Mon Sep 17 00:00:00 2001 From: Frans Englich Date: Wed, 10 Jun 2009 13:53:19 +0200 Subject: Fix "post linker error" with GCCE. Reviewed-by: Miikka Heikkinen --- tests/auto/qtablewidget/qtablewidget.pro | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/auto/qtablewidget/qtablewidget.pro b/tests/auto/qtablewidget/qtablewidget.pro index bcc82bd..d66d0ac 100644 --- a/tests/auto/qtablewidget/qtablewidget.pro +++ b/tests/auto/qtablewidget/qtablewidget.pro @@ -1,5 +1,16 @@ load(qttest_p4) SOURCES += tst_qtablewidget.cpp +# This prevents the GCCE compile failure: "elf2e32: Error 1063: Fatal Error in +# PostLinker." The paged statement is documented in the S60 docs. +symbian { + MMP_RULES -= PAGED + + custom_paged_rule = "$${LITERAL_HASH}ifndef GCCE"\ + "PAGED" \ + "$${LITERAL_HASH}endif" + MMP_RULES += custom_paged_rule +} + symbian:MMP_RULES += "OPTION GCCE -mlong-calls" -- cgit v0.12