Skip to content

Commit

Permalink
Merge pull request #3100 from alexbruy/add-db-table
Browse files Browse the repository at this point in the history
enable Add button in DB dialogs only when at least one table is selected (fix #5616)
  • Loading branch information
alexbruy committed May 28, 2016
2 parents 27c5f78 + 7132209 commit 427559c
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 13 deletions.
11 changes: 8 additions & 3 deletions src/providers/db2/qgsdb2sourceselect.cpp
Expand Up @@ -176,6 +176,8 @@ QgsDb2SourceSelect::QgsDb2SourceSelect( QWidget *parent, Qt::WindowFlags fl, boo
mTablesTreeView->setEditTriggers( QAbstractItemView::CurrentChanged );
mTablesTreeView->setItemDelegate( new QgsDb2SourceSelectDelegate( this ) );

connect( mTablesTreeView->selectionModel(), SIGNAL( selectionChanged( const QItemSelection&, const QItemSelection& ) ), this, SLOT( treeWidgetSelectionChanged( const QItemSelection&, const QItemSelection& ) ) );

QSettings settings;
mTablesTreeView->setSelectionMode( settings.value( "/qgis/addDb2DC", false ).toBool() ?
QAbstractItemView::ExtendedSelection :
Expand Down Expand Up @@ -558,9 +560,6 @@ void QgsDb2SourceSelect::finishList()
{
QApplication::restoreOverrideCursor();

if ( cmbConnections->count() > 0 )
mAddButton->setEnabled( true );

mTablesTreeView->sortByColumn( QgsDb2TableModel::dbtmTable, Qt::AscendingOrder );
mTablesTreeView->sortByColumn( QgsDb2TableModel::dbtmSchema, Qt::AscendingOrder );
}
Expand Down Expand Up @@ -663,6 +662,12 @@ void QgsDb2SourceSelect::setSearchExpression( const QString& regexp )
Q_UNUSED( regexp );
}

void QgsDb2SourceSelect::treeWidgetSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected )
{
Q_UNUSED( deselected )
mAddButton->setEnabled( !selected.isEmpty() );
}


QgsDb2GeomColumnTypeThread::QgsDb2GeomColumnTypeThread( QString connectionName, bool useEstimatedMetadata )
: QThread()
Expand Down
1 change: 1 addition & 0 deletions src/providers/db2/qgsdb2sourceselect.h
Expand Up @@ -142,6 +142,7 @@ class QgsDb2SourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
void setLayerType( QgsDb2LayerProperty layerProperty );
void on_mTablesTreeView_clicked( const QModelIndex &index );
void on_mTablesTreeView_doubleClicked( const QModelIndex &index );
void treeWidgetSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
//!Sets a new regular expression to the model
void setSearchExpression( const QString& regexp );

Expand Down
10 changes: 7 additions & 3 deletions src/providers/mssql/qgsmssqlsourceselect.cpp
Expand Up @@ -173,6 +173,8 @@ QgsMssqlSourceSelect::QgsMssqlSourceSelect( QWidget *parent, Qt::WindowFlags fl,
mTablesTreeView->setEditTriggers( QAbstractItemView::CurrentChanged );
mTablesTreeView->setItemDelegate( new QgsMssqlSourceSelectDelegate( this ) );

connect( mTablesTreeView->selectionModel(), SIGNAL( selectionChanged( const QItemSelection&, const QItemSelection& ) ), this, SLOT( treeWidgetSelectionChanged( const QItemSelection&, const QItemSelection& ) ) );

QSettings settings;
mTablesTreeView->setSelectionMode( settings.value( "/qgis/addMSSQLDC", false ).toBool() ?
QAbstractItemView::ExtendedSelection :
Expand Down Expand Up @@ -632,9 +634,6 @@ void QgsMssqlSourceSelect::finishList()
{
QApplication::restoreOverrideCursor();

if ( cmbConnections->count() > 0 )
mAddButton->setEnabled( true );

mTablesTreeView->sortByColumn( QgsMssqlTableModel::dbtmTable, Qt::AscendingOrder );
mTablesTreeView->sortByColumn( QgsMssqlTableModel::dbtmSchema, Qt::AscendingOrder );
}
Expand Down Expand Up @@ -737,6 +736,11 @@ void QgsMssqlSourceSelect::setSearchExpression( const QString& regexp )
Q_UNUSED( regexp );
}

void QgsMssqlSourceSelect::treeWidgetSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected )
{
Q_UNUSED( deselected )
mAddButton->setEnabled( !selected.isEmpty() );
}

QgsMssqlGeomColumnTypeThread::QgsMssqlGeomColumnTypeThread( QString connectionName, bool useEstimatedMetadata )
: QThread()
Expand Down
1 change: 1 addition & 0 deletions src/providers/mssql/qgsmssqlsourceselect.h
Expand Up @@ -140,6 +140,7 @@ class QgsMssqlSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
void setLayerType( const QgsMssqlLayerProperty& layerProperty );
void on_mTablesTreeView_clicked( const QModelIndex &index );
void on_mTablesTreeView_doubleClicked( const QModelIndex &index );
void treeWidgetSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
//!Sets a new regular expression to the model
void setSearchExpression( const QString& regexp );

Expand Down
11 changes: 8 additions & 3 deletions src/providers/oracle/qgsoraclesourceselect.cpp
Expand Up @@ -224,6 +224,8 @@ QgsOracleSourceSelect::QgsOracleSourceSelect( QWidget *parent, Qt::WindowFlags f
mTablesTreeView->setEditTriggers( QAbstractItemView::CurrentChanged );
mTablesTreeView->setItemDelegate( mTablesTreeDelegate );

connect( mTablesTreeView->selectionModel(), SIGNAL( selectionChanged( const QItemSelection&, const QItemSelection& ) ), this, SLOT( treeWidgetSelectionChanged( const QItemSelection&, const QItemSelection& ) ) );

QSettings settings;
mTablesTreeView->setSelectionMode( settings.value( "/qgis/addOracleDC", false ).toBool() ?
QAbstractItemView::ExtendedSelection :
Expand Down Expand Up @@ -541,9 +543,6 @@ void QgsOracleSourceSelect::finishList()
{
QApplication::restoreOverrideCursor();

if ( cmbConnections->count() > 0 )
mAddButton->setEnabled( true );

#if 0
for ( int i = 0; i < QgsOracleTableModel::dbtmColumns; i++ )
mTablesTreeView->resizeColumnToContents( i );
Expand Down Expand Up @@ -678,3 +677,9 @@ void QgsOracleSourceSelect::loadTableFromCache()

finishList();
}

void QgsOracleSourceSelect::treeWidgetSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected )
{
Q_UNUSED( deselected )
mAddButton->setEnabled( !selected.isEmpty() );
}
1 change: 1 addition & 0 deletions src/providers/oracle/qgsoraclesourceselect.h
Expand Up @@ -130,6 +130,7 @@ class QgsOracleSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
void setLayerType( QgsOracleLayerProperty layerProperty );
void on_mTablesTreeView_clicked( const QModelIndex &index );
void on_mTablesTreeView_doubleClicked( const QModelIndex &index );
void treeWidgetSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
//!Sets a new regular expression to the model
void setSearchExpression( const QString& regexp );

Expand Down
11 changes: 8 additions & 3 deletions src/providers/postgres/qgspgsourceselect.cpp
Expand Up @@ -252,6 +252,8 @@ QgsPgSourceSelect::QgsPgSourceSelect( QWidget *parent, Qt::WindowFlags fl, bool
mTablesTreeView->setEditTriggers( QAbstractItemView::CurrentChanged );
mTablesTreeView->setItemDelegate( new QgsPgSourceSelectDelegate( this ) );

connect( mTablesTreeView->selectionModel(), SIGNAL( selectionChanged( const QItemSelection&, const QItemSelection& ) ), this, SLOT( treeWidgetSelectionChanged( const QItemSelection&, const QItemSelection& ) ) );

QSettings settings;
mTablesTreeView->setSelectionMode( settings.value( "/qgis/addPostgisDC", false ).toBool() ?
QAbstractItemView::ExtendedSelection :
Expand Down Expand Up @@ -557,9 +559,6 @@ void QgsPgSourceSelect::finishList()
{
QApplication::restoreOverrideCursor();

if ( cmbConnections->count() > 0 )
mAddButton->setEnabled( true );

#if 0
for ( int i = 0; i < QgsPgTableModel::dbtmColumns; i++ )
mTablesTreeView->resizeColumnToContents( i );
Expand Down Expand Up @@ -658,3 +657,9 @@ void QgsPgSourceSelect::setSearchExpression( const QString& regexp )
{
Q_UNUSED( regexp );
}

void QgsPgSourceSelect::treeWidgetSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected )
{
Q_UNUSED( deselected )
mAddButton->setEnabled( !selected.isEmpty() );
}
1 change: 1 addition & 0 deletions src/providers/postgres/qgspgsourceselect.h
Expand Up @@ -112,6 +112,7 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
void setLayerType( const QgsPostgresLayerProperty& layerProperty );
void on_mTablesTreeView_clicked( const QModelIndex &index );
void on_mTablesTreeView_doubleClicked( const QModelIndex &index );
void treeWidgetSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
//!Sets a new regular expression to the model
void setSearchExpression( const QString& regexp );

Expand Down
9 changes: 8 additions & 1 deletion src/providers/spatialite/qgsspatialitesourceselect.cpp
Expand Up @@ -96,6 +96,8 @@ QgsSpatiaLiteSourceSelect::QgsSpatiaLiteSourceSelect( QWidget * parent, Qt::Wind
mTablesTreeView->setModel( &mProxyModel );
mTablesTreeView->setSortingEnabled( true );

connect( mTablesTreeView->selectionModel(), SIGNAL( selectionChanged( const QItemSelection&, const QItemSelection& ) ), this, SLOT( treeWidgetSelectionChanged( const QItemSelection&, const QItemSelection& ) ) );

//for Qt < 4.3.2, passing -1 to include all model columns
//in search does not seem to work
mSearchColumnComboBox->setCurrentIndex( 1 );
Expand Down Expand Up @@ -484,7 +486,6 @@ void QgsSpatiaLiteSourceSelect::on_btnConnect_clicked()

if ( cmbConnections->count() > 0 )
{
mAddButton->setEnabled( true );
mStatsButton->setEnabled( true );
}

Expand Down Expand Up @@ -573,3 +574,9 @@ void QgsSpatiaLiteSourceSelect::setSearchExpression( const QString & regexp )
{
Q_UNUSED( regexp );
}

void QgsSpatiaLiteSourceSelect::treeWidgetSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected )
{
Q_UNUSED( deselected )
mAddButton->setEnabled( !selected.isEmpty() );
}
1 change: 1 addition & 0 deletions src/providers/spatialite/qgsspatialitesourceselect.h
Expand Up @@ -86,6 +86,7 @@ class QgsSpatiaLiteSourceSelect: public QDialog, private Ui::QgsDbSourceSelectBa
void setLayerType( const QString& table, const QString& column, const QString& type );
void on_mTablesTreeView_clicked( const QModelIndex &index );
void on_mTablesTreeView_doubleClicked( const QModelIndex &index );
void treeWidgetSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
//!Sets a new regular expression to the model
void setSearchExpression( const QString & regexp );

Expand Down
6 changes: 6 additions & 0 deletions src/ui/qgsdbsourceselectbase.ui
Expand Up @@ -101,6 +101,12 @@
</item>
<item row="1" column="0">
<widget class="QTreeView" name="mTablesTreeView">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
Expand Down

0 comments on commit 427559c

Please sign in to comment.