Skip to content
Permalink
Browse files

Rename enum values for consistency

  • Loading branch information
nyalldawson committed Nov 16, 2016
1 parent fc65334 commit 1da400a99de1d8fec1eba454d25cd0736e2d28d3
@@ -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
};

/**
@@ -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 )
@@ -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
};

/**
@@ -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() );
@@ -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;
@@ -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()])

@@ -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()])

0 comments on commit 1da400a

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