Skip to content

Commit

Permalink
Code filters and slight doxygen changes (#3)
Browse files Browse the repository at this point in the history
* Utility icons script for Windows

* Adds QoL conan scripts

* Better doxygen for libraries

Disables source view, adds alphabetical indexing and removes "referenced by" text. Doxygen for development haven't been touched.

* Force line endings as LF

This should also fix the UnixScripts "bad interpreter" error, but the correction scripts won't be removed anyways and an entry in README about the error will be added in the future

* Adds another resource

As an example how to add multiple entries, for those who are not familiar with CMake syntax

* Changed Exceptions' files structure

Exception code files are now in separate folder

* Adds code filters

* Adds code filters usage to README

Also CMakeLists.txt most important lines are now mentioned for simpler navigation
  • Loading branch information
LightTab2 authored Mar 25, 2024
1 parent 44f2bc1 commit d4ce441
Show file tree
Hide file tree
Showing 14 changed files with 222 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
54 changes: 54 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,37 @@ foreach(library IN LISTS BOOST_COMPONENTS)
endif()
endforeach()

# Create code filters
# For source code
file(GLOB_RECURSE SOURCES "src/*.cpp" "src/*.h" "src/*.ui")
foreach(SOURCE ${SOURCES})
get_filename_component(SOURCE_DIR "${SOURCE}" DIRECTORY)
file(RELATIVE_PATH SOURCE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ${SOURCE_DIR})
string(REPLACE "src" "Source Files" SOURCE_PATH "${SOURCE_PATH}")
source_group("${SOURCE_PATH}" FILES ${SOURCE})
endforeach()
# For resources
file(GLOB_RECURSE SOURCES "*.rc" "*.qrc")
foreach(SOURCE ${SOURCES})
source_group("Resources" FILES ${SOURCE})
endforeach()
source_group("Resources" FILES
"${CMAKE_BINARY_DIR}/.rcc/resources.qrc"
"${CMAKE_BINARY_DIR}/.rcc/qrc_resources.cpp")

# For autogenerated by Qt ui_[name].h files for every src/*.ui file
file(GLOB_RECURSE SOURCES "src/*.ui")
foreach(SOURCE ${SOURCES})
get_filename_component(FILE_NAME ${SOURCE} NAME_WE) # Extract file name without extension
file(RELATIVE_PATH SOURCE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ${SOURCE})
string(REPLACE "${FILE_NAME}.ui" "" FILE_PATH "${SOURCE_PATH}" )
source_group("Autogen/ui/${FILE_NAME}" FILES
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_autogen/include_Debug/${FILE_PATH}ui_${FILE_NAME}.h"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_autogen/include_MinSizeRel/${FILE_PATH}ui_${FILE_NAME}.h"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_autogen/include_Release/${FILE_PATH}ui_${FILE_NAME}.h"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_autogen/include_RelWithDebInfo/${FILE_PATH}ui_${FILE_NAME}.h")
endforeach()

# Resources
include(cmake/Resources.cmake)
string(REPLACE "-" "_" QML_URI "${PROJECT_NAME}")
Expand All @@ -171,6 +202,29 @@ else()
FILES ${RESOURCES})
endif()

# For autogenerated by Qt stamp files
source_group("Autogen/autouic" FILES
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_LIB_autogen/autouic_Debug.stamp"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_LIB_autogen/autouic_MinSizeRel.stamp"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_LIB_autogen/autouic_Release.stamp"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_LIB_autogen/autouic_RelWithDebInfo.stamp" )

# For autogenerated by Qt stamp files
source_group("Autogen/autouic" FILES
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_autogen/autouic_Debug.stamp"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_autogen/autouic_MinSizeRel.stamp"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_autogen/autouic_Release.stamp"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_autogen/autouic_RelWithDebInfo.stamp" )

# For autogenerated by Qt MOC files
source_group("Autogen/moc" FILES
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_autogen/mocs_compilation_Debug.cpp"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_autogen/mocs_compilation_MinSizeRel.cpp"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_autogen/mocs_compilation_Release.cpp"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_autogen/mocs_compilation_RelWithDebInfo.cpp")

source_group("CMake Rules" FILES "CMakeLists.txt")

# Provide alias to library for
if(${PROJECT_NAME}_BUILD_EXECUTABLE)
add_executable(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
Expand Down
111 changes: 106 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ Example:
set(BOOST_COMPONENTS filesystem)
```

Modify `CMakeLists.txt` and after `include(cmake/Modules.cmake)` add following code:
Modify `CMakeLists.txt` and after line `7`: `include(cmake/Modules.cmake)` add following code:

```cmake
foreach(library IN LISTS {NEW_VARIABLE_WITH_COMPONENTS})
Expand All @@ -209,7 +209,7 @@ foreach(library IN LISTS BOOST_COMPONENTS)
endforeach()
```

In the **same file**, after `# Link libraries` add following code:
In the **same file**, after line `135`: `# Link libraries` add following code:

```cmake
foreach(library IN LISTS {NEW_VARIABLE_WITH_COMPONENTS})
Expand All @@ -231,7 +231,7 @@ foreach(library IN LISTS BOOST_COMPONENTS)
endforeach()
```

You should also link the library to the **test** projects. To do that, modify `test/CMakeLists.txt` and after `# Link libraries` add following code:
You should also link the library to the **test** projects. To do that, modify `test/CMakeLists.txt` and after line `53`: `# Link libraries` add following code:

```cmake
foreach(library IN LISTS {NEW_VARIABLE_WITH_COMPONENTS})
Expand Down Expand Up @@ -382,7 +382,7 @@ conan profile new default --detect

Put your **icon image** in **PNG** format into a folder `icon/` and **rename** it, so it matches this convention:

```ini
```
icon_[width]x[height].png
```

Expand Down Expand Up @@ -433,7 +433,7 @@ sudo apt install icnsutils
<hr>
</details>

<details><summary>Docs shouldn't contain <b>private</b> members</summary>
<details><summary>Docs shouldn't contain <b>private</b> members and <b>source code</b></summary>

If your project is a library, you might not want to add the **private** and **protected** members to your documentation. Editing one line in `.github/workflows/doxygen.yml` can change this behaviour. Find this step:

Expand Down Expand Up @@ -462,6 +462,107 @@ And change it to:
<hr>
</details>

<details><summary>"/bin/bash^M: bad interpreter: No such file or directory"</summary>

If you downloaded the project on *Windows* and try to run these scripts in Unix, you might encounter:
*`-bash: ./createIcns.sh: /bin/bash^M: bad interpreter: No such file or directory`*

Run `icon/WinScripts/fixUnixScripts.ps1`
Or some tool like **dos2unix**.
On *Ubuntu* you can install it by:

```bash
sudo apt install dos2unix
```

And then simply run (assuming you are at `qt-template/`):

```bash
dos2unix ./icon/UnixScripts/*.sh
```

<hr>
</details>

<details><summary>Add/change/remove custom filter </summary>

At line `174` of `CMakeLists.txt` you can modify following code for **filters** to change or remove them:

<details><summary>The code</summary>

```cmake
# Create code filters
# For source code
file(GLOB_RECURSE SOURCES "src/*.cpp" "src/*.h" "src/*.ui")
foreach(SOURCE ${SOURCES})
get_filename_component(SOURCE_DIR "${SOURCE}" DIRECTORY)
file(RELATIVE_PATH SOURCE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ${SOURCE_DIR})
string(REPLACE "src" "Source Files" SOURCE_PATH "${SOURCE_PATH}")
source_group("${SOURCE_PATH}" FILES ${SOURCE})
endforeach()
# For resources
file(GLOB_RECURSE SOURCES "*.rc" "*.qrc")
foreach(SOURCE ${SOURCES})
source_group("Resources" FILES ${SOURCE})
endforeach()
source_group("Resources" FILES
"${CMAKE_BINARY_DIR}/.rcc/resources.qrc"
"${CMAKE_BINARY_DIR}/.rcc/qrc_resources.cpp")
# For autogenerated by Qt ui_[name].h files for every src/*.ui file
file(GLOB_RECURSE SOURCES "src/*.ui")
foreach(SOURCE ${SOURCES})
get_filename_component(FILE_NAME ${SOURCE} NAME_WE) # Extract file name without extension
file(RELATIVE_PATH SOURCE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ${SOURCE})
string(REPLACE "${FILE_NAME}.ui" "" FILE_PATH "${SOURCE_PATH}" )
source_group("Autogen/ui/${FILE_NAME}" FILES
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_autogen/include_Debug/${FILE_PATH}ui_${FILE_NAME}.h"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_autogen/include_MinSizeRel/${FILE_PATH}ui_${FILE_NAME}.h"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_autogen/include_Release/${FILE_PATH}ui_${FILE_NAME}.h"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_autogen/include_RelWithDebInfo/${FILE_PATH}ui_${FILE_NAME}.h")
endforeach()
# For autogenerated by Qt stamp files
source_group("Autogen/autouic" FILES
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_LIB_autogen/autouic_Debug.stamp"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_LIB_autogen/autouic_MinSizeRel.stamp"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_LIB_autogen/autouic_Release.stamp"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_LIB_autogen/autouic_RelWithDebInfo.stamp" )
# For autogenerated by Qt stamp files
source_group("Autogen/autouic" FILES
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_autogen/autouic_Debug.stamp"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_autogen/autouic_MinSizeRel.stamp"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_autogen/autouic_Release.stamp"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_autogen/autouic_RelWithDebInfo.stamp" )
# For autogenerated by Qt MOC files
source_group("Autogen/moc" FILES
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_autogen/mocs_compilation_Debug.cpp"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_autogen/mocs_compilation_MinSizeRel.cpp"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_autogen/mocs_compilation_Release.cpp"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_autogen/mocs_compilation_RelWithDebInfo.cpp")
source_group("CMake Rules" FILES "CMakeLists.txt")
```

</details>

You can add your own filters after line `226` in `CMakeLists.txt`, by adding:

```cmake
source_group("[FILTER_NAME]" FILES "[FILE_PATHS]")
```

Example:

```cmake
source_group("birds" FILES "src/flamingo.ui" "src/Birds/crow.h")
```

<hr>
</details>

## Contributing

This project follows these [C++ Core Guidelines](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines), and it would be fun if you followed them too. If you don't, someone will correct your code. An ugly contribution is better than no contribution. **Thanks**!
Expand Down
4 changes: 3 additions & 1 deletion cmake/Resources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ foreach(QML_FILE ${QML_FILES})
QT_RESOURCE_ALIAS ${QML_FILE_PATH})
endforeach()

set(RESOURCES icon/icon_32x32.png)
set(RESOURCES
icon/icon_32x32.png
icon/icon_64x64.png)

# Prepend "../" to each path
foreach(Resource ${RESOURCES})
Expand Down
3 changes: 3 additions & 0 deletions conanLibrariesInstall.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
conan install conan/ --build=missing --settings=build_type=Debug
conan install conan/ --build=missing --settings=build_type=Release
pause
3 changes: 3 additions & 0 deletions conanLibrariesInstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
conan install conan/ --build=missing --settings=build_type=Debug
conan install conan/ --build=missing --settings=build_type=Release
8 changes: 4 additions & 4 deletions doxygen/Doxyfile_dev
Original file line number Diff line number Diff line change
Expand Up @@ -1161,13 +1161,13 @@ FORTRAN_COMMENT_AFTER = 72
# also VERBATIM_HEADERS is set to NO.
# The default value is: NO.

SOURCE_BROWSER = YES
SOURCE_BROWSER = NO

# Setting the INLINE_SOURCES tag to YES will include the body of functions,
# classes and enums directly into the documentation.
# The default value is: NO.

INLINE_SOURCES = YES
INLINE_SOURCES = NO

# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any
# special comment blocks from generated source code fragments. Normal C, C++ and
Expand All @@ -1180,7 +1180,7 @@ STRIP_CODE_COMMENTS = YES
# entity all documented functions referencing it will be listed.
# The default value is: NO.

REFERENCED_BY_RELATION = YES
REFERENCED_BY_RELATION = NO

# If the REFERENCES_RELATION tag is set to YES then for each documented function
# all documented entities called/used by that function will be listed.
Expand Down Expand Up @@ -1285,7 +1285,7 @@ CLANG_DATABASE_PATH =
# classes, structs, unions or interfaces.
# The default value is: YES.

ALPHABETICAL_INDEX = NO
ALPHABETICAL_INDEX = YES

# The IGNORE_PREFIX tag can be used to specify a prefix (or a list of prefixes)
# that should be ignored while generating the index headers. The IGNORE_PREFIX
Expand Down
43 changes: 43 additions & 0 deletions icon/WinScripts/fixUnixScripts.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
$targetPaths = @(
"..\UnixScripts",
"..\..\conanLibrariesInstall.sh"
)

foreach ($targetPath in $targetPaths) {
if (-not (Test-Path -Path $targetPath)) {
Write-Host "The target path '$targetPath' does not exist."
continue
}

if ((Get-Item $targetPath).PSIsContainer) {
# Process a directory
Get-ChildItem -Path $targetPath | ForEach-Object {
$file = $_.FullName
Write-Host "Processing file: $file"

# Read the content of the file and replace carriage return characters with empty strings
$content = Get-Content -Path $file -Raw
$content = $content -replace "\r", ""

# Write the modified content back to the same file without adding a newline at the end
Set-Content -Path $file -Value $content -NoNewline
}

Write-Host "All carriage return characters removed from files in $targetPath."
}
else {
# Process a single file
$file = $targetPath
Write-Host "Processing file: $file"

# Read the content of the file and replace carriage return characters with empty strings
$content = Get-Content -Path $file -Raw
$content = $content -replace "\r", ""

# Write the modified content back to the same file without adding a newline at the end
Set-Content -Path $file -Value $content -NoNewline

Write-Host "All carriage return characters removed from $file."
}
}
Pause
2 changes: 1 addition & 1 deletion src/Exceptions.cpp → src/Exceptions/Exceptions.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "Exceptions.h"
#include "Exceptions.h"

//QML
//QObject* AppException::exceptionMessage = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions.h → src/Exceptions/Exceptions.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once

#include <QDebug>
#include <QException>
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <QApplication>
#include <boost/filesystem.hpp>

#include "Exceptions.h"
#include "Exceptions/Exceptions.h"

int main(int argc, char* argv[])
{
Expand Down
2 changes: 1 addition & 1 deletion src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <boost/multiprecision/integer.hpp>

#include "Exceptions.h"
#include "Exceptions/Exceptions.h"

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent),
Expand Down
2 changes: 1 addition & 1 deletion src/mainwindow.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once
#include <QMainWindow>

QT_BEGIN_NAMESPACE
Expand Down
Empty file.

0 comments on commit d4ce441

Please sign in to comment.