追加添加后台任务显示视图未提交文件
This commit is contained in:
parent
8c96ce6101
commit
8dd2f44dc5
88
src/BackgroundTaskListView/BackgroundTaskListModel.cpp
Normal file
88
src/BackgroundTaskListView/BackgroundTaskListModel.cpp
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
#include "BackgroundTaskListModel.h"
|
||||
#include "DataProcessWorkPool.h"
|
||||
|
||||
|
||||
BackgroundTaskListModel* BackgroundTaskListModel::_s_instance = nullptr;
|
||||
|
||||
BackgroundTaskListModel *BackgroundTaskListModel::Instance()
|
||||
{
|
||||
if (!_s_instance) {
|
||||
_s_instance = new BackgroundTaskListModel();
|
||||
}
|
||||
return _s_instance;
|
||||
}
|
||||
|
||||
BackgroundTaskListModel::~BackgroundTaskListModel()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
BackgroundTaskListModel::BackgroundTaskListModel(QObject *parent)
|
||||
: QAbstractTableModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
int BackgroundTaskListModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
return _task_list.size();
|
||||
}
|
||||
|
||||
int BackgroundTaskListModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
return parent.isValid() ? 0 : 3;
|
||||
}
|
||||
|
||||
QVariant BackgroundTaskListModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
int row = index.row();
|
||||
int col = index.column();
|
||||
if (row < 0 || row >= _task_list.size())
|
||||
return QVariant();
|
||||
|
||||
if (role == Qt::DisplayRole) {
|
||||
switch(col) {
|
||||
case 0: return row + 1;
|
||||
case 2: return _task_list.at(row)->GetTaskName();
|
||||
default: return QVariant();
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
int BackgroundTaskListModel::findTaskIndexByName(const QString &task_name)
|
||||
{
|
||||
for (int i = 0; i < _task_list.size(); ++i) {
|
||||
if (_task_list[i]->GetTaskName() == task_name) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void BackgroundTaskListModel::InserTask(DataProcessWorkPool::DataProcessTask* task)
|
||||
{
|
||||
beginInsertRows(QModelIndex(), _task_list.size(), _task_list.size());
|
||||
_task_list.append(task);
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void BackgroundTaskListModel::RemoveTask(const QString &task_name)
|
||||
{
|
||||
int index = findTaskIndexByName(task_name);
|
||||
if (index < 0) {
|
||||
return;
|
||||
}
|
||||
beginRemoveRows(QModelIndex(), _task_list.size(), _task_list.size());
|
||||
_task_list.removeAt(index);
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
void BackgroundTaskListModel::Clear()
|
||||
{
|
||||
|
||||
}
|
||||
37
src/BackgroundTaskListView/BackgroundTaskListModel.h
Normal file
37
src/BackgroundTaskListView/BackgroundTaskListModel.h
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#ifndef BACKGROUNDTASKLISTMODEL_H
|
||||
#define BACKGROUNDTASKLISTMODEL_H
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <QObject>
|
||||
|
||||
namespace DataProcessWorkPool {
|
||||
class DataProcessTask;
|
||||
}
|
||||
|
||||
class BackgroundTaskListModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static BackgroundTaskListModel* Instance();
|
||||
virtual ~BackgroundTaskListModel();
|
||||
|
||||
void InserTask(DataProcessWorkPool::DataProcessTask *task);
|
||||
void RemoveTask(const QString& task_name);
|
||||
void Clear();
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
private:
|
||||
int findTaskIndexByName(const QString& task_name);
|
||||
|
||||
private:
|
||||
explicit BackgroundTaskListModel(QObject *parent = nullptr);
|
||||
static BackgroundTaskListModel* _s_instance;
|
||||
private:
|
||||
QList<DataProcessWorkPool::DataProcessTask*> _task_list;
|
||||
};
|
||||
|
||||
#endif // BACKGROUNDTASKLISTMODEL_H
|
||||
Loading…
Reference in New Issue
Block a user