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

Clang format #1635

Merged
merged 5 commits into from
Feb 27, 2025
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 0 additions & 13 deletions .astylerc

This file was deleted.

110 changes: 110 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# .clang-format for Shotcut
#
# Adapted from https://github.com/qt-creator/qt-creator/blob/master/.clang-format
#
# The configuration below follows the Qt Creator Coding Rules [1] as closely as
# possible. For documentation of the options, see [2].
#
#
# [1] https://doc-snapshots.qt.io/qtcreator-extending/coding-style.html
# [2] https://clang.llvm.org/docs/ClangFormatStyleOptions.html
#
---
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: DontAlign
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: true
AfterControlStatement: Never
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 100
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- forever # avoids { wrapped to next line
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeCategories:
- Regex: '^<Q.*'
Priority: 200
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ""
MacroBlockEnd: ""
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 88
PenaltyBreakBeforeFirstCallParameter: 300
PenaltyBreakComment: 500
PenaltyBreakFirstLessLess: 400
PenaltyBreakString: 600
PenaltyExcessCharacter: 50
PenaltyReturnTypeOnItsOwnLine: 300
PointerAlignment: Right
ReflowComments: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: true
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: c++11
TabWidth: 4
UseTab: Never
24 changes: 16 additions & 8 deletions .github/workflows/check-code-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,34 @@ on:
push:

jobs:
astyle:
clang-format:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Artistic Style
run: sudo apt-get install -y astyle grep
- name: Install clang-format
run: sudo apt-get install -y clang-format-14

- name: Check style
run: |
results="$(astyle --project=.astylerc --dry-run --recursive "./*.cpp,*.h" | awk '/^Formatted/')"
if [ -z "$results" ]
FILES=`find . -type f -name "*.h" -o -name "*.c" -o -name "*.cpp"`
FILTERED_FILES=()
for file in ${FILES[@]};
do
[[ $file =~ "./src/" ]] &&
[[ ! $file =~ "spatialmedia" ]] &&
[[ ! $file =~ "defaultlayouts.h" ]] &&
[[ ! $file =~ "_autogen" ]] &&
FILTERED_FILES+=($file)
done
clang-format-14 --verbose --dry-run --Werror -style=file -i ${FILTERED_FILES[@]}
if [ $? -eq 0 ]
then
echo "SUCCESS: All files are formatted correctly"
exit 0
else
count=`wc -l <<< "$results"`
echo "FAILURE: $count files are formatted incorrectly"
echo "${results//'Formatted '/' '}"
echo "FAILURE: some files are formatted incorrectly"
exit 99
fi
28 changes: 24 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ project(shotcut
if(WIN32)
option(WINDOWS_DEPLOY "Install exes/libs directly to prefix (no subdir /bin)" ON)
endif()
option(CLANG_FORMAT "Enable Clang Format" ON)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

include(FeatureSummary)

Expand Down Expand Up @@ -66,10 +69,27 @@ add_custom_target(codespell COMMAND
-S export-chapters.js,export-edl.js,CuteLogger,drmingw,node_modules,moc_*,index.theme,*.ts,three.min.js,three.js,jquery.js,rangy-*.js,Makefile,shotcut.pro,*.desktop
)

add_custom_target(astyle COMMAND
cd "${CMAKE_SOURCE_DIR}" &&
astyle --project=.astylerc --ignore-exclude-errors --recursive "./*.cpp,*.h"
)
if(CLANG_FORMAT)
# Formatting may change with different versions of clang-format.
# Test new versions before changing the allowed version here to avoid
# accidental broad changes to formatting.
find_package(ClangFormat 14 EXACT)
if(CLANGFORMAT_FOUND)
file(GLOB_RECURSE FORMAT_FILES "src/*.h" "src/*.c" "src/*.cpp")
# exclude 3rd party & generated source from format checking
list(FILTER FORMAT_FILES EXCLUDE REGEX "/.*/spatialmedia/")
list(FILTER FORMAT_FILES EXCLUDE REGEX "/.*/defaultlayouts.h")
list(FILTER FORMAT_FILES EXCLUDE REGEX "/.*/*_autogen/")
add_custom_target(clang-format COMMAND
${CLANGFORMAT_EXECUTABLE} -style=file -i ${FORMAT_FILES}
)
add_custom_target(clang-format-check COMMAND
${CLANGFORMAT_EXECUTABLE} --dry-run --Werror -style=file -i ${FORMAT_FILES}
)
else()
set(CLANG_FORMAT OFF)
endif()
endif()

file(GLOB_RECURSE QML_SRC "src/qml/*.qml")
add_custom_target(qmlformat COMMAND
Expand Down
91 changes: 91 additions & 0 deletions cmake/FindClangFormat.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#
# .rst: FindClangFormat
# ---------------
#
# The module defines the following variables
#
# ``CLANGFORMAT_EXECUTABLE`` Path to clang-format executable
# ``CLANGFORMAT_FOUND`` True if the clang-format executable was found.
# ``CLANGFORMAT_VERSION`` The version of clang-format found
#
# Example usage:
#
# .. code-block:: cmake
#
# find_package(ClangFormat)
# if(CLANGFORMAT_FOUND)
# message("clang-format executable found: ${CLANGFORMAT_EXECUTABLE}\n" "version: ${CLANGFORMAT_VERSION}")
# endif()

include(FindPackageHandleStandardArgs)

function(_ClangFormat_get_version clangformat_version result_var clangformat_path)
execute_process(
COMMAND "${clangformat_path}" --version
OUTPUT_VARIABLE full_clangformat_version
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE version_result
)

# full_clangformat_version sample: "clang-format version 3.9.1-4ubuntu3~16.04.1 (tags/RELEASE_391/rc2)"
# clean clangformat_version sample: "3.9.1"
string(REGEX
REPLACE "[^0-9]*([.0-9]+).*"
"\\1"
clean_clangformat_version
"${full_clangformat_version}")

set(${result_var} ${version_result} PARENT_SCOPE)
set(${clangformat_version} ${clean_clangformat_version} PARENT_SCOPE)
endfunction()

function(_ClangFromat_version_validator version_match clangformat_path)
if(NOT DEFINED ClangFormat_FIND_VERSION)
set(${is_valid_version} TRUE PARENT_SCOPE)
else()
_ClangFormat_get_version(candidate_version version_result "${clangformat_path}")

if(version_result)
message(DEBUG "Unable to determine candidate clang-format version at ${clangformat_path}: ${version_result}")
endif()

find_package_check_version("${candidate_version}" valid_clangformat_version
HANDLE_VERSION_RANGE
)

set(${version_match} "${valid_clangformat_version}" PARENT_SCOPE)
endif()
endfunction()

find_program(CLANGFORMAT_EXECUTABLE
NAMES clang-format
clang-format-16
clang-format-15
clang-format-14
clang-format-13
clang-format-12
clang-format-11
clang-format-10
DOC "clang-format executable"
VALIDATOR _ClangFromat_version_validator
)
mark_as_advanced(CLANGFORMAT_EXECUTABLE)

if(CLANGFORMAT_EXECUTABLE)
_ClangFormat_get_version(CLANGFORMAT_VERSION _Clangformat_version_result "${CLANGFORMAT_EXECUTABLE}")

if(_Clangformat_version_result)
set(CLANGFORMAT_FOUND FALSE)
message(WARNING "Unable to determine clang-format version: ${_Clangformat_version_result}")
else()
set(CLANGFORMAT_FOUND TRUE)
endif()
endif()

find_package_handle_standard_args(ClangFormat
FOUND_VAR CLANGFORMAT_FOUND
REQUIRED_VARS
CLANGFORMAT_EXECUTABLE
CLANGFORMAT_VERSION
VERSION_VAR CLANGFORMAT_VERSION
)
18 changes: 7 additions & 11 deletions src/abstractproducerwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@
*/

#include "abstractproducerwidget.h"

#include <QWidget>

AbstractProducerWidget::AbstractProducerWidget()
{
}
AbstractProducerWidget::AbstractProducerWidget() {}

AbstractProducerWidget::~AbstractProducerWidget()
{
}
AbstractProducerWidget::~AbstractProducerWidget() {}

void AbstractProducerWidget::setProducer(Mlt::Producer *producer)
{
Expand All @@ -39,10 +36,9 @@ void AbstractProducerWidget::setProducer(Mlt::Producer *producer)
bool AbstractProducerWidget::isDevice(const QWidget *widget)
{
auto name = widget->objectName();
return "AlsaWidget" == name || "alsaWidget" == name
|| "AvfoundationProducerWidget" == name || "avfoundationWidget" == name
|| "DecklinkProducerWidget" == name || "decklinkWidget" == name
|| "DirectShowVideoWidget" == name || "dshowVideoWidget" == name
|| "PulseAudioWidget" == name || "pulseWidget" == name
return "AlsaWidget" == name || "alsaWidget" == name || "AvfoundationProducerWidget" == name
|| "avfoundationWidget" == name || "DecklinkProducerWidget" == name
|| "decklinkWidget" == name || "DirectShowVideoWidget" == name
|| "dshowVideoWidget" == name || "PulseAudioWidget" == name || "pulseWidget" == name
|| "Video4LinuxWidget" == name || "v4lWidget" == name;
}
5 changes: 1 addition & 4 deletions src/abstractproducerwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ class AbstractProducerWidget
return p;
}
virtual void loadPreset(Mlt::Properties &) {}
Mlt::Producer *producer() const
{
return m_producer.data();
}
Mlt::Producer *producer() const { return m_producer.data(); }
static bool isDevice(const QWidget *widget);

protected:
Expand Down
6 changes: 3 additions & 3 deletions src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "actions.h"

#include <Logger.h>
#include "Logger.h"
#include "settings.h"

#include <QAction>
Expand Down Expand Up @@ -51,7 +51,7 @@ void ShotcutActions::add(const QString &key, QAction *action, QString group)
if (group.isEmpty()) {
group = tr("Other");
}
action->setProperty(displayProperty, group + " > " + action->iconText());
action->setProperty(displayProperty, group + " > " + action->iconText());

QList<QKeySequence> sequences = action->shortcuts();
if (sequences.size() > 0)
Expand Down Expand Up @@ -93,7 +93,7 @@ void ShotcutActions::loadFromMenu(QMenu *menu, QString group)
}
}

QAction *ShotcutActions::operator [](const QString &key)
QAction *ShotcutActions::operator[](const QString &key)
{
auto iterator = m_actions.find(key);
if (iterator != m_actions.end()) {
Expand Down
7 changes: 4 additions & 3 deletions src/actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,20 @@ class ShotcutActions : public QObject
Q_OBJECT

public:

static const char *hardKeyProperty;
static const char *displayProperty;
static const char *defaultKey1Property;
static const char *defaultKey2Property;
static const char *defaultToolTipProperty;

static ShotcutActions &singleton();
explicit ShotcutActions() : QObject() {}
explicit ShotcutActions()
: QObject()
{}

void add(const QString &name, QAction *action, QString group = "");
void loadFromMenu(QMenu *menu, const QString group = "");
QAction *operator [](const QString &key);
QAction *operator[](const QString &key);
QList<QString> keys();
void overrideShortcuts(const QString &key, QList<QKeySequence> shortcuts);
void initializeShortcuts();
Expand Down
Loading