#6462 Add reordering to color legend items

This commit is contained in:
Magne Sjaastad 2020-09-08 09:23:27 +02:00
parent b0448043f3
commit cbce19bb65
6 changed files with 62 additions and 16 deletions

View File

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

View File

@ -48,6 +48,7 @@ public:
QString colorLegendName();
void setReadOnly( bool doReadOnly );
void addReorderCapability();
void appendColorLegendItem( RimColorLegendItem* colorLegendItem );
std::vector<RimColorLegendItem*> 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<QString> m_colorLegendName;
caf::PdmChildArrayField<RimColorLegendItem*> m_colorLegendItems;

View File

@ -59,6 +59,7 @@ RimColorLegendCollection::~RimColorLegendCollection()
//--------------------------------------------------------------------------------------------------
void RimColorLegendCollection::appendCustomColorLegend( RimColorLegend* colorLegend )
{
colorLegend->addReorderCapability();
m_customColorLegends.push_back( colorLegend );
}
@ -157,15 +158,6 @@ std::vector<RimColorLegend*> 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();
}
}

View File

@ -43,19 +43,17 @@ public:
~RimColorLegendCollection() override;
void createStandardColorLegends();
void appendCustomColorLegend( RimColorLegend* customColorLegend );
bool isStandardColorLegend( RimColorLegend* colorLegend );
void deleteCustomColorLegends();
std::vector<RimColorLegend*> 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;

View File

@ -19,6 +19,8 @@
#include "RimColorLegendItem.h"
#include "RimColorLegend.h"
#include "cafPdmUiSliderEditor.h"
#include "cvfColor3.h"
#include <QColor>
@ -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<caf::PdmUiSliderEditorAttribute*>( 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
//--------------------------------------------------------------------------------------------------

View File

@ -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;