Skip to content

Commit 09fc7f4

Browse files
committedNov 15, 2011
Fix #4511 - refreshing of Postgres tables
1 parent 295bf55 commit 09fc7f4

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed
 

‎src/providers/postgres/qgspostgresdataitems.cpp

+15-11
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,25 @@ QVector<QgsDataItem*> QgsPGConnectionItem::createChildren()
2929
QString mConnInfo = connection.connectionInfo();
3030
QgsDebugMsg( "mConnInfo = " + mConnInfo );
3131

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

38-
QMap<QString, QVector<QgsPostgresLayerProperty> > schemasMap;
39-
foreach( QgsPostgresLayerProperty layerProperty, mLayerProperties )
39+
// fill the schemas map
40+
mSchemasMap.clear();
41+
foreach( QgsPostgresLayerProperty layerProperty, layerProperties )
4042
{
41-
schemasMap[ layerProperty.schemaName ].push_back( layerProperty );
43+
mSchemasMap[ layerProperty.schemaName ].push_back( layerProperty );
4244
}
4345

44-
QMap<QString, QVector<QgsPostgresLayerProperty> >::const_iterator it = schemasMap.constBegin();
45-
for ( ; it != schemasMap.constEnd(); it++ )
46+
QMap<QString, QVector<QgsPostgresLayerProperty> >::const_iterator it = mSchemasMap.constBegin();
47+
for ( ; it != mSchemasMap.constEnd(); it++ )
4648
{
4749
QgsDebugMsg( "schema: " + it.key() );
48-
QgsPGSchemaItem * schema = new QgsPGSchemaItem( this, it.key(), mPath + "/" + it.key(), mConnInfo, it.value() );
50+
QgsPGSchemaItem * schema = new QgsPGSchemaItem( this, it.key(), mPath + "/" + it.key(), mConnInfo );
4951

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

120122
// ---------------------------------------------------------------------------
121-
QgsPGSchemaItem::QgsPGSchemaItem( QgsDataItem* parent, QString name, QString path, QString connInfo, QVector<QgsPostgresLayerProperty> layerProperties )
123+
QgsPGSchemaItem::QgsPGSchemaItem( QgsDataItem* parent, QString name, QString path, QString connInfo )
122124
: QgsDataCollectionItem( parent, name, path )
123125
{
124126
mIcon = QIcon( getThemePixmap( "mIconDbSchema.png" ) );
125127
mConnInfo = connInfo;
126-
mLayerProperties = layerProperties;
127-
populate();
128128
}
129129

130130
QVector<QgsDataItem*> QgsPGSchemaItem::createChildren()
131131
{
132+
QgsPGConnectionItem* connItem = dynamic_cast<QgsPGConnectionItem*>( mParent );
133+
Q_ASSERT( connItem );
134+
QVector<QgsPostgresLayerProperty> layers = connItem->mSchemasMap.value( mName );
135+
132136
QVector<QgsDataItem*> children;
133137
// Populate everything, it costs nothing, all info about layers is collected
134-
foreach( QgsPostgresLayerProperty layerProperty, mLayerProperties )
138+
foreach( QgsPostgresLayerProperty layerProperty, layers )
135139
{
136140
QgsDebugMsg( "table: " + layerProperty.schemaName + "." + layerProperty.tableName );
137141

‎src/providers/postgres/qgspostgresdataitems.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class QgsPGConnectionItem : public QgsDataCollectionItem
1818
virtual QList<QAction*> actions();
1919

2020
QString mConnInfo;
21-
QVector<QgsPostgresLayerProperty> mLayerProperties;
21+
QMap<QString, QVector<QgsPostgresLayerProperty> > mSchemasMap;
2222

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

5252
QVector<QgsDataItem*> createChildren();
5353

5454
protected:
5555
QString mConnInfo;
56-
QVector<QgsPostgresLayerProperty> mLayerProperties;
5756
};
5857

5958
class QgsPGRootItem : public QgsDataCollectionItem

0 commit comments

Comments
 (0)
Please sign in to comment.