#1294 - Adding function for getting save directory from dialog, checking if files already exsist in dir and if so ask in dialog if they should be overwritten.

This commit is contained in:
astridkbjorke 2017-03-10 13:16:07 +01:00
parent eb3283041f
commit 04c9616abc
2 changed files with 60 additions and 0 deletions

View File

@ -44,6 +44,9 @@
#include <QtOpenGL/QGLContext>
#include <QFileDialog>
#include <QMessageBox>
namespace caf {
@ -161,5 +164,58 @@ QString Utils::indentString(int numSpacesToIndent, const QString& str)
return retStr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool Utils::getSaveDirectoryAndCheckOverwriteFiles(QString& saveDir, std::vector<QString> fileNames)
{
bool overWriteFiles = false;
saveDir = QFileDialog::getExistingDirectory(NULL, "Select save directory", saveDir);
std::vector<QString> filesToOverwrite;
for (QString fileName : fileNames)
{
QFileInfo fileInfo(saveDir + "/" + fileName);
if (fileInfo.exists())
{
filesToOverwrite.push_back(fileName);
}
}
if (filesToOverwrite.size() > 0)
{
QMessageBox msgBox;
QString message = "The following files will be overwritten in the export:";
for (QString fileName : filesToOverwrite)
{
message += "\n" + saveDir + "/" + fileName;
}
msgBox.setText(message);
msgBox.setInformativeText("Do you want to continue?");
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Ok);
int ret = msgBox.exec();
switch (ret)
{
case QMessageBox::Ok:
overWriteFiles = true;
break;
case QMessageBox::Cancel:
overWriteFiles = false;
break;
default:
// should never be reached
break;
}
}
return overWriteFiles;
}
} // namespace caf

View File

@ -37,6 +37,8 @@
#pragma once
#include <vector>
class QLineEdit;
class QString;
class QStringList;
@ -60,6 +62,8 @@ public:
static QString indentString(int numSpacesToIndent, const QString& str);
static bool getSaveDirectoryAndCheckOverwriteFiles(QString& defaultDir, std::vector<QString> fileNames);
};
}