Salome HOME
Add file dialog options in QtxPathEdit
authorCHEMIN Sebastien <sc236498@is245491.intra.cea.fr>
Fri, 12 Jan 2024 09:23:43 +0000 (10:23 +0100)
committerNabil Ghodbane <nabil.ghodbane@cea.fr>
Thu, 29 Feb 2024 11:10:57 +0000 (12:10 +0100)
src/Qtx/QtxPagePrefMgr.cxx
src/Qtx/QtxPagePrefMgr.h
src/Qtx/QtxPathEdit.cxx
src/Qtx/QtxPathEdit.h

index 412e178d40ac0d41ddd7a5009e37a23ef7d5788a..d0d861ed0060b74e1b4c7ab772bbd8f3f2b3436c 100644 (file)
@@ -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 );
 }
index a327f47b2d07d918464110924028a9b52f9d8c89..5341734811f9890d3eb71aa8787df3153b097bb8 100644 (file)
@@ -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();
index c349ff8a20602e9280ad34f5f5db13cddbf14edd..8dcac94eec04bae436f0b3eed6001d07ef98bcd7 100644 (file)
@@ -29,7 +29,6 @@
 #include <QCompleter>
 #include <QKeyEvent>
 #include <QToolButton>
-#include <QFileDialog>
 #include <QRegExpValidator>
 
 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;
   }
 
index e436be28dd8f6623a9d2155dbcaadef9ec83ba67..6a4b670c476e143c78ce675fda367d307993386b 100644 (file)
@@ -26,6 +26,7 @@
 #include "Qtx.h"
 
 #include <QFrame>
+#include <QFileDialog>
 
 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;
 };