From 398b1f69239c413476f100add1c8445941feaec7 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero <guillaume.pasero@c-s.fr> Date: Fri, 15 Sep 2017 09:38:06 +0200 Subject: [PATCH] BUG: Mantis-1420: handle the layer name as an alias --- .../include/mvdAbstractLayerModel.h | 7 +++ .../src/mvdAbstractLayerModel.cxx | 22 ++++++- .../src/mvdVectorImageModel.cxx | 1 + .../src/mvdLayerStackItemModel.cxx | 60 ++++++++++--------- 4 files changed, 60 insertions(+), 30 deletions(-) diff --git a/Modules/Visualization/MonteverdiCore/include/mvdAbstractLayerModel.h b/Modules/Visualization/MonteverdiCore/include/mvdAbstractLayerModel.h index ce0c2bdff6..b970cef9ce 100644 --- a/Modules/Visualization/MonteverdiCore/include/mvdAbstractLayerModel.h +++ b/Modules/Visualization/MonteverdiCore/include/mvdAbstractLayerModel.h @@ -139,6 +139,12 @@ public: */ void ToWgs84( const PointType &, PointType & wgs84, double & alt ) const; + /** Setter for the m_Name attribute ( should be initialized by subclasses )*/ + void SetName(const QString & name); + + /** Getter for the m_Name attribute */ + const QString & GetName() const; + /*-[ PUBLIC SLOTS SECTION ]------------------------------------------------*/ // @@ -198,6 +204,7 @@ private: // Private attributes. private: + QString m_Name; /*-[ PRIVATE SLOTS SECTION ]-----------------------------------------------*/ // diff --git a/Modules/Visualization/MonteverdiCore/src/mvdAbstractLayerModel.cxx b/Modules/Visualization/MonteverdiCore/src/mvdAbstractLayerModel.cxx index caac49abe2..84aefd2297 100644 --- a/Modules/Visualization/MonteverdiCore/src/mvdAbstractLayerModel.cxx +++ b/Modules/Visualization/MonteverdiCore/src/mvdAbstractLayerModel.cxx @@ -114,7 +114,8 @@ GetSpatialReferenceType( const std::string & wkt, bool hasKwl ) AbstractLayerModel ::AbstractLayerModel( QObject* p ) : AbstractModel( p ), - VisibleInterface() + VisibleInterface(), + m_Name(QString()) { } @@ -180,6 +181,25 @@ AbstractLayerModel virtual_ToWgs84( p, wgs84, alt ); } +/*****************************************************************************/ +void +AbstractLayerModel +::SetName(const QString & name) +{ + if (name != m_Name) + { + m_Name = name; + } +} + +/*****************************************************************************/ +const QString & +AbstractLayerModel +::GetName() const +{ + return m_Name; +} + /*******************************************************************************/ bool AbstractLayerModel diff --git a/Modules/Visualization/MonteverdiCore/src/mvdVectorImageModel.cxx b/Modules/Visualization/MonteverdiCore/src/mvdVectorImageModel.cxx index c60019e18f..378763d26e 100644 --- a/Modules/Visualization/MonteverdiCore/src/mvdVectorImageModel.cxx +++ b/Modules/Visualization/MonteverdiCore/src/mvdVectorImageModel.cxx @@ -94,6 +94,7 @@ VectorImageModel ::SetFilename( const QString& filename , int w, int h) { setObjectName( filename ); + SetName( QFileInfo( filename ).fileName() ); // 1. store the input filename FilenameInterface::SetFilename( filename ); diff --git a/Modules/Visualization/MonteverdiGui/src/mvdLayerStackItemModel.cxx b/Modules/Visualization/MonteverdiGui/src/mvdLayerStackItemModel.cxx index e6c7a548b4..cc073ecd5f 100644 --- a/Modules/Visualization/MonteverdiGui/src/mvdLayerStackItemModel.cxx +++ b/Modules/Visualization/MonteverdiGui/src/mvdLayerStackItemModel.cxx @@ -423,6 +423,7 @@ LayerStackItemModel } break; + case Qt::EditRole: case Qt::DisplayRole: switch( idx.column() ) { @@ -447,21 +448,7 @@ LayerStackItemModel break; case COLUMN_NAME: - if( layer->inherits( - VectorImageModel::staticMetaObject.className() ) ) - { - const VectorImageModel * vectorImageModel = - qobject_cast< const VectorImageModel * >( layer ); - assert( vectorImageModel!=NULL ); - - // qDebug() << "filename:" << vectorImageModel->GetFilename(); - - return QFileInfo( vectorImageModel->GetFilename() ).fileName(); - } - else - { - qDebug() << "Unhandled AbstractLayerModel subclass."; - } + return layer->GetName(); break; case COLUMN_EFFECT: @@ -842,7 +829,7 @@ LayerStackItemModel // qDebug() // << this << "::setData(" << idx << "," << value << "," << role << ")"; - if( idx.column()==COLUMN_NAME && role==Qt::CheckStateRole ) + if( idx.column()==COLUMN_NAME ) { // qDebug() << idx.row() << "check-state:" << value; @@ -856,30 +843,45 @@ LayerStackItemModel assert( layer!=NULL ); assert( layer==dynamic_cast< VisibleInterface * >( layer ) ); - VisibleInterface * interface = dynamic_cast< VisibleInterface * >( layer ); assert( interface!=NULL ); - switch( value.toInt() ) + switch( role ) { - case Qt::Checked: - interface->SetVisible( true ); + case Qt::EditRole: + { + QString strValue = value.toString(); + if( !strValue.isEmpty() ) + { + layer->SetName( strValue ); + emit dataChanged( idx, idx ); + return true; + } + } break; - - case Qt::Unchecked: - interface->SetVisible( false ); + case Qt::CheckStateRole: + 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( idx, idx ); + return true; break; default: - assert( false && "Unhandled Qt::CheckedState value." ); break; } - - emit dataChanged( idx, idx ); - - return true; } - return false; } -- GitLab