From 26a894a1ebdc943cb04cb7455345566b65768d9c Mon Sep 17 00:00:00 2001 From: rtk0c Date: Thu, 30 Jun 2022 21:00:37 -0700 Subject: Rearrange project, add .clang-format and .clang-tidy --- .clang-format | 51 ++++++++++++++++++++++++++++++++++++++++++++ .clang-tidy | 0 CMakeLists.txt | 30 +++++++++++++++++--------- qml/MainWindow.qml | 8 +++++++ source/main.cpp | 31 --------------------------- source/qml/main.qml | 8 ------- src/QCplt/Qml/NodeCanvas.cpp | 1 + src/QCplt/Qml/NodeCanvas.hpp | 1 + src/QCplt/Qml/README.md | 1 + src/main.cpp | 35 ++++++++++++++++++++++++++++++ 10 files changed, 117 insertions(+), 49 deletions(-) create mode 100644 .clang-format create mode 100644 .clang-tidy create mode 100644 qml/MainWindow.qml delete mode 100644 source/main.cpp delete mode 100644 source/qml/main.qml create mode 100644 src/QCplt/Qml/NodeCanvas.cpp create mode 100644 src/QCplt/Qml/NodeCanvas.hpp create mode 100644 src/QCplt/Qml/README.md create mode 100644 src/main.cpp diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..3290fe2 --- /dev/null +++ b/.clang-format @@ -0,0 +1,51 @@ +BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignAfterOpenBracket: DontAlign +AlignOperands: false +AlignTrailingComments: false +AllowAllParametersOfDeclarationOnNextLine: true +AllowAllArgumentsOnNextLine: true +AllowShortCaseLabelsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: true +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterClass: true + AfterControlStatement: MultiLine + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBraces: Custom +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeComma +ColumnLimit: 0 +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +IncludeCategories: + - Regex: '".*"' + Priority: 1 + - Regex: '^<.*\.h>' + Priority: 2 + - Regex: '^<.*' + Priority: 3 +IndentCaseLabels: true +IndentPPDirectives: AfterHash +IndentWidth: 4 +NamespaceIndentation: Inner +PointerAlignment: Left +TabWidth: 4 +UseTab: Always diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..e69de29 diff --git a/CMakeLists.txt b/CMakeLists.txt index 07d4d08..8f217ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,4 @@ cmake_minimum_required(VERSION 3.16) - project(QCplt VERSION 0.1 LANGUAGES CXX) set(CMAKE_AUTOMOC ON) @@ -8,17 +7,23 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt6 6.2 COMPONENTS Quick REQUIRED) -qt_add_executable(AppQCplt - source/main.cpp +file(GLOB_RECURSE appQCplt_SRC_HPP_FILES src/*.hpp) +file(GLOB_RECURSE appQCplt_SRC_CPP_FILES src/*.cpp) +qt_add_executable(appQCplt + ${appQCplt_SRC_HPP_FILES} + ${appQCplt_SRC_CPP_FILES} ) -qt_add_qml_module(AppQCplt +file(GLOB_RECURSE appQCplt_QML_CPPMODULE_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/QCplt/Qml/*.hpp src/QCplt/Qml/*.cpp) +file(GLOB_RECURSE appQCplt_QML_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} qml/*.qml) +qt_add_qml_module(appQCplt URI QCplt VERSION 1.0 - QML_FILES source/qml/main.qml + SOURCES ${appQCplt_QML_CPPMODULE_FILES} + QML_FILES ${appQCplt_QML_FILES} ) -set_target_properties(AppQCplt PROPERTIES +set_target_properties(appQCplt PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER rtk0c.github.io MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} @@ -26,7 +31,12 @@ set_target_properties(AppQCplt PROPERTIES WIN32_EXECUTABLE TRUE ) -target_compile_definitions(AppQCplt - PRIVATE $<$,$>:QT_QML_DEBUG>) -target_link_libraries(AppQCplt - PRIVATE Qt6::Quick) +target_include_directories(appQCplt PUBLIC src) +target_compile_definitions(appQCplt +PRIVATE + $<$,$>:QT_QML_DEBUG> +) +target_link_libraries(appQCplt +PRIVATE + Qt6::Quick +) diff --git a/qml/MainWindow.qml b/qml/MainWindow.qml new file mode 100644 index 0000000..41424f8 --- /dev/null +++ b/qml/MainWindow.qml @@ -0,0 +1,8 @@ +import QtQuick + +Window { + width: 640 + height: 480 + visible: true + title: qsTr("Hello World") +} diff --git a/source/main.cpp b/source/main.cpp deleted file mode 100644 index 699e881..0000000 --- a/source/main.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include - -#include -#include - -int main(int argc, char *argv[]) -{ - QGuiApplication app(argc, argv); - - QTranslator translator; - const QStringList uiLanguages = QLocale::system().uiLanguages(); - for (const QString &locale : uiLanguages) { - const QString baseName = "qcplt_" + QLocale(locale).name(); - if (translator.load(":/i18n/" + baseName)) { - app.installTranslator(&translator); - break; - } - } - - QQmlApplicationEngine engine; - const QUrl url(u"qrc:/qcplt/main.qml"_qs); - QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, - &app, [url](QObject *obj, const QUrl &objUrl) { - if (!obj && url == objUrl) - QCoreApplication::exit(-1); - }, Qt::QueuedConnection); - engine.load(url); - - return app.exec(); -} diff --git a/source/qml/main.qml b/source/qml/main.qml deleted file mode 100644 index 41424f8..0000000 --- a/source/qml/main.qml +++ /dev/null @@ -1,8 +0,0 @@ -import QtQuick - -Window { - width: 640 - height: 480 - visible: true - title: qsTr("Hello World") -} diff --git a/src/QCplt/Qml/NodeCanvas.cpp b/src/QCplt/Qml/NodeCanvas.cpp new file mode 100644 index 0000000..4c53a5e --- /dev/null +++ b/src/QCplt/Qml/NodeCanvas.cpp @@ -0,0 +1 @@ +#include "NodeCanvas.hpp" diff --git a/src/QCplt/Qml/NodeCanvas.hpp b/src/QCplt/Qml/NodeCanvas.hpp new file mode 100644 index 0000000..6f70f09 --- /dev/null +++ b/src/QCplt/Qml/NodeCanvas.hpp @@ -0,0 +1 @@ +#pragma once diff --git a/src/QCplt/Qml/README.md b/src/QCplt/Qml/README.md new file mode 100644 index 0000000..379e257 --- /dev/null +++ b/src/QCplt/Qml/README.md @@ -0,0 +1 @@ +All .hpp and .cpp files in this folder are passed to Qt's buildsystem as QML source files, using CMake `file(GLOB_RECURSE)` diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..c8fb06f --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include + +int main(int argc, char* argv[]) +{ + QGuiApplication app(argc, argv); + + QTranslator translator; + QStringList uiLanguages = QLocale::system().uiLanguages(); + for (const QString& locale : uiLanguages) { + const QString baseName = "qcplt_" + QLocale(locale).name(); + if (translator.load(":/i18n/" + baseName)) { + app.installTranslator(&translator); + break; + } + } + + QQmlApplicationEngine engine; + QUrl url(u"qrc:/QCplt/qml/MainWindow.qml"_qs); + QObject::connect( + &engine, + &QQmlApplicationEngine::objectCreated, + &app, + [url](QObject* obj, const QUrl& objUrl) { + if (!obj && url == objUrl) { + QCoreApplication::exit(-1); + } + }, + Qt::QueuedConnection); + engine.load(url); + + return app.exec(); +} -- cgit v1.2.3-70-g09d2