Skip to content
Permalink
Browse files

Add a "cancel all" button when searching for missing files after open…

…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
homann committed Aug 29, 2009
1 parent b4cc8f7 commit b78d1e2d0c89febb6949a009b3c2a649e3a03897
Showing with 76 additions and 15 deletions.
  1. +37 −15 src/app/qgisapp.cpp
  2. +25 −0 src/gui/qgsencodingfiledialog.cpp
  3. +14 −0 src/gui/qgsencodingfiledialog.h
@@ -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

@@ -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();
@@ -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_


@@ -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
@@ -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
@@ -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
{
@@ -3000,7 +3016,7 @@ findMissingFile_( QString const & fileFilters, QDomNode & layerNode )
QgsDebugMsg( "unable to re-read layer" );
}
}

return retVal;
} // findMissingFile_


@@ -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:
@@ -3044,7 +3062,7 @@ findLayer_( QString const & fileFilters, QDomNode const & constLayerNode )
QgsDebugMsg( "layer has an unkown type" );
break;
}

return retVal;
} // findLayer_


@@ -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_
@@ -18,6 +18,7 @@
#include "qgslogger.h"
#include <QSettings>
#include <QComboBox>
#include <QPushButton>
#include <QLabel>
#include <QLayout>
#include <QTextCodec>
@@ -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 );
@@ -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();
}
@@ -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.
@@ -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.
You can’t perform that action at this time.