summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/template.cpp
blob: f02f442661b1e397e282f0083e9179d5f70ba15b (plain)
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
/***************************************************************************
 *                                                                         *
 *   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; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   copyright (C) 2003-2006                                               *
 *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
 ***************************************************************************/

// own header
#include "template.h"

// qt/kde includes
#include <tqregexp.h>
#include <kdebug.h>

// app includes
#include "uml.h"
#include "umldoc.h"
#include "dialogs/umltemplatedialog.h"

UMLTemplate::UMLTemplate(const UMLObject *parent, const TQString& name,
                         Uml::IDType id, const TQString& type)
        : UMLClassifierListItem( parent, name, id ) {
    setTypeName( type );
    m_BaseType = Uml::ot_Template;
}

UMLTemplate::UMLTemplate(const UMLObject *parent)
        : UMLClassifierListItem( parent ) {
    m_BaseType = Uml::ot_Template;
}

UMLTemplate::~UMLTemplate() {}

TQString UMLTemplate::toString(Uml::Signature_Type /*sig = st_NoSig*/) {
    if (m_pSecondary == NULL || m_pSecondary->getName() == "class") {
        return getName();
    } else {
        return getName() + " : " + m_pSecondary->getName();
    }
}

TQString UMLTemplate::getTypeName() {
    if (m_pSecondary == NULL)
        return "class";
    return m_pSecondary->getName();
}

bool UMLTemplate::operator==(UMLTemplate &rhs) {
    if (this == &rhs) {
        return true;
    }
    if ( !UMLObject::operator==( rhs ) ) {
        return false;
    }
    if (m_pSecondary != rhs.m_pSecondary) {
        return false;
    }
    return true;
}

void UMLTemplate::copyInto(UMLTemplate *rhs) const
{
    UMLClassifierListItem::copyInto(rhs);
}

UMLObject* UMLTemplate::clone() const
{
    UMLTemplate *clone = new UMLTemplate( (UMLTemplate*) parent());
    copyInto(clone);

    return clone;
}


void UMLTemplate::saveToXMI(TQDomDocument& qDoc, TQDomElement& qElement) {
    //FIXME: uml13.dtd compliance
    TQDomElement attributeElement = UMLObject::save("UML:TemplateParameter", qDoc);
    if (m_pSecondary)
        attributeElement.setAttribute("type", ID2STR(m_pSecondary->getID()));
    qElement.appendChild(attributeElement);
}

bool UMLTemplate::load(TQDomElement& element) {
    m_SecondaryId = element.attribute("type", "");
    return true;
}

bool UMLTemplate::showPropertiesDialog(TQWidget* parent) {
    UMLTemplateDialog dialog(parent, this);
    return dialog.exec();
}