diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiCheckBoxEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiCheckBoxEditor.cpp index 077d6fe99c..360c50b850 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiCheckBoxEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiCheckBoxEditor.cpp @@ -58,8 +58,8 @@ void PdmUiCheckBoxEditor::configureAndUpdateUi( const QString& uiConfigName ) CAF_ASSERT( !m_checkBox.isNull() ); CAF_ASSERT( !m_label.isNull() ); - PdmUiCheckBoxEditorAttribute attributes; - caf::PdmUiObjectHandle* uiObject = uiObj( uiField()->fieldHandle()->ownerObject() ); + PdmUiCheckBoxEditorAttribute attributes = defaultAttributes(); + caf::PdmUiObjectHandle* uiObject = uiObj( uiField()->fieldHandle()->ownerObject() ); if ( uiObject ) { uiObject->editorAttribute( uiField()->fieldHandle(), uiConfigName, &attributes ); @@ -112,4 +112,50 @@ void PdmUiCheckBoxEditor::slotClicked( bool checked ) this->setValueToField( v ); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +PdmUiCheckBoxEditorAttribute PdmUiCheckBoxEditor::defaultAttributes() const +{ + return {}; +} + +//================================================================================================== +// +// +// PdmUiNativeCheckBoxEditor +// +// +//================================================================================================== + +CAF_PDM_UI_FIELD_EDITOR_SOURCE_INIT( PdmUiNativeCheckBoxEditor ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiNativeCheckBoxEditor::configureFieldForEditor( caf::PdmFieldHandle* fieldHandle ) +{ + if ( !fieldHandle ) return; + + if ( auto uiCap = fieldHandle->uiCapability() ) + { + uiCap->setUiEditorTypeName( caf::PdmUiNativeCheckBoxEditor::uiEditorTypeName() ); + + // Hide the editor label, as the label is managed by the native checkbox + uiCap->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN ); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +PdmUiCheckBoxEditorAttribute PdmUiNativeCheckBoxEditor::defaultAttributes() const +{ + PdmUiCheckBoxEditorAttribute attributes; + + attributes.m_useNativeCheckBoxLabel = true; + + return attributes; +} + } // end namespace caf diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiCheckBoxEditor.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiCheckBoxEditor.h index 44ad7368e2..4174a81939 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiCheckBoxEditor.h +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiCheckBoxEditor.h @@ -35,6 +35,7 @@ //################################################################################################## #pragma once + #include "cafPdmUiFieldEditorHandle.h" #include @@ -45,9 +46,8 @@ namespace caf { //================================================================================================== -/// The default editor for several PdmFields. +/// //================================================================================================== - class PdmUiCheckBoxEditorAttribute : public PdmUiEditorAttribute { public: @@ -57,6 +57,14 @@ public: bool m_useNativeCheckBoxLabel; }; +//================================================================================================== +// +// Checkbox editor used to display default Qt checkbox +// On Windows, the default behavior is like this +// +// "some text as label" [x] +// +//================================================================================================== class PdmUiCheckBoxEditor : public PdmUiFieldEditorHandle { Q_OBJECT @@ -74,9 +82,34 @@ protected: protected slots: void slotClicked( bool checked ); + virtual PdmUiCheckBoxEditorAttribute defaultAttributes() const; + private: QPointer m_checkBox; QPointer m_label; }; +//================================================================================================== +// +// Check box editor used to display native checkbox +// On Windows, the default behavior to show the checkbox to the left of the label text +// +// [x] "some text as label" +// +//================================================================================================== +class PdmUiNativeCheckBoxEditor : public PdmUiCheckBoxEditor +{ + Q_OBJECT + CAF_PDM_UI_FIELD_EDITOR_HEADER_INIT; + +public: + PdmUiNativeCheckBoxEditor() = default; + ~PdmUiNativeCheckBoxEditor() override = default; + + static void configureFieldForEditor( caf::PdmFieldHandle* fieldHandle ); + +protected: + PdmUiCheckBoxEditorAttribute defaultAttributes() const override; +}; + } // end namespace caf