Change LogDateSelectDialog to selectDialog

This commit is contained in:
Krad
2021-12-07 14:08:05 +08:00
parent f36570c801
commit 6627b8bb2a
4 changed files with 86 additions and 86 deletions

View File

@@ -2,11 +2,11 @@
// Created by Krad on 2021/11/24.
//
#include "LogDateSelectDialog.h"
#include "SelectDialog.h"
#include "components/SlidePickerBox.h"
#include <QVBoxLayout>
#include <QLabel>
LogDateSelectDialog::LogDateSelectDialog(QWidget *parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) {
SelectDialog::SelectDialog(QWidget *parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) {
this->setFixedSize(360,380);
QVBoxLayout* layout = new QVBoxLayout(formWidget);
box = new SlidePickerBox(formWidget);
@@ -14,22 +14,22 @@ LogDateSelectDialog::LogDateSelectDialog(QWidget *parent, Qt::WindowFlags f) : G
layout->addWidget(box);
}
LogDateSelectDialog::~LogDateSelectDialog() {
SelectDialog::~SelectDialog() {
}
bool LogDateSelectDialog::updateReferenceData() {
bool SelectDialog::updateReferenceData() {
return true;
}
void LogDateSelectDialog::setAvailableDates(QStringList dates) {
void SelectDialog::setAvailableDates(QStringList dates) {
box->setItems(dates);
}
QString LogDateSelectDialog::getSelectedValue() {
QString SelectDialog::getSelectedValue() {
return box->getSelectedValue();
}
void LogDateSelectDialog::setSelectedValue(QString & val) {
void SelectDialog::setSelectedValue(QString & val) {
box->setSelectedValue(val);
}

View File

@@ -2,16 +2,16 @@
// Created by Krad on 2021/11/24.
//
#ifndef GUI_LOGDATESELECTDIALOG_H
#define GUI_LOGDATESELECTDIALOG_H
#ifndef GUI_SelectDialog_H
#define GUI_SelectDialog_H
#include "GUIFormBaseDialog.h"
class SlidePickerBox;
class LogDateSelectDialog :public GUIFormBaseDialog{
class SelectDialog :public GUIFormBaseDialog{
Q_OBJECT
public:
explicit LogDateSelectDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
~LogDateSelectDialog() override;
explicit SelectDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
~SelectDialog() override;
void setAvailableDates(QStringList dates);
QString getSelectedValue();
void setSelectedValue(QString& val);
@@ -21,4 +21,4 @@ protected:
};
#endif //GUI_LOGDATESELECTDIALOG_H
#endif //GUI_SelectDialog_H

View File

@@ -13,52 +13,52 @@
#include <QTableView>
#include "components/SlideableTableView.h"
#include <QPushButton>
#include "LogDateSelectDialog.h"
#include "SelectDialog.h"
#include "mainwindow.h"
QString fileNameToDate(QString fileName)
{
return fileName.split("log/")[1].replace("-op.log","");
return fileName.split("log/")[1].replace("-op.log", "");
}
QString dateToFileName(QString date)
{
return QString("./log/") + date + QString("-op.log");
return QString("./log/") + date + QString("-op.log");
}
UserOperationLogForm::UserOperationLogForm(QWidget *parent) {
layout = new QVBoxLayout(this);
QWidget* header = new QWidget(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);
model = new LogFileTableModel(this);
//暂时先放构造函数,之后需要移除,等需要时再调用
loadUserOperationLog();
connect(btn,&QPushButton::clicked,[=](){
auto files = UserOperationLog::getHistoryLogFiles();
QStringList dates;
for (auto f :files)
{
dates<<fileNameToDate(f);
}
if(!dialog){
dialog = new LogDateSelectDialog(this);
dialog->setWindowModality(Qt::WindowModal);
}
dialog->setAvailableDates(dates);
if (!selectedDateStr.isEmpty()) dialog->setSelectedValue(selectedDateStr);
if (dialog->exec() == QDialog::Accepted)
{
QString date = dialog->getSelectedValue();
QString f = dateToFileName(date);
this->loadUserOperationLog(f,date);
}
});
UserOperationLogForm::UserOperationLogForm(QWidget* parent) {
layout = new QVBoxLayout(this);
QWidget* header = new QWidget(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);
model = new LogFileTableModel(this);
//暂时先放构造函数,之后需要移除,等需要时再调用
loadUserOperationLog();
connect(btn, &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);
}
dialog->setAvailableDates(dates);
if (!selectedDateStr.isEmpty()) dialog->setSelectedValue(selectedDateStr);
if (dialog->exec() == QDialog::Accepted)
{
QString date = dialog->getSelectedValue();
QString f = dateToFileName(date);
this->loadUserOperationLog(f, date);
}
});
}
@@ -69,31 +69,31 @@ UserOperationLogForm::~UserOperationLogForm() {
void UserOperationLogForm::loadUserOperationLog() {
QString filePath = UserOperationLog::Default()->currentLogFile();
model->setFileName(filePath);
btn->setText(fileNameToDate(filePath));
loadUserOperationLog(filePath, fileNameToDate(filePath));
selectedDateStr = fileNameToDate(filePath);
QString filePath = UserOperationLog::Default()->currentLogFile();
model->setFileName(filePath);
btn->setText(fileNameToDate(filePath));
loadUserOperationLog(filePath, fileNameToDate(filePath));
selectedDateStr = fileNameToDate(filePath);
}
void UserOperationLogForm::loadUserOperationLog(const QString& fileName, const QString& date) {
selectedDateStr = date;
model->setFileName(dateToFileName(date));
btn->setText(date);
QStringList header;
header<<"Operation Date"<<"Operation Time"<<"User"<<"Operation";
model->setHeader(header);
// UserOperationLog::getHistoryLogFiles();
delete table;
table = new SlideableTableView(this);
layout->addWidget(table);
table->setModel(model);
selectedDateStr = date;
model->setFileName(dateToFileName(date));
btn->setText(date);
QStringList header;
header << "Operation Date" << "Operation Time" << "User" << "Operation";
model->setHeader(header);
// UserOperationLog::getHistoryLogFiles();
delete table;
table = new SlideableTableView(this);
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->setColumnWidth(0,250);
table->setColumnWidth(1,250);
table->setAlternatingRowColors(true);
table->setSelectionMode(QAbstractItemView::NoSelection);
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
table->verticalHeader()->setDefaultSectionSize(38);
table->horizontalHeader()->setStretchLastSection(true);
table->setColumnWidth(0, 250);
table->setColumnWidth(1, 250);
}

View File

@@ -10,22 +10,22 @@ class QTableView;
class QPushButton;
class LogFileTableModel;
class QVBoxLayout;
class LogDateSelectDialog;
class UserOperationLogForm:public QWidget {
Q_OBJECT
class SelectDialog;
class UserOperationLogForm :public QWidget {
Q_OBJECT
public:
explicit UserOperationLogForm(QWidget *parent = nullptr);
~UserOperationLogForm();
void loadUserOperationLog();
void loadUserOperationLog(const QString& fileName, const QString& date);
explicit UserOperationLogForm(QWidget* parent = nullptr);
~UserOperationLogForm();
void loadUserOperationLog();
void loadUserOperationLog(const QString& fileName, const QString& date);
private:
QTableView * table = nullptr;
QPushButton* btn = nullptr;
LogFileTableModel* model = nullptr;
LogDateSelectDialog* dialog = nullptr;
QVBoxLayout* layout = nullptr;
QString selectedDateStr;
QTableView* table = nullptr;
QPushButton* btn = nullptr;
LogFileTableModel* model = nullptr;
SelectDialog* dialog = nullptr;
QVBoxLayout* layout = nullptr;
QString selectedDateStr;
};