Skip to content
Permalink
Browse files

find index of layeritem with the passed uri

  • Loading branch information
signedav committed Jan 3, 2019
1 parent 1136aab commit d453006fe03fbaef3be9c9554ee73d692a34c334
Showing with 32 additions and 0 deletions.
  1. +24 −0 src/core/qgsbrowsermodel.cpp
  2. +8 −0 src/core/qgsbrowsermodel.h
@@ -366,6 +366,30 @@ QModelIndex QgsBrowserModel::findPath( QAbstractItemModel *model, const QString
return QModelIndex(); // not found
}

QModelIndex QgsBrowserModel::findUri( const QString &uri, QModelIndex index )
{
for ( int i = 0; i < this->rowCount( index ); i++ )
{
QModelIndex idx = this->index( i, 0, index );

if ( qobject_cast<QgsLayerItem *>( dataItem( idx ) ) )
{
QString itemUri = qobject_cast<QgsLayerItem *>( dataItem( idx ) )->uri();

if ( itemUri == uri )
{
QgsDebugMsgLevel( "Arrived " + itemUri, 4 );
return idx; // we have found the item we have been looking for
}
}

QModelIndex childIdx = findUri( uri, idx );
if ( childIdx.isValid() )
return childIdx;
}
return QModelIndex();
}

void QgsBrowserModel::connectItem( QgsDataItem * )
{
// deprecated, no use
@@ -136,6 +136,14 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
//! \note not available in Python bindings
static QModelIndex findPath( QAbstractItemModel *model, const QString &path, Qt::MatchFlag matchFlag = Qt::MatchExactly ) SIP_SKIP;

/**
* Returns index of layer item with given uri. It only searches in currently fetched
* items, i.e. it does not fetch children.
* \param uri item uri
* \param index the current index of the parent (to search for children)
* \returns model index, invalid if item not found */
QModelIndex findUri( const QString &uri, QModelIndex index = QModelIndex() );

/**
* \deprecated Deprecated since QGIS 3.4 -- this method has no effect, and is dangerous to call in earlier QGIS versions. Any usage should be removed (and will have no harmful side-effects!).
*/

0 comments on commit d453006

Please sign in to comment.
You can’t perform that action at this time.