umbrello API Documentation

assocgenpage.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  *  copyright (C) 2003-2006                                                *
00009  *  Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                   *
00010  ***************************************************************************/
00011 
00012 // own header
00013 #include "assocgenpage.h"
00014 
00015 // qt includes
00016 #include <qlayout.h>
00017 #include <kcombobox.h>
00018 
00019 // kde includes
00020 #include <klocale.h>
00021 #include <kmessagebox.h>
00022 #include <kdebug.h>
00023 
00024 // local includes
00025 #include "../association.h"
00026 #include "../dialog_utils.h"
00027 
00028 AssocGenPage::AssocGenPage (UMLDoc *d, QWidget *parent, AssociationWidget *assoc)
00029         : QWidget(parent)
00030 {
00031 
00032     m_pAssociationWidget = assoc;
00033     m_pWidget = 0;
00034     m_pTypeCB = 0;
00035     m_pAssocNameLE = 0;
00036     m_pUmldoc = d;
00037 
00038     constructWidget();
00039 
00040 }
00041 
00042 AssocGenPage::~AssocGenPage() {}
00043 
00044 void AssocGenPage::constructWidget() {
00045 
00046     // general configuration of the GUI
00047     int margin = fontMetrics().height();
00048     setMinimumSize(310,330);
00049     QVBoxLayout * topLayout = new QVBoxLayout(this);
00050     topLayout -> setSpacing(6);
00051 
00052     // group boxes for name, documentation properties
00053     QGroupBox *nameGB = new QGroupBox(this);
00054     QGroupBox *docGB = new QGroupBox(this);
00055     nameGB -> setTitle(i18n("Properties"));
00056     docGB -> setTitle(i18n("Documentation"));
00057     topLayout -> addWidget(nameGB);
00058     topLayout -> addWidget(docGB);
00059 
00060     QGridLayout * nameLayout = new QGridLayout(nameGB, 2, 2);
00061     nameLayout -> setSpacing(6);
00062     nameLayout -> setMargin(margin);
00063 
00064     //Association name
00065     QLabel *pAssocNameL = NULL;
00066     QLineEdit* nameField = Dialog_Utils::makeLabeledEditField( nameGB, nameLayout, 0,
00067                            pAssocNameL, i18n("Name:"),
00068                            m_pAssocNameLE, m_pAssociationWidget->getName() );
00069     nameField->setFocus();
00070 
00071     // document
00072     QHBoxLayout * docLayout = new QHBoxLayout(docGB);
00073     docLayout -> setMargin(margin);
00074 
00075     m_pDoc = new QMultiLineEdit(docGB);
00076     docLayout -> addWidget(m_pDoc);
00077     m_pDoc-> setText(m_pAssociationWidget-> getDoc());
00078     Uml::Association_Type currentType =  m_pAssociationWidget->getAssocType();
00079     QString currentTypeAsString = UMLAssociation::typeAsString(currentType);
00080     QLabel *pTypeL = new QLabel(i18n("Type:"), nameGB);
00081     nameLayout->addWidget(pTypeL, 1, 0);
00082 
00083     /* Here is a list of all the supported choices for changing
00084        association types */
00085     m_AssocTypes.clear();
00086     m_AssocTypes <<  Uml::at_Aggregation
00087         << Uml::at_Composition << Uml::at_Containment;
00088 
00089     bool found=false;
00090     m_AssocTypeStrings.clear();
00091     for (uint i=0; i<m_AssocTypes.size(); ++i) {
00092         if (m_AssocTypes[i] == currentType) found=true;
00093         QString typeStr = UMLAssociation::typeAsString(m_AssocTypes[i]);
00094         m_AssocTypeStrings << typeStr;
00095     }
00096 
00097     if (!found) {
00098         m_AssocTypes.clear();
00099         m_AssocTypes << currentType;
00100         m_AssocTypeStrings.clear();
00101         m_AssocTypeStrings << currentTypeAsString;
00102     }
00103 
00104     m_pTypeCB = new KComboBox(nameGB);
00105     pTypeL->setBuddy(m_pTypeCB);
00106     m_pTypeCB->insertStringList(m_AssocTypeStrings);
00107     m_pTypeCB->setCompletedItems(m_AssocTypeStrings);
00108     m_pTypeCB->setCurrentText(currentTypeAsString);
00109     m_pTypeCB->setDuplicatesEnabled(false);//only allow one of each type in box
00110     m_pTypeCB->setCompletionMode( KGlobalSettings::CompletionPopup );
00111     m_pDoc->setWordWrap(QMultiLineEdit::WidgetWidth);
00112     nameLayout->addWidget(m_pTypeCB, 1, 1);
00113 
00114 
00115 }
00116 
00117 
00118 void AssocGenPage::updateObject() {
00119 
00120     if (m_pAssociationWidget) {
00121         int comboBoxItem = m_pTypeCB->currentItem();
00122         Uml::Association_Type newType = m_AssocTypes[comboBoxItem];
00123         m_pAssociationWidget->setAssocType(newType);
00124         m_pAssociationWidget->setName(m_pAssocNameLE->text());
00125         m_pAssociationWidget->setDoc(m_pDoc->text());
00126 
00127     } //end if m_pAssociationWidget
00128 }
00129 
00130 
00131 #include "assocgenpage.moc"
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:07:54 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003