mirror of
https://github.com/OPM/ResInsight.git
synced 2026-08-27 05:37:21 -05:00
Decorates optional fields with information icon
Adds an information icon to optional fields, providing users with a visual cue indicating that the field is not mandatory. Renames `createTwoStateChainIcon` to `twoStateChainIcon` to better reflect its purpose.
This commit is contained in:
@@ -276,7 +276,7 @@ void PdmUiComboBoxEditor::configureAndUpdateUi( const QString& uiConfigName )
|
||||
|
||||
if ( uiField()->isAutoValueSupported() )
|
||||
{
|
||||
auto icon = UiIconFactory::createTwoStateChainIcon();
|
||||
auto icon = UiIconFactory::twoStateChainIcon();
|
||||
m_autoValueToolButton->setIcon( icon );
|
||||
|
||||
m_autoValueToolButton->setChecked( uiField()->isAutoValueEnabled() );
|
||||
|
||||
@@ -88,6 +88,27 @@ QWidget* PdmUiLineEditor::createEditorWidget( QWidget* parent )
|
||||
{
|
||||
m_lineEdit = new PdmUiLineEdit( parent, false );
|
||||
|
||||
auto isOptionalField = []( caf::PdmUiFieldHandle* uiFieldHandle )
|
||||
{
|
||||
if ( !uiFieldHandle ) return false;
|
||||
|
||||
if ( uiFieldHandle->fieldHandle() )
|
||||
{
|
||||
const std::type_info& typeInfo = typeid( *uiFieldHandle->fieldHandle() );
|
||||
QString typeName = QString( typeInfo.name() );
|
||||
|
||||
return typeName.contains( "optional", Qt::CaseInsensitive );
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
if ( isOptionalField( uiField() ) )
|
||||
{
|
||||
auto icon = UiIconFactory::informationIcon();
|
||||
auto action = m_lineEdit->addAction( icon, QLineEdit::TrailingPosition );
|
||||
action->setToolTip( "This field is optional" );
|
||||
}
|
||||
|
||||
connect( m_lineEdit, SIGNAL( editingFinished() ), this, SLOT( slotEditingFinished() ) );
|
||||
|
||||
m_placeholder = new QWidget( parent );
|
||||
@@ -155,7 +176,7 @@ void PdmUiLineEditor::configureAndUpdateUi( const QString& uiConfigName )
|
||||
|
||||
if ( uiField()->isAutoValueSupported() )
|
||||
{
|
||||
auto icon = UiIconFactory::createTwoStateChainIcon();
|
||||
auto icon = UiIconFactory::twoStateChainIcon();
|
||||
m_autoValueToolButton->setIcon( icon );
|
||||
|
||||
m_autoValueToolButton->setChecked( uiField()->isAutoValueEnabled() );
|
||||
|
||||
@@ -221,6 +221,18 @@ static const char* unlinked_white_svg_data = R"(
|
||||
|
||||
)";
|
||||
|
||||
static const char* information_svg_data = R"(
|
||||
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<!-- Circle background -->
|
||||
<circle cx="12" cy="12" r="10" stroke="#9CA3AF" stroke-width="2" fill="none"/>
|
||||
|
||||
<!-- Letter "i" for information/optional -->
|
||||
<circle cx="12" cy="8" r="1.5" fill="#9CA3AF"/>
|
||||
<rect x="11" y="11" width="2" height="7" rx="1" fill="#9CA3AF"/>
|
||||
</svg>
|
||||
)";
|
||||
|
||||
// clang-format on
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -246,7 +258,7 @@ const QIcon UiIconFactory::stepDownIcon()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const QIcon UiIconFactory::createTwoStateChainIcon()
|
||||
const QIcon UiIconFactory::twoStateChainIcon()
|
||||
{
|
||||
static QIcon icon( UiIconFactory::createTwoStateIcon( linked_svg_data,
|
||||
unlinked_svg_data,
|
||||
@@ -259,7 +271,7 @@ const QIcon UiIconFactory::createTwoStateChainIcon()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const QIcon UiIconFactory::createTwoStateWhiteChainIcon()
|
||||
const QIcon UiIconFactory::twoStateWhiteChainIcon()
|
||||
{
|
||||
static QIcon icon( UiIconFactory::createTwoStateIcon( linked_white_svg_data,
|
||||
unlinked_white_svg_data,
|
||||
@@ -269,6 +281,17 @@ const QIcon UiIconFactory::createTwoStateWhiteChainIcon()
|
||||
return icon;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const QIcon UiIconFactory::informationIcon()
|
||||
{
|
||||
static QIcon icon(
|
||||
UiIconFactory::createSvgIcon( information_svg_data, UiIconFactory::iconWidth(), UiIconFactory::iconHeight() ) );
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -45,8 +45,10 @@ public:
|
||||
static const QIcon stepDownIcon();
|
||||
static const QIcon stepUpIcon();
|
||||
|
||||
static const QIcon createTwoStateChainIcon();
|
||||
static const QIcon createTwoStateWhiteChainIcon();
|
||||
static const QIcon twoStateChainIcon();
|
||||
static const QIcon twoStateWhiteChainIcon();
|
||||
|
||||
static const QIcon informationIcon();
|
||||
|
||||
private:
|
||||
static int iconWidth();
|
||||
|
||||
Reference in New Issue
Block a user