Skip to content

Commit 3fd5c4f

Browse files
committed
[feat] global: add log file
1 parent 36b4034 commit 3fd5c4f

File tree

10 files changed

+189
-127
lines changed

10 files changed

+189
-127
lines changed

docs/user/report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ If you encounter a bug or abnormal behaviors please report it by email at benjam
2020

2121
Other information: ---
2222

23-
You can attach an archive with the Tracking_Result folder if necessary.
23+
Do not forget to attach the log file that can be generated Help -> Generate log.
2424

2525
Kind regards.

src/annotation.cpp

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,24 @@ This file is part of Fast Track.
3131
*/
3232

3333
/**
34-
* @brief Clear the object.
35-
*/
34+
* @brief Clear the object.
35+
*/
3636
void Annotation::clear() {
3737
if (!annotationFile->fileName().isEmpty()) {
3838
writeToFile();
39+
annotationFile->close();
3940
annotationFile->setFileName("");
4041
}
4142
findIndexes.clear();
4243
findIndex = -1;
4344
annotations->clear();
45+
isActive = false;
4446
}
4547

4648
/**
47-
* @brief Set the path for the annotation.
48-
* @param[in] filePath Path to the tracking folder.
49-
*/
49+
* @brief Set the path for the annotation.
50+
* @param[in] filePath Path to the tracking folder.
51+
*/
5052
bool Annotation::setPath(const QString &filePath) {
5153
clear();
5254
annotationFile->setFileName(filePath + "annotation.txt");
@@ -65,30 +67,30 @@ bool Annotation::setPath(const QString &filePath) {
6567
}
6668
}
6769
annotationFile->close();
70+
isActive = true;
6871
return true;
6972
}
7073

7174
/**
72-
* @brief Constructs the annotation object from a file path.
73-
* @param[in] filePath Path to the tracking folder.
74-
*/
75-
Annotation::Annotation(const QString &filePath) {
76-
annotationFile = new QFile();
77-
annotations = new QMap<int, QString>();
75+
* @brief Constructs the annotation object from a file path.
76+
* @param[in] filePath Path to the tracking folder.
77+
*/
78+
Annotation::Annotation(const QString &filePath) : Annotation() {
7879
setPath(filePath);
7980
}
8081

8182
/**
82-
* @brief Constructs the annotation object from a file path.
83-
*/
83+
* @brief Constructs the annotation object from a file path.
84+
*/
8485
Annotation::Annotation() {
8586
annotationFile = new QFile();
8687
annotations = new QMap<int, QString>();
88+
isActive = false;
8789
}
8890

8991
/**
90-
* @brief Writes all the annotation to a file.
91-
*/
92+
* @brief Writes all the annotation to a file.
93+
*/
9294
void Annotation::writeToFile() {
9395
if (!annotationFile->open(QIODevice::WriteOnly)) {
9496
qInfo() << "Can't open file";
@@ -104,28 +106,32 @@ void Annotation::writeToFile() {
104106
}
105107

106108
/**
107-
* @brief Adds an annotation to the annotation QMap.
108-
* @param[in] index Image index.
109-
* @param[in] text Annotation text.
110-
*/
109+
* @brief Adds an annotation to the annotation QMap.
110+
* @param[in] index Image index.
111+
* @param[in] text Annotation text.
112+
*/
111113
void Annotation::write(int index, const QString &text) {
112-
annotations->insert(index, text);
113-
writeToFile();
114+
if (isActive) {
115+
annotations->insert(index, text);
116+
writeToFile();
117+
}
114118
}
115119

116120
/**
117-
* @brief Reads an annotation from the annotation QMap.
118-
* @param[in] index Image index.
119-
*/
121+
* @brief Reads an annotation from the annotation QMap.
122+
* @param[in] index Image index.
123+
*/
120124
void Annotation::read(int index) {
121-
QString text = annotations->value(index);
122-
emit(annotationText(text));
125+
if (isActive) {
126+
QString text = annotations->value(index);
127+
emit(annotationText(text));
128+
}
123129
}
124130

125131
/**
126-
* @brief Finds the index of all the annotation with expression inside their text.
127-
* @param[in] expression Expression to find, case sensitive.
128-
*/
132+
* @brief Finds the index of all the annotation with expression inside their text.
133+
* @param[in] expression Expression to find, case sensitive.
134+
*/
129135
void Annotation::find(const QString &expression) {
130136
findIndexes.clear();
131137
QMapIterator<int, QString> i(*annotations);
@@ -139,8 +145,8 @@ void Annotation::find(const QString &expression) {
139145
}
140146

141147
/**
142-
* @brief Returns the next element of the findIndexes list of annotations that contains the expression to find.
143-
*/
148+
* @brief Returns the next element of the findIndexes list of annotations that contains the expression to find.
149+
*/
144150
int Annotation::next() {
145151
++findIndex;
146152
if (findIndex >= findIndexes.length()) {
@@ -155,8 +161,8 @@ int Annotation::next() {
155161
}
156162

157163
/**
158-
* @brief Returns the previous element of the findIndexes list of annotations that contains the expression to find.
159-
*/
164+
* @brief Returns the previous element of the findIndexes list of annotations that contains the expression to find.
165+
*/
160166
int Annotation::prev() {
161167
--findIndex;
162168
if (findIndex < 0) {
@@ -171,7 +177,9 @@ int Annotation::prev() {
171177
}
172178

173179
Annotation::~Annotation() {
174-
writeToFile();
180+
if (isActive) {
181+
writeToFile();
182+
}
175183
delete annotationFile;
176184
delete annotations;
177185
}

src/annotation.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ class Annotation : public QWidget {
3232

3333
signals:
3434
/**
35-
* @brief Emitted when a new annotation is read.
36-
* @param text Text of the requested annotation.
37-
*/
35+
* @brief Emitted when a new annotation is read.
36+
* @param text Text of the requested annotation.
37+
*/
3838
void annotationText(const QString &text);
3939

4040
public:
@@ -44,6 +44,7 @@ class Annotation : public QWidget {
4444
Annotation &operator=(const Annotation &T) = delete;
4545
~Annotation();
4646
bool setPath(const QString &annotationFile);
47+
bool isActive;
4748
};
4849

4950
#endif

src/interactive.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,11 @@ Interactive::Interactive(QWidget *parent) : QMainWindow(parent),
359359
connect(ui->actionContact, &QAction::triggered, []() {
360360
QDesktopServices::openUrl(QUrl("mailto:[email protected]?subject=[fasttrack]", QUrl::TolerantMode));
361361
});
362+
connect(ui->actionGenerateLog, &QAction::triggered, [this]() {
363+
QString fileName = QFileDialog::getSaveFileName(this, tr("Save Log File"), QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), tr("Logs (*.log)"));
364+
QFile::remove(fileName);
365+
QFile::copy(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/fasttrack.log", fileName);
366+
});
362367
connect(ui->actionAbout, &QAction::triggered, []() {
363368
QMessageBox aboutBox;
364369
aboutBox.setText("FastTrack is a desktop tracking software, easy to install, easy to use, and performant.<br>Created and maintained by Benjamin Gallois.<br>Distributed under the terms of the <a href='https://www.gnu.org/licenses/gpl-3.0'>GPL3.0 license</a>.<br>");
@@ -588,11 +593,12 @@ void Interactive::openFolder() {
588593
crop();
589594
}
590595
// If an error occurs during the opening, resets the information table and warns the user
591-
catch (...) {
596+
catch (exception &e) {
592597
ui->informationTable->item(ui->informationTable->row(ui->informationTable->findItems("Path", Qt::MatchExactly)[0]), 1)->setText("");
593598
ui->informationTable->item(ui->informationTable->row(ui->informationTable->findItems("Image number", Qt::MatchExactly)[0]), 1)->setText("0");
594599
ui->informationTable->item(ui->informationTable->row(ui->informationTable->findItems("Image width", Qt::MatchExactly)[0]), 1)->setText("0");
595600
ui->informationTable->item(ui->informationTable->row(ui->informationTable->findItems("Image height", Qt::MatchExactly)[0]), 1)->setText("0");
601+
qWarning() << QString::fromStdString(e.what()) << "occurs during opening of " << dir;
596602
emit(message("No image found."));
597603
}
598604
}
@@ -678,7 +684,12 @@ void Interactive::display(int index, int scale) {
678684
}
679685
display(frame);
680686
}
687+
catch (const std::exception &e) {
688+
qWarning() << QString::fromStdString(e.what()) << " occurs at image " << index << " display";
689+
emit(message(QString::fromStdString(e.what()) + QString(" occurs on image %1.").arg(index)));
690+
}
681691
catch (...) {
692+
qWarning() << "Unknown error occurs at image " << index << " display";
682693
emit(message(QString("An error occurs on image %1.").arg(index)));
683694
}
684695
}
@@ -795,12 +806,14 @@ void Interactive::computeBackground() {
795806
try {
796807
background = Tracking::backgroundExtraction(*video, nBack, method, registrationMethod);
797808
}
798-
catch (const std::exception &ex) {
799-
emit(message("An error occurs. Please change the registration method"));
800-
}
801809
catch (const std::runtime_error &e) {
810+
qWarning() << QString::fromStdString(e.what()) << "occurs during background computation";
802811
emit(message(e.what()));
803812
}
813+
catch (...) {
814+
qWarning() << "Unknown error occurs during background computation";
815+
emit(message("An error occurs. Please change the registration method"));
816+
}
804817
return background;
805818
});
806819
watcher->setFuture(future);

src/interactive.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ This file is part of Fast Track.
4444
#include <QScrollArea>
4545
#include <QScrollBar>
4646
#include <QSettings>
47+
#include <QStandardPaths>
4748
#include <QString>
4849
#include <QStyleFactory>
4950
#include <QTableWidget>

src/interactive.ui

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@
6262
<rect>
6363
<x>0</x>
6464
<y>0</y>
65-
<width>568</width>
66-
<height>444</height>
65+
<width>569</width>
66+
<height>435</height>
6767
</rect>
6868
</property>
6969
<layout class="QGridLayout" name="gridLayout_2">
@@ -193,7 +193,7 @@
193193
<widget class="QTextBrowser" name="textBrowser">
194194
<property name="html">
195195
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
196-
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
196+
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;meta charset=&quot;utf-8&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
197197
p, li { white-space: pre-wrap; }
198198
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
199199
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:8pt;&quot;&gt;The program will compute a cost for each pair of objects in two successive images using the distance &lt;/span&gt;&lt;span style=&quot; font-size:8pt; font-weight:600;&quot;&gt;d&lt;/span&gt;&lt;span style=&quot; font-size:8pt; font-weight:600; vertical-align:sub;&quot;&gt;ij&lt;/span&gt;&lt;span style=&quot; font-size:8pt;&quot;&gt;, the angular difference &lt;/span&gt;&lt;span style=&quot; font-size:8pt; font-weight:600;&quot;&gt;a&lt;/span&gt;&lt;span style=&quot; font-size:8pt; font-weight:600; vertical-align:sub;&quot;&gt;ij ,&lt;/span&gt;&lt;span style=&quot; font-size:8pt;&quot;&gt; the area difference &lt;/span&gt;&lt;span style=&quot; font-size:8pt; font-weight:600;&quot;&gt;ar&lt;/span&gt;&lt;span style=&quot; font-size:8pt; font-weight:600; vertical-align:sub;&quot;&gt;ij &lt;/span&gt;&lt;span style=&quot; font-size:8pt;&quot;&gt; and the perimeter difference &lt;/span&gt;&lt;span style=&quot; font-size:8pt; font-weight:600;&quot;&gt;p&lt;/span&gt;&lt;span style=&quot; font-size:8pt; font-weight:600; vertical-align:sub;&quot;&gt;ij&lt;/span&gt;&lt;span style=&quot; font-size:8pt;&quot;&gt; between two objects. These two parameters can be computed using the direction and barycenter of the head, tail or body by selecting the&lt;/span&gt;&lt;span style=&quot; font-size:8pt; font-weight:600;&quot;&gt; Spot to track &lt;/span&gt;&lt;span style=&quot; font-size:8pt;&quot;&gt;accordingly.&lt;/span&gt;&lt;/p&gt;
@@ -1185,7 +1185,7 @@ corner: </string>
11851185
<x>0</x>
11861186
<y>0</y>
11871187
<width>1156</width>
1188-
<height>20</height>
1188+
<height>19</height>
11891189
</rect>
11901190
</property>
11911191
<widget class="QMenu" name="menuOpen">
@@ -1217,6 +1217,7 @@ corner: </string>
12171217
<addaction name="actionTuto"/>
12181218
<addaction name="separator"/>
12191219
<addaction name="actionAsk"/>
1220+
<addaction name="actionGenerateLog"/>
12201221
<addaction name="actionIssue"/>
12211222
<addaction name="actionContact"/>
12221223
<addaction name="separator"/>
@@ -1717,6 +1718,11 @@ corner: </string>
17171718
<string>Ask a question</string>
17181719
</property>
17191720
</action>
1721+
<action name="actionGenerateLog">
1722+
<property name="text">
1723+
<string>Generate a log</string>
1724+
</property>
1725+
</action>
17201726
</widget>
17211727
<layoutdefault spacing="6" margin="11"/>
17221728
<customwidgets>

src/main.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,37 @@ This file is part of Fast Track.
1616
*/
1717

1818
#include <QApplication>
19+
#include <QDir>
1920
#include <QFont>
2021
#include <QFontDatabase>
2122
#include <QPixmap>
23+
#include <QScopedPointer>
2224
#include <QSplashScreen>
2325
#include <QString>
2426
#include "mainwindow.h"
2527

28+
QScopedPointer<QFile> logFile;
29+
30+
void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
31+
QTextStream out(logFile.data());
32+
out << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz ");
33+
out << context.category << ": " << msg << Qt::endl;
34+
}
35+
2636
int main(int argc, char *argv[]) {
2737
QApplication a(argc, argv);
2838
QPixmap pixmap(":/assets/icon.png");
2939
QSplashScreen splash(pixmap);
3040
splash.show();
31-
MainWindow w;
3241
a.setApplicationName("FastTrack");
3342
a.setApplicationVersion(APP_VERSION);
3443
a.setOrganizationName("FastTrackOrg");
3544
a.setOrganizationDomain("www.fasttrack.sh");
45+
logFile.reset(new QFile(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/fasttrack.log"));
46+
QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation));
47+
logFile.data()->open(QFile::Append | QFile::Text);
48+
qInstallMessageHandler(messageHandler);
49+
MainWindow w;
3650
w.setWindowIcon(QIcon(":/assets/icon.png"));
3751
QFontDatabase::addApplicationFont(":/assets/Font.ttf");
3852
w.setStyleSheet("QWidget {font-family: 'Lato', sans-serif;}");

src/mainwindow.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
7171
trayIcon->setContextMenu(trayMenu);
7272
trayIcon->show();
7373

74-
// Setup style
75-
QFile stylesheet("");
76-
77-
if (stylesheet.open(QIODevice::ReadOnly | QIODevice::Text)) { // Read the theme file
78-
qApp->setStyleSheet(stylesheet.readAll());
79-
stylesheet.close();
80-
}
81-
8274
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
8375
connect(manager, &QNetworkAccessManager::finished, [this](QNetworkReply *reply) {
8476
if (reply->error() != QNetworkReply::NoError) {

0 commit comments

Comments
 (0)