Add ValidPathOrDesktop() helper function

This commit is contained in:
WarmUpTill 2022-12-16 23:40:24 +01:00 committed by WarmUpTill
parent b5ec9e7586
commit feab4fe744
2 changed files with 12 additions and 9 deletions

View File

@ -29,17 +29,19 @@ void FileSelection::SetPath(const QString &path)
_filePath->setText(path);
}
QString FileSelection::ValidPathOrDesktop(const QString &path)
{
if (std::filesystem::exists(
std::filesystem::path(path.toStdString()))) {
return path;
}
return QStandardPaths::writableLocation(
QStandardPaths::DesktopLocation);
}
void FileSelection::BrowseButtonClicked()
{
QString defaultPath;
if (std::filesystem::exists(
std::filesystem::path(_filePath->text().toStdString()))) {
defaultPath = _filePath->text();
} else {
defaultPath = QStandardPaths::writableLocation(
QStandardPaths::DesktopLocation);
}
QString defaultPath = ValidPathOrDesktop(_filePath->text());
QString path;
if (_type == FileSelection::Type::WRITE) {
path = QFileDialog::getSaveFileName(this, "", defaultPath);

View File

@ -17,6 +17,7 @@ public:
QWidget *parent = 0);
void SetPath(const QString &);
QPushButton *Button() { return _browseButton; }
static QString ValidPathOrDesktop(const QString &path);
private slots:
void BrowseButtonClicked();