mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
AppFwk : Support notification when key is pressed in Line/ComboBox editors
This commit is contained in:
@@ -284,6 +284,20 @@ void PdmUiComboBoxEditor::configureAndUpdateUi( const QString& uiConfigName )
|
||||
m_comboBox->lineEdit()->setPlaceholderText( m_attributes.placeholderText );
|
||||
}
|
||||
|
||||
if ( m_attributes.notifyWhenTextIsEdited )
|
||||
{
|
||||
connect( m_comboBox,
|
||||
SIGNAL( editTextChanged( const QString& ) ),
|
||||
this,
|
||||
SLOT( slotEditTextChanged( const QString& ) ) );
|
||||
|
||||
if ( m_interactiveEditText == m_comboBox->lineEdit()->text() && m_interactiveEditCursorPosition > -1 )
|
||||
{
|
||||
m_comboBox->lineEdit()->setCursorPosition( m_interactiveEditCursorPosition );
|
||||
m_comboBox->lineEdit()->deselect();
|
||||
}
|
||||
}
|
||||
|
||||
if ( m_attributes.minimumWidth != -1 )
|
||||
{
|
||||
m_comboBox->setMinimumWidth( m_attributes.minimumWidth );
|
||||
@@ -455,6 +469,14 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PdmUiComboBoxEditor::PdmUiComboBoxEditor()
|
||||
: m_interactiveEditCursorPosition( -1 )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -509,6 +531,19 @@ void PdmUiComboBoxEditor::slotIndexActivated( int index )
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiComboBoxEditor::slotEditTextChanged( const QString& text )
|
||||
{
|
||||
if ( text == m_interactiveEditText ) return;
|
||||
|
||||
m_interactiveEditText = text;
|
||||
m_interactiveEditCursorPosition = m_comboBox->lineEdit()->cursorPosition();
|
||||
|
||||
this->setValueToField( text );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -63,6 +63,7 @@ public:
|
||||
enableEditableContent = false;
|
||||
minimumWidth = -1;
|
||||
iconSize = QSize( 14, 14 );
|
||||
notifyWhenTextIsEdited = false;
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -80,6 +81,8 @@ public:
|
||||
QSize iconSize;
|
||||
QIcon nextIcon;
|
||||
QIcon previousIcon;
|
||||
|
||||
bool notifyWhenTextIsEdited;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
@@ -91,7 +94,7 @@ class PdmUiComboBoxEditor : public PdmUiFieldEditorHandle
|
||||
CAF_PDM_UI_FIELD_EDITOR_HEADER_INIT;
|
||||
|
||||
public:
|
||||
PdmUiComboBoxEditor() {}
|
||||
PdmUiComboBoxEditor();
|
||||
~PdmUiComboBoxEditor() override {}
|
||||
|
||||
protected:
|
||||
@@ -102,6 +105,7 @@ protected:
|
||||
|
||||
protected slots:
|
||||
void slotIndexActivated( int index );
|
||||
void slotEditTextChanged( const QString& );
|
||||
|
||||
void slotNextButtonPressed();
|
||||
void slotPreviousButtonPressed();
|
||||
@@ -116,6 +120,9 @@ private:
|
||||
QPointer<QWidget> m_placeholder;
|
||||
|
||||
PdmUiComboBoxEditorAttribute m_attributes;
|
||||
|
||||
QString m_interactiveEditText;
|
||||
int m_interactiveEditCursorPosition;
|
||||
};
|
||||
|
||||
} // end namespace caf
|
||||
|
||||
@@ -141,6 +141,11 @@ void PdmUiLineEditor::configureAndUpdateUi( const QString& uiConfigName )
|
||||
{
|
||||
m_lineEdit->setPlaceholderText( leab.placeholderText );
|
||||
}
|
||||
|
||||
if ( leab.notifyWhenTextIsEdited )
|
||||
{
|
||||
connect( m_lineEdit, SIGNAL( textEdited( const QString& ) ), this, SLOT( slotEditingFinished() ) );
|
||||
}
|
||||
}
|
||||
|
||||
bool fromMenuOnly = true;
|
||||
@@ -220,7 +225,10 @@ void PdmUiLineEditor::configureAndUpdateUi( const QString& uiConfigName )
|
||||
displayString = displayStringAttrib.m_displayString;
|
||||
}
|
||||
|
||||
m_lineEdit->setText( displayString );
|
||||
if ( displayString != m_lineEdit->text() )
|
||||
{
|
||||
m_lineEdit->setText( displayString );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ public:
|
||||
maximumWidth = -1;
|
||||
selectAllOnFocusEvent = false;
|
||||
placeholderText = "";
|
||||
notifyWhenTextIsEdited = false;
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -77,6 +78,7 @@ public:
|
||||
int maximumWidth;
|
||||
bool selectAllOnFocusEvent;
|
||||
QString placeholderText;
|
||||
bool notifyWhenTextIsEdited;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user