Skip to content
Permalink
Browse files
a bit more of code duplication removal in provider GUIs
  • Loading branch information
3nids committed Nov 11, 2021
1 parent d2bb874 commit f7fc805b2f9147ad77acdcaab63ca1504d16e193
@@ -28,9 +28,9 @@ Constructor
%End

protected:
void setSourceModel( QgsAbstractDbTableModel *model );
void setSourceModel( QgsAbstractDbTableModel *model, QItemDelegate *delegate = 0 );
%Docstring
Sets the source model for the widget
Sets the source model for the table and optionally a delegate
%End

QSortFilterProxyModel *proxyModel();
@@ -75,9 +75,6 @@ QgsOgrDbSourceSelect::QgsOgrDbSourceSelect( const QString &theSettingsKey, const
mTableModel = new QgsOgrDbTableModel( this );
setSourceModel( mTableModel );

mTablesTreeView->setModel( proxyModel() );
mTablesTreeView->setSortingEnabled( true );

connect( mTablesTreeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &QgsOgrDbSourceSelect::treeWidgetSelectionChanged );

cbxAllowGeometrylessTables->setDisabled( true );
@@ -18,6 +18,7 @@

#include <QMenu>
#include <QSortFilterProxyModel>
#include <QItemDelegate>

QgsDbSourceSelectBase::QgsDbSourceSelectBase( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
: QgsAbstractDataSourceWidget( parent, fl, widgetMode )
@@ -35,11 +36,18 @@ QgsDbSourceSelectBase::QgsDbSourceSelectBase( QWidget *parent, Qt::WindowFlags f
// The list gets sorted in finishList() method when the listing of tables and views has finished.
mProxyModel->setDynamicSortFilter( false );


mTablesTreeView->setSortingEnabled( true );
mTablesTreeView->setUniformRowHeights( true );
mTablesTreeView->setEditTriggers( QAbstractItemView::CurrentChanged );
}

void QgsDbSourceSelectBase::setSourceModel( QgsAbstractDbTableModel *model )
void QgsDbSourceSelectBase::setSourceModel( QgsAbstractDbTableModel *model, QItemDelegate *delegate )
{
mProxyModel->setSourceModel( model );
mTablesTreeView->setModel( mProxyModel );
mTablesTreeView->setItemDelegate( delegate );


// setting the search coluns in search settings menu using the model header data

@@ -23,6 +23,7 @@

class QSortFilterProxyModel;
class QgsAbstractDbTableModel;
class QItemDelegate;

/**
* \ingroup gui
@@ -37,8 +38,8 @@ class GUI_EXPORT QgsDbSourceSelectBase : public QgsAbstractDataSourceWidget, pro
QgsDbSourceSelectBase( QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );

protected:
//! Sets the source model for the widget
void setSourceModel( QgsAbstractDbTableModel *model );
//! Sets the source model for the table and optionally a delegate
void setSourceModel( QgsAbstractDbTableModel *model, QItemDelegate *delegate = nullptr );

//! Returns the proxy model used to filter the results
QSortFilterProxyModel *proxyModel() {return mProxyModel;}
@@ -160,12 +160,7 @@ QgsDb2SourceSelect::QgsDb2SourceSelect( QWidget *parent, Qt::WindowFlags fl, Qgs
populateConnectionList();

mTableModel = new QgsDb2TableModel( this );
setSourceModel( mTableModel );

mTablesTreeView->setModel( proxyModel() );
mTablesTreeView->setSortingEnabled( true );
mTablesTreeView->setEditTriggers( QAbstractItemView::CurrentChanged );
mTablesTreeView->setItemDelegate( new QgsDb2SourceSelectDelegate( this ) );
setSourceModel( mTableModel, new QgsDb2SourceSelectDelegate( this ) );

connect( mTablesTreeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &QgsDb2SourceSelect::treeWidgetSelectionChanged );

@@ -236,12 +236,7 @@ QgsHanaSourceSelect::QgsHanaSourceSelect(
populateConnectionList();

mTableModel = new QgsHanaTableModel( this );
setSourceModel( mTableModel );

mTablesTreeView->setModel( proxyModel() );
mTablesTreeView->setSortingEnabled( true );
mTablesTreeView->setEditTriggers( QAbstractItemView::CurrentChanged );
mTablesTreeView->setItemDelegate( new QgsHanaSourceSelectDelegate( this ) );
setSourceModel( mTableModel, new QgsHanaSourceSelectDelegate( this ) );

connect( mTablesTreeView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsHanaSourceSelect::treeWidgetSelectionChanged );
@@ -165,12 +165,7 @@ QgsMssqlSourceSelect::QgsMssqlSourceSelect( QWidget *parent, Qt::WindowFlags fl,
populateConnectionList();

mTableModel = new QgsMssqlTableModel( this );
setSourceModel( mTableModel );

mTablesTreeView->setModel( proxyModel() );
mTablesTreeView->setSortingEnabled( true );
mTablesTreeView->setEditTriggers( QAbstractItemView::CurrentChanged );
mTablesTreeView->setItemDelegate( new QgsMssqlSourceSelectDelegate( this ) );
setSourceModel( mTableModel, new QgsMssqlSourceSelectDelegate( this ) );

connect( mTablesTreeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &QgsMssqlSourceSelect::treeWidgetSelectionChanged );

@@ -202,12 +202,7 @@ QgsOracleSourceSelect::QgsOracleSourceSelect( QWidget *parent, Qt::WindowFlags f


mTableModel = new QgsOracleTableModel( this );
setSourceModel( mTableModel );

mTablesTreeView->setModel( proxyModel() );
mTablesTreeView->setSortingEnabled( true );
mTablesTreeView->setEditTriggers( QAbstractItemView::CurrentChanged );
mTablesTreeView->setItemDelegate( mTablesTreeDelegate );
setSourceModel( mTableModel, mTablesTreeDelegate );

connect( mTablesTreeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &QgsOracleSourceSelect::treeWidgetSelectionChanged );

@@ -255,13 +255,7 @@ QgsPgSourceSelect::QgsPgSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsPr


mTableModel = new QgsPgTableModel( this );
setSourceModel( mTableModel );

mTablesTreeView->setModel( proxyModel() );
mTablesTreeView->setSortingEnabled( true );
mTablesTreeView->setUniformRowHeights( true );
mTablesTreeView->setEditTriggers( QAbstractItemView::CurrentChanged );
mTablesTreeView->setItemDelegate( new QgsPgSourceSelectDelegate( this ) );
setSourceModel( mTableModel, new QgsPgSourceSelectDelegate( this ) );

connect( mTablesTreeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &QgsPgSourceSelect::treeWidgetSelectionChanged );

@@ -90,9 +90,6 @@ QgsSpatiaLiteSourceSelect::QgsSpatiaLiteSourceSelect( QWidget *parent, Qt::Windo
mTableModel = new QgsSpatiaLiteTableModel( this );
setSourceModel( mTableModel );

mTablesTreeView->setModel( proxyModel() );
mTablesTreeView->setSortingEnabled( true );

connect( mTablesTreeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &QgsSpatiaLiteSourceSelect::treeWidgetSelectionChanged );

cbxAllowGeometrylessTables->setDisabled( true );

0 comments on commit f7fc805

Please sign in to comment.