Skip to content
Permalink
Browse files
regroup query button creation
  • Loading branch information
3nids committed Nov 11, 2021
1 parent 0f39b82 commit 67bcb31226a696a4b30cc952f4caae6770ed5be1
@@ -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();

};

/************************************************************************
@@ -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 );
@@ -92,11 +86,6 @@ void QgsOgrDbSourceSelect::cmbConnections_activated( int )
dbChanged();
}

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


void QgsOgrDbSourceSelect::cbxAllowGeometrylessTables_stateChanged( int )
{
@@ -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 );
@@ -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();
@@ -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 )
@@ -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() );
}


@@ -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();
@@ -58,6 +60,7 @@ class GUI_EXPORT QgsDbSourceSelectBase : public QgsAbstractDataSourceWidget, pro
QAction *mSearchModeWildCardAction = nullptr;
QAction *mSearchModeRegexAction = nullptr;

QPushButton *mBuildQueryButton = nullptr;
};

#endif // QGSDBSOURCESELECTBASE_H
@@ -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 );
@@ -264,11 +254,6 @@ void QgsDb2SourceSelect::cbxAllowGeometrylessTables_stateChanged( int )
btnConnect_clicked();
}

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

void QgsDb2SourceSelect::refresh()
{
populateConnectionList();
@@ -32,7 +32,6 @@
#include <QItemDelegate>
#include <QThread>

class QPushButton;
class QStringList;
class QgisApp;

@@ -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;

@@ -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 );
@@ -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;
@@ -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();
@@ -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 );
@@ -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;
@@ -31,7 +31,6 @@
#include <QItemDelegate>
#include <QString>

class QPushButton;
class QgsProxyProgressTask;
class QStringList;
class QgisApp;
@@ -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.
@@ -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 );
@@ -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.
@@ -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
@@ -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 );
@@ -267,11 +256,6 @@ void QgsMssqlSourceSelect::cbxAllowGeometrylessTables_stateChanged( int )
btnConnect_clicked();
}

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

void QgsMssqlSourceSelect::mTablesTreeView_doubleClicked( const QModelIndex & )
{
addButtonClicked();
@@ -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.
@@ -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 );
@@ -118,6 +116,9 @@ class QgsMssqlSourceSelect : public QgsDbSourceSelectBase

void columnThreadFinished();

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


private:
typedef QPair<QString, QString> geomPair;
@@ -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 );


@@ -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();
@@ -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.
@@ -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 );
@@ -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;
@@ -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();


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

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

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

0 comments on commit 67bcb31

Please sign in to comment.