mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-08-20 08:15:46 -05:00
Add ValidPathOrDesktop() helper function
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user