Add option for word wrap in label and checkbox

* Add support for word wrap in checkbox label
* QLabelEditor: Add word wrap and support for wide label
Add support for one label widget spanning the area usually consumed by a label widget and an editor widget.
* Use word wrap in summary calculation dialog
This commit is contained in:
Magne Sjaastad
2023-03-09 12:46:55 +01:00
committed by GitHub
parent 527743a845
commit f5171310bf
12 changed files with 220 additions and 16 deletions

View File

@@ -36,6 +36,10 @@
#include "cafPdmUiLabelEditor.h"
#include "cafPdmUiFieldEditorHandle.h"
#include "cafPdmUiFieldHandle.h"
#include "cafPdmUiObjectHandle.h"
namespace caf
{
CAF_PDM_UI_FIELD_EDITOR_SOURCE_INIT( PdmUiLabelEditor );
@@ -64,6 +68,27 @@ void PdmUiLabelEditor::configureAndUpdateUi( const QString& uiConfigName )
PdmUiFieldEditorHandle::updateLabelFromField( m_label, uiConfigName );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QWidget* PdmUiLabelEditor::createCombinedWidget( QWidget* parent )
{
caf::PdmUiObjectHandle* uiObject = uiObj( uiField()->fieldHandle()->ownerObject() );
if ( uiObject )
{
const QString uiConfigName;
PdmUiLabelEditorAttribute attributes;
uiObject->editorAttribute( uiField()->fieldHandle(), uiConfigName, &attributes );
if ( attributes.m_useSingleWidgetInsteadOfLabelAndEditorWidget )
{
return createLabelWidget( parent );
}
}
return nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -79,7 +104,23 @@ QWidget* PdmUiLabelEditor::createLabelWidget( QWidget* parent )
{
if ( m_label.isNull() )
{
m_label = new QShortenedLabel( parent );
PdmUiLabelEditorAttribute attributes;
caf::PdmUiObjectHandle* uiObject = uiObj( uiField()->fieldHandle()->ownerObject() );
if ( uiObject )
{
const QString uiConfigName;
uiObject->editorAttribute( uiField()->fieldHandle(), uiConfigName, &attributes );
}
if ( attributes.m_useWordWrap )
{
m_label = new QLabel( parent );
m_label->setWordWrap( true );
}
else
{
m_label = new QShortenedLabel( parent );
}
}
return m_label;