Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
regroup query button creation
  • Loading branch information
3nids committed Nov 11, 2021
1 parent 0f39b82 commit 67bcb31
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 120 deletions.
Expand Up @@ -38,6 +38,11 @@ Sets the source model for the table and optionally a delegate
Returns the proxy model used to filter the results
%End

protected slots:
virtual void treeviewClicked( const QModelIndex &index );
virtual void setSql( const QModelIndex &index ) = 0;
void buildQuery();

};

/************************************************************************
Expand Down
11 changes: 0 additions & 11 deletions src/gui/providers/ogr/qgsogrdbsourceselect.cpp
Expand Up @@ -58,17 +58,11 @@ QgsOgrDbSourceSelect::QgsOgrDbSourceSelect( const QString &theSettingsKey, const
btnSave->hide();
btnLoad->hide();

mBuildQueryButton = new QPushButton( tr( "&Set Filter" ) );
connect( mBuildQueryButton, &QAbstractButton::clicked, this, &QgsOgrDbSourceSelect::buildQuery );
mBuildQueryButton->setEnabled( false );

if ( widgetMode() != QgsProviderRegistry::WidgetMode::None )
{
mHoldDialogOpen->hide();
}

buttonBox->addButton( mBuildQueryButton, QDialogButtonBox::ActionRole );

populateConnectionList();

mTableModel = new QgsOgrDbTableModel( this );
Expand All @@ -92,11 +86,6 @@ void QgsOgrDbSourceSelect::cmbConnections_activated( int )
dbChanged();
}

void QgsOgrDbSourceSelect::buildQuery()
{
setSql( mTablesTreeView->currentIndex() );
}


void QgsOgrDbSourceSelect::cbxAllowGeometrylessTables_stateChanged( int )
{
Expand Down
6 changes: 2 additions & 4 deletions src/gui/providers/ogr/qgsogrdbsourceselect.h
Expand Up @@ -82,13 +82,11 @@ class QgsOgrDbSourceSelect: public QgsDbSourceSelectBase
* Once connected, available layers are displayed.
*/
void btnConnect_clicked();
void buildQuery();
//! Opens the create connection dialog to build a new connection
void btnNew_clicked();
//! Deletes the selected connection
void btnDelete_clicked();
void cbxAllowGeometrylessTables_stateChanged( int );
void setSql( const QModelIndex &index );
void cmbConnections_activated( int );
void mTablesTreeView_doubleClicked( const QModelIndex &index );
void treeWidgetSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
Expand All @@ -97,9 +95,9 @@ class QgsOgrDbSourceSelect: public QgsDbSourceSelectBase

void showHelp();

private slots:
protected slots:
void treeviewClicked( const QModelIndex &index ) override;

void setSql( const QModelIndex &index ) override;

private:
void setConnectionListPosition();
Expand Down
10 changes: 10 additions & 0 deletions src/gui/providers/qgsdbsourceselectbase.cpp
Expand Up @@ -39,6 +39,12 @@ QgsDbSourceSelectBase::QgsDbSourceSelectBase( QWidget *parent, Qt::WindowFlags f
mTablesTreeView->setSortingEnabled( true );
mTablesTreeView->setUniformRowHeights( true );
mTablesTreeView->setEditTriggers( QAbstractItemView::CurrentChanged );

mBuildQueryButton = new QPushButton( tr( "&Set Filter" ) );
mBuildQueryButton->setToolTip( tr( "Set Filter" ) );
mBuildQueryButton->setDisabled( true );
buttonBox->addButton( mBuildQueryButton, QDialogButtonBox::ActionRole );
connect( mBuildQueryButton, &QAbstractButton::clicked, this, &QgsDbSourceSelectBase::buildQuery );
}

void QgsDbSourceSelectBase::init( QgsAbstractDbTableModel *model, QItemDelegate *delegate )
Expand Down Expand Up @@ -100,7 +106,11 @@ void QgsDbSourceSelectBase::init( QgsAbstractDbTableModel *model, QItemDelegate
void QgsDbSourceSelectBase::treeviewClicked( const QModelIndex &index )
{
mBuildQueryButton->setEnabled( index.parent().isValid() );
}

void QgsDbSourceSelectBase::buildQuery()
{
setSql( mTablesTreeView->currentIndex() );
}


Expand Down
5 changes: 4 additions & 1 deletion src/gui/providers/qgsdbsourceselectbase.h
Expand Up @@ -44,8 +44,10 @@ class GUI_EXPORT QgsDbSourceSelectBase : public QgsAbstractDataSourceWidget, pro
//! Returns the proxy model used to filter the results
QSortFilterProxyModel *proxyModel() {return mProxyModel;}

private slots:
protected slots:
virtual void treeviewClicked( const QModelIndex &index );
virtual void setSql( const QModelIndex &index ) = 0;
void buildQuery();

private:
void filterResults();
Expand All @@ -58,6 +60,7 @@ class GUI_EXPORT QgsDbSourceSelectBase : public QgsAbstractDataSourceWidget, pro
QAction *mSearchModeWildCardAction = nullptr;
QAction *mSearchModeRegexAction = nullptr;

QPushButton *mBuildQueryButton = nullptr;
};

#endif // QGSDBSOURCESELECTBASE_H
15 changes: 0 additions & 15 deletions src/providers/db2/qgsdb2sourceselect.cpp
Expand Up @@ -146,16 +146,6 @@ QgsDb2SourceSelect::QgsDb2SourceSelect( QWidget *parent, Qt::WindowFlags fl, Qgs
mHoldDialogOpen->hide();
}

mBuildQueryButton = new QPushButton( tr( "&Set Filter" ) );
mBuildQueryButton->setToolTip( tr( "Set Filter" ) );
mBuildQueryButton->setDisabled( true );

if ( widgetMode() != QgsProviderRegistry::WidgetMode::Manager )
{
buttonBox->addButton( mBuildQueryButton, QDialogButtonBox::ActionRole );
connect( mBuildQueryButton, &QAbstractButton::clicked, this, &QgsDb2SourceSelect::buildQuery );
}

populateConnectionList();

mTableModel = new QgsDb2TableModel( this );
Expand Down Expand Up @@ -264,11 +254,6 @@ void QgsDb2SourceSelect::cbxAllowGeometrylessTables_stateChanged( int )
btnConnect_clicked();
}

void QgsDb2SourceSelect::buildQuery()
{
setSql( mTablesTreeView->currentIndex() );
}

void QgsDb2SourceSelect::refresh()
{
populateConnectionList();
Expand Down
8 changes: 3 additions & 5 deletions src/providers/db2/qgsdb2sourceselect.h
Expand Up @@ -32,7 +32,6 @@
#include <QItemDelegate>
#include <QThread>

class QPushButton;
class QStringList;
class QgisApp;

Expand Down Expand Up @@ -114,7 +113,6 @@ class QgsDb2SourceSelect : public QgsDbSourceSelectBase
public slots:
//! Determines the tables the user selected and closes the dialog
void addButtonClicked() override;
void buildQuery();
//! Triggered when the provider's connections need to be refreshed
void refresh() override;

Expand All @@ -134,7 +132,6 @@ class QgsDb2SourceSelect : public QgsDbSourceSelectBase
void btnSave_clicked();
//! Loads the selected connections from file
void btnLoad_clicked();
void setSql( const QModelIndex &index );
//! Store the selected database
void cmbConnections_activated( int );
void setLayerType( const QgsDb2LayerProperty &layerProperty );
Expand All @@ -145,6 +142,9 @@ class QgsDb2SourceSelect : public QgsDbSourceSelectBase

void columnThreadFinished();

protected slots:
void setSql( const QModelIndex &index ) override;

private:
typedef QPair<QString, QString> geomPair;
typedef QList<geomPair> geomCol;
Expand All @@ -171,8 +171,6 @@ class QgsDb2SourceSelect : public QgsDbSourceSelectBase
//! Model that acts as datasource for mTableTreeWidget
QgsDb2TableModel *mTableModel = nullptr;

QPushButton *mBuildQueryButton = nullptr;

void finishList();

void showHelp();
Expand Down
15 changes: 0 additions & 15 deletions src/providers/hana/qgshanasourceselect.cpp
Expand Up @@ -222,16 +222,6 @@ QgsHanaSourceSelect::QgsHanaSourceSelect(
else
setWindowTitle( tr( "Add SAP HANA Table(s)" ) );

mBuildQueryButton = new QPushButton( tr( "&Set Filter" ) );
mBuildQueryButton->setToolTip( tr( "Set Filter" ) );
mBuildQueryButton->setDisabled( true );

if ( widgetMode() != QgsProviderRegistry::WidgetMode::Manager )
{
buttonBox->addButton( mBuildQueryButton, QDialogButtonBox::ActionRole );
connect( mBuildQueryButton, &QAbstractButton::clicked, this, &QgsHanaSourceSelect::buildQuery );
}

populateConnectionList();

mTableModel = new QgsHanaTableModel( this );
Expand Down Expand Up @@ -338,11 +328,6 @@ void QgsHanaSourceSelect::cbxAllowGeometrylessTables_stateChanged( int )
btnConnect_clicked();
}

void QgsHanaSourceSelect::buildQuery()
{
setSql( mTablesTreeView->currentIndex() );
}

void QgsHanaSourceSelect::mTablesTreeView_doubleClicked( const QModelIndex &index )
{
const QgsSettings settings;
Expand Down
8 changes: 3 additions & 5 deletions src/providers/hana/qgshanasourceselect.h
Expand Up @@ -31,7 +31,6 @@
#include <QItemDelegate>
#include <QString>

class QPushButton;
class QgsProxyProgressTask;
class QStringList;
class QgisApp;
Expand Down Expand Up @@ -94,7 +93,6 @@ class QgsHanaSourceSelect : public QgsDbSourceSelectBase

//! Determines the tables the user selected and closes the dialog
void addButtonClicked() override;
void buildQuery();

/**
* Connects to the database using the stored connection parameters.
Expand All @@ -112,7 +110,6 @@ class QgsHanaSourceSelect : public QgsDbSourceSelectBase
void btnSave_clicked();
//! Loads the selected connections from file
void btnLoad_clicked();
void setSql( const QModelIndex &index );
//! Store the selected database
void cmbConnections_activated( int );
void setLayerType( const QgsHanaLayerProperty &layerProperty );
Expand All @@ -123,6 +120,9 @@ class QgsHanaSourceSelect : public QgsDbSourceSelectBase

void columnThreadFinished();

protected slots:
void setSql( const QModelIndex &index ) override;

private:
// Set the position of the database connection list to the last
// used one.
Expand All @@ -145,8 +145,6 @@ class QgsHanaSourceSelect : public QgsDbSourceSelectBase
QStringList mSelectedTables;
//! Model that acts as datasource for mTableTreeWidget
QgsHanaTableModel *mTableModel = nullptr;

QPushButton *mBuildQueryButton = nullptr;
};

#endif // QGSHANASOURCESELECT_H
16 changes: 0 additions & 16 deletions src/providers/mssql/qgsmssqlsourceselect.cpp
Expand Up @@ -150,17 +150,6 @@ QgsMssqlSourceSelect::QgsMssqlSourceSelect( QWidget *parent, Qt::WindowFlags fl,
setWindowTitle( tr( "Add MSSQL Table(s)" ) );
}

mBuildQueryButton = new QPushButton( tr( "&Set Filter" ) );
mBuildQueryButton->setToolTip( tr( "Set Filter" ) );
mBuildQueryButton->setDisabled( true );

if ( widgetMode() != QgsProviderRegistry::WidgetMode::Manager )
{

buttonBox->addButton( mBuildQueryButton, QDialogButtonBox::ActionRole );
connect( mBuildQueryButton, &QAbstractButton::clicked, this, &QgsMssqlSourceSelect::buildQuery );
}

populateConnectionList();

mTableModel = new QgsMssqlTableModel( this );
Expand Down Expand Up @@ -267,11 +256,6 @@ void QgsMssqlSourceSelect::cbxAllowGeometrylessTables_stateChanged( int )
btnConnect_clicked();
}

void QgsMssqlSourceSelect::buildQuery()
{
setSql( mTablesTreeView->currentIndex() );
}

void QgsMssqlSourceSelect::mTablesTreeView_doubleClicked( const QModelIndex & )
{
addButtonClicked();
Expand Down
5 changes: 3 additions & 2 deletions src/providers/mssql/qgsmssqlsourceselect.h
Expand Up @@ -89,7 +89,6 @@ class QgsMssqlSourceSelect : public QgsDbSourceSelectBase

//! Determines the tables the user selected and closes the dialog
void addButtonClicked() override;
void buildQuery();

/**
* Connects to the database using the stored connection parameters.
Expand All @@ -107,7 +106,6 @@ class QgsMssqlSourceSelect : public QgsDbSourceSelectBase
void btnSave_clicked();
//! Loads the selected connections from file
void btnLoad_clicked();
void setSql( const QModelIndex &index );
//! Store the selected database
void cmbConnections_activated( int );
void setLayerType( const QgsMssqlLayerProperty &layerProperty );
Expand All @@ -118,6 +116,9 @@ class QgsMssqlSourceSelect : public QgsDbSourceSelectBase

void columnThreadFinished();

protected slots:
void setSql( const QModelIndex &index ) override;


private:
typedef QPair<QString, QString> geomPair;
Expand Down
15 changes: 0 additions & 15 deletions src/providers/oracle/qgsoraclesourceselect.cpp
Expand Up @@ -188,16 +188,6 @@ QgsOracleSourceSelect::QgsOracleSourceSelect( QWidget *parent, Qt::WindowFlags f
setWindowTitle( tr( "Add Oracle Table(s)" ) );
}

mBuildQueryButton = new QPushButton( tr( "&Set Filter" ) );
mBuildQueryButton->setToolTip( tr( "Set Filter" ) );
mBuildQueryButton->setDisabled( true );

if ( widgetMode() != QgsProviderRegistry::WidgetMode::Manager )
{
buttonBox->addButton( mBuildQueryButton, QDialogButtonBox::ActionRole );
connect( mBuildQueryButton, &QAbstractButton::clicked, this, &QgsOracleSourceSelect::buildQuery );
}

mTablesTreeDelegate = new QgsOracleSourceSelectDelegate( this );


Expand Down Expand Up @@ -308,11 +298,6 @@ void QgsOracleSourceSelect::on_cbxAllowGeometrylessTables_stateChanged( int )
on_btnConnect_clicked();
}

void QgsOracleSourceSelect::buildQuery()
{
setSql( mTablesTreeView->currentIndex() );
}

void QgsOracleSourceSelect::on_mTablesTreeView_doubleClicked( const QModelIndex & )
{
addButtonClicked();
Expand Down
5 changes: 3 additions & 2 deletions src/providers/oracle/qgsoraclesourceselect.h
Expand Up @@ -96,7 +96,6 @@ class QgsOracleSourceSelect : public QgsDbSourceSelectBase
public slots:
//! Determines the tables the user selected and closes the dialog
void addButtonClicked() override;
void buildQuery();

/**
* Connects to the database using the stored connection parameters.
Expand All @@ -115,7 +114,6 @@ class QgsOracleSourceSelect : public QgsDbSourceSelectBase
//! Loads the selected connections from file
void on_btnLoad_clicked();
void on_cmbConnections_currentIndexChanged( const QString &text );
void setSql( const QModelIndex &index );
//! Store the selected database
void setLayerType( const QgsOracleLayerProperty &layerProperty );
void on_mTablesTreeView_doubleClicked( const QModelIndex &index );
Expand All @@ -125,6 +123,9 @@ class QgsOracleSourceSelect : public QgsDbSourceSelectBase

void columnTaskFinished();

protected slots:
void setSql( const QModelIndex &index ) override;

private:
typedef QPair<QString, QString> geomPair;
typedef QList<geomPair> geomCol;
Expand Down
15 changes: 0 additions & 15 deletions src/providers/postgres/qgspgsourceselect.cpp
Expand Up @@ -240,16 +240,6 @@ QgsPgSourceSelect::QgsPgSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsPr
setWindowTitle( tr( "Add PostGIS Table(s)" ) );
}

mBuildQueryButton = new QPushButton( tr( "&Set Filter" ) );
mBuildQueryButton->setToolTip( tr( "Set Filter" ) );
mBuildQueryButton->setDisabled( true );

if ( widgetMode() != QgsProviderRegistry::WidgetMode::Manager )
{
buttonBox->addButton( mBuildQueryButton, QDialogButtonBox::ActionRole );
connect( mBuildQueryButton, &QAbstractButton::clicked, this, &QgsPgSourceSelect::buildQuery );
}

populateConnectionList();


Expand Down Expand Up @@ -347,11 +337,6 @@ void QgsPgSourceSelect::cbxAllowGeometrylessTables_stateChanged( int )
btnConnect_clicked();
}

void QgsPgSourceSelect::buildQuery()
{
setSql( mTablesTreeView->currentIndex() );
}

void QgsPgSourceSelect::mTablesTreeView_doubleClicked( const QModelIndex & )
{
addButtonClicked();
Expand Down

0 comments on commit 67bcb31

Please sign in to comment.