Skip to content
Permalink
Browse files
refactor ogr provider gui with enhanced filtering UX
  • Loading branch information
3nids committed Nov 9, 2021
1 parent ae0f070 commit ee19074b98cb709cc39dadf4e264cd3656965ded
@@ -43,10 +43,6 @@ QgsOgrDbSourceSelect::QgsOgrDbSourceSelect( const QString &theSettingsKey, const
connect( btnConnect, &QPushButton::clicked, this, &QgsOgrDbSourceSelect::btnConnect_clicked );
connect( btnNew, &QPushButton::clicked, this, &QgsOgrDbSourceSelect::btnNew_clicked );
connect( btnDelete, &QPushButton::clicked, this, &QgsOgrDbSourceSelect::btnDelete_clicked );
connect( mSearchGroupBox, &QGroupBox::toggled, this, &QgsOgrDbSourceSelect::mSearchGroupBox_toggled );
connect( mSearchTableEdit, &QLineEdit::textChanged, this, &QgsOgrDbSourceSelect::mSearchTableEdit_textChanged );
connect( mSearchColumnComboBox, &QComboBox::currentTextChanged, this, &QgsOgrDbSourceSelect::mSearchColumnComboBox_currentIndexChanged );
connect( mSearchModeComboBox, &QComboBox::currentTextChanged, this, &QgsOgrDbSourceSelect::mSearchModeComboBox_currentIndexChanged );
connect( cbxAllowGeometrylessTables, &QCheckBox::stateChanged, this, &QgsOgrDbSourceSelect::cbxAllowGeometrylessTables_stateChanged );
connect( cmbConnections, static_cast<void ( QComboBox::* )( int )>( &QComboBox::activated ), this, &QgsOgrDbSourceSelect::cmbConnections_activated );
connect( mTablesTreeView, &QTreeView::clicked, this, &QgsOgrDbSourceSelect::mTablesTreeView_clicked );
@@ -75,15 +71,6 @@ QgsOgrDbSourceSelect::QgsOgrDbSourceSelect( const QString &theSettingsKey, const

populateConnectionList();

mSearchModeComboBox->addItem( tr( "Wildcard" ) );
mSearchModeComboBox->addItem( tr( "RegExp" ) );

mSearchColumnComboBox->addItem( tr( "All" ) );
mSearchColumnComboBox->addItem( tr( "Table" ) );
mSearchColumnComboBox->addItem( tr( "Type" ) );
mSearchColumnComboBox->addItem( tr( "Geometry column" ) );
mSearchColumnComboBox->addItem( tr( "Sql" ) );

mProxyModel.setParent( this );
mProxyModel.setFilterKeyColumn( -1 );
mProxyModel.setFilterCaseSensitivity( Qt::CaseInsensitive );
@@ -94,20 +81,6 @@ QgsOgrDbSourceSelect::QgsOgrDbSourceSelect( const QString &theSettingsKey, const

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

//for Qt < 4.3.2, passing -1 to include all model columns
//in search does not seem to work
mSearchColumnComboBox->setCurrentIndex( 1 );

//hide the search options by default
//they will be shown when the user ticks
//the search options group box
mSearchLabel->setVisible( false );
mSearchColumnComboBox->setVisible( false );
mSearchColumnsLabel->setVisible( false );
mSearchModeComboBox->setVisible( false );
mSearchModeLabel->setVisible( false );
mSearchTableEdit->setVisible( false );

cbxAllowGeometrylessTables->setDisabled( true );
}

@@ -145,56 +118,6 @@ void QgsOgrDbSourceSelect::mTablesTreeView_doubleClicked( const QModelIndex &ind
setSql( index );
}

void QgsOgrDbSourceSelect::mSearchGroupBox_toggled( bool checked )
{
if ( mSearchTableEdit->text().isEmpty() )
return;

mSearchTableEdit_textChanged( checked ? mSearchTableEdit->text() : QString() );
}

void QgsOgrDbSourceSelect::mSearchTableEdit_textChanged( const QString &text )
{
if ( mSearchModeComboBox->currentText() == tr( "Wildcard" ) )
{
mProxyModel._setFilterWildcard( text );
}
else if ( mSearchModeComboBox->currentText() == tr( "RegExp" ) )
{
mProxyModel._setFilterRegExp( text );
}
}

void QgsOgrDbSourceSelect::mSearchColumnComboBox_currentIndexChanged( const QString &text )
{
if ( text == tr( "All" ) )
{
mProxyModel.setFilterKeyColumn( -1 );
}
else if ( text == tr( "Table" ) )
{
mProxyModel.setFilterKeyColumn( 0 );
}
else if ( text == tr( "Type" ) )
{
mProxyModel.setFilterKeyColumn( 1 );
}
else if ( text == tr( "Geometry column" ) )
{
mProxyModel.setFilterKeyColumn( 2 );
}
else if ( text == tr( "Sql" ) )
{
mProxyModel.setFilterKeyColumn( 3 );
}
}

void QgsOgrDbSourceSelect::mSearchModeComboBox_currentIndexChanged( const QString &text )
{
Q_UNUSED( text )
mSearchTableEdit_textChanged( mSearchTableEdit->text() );
}

void QgsOgrDbSourceSelect::populateConnectionList()
{
cmbConnections->clear();
@@ -86,10 +86,6 @@ class QgsOgrDbSourceSelect: public QgsAbstractDataSourceWidget, private Ui::QgsD
void btnNew_clicked();
//! Deletes the selected connection
void btnDelete_clicked();
void mSearchGroupBox_toggled( bool );
void mSearchTableEdit_textChanged( const QString &text );
void mSearchColumnComboBox_currentIndexChanged( const QString &text );
void mSearchModeComboBox_currentIndexChanged( const QString &text );
void cbxAllowGeometrylessTables_stateChanged( int );
void setSql( const QModelIndex &index );
void cmbConnections_activated( int );
@@ -20,14 +20,30 @@

#include <QIcon>

QgsOgrDbTableModel::QgsOgrDbTableModel()
QgsOgrDbTableModel::QgsOgrDbTableModel( QObject *parent )
: QgsAbstractDbTableModel( parent )
{
QStringList headerLabels;
headerLabels << tr( "Table" );
headerLabels << tr( "Type" );
headerLabels << tr( "Geometry column" );
headerLabels << tr( "Sql" );
setHorizontalHeaderLabels( headerLabels );
mColumns << tr( "Table" )
<< tr( "Type" )
<< tr( "Geometry column" )
<< tr( "Sql" );
setHorizontalHeaderLabels( columns() );
}

QStringList QgsOgrDbTableModel::columns() const
{
return mColumns;
}

int QgsOgrDbTableModel::defaultSearchColumn() const
{
return 0;
}

bool QgsOgrDbTableModel::searchableColumn( int column ) const
{
Q_UNUSED( column )
return true;
}

void QgsOgrDbTableModel::addTableEntry( const Qgis::BrowserLayerType &layerType, const QString &tableName, const QString &uri, const QString &geometryColName, const QString &geometryType, const QString &sql )
@@ -18,22 +18,26 @@

#include "qgis.h"

#include <QObject>
#include <QStandardItemModel>
#include <type_traits>
#include "qgslayeritem.h"
#include "qgis_sip.h"
#include "qgsabstractdbtablemodel.h"


///@cond PRIVATE
#define SIP_NO_FILE

class QgsOgrDbTableModel : public QStandardItemModel
class QgsOgrDbTableModel : public QgsAbstractDbTableModel
{
Q_OBJECT

public:

QgsOgrDbTableModel();
QgsOgrDbTableModel( QObject *parent = nullptr );

QStringList columns() const override;
int defaultSearchColumn() const override;
bool searchableColumn( int column ) const override;

//! Sets the geometry type for the table
void setGeometryTypesForTable( const QString &table, const QString &attribute, const QString &type );
@@ -60,6 +64,7 @@ class QgsOgrDbTableModel : public QStandardItemModel
//! Number of tables in the model
int mTableCount = 0;
QString mPath;
QStringList mColumns;

QIcon iconForType( QgsWkbTypes::Type type ) const;
QString displayStringForType( QgsWkbTypes::Type type ) const;

0 comments on commit ee19074

Please sign in to comment.