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();