mirror of
https://github.com/tnodir/fort
synced 2024-11-15 05:36:09 +00:00
UI: StatisticsPage: Add "Clear" button.
This commit is contained in:
parent
c5bc8ae730
commit
c6663dc1e6
@ -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())
|
||||
|
@ -44,12 +44,15 @@ public:
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void clear();
|
||||
|
||||
private:
|
||||
typedef QList<SqliteStmt *> QStmtList;
|
||||
|
||||
bool createTables();
|
||||
|
||||
void clearStmts();
|
||||
|
||||
qint64 createAppId(const QString &appPath);
|
||||
|
||||
void updateTrafficList(const QStmtList &insertStmtList,
|
||||
|
@ -167,6 +167,7 @@
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/pages/BlockedPage.qml" line="39"/>
|
||||
<location filename="../qml/pages/StatisticsPage.qml" line="48"/>
|
||||
<source>Clear</source>
|
||||
<translation>Очистить</translation>
|
||||
</message>
|
||||
@ -411,66 +412,66 @@
|
||||
<translation>TiB</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/pages/StatisticsPage.qml" line="48"/>
|
||||
<location filename="../qml/pages/StatisticsPage.qml" line="55"/>
|
||||
<source>Refresh</source>
|
||||
<translation>Обновить</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/pages/StatisticsPage.qml" line="58"/>
|
||||
<location filename="../qml/pages/StatisticsPage.qml" line="65"/>
|
||||
<source>Units:</source>
|
||||
<translation>Единицы:</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/pages/StatisticsPage.qml" line="85"/>
|
||||
<location filename="../qml/pages/StatisticsPage.qml" line="92"/>
|
||||
<source>Collect Traffic Statistics</source>
|
||||
<translation>Собирать статистику трафика</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/pages/StatisticsPage.qml" line="116"/>
|
||||
<location filename="../qml/pages/StatisticsPage.qml" line="123"/>
|
||||
<source>All</source>
|
||||
<translation>Все</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/pages/StatisticsPage.qml" line="133"/>
|
||||
<location filename="../qml/pages/StatisticsPage.qml" line="140"/>
|
||||
<source>Hourly</source>
|
||||
<comment>Stat</comment>
|
||||
<translation>Почасовая</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/pages/StatisticsPage.qml" line="137"/>
|
||||
<location filename="../qml/pages/StatisticsPage.qml" line="144"/>
|
||||
<source>Daily</source>
|
||||
<comment>Stat</comment>
|
||||
<translation>Ежедневная</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/pages/StatisticsPage.qml" line="141"/>
|
||||
<location filename="../qml/pages/StatisticsPage.qml" line="148"/>
|
||||
<source>Monthly</source>
|
||||
<comment>Stat</comment>
|
||||
<translation>Ежемесячная</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/pages/StatisticsPage.qml" line="145"/>
|
||||
<location filename="../qml/pages/StatisticsPage.qml" line="152"/>
|
||||
<source>Total</source>
|
||||
<comment>Stat</comment>
|
||||
<translation>Общая</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/pages/StatisticsPage.qml" line="156"/>
|
||||
<location filename="../qml/pages/StatisticsPage.qml" line="163"/>
|
||||
<source>Date</source>
|
||||
<translation>Дата</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/pages/StatisticsPage.qml" line="161"/>
|
||||
<location filename="../qml/pages/StatisticsPage.qml" line="168"/>
|
||||
<source>Download</source>
|
||||
<translation>Загрузка</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/pages/StatisticsPage.qml" line="166"/>
|
||||
<location filename="../qml/pages/StatisticsPage.qml" line="173"/>
|
||||
<source>Upload</source>
|
||||
<translation>Выгрузка</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/pages/StatisticsPage.qml" line="171"/>
|
||||
<location filename="../qml/pages/StatisticsPage.qml" line="178"/>
|
||||
<source>Sum</source>
|
||||
<translation>Сумма</translation>
|
||||
</message>
|
||||
|
@ -29,7 +29,9 @@ TrafListModel *AppStatModel::trafListModel(int trafType, int row) const
|
||||
|
||||
void AppStatModel::clear()
|
||||
{
|
||||
StringListModel::clear();
|
||||
m_trafListModel->clear();
|
||||
|
||||
updateList();
|
||||
}
|
||||
|
||||
void AppStatModel::updateList()
|
||||
|
@ -91,6 +91,9 @@ QHash<int, QByteArray> TrafListModel::roleNames() const
|
||||
|
||||
void TrafListModel::clear()
|
||||
{
|
||||
m_databaseManager->clear();
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
void TrafListModel::updateRowCache(int row) const
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user