From cbce19bb65344588d1cc48381a6ccd986736f280 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 8 Sep 2020 09:23:27 +0200 Subject: [PATCH] #6462 Add reordering to color legend items --- .../ProjectDataModel/RimColorLegend.cpp | 19 +++++++++++++++++ .../ProjectDataModel/RimColorLegend.h | 4 ++++ .../RimColorLegendCollection.cpp | 21 +++++++++++-------- .../RimColorLegendCollection.h | 8 +++---- .../ProjectDataModel/RimColorLegendItem.cpp | 21 ++++++++++++++++++- .../ProjectDataModel/RimColorLegendItem.h | 5 ++++- 6 files changed, 62 insertions(+), 16 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/RimColorLegend.cpp b/ApplicationCode/ProjectDataModel/RimColorLegend.cpp index 798b7ca86b..b0d29956f8 100644 --- a/ApplicationCode/ProjectDataModel/RimColorLegend.cpp +++ b/ApplicationCode/ProjectDataModel/RimColorLegend.cpp @@ -23,6 +23,8 @@ #include "Rim3dView.h" #include "RimColorLegendItem.h" +#include "cafPdmFieldReorderCapability.h" + CAF_PDM_SOURCE_INIT( RimColorLegend, "ColorLegend" ); //-------------------------------------------------------------------------------------------------- @@ -77,6 +79,15 @@ void RimColorLegend::setReadOnly( bool doReadOnly ) } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimColorLegend::addReorderCapability() +{ + auto reorderability = caf::PdmFieldReorderCapability::addToField( &m_colorLegendItems ); + reorderability->orderChanged.connect( this, &RimColorLegend::orderChanged ); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -118,6 +129,14 @@ void RimColorLegend::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrderin this->setUiIcon( paletteIconProvider() ); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimColorLegend::orderChanged( const caf::SignalEmitter* emitter ) +{ + onColorLegendItemHasChanged(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimColorLegend.h b/ApplicationCode/ProjectDataModel/RimColorLegend.h index c10b53737f..49c34d2ce0 100644 --- a/ApplicationCode/ProjectDataModel/RimColorLegend.h +++ b/ApplicationCode/ProjectDataModel/RimColorLegend.h @@ -48,6 +48,7 @@ public: QString colorLegendName(); void setReadOnly( bool doReadOnly ); + void addReorderCapability(); void appendColorLegendItem( RimColorLegendItem* colorLegendItem ); std::vector colorLegendItems() const; @@ -63,6 +64,9 @@ public: void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override; void defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName ) override; +private: + void orderChanged( const caf::SignalEmitter* emitter ); + private: caf::PdmField m_colorLegendName; caf::PdmChildArrayField m_colorLegendItems; diff --git a/ApplicationCode/ProjectDataModel/RimColorLegendCollection.cpp b/ApplicationCode/ProjectDataModel/RimColorLegendCollection.cpp index 7e85b61503..e2bc5fd485 100644 --- a/ApplicationCode/ProjectDataModel/RimColorLegendCollection.cpp +++ b/ApplicationCode/ProjectDataModel/RimColorLegendCollection.cpp @@ -59,6 +59,7 @@ RimColorLegendCollection::~RimColorLegendCollection() //-------------------------------------------------------------------------------------------------- void RimColorLegendCollection::appendCustomColorLegend( RimColorLegend* colorLegend ) { + colorLegend->addReorderCapability(); m_customColorLegends.push_back( colorLegend ); } @@ -157,15 +158,6 @@ std::vector RimColorLegendCollection::allColorLegends() const return allLegends; } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimColorLegendCollection::fieldChangedByUi( const caf::PdmFieldHandle* changedField, - const QVariant& oldValue, - const QVariant& newValue ) -{ -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -258,3 +250,14 @@ RimColorLegend* RimColorLegendCollection::createRockTypeColorLegend() const return colorLegend; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimColorLegendCollection::initAfterRead() +{ + for ( auto legend : m_customColorLegends ) + { + legend->addReorderCapability(); + } +} diff --git a/ApplicationCode/ProjectDataModel/RimColorLegendCollection.h b/ApplicationCode/ProjectDataModel/RimColorLegendCollection.h index 4d028a9c28..c9efc63e8a 100644 --- a/ApplicationCode/ProjectDataModel/RimColorLegendCollection.h +++ b/ApplicationCode/ProjectDataModel/RimColorLegendCollection.h @@ -43,19 +43,17 @@ public: ~RimColorLegendCollection() override; void createStandardColorLegends(); - void appendCustomColorLegend( RimColorLegend* customColorLegend ); - bool isStandardColorLegend( RimColorLegend* colorLegend ); - void deleteCustomColorLegends(); std::vector allColorLegends() const; - void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override; - RimColorLegend* findByName( const QString& name ) const; +protected: + void initAfterRead() override; + private: RimColorLegendItem* createColorLegendItem( const QString& name, int r, int g, int b ) const; RimColorLegend* createRockTypeColorLegend() const; diff --git a/ApplicationCode/ProjectDataModel/RimColorLegendItem.cpp b/ApplicationCode/ProjectDataModel/RimColorLegendItem.cpp index e987fb6e80..f49a4692cc 100644 --- a/ApplicationCode/ProjectDataModel/RimColorLegendItem.cpp +++ b/ApplicationCode/ProjectDataModel/RimColorLegendItem.cpp @@ -19,6 +19,8 @@ #include "RimColorLegendItem.h" #include "RimColorLegend.h" +#include "cafPdmUiSliderEditor.h" + #include "cvfColor3.h" #include @@ -36,7 +38,9 @@ RimColorLegendItem::RimColorLegendItem() CAF_PDM_InitFieldNoDefault( &m_color, "Color", "Color", "", "", "" ); m_color = cvf::Color3f( cvf::Color3::ColorIdent::BLACK ); - CAF_PDM_InitField( &m_categoryValue, "CategoryValue", 0, "Category Value", "", "", "" ); + CAF_PDM_InitField( &m_categoryValue, "CategoryValue", 0, "Category Number", "", "", "" ); + m_categoryValue.uiCapability()->setUiEditorTypeName( caf::PdmUiSliderEditor::uiEditorTypeName() ); + CAF_PDM_InitField( &m_categoryName, "CategoryName", QString( "" ), "Category Name", "", "", "" ); CAF_PDM_InitFieldNoDefault( &m_nameProxy, "NameProxy", "Name Proxy", "", "", "" ); @@ -130,6 +134,21 @@ caf::PdmFieldHandle* RimColorLegendItem::userDescriptionField() return &m_nameProxy; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimColorLegendItem::defineEditorAttribute( const caf::PdmFieldHandle* field, + QString uiConfigName, + caf::PdmUiEditorAttribute* attribute ) +{ + caf::PdmUiSliderEditorAttribute* myAttr = dynamic_cast( attribute ); + if ( myAttr ) + { + myAttr->m_minimum = 0; + myAttr->m_maximum = 100; + } +} + //-------------------------------------------------------------------------------------------------- /// "stringify" category value and name; category value with leading zeros presupposing max 2 digits //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimColorLegendItem.h b/ApplicationCode/ProjectDataModel/RimColorLegendItem.h index ea11bc9b76..a432258c7c 100644 --- a/ApplicationCode/ProjectDataModel/RimColorLegendItem.h +++ b/ApplicationCode/ProjectDataModel/RimColorLegendItem.h @@ -51,9 +51,12 @@ public: QString itemName() const; -public: +private: void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override; void defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName /*= ""*/ ) override; + void defineEditorAttribute( const caf::PdmFieldHandle* field, + QString uiConfigName, + caf::PdmUiEditorAttribute* attribute ) override; caf::PdmFieldHandle* userDescriptionField() override;