16 #include <QApplication> 18 #include <QtConcurrentMap> 44 return QString::localeAwareCompare( a->
name(), b->
name() ) < 0;
48 : QAbstractItemModel( parent )
73 beginRemoveRows( QModelIndex(), idx, idx );
83 beginInsertRows( QModelIndex(), 0, 0 );
95 QStyle *style = QApplication::style();
96 QIcon homeIcon( style->standardPixmap( QStyle::SP_DirHomeIcon ) );
110 foreach ( QFileInfo drive, QDir::drives() )
112 QString path = drive.absolutePath();
120 QString path = QString(
"/Volumes" );
130 QMap<int, QgsDataItem *> providerMap;
132 foreach ( QString key, providersList )
139 if ( !dataCapabilities )
141 QgsDebugMsg( library->fileName() +
" does not have dataCapabilities" );
145 int capabilities = dataCapabilities();
148 QgsDebugMsg( library->fileName() +
" does not have any dataCapabilities" );
155 QgsDebugMsg( library->fileName() +
" does not have dataItem" );
164 providerMap.insertMulti( capabilities, item );
169 foreach (
int key, providerMap.uniqueKeys() )
171 QList<QgsDataItem *> providerGroup = providerMap.values( key );
172 if ( providerGroup.size() > 1 )
197 if ( !index.isValid() )
200 Qt::ItemFlags
flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
205 flags |= Qt::ItemIsDragEnabled;
208 flags |= Qt::ItemIsDropEnabled;
214 if ( !index.isValid() )
222 else if ( role == Qt::DisplayRole )
226 else if ( role == Qt::ToolTipRole )
230 else if ( role == Qt::DecorationRole && index.column() == 0 )
248 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole )
250 return QVariant(
"header" );
260 if ( !parent.isValid() )
276 if ( !parent.isValid() )
291 return findPath(
this, path, matchFlag );
297 return QModelIndex();
299 QModelIndex theIndex;
300 bool foundChild =
true;
306 for (
int i = 0; i < model->rowCount( theIndex ); i++ )
308 QModelIndex idx = model->index( i, 0, theIndex );
310 QString itemPath = model->data( idx,
PathRole ).toString();
311 if ( itemPath == path )
318 if ( path.startsWith( itemPath +
"/" ) )
327 if ( matchFlag == Qt::MatchStartsWith )
331 return QModelIndex();
348 return item ? createIndex( row, column, item ) : QModelIndex();
355 return QModelIndex();
364 for (
int i = 0; i < items.size(); i++ )
366 if ( items[i] == item )
367 return createIndex( i, 0, item );
369 QModelIndex childIndex =
findItem( item, items[i] );
370 if ( childIndex.isValid() )
374 return QModelIndex();
380 QModelIndex idx =
findItem( parent );
381 if ( !idx.isValid() )
384 beginInsertRows( idx, first, last );
395 QModelIndex idx =
findItem( parent );
396 if ( !idx.isValid() )
398 beginRemoveRows( idx, first, last );
409 if ( !idx.isValid() )
411 emit dataChanged( idx, idx );
419 if ( !idx.isValid() )
421 QgsDebugMsg( QString(
"item %1 state changed %2 -> %3" ).arg( item->
path() ).arg( oldState ).arg( item->
state() ) );
434 connect( item, SIGNAL( dataChanged(
QgsDataItem* ) ),
445 types <<
"application/x-vnd.qgis.qgis.uri";
452 foreach (
const QModelIndex &
index, indexes )
454 if ( index.isValid() )
482 void *v = idx.internalPointer();
Contains various Favourites directories.
void removeDirectory(QgsDirectoryItem *item)
static bool cmpByDataItemName_(QgsDataItem *a, QgsDataItem *b)
bool canFetchMore(const QModelIndex &parent) const override
QVector< QgsDataItem * > children() const
QgsDataItem * parent() const
Get item parent.
virtual 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
static QgsProviderRegistry * instance(QString pluginPath=QString::null)
means of accessing canonical single instance
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Used to supply item data to views and delegates.
void addDirectory(QString favIcon)
void removeFavourite(const QModelIndex &index)
virtual bool handleDrop(const QMimeData *, Qt::DropAction)
QgsFavouritesItem * mFavourites
void beginRemoveItems(QgsDataItem *parent, int first, int last)
void connectItem(QgsDataItem *item)
virtual void populate(QVector< QgsDataItem * > children)
void itemStateChanged(QgsDataItem *item, QgsDataItem::State oldState)
virtual QStringList mimeTypes() const override
Returns a list of mime that can describe model indexes.
QString homePath() const
Return project's home path.
virtual void refresh(QVector< QgsDataItem * > children)
bool hasChildren(const QModelIndex &parent=QModelIndex()) const override
QStringList providerList() const
Return list of available providers by their keys.
QgsDirectoryItem * mProjectHome
QgsBrowserModel(QObject *parent=0)
#define QgsDebugMsgLevel(str, level)
virtual QModelIndex parent(const QModelIndex &index) const override
Returns the parent of the model item with the given index.
QgsDataItem * dataItem(const QModelIndex &idx) const
QModelIndex findPath(QString path, Qt::MatchFlag matchFlag=Qt::MatchExactly)
Return index of item with given path.
Children not yet created.
Creating children in separate thread (populating or refreshing)
QgsBrowserWatcher(QgsDataItem *item)
A directory: contains subdirectories and layers.
QModelIndex findItem(QgsDataItem *item, QgsDataItem *parent=0) const
static QMimeData * encodeUriList(UriList layers)
Base class for all items in the model.
QLibrary * providerLibrary(const QString &providerKey) const
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Provides views with information to show in their headers.
void beginInsertItems(QgsDataItem *parent, int first, int last)
virtual 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 refresh(QString path)
static QgsProject * instance()
access to canonical QgsProject instance
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const override
Provides the number of columns of data exposed by the model.
virtual 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.
virtual QMimeData * mimeData(const QModelIndexList &indexes) const override
Returns an object that contains serialized items of data corresponding to the list of indexes specifi...
Item that represents a layer that can be opened with one of the providers.
QgsDataItem * dataItem_t(QString, QgsDataItem *)
void(*)() cast_to_fptr(void *p)
void itemDataChanged(QgsDataItem *item)
virtual Qt::ItemFlags flags(const QModelIndex &index) const override
Used by other components to obtain information about each item provided by the model.
virtual bool acceptDrop()
QVector< QgsDataItem * > mRootItems
void addFavouriteDirectory(QString favDir)