2021-10-31 17:01:34 +08:00
|
|
|
#ifndef OJPROBLEMSETMODEL_H
|
|
|
|
#define OJPROBLEMSETMODEL_H
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
enum class ProblemCaseTestState {
|
|
|
|
NoTested,
|
|
|
|
Passed,
|
|
|
|
Failed
|
|
|
|
};
|
|
|
|
|
|
|
|
struct OJProblemCase {
|
|
|
|
QString name;
|
|
|
|
QString input;
|
|
|
|
QString expected;
|
2021-11-01 00:40:11 +08:00
|
|
|
|
|
|
|
QString output; // no persistence
|
|
|
|
ProblemCaseTestState testState; // no persistence
|
2021-10-31 17:01:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
using POJProblemCase = std::shared_ptr<OJProblemCase>;
|
|
|
|
|
|
|
|
struct OJProblem {
|
|
|
|
QString name;
|
|
|
|
QVector<POJProblemCase> cases;
|
|
|
|
};
|
|
|
|
|
2021-11-01 00:40:11 +08:00
|
|
|
using POJProblem = std::shared_ptr<OJProblem>;
|
2021-10-31 17:01:34 +08:00
|
|
|
|
2021-11-01 00:40:11 +08:00
|
|
|
struct OJProblemSet {
|
|
|
|
QString name;
|
|
|
|
QVector<POJProblem> problems;
|
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
|
|
|
void clear();
|
|
|
|
int count();
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
|
|
|
private:
|
|
|
|
OJProblemSet mProblemSet;
|
|
|
|
|
|
|
|
// QAbstractItemModel interface
|
|
|
|
public:
|
|
|
|
int rowCount(const QModelIndex &parent) const override;
|
|
|
|
QVariant data(const QModelIndex &index, int role) const override;
|
2021-10-31 17:01:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // OJPROBLEMSETMODEL_H
|