Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add a hint on widgets for non existent joined features
  • Loading branch information
pblottiere committed Jul 6, 2017
1 parent 5253aa8 commit e5eda5f
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
7 changes: 7 additions & 0 deletions python/gui/editorwidgets/core/qgseditorwidgetwrapper.sip
Expand Up @@ -156,6 +156,13 @@ class QgsEditorWidgetWrapper : QgsWidgetWrapper
:rtype: str
%End

virtual void setHint( const QString &hintText );
%Docstring
Add a hint text on the widget
\param hintText The hint text to display
.. versionadded:: 3.0
%End

signals:

void valueChanged( const QVariant &value );
Expand Down
2 changes: 1 addition & 1 deletion python/gui/qgsattributeform.sip
Expand Up @@ -167,7 +167,7 @@ class QgsAttributeForm : QWidget

public slots:

void changeAttribute( const QString &field, const QVariant &value );
void changeAttribute( const QString &field, const QVariant &value, const QString &hintText = QString() );
%Docstring
Call this to change the content of a given attribute. Will update the editor(s) related to this field.

Expand Down
5 changes: 5 additions & 0 deletions src/gui/editorwidgets/core/qgseditorwidgetwrapper.cpp
Expand Up @@ -211,3 +211,8 @@ bool QgsEditorWidgetWrapper::isInTable( const QWidget *parent )
if ( qobject_cast<const QTableView *>( parent ) ) return true;
return isInTable( parent->parentWidget() );
}

void QgsEditorWidgetWrapper::setHint( const QString &hintText )
{
widget()->setToolTip( hintText );
}
7 changes: 7 additions & 0 deletions src/gui/editorwidgets/core/qgseditorwidgetwrapper.h
Expand Up @@ -164,6 +164,13 @@ class GUI_EXPORT QgsEditorWidgetWrapper : public QgsWidgetWrapper
*/
QString constraintFailureReason() const;

/**
* Add a hint text on the widget
* \param hintText The hint text to display
* \since QGIS 3.0
*/
virtual void setHint( const QString &hintText );

signals:

/**
Expand Down
16 changes: 13 additions & 3 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -223,14 +223,15 @@ void QgsAttributeForm::setMode( QgsAttributeForm::Mode mode )
emit modeChanged( mMode );
}

void QgsAttributeForm::changeAttribute( const QString &field, const QVariant &value )
void QgsAttributeForm::changeAttribute( const QString &field, const QVariant &value, const QString &hintText )
{
Q_FOREACH ( QgsWidgetWrapper *ww, mWidgets )
{
QgsEditorWidgetWrapper *eww = qobject_cast<QgsEditorWidgetWrapper *>( ww );
if ( eww && eww->field().name() == field )
{
eww->setValue( value );
eww->setHint( hintText );
}
}
}
Expand Down Expand Up @@ -1945,6 +1946,7 @@ void QgsAttributeForm::updateJoinedFields( const QgsEditorWidgetWrapper &eww )
if ( infos.count() == 0 || !currentFormFeature( formFeature ) )
return;

const QString hint = tr( "No feature joined" );
Q_FOREACH ( const QgsVectorLayerJoinInfo *info, infos )
{
if ( !info->isDynamicFormEnabled() )
Expand All @@ -1959,11 +1961,15 @@ void QgsAttributeForm::updateJoinedFields( const QgsEditorWidgetWrapper &eww )
{
QString prefixedName = info->prefixedFieldName( field );
QVariant val;
QString hintText = hint;

if ( joinFeature.isValid() )
{
val = joinFeature.attribute( field );
hintText.clear();
}

changeAttribute( prefixedName, val );
changeAttribute( prefixedName, val, hintText );
}
}
else
Expand All @@ -1972,11 +1978,15 @@ void QgsAttributeForm::updateJoinedFields( const QgsEditorWidgetWrapper &eww )
{
QString prefixedName = info->prefixedFieldName( field );
QVariant val;
QString hintText = hint;

if ( joinFeature.isValid() )
{
val = joinFeature.attribute( field.name() );
hintText.clear();
}

changeAttribute( prefixedName, val );
changeAttribute( prefixedName, val, hintText );
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsattributeform.h
Expand Up @@ -209,7 +209,7 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
* \param field The field to change
* \param value The new value
*/
void changeAttribute( const QString &field, const QVariant &value );
void changeAttribute( const QString &field, const QVariant &value, const QString &hintText = QString() );

/**
* Update all editors to correspond to a different feature.
Expand Down

0 comments on commit e5eda5f

Please sign in to comment.