Layout

Layout module for printing. The purpose is diagrammatize a report for printing, consisting of cartographic elements such as maps, scales and legends, among others, as well as texts and geometric figures. It's possible view and print reports in various formats of paper. It is allowed to extent to create a customized application or plugin for diagrammatize a report for printing.

To assist in the development of the structure was used the Graphics View Framework, available from version Qt 4.2, and also the Qt Property Browser framework.

Features

  • Components: maps, texts and geometrics;
  • Creation, modification and removal of a component;
  • Move, resize and rotate a component;
  • Automatic update of dependent items of one map component;
  • Properties Edition;
  • Object Inspector;
  • Grouping of objects;
  • Undo/Redo;
  • Support for drag-and-drop the layer on a map component;
  • Print;
  • Viewing and printing in different sizes of paper;
  • Planar/Geodesic grid configuration;
  • Systematic scale;
  • Alignment the components on the paper;
  • Zoom In/Out/Area and Pan in the visualization area;
  • Serialization of components:
    • Properties System;
    • Templates System;
  • Coordinate system in millimeters;

Architecture

A layout model consists of graphical components, Item, following the MVC pattern. These are inserted into a scene (QGraphicsScene) and rendered by a widget (QGraphicsView) that contains this scene. The part View of the component is the one that uses the Qt library, specifically the Graphics View framework. Thus the whole vision is also a QGraphicsItem. The items by default understand only coordinates in millimeters.

There is a context object, singleton that keeps active objects while the Plugin/App is loaded in memory and leaves available for access anywhere in the Plugin/App or module. Ex.: factories objects, canvas, class of utility functions, proxy to access the project, etc.

Graphics View Framework provides a surface for managing and interacting with a large number of 2D graphical items custom-made, and a widget (QGraphicsView) for displaying the items, with support for zoom and rotation.

Obs.: due to the calculation of the transformation matrix, the scene has inverted y coordinate, so to print it is necessary to invert the y coordinate of the QPainter before.

The Layout module uses some Graphics View classes, being the main ones:

Scene

The scene of the layout module is child of QGraphicsScene. The scene is not a graphic object, so it can not draw it, but the items that are included in the scene can be drawed. Responsible for managing the items and when and how to redrawing them. The scene coordinate system is, by default, millimeter, and your point 0.0 mm is below the left (Cartesian coordinate system).

View

The View of the Layout module is child of QGraphicsView, The View object is a widget where items, added the scene, are drawn. It is responsible for presentation and interaction between the screen events and the scene. Manages interactive functions and intercepts all mouse and keyboard events. The coordinate system is in pixel (screen coordinate system).

Item

An item is a graphical component that follows the MVC pattern, composed of three parts: Model, Vision and Controller. To create a new item is required inherit the following classes: ItemObserver, ItemModelObservable and ItemController. The part View of the component is the one that uses the Qt library, specifically the Graphics View Framework. Thus the whole View is also a QGraphicsItem. Ex.: TextItem, MapItem, RectangleItem, etc.

Outside

An outside is a widget that follows the MVC pattern, composed of three parts: Model, Vision and Controller. To create a new item is required inherit the following classes: OutsideObserver, OutsideModelObservable and OutsideController. The part View of the widget is the one that uses the Qt library. Thus the whole View is also a QWidget. Ex.: PropertiesOutside, ObjectInspectorOutside, ToolbarOutside, etc.

Coordinate System

The scene of the layout module has coordinate system in millimeters. To make it possible to change the default coordinate system, it was necessary to calculate a transformation matrix and pass it to the View and thus be possible mapping between the View (screen coordinates) and the Scene (coordinates in millimeters). After calculating the transformation matrix is necessary to configure the size of the Scene in millimeters.

Calculation of the transformation matrix:

void te::layout::Scene::calculateMatrixViewScene()
{
  double llx = m_box.m_llx;
  double lly = m_box.m_lly;
  double urx = m_box.m_urx;
  double ury = m_box.m_ury;
 
  double dpiX = Context::getInstance().getDpiX();
 
  double factor = (dpiX / 25.4);
 
  //inverted Y-Axis
  m_matrix = QTransform().scale(factor, -factor).translate(-llx, -ury);
  //World coordinate - mm
  setSceneRect(QRectF(QPointF(llx, lly), QPointF(urx, ury)));
}

Example mapping between View and Scene:

void te::layout::View::mousePressEvent( QMouseEvent * event )
{
  QGraphicsView::mousePressEvent(event);
 
  QPointF scenePos = mapToScene(event->pos());
  te::gm::Coord2D coord(scenePos.x(), scenePos.y());
 
  Scene* sc = dynamic_cast<Scene*>(scene());
  if(!sc)
    return;
 
  EnumModeType* mode = Enums::getInstance().getEnumModeType();
 
  if(Context::getInstance().getMode() == mode->getModeNone())
    return;
 
  sc->createItem(coord);
}

Design Patterns

MVC

Basic classes for creation of an Item(component):

  • ItemModelObservable (Model): abstract class that represents an observable object. Part Model of the MVC component. All classes that represent the part of the model of a Item must inherit from this class.
  • ItemObserver (View): abstract class representing an observer. Part View of the MVC component. All classes that represent the part of the vision of a Item must inherit from this class.
  • ItemController (Controller): abstract class that represents a controller. Part Controller of the MVC component. All classes that represent the part of the Controller of an Item should inherit from this class.

Basic classes for creation a widget that will be accessed outside of a View:

  • OutsideModelObservable (Model): abstract class that represents an observable object. Part Model of the MVC widget. All classes that represent the part of the model of a Outside must inherit from this class.
  • OutsideObserver (View): Abstract class representing an observer. Part View of the MVC widget. All classes that represent the part of the vision of a Outside must inherit from this class.
  • OutsideController (Controller): abstract class that represents a controller. Part Controller of the MVC widget. All classes that represent the part of the Controller of an Outside should inherit from this class.

Factory

Factories, being the main ones:

  • ItemFactory: Factory for creating families of related or dependent graphic objects (MVC components).
  • OutsideFactory: Factory for creating families of related or dependent widgets (MVC widgets).
  • TemplateFactory: Factory for creating families of related or dependent templates.
  • ItemParamsCreate: parameters to creation new object. Ex.: “Model” and “Controller” of the new object (MVC component).
  • OutsideParamsCreate: parameters to creation new object. Ex.: “Model” and “Controller” of the new object (MVC widget).
  • TemplateParamsCreate: parameters to creation new template object.

Singleton

  • Context: singleton that keeps active objects while the Plugin/App is loaded in memory and leaves available for access anywhere in the Plugin/App or module. Ex.: factories objects, canvas, class of utility functions, proxy to access the project, etc.
  • Enums: singleton class responsible for keeping active objects of Enum while the plugin is loaded in memory leaves available for access anywhere in the Plugin/App or module. Ex .: Enum for data type, enum for object type, enum for mode type, enum for template type, etc.

Proxy

  • AbstractProxyProject: Abstract class to provide a surrogate or placeholder for te::qt::af::Project to control access to it. A wrapper to access without complexity. This abstract proxy is required because module not must have dependence te::qt::af. Useful to access the layers belonging to the project.

Visitor

Basic classes that provide the dependence between components to dynamically and automatically update. Ex: Scale(Visitor) depends on a Map(Visitable).

  • Visitable: class to represent a visitable. All classes representing a visitable must inherit from this class.
  • AbstractVisitor: Abstract class to represent a visitor. All classes representing a visitor must inherit from this class.

Enum

Set of classes that represent enumerations. Ex. Data type, mode, object type, etc.

A EnumType object is the value of an enumeration. An enumeration is made of “1..n” EnumType objects.

Enumeration, being the main ones:

  • EnumDataType: Class to represent a data type enumeration. Ex.: int, double, bool, te::color::RGBAColor (color), etc.
  • EnumObjectType: Class to represent a graphic object (MVC component) and widget object (MVC widget) type enumeration. Ex. component: map, legend, scale, rectangle, text, etc; widget: object inspector, toolbar, etc.
  • EnumModeType: Class to represent a mode type enumeration. Ex.: select, pan, create text, etc. The type of mode is used by the context to know what should be done. The mode in context could be modified by the user interaction.

QR Code
QR Code wiki:designimplementation:layout (generated for current page)