Skip to content

Commit f06b01b

Browse files
committedMay 16, 2011
Set data item's parent always in constructor
1 parent e0eb6d8 commit f06b01b

File tree

7 files changed

+29
-28
lines changed

7 files changed

+29
-28
lines changed
 

‎src/browser/qgsbrowsermodel.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010

1111
#include "qgsbrowsermodel.h"
1212

13-
// TODO: bad place, where to put this? qgsproviderregistry?
14-
typedef int dataCapabilities_t();
15-
typedef QgsDataItem * dataItem_t(QString);
1613

1714
QgsBrowserModel::QgsBrowserModel(QObject *parent) :
1815
QAbstractItemModel(parent)
@@ -57,7 +54,7 @@ QgsBrowserModel::QgsBrowserModel(QObject *parent) :
5754
continue;
5855
}
5956

60-
QgsDataItem * item = dataItem ( "" ); // empty path -> top level
57+
QgsDataItem * item = dataItem ( "", NULL ); // empty path -> top level
6158
if ( item )
6259
{
6360
QgsDebugMsg ( "Add new top level item : " + item->mName );
@@ -311,4 +308,4 @@ void QgsBrowserModel::connectItem ( QgsDataItem* item )
311308
this, SLOT(beginRemoveItems( QgsDataItem*, int, int )) );
312309
connect ( item, SIGNAL(endRemoveItems ()),
313310
this, SLOT(endRemoveItems()) );
314-
}
311+
}

‎src/core/qgsdataitem.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ QIcon QgsDataCollectionItem::sDirIcon;
4646
QgsDataItem::QgsDataItem(QgsDataItem::Type type, QgsDataItem* parent, QString name, QString path)
4747
: QObject(parent), mType(type), mParent(parent), mPopulated(false), mName(name), mPath(path)
4848
{
49+
QgsDebugMsg(QString("@ %1 %2 %3").arg(mType).arg((unsigned long)mParent).arg(mPath));
4950
}
5051

5152
QIcon QgsDataItem::icon()
@@ -132,7 +133,6 @@ void QgsDataItem::addChildItem ( QgsDataItem * child, bool refresh )
132133
}
133134

134135
if ( refresh ) emit beginInsertItems ( this, i, i );
135-
child->setParent(this);
136136
mChildren.insert ( i, child );
137137

138138
connect ( child, SIGNAL(beginInsertItems ( QgsDataItem*, int, int )),
@@ -238,8 +238,8 @@ bool QgsLayerItem::equal(const QgsDataItem *other)
238238
}
239239

240240
// ---------------------------------------------------------------------
241-
QgsDataCollectionItem::QgsDataCollectionItem( QgsDataItem::Type type, QgsDataItem* parent, QString name, QString path)
242-
: QgsDataItem( type, parent, name, path)
241+
QgsDataCollectionItem::QgsDataCollectionItem( QgsDataItem* parent, QString name, QString path)
242+
: QgsDataItem( Collection, parent, name, path)
243243
{
244244

245245
if (sDirIcon.isNull())
@@ -261,13 +261,11 @@ QgsDataCollectionItem::~QgsDataCollectionItem()
261261
QVector<QgsDataProvider*> QgsDirectoryItem::mProviders = QVector<QgsDataProvider*>();
262262
QVector<QLibrary*> QgsDirectoryItem::mLibraries = QVector<QLibrary*>();
263263

264-
// TODO: bad place, where to put this? qgsproviderregistry.h?
265-
typedef int dataCapabilities_t();
266-
typedef QgsDataItem * dataItem_t(QString);
267264

268265
QgsDirectoryItem::QgsDirectoryItem(QgsDataItem* parent, QString name, QString path)
269-
: QgsDataCollectionItem(Directory, parent, name, path)
266+
: QgsDataCollectionItem(parent, name, path)
270267
{
268+
mType = Directory;
271269
mIcon = sDirIcon;
272270

273271
if ( mLibraries.size() == 0 ) {
@@ -345,7 +343,7 @@ QVector<QgsDataItem*> QgsDirectoryItem::createChildren( )
345343
continue;
346344
}
347345

348-
QgsDataItem * item = dataItem ( path );
346+
QgsDataItem * item = dataItem ( path, this );
349347
if ( item )
350348
{
351349
children.append( item );

‎src/core/qgsdataitem.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
#include "qgscoordinatereferencesystem.h"
3131

3232
class QgsDataProvider;
33+
class QgsDataItem;
34+
35+
// TODO: bad place, where to put this? qgsproviderregistry.h?
36+
typedef int dataCapabilities_t();
37+
typedef QgsDataItem * dataItem_t(QString, QgsDataItem*);
38+
3339

3440
/** base class for all items in the model */
3541
class CORE_EXPORT QgsDataItem : public QObject
@@ -52,9 +58,6 @@ class CORE_EXPORT QgsDataItem : public QObject
5258

5359
QIcon icon();
5460

55-
// TODO: remove
56-
void setParent ( QgsDataItem *parent ) { mParent = parent; }
57-
5861
//
5962

6063
virtual void refresh();
@@ -161,7 +164,7 @@ class CORE_EXPORT QgsLayerItem : public QgsDataItem
161164
class CORE_EXPORT QgsDataCollectionItem : public QgsDataItem
162165
{
163166
public:
164-
QgsDataCollectionItem( QgsDataItem::Type type, QgsDataItem* parent, QString name, QString path =0);
167+
QgsDataCollectionItem( QgsDataItem* parent, QString name, QString path =0);
165168
~QgsDataCollectionItem();
166169

167170
void setPopulated() { mPopulated = true; }

‎src/providers/gdal/qgsgdalprovider.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,7 +1927,7 @@ bool QgsGdalLayerItem::setCrs ( QgsCoordinateReferenceSystem crs )
19271927
static QStringList extensions = QStringList();
19281928
static QStringList wildcards = QStringList();
19291929

1930-
QGISEXTERN QgsDataItem * dataItem ( QString thePath )
1930+
QGISEXTERN QgsDataItem * dataItem ( QString thePath, QgsDataItem* parentItem )
19311931
{
19321932
if ( thePath.isEmpty() ) return 0;
19331933

@@ -1968,7 +1968,7 @@ QGISEXTERN QgsDataItem * dataItem ( QString thePath )
19681968
QString name = info.fileName();
19691969
QString uri = thePath;
19701970

1971-
QgsLayerItem * item = new QgsGdalLayerItem( 0, name, thePath, uri );
1971+
QgsLayerItem * item = new QgsGdalLayerItem( parentItem, name, thePath, uri );
19721972
return item;
19731973
}
19741974
return 0;

‎src/providers/ogr/qgsogrprovider.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,7 +2227,7 @@ bool QgsOgrLayerItem::setCrs ( QgsCoordinateReferenceSystem crs )
22272227
return false;
22282228
}
22292229

2230-
QGISEXTERN QgsDataItem * dataItem ( QString thePath )
2230+
QGISEXTERN QgsDataItem * dataItem ( QString thePath, QgsDataItem* parentItem )
22312231
{
22322232
if ( thePath.isEmpty() ) return 0;
22332233

@@ -2277,7 +2277,7 @@ QGISEXTERN QgsDataItem * dataItem ( QString thePath )
22772277
QgsDataCollectionItem * collection = 0;
22782278
if ( numLayers > 1 )
22792279
{
2280-
collection = new QgsDataCollectionItem ( QgsDataItem::Collection, 0, info.fileName(), thePath );
2280+
collection = new QgsDataCollectionItem( parentItem, info.fileName(), thePath );
22812281
}
22822282
for ( int i = 0; i < numLayers; i++ )
22832283
{
@@ -2333,7 +2333,7 @@ QGISEXTERN QgsDataItem * dataItem ( QString thePath )
23332333
QString layerUri = thePath + "|layerid=" + QString::number( i );
23342334
QgsDebugMsg( "OGR layer uri : " + layerUri );
23352335

2336-
QgsOgrLayerItem * item = new QgsOgrLayerItem( collection, name, path, layerUri, layerType );
2336+
QgsOgrLayerItem * item = new QgsOgrLayerItem( collection ? collection : parentItem, name, path, layerUri, layerType );
23372337
if ( numLayers == 1 ) return item;
23382338
collection->addChild( item );
23392339
}

‎src/providers/wms/qgswmsprovider.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3051,7 +3051,7 @@ QGISEXTERN int dataCapabilities () {
30513051
}
30523052
// ---------------------------------------------------------------------------
30533053
QgsWMSConnectionItem::QgsWMSConnectionItem ( QgsDataItem* parent, QString name, QString path )
3054-
: QgsDataCollectionItem ( QgsDataItem::Collection, parent, name, path )
3054+
: QgsDataCollectionItem ( parent, name, path )
30553055
{
30563056
}
30573057

@@ -3104,12 +3104,14 @@ bool QgsWMSConnectionItem::equal(const QgsDataItem *other)
31043104
}
31053105
// ---------------------------------------------------------------------------
31063106
QgsWMSLayerItem::QgsWMSLayerItem ( QgsDataItem* parent, QString name, QString path, QgsWmsCapabilitiesProperty capabilitiesProperty, QString connInfo, QgsWmsLayerProperty layerProperty )
3107-
: QgsDataCollectionItem ( QgsDataItem::Collection, parent, name, path ),
3107+
: QgsLayerItem ( parent, name, path, QString(), QgsLayerItem::Raster ),
31083108
mCapabilitiesProperty ( capabilitiesProperty ),
31093109
mConnInfo ( connInfo ),
31103110
mLayerProperty ( layerProperty )
31113111
{
31123112
// Populate everything, it costs nothing, all info about layers is collected
3113+
/*
3114+
// TODO
31133115
foreach ( QgsWmsLayerProperty layerProperty, mLayerProperty.layer )
31143116
{
31153117
// Attention, the name may be empty
@@ -3118,6 +3120,7 @@ QgsWMSLayerItem::QgsWMSLayerItem ( QgsDataItem* parent, QString name, QString pa
31183120
QgsWMSLayerItem * layer = new QgsWMSLayerItem ( this, layerProperty.title, mPath+"/" + pathName, mCapabilitiesProperty, mConnInfo, layerProperty );
31193121
addChild ( layer );
31203122
}
3123+
*/
31213124

31223125
if ( mChildren.size() == 0 )
31233126
{
@@ -3188,7 +3191,7 @@ bool QgsWMSLayerItem::layerInfo(QgsMapLayer::LayerType & type,
31883191

31893192
// ---------------------------------------------------------------------------
31903193
QgsWMSRootItem::QgsWMSRootItem ( QgsDataItem* parent, QString name, QString path )
3191-
: QgsDataCollectionItem ( QgsDataItem::Collection, parent, name, path )
3194+
: QgsDataCollectionItem ( parent, name, path )
31923195
{
31933196
mIcon = QIcon ( getThemePixmap ( "mIconWms.png" ) );
31943197

@@ -3234,9 +3237,9 @@ void QgsWMSRootItem::connectionsChanged()
32343237

32353238
// ---------------------------------------------------------------------------
32363239

3237-
QGISEXTERN QgsDataItem * dataItem ( QString thePath )
3240+
QGISEXTERN QgsDataItem * dataItem ( QString thePath, QgsDataItem* parentItem )
32383241
{
3239-
QgsWMSRootItem * root = new QgsWMSRootItem ( 0, "WMS", "wms:" );
3242+
QgsWMSRootItem * root = new QgsWMSRootItem ( parentItem, "WMS", "wms:" );
32403243

32413244
return root;
32423245
}

‎src/providers/wms/qgswmsprovider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ class QgsWMSConnectionItem : public QgsDataCollectionItem
982982

983983
// WMS Layers may be nested, so that they may be both QgsDataCollectionItem and QgsLayerItem
984984
// We have to use QgsDataCollectionItem and support layer methods if necessary
985-
class QgsWMSLayerItem : public QgsDataCollectionItem
985+
class QgsWMSLayerItem : public QgsLayerItem
986986
{
987987
Q_OBJECT
988988
public:

0 commit comments

Comments
 (0)
Please sign in to comment.