- enhancement: auto save / load problem set
This commit is contained in:
parent
0e76769c3b
commit
e764c14286
|
@ -31,4 +31,4 @@ author: Alan-CRL
|
|||
|
||||
### Monokai
|
||||
|
||||
author: СÁúDev
|
||||
author: СÁúDev(XiaoLoong@github)
|
3
NEWS.md
3
NEWS.md
|
@ -1,7 +1,8 @@
|
|||
Red Panda C++ Version 2.5
|
||||
|
||||
- enhancement: new color scheme Monokai (contributed by 小龙Dev)
|
||||
- enhancement: new color scheme Monokai (contributed by 小龙Dev(XiaoLoong@github))
|
||||
- enhancemnet: add "Reserve word for Types" item in color scheme
|
||||
- enhancement: auto save / load problem set
|
||||
|
||||
Red Panda C++ Version 2.4
|
||||
|
||||
|
|
|
@ -321,9 +321,11 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
//problem set
|
||||
mOJProblemSetNameCounter=1;
|
||||
mOJProblemSetModel.rename(tr("Problem Set %1").arg(mOJProblemSetNameCounter));
|
||||
|
||||
m=ui->lstProblemSet->selectionModel();
|
||||
ui->lstProblemSet->setModel(&mOJProblemSetModel);
|
||||
delete m;
|
||||
|
||||
m=ui->tblProblemCases->selectionModel();
|
||||
ui->tblProblemCases->setModel(&mOJProblemModel);
|
||||
delete m;
|
||||
|
@ -341,6 +343,19 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
|
||||
connect(&mOJProblemModel, &OJProblemModel::dataChanged,
|
||||
this, &MainWindow::updateProblemTitle);
|
||||
try {
|
||||
int currentIndex=-1;
|
||||
mOJProblemSetModel.load(currentIndex);
|
||||
if (currentIndex>=0) {
|
||||
QModelIndex index = mOJProblemSetModel.index(currentIndex,0);
|
||||
ui->lstProblemSet->setCurrentIndex(index);
|
||||
ui->lstProblemSet->scrollTo(index);
|
||||
}
|
||||
} catch (FileError& e) {
|
||||
QMessageBox::warning(nullptr,
|
||||
tr("Error"),
|
||||
e.reason());
|
||||
}
|
||||
|
||||
//files view
|
||||
m=ui->treeFiles->selectionModel();
|
||||
|
@ -4919,6 +4934,17 @@ void MainWindow::closeEvent(QCloseEvent *event) {
|
|||
e.reason());
|
||||
}
|
||||
|
||||
try {
|
||||
int currentIndex=-1;
|
||||
if (ui->lstProblemSet->currentIndex().isValid())
|
||||
currentIndex = ui->lstProblemSet->currentIndex().row();
|
||||
mOJProblemSetModel.save(currentIndex);
|
||||
} catch (FileError& e) {
|
||||
QMessageBox::warning(nullptr,
|
||||
tr("Save Error"),
|
||||
e.reason());
|
||||
}
|
||||
|
||||
if (pSettings->debugger().autosave()) {
|
||||
try {
|
||||
mDebugger->saveForNonproject(includeTrailingPathDelimiter(pSettings->dirs().config())
|
||||
|
@ -7694,7 +7720,10 @@ void MainWindow::on_btnSaveProblemSet_clicked()
|
|||
QDir::setCurrent(extractFileDir(fileName));
|
||||
try {
|
||||
applyCurrentProblemCaseChanges();
|
||||
mOJProblemSetModel.saveToFile(fileName);
|
||||
int currentIndex=-1;
|
||||
if (ui->lstProblemSet->currentIndex().isValid())
|
||||
currentIndex = ui->lstProblemSet->currentIndex().row();
|
||||
mOJProblemSetModel.saveToFile(fileName,currentIndex);
|
||||
} catch (FileError& error) {
|
||||
QMessageBox::critical(this,tr("Save Error"),
|
||||
error.reason());
|
||||
|
@ -7713,7 +7742,15 @@ void MainWindow::on_btnLoadProblemSet_clicked()
|
|||
if (!fileName.isEmpty()) {
|
||||
QDir::setCurrent(extractFileDir(fileName));
|
||||
try {
|
||||
mOJProblemSetModel.loadFromFile(fileName);
|
||||
int currentIndex;
|
||||
mOJProblemSetModel.loadFromFile(fileName,currentIndex);
|
||||
if (currentIndex>=0) {
|
||||
if (currentIndex>=0) {
|
||||
QModelIndex index = mOJProblemSetModel.index(currentIndex,0);
|
||||
ui->lstProblemSet->setCurrentIndex(index);
|
||||
ui->lstProblemSet->scrollTo(index);
|
||||
}
|
||||
}
|
||||
} catch (FileError& error) {
|
||||
QMessageBox::critical(this,tr("Load Error"),
|
||||
error.reason());
|
||||
|
|
|
@ -92,6 +92,8 @@
|
|||
#define DEV_BOOKMARK_FILE "bookmarks.json"
|
||||
#define DEV_DEBUGGER_FILE "debugger.json"
|
||||
#define DEV_HISTORY_FILE "history.json"
|
||||
#define DEV_PROBLEM_SET_FILE "problemset.json"
|
||||
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
# define PATH_SENSITIVITY Qt::CaseInsensitive
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
#include "ojproblemsetmodel.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QIcon>
|
||||
#include <QJsonArray>
|
||||
|
@ -25,6 +26,7 @@
|
|||
#include "../utils.h"
|
||||
#include "../iconsmanager.h"
|
||||
#include "../systemconsts.h"
|
||||
#include "../settings.h"
|
||||
|
||||
OJProblemSetModel::OJProblemSetModel(QObject *parent) : QAbstractListModel(parent)
|
||||
{
|
||||
|
@ -100,7 +102,7 @@ void OJProblemSetModel::removeAllProblems()
|
|||
clear();
|
||||
}
|
||||
|
||||
void OJProblemSetModel::saveToFile(const QString &fileName)
|
||||
void OJProblemSetModel::saveToFile(const QString &fileName, int currentIndex)
|
||||
{
|
||||
QFile file(fileName);
|
||||
if (file.open(QFile::WriteOnly | QFile::Truncate)) {
|
||||
|
@ -138,6 +140,7 @@ void OJProblemSetModel::saveToFile(const QString &fileName)
|
|||
problemsArray.append(problemObj);
|
||||
}
|
||||
obj["problems"]=problemsArray;
|
||||
obj["current_index"]=currentIndex;
|
||||
QJsonDocument doc;
|
||||
doc.setObject(obj);
|
||||
file.write(doc.toJson());
|
||||
|
@ -148,7 +151,7 @@ void OJProblemSetModel::saveToFile(const QString &fileName)
|
|||
}
|
||||
}
|
||||
|
||||
void OJProblemSetModel::loadFromFile(const QString &fileName)
|
||||
void OJProblemSetModel::loadFromFile(const QString &fileName, int& currentIndex)
|
||||
{
|
||||
QFile file(fileName);
|
||||
if (file.open(QFile::ReadOnly)) {
|
||||
|
@ -163,6 +166,7 @@ void OJProblemSetModel::loadFromFile(const QString &fileName)
|
|||
beginResetModel();
|
||||
QJsonObject obj = doc.object();
|
||||
mProblemSet.name = obj["name"].toString();
|
||||
currentIndex = obj["current_index"].toInt(-1);
|
||||
mProblemSet.problems.clear();
|
||||
QJsonArray problemsArray = obj["problems"].toArray();
|
||||
foreach (const QJsonValue& problemVal, problemsArray) {
|
||||
|
@ -203,6 +207,21 @@ void OJProblemSetModel::loadFromFile(const QString &fileName)
|
|||
}
|
||||
}
|
||||
|
||||
void OJProblemSetModel::load(int ¤tIndex)
|
||||
{
|
||||
QDir dir(pSettings->dirs().config());
|
||||
QString filename=dir.filePath(DEV_PROBLEM_SET_FILE);
|
||||
if (fileExists(filename))
|
||||
loadFromFile(filename,currentIndex);
|
||||
}
|
||||
|
||||
void OJProblemSetModel::save(int currentIndex)
|
||||
{
|
||||
QDir dir(pSettings->dirs().config());
|
||||
QString filename=dir.filePath(DEV_PROBLEM_SET_FILE);
|
||||
saveToFile(filename,currentIndex);
|
||||
}
|
||||
|
||||
void OJProblemSetModel::updateProblemAnswerFilename(const QString &oldFilename, const QString &newFilename)
|
||||
{
|
||||
foreach (POJProblem problem, mProblemSet.problems) {
|
||||
|
|
|
@ -85,8 +85,10 @@ public:
|
|||
void removeProblem(int index);
|
||||
bool problemNameUsed(const QString& name);
|
||||
void removeAllProblems();
|
||||
void saveToFile(const QString& fileName);
|
||||
void loadFromFile(const QString& fileName);
|
||||
void saveToFile(const QString& fileName, int currentIndex=-1);
|
||||
void loadFromFile(const QString& fileName, int& currentIndex);
|
||||
void load(int& currentIndex);
|
||||
void save(int currentIndex);
|
||||
void updateProblemAnswerFilename(const QString& oldFilename, const QString& newFilename);
|
||||
|
||||
signals:
|
||||
|
|
Loading…
Reference in New Issue