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 "typeattribute.h"
20 
TypeAttribute()21 TypeAttribute::TypeAttribute()
22 {
23 	obj_type=ObjectType::TypeAttribute;
24 }
25 
TypeAttribute(const TypeAttribute & type_attr)26 TypeAttribute::TypeAttribute(const TypeAttribute &type_attr) : TypeAttribute()
27 {
28     type = type_attr.type;
29     obj_name = type_attr.obj_name;
30     collation = type_attr.collation;
31 }
32 
setType(PgSqlType type)33 void TypeAttribute::setType(PgSqlType type)
34 {
35 	setCodeInvalidated(this->type != type);
36 	this->type=type;
37 }
38 
getType()39 PgSqlType TypeAttribute::getType()
40 {
41 	return type;
42 }
43 
getCodeDefinition(unsigned def_type)44 QString TypeAttribute::getCodeDefinition(unsigned def_type)
45 {
46 	QString code_def=getCachedCode(def_type, false);
47 	if(!code_def.isEmpty()) return code_def;
48 
49 	if(def_type==SchemaParser::SqlDefinition)
50 		attributes[Attributes::Name]=BaseObject::formatName(obj_name);
51 	else
52 		attributes[Attributes::Name]=obj_name;
53 
54 	attributes[Attributes::Type]=type.getCodeDefinition(def_type);
55 
56 	if(collation)
57 	{
58 		if(def_type==SchemaParser::SqlDefinition)
59 			attributes[Attributes::Collation]=collation->getName(true);
60 		else
61 			attributes[Attributes::Collation]=collation->getCodeDefinition(def_type, true);
62 	}
63 
64 	return BaseObject::__getCodeDefinition(def_type);
65 }
66 
operator =(const TypeAttribute & tpattrib)67 void TypeAttribute::operator = (const TypeAttribute &tpattrib)
68 {
69     this->obj_name = tpattrib.obj_name;
70     this->type = tpattrib.type;
71     this->collation = tpattrib.collation;
72 }
73