formclasswizard.cpp 4.1 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
Eike Ziller's avatar
Eike Ziller committed
3
4
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8
9
10
11
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
Eike Ziller's avatar
Eike Ziller committed
12
13
** a written agreement between you and The Qt Company.  For licensing terms and
** conditions see http://www.qt.io/terms-conditions.  For further information
Eike Ziller's avatar
Eike Ziller committed
14
** use the contact form at http://www.qt.io/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18
19
20
21
22
23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
hjk's avatar
hjk committed
24
**
Eike Ziller's avatar
Eike Ziller committed
25
26
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
con's avatar
con committed
27
28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
29
****************************************************************************/
hjk's avatar
hjk committed
30

con's avatar
con committed
31
32
#include "formclasswizard.h"
#include "formclasswizarddialog.h"
33
34
#include <designer/designerconstants.h>
#include <designer/qtdesignerformclasscodegenerator.h>
35
#include <qtsupport/qtsupportconstants.h>
con's avatar
con committed
36
37
38

#include <cppeditor/cppeditorconstants.h>

39
#include <QDebug>
con's avatar
con committed
40

41
42
namespace Designer {
namespace Internal {
con's avatar
con committed
43

hjk's avatar
hjk committed
44
FormClassWizard::FormClassWizard()
con's avatar
con committed
45
{
46
    setRequiredFeatures({ QtSupport::Constants::FEATURE_QWIDGETS });
con's avatar
con committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
}

QString FormClassWizard::headerSuffix() const
{
    return preferredSuffix(QLatin1String(CppEditor::Constants::CPP_HEADER_MIMETYPE));
}

QString FormClassWizard::sourceSuffix() const
{
    return preferredSuffix(QLatin1String(CppEditor::Constants::CPP_SOURCE_MIMETYPE));
}

QString FormClassWizard::formSuffix() const
{
    return preferredSuffix(QLatin1String(Constants::FORM_MIMETYPE));
}

Tobias Hunger's avatar
Tobias Hunger committed
64
Core::BaseFileWizard *FormClassWizard::create(QWidget *parent, const Core::WizardDialogParameters &parameters) const
con's avatar
con committed
65
{
Tobias Hunger's avatar
Tobias Hunger committed
66
    FormClassWizardDialog *wizardDialog = new FormClassWizardDialog(this, parent);
67
    wizardDialog->setPath(parameters.defaultPath());
con's avatar
con committed
68
69
70
71
72
73
    return wizardDialog;
}

Core::GeneratedFiles FormClassWizard::generateFiles(const QWizard *w, QString *errorMessage) const
{
    const FormClassWizardDialog *wizardDialog = qobject_cast<const FormClassWizardDialog *>(w);
74
    const Designer::FormClassWizardParameters params = wizardDialog->parameters();
con's avatar
con committed
75

76
    if (params.uiTemplate.isEmpty()) {
77
        *errorMessage = QLatin1String("Internal error: FormClassWizard::generateFiles: empty template contents");
con's avatar
con committed
78
79
80
81
        return Core::GeneratedFiles();
    }

    // header
82
83
84
    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());
con's avatar
con committed
85
86

    Core::GeneratedFile headerFile(headerFileName);
87
    headerFile.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
con's avatar
con committed
88
89
90

    // Source
    Core::GeneratedFile sourceFile(sourceFileName);
91
    sourceFile.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
con's avatar
con committed
92
93
94

    // UI
    Core::GeneratedFile uiFile(formFileName);
95
    uiFile.setContents(params.uiTemplate);
96
    uiFile.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
con's avatar
con committed
97
98

    QString source, header;
99
100

    QtDesignerFormClassCodeGenerator::generateCpp(params, &header, &source);
con's avatar
con committed
101
102
103
    sourceFile.setContents(source);
    headerFile.setContents(header);

104
    if (Designer::Constants::Internal::debug)
con's avatar
con committed
105
106
107
108
        qDebug() << Q_FUNC_INFO << '\n' << header << '\n' << source;

    return  Core::GeneratedFiles() << headerFile << sourceFile << uiFile;
}
109
110
111

}
}