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

Cppcheck & clang-tidy fixes #744

Merged
merged 6 commits into from
Feb 21, 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
# Webkit style was loosely based on the Qt style
BasedOnStyle: WebKit

Standard: c++14
Standard: c++17

# Column width is limited to 100 in accordance with Qt Coding Style.
# Column width is normally 100 in the Qt Coding Style, but this is way too low.
# https://wiki.qt.io/Qt_Coding_Style
# Note that this may be changed at some point in the future.
ColumnLimit: 100
ColumnLimit: 160
# How much weight do extra characters after the line length limit have.
# PenaltyExcessCharacter: 4

Expand Down Expand Up @@ -82,7 +81,16 @@ AllowShortFunctionsOnASingleLine: Inline
SortIncludes: false

# macros for which the opening brace stays attached.
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH, forever, Q_FOREVER, QBENCHMARK, QBENCHMARK_ONCE ]
ForEachMacros:
[
foreach,
Q_FOREACH,
BOOST_FOREACH,
forever,
Q_FOREVER,
QBENCHMARK,
QBENCHMARK_ONCE,
]

# Break constructor initializers before the colon and after the commas.
BreakConstructorInitializers: BeforeColon
Expand All @@ -109,4 +117,4 @@ SpaceBeforeCpp11BracedList: false
# Custom styles added by this project

# fix for https://bugreports.qt.io/browse/QTCREATORBUG-31858
StatementAttributeLikeMacros: [emit, Q_EMIT]
StatementAttributeLikeMacros: [emit, Q_EMIT]
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ set(SOURCES
${PROJECT_SOURCE_DIR}/src/elidedlabel.h
${PROJECT_SOURCE_DIR}/src/foldertreedelegateeditor.cpp
${PROJECT_SOURCE_DIR}/src/foldertreedelegateeditor.h
${PROJECT_SOURCE_DIR}/src/fontloader.cpp
${PROJECT_SOURCE_DIR}/src/fontloader.h
${PROJECT_SOURCE_DIR}/src/labeledittype.cpp
${PROJECT_SOURCE_DIR}/src/labeledittype.h
Expand Down Expand Up @@ -183,6 +182,7 @@ set(SOURCES
${PROJECT_SOURCE_DIR}/src/trashbuttondelegateeditor.h
${PROJECT_SOURCE_DIR}/src/treeviewlogic.cpp
${PROJECT_SOURCE_DIR}/src/treeviewlogic.h
${PROJECT_SOURCE_DIR}/src/utils.h
# ui
${PROJECT_SOURCE_DIR}/src/aboutwindow.ui
${PROJECT_SOURCE_DIR}/src/mainwindow.ui
Expand Down
61 changes: 28 additions & 33 deletions src/aboutwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
/**
* Initializes the window components and configures the AboutWindow
*/
AboutWindow::AboutWindow(QWidget *parent)
: QDialog(parent), m_ui(new Ui::AboutWindow), m_isProVersion(false)
AboutWindow::AboutWindow(QWidget *parent) : QDialog(parent), m_ui(new Ui::AboutWindow), m_isProVersion(false)
{
m_ui->setupUi(this);
setWindowTitle(tr("About") + " " + QCoreApplication::applicationName());
Expand All @@ -22,13 +21,10 @@ AboutWindow::AboutWindow(QWidget *parent)
m_ui->aboutText->setTextColor(QColor(26, 26, 26));

#ifdef __APPLE__
QFont fontToUse = QFont(QStringLiteral("SF Pro Text")).exactMatch()
? QStringLiteral("SF Pro Text")
: QStringLiteral("Roboto");
QFont fontToUse = QFont(QStringLiteral("SF Pro Text")).exactMatch() ? QStringLiteral("SF Pro Text") : QStringLiteral("Roboto");
m_ui->aboutText->setFont(fontToUse);
#elif _WIN32
QFont fontToUse = QFont(QStringLiteral("Segoe UI")).exactMatch() ? QStringLiteral("Segoe UI")
: QStringLiteral("Roboto");
QFont fontToUse = QFont(QStringLiteral("Segoe UI")).exactMatch() ? QStringLiteral("Segoe UI") : QStringLiteral("Roboto");
m_ui->aboutText->setFont(fontToUse);
#else
m_ui->aboutText->setFont(QFont(QStringLiteral("Roboto")));
Expand Down Expand Up @@ -57,34 +53,33 @@ void AboutWindow::setAboutText()
{
QString proVersionText = m_isProVersion ? " (Pro Version)" : "";

m_ui->aboutText->setText(
"<strong>Version:</strong> " + QCoreApplication::applicationVersion() + proVersionText
+ "<p>Notes was founded by <a href='https://rubymamistvalove.com'>Ruby "
"Mamistvalove</a>, "
"to create an elegant yet powerful cross-platform and open-source note-taking "
"app.</p><a href='https://www.notes-foss.com'>Notes Website"
"</a><br/><a href='https://github.com/nuttyartist/notes'>Source code on "
"Github</a><br/><a "
"href='https://www.notes-foss.com/notes-app-terms-privacy-policy'>Terms and Privacy "
"Policy</a><br/><br/><strong>Acknowledgments</strong><br/>This project couldn't "
"have "
"come this far without the help of these amazing "
"people:<br/><br/><strong>Programmers:</strong><br/>Alex Spataru<br/>Ali Diouri"
"<br/>David Planella<br/>Diep Ngoc<br/>Guilherme "
"Silva<br/>Thorbjørn Lindeijer<br/>Tuur Vanhoutte<br/>Waqar "
"Ahmed<br/><br/><strong>Designers:</strong><br/>Kevin Doyle<br/><br/>And to the "
"many of our beloved users who keep sending us feedback, you are an essential force "
"in "
"helping us improve, thank you!<br/><br/><strong>Notes makes use of the following "
"third-party libraries:</strong><br/><br/>QMarkdownTextEdit<br/>"
m_ui->aboutText->setText("<strong>Version:</strong> " + QCoreApplication::applicationVersion() + proVersionText
+ "<p>Notes was founded by <a href='https://rubymamistvalove.com'>Ruby "
"Mamistvalove</a>, "
"to create an elegant yet powerful cross-platform and open-source note-taking "
"app.</p><a href='https://www.notes-foss.com'>Notes Website"
"</a><br/><a href='https://github.com/nuttyartist/notes'>Source code on "
"Github</a><br/><a "
"href='https://www.notes-foss.com/notes-app-terms-privacy-policy'>Terms and Privacy "
"Policy</a><br/><br/><strong>Acknowledgments</strong><br/>This project couldn't "
"have "
"come this far without the help of these amazing "
"people:<br/><br/><strong>Programmers:</strong><br/>Alex Spataru<br/>Ali Diouri"
"<br/>David Planella<br/>Diep Ngoc<br/>Guilherme "
"Silva<br/>Thorbjørn Lindeijer<br/>Tuur Vanhoutte<br/>Waqar "
"Ahmed<br/><br/><strong>Designers:</strong><br/>Kevin Doyle<br/><br/>And to the "
"many of our beloved users who keep sending us feedback, you are an essential force "
"in "
"helping us improve, thank you!<br/><br/><strong>Notes makes use of the following "
"third-party libraries:</strong><br/><br/>QMarkdownTextEdit<br/>"
#if defined(UPDATE_CHECKER)
"QSimpleUpdater<br/>"
"QSimpleUpdater<br/>"
#endif
"QAutostart<br/>QXT<br/><br/><strong>Notes makes use of the following open source "
"fonts:</strong><br/><br/>Roboto<br/>Source Sans Pro<br/>Trykker<br/>Mate<br/>iA "
"Writer Mono<br/>iA Writer Duo<br/>iA Writer "
"Quattro<br/>Font Awesome<br/>Material Symbols<br/><br/><strong>Qt version:</strong> "
+ qVersion() + " (built with " + QT_VERSION_STR + ")");
"QAutostart<br/>QXT<br/><br/><strong>Notes makes use of the following open source "
"fonts:</strong><br/><br/>Roboto<br/>Source Sans Pro<br/>Trykker<br/>Mate<br/>iA "
"Writer Mono<br/>iA Writer Duo<br/>iA Writer "
"Quattro<br/>Font Awesome<br/>Material Symbols<br/><br/><strong>Qt version:</strong> "
+ qVersion() + " (built with " + QT_VERSION_STR + ")");
}

void AboutWindow::setTheme(Theme::Value theme)
Expand Down
6 changes: 3 additions & 3 deletions src/aboutwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <QDialog>
#include "editorsettingsoptions.h"

namespace Ui {
namespace Ui { // NOLINT(readability-identifier-naming)
class AboutWindow;
}

Expand All @@ -13,8 +13,8 @@ class AboutWindow : public QDialog
Q_OBJECT

public:
explicit AboutWindow(QWidget *parent = 0);
~AboutWindow();
explicit AboutWindow(QWidget *parent = nullptr);
~AboutWindow() override;
void setTheme(Theme::Value theme);
void setProVersion(bool isProVersion);

Expand Down
27 changes: 10 additions & 17 deletions src/allnotebuttontreedelegateeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,15 @@
#include "editorsettingsoptions.h"
#include "fontloader.h"

AllNoteButtonTreeDelegateEditor::AllNoteButtonTreeDelegateEditor(QTreeView *view,
const QStyleOptionViewItem &option,
const QModelIndex &index,
QListView *listView,
QWidget *parent)
AllNoteButtonTreeDelegateEditor::AllNoteButtonTreeDelegateEditor(QTreeView *view, const QStyleOptionViewItem &option, const QModelIndex &index,
QListView *listView, QWidget *parent)
: QWidget(parent),
m_option(option),
m_index(index),
#ifdef __APPLE__
m_displayFont(QFont(QStringLiteral("SF Pro Text")).exactMatch()
? QStringLiteral("SF Pro Text")
: QStringLiteral("Roboto")),
m_displayFont(QFont(QStringLiteral("SF Pro Text")).exactMatch() ? QStringLiteral("SF Pro Text") : QStringLiteral("Roboto")),
#elif _WIN32
m_displayFont(QFont(QStringLiteral("Segoe UI")).exactMatch() ? QStringLiteral("Segoe UI")
: QStringLiteral("Roboto")),
m_displayFont(QFont(QStringLiteral("Segoe UI")).exactMatch() ? QStringLiteral("Segoe UI") : QStringLiteral("Roboto")),
#else
m_displayFont(QStringLiteral("Roboto")),
#endif
Expand All @@ -41,15 +35,16 @@ AllNoteButtonTreeDelegateEditor::AllNoteButtonTreeDelegateEditor(QTreeView *view
m_numberOfNotesColor(26, 26, 26, 127),
m_numberOfNotesSelectedColor(255, 255, 255),
m_view(view),
m_listView(listView)
m_listView(listView),
m_theme(Theme::Light)
{
setContentsMargins(0, 0, 0, 0);
}

void AllNoteButtonTreeDelegateEditor::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
auto iconRect = QRect(rect().x() + 22, rect().y() + (rect().height() - 20) / 2, 18, 20);
auto iconRect = QRect(rect().x() + 22, rect().y() + ((rect().height() - 20) / 2), 18, 20);
auto iconPath = m_index.data(NodeItem::Roles::Icon).toString();
auto displayName = m_index.data(NodeItem::Roles::DisplayText).toString();
QRect nameRect(rect());
Expand All @@ -59,7 +54,7 @@ void AllNoteButtonTreeDelegateEditor::paintEvent(QPaintEvent *event)
painter.fillRect(rect(), QBrush(m_activeColor));
painter.setPen(m_titleSelectedColor);
} else {
auto listView = dynamic_cast<NoteListView *>(m_listView);
auto const *listView = static_cast<NoteListView *>(m_listView);
if (listView->isDragging()) {
if (m_theme == Theme::Dark) {
painter.fillRect(rect(), QBrush(QColor(35, 52, 69)));
Expand All @@ -76,8 +71,7 @@ void AllNoteButtonTreeDelegateEditor::paintEvent(QPaintEvent *event)
#else
int iconPointSizeOffset = -4;
#endif
painter.setFont(FontLoader::getInstance().loadFont("Material Symbols Outlined", "",
16 + iconPointSizeOffset));
painter.setFont(font_loader::loadFont("Material Symbols Outlined", "", 16 + iconPointSizeOffset));
painter.drawText(iconRect, iconPath); // folder

if (m_view->selectionModel()->isSelected(m_index)) {
Expand All @@ -98,8 +92,7 @@ void AllNoteButtonTreeDelegateEditor::paintEvent(QPaintEvent *event)
painter.setPen(m_numberOfNotesColor);
}
painter.setFont(m_numberOfNotesFont);
painter.drawText(childCountRect, Qt::AlignHCenter | Qt::AlignVCenter,
QString::number(childCount));
painter.drawText(childCountRect, Qt::AlignHCenter | Qt::AlignVCenter, QString::number(childCount));
QWidget::paintEvent(event);
}

Expand Down
5 changes: 2 additions & 3 deletions src/allnotebuttontreedelegateeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ class AllNoteButtonTreeDelegateEditor : public QWidget
{
Q_OBJECT
public:
explicit AllNoteButtonTreeDelegateEditor(QTreeView *view, const QStyleOptionViewItem &option,
const QModelIndex &index, QListView *listView,
explicit AllNoteButtonTreeDelegateEditor(QTreeView *view, const QStyleOptionViewItem &option, const QModelIndex &index, QListView *listView,
QWidget *parent = nullptr);
void setTheme(Theme::Value theme);

Expand All @@ -37,7 +36,7 @@ class AllNoteButtonTreeDelegateEditor : public QWidget
Theme::Value m_theme;
// QWidget interface
protected:
virtual void paintEvent(QPaintEvent *event) override;
void paintEvent(QPaintEvent *event) override;
};

#endif // ALLNOTEBUTTONTREEDELEGATEEDITOR_H
8 changes: 4 additions & 4 deletions src/customDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class CustomDocument : public QTextEdit
Q_OBJECT

public:
CustomDocument(QWidget *parent = nullptr);
explicit CustomDocument(QWidget *parent);
void setDocumentPadding(int left, int top, int right, int bottom);
bool eventFilter(QObject *obj, QEvent *event);
bool eventFilter(QObject *obj, QEvent *event) override;
bool openLinkAtCursorPosition();
QString getMarkdownUrlAtPosition(const QString &text, int position);
bool isValidUrl(const QString &urlString);
Expand All @@ -27,8 +27,8 @@ class CustomDocument : public QTextEdit

// QWidget interface
protected:
void resizeEvent(QResizeEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void resizeEvent(QResizeEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;

QStringList _ignoredClickUrlSchemata;
};
Expand Down
32 changes: 11 additions & 21 deletions src/customMarkdownHighlighter.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include "customMarkdownHighlighter.h"
#include "editorsettingsoptions.h"

CustomMarkdownHighlighter::CustomMarkdownHighlighter(QTextDocument *parent,
HighlightingOptions highlightingOptions)
CustomMarkdownHighlighter::CustomMarkdownHighlighter(QTextDocument *parent, HighlightingOptions highlightingOptions)
: MarkdownHighlighter(parent, highlightingOptions)
{
setListsColor(QColor(35, 131, 226)); // accent color
Expand Down Expand Up @@ -34,16 +33,13 @@ void CustomMarkdownHighlighter::setFontSize(qreal fontSize)
}

qreal codeBlockFontSize = fontSize - 4;
_formats[static_cast<HighlighterState>(HighlighterState::InlineCodeBlock)].setFontPointSize(
codeBlockFontSize);
_formats[static_cast<HighlighterState>(HighlighterState::InlineCodeBlock)].setFontPointSize(codeBlockFontSize);
}

void CustomMarkdownHighlighter::setListsColor(QColor color)
{
_formats[static_cast<HighlighterState>(HighlighterState::CheckBoxUnChecked)].setForeground(
color);
_formats[static_cast<HighlighterState>(HighlighterState::CheckBoxChecked)].setForeground(
QColor(90, 113, 140));
_formats[static_cast<HighlighterState>(HighlighterState::CheckBoxUnChecked)].setForeground(color);
_formats[static_cast<HighlighterState>(HighlighterState::CheckBoxChecked)].setForeground(QColor(90, 113, 140));
_formats[static_cast<HighlighterState>(HighlighterState::List)].setForeground(color);
_formats[static_cast<HighlighterState>(HighlighterState::BlockQuote)].setForeground(color);
}
Expand All @@ -53,25 +49,19 @@ void CustomMarkdownHighlighter::setTheme(Theme::Value theme, QColor textColor, q
setHeaderColors(textColor);
setFontSize(fontSize);

auto &icBlock = _formats[static_cast<HighlighterState>(HighlighterState::InlineCodeBlock)];
switch (theme) {
case Theme::Light:
_formats[static_cast<HighlighterState>(HighlighterState::InlineCodeBlock)].setBackground(
QColor(239, 241, 243));
_formats[static_cast<HighlighterState>(HighlighterState::InlineCodeBlock)].setForeground(
QColor(42, 46, 51));
icBlock.setBackground(QColor(239, 241, 243));
icBlock.setForeground(QColor(42, 46, 51));
break;
case Theme::Dark:
_formats[static_cast<HighlighterState>(HighlighterState::InlineCodeBlock)].setBackground(
QColor(52, 57, 66));
_formats[static_cast<HighlighterState>(HighlighterState::InlineCodeBlock)].setForeground(
QColor(230, 237, 243));
icBlock.setBackground(QColor(52, 57, 66));
icBlock.setForeground(QColor(230, 237, 243));
break;
case Theme::Sepia:
_formats[static_cast<HighlighterState>(HighlighterState::InlineCodeBlock)].setBackground(
QColor(239, 241, 243));
_formats[static_cast<HighlighterState>(HighlighterState::InlineCodeBlock)].setForeground(
QColor(42, 46, 51));
break;
icBlock.setBackground(QColor(239, 241, 243));
icBlock.setForeground(QColor(42, 46, 51));
break;
}
}
3 changes: 1 addition & 2 deletions src/customMarkdownHighlighter.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
class CustomMarkdownHighlighter : public MarkdownHighlighter
{
public:
CustomMarkdownHighlighter(QTextDocument *parent = nullptr,
HighlightingOptions highlightingOptions = HighlightingOption::None);
explicit CustomMarkdownHighlighter(QTextDocument *parent, HighlightingOptions highlightingOptions = HighlightingOption::None);
~CustomMarkdownHighlighter() override = default;

void setFontSize(qreal fontSize);
Expand Down
3 changes: 1 addition & 2 deletions src/customapplicationstyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#include <QStyleOption>
#include "editorsettingsoptions.h"

void CustomApplicationStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option,
QPainter *painter, const QWidget *widget) const
void CustomApplicationStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
{
if (element == QStyle::PE_IndicatorItemViewItemDrop) {
painter->setRenderHint(QPainter::Antialiasing, true);
Expand Down
3 changes: 1 addition & 2 deletions src/customapplicationstyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ class CustomApplicationStyle : public QProxyStyle
public:
CustomApplicationStyle();

void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter,
const QWidget *widget) const;
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const override;
void setTheme(Theme::Value theme);

private:
Expand Down
Loading