Skip to content

Commit

Permalink
Add possibility to select several files in FileSelector widget
Browse files Browse the repository at this point in the history
  • Loading branch information
boutinb authored and JorisGoosen committed Sep 30, 2024
1 parent 78c08f1 commit 7f57e7b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Modules/jaspTestModule
3 changes: 2 additions & 1 deletion QMLComponents/components/JASP/Controls/FileSelector.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ TextField
property string filter : "*"
property alias buttonText : button.text
property bool directory : false
property bool multiple : false

implicitWidth : button.x + button.width

Expand All @@ -36,7 +37,7 @@ TextField
else if (selector.save)
browsedFile = messages.browseSaveFileDocumentsQML(selector.caption, selector.filter)
else
browsedFile = messages.browseOpenFileDocumentsQML(selector.caption, selector.filter)
browsedFile = messages.browseOpenFileDocumentsQML(selector.caption, selector.filter, multiple)

selector.value = browsedFile;
selector.doEditingFinished();
Expand Down
12 changes: 7 additions & 5 deletions QMLComponents/utilities/messageforwarder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,17 @@ QString MessageForwarder::askPassword(QString title, QString message)
return QInputDialog::getText(nullptr, title, message, QLineEdit::Password);
}

QString MessageForwarder::browseOpenFile(QString caption, QString browsePath, QString filter)
QString MessageForwarder::browseOpenFile(QString caption, QString browsePath, QString filter, bool multiple)
{
if(useNativeFileDialogs()) return QFileDialog::getOpenFileName(nullptr, caption, browsePath, filter);
else return QFileDialog::getOpenFileName(nullptr, caption, browsePath, filter, nullptr, QFileDialog::DontUseNativeDialog);
QFileDialog::Options options = useNativeFileDialogs() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog;

if (multiple) return QFileDialog::getOpenFileNames(nullptr, caption, browsePath, filter, nullptr, options).join(';');
else return QFileDialog::getOpenFileName(nullptr, caption, browsePath, filter, nullptr, options);
}

QString MessageForwarder::browseOpenFileDocuments(QString caption, QString filter)
QString MessageForwarder::browseOpenFileDocuments(QString caption, QString filter, bool multiple)
{
return browseOpenFile(caption, AppDirs::documents(), filter);
return browseOpenFile(caption, AppDirs::documents(), filter, multiple);
}

QString MessageForwarder::browseSaveFileDocuments(QString caption, QString filter)
Expand Down
9 changes: 4 additions & 5 deletions QMLComponents/utilities/messageforwarder.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class MessageForwarder : public QQuickItem
static DialogResponse showSaveDiscardCancel(QString title, QString message, QString saveTxt = "", QString discardText = "", QString cancelText = "");
static DialogResponse showYesNoCancel( QString title, QString message, QString YesButtonText = "", QString NoButtonText = "", QString CancelButtonText = "");

static QString browseOpenFile( QString caption, QString browsePath, QString filter);
static QString browseOpenFile( QString caption, QString browsePath, QString filter, bool multiple = false);
static QString browseSaveFile( QString caption, QString browsePath, QString filter, QString * selectedExtension = nullptr);
static QString browseOpenFolder( QString caption, QString browsePath);
static QString browseOpenFolder( QString caption);
static QString browseOpenFileDocuments( QString caption, QString filter);
static QString browseOpenFileDocuments( QString caption, QString filter, bool multiple = false);
static QString browseSaveFileDocuments( QString caption, QString filter);

static QString askPassword(QString title, QString message);
Expand All @@ -50,15 +50,14 @@ class MessageForwarder : public QQuickItem
public slots:
DialogResponse showSaveDiscardCancelQML(QString title, QString message, QString saveTxt = "", QString discardText = "", QString cancelText = "") { return showSaveDiscardCancel(title, message, saveTxt, discardText, cancelText); }
void showWarningQML(QString title, QString message) { showWarning(title, message); }
QString browseOpenFileQML(QString caption, QString browsePath, QString filter) { return browseOpenFile(caption, browsePath, filter); }
QString browseOpenFileDocumentsQML(QString caption, QString filter) { return browseOpenFileDocuments(caption, filter); }
QString browseOpenFileQML(QString caption, QString browsePath, QString filter, bool multiple = false) { return browseOpenFile(caption, browsePath, filter, multiple); }
QString browseOpenFileDocumentsQML(QString caption, QString filter, bool multiple = false) { return browseOpenFileDocuments(caption, filter, multiple); }

QString browseSaveFileQML(QString caption, QString browsePath, QString filter) { return browseSaveFile(caption, browsePath, filter); }
QString browseSaveFileDocumentsQML(QString caption, QString filter) { return browseSaveFileDocuments(caption, filter); }
QString browseOpenFolderQML(QString caption, QString browsePath) { return browseOpenFolder(caption, browsePath);}
QString browseOpenFolderQML(QString caption) { return browseOpenFolder(caption);}


void log(QString msg);

private:
Expand Down

0 comments on commit 7f57e7b

Please sign in to comment.