赞
踩
写日志以及日志查询系统--本地版
日志存储在文件夹内,不涉及到数据库以及网络操作,新手上路,很多功能不完善,还请指教
一共两个界面,三个类:
- <?xml version="1.0" encoding="UTF-8"?>
- <ui version="4.0">
- <class>Login</class>
- <widget class="QDialog" name="Login">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>400</width>
- <height>300</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Dialog</string>
- </property>
- <layout class="QGridLayout" name="gridLayout">
- <item row="0" column="0">
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <widget class="QLabel" name="nameLabel">
- <property name="text">
- <string>用户名</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLineEdit" name="nameLineEdit"/>
- </item>
- </layout>
- </item>
- <item row="1" column="0">
- <layout class="QHBoxLayout" name="horizontalLayout_2">
- <item>
- <widget class="QLabel" name="passLabel">
- <property name="text">
- <string> 密码 </string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLineEdit" name="passLineEdit"/>
- </item>
- </layout>
- </item>
- <item row="2" column="0">
- <layout class="QHBoxLayout" name="horizontalLayout_3">
- <item>
- <widget class="QPushButton" name="loBtn">
- <property name="text">
- <string>登录</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="creBtn">
- <property name="text">
- <string>点此注册</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item row="3" column="0">
- <layout class="QHBoxLayout" name="horizontalLayout_4">
- <item>
- <widget class="QPushButton" name="reBtn">
- <property name="text">
- <string>注册</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="canlBtn">
- <property name="text">
- <string>取消</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
- </widget>
- <resources/>
- <connections/>
- </ui>

- <?xml version="1.0" encoding="UTF-8"?>
- <ui version="4.0">
- <class>Log</class>
- <widget class="QMainWindow" name="Log">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>649</width>
- <height>472</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Log</string>
- </property>
- <widget class="QWidget" name="centralWidget">
- <layout class="QGridLayout" name="gridLayout">
- <item row="0" column="0">
- <widget class="QTabWidget" name="tabWidget">
- <property name="currentIndex">
- <number>1</number>
- </property>
- <widget class="QWidget" name="writeLogTab">
- <attribute name="title">
- <string>Tab 1</string>
- </attribute>
- <layout class="QGridLayout" name="gridLayout_2">
- <item row="0" column="0">
- <widget class="QLineEdit" name="taskMenuLineEdit">
- <property name="inputMethodHints">
- <set>Qt::ImhNone</set>
- </property>
- <property name="text">
- <string>任务</string>
- </property>
- <property name="alignment">
- <set>Qt::AlignCenter</set>
- </property>
- <property name="cursorMoveStyle">
- <enum>Qt::LogicalMoveStyle</enum>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QLineEdit" name="timeMenuLineEdit">
- <property name="text">
- <string>耗时</string>
- </property>
- <property name="alignment">
- <set>Qt::AlignCenter</set>
- </property>
- </widget>
- </item>
- <item row="0" column="2">
- <widget class="QLineEdit" name="rateMenuLineEdit">
- <property name="text">
- <string>完成率(所占百分比)</string>
- </property>
- <property name="alignment">
- <set>Qt::AlignCenter</set>
- </property>
- </widget>
- </item>
- <item row="0" column="3">
- <spacer name="horizontalSpacer">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>145</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item row="1" column="0">
- <widget class="QLineEdit" name="taskLineEdit_1"/>
- </item>
- <item row="1" column="1">
- <widget class="QLineEdit" name="timeLineEdit_1"/>
- </item>
- <item row="1" column="2">
- <widget class="QLineEdit" name="rateLineEdit_1"/>
- </item>
- <item row="1" column="3">
- <widget class="QPushButton" name="saveBtn_1">
- <property name="text">
- <string> 保存</string>
- </property>
- </widget>
- </item>
- <item row="2" column="0">
- <widget class="QLineEdit" name="taskLineEdit_2"/>
- </item>
- <item row="2" column="1">
- <widget class="QLineEdit" name="timeLineEdit_2"/>
- </item>
- <item row="2" column="2">
- <widget class="QLineEdit" name="rateLineEdit_2"/>
- </item>
- <item row="2" column="3">
- <widget class="QPushButton" name="saveBtn_2">
- <property name="text">
- <string> 保存</string>
- </property>
- </widget>
- </item>
- <item row="3" column="0">
- <widget class="QLineEdit" name="taskLineEdit_3"/>
- </item>
- <item row="3" column="1">
- <widget class="QLineEdit" name="timeLineEdit_3"/>
- </item>
- <item row="3" column="2">
- <widget class="QLineEdit" name="rateLineEdit_3"/>
- </item>
- <item row="3" column="3">
- <widget class="QPushButton" name="saveBtn_3">
- <property name="text">
- <string> 保存</string>
- </property>
- </widget>
- </item>
- <item row="4" column="0">
- <widget class="QLineEdit" name="taskLineEdit_4"/>
- </item>
- <item row="4" column="1">
- <widget class="QLineEdit" name="timeLineEdit_4"/>
- </item>
- <item row="4" column="2">
- <widget class="QLineEdit" name="rateLineEdit_4"/>
- </item>
- <item row="4" column="3">
- <widget class="QPushButton" name="saveBtn_4">
- <property name="text">
- <string> 保存</string>
- </property>
- </widget>
- </item>
- <item row="5" column="0">
- <widget class="QLineEdit" name="taskLineEdit_5"/>
- </item>
- <item row="5" column="1">
- <widget class="QLineEdit" name="timeLineEdit_5"/>
- </item>
- <item row="5" column="2">
- <widget class="QLineEdit" name="rateLineEdit_5"/>
- </item>
- <item row="5" column="3">
- <widget class="QPushButton" name="saveBtn_5">
- <property name="text">
- <string> 保存</string>
- </property>
- </widget>
- </item>
- <item row="6" column="0">
- <widget class="QLineEdit" name="taskLineEdit_6"/>
- </item>
- <item row="6" column="1">
- <widget class="QLineEdit" name="timeLineEdit_6"/>
- </item>
- <item row="6" column="2">
- <widget class="QLineEdit" name="rateLineEdit_6"/>
- </item>
- <item row="6" column="3">
- <widget class="QPushButton" name="saveBtn_6">
- <property name="text">
- <string> 保存</string>
- </property>
- </widget>
- </item>
- <item row="7" column="0">
- <widget class="QLineEdit" name="taskLineEdit_7"/>
- </item>
- <item row="7" column="1">
- <widget class="QLineEdit" name="timeLineEdit_7"/>
- </item>
- <item row="7" column="2">
- <widget class="QLineEdit" name="rateLineEdit_7"/>
- </item>
- <item row="7" column="3">
- <widget class="QPushButton" name="saveBtn_7">
- <property name="text">
- <string> 保存</string>
- </property>
- </widget>
- </item>
- <item row="8" column="0">
- <widget class="QLineEdit" name="taskLineEdit_8"/>
- </item>
- <item row="8" column="1">
- <widget class="QLineEdit" name="timeLineEdit_8"/>
- </item>
- <item row="8" column="2">
- <widget class="QLineEdit" name="rateLineEdit_8"/>
- </item>
- <item row="8" column="3">
- <widget class="QPushButton" name="saveBtn_8">
- <property name="text">
- <string> 保存</string>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- <widget class="QWidget" name="readLogTab">
- <attribute name="title">
- <string>Tab 2</string>
- </attribute>
- <layout class="QGridLayout" name="gridLayout_3">
- <item row="0" column="0">
- <widget class="QCalendarWidget" name="calendarWidget"/>
- </item>
- <item row="0" column="1" rowspan="2">
- <widget class="QTableView" name="tableView"/>
- </item>
- </layout>
- </widget>
- </widget>
- </item>
- </layout>
- </widget>
- <widget class="QMenuBar" name="menuBar">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>649</width>
- <height>22</height>
- </rect>
- </property>
- </widget>
- <widget class="QToolBar" name="mainToolBar">
- <attribute name="toolBarArea">
- <enum>TopToolBarArea</enum>
- </attribute>
- <attribute name="toolBarBreak">
- <bool>false</bool>
- </attribute>
- </widget>
- <widget class="QStatusBar" name="statusBar"/>
- </widget>
- <layoutdefault spacing="6" margin="11"/>
- <resources/>
- <connections/>
- </ui>

- #ifndef FILEOPERATE_H
- #define FILEOPERATE_H
-
- #include<QString>
- #include<QObject>
- #include<QMap>
- #include<QDate>
-
- class FileOperate
- {
- public:
- FileOperate();
-
- QString strUserName;//用户名
- const QString strInfomationPath = QObject::tr("./source/Infomation/info.txt");//用户信息存放位置
- const QString strUserBasePath = QObject::tr("./source/User");//用户存放位置
-
- QMap<QString, QString>infoMap;//用户信息<用户名, 密码>
-
- struct LOG
- {
- QString task;
- QString time;
- QString rate;
- }log;//log
-
- QList<LOG> logList;//log列表
-
-
- bool newDirAndFile(bool stand = false);//检查并设置目录及文件
-
- bool getInfo();//获取用户信息
-
- bool writeInfo(const QString, const QString);//写入用户信息
-
- bool getLog(QDate data = QDate::currentDate());//获取日志
-
- bool writeLog(const QString, const QString, const QString);//写入日志
- };
-
- #endif // FILEOPERATE_H

- #include "fileoperate.h"
-
- #include<QDir>
- #include<QFile>
- #include<QTextStream>
-
-
- FileOperate::FileOperate()
- {
- this->strUserName = nullptr;
-
- this->log.task = nullptr;
- this->log.time = nullptr;
- this->log.rate = nullptr;
-
- this->newDirAndFile();
- }
-
- bool FileOperate::newDirAndFile(bool stand)
- {
- QDir dir;
-
- //检查并创建目录 ./source/Infomation/
- if (!dir.exists(QObject::tr("./source/Infomation")))
- if (!dir.mkpath(QObject::tr("./source/Infomation")))
- return false;
-
-
- //检查并创建文件 ./source/Infomation/info.txt
- QFile file;
- file.setFileName(this->strInfomationPath);
- if (!file.open(QIODevice::ReadWrite | QIODevice::Text))
- return false;
-
- // info.txt 文件中写入 用户名\t密码\n
- //name\tpass\n
- QTextStream info(&file);
- info << QObject::tr("用户名\t密码\n");
-
- file.close();
-
- //检查并创建目录 ./source/User/
- if (!dir.exists(this->strUserBasePath))
- if (!dir.mkpath(this->strUserBasePath))
- return false;
-
- //stand 为 false 时执行到此结束,为 true 时继续下面的步骤
- if (!stand)
- return true;
-
- //检查并创建目录 ./source/User/userName/
- if (!dir.exists(this->strUserBasePath + QObject::tr("/") + this->strUserName))
- if (!dir.mkpath(this->strUserBasePath + QObject::tr("/") + this->strUserName))
- return false;
-
- //检查并创建文件 ./source/User/userName/date.txt
- file.setFileName(this->strUserBasePath +
- QObject::tr("/") +
- this->strUserName +
- QObject::tr("/") +
- QDate::currentDate().toString(QObject::tr("yyyyMMdd")) +
- QObject::tr(".txt"));
- if (!file.open(QIODevice::ReadWrite | QIODevice::Text))
- return false;
-
- // date.txt 文件中写入 序号\t任务\t\t\t\t\t\t\t\t时间\t完成率\n
- //name\tpass\n
- QTextStream date(&file);
- date << QObject::tr("序号\t任务\t\t\t\t\t\t\t\t时间\t完成率\n");
-
- file.close();
-
- return true;
- }
-
- bool FileOperate::getInfo()
- {
- this->infoMap.clear();
-
- //打开用户信息文件 ./source/Infomation/info.txt
- QFile file(this->strInfomationPath);
- if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
- return false;
-
- QTextStream out(&file);
-
- QString strLine = out.readLine();
-
- while (!out.atEnd())
- {
- strLine = out.readLine();
- if (QObject::tr("") == strLine)
- continue;
-
- QStringList strList = strLine.split(QObject::tr("\t"));
- if (2 != strList.count())
- continue;
-
- this->infoMap.insert(strList.at(0), strList.at(1));
- }
-
- file.close();
- return true;
- }
-
- bool FileOperate::writeInfo(const QString userName, const QString userPass)
- {
- //打开用户信息文件 ./source/Infomation/info.txt
- QFile file(this->strInfomationPath);
- if (!file.open(QIODevice::Append | QIODevice::Text))
- return false;
-
- QTextStream in(&file);
-
- in << userName << QObject::tr("\t") << userPass << QObject::tr("\n");
-
- this->infoMap.insert(userName, userPass);
-
- file.close();
-
- return true;
- }
-
- bool FileOperate::getLog(QDate data)
- {
- this->logList.clear();
-
- //打开用户日志文件 ./source/User/userName/date.txt
- QFile file(this->strUserBasePath +
- QObject::tr("/") +
- this->strUserName +
- QObject::tr("/") +
- /*QDate::currentDate()*/data.toString(QObject::tr("yyyyMMdd")) +
- QObject::tr(".txt"));
- if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
- return false;
-
- QTextStream out(&file);
-
- QString strLine = out.readLine();
-
- while(!out.atEnd())
- {
- strLine = out.readLine();
-
- if (QObject::tr("") == strLine)
- continue;
-
- QStringList strList = strLine.split(QObject::tr("\t"));
- if (4 != strList.count())
- continue;
-
- this->log.task = strList.at(1);
- this->log.time = strList.at(2);
- this->log.rate = strList.at(3);
-
- this->logList.append(this->log);
- }
-
- file.close();
- return true;
- }
-
- bool FileOperate::writeLog(const QString task, const QString time, const QString rate)
- {
- if (!this->getLog())
- return false;
-
- //打开用户日志文件 ./source/User/userName/date.txt
- QFile file(this->strUserBasePath +
- QObject::tr("/") +
- this->strUserName +
- QObject::tr("/") +
- QDate::currentDate().toString(QObject::tr("yyyyMMdd")) +
- QObject::tr(".txt"));
- if (!file.open(QIODevice::Append | QIODevice::Text))
- return false;
-
- this->log.task = task;
- this->log.time = time;
- this->log.rate = rate;
-
- this->logList.append(this->log);
-
- QTextStream in(&file);
-
- QString strNum = QString().setNum(this->logList.count(), 10);
-
- in << strNum << QObject::tr("\t") << task << QObject::tr("\t") << time << QObject::tr("\t") << rate << QObject::tr("\n");
-
- file.close();
-
- return true;
- }

- #ifndef LOGIN_H
- #define LOGIN_H
-
- #include <QDialog>
-
- #include"fileoperate.h"
-
- namespace Ui {
- class Login;
- }
-
- class Login : public QDialog
- {
- Q_OBJECT
-
- public:
- explicit Login(QWidget *parent = 0);
- Login(FileOperate* ,QWidget *parent = 0);
- ~Login();
-
- private slots:
- void on_canlBtn_clicked(bool checked);
-
- void on_creBtn_clicked();
-
- void on_reBtn_clicked();
-
- void on_loBtn_clicked();
-
- private:
- Ui::Login *ui;
-
- FileOperate* fileOperate;
- };
-
- #endif // LOGIN_H

- #include "login.h"
- #include "ui_login.h"
-
- #include<QMessageBox>
-
- Login::Login(QWidget *parent) :
- QDialog(parent),
- ui(new Ui::Login)
- {
- ui->setupUi(this);
- }
-
- Login::Login(FileOperate* fileOperate, QWidget *parent):
- QDialog(parent),
- ui(new Ui::Login)
- {
- ui->setupUi(this);
- this->setWindowTitle(tr("登录系统"));
- this->fileOperate = fileOperate;
-
- ui->reBtn->hide();//注册按钮隐藏
- ui->canlBtn->hide();//取消按钮隐藏
-
- //设置占位符
- ui->nameLineEdit->setPlaceholderText(tr("请输入用户名"));
- ui->passLineEdit->setPlaceholderText(tr("请输入密码"));
-
- //设置密码栏格式
- ui->passLineEdit->setEchoMode(QLineEdit::Password);
- }
-
- Login::~Login()
- {
- delete ui;
- }
-
- //取消按钮
- void Login::on_canlBtn_clicked(bool checked)
- {
- if (!checked)
- {
- ui->nameLineEdit->clear();//用户名清空
- ui->passLineEdit->clear();//密码清空
- }
-
- ui->loBtn->show();//登录按钮显示
- ui->creBtn->show();//点击注册按钮显示
-
- ui->reBtn->hide();//注册按钮隐藏
- ui->canlBtn->hide();//取消按钮隐藏
- }
-
- //点击注册按钮
- void Login::on_creBtn_clicked()
- {
- //密码用户名清空,光标停留在用户名栏
- ui->nameLineEdit->clear();
- ui->passLineEdit->clear();
- ui->nameLineEdit->setFocus();
-
- ui->reBtn->show();//注册按钮显示
- ui->canlBtn->show();//取消按钮显示
-
- ui->loBtn->hide();//登录按钮隐藏
- ui->creBtn->hide();//点击注册按钮隐藏
- }
-
- //注册按钮
- void Login::on_reBtn_clicked()
- {
- QString userName = ui->nameLineEdit->text();
- QString userPass = ui->passLineEdit->text();
-
- if (userName.isEmpty())
- {
- QMessageBox::warning(this, tr("警告"), tr("用户名不能为空"));
- ui->nameLineEdit->clear();
- ui->passLineEdit->clear();
- ui->nameLineEdit->setFocus();
- return;
- }
-
- if (userName.contains(" "))
- {
- QMessageBox::warning(this, tr("警告"), tr("用户名不能包含空格"));
- ui->nameLineEdit->clear();
- ui->passLineEdit->clear();
- ui->nameLineEdit->setFocus();
- return;
- }
-
- if (userPass.isEmpty())
- {
- QMessageBox::warning(this, tr("警告"), tr("密码不能为空"));
- ui->passLineEdit->clear();
- ui->passLineEdit->setFocus();
- return;
- }
-
- if (userPass.contains(" "))
- {
- QMessageBox::warning(this, tr("警告"), tr("密码不能包含空格"));
- ui->passLineEdit->clear();
- ui->passLineEdit->setFocus();
- return;
- }
-
- if (this->fileOperate->infoMap.contains(userName))
- {
- QMessageBox::warning(this, tr("警告"), tr("用户名已存在"));
- ui->nameLineEdit->clear();
- ui->passLineEdit->clear();
- ui->nameLineEdit->setFocus();
- return;
- }
-
- //this->fileOperate->infoMap.insert(userName, userPass);写入步骤添加,此处无需添加
-
- //写入失败,也就是注册失败????
- if (!this->fileOperate->writeInfo(userName, userPass))
- return;
-
- //写入成功,注册成功
- QMessageBox::information(this, tr("提示"), tr("注册成功请登录"));
-
- //返回登录界面
- on_canlBtn_clicked(true);
- return;
- }
-
- void Login::on_loBtn_clicked()
- {
- QString userName = ui->nameLineEdit->text();
- QString userPass = ui->passLineEdit->text();
-
- this->fileOperate->getInfo();
-
- if (userName.isEmpty() || userPass.isEmpty())
- {
- QMessageBox::warning(this, tr("警告"), tr("用户名或密码不能为空"));
- ui->nameLineEdit->clear();
- ui->passLineEdit->clear();
- ui->nameLineEdit->setFocus();
- return;
- }
-
- if (
- (!this->fileOperate->infoMap.contains(userName)) ||
- (userPass != this->fileOperate->infoMap.value(userName))
- )
- {
- QMessageBox::warning(this, tr("警告"), tr("用户名或密码错误"));
- ui->nameLineEdit->clear();
- ui->passLineEdit->clear();
- ui->nameLineEdit->setFocus();
- return;
- }
-
- this->fileOperate->strUserName = userName;
-
- if (!this->fileOperate->newDirAndFile(true))
- return;
-
- /*if (!this->fileOperate->getLog())
- return;*/
-
- this->accept();
- }

- #ifndef LOG_H
- #define LOG_H
-
- #include <QMainWindow>
- #include<QStandardItemModel>
-
- #include"fileoperate.h"
-
- namespace Ui {
- class Log;
- }
-
- class Log : public QMainWindow
- {
- Q_OBJECT
-
- public:
- explicit Log(QWidget *parent = 0);
- Log(FileOperate*, QWidget *parent = 0);
- ~Log();
-
- private slots:
- void on_saveBtn_1_clicked();
-
- void on_saveBtn_2_clicked();
-
- void on_saveBtn_3_clicked();
-
- void on_saveBtn_4_clicked();
-
- void on_saveBtn_5_clicked();
-
- void on_saveBtn_6_clicked();
-
- void on_saveBtn_7_clicked();
-
- void on_saveBtn_8_clicked();
-
- void on_calendarWidget_clicked(const QDate &date);
-
- private:
- Ui::Log *ui;
-
- FileOperate* fileOperate;
-
- QStandardItemModel* model = new QStandardItemModel;
-
- bool isOkSaveLog(const QString, const QString, const QString);
-
- void setWriteLogTab();
- void setReadLogTab();
- };
-
- #endif // LOG_H

- #include "log.h"
- #include "ui_log.h"
-
- #include<QMessageBox>
-
-
- Log::Log(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::Log)
- {
- ui->setupUi(this);
- }
-
- Log::Log(FileOperate *fileOperate, QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::Log)
- {
- ui->setupUi(this);
- this->fileOperate = fileOperate;
-
- //设置窗口标题
- this->setWindowTitle(tr("日志管理"));
-
- this->setWriteLogTab();
- this->setReadLogTab();
-
- ui->tabWidget->setCurrentIndex(0);
- }
-
- Log::~Log()
- {
- delete ui;
- }
-
- bool Log::isOkSaveLog(const QString taskText, const QString timeText, const QString rateText)
- {
- if (
- (taskText.trimmed().isEmpty()) ||
- (timeText.trimmed().isEmpty()) ||
- (rateText.trimmed().isEmpty())
- )
- return false;
-
- QString task = taskText.trimmed();
- QString time = timeText.trimmed();
- QString rate = rateText.trimmed();
-
- if ((time.toInt() > 24) || (time.toInt() < 0))
- return false;
-
- if ((rate.toInt() > 100) || (rate.toInt() < 0))
- return false;
-
- //写入步骤操作,此处无需操作
- /*
- this->fileOperate->log.task = task;
- this->fileOperate->log.time = time;
- this->fileOperate->log.rate = rate;
- this->fileOperate->logList.append(log);
- */
-
- return this->fileOperate->writeLog(task, time, rate);
- }
-
- void Log::setWriteLogTab()
- {
- //设置标题文本
- ui->tabWidget->setTabText(0, tr("写日志"));
-
- //设置无边框且透明
- ui->taskMenuLineEdit->setStyleSheet(tr("background:transparent;border-width:0;border-style:outset"));
- ui->timeMenuLineEdit->setStyleSheet(tr("background:transparent;border-width:0;border-style:outset"));
- ui->rateMenuLineEdit->setStyleSheet(tr("background:transparent;border-width:0;border-style:outset"));
- }
-
- void Log::setReadLogTab()
- {
- //设置标题文本
- ui->tabWidget->setTabText(1, tr("查阅日志"));
-
- //设置tabelview
- //QStandardItemModel* model = new QStandardItemModel;
- model->setColumnCount(3);
- model->setHeaderData(0, Qt::Horizontal, tr("任务"));
- model->setHeaderData(1, Qt::Horizontal, tr("耗时"));
- model->setHeaderData(2, Qt::Horizontal, tr("完成率(所占百分比)"));
-
- ui->tableView->setModel(model);
- //ui->tableView->setFixedWidth(200);
- ui->calendarWidget->setFixedWidth(250);
-
- ui->tableView->hide();
- }
-
- void Log::on_saveBtn_1_clicked()
- {
- if (!this->isOkSaveLog(
- ui->taskLineEdit_1->text(),
- ui->timeLineEdit_1->text(),
- ui->rateLineEdit_1->text())
- )
- return;
-
- QMessageBox::information(this, tr("提示"), tr("保存成功"));
- }
-
- void Log::on_saveBtn_2_clicked()
- {
- if (!this->isOkSaveLog(
- ui->taskLineEdit_2->text(),
- ui->timeLineEdit_2->text(),
- ui->rateLineEdit_2->text())
- )
- return;
-
- QMessageBox::information(this, tr("提示"), tr("保存成功"));
- }
-
- void Log::on_saveBtn_3_clicked()
- {
- if (!this->isOkSaveLog(
- ui->taskLineEdit_3->text(),
- ui->timeLineEdit_3->text(),
- ui->rateLineEdit_3->text())
- )
- return;
-
- QMessageBox::information(this, tr("提示"), tr("保存成功"));
- }
-
- void Log::on_saveBtn_4_clicked()
- {
- if (!this->isOkSaveLog(
- ui->taskLineEdit_4->text(),
- ui->timeLineEdit_4->text(),
- ui->rateLineEdit_4->text())
- )
- return;
-
- QMessageBox::information(this, tr("提示"), tr("保存成功"));
- }
-
- void Log::on_saveBtn_5_clicked()
- {
- if (!this->isOkSaveLog(
- ui->taskLineEdit_5->text(),
- ui->timeLineEdit_5->text(),
- ui->rateLineEdit_5->text())
- )
- return;
-
- QMessageBox::information(this, tr("提示"), tr("保存成功"));
- }
-
- void Log::on_saveBtn_6_clicked()
- {
- if (!this->isOkSaveLog(
- ui->taskLineEdit_6->text(),
- ui->timeLineEdit_6->text(),
- ui->rateLineEdit_6->text())
- )
- return;
-
- QMessageBox::information(this, tr("提示"), tr("保存成功"));
- }
-
- void Log::on_saveBtn_7_clicked()
- {
- if (!this->isOkSaveLog(
- ui->taskLineEdit_7->text(),
- ui->timeLineEdit_7->text(),
- ui->rateLineEdit_7->text())
- )
- return;
-
- QMessageBox::information(this, tr("提示"), tr("保存成功"));
- }
-
- void Log::on_saveBtn_8_clicked()
- {
- if (!this->isOkSaveLog(
- ui->taskLineEdit_8->text(),
- ui->timeLineEdit_8->text(),
- ui->rateLineEdit_8->text())
- )
- return;
-
- QMessageBox::information(this, tr("提示"), tr("保存成功"));
- }
-
- void Log::on_calendarWidget_clicked(const QDate &date)
- {
- ui->tableView->hide();
-
- if (!this->fileOperate->getLog(date))
- return;
-
- if (0 == this->fileOperate->logList.count())
- {
- QMessageBox::warning(this, tr("警告"), tr("此日期无日志"));
- return;
- }
-
- this->model->setRowCount(this->fileOperate->logList.count());
-
- /*
- QStringList strTaskList = QStringList();
- QStringList strTimeList = QStringList();
- QStringList strRateList = QStringList();
- */
- for (int i = 0; i < this->fileOperate->logList.count(); i++)
- {
- model->setItem(i, 0, new QStandardItem(this->fileOperate->logList.at(i).task));
- model->setItem(i, 1, new QStandardItem(this->fileOperate->logList.at(i).time));
- model->setItem(i, 2, new QStandardItem(this->fileOperate->logList.at(i).rate));
- /*
- strTaskList.append(this->fileOperate->logList.at(i).task);
- strTimeList.append(this->fileOperate->logList.at(i).time);
- strRateList.append(this->fileOperate->logList.at(i).rate);
- */
- }
-
- ui->tableView->show();
-
- }

- #include "log.h"
- #include <QApplication>
-
- #include"login.h"
- #include"fileoperate.h"
-
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- FileOperate fileOperate = FileOperate();
- Login ldg(&fileOperate);
- if (QDialog::Accepted == ldg.exec())
- {
- Log w(&fileOperate);
- w.show();
-
- return a.exec();
- }
-
- return 0;
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。