aboutsummaryrefslogtreecommitdiffstats
path: root/QtVsTools.Wizards/ProjectWizard/Quick/QuickWizard.cs
blob: 23db7292d259bf955b425391b4d653356f3e76c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

using System;
using System.Collections.Generic;
using System.Text;

namespace QtVsTools.Wizards.ProjectWizard
{
    using Common;
    using static QtVsTools.Common.EnumExt;

    public class QuickWizard : ProjectTemplateWizard
    {
        protected override Options TemplateType => Options.Application | Options.GUISystem;

        protected enum Qml
        {
            [String("qml_prefix")] Prefix
        }

        protected override WizardData WizardData => Lazy.Get(() =>
            WizardData, () => new WizardData
            {
                DefaultModules = new List<string> { "QtQuick" }
            });

        protected override WizardWindow WizardWindow => Lazy.Get(() =>
            WizardWindow, () => new WizardWindow(title: "Qt Quick Application Wizard")
            {
                new WizardIntroPage {
                    Data = WizardData,
                    Header = @"Welcome to the Qt Quick Application Wizard",
                    Message = @"This wizard generates a Qt Quick application project."
                        + System.Environment.NewLine
                        + "Click Finish to create the project.",
                    PreviousButtonEnabled = false,
                    NextButtonEnabled = true,
                    FinishButtonEnabled = false,
                    CancelButtonEnabled = true
                },
                new ConfigPage {
                    Data = WizardData,
                    Header = @"Welcome to the Qt Quick Application Wizard",
                    Message =
                            @"Setup the configurations you want to include in your project. "
                            + @"The recommended settings for this project are selected by default.",
                    PreviousButtonEnabled = true,
                    NextButtonEnabled = false,
                    FinishButtonEnabled = true,
                    CancelButtonEnabled = true
                }
            });

        protected override void BeforeTemplateExpansion()
        {
            Parameter[Qml.Prefix] = Parameter[NewProject.SafeName].ToLower();

            var include = new StringBuilder();
            if (UsePrecompiledHeaders)
                include.AppendLine($"#include \"{PrecompiledHeader.Include}\"");
            include.AppendLine("#include <QGuiApplication>");
            include.AppendLine("#include <QQmlApplicationEngine>");
            Parameter[NewClass.Include] = FormatParam(include);
        }

        protected override void ExpandQtSettings(StringBuilder xml, IWizardConfiguration config)
        {
            base.ExpandQtSettings(xml, config);
            if (config.IsDebug)
                xml.AppendLine(@"<QtQMLDebugEnable>true</QtQMLDebugEnable>");
        }

        protected override CMakeConfigPreset ConfigureCMakePreset(IWizardConfiguration config)
        {
            var preset = base.ConfigureCMakePreset(config);
            if (config.IsDebug) {
                preset.CacheVariables.CxxFlags = "-DQT_QML_DEBUG";
                (preset.Environment ??= new())
                    .QmlDebugArgs = $"-qmljsdebugger=file:{{{Guid.NewGuid()}}},block";
            }
            return preset;
        }
    }
}