From 9c96fbbba6e06b86749f20c7d6278f5cc8f71146 Mon Sep 17 00:00:00 2001 From: sunwen Date: Mon, 29 Jul 2024 10:16:37 +0800 Subject: [PATCH] feat: Add top and bottom button in UserOperationLog page. --- src/UserOperationLogForm.cpp | 80 +++++++++++--------- src/UserOperationLogForm.h | 14 ++-- src/translations/en_US.ts | 8 ++ src/translations/zh_CN.ts | 141 +++++++++++++++++++---------------- 4 files changed, 138 insertions(+), 105 deletions(-) diff --git a/src/UserOperationLogForm.cpp b/src/UserOperationLogForm.cpp index 7db35a9..65f6c22 100644 --- a/src/UserOperationLogForm.cpp +++ b/src/UserOperationLogForm.cpp @@ -13,6 +13,7 @@ #include "src/dialogs/SelectDialog.h" #include "windows/MainWindow.h" #include "event/EventCenter.h" + QString fileNameToDate(QString fileName) { return fileName.split("log/UserOperationLog/")[1].replace("-op.log", ""); @@ -25,51 +26,59 @@ QString dateToFileName(QString date) UserOperationLogForm::UserOperationLogForm(QWidget* parent) : QWidget (parent) { - layout = new QVBoxLayout(this); + mLayout = new QVBoxLayout(this); QWidget* header = new QWidget(this); QHBoxLayout* headerLayout = new QHBoxLayout(header); QLabel* logdate = new QLabel(tr("Log Date:")); headerLayout->addWidget(logdate); - btn = new QPushButton(header); - headerLayout->addWidget(btn, 0, Qt::AlignLeft); + mDateButton = new QPushButton(header); + headerLayout->addWidget(mDateButton, 0, Qt::AlignLeft); + mTopButton = new QPushButton(header); + mTopButton->setFixedWidth(150); + mTopButton->setText(tr("Top")); + mBottomButton = new QPushButton(header); + mBottomButton->setFixedWidth(150); + mBottomButton->setText(tr("Bottom")); headerLayout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Expanding)); + headerLayout->addWidget(mTopButton, 0, Qt::AlignLeft); + headerLayout->addWidget(mBottomButton, 0, Qt::AlignLeft); - model = new LogFileTableModel(this); - model->setHeader(QStringList()<< tr("Operation Date") << tr("Operation Time") << tr("User") << tr("Operation")); + mModel = new LogFileTableModel(this); + mModel->setHeader(QStringList()<< tr("Operation Date") << tr("Operation Time") << tr("User") << tr("Operation")); loadUserOperationLog(); - table = new SlideTableView(this); - layout->addWidget(header); - layout->addWidget(table); - table->setModel(model); - table->setAlternatingRowColors(true); - table->setSelectionMode(QAbstractItemView::NoSelection); - table->setEditTriggers(QAbstractItemView::NoEditTriggers); - table->verticalHeader()->setDefaultSectionSize(38); - table->horizontalHeader()->setStretchLastSection(true); - table->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); - table->setColumnWidth(0, 250); - table->setColumnWidth(1, 250); - table->setColumnWidth(2, 200); - table->verticalScrollBar()->setStyleSheet("QScrollBar:vertical { width: 40px; }");; + mLogTable = new SlideTableView(this); + mLayout->addWidget(header); + mLayout->addWidget(mLogTable); + mLogTable->setModel(mModel); + mLogTable->setAlternatingRowColors(true); + mLogTable->setSelectionMode(QAbstractItemView::NoSelection); + mLogTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + mLogTable->verticalHeader()->setDefaultSectionSize(38); + mLogTable->horizontalHeader()->setStretchLastSection(true); + mLogTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); + mLogTable->setColumnWidth(0, 250); + mLogTable->setColumnWidth(1, 250); + mLogTable->setColumnWidth(2, 200); + mLogTable->verticalScrollBar()->setStyleSheet("QScrollBar:vertical { width: 40px; }");; //暂时先放构造函数,之后需要移除,等需要时再调用 - connect(btn, &QPushButton::clicked, [=]() { + connect(mDateButton, &QPushButton::clicked, [=]() { auto files = UserOperationLog::getHistoryLogFiles(); QStringList dates; for (auto f : files) { dates << fileNameToDate(f); } - if (!dialog) { - dialog = new SelectDialog(this); - dialog->setWindowModality(Qt::WindowModal); + if (!mSelectDateDialog) { + mSelectDateDialog = new SelectDialog(this); + mSelectDateDialog->setWindowModality(Qt::WindowModal); } - dialog->setValues(dates); - if (!selectedDateStr.isEmpty()) dialog->setSelectedValue(selectedDateStr); - if (dialog->exec() == QDialog::Accepted) + mSelectDateDialog->setValues(dates); + if (!mSelectedDateStr.isEmpty()) mSelectDateDialog->setSelectedValue(mSelectedDateStr); + if (mSelectDateDialog->exec() == QDialog::Accepted) { - QString date = dialog->getSelectedValue(); + QString date = mSelectDateDialog->getSelectedValue(); QString f = dateToFileName(date); this->loadUserOperationLog(f, date); } @@ -77,9 +86,12 @@ UserOperationLogForm::UserOperationLogForm(QWidget* parent) connect(EventCenter::Default(), &EventCenter::ReloadLanguage, [=]() { logdate->setText(tr("Log Date:")); - model->setHeader(QStringList()<< tr("Operation Date") << tr("Operation Time") << tr("User") << tr("Operation")); + mModel->setHeader(QStringList()<< tr("Operation Date") << tr("Operation Time") << tr("User") << tr("Operation")); }); + connect(mTopButton, &QPushButton::clicked, mLogTable, &SlideTableView::scrollToTop); + connect(mBottomButton, &QPushButton::clicked, mLogTable, &SlideTableView::scrollToBottom); + } UserOperationLogForm::~UserOperationLogForm() { @@ -90,19 +102,19 @@ UserOperationLogForm::~UserOperationLogForm() { void UserOperationLogForm::loadUserOperationLog() { QString filePath = UserOperationLog::Default()->currentLogFile(); - btn->setText(fileNameToDate(filePath)); + mDateButton->setText(fileNameToDate(filePath)); loadUserOperationLog(filePath, fileNameToDate(filePath)); - selectedDateStr = fileNameToDate(filePath); + mSelectedDateStr = fileNameToDate(filePath); } void UserOperationLogForm::loadUserOperationLog(const QString& fileName, const QString& date) { - selectedDateStr = date; - model->setFileName(dateToFileName(date)); - btn->setText(date); + mSelectedDateStr = date; + mModel->setFileName(dateToFileName(date)); + mDateButton->setText(date); } void UserOperationLogForm::showEvent(QShowEvent *aEvent) { - loadUserOperationLog("", selectedDateStr); + loadUserOperationLog("", mSelectedDateStr); QWidget::showEvent(aEvent); } diff --git a/src/UserOperationLogForm.h b/src/UserOperationLogForm.h index 26465e2..41b830e 100644 --- a/src/UserOperationLogForm.h +++ b/src/UserOperationLogForm.h @@ -19,12 +19,14 @@ protected: void showEvent(QShowEvent *aEvent) override; private: - QTableView* table = nullptr; - QPushButton* btn = nullptr; - LogFileTableModel* model = nullptr; - SelectDialog* dialog = nullptr; - QVBoxLayout* layout = nullptr; - QString selectedDateStr; + QTableView* mLogTable = nullptr; + QPushButton* mDateButton = nullptr; + QPushButton* mTopButton = nullptr; + QPushButton* mBottomButton = nullptr; + LogFileTableModel* mModel = nullptr; + SelectDialog* mSelectDateDialog = nullptr; + QVBoxLayout* mLayout = nullptr; + QString mSelectedDateStr; }; diff --git a/src/translations/en_US.ts b/src/translations/en_US.ts index de94a50..69e1c66 100644 --- a/src/translations/en_US.ts +++ b/src/translations/en_US.ts @@ -1898,6 +1898,14 @@ progress:99% Operation + + Top + + + + Bottom + + WarningMessageWidget diff --git a/src/translations/zh_CN.ts b/src/translations/zh_CN.ts index d696ec9..375b3f8 100644 --- a/src/translations/zh_CN.ts +++ b/src/translations/zh_CN.ts @@ -247,47 +247,47 @@ - + Name 姓名 - + Role 角色 - + Comment 备注 - + Add 新增 - + Edit 编辑 - + Delete 删除 - + Can't delete current log in account! 无法删除当前用户! - + Delete account with ID:"%1"! 删除账户ID:"%1"! @@ -416,6 +416,7 @@ DeviceManager + DMS connection error @@ -662,58 +663,58 @@ progress:99% - + Accession Number 检查单号 - + Name 姓名 - + Gender 性别 - - - - + + + + Female - - - + + + Male - - + + Other 其他 - + Birth Date 出生日期 - + ID can't be empty! ID不能为空 - + Patient Name can't be empty! 姓名不能为空 - + The ID and Accession number is already existed! ID和检查单号已存在 @@ -722,12 +723,12 @@ progress:99% 备注 - + F - + M @@ -1708,7 +1709,7 @@ progress:99% Other - + 其他 @@ -2261,99 +2262,99 @@ parameters 新增(拉取) - - + + Add 新增 - - + + Edit 编辑 - - + + Patient Information Manage 检查对象信息录入 - - + + Delete 删除 - - + + Select 选择 - + Can't delete selected Patient ! 不能删除已经被选择的对象 - - + + Alert - + Delete Patient "%1" ? 删除检查对象"%1"? - + Confirm 确认 - + Can't delete selected Patient , db submit error! - + ID 检查对象ID - - + + AccessionNumber 检查单号 - - + + Name 姓名 - - + + Birth Date 出生日期 - - + + Gender 性别 - - + + Add Date 添加日期 - - + + Comment 备注 @@ -2675,32 +2676,42 @@ parameters UserOperationLogForm - - + + Log Date: 日志时间 - + Top + 回顶部 + + + + Bottom + 去底部 + + + + Operation Date 操作日期 - - + + Operation Time 操作时间 - - + + User 用户 - - + + Operation 操作内容