- enhancement: remember current problem set's filename

This commit is contained in:
Roy Qu 2022-04-11 17:38:57 +08:00
parent 9cc51a150d
commit 50cca61abc
5 changed files with 26 additions and 8 deletions

View File

@ -1,6 +1,7 @@
Red Panda C++ Version 1.0.4 Red Panda C++ Version 1.0.4
- fix: hide function tips, when move or resize the main window - fix: hide function tips, when move or resize the main window
- enhancement: add help link for regular expression in search dialog - enhancement: add help link for regular expression in search dialog
- enhancement: remember current problem set's filename
Red Panda C++ Version 1.0.3 Red Panda C++ Version 1.0.3
- fix: when oj problem grabbed by competitive companion received, - fix: when oj problem grabbed by competitive companion received,

View File

@ -6653,12 +6653,20 @@ void MainWindow::on_btnRemoveProblem_clicked()
void MainWindow::on_btnSaveProblemSet_clicked() void MainWindow::on_btnSaveProblemSet_clicked()
{ {
QString fileName = QFileDialog::getSaveFileName( QFileDialog dialog(this);
this, dialog.setWindowTitle(tr("Save Problem Set"));
tr("Save Problem Set"), if (!mOJProblemSetModel.exportFilename().isEmpty()) {
QDir().absolutePath(), dialog.setDirectory(mOJProblemSetModel.exportFilename());
tr("Problem Set Files (*.pbs)")); dialog.selectFile(mOJProblemSetModel.exportFilename());
if (!fileName.isEmpty()) { } else {
dialog.setDirectory(QDir().absolutePath());
}
dialog.setNameFilter(tr("Problem Set Files (*.pbs)"));
dialog.setDefaultSuffix("pbs");
dialog.setFileMode(QFileDialog::AnyFile);
dialog.setAcceptMode(QFileDialog::AcceptSave);
if (dialog.exec() == QDialog::Accepted) {
QString fileName=dialog.selectedFiles()[0];
QFileInfo fileInfo(fileName); QFileInfo fileInfo(fileName);
if (fileInfo.suffix().isEmpty()) { if (fileInfo.suffix().isEmpty()) {
fileName.append(".pbs"); fileName.append(".pbs");

View File

@ -63,6 +63,7 @@ using POJProblem = std::shared_ptr<OJProblem>;
struct OJProblemSet { struct OJProblemSet {
QString name; QString name;
QVector<POJProblem> problems; QVector<POJProblem> problems;
QString exportFilename;
}; };
using POJProblemSet = std::shared_ptr<OJProblemSet>; using POJProblemSet = std::shared_ptr<OJProblemSet>;

View File

@ -34,6 +34,7 @@ void OJProblemSetModel::clear()
{ {
beginResetModel(); beginResetModel();
mProblemSet.problems.clear(); mProblemSet.problems.clear();
mProblemSet.exportFilename.clear();
endResetModel(); endResetModel();
} }
@ -54,11 +55,16 @@ void OJProblemSetModel::rename(const QString &newName)
mProblemSet.name = newName; mProblemSet.name = newName;
} }
QString OJProblemSetModel::name() QString OJProblemSetModel::name() const
{ {
return mProblemSet.name; return mProblemSet.name;
} }
QString OJProblemSetModel::exportFilename() const
{
return mProblemSet.exportFilename;
}
void OJProblemSetModel::addProblem(POJProblem problem) void OJProblemSetModel::addProblem(POJProblem problem)
{ {
beginInsertRows(QModelIndex(), mProblemSet.problems.count(), mProblemSet.problems.count()); beginInsertRows(QModelIndex(), mProblemSet.problems.count(), mProblemSet.problems.count());
@ -98,6 +104,7 @@ void OJProblemSetModel::saveToFile(const QString &fileName)
QFile file(fileName); QFile file(fileName);
if (file.open(QFile::WriteOnly | QFile::Truncate)) { if (file.open(QFile::WriteOnly | QFile::Truncate)) {
QJsonObject obj; QJsonObject obj;
mProblemSet.exportFilename=fileName;
obj["name"]=mProblemSet.name; obj["name"]=mProblemSet.name;
QJsonArray problemsArray; QJsonArray problemsArray;
foreach (const POJProblem& problem, mProblemSet.problems) { foreach (const POJProblem& problem, mProblemSet.problems) {

View File

@ -63,7 +63,8 @@ public:
int count(); int count();
void create(const QString& name); void create(const QString& name);
void rename(const QString& newName); void rename(const QString& newName);
QString name(); QString name() const;
QString exportFilename() const;
void addProblem(POJProblem problem); void addProblem(POJProblem problem);
POJProblem problem(int index); POJProblem problem(int index);
void removeProblem(int index); void removeProblem(int index);