Skip to content

Commit 6314fda

Browse files
committed
[ref] global: refactore to follow cppcoreguidelines
Refactored the code to follow the cppcoreguidelines defined in the clang-tidy conf file. Several checks are failing due to qApp casting inside qapplication.
1 parent 0bcfe65 commit 6314fda

20 files changed

+192
-70
lines changed

.clang-tidy

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,clang-*,cppcoreguidelines-avoid-c-arrays,cppcoreguidelines-avoid-goto,cppcoreguidelines-avoid-non-const-global-variables,cppcoreguidelines-c-copy-assignment-signature,cppcoreguidelines-explicit-virtual-functions,cppcoreguidelines-interfaces-global-init,cppcoreguidelines-macro-usage,cppcoreguidelines-narrowing-conversions,cppcoreguidelines-no-malloc,cppcoreguidelines-prefer-member-initializer,cppcoreguidelines-pro-bounds-*,cppcoreguidelines-pro-type-const-cast,cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-type-static-cast-downcast,cppcoreguidelines-pro-type-union-access,cppcoreguidelines-pro-type-vararg,cppcoreguidelines-slicing,cppcoreguidelines-special-member-functions'
3+
WarningsAsErrors: ''
4+
HeaderFilterRegex: ''
5+
AnalyzeTemporaryDtors: false
6+
FormatStyle: none
7+
User: bgallois
8+
CheckOptions:
9+
- key: modernize-loop-convert.MinConfidence
10+
value: reasonable
11+
- key: modernize-replace-auto-ptr.IncludeStyle
12+
value: llvm
13+
- key: cppcoreguidelines-no-malloc.Reallocations
14+
value: '::realloc'
15+
- key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctionsWhenCopyIsDeleted
16+
value: 'false'
17+
- key: google-readability-namespace-comments.ShortNamespaceLines
18+
value: '10'
19+
- key: google-readability-namespace-comments.SpacesBeforeComments
20+
value: '2'
21+
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
22+
value: 'true'
23+
- key: cert-dcl16-c.NewSuffixes
24+
value: 'L;LL;LU;LLU'
25+
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
26+
value: 'false'
27+
- key: modernize-loop-convert.MaxCopySize
28+
value: '16'
29+
- key: cppcoreguidelines-narrowing-conversions.WarnOnIntegerNarrowingConversion
30+
value: 'true'
31+
- key: cppcoreguidelines-no-malloc.Allocations
32+
value: '::malloc;::calloc'
33+
- key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctions
34+
value: 'false'
35+
- key: cppcoreguidelines-prefer-member-initializer.UseAssignment
36+
value: 'false'
37+
- key: cppcoreguidelines-macro-usage.CheckCapsOnly
38+
value: 'false'
39+
- key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
40+
value: 'true'
41+
- key: cppcoreguidelines-pro-bounds-constant-array-index.GslHeader
42+
value: ''
43+
- key: cppcoreguidelines-explicit-virtual-functions.FinalSpelling
44+
value: final
45+
- key: llvm-qualified-auto.AddConstToQualified
46+
value: 'false'
47+
- key: modernize-loop-convert.NamingStyle
48+
value: CamelCase
49+
- key: google-readability-function-size.StatementThreshold
50+
value: '800'
51+
- key: llvm-else-after-return.WarnOnConditionVariables
52+
value: 'false'
53+
- key: cppcoreguidelines-narrowing-conversions.IgnoreConversionFromTypes
54+
value: ''
55+
- key: modernize-pass-by-value.IncludeStyle
56+
value: llvm
57+
- key: cert-str34-c.DiagnoseSignedUnsignedCharComparisons
58+
value: 'false'
59+
- key: cppcoreguidelines-explicit-virtual-functions.AllowOverrideAndFinal
60+
value: 'false'
61+
- key: google-readability-braces-around-statements.ShortStatementLines
62+
value: '1'
63+
- key: cppcoreguidelines-explicit-virtual-functions.OverrideSpelling
64+
value: override
65+
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
66+
value: 'false'
67+
- key: modernize-use-nullptr.NullMacros
68+
value: 'NULL'
69+
- key: cppcoreguidelines-no-malloc.Deallocations
70+
value: '::free'
71+
- key: cppcoreguidelines-macro-usage.IgnoreCommandLineMacros
72+
value: 'true'
73+
- key: cppcoreguidelines-pro-bounds-constant-array-index.IncludeStyle
74+
value: llvm
75+
- key: cppcoreguidelines-macro-usage.AllowedRegexp
76+
value: '^DEBUG_*'
77+
- key: cppcoreguidelines-narrowing-conversions.WarnWithinTemplateInstantiation
78+
value: 'false'
79+
- key: cppcoreguidelines-narrowing-conversions.PedanticMode
80+
value: 'false'
81+
- key: cppcoreguidelines-narrowing-conversions.WarnOnFloatingPointNarrowingConversion
82+
value: 'true'
83+
- key: llvm-else-after-return.WarnOnUnfixable
84+
value: 'false'
85+
- key: cppcoreguidelines-narrowing-conversions.WarnOnEquivalentBitWidth
86+
value: 'true'
87+
...
88+

src/annotation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Annotation::Annotation(const QString &filePath) : Annotation() {
8282
/**
8383
* @brief Constructs the annotation object from a file path.
8484
*/
85-
Annotation::Annotation(QWidget *parent) : annotationFile{new QFile()}, annotations{new QMap<int, QString>()}, isActive{false} {
85+
Annotation::Annotation(QWidget *parent) : annotationFile{new QFile()}, annotations{new QMap<int, QString>()}, findIndex{-1}, isActive{false} {
8686
}
8787

8888
/**

src/annotation.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Annotation : public QWidget {
2020
QMap<int, QString> *annotations;
2121
void writeToFile();
2222
QList<int> findIndexes;
23-
int findIndex;
23+
qsizetype findIndex;
2424

2525
public slots:
2626
void clear();
@@ -42,6 +42,8 @@ class Annotation : public QWidget {
4242
Annotation(const QString &annotationFile);
4343
Annotation(const Annotation &T) = delete;
4444
Annotation &operator=(const Annotation &T) = delete;
45+
Annotation &operator=(Annotation &&T) = delete;
46+
Annotation(Annotation &&T) = delete;
4547
~Annotation();
4648
bool setPath(const QString &annotationFile);
4749
bool isActive;

src/autolevel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class AutoLevel : public QObject {
5050
AutoLevel(const string &path, const UMat &background, const QMap<QString, QString> &parameters);
5151
AutoLevel(const AutoLevel &T) = delete;
5252
AutoLevel &operator=(const AutoLevel &T) = delete;
53+
AutoLevel &operator=(AutoLevel &&T) = delete;
54+
AutoLevel(AutoLevel &&T) = delete;
5355
static double stdev(const QList<double> &vect);
5456

5557
public slots:

src/batch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ using namespace std;
4242
* @brief Constructs the Batch widget.
4343
*/
4444
Batch::Batch(QWidget *parent) : QWidget(parent),
45-
ui(new Ui::Batch) {
45+
ui(new Ui::Batch),
46+
currentPathCount(0) {
4647
ui->setupUi(this);
4748

4849
// Setup the ui
@@ -229,7 +230,6 @@ Batch::Batch(QWidget *parent) : QWidget(parent),
229230

230231
// Setups the path panel
231232
ui->tablePath->horizontalHeader()->setStretchLastSection(true);
232-
currentPathCount = 0;
233233
ui->tablePath->setSortingEnabled(false);
234234
ui->tablePath->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
235235
connect(ui->openPath, &QPushButton::clicked, this, &Batch::openPathFolder);

src/batch.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ class Batch : public QWidget {
5252

5353
public:
5454
explicit Batch(QWidget *parent = nullptr);
55+
Batch(const Batch &T) = delete;
56+
Batch &operator=(const Batch &T) = delete;
57+
Batch &operator=(Batch &&T) = delete;
58+
Batch(Batch &&T) = delete;
59+
5560
~Batch();
5661

5762
private:

src/data.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ Data::Data(const QString &dataPath) : Data() {
8888
/**
8989
* @brief Construct the data object from a tracking result file.
9090
*/
91-
Data::Data() : columns{"xHead", "yHead", "tHead", "xTail", "yTail", "tTail", "xBody", "yBody", "tBody", "curvature", "areaBody", "perimeterBody", "headMajorAxisLength", "headMinorAxisLength", "headExcentricity", "tailMajorAxisLength", "tailMinorAxisLength", "tailExcentricity", "bodyMajorAxisLength", "bodyMinorAxisLength", "bodyExcentricity", "imageNumber", "id"}, connectionName{QString("data_%1").arg(QRandomGenerator::global()->generate())} {
92-
isEmpty = true;
91+
Data::Data() : columns{"xHead", "yHead", "tHead", "xTail", "yTail", "tTail", "xBody", "yBody", "tBody", "curvature", "areaBody", "perimeterBody", "headMajorAxisLength", "headMinorAxisLength", "headExcentricity", "tailMajorAxisLength", "tailMinorAxisLength", "tailExcentricity", "bodyMajorAxisLength", "bodyMinorAxisLength", "bodyExcentricity", "imageNumber", "id"}, connectionName{QString("data_%1").arg(QRandomGenerator::global()->generate())}, isEmpty{true} {
9392
QSqlDatabase data = QSqlDatabase::addDatabase(QStringLiteral("QSQLITE"), connectionName);
9493
}
9594

src/data.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class Data {
3333
explicit Data(const QString &dataPath);
3434
Data(const Data &T) = delete;
3535
Data &operator=(const Data &T) = delete;
36+
Data &operator=(Data &&T) = delete;
37+
Data(Data &&T) = delete;
3638
~Data();
3739

3840
const QString connectionName;

src/interactive.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ This file is part of Fast Track.
3939
* @brief Constructs the interactive object derived from a QMainWindow object.
4040
*/
4141
Interactive::Interactive(QWidget *parent) : QMainWindow(parent),
42-
ui(new Ui::Interactive) {
42+
ui(new Ui::Interactive),
43+
videoStatus(false) {
4344
ui->setupUi(this);
4445
ui->menuBar->setNativeMenuBar(false);
4546

4647
// Loads settings
4748
QSettings settingsFile(QStringLiteral("FastTrack"), QStringLiteral("FastTrackOrg"));
48-
videoStatus = false;
4949

5050
// MetaType
5151
qRegisterMetaType<QMap<QString, double>>("QMap<QString, double>");
@@ -462,7 +462,7 @@ Interactive::Interactive(QWidget *parent) : QMainWindow(parent),
462462

463463
// Set the image preview limits
464464
connect(ui->startImage, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, [this](int startImage) {
465-
ui->stopImage->setRange(0, video->getImageCount() - startImage);
465+
ui->stopImage->setRange(0, static_cast<int>(video->getImageCount()) - startImage);
466466
});
467467

468468
// Events filter to zoom in/out in the display
@@ -539,12 +539,12 @@ void Interactive::openFolder() {
539539
memoryDir = dir;
540540
video->open(dir.toStdString());
541541
ui->slider->setMinimum(0);
542-
ui->slider->setMaximum(video->getImageCount() - 1);
542+
ui->slider->setMaximum(static_cast<int>(video->getImageCount()) - 1);
543543
ui->previewButton->setDisabled(true);
544544
ui->trackButton->setDisabled(true);
545-
ui->nBack->setMaximum(video->getImageCount());
546-
ui->nBack->setValue(video->getImageCount());
547-
ui->startImage->setRange(0, video->getImageCount() - 1);
545+
ui->nBack->setMaximum(static_cast<int>(video->getImageCount()));
546+
ui->nBack->setValue(static_cast<int>(video->getImageCount()));
547+
ui->startImage->setRange(0, static_cast<int>(video->getImageCount()) - 1);
548548
ui->startImage->setValue(0);
549549

550550
Mat frame;
@@ -938,7 +938,7 @@ void Interactive::previewTracking() {
938938
*/
939939
void Interactive::track() {
940940
if (videoStatus) {
941-
ui->progressBar->setRange(0, video->getImageCount() - 1);
941+
ui->progressBar->setRange(0, static_cast<int>(video->getImageCount()) - 1);
942942
ui->progressBar->setValue(0);
943943
ui->previewButton->setDisabled(true);
944944
ui->trackButton->setDisabled(true);
@@ -1003,25 +1003,25 @@ bool Interactive::eventFilter(QObject *target, QEvent *event) {
10031003
if (target == ui->display) {
10041004
// Set the first point for the ROI at user click
10051005
if (event->type() == QEvent::MouseButtonPress) {
1006-
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
1006+
QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent *>(event);
10071007
if (mouseEvent->buttons() == Qt::LeftButton) {
10081008
clicks.first = mouseEvent->pos();
10091009
// The QPixmap is V/Hcentered in the Qlabel widget
10101010
// Gets the click coordinate in the frame of reference of the centered display
1011-
clicks.first.setX(static_cast<unsigned int>(clicks.first.x() - 0.5 * (ui->display->width() - resizedFrame.width())));
1012-
clicks.first.setY(static_cast<unsigned int>(clicks.first.y() - 0.5 * (ui->display->height() - resizedFrame.height())));
1011+
clicks.first.setX(static_cast<int>(clicks.first.x() - 0.5 * (ui->display->width() - resizedFrame.width())));
1012+
clicks.first.setY(static_cast<int>(clicks.first.y() - 0.5 * (ui->display->height() - resizedFrame.height())));
10131013
}
10141014
}
10151015

10161016
// Sets the second point and draw the roi
10171017
if (event->type() == QEvent::MouseMove) {
1018-
QMouseEvent *moveEvent = static_cast<QMouseEvent *>(event);
1018+
QMouseEvent *moveEvent = dynamic_cast<QMouseEvent *>(event);
10191019
if (moveEvent->buttons() == Qt::LeftButton) {
10201020
clicks.second = moveEvent->pos();
10211021
// The QPixmap is V/Hcentered in the Qlabel widget
10221022
// Gets the click coordinate in the frame of reference of the centered display
1023-
clicks.second.setX(static_cast<unsigned int>(clicks.second.x() - 0.5 * (ui->display->width() - resizedFrame.width())));
1024-
clicks.second.setY(static_cast<unsigned int>(clicks.second.y() - 0.5 * (ui->display->height() - resizedFrame.height())));
1023+
clicks.second.setX(static_cast<int>(clicks.second.x() - 0.5 * (ui->display->width() - resizedFrame.width())));
1024+
clicks.second.setY(static_cast<int>(clicks.second.y() - 0.5 * (ui->display->height() - resizedFrame.height())));
10251025

10261026
// Draws the ROI with
10271027
QPixmap tmpImage = resizedPix;
@@ -1065,21 +1065,21 @@ bool Interactive::eventFilter(QObject *target, QEvent *event) {
10651065
if (target == ui->scrollArea->viewport()) {
10661066
// Moves in the image by middle click
10671067
if (event->type() == QEvent::MouseMove) {
1068-
QMouseEvent *moveEvent = static_cast<QMouseEvent *>(event);
1068+
QMouseEvent *moveEvent = dynamic_cast<QMouseEvent *>(event);
10691069
if (moveEvent->buttons() == Qt::MiddleButton) {
1070-
ui->scrollArea->horizontalScrollBar()->setValue(static_cast<unsigned int>(ui->scrollArea->horizontalScrollBar()->value() + (panReferenceClick.x() - moveEvent->localPos().x())));
1071-
ui->scrollArea->verticalScrollBar()->setValue(static_cast<unsigned int>(ui->scrollArea->verticalScrollBar()->value() + (panReferenceClick.y() - moveEvent->localPos().y())));
1070+
ui->scrollArea->horizontalScrollBar()->setValue(static_cast<int>(ui->scrollArea->horizontalScrollBar()->value() + (panReferenceClick.x() - moveEvent->localPos().x())));
1071+
ui->scrollArea->verticalScrollBar()->setValue(static_cast<int>(ui->scrollArea->verticalScrollBar()->value() + (panReferenceClick.y() - moveEvent->localPos().y())));
10721072
panReferenceClick = moveEvent->localPos();
10731073
}
10741074
}
10751075
if (event->type() == QEvent::Wheel) {
1076-
QWheelEvent *wheelEvent = static_cast<QWheelEvent *>(event);
1076+
QWheelEvent *wheelEvent = dynamic_cast<QWheelEvent *>(event);
10771077
zoomReferencePosition = wheelEvent->position();
10781078
}
10791079

10801080
// Zoom/unzoom the display by wheel
10811081
if (event->type() == QEvent::Wheel) {
1082-
QWheelEvent *wheelEvent = static_cast<QWheelEvent *>(event);
1082+
QWheelEvent *wheelEvent = dynamic_cast<QWheelEvent *>(event);
10831083
if (wheelEvent->angleDelta().y() > 0) {
10841084
zoomIn();
10851085
}
@@ -1089,7 +1089,7 @@ bool Interactive::eventFilter(QObject *target, QEvent *event) {
10891089
return true;
10901090
}
10911091
if (event->type() == QEvent::MouseButtonPress) {
1092-
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
1092+
QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent *>(event);
10931093
if (mouseEvent->buttons() == Qt::MiddleButton) {
10941094
qApp->setOverrideCursor(Qt::ClosedHandCursor);
10951095
panReferenceClick = mouseEvent->localPos();

src/interactive.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ class Interactive : public QMainWindow {
7474

7575
public:
7676
explicit Interactive(QWidget *parent = nullptr);
77+
Interactive(const Interactive &T) = delete;
78+
Interactive &operator=(const Interactive &T) = delete;
79+
Interactive &operator=(Interactive &&T) = delete;
80+
Interactive(Interactive &&T) = delete;
7781
~Interactive();
7882

7983
private slots:
@@ -94,7 +98,7 @@ class Interactive : public QMainWindow {
9498
void computeBackground();
9599
void selectBackground();
96100

97-
bool eventFilter(QObject *target, QEvent *event);
101+
bool eventFilter(QObject *target, QEvent *event) override;
98102
void crop();
99103
void reset();
100104

0 commit comments

Comments
 (0)