From: CHEMIN Sebastien Date: Fri, 12 Jan 2024 09:22:48 +0000 (+0100) Subject: Add file dialog options in QtxPathEdit X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a946784ee5de923d03221dec2a310bc70e29ae37;p=modules%2Fgui.git Add file dialog options in QtxPathEdit --- diff --git a/src/Qtx/QtxPagePrefMgr.cxx b/src/Qtx/QtxPagePrefMgr.cxx index 627372091..541764a31 100644 --- a/src/Qtx/QtxPagePrefMgr.cxx +++ b/src/Qtx/QtxPagePrefMgr.cxx @@ -3932,6 +3932,27 @@ void QtxPagePrefPathItem::setPathFilter( const QString& f ) myPath->setPathFilter( f ); } +/*! + \brief Get currently used path widget options. + \return file or directory path options + \sa setPathOptions() +*/ +QFileDialog::Options QtxPagePrefPathItem::pathOptions() const +{ + return myPath->pathOptions(); +} + +/*! + \brief Set path widget options. + \param f new file or directory path options + \sa pathOptions() +*/ +void QtxPagePrefPathItem::setPathOptions( const QFileDialog::Options options ) +{ + myPath->setPathOptions( options ); +} + + /*! \brief Store preference item to the resource manager. \sa retrieve() @@ -3962,6 +3983,8 @@ QVariant QtxPagePrefPathItem::optionValue( const QString& name ) const return pathType(); else if ( name == "path_filter" ) return pathFilter(); + else if ( name == "path_options" ) + return QVariant::fromValue(pathOptions()); else return QtxPageNamedPrefItem::optionValue( name ); } @@ -3984,6 +4007,11 @@ void QtxPagePrefPathItem::setOptionValue( const QString& name, const QVariant& v if ( val.canConvert( QVariant::String ) ) setPathFilter( val.toString() ); } + else if ( name == "path_options" ) + { + if ( val.canConvert( QVariant::Int ) ) + setPathOptions( (QFileDialog::Options)val.toInt() ); + } else QtxPageNamedPrefItem::setOptionValue( name, val ); } diff --git a/src/Qtx/QtxPagePrefMgr.h b/src/Qtx/QtxPagePrefMgr.h index b29945cd6..ea58fd5cb 100644 --- a/src/Qtx/QtxPagePrefMgr.h +++ b/src/Qtx/QtxPagePrefMgr.h @@ -658,6 +658,9 @@ public: QString pathFilter() const; void setPathFilter( const QString& ); + + QFileDialog::Options pathOptions() const; + void setPathOptions(const QFileDialog::Options); virtual void store(); virtual void retrieve(); diff --git a/src/Qtx/QtxPathEdit.cxx b/src/Qtx/QtxPathEdit.cxx index cd881b9a9..2e8e033f2 100644 --- a/src/Qtx/QtxPathEdit.cxx +++ b/src/Qtx/QtxPathEdit.cxx @@ -29,7 +29,6 @@ #include #include #include -#include #include static const char* browse_icon[] = { @@ -185,6 +184,30 @@ void QtxPathEdit::setPathFilter( const QString& f ) updateState(); } +/*! + \brief Set path file dialog options. + \param f new file or directory path options + \sa pathOptions() +*/ +void QtxPathEdit::setPathOptions(const QFileDialog::Options options) +{ + if ( myOptions == options ) + return; + + myOptions = options; +} + +/*! + \brief Get currently used path options. + \return file or directory path options + \sa setPathOptions() +*/ +QFileDialog::Options QtxPathEdit::pathOptions() const +{ + return myOptions; +} + + /*! \brief Called when user clicks "Browse" button. @@ -200,13 +223,13 @@ void QtxPathEdit::onBrowse( bool /*on*/ ) switch ( pathType() ) { case Qtx::PT_OpenFile: - path = QFileDialog::getOpenFileName( myPath, QString(), initial, pathFilter() ); + path = QFileDialog::getOpenFileName( myPath, QString(), initial, pathFilter(), nullptr, pathOptions() ); break; case Qtx::PT_SaveFile: - path = QFileDialog::getSaveFileName( myPath, QString(), initial, pathFilter() ); + path = QFileDialog::getSaveFileName( myPath, QString(), initial, pathFilter(), nullptr, pathOptions() ); break; case Qtx::PT_Directory: - path = QFileDialog::getExistingDirectory( myPath, QString(), initial ); + path = QFileDialog::getExistingDirectory( myPath, QString(), initial, pathOptions() ); break; } diff --git a/src/Qtx/QtxPathEdit.h b/src/Qtx/QtxPathEdit.h index 0320928ad..ad385922c 100644 --- a/src/Qtx/QtxPathEdit.h +++ b/src/Qtx/QtxPathEdit.h @@ -26,6 +26,7 @@ #include "Qtx.h" #include +#include class QLineEdit; @@ -47,6 +48,9 @@ public: QString pathFilter() const; void setPathFilter( const QString& ); + QFileDialog::Options pathOptions() const; + void setPathOptions( const QFileDialog::Options ); + private slots: void onBrowse( bool = false ); @@ -61,6 +65,7 @@ private: QLineEdit* myPath; Qtx::PathType myType; QString myFilter; + QFileDialog::Options myOptions; bool myBrowse; };