diff options
author | Erik Verbruggen <erik.verbruggen@nokia.com> | 2012-02-16 09:36:33 +0100 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@nokia.com> | 2012-02-16 11:02:08 +0100 |
commit | 070fd5ce007a3930de6099ffcc73c0457ea0c958 (patch) | |
tree | 1e516686c9347964097408f6fadbfb34cf3321e6 /src | |
parent | bdb89079930048bd6842dc2dd250e25a29632d00 (diff) | |
download | qt-creator-070fd5ce007a3930de6099ffcc73c0457ea0c958.tar.gz |
Changed code generation for form classes to do a Qt version check
Change-Id: I20200303ef68bc3e73b232c44263d71d09b091a5
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Reviewed-by: Bill King <bill.king@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/utils/codegeneration.cpp | 5 | ||||
-rw-r--r-- | src/libs/utils/codegeneration.h | 2 | ||||
-rw-r--r-- | src/plugins/designer/cpp/cppsettingspage.cpp | 4 | ||||
-rw-r--r-- | src/plugins/designer/cpp/cppsettingspagewidget.ui | 18 | ||||
-rw-r--r-- | src/plugins/designer/qtdesignerformclasscodegenerator.cpp | 30 | ||||
-rw-r--r-- | src/plugins/designer/qtdesignerformclasscodegenerator.h | 1 |
6 files changed, 53 insertions, 7 deletions
diff --git a/src/libs/utils/codegeneration.cpp b/src/libs/utils/codegeneration.cpp index fd5a4f3864..96786b0618 100644 --- a/src/libs/utils/codegeneration.cpp +++ b/src/libs/utils/codegeneration.cpp @@ -81,6 +81,11 @@ void writeIncludeFileDirective(const QString &file, bool globalInclude, str << QLatin1String("#include ") << opening << file << closing << QLatin1Char('\n'); } +QTCREATOR_UTILS_EXPORT void writeBeginQtVersionCheck(QTextStream &str) +{ + str << QLatin1String("#if QT_VERSION >= 0x050000\n"); +} + QTCREATOR_UTILS_EXPORT QString writeOpeningNameSpaces(const QStringList &l, const QString &indent, QTextStream &str) diff --git a/src/libs/utils/codegeneration.h b/src/libs/utils/codegeneration.h index a2fe6c79f2..ed4587a5e6 100644 --- a/src/libs/utils/codegeneration.h +++ b/src/libs/utils/codegeneration.h @@ -55,6 +55,8 @@ void writeIncludeFileDirective(const QString &file, bool globalInclude, QTextStream &str); +QTCREATOR_UTILS_EXPORT void writeBeginQtVersionCheck(QTextStream &str); + // Write opening namespaces and return an indentation string to be used // in the following code if there are any. QTCREATOR_UTILS_EXPORT diff --git a/src/plugins/designer/cpp/cppsettingspage.cpp b/src/plugins/designer/cpp/cppsettingspage.cpp index b55df33b80..dd869fd293 100644 --- a/src/plugins/designer/cpp/cppsettingspage.cpp +++ b/src/plugins/designer/cpp/cppsettingspage.cpp @@ -46,6 +46,8 @@ CppSettingsPageWidget::CppSettingsPageWidget(QWidget *parent) : QWidget(parent) { m_ui.setupUi(this); + connect(m_ui.includeQtModuleCheckBox, SIGNAL(toggled(bool)), + m_ui.addQtVersionCheckBox, SLOT(setEnabled(bool))); } FormClassWizardGenerationParameters CppSettingsPageWidget::parameters() const @@ -54,6 +56,7 @@ FormClassWizardGenerationParameters CppSettingsPageWidget::parameters() const rc.embedding = static_cast<UiClassEmbedding>(uiEmbedding()); rc.retranslationSupport =m_ui.retranslateCheckBox->isChecked(); rc.includeQtModule = m_ui.includeQtModuleCheckBox->isChecked(); + rc.addQtVersionCheck = m_ui.addQtVersionCheckBox->isChecked(); return rc; } @@ -61,6 +64,7 @@ void CppSettingsPageWidget::setParameters(const FormClassWizardGenerationParamet { m_ui.retranslateCheckBox->setChecked(p.retranslationSupport); m_ui.includeQtModuleCheckBox->setChecked(p.includeQtModule); + m_ui.addQtVersionCheckBox->setChecked(p.addQtVersionCheck); setUiEmbedding(p.embedding); } diff --git a/src/plugins/designer/cpp/cppsettingspagewidget.ui b/src/plugins/designer/cpp/cppsettingspagewidget.ui index d34a4f86f4..f9a88364ca 100644 --- a/src/plugins/designer/cpp/cppsettingspagewidget.ui +++ b/src/plugins/designer/cpp/cppsettingspagewidget.ui @@ -2,6 +2,14 @@ <ui version="4.0"> <class>Designer::Internal::CppSettingsPageWidget</class> <widget class="QWidget" name="Designer::Internal::CppSettingsPageWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>340</width> + <height>232</height> + </rect> + </property> <property name="windowTitle"> <string>Form</string> </property> @@ -62,6 +70,16 @@ </property> </widget> </item> + <item> + <widget class="QCheckBox" name="addQtVersionCheckBox"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Add Qt version #ifdef for module names</string> + </property> + </widget> + </item> </layout> </widget> </item> diff --git a/src/plugins/designer/qtdesignerformclasscodegenerator.cpp b/src/plugins/designer/qtdesignerformclasscodegenerator.cpp index ba8752b25b..0098df7329 100644 --- a/src/plugins/designer/qtdesignerformclasscodegenerator.cpp +++ b/src/plugins/designer/qtdesignerformclasscodegenerator.cpp @@ -51,9 +51,10 @@ static const char formClassWizardPageGroupC[] = "FormClassWizardPage"; static const char translationKeyC[] = "RetranslationSupport"; static const char embeddingModeKeyC[] = "Embedding"; -// TODO: These 2 are general coding convention settings and +// TODO: These 3 are general coding convention settings and // should go to CppTools... static const char includeQtModuleKeyC[] = "IncludeQtModule"; +static const char addQtVersionCheckKeyC[] = "AddQtVersionCheck"; static const char indentNamespaceKeyC[] = "IndentNamespace"; static const bool retranslationSupportDefault = false; @@ -65,6 +66,7 @@ FormClassWizardGenerationParameters::FormClassWizardGenerationParameters() : embedding(PointerAggregatedUiClass), retranslationSupport(retranslationSupportDefault), includeQtModule(false), + addQtVersionCheck(false), indentNamespace(false) { } @@ -76,6 +78,7 @@ void FormClassWizardGenerationParameters::fromSettings(const QSettings *settings retranslationSupport = settings->value(group + QLatin1String(translationKeyC), retranslationSupportDefault).toBool(); embedding = static_cast<UiClassEmbedding>(settings->value(group + QLatin1String(embeddingModeKeyC), int(PointerAggregatedUiClass)).toInt()); includeQtModule = settings->value(group + QLatin1String(includeQtModuleKeyC), false).toBool(); + addQtVersionCheck = settings->value(group + QLatin1String(addQtVersionCheckKeyC), false).toBool(); indentNamespace = settings->value(group + QLatin1String(indentNamespaceKeyC), false).toBool(); } @@ -85,14 +88,18 @@ void FormClassWizardGenerationParameters::toSettings(QSettings *settings) const settings->setValue(QLatin1String(translationKeyC), retranslationSupport); settings->setValue(QLatin1String(embeddingModeKeyC), embedding); settings->setValue(QLatin1String(includeQtModuleKeyC), includeQtModule); + settings->setValue(QLatin1String(addQtVersionCheckKeyC), addQtVersionCheck); settings->setValue(QLatin1String(indentNamespaceKeyC), indentNamespace); settings->endGroup(); } bool FormClassWizardGenerationParameters::equals(const FormClassWizardGenerationParameters &rhs) const { - return embedding == rhs.embedding && retranslationSupport == rhs.retranslationSupport - && includeQtModule == rhs.includeQtModule && indentNamespace == rhs.indentNamespace; + return embedding == rhs.embedding + && retranslationSupport == rhs.retranslationSupport + && includeQtModule == rhs.includeQtModule + && addQtVersionCheck == rhs.addQtVersionCheck + && indentNamespace == rhs.indentNamespace; } // Generation code @@ -166,10 +173,19 @@ bool QtDesignerFormClassCodeGenerator::generateCpp(const FormClassWizardParamete // Todo: Can we obtain the header from the code model for custom widgets? // Alternatively, from Designer. if (formBaseClass.startsWith(QLatin1Char('Q'))) { - QString baseInclude = formBaseClass; - if (generationParameters.includeQtModule) - baseInclude.insert(0, QLatin1String("QtGui/")); - Utils::writeIncludeFileDirective(baseInclude, true, headerStr); + if (generationParameters.includeQtModule) { + if (generationParameters.addQtVersionCheck) { + Utils::writeBeginQtVersionCheck(headerStr); + Utils::writeIncludeFileDirective(QLatin1String("QtWidgets/") + formBaseClass, true, headerStr); + headerStr << "#else\n"; + Utils::writeIncludeFileDirective(QLatin1String("QtGui/") + formBaseClass, true, headerStr); + headerStr << "#endif\n"; + } else { + Utils::writeIncludeFileDirective(QLatin1String("QtGui/") + formBaseClass, true, headerStr); + } + } else { + Utils::writeIncludeFileDirective(formBaseClass, true, headerStr); + } } } diff --git a/src/plugins/designer/qtdesignerformclasscodegenerator.h b/src/plugins/designer/qtdesignerformclasscodegenerator.h index ffab76138b..3f7c47c92f 100644 --- a/src/plugins/designer/qtdesignerformclasscodegenerator.h +++ b/src/plugins/designer/qtdesignerformclasscodegenerator.h @@ -65,6 +65,7 @@ struct FormClassWizardGenerationParameters UiClassEmbedding embedding; bool retranslationSupport; // Add handling for language change events bool includeQtModule; // Include "<QtGui/[Class]>" or just "<[Class]>" + bool addQtVersionCheck; // Include #ifdef when using "#include <QtGui/..." bool indentNamespace; }; |