~ubuntu-branches/ubuntu/intrepid/kdesdk/intrepid-updates

« back to all changes in this revision

Viewing changes to umbrello/umbrello/dialogs/umlentityattributedialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-05-28 10:11:43 UTC
  • mto: This revision was merged to the branch mainline in revision 37.
  • Revision ID: james.westby@ubuntu.com-20080528101143-gzc3styjz1b70zxu
Tags: upstream-4.0.80
ImportĀ upstreamĀ versionĀ 4.0.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *   the Free Software Foundation; either version 2 of the License, or     *
6
6
 *   (at your option) any later version.                                   *
7
7
 *                                                                         *
8
 
 *  copyright (C) 2002-2007                                                *
 
8
 *  copyright (C) 2002-2008                                                *
9
9
 *  Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                   *
10
10
 ***************************************************************************/
11
11
 
13
13
#include "umlentityattributedialog.h"
14
14
 
15
15
// qt includes
16
 
#include <qlayout.h>
17
 
#include <qlineedit.h>
18
 
#include <qcheckbox.h>
19
 
#include <qgroupbox.h>
20
 
#include <qbuttongroup.h>
21
 
#include <qradiobutton.h>
22
 
#include <qlabel.h>
 
16
#include <QtGui/QLayout>
 
17
#include <QtGui/QCheckBox>
 
18
#include <q3groupbox.h>
 
19
#include <q3buttongroup.h>
 
20
#include <QtGui/QRadioButton>
 
21
#include <QtGui/QLabel>
 
22
#include <QtGui/QVBoxLayout>
 
23
#include <QtGui/QHBoxLayout>
 
24
#include <QtGui/QGridLayout>
 
25
#include <QtGui/QApplication>
23
26
 
24
27
// kde includes
 
28
#include <klineedit.h>
25
29
#include <kcombobox.h>
26
30
#include <kcompletion.h>
27
31
#include <klocale.h>
28
32
#include <kmessagebox.h>
29
 
#include <kapplication.h>
30
33
#include <kdebug.h>
31
34
 
32
35
// app includes
39
42
#include "../object_factory.h"
40
43
#include "../umlclassifierlist.h"
41
44
 
 
45
 
42
46
UMLEntityAttributeDialog::UMLEntityAttributeDialog( QWidget * pParent, UMLEntityAttribute * pEntityAttribute )
43
 
        : KDialogBase( Plain, i18n("Entity Attribute Properties"), Help | Ok | Cancel , Ok, pParent, "_UMLENTITYATTRIBUTEDLG_", true, true) {
 
47
        : KDialog( pParent)
 
48
{
 
49
    setCaption( i18n("Entity Attribute Properties") );
 
50
    setButtons( Help | Ok | Cancel );
 
51
    setDefaultButton(  Ok );
 
52
    setModal( true );
 
53
    showButtonSeparator( true );
44
54
    m_pEntityAttribute = pEntityAttribute;
45
55
    setupDialog();
46
 
}
47
 
 
48
 
UMLEntityAttributeDialog::~UMLEntityAttributeDialog() {}
49
 
 
50
 
void UMLEntityAttributeDialog::setupDialog() {
 
56
    connect(this,SIGNAL(okClicked()),this,SLOT(slotOk()));
 
57
    connect(this,SIGNAL(applyClicked()),this,SLOT(slotApply()));
 
58
}
 
59
 
 
60
UMLEntityAttributeDialog::~UMLEntityAttributeDialog()
 
61
{
 
62
}
 
63
 
 
64
void UMLEntityAttributeDialog::setupDialog()
 
65
{
51
66
    UMLDoc * pDoc = UMLApp::app()->getDocument();
52
67
    int margin = fontMetrics().height();
53
 
 
54
 
    QVBoxLayout * mainLayout = new QVBoxLayout( plainPage() );
55
 
 
56
 
    m_pValuesGB = new QGroupBox(i18n("General Properties"), plainPage() );
57
 
    QGridLayout * valuesLayout = new QGridLayout(m_pValuesGB, 5, 2);
 
68
    QFrame *frame = new QFrame( this );
 
69
    setMainWidget( frame );
 
70
    QVBoxLayout * mainLayout = new QVBoxLayout( frame );
 
71
 
 
72
    m_pValuesGB = new Q3GroupBox(i18n("General Properties"), frame );
 
73
    QGridLayout * valuesLayout = new QGridLayout(m_pValuesGB);
58
74
    valuesLayout -> setMargin(margin);
59
75
    valuesLayout -> setSpacing(10);
60
76
 
66
82
    m_pTypeL->setBuddy(m_pTypeCB);
67
83
 
68
84
    Dialog_Utils::makeLabeledEditField( m_pValuesGB, valuesLayout, 1,
69
 
                                    m_pNameL, i18n("&Name:"),
 
85
                                    m_pNameL, i18nc("name of entity attribute", "&Name:"),
70
86
                                    m_pNameLE, m_pEntityAttribute->getName() );
71
87
 
72
88
    Dialog_Utils::makeLabeledEditField( m_pValuesGB, valuesLayout, 2,
89
105
    m_pNullCB->setChecked( m_pEntityAttribute->getNull() );
90
106
    valuesLayout->addWidget(m_pNullCB, 6, 0);
91
107
 
 
108
    // enable/disable isNull depending on the state of Auto Increment Check Box
 
109
    slotAutoIncrementStateChanged( m_pAutoIncrementCB->isChecked() );
 
110
 
92
111
    m_pAttributesL = new QLabel(i18n("Attributes:"), m_pValuesGB);
93
112
    valuesLayout->addWidget(m_pAttributesL, 7, 0);
94
113
 
105
124
 
106
125
    mainLayout -> addWidget(m_pValuesGB);
107
126
 
108
 
    m_pScopeBG = new QButtonGroup(i18n("Indexing"), plainPage() );
 
127
    m_pScopeBG = new Q3ButtonGroup(i18n("Indexing"), frame );
109
128
    QHBoxLayout* scopeLayout = new QHBoxLayout(m_pScopeBG);
110
129
    scopeLayout->setMargin(margin);
111
130
 
112
 
    m_pNoneRB = new QRadioButton(i18n("&None"), m_pScopeBG);
 
131
    m_pNoneRB = new QRadioButton(i18n("&Not Indexed"), m_pScopeBG);
113
132
    scopeLayout->addWidget(m_pNoneRB);
114
133
 
 
134
    /*
115
135
    m_pPublicRB = new QRadioButton(i18n("&Primary"), m_pScopeBG);
116
136
    scopeLayout->addWidget(m_pPublicRB);
117
137
 
118
 
    m_pPrivateRB = new QRadioButton(i18n("&Index"), m_pScopeBG);
119
 
    scopeLayout->addWidget(m_pPrivateRB);
120
 
 
121
138
    m_pProtectedRB = new QRadioButton(i18n("&Unique"), m_pScopeBG);
122
139
    scopeLayout->addWidget(m_pProtectedRB);
 
140
    */
 
141
 
 
142
    m_pPrivateRB = new QRadioButton(i18n("&Indexed"), m_pScopeBG);
 
143
    scopeLayout->addWidget(m_pPrivateRB);
123
144
 
124
145
    mainLayout->addWidget(m_pScopeBG);
125
146
    Uml::DBIndex_Type scope = m_pEntityAttribute->getIndexType();
 
147
 
 
148
    /*
126
149
    if ( scope == Uml::Primary )
127
150
        m_pPublicRB->setChecked( true );
128
 
    else if( scope == Uml::Index )
129
 
        m_pPrivateRB -> setChecked( true );
130
151
    else if( scope == Uml::Unique )
131
152
        m_pProtectedRB -> setChecked( true );
 
153
    else */
 
154
 
 
155
    if( scope == Uml::Index )
 
156
        m_pPrivateRB->setChecked( true );
132
157
    else {
133
158
        m_pNoneRB->setChecked(true);
134
159
    }
140
165
    UMLClassifierList dataTypes = pDoc->getDatatypes();
141
166
    if (dataTypes.count() == 0) {
142
167
        // Switch to SQL as the active language if no datatypes are set.
143
 
        UMLApp::app()->setActiveLanguage("SQL");
 
168
        UMLApp::app()->setActiveLanguage(Uml::pl_SQL);
144
169
        pDoc->addDefaultDatatypes();
145
 
        kapp->processEvents();
 
170
        qApp->processEvents();
146
171
        dataTypes = pDoc->getDatatypes();
147
172
    }
148
 
    UMLClassifier *dat;
149
 
    for (UMLClassifierListIt dit(dataTypes); (dat = dit.current()) != NULL; ++dit) {
 
173
    foreach (UMLClassifier* dat, dataTypes ) {
150
174
        insertType(dat->getName());
151
175
    }
152
176
 
154
178
    int typeBoxCount = 0;
155
179
    bool foundType = false;
156
180
    while (typeBoxCount < m_pTypeCB->count() && foundType == false) {
157
 
        QString typeBoxString = m_pTypeCB->text(typeBoxCount);
 
181
        QString typeBoxString = m_pTypeCB->itemText(typeBoxCount);
158
182
        if ( typeBoxString == m_pEntityAttribute->getTypeName() ) {
159
183
            foundType = true;
160
 
            m_pTypeCB->setCurrentItem(typeBoxCount);
 
184
            m_pTypeCB->setCurrentIndex(typeBoxCount);
161
185
        } else {
162
186
            typeBoxCount++;
163
187
        }
165
189
 
166
190
    if (!foundType) {
167
191
        insertType( m_pEntityAttribute->getTypeName(), 0 );
168
 
        m_pTypeCB->setCurrentItem(0);
 
192
        m_pTypeCB->setCurrentIndex(0);
169
193
    }
170
194
 
171
195
    m_pNameLE->setFocus();
172
196
    connect( m_pNameLE, SIGNAL( textChanged ( const QString & ) ), SLOT( slotNameChanged( const QString & ) ) );
 
197
    connect( m_pAutoIncrementCB, SIGNAL( clicked( bool ) ), this, SLOT( slotAutoIncrementStateChanged( bool) ) );
173
198
    slotNameChanged(m_pNameLE->text() );
174
199
}
175
200
 
176
201
void UMLEntityAttributeDialog::slotNameChanged( const QString &_text )
177
202
{
178
 
    enableButtonOK( !_text.isEmpty() );
 
203
    enableButtonOk( !_text.isEmpty() );
179
204
}
180
205
 
181
 
bool UMLEntityAttributeDialog::apply() {
 
206
bool UMLEntityAttributeDialog::apply()
 
207
{
182
208
    QString name = m_pNameLE->text();
183
209
    if (name.isEmpty()) {
184
210
        KMessageBox::error(this, i18n("You have entered an invalid entity attribute name."),
202
228
    m_pEntityAttribute->setAutoIncrement( m_pAutoIncrementCB->isChecked() );
203
229
    m_pEntityAttribute->setNull( m_pNullCB->isChecked() );
204
230
 
 
231
    /*
205
232
    if ( m_pPublicRB->isChecked() ) {
206
233
        m_pEntityAttribute->setIndexType(Uml::Primary);
207
 
    } else if ( m_pPrivateRB -> isChecked() ) {
208
 
        m_pEntityAttribute->setIndexType(Uml::Index);
209
234
    } else if ( m_pProtectedRB -> isChecked() ) {
210
235
        m_pEntityAttribute->setIndexType(Uml::Unique);
 
236
    } else
 
237
    */
 
238
 
 
239
    if ( m_pPrivateRB -> isChecked() ) {
 
240
        m_pEntityAttribute->setIndexType(Uml::Index);
211
241
    } else {
212
242
        m_pEntityAttribute->setIndexType(Uml::None);
213
243
    }
215
245
    QString typeName = m_pTypeCB->currentText();
216
246
    UMLDoc *pDoc = UMLApp::app()->getDocument();
217
247
    UMLClassifierList dataTypes = pDoc->getDatatypes();
218
 
    UMLClassifier *dat;
219
 
    for (UMLClassifierListIt dit(dataTypes); (dat = dit.current()) != NULL; ++dit) {
 
248
    foreach (UMLClassifier* dat, dataTypes ) {
220
249
        if (typeName == dat->getName()) {
221
250
            m_pEntityAttribute->setType(dat);
222
251
            return true;
238
267
    return true;
239
268
}
240
269
 
241
 
void UMLEntityAttributeDialog::slotApply() {
 
270
void UMLEntityAttributeDialog::slotApply()
 
271
{
242
272
    apply();
243
273
}
244
274
 
245
 
void UMLEntityAttributeDialog::slotOk() {
 
275
void UMLEntityAttributeDialog::slotOk()
 
276
{
246
277
    if ( apply() ) {
247
278
        accept();
248
279
    }
249
280
}
250
281
 
251
 
void UMLEntityAttributeDialog::insertType( const QString& type, int index ) {
252
 
    m_pTypeCB->insertItem( type, index );
 
282
void UMLEntityAttributeDialog::insertType( const QString& type, int index )
 
283
{
 
284
    m_pTypeCB->insertItem( index, type );
253
285
    m_pTypeCB->completionObject()->addItem( type );
254
286
}
255
287
 
256
 
void UMLEntityAttributeDialog::insertAttribute( const QString& type, int index ) {
257
 
    m_pAttributesCB->insertItem( type, index );
 
288
void UMLEntityAttributeDialog::insertAttribute( const QString& type, int index )
 
289
{
 
290
    m_pAttributesCB->insertItem( index, type );
258
291
    m_pAttributesCB->completionObject()->addItem( type );
259
292
}
260
293
 
261
294
 
 
295
void UMLEntityAttributeDialog::slotAutoIncrementStateChanged(bool checked)
 
296
{
 
297
    if ( checked == true ) {
 
298
        m_pNullCB->setChecked( false );
 
299
        m_pNullCB->setEnabled( false );
 
300
    } else if ( checked == false ) {
 
301
        m_pNullCB->setEnabled( true );
 
302
    }
 
303
 
 
304
}
 
305
 
 
306
 
262
307
#include "umlentityattributedialog.moc"