• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

umbrello/umbrello

  • sources
  • kde-4.12
  • kdesdk
  • umbrello
  • umbrello
  • dialogs
umlentityattributedialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * This program is free software; you can redistribute it and/or modify *
3  * it under the terms of the GNU General Public License as published by *
4  * the Free Software Foundation; either version 2 of the License, or *
5  * (at your option) any later version. *
6  * *
7  * copyright (C) 2002-2013 *
8  * Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
9  ***************************************************************************/
10 
11 // own header
12 #include "umlentityattributedialog.h"
13 
14 // app includes
15 #include "entityattribute.h"
16 #include "classifier.h"
17 #include "umldoc.h"
18 #include "uml.h"
19 #include "codegenerator.h"
20 #include "dialog_utils.h"
21 #include "object_factory.h"
22 #include "umlclassifierlist.h"
23 
24 // kde includes
25 #include <klineedit.h>
26 #include <kcombobox.h>
27 #include <kcompletion.h>
28 #include <klocale.h>
29 #include <kmessagebox.h>
30 
31 // qt includes
32 #include <QApplication>
33 #include <QCheckBox>
34 #include <QGridLayout>
35 #include <QGroupBox>
36 #include <QHBoxLayout>
37 #include <QLabel>
38 #include <QLayout>
39 #include <QRadioButton>
40 #include <QVBoxLayout>
41 
42 UMLEntityAttributeDialog::UMLEntityAttributeDialog(QWidget * pParent, UMLEntityAttribute * pEntityAttribute)
43  : KDialog(pParent)
44 {
45  setCaption(i18n("Entity Attribute Properties"));
46  setButtons(Help | Ok | Cancel);
47  setDefaultButton(Ok);
48  setModal(true);
49  showButtonSeparator(true);
50  m_pEntityAttribute = pEntityAttribute;
51  setupDialog();
52  connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
53  connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply()));
54 }
55 
56 UMLEntityAttributeDialog::~UMLEntityAttributeDialog()
57 {
58 }
59 
63 void UMLEntityAttributeDialog::setupDialog()
64 {
65  int margin = fontMetrics().height();
66  QFrame *frame = new QFrame(this);
67  setMainWidget(frame);
68  QVBoxLayout * mainLayout = new QVBoxLayout(frame);
69 
70  m_pValuesGB = new QGroupBox(i18n("General Properties"), frame);
71  QGridLayout * valuesLayout = new QGridLayout(m_pValuesGB);
72  valuesLayout->setMargin(margin);
73  valuesLayout->setSpacing(10);
74 
75  m_pTypeL = new QLabel(i18n("&Type:"), m_pValuesGB);
76  valuesLayout->addWidget(m_pTypeL, 0, 0);
77 
78  m_pTypeCB = new KComboBox(true, m_pValuesGB);
79  valuesLayout->addWidget(m_pTypeCB, 0, 1);
80  m_pTypeL->setBuddy(m_pTypeCB);
81 
82  Dialog_Utils::makeLabeledEditField(m_pValuesGB, valuesLayout, 1,
83  m_pNameL, i18nc("name of entity attribute", "&Name:"),
84  m_pNameLE, m_pEntityAttribute->name());
85 
86  Dialog_Utils::makeLabeledEditField(m_pValuesGB, valuesLayout, 2,
87  m_pInitialL, i18n("&Default value:"),
88  m_pInitialLE, m_pEntityAttribute->getInitialValue());
89 
90  Dialog_Utils::makeLabeledEditField(m_pValuesGB, valuesLayout, 3,
91  m_pStereoTypeL, i18n("Stereotype name:"),
92  m_pStereoTypeLE, m_pEntityAttribute->stereotype());
93 
94  Dialog_Utils::makeLabeledEditField(m_pValuesGB, valuesLayout, 4,
95  m_pValuesL, i18n("Length/Values:"),
96  m_pValuesLE, m_pEntityAttribute->getValues());
97 
98  m_pAutoIncrementCB = new QCheckBox(i18n("&Auto increment"), m_pValuesGB);
99  m_pAutoIncrementCB->setChecked(m_pEntityAttribute->getAutoIncrement());
100  valuesLayout->addWidget(m_pAutoIncrementCB, 5, 0);
101 
102  m_pNullCB = new QCheckBox(i18n("Allow &null"), m_pValuesGB);
103  m_pNullCB->setChecked(m_pEntityAttribute->getNull());
104  valuesLayout->addWidget(m_pNullCB, 6, 0);
105 
106  // enable/disable isNull depending on the state of Auto Increment Check Box
107  slotAutoIncrementStateChanged(m_pAutoIncrementCB->isChecked());
108 
109  m_pAttributesL = new QLabel(i18n("Attributes:"), m_pValuesGB);
110  valuesLayout->addWidget(m_pAttributesL, 7, 0);
111 
112  m_pAttributesCB = new KComboBox(true, m_pValuesGB);
113  m_pAttributesCB->setCompletionMode(KGlobalSettings::CompletionPopup);
114  valuesLayout->addWidget(m_pAttributesCB, 7, 1);
115  m_pTypeL->setBuddy(m_pAttributesCB);
116 
117  insertAttribute(m_pEntityAttribute->getAttributes());
118  insertAttribute("binary", m_pAttributesCB->count());
119  insertAttribute("unsigned", m_pAttributesCB->count());
120  insertAttribute("unsigned zerofill", m_pAttributesCB->count());
121 
122  mainLayout->addWidget(m_pValuesGB);
123 
124  m_pScopeGB = new QGroupBox(i18n("Indexing"), frame);
125  QHBoxLayout* scopeLayout = new QHBoxLayout(m_pScopeGB);
126  scopeLayout->setMargin(margin);
127 
128  m_pNoneRB = new QRadioButton(i18n("&Not Indexed"), m_pScopeGB);
129  scopeLayout->addWidget(m_pNoneRB);
130 
131  /*
132  m_pPublicRB = new QRadioButton(i18n("&Primary"), m_pScopeGB);
133  scopeLayout->addWidget(m_pPublicRB);
134 
135  m_pProtectedRB = new QRadioButton(i18n("&Unique"), m_pScopeGB);
136  scopeLayout->addWidget(m_pProtectedRB);
137  */
138 
139  m_pPrivateRB = new QRadioButton(i18n("&Indexed"), m_pScopeGB);
140  scopeLayout->addWidget(m_pPrivateRB);
141 
142  mainLayout->addWidget(m_pScopeGB);
143  UMLEntityAttribute::DBIndex_Type scope = m_pEntityAttribute->indexType();
144 
145  /*
146  if (scope == UMLEntityAttribute::Primary)
147  m_pPublicRB->setChecked(true);
148  else if(scope == UMLEntityAttribute::Unique)
149  m_pProtectedRB->setChecked(true);
150  else */
151 
152  if (scope == UMLEntityAttribute::Index)
153  m_pPrivateRB->setChecked(true);
154  else {
155  m_pNoneRB->setChecked(true);
156  }
157 
158  m_pTypeCB->setDuplicatesEnabled(false); // only allow one of each type in box
159  m_pTypeCB->setCompletionMode(KGlobalSettings::CompletionPopup);
160  insertTypesSorted(m_pEntityAttribute->getTypeName());
161 
162  m_pNameLE->setFocus();
163  connect(m_pNameLE, SIGNAL(textChanged(QString)), SLOT(slotNameChanged(QString)));
164  connect(m_pAutoIncrementCB, SIGNAL(clicked(bool)), this, SLOT(slotAutoIncrementStateChanged(bool)));
165  slotNameChanged(m_pNameLE->text());
166 }
167 
168 void UMLEntityAttributeDialog::slotNameChanged(const QString &_text)
169 {
170  enableButtonOk(!_text.isEmpty());
171 }
172 
177 bool UMLEntityAttributeDialog::apply()
178 {
179  QString name = m_pNameLE->text();
180  if (name.isEmpty()) {
181  KMessageBox::error(this, i18n("You have entered an invalid entity attribute name."),
182  i18n("Entity Attribute Name Invalid"), 0);
183  m_pNameLE->setText(m_pEntityAttribute->name());
184  return false;
185  }
186  UMLClassifier * pConcept = dynamic_cast<UMLClassifier *>(m_pEntityAttribute->parent());
187  UMLObject *o = pConcept->findChildObject(name);
188  if (o && o != m_pEntityAttribute) {
189  KMessageBox::error(this, i18n("The entity attribute name you have chosen is already being used in this operation."),
190  i18n("Entity Attribute Name Not Unique"), 0);
191  m_pNameLE->setText(m_pEntityAttribute->name());
192  return false;
193  }
194  m_pEntityAttribute->setName(name);
195  m_pEntityAttribute->setInitialValue(m_pInitialLE->text());
196  m_pEntityAttribute->setStereotype(m_pStereoTypeLE->text());
197  m_pEntityAttribute->setValues(m_pValuesLE->text());
198  m_pEntityAttribute->setAttributes(m_pAttributesCB->currentText());
199  m_pEntityAttribute->setAutoIncrement(m_pAutoIncrementCB->isChecked());
200  m_pEntityAttribute->setNull(m_pNullCB->isChecked());
201 
202  /*
203  if (m_pPublicRB->isChecked()) {
204  m_pEntityAttribute->setIndexType(UMLEntityAttribute::Primary);
205  } else if (m_pProtectedRB->isChecked()) {
206  m_pEntityAttribute->setIndexType(UMLEntityAttribute::Unique);
207  } else
208  */
209 
210  if (m_pPrivateRB->isChecked()) {
211  m_pEntityAttribute->setIndexType(UMLEntityAttribute::Index);
212  } else {
213  m_pEntityAttribute->setIndexType(UMLEntityAttribute::None);
214  }
215 
216  QString typeName = m_pTypeCB->currentText();
217  UMLDoc *pDoc = UMLApp::app()->document();
218  UMLClassifierList dataTypes = pDoc->datatypes();
219  foreach (UMLClassifier* dat, dataTypes) {
220  if (typeName == dat->name()) {
221  m_pEntityAttribute->setType(dat);
222  return true;
223  }
224  }
225  UMLObject *obj = pDoc->findUMLObject(typeName);
226  UMLClassifier *classifier = dynamic_cast<UMLClassifier*>(obj);
227  if (classifier == NULL) {
228  // If it's obviously a pointer type (C++) then create a datatype.
229  // Else we don't know what it is so as a compromise create a class.
230  UMLObject::ObjectType ot =
231  (typeName.contains('*') ? UMLObject::ot_Datatype : UMLObject::ot_Class);
232  obj = Object_Factory::createUMLObject(ot, typeName);
233  if (obj == NULL)
234  return false;
235  classifier = static_cast<UMLClassifier*>(obj);
236  }
237  m_pEntityAttribute->setType(classifier);
238  return true;
239 }
240 
245 void UMLEntityAttributeDialog::slotApply()
246 {
247  apply();
248 }
249 
253 void UMLEntityAttributeDialog::slotOk()
254 {
255  if (apply()) {
256  accept();
257  }
258 }
259 
263 void UMLEntityAttributeDialog::insertTypesSorted(const QString& type)
264 {
265  QStringList types;
266  // add the data types
267  UMLDoc * pDoc = UMLApp::app()->document();
268  UMLClassifierList dataTypes = pDoc->datatypes();
269  if (dataTypes.count() == 0) {
270  // Switch to SQL as the active language if no datatypes are set.
271  UMLApp::app()->setActiveLanguage(Uml::ProgrammingLanguage::SQL);
272  pDoc->addDefaultDatatypes();
273  qApp->processEvents();
274  dataTypes = pDoc->datatypes();
275  }
276  foreach (UMLClassifier* dat, dataTypes) {
277  types << dat->name();
278  }
279  // add the given parameter
280  if (!types.contains(type)) {
281  types << type;
282  }
283  types.sort();
284 
285  m_pTypeCB->clear();
286  m_pTypeCB->insertItems(-1, types);
287 
288  // select the given parameter
289  int currentIndex = m_pTypeCB->findText(type);
290  if (currentIndex > -1) {
291  m_pTypeCB->setCurrentIndex(currentIndex);
292  }
293  m_pTypeCB->completionObject()->addItem(type);
294 }
295 
299 void UMLEntityAttributeDialog::insertAttribute(const QString& type, int index)
300 {
301  m_pAttributesCB->insertItem(index, type);
302  m_pAttributesCB->completionObject()->addItem(type);
303 }
304 
308 void UMLEntityAttributeDialog::slotAutoIncrementStateChanged(bool checked)
309 {
310  if (checked == true) {
311  m_pNullCB->setChecked(false);
312  m_pNullCB->setEnabled(false);
313  } else if (checked == false) {
314  m_pNullCB->setEnabled(true);
315  }
316 
317 }
318 
319 #include "umlentityattributedialog.moc"
object_factory.h
UMLEntityAttributeDialog::m_pTypeCB
KComboBox * m_pTypeCB
Definition: umlentityattributedialog.h:55
UMLEntityAttribute::Index
Definition: entityattribute.h:34
UMLEntityAttribute::setNull
void setNull(const bool null)
Sets the initial value of the UMLEntityAttribute's allow null value.
Definition: entityattribute.cpp:159
UMLDoc::addDefaultDatatypes
void addDefaultDatatypes()
Calls the active code generator to create its default datatypes.
Definition: umldoc.cpp:2920
dialog_utils.h
UMLEntityAttributeDialog::m_pNameL
QLabel * m_pNameL
Definition: umlentityattributedialog.h:54
UMLClassifier
This class defines the non-graphical information required for a UML Classifier (ie a class or interfa...
Definition: classifier.h:39
UMLEntityAttributeDialog::m_pEntityAttribute
UMLEntityAttribute * m_pEntityAttribute
The EntityAttribute to represent.
Definition: umlentityattributedialog.h:48
UMLEntityAttributeDialog::~UMLEntityAttributeDialog
~UMLEntityAttributeDialog()
Definition: umlentityattributedialog.cpp:56
UMLEntityAttributeDialog::slotApply
void slotApply()
I don't think this is used, but if we had an apply button it would slot into here.
Definition: umlentityattributedialog.cpp:245
umlentityattributedialog.h
UMLEntityAttributeDialog::m_pValuesL
QLabel * m_pValuesL
Definition: umlentityattributedialog.h:54
UMLEntityAttribute::getAttributes
QString getAttributes() const
Returns the value of the UMLEntityAttribute's attributes property.
Definition: entityattribute.cpp:78
UMLEntityAttribute::setValues
void setValues(const QString &values)
Sets the UMLEntityAttribute's length/values property.
Definition: entityattribute.cpp:105
UMLAttribute::getInitialValue
QString getInitialValue() const
Returns The initial value of the UMLAttribute.
Definition: attribute.cpp:98
UMLEntityAttribute::None
Definition: entityattribute.h:32
UMLClassifierListItem::setType
virtual void setType(UMLObject *type)
Sets the type of the UMLAttribute.
Definition: classifierlistitem.cpp:125
UMLEntityAttribute::indexType
DBIndex_Type indexType() const
Returns the UMLEntityAttribute's index type property.
Definition: entityattribute.cpp:132
UMLEntityAttributeDialog::m_pAttributesCB
KComboBox * m_pAttributesCB
Definition: umlentityattributedialog.h:56
entityattribute.h
UMLEntityAttributeDialog::m_pValuesGB
QGroupBox * m_pValuesGB
Definition: umlentityattributedialog.h:51
UMLEntityAttributeDialog::slotAutoIncrementStateChanged
void slotAutoIncrementStateChanged(bool checked)
Is activated when the auto increment state is changed.
Definition: umlentityattributedialog.cpp:308
QWidget
UMLApp::app
static UMLApp * app()
Get the last created instance of this class.
Definition: uml.cpp:206
UMLEntityAttribute::getValues
QString getValues() const
Returns the UMLEntityAttribute's length/values property.
Definition: entityattribute.cpp:96
UMLEntityAttributeDialog::m_pInitialLE
KLineEdit * m_pInitialLE
Definition: umlentityattributedialog.h:57
UMLEntityAttributeDialog::m_pAttributesL
QLabel * m_pAttributesL
Definition: umlentityattributedialog.h:54
UMLAttribute::setName
void setName(const QString &name)
Reimplementation of method from UMLObject is required as an extra signal, attributeChanged(), is emitted.
Definition: attribute.cpp:75
UMLEntityAttributeDialog::m_pNameLE
KLineEdit * m_pNameLE
Definition: umlentityattributedialog.h:57
UMLApp::setActiveLanguage
void setActiveLanguage(Uml::ProgrammingLanguage::Enum pl)
Set the language for which code will be generated.
Definition: uml.cpp:2344
KDialog
UMLEntityAttributeDialog::insertTypesSorted
void insertTypesSorted(const QString &type="")
Inserts type into the type-combobox as well as its completion object.
Definition: umlentityattributedialog.cpp:263
UMLEntityAttributeDialog::slotNameChanged
void slotNameChanged(const QString &)
Definition: umlentityattributedialog.cpp:168
classifier.h
UMLApp::document
UMLDoc * document() const
Returns a pointer to the current document connected to the KMainWindow instance.
Definition: uml.cpp:872
UMLObject
This class is the non-graphical version of UMLWidget.
Definition: umlobject.h:41
UMLEntityAttributeDialog::m_pInitialL
QLabel * m_pInitialL
Definition: umlentityattributedialog.h:54
Object_Factory::createUMLObject
UMLObject * createUMLObject(UMLObject::ObjectType type, const QString &n, UMLPackage *parentPkg, bool solicitNewName)
Creates a UMLObject of the given type.
Definition: object_factory.cpp:162
UMLEntityAttributeDialog::insertAttribute
void insertAttribute(const QString &type, int index=-1)
Inserts type into the type-combobox as well as its completion object.
Definition: umlentityattributedialog.cpp:299
codegenerator.h
UMLEntityAttributeDialog::m_pAutoIncrementCB
QCheckBox * m_pAutoIncrementCB
Definition: umlentityattributedialog.h:58
UMLAttribute::setInitialValue
void setInitialValue(const QString &iv)
Sets the initial value of the UMLAttribute.
Definition: attribute.cpp:108
UMLEntityAttributeDialog::m_pPrivateRB
QRadioButton * m_pPrivateRB
Definition: umlentityattributedialog.h:53
UMLEntityAttribute::setAutoIncrement
void setAutoIncrement(const bool autoIncrement)
Sets the UMLEntityAttribute's auto_increment boolean.
Definition: entityattribute.cpp:123
Uml::ProgrammingLanguage::SQL
Definition: basictypes.h:258
UMLEntityAttributeDialog::apply
bool apply()
Checks if changes are valid and applies them if they are, else returns false.
Definition: umlentityattributedialog.cpp:177
UMLClassifierList
QList< UMLClassifier * > UMLClassifierList
Definition: umlclassifierlist.h:17
UMLCanvasObject::findChildObject
virtual UMLObject * findChildObject(const QString &n, UMLObject::ObjectType t=UMLObject::ot_UMLObject)
Find a child object with the given name.
Definition: umlcanvasobject.cpp:240
UMLEntityAttributeDialog::setupDialog
void setupDialog()
Sets up the dialog.
Definition: umlentityattributedialog.cpp:63
UMLEntityAttributeDialog::m_pStereoTypeL
QLabel * m_pStereoTypeL
Definition: umlentityattributedialog.h:54
Dialog_Utils::makeLabeledEditField
KLineEdit * makeLabeledEditField(QGroupBox *containingBox, QGridLayout *layout, int row, QLabel *&label, const QString &labelText, KLineEdit *&editField, const QString &editFieldText)
Create a labeled text lineedit widget.
Definition: dialog_utils.cpp:43
UMLObject::stereotype
QString stereotype(bool includeAdornments=false) const
Returns the stereotype.
Definition: umlobject.cpp:581
UMLEntityAttribute::getNull
bool getNull() const
Returns the UMLEntityAttribute's allow null value.
Definition: entityattribute.cpp:150
UMLDoc::datatypes
UMLClassifierList datatypes()
Returns a list of the datatypes in this UMLDoc.
Definition: umldoc.cpp:2531
UMLEntityAttribute::setIndexType
void setIndexType(const DBIndex_Type indexType)
Sets the initial value of the UMLEntityAttribute's index type property.
Definition: entityattribute.cpp:141
UMLEntityAttributeDialog::m_pScopeGB
QGroupBox * m_pScopeGB
Definition: umlentityattributedialog.h:52
umlclassifierlist.h
umldoc.h
UMLEntityAttributeDialog::m_pTypeL
QLabel * m_pTypeL
Definition: umlentityattributedialog.h:54
UMLObject::ObjectType
ObjectType
Definition: umlobject.h:47
UMLEntityAttribute
This class is used to set up information for an entityattribute.
Definition: entityattribute.h:25
UMLEntityAttributeDialog::m_pNullCB
QCheckBox * m_pNullCB
Definition: umlentityattributedialog.h:59
UMLObject::ot_Class
Definition: umlobject.h:56
UMLEntityAttribute::setAttributes
void setAttributes(const QString &attributes)
Sets the UMLEntityAttribute's attributes property.
Definition: entityattribute.cpp:87
UMLEntityAttributeDialog::m_pStereoTypeLE
KLineEdit * m_pStereoTypeLE
Definition: umlentityattributedialog.h:57
UMLEntityAttributeDialog::UMLEntityAttributeDialog
UMLEntityAttributeDialog(QWidget *pParent, UMLEntityAttribute *pEntityAttribute)
Definition: umlentityattributedialog.cpp:42
UMLObject::name
QString name() const
Returns a copy of m_name.
Definition: umlobject.cpp:185
UMLEntityAttribute::getAutoIncrement
bool getAutoIncrement() const
Returns the UMLEntityAttribute's auto_increment boolean.
Definition: entityattribute.cpp:114
UMLEntityAttributeDialog::m_pNoneRB
QRadioButton * m_pNoneRB
Definition: umlentityattributedialog.h:53
UMLEntityAttributeDialog::slotOk
void slotOk()
Used when the OK button is clicked.
Definition: umlentityattributedialog.cpp:253
UMLClassifierListItem::getTypeName
virtual QString getTypeName() const
Returns the type name of the UMLClassifierListItem.
Definition: classifierlistitem.cpp:110
UMLDoc::findUMLObject
UMLObject * findUMLObject(const QString &name, UMLObject::ObjectType type=UMLObject::ot_UMLObject, UMLObject *currentObj=0)
Used to find a UMLObject by its type and name.
Definition: umldoc.cpp:809
UMLObject::setStereotype
void setStereotype(const QString &_name)
Sets the classes stereotype name.
Definition: umlobject.cpp:494
UMLObject::ot_Datatype
Definition: umlobject.h:54
UMLEntityAttribute::DBIndex_Type
DBIndex_Type
Definition: entityattribute.h:30
UMLEntityAttributeDialog::m_pValuesLE
KLineEdit * m_pValuesLE
Definition: umlentityattributedialog.h:57
uml.h
UMLDoc
UMLDoc provides a document object for a document-view model.
Definition: umldoc.h:63
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:06:00 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

umbrello/umbrello

Skip menu "umbrello/umbrello"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal