Skip to content
Permalink
Browse files

Set data item's parent always in constructor

  • Loading branch information
wonder-sk committed May 16, 2011
1 parent e0eb6d8 commit f06b01b98ec871860e705e98de6611403d455a20
@@ -10,9 +10,6 @@

#include "qgsbrowsermodel.h"

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

QgsBrowserModel::QgsBrowserModel(QObject *parent) :
QAbstractItemModel(parent)
@@ -57,7 +54,7 @@ QgsBrowserModel::QgsBrowserModel(QObject *parent) :
continue;
}

QgsDataItem * item = dataItem ( "" ); // empty path -> top level
QgsDataItem * item = dataItem ( "", NULL ); // empty path -> top level
if ( item )
{
QgsDebugMsg ( "Add new top level item : " + item->mName );
@@ -311,4 +308,4 @@ void QgsBrowserModel::connectItem ( QgsDataItem* item )
this, SLOT(beginRemoveItems( QgsDataItem*, int, int )) );
connect ( item, SIGNAL(endRemoveItems ()),
this, SLOT(endRemoveItems()) );
}
}
@@ -46,6 +46,7 @@ QIcon QgsDataCollectionItem::sDirIcon;
QgsDataItem::QgsDataItem(QgsDataItem::Type type, QgsDataItem* parent, QString name, QString path)
: QObject(parent), mType(type), mParent(parent), mPopulated(false), mName(name), mPath(path)
{
QgsDebugMsg(QString("@ %1 %2 %3").arg(mType).arg((unsigned long)mParent).arg(mPath));
}

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

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

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

// ---------------------------------------------------------------------
QgsDataCollectionItem::QgsDataCollectionItem( QgsDataItem::Type type, QgsDataItem* parent, QString name, QString path)
: QgsDataItem( type, parent, name, path)
QgsDataCollectionItem::QgsDataCollectionItem( QgsDataItem* parent, QString name, QString path)
: QgsDataItem( Collection, parent, name, path)
{

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

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

QgsDirectoryItem::QgsDirectoryItem(QgsDataItem* parent, QString name, QString path)
: QgsDataCollectionItem(Directory, parent, name, path)
: QgsDataCollectionItem(parent, name, path)
{
mType = Directory;
mIcon = sDirIcon;

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

QgsDataItem * item = dataItem ( path );
QgsDataItem * item = dataItem ( path, this );
if ( item )
{
children.append( item );
@@ -30,6 +30,12 @@
#include "qgscoordinatereferencesystem.h"

class QgsDataProvider;
class QgsDataItem;

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


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

QIcon icon();

// TODO: remove
void setParent ( QgsDataItem *parent ) { mParent = parent; }

//

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

void setPopulated() { mPopulated = true; }
@@ -1927,7 +1927,7 @@ bool QgsGdalLayerItem::setCrs ( QgsCoordinateReferenceSystem crs )
static QStringList extensions = QStringList();
static QStringList wildcards = QStringList();

QGISEXTERN QgsDataItem * dataItem ( QString thePath )
QGISEXTERN QgsDataItem * dataItem ( QString thePath, QgsDataItem* parentItem )
{
if ( thePath.isEmpty() ) return 0;

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

QgsLayerItem * item = new QgsGdalLayerItem( 0, name, thePath, uri );
QgsLayerItem * item = new QgsGdalLayerItem( parentItem, name, thePath, uri );
return item;
}
return 0;
@@ -2227,7 +2227,7 @@ bool QgsOgrLayerItem::setCrs ( QgsCoordinateReferenceSystem crs )
return false;
}

QGISEXTERN QgsDataItem * dataItem ( QString thePath )
QGISEXTERN QgsDataItem * dataItem ( QString thePath, QgsDataItem* parentItem )
{
if ( thePath.isEmpty() ) return 0;

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

QgsOgrLayerItem * item = new QgsOgrLayerItem( collection, name, path, layerUri, layerType );
QgsOgrLayerItem * item = new QgsOgrLayerItem( collection ? collection : parentItem, name, path, layerUri, layerType );
if ( numLayers == 1 ) return item;
collection->addChild( item );
}
@@ -3051,7 +3051,7 @@ QGISEXTERN int dataCapabilities () {
}
// ---------------------------------------------------------------------------
QgsWMSConnectionItem::QgsWMSConnectionItem ( QgsDataItem* parent, QString name, QString path )
: QgsDataCollectionItem ( QgsDataItem::Collection, parent, name, path )
: QgsDataCollectionItem ( parent, name, path )
{
}

@@ -3104,12 +3104,14 @@ bool QgsWMSConnectionItem::equal(const QgsDataItem *other)
}
// ---------------------------------------------------------------------------
QgsWMSLayerItem::QgsWMSLayerItem ( QgsDataItem* parent, QString name, QString path, QgsWmsCapabilitiesProperty capabilitiesProperty, QString connInfo, QgsWmsLayerProperty layerProperty )
: QgsDataCollectionItem ( QgsDataItem::Collection, parent, name, path ),
: QgsLayerItem ( parent, name, path, QString(), QgsLayerItem::Raster ),
mCapabilitiesProperty ( capabilitiesProperty ),
mConnInfo ( connInfo ),
mLayerProperty ( layerProperty )
{
// Populate everything, it costs nothing, all info about layers is collected
/*
// TODO
foreach ( QgsWmsLayerProperty layerProperty, mLayerProperty.layer )
{
// Attention, the name may be empty
@@ -3118,6 +3120,7 @@ QgsWMSLayerItem::QgsWMSLayerItem ( QgsDataItem* parent, QString name, QString pa
QgsWMSLayerItem * layer = new QgsWMSLayerItem ( this, layerProperty.title, mPath+"/" + pathName, mCapabilitiesProperty, mConnInfo, layerProperty );
addChild ( layer );
}
*/

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

// ---------------------------------------------------------------------------
QgsWMSRootItem::QgsWMSRootItem ( QgsDataItem* parent, QString name, QString path )
: QgsDataCollectionItem ( QgsDataItem::Collection, parent, name, path )
: QgsDataCollectionItem ( parent, name, path )
{
mIcon = QIcon ( getThemePixmap ( "mIconWms.png" ) );

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

// ---------------------------------------------------------------------------

QGISEXTERN QgsDataItem * dataItem ( QString thePath )
QGISEXTERN QgsDataItem * dataItem ( QString thePath, QgsDataItem* parentItem )
{
QgsWMSRootItem * root = new QgsWMSRootItem ( 0, "WMS", "wms:" );
QgsWMSRootItem * root = new QgsWMSRootItem ( parentItem, "WMS", "wms:" );

return root;
}
@@ -982,7 +982,7 @@ class QgsWMSConnectionItem : public QgsDataCollectionItem

// WMS Layers may be nested, so that they may be both QgsDataCollectionItem and QgsLayerItem
// We have to use QgsDataCollectionItem and support layer methods if necessary
class QgsWMSLayerItem : public QgsDataCollectionItem
class QgsWMSLayerItem : public QgsLayerItem
{
Q_OBJECT
public:

0 comments on commit f06b01b

Please sign in to comment.
You can’t perform that action at this time.