2021-12-26 23:18:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-10-31 17:01:34 +08:00
|
|
|
#ifndef OJPROBLEMSETMODEL_H
|
|
|
|
#define OJPROBLEMSETMODEL_H
|
|
|
|
|
2022-03-29 18:06:24 +08:00
|
|
|
#include <QAbstractTableModel>
|
2021-10-31 17:01:34 +08:00
|
|
|
#include <memory>
|
2021-11-01 20:44:08 +08:00
|
|
|
#include "../problems/ojproblemset.h"
|
2021-11-01 00:40:11 +08:00
|
|
|
|
2022-03-29 18:06:24 +08:00
|
|
|
class OJProblemModel: public QAbstractTableModel {
|
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);
|
2022-04-16 20:39:09 +08:00
|
|
|
void removeCases();
|
2021-11-01 00:40:11 +08:00
|
|
|
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-11-02 09:29:35 +08:00
|
|
|
QString getTitle();
|
2021-11-04 09:07:06 +08:00
|
|
|
QString getTooltip();
|
2021-10-31 17:01:34 +08:00
|
|
|
|
|
|
|
private:
|
2021-11-01 00:40:11 +08:00
|
|
|
POJProblem mProblem;
|
2022-09-03 20:18:32 +08:00
|
|
|
int mMoveTargetRow;
|
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;
|
2022-03-29 18:06:24 +08:00
|
|
|
|
|
|
|
// QAbstractItemModel interface
|
|
|
|
public:
|
|
|
|
int columnCount(const QModelIndex &parent) const override;
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
2022-09-03 20:18:32 +08:00
|
|
|
|
|
|
|
// QAbstractItemModel interface
|
|
|
|
public:
|
|
|
|
Qt::DropActions supportedDropActions() const override;
|
|
|
|
|
|
|
|
// QAbstractItemModel interface
|
|
|
|
public:
|
|
|
|
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
|
|
|
|
|
|
|
|
// QAbstractItemModel interface
|
|
|
|
public:
|
|
|
|
bool insertRows(int row, int count, const QModelIndex &parent) override;
|
|
|
|
bool removeRows(int row, int count, const QModelIndex &parent) 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);
|
2022-04-11 17:38:57 +08:00
|
|
|
QString name() const;
|
|
|
|
QString exportFilename() const;
|
2021-11-01 00:40:11 +08:00
|
|
|
void addProblem(POJProblem problem);
|
|
|
|
POJProblem problem(int index);
|
|
|
|
void removeProblem(int index);
|
|
|
|
bool problemNameUsed(const QString& name);
|
|
|
|
void removeAllProblems();
|
2022-11-14 19:10:32 +08:00
|
|
|
void saveToFile(const QString& fileName, int currentIndex=-1);
|
|
|
|
void loadFromFile(const QString& fileName, int& currentIndex);
|
|
|
|
void load(int& currentIndex);
|
|
|
|
void save(int currentIndex);
|
2022-01-02 10:37:00 +08:00
|
|
|
void updateProblemAnswerFilename(const QString& oldFilename, const QString& newFilename);
|
|
|
|
|
2021-11-02 01:07:37 +08:00
|
|
|
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;
|
2022-09-03 20:18:32 +08:00
|
|
|
|
|
|
|
// QAbstractItemModel interface
|
|
|
|
public:
|
|
|
|
Qt::DropActions supportedDropActions() const override;
|
|
|
|
bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) override;
|
2021-10-31 17:01:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // OJPROBLEMSETMODEL_H
|