Improved question an error handling when closing and saving query.
This commit is contained in:
parent
f5046fbd68
commit
4adb78a84e
2 changed files with 27 additions and 13 deletions
|
|
@ -152,23 +152,29 @@ bool QueryTab::load(const QString &filename)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QueryTab::save()
|
bool QueryTab::save()
|
||||||
{
|
{
|
||||||
|
bool result;
|
||||||
if (m_fileName.isEmpty()) {
|
if (m_fileName.isEmpty()) {
|
||||||
saveAs();
|
result = saveAs();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
saveSqlTo(m_fileName);
|
result = saveSqlTo(m_fileName);
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QueryTab::saveAs()
|
bool QueryTab::saveAs()
|
||||||
{
|
{
|
||||||
|
bool result = false;
|
||||||
QString filename = promptUserForSaveSqlFilename();
|
QString filename = promptUserForSaveSqlFilename();
|
||||||
if (!filename.isEmpty()) {
|
if (!filename.isEmpty()) {
|
||||||
saveSqlTo(filename);
|
result = saveSqlTo(filename);
|
||||||
|
if (result) {
|
||||||
setFileName(filename);
|
setFileName(filename);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QueryTab::saveCopyAs()
|
void QueryTab::saveCopyAs()
|
||||||
|
|
@ -253,12 +259,19 @@ bool QueryTab::continueWithoutSavingWarning()
|
||||||
{
|
{
|
||||||
QMessageBox msgBox;
|
QMessageBox msgBox;
|
||||||
msgBox.setIcon(QMessageBox::Warning);
|
msgBox.setIcon(QMessageBox::Warning);
|
||||||
msgBox.setText("The document has been modified.");
|
msgBox.setText(QString("Save changes in document \"%1\" before closing?").arg(m_fileName));
|
||||||
msgBox.setInformativeText("The current query has unsaved changes, do you want to continue without saving those changes?");
|
msgBox.setInformativeText("The changes will be lost when you choose Discard.");
|
||||||
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
|
||||||
msgBox.setDefaultButton(QMessageBox::No);
|
msgBox.setDefaultButton(QMessageBox::Cancel);
|
||||||
int ret = msgBox.exec();
|
int ret = msgBox.exec();
|
||||||
return ret == QMessageBox::Yes;
|
if (ret == QMessageBox::Save) {
|
||||||
|
if (!save()) {
|
||||||
|
// save failed or was a saveAs and was cancelled, don't close!
|
||||||
|
ret = QMessageBox::Cancel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret != QMessageBox::Cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QueryTab::saveSqlTo(const QString &filename)
|
bool QueryTab::saveSqlTo(const QString &filename)
|
||||||
|
|
@ -281,6 +294,7 @@ bool QueryTab::saveSqlTo(const QString &filename)
|
||||||
block = block.next();
|
block = block.next();
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
stream.flush();
|
||||||
if (stream.status() == QTextStream::Ok) {
|
if (stream.status() == QTextStream::Ok) {
|
||||||
m_queryTextChanged = false;
|
m_queryTextChanged = false;
|
||||||
result = true;
|
result = true;
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,8 @@ public:
|
||||||
void newdoc();
|
void newdoc();
|
||||||
// void open();
|
// void open();
|
||||||
bool load(const QString &filename);
|
bool load(const QString &filename);
|
||||||
void save();
|
bool save();
|
||||||
void saveAs();
|
bool saveAs();
|
||||||
void saveCopyAs();
|
void saveCopyAs();
|
||||||
|
|
||||||
void execute();
|
void execute();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue