Skip to content

Commit

Permalink
[feat] global: add log file
Browse files Browse the repository at this point in the history
  • Loading branch information
bgallois committed Feb 8, 2022
1 parent 36b4034 commit 3fd5c4f
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 127 deletions.
2 changes: 1 addition & 1 deletion docs/user/report.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ If you encounter a bug or abnormal behaviors please report it by email at benjam

Other information: ---

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

Kind regards.
76 changes: 42 additions & 34 deletions src/annotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,24 @@ This file is part of Fast Track.
*/

/**
* @brief Clear the object.
*/
* @brief Clear the object.
*/
void Annotation::clear() {
if (!annotationFile->fileName().isEmpty()) {
writeToFile();
annotationFile->close();
annotationFile->setFileName("");
}
findIndexes.clear();
findIndex = -1;
annotations->clear();
isActive = false;
}

/**
* @brief Set the path for the annotation.
* @param[in] filePath Path to the tracking folder.
*/
* @brief Set the path for the annotation.
* @param[in] filePath Path to the tracking folder.
*/
bool Annotation::setPath(const QString &filePath) {
clear();
annotationFile->setFileName(filePath + "annotation.txt");
Expand All @@ -65,30 +67,30 @@ bool Annotation::setPath(const QString &filePath) {
}
}
annotationFile->close();
isActive = true;
return true;
}

/**
* @brief Constructs the annotation object from a file path.
* @param[in] filePath Path to the tracking folder.
*/
Annotation::Annotation(const QString &filePath) {
annotationFile = new QFile();
annotations = new QMap<int, QString>();
* @brief Constructs the annotation object from a file path.
* @param[in] filePath Path to the tracking folder.
*/
Annotation::Annotation(const QString &filePath) : Annotation() {
setPath(filePath);
}

/**
* @brief Constructs the annotation object from a file path.
*/
* @brief Constructs the annotation object from a file path.
*/
Annotation::Annotation() {
annotationFile = new QFile();
annotations = new QMap<int, QString>();
isActive = false;
}

/**
* @brief Writes all the annotation to a file.
*/
* @brief Writes all the annotation to a file.
*/
void Annotation::writeToFile() {
if (!annotationFile->open(QIODevice::WriteOnly)) {
qInfo() << "Can't open file";
Expand All @@ -104,28 +106,32 @@ void Annotation::writeToFile() {
}

/**
* @brief Adds an annotation to the annotation QMap.
* @param[in] index Image index.
* @param[in] text Annotation text.
*/
* @brief Adds an annotation to the annotation QMap.
* @param[in] index Image index.
* @param[in] text Annotation text.
*/
void Annotation::write(int index, const QString &text) {
annotations->insert(index, text);
writeToFile();
if (isActive) {
annotations->insert(index, text);
writeToFile();
}
}

/**
* @brief Reads an annotation from the annotation QMap.
* @param[in] index Image index.
*/
* @brief Reads an annotation from the annotation QMap.
* @param[in] index Image index.
*/
void Annotation::read(int index) {
QString text = annotations->value(index);
emit(annotationText(text));
if (isActive) {
QString text = annotations->value(index);
emit(annotationText(text));
}
}

/**
* @brief Finds the index of all the annotation with expression inside their text.
* @param[in] expression Expression to find, case sensitive.
*/
* @brief Finds the index of all the annotation with expression inside their text.
* @param[in] expression Expression to find, case sensitive.
*/
void Annotation::find(const QString &expression) {
findIndexes.clear();
QMapIterator<int, QString> i(*annotations);
Expand All @@ -139,8 +145,8 @@ void Annotation::find(const QString &expression) {
}

/**
* @brief Returns the next element of the findIndexes list of annotations that contains the expression to find.
*/
* @brief Returns the next element of the findIndexes list of annotations that contains the expression to find.
*/
int Annotation::next() {
++findIndex;
if (findIndex >= findIndexes.length()) {
Expand All @@ -155,8 +161,8 @@ int Annotation::next() {
}

/**
* @brief Returns the previous element of the findIndexes list of annotations that contains the expression to find.
*/
* @brief Returns the previous element of the findIndexes list of annotations that contains the expression to find.
*/
int Annotation::prev() {
--findIndex;
if (findIndex < 0) {
Expand All @@ -171,7 +177,9 @@ int Annotation::prev() {
}

Annotation::~Annotation() {
writeToFile();
if (isActive) {
writeToFile();
}
delete annotationFile;
delete annotations;
}
7 changes: 4 additions & 3 deletions src/annotation.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class Annotation : public QWidget {

signals:
/**
* @brief Emitted when a new annotation is read.
* @param text Text of the requested annotation.
*/
* @brief Emitted when a new annotation is read.
* @param text Text of the requested annotation.
*/
void annotationText(const QString &text);

public:
Expand All @@ -44,6 +44,7 @@ class Annotation : public QWidget {
Annotation &operator=(const Annotation &T) = delete;
~Annotation();
bool setPath(const QString &annotationFile);
bool isActive;
};

#endif
21 changes: 17 additions & 4 deletions src/interactive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,11 @@ Interactive::Interactive(QWidget *parent) : QMainWindow(parent),
connect(ui->actionContact, &QAction::triggered, []() {
QDesktopServices::openUrl(QUrl("mailto:benjamin.gallois@fasttrack.sh?subject=[fasttrack]", QUrl::TolerantMode));
});
connect(ui->actionGenerateLog, &QAction::triggered, [this]() {
QString fileName = QFileDialog::getSaveFileName(this, tr("Save Log File"), QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), tr("Logs (*.log)"));
QFile::remove(fileName);
QFile::copy(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/fasttrack.log", fileName);
});
connect(ui->actionAbout, &QAction::triggered, []() {
QMessageBox aboutBox;
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>");
Expand Down Expand Up @@ -588,11 +593,12 @@ void Interactive::openFolder() {
crop();
}
// If an error occurs during the opening, resets the information table and warns the user
catch (...) {
catch (exception &e) {
ui->informationTable->item(ui->informationTable->row(ui->informationTable->findItems("Path", Qt::MatchExactly)[0]), 1)->setText("");
ui->informationTable->item(ui->informationTable->row(ui->informationTable->findItems("Image number", Qt::MatchExactly)[0]), 1)->setText("0");
ui->informationTable->item(ui->informationTable->row(ui->informationTable->findItems("Image width", Qt::MatchExactly)[0]), 1)->setText("0");
ui->informationTable->item(ui->informationTable->row(ui->informationTable->findItems("Image height", Qt::MatchExactly)[0]), 1)->setText("0");
qWarning() << QString::fromStdString(e.what()) << "occurs during opening of " << dir;
emit(message("No image found."));
}
}
Expand Down Expand Up @@ -678,7 +684,12 @@ void Interactive::display(int index, int scale) {
}
display(frame);
}
catch (const std::exception &e) {
qWarning() << QString::fromStdString(e.what()) << " occurs at image " << index << " display";
emit(message(QString::fromStdString(e.what()) + QString(" occurs on image %1.").arg(index)));
}
catch (...) {
qWarning() << "Unknown error occurs at image " << index << " display";
emit(message(QString("An error occurs on image %1.").arg(index)));
}
}
Expand Down Expand Up @@ -795,12 +806,14 @@ void Interactive::computeBackground() {
try {
background = Tracking::backgroundExtraction(*video, nBack, method, registrationMethod);
}
catch (const std::exception &ex) {
emit(message("An error occurs. Please change the registration method"));
}
catch (const std::runtime_error &e) {
qWarning() << QString::fromStdString(e.what()) << "occurs during background computation";
emit(message(e.what()));
}
catch (...) {
qWarning() << "Unknown error occurs during background computation";
emit(message("An error occurs. Please change the registration method"));
}
return background;
});
watcher->setFuture(future);
Expand Down
1 change: 1 addition & 0 deletions src/interactive.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ This file is part of Fast Track.
#include <QScrollArea>
#include <QScrollBar>
#include <QSettings>
#include <QStandardPaths>
#include <QString>
#include <QStyleFactory>
#include <QTableWidget>
Expand Down
14 changes: 10 additions & 4 deletions src/interactive.ui
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>568</width>
<height>444</height>
<width>569</width>
<height>435</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">
Expand Down Expand Up @@ -193,7 +193,7 @@
<widget class="QTextBrowser" name="textBrowser">
<property name="html">
<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;
&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;
&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;
p, li { white-space: pre-wrap; }
&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;
&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;
Expand Down Expand Up @@ -1185,7 +1185,7 @@ corner: </string>
<x>0</x>
<y>0</y>
<width>1156</width>
<height>20</height>
<height>19</height>
</rect>
</property>
<widget class="QMenu" name="menuOpen">
Expand Down Expand Up @@ -1217,6 +1217,7 @@ corner: </string>
<addaction name="actionTuto"/>
<addaction name="separator"/>
<addaction name="actionAsk"/>
<addaction name="actionGenerateLog"/>
<addaction name="actionIssue"/>
<addaction name="actionContact"/>
<addaction name="separator"/>
Expand Down Expand Up @@ -1717,6 +1718,11 @@ corner: </string>
<string>Ask a question</string>
</property>
</action>
<action name="actionGenerateLog">
<property name="text">
<string>Generate a log</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
Expand Down
16 changes: 15 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,37 @@ This file is part of Fast Track.
*/

#include <QApplication>
#include <QDir>
#include <QFont>
#include <QFontDatabase>
#include <QPixmap>
#include <QScopedPointer>
#include <QSplashScreen>
#include <QString>
#include "mainwindow.h"

QScopedPointer<QFile> logFile;

void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
QTextStream out(logFile.data());
out << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz ");
out << context.category << ": " << msg << Qt::endl;
}

int main(int argc, char *argv[]) {
QApplication a(argc, argv);
QPixmap pixmap(":/assets/icon.png");
QSplashScreen splash(pixmap);
splash.show();
MainWindow w;
a.setApplicationName("FastTrack");
a.setApplicationVersion(APP_VERSION);
a.setOrganizationName("FastTrackOrg");
a.setOrganizationDomain("www.fasttrack.sh");
logFile.reset(new QFile(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/fasttrack.log"));
QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation));
logFile.data()->open(QFile::Append | QFile::Text);
qInstallMessageHandler(messageHandler);
MainWindow w;
w.setWindowIcon(QIcon(":/assets/icon.png"));
QFontDatabase::addApplicationFont(":/assets/Font.ttf");
w.setStyleSheet("QWidget {font-family: 'Lato', sans-serif;}");
Expand Down
8 changes: 0 additions & 8 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
trayIcon->setContextMenu(trayMenu);
trayIcon->show();

// Setup style
QFile stylesheet("");

if (stylesheet.open(QIODevice::ReadOnly | QIODevice::Text)) { // Read the theme file
qApp->setStyleSheet(stylesheet.readAll());
stylesheet.close();
}

QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager, &QNetworkAccessManager::finished, [this](QNetworkReply *reply) {
if (reply->error() != QNetworkReply::NoError) {
Expand Down
Loading

0 comments on commit 3fd5c4f

Please sign in to comment.