- fix: remove the file change monitor if it's remove from the disk

- fix: don't test if a file is writable before save to it (because qt can't do that test reliably).
 - problem set ui almost done
This commit is contained in:
royqh1979@gmail.com 2021-11-02 01:07:37 +08:00
parent afbaaa07a6
commit f28aac649b
9 changed files with 72 additions and 35 deletions

View File

@ -2,6 +2,8 @@ Version 0.7.7
- change: "save" action will be enabled no matter contents in the current editor is modified or not - change: "save" action will be enabled no matter contents in the current editor is modified or not
- fix: focus not correctly set when the current editor is closed - fix: focus not correctly set when the current editor is closed
- fix: can't parse old c-style enum variable definition like "enum Test test;" - fix: can't parse old c-style enum variable definition like "enum Test test;"
- fix: remove the file change monitor if it's remove from the disk
- fix: don't test if a file is writable before save to it (because qt can't do that test reliably).
Version 0.7.6 Version 0.7.6
- change: don't auto insert a new line when input an enter between '(' and ')' or between '[' and ']' (indent instead) - change: don't auto insert a new line when input an enter between '(' and ')' or between '[' and ']' (indent instead)

View File

@ -21,9 +21,9 @@ OJProblemCasesRunner::OJProblemCasesRunner(const QString& filename, const QStrin
void OJProblemCasesRunner::runCase(int index,POJProblemCase problemCase) void OJProblemCasesRunner::runCase(int index,POJProblemCase problemCase)
{ {
emit caseStarted(problemCase->getId(),mProblemCases.count(),index); emit caseStarted(problemCase->getId(),index, mProblemCases.count());
auto action = finally([this,&index, &problemCase]{ auto action = finally([this,&index, &problemCase]{
emit caseFinished(problemCase->getId(),mProblemCases.count(),index); emit caseFinished(problemCase->getId(), index, mProblemCases.count());
}); });
QProcess process; QProcess process;
bool errorOccurred = false; bool errorOccurred = false;

View File

@ -14,8 +14,8 @@ public:
explicit OJProblemCasesRunner(const QString& filename, const QString& arguments, const QString& workDir, explicit OJProblemCasesRunner(const QString& filename, const QString& arguments, const QString& workDir,
POJProblemCase problemCase, QObject *parent = nullptr); POJProblemCase problemCase, QObject *parent = nullptr);
signals: signals:
void caseStarted(const QString& id, int total, int current); void caseStarted(const QString& id, int current, int total);
void caseFinished(const QString& id, int total, int current); void caseFinished(const QString& id, int current, int total);
private: private:
void runCase(int index, POJProblemCase problemCase); void runCase(int index, POJProblemCase problemCase);
private: private:

View File

@ -222,29 +222,27 @@ bool Editor::save(bool force, bool doReparse) {
if (this->mIsNew && !force) { if (this->mIsNew && !force) {
return saveAs(); return saveAs();
} }
QFileInfo info(mFilename);
//is this file writable; //is this file writable;
if (!force && !info.isWritable()) { pMainWindow->fileSystemWatcher()->removePath(mFilename);
QMessageBox::critical(pMainWindow,tr("Error"), try {
tr("File %1 is not writable!").arg(mFilename)); // QFileInfo info(mFilename);
return false; // if (!force && !info.isWritable()) {
} // QMessageBox::critical(pMainWindow,tr("Error"),
if (this->modified()|| force) { // tr("File %1 is not writable!").arg(mFilename));
pMainWindow->fileSystemWatcher()->removePath(mFilename); // return false;
try { // }
saveFile(mFilename); saveFile(mFilename);
pMainWindow->fileSystemWatcher()->addPath(mFilename); pMainWindow->fileSystemWatcher()->addPath(mFilename);
setModified(false); setModified(false);
mIsNew = false; mIsNew = false;
this->updateCaption(); this->updateCaption();
} catch (SaveException& exception) { } catch (SaveException& exception) {
if (!force) { if (!force) {
QMessageBox::critical(pMainWindow,tr("Error"), QMessageBox::critical(pMainWindow,tr("Error"),
exception.reason()); exception.reason());
}
pMainWindow->fileSystemWatcher()->addPath(mFilename);
return false;
} }
pMainWindow->fileSystemWatcher()->addPath(mFilename);
return false;
} }
if (doReparse && mParser) { if (doReparse && mParser) {

View File

@ -205,6 +205,9 @@ MainWindow::MainWindow(QWidget *parent)
connect(mSearchResultTreeModel.get() , &QAbstractItemModel::modelReset, connect(mSearchResultTreeModel.get() , &QAbstractItemModel::modelReset,
ui->searchView,&QTreeView::expandAll); ui->searchView,&QTreeView::expandAll);
ui->replacePanel->setVisible(false); ui->replacePanel->setVisible(false);
ui->tabProblem->setEnabled(false);
ui->btnRemoveProblem->setEnabled(false);
ui->btnRemoveProblemCase->setEnabled(false);
mOJProblemSetNameCounter=1; mOJProblemSetNameCounter=1;
mOJProblemSetModel.rename(tr("Problem Set %1").arg(mOJProblemSetNameCounter)); mOJProblemSetModel.rename(tr("Problem Set %1").arg(mOJProblemSetNameCounter));
@ -216,6 +219,9 @@ MainWindow::MainWindow(QWidget *parent)
connect(ui->lstProblemCases->selectionModel(), connect(ui->lstProblemCases->selectionModel(),
&QItemSelectionModel::currentRowChanged, &QItemSelectionModel::currentRowChanged,
this, &MainWindow::onProblemCaseIndexChanged); this, &MainWindow::onProblemCaseIndexChanged);
connect(&mOJProblemSetModel, &OJProblemSetModel::problemNameChanged,
this , &MainWindow::onProblemNameChanged);
ui->pbProblemCases->setVisible(false);
//files view //files view
ui->treeFiles->setModel(&mFileSystemModel); ui->treeFiles->setModel(&mFileSystemModel);
@ -1135,6 +1141,8 @@ void MainWindow::runExecutable(const QString &exeName,const QString &filename,Ru
if (problem) { if (problem) {
mCompilerManager->runProblem(exeName,params,QFileInfo(exeName).absolutePath(), mCompilerManager->runProblem(exeName,params,QFileInfo(exeName).absolutePath(),
problem->cases); problem->cases);
openCloseBottomPanel(true);
ui->tabMessages->setCurrentWidget(ui->tabProblem);
} }
} else if (runType == RunType::CurrentProblemCase) { } else if (runType == RunType::CurrentProblemCase) {
QModelIndex index = ui->lstProblemCases->currentIndex(); QModelIndex index = ui->lstProblemCases->currentIndex();
@ -1142,6 +1150,8 @@ void MainWindow::runExecutable(const QString &exeName,const QString &filename,Ru
POJProblemCase problemCase =mOJProblemModel.getCase(index.row()); POJProblemCase problemCase =mOJProblemModel.getCase(index.row());
mCompilerManager->runProblem(exeName,params,QFileInfo(exeName).absolutePath(), mCompilerManager->runProblem(exeName,params,QFileInfo(exeName).absolutePath(),
problemCase); problemCase);
openCloseBottomPanel(true);
ui->tabMessages->setCurrentWidget(ui->tabProblem);
} }
} }
updateAppTitle(); updateAppTitle();
@ -2518,24 +2528,22 @@ void MainWindow::onFilesViewContextMenu(const QPoint &pos)
void MainWindow::onProblemSetIndexChanged(const QModelIndex &current, const QModelIndex &previous) void MainWindow::onProblemSetIndexChanged(const QModelIndex &current, const QModelIndex &previous)
{ {
QModelIndex idx = current; QModelIndex idx = current;
// if (previous.isValid()) {
// QModelIndex caseIdx = ui->lstProblemCases->currentIndex();
// if (caseIdx.isValid()) {
// POJProblemCase problemCase = mOJProblemModel.getCase(caseIdx.row());
// problemCase->input = ui->txtProblemCaseInput->toPlainText();
// problemCase->expected = ui->txtProblemCaseExpected->toPlainText();
// problemCase->output = ui->txtProblemCaseOutput->toPlainText();
// }
// }
if (!idx.isValid()) { if (!idx.isValid()) {
ui->btnRemoveProblem->setEnabled(false); ui->btnRemoveProblem->setEnabled(false);
mOJProblemModel.setProblem(nullptr);
ui->txtProblemCaseExpected->clear();
ui->txtProblemCaseInput->clear();
ui->txtProblemCaseOutput->clear();
ui->tabProblem->setEnabled(false);
} else { } else {
ui->btnRemoveProblem->setEnabled(true); ui->btnRemoveProblem->setEnabled(true);
POJProblem problem = mOJProblemSetModel.problem(idx.row()); POJProblem problem = mOJProblemSetModel.problem(idx.row());
mOJProblemModel.setProblem(problem); mOJProblemModel.setProblem(problem);
ui->lblProblem->setText(problem->name); ui->lblProblem->setText(problem->name);
ui->lstProblemCases->setCurrentIndex(mOJProblemModel.index(0,0));
openCloseBottomPanel(true); openCloseBottomPanel(true);
ui->tabMessages->setCurrentWidget(ui->tabProblem); ui->tabMessages->setCurrentWidget(ui->tabProblem);
ui->tabProblem->setEnabled(true);
} }
} }
@ -2569,6 +2577,15 @@ void MainWindow::onProblemCaseIndexChanged(const QModelIndex &current, const QMo
ui->txtProblemCaseOutput->setReadOnly(true); ui->txtProblemCaseOutput->setReadOnly(true);
} }
void MainWindow::onProblemNameChanged(int index)
{
QModelIndex idx = ui->lstProblemSet->currentIndex();
if (idx.isValid() && index == idx.row()) {
POJProblem problem = mOJProblemSetModel.problem(idx.row());
ui->lblProblem->setText(problem->name);
}
}
void MainWindow::onShowInsertCodeSnippetMenu() void MainWindow::onShowInsertCodeSnippetMenu()
{ {
mMenuInsertCodeSnippet->clear(); mMenuInsertCodeSnippet->clear();
@ -2894,6 +2911,7 @@ void MainWindow::onFileChanged(const QString &path)
e->setModified(true); e->setModified(true);
e->updateCaption(); e->updateCaption();
} }
mFileSystemWatcher.removePath(e->filename());
} }
} }
} }
@ -3332,12 +3350,14 @@ void MainWindow::onRunFinished()
void MainWindow::onRunProblemFinished() void MainWindow::onRunProblemFinished()
{ {
ui->pbProblemCases->setVisible(false);
updateCompileActions(); updateCompileActions();
updateAppTitle(); updateAppTitle();
} }
void MainWindow::onOJProblemCaseStarted(const QString& id,int current, int total) void MainWindow::onOJProblemCaseStarted(const QString& id,int current, int total)
{ {
ui->pbProblemCases->setVisible(true);
ui->pbProblemCases->setMaximum(total); ui->pbProblemCases->setMaximum(total);
ui->pbProblemCases->setValue(current); ui->pbProblemCases->setValue(current);
int row = mOJProblemModel.getCaseIndexById(id); int row = mOJProblemModel.getCaseIndexById(id);
@ -5021,6 +5041,7 @@ void MainWindow::on_btnLoadProblemSet_clicked()
} }
} }
ui->lblProblemSet->setText(mOJProblemSetModel.name()); ui->lblProblemSet->setText(mOJProblemSetModel.name());
ui->lstProblemSet->setCurrentIndex(mOJProblemSetModel.index(0,0));
} }

View File

@ -226,6 +226,7 @@ private slots:
void onFilesViewContextMenu(const QPoint& pos); void onFilesViewContextMenu(const QPoint& pos);
void onProblemSetIndexChanged(const QModelIndex &current, const QModelIndex &previous); void onProblemSetIndexChanged(const QModelIndex &current, const QModelIndex &previous);
void onProblemCaseIndexChanged(const QModelIndex &current, const QModelIndex &previous); void onProblemCaseIndexChanged(const QModelIndex &current, const QModelIndex &previous);
void onProblemNameChanged(int index);
void onShowInsertCodeSnippetMenu(); void onShowInsertCodeSnippetMenu();

View File

@ -1234,8 +1234,17 @@
</item> </item>
<item> <item>
<widget class="QProgressBar" name="pbProblemCases"> <widget class="QProgressBar" name="pbProblemCases">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximum">
<number>0</number>
</property>
<property name="value"> <property name="value">
<number>24</number> <number>0</number>
</property> </property>
<property name="format"> <property name="format">
<string>%v/%m</string> <string>%v/%m</string>

View File

@ -57,7 +57,9 @@ POJProblem OJProblemSetModel::problem(int index)
void OJProblemSetModel::removeProblem(int index) void OJProblemSetModel::removeProblem(int index)
{ {
Q_ASSERT(index>=0 && index < mProblemSet.problems.count()); Q_ASSERT(index>=0 && index < mProblemSet.problems.count());
beginRemoveRows(QModelIndex(),index,index);
mProblemSet.problems.removeAt(index); mProblemSet.problems.removeAt(index);
endRemoveRows();
} }
bool OJProblemSetModel::problemNameUsed(const QString &name) bool OJProblemSetModel::problemNameUsed(const QString &name)
@ -169,6 +171,7 @@ bool OJProblemSetModel::setData(const QModelIndex &index, const QVariant &value,
QString s = value.toString(); QString s = value.toString();
if (!s.isEmpty()) { if (!s.isEmpty()) {
mProblemSet.problems[index.row()]->name = s; mProblemSet.problems[index.row()]->name = s;
emit problemNameChanged(index.row());
return true; return true;
} }
} }

View File

@ -48,6 +48,9 @@ public:
void removeAllProblems(); void removeAllProblems();
void saveToFile(const QString& fileName); void saveToFile(const QString& fileName);
void loadFromFile(const QString& fileName); void loadFromFile(const QString& fileName);
signals:
void problemNameChanged(int index);
private: private:
OJProblemSet mProblemSet; OJProblemSet mProblemSet;