2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-07-06 10:38:53 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-07-06 10:38:53 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-07-06 10:38:53 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2011-07-06 10:38:53 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-07-06 10:38:53 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-07-06 10:38:53 +02:00
|
|
|
|
2011-08-16 10:45:23 +02:00
|
|
|
#include "cppcodestylepreferencesfactory.h"
|
2013-03-27 18:54:03 +01:00
|
|
|
|
2011-02-03 15:48:14 +01:00
|
|
|
#include "cppcodestylesettingspage.h"
|
|
|
|
|
#include "cppcodestylepreferences.h"
|
|
|
|
|
#include "cpptoolsconstants.h"
|
2011-08-05 09:59:28 +02:00
|
|
|
#include "cppqtstyleindenter.h"
|
2013-03-27 18:54:03 +01:00
|
|
|
|
2011-08-16 10:45:23 +02:00
|
|
|
#include <cppeditor/cppeditorconstants.h>
|
2013-03-27 18:54:03 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QLayout>
|
2011-02-03 15:48:14 +01:00
|
|
|
|
|
|
|
|
using namespace CppTools;
|
|
|
|
|
|
2011-08-16 10:45:23 +02:00
|
|
|
static const char *defaultPreviewText =
|
|
|
|
|
"#include <math.h>\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"class Complex\n"
|
|
|
|
|
" {\n"
|
|
|
|
|
"public:\n"
|
|
|
|
|
" Complex(double re, double im)\n"
|
|
|
|
|
" : _re(re), _im(im)\n"
|
|
|
|
|
" {}\n"
|
|
|
|
|
" double modulus() const\n"
|
|
|
|
|
" {\n"
|
|
|
|
|
" return sqrt(_re * _re + _im * _im);\n"
|
|
|
|
|
" }\n"
|
|
|
|
|
"private:\n"
|
|
|
|
|
" double _re;\n"
|
|
|
|
|
" double _im;\n"
|
|
|
|
|
" };\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"void bar(int i)\n"
|
|
|
|
|
" {\n"
|
|
|
|
|
" static int counter = 0;\n"
|
|
|
|
|
" counter += i;\n"
|
|
|
|
|
" }\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"namespace Foo\n"
|
|
|
|
|
" {\n"
|
|
|
|
|
" namespace Bar\n"
|
|
|
|
|
" {\n"
|
|
|
|
|
" void foo(int a, int b)\n"
|
|
|
|
|
" {\n"
|
|
|
|
|
" for (int i = 0; i < a; i++)\n"
|
|
|
|
|
" {\n"
|
|
|
|
|
" if (i < b)\n"
|
|
|
|
|
" bar(i);\n"
|
|
|
|
|
" else\n"
|
|
|
|
|
" {\n"
|
|
|
|
|
" bar(i);\n"
|
|
|
|
|
" bar(b);\n"
|
|
|
|
|
" }\n"
|
|
|
|
|
" }\n"
|
|
|
|
|
" }\n"
|
|
|
|
|
" } // namespace Bar\n"
|
|
|
|
|
" } // namespace Foo\n"
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
2019-01-14 01:40:53 +01:00
|
|
|
CppCodeStylePreferencesFactory::CppCodeStylePreferencesFactory() = default;
|
2011-02-03 15:48:14 +01:00
|
|
|
|
2012-11-21 21:47:17 +02:00
|
|
|
Core::Id CppCodeStylePreferencesFactory::languageId()
|
2011-02-03 15:48:14 +01:00
|
|
|
{
|
|
|
|
|
return Constants::CPP_SETTINGS_ID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CppCodeStylePreferencesFactory::displayName()
|
|
|
|
|
{
|
2012-11-21 22:36:47 +02:00
|
|
|
return QString::fromUtf8(Constants::CPP_SETTINGS_NAME);
|
2011-02-03 15:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
2011-08-16 10:45:23 +02:00
|
|
|
TextEditor::ICodeStylePreferences *CppCodeStylePreferencesFactory::createCodeStyle() const
|
2011-02-03 15:48:14 +01:00
|
|
|
{
|
2011-08-16 10:45:23 +02:00
|
|
|
return new CppCodeStylePreferences();
|
2011-02-03 15:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
2011-08-16 10:45:23 +02:00
|
|
|
QWidget *CppCodeStylePreferencesFactory::createEditor(TextEditor::ICodeStylePreferences *preferences,
|
2011-02-03 15:48:14 +01:00
|
|
|
QWidget *parent) const
|
|
|
|
|
{
|
2019-01-14 01:40:53 +01:00
|
|
|
auto cppPreferences = qobject_cast<CppCodeStylePreferences *>(preferences);
|
2011-02-03 15:48:14 +01:00
|
|
|
if (!cppPreferences)
|
2019-01-14 01:40:53 +01:00
|
|
|
return nullptr;
|
|
|
|
|
auto widget = new Internal::CppCodeStylePreferencesWidget(parent);
|
2011-02-03 15:48:14 +01:00
|
|
|
widget->layout()->setMargin(0);
|
2011-08-16 10:45:23 +02:00
|
|
|
widget->setCodeStyle(cppPreferences);
|
2011-02-03 15:48:14 +01:00
|
|
|
return widget;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-16 09:37:54 +01:00
|
|
|
TextEditor::Indenter *CppCodeStylePreferencesFactory::createIndenter(QTextDocument *doc) const
|
2011-08-05 09:59:28 +02:00
|
|
|
{
|
2019-01-16 09:37:54 +01:00
|
|
|
return new CppQtStyleIndenter(doc);
|
2011-08-05 09:59:28 +02:00
|
|
|
}
|
|
|
|
|
|
2018-02-06 15:59:05 +01:00
|
|
|
QString CppCodeStylePreferencesFactory::snippetProviderGroupId() const
|
2011-08-16 10:45:23 +02:00
|
|
|
{
|
2018-02-07 09:49:03 +01:00
|
|
|
return QString(CppEditor::Constants::CPP_SNIPPETS_GROUP_ID);
|
2011-08-16 10:45:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CppCodeStylePreferencesFactory::previewText() const
|
|
|
|
|
{
|
|
|
|
|
return QLatin1String(defaultPreviewText);
|
|
|
|
|
}
|
|
|
|
|
|