Commit 37942582 authored by Stéphane Albert's avatar Stéphane Albert

(Mv2) Implemented visible check-box in layer-stack.

parent 762e8999
......@@ -1711,7 +1711,7 @@ void
MainWindow
::OnReferenceLayerChanged( size_t index )
{
qDebug() << this << "::OnReferenceLayerChanged(" << index << ")";
// qDebug() << this << "::OnReferenceLayerChanged(" << index << ")";
//
// Access widget.
......@@ -1747,7 +1747,7 @@ void
MainWindow
::OnReferenceLayerCurrentIndexChanged( int index )
{
qDebug() << this << "::OnReferenceLayerCurrentIndexChanged(" << index << ")";
// qDebug() << this << "::OnReferenceLayerCurrentIndexChanged(" << index << ")";
//
// Access widget.
......@@ -1784,7 +1784,7 @@ void
MainWindow
::RefreshReferenceLayerComboBox()
{
qDebug() << this << "::RefreshReferenceLayerComboBox()";
// qDebug() << this << "::RefreshReferenceLayerComboBox()";
assert( I18nCoreApplication::Instance()!=NULL );
assert( I18nCoreApplication::Instance()->GetModel()==
......
......@@ -29,6 +29,7 @@ set( Common_Core_SOURCES
mvdTextStream.cxx
mvdTypes.cxx
mvdVectorImageModel.cxx
mvdVisibleInterface.cxx
)
#############################################################################
......
......@@ -67,7 +67,8 @@ namespace
/*******************************************************************************/
AbstractLayerModel
::AbstractLayerModel( QObject* parent ) :
AbstractModel( parent )
AbstractModel( parent ),
VisibleInterface()
{
}
......
......@@ -44,8 +44,8 @@
//
// Monteverdi includes (sorted by alphabetic order)
#include "mvdAbstractModel.h"
#include "Core/mvdAbstractModel.h"
#include "Core/mvdVisibleInterface.h"
/*****************************************************************************/
/* PRE-DECLARATION SECTION */
......@@ -71,7 +71,8 @@ namespace mvd
* \brief WIP.
*/
class Monteverdi2_EXPORT AbstractLayerModel :
public AbstractModel
public AbstractModel,
public VisibleInterface
{
/*-[ QOBJECT SECTION ]-----------------------------------------------------*/
......
/*=========================================================================
Program: Monteverdi2
Language: C++
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See Copyright.txt for details.
Monteverdi2 is distributed under the CeCILL licence version 2. See
Licence_CeCILL_V2-en.txt or
http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt for more details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "mvdVisibleInterface.h"
/*****************************************************************************/
/* INCLUDE SECTION */
//
// Qt includes (sorted by alphabetic order)
//// Must be included before system/custom includes.
//
// System includes (sorted by alphabetic order)
//
// ITK includes (sorted by alphabetic order)
//
// OTB includes (sorted by alphabetic order)
//
// Monteverdi includes (sorted by alphabetic order)
namespace mvd
{
/*
TRANSLATOR mvd::VisibleInterface
Necessary for lupdate to be aware of C++ namespaces.
Context comment for translator.
*/
/*****************************************************************************/
/* CONSTANTS */
namespace
{
} // end of anonymous namespace.
/*****************************************************************************/
/* STATIC IMPLEMENTATION SECTION */
/*****************************************************************************/
/* CLASS IMPLEMENTATION SECTION */
/*******************************************************************************/
VisibleInterface
::VisibleInterface( bool isVisible ) :
m_IsVisible( isVisible )
{
}
/*******************************************************************************/
VisibleInterface
::~VisibleInterface()
{
}
/*******************************************************************************/
void
VisibleInterface
::virtual_SignalVisibilityChanged( bool ) const
{
}
/*******************************************************************************/
/* SLOTS */
/*******************************************************************************/
} // end namespace 'mvd'
/*=========================================================================
Program: Monteverdi2
Language: C++
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See Copyright.txt for details.
Monteverdi2 is distributed under the CeCILL licence version 2. See
Licence_CeCILL_V2-en.txt or
http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt for more details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __mvdVisibleInterface_h
#define __mvdVisibleInterface_h
//
// Configuration include.
//// Included at first position before any other ones.
#include "ConfigureMonteverdi2.h"
/*****************************************************************************/
/* INCLUDE SECTION */
//
// Qt includes (sorted by alphabetic order)
//// Must be included before system/custom includes.
//
// System includes (sorted by alphabetic order)
//
// ITK includes (sorted by alphabetic order)
//
// OTB includes (sorted by alphabetic order)
//
// Monteverdi includes (sorted by alphabetic order)
/*****************************************************************************/
/* PRE-DECLARATION SECTION */
//
// External classes pre-declaration.
namespace
{
}
namespace mvd
{
//
// Internal classes pre-declaration.
/*****************************************************************************/
/* CLASS DEFINITION SECTION */
/**
* \class VisibleInterface
*
* \brief WIP.
*/
class Monteverdi2_EXPORT VisibleInterface
{
/*-[ PUBLIC SECTION ]------------------------------------------------------*/
//
// Public methods.
public:
/** \brief Constructor. */
VisibleInterface( bool =true );
/** \brief Destructor. */
virtual ~VisibleInterface();
/**
*/
inline void SetVisible( bool );
/**
*/
inline bool IsVisible() const;
/*-[ PROTECTED SECTION ]---------------------------------------------------*/
//
// Protected methods.
protected:
//
// Protected attributes.
protected:
/*-[ PRIVATE SECTION ]-----------------------------------------------------*/
//
// Private methods.
private:
/**
*/
virtual void virtual_SignalVisibilityChanged( bool ) const;
//
// Private attributes.
private:
bool m_IsVisible: 1;
};
} // end namespace 'mvd'.
/*****************************************************************************/
/* INLINE SECTION */
//
// Qt includes (sorted by alphabetic order)
//// Must be included before system/custom includes.
//
// System includes (sorted by alphabetic order)
//
// ITK includes (sorted by alphabetic order)
//
// OTB includes (sorted by alphabetic order)
//
// Monteverdi includes (sorted by alphabetic order)
namespace mvd
{
/*****************************************************************************/
inline
bool
VisibleInterface
::IsVisible() const
{
return m_IsVisible;
}
/*****************************************************************************/
inline
void
VisibleInterface
::SetVisible( bool state )
{
m_IsVisible = state;
virtual_SignalVisibilityChanged( state );
}
} // end namespace 'mvd'
#endif // __mvdVisibleInterface_h
......@@ -41,6 +41,7 @@
#include "Core/mvdAbstractLayerModel.h"
#include "Core/mvdStackedLayerModel.h"
#include "Core/mvdVectorImageModel.h"
#include "Core/mvdVisibleInterface.h"
namespace mvd
{
......@@ -241,9 +242,34 @@ LayerStackItemModel
::data( const QModelIndex & index, int role ) const
{
// qDebug() << this << "::data(" << index << "," << role << ")";
switch( role )
{
case Qt::CheckStateRole:
if( index.column()!=COLUMN_NAME )
return QVariant();
else
{
assert( !index.parent().isValid() );
assert( index.internalPointer()!=NULL );
AbstractLayerModel * layer =
static_cast< AbstractLayerModel * >( index.internalPointer() );
assert( layer!=NULL );
assert( layer==dynamic_cast< VisibleInterface * >( layer ) );
VisibleInterface * interface =
dynamic_cast< VisibleInterface * >( layer );
assert( interface!=NULL );
return
interface->IsVisible()
? Qt::Checked
: Qt::Unchecked;
}
break;
case Qt::DisplayRole:
switch( index.column() )
{
......@@ -256,7 +282,8 @@ LayerStackItemModel
assert( m_StackedLayerModel!=NULL );
const AbstractLayerModel * layerModel =
m_StackedLayerModel->At( index.row() );
static_cast< AbstractLayerModel * >( index.internalPointer() );
// m_StackedLayerModel->At( index.row() );
assert( layerModel!=NULL );
......@@ -314,11 +341,16 @@ LayerStackItemModel
if( !index.isValid() )
return QAbstractItemModel::flags( index );
return
Qt::ItemFlags flags =
QAbstractItemModel::flags( index )
// | Qt::ItemIsDragEnabled
// | Qt::ItemIsDropEnabled
| Qt::ItemIsUserCheckable;
;
if( index.column()==COLUMN_NAME )
flags |= Qt::ItemIsUserCheckable | Qt::ItemIsEditable;
return flags;
}
/*****************************************************************************/
......@@ -500,6 +532,44 @@ LayerStackItemModel
// qDebug()
// << this << "::setData(" << index << "," << value << "," << role << ")";
if( index.column()==COLUMN_NAME && role==Qt::CheckStateRole )
{
// qDebug() << index.row() << "check-state:" << value;
assert( !index.parent().isValid() );
assert( index.internalPointer()!=NULL );
assert( index.internalPointer()!=NULL );
AbstractLayerModel * layer =
static_cast< AbstractLayerModel * >( index.internalPointer() );
assert( layer!=NULL );
assert( layer==dynamic_cast< VisibleInterface * >( layer ) );
VisibleInterface * interface = dynamic_cast< VisibleInterface * >( layer );
assert( interface!=NULL );
switch( value.toInt() )
{
case Qt::Checked:
interface->SetVisible( true );
break;
case Qt::Unchecked:
interface->SetVisible( false );
break;
default:
assert( false && "Unhandled Qt::CheckedState value." );
break;
}
emit dataChanged( index, index );
return true;
}
return false;
}
......
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