Skip to content
Permalink
Browse files

postgresql & oracle provider fixes:

- start with an empty line edit when entering srids (fixes #8016)
- oracle provider: order primary key candidates in views by column id (fixes #8018)
- disable non-selectable entries and provide tooltips on why they are disabled
  • Loading branch information
jef-n committed Jun 7, 2013
1 parent eea63a4 commit 3d9d1eeb33de58135cd48c068131af28c8dc9189
@@ -156,7 +156,7 @@ QStringList QgsOracleConn::pkCandidates( QString ownerName, QString viewName )
QStringList cols;

QSqlQuery qry( mDatabase );
if ( !exec( qry, QString( "SELECT column_name FROM all_tab_columns WHERE owner=%1 AND table_name=%2" )
if ( !exec( qry, QString( "SELECT column_name FROM all_tab_columns WHERE owner=%1 AND table_name=%2 ORDER BY column_id" )
.arg( quotedValue( ownerName ) ).arg( quotedValue( viewName ) ) ) )
{
QgsMessageLog::logMessage( tr( "SQL:%1\nerror:%2\n" ).arg( qry.lastQuery() ).arg( qry.lastError().text() ), tr( "Oracle" ) );
@@ -41,11 +41,14 @@ email : jef at norbit dot de
QWidget *QgsOracleSourceSelectDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const
{
Q_UNUSED( option );

QString tableName = index.sibling( index.row(), QgsOracleTableModel::dbtmTable ).data( Qt::DisplayRole ).toString();
if ( tableName.isEmpty() )
return 0;

if ( index.column() == QgsOracleTableModel::dbtmSql )
{
QLineEdit *le = new QLineEdit( parent );
le->setText( index.data( Qt::DisplayRole ).toString() );
return le;
return new QLineEdit( parent );
}

if ( index.column() == QgsOracleTableModel::dbtmType && index.data( Qt::UserRole + 1 ).toBool() )
@@ -63,7 +66,6 @@ QWidget *QgsOracleSourceSelectDelegate::createEditor( QWidget *parent, const QSt
{
cb->addItem( QgsOracleTableModel::iconForWkbType( type ), QgsOracleConn::displayStringForWkbType( type ), type );
}
cb->setCurrentIndex( cb->findData( index.data( Qt::UserRole + 2 ).toInt() ) );
return cb;
}

@@ -76,9 +78,7 @@ QWidget *QgsOracleSourceSelectDelegate::createEditor( QWidget *parent, const QSt
QStringList values = index.data( Qt::UserRole + 2 ).toStringList();
if ( values.size() == 0 )
{
QString tableName = index.sibling( index.row(), QgsOracleTableModel::dbtmTable ).data( Qt::DisplayRole ).toString();
QString ownerName = index.sibling( index.row(), QgsOracleTableModel::dbtmOwner ).data( Qt::DisplayRole ).toString();

values = mConn->pkCandidates( ownerName, tableName );
}

@@ -89,7 +89,6 @@ QWidget *QgsOracleSourceSelectDelegate::createEditor( QWidget *parent, const QSt
{
QComboBox *cb = new QComboBox( parent );
cb->addItems( values );
cb->setCurrentIndex( cb->findText( index.data( Qt::DisplayRole ).toString() ) );
return cb;
}
}
@@ -98,13 +97,38 @@ QWidget *QgsOracleSourceSelectDelegate::createEditor( QWidget *parent, const QSt
{
QLineEdit *le = new QLineEdit( parent );
le->setValidator( new QIntValidator( -1, 999999, parent ) );
le->insert( index.data( Qt::DisplayRole ).toString() );
return le;
}

return 0;
}

void QgsOracleSourceSelectDelegate::setEditorData( QWidget *editor, const QModelIndex &index ) const
{
QString value( index.data( Qt::DisplayRole ).toString() );

QComboBox *cb = qobject_cast<QComboBox* >( editor );
if ( cb )
{
if ( index.column() == QgsOracleTableModel::dbtmType )
cb->setCurrentIndex( cb->findData( index.data( Qt::UserRole + 2 ).toInt() ) );

if ( index.column() == QgsOracleTableModel::dbtmPkCol && index.data( Qt::UserRole + 2 ).toBool() )
cb->setCurrentIndex( cb->findText( value ) );
}

QLineEdit *le = qobject_cast<QLineEdit*>( editor );
if ( le )
{
bool ok;
value.toInt( &ok );
if ( index.column() == QgsOracleTableModel::dbtmSrid && !ok )
value = "";

le->setText( value );
}
}

void QgsOracleSourceSelectDelegate::setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const
{
QComboBox *cb = qobject_cast<QComboBox *>( editor );
@@ -120,14 +144,24 @@ void QgsOracleSourceSelectDelegate::setModelData( QWidget *editor, QAbstractItem
}
else if ( index.column() == QgsOracleTableModel::dbtmPkCol )
{
model->setData( index, cb->currentText() );
model->setData( index, cb->currentText(), Qt::UserRole + 2 );
QString value( cb->currentText() );
model->setData( index, value.isEmpty() ? tr( "Select..." ) : value );
model->setData( index, !value.isEmpty(), Qt::UserRole + 2 );
}
}

QLineEdit *le = qobject_cast<QLineEdit *>( editor );
if ( le )
model->setData( index, le->text() );
{
QString value( le->text() );

if ( index.column() == QgsOracleTableModel::dbtmSrid && value.isEmpty() )
{
value = tr( "Enter..." );
}

model->setData( index, value );
}
}

QgsOracleSourceSelect::QgsOracleSourceSelect( QWidget *parent, Qt::WFlags fl, bool managerMode, bool embeddedMode )
@@ -20,9 +20,8 @@
#include "ui_qgsdbsourceselectbase.h"
#include "qgisgui.h"
#include "qgsdbfilterproxymodel.h"
#include "qgscontexthelp.h"

#include "qgsoracletablemodel.h"
#include "qgscontexthelp.h"

#include <QMap>
#include <QPair>
@@ -31,8 +30,8 @@

class QPushButton;
class QStringList;
class QgisApp;
class QgsOracleColumnTypeThread;
class QgisApp;
class QgsOracleSourceSelect;

class QgsOracleSourceSelectDelegate : public QItemDelegate
@@ -52,8 +51,10 @@ class QgsOracleSourceSelectDelegate : public QItemDelegate

QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const;
void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const;
void setEditorData( QWidget *editor, const QModelIndex &index ) const;

void setConn( QgsOracleConn *conn ) { if ( mConn ) mConn->disconnect(); mConn = conn; }

private:
QgsOracleConn *mConn;
};
@@ -57,10 +57,23 @@ void QgsOracleTableModel::addTableEntry( const QgsOracleLayerProperty &layerProp
QGis::WkbType wkbType = layerProperty.types[ i ];
int srid = layerProperty.srids[ i ];

QStandardItem *ownerNameItem = new QStandardItem( layerProperty.ownerName );

bool selectable = wkbType == QGis::WKBNoGeometry || ( wkbType != QGis::WKBUnknown && srid != 0 );
QString tip;
if ( wkbType == QGis::WKBUnknown )
{
tip = tr( "Specify a geometry type" );
}
else if ( wkbType != QGis::WKBNoGeometry && srid == 0 )
{
tip = tr( "Enter a SRID" );
}

if ( tip.isEmpty() && layerProperty.isView )
{
tip = tr( "Select a primary key" );
}

QStandardItem *ownerNameItem = new QStandardItem( layerProperty.ownerName );
QStandardItem *typeItem = new QStandardItem( iconForWkbType( wkbType ), wkbType == QGis::WKBUnknown ? tr( "Select..." ) : QgsOracleConn::displayStringForWkbType( wkbType ) );
typeItem->setData( wkbType == QGis::WKBUnknown, Qt::UserRole + 1 );
typeItem->setData( wkbType, Qt::UserRole + 2 );
@@ -77,9 +90,12 @@ void QgsOracleTableModel::addTableEntry( const QgsOracleLayerProperty &layerProp
sridItem->setFlags( sridItem->flags() | Qt::ItemIsEditable );
}

QStandardItem *pkItem = new QStandardItem( layerProperty.isView ? tr( "Select..." ) : "" );
QStandardItem *pkItem = new QStandardItem( "" );
if ( layerProperty.isView )
{
pkItem->setText( tr( "Select..." ) );
pkItem->setFlags( pkItem->flags() | Qt::ItemIsEditable );
}
else
pkItem->setFlags( pkItem->flags() & ~Qt::ItemIsEditable );

@@ -105,13 +121,20 @@ void QgsOracleTableModel::addTableEntry( const QgsOracleLayerProperty &layerProp

foreach ( QStandardItem *item, childItemList )
{
if ( selectable )
if ( tip.isEmpty() )
{
item->setFlags( item->flags() | Qt::ItemIsSelectable );
item->setFlags( item->flags() | Qt::ItemIsSelectable | Qt::ItemIsEnabled );
item->setToolTip( "" );
}
else
{
item->setFlags( item->flags() & ~Qt::ItemIsSelectable );

if ( item == ownerNameItem || item == tableItem || item == geomItem )
{
item->setFlags( item->flags() & ~Qt::ItemIsEnabled );
item->setToolTip( tip );
}
}
}

@@ -235,26 +258,45 @@ bool QgsOracleTableModel::setData( const QModelIndex &idx, const QVariant &value

if ( idx.column() == dbtmType || idx.column() == dbtmSrid || idx.column() == dbtmPkCol )
{
QGis::WkbType geomType = ( QGis::WkbType ) idx.sibling( idx.row(), dbtmType ).data( Qt::UserRole + 2 ).toInt();

bool ok = geomType != QGis::WKBUnknown;
QGis::WkbType wkbType = ( QGis::WkbType ) idx.sibling( idx.row(), dbtmType ).data( Qt::UserRole + 2 ).toInt();

if ( ok && geomType != QGis::WKBNoGeometry )
QString tip;
if ( wkbType == QGis::WKBUnknown )
{
tip = tr( "Specify a geometry type" );
}
else if ( wkbType != QGis::WKBNoGeometry )
{
bool ok;
int srid = idx.sibling( idx.row(), dbtmSrid ).data().toInt( &ok );
ok &= srid != 0;

if ( !ok || srid == 0 )
tip = tr( "Enter a SRID" );
}

ok &= !idx.sibling( idx.row(), dbtmPkCol ).data( Qt::UserRole + 1 ).toBool() ||
idx.sibling( idx.row(), dbtmPkCol ).data( Qt::UserRole + 2 ).toBool();
if ( tip.isEmpty() && idx.sibling( idx.row(), dbtmPkCol ).data( Qt::UserRole + 1 ).toBool() )
{
if ( !idx.sibling( idx.row(), dbtmPkCol ).data( Qt::UserRole + 2 ).toBool() )
tip = tr( "Select a primary key" );
}

for ( int i = 0; i < dbtmColumns; i++ )
{
QStandardItem *item = itemFromIndex( idx.sibling( idx.row(), i ) );
if ( ok )
item->setFlags( item->flags() | Qt::ItemIsSelectable );
if ( tip.isEmpty() )
{
item->setFlags( item->flags() | Qt::ItemIsSelectable | Qt::ItemIsEnabled );
item->setToolTip( "" );
}
else
{
item->setFlags( item->flags() & ~Qt::ItemIsSelectable );
if ( i == dbtmOwner || i == dbtmTable || i == dbtmGeomCol )
{
item->setFlags( item->flags() & ~Qt::ItemIsEnabled );
item->setToolTip( tip );
}
}
}
}

@@ -41,11 +41,14 @@ email : sherman at mrcc.com
QWidget *QgsPgSourceSelectDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const
{
Q_UNUSED( option );

QString tableName = index.sibling( index.row(), QgsPgTableModel::dbtmTable ).data( Qt::DisplayRole ).toString();
if ( tableName.isEmpty() )
return 0;

if ( index.column() == QgsPgTableModel::dbtmSql )
{
QLineEdit *le = new QLineEdit( parent );
le->setText( index.data( Qt::DisplayRole ).toString() );
return le;
return new QLineEdit( parent );
}

if ( index.column() == QgsPgTableModel::dbtmType && index.data( Qt::UserRole + 1 ).toBool() )
@@ -63,7 +66,6 @@ QWidget *QgsPgSourceSelectDelegate::createEditor( QWidget *parent, const QStyleO
{
cb->addItem( QgsPgTableModel::iconForWkbType( type ), QgsPostgresConn::displayStringForWkbType( type ), type );
}
cb->setCurrentIndex( cb->findData( index.data( Qt::UserRole + 2 ).toInt() ) );
return cb;
}

@@ -75,7 +77,6 @@ QWidget *QgsPgSourceSelectDelegate::createEditor( QWidget *parent, const QStyleO
{
QComboBox *cb = new QComboBox( parent );
cb->addItems( values );
cb->setCurrentIndex( cb->findText( index.data( Qt::DisplayRole ).toString() ) );
return cb;
}
}
@@ -84,13 +85,38 @@ QWidget *QgsPgSourceSelectDelegate::createEditor( QWidget *parent, const QStyleO
{
QLineEdit *le = new QLineEdit( parent );
le->setValidator( new QIntValidator( -1, 999999, parent ) );
le->insert( index.data( Qt::DisplayRole ).toString() );
return le;
}

return 0;
}

void QgsPgSourceSelectDelegate::setEditorData( QWidget *editor, const QModelIndex &index ) const
{
QString value( index.data( Qt::DisplayRole ).toString() );

QComboBox *cb = qobject_cast<QComboBox* >( editor );
if ( cb )
{
if ( index.column() == QgsPgTableModel::dbtmType )
cb->setCurrentIndex( cb->findData( index.data( Qt::UserRole + 2 ).toInt() ) );

if ( index.column() == QgsPgTableModel::dbtmPkCol && !index.data( Qt::UserRole + 2 ).toString().isEmpty() )
cb->setCurrentIndex( cb->findText( index.data( Qt::UserRole + 2 ).toString() ) );
}

QLineEdit *le = qobject_cast<QLineEdit*>( editor );
if ( le )
{
bool ok;
value.toInt( &ok );
if ( index.column() == QgsPgTableModel::dbtmSrid && !ok )
value = "";

le->setText( value );
}
}

void QgsPgSourceSelectDelegate::setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const
{
QComboBox *cb = qobject_cast<QComboBox *>( editor );
@@ -106,14 +132,24 @@ void QgsPgSourceSelectDelegate::setModelData( QWidget *editor, QAbstractItemMode
}
else if ( index.column() == QgsPgTableModel::dbtmPkCol )
{
model->setData( index, cb->currentText() );
model->setData( index, cb->currentText(), Qt::UserRole + 2 );
QString value( cb->currentText() );
model->setData( index, value.isEmpty() ? tr( "Select..." ) : value );
model->setData( index, value, Qt::UserRole + 2 );
}
}

QLineEdit *le = qobject_cast<QLineEdit *>( editor );
if ( le )
model->setData( index, le->text() );
{
QString value( le->text() );

if ( index.column() == QgsPgTableModel::dbtmSrid && value.isEmpty() )
{
value = tr( "Enter..." );
}

model->setData( index, value );
}
}

QgsPgSourceSelect::QgsPgSourceSelect( QWidget *parent, Qt::WFlags fl, bool managerMode, bool embeddedMode )
@@ -45,6 +45,7 @@ class QgsPgSourceSelectDelegate : public QItemDelegate

QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const;
void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const;
void setEditorData( QWidget *editor, const QModelIndex &index ) const;
};


0 comments on commit 3d9d1ee

Please sign in to comment.
You can’t perform that action at this time.