Added updateUiIconFromState() in cafPdmUiItem to create disabled icons based on object state

Use updateUiIconFromState() from collection objects
p4#: 21459
This commit is contained in:
Magne Sjaastad 2013-04-26 14:47:34 +02:00
parent 4b8e30e649
commit 0b2e19926d
11 changed files with 57 additions and 83 deletions

View File

@ -35,6 +35,9 @@ Rim3dOverlayInfoConfig::Rim3dOverlayInfoConfig()
{
CAF_PDM_InitObject("Overlay 3D info", ":/Legend.png", "", "");
CAF_PDM_InitField(&active, "Active", true, "Active", "", "", "");
active.setUiHidden(true);
CAF_PDM_InitField(&showInfoText, "ShowInfoText", true, "Info Text", "", "", "");
CAF_PDM_InitField(&showAnimProgress, "ShowAnimProgress", true, "Animation progress", "", "", "");
CAF_PDM_InitField(&showHistogram, "ShowHistogram", true, "Histogram", "", "", "");
@ -70,8 +73,19 @@ void Rim3dOverlayInfoConfig::setPosition(cvf::Vec2ui position)
//--------------------------------------------------------------------------------------------------
void Rim3dOverlayInfoConfig::update3DInfo()
{
this->updateUiIconFromState(active);
if (!m_reservoirView) return;
if (!m_reservoirView->viewer()) return;
if (!this->active())
{
m_reservoirView->viewer()->showInfoText(false);
m_reservoirView->viewer()->showHistogram(false);
m_reservoirView->viewer()->showAnimationProgress(false);
return;
}
m_reservoirView->viewer()->showInfoText(showInfoText());
m_reservoirView->viewer()->showHistogram(false);
@ -172,3 +186,11 @@ void Rim3dOverlayInfoConfig::update3DInfo()
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmFieldHandle* Rim3dOverlayInfoConfig::objectToggleField()
{
return &active;
}

View File

@ -29,7 +29,7 @@ class RimReservoirView;
///
///
//==================================================================================================
class Rim3dOverlayInfoConfig: public caf::PdmObject
class Rim3dOverlayInfoConfig : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
@ -41,13 +41,14 @@ public:
void setReservoirView(RimReservoirView* ownerReservoirView) {m_reservoirView = ownerReservoirView; }
void setPosition(cvf::Vec2ui position);
caf::PdmField<bool> active;
caf::PdmField<bool> showInfoText;
caf::PdmField<bool> showAnimProgress;
caf::PdmField<bool> showHistogram;
protected:
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
virtual caf::PdmFieldHandle* objectToggleField();
private:
caf::PdmPointer<RimReservoirView> m_reservoirView;

View File

@ -78,7 +78,7 @@ RimReservoirView* RimCellPropertyFilterCollection::reservoirView()
//--------------------------------------------------------------------------------------------------
void RimCellPropertyFilterCollection::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue)
{
updateIconState();
this->updateUiIconFromState(active);
m_reservoirView->fieldChangedByUi(&(m_reservoirView->propertyFilterCollection), oldValue, newValue);
}
@ -173,30 +173,6 @@ bool RimCellPropertyFilterCollection::hasActiveDynamicFilters() const
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCellPropertyFilterCollection::updateIconState()
{
// Reset dynamic icon
this->setUiIcon(QIcon());
// Get static one
QIcon icon = this->uiIcon();
// Get a pixmap, and modify it
QPixmap icPixmap;
icPixmap = icon.pixmap(16, 16, QIcon::Normal);
if (!active)
{
QIcon temp(icPixmap);
icPixmap = temp.pixmap(16, 16, QIcon::Disabled);
}
QIcon newIcon(icPixmap);
this->setUiIcon(newIcon);
}
//--------------------------------------------------------------------------------------------------
///

View File

@ -48,8 +48,6 @@ public:
void loadAndInitializePropertyFilters();
void updateIconState();
// Overridden methods
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);

View File

@ -139,7 +139,7 @@ RigActiveCellInfo* RimCellRangeFilterCollection::activeCellInfo() const
//--------------------------------------------------------------------------------------------------
void RimCellRangeFilterCollection::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue)
{
updateIconState();
updateUiIconFromState(active);
CVF_ASSERT(m_reservoirView);
@ -221,27 +221,3 @@ caf::PdmFieldHandle* RimCellRangeFilterCollection::objectToggleField()
return &active;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCellRangeFilterCollection::updateIconState()
{
// Reset dynamic icon
this->setUiIcon(QIcon());
// Get static one
QIcon icon = this->uiIcon();
// Get a pixmap, and modify it
QPixmap icPixmap;
icPixmap = icon.pixmap(16, 16, QIcon::Normal);
if (!active)
{
QIcon temp(icPixmap);
icPixmap = temp.pixmap(16, 16, QIcon::Disabled);
}
QIcon newIcon(icPixmap);
this->setUiIcon(newIcon);
}

View File

@ -50,8 +50,6 @@ public:
RigMainGrid* mainGrid() const;
RigActiveCellInfo* activeCellInfo() const;
void updateIconState();
// Overridden methods
virtual void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue );
virtual caf::PdmFieldHandle* objectToggleField();

View File

@ -376,6 +376,8 @@ void RimReservoirView::fieldChangedByUi(const caf::PdmFieldHandle* changedField,
m_viewer = NULL;
}
}
this->updateUiIconFromState(showWindow);
}
else if (changedField == &backgroundColor )
{

View File

@ -177,7 +177,7 @@ void RimWellCollection::fieldChangedByUi(const caf::PdmFieldHandle* changedField
{
if (&showWellLabel == changedField || &active == changedField)
{
updateIconState();
this->updateUiIconFromState(active);
if (m_reservoirView)
{
@ -276,27 +276,3 @@ caf::PdmFieldHandle* RimWellCollection::objectToggleField()
return &active;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellCollection::updateIconState()
{
// Reset dynamic icon
this->setUiIcon(QIcon());
// Get static one
QIcon icon = this->uiIcon();
// Get a pixmap, and modify it
QPixmap icPixmap;
icPixmap = icon.pixmap(16, 16, QIcon::Normal);
if (!active)
{
QIcon temp(icPixmap);
icPixmap = temp.pixmap(16, 16, QIcon::Disabled);
}
QIcon newIcon(icPixmap);
this->setUiIcon(newIcon);
}

View File

@ -90,8 +90,6 @@ public:
bool hasVisibleWellCells();
bool hasVisibleWellPipes();
void updateIconState();
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering);
virtual caf::PdmFieldHandle* objectToggleField();

View File

@ -267,5 +267,30 @@ PdmUiItem::~PdmUiItem()
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmUiItem::updateUiIconFromState(bool active)
{
// Reset dynamic icon
this->setUiIcon(QIcon());
// Get static one
QIcon icon = this->uiIcon();
// Get a pixmap, and modify it
QPixmap icPixmap;
icPixmap = icon.pixmap(16, 16, QIcon::Normal);
if (!active)
{
QIcon temp(icPixmap);
icPixmap = temp.pixmap(16, 16, QIcon::Disabled);
}
QIcon newIcon(icPixmap);
this->setUiIcon(newIcon);
}
} //End of namespace caf

View File

@ -129,6 +129,8 @@ public:
void updateConnectedEditors();
void updateUiIconFromState(bool active);
public: // Pdm-Private only
//==================================================================================================
/// This method sets the GUI description pointer, which is supposed to be statically allocated