forked from z1dev/zkanji
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dictionarystatsform.h
98 lines (77 loc) · 2.2 KB
/
dictionarystatsform.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
** Copyright 2007-2013, 2017-2018 Sólyom Zoltán
** This file is part of zkanji, a free software released under the terms of the
** GNU General Public License version 3. See the file LICENSE for details.
**/
#ifndef DICTIONARYSTATSFORM_H
#define DICTIONARYSTATSFORM_H
#include <QBasicTimer>
#include <QThread>
#include <atomic>
#include <memory>
#include "dialogwindow.h"
namespace Ui {
class DictionaryStatsForm;
}
class DictionaryStatsForm;
class Dictionary;
class StatsThread : public QRunnable
{
public:
StatsThread(DictionaryStatsForm *owner, Dictionary *dict);
virtual ~StatsThread();
virtual void run() override;
// Returns the calculated value. Only valid when the variable "done" is set to true.
int entryResult() const;
int definitionResult() const;
int kanjiResult() const;
std::atomic_bool terminate;
std::atomic_bool done;
private:
// Checks whether the thread should be terminated. If so, sets done to true and returns
// true.
bool checkTerminate();
bool calculateEntries();
bool calculateDefinitions();
bool calculateKanji();
DictionaryStatsForm *owner;
Dictionary *dict;
int valentry;
int valdef;
int valkanji;
typedef QRunnable base;
};
struct StatResult
{
int entries;
int defs;
int kanji;
};
class Dictionary;
class DictionaryStatsForm : public DialogWindow
{
Q_OBJECT
public:
DictionaryStatsForm(int index, QWidget *parent = nullptr);
virtual ~DictionaryStatsForm();
public slots:
void on_dictCBox_currentIndexChanged(int newindex);
protected:
virtual bool event(QEvent *e) override;
virtual bool eventFilter(QObject *o, QEvent *e) override;
virtual void closeEvent(QCloseEvent *e) override;
virtual void showEvent(QShowEvent *e) override;
private:
void updateData();
void stopThreads();
void startThreads(Dictionary *d);
void translateTexts();
void updateLabels(const StatResult &result);
void setHtmlInfoText(const QString &str);
Ui::DictionaryStatsForm *ui;
QBasicTimer timer;
std::unique_ptr<StatsThread> thread;
std::map<Dictionary *, StatResult> results;
typedef DialogWindow base;
};
#endif // DICTIONARYSTATSFORM_H