Skip to content

Commit

Permalink
Rename enum values for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 16, 2016
1 parent fc65334 commit 1da400a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions python/core/qgsmaplayermodel.sip
Expand Up @@ -19,8 +19,8 @@ class QgsMapLayerModel : QAbstractItemModel
{
LayerIdRole, /*!< Stores the map layer ID */
LayerRole, /*!< Stores pointer to the map layer itself */
IsEmptyRole, //!< True if index corresponds to the empty (not set) value
IsAdditionalRole, //!< True if index corresponds to an additional (non map layer) item
EmptyRole, //!< True if index corresponds to the empty (not set) value
AdditionalRole, //!< True if index corresponds to an additional (non map layer) item
};

/**
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsmaplayermodel.cpp
Expand Up @@ -257,10 +257,10 @@ QVariant QgsMapLayerModel::data( const QModelIndex &index, int role ) const
return QVariant::fromValue<QgsMapLayer*>( static_cast<QgsMapLayer*>( index.internalPointer() ) );
}

if ( role == IsEmptyRole )
if ( role == EmptyRole )
return isEmpty;

if ( role == IsAdditionalRole )
if ( role == AdditionalRole )
return additionalIndex >= 0;

if ( role == Qt::CheckStateRole && mItemCheckable )
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsmaplayermodel.h
Expand Up @@ -45,8 +45,8 @@ class CORE_EXPORT QgsMapLayerModel : public QAbstractItemModel
{
LayerIdRole = Qt::UserRole + 1, //!< Stores the map layer ID
LayerRole, //!< Stores pointer to the map layer itself
IsEmptyRole, //!< True if index corresponds to the empty (not set) value
IsAdditionalRole, //!< True if index corresponds to an additional (non map layer) item
EmptyRole, //!< True if index corresponds to the empty (not set) value
AdditionalRole, //!< True if index corresponds to an additional (non map layer) item
};

/**
Expand Down
12 changes: 6 additions & 6 deletions src/core/qgsmaplayerproxymodel.cpp
Expand Up @@ -87,8 +87,8 @@ bool QgsMapLayerProxyModel::filterAcceptsRow( int source_row, const QModelIndex

QModelIndex index = sourceModel()->index( source_row, 0, source_parent );

if ( sourceModel()->data( index, QgsMapLayerModel::IsEmptyRole ).toBool()
|| sourceModel()->data( index, QgsMapLayerModel::IsAdditionalRole ).toBool() )
if ( sourceModel()->data( index, QgsMapLayerModel::EmptyRole ).toBool()
|| sourceModel()->data( index, QgsMapLayerModel::AdditionalRole ).toBool() )
return true;

QgsMapLayer* layer = static_cast<QgsMapLayer*>( index.internalPointer() );
Expand Down Expand Up @@ -143,14 +143,14 @@ bool QgsMapLayerProxyModel::filterAcceptsRow( int source_row, const QModelIndex
bool QgsMapLayerProxyModel::lessThan( const QModelIndex &left, const QModelIndex &right ) const
{
// empty row is always first
if ( sourceModel()->data( left, QgsMapLayerModel::IsEmptyRole ).toBool() )
if ( sourceModel()->data( left, QgsMapLayerModel::EmptyRole ).toBool() )
return true;
else if ( sourceModel()->data( right, QgsMapLayerModel::IsEmptyRole ).toBool() )
else if ( sourceModel()->data( right, QgsMapLayerModel::EmptyRole ).toBool() )
return false;

// additional rows are always last
bool leftAdditional = sourceModel()->data( left, QgsMapLayerModel::IsAdditionalRole ).toBool();
bool rightAdditional = sourceModel()->data( right, QgsMapLayerModel::IsAdditionalRole ).toBool();
bool leftAdditional = sourceModel()->data( left, QgsMapLayerModel::AdditionalRole ).toBool();
bool rightAdditional = sourceModel()->data( right, QgsMapLayerModel::AdditionalRole ).toBool();

if ( leftAdditional && !rightAdditional )
return false;
Expand Down
30 changes: 15 additions & 15 deletions tests/src/python/test_qgsmaplayermodel.py
Expand Up @@ -242,15 +242,15 @@ def testIsEmptyRole(self):
l2 = create_layer('l2')
QgsMapLayerRegistry.instance().addMapLayers([l1, l2])
m = QgsMapLayerModel()
self.assertFalse(m.data(m.index(0, 0), QgsMapLayerModel.IsEmptyRole))
self.assertFalse(m.data(m.index(1, 0), QgsMapLayerModel.IsEmptyRole))
self.assertFalse(m.data(m.index(0, 0), QgsMapLayerModel.EmptyRole))
self.assertFalse(m.data(m.index(1, 0), QgsMapLayerModel.EmptyRole))
m.setAllowEmptyLayer(True)
self.assertTrue(m.data(m.index(0, 0), QgsMapLayerModel.IsEmptyRole))
self.assertFalse(m.data(m.index(1, 0), QgsMapLayerModel.IsEmptyRole))
self.assertFalse(m.data(m.index(2, 0), QgsMapLayerModel.IsEmptyRole))
self.assertTrue(m.data(m.index(0, 0), QgsMapLayerModel.EmptyRole))
self.assertFalse(m.data(m.index(1, 0), QgsMapLayerModel.EmptyRole))
self.assertFalse(m.data(m.index(2, 0), QgsMapLayerModel.EmptyRole))

m.setAdditionalItems(['a'])
self.assertFalse(m.data(m.index(3, 0), QgsMapLayerModel.IsEmptyRole))
self.assertFalse(m.data(m.index(3, 0), QgsMapLayerModel.EmptyRole))

QgsMapLayerRegistry.instance().removeMapLayers([l1.id(), l2.id()])

Expand All @@ -259,18 +259,18 @@ def testIsAdditionalRole(self):
l2 = create_layer('l2')
QgsMapLayerRegistry.instance().addMapLayers([l1, l2])
m = QgsMapLayerModel()
self.assertFalse(m.data(m.index(0, 0), QgsMapLayerModel.IsAdditionalRole))
self.assertFalse(m.data(m.index(1, 0), QgsMapLayerModel.IsAdditionalRole))
self.assertFalse(m.data(m.index(0, 0), QgsMapLayerModel.AdditionalRole))
self.assertFalse(m.data(m.index(1, 0), QgsMapLayerModel.AdditionalRole))
m.setAllowEmptyLayer(True)
self.assertFalse(m.data(m.index(0, 0), QgsMapLayerModel.IsAdditionalRole))
self.assertFalse(m.data(m.index(1, 0), QgsMapLayerModel.IsAdditionalRole))
self.assertFalse(m.data(m.index(2, 0), QgsMapLayerModel.IsAdditionalRole))
self.assertFalse(m.data(m.index(0, 0), QgsMapLayerModel.AdditionalRole))
self.assertFalse(m.data(m.index(1, 0), QgsMapLayerModel.AdditionalRole))
self.assertFalse(m.data(m.index(2, 0), QgsMapLayerModel.AdditionalRole))

m.setAdditionalItems(['a'])
self.assertFalse(m.data(m.index(0, 0), QgsMapLayerModel.IsAdditionalRole))
self.assertFalse(m.data(m.index(1, 0), QgsMapLayerModel.IsAdditionalRole))
self.assertFalse(m.data(m.index(2, 0), QgsMapLayerModel.IsAdditionalRole))
self.assertTrue(m.data(m.index(3, 0), QgsMapLayerModel.IsAdditionalRole))
self.assertFalse(m.data(m.index(0, 0), QgsMapLayerModel.AdditionalRole))
self.assertFalse(m.data(m.index(1, 0), QgsMapLayerModel.AdditionalRole))
self.assertFalse(m.data(m.index(2, 0), QgsMapLayerModel.AdditionalRole))
self.assertTrue(m.data(m.index(3, 0), QgsMapLayerModel.AdditionalRole))

QgsMapLayerRegistry.instance().removeMapLayers([l1.id(), l2.id()])

Expand Down

0 comments on commit 1da400a

Please sign in to comment.