Skip to content

Commit fbea9f5

Browse files
committedNov 5, 2018
Renamed buttons for bad layers dialog
1 parent 70d9b6c commit fbea9f5

File tree

3 files changed

+23
-58
lines changed

3 files changed

+23
-58
lines changed
 

‎src/app/qgshandlebadlayers.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,18 @@
3333
#include <QPushButton>
3434
#include <QToolButton>
3535
#include <QMessageBox>
36+
#include <QDialogButtonBox>
3637
#include <QUrl>
3738

3839
void QgsHandleBadLayersHandler::handleBadLayers( const QList<QDomNode> &layers )
3940
{
4041
QApplication::setOverrideCursor( Qt::ArrowCursor );
4142
QgsHandleBadLayers *dialog = new QgsHandleBadLayers( layers );
4243

44+
dialog->buttonBox->button( QDialogButtonBox::Ignore )->setToolTip( tr( "Import all bad layers unmodified (you can fix them later)." ) );
45+
dialog->buttonBox->button( QDialogButtonBox::Apply )->setToolTip( tr( "Apply fixes to bad layers (remaining bad layers will be removed from the project)." ) );
46+
dialog->buttonBox->button( QDialogButtonBox::Discard )->setToolTip( tr( "Remove all bad layers from the project" ) );
47+
4348
if ( dialog->layerCount() < layers.size() )
4449
QgisApp::instance()->messageBar()->pushMessage(
4550
tr( "Handle bad layers" ),
@@ -72,6 +77,8 @@ QgsHandleBadLayers::QgsHandleBadLayers( const QList<QDomNode> &layers )
7277
connect( mLayerList, &QTableWidget::itemSelectionChanged, this, &QgsHandleBadLayers::selectionChanged );
7378
connect( mBrowseButton, &QAbstractButton::clicked, this, &QgsHandleBadLayers::browseClicked );
7479
connect( buttonBox->button( QDialogButtonBox::Apply ), &QAbstractButton::clicked, this, &QgsHandleBadLayers::apply );
80+
connect( buttonBox->button( QDialogButtonBox::Ignore ), &QPushButton::clicked, this, &QgsHandleBadLayers::reject );
81+
connect( buttonBox->button( QDialogButtonBox::Discard ), &QPushButton::clicked, this, &QgsHandleBadLayers::accept );
7582

7683
mLayerList->clear();
7784
mLayerList->setSortingEnabled( true );
@@ -340,6 +347,13 @@ void QgsHandleBadLayers::editAuthCfg()
340347

341348
void QgsHandleBadLayers::apply()
342349
{
350+
QList<QgsMapLayer *> toRemove;
351+
for ( const auto &l : QgsProject::instance()->mapLayers( ) )
352+
{
353+
if ( ! l->isValid() )
354+
toRemove << l;
355+
}
356+
QgsProject::instance()->removeMapLayers( toRemove );
343357
for ( int i = 0; i < mLayerList->rowCount(); i++ )
344358
{
345359
int idx = mLayerList->item( i, 0 )->data( Qt::UserRole ).toInt();
@@ -364,7 +378,6 @@ void QgsHandleBadLayers::accept()
364378
{
365379
apply();
366380

367-
/*
368381
if ( mLayerList->rowCount() > 0 &&
369382
QMessageBox::warning( this,
370383
tr( "Unhandled layer will be lost." ),
@@ -376,29 +389,15 @@ void QgsHandleBadLayers::accept()
376389
{
377390
return;
378391
}
379-
*/
380-
381-
QDialog::accept();
382-
}
383-
384-
void QgsHandleBadLayers::reject()
385-
{
386-
387-
/*
388-
if ( mLayerList->rowCount() > 0 &&
389-
QMessageBox::warning( this,
390-
tr( "Unhandled layer will be lost." ),
391-
tr( "There are still %n unhandled layer(s), that will be lost if you closed now.",
392-
"unhandled layers",
393-
mLayerList->rowCount() ),
394-
QMessageBox::Ok | QMessageBox::Cancel,
395-
QMessageBox::Cancel ) == QMessageBox::Cancel )
392+
QList<QgsMapLayer *> toRemove;
393+
for ( const auto &l : QgsProject::instance()->mapLayers( ) )
396394
{
397-
return;
395+
if ( ! l->isValid() )
396+
toRemove << l;
398397
}
399-
*/
398+
mLayerList->clear();
400399

401-
QDialog::reject();
400+
QDialog::accept();
402401
}
403402

404403
int QgsHandleBadLayers::layerCount()

‎src/app/qgshandlebadlayers.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class QPushButton;
3939

4040
class APP_EXPORT QgsHandleBadLayers
4141
: public QDialog
42-
, private Ui::QgsHandleBadLayersBase
42+
, public Ui::QgsHandleBadLayersBase
4343
{
4444
Q_OBJECT
4545

@@ -54,7 +54,6 @@ class APP_EXPORT QgsHandleBadLayers
5454
void editAuthCfg();
5555
void apply();
5656
void accept() override;
57-
void reject() override;
5857

5958
private:
6059
QPushButton *mBrowseButton = nullptr;

‎src/ui/qgshandlebadlayersbase.ui

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,45 +27,12 @@
2727
<enum>Qt::Horizontal</enum>
2828
</property>
2929
<property name="standardButtons">
30-
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
30+
<set>QDialogButtonBox::Apply|QDialogButtonBox::Discard|QDialogButtonBox::Ignore</set>
3131
</property>
3232
</widget>
3333
</item>
3434
</layout>
3535
</widget>
3636
<resources/>
37-
<connections>
38-
<connection>
39-
<sender>buttonBox</sender>
40-
<signal>accepted()</signal>
41-
<receiver>QgsHandleBadLayersBase</receiver>
42-
<slot>accept()</slot>
43-
<hints>
44-
<hint type="sourcelabel">
45-
<x>248</x>
46-
<y>254</y>
47-
</hint>
48-
<hint type="destinationlabel">
49-
<x>157</x>
50-
<y>274</y>
51-
</hint>
52-
</hints>
53-
</connection>
54-
<connection>
55-
<sender>buttonBox</sender>
56-
<signal>rejected()</signal>
57-
<receiver>QgsHandleBadLayersBase</receiver>
58-
<slot>reject()</slot>
59-
<hints>
60-
<hint type="sourcelabel">
61-
<x>316</x>
62-
<y>260</y>
63-
</hint>
64-
<hint type="destinationlabel">
65-
<x>286</x>
66-
<y>274</y>
67-
</hint>
68-
</hints>
69-
</connection>
70-
</connections>
37+
<connections/>
7138
</ui>

0 commit comments

Comments
 (0)
Please sign in to comment.