Skip to content

Commit

Permalink
make virtual methods protected so they can be overidden in Python
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Jan 25, 2021
1 parent df17603 commit 57c5a6f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
Expand Up @@ -217,34 +217,38 @@ Unlinks the features with ``fids``
%End


private:
virtual void updateUi();
%Docstring
A hook called every time the state of the relation editor widget has changed via calling its `set*` methods or slots,
e.g. changed relation, added feature, etc.
Should be used to refresh the UI regarding the new data.
Check QgsRealationEditorWidget as an example.
%End

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

virtual void beforeSetRelationFeature( const QgsRelation &newRelation, const QgsFeature &newFeature );
%Docstring
A hook called right before :py:func:`~QgsAbstractRelationEditorWidget.setRelationFeature` is executed. Used to update the UI once setting the relation feature is done.
Check QgsRealationEditorWidget as an example.
%End

virtual void afterSetRelationFeature();
%Docstring
A hook called right after :py:func:`~QgsAbstractRelationEditorWidget.setRelationFeature` is executed, but before :py:func:`~QgsAbstractRelationEditorWidget.updateUi` is called. Used to update the UI once setting the relation feature is done.
Check QgsRealationEditorWidget as an example.
%End

virtual void beforeSetRelations( const QgsRelation &newRelation, const QgsRelation &newNmRelation );
%Docstring
A hook called right before :py:func:`~QgsAbstractRelationEditorWidget.setRelations` is executed. Used to manipulate UI once setting the relations is done.
Check QgsRealationEditorWidget as an example.
%End

virtual void afterSetRelations();
%Docstring
A hook called right after :py:func:`~QgsAbstractRelationEditorWidget.setRelations` is executed, but before :py:func:`~QgsAbstractRelationEditorWidget.updateUi` is called. Used to update the UI once setting the relations is done.
Expand Down
11 changes: 10 additions & 1 deletion python/gui/auto_generated/qgsrelationeditorwidget.sip.in
Expand Up @@ -145,8 +145,17 @@ Sets the title of the root groupbox
virtual void parentFormValueChanged( const QString &attribute, const QVariant &newValue );


private:
protected:
virtual void updateUi();
virtual void beforeSetRelationFeature( const QgsRelation &newRelation, const QgsFeature &newFeature );

virtual void afterSetRelationFeature();

virtual void beforeSetRelations( const QgsRelation &newRelation, const QgsRelation &newNmRelation );

virtual void afterSetRelations();


};


Expand Down
15 changes: 7 additions & 8 deletions src/gui/qgsabstractrelationeditorwidget.h
Expand Up @@ -244,46 +244,45 @@ class GUI_EXPORT QgsAbstractRelationEditorWidget : public QWidget
*/
void unlinkFeatures( const QgsFeatureIds &fids );


private:
// Following virtual methods need to be protected so they can be overridden in bindings

/**
* A hook called every time the state of the relation editor widget has changed via calling its `set*` methods or slots,
* e.g. changed relation, added feature, etc.
* Should be used to refresh the UI regarding the new data.
* Check QgsRealationEditorWidget as an example.
*/
virtual void updateUi() SIP_FORCE;
virtual void updateUi();

/**
* Sets the title of the widget, if it is wrapped within a QgsCollapsibleGroupBox
* Check QgsRealationEditorWidget as an example.
*/
virtual void setTitle( const QString &title ) SIP_FORCE;
virtual void setTitle( const QString &title );

/**
* A hook called right before setRelationFeature() is executed. Used to update the UI once setting the relation feature is done.
* Check QgsRealationEditorWidget as an example.
*/
virtual void beforeSetRelationFeature( const QgsRelation &newRelation, const QgsFeature &newFeature ) SIP_FORCE;
virtual void beforeSetRelationFeature( const QgsRelation &newRelation, const QgsFeature &newFeature );

/**
* A hook called right after setRelationFeature() is executed, but before updateUi() is called. Used to update the UI once setting the relation feature is done.
* Check QgsRealationEditorWidget as an example.
*/
virtual void afterSetRelationFeature() SIP_FORCE;
virtual void afterSetRelationFeature();

/**
* A hook called right before setRelations() is executed. Used to manipulate UI once setting the relations is done.
* Check QgsRealationEditorWidget as an example.
*/
virtual void beforeSetRelations( const QgsRelation &newRelation, const QgsRelation &newNmRelation ) SIP_FORCE;
virtual void beforeSetRelations( const QgsRelation &newRelation, const QgsRelation &newNmRelation );

/**
* A hook called right after setRelations() is executed, but before updateUi() is called. Used to update the UI once setting the relations is done.
* Check QgsRealationEditorWidget as an example.
*/
virtual void afterSetRelations() SIP_FORCE;
virtual void afterSetRelations();
};


Expand Down
13 changes: 7 additions & 6 deletions src/gui/qgsrelationeditorwidget.h
Expand Up @@ -193,6 +193,13 @@ class GUI_EXPORT QgsRelationEditorWidget : public QgsAbstractRelationEditorWidge
public slots:
void parentFormValueChanged( const QString &attribute, const QVariant &newValue ) override;

protected:
virtual void updateUi() override;
void beforeSetRelationFeature( const QgsRelation &newRelation, const QgsFeature &newFeature ) override;
void afterSetRelationFeature() override;
void beforeSetRelations( const QgsRelation &newRelation, const QgsRelation &newNmRelation ) override;
void afterSetRelations() override;

private slots:
void setViewMode( int mode ) {setViewMode( static_cast<QgsDualView::ViewMode>( mode ) );}
void updateButtons();
Expand All @@ -206,7 +213,6 @@ class GUI_EXPORT QgsRelationEditorWidget : public QgsAbstractRelationEditorWidge
void onDigitizingCompleted( const QgsFeature &feature );

private:
virtual void updateUi() override SIP_FORCE;
void initDualView( QgsVectorLayer *layer, const QgsFeatureRequest &request );
void setMapTool( QgsMapTool *mapTool );
void unsetMapTool();
Expand Down Expand Up @@ -234,11 +240,6 @@ class GUI_EXPORT QgsRelationEditorWidget : public QgsAbstractRelationEditorWidge

Buttons mButtonsVisibility = Button::AllButtons;
bool mVisible = true;

void beforeSetRelationFeature( const QgsRelation &newRelation, const QgsFeature &newFeature ) override;
void afterSetRelationFeature() override;
void beforeSetRelations( const QgsRelation &newRelation, const QgsRelation &newNmRelation ) override;
void afterSetRelations() override;
};


Expand Down

0 comments on commit 57c5a6f

Please sign in to comment.