Schim
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
GObject Class Reference

The base class of all objects represented in a graphical scene. More...

#include <gobject.h>

Inheritance diagram for GObject:
[legend]
Collaboration diagram for GObject:
[legend]

Public Member Functions

 GObject (Object *obj)
 Construct a wrapper around obj. More...
 
virtual ~GObject ()
 
virtual Objectget ()
 Return the object that is being wrapped by this class. More...
 
bool isHovered () const
 Return whether the mouse is over this object.
 
virtual void setCosmetic (bool cosmetic)
 Make the object's pen independent of any transformations. More...
 
virtual void reloadFromModel ()
 Update the graphical representation to match the object from the model. More...
 
virtual void applyToModel ()
 Apply changes to the underlying model object. More...
 
virtual void showHandles (bool show=true)
 Display/hide the handles for this item. More...
 
virtual void handleChanged (GObjectHandle *handle)
 Called when a handle's position has changed. More...
 
void hoverEnterEvent (QGraphicsSceneHoverEvent *event) override
 Set hovered=true so that it can be used by paint.
 
void hoverLeaveEvent (QGraphicsSceneHoverEvent *event) override
 Disable the bool hovered so that it can be used by paint.
 
QRectF boundingRect () const override
 Default implementation that returns childrenBoundingRect().
 
void paint (QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override
 
GCompositeObjectparentItem () const
 Return the parent item cast to a GObject*.
 

Static Public Member Functions

static GObjectassign (Object *obj)
 Return a dynamically allocated GObject wrapping the specified object. More...
 

Protected Member Functions

void mouseMoveEvent (QGraphicsSceneMouseEvent *event) override
 
QVariant itemChange (GraphicsItemChange change, const QVariant &value) override
 Process item changes that should behave uniformly across different object types. More...
 

Protected Attributes

Objectobj
 The object that is being wrapped.
 
QList< GObjectHandle * > * handles {}
 Dynamically allocated list of handles.
 

Friends

class GObjectHandle
 

Detailed Description

The base class of all objects represented in a graphical scene.

This class is conceptually an abstract one - it shouldn't be used on its own.

Constructor & Destructor Documentation

◆ GObject()

GObject::GObject ( Object obj)
explicit

Construct a wrapper around obj.

The object is movable, selectable and sends geometry changes by default. Hover events are accepted.

◆ ~GObject()

virtual GObject::~GObject ( )
virtual

Destroy any handles that are still active.

Member Function Documentation

◆ applyToModel()

virtual void GObject::applyToModel ( )
virtual

Apply changes to the underlying model object.

Note
The base implementation does nothing and should be implemented in derived classes.

Reimplemented in GText, GCompositeObject, GRect, GLine, GTerminal, and GLinearObjectArray.

◆ assign()

static GObject* GObject::assign ( Object obj)
static

Return a dynamically allocated GObject wrapping the specified object.

The actual type of the returned object is determined based on the actual type of obj. For example, if obj is of type Line*, then a GLine* will be returned.

◆ get()

virtual Object* GObject::get ( )
virtual

Return the object that is being wrapped by this class.

Note
Derived classes should change the return type of this method to match the type of the object that is wrapped by them.

Reimplemented in GText, GLine, GComponent, GHeader, GRect, GCompositeObject, GTerminal, and GLinearObjectArray.

◆ handleChanged()

virtual void GObject::handleChanged ( GObjectHandle handle)
virtual

Called when a handle's position has changed.

The base implementation does nothing.

Parameters
handleThe handle that has been modified.

Reimplemented in GRect, and GLine.

◆ itemChange()

QVariant GObject::itemChange ( GraphicsItemChange  change,
const QVariant &  value 
)
overrideprotected

Process item changes that should behave uniformly across different object types.

The following changes are processed:

  • ItemZValueHasChanged: display the handles above this object.
  • ItemSelectedHasChanged: show the handles.
  • ItemSceneHasChanged: unselect and unhover.
  • ItemPositionChange: apply snap-to-grid before the position actually changes.
  • ItemPositionHasChanged: apply position change to the underlying model object.
Note
All derived objects should call this version in their implementation.

◆ mouseMoveEvent()

void GObject::mouseMoveEvent ( QGraphicsSceneMouseEvent *  event)
overrideprotected

If the item is being dragged (left button is down), snap the cursor guides to the grid.

◆ paint()

void GObject::paint ( QPainter *  ,
const QStyleOptionGraphicsItem *  ,
QWidget *   
)
override

This implementation applies aesthetic modifications when the object is hovered or selected.

Note
Derived classes should call this version at the beginning of their implementation to apply the aesthetic changes.

◆ reloadFromModel()

virtual void GObject::reloadFromModel ( )
virtual

Update the graphical representation to match the object from the model.

Note
The base implementation does nothing and should be implemented in derived classes.

Reimplemented in GText, GCompositeObject, GRect, GLine, GTerminal, and GLinearObjectArray.

◆ setCosmetic()

virtual void GObject::setCosmetic ( bool  cosmetic)
virtual

Make the object's pen independent of any transformations.

Make an object cosmetic when it is going to be rendered to an icon.

Reimplemented in GCompositeObject.

◆ showHandles()

virtual void GObject::showHandles ( bool  show = true)
virtual

Display/hide the handles for this item.

The list of handles is dynamically allocated and it exists only while the handles are visible. This way, the handles do not take up memory when they are not used.

Note
The base version of this method implements only the deletion of handles, i.e. when show = true. Each subclass should implement this this method separately, optionally calling the superclass method but only as the last statement.

Reimplemented in GRect, and GLine.


The documentation for this class was generated from the following file: