Skip to content

Commit 7132209

Browse files
committedMay 24, 2016
enable Add button in DB dialogs only when at least one table is selected (fix #5616)
1 parent 9928980 commit 7132209

11 files changed

+50
-13
lines changed
 

‎src/providers/db2/qgsdb2sourceselect.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ QgsDb2SourceSelect::QgsDb2SourceSelect( QWidget *parent, Qt::WindowFlags fl, boo
176176
mTablesTreeView->setEditTriggers( QAbstractItemView::CurrentChanged );
177177
mTablesTreeView->setItemDelegate( new QgsDb2SourceSelectDelegate( this ) );
178178

179+
connect( mTablesTreeView->selectionModel(), SIGNAL( selectionChanged( const QItemSelection&, const QItemSelection& ) ), this, SLOT( treeWidgetSelectionChanged( const QItemSelection&, const QItemSelection& ) ) );
180+
179181
QSettings settings;
180182
mTablesTreeView->setSelectionMode( settings.value( "/qgis/addDb2DC", false ).toBool() ?
181183
QAbstractItemView::ExtendedSelection :
@@ -558,9 +560,6 @@ void QgsDb2SourceSelect::finishList()
558560
{
559561
QApplication::restoreOverrideCursor();
560562

561-
if ( cmbConnections->count() > 0 )
562-
mAddButton->setEnabled( true );
563-
564563
mTablesTreeView->sortByColumn( QgsDb2TableModel::dbtmTable, Qt::AscendingOrder );
565564
mTablesTreeView->sortByColumn( QgsDb2TableModel::dbtmSchema, Qt::AscendingOrder );
566565
}
@@ -663,6 +662,12 @@ void QgsDb2SourceSelect::setSearchExpression( const QString& regexp )
663662
Q_UNUSED( regexp );
664663
}
665664

665+
void QgsDb2SourceSelect::treeWidgetSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected )
666+
{
667+
Q_UNUSED( deselected )
668+
mAddButton->setEnabled( !selected.isEmpty() );
669+
}
670+
666671

667672
QgsDb2GeomColumnTypeThread::QgsDb2GeomColumnTypeThread( QString connectionName, bool useEstimatedMetadata )
668673
: QThread()

‎src/providers/db2/qgsdb2sourceselect.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class QgsDb2SourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
142142
void setLayerType( QgsDb2LayerProperty layerProperty );
143143
void on_mTablesTreeView_clicked( const QModelIndex &index );
144144
void on_mTablesTreeView_doubleClicked( const QModelIndex &index );
145+
void treeWidgetSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
145146
//!Sets a new regular expression to the model
146147
void setSearchExpression( const QString& regexp );
147148

‎src/providers/mssql/qgsmssqlsourceselect.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ QgsMssqlSourceSelect::QgsMssqlSourceSelect( QWidget *parent, Qt::WindowFlags fl,
173173
mTablesTreeView->setEditTriggers( QAbstractItemView::CurrentChanged );
174174
mTablesTreeView->setItemDelegate( new QgsMssqlSourceSelectDelegate( this ) );
175175

176+
connect( mTablesTreeView->selectionModel(), SIGNAL( selectionChanged( const QItemSelection&, const QItemSelection& ) ), this, SLOT( treeWidgetSelectionChanged( const QItemSelection&, const QItemSelection& ) ) );
177+
176178
QSettings settings;
177179
mTablesTreeView->setSelectionMode( settings.value( "/qgis/addMSSQLDC", false ).toBool() ?
178180
QAbstractItemView::ExtendedSelection :
@@ -632,9 +634,6 @@ void QgsMssqlSourceSelect::finishList()
632634
{
633635
QApplication::restoreOverrideCursor();
634636

635-
if ( cmbConnections->count() > 0 )
636-
mAddButton->setEnabled( true );
637-
638637
mTablesTreeView->sortByColumn( QgsMssqlTableModel::dbtmTable, Qt::AscendingOrder );
639638
mTablesTreeView->sortByColumn( QgsMssqlTableModel::dbtmSchema, Qt::AscendingOrder );
640639
}
@@ -737,6 +736,11 @@ void QgsMssqlSourceSelect::setSearchExpression( const QString& regexp )
737736
Q_UNUSED( regexp );
738737
}
739738

739+
void QgsMssqlSourceSelect::treeWidgetSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected )
740+
{
741+
Q_UNUSED( deselected )
742+
mAddButton->setEnabled( !selected.isEmpty() );
743+
}
740744

741745
QgsMssqlGeomColumnTypeThread::QgsMssqlGeomColumnTypeThread( QString connectionName, bool useEstimatedMetadata )
742746
: QThread()

‎src/providers/mssql/qgsmssqlsourceselect.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class QgsMssqlSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
140140
void setLayerType( const QgsMssqlLayerProperty& layerProperty );
141141
void on_mTablesTreeView_clicked( const QModelIndex &index );
142142
void on_mTablesTreeView_doubleClicked( const QModelIndex &index );
143+
void treeWidgetSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
143144
//!Sets a new regular expression to the model
144145
void setSearchExpression( const QString& regexp );
145146

‎src/providers/oracle/qgsoraclesourceselect.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ QgsOracleSourceSelect::QgsOracleSourceSelect( QWidget *parent, Qt::WindowFlags f
224224
mTablesTreeView->setEditTriggers( QAbstractItemView::CurrentChanged );
225225
mTablesTreeView->setItemDelegate( mTablesTreeDelegate );
226226

227+
connect( mTablesTreeView->selectionModel(), SIGNAL( selectionChanged( const QItemSelection&, const QItemSelection& ) ), this, SLOT( treeWidgetSelectionChanged( const QItemSelection&, const QItemSelection& ) ) );
228+
227229
QSettings settings;
228230
mTablesTreeView->setSelectionMode( settings.value( "/qgis/addOracleDC", false ).toBool() ?
229231
QAbstractItemView::ExtendedSelection :
@@ -541,9 +543,6 @@ void QgsOracleSourceSelect::finishList()
541543
{
542544
QApplication::restoreOverrideCursor();
543545

544-
if ( cmbConnections->count() > 0 )
545-
mAddButton->setEnabled( true );
546-
547546
#if 0
548547
for ( int i = 0; i < QgsOracleTableModel::dbtmColumns; i++ )
549548
mTablesTreeView->resizeColumnToContents( i );
@@ -678,3 +677,9 @@ void QgsOracleSourceSelect::loadTableFromCache()
678677

679678
finishList();
680679
}
680+
681+
void QgsOracleSourceSelect::treeWidgetSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected )
682+
{
683+
Q_UNUSED( deselected )
684+
mAddButton->setEnabled( !selected.isEmpty() );
685+
}

‎src/providers/oracle/qgsoraclesourceselect.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class QgsOracleSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
130130
void setLayerType( QgsOracleLayerProperty layerProperty );
131131
void on_mTablesTreeView_clicked( const QModelIndex &index );
132132
void on_mTablesTreeView_doubleClicked( const QModelIndex &index );
133+
void treeWidgetSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
133134
//!Sets a new regular expression to the model
134135
void setSearchExpression( const QString& regexp );
135136

‎src/providers/postgres/qgspgsourceselect.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ QgsPgSourceSelect::QgsPgSourceSelect( QWidget *parent, Qt::WindowFlags fl, bool
252252
mTablesTreeView->setEditTriggers( QAbstractItemView::CurrentChanged );
253253
mTablesTreeView->setItemDelegate( new QgsPgSourceSelectDelegate( this ) );
254254

255+
connect( mTablesTreeView->selectionModel(), SIGNAL( selectionChanged( const QItemSelection&, const QItemSelection& ) ), this, SLOT( treeWidgetSelectionChanged( const QItemSelection&, const QItemSelection& ) ) );
256+
255257
QSettings settings;
256258
mTablesTreeView->setSelectionMode( settings.value( "/qgis/addPostgisDC", false ).toBool() ?
257259
QAbstractItemView::ExtendedSelection :
@@ -557,9 +559,6 @@ void QgsPgSourceSelect::finishList()
557559
{
558560
QApplication::restoreOverrideCursor();
559561

560-
if ( cmbConnections->count() > 0 )
561-
mAddButton->setEnabled( true );
562-
563562
#if 0
564563
for ( int i = 0; i < QgsPgTableModel::dbtmColumns; i++ )
565564
mTablesTreeView->resizeColumnToContents( i );
@@ -658,3 +657,9 @@ void QgsPgSourceSelect::setSearchExpression( const QString& regexp )
658657
{
659658
Q_UNUSED( regexp );
660659
}
660+
661+
void QgsPgSourceSelect::treeWidgetSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected )
662+
{
663+
Q_UNUSED( deselected )
664+
mAddButton->setEnabled( !selected.isEmpty() );
665+
}

‎src/providers/postgres/qgspgsourceselect.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
112112
void setLayerType( const QgsPostgresLayerProperty& layerProperty );
113113
void on_mTablesTreeView_clicked( const QModelIndex &index );
114114
void on_mTablesTreeView_doubleClicked( const QModelIndex &index );
115+
void treeWidgetSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
115116
//!Sets a new regular expression to the model
116117
void setSearchExpression( const QString& regexp );
117118

‎src/providers/spatialite/qgsspatialitesourceselect.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ QgsSpatiaLiteSourceSelect::QgsSpatiaLiteSourceSelect( QWidget * parent, Qt::Wind
9696
mTablesTreeView->setModel( &mProxyModel );
9797
mTablesTreeView->setSortingEnabled( true );
9898

99+
connect( mTablesTreeView->selectionModel(), SIGNAL( selectionChanged( const QItemSelection&, const QItemSelection& ) ), this, SLOT( treeWidgetSelectionChanged( const QItemSelection&, const QItemSelection& ) ) );
100+
99101
//for Qt < 4.3.2, passing -1 to include all model columns
100102
//in search does not seem to work
101103
mSearchColumnComboBox->setCurrentIndex( 1 );
@@ -484,7 +486,6 @@ void QgsSpatiaLiteSourceSelect::on_btnConnect_clicked()
484486

485487
if ( cmbConnections->count() > 0 )
486488
{
487-
mAddButton->setEnabled( true );
488489
mStatsButton->setEnabled( true );
489490
}
490491

@@ -573,3 +574,9 @@ void QgsSpatiaLiteSourceSelect::setSearchExpression( const QString & regexp )
573574
{
574575
Q_UNUSED( regexp );
575576
}
577+
578+
void QgsSpatiaLiteSourceSelect::treeWidgetSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected )
579+
{
580+
Q_UNUSED( deselected )
581+
mAddButton->setEnabled( !selected.isEmpty() );
582+
}

‎src/providers/spatialite/qgsspatialitesourceselect.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class QgsSpatiaLiteSourceSelect: public QDialog, private Ui::QgsDbSourceSelectBa
8686
void setLayerType( const QString& table, const QString& column, const QString& type );
8787
void on_mTablesTreeView_clicked( const QModelIndex &index );
8888
void on_mTablesTreeView_doubleClicked( const QModelIndex &index );
89+
void treeWidgetSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
8990
//!Sets a new regular expression to the model
9091
void setSearchExpression( const QString & regexp );
9192

‎src/ui/qgsdbsourceselectbase.ui

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@
101101
</item>
102102
<item row="1" column="0">
103103
<widget class="QTreeView" name="mTablesTreeView">
104+
<property name="editTriggers">
105+
<set>QAbstractItemView::NoEditTriggers</set>
106+
</property>
107+
<property name="alternatingRowColors">
108+
<bool>true</bool>
109+
</property>
104110
<property name="selectionMode">
105111
<enum>QAbstractItemView::ExtendedSelection</enum>
106112
</property>

0 commit comments

Comments
 (0)
Please sign in to comment.