diff options
Diffstat (limited to 'util/qt3d/assetviewer/quickfile.cpp')
-rw-r--r-- | util/qt3d/assetviewer/quickfile.cpp | 163 |
1 files changed, 0 insertions, 163 deletions
diff --git a/util/qt3d/assetviewer/quickfile.cpp b/util/qt3d/assetviewer/quickfile.cpp deleted file mode 100644 index 3fead170..00000000 --- a/util/qt3d/assetviewer/quickfile.cpp +++ /dev/null @@ -1,163 +0,0 @@ -#include "quickfile.h" -#include <QFileDialog> -#include <QUrl> - #include <QMessageBox> - -/*! - \qmlclass QuickFile QuickFile - \brief QuickFile is a quick-and-dirty file handling object that supports file-io that QML/Javascript doesn't. - \inherits QObject - - The QuickFile element is part of the \c{ModelTweak} namespace, - so the following must appear at the top of any QML file that - references it: - - \code - import ModelTweak 1.0 - \endcode - - \sa QObject -*/ - -/*! - \internal -*/ -QuickFile::QuickFile(QObject *parent) : - 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/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"); - - QDir outputDir = QFileInfo(filename).absoluteDir(); - - QString modelFilename = QUrl(_filename).toLocalFile(); - QString modelFN = QFileInfo(modelFilename).fileName(); - - QString dstModelLocation = outputDir.path() + QDir::separator() + modelFN; - if (dstModelLocation.compare(modelFilename,Qt::CaseInsensitive) != 0) { - // src and dst model paths are different. - // Copy model file over. - qDebug("Attempting to copy:"); - qDebug(" from: %s",modelFilename.toAscii().constData()); - qDebug(" to : %s",dstModelLocation.toAscii().constData()); - QFile dstModelFile(dstModelLocation); - if (dstModelFile.exists()) { - if (!dstModelFile.remove()) { - qDebug(" failed to remove dst file!"); - } - } - QFile srcModelFile(modelFilename); - if (srcModelFile.copy(dstModelLocation)) { - qDebug(" Model was copied successfully."); - } else { - qDebug(" failed to copy model file !"); - } - } - - QFile file(filename); - - qDebug("Attempting to write: %s", file.fileName().toAscii().constData()); - - if (!file.open(QFile::WriteOnly)) - return file.errorString(); - - QString dataToWrite = _data.arg(modelFN); - - file.write(dataToWrite.toUtf8()); - - file.close(); - - return QString(); -} - -/*! - 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. -*/ -void QuickFile::load() -{ - QString qmlFilename = QFileDialog::getOpenFileName(0, _title, "", _filter); - setFilename(qmlFilename); -} - - -QString QuickFile::filename() const { - return _filename; -} - -void QuickFile::setFilename(const QString filename) { - if (_filename != filename) - _filename = filename; - emit filenameChanged(filename); -} - -QString QuickFile::title() const { - return _title; -} - -void QuickFile::setTitle(const QString title) { - if (_title != title) - _title = title; - emit titleChanged(title); -} - -QString QuickFile::filter() const { - return _filter; -} - -void QuickFile::setFilter(const QString filter) { - if (_filter != filter) - _filter = filter; - emit filterChanged(filter); -} - -QString QuickFile::data() const { - return _data; -} - -void QuickFile::setData(const QString data) { - if (_data != data) - _data = data; - emit dataChanged(data); -} - |