Skip to content
Permalink
Browse files
refactor oracle provider gui with enhanced filtering UX
  • Loading branch information
3nids committed Nov 9, 2021
1 parent ac998ab commit c34f577757e3f2cd68bb4f0729a894cf5e129ca5
@@ -32,6 +32,8 @@ email : jef at norbit dot de
#include "qgsproxyprogresstask.h"
#include "qgsgui.h"
#include "qgsiconutils.h"
#include "qgsoracletablemodel.h"


#include <QFileDialog>
#include <QInputDialog>
@@ -172,7 +174,6 @@ void QgsOracleSourceSelectDelegate::setModelData( QWidget *editor, QAbstractItem
QgsOracleSourceSelect::QgsOracleSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode theWidgetMode )
: QgsAbstractDataSourceWidget( parent, fl, theWidgetMode )
{
setupUi( this );
QgsGui::instance()->enableAutoGeometryRestore( this );
setupButtons( buttonBox );
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsOracleSourceSelect::showHelp );
@@ -196,26 +197,13 @@ QgsOracleSourceSelect::QgsOracleSourceSelect( QWidget *parent, Qt::WindowFlags f
connect( mBuildQueryButton, &QAbstractButton::clicked, this, &QgsOracleSourceSelect::buildQuery );
}

mSearchModeComboBox->addItem( tr( "Wildcard" ) );
mSearchModeComboBox->addItem( tr( "RegExp" ) );
mTablesTreeDelegate = new QgsOracleSourceSelectDelegate( this );

mSearchColumnComboBox->addItem( tr( "All" ) );
mSearchColumnComboBox->addItem( tr( "Owner" ) );
mSearchColumnComboBox->addItem( tr( "Table" ) );
mSearchColumnComboBox->addItem( tr( "Type" ) );
mSearchColumnComboBox->addItem( tr( "Geometry column" ) );
mSearchColumnComboBox->addItem( tr( "Primary key column" ) );
mSearchColumnComboBox->addItem( tr( "SRID" ) );
mSearchColumnComboBox->addItem( tr( "Sql" ) );

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

mTablesTreeDelegate = new QgsOracleSourceSelectDelegate( this );

mTablesTreeView->setModel( &mProxyModel );
mTablesTreeView->setModel( proxyModel() );
mTablesTreeView->setSortingEnabled( true );
mTablesTreeView->setEditTriggers( QAbstractItemView::CurrentChanged );
mTablesTreeView->setItemDelegate( mTablesTreeDelegate );
@@ -224,28 +212,14 @@ QgsOracleSourceSelect::QgsOracleSourceSelect( QWidget *parent, Qt::WindowFlags f

mTablesTreeView->setSelectionMode( QAbstractItemView::ExtendedSelection );

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

QgsSettings settings;
mHoldDialogOpen->setChecked( settings.value( QStringLiteral( "/Windows/OracleSourceSelect/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/OracleSourceSelect/columnWidths/%1" ).arg( i ), mTablesTreeView->columnWidth( i ) ).toInt() );
}

//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 );

populateConnectionList();
}
//! Autoconnected SLOTS
@@ -353,71 +327,9 @@ void QgsOracleSourceSelect::on_mTablesTreeView_doubleClicked( const QModelIndex
addButtonClicked();
}

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

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

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

void QgsOracleSourceSelect::on_mSearchColumnComboBox_currentIndexChanged( const QString &text )
{
if ( text == tr( "All" ) )
{
mProxyModel.setFilterKeyColumn( -1 );
}
else if ( text == tr( "Owner" ) )
{
mProxyModel.setFilterKeyColumn( QgsOracleTableModel::DbtmOwner );
}
else if ( text == tr( "Table" ) )
{
mProxyModel.setFilterKeyColumn( QgsOracleTableModel::DbtmTable );
}
else if ( text == tr( "Type" ) )
{
mProxyModel.setFilterKeyColumn( QgsOracleTableModel::DbtmType );
}
else if ( text == tr( "Geometry column" ) )
{
mProxyModel.setFilterKeyColumn( QgsOracleTableModel::DbtmGeomCol );
}
else if ( text == tr( "Primary key column" ) )
{
mProxyModel.setFilterKeyColumn( QgsOracleTableModel::DbtmPkCol );
}
else if ( text == tr( "SRID" ) )
{
mProxyModel.setFilterKeyColumn( QgsOracleTableModel::DbtmSrid );
}
else if ( text == tr( "Sql" ) )
{
mProxyModel.setFilterKeyColumn( QgsOracleTableModel::DbtmSql );
}
}

void QgsOracleSourceSelect::on_mSearchModeComboBox_currentIndexChanged( const QString &text )
{
Q_UNUSED( text )
on_mSearchTableEdit_textChanged( mSearchTableEdit->text() );
}

void QgsOracleSourceSelect::setLayerType( const QgsOracleLayerProperty &layerProperty )
{
mTableModel.addTableEntry( layerProperty );
mTableModel->addTableEntry( layerProperty );
}

QgsOracleSourceSelect::~QgsOracleSourceSelect()
@@ -431,7 +343,7 @@ QgsOracleSourceSelect::~QgsOracleSourceSelect()
QgsSettings settings;
settings.setValue( QStringLiteral( "/Windows/OracleSourceSelect/HoldDialogOpen" ), mHoldDialogOpen->isChecked() );

for ( int i = 0; i < mTableModel.columnCount(); i++ )
for ( int i = 0; i < mTableModel->columnCount(); i++ )
{
settings.setValue( QStringLiteral( "Windows/OracleSourceSelect/columnWidths/%1" ).arg( i ), mTablesTreeView->columnWidth( i ) );
}
@@ -465,7 +377,7 @@ void QgsOracleSourceSelect::addButtonClicked()
if ( idx.column() != QgsOracleTableModel::DbtmTable )
continue;

QString uri = mTableModel.layerURI( mProxyModel.mapToSource( idx ), mConnInfo );
QString uri = mTableModel->layerURI( proxyModel()->mapToSource( idx ), mConnInfo );
if ( uri.isNull() )
continue;

@@ -496,8 +408,8 @@ void QgsOracleSourceSelect::on_btnConnect_clicked()
return;
}

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

QApplication::setOverrideCursor( Qt::BusyCursor );

@@ -579,10 +491,10 @@ void QgsOracleSourceSelect::setSql( const QModelIndex &index )
return;
}

QModelIndex idx = mProxyModel.mapToSource( index );
QString tableName = mTableModel.itemFromIndex( idx.sibling( idx.row(), QgsOracleTableModel::DbtmTable ) )->text();
QModelIndex idx = proxyModel()->mapToSource( index );
QString tableName = mTableModel->itemFromIndex( idx.sibling( idx.row(), QgsOracleTableModel::DbtmTable ) )->text();

QString uri = mTableModel.layerURI( idx, mConnInfo );
QString uri = mTableModel->layerURI( idx, mConnInfo );
if ( uri.isNull() )
{
QgsDebugMsg( QStringLiteral( "no uri" ) );
@@ -600,7 +512,7 @@ void QgsOracleSourceSelect::setSql( const QModelIndex &index )
QgsQueryBuilder *gb = new QgsQueryBuilder( vlayer, this );
if ( gb->exec() )
{
mTableModel.setSql( mProxyModel.mapToSource( index ), gb->sql() );
mTableModel->setSql( proxyModel()->mapToSource( index ), gb->sql() );
}

delete gb;
@@ -639,8 +551,8 @@ void QgsOracleSourceSelect::setSearchExpression( const QString &regexp )

void QgsOracleSourceSelect::loadTableFromCache()
{
QModelIndex rootItemIndex = mTableModel.indexFromItem( mTableModel.invisibleRootItem() );
mTableModel.removeRows( 0, mTableModel.rowCount( rootItemIndex ), rootItemIndex );
QModelIndex rootItemIndex = mTableModel->indexFromItem( mTableModel->invisibleRootItem() );
mTableModel->removeRows( 0, mTableModel->rowCount( rootItemIndex ), rootItemIndex );

QString connName = cmbConnections->currentText();
QgsDataSourceUri uri = QgsOracleConn::connUri( connName );
@@ -650,7 +562,7 @@ void QgsOracleSourceSelect::loadTableFromCache()

const auto constLayers = layers;
for ( const QgsOracleLayerProperty &layerProperty : constLayers )
mTableModel.addTableEntry( layerProperty );
mTableModel->addTableEntry( layerProperty );

QApplication::setOverrideCursor( Qt::BusyCursor );

@@ -17,10 +17,8 @@
#ifndef QGSORACLESOURCESELECT_H
#define QGSORACLESOURCESELECT_H

#include "ui_qgsdbsourceselectbase.h"
#include "qgsguiutils.h"
#include "qgsdbfilterproxymodel.h"
#include "qgsoracletablemodel.h"
#include "qgshelp.h"
#include "qgsoracleconnpool.h"
#include "qgsproviderregistry.h"
@@ -32,10 +30,10 @@
#include <QItemDelegate>

class QPushButton;
class QStringList;
class QgsOracleColumnTypeTask;
class QgisApp;
class QgsOracleSourceSelect;
class QgsOracleTableModel;

class QgsOracleSourceSelectDelegate : public QItemDelegate
{
@@ -117,10 +115,6 @@ class QgsOracleSourceSelect : public QgsAbstractDataSourceWidget, private Ui::Qg
void on_btnSave_clicked();
//! Loads the selected connections from file
void on_btnLoad_clicked();
void on_mSearchGroupBox_toggled( bool );
void on_mSearchTableEdit_textChanged( const QString &text );
void on_mSearchColumnComboBox_currentIndexChanged( const QString &text );
void on_mSearchModeComboBox_currentIndexChanged( const QString &text );
void on_cmbConnections_currentIndexChanged( const QString &text );
void setSql( const QModelIndex &index );
//! Store the selected database
@@ -159,8 +153,7 @@ class QgsOracleSourceSelect : public QgsAbstractDataSourceWidget, private Ui::Qg
QMap<QString, QPair<QString, QIcon> > mLayerIcons;

//! Model that acts as datasource for mTableTreeWidget
QgsOracleTableModel mTableModel;
QgsDatabaseFilterProxyModel mProxyModel;
QgsOracleTableModel *mTableModel = nullptr;
QgsOracleSourceSelectDelegate *mTablesTreeDelegate = nullptr;

QPushButton *mBuildQueryButton = nullptr;
@@ -20,18 +20,47 @@
#include "qgsapplication.h"
#include "qgsiconutils.h"

QgsOracleTableModel::QgsOracleTableModel()
QgsOracleTableModel::QgsOracleTableModel( QObject *parent )
: QgsAbstractDbTableModel( parent )
{
QStringList headerLabels;
headerLabels << tr( "Owner" );
headerLabels << tr( "Table" );
headerLabels << tr( "Type" );
headerLabels << tr( "Geometry column" );
headerLabels << tr( "SRID" );
headerLabels << tr( "Primary key column" );
headerLabels << tr( "Select at id" );
headerLabels << tr( "Sql" );
setHorizontalHeaderLabels( headerLabels );
mColumns << tr( "Owner" )
<< tr( "Table" )
<< tr( "Type" )
<< tr( "Geometry column" )
<< tr( "SRID" )
<< tr( "Primary key column" )
<< tr( "Select at id" )
<< tr( "Sql" );
setHorizontalHeaderLabels( mColumns );
}

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

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

bool QgsOracleTableModel::searchableColumn( int column ) const
{
Columns col = static_cast<Columns>( column );
switch ( col )
{
case DbtmOwner:
case DbtmTable:
case DbtmGeomCol:
case DbtmType:
case DbtmSrid:
case DbtmSql:
return true;

case DbtmPkCol:
case DbtmSelectAtId:
return false;
}
}

void QgsOracleTableModel::addTableEntry( const QgsOracleLayerProperty &layerProperty )
@@ -251,7 +280,7 @@ bool QgsOracleTableModel::setData( const QModelIndex &idx, const QVariant &value
tip = tr( "Select a primary key" );
}

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() )
@@ -16,10 +16,11 @@
***************************************************************************/
#ifndef QGSORACLETABLEMODEL_H
#define QGSORACLETABLEMODEL_H
#include <QStandardItemModel>

#include "qgis.h"
#include "qgsoracleconn.h"
#include "qgsabstractdbtablemodel.h"


class QIcon;

@@ -29,11 +30,15 @@ class QIcon;
*
* The tables have the following columns: Type, Owner, Tablename, Geometry Column, Sql
*/
class QgsOracleTableModel : public QStandardItemModel
class QgsOracleTableModel : public QgsAbstractDbTableModel
{
Q_OBJECT
public:
QgsOracleTableModel();
QgsOracleTableModel( 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 QgsOracleLayerProperty &property );
@@ -53,8 +58,7 @@ class QgsOracleTableModel : public QStandardItemModel
DbtmSrid,
DbtmPkCol,
DbtmSelectAtId,
DbtmSql,
DbtmColumns
DbtmSql
};

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

};

#endif // QGSORACLETABLEMODEL_H

0 comments on commit c34f577

Please sign in to comment.