- 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
- 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: 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
- 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)
{
emit caseStarted(problemCase->getId(),mProblemCases.count(),index);
emit caseStarted(problemCase->getId(),index, mProblemCases.count());
auto action = finally([this,&index, &problemCase]{
emit caseFinished(problemCase->getId(),mProblemCases.count(),index);
emit caseFinished(problemCase->getId(), index, mProblemCases.count());
});
QProcess process;
bool errorOccurred = false;

View File

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

View File

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

View File

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

View File

@ -1234,8 +1234,17 @@
</item>
<item>
<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">
<number>24</number>
<number>0</number>
</property>
<property name="format">
<string>%v/%m</string>

View File

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

View File

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