mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Various operations on color legends
This commit is contained in:
committed by
Magne Sjaastad
parent
fd475589a5
commit
d39bcb31ab
@@ -44,9 +44,9 @@ RimColorLegend::~RimColorLegend()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmFieldHandle* RimColorLegend::userDescriptionField()
|
||||
QString RimColorLegend::colorLegendName()
|
||||
{
|
||||
return &m_colorLegendName;
|
||||
return m_colorLegendName;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -57,6 +57,19 @@ void RimColorLegend::setColorLegendName( const QString& colorLegendName )
|
||||
m_colorLegendName = colorLegendName;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimColorLegend::setReadOnly( bool doReadOnly )
|
||||
{
|
||||
m_colorLegendName.uiCapability()->setUiReadOnly( true );
|
||||
|
||||
for ( auto colorLegendItem : m_colorLegendItems )
|
||||
{
|
||||
colorLegendItem->setReadOnly( true );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -73,6 +86,14 @@ std::vector<RimColorLegendItem*> RimColorLegend::colorLegendItems() const
|
||||
return m_colorLegendItems.childObjects();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmFieldHandle* RimColorLegend::userDescriptionField()
|
||||
{
|
||||
return &m_colorLegendName;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -42,7 +42,12 @@ public:
|
||||
~RimColorLegend() override;
|
||||
|
||||
public:
|
||||
QString colorLegendName();
|
||||
|
||||
void setColorLegendName( const QString& colorLegendName );
|
||||
|
||||
void setReadOnly( bool doReadOnly );
|
||||
|
||||
void appendColorLegendItem( RimColorLegendItem* colorLegendItem );
|
||||
|
||||
std::vector<RimColorLegendItem*> colorLegendItems() const;
|
||||
|
||||
@@ -18,6 +18,11 @@
|
||||
|
||||
#include "RimColorLegendCollection.h"
|
||||
#include "RimColorLegend.h"
|
||||
#include "RimRegularLegendConfig.h"
|
||||
|
||||
#include "RimColorLegendItem.h"
|
||||
#include "RimProject.h"
|
||||
#include <QString>
|
||||
|
||||
CAF_PDM_SOURCE_INIT( RimColorLegendCollection, "ColorLegendCollection" );
|
||||
|
||||
@@ -26,10 +31,16 @@ CAF_PDM_SOURCE_INIT( RimColorLegendCollection, "ColorLegendCollection" );
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimColorLegendCollection::RimColorLegendCollection()
|
||||
{
|
||||
CAF_PDM_InitObject( "ColorLegendCollection", ":/Formations16x16.png", "", "" );
|
||||
CAF_PDM_InitObject( "Color Legend Collection", ":/Legend.png", "", "" );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_colorLegends, "ColorLegends", "", "", "", "" );
|
||||
m_colorLegends.uiCapability()->setUiHidden( true );
|
||||
CAF_PDM_InitFieldNoDefault( &m_standardColorLegends,
|
||||
"StandardColorLegends",
|
||||
"Standard Color Legends",
|
||||
":/Legend.png",
|
||||
"",
|
||||
"" );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_customColorLegends, "CustomColorLegends", "Custom Color Legends", ":/Legend.png", "", "" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -42,17 +53,86 @@ RimColorLegendCollection::~RimColorLegendCollection()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimColorLegendCollection::appendColorLegend( RimColorLegend* colorLegend )
|
||||
void RimColorLegendCollection::appendCustomColorLegend( RimColorLegend* colorLegend )
|
||||
{
|
||||
m_colorLegends.push_back( colorLegend );
|
||||
m_customColorLegends.push_back( colorLegend );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<RimColorLegend*> RimColorLegendCollection::colorLegends() const
|
||||
bool RimColorLegendCollection::isStandardColorLegend( RimColorLegend* legend )
|
||||
{
|
||||
return m_colorLegends.childObjects();
|
||||
for ( auto standardLegend : m_standardColorLegends )
|
||||
{
|
||||
if ( legend == standardLegend ) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimColorLegendCollection::deleteCustomColorLegends()
|
||||
{
|
||||
m_customColorLegends.deleteAllChildObjects();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimColorLegendCollection::createStandardColorLegends()
|
||||
{
|
||||
typedef caf::AppEnum<RimRegularLegendConfig::ColorRangesType> ColorRangeEnum;
|
||||
|
||||
for ( size_t typeIdx = 0; typeIdx < ColorRangeEnum::size(); typeIdx++ )
|
||||
{
|
||||
QString legendName = ColorRangeEnum::uiTextFromIndex( typeIdx );
|
||||
cvf::Color3ubArray colorArray =
|
||||
RimRegularLegendConfig::colorArrayFromColorType( ColorRangeEnum::fromIndex( typeIdx ) );
|
||||
|
||||
RimColorLegend* colorLegend = new RimColorLegend;
|
||||
colorLegend->setColorLegendName( legendName );
|
||||
|
||||
for ( int i = (int)colorArray.size() - 1; i > -1; i-- ) // reverse to assign last color to top of legend
|
||||
{
|
||||
cvf::Color3f color3f( colorArray[i] );
|
||||
QColor colorQ( colorArray[i].r(), colorArray[i].g(), colorArray[i].b() );
|
||||
|
||||
RimColorLegendItem* colorLegendItem = new RimColorLegendItem;
|
||||
colorLegendItem->setValues( colorQ.name(), i, color3f );
|
||||
|
||||
colorLegend->appendColorLegendItem( colorLegendItem );
|
||||
colorLegend->setReadOnly( true );
|
||||
}
|
||||
|
||||
m_standardColorLegends.push_back( colorLegend );
|
||||
}
|
||||
|
||||
this->updateConnectedEditors();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<RimColorLegend*> RimColorLegendCollection::customColorLegends() const
|
||||
{
|
||||
std::vector<RimColorLegend*> allLegends;
|
||||
|
||||
auto standardLegends = m_standardColorLegends.childObjects();
|
||||
for ( auto l : standardLegends )
|
||||
{
|
||||
allLegends.push_back( l );
|
||||
}
|
||||
|
||||
auto customLegends = m_customColorLegends.childObjects();
|
||||
for ( auto l : customLegends )
|
||||
{
|
||||
allLegends.push_back( l );
|
||||
}
|
||||
|
||||
return allLegends;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -41,12 +41,19 @@ public:
|
||||
RimColorLegendCollection();
|
||||
~RimColorLegendCollection() override;
|
||||
|
||||
void appendColorLegend( RimColorLegend* colorLegend );
|
||||
void createStandardColorLegends();
|
||||
|
||||
std::vector<RimColorLegend*> colorLegends() const;
|
||||
void appendCustomColorLegend( RimColorLegend* customColorLegend );
|
||||
|
||||
bool isStandardColorLegend( RimColorLegend* colorLegend );
|
||||
|
||||
void deleteCustomColorLegends();
|
||||
|
||||
std::vector<RimColorLegend*> customColorLegends() const;
|
||||
|
||||
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
|
||||
|
||||
private:
|
||||
caf::PdmChildArrayField<RimColorLegend*> m_colorLegends;
|
||||
caf::PdmChildArrayField<RimColorLegend*> m_standardColorLegends; // ResInsight standard (built-in) legends
|
||||
caf::PdmChildArrayField<RimColorLegend*> m_customColorLegends; // user specified legends
|
||||
};
|
||||
|
||||
@@ -33,6 +33,7 @@ RimColorLegendItem::RimColorLegendItem()
|
||||
CAF_PDM_InitObject( "ColorLegendItem", "", "", "" );
|
||||
|
||||
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_categoryName, "CategoryName", QString( "" ), "Category Name", "", "", "" );
|
||||
@@ -60,6 +61,16 @@ void RimColorLegendItem::setValues( const QString& categoryName, int categoryVal
|
||||
m_color = color;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimColorLegendItem::setReadOnly( bool doReadOnly )
|
||||
{
|
||||
m_categoryName.uiCapability()->setUiReadOnly( true );
|
||||
m_categoryValue.uiCapability()->setUiReadOnly( true );
|
||||
m_color.uiCapability()->setUiReadOnly( true );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -41,7 +41,9 @@ public:
|
||||
RimColorLegendItem();
|
||||
~RimColorLegendItem() override;
|
||||
|
||||
void setValues( const QString& categoryName, int categoryValue, const cvf::Color3f& color );
|
||||
void setValues( const QString& categoryName, int categoryValue, const cvf::Color3f& color );
|
||||
void setReadOnly( bool doReadOnly );
|
||||
|
||||
const cvf::Color3f& color() const;
|
||||
const QString& categoryName() const;
|
||||
int categoryValue() const;
|
||||
@@ -49,6 +51,7 @@ public:
|
||||
public:
|
||||
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
|
||||
void defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName /*= ""*/ ) override;
|
||||
|
||||
caf::PdmFieldHandle* userDescriptionField() override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -39,7 +39,9 @@
|
||||
#include "RimCellEdgeColors.h"
|
||||
#include "RimCellRangeFilter.h"
|
||||
#include "RimCellRangeFilterCollection.h"
|
||||
#include "RimColorLegend.h"
|
||||
#include "RimColorLegendCollection.h"
|
||||
#include "RimColorLegendItem.h"
|
||||
#include "RimCorrelationMatrixPlot.h"
|
||||
#include "RimCorrelationPlot.h"
|
||||
#include "RimCorrelationPlotCollection.h"
|
||||
@@ -792,8 +794,20 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
|
||||
}
|
||||
else if ( dynamic_cast<RimColorLegendCollection*>( firstUiItem ) )
|
||||
{
|
||||
menuBuilder << "RicImportColorCategories";
|
||||
menuBuilder << "RicInsertColorLegendFeature";
|
||||
menuBuilder << "RicImportColorCategoriesFeature"; // import of color legend from LYR file
|
||||
}
|
||||
else if ( dynamic_cast<RimColorLegend*>( firstUiItem ) )
|
||||
{
|
||||
menuBuilder << "RicInsertColorLegendFeature";
|
||||
menuBuilder << "RicCopyStandardLegendFeature";
|
||||
menuBuilder << "RicInsertColorLegendItemFeature";
|
||||
}
|
||||
else if ( dynamic_cast<RimColorLegendItem*>( firstUiItem ) )
|
||||
{
|
||||
menuBuilder << "RicInsertColorLegendItemFeature";
|
||||
}
|
||||
|
||||
else if ( dynamic_cast<RimFormationNames*>( firstUiItem ) )
|
||||
{
|
||||
menuBuilder << "RicImportFormationNamesFeature";
|
||||
|
||||
@@ -133,6 +133,7 @@ RimProject::RimProject( void )
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &colorLegendCollection, "ColorLegendCollection", "Color Legend Collection", "", "", "" );
|
||||
colorLegendCollection = new RimColorLegendCollection();
|
||||
colorLegendCollection->createStandardColorLegends();
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &scriptCollection, "ScriptCollection", "Octave Scripts", ":/octave.png", "", "" );
|
||||
scriptCollection.uiCapability()->setUiHidden( true );
|
||||
@@ -256,6 +257,7 @@ void RimProject::close()
|
||||
m_dialogData->clearProjectSpecificData();
|
||||
|
||||
calculationCollection->deleteAllContainedObjects();
|
||||
colorLegendCollection->deleteCustomColorLegends();
|
||||
|
||||
delete viewLinkerCollection->viewLinker();
|
||||
viewLinkerCollection->viewLinker = nullptr;
|
||||
|
||||
@@ -2525,7 +2525,7 @@ void RimWellLogTrack::updateResultPropertyNamesOnPlot()
|
||||
|
||||
RimProject* proj = RimProject::current();
|
||||
RimColorLegendCollection* colorLegendCollection = proj->colorLegendCollection;
|
||||
std::vector<RimColorLegend*> legends = colorLegendCollection->colorLegends();
|
||||
std::vector<RimColorLegend*> legends = colorLegendCollection->customColorLegends();
|
||||
if ( legends.empty() )
|
||||
{
|
||||
RiaLogging::error( "No color legend found." );
|
||||
|
||||
Reference in New Issue
Block a user