Skip to content

Commit 05a28b8

Browse files
committedSep 26, 2015
[auth] Integrate authcfg editing widget into handle bad layers dialog
1 parent c74ddf1 commit 05a28b8

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed
 

‎src/app/qgshandlebadlayers.cpp

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "qgshandlebadlayers.h"
1919
#include "qgisapp.h"
20+
#include "qgsauthconfigselect.h"
2021
#include "qgisgui.h"
2122
#include "qgsdatasourceuri.h"
2223
#include "qgslogger.h"
@@ -78,12 +79,14 @@ QgsHandleBadLayers::QgsHandleBadLayers( const QList<QDomNode> &layers, const QDo
7879
mLayerList->clear();
7980
mLayerList->setSortingEnabled( true );
8081
mLayerList->setSelectionBehavior( QAbstractItemView::SelectRows );
81-
mLayerList->setColumnCount( 4 );
82+
mLayerList->setColumnCount( 5 );
83+
mLayerList->setColumnWidth( 3, 75 );
8284

8385
mLayerList->setHorizontalHeaderLabels( QStringList()
8486
<< tr( "Layer name" )
8587
<< tr( "Type" )
8688
<< tr( "Provider" )
89+
<< tr( "Auth config" )
8790
<< tr( "Datasource" )
8891
);
8992

@@ -123,8 +126,24 @@ QgsHandleBadLayers::QgsHandleBadLayers( const QList<QDomNode> &layers, const QDo
123126
item->setFlags( item->flags() & ~Qt::ItemIsEditable );
124127
mLayerList->setItem( j, 2, item );
125128

129+
if ( QgsAuthConfigUriEdit::hasConfigID( datasource ) )
130+
{
131+
QToolButton *btn = new QToolButton( this );
132+
btn->setMaximumWidth( 75 );
133+
btn->setMinimumHeight( 24 );
134+
btn->setText( tr( "Edit" ) );
135+
btn->setProperty( "row", j );
136+
connect( btn, SIGNAL( clicked() ), this, SLOT( editAuthCfg() ) );
137+
mLayerList->setCellWidget( j, 3, btn );
138+
}
139+
else
140+
{
141+
item = new QTableWidgetItem( "" );
142+
mLayerList->setItem( j, 3, item );
143+
}
144+
126145
item = new QTableWidgetItem( datasource );
127-
mLayerList->setItem( j, 3, item );
146+
mLayerList->setItem( j, 4, item );
128147

129148
j++;
130149
}
@@ -161,7 +180,7 @@ QString QgsHandleBadLayers::filename( int row )
161180
{
162181
QString type = mLayerList->item( row, 1 )->text();
163182
QString provider = mLayerList->item( row, 2 )->text();
164-
QString datasource = mLayerList->item( row, 3 )->text();
183+
QString datasource = mLayerList->item( row, 4 )->text();
165184

166185
if ( type == "vector" )
167186
{
@@ -195,7 +214,7 @@ void QgsHandleBadLayers::setFilename( int row, QString filename )
195214

196215
QString type = mLayerList->item( row, 1 )->text();
197216
QString provider = mLayerList->item( row, 2 )->text();
198-
QTableWidgetItem *item = mLayerList->item( row, 3 );
217+
QTableWidgetItem *item = mLayerList->item( row, 4 );
199218

200219
QString datasource = item->text();
201220

@@ -305,6 +324,42 @@ void QgsHandleBadLayers::browseClicked()
305324
}
306325
}
307326

327+
void QgsHandleBadLayers::editAuthCfg()
328+
{
329+
QToolButton *btn = qobject_cast<QToolButton*>( sender() );
330+
int row = -1;
331+
for ( int i = 0; i < mLayerList->rowCount(); i++ )
332+
{
333+
if ( mLayerList->cellWidget( i, 3 ) == btn )
334+
{
335+
row = i;
336+
break;
337+
}
338+
}
339+
340+
if ( row == -1 )
341+
return;
342+
343+
QString provider = mLayerList->item( row, 2 )->text();
344+
if ( provider == "none" )
345+
provider.clear();
346+
347+
QString prevuri = mLayerList->item( row, 4 )->text();
348+
349+
QgsAuthConfigUriEdit *dlg = new QgsAuthConfigUriEdit( this, prevuri, provider );
350+
dlg->setWindowModality( Qt::WindowModal );
351+
dlg->resize( 500, 500 );
352+
if ( dlg->exec() )
353+
{
354+
QString newuri( dlg->dataSourceUri() );
355+
if ( newuri != prevuri )
356+
{
357+
mLayerList->item( row, 4 )->setText( newuri );
358+
}
359+
}
360+
dlg->deleteLater();
361+
}
362+
308363
void QgsHandleBadLayers::apply()
309364
{
310365
QgsDebugMsg( "entered." );
@@ -315,7 +370,7 @@ void QgsHandleBadLayers::apply()
315370

316371
QString type = mLayerList->item( i, 1 )->text();
317372
QString provider = mLayerList->item( i, 2 )->text();
318-
QTableWidgetItem *item = mLayerList->item( i, 3 );
373+
QTableWidgetItem *item = mLayerList->item( i, 4 );
319374
QString datasource = item->text();
320375

321376
node.namedItem( "datasource" ).toElement().firstChild().toText().setData( datasource );

‎src/app/qgshandlebadlayers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class APP_EXPORT QgsHandleBadLayers
5151
private slots:
5252
void selectionChanged();
5353
void browseClicked();
54+
void editAuthCfg();
5455
void apply();
5556
void accept() override;
5657
void rejected();

0 commit comments

Comments
 (0)
Please sign in to comment.