Skip to content

Commit

Permalink
Add a "cancel all" button when searching for missing files after open…
Browse files Browse the repository at this point in the history
…ing a project. Fixes #1317

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11524 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
homann committed Aug 29, 2009
1 parent b4cc8f7 commit b78d1e2
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 15 deletions.
52 changes: 37 additions & 15 deletions src/app/qgisapp.cpp
Expand Up @@ -2338,10 +2338,13 @@ static void buildSupportedVectorFileFilter_( QString & fileFilters )
*/

static void openFilesRememberingFilter_( QString const &filterName,
QString const &filters, QStringList & selectedFiles, QString& enc, QString &title )
static bool openFilesRememberingFilter_( QString const &filterName,
QString const &filters, QStringList & selectedFiles, QString& enc, QString &title,
bool cancelAll = false )
{

bool retVal = false;

bool haveLastUsedFilter = false; // by default, there is no last
// used filter

Expand All @@ -2367,6 +2370,12 @@ static void openFilesRememberingFilter_( QString const &filterName,
openFileDialog->selectFilter( lastUsedFilter );
}

// Check if we should add a cancel all button
if ( cancelAll )
{
openFileDialog->addCancelAll();
}

if ( openFileDialog->exec() == QDialog::Accepted )
{
selectedFiles = openFileDialog->selectedFiles();
Expand All @@ -2383,8 +2392,14 @@ static void openFilesRememberingFilter_( QString const &filterName,
settings.setValue( "/UI/" + filterName, openFileDialog->selectedFilter() );
settings.setValue( "/UI/" + filterName + "Dir", myPath );
}
else
{
// Cancel or cancel all
retVal = openFileDialog->cancelAll();
}

delete openFileDialog;
return retVal;
} // openFilesRememberingFilter_


Expand Down Expand Up @@ -2938,7 +2953,7 @@ setDataSource_( QDomNode & layerNode, QString const & dataSource )
*/
static
void
bool
findMissingFile_( QString const & fileFilters, QDomNode & layerNode )
{
// Prepend that file name to the valid file format filter list since it
Expand Down Expand Up @@ -2966,7 +2981,7 @@ findMissingFile_( QString const & fileFilters, QDomNode & layerNode )
}
default:
QgsDebugMsg( "unable to determine data type" );
return;
return false;
}

// Prepend the original data source base name to make it easier to pick it
Expand All @@ -2982,15 +2997,16 @@ findMissingFile_( QString const & fileFilters, QDomNode & layerNode )
.arg( originalDataSource.fileName() )
.arg( originalDataSource.absoluteFilePath() );

openFilesRememberingFilter_( memoryQualifier,
myFileFilters,
selectedFiles,
enc,
title );
bool retVal = openFilesRememberingFilter_( memoryQualifier,
myFileFilters,
selectedFiles,
enc,
title,
true );

if ( selectedFiles.isEmpty() )
{
return;
return retVal;
}
else
{
Expand All @@ -3000,7 +3016,7 @@ findMissingFile_( QString const & fileFilters, QDomNode & layerNode )
QgsDebugMsg( "unable to re-read layer" );
}
}

return retVal;
} // findMissingFile_


Expand All @@ -3019,17 +3035,19 @@ findMissingFile_( QString const & fileFilters, QDomNode & layerNode )
*/
static
void
bool
findLayer_( QString const & fileFilters, QDomNode const & constLayerNode )
{
// XXX actually we could possibly get away with a copy of the node
QDomNode & layerNode = const_cast<QDomNode&>( constLayerNode );

bool retVal = false;

switch ( providerType_( layerNode ) )
{
case IS_FILE:
QgsDebugMsg( "layer is file based" );
findMissingFile_( fileFilters, layerNode );
retVal = findMissingFile_( fileFilters, layerNode );
break;

case IS_DATABASE:
Expand All @@ -3044,7 +3062,7 @@ findLayer_( QString const & fileFilters, QDomNode const & constLayerNode )
QgsDebugMsg( "layer has an unkown type" );
break;
}

return retVal;
} // findLayer_


Expand All @@ -3064,7 +3082,11 @@ findLayers_( QString const & fileFilters, std::list<QDomNode> const & layerNodes
i != layerNodes.end();
++i )
{
findLayer_( fileFilters, *i );
if ( findLayer_( fileFilters, *i ) )
{
// If findLayer returns true, the user hit Cancel All button
break;
}
}

} // findLayers_
Expand Down
25 changes: 25 additions & 0 deletions src/gui/qgsencodingfiledialog.cpp
Expand Up @@ -18,6 +18,7 @@
#include "qgslogger.h"
#include <QSettings>
#include <QComboBox>
#include <QPushButton>
#include <QLabel>
#include <QLayout>
#include <QTextCodec>
Expand All @@ -28,6 +29,8 @@ QgsEncodingFileDialog::QgsEncodingFileDialog( QWidget * parent,
const QString & filter, const QString & encoding )
: QFileDialog( parent, caption, directory, filter )
{
mCancelAll = false;
mCancelAllButton = 0;
mEncodingComboBox = new QComboBox( this );
QLabel* l = new QLabel( tr( "Encoding:" ), this );
layout()->addWidget( l );
Expand Down Expand Up @@ -121,3 +124,25 @@ void QgsEncodingFileDialog::saveUsedEncoding()
settings.setValue( "/UI/encoding", encoding() );
QgsDebugMsg( QString( "Set encoding " + encoding() + " as default." ) );
}

void QgsEncodingFileDialog::addCancelAll()
{
if ( ! mCancelAllButton )
{
mCancelAllButton = new QPushButton( "Cancel &All", NULL );
layout()->addWidget( mCancelAllButton ); // Ownership transfered, no need to delete later on
connect( mCancelAllButton, SIGNAL( clicked() ), this, SLOT( pbnCancelAll_clicked() ) );
}
}

bool QgsEncodingFileDialog::cancelAll()
{
return mCancelAll;
}

void QgsEncodingFileDialog::pbnCancelAll_clicked()
{
mCancelAll = true;
// Now, continue as the user clicked the cancel button
reject();
}
14 changes: 14 additions & 0 deletions src/gui/qgsencodingfiledialog.h
Expand Up @@ -18,6 +18,7 @@

#include <QFileDialog>
class QComboBox;
class QPushButton;

/** \ingroup gui
* A file dialog which lets the user select the prefered encoding type for a data provider.
Expand All @@ -32,12 +33,25 @@ class GUI_EXPORT QgsEncodingFileDialog: public QFileDialog
~QgsEncodingFileDialog();
/**Returns a string describing the choosen encoding*/
QString encoding() const;
/* Adds a 'Cancel All' button for the user to click */
void addCancelAll();
/* Returns true if the user clicked 'Cancel All' */
bool cancelAll();

public slots:
void saveUsedEncoding();

void pbnCancelAll_clicked();

private:
/**Box to choose the encoding type*/
QComboBox* mEncodingComboBox;

/* The button to click */
QPushButton *mCancelAllButton;

/* Set if user clicked 'Cancel All' */
bool mCancelAll;
};

#endif

0 comments on commit b78d1e2

Please sign in to comment.