Commit 7e678663 authored by Stéphane Albert's avatar Stéphane Albert

ENH: (Bug) Linked layer-stack visible checkbox update to change layer-model visibility state.

parent 341a795d
......@@ -81,9 +81,10 @@ AbstractLayerModel
/*******************************************************************************/
void
AbstractLayerModel
::virtual_SignalVisibilityChanged( bool isVisible ) const
::virtual_SignalVisibilityChanged( bool isVisible )
{
emit VisibilityChanged( isVisible );
emit VisibilityChanged( this, isVisible );
}
/*******************************************************************************/
......
......@@ -105,7 +105,8 @@ public slots:
signals:
/**
*/
void VisibilityChanged( bool =true ) const;
void VisibilityChanged( bool =true );
void VisibilityChanged( AbstractLayerModel *, bool );
/*-[ PROTECTED SECTION ]---------------------------------------------------*/
......@@ -128,7 +129,7 @@ private:
//
// VisibleInterface overloads.
void virtual_SignalVisibilityChanged( bool ) const;
void virtual_SignalVisibilityChanged( bool );
//
// Private attributes.
......
......@@ -171,6 +171,8 @@ public:
inline bool HasReference() const;
inline SizeType IndexOf( const AbstractLayerModel * ) const;
inline bool IsEmpty() const;
inline void SetCurrent( SizeType, bool =false );
......@@ -602,6 +604,27 @@ StackedLayerModel
return m_Reference;
}
/*****************************************************************************/
inline
StackedLayerModel::SizeType
StackedLayerModel
::IndexOf( const AbstractLayerModel * layer ) const
{
KeyType key( KeyOf( layer ) );
if( key==StackedLayerModel::NIL_KEY )
return StackedLayerModel::NIL_INDEX;
for( KeyVector::size_type i=0;
i<m_Keys.size();
++i )
if( m_Keys[ i ]==key )
return i;
return StackedLayerModel::NIL_INDEX;
}
/*****************************************************************************/
inline
bool
......
......@@ -80,7 +80,7 @@ VisibleInterface
/*******************************************************************************/
void
VisibleInterface
::virtual_SignalVisibilityChanged( bool ) const
::virtual_SignalVisibilityChanged( bool )
{
}
......
......@@ -110,7 +110,7 @@ protected:
private:
/**
*/
virtual void virtual_SignalVisibilityChanged( bool ) const;
virtual void virtual_SignalVisibilityChanged( bool );
//
// Private attributes.
......
......@@ -113,6 +113,38 @@ LayerStackItemModel
{
}
/*****************************************************************************/
void
LayerStackItemModel
::Connect( AbstractLayerModel * layer )
{
assert( layer!=NULL );
QObject::connect(
layer,
SIGNAL( VisibilityChanged( AbstractLayerModel *, bool ) ),
// to:*
this,
SLOT( OnLayerVisibilityChanged( AbstractLayerModel *, bool ) )
);
}
/*****************************************************************************/
void
LayerStackItemModel
::Disconnect( AbstractLayerModel * layer )
{
assert( layer!=NULL );
QObject::disconnect(
layer,
SIGNAL( VisibilityChanged( AbstractLayerModel *, bool ) ),
// to:*
this,
SLOT( OnLayerVisibilityChanged( AbstractLayerModel *, bool ) )
);
}
/*****************************************************************************/
void
LayerStackItemModel
......@@ -122,6 +154,11 @@ LayerStackItemModel
if( m_StackedLayerModel!=NULL )
{
for( StackedLayerModel::ConstIterator it( m_StackedLayerModel->Begin() );
it!=m_StackedLayerModel->End();
++it )
Disconnect( it->second );
QObject::disconnect(
m_StackedLayerModel,
SIGNAL( ContentAboutToBeReset() ),
......@@ -221,6 +258,11 @@ LayerStackItemModel
SIGNAL( layoutChanged() )
);
for( StackedLayerModel::ConstIterator it( m_StackedLayerModel->Begin() );
it!=m_StackedLayerModel->End();
++it )
Connect( it->second );
// emit layoutChanged();
}
......@@ -624,7 +666,15 @@ void
LayerStackItemModel
::OnLayerAdded( size_t index )
{
insertRow( index );
if( !insertRow( index ) )
{
assert( false && "QAbstractItemModel::insertRow() failed!" );
return;
}
assert( m_StackedLayerModel!=NULL );
Connect( m_StackedLayerModel->At( index ) );
}
/*****************************************************************************/
......@@ -632,7 +682,40 @@ void
LayerStackItemModel
::OnLayerDeleted( size_t index )
{
assert( m_StackedLayerModel!=NULL );
Disconnect( m_StackedLayerModel->At( index ) );
#ifdef _DEBUG
bool isRowRemoved =
#endif
removeRow( index );
#ifdef _DEBUG
assert( isRowRemoved && "QAbstractItemModel::removeRow() failed!" );
#endif
}
/*****************************************************************************/
void
LayerStackItemModel
::OnLayerVisibilityChanged( AbstractLayerModel * layer, bool isVisible )
{
qDebug() << this << "::OnLayerVisibilityChanged(" << layer << "," << isVisible << ")";
assert( m_StackedLayerModel!=NULL );
assert( m_StackedLayerModel->IndexOf( layer )!=StackedLayerModel::NIL_INDEX );
QModelIndex index(
createIndex(
m_StackedLayerModel->IndexOf( layer ),
COLUMN_NAME,
layer
)
);
emit dataChanged( index, index );
}
/*****************************************************************************/
......
......@@ -59,6 +59,7 @@ namespace mvd
{
//
// Internal classes pre-declaration.
class AbstractLayerModel;
class StackedLayerModel;
/*****************************************************************************/
......@@ -255,6 +256,14 @@ protected:
// Private methods.
private:
/**
*/
void Connect( AbstractLayerModel * );
/**
*/
void Disconnect( AbstractLayerModel * );
//
// Private attributes.
......@@ -276,6 +285,7 @@ private slots:
// void OnModelReset();
void OnLayerAdded( size_t );
void OnLayerDeleted( size_t );
void OnLayerVisibilityChanged( AbstractLayerModel *, bool );
};
} // end namespace 'mvd'.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment