From 00e954ca817f89958a8a8777d93d3843252dc88c Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 23 Aug 2010 14:55:39 +0200 Subject: Qt Designer/Integrations: Add properties for use by C++-IDEs. ...such as the header suffix (like ".h") or whether headers should be lowercase only. Allows for using different suffixes and conventions like 'CamelCase.hxx", etc. Reviewed-by: Jarek Kobus API-reviewed-by: Kai Koehne Task-number: QTCREATORBUG-163 --- tools/designer/src/lib/sdk/abstractintegration.cpp | 49 ++++++++++++++++++++++ tools/designer/src/lib/sdk/abstractintegration.h | 10 +++++ .../src/lib/shared/qdesigner_promotiondialog.cpp | 12 +++++- .../src/lib/shared/qdesigner_promotiondialog_p.h | 11 ++++- 4 files changed, 79 insertions(+), 3 deletions(-) diff --git a/tools/designer/src/lib/sdk/abstractintegration.cpp b/tools/designer/src/lib/sdk/abstractintegration.cpp index c5a60db..e8b0005 100644 --- a/tools/designer/src/lib/sdk/abstractintegration.cpp +++ b/tools/designer/src/lib/sdk/abstractintegration.cpp @@ -42,13 +42,62 @@ #include "abstractintegration.h" #include "abstractformeditor.h" +#include +#include + QT_BEGIN_NAMESPACE +// Add 'private' struct as a dynamic property. + +static const char privatePropertyC[] = "_q_integrationprivate"; + +struct QDesignerIntegrationInterfacePrivate { + QDesignerIntegrationInterfacePrivate() : + headerSuffix(QLatin1String(".h")), + headerLowercase(true) {} + + QString headerSuffix; + bool headerLowercase; +}; + +typedef QSharedPointer QDesignerIntegrationInterfacePrivatePtr; + +Q_DECLARE_METATYPE(QDesignerIntegrationInterfacePrivatePtr) + +static QDesignerIntegrationInterfacePrivatePtr integrationD(const QObject *o) +{ + const QVariant property = o->property(privatePropertyC); + Q_ASSERT(qVariantCanConvert(property)); + return qvariant_cast(property); +} + QDesignerIntegrationInterface::QDesignerIntegrationInterface(QDesignerFormEditorInterface *core, QObject *parent) : QObject(parent), m_core(core) { core->setIntegration(this); + const QDesignerIntegrationInterfacePrivatePtr d(new QDesignerIntegrationInterfacePrivate); + setProperty(privatePropertyC, qVariantFromValue(d)); +} + +QString QDesignerIntegrationInterface::headerSuffix() const +{ + return integrationD(this)->headerSuffix; +} + +void QDesignerIntegrationInterface::setHeaderSuffix(const QString &headerSuffix) +{ + integrationD(this)->headerSuffix = headerSuffix; +} + +bool QDesignerIntegrationInterface::isHeaderLowercase() const +{ + return integrationD(this)->headerLowercase; +} + +void QDesignerIntegrationInterface::setHeaderLowercase(bool headerLowercase) +{ + integrationD(this)->headerLowercase = headerLowercase; } QT_END_NAMESPACE diff --git a/tools/designer/src/lib/sdk/abstractintegration.h b/tools/designer/src/lib/sdk/abstractintegration.h index 9b2b856..acac711 100644 --- a/tools/designer/src/lib/sdk/abstractintegration.h +++ b/tools/designer/src/lib/sdk/abstractintegration.h @@ -45,6 +45,7 @@ #include #include +#include QT_BEGIN_HEADER @@ -55,6 +56,9 @@ class QDesignerFormEditorInterface; class QDESIGNER_SDK_EXPORT QDesignerIntegrationInterface: public QObject { Q_OBJECT + Q_PROPERTY(QString headerSuffix READ headerSuffix WRITE setHeaderSuffix) + Q_PROPERTY(bool headerLowercase READ isHeaderLowercase WRITE setHeaderLowercase) + public: QDesignerIntegrationInterface(QDesignerFormEditorInterface *core, QObject *parent = 0); @@ -62,6 +66,12 @@ public: virtual QWidget *containerWindow(QWidget *widget) const = 0; + QString headerSuffix() const; + void setHeaderSuffix(const QString &headerSuffix); + + bool isHeaderLowercase() const; + void setHeaderLowercase(bool headerLowerCase); + private: QDesignerFormEditorInterface *m_core; }; diff --git a/tools/designer/src/lib/shared/qdesigner_promotiondialog.cpp b/tools/designer/src/lib/shared/qdesigner_promotiondialog.cpp index eca6615..1fbfccb 100644 --- a/tools/designer/src/lib/shared/qdesigner_promotiondialog.cpp +++ b/tools/designer/src/lib/shared/qdesigner_promotiondialog.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include #include @@ -152,8 +153,13 @@ namespace qdesigner_internal { void NewPromotedClassPanel::slotNameChanged(const QString &className) { // Suggest a name if (!className.isEmpty()) { - QString suggestedHeader = className.toLower().replace(QLatin1String("::"), QString(QLatin1Char('_'))); - suggestedHeader += QLatin1String(".h"); + const QChar dot(QLatin1Char('.')); + QString suggestedHeader = m_promotedHeaderLowerCase ? + className.toLower() : className; + suggestedHeader.replace(QLatin1String("::"), QString(QLatin1Char('_'))); + if (!m_promotedHeaderSuffix.startsWith(dot)) + suggestedHeader += dot; + suggestedHeader += m_promotedHeaderSuffix; const bool blocked = m_includeFileEdit->blockSignals(true); m_includeFileEdit->setText(suggestedHeader); @@ -248,6 +254,8 @@ namespace qdesigner_internal { preselectedBaseClass = baseClassNameList.indexOf(QLatin1String("QFrame")); NewPromotedClassPanel *newPromotedClassPanel = new NewPromotedClassPanel(baseClassNameList, preselectedBaseClass); + newPromotedClassPanel->setPromotedHeaderSuffix(core->integration()->headerSuffix()); + newPromotedClassPanel->setPromotedHeaderLowerCase(core->integration()->isHeaderLowercase()); connect(newPromotedClassPanel, SIGNAL(newPromotedClass(PromotionParameters,bool*)), this, SLOT(slotNewPromotedClass(PromotionParameters,bool*))); connect(this, SIGNAL(selectedBaseClassChanged(QString)), newPromotedClassPanel, SLOT(chooseBaseClass(QString))); diff --git a/tools/designer/src/lib/shared/qdesigner_promotiondialog_p.h b/tools/designer/src/lib/shared/qdesigner_promotiondialog_p.h index 1e63d81..f2a2b2a 100644 --- a/tools/designer/src/lib/shared/qdesigner_promotiondialog_p.h +++ b/tools/designer/src/lib/shared/qdesigner_promotiondialog_p.h @@ -84,7 +84,13 @@ namespace qdesigner_internal { int selectedBaseClass = -1, QWidget *parent = 0); - signals: + QString promotedHeaderSuffix() const { return m_promotedHeaderSuffix; } + void setPromotedHeaderSuffix(const QString &s) { m_promotedHeaderSuffix = s; } + + bool isPromotedHeaderLowerCase() const { return m_promotedHeaderLowerCase; } + void setPromotedHeaderLowerCase(bool l) { m_promotedHeaderLowerCase = l; } + + signals: void newPromotedClass(const PromotionParameters &, bool *ok); public slots: @@ -100,6 +106,9 @@ namespace qdesigner_internal { PromotionParameters promotionParameters() const; void enableButtons(); + QString m_promotedHeaderSuffix; + bool m_promotedHeaderLowerCase; + QComboBox *m_baseClassCombo; QLineEdit *m_classNameEdit; QLineEdit *m_includeFileEdit; -- cgit v0.12 From 10e69e1d5069efa24dd70ef3fb5f9ef827ff9a4a Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 23 Aug 2010 16:31:59 +0200 Subject: Namespace compile fix for 00e954ca817f89958a8a8777d93d3843252dc88c Task-number: QTCREATORBUG-163 --- tools/designer/src/lib/sdk/abstractintegration.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/designer/src/lib/sdk/abstractintegration.cpp b/tools/designer/src/lib/sdk/abstractintegration.cpp index e8b0005..3924db6 100644 --- a/tools/designer/src/lib/sdk/abstractintegration.cpp +++ b/tools/designer/src/lib/sdk/abstractintegration.cpp @@ -62,7 +62,9 @@ struct QDesignerIntegrationInterfacePrivate { typedef QSharedPointer QDesignerIntegrationInterfacePrivatePtr; -Q_DECLARE_METATYPE(QDesignerIntegrationInterfacePrivatePtr) +QT_END_NAMESPACE +Q_DECLARE_METATYPE(QT_PREPEND_NAMESPACE(QDesignerIntegrationInterfacePrivatePtr)) +QT_BEGIN_NAMESPACE static QDesignerIntegrationInterfacePrivatePtr integrationD(const QObject *o) { -- cgit v0.12