QGIS API Documentation  3.2.0-Bonn (bc43194)
qgsbrowsermodel.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsbrowsermodel.cpp
3  ---------------------
4  begin : July 2011
5  copyright : (C) 2011 by Martin Dobias
6  email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #include <QDir>
16 #include <QApplication>
17 #include <QStyle>
18 #include <QtConcurrentMap>
19 #include <QUrl>
20 
21 #include "qgis.h"
22 #include "qgsapplication.h"
23 #include "qgsdataitemprovider.h"
25 #include "qgsdataprovider.h"
26 #include "qgsmimedatautils.h"
27 #include "qgslogger.h"
28 #include "qgsproviderregistry.h"
29 #include "qgsbrowsermodel.h"
30 #include "qgsproject.h"
31 #include "qgssettings.h"
32 
34  : QFutureWatcher( nullptr )
35  , mItem( item )
36 {
37 }
38 
39 // sort function for QList<QgsDataItem*>, e.g. sorted/grouped provider listings
40 static bool cmpByDataItemName_( QgsDataItem *a, QgsDataItem *b )
41 {
42  return QString::localeAwareCompare( a->name(), b->name() ) < 0;
43 }
44 
46  : QAbstractItemModel( parent )
47 
48 {
49 }
50 
52 {
54 }
55 
57 {
58  QString home = QgsProject::instance()->homePath();
59  if ( mProjectHome && mProjectHome->path() == home )
60  return;
61 
62  int idx = mRootItems.indexOf( mProjectHome );
63 
64  // using layoutAboutToBeChanged() was messing expanded items
65  if ( idx >= 0 )
66  {
67  beginRemoveRows( QModelIndex(), idx, idx );
68  mRootItems.remove( idx );
69  endRemoveRows();
70  }
71  delete mProjectHome;
72  mProjectHome = home.isNull() ? nullptr : new QgsProjectHomeItem( nullptr, tr( "Project Home" ), home, "project:" + home );
73  if ( mProjectHome )
74  {
76 
77  beginInsertRows( QModelIndex(), 0, 0 );
78  mRootItems.insert( 0, mProjectHome );
79  endInsertRows();
80  }
81 }
82 
84 {
86 
87  // give the home directory a prominent third place
88  QgsDirectoryItem *item = new QgsDirectoryItem( nullptr, tr( "Home" ), QDir::homePath(), "home:" + QDir::homePath() );
89  item->setSortKey( QStringLiteral( " 2" ) );
90  QStyle *style = QApplication::style();
91  QIcon homeIcon( style->standardPixmap( QStyle::SP_DirHomeIcon ) );
92  item->setIcon( homeIcon );
93  connectItem( item );
94  mRootItems << item;
95 
96  // add favorite directories
97  mFavorites = new QgsFavoritesItem( nullptr, tr( "Favorites" ) );
98  if ( mFavorites )
99  {
102  }
103 
104  // add drives
105  Q_FOREACH ( const QFileInfo &drive, QDir::drives() )
106  {
107  QString path = drive.absolutePath();
108 
109  if ( QgsDirectoryItem::hiddenPath( path ) )
110  continue;
111 
112  QgsDirectoryItem *item = new QgsDirectoryItem( nullptr, path, path );
113  item->setSortKey( QStringLiteral( " 3 %1" ).arg( path ) );
114 
115  connectItem( item );
116  mRootItems << item;
117  }
118 
119 #ifdef Q_OS_MAC
120  QString path = QString( "/Volumes" );
121  QgsDirectoryItem *vols = new QgsDirectoryItem( nullptr, path, path );
122  connectItem( vols );
123  mRootItems << vols;
124 #endif
125 
126  // container for displaying providers as sorted groups (by QgsDataProvider::DataCapability enum)
127  QMap<int, QgsDataItem *> providerMap;
128 
129  Q_FOREACH ( QgsDataItemProvider *pr, QgsApplication::dataItemProviderRegistry()->providers() )
130  {
131  int capabilities = pr->capabilities();
132  if ( capabilities == QgsDataProvider::NoDataCapabilities )
133  {
134  QgsDebugMsgLevel( pr->name() + " does not have any dataCapabilities", 4 );
135  continue;
136  }
137 
138  QgsDataItem *item = pr->createDataItem( QLatin1String( "" ), nullptr ); // empty path -> top level
139  if ( item )
140  {
141  // Forward the signal from the root items to the model (and then to the app)
143  QgsDebugMsgLevel( "Add new top level item : " + item->name(), 4 );
144  connectItem( item );
145  providerMap.insertMulti( capabilities, item );
146  }
147  }
148 
149  // add as sorted groups by QgsDataProvider::DataCapability enum
150  Q_FOREACH ( int key, providerMap.uniqueKeys() )
151  {
152  QList<QgsDataItem *> providerGroup = providerMap.values( key );
153  if ( providerGroup.size() > 1 )
154  {
155  std::sort( providerGroup.begin(), providerGroup.end(), cmpByDataItemName_ );
156  }
157 
158  Q_FOREACH ( QgsDataItem *ditem, providerGroup )
159  {
160  mRootItems << ditem;
161  }
162  }
163 }
164 
166 {
167  Q_FOREACH ( QgsDataItem *item, mRootItems )
168  {
169  delete item;
170  }
171 
172  mRootItems.clear();
173 }
174 
176 {
177  if ( ! mInitialized )
178  {
182  addRootItems();
183  mInitialized = true;
184  }
185 }
186 
187 
188 Qt::ItemFlags QgsBrowserModel::flags( const QModelIndex &index ) const
189 {
190  if ( !index.isValid() )
191  return Qt::ItemFlags();
192 
193  Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
194 
195  QgsDataItem *ptr = reinterpret_cast< QgsDataItem * >( index.internalPointer() );
196  if ( ptr->hasDragEnabled() )
197  flags |= Qt::ItemIsDragEnabled;
198 
199  if ( ptr->acceptDrop() )
200  flags |= Qt::ItemIsDropEnabled;
201  return flags;
202 }
203 
204 QVariant QgsBrowserModel::data( const QModelIndex &index, int role ) const
205 {
206  if ( !index.isValid() )
207  return QVariant();
208 
209  QgsDataItem *item = dataItem( index );
210  if ( !item )
211  {
212  return QVariant();
213  }
214  else if ( role == Qt::DisplayRole )
215  {
216  return item->name();
217  }
218  else if ( role == QgsBrowserModel::SortRole )
219  {
220  return item->sortKey();
221  }
222  else if ( role == Qt::ToolTipRole )
223  {
224  return item->toolTip();
225  }
226  else if ( role == Qt::DecorationRole && index.column() == 0 )
227  {
228  return item->icon();
229  }
230  else if ( role == QgsBrowserModel::PathRole )
231  {
232  return item->path();
233  }
234  else if ( role == QgsBrowserModel::CommentRole )
235  {
236  if ( item->type() == QgsDataItem::Layer )
237  {
238  QgsLayerItem *lyrItem = qobject_cast<QgsLayerItem *>( item );
239  return lyrItem->comments();
240  }
241  return QVariant();
242  }
243  else
244  {
245  // unsupported role
246  return QVariant();
247  }
248 }
249 
250 QVariant QgsBrowserModel::headerData( int section, Qt::Orientation orientation, int role ) const
251 {
252  Q_UNUSED( section );
253  if ( orientation == Qt::Horizontal && role == Qt::DisplayRole )
254  {
255  return QVariant( "header" );
256  }
257 
258  return QVariant();
259 }
260 
261 int QgsBrowserModel::rowCount( const QModelIndex &parent ) const
262 {
263  //QgsDebugMsg(QString("isValid = %1 row = %2 column = %3").arg(parent.isValid()).arg(parent.row()).arg(parent.column()));
264 
265  if ( !parent.isValid() )
266  {
267  // root item: its children are top level items
268  return mRootItems.count(); // mRoot
269  }
270  else
271  {
272  // ordinary item: number of its children
273  QgsDataItem *item = dataItem( parent );
274  //if ( item ) QgsDebugMsg(QString("path = %1 rowCount = %2").arg(item->path()).arg(item->rowCount()) );
275  return item ? item->rowCount() : 0;
276  }
277 }
278 
279 bool QgsBrowserModel::hasChildren( const QModelIndex &parent ) const
280 {
281  if ( !parent.isValid() )
282  return true; // root item: its children are top level items
283 
284  QgsDataItem *item = dataItem( parent );
285  return item && item->hasChildren();
286 }
287 
288 int QgsBrowserModel::columnCount( const QModelIndex &parent ) const
289 {
290  Q_UNUSED( parent );
291  return 1;
292 }
293 
294 QModelIndex QgsBrowserModel::findPath( const QString &path, Qt::MatchFlag matchFlag )
295 {
296  return findPath( this, path, matchFlag );
297 }
298 
299 QModelIndex QgsBrowserModel::findPath( QAbstractItemModel *model, const QString &path, Qt::MatchFlag matchFlag )
300 {
301  if ( !model )
302  return QModelIndex();
303 
304  QModelIndex index; // starting from root
305  bool foundChild = true;
306 
307  while ( foundChild )
308  {
309  foundChild = false; // assume that the next child item will not be found
310 
311  for ( int i = 0; i < model->rowCount( index ); i++ )
312  {
313  QModelIndex idx = model->index( i, 0, index );
314 
315  QString itemPath = model->data( idx, PathRole ).toString();
316  if ( itemPath == path )
317  {
318  QgsDebugMsgLevel( "Arrived " + itemPath, 4 );
319  return idx; // we have found the item we have been looking for
320  }
321 
322  // paths are slash separated identifier
323  if ( path.startsWith( itemPath + '/' ) )
324  {
325  foundChild = true;
326  index = idx;
327  break;
328  }
329  }
330  }
331 
332  if ( matchFlag == Qt::MatchStartsWith )
333  return index;
334 
335  QgsDebugMsgLevel( "path not found", 4 );
336  return QModelIndex(); // not found
337 }
338 
340 {
341  // TODO: put items creating currently children in threads to deleteLater (does not seem urget because reload() is not used in QGIS)
342  beginResetModel();
343  removeRootItems();
344  addRootItems();
345  endResetModel();
346 }
347 
348 QModelIndex QgsBrowserModel::index( int row, int column, const QModelIndex &parent ) const
349 {
350  if ( column < 0 || column >= columnCount() || row < 0 )
351  return QModelIndex();
352 
353  QgsDataItem *p = dataItem( parent );
354  const QVector<QgsDataItem *> &items = p ? p->children() : mRootItems;
355  QgsDataItem *item = items.value( row, nullptr );
356  return item ? createIndex( row, column, item ) : QModelIndex();
357 }
358 
359 QModelIndex QgsBrowserModel::parent( const QModelIndex &index ) const
360 {
361  QgsDataItem *item = dataItem( index );
362  if ( !item )
363  return QModelIndex();
364 
365  return findItem( item->parent() );
366 }
367 
369 {
370  const QVector<QgsDataItem *> &items = parent ? parent->children() : mRootItems;
371 
372  for ( int i = 0; i < items.size(); i++ )
373  {
374  if ( items[i] == item )
375  return createIndex( i, 0, item );
376 
377  QModelIndex childIndex = findItem( item, items[i] );
378  if ( childIndex.isValid() )
379  return childIndex;
380  }
381 
382  return QModelIndex();
383 }
384 
386 {
387  QgsDebugMsgLevel( "parent mPath = " + parent->path(), 3 );
388  QModelIndex idx = findItem( parent );
389  if ( !idx.isValid() )
390  return;
391  QgsDebugMsgLevel( "valid", 3 );
392  beginInsertRows( idx, first, last );
393  QgsDebugMsgLevel( "end", 3 );
394 }
396 {
397  QgsDebugMsgLevel( "Entered", 3 );
398  endInsertRows();
399 }
401 {
402  QgsDebugMsgLevel( "parent mPath = " + parent->path(), 3 );
403  QModelIndex idx = findItem( parent );
404  if ( !idx.isValid() )
405  return;
406  beginRemoveRows( idx, first, last );
407 }
409 {
410  QgsDebugMsgLevel( "Entered", 3 );
411  endRemoveRows();
412 }
414 {
415  QgsDebugMsgLevel( "Entered", 3 );
416  QModelIndex idx = findItem( item );
417  if ( !idx.isValid() )
418  return;
419  emit dataChanged( idx, idx );
420 }
422 {
423  if ( !item )
424  return;
425  QModelIndex idx = findItem( item );
426  if ( !idx.isValid() )
427  return;
428  QgsDebugMsgLevel( QString( "item %1 state changed %2 -> %3" ).arg( item->path() ).arg( oldState ).arg( item->state() ), 4 );
429  emit stateChanged( idx, oldState );
430 }
431 
433 {
434  connect( item, &QgsDataItem::beginInsertItems,
436  connect( item, &QgsDataItem::endInsertItems,
438  connect( item, &QgsDataItem::beginRemoveItems,
440  connect( item, &QgsDataItem::endRemoveItems,
442  connect( item, &QgsDataItem::dataChanged,
444  connect( item, &QgsDataItem::stateChanged,
446 
447  // if it's a collection item, also forwards connectionsChanged
448  QgsDataCollectionItem *collectionItem = dynamic_cast<QgsDataCollectionItem *>( item );
449  if ( collectionItem )
451 }
452 
453 QStringList QgsBrowserModel::mimeTypes() const
454 {
455  QStringList types;
456  // In theory the mime type convention is: application/x-vnd.<vendor>.<application>.<type>
457  // but it seems a bit over formalized. Would be an application/x-qgis-uri better?
458  types << QStringLiteral( "application/x-vnd.qgis.qgis.uri" );
459  return types;
460 }
461 
462 QMimeData *QgsBrowserModel::mimeData( const QModelIndexList &indexes ) const
463 {
465  Q_FOREACH ( const QModelIndex &index, indexes )
466  {
467  if ( index.isValid() )
468  {
469  QgsDataItem *ptr = reinterpret_cast< QgsDataItem * >( index.internalPointer() );
470  QgsMimeDataUtils::Uri uri = ptr->mimeUri();
471  if ( uri.isValid() )
472  lst.append( uri );
473  }
474  }
475  return QgsMimeDataUtils::encodeUriList( lst );
476 }
477 
478 bool QgsBrowserModel::dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent )
479 {
480  Q_UNUSED( row );
481  Q_UNUSED( column );
482 
483  QgsDataItem *destItem = dataItem( parent );
484  if ( !destItem )
485  {
486  QgsDebugMsgLevel( "DROP PROBLEM!", 4 );
487  return false;
488  }
489 
490  return destItem->handleDrop( data, action );
491 }
492 
493 QgsDataItem *QgsBrowserModel::dataItem( const QModelIndex &idx ) const
494 {
495  void *v = idx.internalPointer();
496  QgsDataItem *d = reinterpret_cast<QgsDataItem *>( v );
497  Q_ASSERT( !v || d );
498  return d;
499 }
500 
501 bool QgsBrowserModel::canFetchMore( const QModelIndex &parent ) const
502 {
503  QgsDataItem *item = dataItem( parent );
504  // if ( item )
505  // QgsDebugMsg( QString( "path = %1 canFetchMore = %2" ).arg( item->path() ).arg( item && ! item->isPopulated() ) );
506  return ( item && item->state() == QgsDataItem::NotPopulated );
507 }
508 
509 void QgsBrowserModel::fetchMore( const QModelIndex &parent )
510 {
511  QgsDataItem *item = dataItem( parent );
512 
513  if ( !item || item->state() == QgsDataItem::Populating || item->state() == QgsDataItem::Populated )
514  return;
515 
516  QgsDebugMsgLevel( "path = " + item->path(), 4 );
517 
518  item->populate();
519 }
520 
521 /* Refresh dir path */
522 void QgsBrowserModel::refresh( const QString &path )
523 {
524  QModelIndex index = findPath( path );
525  refresh( index );
526 }
527 
528 /* Refresh item */
529 void QgsBrowserModel::refresh( const QModelIndex &index )
530 {
531  QgsDataItem *item = dataItem( index );
532  if ( !item || item->state() == QgsDataItem::Populating )
533  return;
534 
535  QgsDebugMsgLevel( "Refresh " + item->path(), 4 );
536 
537  item->refresh();
538 }
539 
540 void QgsBrowserModel::addFavoriteDirectory( const QString &directory, const QString &name )
541 {
542  Q_ASSERT( mFavorites );
543  mFavorites->addDirectory( directory, name );
544 }
545 
546 void QgsBrowserModel::removeFavorite( const QModelIndex &index )
547 {
548  QgsDirectoryItem *item = dynamic_cast<QgsDirectoryItem *>( dataItem( index ) );
549  if ( !item )
550  return;
551 
552  mFavorites->removeDirectory( item );
553 }
554 
556 {
557  QgsSettings settings;
558  QStringList hiddenItems = settings.value( QStringLiteral( "browser/hiddenPaths" ),
559  QStringList() ).toStringList();
560  int idx = hiddenItems.indexOf( item->path() );
561  if ( idx != -1 )
562  {
563  hiddenItems.removeAt( idx );
564  }
565  else
566  {
567  hiddenItems << item->path();
568  }
569  settings.setValue( QStringLiteral( "browser/hiddenPaths" ), hiddenItems );
570  if ( item->parent() )
571  {
572  item->parent()->deleteChildItem( item );
573  }
574  else
575  {
576  int i = mRootItems.indexOf( item );
577  beginRemoveRows( QModelIndex(), i, i );
578  mRootItems.remove( i );
579  item->deleteLater();
580  endRemoveRows();
581  }
582 }
A Collection: logical collection of layers or subcollections, e.g.
Definition: qgsdataitem.h:514
virtual QVariant sortKey() const
Returns the sorting key for the item.
void beginInsertItems(QgsDataItem *parent, int first, int last)
QString path() const
Definition: qgsdataitem.h:266
void setSortKey(const QVariant &key)
Sets a custom sorting key for the item.
bool canFetchMore(const QModelIndex &parent) const override
QString name() const
Returns the name of the item (the displayed text for the item).
Definition: qgsdataitem.h:257
void connectionsChanged()
Connections changed in the browser, forwarded to the widget and used to notify the provider dialogs o...
void dataChanged(QgsDataItem *item)
QString toolTip() const
Definition: qgsdataitem.h:298
void hidePath(QgsDataItem *item)
Hide the given path in the browser model.
QgsBrowserModel(QObject *parent=nullptr)
Constructor for QgsBrowserModel, with the specified parent object.
This class is a composition of two QSettings instances:
Definition: qgssettings.h:58
virtual QgsDataItem * createDataItem(const QString &path, QgsDataItem *parentItem)=0
Create a new instance of QgsDataItem (or null) for given path and parent item.
void connectionsChanged()
Emitted when the provider&#39;s connections of the child items have changed This signal is normally forwa...
int rowCount(const QModelIndex &parent=QModelIndex()) const override
void fetchMore(const QModelIndex &parent) override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
virtual bool handleDrop(const QMimeData *, Qt::DropAction)
Attempts to process the mime data dropped on this item.
Definition: qgsdataitem.h:180
QModelIndex findPath(const QString &path, Qt::MatchFlag matchFlag=Qt::MatchExactly)
Returns index of item with given path.
void beginRemoveItems(QgsDataItem *parent, int first, int last)
virtual QIcon icon()
void connectItem(QgsDataItem *item)
Type type() const
Definition: qgsdataitem.h:238
static QMimeData * encodeUriList(const UriList &layers)
void setIcon(const QIcon &icon)
Definition: qgsdataitem.h:294
bool isValid() const
Returns whether the object contains valid data.
void itemStateChanged(QgsDataItem *item, QgsDataItem::State oldState)
QStringList mimeTypes() const override
void projectSaved()
Emitted when the project file has been written and closed.
bool hasChildren(const QModelIndex &parent=QModelIndex()) const override
void endRemoveItems()
State state() const
Item path used to access path in the tree, see QgsDataItem::mPath.
QString homePath
Definition: qgsproject.h:90
QgsDirectoryItem * mProjectHome
static void deleteLater(QVector< QgsDataItem *> &items)
QgsDataItem * parent() const
Gets item parent.
Definition: qgsdataitem.h:243
QgsFavoritesItem * mFavorites
void beginRemoveItems(QgsDataItem *parent, int first, int last)
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
QModelIndex parent(const QModelIndex &index) const override
QVector< QgsDataItem * > mRootItems
void readProject(const QDomDocument &)
Emitted when a project is being read.
Children not yet created.
Definition: qgsdataitem.h:104
Creating children in separate thread (populating or refreshing)
Definition: qgsdataitem.h:105
void initialize()
Delayed initialization, needed because the provider registry must be already populated.
QgsDataItem * dataItem(const QModelIndex &idx) const
void removeFavorite(const QModelIndex &index)
Removes a favorite directory from its corresponding model index.
virtual bool hasDragEnabled() const
Returns true if the item may be dragged.
Definition: qgsdataitem.h:197
virtual int capabilities()=0
Returns combination of flags from QgsDataProvider::DataCapabilities.
virtual QgsMimeDataUtils::Uri mimeUri() const
Returns mime URI for the data item.
Definition: qgsdataitem.h:205
QgsBrowserWatcher(QgsDataItem *item)
bool hasChildren()
static bool hiddenPath(const QString &path)
Check if the given path is hidden from the browser model.
void reload()
Reload the whole model.
A directory: contains subdirectories and layers.
Definition: qgsdataitem.h:531
Base class for all items in the model.
Definition: qgsdataitem.h:49
Custom sort role, see QgsDataItem::sortKey()
QVector< QgsDataItem * > children() const
Definition: qgsdataitem.h:249
QModelIndex findItem(QgsDataItem *item, QgsDataItem *parent=nullptr) const
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
~QgsBrowserModel() override
void addFavoriteDirectory(const QString &directory, const QString &name=QString())
Adds a directory to the favorites group.
void beginInsertItems(QgsDataItem *parent, int first, int last)
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
Contains various Favorites directories.
Definition: qgsdataitem.h:647
void removeDirectory(QgsDirectoryItem *item)
Removes an existing directory from the favorites group.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
void addDirectory(const QString &directory, const QString &name=QString())
Adds a new directory to the favorites group.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:391
int columnCount(const QModelIndex &parent=QModelIndex()) const override
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
void stateChanged(const QModelIndex &index, QgsDataItem::State oldState)
Emitted when item children fetch was finished.
void refresh(const QString &path)
Refresh item specified by path.
QList< QgsMimeDataUtils::Uri > UriList
void endInsertItems()
QMimeData * mimeData(const QModelIndexList &indexes) const override
void homePathChanged()
Emitted when the home path of the project changes.
Item that represents a layer that can be opened with one of the providers.
Definition: qgsdataitem.h:409
virtual void deleteChildItem(QgsDataItem *child)
Removes and deletes a child item, emitting relevant signals to the model.
virtual QString name()=0
Human-readable name of the provider name.
void itemDataChanged(QgsDataItem *item)
Qt::ItemFlags flags(const QModelIndex &index) const override
virtual void populate(const QVector< QgsDataItem *> &children)
Children created.
Definition: qgsdataitem.h:106
virtual bool acceptDrop()
Returns whether the item accepts drag and dropped layers - e.g.
Definition: qgsdataitem.h:173
virtual QString comments() const
Returns comments of the layer.
Definition: qgsdataitem.h:468
void addRootItems()
Populates the model.
static QgsDataItemProviderRegistry * dataItemProviderRegistry()
Returns the application&#39;s data item provider registry, which keeps a list of data item providers that...
virtual void refresh(const QVector< QgsDataItem *> &children)
Refresh the items from a specified list of child items.
This is the interface for those who want to add custom data items to the browser tree.
void stateChanged(QgsDataItem *item, QgsDataItem::State oldState)