Skip to content

Commit

Permalink
Add error item to facilitate error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Oct 14, 2011
1 parent befb5f6 commit fb6d551
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/core/qgsdataitem.cpp
Expand Up @@ -565,3 +565,16 @@ void QgsDirectoryParamWidget::showHideColumn()
}
settings.setValue( "/dataitem/directoryHiddenColumns", lst );
}


QgsErrorItem::QgsErrorItem( QgsDataItem* parent, QString error, QString path )
: QgsDataItem( QgsDataItem::Error, parent, error, path )
{
mIcon = QIcon( getThemePixmap( "/mIconDelete.png" ) );

mPopulated = true; // no more children
}

QgsErrorItem::~QgsErrorItem()
{
}
19 changes: 19 additions & 0 deletions src/core/qgsdataitem.h
Expand Up @@ -46,6 +46,7 @@ class CORE_EXPORT QgsDataItem : public QObject
Collection,
Directory,
Layer,
Error,
};

QgsDataItem( QgsDataItem::Type type, QgsDataItem* parent, QString name, QString path );
Expand Down Expand Up @@ -225,6 +226,24 @@ class CORE_EXPORT QgsDirectoryItem : public QgsDataCollectionItem
static QVector<QLibrary*> mLibraries;
};

/**
Data item that can be used to report problems (e.g. network error)
*/
class CORE_EXPORT QgsErrorItem : public QgsDataItem
{
Q_OBJECT
public:

QgsErrorItem( QgsDataItem* parent, QString error, QString path );
~QgsErrorItem();

//QVector<QgsDataItem*> createChildren();
//virtual bool equal( const QgsDataItem *other );
};


// ---------

class QgsDirectoryParamWidget : public QTreeWidget
{
Q_OBJECT
Expand Down
3 changes: 3 additions & 0 deletions src/providers/postgres/qgspostgresdataitems.cpp
Expand Up @@ -29,7 +29,10 @@ QVector<QgsDataItem*> QgsPGConnectionItem::createChildren()
QgsDebugMsg( "mConnInfo = " + mConnInfo );

if ( !pgProvider->supportedLayers( mLayerProperties, 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 )
Expand Down
2 changes: 1 addition & 1 deletion src/providers/wfs/qgswfsdataitems.cpp
Expand Up @@ -57,7 +57,7 @@ QVector<QgsDataItem*> QgsWFSConnectionItem::createChildren()
}
else
{
// TODO: return an "error" item
layers.append( new QgsErrorItem( this, tr( "Failed to retrieve layers" ), mPath + "/error" ) );
}

mConn->deleteLater();
Expand Down
3 changes: 3 additions & 0 deletions src/providers/wms/qgswmsdataitems.cpp
Expand Up @@ -31,7 +31,10 @@ QVector<QgsDataItem*> QgsWMSConnectionItem::createChildren()

// Attention: supportedLayers() gives tree leafes, not top level
if ( !wmsProvider->supportedLayers( mLayerProperties ) )
{
children.append( new QgsErrorItem( this, tr( "Failed to retrieve layers" ), mPath + "/error" ) );
return children;
}

QgsWmsCapabilitiesProperty mCapabilitiesProperty = wmsProvider->capabilitiesProperty();
QgsWmsCapabilityProperty capabilityProperty = mCapabilitiesProperty.capability;
Expand Down

0 comments on commit fb6d551

Please sign in to comment.