Qt Designer: BC cleanup
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>
Mon, 9 May 2011 10:36:48 +0000 (12:36 +0200)
committerFriedemann Kleint <Friedemann.Kleint@nokia.com>
Mon, 9 May 2011 10:36:48 +0000 (12:36 +0200)
Introduce private classes instead of static hacks
for QDesignerFormWindowManagerInterface and
Integration. Make WidgetBox::Widget a shared data class.

src/designer/src/lib/sdk/abstractformwindowmanager.cpp
src/designer/src/lib/sdk/abstractformwindowmanager.h
src/designer/src/lib/sdk/abstractintegration.cpp
src/designer/src/lib/sdk/abstractintegration.h
src/designer/src/lib/sdk/abstractwidgetbox.h
src/designer/src/lib/shared/qdesigner_widgetbox.cpp

index 75c1d4a..867acbc 100644 (file)
@@ -99,7 +99,9 @@ QT_BEGIN_NAMESPACE
 
 // ------------- QDesignerFormWindowManagerInterfacePrivate
 
-struct QDesignerFormWindowManagerInterfacePrivate {
+class QDesignerFormWindowManagerInterfacePrivate
+{
+public:
     QDesignerFormWindowManagerInterfacePrivate();
     QAction *m_simplifyLayoutAction;
     QAction *m_formLayoutAction;
@@ -111,18 +113,14 @@ QDesignerFormWindowManagerInterfacePrivate::QDesignerFormWindowManagerInterfaceP
 {
 }
 
-typedef QMap<const QDesignerFormWindowManagerInterface *, QDesignerFormWindowManagerInterfacePrivate *> FormWindowManagerPrivateMap;
-
-Q_GLOBAL_STATIC(FormWindowManagerPrivateMap, g_FormWindowManagerPrivateMap)
-
 /*!
     Constructs an interface with the given \a parent for the form window
     manager.
 */
 QDesignerFormWindowManagerInterface::QDesignerFormWindowManagerInterface(QObject *parent)
-    : QObject(parent)
+    : QObject(parent), d(new QDesignerFormWindowManagerInterfacePrivate)
+
 {
-    g_FormWindowManagerPrivateMap()->insert(this, new QDesignerFormWindowManagerInterfacePrivate);
 }
 
 /*!
@@ -130,11 +128,6 @@ QDesignerFormWindowManagerInterface::QDesignerFormWindowManagerInterface(QObject
 */
 QDesignerFormWindowManagerInterface::~QDesignerFormWindowManagerInterface()
 {
-    FormWindowManagerPrivateMap *fwmpm = g_FormWindowManagerPrivateMap();
-    const FormWindowManagerPrivateMap::iterator it = fwmpm->find(this);
-    Q_ASSERT(it !=  fwmpm->end());
-    delete it.value();
-    fwmpm->erase(it);
 }
 
 /*!
@@ -284,8 +277,6 @@ FormWindowManagerPrivateMap *fwmpm = g_FormWindowManagerPrivateMap();    \sa QAc
 
 QAction *QDesignerFormWindowManagerInterface::actionFormLayout() const
 {
-    const QDesignerFormWindowManagerInterfacePrivate *d = g_FormWindowManagerPrivateMap()->value(this);
-    Q_ASSERT(d);
     return d->m_formLayoutAction;
 }
 
@@ -298,8 +289,6 @@ QAction *QDesignerFormWindowManagerInterface::actionFormLayout() const
 
 void QDesignerFormWindowManagerInterface::setActionFormLayout(QAction *action)
 {
-    QDesignerFormWindowManagerInterfacePrivate *d = g_FormWindowManagerPrivateMap()->value(this);
-    Q_ASSERT(d);
     d->m_formLayoutAction = action;
 }
 
@@ -335,8 +324,6 @@ QAction *QDesignerFormWindowManagerInterface::actionAdjustSize() const
 
 QAction *QDesignerFormWindowManagerInterface::actionSimplifyLayout() const
 {
-    const QDesignerFormWindowManagerInterfacePrivate *d = g_FormWindowManagerPrivateMap()->value(this);
-    Q_ASSERT(d);
     return d->m_simplifyLayoutAction;
 }
 
@@ -349,8 +336,6 @@ QAction *QDesignerFormWindowManagerInterface::actionSimplifyLayout() const
 
 void QDesignerFormWindowManagerInterface::setActionSimplifyLayout(QAction *action)
 {
-    QDesignerFormWindowManagerInterfacePrivate *d = g_FormWindowManagerPrivateMap()->value(this);
-    Q_ASSERT(d);
     d->m_simplifyLayoutAction = action;
 }
 
index bdd7c99..60b12a3 100644 (file)
@@ -46,6 +46,7 @@
 #include <QtDesigner/abstractformwindow.h>
 
 #include <QtCore/QObject>
+#include <QtCore/QScopedPointer>
 
 QT_BEGIN_HEADER
 
@@ -58,6 +59,8 @@ class DomUI;
 class QWidget;
 class QDesignerDnDItemInterface;
 
+class QDesignerFormWindowManagerInterfacePrivate;
+
 class QDESIGNER_SDK_EXPORT QDesignerFormWindowManagerInterface: public QObject
 {
     Q_OBJECT
@@ -111,8 +114,7 @@ protected:
     void setActionSimplifyLayout(QAction *action);
 
 private:
-    QDesignerFormWindowManagerInterface(const QDesignerFormWindowManagerInterface &other);
-    QDesignerFormWindowManagerInterface &operator = (const QDesignerFormWindowManagerInterface &other);
+    QScopedPointer<QDesignerFormWindowManagerInterfacePrivate> d;
 };
 
 QT_END_NAMESPACE
index 0c888f6..feb68a9 100644 (file)
 #include "abstractintegration.h"
 #include "abstractformeditor.h"
 
-#include <QtCore/QVariant>
-#include <QtCore/QSharedPointer>
-
 QT_BEGIN_NAMESPACE
 
-// Add 'private' struct as a dynamic property.
-
-static const char privatePropertyC[] = "_q_integrationprivate";
-
-struct QDesignerIntegrationInterfacePrivate {
-    QDesignerIntegrationInterfacePrivate() :
+class QDesignerIntegrationInterfacePrivate
+{
+public:
+    QDesignerIntegrationInterfacePrivate(QDesignerFormEditorInterface *core) :
         headerSuffix(QLatin1String(".h")),
-        headerLowercase(true) {}
+        headerLowercase(true), m_core(core) {}
 
     QString headerSuffix;
     bool headerLowercase;
+    QDesignerFormEditorInterface *m_core;
 };
 
-typedef QSharedPointer<QDesignerIntegrationInterfacePrivate> QDesignerIntegrationInterfacePrivatePtr;
-
-QT_END_NAMESPACE
-Q_DECLARE_METATYPE(QT_PREPEND_NAMESPACE(QDesignerIntegrationInterfacePrivatePtr))
-QT_BEGIN_NAMESPACE
-
-static QDesignerIntegrationInterfacePrivatePtr integrationD(const QObject *o)
+QDesignerIntegrationInterface::QDesignerIntegrationInterface(QDesignerFormEditorInterface *core, QObject *parent)
+    : QObject(parent), d(new QDesignerIntegrationInterfacePrivate(core))
 {
-    const QVariant property = o->property(privatePropertyC);
-    Q_ASSERT(qVariantCanConvert<QDesignerIntegrationInterfacePrivatePtr>(property));
-    return qvariant_cast<QDesignerIntegrationInterfacePrivatePtr>(property);
+    core->setIntegration(this);
 }
 
-QDesignerIntegrationInterface::QDesignerIntegrationInterface(QDesignerFormEditorInterface *core, QObject *parent)
-    : QObject(parent),
-      m_core(core)
+QDesignerIntegrationInterface::~QDesignerIntegrationInterface()
 {
-    core->setIntegration(this);
-    const QDesignerIntegrationInterfacePrivatePtr d(new QDesignerIntegrationInterfacePrivate);
-    setProperty(privatePropertyC, qVariantFromValue<QDesignerIntegrationInterfacePrivatePtr>(d));
 }
 
 QString QDesignerIntegrationInterface::headerSuffix() const
 {
-    return integrationD(this)->headerSuffix;
+    return d->headerSuffix;
 }
 
 void QDesignerIntegrationInterface::setHeaderSuffix(const QString &headerSuffix)
 {
-    integrationD(this)->headerSuffix = headerSuffix;
+    d->headerSuffix = headerSuffix;
 }
 
 bool QDesignerIntegrationInterface::isHeaderLowercase() const
 {
-    return integrationD(this)->headerLowercase;
+    return d->headerLowercase;
 }
 
 void QDesignerIntegrationInterface::setHeaderLowercase(bool headerLowercase)
 {
-    integrationD(this)->headerLowercase = headerLowercase;
+    d->headerLowercase = headerLowercase;
+}
+
+QDesignerFormEditorInterface *QDesignerIntegrationInterface::QDesignerIntegrationInterface::core() const
+{
+    return d->m_core;
 }
 
 QT_END_NAMESPACE
index 9e27f90..f67c4f0 100644 (file)
@@ -45,6 +45,7 @@
 #include <QtDesigner/sdk_global.h>
 
 #include <QtCore/QObject>
+#include <QtCore/QScopedPointer>
 #include <QtCore/QString>
 
 QT_BEGIN_HEADER
@@ -52,6 +53,7 @@ QT_BEGIN_HEADER
 QT_BEGIN_NAMESPACE
 
 class QDesignerFormEditorInterface;
+class QDesignerIntegrationInterfacePrivate;
 
 class QDESIGNER_SDK_EXPORT QDesignerIntegrationInterface: public QObject
 {
@@ -61,8 +63,9 @@ class QDESIGNER_SDK_EXPORT QDesignerIntegrationInterface: public QObject
 
 public:
     QDesignerIntegrationInterface(QDesignerFormEditorInterface *core, QObject *parent = 0);
+    virtual ~QDesignerIntegrationInterface();
 
-    inline QDesignerFormEditorInterface *core() const;
+    QDesignerFormEditorInterface *core() const;
 
     virtual QWidget *containerWindow(QWidget *widget) const = 0;
 
@@ -73,12 +76,9 @@ public:
     void setHeaderLowercase(bool headerLowerCase);
 
 private:
-    QDesignerFormEditorInterface *m_core;
+    QScopedPointer<QDesignerIntegrationInterfacePrivate> d;
 };
 
-inline QDesignerFormEditorInterface *QDesignerIntegrationInterface::core() const
-{ return m_core; }
-
 QT_END_NAMESPACE
 
 QT_END_HEADER
index cf1cb1b..2c65319 100644 (file)
@@ -44,6 +44,7 @@
 
 #include <QtDesigner/sdk_global.h>
 
+#include <QtCore/QSharedDataPointer>
 #include <QtCore/QMetaType>
 #include <QtGui/QWidget>
 #include <QtGui/QIcon>
@@ -55,6 +56,8 @@ QT_BEGIN_NAMESPACE
 class DomUI;
 class QDesignerDnDItemInterface;
 
+class QDesignerWidgetBoxWidgetData;
+
 class QDESIGNER_SDK_EXPORT QDesignerWidgetBoxInterface : public QWidget
 {
     Q_OBJECT
@@ -63,25 +66,26 @@ public:
     public:
         enum Type { Default, Custom };
         Widget(const QString &aname = QString(), const QString &xml = QString(),
-                const QString &icon_name = QString(), Type atype = Default)
-            : m_name(aname), m_xml(xml), m_icon_name(icon_name), m_type(atype) {}
-        QString name() const { return m_name; }
-        void setName(const QString &aname) { m_name = aname; }
-        QString domXml() const { return m_xml; }
-        void setDomXml(const QString &xml) { m_xml = xml; }
-        QString iconName() const { return m_icon_name; }
-        void setIconName(const QString &icon_name) { m_icon_name = icon_name; }
-        Type type() const { return m_type; }
-        void setType(Type atype) { m_type = atype; }
-
-        bool isNull() const { return m_name.isEmpty(); }
+                const QString &icon_name = QString(), Type atype = Default);
+        ~Widget();
+        Widget(const Widget &w);
+        Widget &operator=(const Widget &w);
+
+        QString name() const;
+        void setName(const QString &aname);
+        QString domXml() const;
+        void setDomXml(const QString &xml);
+        QString iconName() const;
+        void setIconName(const QString &icon_name);
+        Type type() const;
+        void setType(Type atype);
+
+        bool isNull() const;
 
     private:
-        QString m_name;
-        QString m_xml;
-        QString m_icon_name;
-        Type m_type;
+        QSharedDataPointer<QDesignerWidgetBoxWidgetData> m_data;
     };
+
     typedef QList<Widget> WidgetList;
 
     class Category {
index 154b2d6..de1c0ac 100644 (file)
 #include <QtCore/QRegExp>
 #include <QtCore/QDebug>
 #include <QtCore/QXmlStreamReader>
+#include <QtCore/QSharedData>
 
 QT_BEGIN_NAMESPACE
 
+class QDesignerWidgetBoxWidgetData : public QSharedData
+{
+public:
+    QDesignerWidgetBoxWidgetData(const QString &aname, const QString &xml,
+                                 const QString &icon_name,
+                                 QDesignerWidgetBoxInterface::Widget::Type atype);
+    QString m_name;
+    QString m_xml;
+    QString m_icon_name;
+    QDesignerWidgetBoxInterface::Widget::Type m_type;
+};
+
+QDesignerWidgetBoxWidgetData::QDesignerWidgetBoxWidgetData(const QString &aname,
+                                                           const QString &xml,
+                                                           const QString &icon_name,
+                                                           QDesignerWidgetBoxInterface::Widget::Type atype) :
+    m_name(aname), m_xml(xml), m_icon_name(icon_name), m_type(atype)
+{
+}
+
+QDesignerWidgetBoxInterface::Widget::Widget(const QString &aname, const QString &xml,
+                                            const QString &icon_name, Type atype) :
+    m_data(new QDesignerWidgetBoxWidgetData(aname, xml, icon_name, atype))
+{
+}
+
+QDesignerWidgetBoxInterface::Widget::~Widget()
+{
+}
+
+QDesignerWidgetBoxInterface::Widget::Widget(const Widget &w) :
+    m_data(w.m_data)
+{
+}
+
+QDesignerWidgetBoxInterface::Widget &QDesignerWidgetBoxInterface::Widget::operator=(const Widget &rhs)
+{
+    if (this != &rhs) {
+        m_data = rhs.m_data;
+    }
+    return *this;
+}
+
+QString QDesignerWidgetBoxInterface::Widget::name() const
+{
+    return m_data->m_name;
+}
+
+void QDesignerWidgetBoxInterface::Widget::setName(const QString &aname)
+{
+    m_data->m_name = aname;
+}
+
+QString QDesignerWidgetBoxInterface::Widget::domXml() const
+{
+    return m_data->m_xml;
+}
+
+void QDesignerWidgetBoxInterface::Widget::setDomXml(const QString &xml)
+{
+    m_data->m_xml = xml;
+}
+
+QString QDesignerWidgetBoxInterface::Widget::iconName() const
+{
+    return m_data->m_icon_name;
+}
+
+void QDesignerWidgetBoxInterface::Widget::setIconName(const QString &icon_name)
+{
+    m_data->m_icon_name = icon_name;
+}
+
+QDesignerWidgetBoxInterface::Widget::Type QDesignerWidgetBoxInterface::Widget::type() const
+{
+    return m_data->m_type;
+}
+
+void QDesignerWidgetBoxInterface::Widget::setType(Type atype)
+{
+    m_data->m_type = atype;
+}
+
+bool QDesignerWidgetBoxInterface::Widget::isNull() const
+{
+    return m_data->m_name.isEmpty();
+}
+
 namespace qdesigner_internal {
 QDesignerWidgetBox::QDesignerWidgetBox(QWidget *parent, Qt::WindowFlags flags)
     : QDesignerWidgetBoxInterface(parent, flags),