Add additional static functions to filedialog

This commit is contained in:
GriffinR 2024-10-10 01:43:35 -04:00
parent 1ed9b1ee10
commit f192b745dd
2 changed files with 27 additions and 0 deletions

View file

@ -36,6 +36,18 @@ public:
QString *selectedFilter = nullptr, QString *selectedFilter = nullptr,
QFileDialog::Options options = Options()); QFileDialog::Options options = Options());
static QStringList getOpenFileNames(QWidget *parent = nullptr,
const QString &caption = QString(),
const QString &dir = QString(),
const QString &filter = QString(),
QString *selectedFilter = nullptr,
QFileDialog::Options options = Options());
static QString getExistingDirectory(QWidget *parent = nullptr,
const QString &caption = QString(),
const QString &dir = QString(),
QFileDialog::Options options = ShowDirsOnly);
static QString getSaveFileName(QWidget *parent = nullptr, static QString getSaveFileName(QWidget *parent = nullptr,
const QString &caption = QString(), const QString &caption = QString(),
const QString &dir = QString(), const QString &dir = QString(),

View file

@ -27,6 +27,14 @@ QString FileDialog::getOpenFileName(QWidget *parent, const QString &caption, con
return fileName; return fileName;
} }
QStringList FileDialog::getOpenFileNames(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options) {
const QStringList fileNames = QFileDialog::getOpenFileNames(parent, caption, getDirectoryFromInput(dir), filter, selectedFilter, options);
if (!fileNames.isEmpty())
setDirectoryFromFile(fileNames.last());
restoreFocus(parent);
return fileNames;
}
QString FileDialog::getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options) { QString FileDialog::getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options) {
const QString fileName = QFileDialog::getSaveFileName(parent, caption, getDirectoryFromInput(dir), filter, selectedFilter, options); const QString fileName = QFileDialog::getSaveFileName(parent, caption, getDirectoryFromInput(dir), filter, selectedFilter, options);
setDirectoryFromFile(fileName); setDirectoryFromFile(fileName);
@ -34,3 +42,10 @@ QString FileDialog::getSaveFileName(QWidget *parent, const QString &caption, con
return fileName; return fileName;
} }
QString FileDialog::getExistingDirectory(QWidget *parent, const QString &caption, const QString &dir, QFileDialog::Options options) {
const QString existingDir = QFileDialog::getExistingDirectory(parent, caption, getDirectoryFromInput(dir), options);
if (!existingDir.isEmpty())
setDirectory(existingDir);
restoreFocus(parent);
return existingDir;
}