Skip to content

Commit bc92ebb

Browse files
author
homann
committed
Add a "cancel all" button when searching for missing files after opening a project. Fixes #1317
git-svn-id: http://svn.osgeo.org/qgis/trunk@11524 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent d85624a commit bc92ebb

File tree

3 files changed

+76
-15
lines changed

3 files changed

+76
-15
lines changed

src/app/qgisapp.cpp

+37-15
Original file line numberDiff line numberDiff line change
@@ -2338,10 +2338,13 @@ static void buildSupportedVectorFileFilter_( QString & fileFilters )
23382338
23392339
*/
23402340

2341-
static void openFilesRememberingFilter_( QString const &filterName,
2342-
QString const &filters, QStringList & selectedFiles, QString& enc, QString &title )
2341+
static bool openFilesRememberingFilter_( QString const &filterName,
2342+
QString const &filters, QStringList & selectedFiles, QString& enc, QString &title,
2343+
bool cancelAll = false )
23432344
{
23442345

2346+
bool retVal = false;
2347+
23452348
bool haveLastUsedFilter = false; // by default, there is no last
23462349
// used filter
23472350

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

2373+
// Check if we should add a cancel all button
2374+
if ( cancelAll )
2375+
{
2376+
openFileDialog->addCancelAll();
2377+
}
2378+
23702379
if ( openFileDialog->exec() == QDialog::Accepted )
23712380
{
23722381
selectedFiles = openFileDialog->selectedFiles();
@@ -2383,8 +2392,14 @@ static void openFilesRememberingFilter_( QString const &filterName,
23832392
settings.setValue( "/UI/" + filterName, openFileDialog->selectedFilter() );
23842393
settings.setValue( "/UI/" + filterName + "Dir", myPath );
23852394
}
2395+
else
2396+
{
2397+
// Cancel or cancel all
2398+
retVal = openFileDialog->cancelAll();
2399+
}
23862400

23872401
delete openFileDialog;
2402+
return retVal;
23882403
} // openFilesRememberingFilter_
23892404

23902405

@@ -2938,7 +2953,7 @@ setDataSource_( QDomNode & layerNode, QString const & dataSource )
29382953
29392954
*/
29402955
static
2941-
void
2956+
bool
29422957
findMissingFile_( QString const & fileFilters, QDomNode & layerNode )
29432958
{
29442959
// Prepend that file name to the valid file format filter list since it
@@ -2966,7 +2981,7 @@ findMissingFile_( QString const & fileFilters, QDomNode & layerNode )
29662981
}
29672982
default:
29682983
QgsDebugMsg( "unable to determine data type" );
2969-
return;
2984+
return false;
29702985
}
29712986

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

2985-
openFilesRememberingFilter_( memoryQualifier,
2986-
myFileFilters,
2987-
selectedFiles,
2988-
enc,
2989-
title );
3000+
bool retVal = openFilesRememberingFilter_( memoryQualifier,
3001+
myFileFilters,
3002+
selectedFiles,
3003+
enc,
3004+
title,
3005+
true );
29903006

29913007
if ( selectedFiles.isEmpty() )
29923008
{
2993-
return;
3009+
return retVal;
29943010
}
29953011
else
29963012
{
@@ -3000,7 +3016,7 @@ findMissingFile_( QString const & fileFilters, QDomNode & layerNode )
30003016
QgsDebugMsg( "unable to re-read layer" );
30013017
}
30023018
}
3003-
3019+
return retVal;
30043020
} // findMissingFile_
30053021

30063022

@@ -3019,17 +3035,19 @@ findMissingFile_( QString const & fileFilters, QDomNode & layerNode )
30193035
30203036
*/
30213037
static
3022-
void
3038+
bool
30233039
findLayer_( QString const & fileFilters, QDomNode const & constLayerNode )
30243040
{
30253041
// XXX actually we could possibly get away with a copy of the node
30263042
QDomNode & layerNode = const_cast<QDomNode&>( constLayerNode );
30273043

3044+
bool retVal = false;
3045+
30283046
switch ( providerType_( layerNode ) )
30293047
{
30303048
case IS_FILE:
30313049
QgsDebugMsg( "layer is file based" );
3032-
findMissingFile_( fileFilters, layerNode );
3050+
retVal = findMissingFile_( fileFilters, layerNode );
30333051
break;
30343052

30353053
case IS_DATABASE:
@@ -3044,7 +3062,7 @@ findLayer_( QString const & fileFilters, QDomNode const & constLayerNode )
30443062
QgsDebugMsg( "layer has an unkown type" );
30453063
break;
30463064
}
3047-
3065+
return retVal;
30483066
} // findLayer_
30493067

30503068

@@ -3064,7 +3082,11 @@ findLayers_( QString const & fileFilters, std::list<QDomNode> const & layerNodes
30643082
i != layerNodes.end();
30653083
++i )
30663084
{
3067-
findLayer_( fileFilters, *i );
3085+
if ( findLayer_( fileFilters, *i ) )
3086+
{
3087+
// If findLayer returns true, the user hit Cancel All button
3088+
break;
3089+
}
30683090
}
30693091

30703092
} // findLayers_

src/gui/qgsencodingfiledialog.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "qgslogger.h"
1919
#include <QSettings>
2020
#include <QComboBox>
21+
#include <QPushButton>
2122
#include <QLabel>
2223
#include <QLayout>
2324
#include <QTextCodec>
@@ -28,6 +29,8 @@ QgsEncodingFileDialog::QgsEncodingFileDialog( QWidget * parent,
2829
const QString & filter, const QString & encoding )
2930
: QFileDialog( parent, caption, directory, filter )
3031
{
32+
mCancelAll = false;
33+
mCancelAllButton = 0;
3134
mEncodingComboBox = new QComboBox( this );
3235
QLabel* l = new QLabel( tr( "Encoding:" ), this );
3336
layout()->addWidget( l );
@@ -121,3 +124,25 @@ void QgsEncodingFileDialog::saveUsedEncoding()
121124
settings.setValue( "/UI/encoding", encoding() );
122125
QgsDebugMsg( QString( "Set encoding " + encoding() + " as default." ) );
123126
}
127+
128+
void QgsEncodingFileDialog::addCancelAll()
129+
{
130+
if ( ! mCancelAllButton )
131+
{
132+
mCancelAllButton = new QPushButton( "Cancel &All", NULL );
133+
layout()->addWidget( mCancelAllButton ); // Ownership transfered, no need to delete later on
134+
connect( mCancelAllButton, SIGNAL( clicked() ), this, SLOT( pbnCancelAll_clicked() ) );
135+
}
136+
}
137+
138+
bool QgsEncodingFileDialog::cancelAll()
139+
{
140+
return mCancelAll;
141+
}
142+
143+
void QgsEncodingFileDialog::pbnCancelAll_clicked()
144+
{
145+
mCancelAll = true;
146+
// Now, continue as the user clicked the cancel button
147+
reject();
148+
}

src/gui/qgsencodingfiledialog.h

+14
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <QFileDialog>
2020
class QComboBox;
21+
class QPushButton;
2122

2223
/** \ingroup gui
2324
* 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
3233
~QgsEncodingFileDialog();
3334
/**Returns a string describing the choosen encoding*/
3435
QString encoding() const;
36+
/* Adds a 'Cancel All' button for the user to click */
37+
void addCancelAll();
38+
/* Returns true if the user clicked 'Cancel All' */
39+
bool cancelAll();
40+
3541
public slots:
3642
void saveUsedEncoding();
3743

44+
void pbnCancelAll_clicked();
45+
3846
private:
3947
/**Box to choose the encoding type*/
4048
QComboBox* mEncodingComboBox;
49+
50+
/* The button to click */
51+
QPushButton *mCancelAllButton;
52+
53+
/* Set if user clicked 'Cancel All' */
54+
bool mCancelAll;
4155
};
4256

4357
#endif

0 commit comments

Comments
 (0)