1 /*
2 # PostgreSQL Database Modeler (pgModeler)
3 #
4 # Copyright 2006-2020 - Raphael Araújo e Silva <raphael@pgmodeler.io>
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation version 3.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # The complete text of GPLv3 is at LICENSE file on source code root directory.
16 # Also, you can get the complete GNU General Public License at <http://www.gnu.org/licenses/>
17 */
18 
19 #include "basegraphicobject.h"
20 
BaseGraphicObject()21 BaseGraphicObject::BaseGraphicObject()
22 {
23 	is_modified=true;
24 	is_faded_out=false;
25 	attributes[Attributes::XPos]="";
26 	attributes[Attributes::YPos]="";
27 	attributes[Attributes::Position]="";
28 	attributes[Attributes::FadedOut]="";
29 	attributes[Attributes::Layer]="";
30 	attributes[Attributes::ZValue]="";
31 	receiver_object=nullptr;
32 	layer = 0;
33 	z_value=0;
34 }
35 
setProtected(bool value)36 void BaseGraphicObject::setProtected(bool value)
37 {
38 	BaseObject::setProtected(value);
39 	emit s_objectProtected(this->isProtected());
40 }
41 
setSystemObject(bool value)42 void BaseGraphicObject::setSystemObject(bool value)
43 {
44 	BaseObject::setSystemObject(value);
45 }
46 
setModified(bool value)47 void BaseGraphicObject::setModified(bool value)
48 {
49 	is_modified=value;
50 
51 	if(is_modified)
52 		emit s_objectModified();
53 }
54 
setSQLDisabled(bool value)55 void BaseGraphicObject::setSQLDisabled(bool value)
56 {
57 	bool curr_val=sql_disabled;
58 
59 	BaseObject::setSQLDisabled(value);
60 
61 	if(value != curr_val)
62 		emit s_objectModified();
63 }
64 
setFadedOut(bool value)65 void BaseGraphicObject::setFadedOut(bool value)
66 {
67 	setCodeInvalidated(is_faded_out != value);
68 	is_faded_out = value;
69 }
70 
isModified()71 bool BaseGraphicObject::isModified()
72 {
73 	return is_modified;
74 }
75 
isFadedOut()76 bool BaseGraphicObject::isFadedOut()
77 {
78 	return is_faded_out;
79 }
80 
setFadedOutAttribute()81 void BaseGraphicObject::setFadedOutAttribute()
82 {
83 	attributes[Attributes::FadedOut]=(is_faded_out ? Attributes::True : "");
84 }
85 
setPositionAttribute()86 void BaseGraphicObject::setPositionAttribute()
87 {
88 	attributes[Attributes::XPos]=QString("%1").arg(position.x());
89 	attributes[Attributes::YPos]=QString("%1").arg(position.y());
90 	attributes[Attributes::Position]=schparser.getCodeDefinition(Attributes::Position, attributes, SchemaParser::XmlDefinition);
91 }
92 
setPosition(QPointF pos)93 void  BaseGraphicObject::setPosition(QPointF pos)
94 {
95 	setCodeInvalidated(position != pos);
96 	position=pos;
97 }
98 
getPosition()99 QPointF BaseGraphicObject::getPosition()
100 {
101 	return position;
102 }
103 
operator =(BaseGraphicObject & obj)104 void BaseGraphicObject::operator = (BaseGraphicObject &obj)
105 {
106 	*(dynamic_cast<BaseObject *>(this))=dynamic_cast<BaseObject &>(obj);
107 	this->position=obj.position;
108 	this->z_value=obj.z_value;
109 }
110 
setReceiverObject(QObject * obj)111 void BaseGraphicObject::setReceiverObject(QObject *obj)
112 {
113 	if(!obj && receiver_object)
114 		disconnect(this, nullptr, receiver_object, nullptr);
115 
116 	receiver_object=obj;
117 }
118 
getOverlyingObject()119 QObject *BaseGraphicObject::getOverlyingObject()
120 {
121 	return receiver_object;
122 }
123 
isGraphicObject(ObjectType type)124 bool BaseGraphicObject::isGraphicObject(ObjectType type)
125 {
126 	return (type==ObjectType::Table || type==ObjectType::View || type==ObjectType::Relationship ||
127 				 type==ObjectType::BaseRelationship || type==ObjectType::Textbox || type==ObjectType::Schema ||
128 				 type==ObjectType::ForeignTable);
129 }
130 
setLayer(unsigned layer)131 void BaseGraphicObject::setLayer(unsigned layer)
132 {
133 	setCodeInvalidated(this->layer != layer);
134 	this->layer = layer;
135 }
136 
getLayer()137 unsigned BaseGraphicObject::getLayer()
138 {
139 	return layer;
140 }
141 
setZValue(int z_value)142 void BaseGraphicObject::setZValue(int z_value)
143 {
144 	if(z_value < MinZValue)
145 		z_value = MinZValue;
146 	else if(z_value > MaxZValue)
147 		z_value = MaxZValue;
148 
149 	this->z_value = z_value;
150 }
151 
getZValue()152 int BaseGraphicObject::getZValue()
153 {
154 	return z_value;
155 }
156