Model¶
Everything that exists in a project is represented by a model class, including
the project itself. A model class contains those attributes that remain the same
regardless of the format in which something is accessed. For example, the model
class of an object does not contain information about whether the object is
selected for editing, because that is only relevant inside the graphical editor.
All model classes reside in files under the src/model/ directory or one of its
subdirectories.
Entity¶
Inheritance graph
An entity is an object that can have metadata associated with it. The
following entities are defined: Project, Sheet, CompositeObject,
and all of their subclasses. Note that primitive objects are never entities.
-
class
Entity¶ Subclassed by CompositeObject, Project, Sheet
-
class
Entity Base class for entities.
An entity is any class that has some metadata associated with it. Metadata can be a name, annotative properties and variables. Currently, the only entities in Schim are
Project,Sheet,CompositeObjectand any of their subclasses.The currently defined common metadata for all entities are:
name, a friendly name. Can be empty but this is not recommended.filename, the source file of the entity. This can be empty.variables, various variables including built-in and user-defined ones.parent, the parent entity.
Note
Entities are not the only items that can have parents. Other items like primitive objects also have parents, but they need not keep a reference to their parent (to reduce memory usage). In some circumstances primitive objects may keep a reference to their parent, but this is treated on a case-by-case basis.
Note
Children of the entity are not handled in the base class. Derived classes should implement this on their own if needed.
- See
Subclassed by CompositeObject, Project, Sheet
Public Functions
-
explicit
Entity(Entity *parent = nullptr) Construct an empty entity with an optional parent.
-
virtual
~Entity() = default Default destructor that makes this class virtual.
-
VariableSet
getVariables() const Return the variables defined for this entity.
- Returns
The variables defined for this entity, including local variables and those inherited from the parent entity.
Project¶
A project is little more than a collection of sheets (of paper) and some
properties. It is also an Entity.
-
class
Project: public Entity A project is essentially a list of sheets, along with some project properties.
This class should always take care of the destruction of sheets.
Public Functions
-
Project() Construct an empty project with default properties.
-
explicit
Project(const QList<Sheet*> &sheets)
-
~Project()
-
QString
getProperty(const QString name)
-
QList<Sheet*> &
getSheets()
-
QList<Sheet*>
getSheets() const
-
virtual Entity *
getParent() const = delete A project is an entity that has no parent.
-
void
setProperty(const QString &name, const QString &value)
-
void
addSheet(Sheet *sheet, int index = -1)
-
void
removeSheet(Sheet *sheet)
-
virtual void
setParent() const = delete A project is an entity that has no parent.
-
QList<Sheet*>::iterator
begin()
-
QList<Sheet*>::iterator
end()
-
Sheet¶
-
class
Sheet: public Entity This class models a sheet of paper.
This class should always take care of the destruction of the objects it contains.
Public Functions
-
explicit
Sheet(bool defaultHeader = true)
-
~Sheet()
-
float
getWidth() const
-
float
getHeight() const
-
Header *
getHeader()
-
QRectF
getContentArea() const
-
QList<Object*> &
getObjects()
-
QList<Object*>
getObjects() const
-
int
getIndex() Return the index of the sheet in the project it belongs to.
-
void
setWidth(float width)
-
void
setHeight(float height)
-
void
setHeight() const
-
void
setHeader(Header *header, bool destroy = true) Set this sheet's header.
Note
The sheet takes ownership of
header.- Parameters
destroy -- Whether to destroy the old header.
-
void
addObject(Object *obj)
-
void
removeObject(Object *obj)
-
virtual void
setParent(Project *project)
-
QList<Object*>::iterator
begin()
-
QList<Object*>::iterator
end()
-
explicit
Object¶
Inheritance graph
Collaboration graph
All objects are derived from the base class Object.
-
class
Object¶ Subclassed by CompositeObject, Line, Rect, Terminal, Text
-
class
Object The abstract base class for all objects in a sheet.
Everything that has a visual representation in a sheet is derived from this class.
This is a model class, which is distinct from a graphical class. A graphical class represents a wrapper around model classes so that they can be represented in a QGraphicsScene. Model classes are independent of any user interface.
Subclassed by CompositeObject, Line, Rect, Terminal, Text
Public Functions
-
virtual
~Object() = default This destructor does nothing.
It is declared virtual in order to be properly used by derived classes.
-
virtual Object *
clone() const = 0
-
virtual QPointF
getPos() const = 0 Return the position of the object in the sheet.
-
virtual QString
getProperty(const QString &name) const
-
virtual void
setPos(const QPointF &pos) = 0 Set the position of the object in the sheet.
-
virtual void
setProperty(const QString &name, const QString &value)
-
virtual bool
operator==(const Object &obj) const
-
virtual bool
operator!=(const Object &obj) const
-
virtual
Primitive objects¶
Objects that directly inherit from the class Object (apart from CompositeObject) are primitive objects. Currently, the following primitive objects are defined:
Composite objects¶
Objects like electrical devices consist of multiple primitive objects such as lines, rectangles, etc. Such objects are called composite objects. They are all derived from the class CompositeObject, which in turn inherits Object.
-
class
CompositeObject: public Object, public Entity An object that consists of other child objects.
This is the most general representation of an object. Destruction of its child objects should always be performed in the destructor. This class inherits QList<Object*> so we don't have to reimplement the convenience functions that QList already provides.
Subclassed by Component, Corner, Header, ObjectArray
Public Functions
-
CompositeObject()
-
CompositeObject(const CompositeObject &obj) Copy constructor.
-
virtual
~CompositeObject()
-
virtual Object *
clone() const override
-
virtual QPointF
getPos() const override Return the position of the object in the sheet.
-
QList<Object*> &
getConstituents()
-
const QList<Object*> &
getConstituents() const
-
virtual void
setPos(const QPointF &pos) override Set the position of the object in the sheet.
-
void
add(Object *obj)
-
void
add(const QList<Object*> &list)
-
virtual void
remove(Object *obj) Remove
objfrom the object.If this is an instance of
CompositeObject, thenobjis removed from its list of constituents. The behavior can vary in subclasses.- See
For an example behavior in subclasses, see
Component::remove.
-
bool
operator==(const CompositeObject &obj) const
-
bool
operator!=(const CompositeObject &obj) const
-
Variables¶
For familiarity with the concept of variables, see Variables in the user manual.
-
struct
Variable A model representation of a variable.
Every variable has three fields:
names, avalueand adescription.The StringList
namesis used to identify the variable in a string. Each string innamesis an alias for the variable, and must matchallowedPatterns.The
valueis what the variable will be replaced with when displaying text.The
descriptionis simply a way for the user to document the variable.Public Functions
-
Variable() = default
-
explicit
Variable(const QStringList &names, const QString &value = "")
-
Variable(const QStringList &names, const QString &value, const QString &description)
-
QString
getTrueName() const
-
QStringList
getAliases() const
-
bool
operator==(const Variable &var) const
Public Members
-
QStringList
names Contains all names that can be used to identify this variable, separated by a comma.
-
QString
value
-
QString
description
Public Static Functions
-
static QString
allowedPatterns() Return the regex pattern that represents a valid variable name.
-
static Variable
find(const VariableSet &list, QString name) Find a variable named
nameinsidelistand return it.
-
static QString
substitute(QString str, const VariableSet &variableSet) Substitute all variables in
strwith their values.A variable is any substring in
strof the forms%patternor%{pattern}, where pattern is any pattern that matches against the regex returned byallowedPatterns.- Parameters
variableSet -- Supplies the values for the variables. If a variable occurs in
strbut is not contained invariableSet, it is assumed to have an empty value.
-