diff options
Diffstat (limited to 'util/qt3d/modeltweak/quickfile.cpp')
-rw-r--r-- | util/qt3d/modeltweak/quickfile.cpp | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/util/qt3d/modeltweak/quickfile.cpp b/util/qt3d/modeltweak/quickfile.cpp index c6bc7bd5..52bae098 100644 --- a/util/qt3d/modeltweak/quickfile.cpp +++ b/util/qt3d/modeltweak/quickfile.cpp @@ -1,6 +1,7 @@ #include "quickfile.h" #include <QFileDialog> #include <QUrl> + #include <QMessageBox> /*! \qmlclass QuickFile QuickFile @@ -29,12 +30,17 @@ QuickFile::QuickFile(QObject *parent) : /*! Prompts for a location and filename to save the qml \c{QuickFile::data} generated by ModelTweaker. Returns an error message if the file was unsuccessfully saved, - or an empty string if the save was successful. + or an empty string if the save was successful/cancelled. */ QString QuickFile::save() const { QString filename = QFileDialog::getSaveFileName(0, tr("Save QML File"), "",tr("Files (*.qml)")); + //If cancel button pressed (ie. filename empty), we can just drop out immediately + if (filename.isEmpty()) { + return QString(); + } + // FIXME: ensure fileName is appropriate as a qml Component if (!filename.endsWith(".qml")) filename.append(".qml"); @@ -82,6 +88,29 @@ QString QuickFile::save() const } /*! + Save/Close dialog for unsaved changes to QML files. This is shown if the user + closes the app without saving the modifications they have made. + + Returns an error message if the file was unsuccessfully saved, + or an empty string if the save was successful/cancelled. +*/ +QString QuickFile::promptSave() const +{ + QMessageBox msgBox; + msgBox.setText("The document has been modified."); + msgBox.setInformativeText("Do you want to save your changes?"); + msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard); + msgBox.setDefaultButton(QMessageBox::Save); + int ret = msgBox.exec(); + + if (ret==QMessageBox::Save) { + return save(); + } else { + return QString(); + } +} + +/*! Prompts for a location to load a model file from and stores it into the the \c{QuickFile::filename} variable. */ @@ -92,6 +121,7 @@ void QuickFile::load() setFilename(qmlFilename); } + QString QuickFile::filename() const { return _filename; } @@ -111,3 +141,4 @@ void QuickFile::setData(const QString data) { _data = data; emit dataChanged(data); } + |