void QgsOracleTableModel::addTableEntry( const QgsOracleLayerProperty &layerProperty ) { QgsDebugMsg( layerProperty.toString() ); if ( layerProperty.isView && layerProperty.pkCols.isEmpty() ) { QgsDebugMsg( "View without pk skipped." ); return; } // is there already a root item with the given scheme Name? QStandardItem *ownerItem = 0; for ( int i = 0; i < layerProperty.size(); i++ ) { QGis::WkbType wkbType = layerProperty.types[ i ]; int srid = layerProperty.srids[ i ]; 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 ); if ( wkbType == QGis::WKBUnknown ) typeItem->setFlags( typeItem->flags() | Qt::ItemIsEditable ); QStandardItem *tableItem = new QStandardItem( layerProperty.tableName ); QStandardItem *geomItem = new QStandardItem( layerProperty.geometryColName ); QStandardItem *sridItem = new QStandardItem( wkbType != QGis::WKBNoGeometry ? QString::number( srid ) : "" ); sridItem->setEditable( wkbType != QGis::WKBNoGeometry && srid == 0 ); if ( sridItem->isEditable() ) { sridItem->setText( tr( "Enter..." ) ); sridItem->setFlags( sridItem->flags() | Qt::ItemIsEditable ); } QStandardItem *pkItem = new QStandardItem( "" ); if ( layerProperty.isView ) { pkItem->setText( tr( "Select..." ) ); pkItem->setFlags( pkItem->flags() | Qt::ItemIsEditable ); } else pkItem->setFlags( pkItem->flags() & ~Qt::ItemIsEditable ); pkItem->setData( layerProperty.isView, Qt::UserRole + 1 ); pkItem->setData( false, Qt::UserRole + 2 ); // not selected QStandardItem *selItem = new QStandardItem( "" ); selItem->setFlags( selItem->flags() | Qt::ItemIsUserCheckable ); selItem->setCheckState( Qt::Checked ); selItem->setToolTip( tr( "Disable 'Fast Access to Features at ID' capability to force keeping the attribute table in memory (e.g. in case of expensive views)." ) ); QStandardItem* sqlItem = new QStandardItem( layerProperty.sql ); QList<QStandardItem*> childItemList; childItemList << ownerNameItem; childItemList << tableItem; childItemList << typeItem; childItemList << geomItem; childItemList << sridItem; childItemList << pkItem; childItemList << selItem; childItemList << sqlItem; foreach ( QStandardItem *item, childItemList ) { if ( tip.isEmpty() ) { 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 ); } } } if ( !ownerItem ) { QList<QStandardItem*> ownerItems = findItems( layerProperty.ownerName, Qt::MatchExactly, dbtmOwner ); // there is already an item for this schema if ( ownerItems.size() > 0 ) { ownerItem = ownerItems.at( dbtmOwner ); } else { // create a new toplevel item for this schema ownerItem = new QStandardItem( layerProperty.ownerName ); ownerItem->setFlags( Qt::ItemIsEnabled ); invisibleRootItem()->setChild( invisibleRootItem()->rowCount(), ownerItem ); } } ownerItem->appendRow( childItemList ); ++mTableCount; } }
void QgsPgTableModel::addTableEntry( const QgsPostgresLayerProperty &layerProperty ) { QgsDebugMsg( layerProperty.toString() ); // is there already a root item with the given scheme Name? QStandardItem *schemaItem = nullptr; for ( int i = 0; i < layerProperty.size(); i++ ) { QgsWkbTypes::Type wkbType = layerProperty.types[ i ]; int srid = layerProperty.srids[ i ]; if ( wkbType == QgsWkbTypes::Unknown && layerProperty.geometryColName.isEmpty() ) { wkbType = QgsWkbTypes::NoGeometry; } QString tip; if ( wkbType == QgsWkbTypes::Unknown ) { tip = tr( "Specify a geometry type in the '%1' column" ).arg( tr( "Data Type" ) ); } else if ( wkbType != QgsWkbTypes::NoGeometry && srid == INT_MIN ) { tip = tr( "Enter a SRID into the '%1' column" ).arg( tr( "SRID" ) ); } else if ( !layerProperty.pkCols.isEmpty() ) { tip = tr( "Select columns in the '%1' column that uniquely identify features of this layer" ).arg( tr( "Feature id" ) ); } QStandardItem *schemaNameItem = new QStandardItem( layerProperty.schemaName ); QStandardItem *typeItem = new QStandardItem( iconForWkbType( wkbType ), wkbType == QgsWkbTypes::Unknown ? tr( "Select..." ) : QgsPostgresConn::displayStringForWkbType( wkbType ) ); typeItem->setData( wkbType == QgsWkbTypes::Unknown, Qt::UserRole + 1 ); typeItem->setData( wkbType, Qt::UserRole + 2 ); if ( wkbType == QgsWkbTypes::Unknown ) typeItem->setFlags( typeItem->flags() | Qt::ItemIsEditable ); QStandardItem *geomTypeItem = new QStandardItem( QgsPostgresConn::displayStringForGeomType( layerProperty.geometryColType ) ); QStandardItem *tableItem = new QStandardItem( layerProperty.tableName ); QStandardItem *commentItem = new QStandardItem( layerProperty.tableComment ); QStandardItem *geomItem = new QStandardItem( layerProperty.geometryColName ); QStandardItem *sridItem = new QStandardItem( wkbType != QgsWkbTypes::NoGeometry ? QString::number( srid ) : QLatin1String( "" ) ); sridItem->setEditable( wkbType != QgsWkbTypes::NoGeometry && srid == INT_MIN ); if ( sridItem->isEditable() ) { sridItem->setText( tr( "Enter..." ) ); sridItem->setFlags( sridItem->flags() | Qt::ItemIsEditable ); } QStandardItem *pkItem = new QStandardItem( QLatin1String( "" ) ); if ( !layerProperty.pkCols.isEmpty() ) { pkItem->setText( tr( "Select..." ) ); pkItem->setFlags( pkItem->flags() | Qt::ItemIsEditable ); } else pkItem->setFlags( pkItem->flags() & ~Qt::ItemIsEditable ); pkItem->setData( layerProperty.pkCols, Qt::UserRole + 1 ); pkItem->setData( "", Qt::UserRole + 2 ); QStandardItem *selItem = new QStandardItem( QLatin1String( "" ) ); selItem->setFlags( selItem->flags() | Qt::ItemIsUserCheckable ); selItem->setCheckState( Qt::Checked ); selItem->setToolTip( tr( "Disable 'Fast Access to Features at ID' capability to force keeping the attribute table in memory (e.g. in case of expensive views)." ) ); QStandardItem *sqlItem = new QStandardItem( layerProperty.sql ); QList<QStandardItem *> childItemList; childItemList << schemaNameItem; childItemList << tableItem; childItemList << commentItem; childItemList << geomItem; childItemList << geomTypeItem; childItemList << typeItem; childItemList << sridItem; childItemList << pkItem; childItemList << selItem; childItemList << sqlItem; Q_FOREACH ( QStandardItem *item, childItemList ) { if ( tip.isEmpty() ) { item->setFlags( item->flags() | Qt::ItemIsSelectable ); item->setToolTip( QLatin1String( "" ) ); } else { item->setFlags( item->flags() & ~Qt::ItemIsSelectable ); if ( item == schemaNameItem ) item->setData( QgsApplication::getThemeIcon( QStringLiteral( "/mIconWarning.svg" ) ), Qt::DecorationRole ); if ( item == schemaNameItem || item == tableItem || item == geomItem ) { item->setToolTip( tip ); } } } if ( !schemaItem ) { QList<QStandardItem *> schemaItems = findItems( layerProperty.schemaName, Qt::MatchExactly, DbtmSchema ); // there is already an item for this schema if ( !schemaItems.isEmpty() ) { schemaItem = schemaItems.at( DbtmSchema ); } else { // create a new toplevel item for this schema schemaItem = new QStandardItem( layerProperty.schemaName ); schemaItem->setFlags( Qt::ItemIsEnabled ); invisibleRootItem()->setChild( invisibleRootItem()->rowCount(), schemaItem ); } } schemaItem->appendRow( childItemList ); ++mTableCount; } }
void QgsDb2TableModel::addTableEntry( const QgsDb2LayerProperty &layerProperty ) { QgsDebugMsg( QStringLiteral( " DB2 **** %1.%2.%3 type=%4 srid=%5 pk=%6 sql=%7" ) .arg( layerProperty.schemaName ) .arg( layerProperty.tableName ) .arg( layerProperty.geometryColName ) .arg( layerProperty.type ) .arg( layerProperty.srid ) .arg( layerProperty.pkCols.join( ',' ) ) .arg( layerProperty.sql ) ); // is there already a root item with the given scheme Name? QStandardItem *schemaItem = nullptr; QList<QStandardItem *> schemaItems = findItems( layerProperty.schemaName, Qt::MatchExactly, DbtmSchema ); // there is already an item for this schema if ( schemaItems.size() > 0 ) { schemaItem = schemaItems.at( DbtmSchema ); } else { // create a new toplevel item for this schema schemaItem = new QStandardItem( layerProperty.schemaName ); schemaItem->setFlags( Qt::ItemIsEnabled ); invisibleRootItem()->setChild( invisibleRootItem()->rowCount(), schemaItem ); } QgsWkbTypes::Type wkbType = QgsDb2TableModel::wkbTypeFromDb2( layerProperty.type ); if ( wkbType == QgsWkbTypes::Unknown && layerProperty.geometryColName.isEmpty() ) { wkbType = QgsWkbTypes::NoGeometry; } bool needToDetect = wkbType == QgsWkbTypes::Unknown && layerProperty.type != QLatin1String( "GEOMETRYCOLLECTION" ); QList<QStandardItem *> childItemList; QStandardItem *schemaNameItem = new QStandardItem( layerProperty.schemaName ); schemaNameItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable ); QStandardItem *typeItem = new QStandardItem( iconForWkbType( wkbType ), needToDetect ? tr( "Detecting…" ) : QgsWkbTypes::displayString( wkbType ) ); typeItem->setData( needToDetect, Qt::UserRole + 1 ); typeItem->setData( wkbType, Qt::UserRole + 2 ); QStandardItem *tableItem = new QStandardItem( layerProperty.tableName ); QStandardItem *geomItem = new QStandardItem( layerProperty.geometryColName ); QStandardItem *sridItem = new QStandardItem( layerProperty.srid ); sridItem->setEditable( false ); QString pkText; QString pkCol; switch ( layerProperty.pkCols.size() ) { case 0: break; case 1: pkText = layerProperty.pkCols[0]; pkCol = pkText; break; default: pkText = tr( "Select…" ); break; } QStandardItem *pkItem = new QStandardItem( pkText ); if ( pkText == tr( "Select…" ) ) pkItem->setFlags( pkItem->flags() | Qt::ItemIsEditable ); pkItem->setData( layerProperty.pkCols, Qt::UserRole + 1 ); pkItem->setData( pkCol, Qt::UserRole + 2 ); QStandardItem *selItem = new QStandardItem( QLatin1String( "" ) ); selItem->setFlags( selItem->flags() | Qt::ItemIsUserCheckable ); selItem->setCheckState( Qt::Checked ); selItem->setToolTip( tr( "Disable 'Fast Access to Features at ID' capability to force keeping the attribute table in memory (e.g. in case of expensive views)." ) ); QStandardItem *sqlItem = new QStandardItem( layerProperty.sql ); childItemList << schemaNameItem; childItemList << tableItem; childItemList << typeItem; childItemList << geomItem; childItemList << sridItem; childItemList << pkItem; childItemList << selItem; childItemList << sqlItem; bool detailsFromThread = needToDetect || ( wkbType != QgsWkbTypes::NoGeometry && layerProperty.srid.isEmpty() ); if ( detailsFromThread || pkText == tr( "Select…" ) ) { Qt::ItemFlags flags = Qt::ItemIsSelectable; if ( detailsFromThread ) flags |= Qt::ItemIsEnabled; for ( QStandardItem *item : qgis::as_const( childItemList ) ) { item->setFlags( item->flags() & ~flags ); } } schemaItem->appendRow( childItemList ); ++mTableCount; }
void QgsDb2TableModel::setGeometryTypesForTable( QgsDb2LayerProperty layerProperty ) { QStringList typeList = layerProperty.type.split( ',', QString::SkipEmptyParts ); QStringList sridList = layerProperty.srid.split( ',', QString::SkipEmptyParts ); Q_ASSERT( typeList.size() == sridList.size() ); //find schema item and table item QStandardItem *schemaItem = nullptr; QList<QStandardItem *> schemaItems = findItems( layerProperty.schemaName, Qt::MatchExactly, DbtmSchema ); if ( schemaItems.empty() ) { return; } schemaItem = schemaItems.at( 0 ); int n = schemaItem->rowCount(); for ( int i = 0; i < n; i++ ) { QModelIndex currentChildIndex = indexFromItem( schemaItem->child( i, DbtmSchema ) ); if ( !currentChildIndex.isValid() ) { continue; } QList<QStandardItem *> row; row.reserve( DbtmColumns ); for ( int j = 0; j < DbtmColumns; j++ ) { row << itemFromIndex( currentChildIndex.sibling( i, j ) ); } if ( row[ DbtmTable ]->text() == layerProperty.tableName && row[ DbtmGeomCol ]->text() == layerProperty.geometryColName ) { row[ DbtmSrid ]->setText( layerProperty.srid ); if ( typeList.isEmpty() ) { row[ DbtmType ]->setText( tr( "Select…" ) ); row[ DbtmType ]->setFlags( row[ DbtmType ]->flags() | Qt::ItemIsEditable ); row[ DbtmSrid ]->setText( tr( "Enter…" ) ); row[ DbtmSrid ]->setFlags( row[ DbtmSrid ]->flags() | Qt::ItemIsEditable ); for ( QStandardItem *item : qgis::as_const( row ) ) { item->setFlags( item->flags() | Qt::ItemIsEnabled ); } } else { // update existing row QgsWkbTypes::Type wkbType = QgsDb2TableModel::wkbTypeFromDb2( typeList.at( 0 ) ); row[ DbtmType ]->setIcon( iconForWkbType( wkbType ) ); row[ DbtmType ]->setText( QgsWkbTypes::displayString( wkbType ) ); row[ DbtmType ]->setData( false, Qt::UserRole + 1 ); row[ DbtmType ]->setData( wkbType, Qt::UserRole + 2 ); row[ DbtmSrid ]->setText( sridList.at( 0 ) ); Qt::ItemFlags flags = Qt::ItemIsEnabled; if ( layerProperty.pkCols.size() < 2 ) flags |= Qt::ItemIsSelectable; for ( QStandardItem *item : qgis::as_const( row ) ) { item->setFlags( item->flags() | flags ); } for ( int j = 1; j < typeList.size(); j++ ) { layerProperty.type = typeList[j]; layerProperty.srid = sridList[j]; addTableEntry( layerProperty ); } } } } }
void QgsPgTableModel::addTableEntry( const QgsPostgresLayerProperty &layerProperty ) { QgsDebugMsg( layerProperty.toString() ); // is there already a root item with the given scheme Name? QStandardItem *schemaItem = nullptr; for ( int i = 0; i < layerProperty.size(); i++ ) { QgsWkbTypes::Type wkbType = layerProperty.types[ i ]; int srid = layerProperty.srids[ i ]; if ( wkbType == QgsWkbTypes::Unknown && layerProperty.geometryColName.isEmpty() ) { wkbType = QgsWkbTypes::NoGeometry; } QString tip; bool withTipButSelectable = false; if ( wkbType == QgsWkbTypes::Unknown ) { tip = tr( "Specify a geometry type in the '%1' column" ).arg( tr( "Data Type" ) ); } else if ( wkbType != QgsWkbTypes::NoGeometry && srid == std::numeric_limits<int>::min() ) { tip = tr( "Enter a SRID into the '%1' column" ).arg( tr( "SRID" ) ); } else if ( !layerProperty.pkCols.isEmpty() ) { tip = tr( "Select columns in the '%1' column that uniquely identify features of this layer" ).arg( tr( "Feature id" ) ); withTipButSelectable = true; } QStandardItem *schemaNameItem = new QStandardItem( layerProperty.schemaName ); QStandardItem *typeItem = new QStandardItem( iconForWkbType( wkbType ), wkbType == QgsWkbTypes::Unknown ? tr( "Select…" ) : QgsPostgresConn::displayStringForWkbType( wkbType ) ); typeItem->setData( wkbType == QgsWkbTypes::Unknown, Qt::UserRole + 1 ); typeItem->setData( wkbType, Qt::UserRole + 2 ); if ( wkbType == QgsWkbTypes::Unknown ) typeItem->setFlags( typeItem->flags() | Qt::ItemIsEditable ); QStandardItem *geomTypeItem = new QStandardItem( QgsPostgresConn::displayStringForGeomType( layerProperty.geometryColType ) ); QStandardItem *tableItem = new QStandardItem( layerProperty.tableName ); QStandardItem *commentItem = new QStandardItem( layerProperty.tableComment ); QStandardItem *geomItem = new QStandardItem( layerProperty.geometryColName ); QStandardItem *sridItem = new QStandardItem( wkbType != QgsWkbTypes::NoGeometry ? QString::number( srid ) : QString() ); sridItem->setEditable( wkbType != QgsWkbTypes::NoGeometry && srid == std::numeric_limits<int>::min() ); if ( sridItem->isEditable() ) { sridItem->setText( tr( "Enter…" ) ); sridItem->setFlags( sridItem->flags() | Qt::ItemIsEditable ); } QStandardItem *pkItem = new QStandardItem( QString() ); if ( !layerProperty.pkCols.isEmpty() ) { pkItem->setText( tr( "Select…" ) ); pkItem->setFlags( pkItem->flags() | Qt::ItemIsEditable ); } else pkItem->setFlags( pkItem->flags() & ~Qt::ItemIsEditable ); pkItem->setData( layerProperty.pkCols, Qt::UserRole + 1 ); QStringList defPk( QgsSettings().value( QStringLiteral( "/PostgreSQL/connections/%1/keys/%2/%3" ).arg( mConnName, layerProperty.schemaName, layerProperty.tableName ), QStringList() ).toStringList() ); if ( !layerProperty.pkCols.isEmpty() && defPk.isEmpty() ) { // If we have a view with multiple possible columns to be used as the primary key, for convenience // let's select the first one - this is what the browser dock already does. We risk that a wrong column // will be used, but most of the time we should be fine. defPk = QStringList( layerProperty.pkCols[0] ); } pkItem->setData( defPk, Qt::UserRole + 2 ); if ( !defPk.isEmpty() ) pkItem->setText( defPk.join( ',' ) ); QStandardItem *selItem = new QStandardItem( QString() ); selItem->setFlags( selItem->flags() | Qt::ItemIsUserCheckable ); selItem->setCheckState( Qt::Checked ); selItem->setToolTip( headerData( Columns::DbtmSelectAtId, Qt::Orientation::Horizontal, Qt::ToolTipRole ).toString() ); QStandardItem *checkPkUnicityItem = new QStandardItem( QString() ); checkPkUnicityItem->setFlags( checkPkUnicityItem->flags() | Qt::ItemIsUserCheckable ); // Legacy: default value is determined by project option to trust layer's metadata // TODO: remove this default from QGIS 4 and leave default value to false? // checkPkUnicity has only effect on views and materialized views, so we can safely disable it if ( layerProperty.isView || layerProperty.isMaterializedView ) { checkPkUnicityItem->setCheckState( QgsProject::instance( )->trustLayerMetadata() ? Qt::CheckState::Unchecked : Qt::CheckState::Checked ); checkPkUnicityItem->setToolTip( headerData( Columns::DbtmCheckPkUnicity, Qt::Orientation::Horizontal, Qt::ToolTipRole ).toString() ); } else { checkPkUnicityItem->setCheckState( Qt::CheckState::Unchecked ); checkPkUnicityItem->setFlags( checkPkUnicityItem->flags() & ~ Qt::ItemIsEnabled ); checkPkUnicityItem->setToolTip( tr( "This option is only available for views and materialized views." ) ); } QStandardItem *sqlItem = new QStandardItem( layerProperty.sql ); QList<QStandardItem *> childItemList; childItemList << schemaNameItem; childItemList << tableItem; childItemList << commentItem; childItemList << geomItem; childItemList << geomTypeItem; childItemList << typeItem; childItemList << sridItem; childItemList << pkItem; childItemList << selItem; childItemList << checkPkUnicityItem; childItemList << sqlItem; const auto constChildItemList = childItemList; for ( QStandardItem *item : constChildItemList ) { if ( tip.isEmpty() || withTipButSelectable ) item->setFlags( item->flags() | Qt::ItemIsSelectable ); else item->setFlags( item->flags() & ~Qt::ItemIsSelectable ); if ( 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 ) { QList<QStandardItem *> schemaItems = findItems( layerProperty.schemaName, Qt::MatchExactly, DbtmSchema ); // there is already an item for this schema if ( !schemaItems.isEmpty() ) { schemaItem = schemaItems.at( DbtmSchema ); } else { // create a new toplevel item for this schema schemaItem = new QStandardItem( layerProperty.schemaName ); schemaItem->setFlags( Qt::ItemIsEnabled ); invisibleRootItem()->setChild( invisibleRootItem()->rowCount(), schemaItem ); } } schemaItem->appendRow( childItemList ); ++mTableCount; } }
void QgsPgTableModel::addTableEntry( const QgsPostgresLayerProperty& layerProperty ) { QgsDebugMsg( layerProperty.toString() ); // is there already a root item with the given scheme Name? QStandardItem *schemaItem = 0; for ( int i = 0; i < layerProperty.size(); i++ ) { QGis::WkbType wkbType = layerProperty.types[ i ]; int srid = layerProperty.srids[ i ]; if ( wkbType == QGis::WKBUnknown && layerProperty.geometryColName.isEmpty() ) { wkbType = QGis::WKBNoGeometry; } bool selectable = wkbType == QGis::WKBNoGeometry || ( wkbType != QGis::WKBUnknown && srid != INT_MIN ); QStandardItem *schemaNameItem = new QStandardItem( layerProperty.schemaName ); QStandardItem *typeItem = new QStandardItem( iconForWkbType( wkbType ), wkbType == QGis::WKBUnknown ? tr( "Select..." ) : QgsPostgresConn::displayStringForWkbType( wkbType ) ); typeItem->setData( wkbType == QGis::WKBUnknown, Qt::UserRole + 1 ); typeItem->setData( wkbType, Qt::UserRole + 2 ); if ( wkbType == QGis::WKBUnknown ) typeItem->setFlags( typeItem->flags() | Qt::ItemIsEditable ); QStandardItem *geomTypeItem = new QStandardItem( QgsPostgresConn::displayStringForGeomType( layerProperty.geometryColType ) ); QStandardItem *tableItem = new QStandardItem( layerProperty.tableName ); QStandardItem *geomItem = new QStandardItem( layerProperty.geometryColName ); QStandardItem *sridItem = new QStandardItem( wkbType != QGis::WKBNoGeometry ? QString::number( srid ) : "" ); sridItem->setEditable( wkbType != QGis::WKBNoGeometry && srid == INT_MIN ); if ( sridItem->isEditable() ) { sridItem->setText( tr( "Enter..." ) ); sridItem->setFlags( sridItem->flags() | Qt::ItemIsEditable ); } QString pkCol = ""; if ( layerProperty.pkCols.size() > 0 ) { pkCol = layerProperty.pkCols[0]; } QStandardItem *pkItem = new QStandardItem( pkCol ); if ( layerProperty.pkCols.size() > 1 ) pkItem->setFlags( pkItem->flags() | Qt::ItemIsEditable ); else pkItem->setFlags( pkItem->flags() & ~Qt::ItemIsEditable ); pkItem->setData( layerProperty.pkCols, Qt::UserRole + 1 ); pkItem->setData( pkCol, Qt::UserRole + 2 ); QStandardItem *selItem = new QStandardItem( "" ); selItem->setFlags( selItem->flags() | Qt::ItemIsUserCheckable ); selItem->setCheckState( Qt::Checked ); selItem->setToolTip( tr( "Disable 'Fast Access to Features at ID' capability to force keeping the attribute table in memory (e.g. in case of expensive views)." ) ); QStandardItem* sqlItem = new QStandardItem( layerProperty.sql ); QList<QStandardItem*> childItemList; childItemList << schemaNameItem; childItemList << tableItem; childItemList << geomItem; childItemList << geomTypeItem; childItemList << typeItem; childItemList << sridItem; childItemList << pkItem; childItemList << selItem; childItemList << sqlItem; foreach ( QStandardItem *item, childItemList ) { if ( selectable ) { item->setFlags( item->flags() | Qt::ItemIsSelectable ); } else { item->setFlags( item->flags() & ~Qt::ItemIsSelectable ); } } if ( !schemaItem ) { QList<QStandardItem*> schemaItems = findItems( layerProperty.schemaName, Qt::MatchExactly, dbtmSchema ); // there is already an item for this schema if ( schemaItems.size() > 0 ) { schemaItem = schemaItems.at( dbtmSchema ); } else { // create a new toplevel item for this schema schemaItem = new QStandardItem( layerProperty.schemaName ); schemaItem->setFlags( Qt::ItemIsEnabled ); invisibleRootItem()->setChild( invisibleRootItem()->rowCount(), schemaItem ); } } schemaItem->appendRow( childItemList ); ++mTableCount; } }