Skip to content
Permalink
Browse files
Fix #4511 - refreshing of Postgres tables
  • Loading branch information
wonder-sk committed Nov 15, 2011
1 parent 295bf55 commit 09fc7f4043b630d77a0b7b85265580b9f03fb339
Showing with 17 additions and 14 deletions.
  1. +15 −11 src/providers/postgres/qgspostgresdataitems.cpp
  2. +2 −3 src/providers/postgres/qgspostgresdataitems.h
@@ -29,23 +29,25 @@ QVector<QgsDataItem*> QgsPGConnectionItem::createChildren()
QString mConnInfo = connection.connectionInfo();
QgsDebugMsg( "mConnInfo = " + mConnInfo );

if ( !pgProvider->supportedLayers( mLayerProperties, true, false, false ) )
QVector<QgsPostgresLayerProperty> layerProperties;
if ( !pgProvider->supportedLayers( layerProperties, true, false, false ) )
{
children.append( new QgsErrorItem( this, tr( "Failed to retrieve layers" ), mPath + "/error" ) );
return children;
}

QMap<QString, QVector<QgsPostgresLayerProperty> > schemasMap;
foreach( QgsPostgresLayerProperty layerProperty, mLayerProperties )
// fill the schemas map
mSchemasMap.clear();
foreach( QgsPostgresLayerProperty layerProperty, layerProperties )
{
schemasMap[ layerProperty.schemaName ].push_back( layerProperty );
mSchemasMap[ layerProperty.schemaName ].push_back( layerProperty );
}

QMap<QString, QVector<QgsPostgresLayerProperty> >::const_iterator it = schemasMap.constBegin();
for ( ; it != schemasMap.constEnd(); it++ )
QMap<QString, QVector<QgsPostgresLayerProperty> >::const_iterator it = mSchemasMap.constBegin();
for ( ; it != mSchemasMap.constEnd(); it++ )
{
QgsDebugMsg( "schema: " + it.key() );
QgsPGSchemaItem * schema = new QgsPGSchemaItem( this, it.key(), mPath + "/" + it.key(), mConnInfo, it.value() );
QgsPGSchemaItem * schema = new QgsPGSchemaItem( this, it.key(), mPath + "/" + it.key(), mConnInfo );

children.append( schema );
}
@@ -118,20 +120,22 @@ QString QgsPGLayerItem::createUri()
}

// ---------------------------------------------------------------------------
QgsPGSchemaItem::QgsPGSchemaItem( QgsDataItem* parent, QString name, QString path, QString connInfo, QVector<QgsPostgresLayerProperty> layerProperties )
QgsPGSchemaItem::QgsPGSchemaItem( QgsDataItem* parent, QString name, QString path, QString connInfo )
: QgsDataCollectionItem( parent, name, path )
{
mIcon = QIcon( getThemePixmap( "mIconDbSchema.png" ) );
mConnInfo = connInfo;
mLayerProperties = layerProperties;
populate();
}

QVector<QgsDataItem*> QgsPGSchemaItem::createChildren()
{
QgsPGConnectionItem* connItem = dynamic_cast<QgsPGConnectionItem*>( mParent );
Q_ASSERT( connItem );
QVector<QgsPostgresLayerProperty> layers = connItem->mSchemasMap.value( mName );

QVector<QgsDataItem*> children;
// Populate everything, it costs nothing, all info about layers is collected
foreach( QgsPostgresLayerProperty layerProperty, mLayerProperties )
foreach( QgsPostgresLayerProperty layerProperty, layers )
{
QgsDebugMsg( "table: " + layerProperty.schemaName + "." + layerProperty.tableName );

@@ -18,7 +18,7 @@ class QgsPGConnectionItem : public QgsDataCollectionItem
virtual QList<QAction*> actions();

QString mConnInfo;
QVector<QgsPostgresLayerProperty> mLayerProperties;
QMap<QString, QVector<QgsPostgresLayerProperty> > mSchemasMap;

public slots:
void editConnection();
@@ -46,14 +46,13 @@ class QgsPGSchemaItem : public QgsDataCollectionItem
Q_OBJECT
public:
QgsPGSchemaItem( QgsDataItem* parent, QString name, QString path,
QString connInfo, QVector<QgsPostgresLayerProperty> layerProperties );
QString connInfo );
~QgsPGSchemaItem();

QVector<QgsDataItem*> createChildren();

protected:
QString mConnInfo;
QVector<QgsPostgresLayerProperty> mLayerProperties;
};

class QgsPGRootItem : public QgsDataCollectionItem

0 comments on commit 09fc7f4

Please sign in to comment.