Skip to content

Commit

Permalink
Hide QgsDataItem members: use getters for access
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed May 16, 2011
1 parent f06b01b commit c2457ae
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 37 deletions.
16 changes: 8 additions & 8 deletions src/browser/qgsbrowser.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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 ) )
Expand Down Expand Up @@ -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++ )
Expand Down
28 changes: 14 additions & 14 deletions src/browser/qgsbrowsermodel.cpp
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
}
Expand All @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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++)
Expand All @@ -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;
Expand All @@ -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");
Expand All @@ -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 );
Expand Down
14 changes: 3 additions & 11 deletions src/core/qgsdataitem.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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()
Expand Down
13 changes: 10 additions & 3 deletions src/core/qgsdataitem.h
Expand Up @@ -56,8 +56,6 @@ class CORE_EXPORT QgsDataItem : public QObject

int rowCount();

QIcon icon();

//

virtual void refresh();
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -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;
}
Expand Down

0 comments on commit c2457ae

Please sign in to comment.