Commit e48e411e authored by Christoph Cullmann's avatar Christoph Cullmann

use ECM provided clang-format target, guard for older ECM versions

parent b77babcf
---
# SPDX-License-Identifier: MIT
#
# Copyright (C) 2019 Christoph Cullmann <cullmann@kde.org>
# Copyright (C) 2019 Gernot Gebhard <gebhard@absint.com>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Style for C++
Language: Cpp
# base is WebKit coding style: http://www.webkit.org/coding/coding-style.html
# below are only things set that diverge from this style!
BasedOnStyle: WebKit
# enforce C++11 (e.g. for std::vector<std::vector<lala>>
Standard: Cpp11
# 4 spaces indent
TabWidth: 4
# 3 * 80 wide lines
ColumnLimit: 240
# sematics shall be grouped via empty lines
SortIncludes: true
# break before braces on function, namespace and class definitions.
BreakBeforeBraces: Linux
# CrlInstruction *a;
PointerAlignment: Right
# horizontally aligns arguments after an open bracket.
AlignAfterOpenBracket: Align
# align trailing comments
AlignTrailingComments: true
# don't move all parameters to new line
AllowAllParametersOfDeclarationOnNextLine: false
# no single line functions
AllowShortFunctionsOnASingleLine: None
# always break before you encounter multi line strings
AlwaysBreakBeforeMultilineStrings: true
# don't move arguments to own lines if they are not all on the same
BinPackArguments: false
# don't move parameters to own lines if they are not all on the same
BinPackParameters: false
# don't break binary ops
BreakBeforeBinaryOperators: None
# don't break tenary ops
BreakBeforeTernaryOperators: false
# format C++11 braced lists like function calls
Cpp11BracedListStyle: true
# indent case labels one level
IndentCaseLabels: true
# remove empty lines
KeepEmptyLinesAtTheStartOfBlocks: false
# no namespace indentation to keep indent level low
NamespaceIndentation: None
......@@ -4,6 +4,7 @@
*.orig
*.out
CMakeLists.txt.user*
.clang-format
# kate
*~
......
......@@ -46,3 +46,12 @@ ecm_optional_add_subdirectory(kate)
ecm_optional_add_subdirectory(doc)
feature_summary(INCLUDE_QUIET_PACKAGES WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
# this needs at least ECM 5.64...
if(${ECM_VERSION} VERSION_GREATER "5.63.0")
include(KDEClangFormat)
# add clang-format target for all our real source files
file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h)
kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES})
endif()
......@@ -211,41 +211,41 @@ void KateExternalToolsPlugin::handleToolFinished(KateToolRunner *runner, int exi
auto view = runner->view();
if (view && !runner->outputData().isEmpty()) {
switch (runner->tool()->outputMode) {
case KateExternalTool::OutputMode::InsertAtCursor: {
KTextEditor::Document::EditingTransaction transaction(view->document());
view->removeSelection();
view->insertText(runner->outputData());
break;
}
case KateExternalTool::OutputMode::ReplaceSelectedText: {
KTextEditor::Document::EditingTransaction transaction(view->document());
view->removeSelectionText();
view->insertText(runner->outputData());
break;
}
case KateExternalTool::OutputMode::ReplaceCurrentDocument: {
KTextEditor::Document::EditingTransaction transaction(view->document());
view->document()->clear();
view->insertText(runner->outputData());
break;
}
case KateExternalTool::OutputMode::AppendToCurrentDocument: {
view->document()->insertText(view->document()->documentEnd(), runner->outputData());
break;
}
case KateExternalTool::OutputMode::InsertInNewDocument: {
auto mainWindow = view->mainWindow();
auto newView = mainWindow->openUrl({});
newView->insertText(runner->outputData());
mainWindow->activateView(newView->document());
break;
}
case KateExternalTool::OutputMode::CopyToClipboard: {
QGuiApplication::clipboard()->setText(runner->outputData());
break;
}
default:
break;
case KateExternalTool::OutputMode::InsertAtCursor: {
KTextEditor::Document::EditingTransaction transaction(view->document());
view->removeSelection();
view->insertText(runner->outputData());
break;
}
case KateExternalTool::OutputMode::ReplaceSelectedText: {
KTextEditor::Document::EditingTransaction transaction(view->document());
view->removeSelectionText();
view->insertText(runner->outputData());
break;
}
case KateExternalTool::OutputMode::ReplaceCurrentDocument: {
KTextEditor::Document::EditingTransaction transaction(view->document());
view->document()->clear();
view->insertText(runner->outputData());
break;
}
case KateExternalTool::OutputMode::AppendToCurrentDocument: {
view->document()->insertText(view->document()->documentEnd(), runner->outputData());
break;
}
case KateExternalTool::OutputMode::InsertInNewDocument: {
auto mainWindow = view->mainWindow();
auto newView = mainWindow->openUrl({});
newView->insertText(runner->outputData());
mainWindow->activateView(newView->document());
break;
}
case KateExternalTool::OutputMode::CopyToClipboard: {
QGuiApplication::clipboard()->setText(runner->outputData());
break;
}
default:
break;
}
}
......
......@@ -28,12 +28,12 @@ namespace
QString toString(KateExternalTool::SaveMode saveMode)
{
switch (saveMode) {
case KateExternalTool::SaveMode::None:
return QStringLiteral("None");
case KateExternalTool::SaveMode::CurrentDocument:
return QStringLiteral("CurrentDocument");
case KateExternalTool::SaveMode::AllDocuments:
return QStringLiteral("AllDocuments");
case KateExternalTool::SaveMode::None:
return QStringLiteral("None");
case KateExternalTool::SaveMode::CurrentDocument:
return QStringLiteral("CurrentDocument");
case KateExternalTool::SaveMode::AllDocuments:
return QStringLiteral("AllDocuments");
}
Q_ASSERT(false); // yout forgot a case above
return QStringLiteral("None");
......@@ -53,22 +53,22 @@ KateExternalTool::SaveMode toSaveMode(const QString &mode)
QString toString(KateExternalTool::OutputMode outputMode)
{
switch (outputMode) {
case KateExternalTool::OutputMode::Ignore:
return QStringLiteral("Ignore");
case KateExternalTool::OutputMode::InsertAtCursor:
return QStringLiteral("InsertAtCursor");
case KateExternalTool::OutputMode::ReplaceSelectedText:
return QStringLiteral("ReplaceSelectedText");
case KateExternalTool::OutputMode::ReplaceCurrentDocument:
return QStringLiteral("ReplaceCurrentDocument");
case KateExternalTool::OutputMode::AppendToCurrentDocument:
return QStringLiteral("AppendToCurrentDocument");
case KateExternalTool::OutputMode::InsertInNewDocument:
return QStringLiteral("InsertInNewDocument");
case KateExternalTool::OutputMode::CopyToClipboard:
return QStringLiteral("CopyToClipboard");
case KateExternalTool::OutputMode::DisplayInPane:
return QStringLiteral("DisplayInPane");
case KateExternalTool::OutputMode::Ignore:
return QStringLiteral("Ignore");
case KateExternalTool::OutputMode::InsertAtCursor:
return QStringLiteral("InsertAtCursor");
case KateExternalTool::OutputMode::ReplaceSelectedText:
return QStringLiteral("ReplaceSelectedText");
case KateExternalTool::OutputMode::ReplaceCurrentDocument:
return QStringLiteral("ReplaceCurrentDocument");
case KateExternalTool::OutputMode::AppendToCurrentDocument:
return QStringLiteral("AppendToCurrentDocument");
case KateExternalTool::OutputMode::InsertInNewDocument:
return QStringLiteral("InsertInNewDocument");
case KateExternalTool::OutputMode::CopyToClipboard:
return QStringLiteral("CopyToClipboard");
case KateExternalTool::OutputMode::DisplayInPane:
return QStringLiteral("DisplayInPane");
}
Q_ASSERT(false); // yout forgot a case above
return QStringLiteral("Ignore");
......
......@@ -526,52 +526,52 @@ QVariant KateFileTreeModel::data(const QModelIndex &index, int role) const
}
switch (role) {
case KateFileTreeModel::PathRole:
// allow to sort with hostname + path, bug 271488
return (item->doc() && !item->doc()->url().isEmpty()) ? item->doc()->url().toString() : item->path();
case KateFileTreeModel::PathRole:
// allow to sort with hostname + path, bug 271488
return (item->doc() && !item->doc()->url().isEmpty()) ? item->doc()->url().toString() : item->path();
case KateFileTreeModel::DocumentRole:
return QVariant::fromValue(item->doc());
case KateFileTreeModel::DocumentRole:
return QVariant::fromValue(item->doc());
case KateFileTreeModel::OpeningOrderRole:
return item->row();
case KateFileTreeModel::OpeningOrderRole:
return item->row();
case KateFileTreeModel::DocumentTreeRole:
return QVariant::fromValue(item->docTree());
case KateFileTreeModel::DocumentTreeRole:
return QVariant::fromValue(item->docTree());
case Qt::DisplayRole:
// in list mode we want to use kate's fancy names.
if (m_listMode) {
return item->documentName();
} else {
return item->display();
}
case Qt::DecorationRole:
return item->icon();
case Qt::DisplayRole:
// in list mode we want to use kate's fancy names.
if (m_listMode) {
return item->documentName();
} else {
return item->display();
}
case Qt::ToolTipRole: {
QString tooltip = item->path();
if (item->flag(ProxyItem::DeletedExternally) || item->flag(ProxyItem::ModifiedExternally)) {
tooltip = i18nc("%1 is the full path", "<p><b>%1</b></p><p>The document has been modified by another application.</p>", item->path());
}
case Qt::DecorationRole:
return item->icon();
return tooltip;
case Qt::ToolTipRole: {
QString tooltip = item->path();
if (item->flag(ProxyItem::DeletedExternally) || item->flag(ProxyItem::ModifiedExternally)) {
tooltip = i18nc("%1 is the full path", "<p><b>%1</b></p><p>The document has been modified by another application.</p>", item->path());
}
case Qt::ForegroundRole: {
const KColorScheme colors(QPalette::Active);
if (!item->flag(ProxyItem::Dir) && (!item->doc() || item->doc()->openingError())) {
return colors.foreground(KColorScheme::InactiveText).color();
}
} break;
return tooltip;
}
case Qt::BackgroundRole:
// TODO: do that funky shading the file list does...
if (m_shadingEnabled && m_brushes.contains(item)) {
return m_brushes[item];
}
break;
case Qt::ForegroundRole: {
const KColorScheme colors(QPalette::Active);
if (!item->flag(ProxyItem::Dir) && (!item->doc() || item->doc()->openingError())) {
return colors.foreground(KColorScheme::InactiveText).color();
}
} break;
case Qt::BackgroundRole:
// TODO: do that funky shading the file list does...
if (m_shadingEnabled && m_brushes.contains(item)) {
return m_brushes[item];
}
break;
}
return QVariant();
......
......@@ -52,20 +52,20 @@ bool KateFileTreeProxyModel::lessThan(const QModelIndex &left, const QModelIndex
collate.setNumericMode(true);
switch (sortRole()) {
case Qt::DisplayRole: {
const QString left_name = model->data(left).toString();
const QString right_name = model->data(right).toString();
return collate.compare(left_name, right_name) < 0;
}
case KateFileTreeModel::PathRole: {
const QString left_name = model->data(left, KateFileTreeModel::PathRole).toString();
const QString right_name = model->data(right, KateFileTreeModel::PathRole).toString();
return collate.compare(left_name, right_name) < 0;
}
case KateFileTreeModel::OpeningOrderRole:
return (left.row() - right.row()) < 0;
case Qt::DisplayRole: {
const QString left_name = model->data(left).toString();
const QString right_name = model->data(right).toString();
return collate.compare(left_name, right_name) < 0;
}
case KateFileTreeModel::PathRole: {
const QString left_name = model->data(left, KateFileTreeModel::PathRole).toString();
const QString right_name = model->data(right, KateFileTreeModel::PathRole).toString();
return collate.compare(left_name, right_name) < 0;
}
case KateFileTreeModel::OpeningOrderRole:
return (left.row() - right.row()) < 0;
}
return false;
......
......@@ -63,17 +63,17 @@ const QStringList AdvancedGDBSettings::configs() const
tmp << u_gdbCmd->text();
switch (u_localRemote->currentIndex()) {
case 1:
tmp << QStringLiteral("target remote %1:%2").arg(u_tcpHost->text(), u_tcpPort->text());
tmp << QString();
break;
case 2:
tmp << QStringLiteral("target remote %1").arg(u_ttyPort->text());
tmp << QStringLiteral("set remotebaud %1").arg(u_baudCombo->currentText());
break;
default:
tmp << QString();
tmp << QString();
case 1:
tmp << QStringLiteral("target remote %1:%2").arg(u_tcpHost->text(), u_tcpPort->text());
tmp << QString();
break;
case 2:
tmp << QStringLiteral("target remote %1").arg(u_ttyPort->text());
tmp << QStringLiteral("set remotebaud %1").arg(u_baudCombo->currentText());
break;
default:
tmp << QString();
tmp << QString();
}
if (!u_soAbsPrefix->text().isEmpty()) {
tmp << QStringLiteral("set solib-absolute-prefix %1").arg(u_soAbsPrefix->text());
......
This diff is collapsed.
......@@ -308,10 +308,10 @@ QVariant TargetModel::data(const QModelIndex &index, int role) const
return QVariant();
}
switch (index.column()) {
case 0:
return m_targets[row].name;
case 1:
return m_targets[row].workDir;
case 0:
return m_targets[row].name;
case 1:
return m_targets[row].workDir;
}
} else {
int rootIndex = index.internalId();
......@@ -329,10 +329,10 @@ QVariant TargetModel::data(const QModelIndex &index, int role) const
return m_targets[rootIndex].commands[row].first == m_targets[rootIndex].defaultCmd ? Qt::Checked : Qt::Unchecked;
} else {
switch (index.column()) {
case 0:
return m_targets[rootIndex].commands[row].first;
case 1:
return m_targets[rootIndex].commands[row].second;
case 0:
return m_targets[rootIndex].commands[row].first;
case 1:
return m_targets[rootIndex].commands[row].second;
}
}
}
......@@ -375,12 +375,12 @@ bool TargetModel::setData(const QModelIndex &index, const QVariant &value, int r
return false;
}
switch (index.column()) {
case 0:
m_targets[row].name = value.toString();
return true;
case 1:
m_targets[row].workDir = value.toString();
return true;
case 0:
m_targets[row].name = value.toString();
return true;
case 1:
m_targets[row].workDir = value.toString();
return true;
}
} else {
int rootIndex = index.internalId();
......@@ -398,12 +398,12 @@ bool TargetModel::setData(const QModelIndex &index, const QVariant &value, int r
}
} else {
switch (index.column()) {
case 0:
m_targets[rootIndex].commands[row].first = value.toString();
return true;
case 1:
m_targets[rootIndex].commands[row].second = value.toString();
return true;
case 0:
m_targets[rootIndex].commands[row].first = value.toString();
return true;
case 1:
m_targets[rootIndex].commands[row].second = value.toString();
return true;
}
}
}
......
......@@ -75,12 +75,12 @@ static QIcon messageIcon(KateBuildView::ErrorCategory severity)
return icon; \
}
switch (severity) {
case KateBuildView::CategoryError:
RETURN_CACHED_ICON("dialog-error")
case KateBuildView::CategoryWarning:
RETURN_CACHED_ICON("dialog-warning")
default:
break;
case KateBuildView::CategoryError:
RETURN_CACHED_ICON("dialog-error")
case KateBuildView::CategoryWarning:
RETURN_CACHED_ICON("dialog-warning")
default:
break;
}
return QIcon();
}
......@@ -526,18 +526,18 @@ void KateBuildView::addMarks(KTextEditor::Document *doc, bool mark)
KTextEditor::MarkInterface::MarkTypes markType {};
switch (category) {
case CategoryError: {
markType = KTextEditor::MarkInterface::Error;
iface->setMarkDescription(markType, i18n("Error"));
break;
}
case CategoryWarning: {
markType = KTextEditor::MarkInterface::Warning;
iface->setMarkDescription(markType, i18n("Warning"));
break;
}
default:
break;
case CategoryError: {
markType = KTextEditor::MarkInterface::Error;
iface->setMarkDescription(markType, i18n("Error"));
break;
}
case CategoryWarning: {
markType = KTextEditor::MarkInterface::Warning;
iface->setMarkDescription(markType, i18n("Warning"));
break;
}
default:
break;
}
if (markType) {
......@@ -1082,18 +1082,18 @@ void KateBuildView::slotDisplayMode(int mode)
QString modeText;
switch (mode) {
case OnlyErrors:
modeText = i18n("Only Errors");
break;
case ErrorsAndWarnings:
modeText = i18n("Errors and Warnings");
break;
case ParsedOutput:
modeText = i18n("Parsed Output");
break;
case FullOutput:
modeText = i18n("Full Output");
break;
case OnlyErrors:
modeText = i18n("Only Errors");
break;
case ErrorsAndWarnings:
modeText = i18n("Errors and Warnings");
break;
case ParsedOutput:
modeText = i18n("Parsed Output");
break;
case FullOutput:
modeText = i18n("Full Output");
break;
}
m_buildUi.displayModeLabel->setText(modeText);
......@@ -1109,15 +1109,15 @@ void KateBuildView::slotDisplayMode(int mode)
const ErrorCategory errorCategory = static_cast<ErrorCategory>(item->data(0, ErrorRole).toInt());
switch (errorCategory) {
case CategoryInfo:
item->setHidden(mode > 1);
break;
case CategoryWarning:
item->setHidden(mode > 2);
break;
case CategoryError:
item->setHidden(false);
break;
case CategoryInfo:
item->setHidden(mode > 1);
break;
case CategoryWarning:
item->setHidden(mode > 2);
break;
case CategoryError:
item->setHidden(false);
break;
}
}
}
......
......@@ -55,22 +55,22 @@ QVariant ConnectionModel::data(const QModelIndex &index, int role) const
const QString key = m_connections.keys().at(index.row());
switch (role) {
case Qt::DisplayRole:
return QVariant(m_connections.value(key).name);
case Qt::DisplayRole:
return QVariant(m_connections.value(key).name);
case Qt::UserRole:
return QVariant::fromValue<Connection>(m_connections.value(key));
case Qt::UserRole:
return QVariant::fromValue<Connection>(m_connections.value(key));
case Qt::DecorationRole:
return m_icons[m_connections.value(key).status];
case Qt::DecorationRole:
return m_icons[m_connections.value(key).status];
case Qt::SizeHintRole: {
const QFontMetrics metrics(QFontDatabase::systemFont(QFontDatabase::GeneralFont));
return QSize(metrics.boundingRect(m_connections.value(key).name).width(), 22);
}
case Qt::SizeHintRole: {
const QFontMetrics metrics(QFontDatabase::systemFont(QFontDatabase::GeneralFont));
return QSize(metrics.boundingRect(m_connections.value(key).name).width(), 22);
}
default:
return QVariant();
default:
return QVariant();
}
return QVariant();
......
......@@ -232,25 +232,25 @@ void SchemaWidget::slotItemExpanded(QTreeWidgetItem *item)
return;
switch (item->type()) {
case SchemaWidget::TablesFolderType: {
if (!m_tablesLoaded)
buildTables(item);
} break;
case SchemaWidget::ViewsFolderType: {
if (!m_viewsLoaded)
buildViews(item);
} break;
case SchemaWidget::TableType:
case SchemaWidget::SystemTableType:
case SchemaWidget::ViewType: {
if (item->childCount() == 0)
buildFields(item);
} break;
default:
break;
case SchemaWidget::TablesFolderType: {
if (!m_tablesLoaded)
buildTables(item);
} break;
case SchemaWidget::ViewsFolderType: {
if (!m_viewsLoaded)
buildViews(item);
} break;
case SchemaWidget::TableType:
case SchemaWidget::SystemTableType:
case SchemaWidget::ViewType: {
if (item->childCount() == 0)
buildFields(item);
} break;
default:
break;
}
}
......@@ -297,41 +297,41 @@ void SchemaWidget::generateStatement(QSqlDriver::StatementType statementType)
QString statement;
switch (item->type()) {
case TableType:
case SystemTableType:
case ViewType: {
QString tableName = item->text(0);
case TableType:
case SystemTableType:
case ViewType: {
QString tableName = item->text(0);
QSqlRecord rec = db.record(tableName);
QSqlRecord rec = db.record(tableName);
// set all fields to a value (NULL)
// values are needed to generate update and insert statements
if (statementType == QSqlDriver::UpdateStatement || statementType == QSqlDriver::InsertStatement)
for (int i = 0, n = rec.count(); i < n; ++i)
rec.setNull(i);
// set all fields to a value (NULL)
// values are needed to generate update and insert statements
if (statementType == QSqlDriver::UpdateStatement || statementType == QSqlDriver::InsertStatement)
for (int i = 0, n = rec.count(); i < n; ++i)
rec.setNull(i);
statement = drv->sqlStatement(statementType, tableName, rec, false);
} break;
statement = drv->sqlStatement(statementType, tableName, rec, false);
} break;
case FieldType: {
QString tableName = item->parent()->text(0);
QSqlRecord rec = db.record(tableName);
case FieldType: {
QString tableName = item->parent()->text(0);
QSqlRecord rec = db.record(tableName);
// get the selected column...
QSqlField field = rec.field(item->text(0));
// get the selected column...
QSqlField field = rec.field(item->text(0));