Skip to content
Permalink
Browse files

Hide QgsDataItem members: use getters for access

  • Loading branch information
wonder-sk committed May 16, 2011
1 parent f06b01b commit c2457ae4fdee67750296fad12c4b4afc54e8585b
@@ -90,7 +90,7 @@ void QgsBrowser::expand( QString path, const QModelIndex& index )
QModelIndex idx = mModel->index(i, 0, index);
QgsDataItem* ptr = (QgsDataItem*) idx.internalPointer();

if ( path.indexOf ( ptr->mPath ) == 0 )
if ( path.indexOf ( ptr->path() ) == 0 )
{
treeView->expand( idx );
treeView->scrollTo (idx, QAbstractItemView::PositionAtTop );
@@ -145,7 +145,7 @@ void QgsBrowser::itemClicked(const QModelIndex& index)
paramEnable = true;
}

if (ptr->mType == QgsDataItem::Layer)
if (ptr->type() == QgsDataItem::Layer)
{
QgsLayerItem* item = static_cast<QgsLayerItem*>(ptr);
bool res = layerClicked(item);
@@ -186,7 +186,7 @@ void QgsBrowser::itemClicked(const QModelIndex& index)
tabWidget->setCurrentIndex ( selected );
}

qDebug("clicked: %d %d %s", index.row(), index.column(), ptr->mName.toAscii().data());
qDebug("clicked: %d %d %s", index.row(), index.column(), ptr->name().toAscii().data());
}

bool QgsBrowser::layerClicked(QgsLayerItem* ptr)
@@ -250,7 +250,7 @@ void QgsBrowser::itemDoubleClicked(const QModelIndex& index)
QgsDataItem* ptr = (QgsDataItem*) index.internalPointer();

ptr->doubleClick();
qDebug("doubleclicked: %d %d %s", index.row(), index.column(), ptr->mName.toAscii().data());
qDebug("doubleclicked: %d %d %s", index.row(), index.column(), ptr->name().toAscii().data());
}

void QgsBrowser::itemExpanded(const QModelIndex& index)
@@ -265,8 +265,8 @@ void QgsBrowser::itemExpanded(const QModelIndex& index)
}
*/
// TODO: save separately each type (FS, WMS)
settings.setValue ( "/Browser/lastExpanded", ptr->mPath );
QgsDebugMsg( "last expanded: " + ptr->mPath );
settings.setValue ( "/Browser/lastExpanded", ptr->path() );
QgsDebugMsg( "last expanded: " + ptr->path() );
}

void QgsBrowser::newVectorLayer()
@@ -320,7 +320,7 @@ void QgsBrowser::on_mActionSetProjection_triggered()
// selectedIndexes() is protected

QgsDataItem* ptr = (QgsDataItem*) mIndex.internalPointer();
if ( ptr->mType == QgsDataItem::Layer )
if ( ptr->type() == QgsDataItem::Layer )
{
QgsLayerItem* layerItem = static_cast<QgsLayerItem*>(ptr);
if ( ! layerItem->setCrs ( srs ) )
@@ -490,7 +490,7 @@ void QgsBrowser::refresh( const QModelIndex& index )
if ( index.isValid() )
{
QgsDataItem* item = (QgsDataItem*) index.internalPointer();
QgsDebugMsg( "path = " + item->mPath );
QgsDebugMsg( "path = " + item->path() );
}
mModel->refresh( index );
for ( int i = 0 ; i < mModel->rowCount(index); i++ )
@@ -57,7 +57,7 @@ QgsBrowserModel::QgsBrowserModel(QObject *parent) :
QgsDataItem * item = dataItem ( "", NULL ); // empty path -> top level
if ( item )
{
QgsDebugMsg ( "Add new top level item : " + item->mName );
QgsDebugMsg ( "Add new top level item : " + item->name() );
connectItem(item);
mRootItems << item;
}
@@ -88,7 +88,7 @@ QVariant QgsBrowserModel::data( const QModelIndex & index, int role ) const

if (role == Qt::DisplayRole)
{
return QVariant(ptr->mName);
return QVariant(ptr->name());
}
else if (role == Qt::DecorationRole && index.column() == 0)
{
@@ -162,13 +162,13 @@ QModelIndex QgsBrowserModel::index( int row, int column, const QModelIndex & par
{
// this is ordinary item: return a valid index if the requested child exists
QgsDataItem* ptr = (QgsDataItem*) parent.internalPointer();
if (ptr->mType == QgsDataItem::Directory || ptr->mType == QgsDataItem::Collection)
if (ptr->type() == QgsDataItem::Directory || ptr->type() == QgsDataItem::Collection)
{
// this is a directory: get index of its subdir!
QgsDirectoryItem* di = (QgsDirectoryItem*) ptr;
return createIndex(row, column, di->mChildren.at(row));
return createIndex(row, column, di->children().at(row));
}
if (ptr->mType == QgsDataItem::Layer)
if (ptr->type() == QgsDataItem::Layer)
{
return QModelIndex(); // has no children
}
@@ -184,7 +184,7 @@ QModelIndex QgsBrowserModel::index( QgsDataItem *item )
// Item index
QModelIndex index = QModelIndex();

const QVector<QgsDataItem*>& children = item->mParent ? item->mParent->mChildren : mRootItems;
const QVector<QgsDataItem*>& children = item->parent() ? item->parent()->children() : mRootItems;

Q_ASSERT( children.size() > 0 );
int row = -1;
@@ -213,7 +213,7 @@ QModelIndex QgsBrowserModel::parent( const QModelIndex & index ) const
//qDebug("parent of: %d %d", index.row(), index.column());

QgsDataItem* ptr = (QgsDataItem*) index.internalPointer();
QgsDataItem* parentItem = ptr->mParent;
QgsDataItem* parentItem = ptr->parent();

if (parentItem == NULL)
{
@@ -222,7 +222,7 @@ QModelIndex QgsBrowserModel::parent( const QModelIndex & index ) const
}

const QVector<QgsDataItem*>& children =
parentItem->mParent ? ((QgsDirectoryItem*)parentItem->mParent)->mChildren : mRootItems;
parentItem->parent() ? ((QgsDirectoryItem*)parentItem->parent())->children() : mRootItems;
Q_ASSERT(children.count() > 0);

for (int i = 0; i < children.count(); i++)
@@ -243,13 +243,13 @@ void QgsBrowserModel::refresh( QString path, const QModelIndex& theIndex )
{
QModelIndex idx = index(i, 0, theIndex);
QgsDataItem* ptr = (QgsDataItem*) idx.internalPointer();
if ( ptr->mPath == path )
if ( ptr->path() == path )
{
QgsDebugMsg( "Arrived " + ptr->mPath );
QgsDebugMsg( "Arrived " + ptr->path() );
ptr->refresh();
return;
}
if ( path.indexOf ( ptr->mPath ) == 0 )
if ( path.indexOf ( ptr->path() ) == 0 )
{
refresh( path, idx );
break;
@@ -267,14 +267,14 @@ void QgsBrowserModel::refresh( const QModelIndex& theIndex )
else
{
QgsDataItem* ptr = (QgsDataItem*) theIndex.internalPointer();
QgsDebugMsg( "Refresh " + ptr->mPath );
QgsDebugMsg( "Refresh " + ptr->path() );
ptr->refresh();
}
}

void QgsBrowserModel::beginInsertItems( QgsDataItem* parent, int first, int last )
{
QgsDebugMsg( "parent mPath = " + parent->mPath );
QgsDebugMsg( "parent mPath = " + parent->path() );
QModelIndex idx = index( parent );
if ( !idx.isValid() ) return;
QgsDebugMsg( "valid");
@@ -288,7 +288,7 @@ void QgsBrowserModel::endInsertItems()
}
void QgsBrowserModel::beginRemoveItems( QgsDataItem* parent, int first, int last )
{
QgsDebugMsg( "parent mPath = " + parent->mPath );
QgsDebugMsg( "parent mPath = " + parent->path() );
QModelIndex idx = index( parent );
if ( !idx.isValid() ) return;
beginRemoveRows( idx, first, last );
@@ -46,12 +46,6 @@ 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()
{
return mIcon;
}

// TODO: This is copy from QgisApp, bad
@@ -227,9 +221,8 @@ QgsLayerItem::QgsLayerItem(QgsDataItem* parent, QString name, QString path, QStr
bool QgsLayerItem::equal(const QgsDataItem *other)
{
//QgsDebugMsg ( mPath + " x " + other->mPath );
if ( typeid ( *this ) != typeid ( *other ) )
if ( type() != other->type() )
{
//QgsDebugMsg ( "different typeid" );
return false;
}
//const QgsLayerItem *o = qobject_cast<const QgsLayerItem *> ( other );
@@ -356,12 +349,11 @@ QVector<QgsDataItem*> QgsDirectoryItem::createChildren( )
bool QgsDirectoryItem::equal(const QgsDataItem *other)
{
//QgsDebugMsg ( mPath + " x " + other->mPath );
if ( typeid ( *this ) != typeid ( *other ) )
if ( type() != other->type() )
{
//QgsDebugMsg ( "different typeid" );
return false;
}
return ( mPath == other->mPath );
return ( path() == other->path() );
}

QWidget * QgsDirectoryItem::paramWidget()
@@ -56,8 +56,6 @@ class CORE_EXPORT QgsDataItem : public QObject

int rowCount();

QIcon icon();

//

virtual void refresh();
@@ -88,13 +86,22 @@ class CORE_EXPORT QgsDataItem : public QObject

// members

Type type() const { return mType; }
QgsDataItem* parent() const { return mParent; }
QVector<QgsDataItem*> children() const { return mChildren; }
QIcon icon() const { return mIcon; }
QString name() const { return mName; }
QString path() const { return mPath; }

protected:

Type mType;
QgsDataItem* mParent;
QVector<QgsDataItem*> mChildren; // easier to have it always
bool mPopulated;
QString mName;
QIcon mIcon;
QString mPath; // it is also used to identify item in tree
QIcon mIcon;

public slots:
virtual void doubleClick();
@@ -3095,7 +3095,7 @@ QVector<QgsDataItem*> QgsWMSConnectionItem::createChildren()

bool QgsWMSConnectionItem::equal(const QgsDataItem *other)
{
if ( typeid ( *this ) != typeid ( *other ) )
if ( type() != other->type() )
{
return false;
}

0 comments on commit c2457ae

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