Skip to content

Commit

Permalink
Fix #4511 - refreshing of Postgres tables
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Nov 15, 2011
1 parent 295bf55 commit 09fc7f4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
26 changes: 15 additions & 11 deletions src/providers/postgres/qgspostgresdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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 );

Expand Down
5 changes: 2 additions & 3 deletions src/providers/postgres/qgspostgresdataitems.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 09fc7f4

Please sign in to comment.