Skip to content

Commit fb6d551

Browse files
committed
Add error item to facilitate error handling
1 parent befb5f6 commit fb6d551

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

src/core/qgsdataitem.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -565,3 +565,16 @@ void QgsDirectoryParamWidget::showHideColumn()
565565
}
566566
settings.setValue( "/dataitem/directoryHiddenColumns", lst );
567567
}
568+
569+
570+
QgsErrorItem::QgsErrorItem( QgsDataItem* parent, QString error, QString path )
571+
: QgsDataItem( QgsDataItem::Error, parent, error, path )
572+
{
573+
mIcon = QIcon( getThemePixmap( "/mIconDelete.png" ) );
574+
575+
mPopulated = true; // no more children
576+
}
577+
578+
QgsErrorItem::~QgsErrorItem()
579+
{
580+
}

src/core/qgsdataitem.h

+19
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class CORE_EXPORT QgsDataItem : public QObject
4646
Collection,
4747
Directory,
4848
Layer,
49+
Error,
4950
};
5051

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

229+
/**
230+
Data item that can be used to report problems (e.g. network error)
231+
*/
232+
class CORE_EXPORT QgsErrorItem : public QgsDataItem
233+
{
234+
Q_OBJECT
235+
public:
236+
237+
QgsErrorItem( QgsDataItem* parent, QString error, QString path );
238+
~QgsErrorItem();
239+
240+
//QVector<QgsDataItem*> createChildren();
241+
//virtual bool equal( const QgsDataItem *other );
242+
};
243+
244+
245+
// ---------
246+
228247
class QgsDirectoryParamWidget : public QTreeWidget
229248
{
230249
Q_OBJECT

src/providers/postgres/qgspostgresdataitems.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ QVector<QgsDataItem*> QgsPGConnectionItem::createChildren()
2929
QgsDebugMsg( "mConnInfo = " + mConnInfo );
3030

3131
if ( !pgProvider->supportedLayers( mLayerProperties, true, false, false ) )
32+
{
33+
children.append( new QgsErrorItem( this, tr( "Failed to retrieve layers" ), mPath + "/error" ) );
3234
return children;
35+
}
3336

3437
QMap<QString, QVector<QgsPostgresLayerProperty> > schemasMap;
3538
foreach( QgsPostgresLayerProperty layerProperty, mLayerProperties )

src/providers/wfs/qgswfsdataitems.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ QVector<QgsDataItem*> QgsWFSConnectionItem::createChildren()
5757
}
5858
else
5959
{
60-
// TODO: return an "error" item
60+
layers.append( new QgsErrorItem( this, tr( "Failed to retrieve layers" ), mPath + "/error" ) );
6161
}
6262

6363
mConn->deleteLater();

src/providers/wms/qgswmsdataitems.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ QVector<QgsDataItem*> QgsWMSConnectionItem::createChildren()
3131

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

3639
QgsWmsCapabilitiesProperty mCapabilitiesProperty = wmsProvider->capabilitiesProperty();
3740
QgsWmsCapabilityProperty capabilityProperty = mCapabilitiesProperty.capability;

0 commit comments

Comments
 (0)