#4388 AppFwk : Make sure context menu policy is set correctly in all use cases

This commit is contained in:
Magne Sjaastad 2019-05-06 11:46:44 +02:00
parent a852d1a50e
commit 911b69b56f
2 changed files with 29 additions and 8 deletions

View File

@ -80,14 +80,30 @@ void PdmUiFieldEditorHandle::setUiField(PdmUiFieldHandle * field)
if (m_editorWidget)
{
if (field && field->isCustomContextMenuEnabled())
{
m_editorWidget->setContextMenuPolicy(Qt::CustomContextMenu);
}
else
{
m_editorWidget->setContextMenuPolicy(Qt::DefaultContextMenu);
}
// Required to be called here to be able to handle different context menu
// policy when switching between objects of same type. In this case, the
// PdmUiFieldEditorHandle::createWidgets() will not be run, as the field
// widgets are cached by the property editor
updateContextMenuPolicy();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmUiFieldEditorHandle::updateContextMenuPolicy()
{
if (m_editorWidget.isNull()) return;
PdmUiFieldHandle* field = uiField();
if (field && field->isCustomContextMenuEnabled())
{
m_editorWidget->setContextMenuPolicy(Qt::CustomContextMenu);
}
else
{
m_editorWidget->setContextMenuPolicy(Qt::DefaultContextMenu);
}
}
@ -110,6 +126,8 @@ void PdmUiFieldEditorHandle::createWidgets(QWidget * parent)
if (m_editorWidget)
{
updateContextMenuPolicy();
connect(m_editorWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customMenuRequested(QPoint)));
}
if (m_labelWidget)

View File

@ -114,6 +114,9 @@ protected: // Virtual interface to override
virtual QMargins calculateLabelContentMargins() const;
virtual bool isMultiRowEditor() const;
private:
void updateContextMenuPolicy();
private slots:
void customMenuRequested(QPoint pos);