Skip to content

Commit

Permalink
Moved label implementation of relation editor widget to attribute form
Browse files Browse the repository at this point in the history
  • Loading branch information
domi4484 committed May 12, 2021
1 parent c773fd9 commit d8aa6dd
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 84 deletions.
Expand Up @@ -40,20 +40,26 @@ Constructor for QgsRelationWidgetWrapper
Constructor for QgsRelationWidgetWrapper
%End

bool showLabel() const;
bool showLabel() const /Deprecated/;
%Docstring
Defines if a title label should be shown for this widget.
Only has an effect after :py:func:`~QgsRelationWidgetWrapper.widget` has been called at least once.

.. versionadded:: 2.18

.. deprecated:: QGIS 3.20
label is handled directly in :py:class:`QgsAttributeForm`.
%End

void setShowLabel( bool showLabel );
void setShowLabel( bool showLabel ) /Deprecated/;
%Docstring
Defines if a title label should be shown for this widget.
Only has an effect after :py:func:`~QgsRelationWidgetWrapper.widget` has been called at least once.

.. versionadded:: 2.18

.. deprecated:: QGIS 3.20
label is handled directly in :py:class:`QgsAttributeForm`.
%End

bool showLinkButton() const /Deprecated/;
Expand Down Expand Up @@ -185,19 +191,25 @@ If it's empty, then it's considered as a 1:M relationship.
.. versionadded:: 3.16
%End

QString label() const;
QString label() const /Deprecated/;
%Docstring
Determines the label of this element

.. versionadded:: 3.16

.. deprecated:: QGIS 3.20
label is handled directly in :py:class:`QgsAttributeForm`.
%End

void setLabel( const QString &label = QString() );
void setLabel( const QString &label = QString() ) /Deprecated/;
%Docstring
Sets ``label`` for this element
If it's empty it takes the relation id as label

.. versionadded:: 3.16

.. deprecated:: QGIS 3.20
label is handled directly in :py:class:`QgsAttributeForm`.
%End

QgsRelation relation() const;
Expand Down
26 changes: 20 additions & 6 deletions python/gui/auto_generated/qgsabstractrelationeditorwidget.sip.in
Expand Up @@ -91,14 +91,20 @@ Sets the editor ``context``
Returns the attribute editor context.
%End

bool showLabel() const;
bool showLabel() const /Deprecated/;
%Docstring
Defines if a title label should be shown for this widget.

.. deprecated:: QGIS 3.20
label is handled directly in :py:class:`QgsAttributeForm`.
%End

void setShowLabel( bool showLabel );
void setShowLabel( bool showLabel ) /Deprecated/;
%Docstring
Defines if a title label should be shown for this widget.

.. deprecated:: QGIS 3.20
label is handled directly in :py:class:`QgsAttributeForm`.
%End

QVariant nmRelationId() const;
Expand All @@ -112,9 +118,12 @@ Sets ``nmRelationId`` for the relation id of the second relation involved in an
If it's empty, then it's considered as a 1:M relationship.
%End

QString label() const;
QString label() const /Deprecated/;
%Docstring
Determines the label of this element

.. deprecated:: QGIS 3.20
label is handled directly in :py:class:`QgsAttributeForm`.
%End

void setLabel( const QString &label = QString() );
Expand Down Expand Up @@ -208,9 +217,12 @@ Duplicates features



void updateTitle();
void updateTitle() /Deprecated/;
%Docstring
Updates the title contents to reflect the current state of the widget

.. deprecated:: QGIS 3.20
label is handled directly in :py:class:`QgsAttributeForm`.
%End

void deleteFeatures( const QgsFeatureIds &fids );
Expand All @@ -232,10 +244,12 @@ Should be used to refresh the UI regarding the new data.
Check :py:class:`QgsRealationEditorWidget` as an example.
%End

virtual void setTitle( const QString &title );
virtual void setTitle( const QString &title ) /Deprecated/;
%Docstring
Sets the title of the widget, if it is wrapped within a :py:class:`QgsCollapsibleGroupBox`
Check :py:class:`QgsRealationEditorWidget` as an example.

.. deprecated:: QGIS 3.20
label is handled directly in :py:class:`QgsAttributeForm`.
%End

virtual void beforeSetRelationFeature( const QgsRelation &newRelation, const QgsFeature &newFeature );
Expand Down
12 changes: 2 additions & 10 deletions src/gui/editorwidgets/qgsrelationwidgetwrapper.cpp
Expand Up @@ -138,17 +138,12 @@ void QgsRelationWidgetWrapper::setShowSaveChildEditsButton( bool showSaveChildEd

bool QgsRelationWidgetWrapper::showLabel() const
{
if ( mWidget )
{
return mWidget->showLabel();
}
return false;
}

void QgsRelationWidgetWrapper::setShowLabel( bool showLabel )
{
if ( mWidget )
mWidget->setShowLabel( showLabel );
Q_UNUSED( showLabel )
}

void QgsRelationWidgetWrapper::initWidget( QWidget *editor )
Expand Down Expand Up @@ -297,14 +292,11 @@ QVariant QgsRelationWidgetWrapper::nmRelationId() const

void QgsRelationWidgetWrapper::setLabel( const QString &label )
{
if ( mWidget )
mWidget->setLabel( label );
Q_UNUSED( label )
}

QString QgsRelationWidgetWrapper::label() const
{
if ( mWidget )
return mWidget->label();
return QString();
}

Expand Down
12 changes: 8 additions & 4 deletions src/gui/editorwidgets/qgsrelationwidgetwrapper.h
Expand Up @@ -57,16 +57,18 @@ class GUI_EXPORT QgsRelationWidgetWrapper : public QgsWidgetWrapper
* Only has an effect after widget() has been called at least once.
*
* \since QGIS 2.18
* \deprecated since QGIS 3.20 label is handled directly in QgsAttributeForm.
*/
bool showLabel() const;
Q_DECL_DEPRECATED bool showLabel() const SIP_DEPRECATED;

/**
* Defines if a title label should be shown for this widget.
* Only has an effect after widget() has been called at least once.
*
* \since QGIS 2.18
* \deprecated since QGIS 3.20 label is handled directly in QgsAttributeForm.
*/
void setShowLabel( bool showLabel );
Q_DECL_DEPRECATED void setShowLabel( bool showLabel ) SIP_DEPRECATED;

/**
* Determines if the "link feature" button should be shown
Expand Down Expand Up @@ -170,15 +172,17 @@ class GUI_EXPORT QgsRelationWidgetWrapper : public QgsWidgetWrapper
/**
* Determines the label of this element
* \since QGIS 3.16
* \deprecated since QGIS 3.20 label is handled directly in QgsAttributeForm.
*/
QString label() const;
Q_DECL_DEPRECATED QString label() const SIP_DEPRECATED;

/**
* Sets \a label for this element
* If it's empty it takes the relation id as label
* \since QGIS 3.16
* \deprecated since QGIS 3.20 label is handled directly in QgsAttributeForm.
*/
void setLabel( const QString &label = QString() );
Q_DECL_DEPRECATED void setLabel( const QString &label = QString() ) SIP_DEPRECATED;

/**
* The relation for which this wrapper is created.
Expand Down
42 changes: 5 additions & 37 deletions src/gui/qgsabstractrelationeditorwidget.cpp
Expand Up @@ -28,25 +28,14 @@
#include "qgsproject.h"
#include "qgstransactiongroup.h"
#include "qgsvectorlayerutils.h"
#include "qgscollapsiblegroupbox.h"

#include <QMessageBox>
#include <QPushButton>
#include <QVBoxLayout>

QgsAbstractRelationEditorWidget::QgsAbstractRelationEditorWidget( const QVariantMap &config, QWidget *parent )
: QWidget( parent )
{
Q_UNUSED( config );

QVBoxLayout *rootLayout = new QVBoxLayout( this );
rootLayout->setContentsMargins( 0, 0, 0, 0 );

mRootCollapsibleGroupBox = new QgsCollapsibleGroupBox( QString(), this );
rootLayout->addWidget( mRootCollapsibleGroupBox );

mTopVBoxLayout = new QVBoxLayout( mRootCollapsibleGroupBox );
mTopVBoxLayout->setContentsMargins( 0, 9, 0, 0 );
}

void QgsAbstractRelationEditorWidget::setRelationFeature( const QgsRelation &relation, const QgsFeature &feature )
Expand Down Expand Up @@ -141,26 +130,22 @@ QVariant QgsAbstractRelationEditorWidget::nmRelationId() const

QString QgsAbstractRelationEditorWidget::label() const
{
return mLabel;
return QString();
}

void QgsAbstractRelationEditorWidget::setLabel( const QString &label )
{
mLabel = label;

updateTitle();
Q_UNUSED( label )
}

bool QgsAbstractRelationEditorWidget::showLabel() const
{
return mShowLabel;
return false;
}

void QgsAbstractRelationEditorWidget::setShowLabel( bool showLabel )
{
mShowLabel = showLabel;

updateTitle();
Q_UNUSED( showLabel )
}

void QgsAbstractRelationEditorWidget::setForceSuppressFormPopup( bool forceSuppressFormPopup )
Expand All @@ -175,18 +160,6 @@ bool QgsAbstractRelationEditorWidget::forceSuppressFormPopup() const

void QgsAbstractRelationEditorWidget::updateTitle()
{
if ( mShowLabel && !mLabel.isEmpty() )
{
setTitle( mLabel );
}
else if ( mShowLabel && mRelation.isValid() )
{
setTitle( mRelation.name() );
}
else
{
setTitle( QString() );
}
}

QgsFeature QgsAbstractRelationEditorWidget::feature() const
Expand Down Expand Up @@ -617,7 +590,7 @@ void QgsAbstractRelationEditorWidget::updateUi()

void QgsAbstractRelationEditorWidget::setTitle( const QString &title )
{
mRootCollapsibleGroupBox->setTitle( title );
Q_UNUSED( title )
}

void QgsAbstractRelationEditorWidget::beforeSetRelationFeature( const QgsRelation &newRelation, const QgsFeature &newFeature )
Expand All @@ -638,11 +611,6 @@ void QgsAbstractRelationEditorWidget::beforeSetRelations( const QgsRelation &new
void QgsAbstractRelationEditorWidget::afterSetRelations()
{}

QVBoxLayout *QgsAbstractRelationEditorWidget::rootTopVBoxLayout() const
{
return mTopVBoxLayout;
}

void QgsAbstractRelationEditorWidget::duplicateFeature( const QgsFeatureId &fid )
{
duplicateFeatures( QgsFeatureIds() << fid );
Expand Down
27 changes: 10 additions & 17 deletions src/gui/qgsabstractrelationeditorwidget.h
Expand Up @@ -33,10 +33,8 @@
% End
#endif

class QVBoxLayout;
class QgsFeature;
class QgsVectorLayer;
class QgsCollapsibleGroupBox;

/**
* Base class to build new relation widgets.
Expand Down Expand Up @@ -113,13 +111,15 @@ class GUI_EXPORT QgsAbstractRelationEditorWidget : public QWidget

/**
* Defines if a title label should be shown for this widget.
* \deprecated since QGIS 3.20 label is handled directly in QgsAttributeForm.
*/
bool showLabel() const;
Q_DECL_DEPRECATED bool showLabel() const SIP_DEPRECATED;

/**
* Defines if a title label should be shown for this widget.
* \deprecated since QGIS 3.20 label is handled directly in QgsAttributeForm.
*/
void setShowLabel( bool showLabel );
Q_DECL_DEPRECATED void setShowLabel( bool showLabel ) SIP_DEPRECATED;

/**
* Determines the relation id of the second relation involved in an N:M relation.
Expand All @@ -134,8 +134,9 @@ class GUI_EXPORT QgsAbstractRelationEditorWidget : public QWidget

/**
* Determines the label of this element
* \deprecated since QGIS 3.20 label is handled directly in QgsAttributeForm.
*/
QString label() const;
Q_DECL_DEPRECATED QString label() const SIP_DEPRECATED;

/**
* Sets \a label for this element
Expand Down Expand Up @@ -230,19 +231,15 @@ class GUI_EXPORT QgsAbstractRelationEditorWidget : public QWidget
QgsRelation mNmRelation;
QgsFeature mFeature;

bool mShowLabel = true;
bool mLayerInSameTransactionGroup = false;

bool mForceSuppressFormPopup = false;
QString mLabel;

QgsCollapsibleGroupBox *mRootCollapsibleGroupBox = nullptr;
QVBoxLayout *mTopVBoxLayout = nullptr;

/**
* Updates the title contents to reflect the current state of the widget
* \deprecated since QGIS 3.20 label is handled directly in QgsAttributeForm.
*/
void updateTitle();
Q_DECL_DEPRECATED void updateTitle() SIP_DEPRECATED;

/**
* Deletes the features with \a fids
Expand All @@ -266,8 +263,9 @@ class GUI_EXPORT QgsAbstractRelationEditorWidget : public QWidget

/**
* Sets the title of the widget, if it is wrapped within a QgsCollapsibleGroupBox
* \deprecated since QGIS 3.20 label is handled directly in QgsAttributeForm.
*/
virtual void setTitle( const QString &title );
Q_DECL_DEPRECATED virtual void setTitle( const QString &title ) SIP_DEPRECATED;

/**
* A hook called right before setRelationFeature() is executed. Used to update the UI once setting the relation feature is done.
Expand All @@ -292,11 +290,6 @@ class GUI_EXPORT QgsAbstractRelationEditorWidget : public QWidget
* Check QgsRealationEditorWidget as an example.
*/
virtual void afterSetRelations();

/**
* The root collapsible group box to insert content into
*/
QVBoxLayout *rootTopVBoxLayout() const;
};


Expand Down

0 comments on commit d8aa6dd

Please sign in to comment.