Commit b606469a authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Project managers: Remove dependency to Qt Designer.

(Cmake/Qt4). Use PluginManager invocation facility
for the form class code generation. Do the rest
(testing for form editor, retrieving the editor
contents).

Acked-By: hjk
parent bda60114
......@@ -43,7 +43,7 @@
namespace ExtensionSystem {
class InvokerBase
class EXTENSIONSYSTEM_EXPORT InvokerBase
{
public:
InvokerBase();
......
......@@ -49,7 +49,6 @@
#include <projectexplorer/toolchain.h>
#include <cplusplus/ModelManagerInterface.h>
#include <extensionsystem/pluginmanager.h>
#include <designer/formwindoweditor.h>
#include <utils/qtcassert.h>
#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
......@@ -76,6 +75,20 @@ using namespace ProjectExplorer;
// Open Questions
// Who sets up the environment for cl.exe ? INCLUDEPATH and so on
// Test for form editor (loosely coupled)
static inline bool isFormWindowEditor(const QObject *o)
{
return o && !qstrcmp(o->metaObject()->className(), "Designer::FormWindowEditor");
}
// Return contents of form editor (loosely coupled)
static inline QString formWindowEditorContents(const QObject *editor)
{
const QVariant contentV = editor->property("contents");
QTC_ASSERT(contentV.isValid(), return QString(); )
return contentV.toString();
}
/*!
\class CMakeProject
*/
......@@ -659,13 +672,11 @@ void CMakeProject::updateCodeModelSupportFromEditor(const QString &uiFileName,
void CMakeProject::editorChanged(Core::IEditor *editor)
{
// Handle old editor
Designer::FormWindowEditor *lastFormEditor = qobject_cast<Designer::FormWindowEditor *>(m_lastEditor);
if (lastFormEditor) {
disconnect(lastFormEditor, SIGNAL(changed()), this, SLOT(uiEditorContentsChanged()));
if (isFormWindowEditor(m_lastEditor)) {
disconnect(m_lastEditor, SIGNAL(changed()), this, SLOT(uiEditorContentsChanged()));
if (m_dirtyUic) {
const QString contents = lastFormEditor->contents();
updateCodeModelSupportFromEditor(lastFormEditor->file()->fileName(), contents);
const QString contents = formWindowEditorContents(m_lastEditor);
updateCodeModelSupportFromEditor(m_lastEditor->file()->fileName(), contents);
m_dirtyUic = false;
}
}
......@@ -673,8 +684,8 @@ void CMakeProject::editorChanged(Core::IEditor *editor)
m_lastEditor = editor;
// Handle new editor
if (Designer::FormWindowEditor *fw = qobject_cast<Designer::FormWindowEditor *>(editor))
connect(fw, SIGNAL(changed()), this, SLOT(uiEditorContentsChanged()));
if (isFormWindowEditor(editor))
connect(editor, SIGNAL(changed()), this, SLOT(uiEditorContentsChanged()));
}
void CMakeProject::editorAboutToClose(Core::IEditor *editor)
......@@ -682,12 +693,11 @@ void CMakeProject::editorAboutToClose(Core::IEditor *editor)
if (m_lastEditor == editor) {
// Oh no our editor is going to be closed
// get the content first
Designer::FormWindowEditor *lastEditor = qobject_cast<Designer::FormWindowEditor *>(m_lastEditor);
if (lastEditor) {
disconnect(lastEditor, SIGNAL(changed()), this, SLOT(uiEditorContentsChanged()));
if (isFormWindowEditor(m_lastEditor)) {
disconnect(m_lastEditor, SIGNAL(changed()), this, SLOT(uiEditorContentsChanged()));
if (m_dirtyUic) {
const QString contents = lastEditor->contents();
updateCodeModelSupportFromEditor(lastEditor->file()->fileName(), contents);
const QString contents = formWindowEditorContents(m_lastEditor);
updateCodeModelSupportFromEditor(m_lastEditor->file()->fileName(), contents);
m_dirtyUic = false;
}
}
......@@ -698,12 +708,8 @@ void CMakeProject::editorAboutToClose(Core::IEditor *editor)
void CMakeProject::uiEditorContentsChanged()
{
// cast sender, get filename
if (m_dirtyUic)
return;
Designer::FormWindowEditor *fw = qobject_cast<Designer::FormWindowEditor *>(sender());
if (!fw)
return;
m_dirtyUic = true;
if (!m_dirtyUic && isFormWindowEditor(sender()))
m_dirtyUic = true;
}
void CMakeProject::buildStateChanged(ProjectExplorer::Project *project)
......
include(../../plugins/projectexplorer/projectexplorer.pri)
include(../../plugins/cpptools/cpptools.pri)
include(../../plugins/texteditor/texteditor.pri)
include(../../plugins/designer/designer.pri)
......@@ -52,38 +52,38 @@ CppSettingsPageWidget::CppSettingsPageWidget(QWidget *parent) :
FormClassWizardGenerationParameters CppSettingsPageWidget::parameters() const
{
FormClassWizardGenerationParameters rc;
rc.setEmbedding(static_cast<FormClassWizardGenerationParameters::UiClassEmbedding>(uiEmbedding()));
rc.setRetranslationSupport(m_ui.retranslateCheckBox->isChecked());
rc.setIncludeQtModule(m_ui.includeQtModuleCheckBox->isChecked());
rc.embedding = static_cast<UiClassEmbedding>(uiEmbedding());
rc.retranslationSupport =m_ui.retranslateCheckBox->isChecked();
rc.includeQtModule = m_ui.includeQtModuleCheckBox->isChecked();
return rc;
}
void CppSettingsPageWidget::setParameters(const FormClassWizardGenerationParameters &p)
{
m_ui.retranslateCheckBox->setChecked(p.retranslationSupport());
m_ui.includeQtModuleCheckBox->setChecked(p.includeQtModule());
setUiEmbedding(p.embedding());
m_ui.retranslateCheckBox->setChecked(p.retranslationSupport);
m_ui.includeQtModuleCheckBox->setChecked(p.includeQtModule);
setUiEmbedding(p.embedding);
}
int CppSettingsPageWidget::uiEmbedding() const
{
if (m_ui.ptrAggregationRadioButton->isChecked())
return FormClassWizardGenerationParameters::PointerAggregatedUiClass;
return PointerAggregatedUiClass;
if (m_ui.aggregationButton->isChecked())
return FormClassWizardGenerationParameters::AggregatedUiClass;
return FormClassWizardGenerationParameters::InheritedUiClass;
return AggregatedUiClass;
return InheritedUiClass;
}
void CppSettingsPageWidget::setUiEmbedding(int v)
{
switch (v) {
case FormClassWizardGenerationParameters::PointerAggregatedUiClass:
case PointerAggregatedUiClass:
m_ui.ptrAggregationRadioButton->setChecked(true);
break;
case FormClassWizardGenerationParameters::AggregatedUiClass:
case AggregatedUiClass:
m_ui.aggregationButton->setChecked(true);
break;
case FormClassWizardGenerationParameters::InheritedUiClass:
case InheritedUiClass:
m_ui.multipleInheritanceButton->setChecked(true);
break;
}
......
......@@ -34,8 +34,8 @@
#ifndef CPPSETTINGSPAGE_H
#define CPPSETTINGSPAGE_H
#include "formclasswizardparameters.h"
#include "ui_cppsettingspagewidget.h"
#include "qtdesignerformclasscodegenerator.h"
#include <coreplugin/dialogs/ioptionspage.h>
......
......@@ -35,6 +35,7 @@
#include "formclasswizarddialog.h"
#include "designerconstants.h"
#include "formwindoweditor.h"
#include "qtdesignerformclasscodegenerator.h"
#include <coreplugin/icore.h>
#include <cppeditor/cppeditorconstants.h>
......@@ -80,15 +81,15 @@ Core::GeneratedFiles FormClassWizard::generateFiles(const QWizard *w, QString *e
const FormClassWizardDialog *wizardDialog = qobject_cast<const FormClassWizardDialog *>(w);
const Designer::FormClassWizardParameters params = wizardDialog->parameters();
if (params.uiTemplate().isEmpty()) {
if (params.uiTemplate.isEmpty()) {
*errorMessage = QLatin1String("Internal error: FormClassWizard::generateFiles: empty template contents");
return Core::GeneratedFiles();
}
// header
const QString formFileName = buildFileName(params.path(), params.uiFile(), formSuffix());
const QString headerFileName = buildFileName(params.path(), params.headerFile(), headerSuffix());
const QString sourceFileName = buildFileName(params.path(), params.sourceFile(), sourceSuffix());
const QString formFileName = buildFileName(params.path, params.uiFile, formSuffix());
const QString headerFileName = buildFileName(params.path, params.headerFile, headerSuffix());
const QString sourceFileName = buildFileName(params.path, params.sourceFile, sourceSuffix());
Core::GeneratedFile headerFile(headerFileName);
headerFile.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
......@@ -99,13 +100,12 @@ Core::GeneratedFiles FormClassWizard::generateFiles(const QWizard *w, QString *e
// UI
Core::GeneratedFile uiFile(formFileName);
uiFile.setContents(params.uiTemplate());
uiFile.setContents(params.uiTemplate);
uiFile.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
QString source, header;
Designer::FormClassWizardGenerationParameters generationParameters;
generationParameters.fromSettings(Core::ICore::instance()->settings());
params.generateCpp(generationParameters, &header, &source);
QtDesignerFormClassCodeGenerator::generateCpp(params, &header, &source);
sourceFile.setContents(source);
headerFile.setContents(header);
......
......@@ -103,7 +103,7 @@ FormClassWizardParameters FormClassWizardDialog::parameters() const
FormClassWizardParameters rc;
m_classPage->getParameters(&rc);
// Name the ui class in the Ui namespace after the class specified
rc.setUiTemplate(FormTemplateWizardPage::changeUiClassName(m_rawFormTemplate, rc.className()));
rc.uiTemplate = FormTemplateWizardPage::changeUiClassName(m_rawFormTemplate, rc.className);
return rc;
}
......
......@@ -112,11 +112,11 @@ void FormClassWizardPage::setPath(const QString &p)
void FormClassWizardPage::getParameters(FormClassWizardParameters *p) const
{
p->setClassName(m_ui->newClassWidget->className());
p->setPath(path());
p->setSourceFile(m_ui->newClassWidget->sourceFileName());
p->setHeaderFile(m_ui->newClassWidget->headerFileName());
p->setUiFile(m_ui->newClassWidget-> formFileName());
p->className = m_ui->newClassWidget->className();
p->path = path();
p->sourceFile = m_ui->newClassWidget->sourceFileName();
p->headerFile = m_ui->newClassWidget->headerFileName();
p->uiFile = m_ui->newClassWidget-> formFileName();
}
void FormClassWizardPage::slotValidChanged()
......
......@@ -34,433 +34,3 @@
#include "formclasswizardparameters.h"
#include "formtemplatewizardpage.h"
#include <utils/codegeneration.h>
#include <cpptools/abstracteditorsupport.h>
#include <QtCore/QTextStream>
#include <QtCore/QSettings>
#include <QtCore/QFileInfo>
#include <QtCore/QDebug>
#include <QtCore/QSharedData>
static const char *uiMemberC = "ui";
static const char *uiNamespaceC = "Ui";
static const char *formClassWizardPageGroupC = "FormClassWizardPage";
static const char *translationKeyC = "RetranslationSupport";
static const char *embeddingModeKeyC = "Embedding";
// TODO: These 2 are general coding convention settings and
// should go to CppTools...
static const char *includeQtModuleKeyC = "IncludeQtModule";
static const char *indentNamespaceKeyC = "IndentNamespace";
static const bool retranslationSupportDefault = false;
namespace Designer {
class FormClassWizardGenerationParametersPrivate : public QSharedData
{
public:
FormClassWizardGenerationParametersPrivate();
void fromSettings(const QSettings *);
void toSettings(QSettings *) const;
bool equals(const FormClassWizardGenerationParametersPrivate &rhs) const;
FormClassWizardGenerationParameters::UiClassEmbedding embedding;
bool retranslationSupport; // Add handling for language change events
bool includeQtModule; // Include "<QtGui/[Class]>" or just "<[Class]>"
bool indentNamespace;
};
FormClassWizardGenerationParametersPrivate::FormClassWizardGenerationParametersPrivate() :
embedding(FormClassWizardGenerationParameters::PointerAggregatedUiClass),
retranslationSupport(retranslationSupportDefault),
includeQtModule(false),
indentNamespace(false)
{
}
void FormClassWizardGenerationParametersPrivate::fromSettings(const QSettings *settings)
{
QString key = QLatin1String(formClassWizardPageGroupC);
key += QLatin1Char('/');
const int groupLength = key.size();
key += QLatin1String(translationKeyC);
retranslationSupport = settings->value(key, retranslationSupportDefault).toBool();
key.truncate(groupLength);
key += QLatin1String(embeddingModeKeyC);
embedding = static_cast<FormClassWizardGenerationParameters::UiClassEmbedding>(settings->value(key, int(FormClassWizardGenerationParameters::PointerAggregatedUiClass)).toInt());
key.truncate(groupLength);
key += QLatin1String(includeQtModuleKeyC);
includeQtModule = settings->value(key, false).toBool();
key.truncate(groupLength);
key += QLatin1String(indentNamespaceKeyC);
indentNamespace = settings->value(key, false).toBool();
}
void FormClassWizardGenerationParametersPrivate::toSettings(QSettings *settings) const
{
settings->beginGroup(QLatin1String(formClassWizardPageGroupC));
settings->setValue(QLatin1String(translationKeyC), retranslationSupport);
settings->setValue(QLatin1String(embeddingModeKeyC), embedding);
settings->setValue(QLatin1String(includeQtModuleKeyC), includeQtModule);
settings->setValue(QLatin1String(indentNamespaceKeyC), indentNamespace);
settings->endGroup();
}
bool FormClassWizardGenerationParametersPrivate::equals(const FormClassWizardGenerationParametersPrivate &rhs) const
{
return embedding == rhs.embedding && retranslationSupport == rhs.retranslationSupport
&& includeQtModule == rhs.includeQtModule && indentNamespace == rhs.indentNamespace;
}
FormClassWizardGenerationParameters::FormClassWizardGenerationParameters() :
m_d(new FormClassWizardGenerationParametersPrivate)
{
}
FormClassWizardGenerationParameters::~FormClassWizardGenerationParameters()
{
}
FormClassWizardGenerationParameters::FormClassWizardGenerationParameters(const FormClassWizardGenerationParameters &rhs) :
m_d(rhs.m_d)
{
}
FormClassWizardGenerationParameters &FormClassWizardGenerationParameters::operator=(const FormClassWizardGenerationParameters &rhs)
{
if (this != &rhs)
m_d.operator=(rhs.m_d);
return *this;
}
bool FormClassWizardGenerationParameters::equals(const FormClassWizardGenerationParameters &rhs) const
{
return m_d->equals(*rhs.m_d.constData());
}
FormClassWizardGenerationParameters::UiClassEmbedding FormClassWizardGenerationParameters::embedding() const
{
return m_d->embedding;
}
void FormClassWizardGenerationParameters::setEmbedding(UiClassEmbedding e)
{
m_d->embedding = e;
}
bool FormClassWizardGenerationParameters::retranslationSupport() const
{
return m_d->retranslationSupport;
}
void FormClassWizardGenerationParameters::setRetranslationSupport(bool v)
{
m_d->retranslationSupport = v;
}
bool FormClassWizardGenerationParameters::includeQtModule() const
{
return m_d->includeQtModule;
}
void FormClassWizardGenerationParameters::setIncludeQtModule(bool v)
{
m_d->includeQtModule = v;
}
bool FormClassWizardGenerationParameters::indentNamespace() const
{
return m_d->indentNamespace;
}
void FormClassWizardGenerationParameters::setIndentNamespace(bool v)
{
m_d->indentNamespace = v;
}
void FormClassWizardGenerationParameters::fromSettings(const QSettings *settings)
{
m_d->fromSettings(settings);
}
void FormClassWizardGenerationParameters::toSettings(QSettings *settings) const
{
m_d->toSettings(settings);
}
// -----------
class FormClassWizardParametersPrivate : public QSharedData {
public:
bool generateCpp(const FormClassWizardGenerationParameters &fgp,
QString *header, QString *source, int indentation) const;
QString uiTemplate;
QString className;
QString path;
QString sourceFile;
QString headerFile;
QString uiFile;
};
FormClassWizardParameters::FormClassWizardParameters() :
m_d(new FormClassWizardParametersPrivate)
{
}
FormClassWizardParameters::~FormClassWizardParameters()
{
}
FormClassWizardParameters::FormClassWizardParameters(const FormClassWizardParameters &rhs) :
m_d(rhs.m_d)
{
}
FormClassWizardParameters &FormClassWizardParameters::operator=(const FormClassWizardParameters &rhs)
{
if (this != &rhs)
m_d.operator =(rhs.m_d);
return *this;
}
QString FormClassWizardParameters::uiTemplate() const
{
return m_d->uiTemplate;
}
void FormClassWizardParameters::setUiTemplate(const QString &s)
{
m_d->uiTemplate = s;
}
QString FormClassWizardParameters::className() const
{
return m_d->className;
}
void FormClassWizardParameters::setClassName(const QString &s)
{
m_d->className = s;
}
QString FormClassWizardParameters::path() const
{
return m_d->path;
}
void FormClassWizardParameters::setPath(const QString &s)
{
m_d->path = s;
}
QString FormClassWizardParameters::sourceFile() const
{
return m_d->sourceFile;
}
void FormClassWizardParameters::setSourceFile(const QString &s)
{
m_d->sourceFile = s;
}
QString FormClassWizardParameters::headerFile() const
{
return m_d->headerFile;
}
void FormClassWizardParameters::setHeaderFile(const QString &s)
{
m_d->headerFile = s;
}
QString FormClassWizardParameters::uiFile() const
{
return m_d->uiFile;
}
void FormClassWizardParameters::setUiFile(const QString &s)
{
m_d->uiFile = s;
}
bool FormClassWizardParameters::getUIXmlData(const QString &uiXml, QString *formBaseClass, QString *uiClassName)
{
return Designer::Internal::FormTemplateWizardPage::getUIXmlData(uiXml, formBaseClass, uiClassName);
}
QString FormClassWizardParameters::changeUiClassName(const QString &uiXml, const QString &newUiClassName)
{
return Designer::Internal::FormTemplateWizardPage::changeUiClassName(uiXml, newUiClassName);
}
// Write out how to access the Ui class in the source code.
static inline void writeUiMemberAccess(const FormClassWizardGenerationParameters &fp, QTextStream &str)
{
switch(fp.embedding()) {
case FormClassWizardGenerationParameters::PointerAggregatedUiClass:
str << uiMemberC << "->";
break;
case FormClassWizardGenerationParameters::AggregatedUiClass:
str << uiMemberC << '.';
break;
case FormClassWizardGenerationParameters::InheritedUiClass:
break;
}
}
bool FormClassWizardParametersPrivate::generateCpp(const FormClassWizardGenerationParameters &generationParameters,
QString *header, QString *source, int indentation) const
{
const QString indent = QString(indentation, QLatin1Char(' '));
QString formBaseClass;
QString uiClassName;
if (!FormClassWizardParameters::getUIXmlData(uiTemplate, &formBaseClass, &uiClassName)) {
qWarning("Unable to determine the form base class from %s.", uiTemplate.toUtf8().constData());
return false;
}
// Build the ui class (Ui::Foo) name relative to the namespace (which is the same):
const FormClassWizardGenerationParameters::UiClassEmbedding embedding = generationParameters.embedding();
const QString colonColon = QLatin1String("::");
const int lastSeparator = uiClassName.lastIndexOf(colonColon);
if (lastSeparator != -1)
uiClassName.remove(0, lastSeparator + colonColon.size());
uiClassName.insert(0, QLatin1String(uiNamespaceC) + colonColon);
// Do we have namespaces?
QStringList namespaceList = className.split(colonColon);
if (namespaceList.empty()) // Paranoia!
return false;
const QString unqualifiedClassName = namespaceList.takeLast();
const QString headerLicense =
CppTools::AbstractEditorSupport::licenseTemplate(headerFile, className);
const QString sourceLicense =
CppTools::AbstractEditorSupport::licenseTemplate(sourceFile, className);
// Include guards
const QString guard = Utils::headerGuard(headerFile);
QString uiInclude = QLatin1String("ui_");
uiInclude += QFileInfo(uiFile).completeBaseName();
uiInclude += QLatin1String(".h");
// 1) Header file
QTextStream headerStr(header);
headerStr << headerLicense << "#ifndef " << guard
<< "\n#define " << guard << '\n' << '\n';
// Include 'ui_'
if (embedding != FormClassWizardGenerationParameters::PointerAggregatedUiClass) {
Utils::writeIncludeFileDirective(uiInclude, false, headerStr);
} else {
// 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);
}
}
const QString namespaceIndent = Utils::writeOpeningNameSpaces(namespaceList,
generationParameters.indentNamespace() ? indent : QString(),
headerStr);
// Forward-declare the UI class