From ded22958849d839efe21b0f4831bd89fb5ff3bd8 Mon Sep 17 00:00:00 2001 From: CHEMIN Sebastien Date: Fri, 12 Jan 2024 10:23:43 +0100 Subject: [PATCH] Add file dialog options in QtxPathEdit --- src/Qtx/QtxPagePrefMgr.cxx | 28 ++++++++++++++++++++++++++++ src/Qtx/QtxPagePrefMgr.h | 3 +++ src/Qtx/QtxPathEdit.cxx | 31 +++++++++++++++++++++++++++---- src/Qtx/QtxPathEdit.h | 5 +++++ 4 files changed, 63 insertions(+), 4 deletions(-) diff --git a/src/Qtx/QtxPagePrefMgr.cxx b/src/Qtx/QtxPagePrefMgr.cxx index 412e178d4..d0d861ed0 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 a327f47b2..534173481 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 c349ff8a2..8dcac94ee 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 e436be28d..6a4b670c4 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; }; -- 2.30.2