mirror of
https://github.com/qgis/QGIS.git
synced 2025-07-03 00:03:10 -04:00
Compare commits
3 Commits
4daa7545b1
...
10535c5694
Author | SHA1 | Date | |
---|---|---|---|
|
10535c5694 | ||
|
8482761588 | ||
|
1552fe8887 |
@ -1329,7 +1329,18 @@ QList<QgsMapLayer *> QgsAppLayerHandling::addDatabaseLayers( const QStringList &
|
|||||||
QgsMessageLog::logMessage( QObject::tr( "%1 is an invalid layer - not loaded" ).arg( layerPath ) );
|
QgsMessageLog::logMessage( QObject::tr( "%1 is an invalid layer - not loaded" ).arg( layerPath ) );
|
||||||
QLabel *msgLabel = new QLabel( QObject::tr( "%1 is an invalid layer and cannot be loaded. Please check the <a href=\"#messageLog\">message log</a> for further info." ).arg( layerPath ), QgisApp::instance()->messageBar() );
|
QLabel *msgLabel = new QLabel( QObject::tr( "%1 is an invalid layer and cannot be loaded. Please check the <a href=\"#messageLog\">message log</a> for further info." ).arg( layerPath ), QgisApp::instance()->messageBar() );
|
||||||
msgLabel->setWordWrap( true );
|
msgLabel->setWordWrap( true );
|
||||||
QObject::connect( msgLabel, &QLabel::linkActivated, QgisApp::instance()->logDock(), &QWidget::show );
|
|
||||||
|
if ( providerKey == QLatin1String( "postgres" ) )
|
||||||
|
{
|
||||||
|
QObject::connect( msgLabel, &QLabel::linkActivated, QgisApp::instance(), [] {
|
||||||
|
QgisApp::instance()->openMessageLog( QObject::tr( "PostGIS" ) );
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QObject::connect( msgLabel, &QLabel::linkActivated, QgisApp::instance()->logDock(), &QWidget::show );
|
||||||
|
}
|
||||||
|
|
||||||
QgsMessageBarItem *item = new QgsMessageBarItem( msgLabel, Qgis::MessageLevel::Warning );
|
QgsMessageBarItem *item = new QgsMessageBarItem( msgLabel, Qgis::MessageLevel::Warning );
|
||||||
QgisApp::instance()->messageBar()->pushItem( item );
|
QgisApp::instance()->messageBar()->pushItem( item );
|
||||||
delete layer;
|
delete layer;
|
||||||
|
@ -96,7 +96,7 @@ void QgsPgTableModel::addTableEntry( const QgsPostgresLayerProperty &layerProper
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString tip;
|
QString tip;
|
||||||
bool withTipButSelectable = false;
|
bool layerNeedsFeatureId = false;
|
||||||
if ( !layerProperty.isRaster )
|
if ( !layerProperty.isRaster )
|
||||||
{
|
{
|
||||||
if ( wkbType == Qgis::WkbType::Unknown )
|
if ( wkbType == Qgis::WkbType::Unknown )
|
||||||
@ -110,7 +110,7 @@ void QgsPgTableModel::addTableEntry( const QgsPostgresLayerProperty &layerProper
|
|||||||
else if ( !layerProperty.pkCols.isEmpty() )
|
else if ( !layerProperty.pkCols.isEmpty() )
|
||||||
{
|
{
|
||||||
tip = tr( "Select columns in the '%1' column that uniquely identify features of this layer" ).arg( tr( "Feature id" ) );
|
tip = tr( "Select columns in the '%1' column that uniquely identify features of this layer" ).arg( tr( "Feature id" ) );
|
||||||
withTipButSelectable = true;
|
layerNeedsFeatureId = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +160,9 @@ void QgsPgTableModel::addTableEntry( const QgsPostgresLayerProperty &layerProper
|
|||||||
pkItem->setFlags( pkItem->flags() | Qt::ItemIsEditable );
|
pkItem->setFlags( pkItem->flags() | Qt::ItemIsEditable );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
pkItem->setFlags( pkItem->flags() & ~Qt::ItemIsEditable );
|
pkItem->setFlags( pkItem->flags() & ~Qt::ItemIsEditable );
|
||||||
|
}
|
||||||
|
|
||||||
pkItem->setData( layerProperty.pkCols, Qt::UserRole + 1 );
|
pkItem->setData( layerProperty.pkCols, Qt::UserRole + 1 );
|
||||||
|
|
||||||
@ -176,8 +178,17 @@ void QgsPgTableModel::addTableEntry( const QgsPostgresLayerProperty &layerProper
|
|||||||
|
|
||||||
pkItem->setData( defPk, Qt::UserRole + 2 );
|
pkItem->setData( defPk, Qt::UserRole + 2 );
|
||||||
if ( !defPk.isEmpty() )
|
if ( !defPk.isEmpty() )
|
||||||
|
{
|
||||||
pkItem->setText( defPk.join( ',' ) );
|
pkItem->setText( defPk.join( ',' ) );
|
||||||
|
|
||||||
|
// Reset the tip since we're pre-selecting fields in the Feature id combo box.
|
||||||
|
// Note we don't reset the tip if Geom type or SRID need some action from users.
|
||||||
|
if ( layerNeedsFeatureId )
|
||||||
|
{
|
||||||
|
tip = QString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QStandardItem *selItem = new QStandardItem( QString() );
|
QStandardItem *selItem = new QStandardItem( QString() );
|
||||||
selItem->setFlags( selItem->flags() | Qt::ItemIsUserCheckable );
|
selItem->setFlags( selItem->flags() | Qt::ItemIsUserCheckable );
|
||||||
selItem->setCheckState( Qt::Checked );
|
selItem->setCheckState( Qt::Checked );
|
||||||
@ -237,28 +248,10 @@ void QgsPgTableModel::addTableEntry( const QgsPostgresLayerProperty &layerProper
|
|||||||
childItemList << checkPkUnicityItem;
|
childItemList << checkPkUnicityItem;
|
||||||
childItemList << sqlItem;
|
childItemList << sqlItem;
|
||||||
|
|
||||||
const auto constChildItemList = childItemList;
|
for ( int column = 0; column < childItemList.count(); column++ )
|
||||||
for ( QStandardItem *item : constChildItemList )
|
|
||||||
{
|
{
|
||||||
if ( tip.isEmpty() || withTipButSelectable )
|
QStandardItem *item = childItemList.at( column );
|
||||||
item->setFlags( item->flags() | Qt::ItemIsSelectable );
|
setItemStatus( item, tip, column );
|
||||||
else
|
|
||||||
item->setFlags( item->flags() & ~Qt::ItemIsSelectable );
|
|
||||||
|
|
||||||
if ( item->toolTip().isEmpty() && tip.isEmpty() && item != checkPkUnicityItem && item != selItem )
|
|
||||||
{
|
|
||||||
item->setToolTip( QString() );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( item == schemaNameItem )
|
|
||||||
item->setData( QgsApplication::getThemeIcon( QStringLiteral( "/mIconWarning.svg" ) ), Qt::DecorationRole );
|
|
||||||
|
|
||||||
if ( item == schemaNameItem || item == tableItem || item == geomItem )
|
|
||||||
{
|
|
||||||
item->setToolTip( tip );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !schemaItem )
|
if ( !schemaItem )
|
||||||
@ -285,6 +278,38 @@ void QgsPgTableModel::addTableEntry( const QgsPostgresLayerProperty &layerProper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsPgTableModel::setItemStatus( QStandardItem *item, const QString &tip, int column )
|
||||||
|
{
|
||||||
|
if ( tip.isEmpty() )
|
||||||
|
{
|
||||||
|
item->setFlags( item->flags() | Qt::ItemIsSelectable );
|
||||||
|
|
||||||
|
if ( column == DbtmSchema || column == DbtmTable || column == DbtmGeomCol )
|
||||||
|
{
|
||||||
|
item->setToolTip( QString() );
|
||||||
|
|
||||||
|
if ( column == DbtmSchema )
|
||||||
|
{
|
||||||
|
item->setData( QVariant(), Qt::DecorationRole );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
item->setFlags( item->flags() & ~Qt::ItemIsSelectable );
|
||||||
|
|
||||||
|
if ( column == DbtmSchema || column == DbtmTable || column == DbtmGeomCol )
|
||||||
|
{
|
||||||
|
item->setToolTip( tip );
|
||||||
|
|
||||||
|
if ( column == DbtmSchema )
|
||||||
|
{
|
||||||
|
item->setData( QgsApplication::getThemeIcon( QStringLiteral( "/mIconWarning.svg" ) ), Qt::DecorationRole );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void QgsPgTableModel::setSql( const QModelIndex &index, const QString &sql )
|
void QgsPgTableModel::setSql( const QModelIndex &index, const QString &sql )
|
||||||
{
|
{
|
||||||
if ( !index.isValid() || !index.parent().isValid() )
|
if ( !index.isValid() || !index.parent().isValid() )
|
||||||
@ -362,6 +387,7 @@ bool QgsPgTableModel::setData( const QModelIndex &idx, const QVariant &value, in
|
|||||||
if ( !QStandardItemModel::setData( idx, value, role ) )
|
if ( !QStandardItemModel::setData( idx, value, role ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// After changes in type, srid, or feature id columns, update other sibling columns
|
||||||
if ( idx.column() == DbtmType || idx.column() == DbtmSrid || idx.column() == DbtmPkCol )
|
if ( idx.column() == DbtmType || idx.column() == DbtmSrid || idx.column() == DbtmPkCol )
|
||||||
{
|
{
|
||||||
const Qgis::WkbType wkbType = static_cast<Qgis::WkbType>( idx.sibling( idx.row(), DbtmType ).data( Qt::UserRole + 2 ).toInt() );
|
const Qgis::WkbType wkbType = static_cast<Qgis::WkbType>( idx.sibling( idx.row(), DbtmType ).data( Qt::UserRole + 2 ).toInt() );
|
||||||
@ -386,35 +412,15 @@ bool QgsPgTableModel::setData( const QModelIndex &idx, const QVariant &value, in
|
|||||||
const QSet<QString> s0( qgis::listToSet( idx.sibling( idx.row(), DbtmPkCol ).data( Qt::UserRole + 2 ).toStringList() ) );
|
const QSet<QString> s0( qgis::listToSet( idx.sibling( idx.row(), DbtmPkCol ).data( Qt::UserRole + 2 ).toStringList() ) );
|
||||||
const QSet<QString> s1( qgis::listToSet( pkCols ) );
|
const QSet<QString> s1( qgis::listToSet( pkCols ) );
|
||||||
if ( !s0.intersects( s1 ) )
|
if ( !s0.intersects( s1 ) )
|
||||||
|
{
|
||||||
tip = tr( "Select columns in the '%1' column that uniquely identify features of this layer" ).arg( tr( "Feature id" ) );
|
tip = tr( "Select columns in the '%1' column that uniquely identify features of this layer" ).arg( tr( "Feature id" ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( int i = 0; i < columnCount(); i++ )
|
for ( int column = 0; column < columnCount(); column++ )
|
||||||
{
|
{
|
||||||
QStandardItem *item = itemFromIndex( idx.sibling( idx.row(), i ) );
|
QStandardItem *item = itemFromIndex( idx.sibling( idx.row(), column ) );
|
||||||
if ( tip.isEmpty() )
|
setItemStatus( item, tip, column );
|
||||||
{
|
|
||||||
if ( i == DbtmSchema )
|
|
||||||
{
|
|
||||||
item->setData( QVariant(), Qt::DecorationRole );
|
|
||||||
}
|
|
||||||
|
|
||||||
item->setFlags( item->flags() | Qt::ItemIsSelectable );
|
|
||||||
item->setToolTip( QString() );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
item->setFlags( item->flags() & ~Qt::ItemIsSelectable );
|
|
||||||
|
|
||||||
if ( i == DbtmSchema )
|
|
||||||
item->setData( QgsApplication::getThemeIcon( QStringLiteral( "/mIconWarning.svg" ) ), Qt::DecorationRole );
|
|
||||||
|
|
||||||
if ( i == DbtmSchema || i == DbtmTable || i == DbtmGeomCol )
|
|
||||||
{
|
|
||||||
item->setFlags( item->flags() );
|
|
||||||
item->setToolTip( tip );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,6 +69,15 @@ class QgsPgTableModel : public QgsAbstractDbTableModel
|
|||||||
|
|
||||||
void setConnectionName( const QString &connName ) { mConnName = connName; }
|
void setConnectionName( const QString &connName ) { mConnName = connName; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets flags, tool tips and decorators to the schema, table and geometry column items.
|
||||||
|
*
|
||||||
|
* \param item Item to be modified.
|
||||||
|
* \param tip Tool tip to be applied to the item.
|
||||||
|
* \param column Column where the item is located in the current row.
|
||||||
|
*/
|
||||||
|
void setItemStatus( QStandardItem *item, const QString &tip, int column );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Number of tables in the model
|
//! Number of tables in the model
|
||||||
int mTableCount = 0;
|
int mTableCount = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user