[QGIS Commit] r11795 - in trunk/qgis/src/app: . ogr

svn_qgis at osgeo.org svn_qgis at osgeo.org
Mon Oct 12 04:55:13 EDT 2009


Author: mhugent
Date: 2009-10-12 04:55:12 -0400 (Mon, 12 Oct 2009)
New Revision: 11795

Modified:
   trunk/qgis/src/app/ogr/qgsopenvectorlayerdialog.cpp
   trunk/qgis/src/app/qgisapp.cpp
   trunk/qgis/src/app/qgsvectorlayerproperties.cpp
Log:
Use native file dialogs (via static methods from QFileDialog)

Modified: trunk/qgis/src/app/ogr/qgsopenvectorlayerdialog.cpp
===================================================================
--- trunk/qgis/src/app/ogr/qgsopenvectorlayerdialog.cpp	2009-10-11 10:14:24 UTC (rev 11794)
+++ trunk/qgis/src/app/ogr/qgsopenvectorlayerdialog.cpp	2009-10-12 08:55:12 UTC (rev 11795)
@@ -348,42 +348,28 @@
                            QVariant( QString::null ) ).toString();
 
   QString lastUsedDir = settings.value( "/UI/" + filterName + "Dir", "." ).toString();
-
-  //QString lastUsedEncoding = settings.value( "/UI/encoding" ).toString();
-
   QgsDebugMsg( "Opening file dialog with filters: " + filters );
 
-  QFileDialog* openFileDialog = new QFileDialog( 0,
-      title, lastUsedDir, filters );
-
-  // allow for selection of more than one file
-  openFileDialog->setFileMode( QFileDialog::ExistingFiles );
-
-  if ( haveLastUsedFilter )     // set the filter to the last one used
+  if ( haveLastUsedFilter )
   {
-    openFileDialog->selectFilter( lastUsedFilter );
+    selectedFiles = QFileDialog::getOpenFileNames( 0, title, lastUsedDir, filters, &lastUsedFilter );
   }
+  else
+  {
+    selectedFiles = QFileDialog::getOpenFileNames( 0, title, lastUsedDir, filters );
+  }
 
-  if ( openFileDialog->exec() == QDialog::Accepted )
+  if ( !selectedFiles.isEmpty() )
   {
-    selectedFiles = openFileDialog->selectedFiles();
-    //enc = openFileDialog->encoding();
-    // Fix by Tim - getting the dirPath from the dialog
-    // directly truncates the last node in the dir path.
-    // This is a workaround for that
     QString myFirstFileName = selectedFiles.first();
     QFileInfo myFI( myFirstFileName );
     QString myPath = myFI.path();
 
     QgsDebugMsg( "Writing last used dir: " + myPath );
 
-    settings.setValue( "/UI/" + filterName, openFileDialog->selectedFilter() );
+    settings.setValue( "/UI/" + filterName, lastUsedFilter );
     settings.setValue( "/UI/" + filterName + "Dir", myPath );
-    //settings.setValue( "/UI/encoding", openFileDialog->encoding() );
   }
-
-  delete openFileDialog;
-
 }   // openFilesRememberingFilter_
 
 

Modified: trunk/qgis/src/app/qgisapp.cpp
===================================================================
--- trunk/qgis/src/app/qgisapp.cpp	2009-10-11 10:14:24 UTC (rev 11794)
+++ trunk/qgis/src/app/qgisapp.cpp	2009-10-12 08:55:12 UTC (rev 11795)
@@ -2304,8 +2304,6 @@
     bool cancelAll = false )
 {
 
-  bool retVal = false;
-
   bool haveLastUsedFilter = false; // by default, there is no last
   // used filter
 
@@ -2319,28 +2317,9 @@
   QString lastUsedDir = settings.value( "/UI/" + filterName + "Dir", "." ).toString();
 
   QgsDebugMsg( "Opening file dialog with filters: " + filters );
-
-  QgsEncodingFileDialog* openFileDialog = new QgsEncodingFileDialog( 0,
-      title, lastUsedDir, filters, QString( "" ) );
-
-  // allow for selection of more than one file
-  openFileDialog->setFileMode( QFileDialog::ExistingFiles );
-
-  if ( haveLastUsedFilter )     // set the filter to the last one used
+  selectedFiles = QFileDialog::getOpenFileNames( 0, title, lastUsedDir, filters, &lastUsedFilter );
+  if ( !selectedFiles.isEmpty() )
   {
-    openFileDialog->selectFilter( lastUsedFilter );
-  }
-
-  // Check if we should add a cancel all button
-  if ( cancelAll )
-  {
-    openFileDialog->addCancelAll();
-  }
-
-  if ( openFileDialog->exec() == QDialog::Accepted )
-  {
-    selectedFiles = openFileDialog->selectedFiles();
-    enc = openFileDialog->encoding();
     // Fix by Tim - getting the dirPath from the dialog
     // directly truncates the last node in the dir path.
     // This is a workaround for that
@@ -2350,17 +2329,11 @@
 
     QgsDebugMsg( "Writing last used dir: " + myPath );
 
-    settings.setValue( "/UI/" + filterName, openFileDialog->selectedFilter() );
+    settings.setValue( "/UI/" + filterName, lastUsedFilter );
     settings.setValue( "/UI/" + filterName + "Dir", myPath );
+    return true;
   }
-  else
-  {
-    // Cancel or cancel all
-    retVal = openFileDialog->cancelAll();
-  }
-
-  delete openFileDialog;
-  return retVal;
+  return false;
 }   // openFilesRememberingFilter_
 
 
@@ -3281,33 +3254,19 @@
     // Retrieve last used project dir from persistent settings
     QSettings settings;
     QString lastUsedDir = settings.value( "/UI/lastProjectDir", "." ).toString();
-
-    QFileDialog * openFileDialog = new QFileDialog( this,
-        tr( "Choose a QGIS project file to open" ),
-        lastUsedDir, tr( "QGis files (*.qgs)" ) );
-    openFileDialog->setFileMode( QFileDialog::ExistingFile );
-
-
-    QString fullPath;
-    if ( openFileDialog->exec() == QDialog::Accepted )
+    QString fullPath = QFileDialog::getOpenFileName( this, tr( "Choose a QGIS project file to open" ), lastUsedDir, tr( "QGis files (*.qgs)" ) );
+    if ( fullPath.isNull() )
     {
-      // Fix by Tim - getting the dirPath from the dialog
-      // directly truncates the last node in the dir path.
-      // This is a workaround for that
-      fullPath = openFileDialog->selectedFiles().first();
-      QFileInfo myFI( fullPath );
-      QString myPath = myFI.path();
-      // Persist last used project dir
-      settings.setValue( "/UI/lastProjectDir", myPath );
-    }
-    else
-    {
-      // if they didn't select anything, just return
-      delete openFileDialog;
       return;
     }
 
-    delete openFileDialog;
+    // Fix by Tim - getting the dirPath from the dialog
+    // directly truncates the last node in the dir path.
+    // This is a workaround for that
+    QFileInfo myFI( fullPath );
+    QString myPath = myFI.path();
+    // Persist last used project dir
+    settings.setValue( "/UI/lastProjectDir", myPath );
 
     delete mComposer;
     mComposer = new QgsComposer( this );
@@ -3563,55 +3522,31 @@
   // Retrieve last used project dir from persistent settings
   QSettings settings;
   QString lastUsedDir = settings.value( "/UI/lastProjectDir", "." ).toString();
-
-  std::auto_ptr<QFileDialog> saveFileDialog( new QFileDialog( this,
-      tr( "Choose a file name to save the QGIS project file as" ),
-      lastUsedDir, tr( "QGis files (*.qgs)" ) ) );
-
-  saveFileDialog->setFileMode( QFileDialog::AnyFile );
-
-  saveFileDialog->setAcceptMode( QFileDialog::AcceptSave );
-
-  saveFileDialog->setConfirmOverwrite( true );
-
-  // if we don't have a file name, then obviously we need to get one; note
-  // that the project file name is reset to null in fileNew()
-  QFileInfo fullPath;
-
-  if ( saveFileDialog->exec() == QDialog::Accepted )
+  QString saveFilePath = QFileDialog::getSaveFileName( this, tr( "Choose a file name to save the QGIS project file as" ), lastUsedDir, tr( "QGis files (*.qgs)" ) );
+  if ( saveFilePath.isNull() ) //canceled
   {
-    // Fix by Tim - getting the dirPath from the dialog
-    // directly truncates the last node in the dir path.
-    // This is a workaround for that
-    fullPath.setFile( saveFileDialog->selectedFiles().first() );
-    QString myPath = fullPath.path();
-    // Persist last used project dir
-    settings.setValue( "/UI/lastProjectDir", myPath );
-  }
-  else
-  {
-    // if they didn't select anything, just return
-    // delete saveFileDialog; auto_ptr auto deletes
     return;
   }
+  QFileInfo myFI( saveFilePath );
+  QString myPath = myFI.path();
+  settings.setValue( "/UI/lastProjectDir", myPath );
 
   // make sure the .qgs extension is included in the path name. if not, add it...
-  if ( "qgs" != fullPath.suffix() )
+  if ( "qgs" != myFI.suffix() )
   {
-    QString newFilePath = fullPath.filePath() + ".qgs";
-    fullPath.setFile( newFilePath );
+    saveFilePath = myFI.filePath() + ".qgs";
   }
 
   try
   {
-    QgsProject::instance()->setFileName( fullPath.filePath() );
+    QgsProject::instance()->setFileName( saveFilePath );
 
     if ( QgsProject::instance()->write() )
     {
       setTitleBarText_( *this ); // update title bar
       statusBar()->showMessage( tr( "Saved project to: %1" ).arg( QgsProject::instance()->fileName() ) );
       // add this to the list of recently used project files
-      saveRecentProjectPath( fullPath.filePath(), settings );
+      saveRecentProjectPath( saveFilePath, settings );
     }
     else
     {

Modified: trunk/qgis/src/app/qgsvectorlayerproperties.cpp
===================================================================
--- trunk/qgis/src/app/qgsvectorlayerproperties.cpp	2009-10-11 10:14:24 UTC (rev 11794)
+++ trunk/qgis/src/app/qgsvectorlayerproperties.cpp	2009-10-12 08:55:12 UTC (rev 11795)
@@ -956,60 +956,28 @@
 {
   QSettings myQSettings;  // where we keep last used filter in persistant state
   QString myLastUsedDir = myQSettings.value( "style/lastStyleDir", "." ).toString();
-
-  //create a file dialog
-  std::auto_ptr < QFileDialog > myFileDialog
-  (
-    new QFileDialog(
-      this,
-      tr( "Load layer properties from style file (.qml)" ),
-      myLastUsedDir,
-      tr( "QGIS Layer Style File (*.qml)" )
-    )
-  );
-  myFileDialog->setFileMode( QFileDialog::AnyFile );
-  myFileDialog->setAcceptMode( QFileDialog::AcceptOpen );
-
-  //prompt the user for a file name
-  QString myFileName;
-  if ( myFileDialog->exec() == QDialog::Accepted )
+  QString myFileName = QFileDialog::getOpenFileName( this, tr( "Load layer properties from style file (.qml)" ), myLastUsedDir, tr( "QGIS Layer Style File (*.qml)" ) );
+  if ( myFileName.isNull() )
   {
-    QStringList myFiles = myFileDialog->selectedFiles();
-    if ( !myFiles.isEmpty() )
-    {
-      myFileName = myFiles[0];
-    }
+    return;
   }
 
-  if ( !myFileName.isEmpty() )
+  bool defaultLoadedFlag = false;
+  QString myMessage = layer->loadNamedStyle( myFileName, defaultLoadedFlag );
+  //reset if the default style was loaded ok only
+  if ( defaultLoadedFlag )
   {
-    if ( myFileDialog->selectedFilter() == tr( "QGIS Layer Style File (*.qml)" ) )
-    {
-      //ensure the user never omitted the extension from the file name
-      if ( !myFileName.endsWith( ".qml", Qt::CaseInsensitive ) )
-      {
-        myFileName += ".qml";
-      }
-      bool defaultLoadedFlag = false;
-      QString myMessage = layer->loadNamedStyle( myFileName, defaultLoadedFlag );
-      //reset if the default style was loaded ok only
-      if ( defaultLoadedFlag )
-      {
-        reset();
-      }
-      else
-      {
-        //let the user know what went wrong
-        QMessageBox::information( this, tr( "Saved Style" ), myMessage );
-      }
-    }
-    else
-    {
-      QMessageBox::warning( this, tr( "QGIS" ),
-                            tr( "Unknown style format: %1" ).arg( myFileDialog->selectedFilter() ) );
-    }
-    myQSettings.setValue( "style/lastStyleDir", myFileDialog->directory().absolutePath() );
+    reset();
   }
+  else
+  {
+    //let the user know what went wrong
+    QMessageBox::information( this, tr( "Saved Style" ), myMessage );
+  }
+
+  QFileInfo myFI( myFileName );
+  QString myPath = myFI.path();
+  myQSettings.setValue( "style/lastStyleDir", myPath );
 }
 
 
@@ -1017,64 +985,37 @@
 {
   QSettings myQSettings;  // where we keep last used filter in persistant state
   QString myLastUsedDir = myQSettings.value( "style/lastStyleDir", "." ).toString();
+  QString myOutputFileName = QFileDialog::getSaveFileName( this, tr( "Save layer properties as style file (.qml)" ), myLastUsedDir, tr( "QGIS Layer Style File (*.qml)" ) );
+  if ( myOutputFileName.isNull() ) //dialog canceled
+  {
+    return;
+  }
 
-  //create a file dialog
-  std::auto_ptr < QFileDialog > myFileDialog
-  (
-    new QFileDialog(
-      this,
-      tr( "Save layer properties as style file (.qml)" ),
-      myLastUsedDir,
-      tr( "QGIS Layer Style File (*.qml)" )
-    )
-  );
-  myFileDialog->setFileMode( QFileDialog::AnyFile );
-  myFileDialog->setAcceptMode( QFileDialog::AcceptSave );
+  apply(); // make sure the qml to save is uptodate
 
-  //prompt the user for a file name
-  QString myOutputFileName;
-  if ( myFileDialog->exec() == QDialog::Accepted )
+  //ensure the user never ommitted the extension from the file name
+  if ( !myOutputFileName.endsWith( ".qml", Qt::CaseInsensitive ) )
   {
-    QStringList myFiles = myFileDialog->selectedFiles();
-    if ( !myFiles.isEmpty() )
-    {
-      myOutputFileName = myFiles[0];
-    }
+    myOutputFileName += ".qml";
   }
 
-  if ( !myOutputFileName.isEmpty() )
+  bool defaultLoadedFlag = false;
+  QString myMessage = layer->saveNamedStyle( myOutputFileName, defaultLoadedFlag );
+  //reset if the default style was loaded ok only
+  if ( defaultLoadedFlag )
   {
-    if ( myFileDialog->selectedFilter() == tr( "QGIS Layer Style File (*.qml)" ) )
-    {
-      apply(); // make sure the qml to save is uptodate
-
-      //ensure the user never ommitted the extension from the file name
-      if ( !myOutputFileName.endsWith( ".qml", Qt::CaseInsensitive ) )
-      {
-        myOutputFileName += ".qml";
-      }
-
-      bool defaultLoadedFlag = false;
-      QString myMessage = layer->saveNamedStyle( myOutputFileName, defaultLoadedFlag );
-      //reset if the default style was loaded ok only
-      if ( defaultLoadedFlag )
-      {
-        reset();
-      }
-      else
-      {
-        //let the user know what went wrong
-        QMessageBox::information( this, tr( "Saved Style" ), myMessage );
-      }
-    }
-    else
-    {
-      QMessageBox::warning( this, tr( "QGIS" ),
-                            tr( "Unknown style format: %1" ).arg( myFileDialog->selectedFilter() ) );
-    }
-
-    myQSettings.setValue( "style/lastStyleDir", myFileDialog->directory().absolutePath() );
+    reset();
   }
+  else
+  {
+    //let the user know what went wrong
+    QMessageBox::information( this, tr( "Saved Style" ), myMessage );
+  }
+
+  QFileInfo myFI( myOutputFileName );
+  QString myPath = myFI.path();
+  // Persist last used dir
+  myQSettings.setValue( "style/lastStyleDir", myPath );
 }
 
 void QgsVectorLayerProperties::on_tblAttributes_cellChanged( int row, int column )



More information about the QGIS-commit mailing list