UI: StatisticsPage: Add "Clear" button.

This commit is contained in:
Nodir Temirkhodjaev 2017-12-12 07:48:26 +05:00
parent c5bc8ae730
commit c6663dc1e6
6 changed files with 58 additions and 22 deletions

View File

@ -11,9 +11,6 @@
DatabaseManager::DatabaseManager(const QString &filePath, DatabaseManager::DatabaseManager(const QString &filePath,
QObject *parent) : QObject *parent) :
QObject(parent), QObject(parent),
m_lastTrafHour(0),
m_lastTrafDay(0),
m_lastTrafMonth(0),
m_filePath(filePath), m_filePath(filePath),
m_conf(nullptr), m_conf(nullptr),
m_sqliteDb(new SqliteDb()) m_sqliteDb(new SqliteDb())
@ -23,7 +20,7 @@ DatabaseManager::DatabaseManager(const QString &filePath,
DatabaseManager::~DatabaseManager() DatabaseManager::~DatabaseManager()
{ {
qDeleteAll(m_sqliteStmts); clearStmts();
delete m_sqliteDb; delete m_sqliteDb;
@ -43,6 +40,8 @@ bool DatabaseManager::initialize()
{ {
const bool fileExists = FileUtil::fileExists(m_filePath); const bool fileExists = FileUtil::fileExists(m_filePath);
m_lastTrafHour = m_lastTrafDay = m_lastTrafMonth = 0;
if (!m_sqliteDb->open(m_filePath)) if (!m_sqliteDb->open(m_filePath))
return false; return false;
@ -51,6 +50,23 @@ bool DatabaseManager::initialize()
return fileExists || createTables(); return fileExists || createTables();
} }
void DatabaseManager::clear()
{
clearStmts();
m_sqliteDb->close();
FileUtil::removeFile(m_filePath);
initialize();
}
void DatabaseManager::clearStmts()
{
qDeleteAll(m_sqliteStmts);
m_sqliteStmts.clear();
}
qint64 DatabaseManager::logProcNew(const QString &appPath, bool &isNew) qint64 DatabaseManager::logProcNew(const QString &appPath, bool &isNew)
{ {
if (m_conf && !m_conf->logStat()) if (m_conf && !m_conf->logStat())

View File

@ -44,12 +44,15 @@ public:
signals: signals:
public slots: public slots:
void clear();
private: private:
typedef QList<SqliteStmt *> QStmtList; typedef QList<SqliteStmt *> QStmtList;
bool createTables(); bool createTables();
void clearStmts();
qint64 createAppId(const QString &appPath); qint64 createAppId(const QString &appPath);
void updateTrafficList(const QStmtList &insertStmtList, void updateTrafficList(const QStmtList &insertStmtList,

View File

@ -167,6 +167,7 @@
</message> </message>
<message> <message>
<location filename="../qml/pages/BlockedPage.qml" line="39"/> <location filename="../qml/pages/BlockedPage.qml" line="39"/>
<location filename="../qml/pages/StatisticsPage.qml" line="48"/>
<source>Clear</source> <source>Clear</source>
<translation>Очистить</translation> <translation>Очистить</translation>
</message> </message>
@ -411,66 +412,66 @@
<translation>TiB</translation> <translation>TiB</translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/StatisticsPage.qml" line="48"/> <location filename="../qml/pages/StatisticsPage.qml" line="55"/>
<source>Refresh</source> <source>Refresh</source>
<translation>Обновить</translation> <translation>Обновить</translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/StatisticsPage.qml" line="58"/> <location filename="../qml/pages/StatisticsPage.qml" line="65"/>
<source>Units:</source> <source>Units:</source>
<translation>Единицы:</translation> <translation>Единицы:</translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/StatisticsPage.qml" line="85"/> <location filename="../qml/pages/StatisticsPage.qml" line="92"/>
<source>Collect Traffic Statistics</source> <source>Collect Traffic Statistics</source>
<translation>Собирать статистику трафика</translation> <translation>Собирать статистику трафика</translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/StatisticsPage.qml" line="116"/> <location filename="../qml/pages/StatisticsPage.qml" line="123"/>
<source>All</source> <source>All</source>
<translation>Все</translation> <translation>Все</translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/StatisticsPage.qml" line="133"/> <location filename="../qml/pages/StatisticsPage.qml" line="140"/>
<source>Hourly</source> <source>Hourly</source>
<comment>Stat</comment> <comment>Stat</comment>
<translation>Почасовая</translation> <translation>Почасовая</translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/StatisticsPage.qml" line="137"/> <location filename="../qml/pages/StatisticsPage.qml" line="144"/>
<source>Daily</source> <source>Daily</source>
<comment>Stat</comment> <comment>Stat</comment>
<translation>Ежедневная</translation> <translation>Ежедневная</translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/StatisticsPage.qml" line="141"/> <location filename="../qml/pages/StatisticsPage.qml" line="148"/>
<source>Monthly</source> <source>Monthly</source>
<comment>Stat</comment> <comment>Stat</comment>
<translation>Ежемесячная</translation> <translation>Ежемесячная</translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/StatisticsPage.qml" line="145"/> <location filename="../qml/pages/StatisticsPage.qml" line="152"/>
<source>Total</source> <source>Total</source>
<comment>Stat</comment> <comment>Stat</comment>
<translation>Общая</translation> <translation>Общая</translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/StatisticsPage.qml" line="156"/> <location filename="../qml/pages/StatisticsPage.qml" line="163"/>
<source>Date</source> <source>Date</source>
<translation>Дата</translation> <translation>Дата</translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/StatisticsPage.qml" line="161"/> <location filename="../qml/pages/StatisticsPage.qml" line="168"/>
<source>Download</source> <source>Download</source>
<translation>Загрузка</translation> <translation>Загрузка</translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/StatisticsPage.qml" line="166"/> <location filename="../qml/pages/StatisticsPage.qml" line="173"/>
<source>Upload</source> <source>Upload</source>
<translation>Выгрузка</translation> <translation>Выгрузка</translation>
</message> </message>
<message> <message>
<location filename="../qml/pages/StatisticsPage.qml" line="171"/> <location filename="../qml/pages/StatisticsPage.qml" line="178"/>
<source>Sum</source> <source>Sum</source>
<translation>Сумма</translation> <translation>Сумма</translation>
</message> </message>

View File

@ -29,7 +29,9 @@ TrafListModel *AppStatModel::trafListModel(int trafType, int row) const
void AppStatModel::clear() void AppStatModel::clear()
{ {
StringListModel::clear(); m_trafListModel->clear();
updateList();
} }
void AppStatModel::updateList() void AppStatModel::updateList()

View File

@ -91,6 +91,9 @@ QHash<int, QByteArray> TrafListModel::roleNames() const
void TrafListModel::clear() void TrafListModel::clear()
{ {
m_databaseManager->clear();
reset();
} }
void TrafListModel::updateRowCache(int row) const void TrafListModel::updateRowCache(int row) const

View File

@ -18,10 +18,10 @@ BasePage {
? appListView.currentItem.appPath : "" ? appListView.currentItem.appPath : ""
readonly property var trafCellWidths: [ readonly property var trafCellWidths: [
trafsContainer.width * 0.4, trafsContainer.width * 0.34,
trafsContainer.width * 0.2, trafsContainer.width * 0.22,
trafsContainer.width * 0.2, trafsContainer.width * 0.22,
trafsContainer.width * 0.2 trafsContainer.width * 0.22
] ]
readonly property var trafUnitNames: readonly property var trafUnitNames:
@ -43,7 +43,18 @@ BasePage {
spacing: 15 spacing: 15
Button { Button {
enabled: appListView.currentIndex >= 0 enabled: appListView.count
text: translationManager.dummyBool
&& qsTranslate("qml", "Clear")
onClicked: {
appStatModel.clear();
appListView.currentIndex = 0;
}
}
Button {
enabled: appListView.count
text: translationManager.dummyBool text: translationManager.dummyBool
&& qsTranslate("qml", "Refresh") && qsTranslate("qml", "Refresh")
onClicked: trafListModel.refresh() onClicked: trafListModel.refresh()