16 #include <QApplication>
34 return QString::localeAwareCompare( a->
name(), b->
name() ) < 0;
38 : QAbstractItemModel( parent )
58 emit layoutAboutToBeChanged();
85 QStyle *style = QApplication::style();
86 QIcon homeIcon( style->standardPixmap( QStyle::SP_DirHomeIcon ) );
100 foreach ( QFileInfo drive, QDir::drives() )
102 QString path = drive.absolutePath();
110 QString path = QString(
"/Volumes" );
120 QMap<int, QgsDataItem *> providerMap;
122 foreach ( QString key, providersList )
129 if ( !dataCapabilities )
131 QgsDebugMsg( library->fileName() +
" does not have dataCapabilities" );
135 int capabilities = dataCapabilities();
138 QgsDebugMsg( library->fileName() +
" does not have any dataCapabilities" );
145 QgsDebugMsg( library->fileName() +
" does not have dataItem" );
154 providerMap.insertMulti( capabilities, item );
159 foreach (
int key, providerMap.uniqueKeys() )
161 QList<QgsDataItem *> providerGroup = providerMap.values( key );
162 if ( providerGroup.size() > 1 )
187 if ( !index.isValid() )
190 Qt::ItemFlags
flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
195 flags |= Qt::ItemIsDragEnabled;
198 flags |= Qt::ItemIsDropEnabled;
204 if ( !index.isValid() )
212 else if ( role == Qt::DisplayRole )
216 else if ( role == Qt::ToolTipRole )
220 else if ( role == Qt::DecorationRole && index.column() == 0 )
234 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole )
236 return QVariant(
"header" );
246 if ( !parent.isValid() )
261 if ( !parent.isValid() )
276 QModelIndex theIndex;
277 bool foundChild =
true;
283 for (
int i = 0; i <
rowCount( theIndex ); i++ )
285 QModelIndex idx =
index( i, 0, theIndex );
288 return QModelIndex();
290 if ( item->
path() == path )
296 if ( path.startsWith( item->
path() ) )
306 return QModelIndex();
334 return item ? createIndex( row, column, item ) : QModelIndex();
341 return QModelIndex();
350 for (
int i = 0; i < items.size(); i++ )
352 if ( items[i] == item )
353 return createIndex( i, 0, item );
355 QModelIndex childIndex =
findItem( item, items[i] );
356 if ( childIndex.isValid() )
360 return QModelIndex();
377 QModelIndex idx =
findItem( parent );
378 if ( !idx.isValid() )
381 beginInsertRows( idx, first, last );
392 QModelIndex idx =
findItem( parent );
393 if ( !idx.isValid() )
395 beginRemoveRows( idx, first, last );
419 types <<
"application/x-vnd.qgis.qgis.uri";
426 foreach (
const QModelIndex &
index, indexes )
428 if ( index.isValid() )
456 void *v = idx.internalPointer();
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Used by other components to obtain information about each item provided by the model.
Contains various Favourites directories.
bool hasChildren(const QModelIndex &parent=QModelIndex()) const
void removeDirectory(QgsDirectoryItem *item)
static bool cmpByDataItemName_(QgsDataItem *a, QgsDataItem *b)
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Provides the number of columns of data exposed by the model.
QVector< QgsDataItem * > children() const
QgsDataItem * parent() const
static QgsProviderRegistry * instance(QString pluginPath=QString::null)
means of accessing canonical single instance
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 fetchMore(const QModelIndex &parent)
void connectItem(QgsDataItem *item)
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Provides views with information to show in their headers.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Provides the number of rows of data exposed by the model.
QString homePath() const
Return project's home path.
QStringList providerList() const
Return list of available providers by their keys.
QgsDirectoryItem * mProjectHome
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
Handles the data supplied by a drag and drop operation that ended with the given action.
QgsBrowserModel(QObject *parent=0)
QgsDataItem * dataItem(const QModelIndex &idx) const
bool canFetchMore(const QModelIndex &parent) const
virtual QModelIndex parent(const QModelIndex &index) const
Returns the parent of the model item with the given index.
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Returns the index of the item in the model specified by the given row, column and parent index...
QModelIndex findPath(QString path)
return index of a path
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
void beginInsertItems(QgsDataItem *parent, int first, int last)
virtual QStringList mimeTypes() const
Returns a list of mime that can describe model indexes.
void refresh(QString path)
static QgsProject * instance()
access to canonical QgsProject instance
virtual QMimeData * mimeData(const QModelIndexList &indexes) const
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)
virtual bool acceptDrop()
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Used to supply item data to views and delegates.
QVector< QgsDataItem * > mRootItems
void addFavouriteDirectory(QString favDir)