Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use clang-format with Qt style #63

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Copyright (C) 2016 Olivier Goffart <ogoffart@woboq.com>
#
# You may use this file under the terms of the 3-clause BSD license.
# See the file LICENSE from this package for details.

# This is the clang-format configuration style to be used by Qt,
# based on the rules from https://wiki.qt.io/Qt_Coding_Style and
# https://wiki.qt.io/Coding_Conventions

---
# Webkit style was loosely based on the Qt style
BasedOnStyle: WebKit

Standard: c++17

# Column width is limited to 100 in accordance with Qt Coding Style.
# https://wiki.qt.io/Qt_Coding_Style
# Note that this may be changed at some point in the future.
ColumnLimit: 100
# How much weight do extra characters after the line length limit have.
# PenaltyExcessCharacter: 4

# Disable reflow of some specific comments
# qdoc comments: indentation rules are different.
# Translation comments and SPDX license identifiers are also excluded.
CommentPragmas: "^!|^:|^ SPDX-License-Identifier:"

# We want a space between the type and the star for pointer types.
PointerBindsToType: false

# We generally use "template <" with space.
SpaceAfterTemplateKeyword: true

# We want to break before the operators, but not before a '='.
BreakBeforeBinaryOperators: NonAssignment

# Braces are usually attached, but not after functions or class declarations.
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false

# When constructor initializers do not fit on one line, put them each on a new line.
ConstructorInitializerAllOnOneLineOrOnePerLine: true
# Indent initializers by 4 spaces
ConstructorInitializerIndentWidth: 4

# Indent width for line continuations.
ContinuationIndentWidth: 8

# No indentation for namespaces.
NamespaceIndentation: None

# Allow indentation for preprocessing directives (if/ifdef/endif). https://reviews.llvm.org/rL312125
IndentPPDirectives: AfterHash
# We only indent with 2 spaces for preprocessor directives
PPIndentWidth: 2

# Horizontally align arguments after an open bracket.
# The coding style does not specify the following, but this is what gives
# results closest to the existing code.
AlignAfterOpenBracket: true
AlwaysBreakTemplateDeclarations: true

# Ideally we should also allow less short function in a single line, but
# clang-format does not handle that.
AllowShortFunctionsOnASingleLine: Inline

# The coding style specifies some include order categories, but also tells to
# separate categories with an empty line. It does not specify the order within
# the categories. Since the SortInclude feature of clang-format does not
# re-order includes separated by empty lines, the feature is not used.
SortIncludes: false

# macros for which the opening brace stays attached.
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH, forever, Q_FOREVER, QBENCHMARK, QBENCHMARK_ONCE ]

# Break constructor initializers before the colon and after the commas.
BreakConstructorInitializers: BeforeColon

# Add "// namespace <namespace>" comments on closing brace for a namespace
# Ignored for namespaces that qualify as a short namespace,
# see 'ShortNamespaceLines'
FixNamespaceComments: true

# Definition of how short a short namespace is, default 1
ShortNamespaceLines: 1

# When escaping newlines in a macro attach the '\' as far left as possible, e.g.
##define a \
# something; \
# other; \
# thelastlineislong;
AlignEscapedNewlines: Left

# Avoids the addition of a space between an identifier and the
# initializer list in list-initialization.
SpaceBeforeCpp11BracedList: false

---
# Use the Google-based style for .proto files.
Language: Proto
BasedOnStyle: Google
IndentWidth: 4
ColumnLimit: 100
75 changes: 39 additions & 36 deletions app/aboutdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,45 +25,48 @@

#include "ktikzapplication.h"

AboutDialog::AboutDialog(QWidget *parent)
: QDialog(parent)
AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent)
{
QLabel *pixmapLabel = new QLabel;
pixmapLabel->setPixmap(QPixmap(QLatin1String(":/icons/qtikz-128.png")));
QLabel *label = new QLabel(QString(QLatin1String("<h1>%1 %2</h1><p>%3</p><p>%4</p>"))
.arg(KtikzApplication::applicationName())
.arg(QCoreApplication::applicationVersion())
.arg(tr("Copyright 2007-2014 Florian Hackenberger and Glad Deschrijver"))
.arg(tr("This is a program for creating TikZ (from the LaTeX pgf package) diagrams.")));
label->setWordWrap(true);
QLabel *pixmapLabel = new QLabel;
pixmapLabel->setPixmap(QPixmap(QLatin1String(":/icons/qtikz-128.png")));
QLabel *label = new QLabel(
QString(QLatin1String("<h1>%1 %2</h1><p>%3</p><p>%4</p>"))
.arg(KtikzApplication::applicationName())
.arg(QCoreApplication::applicationVersion())
.arg(tr("Copyright 2007-2014 Florian Hackenberger and Glad Deschrijver"))
.arg(tr("This is a program for creating TikZ (from the LaTeX pgf package) "
"diagrams.")));
label->setWordWrap(true);

QWidget *topWidget = new QWidget;
QHBoxLayout *topLayout = new QHBoxLayout;
topLayout->addWidget(pixmapLabel);
topLayout->addWidget(label);
topWidget->setLayout(topLayout);
QWidget *topWidget = new QWidget;
QHBoxLayout *topLayout = new QHBoxLayout;
topLayout->addWidget(pixmapLabel);
topLayout->addWidget(label);
topWidget->setLayout(topLayout);

QTextBrowser *textEdit = new QTextBrowser;
textEdit->setHtml(tr("<p>This program is free "
"software; you can redistribute it and/or modify it under the "
"terms of the GNU General Public License as published by the "
"Free Software Foundation; either version 2 of the License, "
"or (at your option) any later version.</p>"
"<p>This program is distributed in the hope that it will "
"be useful, but WITHOUT ANY WARRANTY; without even the implied "
"warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. "
"See the <a href=\"http://www.gnu.org/licenses/old-licenses/gpl-2.0.html\">GNU General Public License</a> for more details.</p>"));
textEdit->setReadOnly(true);
textEdit->setOpenExternalLinks(true);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
QTextBrowser *textEdit = new QTextBrowser;
textEdit->setHtml(
tr("<p>This program is free "
"software; you can redistribute it and/or modify it under the "
"terms of the GNU General Public License as published by the "
"Free Software Foundation; either version 2 of the License, "
"or (at your option) any later version.</p>"
"<p>This program is distributed in the hope that it will "
"be useful, but WITHOUT ANY WARRANTY; without even the implied "
"warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. "
"See the <a href=\"http://www.gnu.org/licenses/old-licenses/gpl-2.0.html\">GNU "
"General Public License</a> for more details.</p>"));
textEdit->setReadOnly(true);
textEdit->setOpenExternalLinks(true);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));

QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->addWidget(topWidget);
mainLayout->addWidget(textEdit);
mainLayout->addWidget(buttonBox);
mainLayout->setSpacing(10);
buttonBox->setFocus();
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->addWidget(topWidget);
mainLayout->addWidget(textEdit);
mainLayout->addWidget(buttonBox);
mainLayout->setSpacing(10);
buttonBox->setFocus();

setWindowTitle(tr("About %1").arg(KtikzApplication::applicationName()));
setWindowTitle(tr("About %1").arg(KtikzApplication::applicationName()));
}
4 changes: 2 additions & 2 deletions app/aboutdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

class AboutDialog : public QDialog
{
Q_OBJECT
Q_OBJECT

public:
explicit AboutDialog(QWidget *parent = 0);
explicit AboutDialog(QWidget *parent = 0);
};

#endif
86 changes: 41 additions & 45 deletions app/assistantcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,69 +26,65 @@

#include "ktikzapplication.h"

AssistantController::AssistantController()
: m_process(0)
{
}
AssistantController::AssistantController() : m_process(0) { }

AssistantController::~AssistantController()
{
if (m_process && m_process->state() == QProcess::Running)
{
m_process->terminate();
m_process->waitForFinished(3000);
}
delete m_process;
if (m_process && m_process->state() == QProcess::Running) {
m_process->terminate();
m_process->waitForFinished(3000);
}
delete m_process;
}

bool AssistantController::startAssistant()
{
if (!m_process)
m_process = new QProcess();
if (!m_process)
m_process = new QProcess();

if (m_process->state() != QProcess::Running)
{
QString app = QLibraryInfo::location(QLibraryInfo::BinariesPath) + QDir::separator();
if (m_process->state() != QProcess::Running) {
QString app = QLibraryInfo::location(QLibraryInfo::BinariesPath) + QDir::separator();
#if !defined(Q_OS_MAC)
app += QLatin1String("assistant");
app += QLatin1String("assistant");
#else
app += QLatin1String("Assistant.app/Contents/MacOS/Assistant");
app += QLatin1String("Assistant.app/Contents/MacOS/Assistant");
#endif

const QString ktikzDocFile = QString::fromLocal8Bit(KTIKZ_DOCUMENTATION_INSTALL_DIR) + QLatin1String("/qtikz.qhc");
if (!QFileInfo(ktikzDocFile).isReadable())
{
QMessageBox::critical(0, KtikzApplication::applicationName(),
QCoreApplication::translate("AssistantController", "Unable to open the help file (%1)").arg(ktikzDocFile));
return false;
}
const QString ktikzDocFile = QString::fromLocal8Bit(KTIKZ_DOCUMENTATION_INSTALL_DIR)
+ QLatin1String("/qtikz.qhc");
if (!QFileInfo(ktikzDocFile).isReadable()) {
QMessageBox::critical(0, KtikzApplication::applicationName(),
QCoreApplication::translate("AssistantController",
"Unable to open the help file (%1)")
.arg(ktikzDocFile));
return false;
}

QStringList args;
args << QLatin1String("-collectionFile")
<< ktikzDocFile
<< QLatin1String("-enableRemoteControl");
QStringList args;
args << QLatin1String("-collectionFile") << ktikzDocFile
<< QLatin1String("-enableRemoteControl");

m_process->start(app, args);
m_process->start(app, args);

if (!m_process->waitForStarted())
{
QMessageBox::critical(0, KtikzApplication::applicationName(),
QCoreApplication::translate("AssistantController", "Unable to launch Qt Assistant (%1)").arg(app));
return false;
}
}
return true;
if (!m_process->waitForStarted()) {
QMessageBox::critical(0, KtikzApplication::applicationName(),
QCoreApplication::translate("AssistantController",
"Unable to launch Qt Assistant (%1)")
.arg(app));
return false;
}
}
return true;
}

void AssistantController::showDocumentation(const QString &page)
{
if (!startAssistant())
return;
if (!startAssistant())
return;

if (!page.isEmpty())
{
QByteArray ba;
ba.append("setSource qthelp://hackenberger.qtikz/doc/");
m_process->write(ba + page.toLocal8Bit() + '\0');
}
if (!page.isEmpty()) {
QByteArray ba;
ba.append("setSource qthelp://hackenberger.qtikz/doc/");
m_process->write(ba + page.toLocal8Bit() + '\0');
}
}
10 changes: 5 additions & 5 deletions app/assistantcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ class QProcess;
class AssistantController
{
public:
AssistantController();
~AssistantController();
AssistantController();
~AssistantController();

void showDocumentation(const QString &page = QString());
void showDocumentation(const QString &page = QString());

private:
bool startAssistant();
bool startAssistant();

QProcess *m_process;
QProcess *m_process;
};

#endif
Loading