Simple UserOperationLog table.
This commit is contained in:
56
src/log/LogFileTableModel.cpp
Normal file
56
src/log/LogFileTableModel.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
//
|
||||
// Created by Krad on 2021/11/23.
|
||||
//
|
||||
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QTextStream>
|
||||
#include "LogFileTableModel.h"
|
||||
|
||||
LogFileTableModel::LogFileTableModel(QObject *parent) : QAbstractTableModel(parent) {
|
||||
|
||||
}
|
||||
|
||||
void LogFileTableModel::setFileName(QString fileName) {
|
||||
logdata.clear();
|
||||
QFile f;
|
||||
f.setFileName(fileName);
|
||||
if (!f.exists()) return;
|
||||
if(f.open(QFile::OpenModeFlag::ReadOnly | QFile::OpenModeFlag::Text))
|
||||
{
|
||||
|
||||
QTextStream in(&f);
|
||||
while(!in.atEnd()){
|
||||
logdata.push_back(in.readLine().split("\t"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QVariant LogFileTableModel::data(const QModelIndex &index, int role) const {
|
||||
if (!index.isValid()) return QVariant();
|
||||
if (role == Qt::TextAlignmentRole) {
|
||||
return Qt::AlignCenter;
|
||||
}
|
||||
if (role == Qt::DisplayRole || role == Qt::EditRole )
|
||||
{
|
||||
return logdata[index.row()][index.column()];
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
int LogFileTableModel::rowCount(const QModelIndex &parent) const {
|
||||
if (!logdata.isEmpty()) return logdata.count();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LogFileTableModel::columnCount(const QModelIndex &parent) const {
|
||||
if (!logdata.isEmpty()) return logdata[0].count();
|
||||
return 0;
|
||||
}
|
||||
|
||||
QVariant LogFileTableModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
||||
if(role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
if(orientation == Qt::Horizontal)
|
||||
return headerStrings.at(section);
|
||||
return QVariant();
|
||||
}
|
||||
Reference in New Issue
Block a user