Skip to content
Permalink
Browse files

Follow up c6c8277, fix bad behaviour of QgsBrowserModel introduced

by 44d9b35 (fix #14296)
  • Loading branch information
nyalldawson committed Feb 16, 2016
1 parent 13c5848 commit 14f9a888111a69a1679ffa9b4cc79cdeaccc7702
Showing with 30 additions and 36 deletions.
  1. +7 −7 python/core/qgsbrowsermodel.sip
  2. +5 −10 src/app/qgsbrowserdockwidget.cpp
  3. +11 −12 src/core/qgsbrowsermodel.cpp
  4. +7 −7 src/core/qgsbrowsermodel.h
@@ -10,8 +10,8 @@ class QgsBrowserModel : QAbstractItemModel

enum ItemDataRole
{
// item path used to access path in the tree, see QgsDataItem::mPath
PathRole
PathRole, /*!< Item path used to access path in the tree, see QgsDataItem::mPath */
CommentRole, /*!< Item comment */
};
// implemented methods from QAbstractItemModel for read-only access

@@ -59,10 +59,10 @@ class QgsBrowserModel : QAbstractItemModel

bool hasChildren( const QModelIndex &parent = QModelIndex() ) const;

// Refresh item specified by path
//! Refresh item specified by path
void refresh( const QString& path );

// Refresh item childs
//! Refresh item children
void refresh( const QModelIndex &index = QModelIndex() );

/** Return index of item with given path. It only searches in currently fetched
@@ -73,7 +73,7 @@ class QgsBrowserModel : QAbstractItemModel
* @return model index, invalid if item not found */
QModelIndex findPath( const QString& path, Qt::MatchFlag matchFlag = Qt::MatchExactly );

// @note not available in python bindings
//! @note not available in python bindings
// static QModelIndex findPath( QAbstractItemModel *model, const QString& path, Qt::MatchFlag matchFlag = Qt::MatchExactly );

void connectItem( QgsDataItem *item );
@@ -86,7 +86,7 @@ class QgsBrowserModel : QAbstractItemModel
void stateChanged( const QModelIndex & index, QgsDataItem::State oldState );

public slots:
// Reload the whole model
//! Reload the whole model
void reload();
void beginInsertItems( QgsDataItem *parent, int first, int last );
void endInsertItems();
@@ -103,7 +103,7 @@ class QgsBrowserModel : QAbstractItemModel
void hidePath( QgsDataItem *item );

protected:
// populates the model
//! Populates the model
void addRootItems();
void removeRootItems();
};
@@ -906,10 +906,7 @@ bool QgsBrowserTreeFilterProxyModel::filterAcceptsRow( int sourceRow, const QMod
if ( mFilter == "" || !mModel ) return true;

QModelIndex sourceIndex = mModel->index( sourceRow, 0, sourceParent );
// also look into the comment column
QModelIndex commentIndex = mModel->index( sourceRow, 1, sourceParent );
return filterAcceptsItem( sourceIndex ) || filterAcceptsAncestor( sourceIndex ) || filterAcceptsDescendant( sourceIndex ) ||
filterAcceptsItem( commentIndex ) || filterAcceptsAncestor( commentIndex ) || filterAcceptsDescendant( commentIndex );
return filterAcceptsItem( sourceIndex ) || filterAcceptsAncestor( sourceIndex ) || filterAcceptsDescendant( sourceIndex );
}

bool QgsBrowserTreeFilterProxyModel::filterAcceptsAncestor( const QModelIndex& sourceIndex ) const
@@ -939,11 +936,6 @@ bool QgsBrowserTreeFilterProxyModel::filterAcceptsDescendant( const QModelIndex&
return true;
if ( filterAcceptsDescendant( sourceChildIndex ) )
return true;
sourceChildIndex = mModel->index( i, 1, sourceIndex );
if ( filterAcceptsItem( sourceChildIndex ) )
return true;
if ( filterAcceptsDescendant( sourceChildIndex ) )
return true;
}
return false;
}
@@ -952,5 +944,8 @@ bool QgsBrowserTreeFilterProxyModel::filterAcceptsItem( const QModelIndex& sourc
{
if ( !mModel )
return true;
return filterAcceptsString( mModel->data( sourceIndex, Qt::DisplayRole ).toString() );
//accept item if either displayed text or comment role matches string
QString comment = mModel->data( sourceIndex, QgsBrowserModel::CommentRole ).toString();
return ( filterAcceptsString( mModel->data( sourceIndex, Qt::DisplayRole ).toString() )
|| ( !comment.isEmpty() && filterAcceptsString( comment ) ) );
}
@@ -207,16 +207,7 @@ QVariant QgsBrowserModel::data( const QModelIndex &index, int role ) const
}
else if ( role == Qt::DisplayRole )
{
if ( index.column() == 0 )
{
return item->name();
}
if ( item->type() == QgsDataItem::Layer )
{
QgsLayerItem* lyrItem = qobject_cast<QgsLayerItem*>( item );
return lyrItem->comments();
}
return "";
return item->name();
}
else if ( role == Qt::ToolTipRole )
{
@@ -230,6 +221,15 @@ QVariant QgsBrowserModel::data( const QModelIndex &index, int role ) const
{
return item->path();
}
else if ( role == QgsBrowserModel::CommentRole )
{
if ( item->type() == QgsDataItem::Layer )
{
QgsLayerItem* lyrItem = qobject_cast<QgsLayerItem*>( item );
return lyrItem->comments();
}
return QVariant();
}
else
{
// unsupported role
@@ -337,8 +337,7 @@ void QgsBrowserModel::reload()

QModelIndex QgsBrowserModel::index( int row, int column, const QModelIndex &parent ) const
{
if ( column < 0 || column >= columnCount( parent ) ||
row < 0 || row >= rowCount( parent ) )
if ( column < 0 || column >= columnCount() || row < 0 )
return QModelIndex();

QgsDataItem *p = dataItem( parent );
@@ -54,8 +54,8 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel

enum ItemDataRole
{
// item path used to access path in the tree, see QgsDataItem::mPath
PathRole = Qt::UserRole
PathRole = Qt::UserRole, /*!< Item path used to access path in the tree, see QgsDataItem::mPath */
CommentRole = Qt::UserRole + 1, /*!< Item comment */
};
// implemented methods from QAbstractItemModel for read-only access

@@ -103,10 +103,10 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel

bool hasChildren( const QModelIndex &parent = QModelIndex() ) const override;

// Refresh item specified by path
//! Refresh item specified by path
void refresh( const QString& path );

// Refresh item childs
//! Refresh item children
void refresh( const QModelIndex &index = QModelIndex() );

/** Return index of item with given path. It only searches in currently fetched
@@ -117,7 +117,7 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
* @return model index, invalid if item not found */
QModelIndex findPath( const QString& path, Qt::MatchFlag matchFlag = Qt::MatchExactly );

// @note not available in python bindings
//! @note not available in python bindings
static QModelIndex findPath( QAbstractItemModel *model, const QString& path, Qt::MatchFlag matchFlag = Qt::MatchExactly );

void connectItem( QgsDataItem *item );
@@ -130,7 +130,7 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
void stateChanged( const QModelIndex & index, QgsDataItem::State oldState );

public slots:
// Reload the whole model
//! Reload the whole model
void reload();
void beginInsertItems( QgsDataItem *parent, int first, int last );
void endInsertItems();
@@ -147,7 +147,7 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
void hidePath( QgsDataItem *item );

protected:
// populates the model
//! Populates the model
void addRootItems();
void removeRootItems();

0 comments on commit 14f9a88

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