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 "tableobject.h"
20 
TableObject()21 TableObject::TableObject()
22 {
23 	parent_table=nullptr;
24 	decl_in_table=true;
25 	add_by_linking=add_by_generalization=add_by_copy=false;
26 }
27 
setParentTable(BaseTable * table)28 void TableObject::setParentTable(BaseTable *table)
29 {
30 	parent_table=table;
31 }
32 
getParentTable()33 BaseTable *TableObject::getParentTable()
34 {
35 	return parent_table;
36 }
37 
setAddedByLinking(bool value)38 void TableObject::setAddedByLinking(bool value)
39 {
40 	add_by_linking=value;
41 	add_by_generalization=false;
42 	add_by_copy=false;
43 }
44 
isAddedByLinking()45 bool TableObject::isAddedByLinking()
46 {
47 	return add_by_linking;
48 }
49 
setAddedByGeneralization(bool value)50 void TableObject::setAddedByGeneralization(bool value)
51 {
52 	add_by_generalization=value;
53 	add_by_linking=false;
54 	add_by_copy=false;
55 }
56 
setDeclaredInTable(bool value)57 void TableObject::setDeclaredInTable(bool value)
58 {
59 	setCodeInvalidated(decl_in_table != value);
60 	decl_in_table=value;
61 }
62 
isAddedByGeneralization()63 bool TableObject::isAddedByGeneralization()
64 {
65 	return add_by_generalization;
66 }
67 
setAddedByCopy(bool value)68 void TableObject::setAddedByCopy(bool value)
69 {
70 	add_by_copy=value;
71 	add_by_generalization=false;
72 	add_by_linking=false;
73 }
74 
isAddedByCopy()75 bool TableObject::isAddedByCopy()
76 {
77 	return add_by_copy;
78 }
79 
isAddedByRelationship()80 bool TableObject::isAddedByRelationship()
81 {
82 	return (add_by_linking || add_by_generalization || add_by_copy);
83 }
84 
isDeclaredInTable()85 bool  TableObject::isDeclaredInTable()
86 {
87 	return decl_in_table;
88 }
89 
isTableObject(ObjectType type)90 bool TableObject::isTableObject(ObjectType type)
91 {
92 	return (type==ObjectType::Column || type==ObjectType::Constraint || type==ObjectType::Trigger ||
93 			 type==ObjectType::Rule || type==ObjectType::Index || type==ObjectType::Policy);
94 }
95 
operator =(TableObject & object)96 void TableObject::operator = (TableObject &object)
97 {
98 	*(dynamic_cast<BaseObject *>(this))=dynamic_cast<BaseObject &>(object);
99 	this->parent_table=object.parent_table;
100 	this->add_by_copy=false;
101 	this->add_by_generalization=false;
102 	this->add_by_linking=false;
103 	this->decl_in_table=object.decl_in_table;
104 }
105 
setCodeInvalidated(bool value)106 void TableObject::setCodeInvalidated(bool value)
107 {
108 	if(parent_table)
109 		parent_table->BaseObject::setCodeInvalidated(value);
110 
111 	BaseObject::setCodeInvalidated(value);
112 }
113 
getDropDefinition(bool cascade)114 QString TableObject::getDropDefinition(bool cascade)
115 {
116 	if(getParentTable())
117 		attributes[Attributes::Table]=getParentTable()->getName(true);
118 
119 	attributes[this->getSchemaName()]=Attributes::True;
120 
121 	return BaseObject::getDropDefinition(cascade);
122 }
123 
getSignature(bool format)124 QString TableObject::getSignature(bool format)
125 {
126 	if(!parent_table)
127 		return BaseObject::getSignature(format);
128 
129 	return QString("%1.%2").arg(parent_table->getSignature(format)).arg(this->getName(format));
130 }
131