Skip to content

Commit c2457ae

Browse files
committed
Hide QgsDataItem members: use getters for access
1 parent f06b01b commit c2457ae

File tree

5 files changed

+36
-37
lines changed

5 files changed

+36
-37
lines changed

src/browser/qgsbrowser.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void QgsBrowser::expand( QString path, const QModelIndex& index )
9090
QModelIndex idx = mModel->index(i, 0, index);
9191
QgsDataItem* ptr = (QgsDataItem*) idx.internalPointer();
9292

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

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

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

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

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

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

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

322322
QgsDataItem* ptr = (QgsDataItem*) mIndex.internalPointer();
323-
if ( ptr->mType == QgsDataItem::Layer )
323+
if ( ptr->type() == QgsDataItem::Layer )
324324
{
325325
QgsLayerItem* layerItem = static_cast<QgsLayerItem*>(ptr);
326326
if ( ! layerItem->setCrs ( srs ) )
@@ -490,7 +490,7 @@ void QgsBrowser::refresh( const QModelIndex& index )
490490
if ( index.isValid() )
491491
{
492492
QgsDataItem* item = (QgsDataItem*) index.internalPointer();
493-
QgsDebugMsg( "path = " + item->mPath );
493+
QgsDebugMsg( "path = " + item->path() );
494494
}
495495
mModel->refresh( index );
496496
for ( int i = 0 ; i < mModel->rowCount(index); i++ )

src/browser/qgsbrowsermodel.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ QgsBrowserModel::QgsBrowserModel(QObject *parent) :
5757
QgsDataItem * item = dataItem ( "", NULL ); // empty path -> top level
5858
if ( item )
5959
{
60-
QgsDebugMsg ( "Add new top level item : " + item->mName );
60+
QgsDebugMsg ( "Add new top level item : " + item->name() );
6161
connectItem(item);
6262
mRootItems << item;
6363
}
@@ -88,7 +88,7 @@ QVariant QgsBrowserModel::data( const QModelIndex & index, int role ) const
8888

8989
if (role == Qt::DisplayRole)
9090
{
91-
return QVariant(ptr->mName);
91+
return QVariant(ptr->name());
9292
}
9393
else if (role == Qt::DecorationRole && index.column() == 0)
9494
{
@@ -162,13 +162,13 @@ QModelIndex QgsBrowserModel::index( int row, int column, const QModelIndex & par
162162
{
163163
// this is ordinary item: return a valid index if the requested child exists
164164
QgsDataItem* ptr = (QgsDataItem*) parent.internalPointer();
165-
if (ptr->mType == QgsDataItem::Directory || ptr->mType == QgsDataItem::Collection)
165+
if (ptr->type() == QgsDataItem::Directory || ptr->type() == QgsDataItem::Collection)
166166
{
167167
// this is a directory: get index of its subdir!
168168
QgsDirectoryItem* di = (QgsDirectoryItem*) ptr;
169-
return createIndex(row, column, di->mChildren.at(row));
169+
return createIndex(row, column, di->children().at(row));
170170
}
171-
if (ptr->mType == QgsDataItem::Layer)
171+
if (ptr->type() == QgsDataItem::Layer)
172172
{
173173
return QModelIndex(); // has no children
174174
}
@@ -184,7 +184,7 @@ QModelIndex QgsBrowserModel::index( QgsDataItem *item )
184184
// Item index
185185
QModelIndex index = QModelIndex();
186186

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

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

215215
QgsDataItem* ptr = (QgsDataItem*) index.internalPointer();
216-
QgsDataItem* parentItem = ptr->mParent;
216+
QgsDataItem* parentItem = ptr->parent();
217217

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

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

228228
for (int i = 0; i < children.count(); i++)
@@ -243,13 +243,13 @@ void QgsBrowserModel::refresh( QString path, const QModelIndex& theIndex )
243243
{
244244
QModelIndex idx = index(i, 0, theIndex);
245245
QgsDataItem* ptr = (QgsDataItem*) idx.internalPointer();
246-
if ( ptr->mPath == path )
246+
if ( ptr->path() == path )
247247
{
248-
QgsDebugMsg( "Arrived " + ptr->mPath );
248+
QgsDebugMsg( "Arrived " + ptr->path() );
249249
ptr->refresh();
250250
return;
251251
}
252-
if ( path.indexOf ( ptr->mPath ) == 0 )
252+
if ( path.indexOf ( ptr->path() ) == 0 )
253253
{
254254
refresh( path, idx );
255255
break;
@@ -267,14 +267,14 @@ void QgsBrowserModel::refresh( const QModelIndex& theIndex )
267267
else
268268
{
269269
QgsDataItem* ptr = (QgsDataItem*) theIndex.internalPointer();
270-
QgsDebugMsg( "Refresh " + ptr->mPath );
270+
QgsDebugMsg( "Refresh " + ptr->path() );
271271
ptr->refresh();
272272
}
273273
}
274274

275275
void QgsBrowserModel::beginInsertItems( QgsDataItem* parent, int first, int last )
276276
{
277-
QgsDebugMsg( "parent mPath = " + parent->mPath );
277+
QgsDebugMsg( "parent mPath = " + parent->path() );
278278
QModelIndex idx = index( parent );
279279
if ( !idx.isValid() ) return;
280280
QgsDebugMsg( "valid");
@@ -288,7 +288,7 @@ void QgsBrowserModel::endInsertItems()
288288
}
289289
void QgsBrowserModel::beginRemoveItems( QgsDataItem* parent, int first, int last )
290290
{
291-
QgsDebugMsg( "parent mPath = " + parent->mPath );
291+
QgsDebugMsg( "parent mPath = " + parent->path() );
292292
QModelIndex idx = index( parent );
293293
if ( !idx.isValid() ) return;
294294
beginRemoveRows( idx, first, last );

src/core/qgsdataitem.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@ 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));
50-
}
51-
52-
QIcon QgsDataItem::icon()
53-
{
54-
return mIcon;
5549
}
5650

5751
// TODO: This is copy from QgisApp, bad
@@ -227,9 +221,8 @@ QgsLayerItem::QgsLayerItem(QgsDataItem* parent, QString name, QString path, QStr
227221
bool QgsLayerItem::equal(const QgsDataItem *other)
228222
{
229223
//QgsDebugMsg ( mPath + " x " + other->mPath );
230-
if ( typeid ( *this ) != typeid ( *other ) )
224+
if ( type() != other->type() )
231225
{
232-
//QgsDebugMsg ( "different typeid" );
233226
return false;
234227
}
235228
//const QgsLayerItem *o = qobject_cast<const QgsLayerItem *> ( other );
@@ -356,12 +349,11 @@ QVector<QgsDataItem*> QgsDirectoryItem::createChildren( )
356349
bool QgsDirectoryItem::equal(const QgsDataItem *other)
357350
{
358351
//QgsDebugMsg ( mPath + " x " + other->mPath );
359-
if ( typeid ( *this ) != typeid ( *other ) )
352+
if ( type() != other->type() )
360353
{
361-
//QgsDebugMsg ( "different typeid" );
362354
return false;
363355
}
364-
return ( mPath == other->mPath );
356+
return ( path() == other->path() );
365357
}
366358

367359
QWidget * QgsDirectoryItem::paramWidget()

src/core/qgsdataitem.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ class CORE_EXPORT QgsDataItem : public QObject
5656

5757
int rowCount();
5858

59-
QIcon icon();
60-
6159
//
6260

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

8987
// members
9088

89+
Type type() const { return mType; }
90+
QgsDataItem* parent() const { return mParent; }
91+
QVector<QgsDataItem*> children() const { return mChildren; }
92+
QIcon icon() const { return mIcon; }
93+
QString name() const { return mName; }
94+
QString path() const { return mPath; }
95+
96+
protected:
97+
9198
Type mType;
9299
QgsDataItem* mParent;
93100
QVector<QgsDataItem*> mChildren; // easier to have it always
94101
bool mPopulated;
95102
QString mName;
96-
QIcon mIcon;
97103
QString mPath; // it is also used to identify item in tree
104+
QIcon mIcon;
98105

99106
public slots:
100107
virtual void doubleClick();

src/providers/wms/qgswmsprovider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3095,7 +3095,7 @@ QVector<QgsDataItem*> QgsWMSConnectionItem::createChildren()
30953095

30963096
bool QgsWMSConnectionItem::equal(const QgsDataItem *other)
30973097
{
3098-
if ( typeid ( *this ) != typeid ( *other ) )
3098+
if ( type() != other->type() )
30993099
{
31003100
return false;
31013101
}

0 commit comments

Comments
 (0)