-
-
Notifications
You must be signed in to change notification settings - Fork 385
/
baseobjectview.h
192 lines (140 loc) · 6.83 KB
/
baseobjectview.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
# PostgreSQL Database Modeler (pgModeler)
#
# Copyright 2006-2016 - Raphael Araújo e Silva <raphael@pgmodeler.com.br>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# The complete text of GPLv3 is at LICENSE file on source code root directory.
# Also, you can get the complete GNU General Public License at <http://www.gnu.org/licenses/>
*/
/**
\ingroup libobjrenderer
\class BaseObjectView
\brief Implements the basic routines to graphically represent the objects: table, relationship, textbox, view.
*/
#ifndef BASE_OBJECT_VIEW_H
#define BASE_OBJECT_VIEW_H
#include <QtWidgets>
#include "basegraphicobject.h"
#include "baserelationship.h"
#include "xmlparser.h"
#include "roundedrectitem.h"
class BaseObjectView: public QObject, public QGraphicsItemGroup {
private:
Q_OBJECT
protected:
/*! brief Indicates if the placeholder object must be used when moving objects.
Place holder objects when enabled causes a significant performance gain mainly when
moving tables linked to relationships because the relationships will be updated only
when the table moviment ends and not during it */
static bool use_placeholder;
/*! \brief Stores the global selection order of objects. This attributes
is incremented each time an object is selected. */
static unsigned global_sel_order;
/*! \brief Stores the selection order of the current object. This attribute is used to
know when an item was selected before another in the scene because the implementation of
the method QGraphicsScene :: selectedItem() the selected objects are returned without
any sort, but for the database model objects is the ESSENTIAL to know the selection order
mainly when creating relationships between tables. */
unsigned sel_order;
//! \brief Graphical text for the position info
QGraphicsSimpleTextItem *pos_info_txt;
//! \brief Graphical object (rectangle) of the position info
QGraphicsRectItem *pos_info_rect;
//! \brief Stores the objects bounding rect
QRectF bounding_rect;
//! \brief Graphical object that represents the object selection
QGraphicsItem *obj_selection;
//! \brief Icon that represent the object protection
QGraphicsItemGroup *protected_icon;
//! \brief Graphical object that represents the current object shadow
QGraphicsItem *obj_shadow;
//! brief Graphical object that represents the placeholder when the object is being moved
RoundedRectItem *placeholder;
//! \brief Graphical object of the sql disabled info
QGraphicsRectItem *sql_disabled_box;
//! \brief Graphical text for the sql disabled info
QGraphicsSimpleTextItem *sql_disabled_txt;
//! \brief Stores the object font configuration
static map<QString, QTextCharFormat> font_config;
//! \brief Stores the object colors configuration
static map<QString, QColor*> color_config;
//! \brief Resizes to the specified dimension the passed polygon
void resizePolygon(QPolygonF &pol, double width, double height);
//! \brief Configures the objects shadow polygon
void configureObjectShadow(void);
//! \brief Configures the object selection polygon
void configureObjectSelection(void);
//! \brief Configures the polygons used to show the current object position
void configurePositionInfo(QPointF pos);
//! \brief Configures the rectangle used to show the sql disabled status
void configureSQLDisabledInfo(void);
//! \brief Configures the icon that denotes the object's protection
void configureProtectedIcon(void);
void configurePlaceholder(void);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void setSelectionOrder(bool selected);
public:
static constexpr double VERT_SPACING=2.0f,
HORIZ_SPACING=2.0f,
DEFAULT_FONT_SIZE=9.0f,
OBJ_BORDER_WIDTH=0.80f;
BaseObjectView(BaseObject *object=nullptr);
virtual ~BaseObjectView(void);
//! \brief Returns the object selection order
unsigned getSelectionOrder(void);
//! \brief Controls the changes during the object's selection and moving
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
//! \brief Returns the object that is representend by the graphical object
BaseObject *getSourceObject(void);
//! \brief Loads the font / color styels for the objects from a XML configuration file
static void loadObjectsStyle(void);
//! \brief Returns the objects bounding rect in local coordination
QRectF boundingRect(void) const;
//! \brief Returns the fill style in a form of gradient for the specified element id
static QLinearGradient getFillStyle(const QString &id);
/*! \brief Returns fill style storing the colors on the specified parameters color1 and color2
for the specified element id */
static void getFillStyle(const QString &id, QColor &color1, QColor &color2);
//! \brief Returns the border style for the specified element id
static QPen getBorderStyle(const QString &id);
//! \brief Returns the font style for the specified element id
static QTextCharFormat getFontStyle(const QString &id);
static void setPlaceholderEnabled(bool value);
static bool isPlaceholderEnabled(void);
//! \brief Sets the font style for the specified element id
static void setFontStyle(const QString &id, QTextCharFormat font_fmt);
//! \brief Sets the color for the specified element id (used to set color for objects and font)
static void setElementColor(const QString &id, QColor color, unsigned color_id);
//! \brief Returns the color for the specified element id (used to get color for objects and font)
static QColor getElementColor(const QString &id, unsigned color_id);
//! \brief Defines the object that the view represents
void setSourceObject(BaseObject *object);
//! \brief Pure virtual object (the derived classes must implement it)
virtual void configureObject(void)=0;
/*! \brief Returns the center point of the whole object.
Note: this is not the same as calling boundingRect()->center(). Instead, this
method calculates the center point based upon the current object's position */
virtual QPointF getCenter(void);
//! brief Toggles the wireframe display
virtual void togglePlaceholder(bool visible);
protected slots:
//! \brief Make the basic object operations
void __configureObject(void);
//! \brief Toggles the protection icon
void toggleProtectionIcon(bool value);
signals:
//! \brief Signal emmited when the object is (un)selected
void s_objectSelected(BaseGraphicObject *object, bool selected);
//! brief Signal emmited whenever the width or height of the table changes
void s_objectDimensionChanged(void);
};
#endif