Files
qt-creator/src/plugins/qmljstools/qmljscodestylepreferencesfactory.cpp
hjk 63374fb34d QmlJsEditor: Don't export Internal classes
Export two functions doing the actual work instead.
Centralize some repeated code.

Change-Id: I7de674ef7ae5537663d1227d36cc556c4ee3ed74
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
2024-01-09 16:17:37 +00:00

80 lines
2.1 KiB
C++

// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "qmljscodestylepreferencesfactory.h"
#include "qmljscodestylepreferences.h"
#include "qmljscodestylesettingspage.h"
#include "qmljsindenter.h"
#include "qmljstoolsconstants.h"
#include "qmljstoolstr.h"
#include <qmljseditor/qmljseditorconstants.h>
using namespace QmlJSTools;
static const char *defaultPreviewText =
"import QtQuick 1.0\n"
"\n"
"Rectangle {\n"
" width: 360\n"
" height: 360\n"
" Text {\n"
" anchors.centerIn: parent\n"
" text: \"Hello World\"\n"
" }\n"
" MouseArea {\n"
" anchors.fill: parent\n"
" onClicked: {\n"
" Qt.quit();\n"
" }\n"
" }\n"
"}\n";
QmlJSCodeStylePreferencesFactory::QmlJSCodeStylePreferencesFactory() = default;
Utils::Id QmlJSCodeStylePreferencesFactory::languageId()
{
return Constants::QML_JS_SETTINGS_ID;
}
QString QmlJSCodeStylePreferencesFactory::displayName()
{
return Tr::tr("Qt Quick");
}
TextEditor::ICodeStylePreferences *QmlJSCodeStylePreferencesFactory::createCodeStyle() const
{
return new QmlJSCodeStylePreferences();
}
TextEditor::CodeStyleEditorWidget *QmlJSCodeStylePreferencesFactory::createEditor(
TextEditor::ICodeStylePreferences *preferences,
ProjectExplorer::Project *project,
QWidget *parent) const
{
Q_UNUSED(project)
auto qmlJSPreferences = qobject_cast<QmlJSCodeStylePreferences *>(preferences);
if (!qmlJSPreferences)
return nullptr;
auto widget = new Internal::QmlJSCodeStylePreferencesWidget(this, parent);
widget->setPreferences(qmlJSPreferences);
return widget;
}
TextEditor::Indenter *QmlJSCodeStylePreferencesFactory::createIndenter(QTextDocument *doc) const
{
return QmlJSEditor::createQmlJsIndenter(doc);
}
QString QmlJSCodeStylePreferencesFactory::snippetProviderGroupId() const
{
return QString(QmlJSEditor::Constants::QML_SNIPPETS_GROUP_ID);
}
QString QmlJSCodeStylePreferencesFactory::previewText() const
{
return QLatin1String(defaultPreviewText);
}