Skip to content

Commit

Permalink
Add additional static functions to filedialog
Browse files Browse the repository at this point in the history
  • Loading branch information
GriffinRichards committed Oct 10, 2024
1 parent 1ed9b1e commit f192b74
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/core/filedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ class FileDialog : public QFileDialog
QString *selectedFilter = nullptr,
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,
const QString &caption = QString(),
const QString &dir = QString(),
Expand Down
15 changes: 15 additions & 0 deletions src/core/filedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,25 @@ QString FileDialog::getOpenFileName(QWidget *parent, const QString &caption, con
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) {
const QString fileName = QFileDialog::getSaveFileName(parent, caption, getDirectoryFromInput(dir), filter, selectedFilter, options);
setDirectoryFromFile(fileName);
restoreFocus(parent);
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;
}

0 comments on commit f192b74

Please sign in to comment.