- 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
- fix: hide function tips, when move or resize the main window
- enhancement: add help link for regular expression in search dialog
- enhancement: remember current problem set's filename
Red Panda C++ Version 1.0.3
- 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()
{
QString fileName = QFileDialog::getSaveFileName(
this,
tr("Save Problem Set"),
QDir().absolutePath(),
tr("Problem Set Files (*.pbs)"));
if (!fileName.isEmpty()) {
QFileDialog dialog(this);
dialog.setWindowTitle(tr("Save Problem Set"));
if (!mOJProblemSetModel.exportFilename().isEmpty()) {
dialog.setDirectory(mOJProblemSetModel.exportFilename());
dialog.selectFile(mOJProblemSetModel.exportFilename());
} 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);
if (fileInfo.suffix().isEmpty()) {
fileName.append(".pbs");

View File

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

View File

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

View File

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