From c6663dc1e6c7e24bcd72380afcc97fa328c8724d Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Tue, 12 Dec 2017 07:48:26 +0500 Subject: [PATCH] UI: StatisticsPage: Add "Clear" button. --- src/ui/db/databasemanager.cpp | 24 ++++++++++++++++++++---- src/ui/db/databasemanager.h | 3 +++ src/ui/i18n/i18n_ru.ts | 25 +++++++++++++------------ src/ui/log/model/appstatmodel.cpp | 4 +++- src/ui/log/model/traflistmodel.cpp | 3 +++ src/ui/qml/pages/StatisticsPage.qml | 21 ++++++++++++++++----- 6 files changed, 58 insertions(+), 22 deletions(-) diff --git a/src/ui/db/databasemanager.cpp b/src/ui/db/databasemanager.cpp index 7aeff31e..556c35b5 100644 --- a/src/ui/db/databasemanager.cpp +++ b/src/ui/db/databasemanager.cpp @@ -11,9 +11,6 @@ DatabaseManager::DatabaseManager(const QString &filePath, QObject *parent) : QObject(parent), - m_lastTrafHour(0), - m_lastTrafDay(0), - m_lastTrafMonth(0), m_filePath(filePath), m_conf(nullptr), m_sqliteDb(new SqliteDb()) @@ -23,7 +20,7 @@ DatabaseManager::DatabaseManager(const QString &filePath, DatabaseManager::~DatabaseManager() { - qDeleteAll(m_sqliteStmts); + clearStmts(); delete m_sqliteDb; @@ -43,6 +40,8 @@ bool DatabaseManager::initialize() { const bool fileExists = FileUtil::fileExists(m_filePath); + m_lastTrafHour = m_lastTrafDay = m_lastTrafMonth = 0; + if (!m_sqliteDb->open(m_filePath)) return false; @@ -51,6 +50,23 @@ bool DatabaseManager::initialize() 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) { if (m_conf && !m_conf->logStat()) diff --git a/src/ui/db/databasemanager.h b/src/ui/db/databasemanager.h index a4f754b0..bb7d83de 100644 --- a/src/ui/db/databasemanager.h +++ b/src/ui/db/databasemanager.h @@ -44,12 +44,15 @@ public: signals: public slots: + void clear(); private: typedef QList QStmtList; bool createTables(); + void clearStmts(); + qint64 createAppId(const QString &appPath); void updateTrafficList(const QStmtList &insertStmtList, diff --git a/src/ui/i18n/i18n_ru.ts b/src/ui/i18n/i18n_ru.ts index 02672a76..96f2c5c4 100644 --- a/src/ui/i18n/i18n_ru.ts +++ b/src/ui/i18n/i18n_ru.ts @@ -167,6 +167,7 @@ + Clear Очистить @@ -411,66 +412,66 @@ TiB - + Refresh Обновить - + Units: Единицы: - + Collect Traffic Statistics Собирать статистику трафика - + All Все - + Hourly Stat Почасовая - + Daily Stat Ежедневная - + Monthly Stat Ежемесячная - + Total Stat Общая - + Date Дата - + Download Загрузка - + Upload Выгрузка - + Sum Сумма diff --git a/src/ui/log/model/appstatmodel.cpp b/src/ui/log/model/appstatmodel.cpp index 4b721b88..b9b7ccdd 100644 --- a/src/ui/log/model/appstatmodel.cpp +++ b/src/ui/log/model/appstatmodel.cpp @@ -29,7 +29,9 @@ TrafListModel *AppStatModel::trafListModel(int trafType, int row) const void AppStatModel::clear() { - StringListModel::clear(); + m_trafListModel->clear(); + + updateList(); } void AppStatModel::updateList() diff --git a/src/ui/log/model/traflistmodel.cpp b/src/ui/log/model/traflistmodel.cpp index 3173928e..f1733cb2 100644 --- a/src/ui/log/model/traflistmodel.cpp +++ b/src/ui/log/model/traflistmodel.cpp @@ -91,6 +91,9 @@ QHash TrafListModel::roleNames() const void TrafListModel::clear() { + m_databaseManager->clear(); + + reset(); } void TrafListModel::updateRowCache(int row) const diff --git a/src/ui/qml/pages/StatisticsPage.qml b/src/ui/qml/pages/StatisticsPage.qml index a6cc64b6..009c1020 100644 --- a/src/ui/qml/pages/StatisticsPage.qml +++ b/src/ui/qml/pages/StatisticsPage.qml @@ -18,10 +18,10 @@ BasePage { ? appListView.currentItem.appPath : "" readonly property var trafCellWidths: [ - trafsContainer.width * 0.4, - trafsContainer.width * 0.2, - trafsContainer.width * 0.2, - trafsContainer.width * 0.2 + trafsContainer.width * 0.34, + trafsContainer.width * 0.22, + trafsContainer.width * 0.22, + trafsContainer.width * 0.22 ] readonly property var trafUnitNames: @@ -43,7 +43,18 @@ BasePage { spacing: 15 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 && qsTranslate("qml", "Refresh") onClicked: trafListModel.refresh()