mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
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:
parent
527743a845
commit
f5171310bf
@ -41,6 +41,7 @@
|
||||
|
||||
#include "RiuExpressionContextMenuManager.h"
|
||||
|
||||
#include "cafPdmUiCheckBoxEditor.h"
|
||||
#include "cafPdmUiLineEditor.h"
|
||||
#include "cafPdmUiTableViewEditor.h"
|
||||
#include "cafPdmUiTextEditor.h"
|
||||
@ -194,6 +195,23 @@ bool RimSummaryCalculation::detectCyclicCalculation( int id, std::set<int>& ids
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryCalculation::defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute )
|
||||
{
|
||||
RimUserDefinedCalculation::defineEditorAttribute( field, uiConfigName, attribute );
|
||||
|
||||
if ( field == &m_distributeToOtherItems )
|
||||
{
|
||||
auto myAttr = dynamic_cast<caf::PdmUiCheckBoxEditorAttribute*>( attribute );
|
||||
if ( myAttr )
|
||||
{
|
||||
myAttr->setWordWrap( true );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -85,8 +85,10 @@ protected:
|
||||
std::optional<std::vector<SummaryCalculationVariable>> getVariables() const;
|
||||
|
||||
bool checkVariables() const;
|
||||
|
||||
bool detectCyclicCalculation( int id, std::set<int>& ids ) const;
|
||||
|
||||
void defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override;
|
||||
|
||||
private:
|
||||
caf::PdmField<bool> m_distributeToOtherItems;
|
||||
};
|
||||
|
@ -396,6 +396,14 @@ void RimUserDefinedCalculation::defineEditorAttribute( const caf::PdmFieldHandle
|
||||
attrib->m_buttonText = "Open Help Page";
|
||||
}
|
||||
}
|
||||
else if ( field == &m_helpText )
|
||||
{
|
||||
auto* attrib = dynamic_cast<caf::PdmUiLabelEditorAttribute*>( attribute );
|
||||
if ( attrib )
|
||||
{
|
||||
attrib->m_useWordWrap = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -164,7 +164,7 @@ void PdmUiFieldEditorHandle::setValueToField( const QVariant& newUiValue )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiFieldEditorHandle::updateLabelFromField( QShortenedLabel* label, const QString& uiConfigName /*= ""*/ ) const
|
||||
void PdmUiFieldEditorHandle::updateLabelFromField( QLabel* label, const QString& uiConfigName /*= ""*/ ) const
|
||||
{
|
||||
CAF_ASSERT( label );
|
||||
|
||||
@ -179,7 +179,15 @@ void PdmUiFieldEditorHandle::updateLabelFromField( QShortenedLabel* label, const
|
||||
else
|
||||
{
|
||||
QString uiName = fieldHandle->uiName( uiConfigName );
|
||||
label->setText( uiName );
|
||||
if ( auto shortLabel = dynamic_cast<QShortenedLabel*>( label ) )
|
||||
{
|
||||
// It is required to do a dynamic cast here, as the setText() function is not virtual
|
||||
shortLabel->setText( uiName );
|
||||
}
|
||||
else
|
||||
{
|
||||
label->setText( uiName );
|
||||
}
|
||||
}
|
||||
|
||||
label->setEnabled( !fieldHandle->isUiReadOnly( uiConfigName ) );
|
||||
|
@ -112,7 +112,7 @@ protected: // Virtual interface to override
|
||||
|
||||
void setValueToField( const QVariant& value );
|
||||
|
||||
void updateLabelFromField( QShortenedLabel* label, const QString& uiConfigName = "" ) const;
|
||||
void updateLabelFromField( QLabel* label, const QString& uiConfigName = "" ) const;
|
||||
virtual QMargins calculateLabelContentMargins() const;
|
||||
virtual bool isMultiRowEditor() const;
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
|
||||
#include "LineEditAndPushButtons.h"
|
||||
|
||||
#include "cafPdmUiLabelEditor.h"
|
||||
#include "cafPdmUiLineEditor.h"
|
||||
#include "cafPdmUiListEditor.h"
|
||||
#include "cafPdmUiPushButtonEditor.h"
|
||||
@ -17,6 +18,19 @@ LineEditAndPushButtons::LineEditAndPushButtons()
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_statusTextField, "StatusTextField", "Status Text", "", "", "");
|
||||
CAF_PDM_InitFieldNoDefault(&m_textField, "TextField", "Text", "", "", "");
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_labelField, "LabelField", "Medium length text in label", "", "", "");
|
||||
m_labelField.uiCapability()->setUiEditorTypeName(caf::PdmUiLabelEditor::uiEditorTypeName());
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(
|
||||
&m_labelLongTextField,
|
||||
"LongTextField",
|
||||
"Long length text in label length text in label length text in label length text in label length text in label",
|
||||
"",
|
||||
"",
|
||||
"");
|
||||
m_labelLongTextField.uiCapability()->setUiEditorTypeName(caf::PdmUiLabelEditor::uiEditorTypeName());
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_textListField, "TextListField", "Text List Field", "", "", "");
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_pushButton_a, "PushButtonA", "Rotate", "", "", "");
|
||||
@ -114,6 +128,15 @@ void LineEditAndPushButtons::defineEditorAttribute(const caf::PdmFieldHandle* fi
|
||||
myAttr->notifyWhenTextIsEdited = true;
|
||||
}
|
||||
}
|
||||
else if (field == &m_labelLongTextField)
|
||||
{
|
||||
auto myAttr = dynamic_cast<caf::PdmUiLabelEditorAttribute*>(attribute);
|
||||
if (myAttr)
|
||||
{
|
||||
myAttr->m_useWordWrap = true;
|
||||
myAttr->m_useSingleWidgetInsteadOfLabelAndEditorWidget = true;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto myAttr = dynamic_cast<caf::PdmUiPushButtonEditorAttribute*>(attribute);
|
||||
|
@ -26,8 +26,12 @@ private:
|
||||
void clearText();
|
||||
|
||||
private:
|
||||
caf::PdmField<QString> m_textField;
|
||||
caf::PdmField<QString> m_statusTextField;
|
||||
caf::PdmField<QString> m_textField;
|
||||
caf::PdmField<QString> m_statusTextField;
|
||||
|
||||
caf::PdmField<QString> m_labelField;
|
||||
caf::PdmField<QString> m_labelLongTextField;
|
||||
|
||||
caf::PdmField<std::vector<QString>> m_textListField;
|
||||
|
||||
caf::PdmField<bool> m_pushButton_a;
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "cafPdmProxyValueField.h"
|
||||
#include "cafPdmPtrField.h"
|
||||
#include "cafPdmReferenceHelper.h"
|
||||
#include "cafPdmUiCheckBoxEditor.h"
|
||||
#include "cafPdmUiColorEditor.h"
|
||||
#include "cafPdmUiComboBoxEditor.h"
|
||||
#include "cafPdmUiFilePathEditor.h"
|
||||
@ -670,7 +671,15 @@ public:
|
||||
"This object is a demo of the CAF framework",
|
||||
"This object is a demo of the CAF framework");
|
||||
|
||||
CAF_PDM_InitField(&m_toggleField, "Toggle", false, "Toggle Field", "", "Toggle Field tooltip", " Toggle Field whatsthis");
|
||||
CAF_PDM_InitField(&m_toggleField,
|
||||
"Toggle",
|
||||
false,
|
||||
"Toggle Field much text much text much much text much text muchmuch text much text muchmuch text much "
|
||||
"text muchmuch text much text muchmuch text much text much",
|
||||
"",
|
||||
"Toggle Field tooltip",
|
||||
" Toggle Field whatsthis");
|
||||
|
||||
CAF_PDM_InitField(&m_pushButtonField, "Push", false, "Button Field", "", "", " ");
|
||||
CAF_PDM_InitField(&m_doubleField,
|
||||
"BigNumber",
|
||||
@ -865,6 +874,14 @@ protected:
|
||||
attr->showPreviousAndNextButtons = true;
|
||||
}
|
||||
}
|
||||
else if (field == &m_toggleField)
|
||||
{
|
||||
auto* attr = dynamic_cast<caf::PdmUiCheckBoxEditorAttribute*>(attribute);
|
||||
if (attr)
|
||||
{
|
||||
attr->setWordWrap(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -65,7 +65,7 @@ void PdmUiCheckBoxEditor::configureAndUpdateUi( const QString& uiConfigName )
|
||||
uiObject->editorAttribute( uiField()->fieldHandle(), uiConfigName, &attributes );
|
||||
}
|
||||
|
||||
if ( attributes.m_useNativeCheckBoxLabel )
|
||||
if ( attributes.useNativeCheckBox() )
|
||||
{
|
||||
m_checkBox->setText( uiField()->uiName( uiConfigName ) );
|
||||
|
||||
@ -98,7 +98,24 @@ QWidget* PdmUiCheckBoxEditor::createEditorWidget( QWidget* parent )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QWidget* PdmUiCheckBoxEditor::createLabelWidget( QWidget* parent )
|
||||
{
|
||||
m_label = new QShortenedLabel( parent );
|
||||
PdmUiCheckBoxEditorAttribute attributes;
|
||||
caf::PdmUiObjectHandle* uiObject = uiObj( uiField()->fieldHandle()->ownerObject() );
|
||||
if ( uiObject )
|
||||
{
|
||||
const QString uiConfigName;
|
||||
uiObject->editorAttribute( uiField()->fieldHandle(), uiConfigName, &attributes );
|
||||
}
|
||||
|
||||
if ( attributes.useWordWrap() )
|
||||
{
|
||||
m_label = new QLabel( parent );
|
||||
m_label->setWordWrap( true );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_label = new QShortenedLabel( parent );
|
||||
}
|
||||
|
||||
return m_label;
|
||||
}
|
||||
|
||||
@ -153,9 +170,45 @@ PdmUiCheckBoxEditorAttribute PdmUiNativeCheckBoxEditor::defaultAttributes() cons
|
||||
{
|
||||
PdmUiCheckBoxEditorAttribute attributes;
|
||||
|
||||
attributes.m_useNativeCheckBoxLabel = true;
|
||||
attributes.setNativeCheckBox( true );
|
||||
|
||||
return attributes;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiCheckBoxEditorAttribute::setNativeCheckBox( bool enable )
|
||||
{
|
||||
CAF_ASSERT( enable && !m_useWordWrap && "Native checkbox is not compatible with use of word wrap" );
|
||||
|
||||
m_useNativeCheckBoxLabel = enable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiCheckBoxEditorAttribute::setWordWrap( bool enable )
|
||||
{
|
||||
CAF_ASSERT( enable && !m_useNativeCheckBoxLabel && "Native checkbox is not compatible with use of word wrap" );
|
||||
|
||||
m_useWordWrap = enable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool PdmUiCheckBoxEditorAttribute::useNativeCheckBox() const
|
||||
{
|
||||
return m_useNativeCheckBoxLabel;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool PdmUiCheckBoxEditorAttribute::useWordWrap() const
|
||||
{
|
||||
return m_useWordWrap;
|
||||
}
|
||||
|
||||
} // end namespace caf
|
||||
|
@ -51,10 +51,21 @@ namespace caf
|
||||
class PdmUiCheckBoxEditorAttribute : public PdmUiEditorAttribute
|
||||
{
|
||||
public:
|
||||
PdmUiCheckBoxEditorAttribute() { m_useNativeCheckBoxLabel = false; }
|
||||
PdmUiCheckBoxEditorAttribute()
|
||||
: m_useNativeCheckBoxLabel( false )
|
||||
, m_useWordWrap( false )
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
void setNativeCheckBox( bool enable );
|
||||
void setWordWrap( bool enable );
|
||||
|
||||
bool useNativeCheckBox() const;
|
||||
bool useWordWrap() const;
|
||||
|
||||
private:
|
||||
bool m_useNativeCheckBoxLabel;
|
||||
bool m_useWordWrap;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
@ -85,8 +96,8 @@ protected slots:
|
||||
virtual PdmUiCheckBoxEditorAttribute defaultAttributes() const;
|
||||
|
||||
private:
|
||||
QPointer<QCheckBox> m_checkBox;
|
||||
QPointer<QShortenedLabel> m_label;
|
||||
QPointer<QCheckBox> m_checkBox;
|
||||
QPointer<QLabel> m_label;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
|
@ -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;
|
||||
|
@ -48,6 +48,23 @@ class QGridLayout;
|
||||
|
||||
namespace caf
|
||||
{
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class PdmUiLabelEditorAttribute : public PdmUiEditorAttribute
|
||||
{
|
||||
public:
|
||||
PdmUiLabelEditorAttribute()
|
||||
: m_useWordWrap( false )
|
||||
, m_useSingleWidgetInsteadOfLabelAndEditorWidget( false )
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
bool m_useWordWrap;
|
||||
bool m_useSingleWidgetInsteadOfLabelAndEditorWidget;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
/// An editor to show (and possibly edit?) formatted larger portions of text
|
||||
//==================================================================================================
|
||||
@ -65,8 +82,10 @@ protected:
|
||||
QWidget* createLabelWidget( QWidget* parent ) override;
|
||||
void configureAndUpdateUi( const QString& uiConfigName ) override;
|
||||
|
||||
QWidget* createCombinedWidget( QWidget* parent ) override;
|
||||
|
||||
private:
|
||||
QPointer<QShortenedLabel> m_label;
|
||||
QPointer<QLabel> m_label;
|
||||
};
|
||||
|
||||
} // end namespace caf
|
||||
|
Loading…
Reference in New Issue
Block a user