RedPanda-CPP/RedPandaIDE/widgets/ojproblemsetmodel.h

66 lines
2.0 KiB
C
Raw Normal View History

2021-10-31 17:01:34 +08:00
#ifndef OJPROBLEMSETMODEL_H
#define OJPROBLEMSETMODEL_H
#include <QAbstractListModel>
#include <memory>
2021-11-01 20:44:08 +08:00
#include "../problems/ojproblemset.h"
2021-11-01 00:40:11 +08:00
class OJProblemModel: public QAbstractListModel {
2021-10-31 17:01:34 +08:00
Q_OBJECT
public:
2021-11-01 00:40:11 +08:00
explicit OJProblemModel(QObject *parent = nullptr);
const POJProblem &problem() const;
void setProblem(const POJProblem &newProblem);
void addCase(POJProblemCase problemCase);
void removeCase(int index);
POJProblemCase getCase(int index);
2021-11-01 20:44:08 +08:00
POJProblemCase getCaseById(const QString& id);
int getCaseIndexById(const QString& id);
2021-11-01 00:40:11 +08:00
void clear();
int count();
2021-11-01 20:44:08 +08:00
void update(int row);
2021-10-31 17:01:34 +08:00
private:
2021-11-01 00:40:11 +08:00
POJProblem mProblem;
2021-10-31 17:01:34 +08:00
// QAbstractItemModel interface
public:
int rowCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
2021-11-01 09:18:23 +08:00
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
2021-10-31 17:01:34 +08:00
};
class OJProblemSetModel : public QAbstractListModel
{
Q_OBJECT
public:
explicit OJProblemSetModel(QObject *parent = nullptr);
2021-11-01 00:40:11 +08:00
void clear();
int count();
void create(const QString& name);
void rename(const QString& newName);
QString name();
void addProblem(POJProblem problem);
POJProblem problem(int index);
void removeProblem(int index);
bool problemNameUsed(const QString& name);
void removeAllProblems();
void saveToFile(const QString& fileName);
void loadFromFile(const QString& fileName);
signals:
void problemNameChanged(int index);
2021-11-01 00:40:11 +08:00
private:
OJProblemSet mProblemSet;
// QAbstractItemModel interface
public:
int rowCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
2021-11-01 09:18:23 +08:00
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
2021-10-31 17:01:34 +08:00
};
#endif // OJPROBLEMSETMODEL_H