diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2013-12-22 03:17:30 -0600 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2013-12-22 03:17:30 -0600 |
commit | d1b6b7be7d5bc7754a143b424295a267bbdafdbd (patch) | |
tree | 20ee69ce981cd5ba62c65bb35b21188cd7b83246 /src | |
parent | f4193c940cdc34284e19cf4cb0687c1a8e81a458 (diff) | |
download | qt3-d1b6b7be7d5bc7754a143b424295a267bbdafdbd.tar.gz qt3-d1b6b7be7d5bc7754a143b424295a267bbdafdbd.zip |
Repair performance regression accidentally introduced with new style API
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel/qobject.cpp | 52 | ||||
-rw-r--r-- | src/kernel/qobject.h | 6 | ||||
-rw-r--r-- | src/kernel/qstyle.cpp | 78 | ||||
-rw-r--r-- | src/kernel/qstyle.h | 14 | ||||
-rw-r--r-- | src/kernel/qthread_unix.cpp | 2 | ||||
-rw-r--r-- | src/styles/qcommonstyle.cpp | 314 | ||||
-rw-r--r-- | src/tools/qvaluelist.h | 15 | ||||
-rw-r--r-- | src/widgets/qdockarea.cpp | 6 | ||||
-rw-r--r-- | src/widgets/qprogressbar.cpp | 10 |
9 files changed, 342 insertions, 155 deletions
diff --git a/src/kernel/qobject.cpp b/src/kernel/qobject.cpp index 403691e..d6be971 100644 --- a/src/kernel/qobject.cpp +++ b/src/kernel/qobject.cpp @@ -49,6 +49,9 @@ #include "qucomextra_p.h" #include "qptrvector.h" +// QStyleControlElementData +#include "qstyle.h" + #ifdef QT_THREAD_SUPPORT #include "qmutex.h" #include <private/qmutexpool_p.h> @@ -58,6 +61,33 @@ #include <ctype.h> #include <stdlib.h> +// Keep in sync with duplicate definition in qcommonstyle.cpp +class QStyleControlElementDataPrivate { + public: + bool isQPushButton; + bool isQToolButton; + bool isQButton; + bool isQTabBar; + bool isQTitleBar; + bool isQToolBox; + bool isQToolBar; + bool isQProgressBar; + bool isQPopupMenu; + bool isQComboBox; + bool isQCheckBox; + bool isQRadioButton; + bool isQHeader; + bool isQScrollBar; + bool isQSlider; + bool isQDialogButtons; + bool isQSpinWidget; + bool isQListView; + bool isQDockWindow; + bool isQTabWidget; + bool isQFrame; + bool isQWidget; +}; + #ifndef QT_NO_USERDATA class QObjectPrivate : public QPtrVector<QObjectUserData> #else @@ -70,14 +100,36 @@ public: ownThread = NULL; disableThreadPostedEvents = false; setAutoDelete( TRUE ); + controlElementData = NULL; + controlElementDataPrivate = NULL; + } + ~QObjectPrivate() { + delete controlElementData; + delete controlElementDataPrivate; } #endif QThread* ownThread; QMutex* senderObjectListMutex; QMutex* childObjectListMutex; bool disableThreadPostedEvents; + QStyleControlElementData* controlElementData; + QStyleControlElementDataPrivate* controlElementDataPrivate; }; +QStyleControlElementData* QObject::controlElementDataObject() { + if (!d->controlElementData) { + d->controlElementData = new QStyleControlElementData(); + } + return d->controlElementData; +} + +QStyleControlElementDataPrivate* QObject::controlElementDataPrivateObject() { + if (!d->controlElementDataPrivate) { + d->controlElementDataPrivate = new QStyleControlElementDataPrivate(); + } + return d->controlElementDataPrivate; +} + #if defined(QT_THREAD_SUPPORT) void QObject::moveToThread_helper(QThread *targetThread) diff --git a/src/kernel/qobject.h b/src/kernel/qobject.h index a63fc4d..3a86cb9 100644 --- a/src/kernel/qobject.h +++ b/src/kernel/qobject.h @@ -68,6 +68,9 @@ struct QUObject; class QThread; #endif +class QStyleControlElementData; +class QStyleControlElementDataPrivate; + class Q_EXPORT QObject: public Qt { Q_OBJECT @@ -140,6 +143,9 @@ public: void dumpObjectTree(); void dumpObjectInfo(); + QStyleControlElementData* controlElementDataObject(); + QStyleControlElementDataPrivate* controlElementDataPrivateObject(); + #ifndef QT_NO_PROPERTIES virtual bool setProperty( const char *name, const QVariant& value ); virtual QVariant property( const char *name ) const; diff --git a/src/kernel/qstyle.cpp b/src/kernel/qstyle.cpp index 75757c9..eb12c1b 100644 --- a/src/kernel/qstyle.cpp +++ b/src/kernel/qstyle.cpp @@ -637,8 +637,8 @@ QStyle::~QStyle() \sa unPolish() */ void QStyle::polish( QWidget *widget ) { - QStyleControlElementData ceData = populateControlElementDataFromWidget(widget, QStyleOption()); - polish(ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, QStyleOption()), widget); + const QStyleControlElementData &ceData = populateControlElementDataFromWidget(widget, QStyleOption()); + polish(ceData, getControlElementFlagsForObject(widget, QStyleOption()), widget); } /*! @@ -652,8 +652,8 @@ void QStyle::polish( QWidget *widget ) { \sa polish() */ void QStyle::unPolish( QWidget *widget ) { - QStyleControlElementData ceData = populateControlElementDataFromWidget(widget, QStyleOption()); - unPolish(ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, QStyleOption()), widget); + const QStyleControlElementData &ceData = populateControlElementDataFromWidget(widget, QStyleOption()); + unPolish(ceData, getControlElementFlagsForObject(widget, QStyleOption()), widget); } /*! @@ -715,8 +715,8 @@ void QStyle::unPolish( const QStyleControlElementData &ceData, ControlElementFla \sa unPolish() */ void QStyle::polish( QApplication *app ) { - QStyleControlElementData ceData = populateControlElementDataFromApplication(app, QStyleOption()); - applicationPolish(ceData, getControlElementFlagsForObject(app, ceData.widgetObjectTypes, QStyleOption()), app); + const QStyleControlElementData &ceData = populateControlElementDataFromApplication(app, QStyleOption()); + applicationPolish(ceData, getControlElementFlagsForObject(app, QStyleOption()), app); } /*! @@ -727,8 +727,8 @@ void QStyle::polish( QApplication *app ) { \sa polish() */ void QStyle::unPolish( QApplication *app ) { - QStyleControlElementData ceData = populateControlElementDataFromApplication(app, QStyleOption()); - applicationUnPolish(ceData, getControlElementFlagsForObject(app, ceData.widgetObjectTypes, QStyleOption()), app); + const QStyleControlElementData &ceData = populateControlElementDataFromApplication(app, QStyleOption()); + applicationUnPolish(ceData, getControlElementFlagsForObject(app, QStyleOption()), app); } /*! @@ -782,8 +782,8 @@ void QStyle::polish( QPalette&) checkable by default (\l{QPopupMenu::setCheckable()}). */ void QStyle::polishPopupMenu( QPopupMenu *pm ) { - QStyleControlElementData ceData = populateControlElementDataFromWidget(pm, QStyleOption()); - unPolish(ceData, getControlElementFlagsForObject(pm, ceData.widgetObjectTypes, QStyleOption()), pm); + const QStyleControlElementData &ceData = populateControlElementDataFromWidget(pm, QStyleOption()); + unPolish(ceData, getControlElementFlagsForObject(pm, QStyleOption()), pm); } /*! @@ -2351,14 +2351,16 @@ bool QStyle::eventFilter(QObject *o, QEvent *e) { if (m_objectEventSourceToHandlerMap.contains(o)) { QStyle* handler = m_objectEventSourceToHandlerMap[o]; - QStyleControlElementData ceData = m_objectEventSourceDataToHandlerMap[o]; + const QStyleControlElementData &ceData = m_objectEventSourceDataToHandlerMap[o]; ControlElementFlags elementFlags = m_objectEventSourceFlagsToHandlerMap[o]; bool ret; QWidget* w = dynamic_cast<QWidget*>(o); if ((w) && (e->type() == QEvent::Paint)) { QPainter p(w); - ceData.activePainter = &p; + QPainter* activePainterOrig = ceData.activePainter; + const_cast<QStyleControlElementData&>(ceData).activePainter = &p; ret = handler->objectEventHandler(ceData, elementFlags, o, e); + const_cast<QStyleControlElementData&>(ceData).activePainter = activePainterOrig; } else { ret = handler->objectEventHandler(ceData, elementFlags, o, e); @@ -2638,8 +2640,8 @@ void QStyle::drawPrimitive( PrimitiveElement pe, } } - QStyleControlElementData ceData = populateControlElementDataFromWidget(widget, opt); - drawPrimitive(pe, p, ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, QStyleOption()), r, cg, flags, opt); + const QStyleControlElementData &ceData = populateControlElementDataFromWidget(widget, opt); + drawPrimitive(pe, p, ceData, getControlElementFlagsForObject(widget, QStyleOption()), r, cg, flags, opt); } void QStyle::drawControl( ControlElement element, @@ -2657,8 +2659,8 @@ void QStyle::drawControl( ControlElement element, } #endif - QStyleControlElementData ceData = populateControlElementDataFromWidget(widget, opt); - drawControl(element, p, ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, opt), r, cg, flags, opt, widget); + const QStyleControlElementData &ceData = populateControlElementDataFromWidget(widget, opt); + drawControl(element, p, ceData, getControlElementFlagsForObject(widget, opt), r, cg, flags, opt, widget); } void QStyle::drawControlMask( ControlElement control, @@ -2667,8 +2669,8 @@ void QStyle::drawControlMask( ControlElement control, const QRect &r, const QStyleOption& opt ) const { - QStyleControlElementData ceData = populateControlElementDataFromWidget(widget, opt); - drawControlMask(control, p, ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, opt), r, opt, widget); + const QStyleControlElementData &ceData = populateControlElementDataFromWidget(widget, opt); + drawControlMask(control, p, ceData, getControlElementFlagsForObject(widget, opt), r, opt, widget); } QRect QStyle::subRect(SubRect r, const QWidget *widget) const @@ -2680,8 +2682,8 @@ QRect QStyle::subRect(SubRect r, const QWidget *widget) const } #endif - QStyleControlElementData ceData = populateControlElementDataFromWidget(widget, QStyleOption()); - return subRect(r, ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, QStyleOption()), widget); + const QStyleControlElementData &ceData = populateControlElementDataFromWidget(widget, QStyleOption()); + return subRect(r, ceData, getControlElementFlagsForObject(widget, QStyleOption()), widget); } void QStyle::drawComplexControl( ComplexControl control, @@ -2701,8 +2703,8 @@ void QStyle::drawComplexControl( ComplexControl control, } #endif - QStyleControlElementData ceData = populateControlElementDataFromWidget(widget, opt); - drawComplexControl(control, p, ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, QStyleOption()), r, cg, flags, controls, active, opt, widget); + const QStyleControlElementData &ceData = populateControlElementDataFromWidget(widget, opt); + drawComplexControl(control, p, ceData, getControlElementFlagsForObject(widget, QStyleOption()), r, cg, flags, controls, active, opt, widget); } void QStyle::drawComplexControlMask( ComplexControl control, @@ -2711,8 +2713,8 @@ void QStyle::drawComplexControlMask( ComplexControl control, const QRect &r, const QStyleOption& opt ) const { - QStyleControlElementData ceData = populateControlElementDataFromWidget(widget, opt); - drawComplexControlMask(control, p, ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, QStyleOption()), r, opt, widget); + const QStyleControlElementData &ceData = populateControlElementDataFromWidget(widget, opt); + drawComplexControlMask(control, p, ceData, getControlElementFlagsForObject(widget, QStyleOption()), r, opt, widget); } QRect QStyle::querySubControlMetrics( ComplexControl control, @@ -2727,8 +2729,8 @@ QRect QStyle::querySubControlMetrics( ComplexControl control, } #endif - QStyleControlElementData ceData = populateControlElementDataFromWidget(widget, opt, false); - return querySubControlMetrics(control, ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, QStyleOption()), sc, opt, widget); + const QStyleControlElementData &ceData = populateControlElementDataFromWidget(widget, opt, false); + return querySubControlMetrics(control, ceData, getControlElementFlagsForObject(widget, QStyleOption()), sc, opt, widget); } QStyle::SubControl QStyle::querySubControl(ComplexControl control, @@ -2736,14 +2738,14 @@ QStyle::SubControl QStyle::querySubControl(ComplexControl control, const QPoint &pos, const QStyleOption& opt ) const { - QStyleControlElementData ceData = populateControlElementDataFromWidget(widget, opt); - return querySubControl(control, ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, opt), pos, opt, widget); + const QStyleControlElementData &ceData = populateControlElementDataFromWidget(widget, opt); + return querySubControl(control, ceData, getControlElementFlagsForObject(widget, opt), pos, opt, widget); } int QStyle::pixelMetric(PixelMetric m, const QWidget *widget) const { - QStyleControlElementData ceData = populateControlElementDataFromWidget(widget, QStyleOption()); - return pixelMetric(m, ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, QStyleOption()), widget); + const QStyleControlElementData &ceData = populateControlElementDataFromWidget(widget, QStyleOption(), false); + return pixelMetric(m, ceData, getControlElementFlagsForObject(widget, QStyleOption()), widget); } QSize QStyle::sizeFromContents(ContentsType contents, @@ -2760,8 +2762,8 @@ QSize QStyle::sizeFromContents(ContentsType contents, } #endif - QStyleControlElementData ceData = populateControlElementDataFromWidget(widget, opt); - return sizeFromContents(contents, ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, QStyleOption()), contentsSize, opt, widget); + const QStyleControlElementData &ceData = populateControlElementDataFromWidget(widget, opt); + return sizeFromContents(contents, ceData, getControlElementFlagsForObject(widget, QStyleOption()), contentsSize, opt, widget); } int QStyle::styleHint(StyleHint sh, const QWidget * w, const QStyleOption &so, QStyleHintReturn *shr) const @@ -2770,14 +2772,14 @@ int QStyle::styleHint(StyleHint sh, const QWidget * w, const QStyleOption &so, Q if (sh == SH_Widget_ShareActivation) { ceDataNotNeeded = true; } - QStyleControlElementData ceData = populateControlElementDataFromWidget(w, so, false, ceDataNotNeeded); - return styleHint(sh, ceData, getControlElementFlagsForObject(w, ceData.widgetObjectTypes, QStyleOption(), false), so, shr, w); + const QStyleControlElementData &ceData = populateControlElementDataFromWidget(w, so, false, ceDataNotNeeded); + return styleHint(sh, ceData, getControlElementFlagsForObject(w, QStyleOption(), false), so, shr, w); } QPixmap QStyle::stylePixmap(StylePixmap sp, const QWidget *w, const QStyleOption &so) const { - QStyleControlElementData ceData = populateControlElementDataFromWidget(w, so); - return stylePixmap(sp, ceData, getControlElementFlagsForObject(w, ceData.widgetObjectTypes, QStyleOption()), so, w); + const QStyleControlElementData &ceData = populateControlElementDataFromWidget(w, so); + return stylePixmap(sp, ceData, getControlElementFlagsForObject(w, QStyleOption()), so, w); } /*! @@ -2830,4 +2832,8 @@ QStyleControlElementData::QStyleControlElementData() { topLevelWidgetFlags = 0; } +QStyleControlElementData::~QStyleControlElementData() { + // +} + #endif // QT_NO_STYLE diff --git a/src/kernel/qstyle.h b/src/kernel/qstyle.h index be23340..3f4ae79 100644 --- a/src/kernel/qstyle.h +++ b/src/kernel/qstyle.h @@ -223,6 +223,7 @@ class QStyleControlElementTabBarData { class Q_EXPORT QStyleControlElementData { public: QStyleControlElementData(); + ~QStyleControlElementData(); public: bool isNull; @@ -285,6 +286,11 @@ class Q_EXPORT QStyleControlElementData { QStyleControlElementGenericWidgetData topLevelWidgetData; Q_UINT32 topLevelWidgetFlags; QPixmap paletteBgPixmap; + + private: + // Disable copy constructor + QStyleControlElementData(const QStyleControlElementData&); + }; class Q_EXPORT QStyleWidgetActionRequestData { @@ -1222,11 +1228,11 @@ private: inline QStyle::ControlElementFlags operator|(const QStyle::ControlElementFlags a, const QStyle::ControlElementFlags b) { return static_cast<QStyle::ControlElementFlags>(static_cast<int>(a) | static_cast<int>(b)); } // inline QStyle::ControlElementFlags operator|=(QStyle::ControlElementFlags &a, const QStyle::ControlElementFlags b) { a = static_cast<QStyle::ControlElementFlags>(static_cast<int>(a) | static_cast<int>(b)); return a; } -Q_EXPORT QStyleControlElementData populateControlElementDataFromWidget(const QWidget* widget, const QStyleOption& opt, bool populateReliantFields=true); -Q_EXPORT QStyleControlElementData populateControlElementDataFromApplication(const QApplication* app, const QStyleOption& opt, bool populateReliantFields=true); -Q_EXPORT QStyle::ControlElementFlags getControlElementFlagsForObject(const QObject* object, QStringList objectTypeList, const QStyleOption& opt, bool populateReliantFields=true); +Q_EXPORT const QStyleControlElementData &populateControlElementDataFromWidget(const QWidget* widget, const QStyleOption& opt, bool populateReliantFields=true); +Q_EXPORT const QStyleControlElementData &populateControlElementDataFromApplication(const QApplication* app, const QStyleOption& opt, bool populateReliantFields=true); +Q_EXPORT QStyle::ControlElementFlags getControlElementFlagsForObject(const QObject* object, const QStyleOption& opt, bool populateReliantFields=true); Q_EXPORT QStringList getObjectTypeListForObject(const QObject* object); -Q_EXPORT QStyleControlElementData populateControlElementDataFromWidget(const QWidget* widget, const QStyleOption& opt, bool populateReliantFields, bool populateMinimumNumberOfFields); +Q_EXPORT const QStyleControlElementData &populateControlElementDataFromWidget(const QWidget* widget, const QStyleOption& opt, bool populateReliantFields, bool populateMinimumNumberOfFields); #endif // QT_NO_STYLE #endif // QSTYLE_H diff --git a/src/kernel/qthread_unix.cpp b/src/kernel/qthread_unix.cpp index bc492af..1358250 100644 --- a/src/kernel/qthread_unix.cpp +++ b/src/kernel/qthread_unix.cpp @@ -410,7 +410,7 @@ void QThread::start(Priority priority) d->args[1] = d; #if defined(QT_USE_GLIBMAINLOOP) // The correct thread_id is set in QThreadInstance::start using the value of d->args[1] - d->thread_id = NULL; + d->thread_id = 0; // Legacy glib versions require this threading system initialization call if (!GLIB_CHECK_VERSION (2, 32, 0)) { diff --git a/src/styles/qcommonstyle.cpp b/src/styles/qcommonstyle.cpp index 1de0b7a..f6319a4 100644 --- a/src/styles/qcommonstyle.cpp +++ b/src/styles/qcommonstyle.cpp @@ -147,6 +147,7 @@ static QString QButton_static_string("QButton"); static QString QTabBar_static_string("QTabBar"); static QString QTitleBar_static_string("QTitleBar"); static QString QToolBox_static_string("QToolBox"); +static QString QToolBar_static_string("QToolBar"); static QString QProgressBar_static_string("QProgressBar"); static QString QPopupMenu_static_string("QPopupMenu"); static QString QComboBox_static_string("QComboBox"); @@ -159,17 +160,48 @@ static QString QDialogButtons_static_string("QDialogButtons"); static QString QSpinWidget_static_string("QSpinWidget"); static QString QListView_static_string("QListView"); static QString QDockWindow_static_string("QDockWindow"); +static QString QTabWidget_static_string("QTabWidget"); static QString QFrame_static_string("QFrame"); +static QString QWidget_static_string("QWidget"); + +static QStyleControlElementData* QStyleControlElementData_null = NULL; #include <qmetaobject.h> +// Keep in sync with duplicate definition in qobject.cpp +class QStyleControlElementDataPrivate { + public: + bool isQPushButton; + bool isQToolButton; + bool isQButton; + bool isQTabBar; + bool isQTitleBar; + bool isQToolBox; + bool isQToolBar; + bool isQProgressBar; + bool isQPopupMenu; + bool isQComboBox; + bool isQCheckBox; + bool isQRadioButton; + bool isQHeader; + bool isQScrollBar; + bool isQSlider; + bool isQDialogButtons; + bool isQSpinWidget; + bool isQListView; + bool isQDockWindow; + bool isQTabWidget; + bool isQFrame; + bool isQWidget; +}; + QStringList getObjectTypeListForObject(const QObject* object) { QStringList objectTypes; if (object) { QMetaObject* objectMetaObject = object->metaObject(); const char* name; - + while (objectMetaObject) { name = objectMetaObject->className(); objectTypes.append(QString(name)); @@ -180,12 +212,54 @@ QStringList getObjectTypeListForObject(const QObject* object) { return objectTypes; } -QStyle::ControlElementFlags getControlElementFlagsForObject(const QObject* object, QStringList objectTypeList, const QStyleOption& opt, bool populateReliantFields) { +void determineObjectTypes(const QObject* object, QStyleControlElementData &ceData, QStyleControlElementDataPrivate* ceDataPrivate) { + ceData.widgetObjectTypes = getObjectTypeListForObject(object); + + // Increase speed on repeated calls by checking object types here and caching them + ceDataPrivate->isQPushButton = ceData.widgetObjectTypes.containsYesNo(QPushButton_static_string); + ceDataPrivate->isQToolButton = ceData.widgetObjectTypes.containsYesNo(QToolButton_static_string); + ceDataPrivate->isQButton = ceData.widgetObjectTypes.containsYesNo(QButton_static_string); + ceDataPrivate->isQTabBar = ceData.widgetObjectTypes.containsYesNo(QTabBar_static_string); + ceDataPrivate->isQTitleBar = ceData.widgetObjectTypes.containsYesNo(QTitleBar_static_string); + ceDataPrivate->isQToolBox = ceData.widgetObjectTypes.containsYesNo(QToolBox_static_string); + ceDataPrivate->isQToolBar = ceData.widgetObjectTypes.containsYesNo(QToolBar_static_string); + ceDataPrivate->isQProgressBar = ceData.widgetObjectTypes.containsYesNo(QProgressBar_static_string); + ceDataPrivate->isQPopupMenu = ceData.widgetObjectTypes.containsYesNo(QPopupMenu_static_string); + ceDataPrivate->isQComboBox = ceData.widgetObjectTypes.containsYesNo(QComboBox_static_string); + ceDataPrivate->isQCheckBox = ceData.widgetObjectTypes.containsYesNo(QCheckBox_static_string); + ceDataPrivate->isQRadioButton = ceData.widgetObjectTypes.containsYesNo(QRadioButton_static_string); + ceDataPrivate->isQHeader = ceData.widgetObjectTypes.containsYesNo(QHeader_static_string); + ceDataPrivate->isQScrollBar = ceData.widgetObjectTypes.containsYesNo(QScrollBar_static_string); + ceDataPrivate->isQSlider = ceData.widgetObjectTypes.containsYesNo(QSlider_static_string); + ceDataPrivate->isQDialogButtons = ceData.widgetObjectTypes.containsYesNo(QDialogButtons_static_string); + ceDataPrivate->isQSpinWidget = ceData.widgetObjectTypes.containsYesNo(QSpinWidget_static_string); + ceDataPrivate->isQListView = ceData.widgetObjectTypes.containsYesNo(QListView_static_string); + ceDataPrivate->isQDockWindow = ceData.widgetObjectTypes.containsYesNo(QDockWindow_static_string); + ceDataPrivate->isQTabWidget = ceData.widgetObjectTypes.containsYesNo(QTabWidget_static_string); + ceDataPrivate->isQFrame = ceData.widgetObjectTypes.containsYesNo(QFrame_static_string); + ceDataPrivate->isQWidget = ceData.widgetObjectTypes.containsYesNo(QWidget_static_string); +} + +void updateObjectTypeListIfNeeded(const QObject* object) { + QStyleControlElementData &ceData = *(const_cast<QObject*>(object)->controlElementDataObject()); + QStyleControlElementDataPrivate* ceDataPrivate = const_cast<QObject*>(object)->controlElementDataPrivateObject(); + + // This is much faster than (ceData.widgetObjectTypes[0] != QString(object->metaObject()->className())) due to QString constructor/destructor overhead + // Casting to const also increases speed by preventing unneeded calls to detach() + if ((ceData.widgetObjectTypes.isEmpty()) || (strcmp(const_cast<const QStringList&>(ceData.widgetObjectTypes)[0].ascii(), object->metaObject()->className()) != 0)) { + determineObjectTypes(object, ceData, ceDataPrivate); + } +} + +QStyle::ControlElementFlags getControlElementFlagsForObject(const QObject* object, const QStyleOption& opt, bool populateReliantFields) { QStyle::ControlElementFlags cef = QStyle::CEF_None; if (object) { - if (objectTypeList.contains(QPushButton_static_string)) { - const QPushButton *button = dynamic_cast<const QPushButton*>(object); + QStyleControlElementDataPrivate* ceDataPrivate = const_cast<QObject*>(object)->controlElementDataPrivateObject(); + updateObjectTypeListIfNeeded(object); + + if (ceDataPrivate->isQPushButton) { + const QPushButton *button = static_cast<const QPushButton*>(object); if (button) { if (button->isDefault()) cef = cef | QStyle::CEF_IsDefault; if (button->autoDefault()) cef = cef | QStyle::CEF_AutoDefault; @@ -194,8 +268,8 @@ QStyle::ControlElementFlags getControlElementFlagsForObject(const QObject* objec if (button->isFlat()) cef = cef | QStyle::CEF_IsFlat; } } - if (objectTypeList.contains(QToolButton_static_string)) { - const QToolButton *button = dynamic_cast<const QToolButton*>(object); + if (ceDataPrivate->isQToolButton) { + const QToolButton *button = static_cast<const QToolButton*>(object); if (button) { if (button->isToggleButton()) cef = cef | QStyle::CEF_BiState; if (button->usesTextLabel()) cef = cef | QStyle::CEF_UsesTextLabel; @@ -203,65 +277,67 @@ QStyle::ControlElementFlags getControlElementFlagsForObject(const QObject* objec if (button->popup()) cef = cef | QStyle::CEF_HasPopupMenu; } } - if (objectTypeList.contains(QButton_static_string)) { - const QButton *button = dynamic_cast<const QButton*>(object); + if (ceDataPrivate->isQButton) { + const QButton *button = static_cast<const QButton*>(object); if (button) { if (button->isDown()) cef = cef | QStyle::CEF_IsDown; if (button->isOn()) cef = cef | QStyle::CEF_IsOn; if (button->isToggleButton()) cef = cef | QStyle::CEF_BiState; } } - if (objectTypeList.contains(QTabBar_static_string)) { - const QTabBar *tb = dynamic_cast<const QTabBar*>(object); + if (ceDataPrivate->isQTabBar) { + const QTabBar *tb = static_cast<const QTabBar*>(object); QTab * t = opt.tab(); if ((t) && (tb)) { if (t->identifier() == tb->currentTab()) cef = cef | QStyle::CEF_IsActive; } } - if (objectTypeList.contains(QTitleBar_static_string)) { - const QTitleBar *tb = dynamic_cast<const QTitleBar*>(object); + if (ceDataPrivate->isQTitleBar) { + const QTitleBar *tb = static_cast<const QTitleBar*>(object); if (tb) { if (tb->isActive()) cef = cef | QStyle::CEF_IsActive; } } - if (objectTypeList.contains(QToolBox_static_string)) { - const QToolBox *tb = dynamic_cast<const QToolBox*>(object); + if (ceDataPrivate->isQToolBox) { + const QToolBox *tb = static_cast<const QToolBox*>(object); if (tb) { if (!tb->currentItem()) cef = cef | QStyle::CEF_IsContainerEmpty; } } - if (objectTypeList.contains(QProgressBar_static_string)) { - const QProgressBar *pb = dynamic_cast<const QProgressBar*>(object); + if (ceDataPrivate->isQProgressBar) { + const QProgressBar *pb = static_cast<const QProgressBar*>(object); if (pb) { if (pb->centerIndicator()) cef = cef | QStyle::CEF_CenterIndicator; if (pb->indicatorFollowsStyle()) cef = cef | QStyle::CEF_IndicatorFollowsStyle; } } - if (objectTypeList.contains(QPopupMenu_static_string)) { - const QPopupMenu *pm = dynamic_cast<const QPopupMenu*>(object); + if (ceDataPrivate->isQPopupMenu) { + const QPopupMenu *pm = static_cast<const QPopupMenu*>(object); if (pm) { if (pm->isCheckable()) cef = cef | QStyle::CEF_IsCheckable; } } - if (objectTypeList.contains(QComboBox_static_string)) { - const QComboBox *cb = dynamic_cast<const QComboBox*>(object); + if (ceDataPrivate->isQComboBox) { + const QComboBox *cb = static_cast<const QComboBox*>(object); if (cb) { if (cb->editable()) cef = cef | QStyle::CEF_IsEditable; } } // Generic flags - const QWidget* widget = dynamic_cast<const QWidget*>(object); - if (widget) { - if (widget->isEnabled()) cef = cef | QStyle::CEF_IsEnabled; - if (widget->parentWidget()) cef = cef | QStyle::CEF_HasParentWidget; - if (widget->focusProxy()) cef = cef | QStyle::CEF_HasFocusProxy; - if (widget->hasFocus()) cef = cef | QStyle::CEF_HasFocus; - if (widget->hasMouse()) cef = cef | QStyle::CEF_HasMouse; - if (populateReliantFields) { - if (widget->isActiveWindow()) cef = cef | QStyle::CEF_IsActiveWindow; - if (widget->isTopLevel()) cef = cef | QStyle::CEF_IsTopLevel; - if (widget->isVisible()) cef = cef | QStyle::CEF_IsVisible; - if (widget->isShown()) cef = cef | QStyle::CEF_IsShown; + if (ceDataPrivate->isQWidget) { + const QWidget* widget = static_cast<const QWidget*>(object); + if (widget) { + if (widget->isEnabled()) cef = cef | QStyle::CEF_IsEnabled; + if (widget->parentWidget()) cef = cef | QStyle::CEF_HasParentWidget; + if (widget->focusProxy()) cef = cef | QStyle::CEF_HasFocusProxy; + if (widget->hasFocus()) cef = cef | QStyle::CEF_HasFocus; + if (widget->hasMouse()) cef = cef | QStyle::CEF_HasMouse; + if (populateReliantFields) { + if (widget->isActiveWindow()) cef = cef | QStyle::CEF_IsActiveWindow; + if (widget->isTopLevel()) cef = cef | QStyle::CEF_IsTopLevel; + if (widget->isVisible()) cef = cef | QStyle::CEF_IsVisible; + if (widget->isShown()) cef = cef | QStyle::CEF_IsShown; + } } } } @@ -272,16 +348,18 @@ QStyle::ControlElementFlags getControlElementFlagsForObject(const QObject* objec return cef; } -QStyleControlElementData populateControlElementDataFromWidget(const QWidget* widget, const QStyleOption& opt, bool populateReliantFields) { +const QStyleControlElementData &populateControlElementDataFromWidget(const QWidget* widget, const QStyleOption& opt, bool populateReliantFields) { return populateControlElementDataFromWidget(widget, opt, populateReliantFields, false); } -QStyleControlElementData populateControlElementDataFromWidget(const QWidget* widget, const QStyleOption& opt, bool populateReliantFields, bool populateMinimumNumberOfFields) { - QStyleControlElementData ceData; - +const QStyleControlElementData &populateControlElementDataFromWidget(const QWidget* widget, const QStyleOption& opt, bool populateReliantFields, bool populateMinimumNumberOfFields) { if (widget) { + QStyleControlElementData &ceData = *(const_cast<QWidget*>(widget)->controlElementDataObject()); + QStyleControlElementDataPrivate* ceDataPrivate = const_cast<QWidget*>(widget)->controlElementDataPrivateObject(); + ceData.isNull = false; - ceData.widgetObjectTypes = getObjectTypeListForObject(widget); + updateObjectTypeListIfNeeded(widget); + ceData.allDataPopulated = populateReliantFields & populateMinimumNumberOfFields; if (!populateMinimumNumberOfFields) { const QPixmap* erasePixmap = widget->backgroundPixmap(); @@ -316,8 +394,8 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid ceData.name = widget->name(); ceData.caption = widget->caption(); if (!populateMinimumNumberOfFields) { - if (ceData.widgetObjectTypes.contains(QPushButton_static_string)) { - const QPushButton *button = dynamic_cast<const QPushButton*>(widget); + if (ceDataPrivate->isQPushButton) { + const QPushButton *button = static_cast<const QPushButton*>(widget); if (button) { QIconSet* iconSet = 0; const QPixmap* fgPixmap = 0; @@ -331,8 +409,8 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid } } } - if (ceData.widgetObjectTypes.contains(QToolButton_static_string)) { - const QToolButton *button = dynamic_cast<const QToolButton*>(widget); + if (ceDataPrivate->isQToolButton) { + const QToolButton *button = static_cast<const QToolButton*>(widget); if (button) { const QPixmap* fgPixmap = 0; ceData.iconSet = button->iconSet(); @@ -345,8 +423,8 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid ceData.popupDelay = button->popupDelay(); } } - if (ceData.widgetObjectTypes.contains(QCheckBox_static_string)) { - const QCheckBox *button = dynamic_cast<const QCheckBox*>(widget); + if (ceDataPrivate->isQCheckBox) { + const QCheckBox *button = static_cast<const QCheckBox*>(widget); if (button) { const QPixmap* fgPixmap = 0; fgPixmap = button->pixmap(); @@ -355,8 +433,8 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid } } } - if (ceData.widgetObjectTypes.contains(QRadioButton_static_string)) { - const QRadioButton *button = dynamic_cast<const QRadioButton*>(widget); + if (ceDataPrivate->isQRadioButton) { + const QRadioButton *button = static_cast<const QRadioButton*>(widget); if (button) { const QPixmap* fgPixmap = 0; fgPixmap = button->pixmap(); @@ -365,8 +443,8 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid } } } - if (ceData.widgetObjectTypes.contains(QButton_static_string)) { - const QButton *button = dynamic_cast<const QButton*>(widget); + if (ceDataPrivate->isQButton) { + const QButton *button = static_cast<const QButton*>(widget); if (button) { ceData.text = button->text(); const QPixmap* paletteBgPixmap = 0; @@ -376,8 +454,8 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid } } } - if (ceData.widgetObjectTypes.contains(QTabBar_static_string)) { - const QTabBar *tb = dynamic_cast<const QTabBar*>(widget); + if (ceDataPrivate->isQTabBar) { + const QTabBar *tb = static_cast<const QTabBar*>(widget); if (tb) { ceData.tabBarData.tabCount = tb->count(); ceData.tabBarData.currentTabIndex = tb->currentTab(); @@ -390,33 +468,38 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid ceData.tabBarData.identIndexMap[currentTab->identifier()] = tb->indexOf(currentTab->identifier()); } } - const QTabWidget *tw = dynamic_cast<const QTabWidget*>(tb->parent()); - if (tw) { + updateObjectTypeListIfNeeded(tb->parent()); + if ((const_cast<QObject*>(tb->parent())->controlElementDataPrivateObject())->isQTabWidget) { + const QTabWidget *tw = static_cast<const QTabWidget*>(tb->parent()); QWidget *cw; cw = tw->cornerWidget(Qt::TopLeft); - if(cw) { - ceData.tabBarData.cornerWidgets[QStyleControlElementTabBarData::CWL_TopLeft].widgetObjectTypes = getObjectTypeListForObject(cw); + if (cw) { + updateObjectTypeListIfNeeded(cw); + ceData.tabBarData.cornerWidgets[QStyleControlElementTabBarData::CWL_TopLeft].widgetObjectTypes = (const_cast<QWidget*>(cw)->controlElementDataObject())->widgetObjectTypes; ceData.tabBarData.cornerWidgets[QStyleControlElementTabBarData::CWL_TopLeft].geometry = cw->geometry(); ceData.tabBarData.cornerWidgets[QStyleControlElementTabBarData::CWL_TopLeft].rect = cw->rect(); ceData.tabBarData.cornerWidgets[QStyleControlElementTabBarData::CWL_TopLeft].pos = cw->pos(); } cw = tw->cornerWidget(Qt::TopRight); - if(cw) { - ceData.tabBarData.cornerWidgets[QStyleControlElementTabBarData::CWL_TopRight].widgetObjectTypes = getObjectTypeListForObject(cw); + if (cw) { + updateObjectTypeListIfNeeded(cw); + ceData.tabBarData.cornerWidgets[QStyleControlElementTabBarData::CWL_TopRight].widgetObjectTypes = (const_cast<QWidget*>(cw)->controlElementDataObject())->widgetObjectTypes; ceData.tabBarData.cornerWidgets[QStyleControlElementTabBarData::CWL_TopRight].geometry = cw->geometry(); ceData.tabBarData.cornerWidgets[QStyleControlElementTabBarData::CWL_TopRight].rect = cw->rect(); ceData.tabBarData.cornerWidgets[QStyleControlElementTabBarData::CWL_TopRight].pos = cw->pos(); } cw = tw->cornerWidget(Qt::BottomLeft); - if(cw) { - ceData.tabBarData.cornerWidgets[QStyleControlElementTabBarData::CWL_BottomLeft].widgetObjectTypes = getObjectTypeListForObject(cw); + if (cw) { + updateObjectTypeListIfNeeded(cw); + ceData.tabBarData.cornerWidgets[QStyleControlElementTabBarData::CWL_BottomLeft].widgetObjectTypes = (const_cast<QWidget*>(cw)->controlElementDataObject())->widgetObjectTypes; ceData.tabBarData.cornerWidgets[QStyleControlElementTabBarData::CWL_BottomLeft].geometry = cw->geometry(); ceData.tabBarData.cornerWidgets[QStyleControlElementTabBarData::CWL_BottomLeft].rect = cw->rect(); ceData.tabBarData.cornerWidgets[QStyleControlElementTabBarData::CWL_BottomLeft].pos = cw->pos(); } cw = tw->cornerWidget(Qt::BottomRight); - if(cw) { - ceData.tabBarData.cornerWidgets[QStyleControlElementTabBarData::CWL_BottomRight].widgetObjectTypes = getObjectTypeListForObject(cw); + if (cw) { + updateObjectTypeListIfNeeded(cw); + ceData.tabBarData.cornerWidgets[QStyleControlElementTabBarData::CWL_BottomRight].widgetObjectTypes = (const_cast<QWidget*>(cw)->controlElementDataObject())->widgetObjectTypes; ceData.tabBarData.cornerWidgets[QStyleControlElementTabBarData::CWL_BottomRight].geometry = cw->geometry(); ceData.tabBarData.cornerWidgets[QStyleControlElementTabBarData::CWL_BottomRight].rect = cw->rect(); ceData.tabBarData.cornerWidgets[QStyleControlElementTabBarData::CWL_BottomRight].pos = cw->pos(); @@ -424,8 +507,8 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid } } } - if (ceData.widgetObjectTypes.contains(QToolBox_static_string)) { - const QToolBox *tb = dynamic_cast<const QToolBox*>(widget); + if (ceDataPrivate->isQToolBox) { + const QToolBox *tb = static_cast<const QToolBox*>(widget); if (tb) { const QWidget* currentItem = tb->currentItem(); if (currentItem) { @@ -433,8 +516,8 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid } } } - if (ceData.widgetObjectTypes.contains(QProgressBar_static_string)) { - const QProgressBar *pb = dynamic_cast<const QProgressBar*>(widget); + if (ceDataPrivate->isQProgressBar) { + const QProgressBar *pb = static_cast<const QProgressBar*>(widget); if (pb) { ceData.currentStep = pb->progress(); ceData.totalSteps = pb->totalSteps(); @@ -443,8 +526,8 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid ceData.orientation = pb->orientation(); } } - if (ceData.widgetObjectTypes.contains(QHeader_static_string)) { - const QHeader *header = dynamic_cast<const QHeader*>(widget); + if (ceDataPrivate->isQHeader) { + const QHeader *header = static_cast<const QHeader*>(widget); if (header) { int section = opt.headerSection(); QIconSet* iconSet = 0; @@ -456,8 +539,8 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid } } // Complex Controls - if (ceData.widgetObjectTypes.contains(QScrollBar_static_string)) { - const QScrollBar *sb = dynamic_cast<const QScrollBar*>(widget); + if (ceDataPrivate->isQScrollBar) { + const QScrollBar *sb = static_cast<const QScrollBar*>(widget); if (sb) { ceData.orientation = sb->orientation(); ceData.minSteps = sb->minValue(); @@ -471,8 +554,8 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid } } } - if (ceData.widgetObjectTypes.contains(QSlider_static_string)) { - const QSlider *sl = dynamic_cast<const QSlider*>(widget); + if (ceDataPrivate->isQSlider) { + const QSlider *sl = static_cast<const QSlider*>(widget); if (sl) { ceData.orientation = sl->orientation(); ceData.minSteps = sl->minValue(); @@ -488,8 +571,8 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid } } } - if (ceData.widgetObjectTypes.contains(QDialogButtons_static_string)) { - const QDialogButtons *dlgbtns = dynamic_cast<const QDialogButtons*>(widget); + if (ceDataPrivate->isQDialogButtons) { + const QDialogButtons *dlgbtns = static_cast<const QDialogButtons*>(widget); if (dlgbtns) { ceData.orientation = dlgbtns->orientation(); ceData.dlgVisibleButtons = dlgbtns->visibleButtons(); @@ -499,11 +582,11 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid ceData.dlgVisibleSizeHints[btns[i]] = dlgbtns->sizeHint(btns[i]); } } - + } } - if (ceData.widgetObjectTypes.contains(QTitleBar_static_string)) { - const QTitleBar *tb = dynamic_cast<const QTitleBar*>(widget); + if (ceDataPrivate->isQTitleBar) { + const QTitleBar *tb = static_cast<const QTitleBar*>(widget); if (tb) { ceData.titleBarData.hasWindow = !!(tb->window()); if (populateReliantFields) { @@ -515,8 +598,8 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid ceData.titleBarData.visibleText = tb->visibleText(); } } - if (ceData.widgetObjectTypes.contains(QSpinWidget_static_string)) { - const QSpinWidget *sw = dynamic_cast<const QSpinWidget*>(widget); + if (ceDataPrivate->isQSpinWidget) { + const QSpinWidget *sw = static_cast<const QSpinWidget*>(widget); if (sw) { ceData.spinWidgetData.buttonSymbols = sw->buttonSymbols(); ceData.spinWidgetData.upRect = sw->upRect(); @@ -525,14 +608,15 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid ceData.spinWidgetData.downEnabled = sw->isDownEnabled(); } } - if (ceData.widgetObjectTypes.contains(QListView_static_string)) { - const QListView *lv = dynamic_cast<const QListView*>(widget); + if (ceDataPrivate->isQListView) { + const QListView *lv = static_cast<const QListView*>(widget); if (lv) { ceData.listViewData.rootDecorated = lv->rootIsDecorated(); ceData.listViewData.itemMargin = lv->itemMargin(); QWidget* viewport = lv->viewport(); if (viewport) { - ceData.viewportData.widgetObjectTypes = getObjectTypeListForObject(viewport); + updateObjectTypeListIfNeeded(viewport); + ceData.viewportData.widgetObjectTypes = (const_cast<QWidget*>(viewport)->controlElementDataObject())->widgetObjectTypes; ceData.viewportData.allDataPopulated = populateReliantFields & populateMinimumNumberOfFields; const QPixmap* erasePixmap = viewport->backgroundPixmap(); if (erasePixmap) { @@ -567,29 +651,31 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid } } } - if (ceData.widgetObjectTypes.contains(QComboBox_static_string)) { - const QComboBox *cb = dynamic_cast<const QComboBox*>(widget); + if (ceDataPrivate->isQComboBox) { + const QComboBox *cb = static_cast<const QComboBox*>(widget); if (cb) { const QLineEdit* lineEdit = cb->lineEdit(); if (lineEdit) { - ceData.comboBoxLineEditFlags = getControlElementFlagsForObject(lineEdit, ceData.widgetObjectTypes, QStyleOption::Default); + ceData.comboBoxLineEditFlags = getControlElementFlagsForObject(lineEdit, QStyleOption::Default); } const QListBox* listBox = cb->listBox(); if (listBox) { - ceData.comboBoxListBoxFlags = getControlElementFlagsForObject(listBox, ceData.widgetObjectTypes, QStyleOption::Default); + ceData.comboBoxListBoxFlags = getControlElementFlagsForObject(listBox, QStyleOption::Default); } } } - if (ceData.widgetObjectTypes.contains(QFrame_static_string)) { - const QFrame *frame = dynamic_cast<const QFrame*>(widget); + if (ceDataPrivate->isQFrame) { + const QFrame *frame = static_cast<const QFrame*>(widget); if (frame) { ceData.frameStyle = frame->frameStyle(); } } - + const QWidget* parentWidget = widget->parentWidget(); if (parentWidget) { - ceData.parentWidgetData.widgetObjectTypes = getObjectTypeListForObject(parentWidget); + updateObjectTypeListIfNeeded(parentWidget); + ceData.parentWidgetData.widgetObjectTypes = (const_cast<QWidget*>(parentWidget)->controlElementDataObject())->widgetObjectTypes; + QStyleControlElementDataPrivate* parentWidgetCEDataPrivate = const_cast<QWidget*>(parentWidget)->controlElementDataPrivateObject(); ceData.parentWidgetData.allDataPopulated = populateReliantFields & populateMinimumNumberOfFields; const QPixmap* erasePixmap = parentWidget->backgroundPixmap(); if (erasePixmap) { @@ -621,9 +707,9 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid ceData.parentWidgetData.font = parentWidget->font(); ceData.parentWidgetData.name = parentWidget->name(); ceData.parentWidgetData.caption = parentWidget->caption(); - - const QDockWindow * dw = dynamic_cast<const QDockWindow*>(parentWidget); - if (dw) { + + if (parentWidgetCEDataPrivate->isQDockWindow) { + const QDockWindow * dw = static_cast<const QDockWindow*>(parentWidget); if (dw->area()) { ceData.dwData.hasDockArea = true; ceData.dwData.areaOrientation = dw->area()->orientation(); @@ -633,15 +719,17 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid } ceData.dwData.closeEnabled = dw->isCloseEnabled(); } - const QToolBar * toolbar = dynamic_cast<const QToolBar*>(parentWidget); - if (toolbar) { + if (parentWidgetCEDataPrivate->isQToolBar) { + const QToolBar * toolbar = static_cast<const QToolBar*>(parentWidget); ceData.toolBarData.orientation = toolbar->orientation(); } - ceData.parentWidgetFlags = getControlElementFlagsForObject(parentWidget, ceData.parentWidgetData.widgetObjectTypes, QStyleOption::Default, populateReliantFields); + ceData.parentWidgetFlags = getControlElementFlagsForObject(parentWidget, QStyleOption::Default, populateReliantFields); } const QWidget* topLevelWidget = widget->topLevelWidget(); if (topLevelWidget) { - ceData.topLevelWidgetData.widgetObjectTypes = getObjectTypeListForObject(topLevelWidget); + updateObjectTypeListIfNeeded(topLevelWidget); + ceData.topLevelWidgetData.widgetObjectTypes = (const_cast<QWidget*>(topLevelWidget)->controlElementDataObject())->widgetObjectTypes; + QStyleControlElementDataPrivate* topLevelWidgetCEDataPrivate = const_cast<QWidget*>(topLevelWidget)->controlElementDataPrivateObject(); ceData.topLevelWidgetData.allDataPopulated = populateReliantFields & populateMinimumNumberOfFields; const QPixmap* erasePixmap = topLevelWidget->backgroundPixmap(); if (erasePixmap) { @@ -673,9 +761,9 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid ceData.topLevelWidgetData.font = topLevelWidget->font(); ceData.topLevelWidgetData.name = topLevelWidget->name(); ceData.topLevelWidgetData.caption = topLevelWidget->caption(); - - const QDockWindow * dw = dynamic_cast<const QDockWindow*>(topLevelWidget); - if (dw) { + + if (topLevelWidgetCEDataPrivate->isQDockWindow) { + const QDockWindow * dw = static_cast<const QDockWindow*>(topLevelWidget); if (dw->area()) { ceData.dwData.hasDockArea = true; ceData.dwData.areaOrientation = dw->area()->orientation(); @@ -685,13 +773,13 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid } ceData.dwData.closeEnabled = dw->isCloseEnabled(); } - const QToolBar * toolbar = dynamic_cast<const QToolBar*>(topLevelWidget); - if (toolbar) { + if (topLevelWidgetCEDataPrivate->isQToolBar) { + const QToolBar * toolbar = static_cast<const QToolBar*>(topLevelWidget); ceData.toolBarData.orientation = toolbar->orientation(); } - ceData.topLevelWidgetFlags = getControlElementFlagsForObject(topLevelWidget, ceData.topLevelWidgetData.widgetObjectTypes, QStyleOption::Default, populateReliantFields); + ceData.topLevelWidgetFlags = getControlElementFlagsForObject(topLevelWidget, QStyleOption::Default, populateReliantFields); } - + QCheckListItem *item = opt.checkListItem(); if (item) { ceData.checkListItemData.dataValid = true; @@ -703,16 +791,24 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid ceData.checkListItemData.dataValid = false; } } - } - return ceData; + return ceData; + } + else { + if (!QStyleControlElementData_null) { + QStyleControlElementData_null = new QStyleControlElementData(); + } + QStyleControlElementData &ceData = *QStyleControlElementData_null; + return ceData; + } } -QStyleControlElementData populateControlElementDataFromApplication(const QApplication* app, const QStyleOption&, bool) { - QStyleControlElementData ceData; +const QStyleControlElementData &populateControlElementDataFromApplication(const QApplication* app, const QStyleOption&, bool) { + QStyleControlElementData &ceData = *(const_cast<QApplication*>(app)->controlElementDataObject()); if (app) { - ceData.widgetObjectTypes = getObjectTypeListForObject(app); + updateObjectTypeListIfNeeded(app); + ceData.widgetObjectTypes = (const_cast<QApplication*>(app)->controlElementDataObject())->widgetObjectTypes; ceData.palette = app->palette(); ceData.font = app->font(); } @@ -1179,7 +1275,7 @@ void QCommonStyle::drawPrimitive( PrimitiveElement pe, activePainter = 0; } -void qt_style_erase_region(QPainter* p, const QRegion& region, QStyleControlElementData ceData) { +void qt_style_erase_region(QPainter* p, const QRegion& region, const QStyleControlElementData &ceData) { QRegion reg = region; QPoint offset = ceData.bgOffset; @@ -2797,7 +2893,7 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleControlElementData &ceD if ( ceData.wflags & WStyle_Tool ) { ret = QMAX( QFontMetrics(ceData.font).lineSpacing(), 16 ); #ifndef QT_NO_MAINWINDOW - } else if ( ceData.widgetObjectTypes.contains(QDockWindow_static_string) ) { + } else if ( ceData.widgetObjectTypes.containsYesNo(QDockWindow_static_string) ) { ret = QMAX( QFontMetrics(ceData.font).lineSpacing(), 13 ); #endif } else { @@ -2945,7 +3041,7 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleControlElementData &ceD #ifndef QT_NO_TABBAR case PM_TabBarTabVSpace: { - if ( ceData.widgetObjectTypes.contains(QTabBar_static_string) && ( ceData.tabBarData.shape == QTabBar::RoundedAbove || + if ( ceData.widgetObjectTypes.containsYesNo(QTabBar_static_string) && ( ceData.tabBarData.shape == QTabBar::RoundedAbove || ceData.tabBarData.shape == QTabBar::RoundedBelow ) ) ret = 10; else diff --git a/src/tools/qvaluelist.h b/src/tools/qvaluelist.h index 95dc7ff..b082097 100644 --- a/src/tools/qvaluelist.h +++ b/src/tools/qvaluelist.h @@ -250,6 +250,7 @@ public: NodePtr find( NodePtr start, const T& x ) const; int findIndex( NodePtr start, const T& x ) const; uint contains( const T& x ) const; + bool containsYesNo( const T& x ) const; uint remove( const T& x ); NodePtr at( size_type i ) const; void clear(); @@ -355,6 +356,19 @@ Q_INLINE_TEMPLATES uint QValueListPrivate<T>::contains( const T& x ) const } template <class T> +Q_INLINE_TEMPLATES bool QValueListPrivate<T>::containsYesNo( const T& x ) const +{ + Iterator first = Iterator( node->next ); + Iterator last = Iterator( node ); + while( first != last) { + if ( *first == x ) + return true; + ++first; + } + return false; +} + +template <class T> Q_INLINE_TEMPLATES uint QValueListPrivate<T>::remove( const T& _x ) { const T x = _x; @@ -547,6 +561,7 @@ public: const_iterator find ( const_iterator it, const T& x ) const { return const_iterator( sh->find( it.node, x ) ); } int findIndex( const T& x ) const { return sh->findIndex( sh->node->next, x) ; } size_type contains( const T& x ) const { return sh->contains( x ); } + bool containsYesNo( const T& x ) const { return sh->containsYesNo( x ); } size_type count() const { return sh->nodes; } diff --git a/src/widgets/qdockarea.cpp b/src/widgets/qdockarea.cpp index 663c3d9..68d9e1c 100644 --- a/src/widgets/qdockarea.cpp +++ b/src/widgets/qdockarea.cpp @@ -204,13 +204,15 @@ static int dock_strut( QDockWindow *w, Qt::Orientation o ) { if ( o != Qt::Horizontal ) { int wid; - if ( ( wid = w->fixedExtent().width() ) != -1 ) + if ( ( wid = w->fixedExtent().width() ) != -1 ) { return QMAX( wid, QMAX( w->minimumSize().width(), w->minimumSizeHint().width() ) ); + } return QMAX( w->sizeHint().width(), QMAX( w->minimumSize().width(), w->minimumSizeHint().width() ) ); } else { int hei; - if ( ( hei = w->fixedExtent().height() ) != -1 ) + if ( ( hei = w->fixedExtent().height() ) != -1 ) { return QMAX( hei, QMAX( w->minimumSizeHint().height(), w->minimumSize().height() ) ); + } return QMAX( w->sizeHint().height(), QMAX( w->minimumSizeHint().height(), w->minimumSize().height() ) ); } } diff --git a/src/widgets/qprogressbar.cpp b/src/widgets/qprogressbar.cpp index d5011da..99dedb0 100644 --- a/src/widgets/qprogressbar.cpp +++ b/src/widgets/qprogressbar.cpp @@ -429,8 +429,10 @@ void QProgressBar::drawContents( QPainter *p ) QWMatrix oldMatrix = buffer.painter()->worldMatrix(); - QStyleControlElementData ceData = populateControlElementDataFromWidget(this, QStyleOption()); - QStyle::ControlElementFlags elementFlags = getControlElementFlagsForObject(this, ceData.widgetObjectTypes, QStyleOption()); + const QStyleControlElementData &ceData = populateControlElementDataFromWidget(this, QStyleOption()); + QStyle::ControlElementFlags elementFlags = getControlElementFlagsForObject(this, QStyleOption()); + + QRect ceDataRectOrig = ceData.rect; // Draw contents if (m_orientation == Qt::Vertical) { @@ -447,7 +449,7 @@ void QProgressBar::drawContents( QPainter *p ) buffer.painter()->setWorldMatrix(m, TRUE); - ceData.rect = QRect(ceData.rect.y(), ceData.rect.x(), ceData.rect.height(), ceData.rect.width()); + const_cast<QStyleControlElementData&>(ceData).rect = QRect(ceData.rect.y(), ceData.rect.x(), ceData.rect.height(), ceData.rect.width()); } style().drawControl(QStyle::CE_ProgressBarContents, buffer.painter(), ceData, elementFlags, @@ -461,6 +463,8 @@ void QProgressBar::drawContents( QPainter *p ) QStyle::visualRect(style().subRect(QStyle::SR_ProgressBarLabel, this), this ), colorGroup(), flags); } + + const_cast<QStyleControlElementData&>(ceData).rect = ceDataRectOrig; } #endif |