Skip to content

Commit

Permalink
Update .clang-format with new features
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierLDff committed Apr 25, 2020
1 parent 9af2e27 commit c270aec
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 227 deletions.
33 changes: 22 additions & 11 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
BasedOnStyle: Microsoft
---
BasedOnStyle: Google
IndentWidth: 4
Language: Cpp
AccessModifierOffset: -4
Language: Cpp
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: true
AlignConsecutiveMacros: true
AlignEscapedNewlines: Left
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: false
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: true
AllowShortBlocksOnASingleLine: Always
AllowShortFunctionsOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true

BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: false
Expand All @@ -33,6 +36,7 @@ BraceWrapping:
AfterExternBlock: false
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: true
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
Expand All @@ -45,8 +49,10 @@ BreakStringLiterals: true
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: true
IncludeBlocks: Regroup
IndentCaseBlocks: false
IndentCaseLabels: true
IndentWidth: 4
IndentWrappedFunctionNames: true
Expand All @@ -65,11 +71,16 @@ SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeParens: Never
SpaceBeforeRangeBasedForLoopColon: false
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
UseTab: Never
FixNamespaceComments: false
FixNamespaceComments: false

IndentPPDirectives: AfterHash
4 changes: 2 additions & 2 deletions examples/QOlmExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void removeExample()
foo3.setFoo(3);
Foo foo4;
foo4.setFoo(4);
list.append({ &foo1, &foo2, &foo3, &foo4 });
list.append({&foo1, &foo2, &foo3, &foo4});

qInfo("list : %s", qPrintable(list.toString()));

Expand Down Expand Up @@ -79,7 +79,7 @@ void moveExample()
foo3.setFoo(3);
Foo foo4;
foo4.setFoo(4);
list.append({ &foo1, &foo2, &foo3, &foo4 });
list.append({&foo1, &foo2, &foo3, &foo4});

qInfo("list : %s", qPrintable(list.toString()));

Expand Down
120 changes: 79 additions & 41 deletions examples/include/FooExample.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class Foo : public QObject

QString toString() const
{
return QStringLiteral("Foo: {foo=") + QString::number(getFoo()) + QStringLiteral("}");
return QStringLiteral("Foo: {foo=") + QString::number(getFoo()) +
QStringLiteral("}");
}
Q_SIGNALS:
void fooChanged();
Expand All @@ -40,59 +41,84 @@ class FooList : public QOlm::QOlm<Foo>
FooList(QObject* parent = nullptr,
const QList<QByteArray>& exposedRoles = {},
const QByteArray& displayRole = {}) :
QOlm<Foo>(parent, exposedRoles, displayRole)
QOlm<Foo>(parent, exposedRoles, displayRole)
{
// CALLBACK LISTEN DEMO
onInserted([](const InsertedCallbackArgs& foo)
{
// foo->foo can be directly accessed
// foo.object gives a _Object*
// foo.index gives inserted object index
qInfo("callback : onInserted 0x%s : %d", qPrintable(QString::number(reinterpret_cast<quintptr>(static_cast<Foo*>(foo)), 16)), foo.index);
});
onRemoved([](const RemovedCallbackArgs& foo)
{
// foo->foo can be directly accessed
// foo.object gives a _Object*
// foo.index gives removed object index
qInfo("callback : onRemoved 0x%s : %d", qPrintable(QString::number(reinterpret_cast<quintptr>(static_cast<Foo*>(foo)), 16)), foo.index);
});
onMoved([](const MovedCallbackArgs& foo)
{
// foo->foo can be directly accessed
// foo.object gives a _Object*
// foo.from gives previous object index
// foo.to gives new object index
qInfo("callback : onMoved 0x%s : %d %d", qPrintable(QString::number(reinterpret_cast<quintptr>(static_cast<Foo*>(foo)), 16)), foo.from, foo.to);
});
onInserted(
[](const InsertedCallbackArgs& foo)
{
// foo->foo can be directly accessed
// foo.object gives a _Object*
// foo.index gives inserted object index
qInfo("callback : onInserted 0x%s : %d",
qPrintable(QString::number(
reinterpret_cast<quintptr>(static_cast<Foo*>(foo)),
16)),
foo.index);
});
onRemoved(
[](const RemovedCallbackArgs& foo)
{
// foo->foo can be directly accessed
// foo.object gives a _Object*
// foo.index gives removed object index
qInfo("callback : onRemoved 0x%s : %d",
qPrintable(QString::number(
reinterpret_cast<quintptr>(static_cast<Foo*>(foo)),
16)),
foo.index);
});
onMoved(
[](const MovedCallbackArgs& foo)
{
// foo->foo can be directly accessed
// foo.object gives a _Object*
// foo.from gives previous object index
// foo.to gives new object index
qInfo("callback : onMoved 0x%s : %d %d",
qPrintable(QString::number(
reinterpret_cast<quintptr>(static_cast<Foo*>(foo)),
16)),
foo.from, foo.to);
});

// SIGNAL LISTEN DEMO
connect(this, &FooList::objectInserted, this,
[](QObject* obj, int index)
{
qInfo("signal : onInserted 0x%s : %d", qPrintable(QString::number(reinterpret_cast<quintptr>(qobject_cast<Foo*>(obj)), 16)), index);
}
);
qInfo("signal : onInserted 0x%s : %d",
qPrintable(QString::number(
reinterpret_cast<quintptr>(qobject_cast<Foo*>(obj)),
16)),
index);
});
connect(this, &FooList::objectRemoved, this,
[](QObject* obj, int index)
{
qInfo("signal : onRemoved 0x%s : %d", qPrintable(QString::number(reinterpret_cast<quintptr>(qobject_cast<Foo*>(obj)), 16)), index);
}
);
qInfo("signal : onRemoved 0x%s : %d",
qPrintable(QString::number(
reinterpret_cast<quintptr>(qobject_cast<Foo*>(obj)),
16)),
index);
});
connect(this, &FooList::objectMoved, this,
[](QObject* obj, int from, int to)
{
qInfo("signal : onRemoved 0x%s : %d %d", qPrintable(QString::number(reinterpret_cast<quintptr>(qobject_cast<Foo*>(obj)), 16)), from, to);
}
);
qInfo("signal : onRemoved 0x%s : %d %d",
qPrintable(QString::number(
reinterpret_cast<quintptr>(qobject_cast<Foo*>(obj)),
16)),
from, to);
});
}

QString toString() const
{
QString res = QStringLiteral("FooList : {");

for (const auto it : *this)
res += QStringLiteral("foo") + QString::number(it->getFoo()) + QStringLiteral(", ");
for(const auto it: *this)
res += QStringLiteral("foo") + QString::number(it->getFoo()) +
QStringLiteral(", ");
res += QStringLiteral("}");

return res;
Expand All @@ -102,27 +128,39 @@ class FooList : public QOlm::QOlm<Foo>
protected:
void onObjectAboutToBeInserted(Foo* item, int row) override final
{
qInfo("override : onItemAboutToBeInserted 0x%s : %d", qPrintable(QString::number(reinterpret_cast<quintptr>(item), 16)), row);
qInfo("override : onItemAboutToBeInserted 0x%s : %d",
qPrintable(QString::number(reinterpret_cast<quintptr>(item), 16)),
row);
}
void onObjectInserted(Foo* item, int row) override final
{
qInfo("override : onItemInserted 0x%s : %d", qPrintable(QString::number(reinterpret_cast<quintptr>(item), 16)), row);
qInfo("override : onItemInserted 0x%s : %d",
qPrintable(QString::number(reinterpret_cast<quintptr>(item), 16)),
row);
}
void onObjectAboutToBeMoved(Foo* item, int src, int dest) override final
{
qInfo("override : onItemAboutToBeMoved 0x%s : %d %d", qPrintable(QString::number(reinterpret_cast<quintptr>(item), 16)), src, dest);
qInfo("override : onItemAboutToBeMoved 0x%s : %d %d",
qPrintable(QString::number(reinterpret_cast<quintptr>(item), 16)),
src, dest);
}
void onObjectMoved(Foo* item, int src, int dest) override final
{
qInfo("override : onItemMoved 0x%s : %d %d", qPrintable(QString::number(reinterpret_cast<quintptr>(item), 16)), src, dest);
qInfo("override : onItemMoved 0x%s : %d %d",
qPrintable(QString::number(reinterpret_cast<quintptr>(item), 16)),
src, dest);
}
void onObjectAboutToBeRemoved(Foo* item, int row) override final
{
qInfo("override : onItemAboutToBeRemoved 0x%s : %d", qPrintable(QString::number(reinterpret_cast<quintptr>(item), 16)), row);
qInfo("override : onItemAboutToBeRemoved 0x%s : %d",
qPrintable(QString::number(reinterpret_cast<quintptr>(item), 16)),
row);
}
void onObjectRemoved(Foo* item, int row) override final
{
qInfo("override : onItemRemoved 0x%s : %d", qPrintable(QString::number(reinterpret_cast<quintptr>(item), 16)), row);
qInfo("override : onItemRemoved 0x%s : %d",
qPrintable(QString::number(reinterpret_cast<quintptr>(item), 16)),
row);
}
};

Expand Down
20 changes: 10 additions & 10 deletions include/QOlm/Export.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
#define __QOLM_EXPORT_HPP__

#ifdef WIN32
#ifdef QOLM_DLL_EXPORT // Shared build
#define QOLM_API_ __declspec(dllexport)
#elif QOLM_STATIC // No decoration when building staticlly
#define QOLM_API_
#else // Link to lib
#define QOLM_API_ __declspec(dllimport)
#endif
# ifdef QOLM_DLL_EXPORT
# define QOLM_API_ __declspec(dllexport)
# elif QOLM_STATIC
# define QOLM_API_
# else
# define QOLM_API_ __declspec(dllimport)
# endif
#else
#define QOLM_API_
#endif // WIN32
# define QOLM_API_
#endif

#endif
#endif
Loading

0 comments on commit c270aec

Please sign in to comment.