Skip to content

Commit

Permalink
[skip ci] Implement AcceptMode for FileChooser to also allow to defin…
Browse files Browse the repository at this point in the history
…e an output file
  • Loading branch information
wwmayer committed Dec 13, 2019
1 parent 19127f3 commit 0175008
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Gui/FileDialog.cpp
Expand Up @@ -619,7 +619,10 @@ QString FileIconProvider::type(const QFileInfo & info) const
* Constructs a file chooser called \a name with the parent \a parent.
*/
FileChooser::FileChooser ( QWidget * parent )
: QWidget(parent), md( File ), _filter( QString::null )
: QWidget(parent)
, md( File )
, accMode( AcceptOpen )
, _filter( QString::null )
{
QHBoxLayout *layout = new QHBoxLayout( this );
layout->setMargin( 0 );
Expand Down Expand Up @@ -710,7 +713,10 @@ void FileChooser::chooseFile()

QString fn;
if ( mode() == File ) {
fn = QFileDialog::getOpenFileName( this, tr( "Select a file" ), prechosenDirectory, _filter,0,dlgOpt );
if (acceptMode() == AcceptOpen)
fn = QFileDialog::getOpenFileName(this, tr( "Select a file" ), prechosenDirectory, _filter, 0, dlgOpt);
else
fn = QFileDialog::getSaveFileName(this, tr( "Select a file" ), prechosenDirectory, _filter, 0, dlgOpt);
} else {
QFileDialog::Options option = QFileDialog::ShowDirsOnly | dlgOpt;
fn = QFileDialog::getExistingDirectory( this, tr( "Select a directory" ), prechosenDirectory,option );
Expand Down
17 changes: 17 additions & 0 deletions src/Gui/FileDialog.h
Expand Up @@ -138,12 +138,15 @@ class GuiExport FileChooser : public QWidget

Q_ENUMS( Mode )
Q_PROPERTY( Mode mode READ mode WRITE setMode )
Q_ENUMS( AcceptMode )
Q_PROPERTY( AcceptMode acceptMode READ acceptMode WRITE setAcceptMode )
Q_PROPERTY( QString fileName READ fileName WRITE setFileName )
Q_PROPERTY( QString filter READ filter WRITE setFilter )
Q_PROPERTY( QString buttonText READ buttonText WRITE setButtonText )

public:
enum Mode { File, Directory };
enum AcceptMode { AcceptOpen, AcceptSave };

FileChooser ( QWidget * parent = 0 );
virtual ~FileChooser();
Expand All @@ -169,6 +172,19 @@ class GuiExport FileChooser : public QWidget
*/
QString buttonText() const;

/**
* Sets the accept mode.
*/
void setAcceptMode(AcceptMode mode) {
accMode = mode;
}
/**
* Returns the accept mode.
*/
AcceptMode acceptMode() const {
return accMode;
}

public Q_SLOTS:
virtual void setFileName( const QString &fn );
virtual void setMode( Mode m );
Expand All @@ -192,6 +208,7 @@ private Q_SLOTS:
QFileSystemModel *fs_model;
QPushButton *button;
Mode md;
AcceptMode accMode;
QString _filter;
};

Expand Down

0 comments on commit 0175008

Please sign in to comment.