From 2f22f82ba15d327d9a2ae3ed8604483854dc0e42 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 7 Sep 2017 08:31:29 +0200 Subject: [PATCH] #1867 AppFwk : Add PdmUiFieldEditorHandle::updateLabelFromField --- .../cafPdmUiCore/cafPdmUiEditorHandle.h | 3 ++- .../cafPdmUiFieldEditorHandle.cpp | 26 +++++++++++++++++++ .../cafPdmUiCore/cafPdmUiFieldEditorHandle.h | 4 +++ .../cafPdmUiCore/cafPdmUiItem.cpp | 2 +- .../cafPdmUiCore/cafPdmUiItem.h | 2 +- 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiEditorHandle.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiEditorHandle.h index fd9842f6f2..a5c4e23f99 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiEditorHandle.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiEditorHandle.h @@ -79,7 +79,8 @@ protected: // Interface to override: protected: /// This needs to be called from subclass when connecting to a PdmField or Object void bindToPdmItem(PdmUiItem* item); - PdmUiItem* pdmItem() { return m_pdmItem; } + PdmUiItem* pdmItem() { return m_pdmItem; } + const PdmUiItem* pdmItem() const { return m_pdmItem; } private: friend PdmUiItem::~PdmUiItem(); diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiFieldEditorHandle.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiFieldEditorHandle.cpp index 15c17e161b..003814a2d5 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiFieldEditorHandle.cpp +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiFieldEditorHandle.cpp @@ -40,6 +40,7 @@ #include "cafPdmUiFieldHandle.h" #include "cafPdmUiCommandSystemProxy.h" +#include #include namespace caf @@ -100,6 +101,31 @@ void PdmUiFieldEditorHandle::setValueToField(const QVariant& newUiValue) PdmUiCommandSystemProxy::instance()->setUiValueToField(field(), newUiValue); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiFieldEditorHandle::updateLabelFromField(QLabel* label, const QString& uiConfigName) const +{ + CAF_ASSERT(label); + + const PdmUiFieldHandle* fieldHandle = dynamic_cast(pdmItem()); + if (fieldHandle) + { + QIcon ic = fieldHandle->uiIcon(uiConfigName); + if (!ic.isNull()) + { + label->setPixmap(ic.pixmap(ic.actualSize(QSize(64, 64)))); + } + else + { + QString uiName = fieldHandle->uiName(uiConfigName); + label->setText(uiName); + } + + label->setEnabled(!fieldHandle->isUiReadOnly(uiConfigName)); + label->setToolTip(fieldHandle->uiToolTip(uiConfigName)); + } +} } //End of namespace caf diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiFieldEditorHandle.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiFieldEditorHandle.h index d8ec345b90..4f34bfbbd5 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiFieldEditorHandle.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiFieldEditorHandle.h @@ -47,6 +47,8 @@ #include #include +class QLabel; + // Taken from gtest.h // @@ -118,6 +120,8 @@ protected: // Virtual interface to override void setValueToField(const QVariant& value); + void updateLabelFromField(QLabel* label, const QString& uiConfigName = "") const; + private: QPointer m_combinedWidget; QPointer m_editorWidget; diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.cpp index e05f480831..277f5ea6a2 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.cpp +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.cpp @@ -263,7 +263,7 @@ bool PdmUiItem::isUiTreeChildrenHidden(QString uiConfigName) const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool PdmUiItem::isUiReadOnly(QString uiConfigName /*= ""*/) +bool PdmUiItem::isUiReadOnly(QString uiConfigName /*= ""*/) const { const PdmUiItemInfo* conInfo = configInfo(uiConfigName); const PdmUiItemInfo* defInfo = defaultInfo(); diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.h index f8683849d9..45dde1a6f2 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.h @@ -217,7 +217,7 @@ public: bool isUiTreeChildrenHidden(QString uiConfigName = "") const; void setUiTreeChildrenHidden(bool isTreeChildrenHidden, QString uiConfigName = "") { m_configItemInfos[uiConfigName].m_isTreeChildrenHidden = isTreeChildrenHidden; } - bool isUiReadOnly(QString uiConfigName = ""); + bool isUiReadOnly(QString uiConfigName = "") const; void setUiReadOnly(bool isReadOnly, QString uiConfigName = "") { m_configItemInfos[uiConfigName].m_isReadOnly = isReadOnly; } PdmUiItemInfo::LabelPosType