"Maybe save" message.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2015-07-18 16:01:57 +03:00
parent 820d3dc9bd
commit ac187de0c9
3 changed files with 40 additions and 1 deletions

View File

@ -120,6 +120,19 @@ void TMainWindow::FileOpen()
}
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::closeEvent(QCloseEvent *event)
{
if (MaybeSave())
{
event->accept();
}
else
{
event->ignore();
}
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::FileSave()
{
@ -495,3 +508,24 @@ bool TMainWindow::SaveMeasurements(const QString &fileName, QString &error)
}
return result;
}
//---------------------------------------------------------------------------------------------------------------------
bool TMainWindow::MaybeSave()
{
if (this->isWindowModified())
{
QMessageBox::StandardButton ret;
ret = QMessageBox::warning(this, tr("Unsaved changes"), tr("Measurements have been modified.\n"
"Do you want to save your changes?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
if (ret == QMessageBox::Save)
{
FileSave();
}
else if (ret == QMessageBox::Cancel)
{
return false;
}
}
return true;
}

View File

@ -52,6 +52,9 @@ public slots:
void FileNew();
void FileOpen();
protected:
virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
private slots:
void FileSave();
void FileSaveAs();
@ -82,6 +85,8 @@ private:
void MeasurementsWasSaved(bool saved);
void SetCurrentFile(const QString &fileName);
bool SaveMeasurements(const QString &fileName, QString &error);
bool MaybeSave();
};
#endif // TMAINWINDOW_H

View File

@ -2437,7 +2437,7 @@ bool MainWindow::MaybeSave()
if (this->isWindowModified() && guiEnabled)
{
QMessageBox::StandardButton ret;
ret = QMessageBox::warning(this, tr("Unsaved change"), tr("The pattern has been modified.\n"
ret = QMessageBox::warning(this, tr("Unsaved changes"), tr("The pattern has been modified.\n"
"Do you want to save your changes?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
if (ret == QMessageBox::Save)