summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/dialogs/classwizard.cpp
blob: 8b38c47d31d244d6c73dd13e687407e030c25957 (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
96
97
98
99
100
101
102
103
104
105
106
107
/***************************************************************************
 *                                                                         *
 *   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) 2002-2006                                               *
 *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
 ***************************************************************************/

// own header
#include "classwizard.h"

// system includes
#include <khelpmenu.h>
#include <tdelocale.h>

// local includes
#include "classifierlistpage.h"
#include "../uml.h"
#include "../umldoc.h"
#include "../classifier.h"
#include "../attribute.h"
#include "../operation.h"
#include "../umlclassifierlistitemlist.h"
#include "../classifierlistitem.h"

ClassWizard::ClassWizard( UMLDoc * pDoc ) : KWizard( (TQWidget*)pDoc -> parent(), "_CLASSWIZARD_", true) {
    m_pDoc = pDoc;
    //create a unique class to start with
    UMLObject * pTemp = 0;
    TQString name = i18n("new_class");
    TQString newName = name;
    TQString num = "";
    int i = 0;
    m_pClass = new UMLClassifier( newName );
    do {
        m_pClass -> setName( newName );
        pTemp = m_pDoc -> findUMLObject( newName );
        num.setNum( ++i);
        newName = name;
        newName.append("_").append( num );
    } while( pTemp );
    //setup pages
    setupPages();
}

ClassWizard::~ClassWizard() {}

void ClassWizard::setupPages() {
    //Setup General Page
    m_pGenPage = new ClassGenPage( m_pDoc, this, m_pClass );
    addPage( m_pGenPage, i18n("New Class") );
    setHelpEnabled(m_pGenPage, false);

    //Setup Attribute Page
    m_pAttPage = new ClassifierListPage(this, m_pClass, m_pDoc, Uml::ot_Attribute);
    addPage( m_pAttPage, i18n("Class Attributes") );

    //Setup Operation Page
    m_pOpPage = new ClassifierListPage(this, m_pClass, m_pDoc, Uml::ot_Operation);
    addPage( m_pOpPage, i18n("Class Operations") );
}

void ClassWizard::showPage( TQWidget * pWidget ) {
    TQWizard::showPage( pWidget );
    if( pWidget == m_pOpPage )
        finishButton() -> setEnabled( true );
}

void ClassWizard::next() {
    TQWidget * pWidget = currentPage();
    if( pWidget == m_pGenPage ) {
        m_pGenPage -> updateObject();
    } else if( pWidget == m_pAttPage ) {
        m_pAttPage -> updateObject();
    }
    TQWizard::next();
}

void ClassWizard::back() {
    TQWidget * pWidget = currentPage();
    if( pWidget == m_pAttPage ) {
        m_pAttPage -> updateObject();
    } else if( pWidget == m_pOpPage ) {
        m_pOpPage -> updateObject();
    }
    TQWizard::back();
}

void ClassWizard::accept() {
    m_pDoc -> addUMLObject( m_pClass );
    m_pDoc->signalUMLObjectCreated(m_pClass);

    TQWizard::accept();
}

void ClassWizard::reject() {
    delete m_pClass;
    TQWizard::reject();
}

void ClassWizard::help() {
    KHelpMenu helpMenu(this);
    helpMenu.appHelpActivated();
}