QGIS API Documentation  3.6.0-Noosa (5873452)
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 
33 #define PROJECT_HOME_PREFIX "project:"
34 #define HOME_PREFIX "home:"
35 
37  : QFutureWatcher( nullptr )
38  , mItem( item )
39 {
40 }
41 
42 // sort function for QList<QgsDataItem*>, e.g. sorted/grouped provider listings
43 static bool cmpByDataItemName_( QgsDataItem *a, QgsDataItem *b )
44 {
45  return QString::localeAwareCompare( a->name(), b->name() ) < 0;
46 }
47 
49  : QAbstractItemModel( parent )
50 
51 {
52 }
53 
55 {
57 }
58 
60 {
61  QString home = QgsProject::instance()->homePath();
62  if ( mProjectHome && mProjectHome->path().mid( QStringLiteral( PROJECT_HOME_PREFIX ).length() ) == home )
63  return;
64 
65  int idx = mRootItems.indexOf( mProjectHome );
66 
67  // using layoutAboutToBeChanged() was messing expanded items
68  if ( idx >= 0 )
69  {
70  beginRemoveRows( QModelIndex(), idx, idx );
71  mRootItems.remove( idx );
72  endRemoveRows();
73  }
74  delete mProjectHome;
75  mProjectHome = home.isNull() ? nullptr : new QgsProjectHomeItem( nullptr, tr( "Project Home" ), home, QStringLiteral( PROJECT_HOME_PREFIX ) + home );
76  if ( mProjectHome )
77  {
78  setupItemConnections( mProjectHome );
79 
80  beginInsertRows( QModelIndex(), 0, 0 );
81  mRootItems.insert( 0, mProjectHome );
82  endInsertRows();
83  }
84 }
85 
87 {
89 
90  // give the home directory a prominent third place
91  QgsDirectoryItem *item = new QgsDirectoryItem( nullptr, tr( "Home" ), QDir::homePath(), QStringLiteral( HOME_PREFIX ) + QDir::homePath() );
92  item->setSortKey( QStringLiteral( " 2" ) );
93  setupItemConnections( item );
94  mRootItems << item;
95 
96  // add favorite directories
97  mFavorites = new QgsFavoritesItem( nullptr, tr( "Favorites" ) );
98  if ( mFavorites )
99  {
100  setupItemConnections( mFavorites );
102  }
103 
104  // add drives
105  Q_FOREACH ( const QFileInfo &drive, QDir::drives() )
106  {
107  const 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  mDriveItems.insert( path, item );
115 
116  setupItemConnections( item );
117  mRootItems << item;
118  }
119 
120 #ifdef Q_OS_MAC
121  QString path = QString( "/Volumes" );
122  QgsDirectoryItem *vols = new QgsDirectoryItem( nullptr, path, path );
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( QString(), 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  setupItemConnections( 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  mDriveItems.clear();
174 }
175 
176 QMap<QString, QgsDirectoryItem *> QgsBrowserModel::driveItems() const
177 {
178  return mDriveItems;
179 }
180 
182 {
183  if ( ! mInitialized )
184  {
188  addRootItems();
189  mInitialized = true;
190  }
191 }
192 
193 
194 Qt::ItemFlags QgsBrowserModel::flags( const QModelIndex &index ) const
195 {
196  if ( !index.isValid() )
197  return Qt::ItemFlags();
198 
199  Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
200 
201  QgsDataItem *ptr = reinterpret_cast< QgsDataItem * >( index.internalPointer() );
202  if ( ptr->hasDragEnabled() )
203  flags |= Qt::ItemIsDragEnabled;
204 
205  if ( ptr->acceptDrop() )
206  flags |= Qt::ItemIsDropEnabled;
207 
208  if ( ptr->capabilities2() & QgsDataItem::Rename )
209  flags |= Qt::ItemIsEditable;
210 
211  return flags;
212 }
213 
214 QVariant QgsBrowserModel::data( const QModelIndex &index, int role ) const
215 {
216  if ( !index.isValid() )
217  return QVariant();
218 
219  QgsDataItem *item = dataItem( index );
220  if ( !item )
221  {
222  return QVariant();
223  }
224  else if ( role == Qt::DisplayRole || role == Qt::EditRole )
225  {
226  return item->name();
227  }
228  else if ( role == QgsBrowserModel::SortRole )
229  {
230  return item->sortKey();
231  }
232  else if ( role == Qt::ToolTipRole )
233  {
234  return item->toolTip();
235  }
236  else if ( role == Qt::DecorationRole && index.column() == 0 )
237  {
238  return item->icon();
239  }
240  else if ( role == QgsBrowserModel::PathRole )
241  {
242  return item->path();
243  }
244  else if ( role == QgsBrowserModel::CommentRole )
245  {
246  if ( item->type() == QgsDataItem::Layer )
247  {
248  QgsLayerItem *lyrItem = qobject_cast<QgsLayerItem *>( item );
249  return lyrItem->comments();
250  }
251  return QVariant();
252  }
253  else
254  {
255  // unsupported role
256  return QVariant();
257  }
258 }
259 
260 bool QgsBrowserModel::setData( const QModelIndex &index, const QVariant &value, int role )
261 {
262  if ( !index.isValid() )
263  return false;
264 
265 
266  QgsDataItem *item = dataItem( index );
267  if ( !item )
268  {
269  return false;
270  }
271 
272  if ( !( item->capabilities2() & QgsDataItem::Rename ) )
273  return false;
274 
275  switch ( role )
276  {
277  case Qt::EditRole:
278  {
279  return item->rename( value.toString() );
280  }
281  }
282  return false;
283 }
284 
285 QVariant QgsBrowserModel::headerData( int section, Qt::Orientation orientation, int role ) const
286 {
287  Q_UNUSED( section );
288  if ( orientation == Qt::Horizontal && role == Qt::DisplayRole )
289  {
290  return QVariant( "header" );
291  }
292 
293  return QVariant();
294 }
295 
296 int QgsBrowserModel::rowCount( const QModelIndex &parent ) const
297 {
298  //QgsDebugMsg(QString("isValid = %1 row = %2 column = %3").arg(parent.isValid()).arg(parent.row()).arg(parent.column()));
299 
300  if ( !parent.isValid() )
301  {
302  // root item: its children are top level items
303  return mRootItems.count(); // mRoot
304  }
305  else
306  {
307  // ordinary item: number of its children
308  QgsDataItem *item = dataItem( parent );
309  //if ( item ) QgsDebugMsg(QString("path = %1 rowCount = %2").arg(item->path()).arg(item->rowCount()) );
310  return item ? item->rowCount() : 0;
311  }
312 }
313 
314 bool QgsBrowserModel::hasChildren( const QModelIndex &parent ) const
315 {
316  if ( !parent.isValid() )
317  return !mRootItems.isEmpty(); // root item: its children are top level items
318 
319  QgsDataItem *item = dataItem( parent );
320  return item && item->hasChildren();
321 }
322 
323 int QgsBrowserModel::columnCount( const QModelIndex &parent ) const
324 {
325  Q_UNUSED( parent );
326  return 1;
327 }
328 
329 QModelIndex QgsBrowserModel::findPath( const QString &path, Qt::MatchFlag matchFlag )
330 {
331  return findPath( this, path, matchFlag );
332 }
333 
334 QModelIndex QgsBrowserModel::findPath( QAbstractItemModel *model, const QString &path, Qt::MatchFlag matchFlag )
335 {
336  if ( !model )
337  return QModelIndex();
338 
339  QModelIndex index; // starting from root
340  bool foundChild = true;
341 
342  while ( foundChild )
343  {
344  foundChild = false; // assume that the next child item will not be found
345 
346  for ( int i = 0; i < model->rowCount( index ); i++ )
347  {
348  QModelIndex idx = model->index( i, 0, index );
349 
350  QString itemPath = model->data( idx, PathRole ).toString();
351  if ( itemPath == path )
352  {
353  QgsDebugMsgLevel( "Arrived " + itemPath, 4 );
354  return idx; // we have found the item we have been looking for
355  }
356 
357  // paths are slash separated identifier
358  if ( path.startsWith( itemPath + '/' ) )
359  {
360  foundChild = true;
361  index = idx;
362  break;
363  }
364  }
365  }
366 
367  if ( matchFlag == Qt::MatchStartsWith )
368  return index;
369 
370  QgsDebugMsgLevel( QStringLiteral( "path not found" ), 4 );
371  return QModelIndex(); // not found
372 }
373 
374 QModelIndex QgsBrowserModel::findUri( const QString &uri, QModelIndex index )
375 {
376  for ( int i = 0; i < this->rowCount( index ); i++ )
377  {
378  QModelIndex idx = this->index( i, 0, index );
379 
380  if ( qobject_cast<QgsLayerItem *>( dataItem( idx ) ) )
381  {
382  QString itemUri = qobject_cast<QgsLayerItem *>( dataItem( idx ) )->uri();
383 
384  if ( itemUri == uri )
385  {
386  QgsDebugMsgLevel( "Arrived " + itemUri, 4 );
387  return idx; // we have found the item we have been looking for
388  }
389  }
390 
391  QModelIndex childIdx = findUri( uri, idx );
392  if ( childIdx.isValid() )
393  return childIdx;
394  }
395  return QModelIndex();
396 }
397 
399 {
400  // deprecated, no use
401 }
402 
404 {
405  // TODO: put items creating currently children in threads to deleteLater (does not seem urget because reload() is not used in QGIS)
406  beginResetModel();
407  removeRootItems();
408  addRootItems();
409  endResetModel();
410 }
411 
413 {
414  const QList< QFileInfo > drives = QDir::drives();
415  // remove any removed drives
416  const QStringList existingDrives = mDriveItems.keys();
417  for ( const QString &drivePath : existingDrives )
418  {
419  bool stillExists = false;
420  for ( const QFileInfo &drive : drives )
421  {
422  if ( drivePath == drive.absolutePath() )
423  {
424  stillExists = true;
425  break;
426  }
427  }
428 
429  if ( stillExists )
430  continue;
431 
432  // drive has been removed, remove corresponding item
433  if ( QgsDirectoryItem *driveItem = mDriveItems.value( drivePath ) )
434  removeRootItem( driveItem );
435  }
436 
437  for ( const QFileInfo &drive : drives )
438  {
439  const QString path = drive.absolutePath();
440 
441  if ( QgsDirectoryItem::hiddenPath( path ) )
442  continue;
443 
444  // does an item for this drive already exist?
445  if ( !mDriveItems.contains( path ) )
446  {
447  QgsDirectoryItem *item = new QgsDirectoryItem( nullptr, path, path );
448  item->setSortKey( QStringLiteral( " 3 %1" ).arg( path ) );
449 
450  mDriveItems.insert( path, item );
451  setupItemConnections( item );
452 
453  beginInsertRows( QModelIndex(), mRootItems.count(), mRootItems.count() );
454  mRootItems << item;
455  endInsertRows();
456  }
457  }
458 }
459 
460 QModelIndex QgsBrowserModel::index( int row, int column, const QModelIndex &parent ) const
461 {
462  if ( column < 0 || column >= columnCount() || row < 0 )
463  return QModelIndex();
464 
465  QgsDataItem *p = dataItem( parent );
466  const QVector<QgsDataItem *> &items = p ? p->children() : mRootItems;
467  QgsDataItem *item = items.value( row, nullptr );
468  return item ? createIndex( row, column, item ) : QModelIndex();
469 }
470 
471 QModelIndex QgsBrowserModel::parent( const QModelIndex &index ) const
472 {
473  QgsDataItem *item = dataItem( index );
474  if ( !item )
475  return QModelIndex();
476 
477  return findItem( item->parent() );
478 }
479 
481 {
482  const QVector<QgsDataItem *> &items = parent ? parent->children() : mRootItems;
483 
484  for ( int i = 0; i < items.size(); i++ )
485  {
486  if ( items[i] == item )
487  return createIndex( i, 0, item );
488 
489  QModelIndex childIndex = findItem( item, items[i] );
490  if ( childIndex.isValid() )
491  return childIndex;
492  }
493 
494  return QModelIndex();
495 }
496 
498 {
499  QgsDebugMsgLevel( "parent mPath = " + parent->path(), 3 );
500  QModelIndex idx = findItem( parent );
501  if ( !idx.isValid() )
502  return;
503  QgsDebugMsgLevel( QStringLiteral( "valid" ), 3 );
504  beginInsertRows( idx, first, last );
505  QgsDebugMsgLevel( QStringLiteral( "end" ), 3 );
506 }
508 {
509  QgsDebugMsgLevel( QStringLiteral( "Entered" ), 3 );
510  endInsertRows();
511 }
513 {
514  QgsDebugMsgLevel( "parent mPath = " + parent->path(), 3 );
515  QModelIndex idx = findItem( parent );
516  if ( !idx.isValid() )
517  return;
518  beginRemoveRows( idx, first, last );
519 }
521 {
522  QgsDebugMsgLevel( QStringLiteral( "Entered" ), 3 );
523  endRemoveRows();
524 }
526 {
527  QgsDebugMsgLevel( QStringLiteral( "Entered" ), 3 );
528  QModelIndex idx = findItem( item );
529  if ( !idx.isValid() )
530  return;
531  emit dataChanged( idx, idx );
532 }
534 {
535  if ( !item )
536  return;
537  QModelIndex idx = findItem( item );
538  if ( !idx.isValid() )
539  return;
540  QgsDebugMsgLevel( QStringLiteral( "item %1 state changed %2 -> %3" ).arg( item->path() ).arg( oldState ).arg( item->state() ), 4 );
541  emit stateChanged( idx, oldState );
542 }
543 
544 void QgsBrowserModel::setupItemConnections( QgsDataItem *item )
545 {
546  connect( item, &QgsDataItem::beginInsertItems,
548  connect( item, &QgsDataItem::endInsertItems,
550  connect( item, &QgsDataItem::beginRemoveItems,
552  connect( item, &QgsDataItem::endRemoveItems,
554  connect( item, &QgsDataItem::dataChanged,
556  connect( item, &QgsDataItem::stateChanged,
558 
559  // if it's a collection item, also forwards connectionsChanged
560  QgsDataCollectionItem *collectionItem = qobject_cast<QgsDataCollectionItem *>( item );
561  if ( collectionItem )
563 }
564 
565 QStringList QgsBrowserModel::mimeTypes() const
566 {
567  QStringList types;
568  // In theory the mime type convention is: application/x-vnd.<vendor>.<application>.<type>
569  // but it seems a bit over formalized. Would be an application/x-qgis-uri better?
570  types << QStringLiteral( "application/x-vnd.qgis.qgis.uri" );
571  return types;
572 }
573 
574 QMimeData *QgsBrowserModel::mimeData( const QModelIndexList &indexes ) const
575 {
577  Q_FOREACH ( const QModelIndex &index, indexes )
578  {
579  if ( index.isValid() )
580  {
581  QgsDataItem *ptr = reinterpret_cast< QgsDataItem * >( index.internalPointer() );
582  QgsMimeDataUtils::Uri uri = ptr->mimeUri();
583  if ( uri.isValid() )
584  lst.append( uri );
585  }
586  }
587  return QgsMimeDataUtils::encodeUriList( lst );
588 }
589 
590 bool QgsBrowserModel::dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent )
591 {
592  Q_UNUSED( row );
593  Q_UNUSED( column );
594 
595  QgsDataItem *destItem = dataItem( parent );
596  if ( !destItem )
597  {
598  QgsDebugMsgLevel( QStringLiteral( "DROP PROBLEM!" ), 4 );
599  return false;
600  }
601 
602  return destItem->handleDrop( data, action );
603 }
604 
605 QgsDataItem *QgsBrowserModel::dataItem( const QModelIndex &idx ) const
606 {
607  void *v = idx.internalPointer();
608  QgsDataItem *d = reinterpret_cast<QgsDataItem *>( v );
609  Q_ASSERT( !v || d );
610  return d;
611 }
612 
613 bool QgsBrowserModel::canFetchMore( const QModelIndex &parent ) const
614 {
615  QgsDataItem *item = dataItem( parent );
616  // if ( item )
617  // QgsDebugMsg( QStringLiteral( "path = %1 canFetchMore = %2" ).arg( item->path() ).arg( item && ! item->isPopulated() ) );
618  return ( item && item->state() == QgsDataItem::NotPopulated );
619 }
620 
621 void QgsBrowserModel::fetchMore( const QModelIndex &parent )
622 {
623  QgsDataItem *item = dataItem( parent );
624 
625  if ( !item || item->state() == QgsDataItem::Populating || item->state() == QgsDataItem::Populated )
626  return;
627 
628  QgsDebugMsgLevel( "path = " + item->path(), 4 );
629 
630  item->populate();
631 }
632 
633 /* Refresh dir path */
634 void QgsBrowserModel::refresh( const QString &path )
635 {
636  QModelIndex index = findPath( path );
637  refresh( index );
638 }
639 
640 /* Refresh item */
641 void QgsBrowserModel::refresh( const QModelIndex &index )
642 {
643  QgsDataItem *item = dataItem( index );
644  if ( !item || item->state() == QgsDataItem::Populating )
645  return;
646 
647  QgsDebugMsgLevel( "Refresh " + item->path(), 4 );
648 
649  item->refresh();
650 }
651 
652 void QgsBrowserModel::addFavoriteDirectory( const QString &directory, const QString &name )
653 {
654  Q_ASSERT( mFavorites );
655  mFavorites->addDirectory( directory, name );
656 }
657 
658 void QgsBrowserModel::removeFavorite( const QModelIndex &index )
659 {
660  QgsDirectoryItem *item = qobject_cast<QgsDirectoryItem *>( dataItem( index ) );
661  if ( !item )
662  return;
663 
664  mFavorites->removeDirectory( item );
665 }
666 
667 void QgsBrowserModel::removeFavorite( QgsFavoriteItem *favorite )
668 {
669  if ( !favorite )
670  return;
671 
672  mFavorites->removeDirectory( favorite );
673 }
674 
676 {
677  QgsSettings settings;
678  QStringList hiddenItems = settings.value( QStringLiteral( "browser/hiddenPaths" ),
679  QStringList() ).toStringList();
680  int idx = hiddenItems.indexOf( item->path() );
681  if ( idx != -1 )
682  {
683  hiddenItems.removeAt( idx );
684  }
685  else
686  {
687  hiddenItems << item->path();
688  }
689  settings.setValue( QStringLiteral( "browser/hiddenPaths" ), hiddenItems );
690  if ( item->parent() )
691  {
692  item->parent()->deleteChildItem( item );
693  }
694  else
695  {
696  removeRootItem( item );
697  }
698 }
699 
700 
701 void QgsBrowserModel::removeRootItem( QgsDataItem *item )
702 {
703  int i = mRootItems.indexOf( item );
704  beginRemoveRows( QModelIndex(), i, i );
705  mRootItems.remove( i );
706  QgsDirectoryItem *dirItem = qobject_cast< QgsDirectoryItem * >( item );
707  if ( !mDriveItems.key( dirItem ).isEmpty() )
708  {
709  mDriveItems.remove( mDriveItems.key( dirItem ) );
710  }
711  item->deleteLater();
712  endRemoveRows();
713 }
714 
A Collection: logical collection of layers or subcollections, e.g.
Definition: qgsdataitem.h:550
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:293
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:284
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:325
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.
void refreshDrives()
Refreshes the list of drive items, removing any corresponding to removed drives and adding newly adde...
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()
Q_DECL_DEPRECATED void connectItem(QgsDataItem *item)
#define PROJECT_HOME_PREFIX
Type type() const
Definition: qgsdataitem.h:265
static QMimeData * encodeUriList(const UriList &layers)
Encodes a URI list to a new QMimeData object.
bool isValid() const
Returns whether the object contains valid data.
virtual bool rename(const QString &name)
Sets a new name for the item, and returns true if the item was successfully renamed.
void itemStateChanged(QgsDataItem *item, QgsDataItem::State oldState)
QStringList mimeTypes() const override
QMap< QString, QgsDirectoryItem * > driveItems() const
Returns a map of the root drive items shown in the browser.
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:94
QgsDirectoryItem * mProjectHome
static void deleteLater(QVector< QgsDataItem *> &items)
QgsDataItem * parent() const
Gets item parent.
Definition: qgsdataitem.h:270
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.
#define HOME_PREFIX
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
Returns the data item at the specified index, or a nullptr if no item exists at the index...
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:590
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:276
QModelIndex findItem(QgsDataItem *item, QgsDataItem *parent=nullptr) const
Returns the model index corresponding to the specified data item.
QModelIndex findUri(const QString &uri, QModelIndex index=QModelIndex())
Returns index of layer item with given uri.
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:699
void removeDirectory(QgsDirectoryItem *item)
Removes an existing directory from the favorites group.
Item can be renamed.
Definition: qgsdataitem.h:214
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.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:430
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:436
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:501
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)
virtual Capabilities capabilities2() const
Returns the capabilities for the data item.
Definition: qgsdataitem.h:249