Skip to content
Permalink
Browse files

Add a hint on widgets for non existent joined features

  • Loading branch information
pblottiere committed Jul 6, 2017
1 parent 5253aa8 commit e5eda5f8899fccccb1ba06e1c664203689ac8a38
@@ -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 );
@@ -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.

@@ -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 );
}
@@ -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:

/**
@@ -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 );
}
}
}
@@ -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() )
@@ -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
@@ -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 );
}
}
}
@@ -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.

0 comments on commit e5eda5f

Please sign in to comment.
You can’t perform that action at this time.