5
5
* the Free Software Foundation; either version 2 of the License, or *
6
6
* (at your option) any later version. *
8
* copyright (C) 2002-2007 *
8
* copyright (C) 2002-2008 *
9
9
* Umbrello UML Modeller Authors <uml-devel@uml.sf.net> *
10
10
***************************************************************************/
13
13
#include "umlentityattributedialog.h"
17
#include <qlineedit.h>
18
#include <qcheckbox.h>
19
#include <qgroupbox.h>
20
#include <qbuttongroup.h>
21
#include <qradiobutton.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>
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>
39
42
#include "../object_factory.h"
40
43
#include "../umlclassifierlist.h"
42
46
UMLEntityAttributeDialog::UMLEntityAttributeDialog( QWidget * pParent, UMLEntityAttribute * pEntityAttribute )
43
: KDialogBase( Plain, i18n("Entity Attribute Properties"), Help | Ok | Cancel , Ok, pParent, "_UMLENTITYATTRIBUTEDLG_", true, true) {
49
setCaption( i18n("Entity Attribute Properties") );
50
setButtons( Help | Ok | Cancel );
51
setDefaultButton( Ok );
53
showButtonSeparator( true );
44
54
m_pEntityAttribute = pEntityAttribute;
48
UMLEntityAttributeDialog::~UMLEntityAttributeDialog() {}
50
void UMLEntityAttributeDialog::setupDialog() {
56
connect(this,SIGNAL(okClicked()),this,SLOT(slotOk()));
57
connect(this,SIGNAL(applyClicked()),this,SLOT(slotApply()));
60
UMLEntityAttributeDialog::~UMLEntityAttributeDialog()
64
void UMLEntityAttributeDialog::setupDialog()
51
66
UMLDoc * pDoc = UMLApp::app()->getDocument();
52
67
int margin = fontMetrics().height();
54
QVBoxLayout * mainLayout = new QVBoxLayout( plainPage() );
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 );
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);
66
82
m_pTypeL->setBuddy(m_pTypeCB);
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() );
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);
108
// enable/disable isNull depending on the state of Auto Increment Check Box
109
slotAutoIncrementStateChanged( m_pAutoIncrementCB->isChecked() );
92
111
m_pAttributesL = new QLabel(i18n("Attributes:"), m_pValuesGB);
93
112
valuesLayout->addWidget(m_pAttributesL, 7, 0);
106
125
mainLayout -> addWidget(m_pValuesGB);
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);
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);
115
135
m_pPublicRB = new QRadioButton(i18n("&Primary"), m_pScopeBG);
116
136
scopeLayout->addWidget(m_pPublicRB);
118
m_pPrivateRB = new QRadioButton(i18n("&Index"), m_pScopeBG);
119
scopeLayout->addWidget(m_pPrivateRB);
121
138
m_pProtectedRB = new QRadioButton(i18n("&Unique"), m_pScopeBG);
122
139
scopeLayout->addWidget(m_pProtectedRB);
142
m_pPrivateRB = new QRadioButton(i18n("&Indexed"), m_pScopeBG);
143
scopeLayout->addWidget(m_pPrivateRB);
124
145
mainLayout->addWidget(m_pScopeBG);
125
146
Uml::DBIndex_Type scope = m_pEntityAttribute->getIndexType();
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 );
155
if( scope == Uml::Index )
156
m_pPrivateRB->setChecked( true );
133
158
m_pNoneRB->setChecked(true);
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();
149
for (UMLClassifierListIt dit(dataTypes); (dat = dit.current()) != NULL; ++dit) {
173
foreach (UMLClassifier* dat, dataTypes ) {
150
174
insertType(dat->getName());
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);
166
190
if (!foundType) {
167
191
insertType( m_pEntityAttribute->getTypeName(), 0 );
168
m_pTypeCB->setCurrentItem(0);
192
m_pTypeCB->setCurrentIndex(0);
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() );
176
201
void UMLEntityAttributeDialog::slotNameChanged( const QString &_text )
178
enableButtonOK( !_text.isEmpty() );
203
enableButtonOk( !_text.isEmpty() );
181
bool UMLEntityAttributeDialog::apply() {
206
bool UMLEntityAttributeDialog::apply()
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() );
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);
239
if ( m_pPrivateRB -> isChecked() ) {
240
m_pEntityAttribute->setIndexType(Uml::Index);
212
242
m_pEntityAttribute->setIndexType(Uml::None);
215
245
QString typeName = m_pTypeCB->currentText();
216
246
UMLDoc *pDoc = UMLApp::app()->getDocument();
217
247
UMLClassifierList dataTypes = pDoc->getDatatypes();
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);
241
void UMLEntityAttributeDialog::slotApply() {
270
void UMLEntityAttributeDialog::slotApply()
245
void UMLEntityAttributeDialog::slotOk() {
275
void UMLEntityAttributeDialog::slotOk()
251
void UMLEntityAttributeDialog::insertType( const QString& type, int index ) {
252
m_pTypeCB->insertItem( type, index );
282
void UMLEntityAttributeDialog::insertType( const QString& type, int index )
284
m_pTypeCB->insertItem( index, type );
253
285
m_pTypeCB->completionObject()->addItem( type );
256
void UMLEntityAttributeDialog::insertAttribute( const QString& type, int index ) {
257
m_pAttributesCB->insertItem( type, index );
288
void UMLEntityAttributeDialog::insertAttribute( const QString& type, int index )
290
m_pAttributesCB->insertItem( index, type );
258
291
m_pAttributesCB->completionObject()->addItem( type );
295
void UMLEntityAttributeDialog::slotAutoIncrementStateChanged(bool checked)
297
if ( checked == true ) {
298
m_pNullCB->setChecked( false );
299
m_pNullCB->setEnabled( false );
300
} else if ( checked == false ) {
301
m_pNullCB->setEnabled( true );
262
307
#include "umlentityattributedialog.moc"