QGIS API Documentation  3.0.2-Girona (307d082)
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  {
181  addRootItems();
182  mInitialized = true;
183  }
184 }
185 
186 
187 Qt::ItemFlags QgsBrowserModel::flags( const QModelIndex &index ) const
188 {
189  if ( !index.isValid() )
190  return Qt::ItemFlags();
191 
192  Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
193 
194  QgsDataItem *ptr = reinterpret_cast< QgsDataItem * >( index.internalPointer() );
195  if ( ptr->hasDragEnabled() )
196  flags |= Qt::ItemIsDragEnabled;
197 
198  if ( ptr->acceptDrop() )
199  flags |= Qt::ItemIsDropEnabled;
200  return flags;
201 }
202 
203 QVariant QgsBrowserModel::data( const QModelIndex &index, int role ) const
204 {
205  if ( !index.isValid() )
206  return QVariant();
207 
208  QgsDataItem *item = dataItem( index );
209  if ( !item )
210  {
211  return QVariant();
212  }
213  else if ( role == Qt::DisplayRole )
214  {
215  return item->name();
216  }
217  else if ( role == QgsBrowserModel::SortRole )
218  {
219  return item->sortKey();
220  }
221  else if ( role == Qt::ToolTipRole )
222  {
223  return item->toolTip();
224  }
225  else if ( role == Qt::DecorationRole && index.column() == 0 )
226  {
227  return item->icon();
228  }
229  else if ( role == QgsBrowserModel::PathRole )
230  {
231  return item->path();
232  }
233  else if ( role == QgsBrowserModel::CommentRole )
234  {
235  if ( item->type() == QgsDataItem::Layer )
236  {
237  QgsLayerItem *lyrItem = qobject_cast<QgsLayerItem *>( item );
238  return lyrItem->comments();
239  }
240  return QVariant();
241  }
242  else
243  {
244  // unsupported role
245  return QVariant();
246  }
247 }
248 
249 QVariant QgsBrowserModel::headerData( int section, Qt::Orientation orientation, int role ) const
250 {
251  Q_UNUSED( section );
252  if ( orientation == Qt::Horizontal && role == Qt::DisplayRole )
253  {
254  return QVariant( "header" );
255  }
256 
257  return QVariant();
258 }
259 
260 int QgsBrowserModel::rowCount( const QModelIndex &parent ) const
261 {
262  //QgsDebugMsg(QString("isValid = %1 row = %2 column = %3").arg(parent.isValid()).arg(parent.row()).arg(parent.column()));
263 
264  if ( !parent.isValid() )
265  {
266  // root item: its children are top level items
267  return mRootItems.count(); // mRoot
268  }
269  else
270  {
271  // ordinary item: number of its children
272  QgsDataItem *item = dataItem( parent );
273  //if ( item ) QgsDebugMsg(QString("path = %1 rowCount = %2").arg(item->path()).arg(item->rowCount()) );
274  return item ? item->rowCount() : 0;
275  }
276 }
277 
278 bool QgsBrowserModel::hasChildren( const QModelIndex &parent ) const
279 {
280  if ( !parent.isValid() )
281  return true; // root item: its children are top level items
282 
283  QgsDataItem *item = dataItem( parent );
284  return item && item->hasChildren();
285 }
286 
287 int QgsBrowserModel::columnCount( const QModelIndex &parent ) const
288 {
289  Q_UNUSED( parent );
290  return 1;
291 }
292 
293 QModelIndex QgsBrowserModel::findPath( const QString &path, Qt::MatchFlag matchFlag )
294 {
295  return findPath( this, path, matchFlag );
296 }
297 
298 QModelIndex QgsBrowserModel::findPath( QAbstractItemModel *model, const QString &path, Qt::MatchFlag matchFlag )
299 {
300  if ( !model )
301  return QModelIndex();
302 
303  QModelIndex index; // starting from root
304  bool foundChild = true;
305 
306  while ( foundChild )
307  {
308  foundChild = false; // assume that the next child item will not be found
309 
310  for ( int i = 0; i < model->rowCount( index ); i++ )
311  {
312  QModelIndex idx = model->index( i, 0, index );
313 
314  QString itemPath = model->data( idx, PathRole ).toString();
315  if ( itemPath == path )
316  {
317  QgsDebugMsgLevel( "Arrived " + itemPath, 4 );
318  return idx; // we have found the item we have been looking for
319  }
320 
321  // paths are slash separated identifier
322  if ( path.startsWith( itemPath + '/' ) )
323  {
324  foundChild = true;
325  index = idx;
326  break;
327  }
328  }
329  }
330 
331  if ( matchFlag == Qt::MatchStartsWith )
332  return index;
333 
334  QgsDebugMsgLevel( "path not found", 4 );
335  return QModelIndex(); // not found
336 }
337 
339 {
340  // TODO: put items creating currently children in threads to deleteLater (does not seem urget because reload() is not used in QGIS)
341  beginResetModel();
342  removeRootItems();
343  addRootItems();
344  endResetModel();
345 }
346 
347 QModelIndex QgsBrowserModel::index( int row, int column, const QModelIndex &parent ) const
348 {
349  if ( column < 0 || column >= columnCount() || row < 0 )
350  return QModelIndex();
351 
352  QgsDataItem *p = dataItem( parent );
353  const QVector<QgsDataItem *> &items = p ? p->children() : mRootItems;
354  QgsDataItem *item = items.value( row, nullptr );
355  return item ? createIndex( row, column, item ) : QModelIndex();
356 }
357 
358 QModelIndex QgsBrowserModel::parent( const QModelIndex &index ) const
359 {
360  QgsDataItem *item = dataItem( index );
361  if ( !item )
362  return QModelIndex();
363 
364  return findItem( item->parent() );
365 }
366 
368 {
369  const QVector<QgsDataItem *> &items = parent ? parent->children() : mRootItems;
370 
371  for ( int i = 0; i < items.size(); i++ )
372  {
373  if ( items[i] == item )
374  return createIndex( i, 0, item );
375 
376  QModelIndex childIndex = findItem( item, items[i] );
377  if ( childIndex.isValid() )
378  return childIndex;
379  }
380 
381  return QModelIndex();
382 }
383 
385 {
386  QgsDebugMsgLevel( "parent mPath = " + parent->path(), 3 );
387  QModelIndex idx = findItem( parent );
388  if ( !idx.isValid() )
389  return;
390  QgsDebugMsgLevel( "valid", 3 );
391  beginInsertRows( idx, first, last );
392  QgsDebugMsgLevel( "end", 3 );
393 }
395 {
396  QgsDebugMsgLevel( "Entered", 3 );
397  endInsertRows();
398 }
400 {
401  QgsDebugMsgLevel( "parent mPath = " + parent->path(), 3 );
402  QModelIndex idx = findItem( parent );
403  if ( !idx.isValid() )
404  return;
405  beginRemoveRows( idx, first, last );
406 }
408 {
409  QgsDebugMsgLevel( "Entered", 3 );
410  endRemoveRows();
411 }
413 {
414  QgsDebugMsgLevel( "Entered", 3 );
415  QModelIndex idx = findItem( item );
416  if ( !idx.isValid() )
417  return;
418  emit dataChanged( idx, idx );
419 }
421 {
422  if ( !item )
423  return;
424  QModelIndex idx = findItem( item );
425  if ( !idx.isValid() )
426  return;
427  QgsDebugMsgLevel( QString( "item %1 state changed %2 -> %3" ).arg( item->path() ).arg( oldState ).arg( item->state() ), 4 );
428  emit stateChanged( idx, oldState );
429 }
430 
432 {
433  connect( item, &QgsDataItem::beginInsertItems,
435  connect( item, &QgsDataItem::endInsertItems,
437  connect( item, &QgsDataItem::beginRemoveItems,
439  connect( item, &QgsDataItem::endRemoveItems,
441  connect( item, &QgsDataItem::dataChanged,
443  connect( item, &QgsDataItem::stateChanged,
445 
446  // if it's a collection item, also forwards connectionsChanged
447  QgsDataCollectionItem *collectionItem = dynamic_cast<QgsDataCollectionItem *>( item );
448  if ( collectionItem )
450 }
451 
452 QStringList QgsBrowserModel::mimeTypes() const
453 {
454  QStringList types;
455  // In theory the mime type convention is: application/x-vnd.<vendor>.<application>.<type>
456  // but it seems a bit over formalized. Would be an application/x-qgis-uri better?
457  types << QStringLiteral( "application/x-vnd.qgis.qgis.uri" );
458  return types;
459 }
460 
461 QMimeData *QgsBrowserModel::mimeData( const QModelIndexList &indexes ) const
462 {
464  Q_FOREACH ( const QModelIndex &index, indexes )
465  {
466  if ( index.isValid() )
467  {
468  QgsDataItem *ptr = reinterpret_cast< QgsDataItem * >( index.internalPointer() );
469  if ( ptr->type() == QgsDataItem::Project )
470  {
471  QMimeData *mimeData = new QMimeData();
472  QUrl url = QUrl::fromLocalFile( ptr->path() );
473  QList<QUrl> urls;
474  urls << url;
475  mimeData->setUrls( urls );
476  return mimeData;
477  }
478 
479  QgsMimeDataUtils::Uri uri = ptr->mimeUri();
480  if ( uri.isValid() )
481  lst.append( uri );
482  }
483  }
484  return QgsMimeDataUtils::encodeUriList( lst );
485 }
486 
487 bool QgsBrowserModel::dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent )
488 {
489  Q_UNUSED( row );
490  Q_UNUSED( column );
491 
492  QgsDataItem *destItem = dataItem( parent );
493  if ( !destItem )
494  {
495  QgsDebugMsgLevel( "DROP PROBLEM!", 4 );
496  return false;
497  }
498 
499  return destItem->handleDrop( data, action );
500 }
501 
502 QgsDataItem *QgsBrowserModel::dataItem( const QModelIndex &idx ) const
503 {
504  void *v = idx.internalPointer();
505  QgsDataItem *d = reinterpret_cast<QgsDataItem *>( v );
506  Q_ASSERT( !v || d );
507  return d;
508 }
509 
510 bool QgsBrowserModel::canFetchMore( const QModelIndex &parent ) const
511 {
512  QgsDataItem *item = dataItem( parent );
513  // if ( item )
514  // QgsDebugMsg( QString( "path = %1 canFetchMore = %2" ).arg( item->path() ).arg( item && ! item->isPopulated() ) );
515  return ( item && item->state() == QgsDataItem::NotPopulated );
516 }
517 
518 void QgsBrowserModel::fetchMore( const QModelIndex &parent )
519 {
520  QgsDataItem *item = dataItem( parent );
521 
522  if ( !item || item->state() == QgsDataItem::Populating || item->state() == QgsDataItem::Populated )
523  return;
524 
525  QgsDebugMsgLevel( "path = " + item->path(), 4 );
526 
527  item->populate();
528 }
529 
530 /* Refresh dir path */
531 void QgsBrowserModel::refresh( const QString &path )
532 {
533  QModelIndex index = findPath( path );
534  refresh( index );
535 }
536 
537 /* Refresh item */
538 void QgsBrowserModel::refresh( const QModelIndex &index )
539 {
540  QgsDataItem *item = dataItem( index );
541  if ( !item || item->state() == QgsDataItem::Populating )
542  return;
543 
544  QgsDebugMsgLevel( "Refresh " + item->path(), 4 );
545 
546  item->refresh();
547 }
548 
549 void QgsBrowserModel::addFavoriteDirectory( const QString &directory, const QString &name )
550 {
551  Q_ASSERT( mFavorites );
552  mFavorites->addDirectory( directory, name );
553 }
554 
555 void QgsBrowserModel::removeFavorite( const QModelIndex &index )
556 {
557  QgsDirectoryItem *item = dynamic_cast<QgsDirectoryItem *>( dataItem( index ) );
558  if ( !item )
559  return;
560 
561  mFavorites->removeDirectory( item );
562 }
563 
565 {
566  QgsSettings settings;
567  QStringList hiddenItems = settings.value( QStringLiteral( "browser/hiddenPaths" ),
568  QStringList() ).toStringList();
569  int idx = hiddenItems.indexOf( item->path() );
570  if ( idx != -1 )
571  {
572  hiddenItems.removeAt( idx );
573  }
574  else
575  {
576  hiddenItems << item->path();
577  }
578  settings.setValue( QStringLiteral( "browser/hiddenPaths" ), hiddenItems );
579  if ( item->parent() )
580  {
581  item->parent()->deleteChildItem( item );
582  }
583  else
584  {
585  int i = mRootItems.indexOf( item );
586  beginRemoveRows( QModelIndex(), i, i );
587  mRootItems.remove( i );
588  item->deleteLater();
589  endRemoveRows();
590  }
591 }
A Collection: logical collection of layers or subcollections, e.g.
Definition: qgsdataitem.h:511
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)
This class is a composition of two QSettings instances:
Definition: qgssettings.h:57
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
Provides the number of rows of data exposed by the model.
void fetchMore(const QModelIndex &parent) override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Used to supply item data to views and delegates.
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)
Return 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
Returns a list of mime that can describe model indexes.
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:87
QgsDirectoryItem * mProjectHome
void setValue(const QString &key, const QVariant &value, const QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
static void deleteLater(QVector< QgsDataItem *> &items)
QgsDataItem * parent() const
Get 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
Returns the parent of the model item with the given index.
QVector< QgsDataItem * > mRootItems
void readProject(const QDomDocument &)
emitted when 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
Return combination of flags from QgsDataProvider::DataCapabilities.
virtual QgsMimeDataUtils::Uri mimeUri() const
Return 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:528
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
Provides views with information to show in their headers.
~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)
Contains various Favorites directories.
Definition: qgsdataitem.h:642
void removeDirectory(QgsDirectoryItem *item)
Removes an existing directory from the favorites group.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), const Section section=NoSection) const
Returns the value for setting key.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Returns the index of the item in the model specified by the given row, column and parent index...
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:383
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Provides the number of columns of data exposed by the model.
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
Handles the data supplied by a drag and drop operation that ended with the given action.
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
Returns an object that contains serialized items of data corresponding to the list of indexes specifi...
Represents a QGIS project.
Definition: qgsdataitem.h:83
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
Used by other components to obtain information about each item provided by the model.
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:467
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)