#1867 AppFwk : Add PdmUiFieldEditorHandle::updateLabelFromField

This commit is contained in:
Magne Sjaastad 2017-09-07 08:31:29 +02:00
parent 72a1a69547
commit 2f22f82ba1
5 changed files with 34 additions and 3 deletions

View File

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

View File

@ -40,6 +40,7 @@
#include "cafPdmUiFieldHandle.h"
#include "cafPdmUiCommandSystemProxy.h"
#include <QLabel>
#include <QVariant>
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<const PdmUiFieldHandle*>(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

View File

@ -47,6 +47,8 @@
#include <QString>
#include <QWidget>
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<QWidget> m_combinedWidget;
QPointer<QWidget> m_editorWidget;

View File

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

View File

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