forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -81,6 +81,11 @@ void writeIncludeFileDirective(const QString &file, bool globalInclude,
|
|||||||
str << QLatin1String("#include ") << opening << file << closing << QLatin1Char('\n');
|
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
|
QTCREATOR_UTILS_EXPORT
|
||||||
QString writeOpeningNameSpaces(const QStringList &l, const QString &indent,
|
QString writeOpeningNameSpaces(const QStringList &l, const QString &indent,
|
||||||
QTextStream &str)
|
QTextStream &str)
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ void writeIncludeFileDirective(const QString &file,
|
|||||||
bool globalInclude,
|
bool globalInclude,
|
||||||
QTextStream &str);
|
QTextStream &str);
|
||||||
|
|
||||||
|
QTCREATOR_UTILS_EXPORT void writeBeginQtVersionCheck(QTextStream &str);
|
||||||
|
|
||||||
// Write opening namespaces and return an indentation string to be used
|
// Write opening namespaces and return an indentation string to be used
|
||||||
// in the following code if there are any.
|
// in the following code if there are any.
|
||||||
QTCREATOR_UTILS_EXPORT
|
QTCREATOR_UTILS_EXPORT
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ CppSettingsPageWidget::CppSettingsPageWidget(QWidget *parent) :
|
|||||||
QWidget(parent)
|
QWidget(parent)
|
||||||
{
|
{
|
||||||
m_ui.setupUi(this);
|
m_ui.setupUi(this);
|
||||||
|
connect(m_ui.includeQtModuleCheckBox, SIGNAL(toggled(bool)),
|
||||||
|
m_ui.addQtVersionCheckBox, SLOT(setEnabled(bool)));
|
||||||
}
|
}
|
||||||
|
|
||||||
FormClassWizardGenerationParameters CppSettingsPageWidget::parameters() const
|
FormClassWizardGenerationParameters CppSettingsPageWidget::parameters() const
|
||||||
@@ -54,6 +56,7 @@ FormClassWizardGenerationParameters CppSettingsPageWidget::parameters() const
|
|||||||
rc.embedding = static_cast<UiClassEmbedding>(uiEmbedding());
|
rc.embedding = static_cast<UiClassEmbedding>(uiEmbedding());
|
||||||
rc.retranslationSupport =m_ui.retranslateCheckBox->isChecked();
|
rc.retranslationSupport =m_ui.retranslateCheckBox->isChecked();
|
||||||
rc.includeQtModule = m_ui.includeQtModuleCheckBox->isChecked();
|
rc.includeQtModule = m_ui.includeQtModuleCheckBox->isChecked();
|
||||||
|
rc.addQtVersionCheck = m_ui.addQtVersionCheckBox->isChecked();
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,6 +64,7 @@ void CppSettingsPageWidget::setParameters(const FormClassWizardGenerationParamet
|
|||||||
{
|
{
|
||||||
m_ui.retranslateCheckBox->setChecked(p.retranslationSupport);
|
m_ui.retranslateCheckBox->setChecked(p.retranslationSupport);
|
||||||
m_ui.includeQtModuleCheckBox->setChecked(p.includeQtModule);
|
m_ui.includeQtModuleCheckBox->setChecked(p.includeQtModule);
|
||||||
|
m_ui.addQtVersionCheckBox->setChecked(p.addQtVersionCheck);
|
||||||
setUiEmbedding(p.embedding);
|
setUiEmbedding(p.embedding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,14 @@
|
|||||||
<ui version="4.0">
|
<ui version="4.0">
|
||||||
<class>Designer::Internal::CppSettingsPageWidget</class>
|
<class>Designer::Internal::CppSettingsPageWidget</class>
|
||||||
<widget class="QWidget" name="Designer::Internal::CppSettingsPageWidget">
|
<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">
|
<property name="windowTitle">
|
||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
@@ -62,6 +70,16 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
@@ -51,9 +51,10 @@ static const char formClassWizardPageGroupC[] = "FormClassWizardPage";
|
|||||||
static const char translationKeyC[] = "RetranslationSupport";
|
static const char translationKeyC[] = "RetranslationSupport";
|
||||||
static const char embeddingModeKeyC[] = "Embedding";
|
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...
|
// should go to CppTools...
|
||||||
static const char includeQtModuleKeyC[] = "IncludeQtModule";
|
static const char includeQtModuleKeyC[] = "IncludeQtModule";
|
||||||
|
static const char addQtVersionCheckKeyC[] = "AddQtVersionCheck";
|
||||||
static const char indentNamespaceKeyC[] = "IndentNamespace";
|
static const char indentNamespaceKeyC[] = "IndentNamespace";
|
||||||
|
|
||||||
static const bool retranslationSupportDefault = false;
|
static const bool retranslationSupportDefault = false;
|
||||||
@@ -65,6 +66,7 @@ FormClassWizardGenerationParameters::FormClassWizardGenerationParameters() :
|
|||||||
embedding(PointerAggregatedUiClass),
|
embedding(PointerAggregatedUiClass),
|
||||||
retranslationSupport(retranslationSupportDefault),
|
retranslationSupport(retranslationSupportDefault),
|
||||||
includeQtModule(false),
|
includeQtModule(false),
|
||||||
|
addQtVersionCheck(false),
|
||||||
indentNamespace(false)
|
indentNamespace(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -76,6 +78,7 @@ void FormClassWizardGenerationParameters::fromSettings(const QSettings *settings
|
|||||||
retranslationSupport = settings->value(group + QLatin1String(translationKeyC), retranslationSupportDefault).toBool();
|
retranslationSupport = settings->value(group + QLatin1String(translationKeyC), retranslationSupportDefault).toBool();
|
||||||
embedding = static_cast<UiClassEmbedding>(settings->value(group + QLatin1String(embeddingModeKeyC), int(PointerAggregatedUiClass)).toInt());
|
embedding = static_cast<UiClassEmbedding>(settings->value(group + QLatin1String(embeddingModeKeyC), int(PointerAggregatedUiClass)).toInt());
|
||||||
includeQtModule = settings->value(group + QLatin1String(includeQtModuleKeyC), false).toBool();
|
includeQtModule = settings->value(group + QLatin1String(includeQtModuleKeyC), false).toBool();
|
||||||
|
addQtVersionCheck = settings->value(group + QLatin1String(addQtVersionCheckKeyC), false).toBool();
|
||||||
indentNamespace = settings->value(group + QLatin1String(indentNamespaceKeyC), 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(translationKeyC), retranslationSupport);
|
||||||
settings->setValue(QLatin1String(embeddingModeKeyC), embedding);
|
settings->setValue(QLatin1String(embeddingModeKeyC), embedding);
|
||||||
settings->setValue(QLatin1String(includeQtModuleKeyC), includeQtModule);
|
settings->setValue(QLatin1String(includeQtModuleKeyC), includeQtModule);
|
||||||
|
settings->setValue(QLatin1String(addQtVersionCheckKeyC), addQtVersionCheck);
|
||||||
settings->setValue(QLatin1String(indentNamespaceKeyC), indentNamespace);
|
settings->setValue(QLatin1String(indentNamespaceKeyC), indentNamespace);
|
||||||
settings->endGroup();
|
settings->endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FormClassWizardGenerationParameters::equals(const FormClassWizardGenerationParameters &rhs) const
|
bool FormClassWizardGenerationParameters::equals(const FormClassWizardGenerationParameters &rhs) const
|
||||||
{
|
{
|
||||||
return embedding == rhs.embedding && retranslationSupport == rhs.retranslationSupport
|
return embedding == rhs.embedding
|
||||||
&& includeQtModule == rhs.includeQtModule && indentNamespace == rhs.indentNamespace;
|
&& retranslationSupport == rhs.retranslationSupport
|
||||||
|
&& includeQtModule == rhs.includeQtModule
|
||||||
|
&& addQtVersionCheck == rhs.addQtVersionCheck
|
||||||
|
&& indentNamespace == rhs.indentNamespace;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generation code
|
// Generation code
|
||||||
@@ -166,10 +173,19 @@ bool QtDesignerFormClassCodeGenerator::generateCpp(const FormClassWizardParamete
|
|||||||
// Todo: Can we obtain the header from the code model for custom widgets?
|
// Todo: Can we obtain the header from the code model for custom widgets?
|
||||||
// Alternatively, from Designer.
|
// Alternatively, from Designer.
|
||||||
if (formBaseClass.startsWith(QLatin1Char('Q'))) {
|
if (formBaseClass.startsWith(QLatin1Char('Q'))) {
|
||||||
QString baseInclude = formBaseClass;
|
if (generationParameters.includeQtModule) {
|
||||||
if (generationParameters.includeQtModule)
|
if (generationParameters.addQtVersionCheck) {
|
||||||
baseInclude.insert(0, QLatin1String("QtGui/"));
|
Utils::writeBeginQtVersionCheck(headerStr);
|
||||||
Utils::writeIncludeFileDirective(baseInclude, true, 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ struct FormClassWizardGenerationParameters
|
|||||||
UiClassEmbedding embedding;
|
UiClassEmbedding embedding;
|
||||||
bool retranslationSupport; // Add handling for language change events
|
bool retranslationSupport; // Add handling for language change events
|
||||||
bool includeQtModule; // Include "<QtGui/[Class]>" or just "<[Class]>"
|
bool includeQtModule; // Include "<QtGui/[Class]>" or just "<[Class]>"
|
||||||
|
bool addQtVersionCheck; // Include #ifdef when using "#include <QtGui/..."
|
||||||
bool indentNamespace;
|
bool indentNamespace;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user