forked from qt-creator/qt-creator
CppCodeStyleSettingsPage: Use Layouting
Change-Id: Ied8991d32d5799af944c94a65ff3e85f3f454b26 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -28,7 +28,7 @@ add_qtc_plugin(CppEditor
|
||||
cppcodestylepreferences.cpp cppcodestylepreferences.h
|
||||
cppcodestylepreferencesfactory.cpp cppcodestylepreferencesfactory.h
|
||||
cppcodestylesettings.cpp cppcodestylesettings.h
|
||||
cppcodestylesettingspage.cpp cppcodestylesettingspage.h cppcodestylesettingspage.ui
|
||||
cppcodestylesettingspage.cpp cppcodestylesettingspage.h
|
||||
cppcodestylesnippets.h
|
||||
cppcompletionassist.cpp cppcompletionassist.h
|
||||
cppcompletionassistprocessor.cpp cppcompletionassistprocessor.h
|
||||
|
@@ -3,23 +3,26 @@
|
||||
|
||||
#include "cppcodestylesettingspage.h"
|
||||
|
||||
#include "cppcodeformatter.h"
|
||||
#include "cppcodestylepreferences.h"
|
||||
#include "cppcodestylesnippets.h"
|
||||
#include "cppeditorconstants.h"
|
||||
#include "cpppointerdeclarationformatter.h"
|
||||
#include "cppqtstyleindenter.h"
|
||||
#include "cpptoolssettings.h"
|
||||
#include <ui_cppcodestylesettingspage.h>
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <cppeditor/cppeditorconstants.h>
|
||||
#include <texteditor/codestyleeditor.h>
|
||||
#include <texteditor/displaysettings.h>
|
||||
#include <texteditor/fontsettings.h>
|
||||
#include <texteditor/icodestylepreferencesfactory.h>
|
||||
#include <texteditor/textdocument.h>
|
||||
#include <texteditor/displaysettings.h>
|
||||
#include <texteditor/snippets/snippetprovider.h>
|
||||
#include <texteditor/snippets/snippeteditor.h>
|
||||
#include <texteditor/tabsettings.h>
|
||||
#include <texteditor/tabsettingswidget.h>
|
||||
#include <texteditor/textdocument.h>
|
||||
#include <texteditor/texteditorsettings.h>
|
||||
#include <utils/layoutbuilder.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <cplusplus/Overview.h>
|
||||
@@ -27,8 +30,9 @@
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QTabWidget>
|
||||
#include <QTextBlock>
|
||||
#include <QTextStream>
|
||||
|
||||
using namespace TextEditor;
|
||||
|
||||
@@ -74,74 +78,263 @@ static void applyRefactorings(QTextDocument *textDocument, TextEditorWidget *edi
|
||||
|
||||
// ------------------ CppCodeStyleSettingsWidget
|
||||
|
||||
class CppCodeStylePreferencesWidgetPrivate
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(CppEditor::Internal::CppCodeStyleSettingsPage)
|
||||
|
||||
public:
|
||||
CppCodeStylePreferencesWidgetPrivate(CppCodeStylePreferencesWidget *widget)
|
||||
: q(widget)
|
||||
, m_indentAccessSpecifiers(createCheckBox(tr("\"public\", \"protected\" and\n"
|
||||
"\"private\" within class body")))
|
||||
, m_indentDeclarationsRelativeToAccessSpecifiers(
|
||||
createCheckBox(tr("Declarations relative to \"public\",\n"
|
||||
"\"protected\" and \"private\"")))
|
||||
, m_indentFunctionBody(createCheckBox(tr("Statements within function body")))
|
||||
, m_indentBlockBody(createCheckBox(tr("Statements within blocks")))
|
||||
, m_indentNamespaceBody(createCheckBox(tr("Declarations within\n"
|
||||
"\"namespace\" definition")))
|
||||
, m_indentClassBraces(createCheckBox(tr("Class declarations")))
|
||||
, m_indentNamespaceBraces(createCheckBox(tr("Namespace declarations")))
|
||||
, m_indentEnumBraces(createCheckBox(tr("Enum declarations")))
|
||||
, m_indentFunctionBraces(createCheckBox(tr("Function declarations")))
|
||||
, m_indentBlockBraces(createCheckBox(tr("Blocks")))
|
||||
, m_indentSwitchLabels(createCheckBox(tr("\"case\" or \"default\"")))
|
||||
, m_indentCaseStatements(createCheckBox(tr("Statements relative to\n"
|
||||
"\"case\" or \"default\"")))
|
||||
, m_indentCaseBlocks(createCheckBox(tr("Blocks relative to\n"
|
||||
"\"case\" or \"default\"")))
|
||||
, m_indentCaseBreak(createCheckBox(tr("\"break\" statement relative to\n"
|
||||
"\"case\" or \"default\"")))
|
||||
, m_alignAssignments(createCheckBox(tr("Align after assignments"),
|
||||
tr("<html><head/><body>\n"
|
||||
"Enables alignment to tokens after =, += etc. When the option is disabled, regular continuation line indentation will be used.<br>\n"
|
||||
"<br>\n"
|
||||
"With alignment:\n"
|
||||
"<pre>\n"
|
||||
"a = a +\n"
|
||||
" b\n"
|
||||
"</pre>\n"
|
||||
"Without alignment:\n"
|
||||
"<pre>\n"
|
||||
"a = a +\n"
|
||||
" b\n"
|
||||
"</pre>\n"
|
||||
"</body></html>")))
|
||||
, m_extraPaddingConditions(createCheckBox(tr("Add extra padding to conditions\n"
|
||||
"if they would align to the next line"),
|
||||
tr("<html><head/><body>\n"
|
||||
"Adds an extra level of indentation to multiline conditions in the switch, if, while and foreach statements if they would otherwise have the same or less indentation than a nested statement.\n"
|
||||
"\n"
|
||||
"For four-spaces indentation only if statement conditions are affected. Without extra padding:\n"
|
||||
"<pre>\n"
|
||||
"if (a &&\n"
|
||||
" b)\n"
|
||||
" c;\n"
|
||||
"</pre>\n"
|
||||
"With extra padding:\n"
|
||||
"<pre>\n"
|
||||
"if (a &&\n"
|
||||
" b)\n"
|
||||
" c;\n"
|
||||
"</pre>\n"
|
||||
"</body></html>")))
|
||||
, m_bindStarToIdentifier(createCheckBox(tr("Identifier"),
|
||||
tr("<html><head/><body>This does not apply to the star and reference symbol in pointer/reference to functions and arrays, e.g.:\n"
|
||||
"<pre> int (&rf)() = ...;\n"
|
||||
" int (*pf)() = ...;\n"
|
||||
"\n"
|
||||
" int (&ra)[2] = ...;\n"
|
||||
" int (*pa)[2] = ...;\n"
|
||||
"\n"
|
||||
"</pre></body></html>")))
|
||||
, m_bindStarToTypeName(createCheckBox(tr("Type name")))
|
||||
, m_bindStarToLeftSpecifier(createCheckBox(tr("Left const/volatile")))
|
||||
, m_bindStarToRightSpecifier(createCheckBox(tr("Right const/volatile"),
|
||||
tr("This does not apply to references.")))
|
||||
, m_categoryTab(new QTabWidget)
|
||||
, m_tabSettingsWidget(new TabSettingsWidget)
|
||||
{
|
||||
m_categoryTab->setProperty("_q_custom_style_disabled", true);
|
||||
|
||||
QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
sizePolicy.setHorizontalStretch(0);
|
||||
sizePolicy.setVerticalStretch(0);
|
||||
sizePolicy.setHeightForWidth(m_tabSettingsWidget->sizePolicy().hasHeightForWidth());
|
||||
m_tabSettingsWidget->setSizePolicy(sizePolicy);
|
||||
m_tabSettingsWidget->setFocusPolicy(Qt::TabFocus);
|
||||
QObject::connect(m_tabSettingsWidget, &TabSettingsWidget::settingsChanged,
|
||||
q, &CppCodeStylePreferencesWidget::slotTabSettingsChanged);
|
||||
|
||||
using namespace Utils::Layouting;
|
||||
|
||||
QWidget *generalTab = new QWidget;
|
||||
Row {
|
||||
Column {
|
||||
m_tabSettingsWidget,
|
||||
st
|
||||
},
|
||||
createPreview(0)
|
||||
}.attachTo(generalTab);
|
||||
m_categoryTab->addTab(generalTab, tr("General"));
|
||||
m_controllers.append(m_tabSettingsWidget);
|
||||
|
||||
QWidget *contentTab = new QWidget;
|
||||
Group contentGroup {
|
||||
title(tr("Indent")),
|
||||
Column {
|
||||
m_indentAccessSpecifiers,
|
||||
m_indentDeclarationsRelativeToAccessSpecifiers,
|
||||
m_indentFunctionBody,
|
||||
m_indentBlockBody,
|
||||
m_indentNamespaceBody,
|
||||
st
|
||||
}
|
||||
};
|
||||
Row {
|
||||
contentGroup,
|
||||
createPreview(1)
|
||||
}.attachTo(contentTab);
|
||||
m_categoryTab->addTab(contentTab, tr("Content"));
|
||||
m_controllers.append(contentGroup.widget);
|
||||
|
||||
QWidget *bracesTab = new QWidget;
|
||||
Group bracesGroup {
|
||||
title(tr("Indent Braces")),
|
||||
Column {
|
||||
m_indentClassBraces,
|
||||
m_indentNamespaceBraces,
|
||||
m_indentEnumBraces,
|
||||
m_indentFunctionBraces,
|
||||
m_indentBlockBraces,
|
||||
st
|
||||
}
|
||||
};
|
||||
Row {
|
||||
bracesGroup,
|
||||
createPreview(2)
|
||||
}.attachTo(bracesTab);
|
||||
m_categoryTab->addTab(bracesTab, tr("Braces"));
|
||||
m_controllers.append(bracesGroup.widget);
|
||||
|
||||
QWidget *switchTab = new QWidget;
|
||||
Group switchGroup {
|
||||
title(tr("Indent within \"switch\"")),
|
||||
Column {
|
||||
m_indentSwitchLabels,
|
||||
m_indentCaseStatements,
|
||||
m_indentCaseBlocks,
|
||||
m_indentCaseBreak,
|
||||
st
|
||||
}
|
||||
};
|
||||
Row {
|
||||
switchGroup,
|
||||
createPreview(3)
|
||||
}.attachTo(switchTab);
|
||||
m_categoryTab->addTab(switchTab, tr("\"switch\""));
|
||||
m_controllers.append(switchGroup.widget);
|
||||
|
||||
QWidget *alignmentTab = new QWidget;
|
||||
Group alignmentGroup {
|
||||
title(tr("Align")),
|
||||
Column {
|
||||
m_alignAssignments,
|
||||
m_extraPaddingConditions,
|
||||
st
|
||||
}
|
||||
};
|
||||
Row {
|
||||
alignmentGroup,
|
||||
createPreview(4)
|
||||
}.attachTo(alignmentTab);
|
||||
m_categoryTab->addTab(alignmentTab, tr("Alignment"));
|
||||
m_controllers.append(alignmentGroup.widget);
|
||||
|
||||
QWidget *typesTab = new QWidget;
|
||||
Group typesGroup {
|
||||
title(tr("Bind '*' and '&&' in types/declarations to")),
|
||||
Column {
|
||||
m_bindStarToIdentifier,
|
||||
m_bindStarToTypeName,
|
||||
m_bindStarToLeftSpecifier,
|
||||
m_bindStarToRightSpecifier,
|
||||
st
|
||||
}
|
||||
};
|
||||
Row {
|
||||
typesGroup,
|
||||
createPreview(5)
|
||||
}.attachTo(typesTab);
|
||||
m_categoryTab->addTab(typesTab, tr("Pointers and References"));
|
||||
m_controllers.append(typesGroup.widget);
|
||||
|
||||
Row { m_categoryTab }.attachTo(q);
|
||||
}
|
||||
|
||||
QCheckBox *createCheckBox(const QString &text, const QString &toolTip = {})
|
||||
{
|
||||
QCheckBox *checkBox = new QCheckBox(text);
|
||||
checkBox->setToolTip(toolTip);
|
||||
QObject::connect(checkBox, &QCheckBox::toggled,
|
||||
q, &CppCodeStylePreferencesWidget::slotCodeStyleSettingsChanged);
|
||||
return checkBox;
|
||||
}
|
||||
|
||||
SnippetEditorWidget *createPreview(int i)
|
||||
{
|
||||
SnippetEditorWidget *editor = new SnippetEditorWidget;
|
||||
editor->setPlainText(QLatin1String(Constants::DEFAULT_CODE_STYLE_SNIPPETS[i]));
|
||||
m_previews.append(editor);
|
||||
return editor;
|
||||
}
|
||||
|
||||
CppCodeStylePreferencesWidget *q = nullptr;
|
||||
|
||||
QCheckBox *m_indentAccessSpecifiers = nullptr;
|
||||
QCheckBox *m_indentDeclarationsRelativeToAccessSpecifiers = nullptr;
|
||||
QCheckBox *m_indentFunctionBody = nullptr;
|
||||
QCheckBox *m_indentBlockBody = nullptr;
|
||||
QCheckBox *m_indentNamespaceBody = nullptr;
|
||||
QCheckBox *m_indentClassBraces = nullptr;
|
||||
QCheckBox *m_indentNamespaceBraces = nullptr;
|
||||
QCheckBox *m_indentEnumBraces = nullptr;
|
||||
QCheckBox *m_indentFunctionBraces = nullptr;
|
||||
QCheckBox *m_indentBlockBraces = nullptr;
|
||||
QCheckBox *m_indentSwitchLabels = nullptr;
|
||||
QCheckBox *m_indentCaseStatements = nullptr;
|
||||
QCheckBox *m_indentCaseBlocks = nullptr;
|
||||
QCheckBox *m_indentCaseBreak = nullptr;
|
||||
QCheckBox *m_alignAssignments = nullptr;
|
||||
QCheckBox *m_extraPaddingConditions = nullptr;
|
||||
QCheckBox *m_bindStarToIdentifier = nullptr;
|
||||
QCheckBox *m_bindStarToTypeName = nullptr;
|
||||
QCheckBox *m_bindStarToLeftSpecifier = nullptr;
|
||||
QCheckBox *m_bindStarToRightSpecifier = nullptr;
|
||||
|
||||
QList<SnippetEditorWidget *> m_previews;
|
||||
QList<QWidget *> m_controllers;
|
||||
|
||||
QTabWidget *m_categoryTab = nullptr;
|
||||
TabSettingsWidget *m_tabSettingsWidget = nullptr;
|
||||
};
|
||||
|
||||
CppCodeStylePreferencesWidget::CppCodeStylePreferencesWidget(QWidget *parent)
|
||||
: TextEditor::CodeStyleEditorWidget(parent),
|
||||
m_ui(new Ui::CppCodeStyleSettingsPage)
|
||||
d(new CppCodeStylePreferencesWidgetPrivate(this))
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
m_ui->categoryTab->setProperty("_q_custom_style_disabled", true);
|
||||
|
||||
m_previews << m_ui->previewTextEditGeneral << m_ui->previewTextEditContent
|
||||
<< m_ui->previewTextEditBraces << m_ui->previewTextEditSwitch
|
||||
<< m_ui->previewTextEditPadding << m_ui->previewTextEditPointerReferences;
|
||||
for (int i = 0; i < m_previews.size(); ++i)
|
||||
m_previews[i]->setPlainText(QLatin1String(Constants::DEFAULT_CODE_STYLE_SNIPPETS[i]));
|
||||
|
||||
decorateEditors(TextEditorSettings::fontSettings());
|
||||
connect(TextEditorSettings::instance(), &TextEditorSettings::fontSettingsChanged,
|
||||
this, &CppCodeStylePreferencesWidget::decorateEditors);
|
||||
|
||||
setVisualizeWhitespace(true);
|
||||
|
||||
connect(m_ui->tabSettingsWidget, &TabSettingsWidget::settingsChanged,
|
||||
this, &CppCodeStylePreferencesWidget::slotTabSettingsChanged);
|
||||
connect(m_ui->indentBlockBraces, &QCheckBox::toggled,
|
||||
this, &CppCodeStylePreferencesWidget::slotCodeStyleSettingsChanged);
|
||||
connect(m_ui->indentBlockBody, &QCheckBox::toggled,
|
||||
this, &CppCodeStylePreferencesWidget::slotCodeStyleSettingsChanged);
|
||||
connect(m_ui->indentClassBraces, &QCheckBox::toggled,
|
||||
this, &CppCodeStylePreferencesWidget::slotCodeStyleSettingsChanged);
|
||||
connect(m_ui->indentNamespaceBraces, &QCheckBox::toggled,
|
||||
this, &CppCodeStylePreferencesWidget::slotCodeStyleSettingsChanged);
|
||||
connect(m_ui->indentEnumBraces, &QCheckBox::toggled,
|
||||
this, &CppCodeStylePreferencesWidget::slotCodeStyleSettingsChanged);
|
||||
connect(m_ui->indentNamespaceBody, &QCheckBox::toggled,
|
||||
this, &CppCodeStylePreferencesWidget::slotCodeStyleSettingsChanged);
|
||||
connect(m_ui->indentSwitchLabels, &QCheckBox::toggled,
|
||||
this, &CppCodeStylePreferencesWidget::slotCodeStyleSettingsChanged);
|
||||
connect(m_ui->indentCaseStatements, &QCheckBox::toggled,
|
||||
this, &CppCodeStylePreferencesWidget::slotCodeStyleSettingsChanged);
|
||||
connect(m_ui->indentCaseBlocks, &QCheckBox::toggled,
|
||||
this, &CppCodeStylePreferencesWidget::slotCodeStyleSettingsChanged);
|
||||
connect(m_ui->indentCaseBreak, &QCheckBox::toggled,
|
||||
this, &CppCodeStylePreferencesWidget::slotCodeStyleSettingsChanged);
|
||||
connect(m_ui->indentAccessSpecifiers, &QCheckBox::toggled,
|
||||
this, &CppCodeStylePreferencesWidget::slotCodeStyleSettingsChanged);
|
||||
connect(m_ui->indentDeclarationsRelativeToAccessSpecifiers, &QCheckBox::toggled,
|
||||
this, &CppCodeStylePreferencesWidget::slotCodeStyleSettingsChanged);
|
||||
connect(m_ui->indentFunctionBody, &QCheckBox::toggled,
|
||||
this, &CppCodeStylePreferencesWidget::slotCodeStyleSettingsChanged);
|
||||
connect(m_ui->indentFunctionBraces, &QCheckBox::toggled,
|
||||
this, &CppCodeStylePreferencesWidget::slotCodeStyleSettingsChanged);
|
||||
connect(m_ui->extraPaddingConditions, &QCheckBox::toggled,
|
||||
this, &CppCodeStylePreferencesWidget::slotCodeStyleSettingsChanged);
|
||||
connect(m_ui->alignAssignments, &QCheckBox::toggled,
|
||||
this, &CppCodeStylePreferencesWidget::slotCodeStyleSettingsChanged);
|
||||
connect(m_ui->bindStarToIdentifier, &QCheckBox::toggled,
|
||||
this, &CppCodeStylePreferencesWidget::slotCodeStyleSettingsChanged);
|
||||
connect(m_ui->bindStarToTypeName, &QCheckBox::toggled,
|
||||
this, &CppCodeStylePreferencesWidget::slotCodeStyleSettingsChanged);
|
||||
connect(m_ui->bindStarToLeftSpecifier, &QCheckBox::toggled,
|
||||
this, &CppCodeStylePreferencesWidget::slotCodeStyleSettingsChanged);
|
||||
connect(m_ui->bindStarToRightSpecifier, &QCheckBox::toggled,
|
||||
this, &CppCodeStylePreferencesWidget::slotCodeStyleSettingsChanged);
|
||||
|
||||
m_ui->categoryTab->setCurrentIndex(0);
|
||||
// m_ui->categoryTab->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
CppCodeStylePreferencesWidget::~CppCodeStylePreferencesWidget()
|
||||
{
|
||||
delete m_ui;
|
||||
delete d;
|
||||
}
|
||||
|
||||
void CppCodeStylePreferencesWidget::setCodeStyle(CppCodeStylePreferences *codeStylePreferences)
|
||||
@@ -172,64 +365,64 @@ CppCodeStyleSettings CppCodeStylePreferencesWidget::cppCodeStyleSettings() const
|
||||
{
|
||||
CppCodeStyleSettings set;
|
||||
|
||||
set.indentBlockBraces = m_ui->indentBlockBraces->isChecked();
|
||||
set.indentBlockBody = m_ui->indentBlockBody->isChecked();
|
||||
set.indentClassBraces = m_ui->indentClassBraces->isChecked();
|
||||
set.indentEnumBraces = m_ui->indentEnumBraces->isChecked();
|
||||
set.indentNamespaceBraces = m_ui->indentNamespaceBraces->isChecked();
|
||||
set.indentNamespaceBody = m_ui->indentNamespaceBody->isChecked();
|
||||
set.indentAccessSpecifiers = m_ui->indentAccessSpecifiers->isChecked();
|
||||
set.indentDeclarationsRelativeToAccessSpecifiers = m_ui->indentDeclarationsRelativeToAccessSpecifiers->isChecked();
|
||||
set.indentFunctionBody = m_ui->indentFunctionBody->isChecked();
|
||||
set.indentFunctionBraces = m_ui->indentFunctionBraces->isChecked();
|
||||
set.indentSwitchLabels = m_ui->indentSwitchLabels->isChecked();
|
||||
set.indentStatementsRelativeToSwitchLabels = m_ui->indentCaseStatements->isChecked();
|
||||
set.indentBlocksRelativeToSwitchLabels = m_ui->indentCaseBlocks->isChecked();
|
||||
set.indentControlFlowRelativeToSwitchLabels = m_ui->indentCaseBreak->isChecked();
|
||||
set.bindStarToIdentifier = m_ui->bindStarToIdentifier->isChecked();
|
||||
set.bindStarToTypeName = m_ui->bindStarToTypeName->isChecked();
|
||||
set.bindStarToLeftSpecifier = m_ui->bindStarToLeftSpecifier->isChecked();
|
||||
set.bindStarToRightSpecifier = m_ui->bindStarToRightSpecifier->isChecked();
|
||||
set.extraPaddingForConditionsIfConfusingAlign = m_ui->extraPaddingConditions->isChecked();
|
||||
set.alignAssignments = m_ui->alignAssignments->isChecked();
|
||||
set.indentBlockBraces = d->m_indentBlockBraces->isChecked();
|
||||
set.indentBlockBody = d->m_indentBlockBody->isChecked();
|
||||
set.indentClassBraces = d->m_indentClassBraces->isChecked();
|
||||
set.indentEnumBraces = d->m_indentEnumBraces->isChecked();
|
||||
set.indentNamespaceBraces = d->m_indentNamespaceBraces->isChecked();
|
||||
set.indentNamespaceBody = d->m_indentNamespaceBody->isChecked();
|
||||
set.indentAccessSpecifiers = d->m_indentAccessSpecifiers->isChecked();
|
||||
set.indentDeclarationsRelativeToAccessSpecifiers = d->m_indentDeclarationsRelativeToAccessSpecifiers->isChecked();
|
||||
set.indentFunctionBody = d->m_indentFunctionBody->isChecked();
|
||||
set.indentFunctionBraces = d->m_indentFunctionBraces->isChecked();
|
||||
set.indentSwitchLabels = d->m_indentSwitchLabels->isChecked();
|
||||
set.indentStatementsRelativeToSwitchLabels = d->m_indentCaseStatements->isChecked();
|
||||
set.indentBlocksRelativeToSwitchLabels = d->m_indentCaseBlocks->isChecked();
|
||||
set.indentControlFlowRelativeToSwitchLabels = d->m_indentCaseBreak->isChecked();
|
||||
set.bindStarToIdentifier = d->m_bindStarToIdentifier->isChecked();
|
||||
set.bindStarToTypeName = d->m_bindStarToTypeName->isChecked();
|
||||
set.bindStarToLeftSpecifier = d->m_bindStarToLeftSpecifier->isChecked();
|
||||
set.bindStarToRightSpecifier = d->m_bindStarToRightSpecifier->isChecked();
|
||||
set.extraPaddingForConditionsIfConfusingAlign = d->m_extraPaddingConditions->isChecked();
|
||||
set.alignAssignments = d->m_alignAssignments->isChecked();
|
||||
|
||||
return set;
|
||||
}
|
||||
|
||||
void CppCodeStylePreferencesWidget::setTabSettings(const TabSettings &settings)
|
||||
{
|
||||
m_ui->tabSettingsWidget->setTabSettings(settings);
|
||||
d->m_tabSettingsWidget->setTabSettings(settings);
|
||||
}
|
||||
|
||||
TextEditor::TabSettings CppCodeStylePreferencesWidget::tabSettings() const
|
||||
{
|
||||
return m_ui->tabSettingsWidget->tabSettings();
|
||||
return d->m_tabSettingsWidget->tabSettings();
|
||||
}
|
||||
|
||||
void CppCodeStylePreferencesWidget::setCodeStyleSettings(const CppCodeStyleSettings &s, bool preview)
|
||||
{
|
||||
const bool wasBlocked = m_blockUpdates;
|
||||
m_blockUpdates = true;
|
||||
m_ui->indentBlockBraces->setChecked(s.indentBlockBraces);
|
||||
m_ui->indentBlockBody->setChecked(s.indentBlockBody);
|
||||
m_ui->indentClassBraces->setChecked(s.indentClassBraces);
|
||||
m_ui->indentEnumBraces->setChecked(s.indentEnumBraces);
|
||||
m_ui->indentNamespaceBraces->setChecked(s.indentNamespaceBraces);
|
||||
m_ui->indentNamespaceBody->setChecked(s.indentNamespaceBody);
|
||||
m_ui->indentAccessSpecifiers->setChecked(s.indentAccessSpecifiers);
|
||||
m_ui->indentDeclarationsRelativeToAccessSpecifiers->setChecked(s.indentDeclarationsRelativeToAccessSpecifiers);
|
||||
m_ui->indentFunctionBody->setChecked(s.indentFunctionBody);
|
||||
m_ui->indentFunctionBraces->setChecked(s.indentFunctionBraces);
|
||||
m_ui->indentSwitchLabels->setChecked(s.indentSwitchLabels);
|
||||
m_ui->indentCaseStatements->setChecked(s.indentStatementsRelativeToSwitchLabels);
|
||||
m_ui->indentCaseBlocks->setChecked(s.indentBlocksRelativeToSwitchLabels);
|
||||
m_ui->indentCaseBreak->setChecked(s.indentControlFlowRelativeToSwitchLabels);
|
||||
m_ui->bindStarToIdentifier->setChecked(s.bindStarToIdentifier);
|
||||
m_ui->bindStarToTypeName->setChecked(s.bindStarToTypeName);
|
||||
m_ui->bindStarToLeftSpecifier->setChecked(s.bindStarToLeftSpecifier);
|
||||
m_ui->bindStarToRightSpecifier->setChecked(s.bindStarToRightSpecifier);
|
||||
m_ui->extraPaddingConditions->setChecked(s.extraPaddingForConditionsIfConfusingAlign);
|
||||
m_ui->alignAssignments->setChecked(s.alignAssignments);
|
||||
d->m_indentBlockBraces->setChecked(s.indentBlockBraces);
|
||||
d->m_indentBlockBody->setChecked(s.indentBlockBody);
|
||||
d->m_indentClassBraces->setChecked(s.indentClassBraces);
|
||||
d->m_indentEnumBraces->setChecked(s.indentEnumBraces);
|
||||
d->m_indentNamespaceBraces->setChecked(s.indentNamespaceBraces);
|
||||
d->m_indentNamespaceBody->setChecked(s.indentNamespaceBody);
|
||||
d->m_indentAccessSpecifiers->setChecked(s.indentAccessSpecifiers);
|
||||
d->m_indentDeclarationsRelativeToAccessSpecifiers->setChecked(s.indentDeclarationsRelativeToAccessSpecifiers);
|
||||
d->m_indentFunctionBody->setChecked(s.indentFunctionBody);
|
||||
d->m_indentFunctionBraces->setChecked(s.indentFunctionBraces);
|
||||
d->m_indentSwitchLabels->setChecked(s.indentSwitchLabels);
|
||||
d->m_indentCaseStatements->setChecked(s.indentStatementsRelativeToSwitchLabels);
|
||||
d->m_indentCaseBlocks->setChecked(s.indentBlocksRelativeToSwitchLabels);
|
||||
d->m_indentCaseBreak->setChecked(s.indentControlFlowRelativeToSwitchLabels);
|
||||
d->m_bindStarToIdentifier->setChecked(s.bindStarToIdentifier);
|
||||
d->m_bindStarToTypeName->setChecked(s.bindStarToTypeName);
|
||||
d->m_bindStarToLeftSpecifier->setChecked(s.bindStarToLeftSpecifier);
|
||||
d->m_bindStarToRightSpecifier->setChecked(s.bindStarToRightSpecifier);
|
||||
d->m_extraPaddingConditions->setChecked(s.extraPaddingForConditionsIfConfusingAlign);
|
||||
d->m_alignAssignments->setChecked(s.alignAssignments);
|
||||
m_blockUpdates = wasBlocked;
|
||||
if (preview)
|
||||
updatePreview();
|
||||
@@ -238,12 +431,9 @@ void CppCodeStylePreferencesWidget::setCodeStyleSettings(const CppCodeStyleSetti
|
||||
void CppCodeStylePreferencesWidget::slotCurrentPreferencesChanged(ICodeStylePreferences *preferences, bool preview)
|
||||
{
|
||||
const bool enable = !preferences->isReadOnly();
|
||||
m_ui->tabSettingsWidget->setEnabled(enable);
|
||||
m_ui->contentGroupBox->setEnabled(enable);
|
||||
m_ui->bracesGroupBox->setEnabled(enable);
|
||||
m_ui->switchGroupBox->setEnabled(enable);
|
||||
m_ui->alignmentGroupBox->setEnabled(enable);
|
||||
m_ui->pointerReferencesGroupBox->setEnabled(enable);
|
||||
for (QWidget *widget : d->m_controllers)
|
||||
widget->setEnabled(enable);
|
||||
|
||||
if (preview)
|
||||
updatePreview();
|
||||
}
|
||||
@@ -285,7 +475,7 @@ void CppCodeStylePreferencesWidget::updatePreview()
|
||||
const CppCodeStyleSettings ccss = cppCodeStylePreferences->currentCodeStyleSettings();
|
||||
const TabSettings ts = cppCodeStylePreferences->currentTabSettings();
|
||||
QtStyleCodeFormatter formatter(ts, ccss);
|
||||
for (SnippetEditorWidget *preview : std::as_const(m_previews)) {
|
||||
for (SnippetEditorWidget *preview : std::as_const(d->m_previews)) {
|
||||
preview->textDocument()->setTabSettings(ts);
|
||||
preview->setCodeStyle(cppCodeStylePreferences);
|
||||
|
||||
@@ -307,7 +497,7 @@ void CppCodeStylePreferencesWidget::updatePreview()
|
||||
|
||||
void CppCodeStylePreferencesWidget::decorateEditors(const FontSettings &fontSettings)
|
||||
{
|
||||
for (SnippetEditorWidget *editor : std::as_const(m_previews)) {
|
||||
for (SnippetEditorWidget *editor : std::as_const(d->m_previews)) {
|
||||
editor->textDocument()->setFontSettings(fontSettings);
|
||||
SnippetProvider::decorateEditor(editor, CppEditor::Constants::CPP_SNIPPETS_GROUP_ID);
|
||||
}
|
||||
@@ -315,7 +505,7 @@ void CppCodeStylePreferencesWidget::decorateEditors(const FontSettings &fontSett
|
||||
|
||||
void CppCodeStylePreferencesWidget::setVisualizeWhitespace(bool on)
|
||||
{
|
||||
for (SnippetEditorWidget *editor : std::as_const(m_previews)) {
|
||||
for (SnippetEditorWidget *editor : std::as_const(d->m_previews)) {
|
||||
DisplaySettings displaySettings = editor->displaySettings();
|
||||
displaySettings.m_visualizeWhitespace = on;
|
||||
editor->setDisplaySettings(displaySettings);
|
||||
@@ -327,8 +517,8 @@ void CppCodeStylePreferencesWidget::addTab(CppCodeStyleWidget *page, QString tab
|
||||
if (!page)
|
||||
return;
|
||||
|
||||
m_ui->categoryTab->insertTab(0, page, tabName);
|
||||
m_ui->categoryTab->setCurrentIndex(0);
|
||||
d->m_categoryTab->insertTab(0, page, tabName);
|
||||
d->m_categoryTab->setCurrentIndex(0);
|
||||
|
||||
connect(page, &CppEditor::CppCodeStyleWidget::codeStyleSettingsChanged,
|
||||
this, [this](const CppEditor::CppCodeStyleSettings &settings) {
|
||||
|
@@ -4,7 +4,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "cppcodestylesettings.h"
|
||||
#include "cppcodeformatter.h"
|
||||
|
||||
#include <coreplugin/dialogs/ioptionspage.h>
|
||||
#include <texteditor/icodestylepreferencesfactory.h>
|
||||
@@ -42,7 +41,7 @@ signals:
|
||||
|
||||
namespace Internal {
|
||||
|
||||
namespace Ui { class CppCodeStyleSettingsPage; }
|
||||
class CppCodeStylePreferencesWidgetPrivate;
|
||||
|
||||
class CppCodeStylePreferencesWidget : public TextEditor::CodeStyleEditorWidget
|
||||
{
|
||||
@@ -70,9 +69,9 @@ private:
|
||||
CppCodeStyleSettings cppCodeStyleSettings() const;
|
||||
|
||||
CppCodeStylePreferences *m_preferences = nullptr;
|
||||
Ui::CppCodeStyleSettingsPage *m_ui;
|
||||
QList<TextEditor::SnippetEditorWidget *> m_previews;
|
||||
CppCodeStylePreferencesWidgetPrivate *d = nullptr;
|
||||
bool m_blockUpdates = false;
|
||||
friend class CppCodeStylePreferencesWidgetPrivate;
|
||||
signals:
|
||||
void codeStyleSettingsChanged(const CppEditor::CppCodeStyleSettings &);
|
||||
void tabSettingsChanged(const TextEditor::TabSettings &);
|
||||
|
@@ -1,455 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CppEditor::Internal::CppCodeStyleSettingsPage</class>
|
||||
<widget class="QWidget" name="CppEditor::Internal::CppCodeStyleSettingsPage">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>463</width>
|
||||
<height>317</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QTabWidget" name="categoryTab">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="generalTab">
|
||||
<attribute name="title">
|
||||
<string>General</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="TextEditor::TabSettingsWidget" name="tabSettingsWidget" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::TabFocus</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" rowspan="2">
|
||||
<widget class="TextEditor::SnippetEditorWidget" name="previewTextEditGeneral">
|
||||
<property name="plainText">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<spacer name="verticalSpacer_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>347</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="contentTab">
|
||||
<attribute name="title">
|
||||
<string>Content</string>
|
||||
</attribute>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="contentGroupBox">
|
||||
<property name="title">
|
||||
<string>Indent</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="indentAccessSpecifiers">
|
||||
<property name="text">
|
||||
<string>"public", "protected" and
|
||||
"private" within class body</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="indentDeclarationsRelativeToAccessSpecifiers">
|
||||
<property name="text">
|
||||
<string>Declarations relative to "public",
|
||||
"protected" and "private"</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="indentFunctionBody">
|
||||
<property name="text">
|
||||
<string>Statements within function body</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="indentBlockBody">
|
||||
<property name="text">
|
||||
<string>Statements within blocks</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="indentNamespaceBody">
|
||||
<property name="text">
|
||||
<string>Declarations within
|
||||
"namespace" definition</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>17</width>
|
||||
<height>114</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="TextEditor::SnippetEditorWidget" name="previewTextEditContent">
|
||||
<property name="plainText">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="bracesTab">
|
||||
<attribute name="title">
|
||||
<string>Braces</string>
|
||||
</attribute>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="bracesGroupBox">
|
||||
<property name="title">
|
||||
<string>Indent Braces</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="indentClassBraces">
|
||||
<property name="text">
|
||||
<string>Class declarations</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="indentNamespaceBraces">
|
||||
<property name="text">
|
||||
<string>Namespace declarations</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="indentEnumBraces">
|
||||
<property name="text">
|
||||
<string>Enum declarations</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="indentFunctionBraces">
|
||||
<property name="text">
|
||||
<string>Function declarations</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="indentBlockBraces">
|
||||
<property name="text">
|
||||
<string>Blocks</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>195</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="TextEditor::SnippetEditorWidget" name="previewTextEditBraces">
|
||||
<property name="plainText">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="switchTab">
|
||||
<attribute name="title">
|
||||
<string>"switch"</string>
|
||||
</attribute>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="switchGroupBox">
|
||||
<property name="title">
|
||||
<string>Indent within "switch"</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="indentSwitchLabels">
|
||||
<property name="text">
|
||||
<string>"case" or "default"</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="indentCaseStatements">
|
||||
<property name="text">
|
||||
<string>Statements relative to
|
||||
"case" or "default"</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="indentCaseBlocks">
|
||||
<property name="text">
|
||||
<string>Blocks relative to
|
||||
"case" or "default"</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="indentCaseBreak">
|
||||
<property name="text">
|
||||
<string>"break" statement relative to
|
||||
"case" or "default"</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>143</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="TextEditor::SnippetEditorWidget" name="previewTextEditSwitch">
|
||||
<property name="plainText">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="alignmentTab">
|
||||
<attribute name="title">
|
||||
<string>Alignment</string>
|
||||
</attribute>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="alignmentGroupBox">
|
||||
<property name="title">
|
||||
<string>Align</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="alignAssignments">
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body>
|
||||
Enables alignment to tokens after =, += etc. When the option is disabled, regular continuation line indentation will be used.<br>
|
||||
<br>
|
||||
With alignment:
|
||||
<pre>
|
||||
a = a +
|
||||
b
|
||||
</pre>
|
||||
Without alignment:
|
||||
<pre>
|
||||
a = a +
|
||||
b
|
||||
</pre>
|
||||
</body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Align after assignments</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="extraPaddingConditions">
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body>
|
||||
Adds an extra level of indentation to multiline conditions in the switch, if, while and foreach statements if they would otherwise have the same or less indentation than a nested statement.
|
||||
|
||||
For four-spaces indentation only if statement conditions are affected. Without extra padding:
|
||||
<pre>
|
||||
if (a &&
|
||||
b)
|
||||
c;
|
||||
</pre>
|
||||
With extra padding:
|
||||
<pre>
|
||||
if (a &&
|
||||
b)
|
||||
c;
|
||||
</pre>
|
||||
</body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Add extra padding to conditions
|
||||
if they would align to the next line</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="TextEditor::SnippetEditorWidget" name="previewTextEditPadding">
|
||||
<property name="plainText">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="typesTab">
|
||||
<attribute name="title">
|
||||
<string>Pointers and References</string>
|
||||
</attribute>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="pointerReferencesGroupBox">
|
||||
<property name="title">
|
||||
<string>Bind '*' and '&&' in types/declarations to</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="bindStarToIdentifier">
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body>This does not apply to the star and reference symbol in pointer/reference to functions and arrays, e.g.:
|
||||
<pre> int (&rf)() = ...;
|
||||
int (*pf)() = ...;
|
||||
|
||||
int (&ra)[2] = ...;
|
||||
int (*pa)[2] = ...;
|
||||
|
||||
</pre></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Identifier</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="bindStarToTypeName">
|
||||
<property name="text">
|
||||
<string>Type name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="bindStarToLeftSpecifier">
|
||||
<property name="text">
|
||||
<string>Left const/volatile</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="bindStarToRightSpecifier">
|
||||
<property name="toolTip">
|
||||
<string>This does not apply to references.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Right const/volatile</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_6">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="TextEditor::SnippetEditorWidget" name="previewTextEditPointerReferences">
|
||||
<property name="plainText">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>TextEditor::TabSettingsWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header location="global">texteditor/tabsettingswidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>TextEditor::SnippetEditorWidget</class>
|
||||
<extends>QPlainTextEdit</extends>
|
||||
<header location="global">texteditor/snippets/snippeteditor.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@@ -6,169 +6,175 @@
|
||||
namespace CppEditor {
|
||||
namespace Constants {
|
||||
|
||||
static const char *DEFAULT_CODE_STYLE_SNIPPETS[]
|
||||
= {"#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",
|
||||
"#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",
|
||||
"namespace Foo\n"
|
||||
"{\n"
|
||||
"namespace Bar\n"
|
||||
"{\n"
|
||||
"class FooBar\n"
|
||||
" {\n"
|
||||
"public:\n"
|
||||
" FooBar(int a)\n"
|
||||
" : _a(a)\n"
|
||||
" {}\n"
|
||||
" int calculate() const\n"
|
||||
" {\n"
|
||||
" if (a > 10)\n"
|
||||
" {\n"
|
||||
" int b = 2 * a;\n"
|
||||
" return a * b;\n"
|
||||
" }\n"
|
||||
" return -a;\n"
|
||||
" }\n"
|
||||
"private:\n"
|
||||
" int _a;\n"
|
||||
" };\n"
|
||||
"enum class E\n"
|
||||
"{\n"
|
||||
" V1,\n"
|
||||
" V2,\n"
|
||||
" V3\n"
|
||||
"};\n"
|
||||
"}\n"
|
||||
"}\n",
|
||||
"#include \"bar.h\"\n"
|
||||
"\n"
|
||||
"int foo(int a)\n"
|
||||
" {\n"
|
||||
" switch (a)\n"
|
||||
" {\n"
|
||||
" case 1:\n"
|
||||
" bar(1);\n"
|
||||
" break;\n"
|
||||
" case 2:\n"
|
||||
" {\n"
|
||||
" bar(2);\n"
|
||||
" break;\n"
|
||||
" }\n"
|
||||
" case 3:\n"
|
||||
" default:\n"
|
||||
" bar(3);\n"
|
||||
" break;\n"
|
||||
" }\n"
|
||||
" return 0;\n"
|
||||
" }\n",
|
||||
"void foo() {\n"
|
||||
" if (a &&\n"
|
||||
" b)\n"
|
||||
" c;\n"
|
||||
"\n"
|
||||
" while (a ||\n"
|
||||
" b)\n"
|
||||
" break;\n"
|
||||
" a = b +\n"
|
||||
" c;\n"
|
||||
" myInstance.longMemberName +=\n"
|
||||
" foo;\n"
|
||||
" myInstance.longMemberName += bar +\n"
|
||||
" foo;\n"
|
||||
"}\n",
|
||||
"int *foo(const Bar &b1, Bar &&b2, int*, int *&rpi)\n"
|
||||
"{\n"
|
||||
" int*pi = 0;\n"
|
||||
" int*const*const cpcpi = π\n"
|
||||
" int*const*pcpi = π\n"
|
||||
" int**const cppi = π\n"
|
||||
"\n"
|
||||
" void (*foo)(char *s) = 0;\n"
|
||||
" int (*bar)[] = 0;\n"
|
||||
"\n"
|
||||
" return pi;\n"
|
||||
"}\n"};
|
||||
static const char *DEFAULT_CODE_STYLE_SNIPPETS[] = {
|
||||
R"==(#include <math.h>
|
||||
|
||||
class Complex
|
||||
{
|
||||
public:
|
||||
Complex(double re, double im)
|
||||
: _re(re), _im(im)
|
||||
{}
|
||||
double modulus() const
|
||||
{
|
||||
return sqrt(_re * _re + _im * _im);
|
||||
}
|
||||
private:
|
||||
double _re;
|
||||
double _im;
|
||||
};
|
||||
|
||||
void bar(int i)
|
||||
{
|
||||
static int counter = 0;
|
||||
counter += i;
|
||||
}
|
||||
|
||||
namespace Foo
|
||||
{
|
||||
namespace Bar
|
||||
{
|
||||
void foo(int a, int b)
|
||||
{
|
||||
for (int i = 0; i < a; i++)
|
||||
{
|
||||
if (i < b)
|
||||
bar(i);
|
||||
else
|
||||
{
|
||||
bar(i);
|
||||
bar(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace Bar
|
||||
} // namespace Foo
|
||||
)==",
|
||||
R"==(#include <math.h>
|
||||
|
||||
class Complex
|
||||
{
|
||||
public:
|
||||
Complex(double re, double im)
|
||||
: _re(re), _im(im)
|
||||
{}
|
||||
double modulus() const
|
||||
{
|
||||
return sqrt(_re * _re + _im * _im);
|
||||
}
|
||||
private:
|
||||
double _re;
|
||||
double _im;
|
||||
};
|
||||
|
||||
void bar(int i)
|
||||
{
|
||||
static int counter = 0;
|
||||
counter += i;
|
||||
}
|
||||
|
||||
namespace Foo
|
||||
{
|
||||
namespace Bar
|
||||
{
|
||||
void foo(int a, int b)
|
||||
{
|
||||
for (int i = 0; i < a; i++)
|
||||
{
|
||||
if (i < b)
|
||||
bar(i);
|
||||
else
|
||||
{
|
||||
bar(i);
|
||||
bar(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace Bar
|
||||
} // namespace Foo
|
||||
)==",
|
||||
R"==(namespace Foo
|
||||
{
|
||||
namespace Bar
|
||||
{
|
||||
class FooBar
|
||||
{
|
||||
public:
|
||||
FooBar(int a)
|
||||
: _a(a)
|
||||
{}
|
||||
int calculate() const
|
||||
{
|
||||
if (a > 10)
|
||||
{
|
||||
int b = 2 * a;
|
||||
return a * b;
|
||||
}
|
||||
return -a;
|
||||
}
|
||||
private:
|
||||
int _a;
|
||||
};
|
||||
enum class E
|
||||
{
|
||||
V1,
|
||||
V2,
|
||||
V3
|
||||
};
|
||||
}
|
||||
}
|
||||
)==",
|
||||
R"==(#include "bar.h"
|
||||
|
||||
int foo(int a)
|
||||
{
|
||||
switch (a)
|
||||
{
|
||||
case 1:
|
||||
bar(1);
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
bar(2);
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
default:
|
||||
bar(3);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
)==",
|
||||
R"==(void foo() {
|
||||
if (a &&
|
||||
b)
|
||||
c;
|
||||
|
||||
while (a ||
|
||||
b)
|
||||
break;
|
||||
a = b +
|
||||
c;
|
||||
myInstance.longMemberName +=
|
||||
foo;
|
||||
myInstance.longMemberName += bar +
|
||||
foo;
|
||||
}
|
||||
)==",
|
||||
R"==(int *foo(const Bar &b1, Bar &&b2, int*, int *&rpi)
|
||||
{
|
||||
int*pi = 0;
|
||||
int*const*const cpcpi = π
|
||||
int*const*pcpi = π
|
||||
int**const cppi = π
|
||||
|
||||
void (*foo)(char *s) = 0;
|
||||
int (*bar)[] = 0;
|
||||
|
||||
return pi;
|
||||
}
|
||||
)=="};
|
||||
|
||||
} // namespace Constants
|
||||
} // namespace CppEditor
|
||||
|
@@ -78,7 +78,6 @@ QtcPlugin {
|
||||
"cppcodestylesettings.h",
|
||||
"cppcodestylesettingspage.cpp",
|
||||
"cppcodestylesettingspage.h",
|
||||
"cppcodestylesettingspage.ui",
|
||||
"cppcodestylesnippets.h",
|
||||
"cppcompletionassist.cpp",
|
||||
"cppcompletionassist.h",
|
||||
|
Reference in New Issue
Block a user