From f226f57fb7cacdd0fa6f109721e820c6d6c750c6 Mon Sep 17 00:00:00 2001 From: Krad Date: Tue, 23 Nov 2021 16:53:36 +0800 Subject: [PATCH] Simple User operation log table, v1.1 --- src/UserOperationLogForm.cpp | 21 ++++++++++++++++++--- src/UserOperationLogForm.h | 5 +++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/UserOperationLogForm.cpp b/src/UserOperationLogForm.cpp index db901a3..87ac0ca 100644 --- a/src/UserOperationLogForm.cpp +++ b/src/UserOperationLogForm.cpp @@ -4,15 +4,25 @@ #include "UserOperationLogForm.h" #include +#include #include #include "log/UserOperationLog.h" #include "log/LogFileTableModel.h" #include +#include +#include +#include "components/SlideableTableView.h" +#include UserOperationLogForm::UserOperationLogForm(QWidget *parent) { QVBoxLayout* layout = new QVBoxLayout(this); QWidget* header = new QWidget(this); - table = new QTableView(this); + QHBoxLayout* headerLayout = new QHBoxLayout(header); + headerLayout->addWidget(new QLabel(tr("Log Date:"))); + btn = new QPushButton(header); + headerLayout->addWidget(btn, 0, Qt::AlignLeft); + headerLayout->addSpacerItem(new QSpacerItem(20,20,QSizePolicy::Expanding)); + table = new SlideableTableView(this); layout->addWidget(header); layout->addWidget(table); //暂时先放构造函数,之后需要移除,等需要时再调用 @@ -23,19 +33,24 @@ UserOperationLogForm::~UserOperationLogForm() { } +QString fileNameToDate(QString fileName) +{ + return fileName.replace("./log/","").replace("-op.log",""); +} + void UserOperationLogForm::loadUserOperationLog() { LogFileTableModel* model = new LogFileTableModel(this); QString filePath = UserOperationLog::Default()->currentLogFile(); model->setFileName(filePath); + btn->setText(fileNameToDate(filePath)); QStringList header; header<<"Operation Date"<<"Operation Time"<<"User"<<"Operation"; model->setHeader(header); // UserOperationLog::getHistoryLogFiles(); table->setModel(model); table->setAlternatingRowColors(true); - table->setSelectionMode(QAbstractItemView::SingleSelection); + table->setSelectionMode(QAbstractItemView::NoSelection); table->setEditTriggers(QAbstractItemView::NoEditTriggers); - table->setSelectionBehavior(QAbstractItemView::SelectRows); table->verticalHeader()->setDefaultSectionSize(38); table->horizontalHeader()->setStretchLastSection(true); table->setColumnWidth(0,250); diff --git a/src/UserOperationLogForm.h b/src/UserOperationLogForm.h index 94f98b4..498c4ee 100644 --- a/src/UserOperationLogForm.h +++ b/src/UserOperationLogForm.h @@ -6,8 +6,8 @@ #define GUI_USEROPERATIONLOGFORM_H #include -#include - +class QTableView; +class QPushButton; class UserOperationLogForm:public QWidget { Q_OBJECT public: @@ -17,6 +17,7 @@ public: private: QTableView * table = nullptr; + QPushButton* btn = nullptr; };