Adding .clang-format file.

This commit is contained in:
Louis-Bertrand Varin 2017-05-11 14:36:06 -04:00 committed by Jonathan White
parent c167693ae4
commit 00ae123736
3 changed files with 105 additions and 20 deletions

89
.clang-format Normal file
View file

@ -0,0 +1,89 @@
---
Language: Cpp
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: true
AfterFunction: true
AfterControlStatement: false
AfterEnum: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: Never
...

View file

@ -25,7 +25,7 @@
#include "core/FilePath.h" #include "core/FilePath.h"
SearchWidget::SearchWidget(QWidget *parent) SearchWidget::SearchWidget(QWidget* parent)
: QWidget(parent) : QWidget(parent)
, m_ui(new Ui::SearchWidget()) , m_ui(new Ui::SearchWidget())
{ {
@ -44,7 +44,7 @@ SearchWidget::SearchWidget(QWidget *parent)
m_ui->searchEdit->installEventFilter(this); m_ui->searchEdit->installEventFilter(this);
QMenu *searchMenu = new QMenu(); QMenu* searchMenu = new QMenu();
m_actionCaseSensitive = searchMenu->addAction(tr("Case Sensitive"), this, SLOT(updateCaseSensitive())); m_actionCaseSensitive = searchMenu->addAction(tr("Case Sensitive"), this, SLOT(updateCaseSensitive()));
m_actionCaseSensitive->setObjectName("actionSearchCaseSensitive"); m_actionCaseSensitive->setObjectName("actionSearchCaseSensitive");
m_actionCaseSensitive->setCheckable(true); m_actionCaseSensitive->setCheckable(true);
@ -58,39 +58,35 @@ SearchWidget::SearchWidget(QWidget *parent)
m_ui->searchEdit->addAction(m_ui->clearIcon, QLineEdit::TrailingPosition); m_ui->searchEdit->addAction(m_ui->clearIcon, QLineEdit::TrailingPosition);
// Fix initial visibility of actions (bug in Qt) // Fix initial visibility of actions (bug in Qt)
for (QToolButton * toolButton: m_ui->searchEdit->findChildren<QToolButton *>()) { for (QToolButton* toolButton : m_ui->searchEdit->findChildren<QToolButton*>()) {
toolButton->setVisible(toolButton->defaultAction()->isVisible()); toolButton->setVisible(toolButton->defaultAction()->isVisible());
} }
} }
SearchWidget::~SearchWidget() SearchWidget::~SearchWidget()
{ {
} }
bool SearchWidget::eventFilter(QObject *obj, QEvent *event) bool SearchWidget::eventFilter(QObject* obj, QEvent* event)
{ {
if (event->type() == QEvent::KeyPress) { if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
if (keyEvent->key() == Qt::Key_Escape) { if (keyEvent->key() == Qt::Key_Escape) {
emit escapePressed(); emit escapePressed();
return true; return true;
} } else if (keyEvent->matches(QKeySequence::Copy)) {
else if (keyEvent->matches(QKeySequence::Copy)) {
// If Control+C is pressed in the search edit when no text // If Control+C is pressed in the search edit when no text
// is selected, copy the password of the current entry // is selected, copy the password of the current entry
if (!m_ui->searchEdit->hasSelectedText()) { if (!m_ui->searchEdit->hasSelectedText()) {
emit copyPressed(); emit copyPressed();
return true; return true;
} }
} } else if (keyEvent->matches(QKeySequence::MoveToNextLine)) {
else if (keyEvent->matches(QKeySequence::MoveToNextLine)) {
if (m_ui->searchEdit->cursorPosition() == m_ui->searchEdit->text().length()) { if (m_ui->searchEdit->cursorPosition() == m_ui->searchEdit->text().length()) {
// If down is pressed at EOL, move the focus to the entry view // If down is pressed at EOL, move the focus to the entry view
emit downPressed(); emit downPressed();
return true; return true;
} } else {
else {
// Otherwise move the cursor to EOL // Otherwise move the cursor to EOL
m_ui->searchEdit->setCursorPosition(m_ui->searchEdit->text().length()); m_ui->searchEdit->setCursorPosition(m_ui->searchEdit->text().length());
return true; return true;
@ -110,7 +106,7 @@ void SearchWidget::connectSignals(SignalMultiplexer& mx)
mx.connect(m_ui->searchEdit, SIGNAL(returnPressed()), SLOT(switchToEntryEdit())); mx.connect(m_ui->searchEdit, SIGNAL(returnPressed()), SLOT(switchToEntryEdit()));
} }
void SearchWidget::databaseChanged(DatabaseWidget *dbWidget) void SearchWidget::databaseChanged(DatabaseWidget* dbWidget)
{ {
if (dbWidget != nullptr) { if (dbWidget != nullptr) {
// Set current search text from this database // Set current search text from this database

View file

@ -18,11 +18,11 @@
#ifndef KEEPASSX_SEARCHWIDGET_H #ifndef KEEPASSX_SEARCHWIDGET_H
#define KEEPASSX_SEARCHWIDGET_H #define KEEPASSX_SEARCHWIDGET_H
#include <QWidget>
#include <QTimer> #include <QTimer>
#include <QWidget>
#include "gui/DatabaseWidget.h"
#include "core/SignalMultiplexer.h" #include "core/SignalMultiplexer.h"
#include "gui/DatabaseWidget.h"
namespace Ui { namespace Ui {
class SearchWidget; class SearchWidget;
@ -33,17 +33,17 @@ class SearchWidget : public QWidget
Q_OBJECT Q_OBJECT
public: public:
explicit SearchWidget(QWidget *parent = 0); explicit SearchWidget(QWidget* parent = 0);
~SearchWidget(); ~SearchWidget();
void connectSignals(SignalMultiplexer& mx); void connectSignals(SignalMultiplexer& mx);
void setCaseSensitive(bool state); void setCaseSensitive(bool state);
protected: protected:
bool eventFilter(QObject *obj, QEvent *event); bool eventFilter(QObject* obj, QEvent* event);
signals: signals:
void search(const QString &text); void search(const QString& text);
void caseSensitiveChanged(bool state); void caseSensitiveChanged(bool state);
void escapePressed(); void escapePressed();
void copyPressed(); void copyPressed();
@ -62,7 +62,7 @@ private slots:
private: private:
const QScopedPointer<Ui::SearchWidget> m_ui; const QScopedPointer<Ui::SearchWidget> m_ui;
QTimer* m_searchTimer; QTimer* m_searchTimer;
QAction *m_actionCaseSensitive; QAction* m_actionCaseSensitive;
Q_DISABLE_COPY(SearchWidget) Q_DISABLE_COPY(SearchWidget)
}; };