Skip to content
Permalink
Browse files
refactor hana provider gui with enhanced filtering UX
  • Loading branch information
3nids committed Nov 9, 2021
1 parent ee19074 commit ac998ab6d66fd81fa071850caae373b3aed375b8
Showing with 72 additions and 124 deletions.
  1. +14 −95 src/providers/hana/qgshanasourceselect.cpp
  2. +4 −11 src/providers/hana/qgshanasourceselect.h
  3. +44 −13 src/providers/hana/qgshanatablemodel.cpp
  4. +10 −5 src/providers/hana/qgshanatablemodel.h
@@ -210,10 +210,6 @@ QgsHanaSourceSelect::QgsHanaSourceSelect(
connect( btnDelete, &QPushButton::clicked, this, &QgsHanaSourceSelect::btnDelete_clicked );
connect( btnSave, &QPushButton::clicked, this, &QgsHanaSourceSelect::btnSave_clicked );
connect( btnLoad, &QPushButton::clicked, this, &QgsHanaSourceSelect::btnLoad_clicked );
connect( mSearchGroupBox, &QGroupBox::toggled, this, &QgsHanaSourceSelect::mSearchGroupBox_toggled );
connect( mSearchTableEdit, &QLineEdit::textChanged, this, &QgsHanaSourceSelect::mSearchTableEdit_textChanged );
connect( mSearchColumnComboBox, &QComboBox::currentTextChanged, this, &QgsHanaSourceSelect::mSearchColumnComboBox_currentTextChanged );
connect( mSearchModeComboBox, &QComboBox::currentTextChanged, this, &QgsHanaSourceSelect::mSearchModeComboBox_currentTextChanged );
connect( cmbConnections, static_cast<void ( QComboBox::* )( int )>( &QComboBox::activated ),
this, &QgsHanaSourceSelect::cmbConnections_activated );
connect( mTablesTreeView, &QTreeView::clicked, this, &QgsHanaSourceSelect::mTablesTreeView_clicked );
@@ -238,25 +234,10 @@ QgsHanaSourceSelect::QgsHanaSourceSelect(

populateConnectionList();

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

mSearchColumnComboBox->addItem( tr( "All" ) );
mSearchColumnComboBox->addItem( tr( "Schema" ) );
mSearchColumnComboBox->addItem( tr( "Table" ) );
mSearchColumnComboBox->addItem( tr( "Comment" ) );
mSearchColumnComboBox->addItem( tr( "Geometry column" ) );
mSearchColumnComboBox->addItem( tr( "Type" ) );
mSearchColumnComboBox->addItem( tr( "Feature id" ) );
mSearchColumnComboBox->addItem( tr( "SRID" ) );
mSearchColumnComboBox->addItem( tr( "Sql" ) );

mProxyModel.setParent( this );
mProxyModel.setFilterKeyColumn( -1 );
mProxyModel.setFilterCaseSensitivity( Qt::CaseInsensitive );
mProxyModel.setSourceModel( &mTableModel );

mTablesTreeView->setModel( &mProxyModel );
mTableModel = new QgsHanaTableModel( this );
setSourceModel( mTableModel );

mTablesTreeView->setModel( proxyModel() );
mTablesTreeView->setSortingEnabled( true );
mTablesTreeView->setEditTriggers( QAbstractItemView::CurrentChanged );
mTablesTreeView->setItemDelegate( new QgsHanaSourceSelectDelegate( this ) );
@@ -275,7 +256,7 @@ QgsHanaSourceSelect::QgsHanaSourceSelect(
restoreGeometry( settings.value( QStringLiteral( "Windows/HanaSourceSelect/geometry" ) ).toByteArray() );
mHoldDialogOpen->setChecked( settings.value( QStringLiteral( "Windows/HanaSourceSelect/HoldDialogOpen" ), false ).toBool() );

for ( int i = 0; i < mTableModel.columnCount(); i++ )
for ( int i = 0; i < mTableModel->columnCount(); i++ )
{
mTablesTreeView->setColumnWidth( i, settings.value( QStringLiteral( "Windows/HanaSourceSelect/columnWidths/%1" )
.arg( i ), mTablesTreeView->columnWidth( i ) ).toInt() );
@@ -395,71 +376,9 @@ void QgsHanaSourceSelect::mTablesTreeView_doubleClicked( const QModelIndex &inde
setSql( index );
}

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

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

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

void QgsHanaSourceSelect::mSearchColumnComboBox_currentTextChanged( const QString &text )
{
if ( text == tr( "All" ) )
{
mProxyModel.setFilterKeyColumn( -1 );
}
else if ( text == tr( "Schema" ) )
{
mProxyModel.setFilterKeyColumn( QgsHanaTableModel::DbtmSchema );
}
else if ( text == tr( "Table" ) )
{
mProxyModel.setFilterKeyColumn( QgsHanaTableModel::DbtmTable );
}
else if ( text == tr( "Comment" ) )
{
mProxyModel.setFilterKeyColumn( QgsHanaTableModel::DbtmComment );
}
else if ( text == tr( "Geometry column" ) )
{
mProxyModel.setFilterKeyColumn( QgsHanaTableModel::DbtmGeomCol );
}
else if ( text == tr( "Type" ) )
{
mProxyModel.setFilterKeyColumn( QgsHanaTableModel::DbtmGeomType );
}
else if ( text == tr( "Feature id" ) )
{
mProxyModel.setFilterKeyColumn( QgsHanaTableModel::DbtmPkCol );
}
else if ( text == tr( "SRID" ) )
{
mProxyModel.setFilterKeyColumn( QgsHanaTableModel::DbtmSrid );
}
else if ( text == tr( "Sql" ) )
{
mProxyModel.setFilterKeyColumn( QgsHanaTableModel::DbtmSql );
}
}

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

void QgsHanaSourceSelect::setLayerType( const QgsHanaLayerProperty &layerProperty )
{
mTableModel.addTableEntry( mConnectionName, layerProperty );
mTableModel->addTableEntry( mConnectionName, layerProperty );
}

QgsHanaSourceSelect::~QgsHanaSourceSelect()
@@ -475,7 +394,7 @@ QgsHanaSourceSelect::~QgsHanaSourceSelect()
settings.setValue( QStringLiteral( "Windows/HanaSourceSelect/geometry" ), saveGeometry() );
settings.setValue( QStringLiteral( "Windows/HanaSourceSelect/HoldDialogOpen" ), mHoldDialogOpen->isChecked() );

for ( int i = 0; i < mTableModel.columnCount(); i++ )
for ( int i = 0; i < mTableModel->columnCount(); i++ )
{
settings.setValue( QStringLiteral( "Windows/HanaSourceSelect/columnWidths/%1" )
.arg( i ), mTablesTreeView->columnWidth( i ) );
@@ -518,7 +437,7 @@ void QgsHanaSourceSelect::addButtonClicked()
if ( idx.column() != QgsHanaTableModel::DbtmTable )
continue;

const QString uri = mTableModel.layerURI( mProxyModel.mapToSource( idx ), mConnectionName, mConnectionInfo );
const QString uri = mTableModel->layerURI( mProxyModel->mapToSource( idx ), mConnectionName, mConnectionInfo );
if ( uri.isNull() )
continue;

@@ -550,8 +469,8 @@ void QgsHanaSourceSelect::btnConnect_clicked()

const QString connName = cmbConnections->currentText();

const QModelIndex rootItemIndex = mTableModel.indexFromItem( mTableModel.invisibleRootItem() );
mTableModel.removeRows( 0, mTableModel.rowCount( rootItemIndex ), rootItemIndex );
const QModelIndex rootItemIndex = mTableModel->indexFromItem( mTableModel->invisibleRootItem() );
mTableModel->removeRows( 0, mTableModel->rowCount( rootItemIndex ), rootItemIndex );

QgsHanaSettings settings( connName, true );
settings.setAllowGeometrylessTables( cbxAllowGeometrylessTables->isChecked() );
@@ -627,23 +546,23 @@ void QgsHanaSourceSelect::setSql( const QModelIndex &index )
return;
}

const QModelIndex idx = mProxyModel.mapToSource( index );
const QString uri = mTableModel.layerURI( idx, mConnectionName, mConnectionInfo );
const QModelIndex idx = mProxyModel->mapToSource( index );
const QString uri = mTableModel->layerURI( idx, mConnectionName, mConnectionInfo );
if ( uri.isNull() )
{
QgsDebugMsg( "no uri" );
return;
}

const QString tableName = mTableModel.itemFromIndex( idx.sibling( idx.row(), QgsHanaTableModel::DbtmTable ) )->text();
const QString tableName = mTableModel->itemFromIndex( idx.sibling( idx.row(), QgsHanaTableModel::DbtmTable ) )->text();

QgsVectorLayer vlayer( uri, tableName, QStringLiteral( "hana" ) );
if ( !vlayer.isValid() )
return;

QgsQueryBuilder gb( &vlayer, this );
if ( gb.exec() )
mTableModel.setSql( mProxyModel.mapToSource( index ), gb.sql() );
mTableModel->setSql( mProxyModel->mapToSource( index ), gb.sql() );
}

QString QgsHanaSourceSelect::fullDescription(
@@ -17,15 +17,13 @@
#ifndef QGSHANASOURCESELECT_H
#define QGSHANASOURCESELECT_H

#include "qgsabstractdatasourcewidget.h"
#include "qgsdatasourceuri.h"
#include "qgsdbfilterproxymodel.h"
#include "qgshanatablemodel.h"
#include "qgshanacolumntypethread.h"
#include "qgshelp.h"
#include "qgsproviderregistry.h"
#include "qgsguiutils.h"
#include "ui_qgsdbsourceselectbase.h"
#include "qgsdbsourceselectbase.h"


#include <QMap>
#include <QPair>
@@ -66,7 +64,7 @@ class QgsHanaSourceSelectDelegate : public QItemDelegate
* for SAP HANA databases. The user can then connect and add
* tables from the database to the map canvas.
*/
class QgsHanaSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsDbSourceSelectBase
class QgsHanaSourceSelect : public QgsDbSourceSelectBase
{
Q_OBJECT

@@ -114,10 +112,6 @@ class QgsHanaSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsD
void btnSave_clicked();
//! Loads the selected connections from file
void btnLoad_clicked();
void mSearchGroupBox_toggled( bool );
void mSearchTableEdit_textChanged( const QString &text );
void mSearchColumnComboBox_currentTextChanged( const QString &text );
void mSearchModeComboBox_currentTextChanged( const QString &text );
void setSql( const QModelIndex &index );
//! Store the selected database
void cmbConnections_activated( int );
@@ -151,8 +145,7 @@ class QgsHanaSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsD
std::unique_ptr<QgsProxyProgressTask> mColumnTypeTask;
QStringList mSelectedTables;
//! Model that acts as datasource for mTableTreeWidget
QgsHanaTableModel mTableModel;
QgsDatabaseFilterProxyModel mProxyModel;
QgsHanaTableModel *mTableModel = nullptr;

QPushButton *mBuildQueryButton = nullptr;
};
@@ -22,19 +22,50 @@
#include "qgshanautils.h"
#include "qgslogger.h"

QgsHanaTableModel::QgsHanaTableModel()
QgsHanaTableModel::QgsHanaTableModel( QObject *parent )
: QgsAbstractDbTableModel( parent )

{
mColumns << tr( "Schema" )
<< tr( "Table" )
<< tr( "Comment" )
<< tr( "Column" )
<< tr( "Type" )
<< tr( "SRID" )
<< tr( "Feature id" )
<< tr( "Select at id" )
<< tr( "Sql" );
setHorizontalHeaderLabels( mColumns );
}

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

int QgsHanaTableModel::defaultSearchColumn() const
{
return static_cast<int>( DbtmTable );
}

bool QgsHanaTableModel::searchableColumn( int column ) const
{
QStringList headerLabels;
headerLabels << tr( "Schema" );
headerLabels << tr( "Table" );
headerLabels << tr( "Comment" );
headerLabels << tr( "Column" );
headerLabels << tr( "Type" );
headerLabels << tr( "SRID" );
headerLabels << tr( "Feature id" );
headerLabels << tr( "Select at id" );
headerLabels << tr( "Sql" );
setHorizontalHeaderLabels( headerLabels );
Columns col = static_cast<Columns>( column );
switch ( col )
{
case DbtmSchema:
case DbtmTable:
case DbtmComment:
case DbtmGeomCol:
case DbtmSrid:
case DbtmSql:
return true;

case DbtmGeomType:
case DbtmPkCol:
case DbtmSelectAtId:
return false;
}
}

void QgsHanaTableModel::addTableEntry( const QString &connName, const QgsHanaLayerProperty &layerProperty )
@@ -267,7 +298,7 @@ bool QgsHanaTableModel::setData( const QModelIndex &idx, const QVariant &value,
tip = tr( "Select columns in the '%1' column that uniquely identify features of this layer" ).arg( tr( "Feature id" ) );
}

for ( int i = 0; i < DbtmColumns; i++ )
for ( int i = 0; i < columnCount(); i++ )
{
QStandardItem *item = itemFromIndex( idx.sibling( idx.row(), i ) );
if ( tip.isEmpty() )
@@ -19,7 +19,7 @@

#include "qgis.h"
#include "qgswkbtypes.h"
#include <QStandardItemModel>
#include "qgsabstractdbtablemodel.h"

//! Schema properties structure
struct QgsHanaSchemaProperty
@@ -63,11 +63,15 @@ class QIcon;
*
* The tables have the following columns: Type, Schema, Tablename, Geometry Column, Sql
*/
class QgsHanaTableModel : public QStandardItemModel
class QgsHanaTableModel : public QgsAbstractDbTableModel
{
Q_OBJECT
public:
QgsHanaTableModel();
QgsHanaTableModel( QObject *parent = nullptr );

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

//! Adds entry for one database table to the model
void addTableEntry( const QString &connName, const QgsHanaLayerProperty &property );
@@ -88,8 +92,7 @@ class QgsHanaTableModel : public QStandardItemModel
DbtmSrid,
DbtmPkCol,
DbtmSelectAtId,
DbtmSql,
DbtmColumns
DbtmSql
};

bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
@@ -101,6 +104,8 @@ class QgsHanaTableModel : public QStandardItemModel
private:
//! Number of tables in the model
int mTableCount = 0;
QStringList mColumns;

};

#endif // QGSHANATABLEMODEL_H

0 comments on commit ac998ab

Please sign in to comment.