umbrello API Documentation

classgenpage.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) 2002-2006                                               *
00009  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00010  ***************************************************************************/
00011 
00012 // my own header
00013 #include "classgenpage.h"
00014 
00015 // qt includes
00016 #include <qlayout.h>
00017 #include <qgroupbox.h>
00018 #include <qlabel.h>
00019 #include <qlineedit.h>
00020 #include <qbuttongroup.h>
00021 #include <qmultilineedit.h>
00022 #include <qradiobutton.h>
00023 #include <qcheckbox.h>
00024 
00025 // kde includes
00026 #include <klocale.h>
00027 #include <kdebug.h>
00028 #include <kmessagebox.h>
00029 #include <kcombobox.h>
00030 
00031 // my class includes
00032 #include "../umlobject.h"
00033 #include "../objectwidget.h"
00034 #include "../uml.h"
00035 #include "../umldoc.h"
00036 #include "../artifact.h"
00037 #include "../component.h"
00038 #include "../umlview.h"
00039 #include "../stereotype.h"
00040 
00041 ClassGenPage::ClassGenPage(UMLDoc* d, QWidget* parent, UMLObject* o) : QWidget(parent) {
00042     m_pWidget = 0;
00043     m_pObject = 0;
00044     m_pInstanceWidget = 0;
00045     QString name;
00046     int margin = fontMetrics().height();
00047     Uml::Object_Type t = o -> getBaseType();
00048     m_pUmldoc = d;
00049     if (t == Uml::ot_Class) {
00050         name = i18n("Class &name:");
00051     } else if (t == Uml::ot_Actor) {
00052         name = i18n("Actor &name:");
00053     } else if (t == Uml::ot_Package) {
00054         name = i18n("Package &name:");
00055     } else if (t == Uml::ot_UseCase) {
00056         name = i18n("Use case &name:");
00057     } else if (t == Uml::ot_Interface) {
00058         name = i18n("Interface &name:");
00059     } else if (t == Uml::ot_Component) {
00060         name = i18n("Component &name:");
00061     } else if (t == Uml::ot_Artifact) {
00062         name = i18n("Artifact &name:");
00063     } else if (t == Uml::ot_Enum) {
00064         name = i18n("Enum &name:");
00065     } else if (t == Uml::ot_Datatype) {
00066         name = i18n("Datatype &name:");
00067     } else if (t == Uml::ot_Entity) {
00068         name = i18n("Entity &name:");
00069     } else {
00070         kWarning() << "creating class gen page for unknown widget type" << endl;
00071     }
00072     setMinimumSize(310,330);
00073     QVBoxLayout * topLayout = new QVBoxLayout(this);
00074     topLayout -> setSpacing(6);
00075 
00076     //setup name
00077     QGridLayout * m_pNameLayout = new QGridLayout(topLayout, 4, 2);
00078     m_pNameLayout -> setSpacing(6);
00079     m_pNameL = new QLabel(this);
00080     m_pNameL -> setText(name);
00081     m_pNameLayout -> addWidget(m_pNameL, 0, 0);
00082 
00083     m_pClassNameLE = new QLineEdit(this);
00084     m_pNameLayout -> addWidget(m_pClassNameLE, 0, 1);
00085     m_pClassNameLE->setFocus();
00086     m_pNameL->setBuddy(m_pClassNameLE);
00087 
00088     m_pStereoTypeCB = 0;
00089     m_pPackageLE = 0;
00090     m_pAbstractCB = 0;
00091     m_pDeconCB = 0;
00092 
00093     m_pStereoTypeL = new QLabel(i18n("&Stereotype name:"), this);
00094     m_pNameLayout -> addWidget(m_pStereoTypeL, 1, 0);
00095 
00096     m_pStereoTypeCB = new KComboBox(true, this);
00097     m_pNameLayout -> addWidget(m_pStereoTypeCB, 1, 1);
00098 
00099     m_pStereoTypeCB->setCurrentText( o->getStereotype() );
00100     m_pStereoTypeL->setBuddy(m_pStereoTypeCB);
00101 
00102     if (t == Uml::ot_Interface || t == Uml::ot_Datatype || t == Uml::ot_Enum) {
00103         m_pStereoTypeCB->setEditable(false);
00104     }
00105 
00106     if (t == Uml::ot_Class || t == Uml::ot_Interface) {
00107         m_pPackageL = new QLabel(i18n("&Package name:"), this);
00108         m_pNameLayout -> addWidget(m_pPackageL, 2, 0);
00109 
00110         m_pPackageLE = new QLineEdit(this);
00111         m_pNameLayout -> addWidget(m_pPackageLE, 2, 1);
00112 
00113         m_pPackageLE -> setText(o -> getPackage());
00114         m_pPackageLE -> setEnabled(false);
00115         m_pPackageL->setBuddy(m_pPackageLE);
00116     }
00117 
00118     if (t == Uml::ot_Class || t == Uml::ot_UseCase ) {
00119         QString abstractCaption;
00120         if ( t == Uml::ot_Class  ) {
00121             abstractCaption = i18n("A&bstract class");
00122         } else {
00123             abstractCaption = i18n("A&bstract use case");
00124         }
00125         m_pAbstractCB = new QCheckBox( abstractCaption, this );
00126         m_pAbstractCB -> setChecked( o -> getAbstract() );
00127         m_pNameLayout -> addWidget( m_pAbstractCB, 3, 0 );
00128     }
00129 
00130     if (t == Uml::ot_Component) {
00131         m_pExecutableCB = new QCheckBox(i18n("&Executable"), this);
00132         m_pExecutableCB->setChecked( (static_cast<UMLComponent*>(o))->getExecutable() );
00133         m_pNameLayout->addWidget( m_pExecutableCB, 3, 0 );
00134     }
00135 
00136     if (t == Uml::ot_Artifact) {
00137         //setup artifact draw as
00138         m_pDrawAsBG = new QButtonGroup(i18n("Draw As"), this);
00139         QHBoxLayout* drawAsLayout = new QHBoxLayout(m_pDrawAsBG);
00140         drawAsLayout->setMargin(margin);
00141         m_pDrawAsBG->setExclusive(true);
00142 
00143         m_pDefaultRB = new QRadioButton(i18n("&Default"), m_pDrawAsBG);
00144         drawAsLayout->addWidget(m_pDefaultRB);
00145 
00146         m_pFileRB = new QRadioButton(i18n("&File"), m_pDrawAsBG);
00147         drawAsLayout->addWidget(m_pFileRB);
00148 
00149         m_pLibraryRB = new QRadioButton(i18n("&Library"), m_pDrawAsBG);
00150         drawAsLayout->addWidget(m_pLibraryRB);
00151 
00152         m_pTableRB = new QRadioButton(i18n("&Table"), m_pDrawAsBG);
00153         drawAsLayout->addWidget(m_pTableRB);
00154 
00155         topLayout->addWidget(m_pDrawAsBG);
00156 
00157         UMLArtifact::Draw_Type drawAs = (static_cast<UMLArtifact*>(o))->getDrawAsType();
00158 
00159         if (drawAs == UMLArtifact::file) {
00160             m_pFileRB->setChecked(true);
00161         } else if (drawAs == UMLArtifact::library) {
00162             m_pLibraryRB->setChecked(true);
00163         } else if (drawAs == UMLArtifact::table) {
00164             m_pTableRB->setChecked(true);
00165         } else {
00166             m_pDefaultRB->setChecked(true);
00167         }
00168     }
00169 
00170     //setup scope
00171     m_pButtonBG = new QButtonGroup(i18n("Visibility"), this);
00172     QHBoxLayout * scopeLayout = new QHBoxLayout(m_pButtonBG);
00173     scopeLayout -> setMargin(margin);
00174     m_pButtonBG -> setExclusive(true);
00175 
00176     m_pPublicRB = new QRadioButton(i18n("P&ublic"), m_pButtonBG);
00177     scopeLayout -> addWidget(m_pPublicRB);
00178 
00179     m_pPrivateRB = new QRadioButton(i18n("P&rivate"), m_pButtonBG);
00180     scopeLayout -> addWidget(m_pPrivateRB);
00181 
00182     m_pProtectedRB = new QRadioButton(i18n("Pro&tected"), m_pButtonBG);
00183     scopeLayout -> addWidget(m_pProtectedRB);
00184     topLayout -> addWidget(m_pButtonBG);
00185 
00186     m_pImplementationRB = new QRadioButton(i18n("Imple&mentation"), m_pButtonBG);
00187     scopeLayout -> addWidget(m_pImplementationRB);
00188     topLayout -> addWidget(m_pButtonBG);
00189     //setup documentation
00190     m_pDocGB = new QGroupBox(this);
00191     QHBoxLayout * docLayout = new QHBoxLayout(m_pDocGB);
00192     docLayout -> setMargin(margin);
00193     m_pDocGB -> setTitle(i18n("Documentation"));
00194 
00195     m_pDoc = new QMultiLineEdit(m_pDocGB);
00196     docLayout -> addWidget(m_pDoc);
00197     topLayout -> addWidget(m_pDocGB);
00198 
00199     m_pObject = o;
00200     //setup fields
00201     m_pClassNameLE -> setText(o -> getName());
00202     m_pDoc-> setText(o -> getDoc());
00203     Uml::Visibility s = o -> getVisibility();
00204     if(s == Uml::Visibility::Public)
00205         m_pPublicRB->setChecked(true);
00206     else if(s == Uml::Visibility::Private)
00207         m_pPrivateRB->setChecked(true);
00208     else if(s == Uml::Visibility::Protected)
00209           m_pProtectedRB->setChecked(true);
00210     else
00211         m_pImplementationRB -> setChecked(true);
00212 
00213     // manage stereotypes
00214     m_pStereoTypeCB -> setDuplicatesEnabled(false);//only allow one of each type in box
00215     m_pStereoTypeCB->setCompletionMode( KGlobalSettings::CompletionPopup );
00216     insertStereotype (QString("")); // an empty stereotype is the default
00217     int defaultStereotype=0;
00218     bool foundDefaultStereotype = false;
00219     for (UMLStereotypeListIt it(m_pUmldoc->getStereotypes()); it.current(); ++it) {
00220         if (!foundDefaultStereotype) {
00221             if ( m_pObject->getStereotype() == it.current()->getName()) {
00222                 foundDefaultStereotype = true;
00223             }
00224             defaultStereotype++;
00225         }
00226         insertStereotype (it.current()->getName());
00227     }
00228     // lookup for a default stereotype, if the operation doesn't have one
00229     if (foundDefaultStereotype)
00230         m_pStereoTypeCB -> setCurrentItem(defaultStereotype);
00231     else
00232         m_pStereoTypeCB -> setCurrentItem(-1);
00233 
00235     m_pDoc->setWordWrap(QMultiLineEdit::WidgetWidth);
00237 }
00238 
00239 ClassGenPage::ClassGenPage(UMLDoc* d, QWidget* parent, ObjectWidget* o) : QWidget(parent) {
00240     m_pObject = 0;
00241     m_pInstanceWidget = 0;
00242     m_pWidget = o;
00243     m_pDeconCB = 0;
00244     m_pMultiCB = 0;
00245     int margin = fontMetrics().height();
00246     //int t = o -> getBaseType();
00247     m_pUmldoc = d;
00248     setMinimumSize(310,330);
00249     QGridLayout * topLayout = new QGridLayout(this, 2, 1);
00250     topLayout -> setSpacing(6);
00251 
00252     //setup name
00253     QGridLayout * m_pNameLayout = new QGridLayout(topLayout, 3, 2);
00254     m_pNameLayout -> setSpacing(6);
00255     m_pNameL = new QLabel(this);
00256     m_pNameL -> setText(i18n("Class name:"));
00257     m_pNameLayout -> addWidget(m_pNameL, 0, 0);
00258 
00259     m_pClassNameLE = new QLineEdit(this);
00260     m_pClassNameLE -> setText(o -> getName());
00261     m_pNameLayout -> addWidget(m_pClassNameLE, 0, 1);
00262 
00263     m_pInstanceL = new QLabel(this);
00264     m_pInstanceL -> setText(i18n("Instance name:"));
00265     m_pNameLayout -> addWidget(m_pInstanceL, 1, 0);
00266 
00267     m_pInstanceLE = new QLineEdit(this);
00268     m_pInstanceLE -> setText(o -> getInstanceName());
00269     m_pNameLayout -> addWidget(m_pInstanceLE, 1, 1);
00270     UMLView *view = UMLApp::app()->getCurrentView();
00271 
00272     m_pDrawActorCB = new QCheckBox( i18n( "Draw as actor" ) , this );
00273     m_pDrawActorCB -> setChecked( o -> getDrawAsActor() );
00274     m_pNameLayout -> addWidget( m_pDrawActorCB, 2, 0 );
00275 
00276     if(view -> getType() == Uml::dt_Collaboration) {
00277         m_pMultiCB = new QCheckBox(i18n("Multiple instance"), this);
00278         m_pMultiCB -> setChecked(o -> getMultipleInstance());
00279         m_pNameLayout -> addWidget(m_pMultiCB, 2,1);
00280         if( m_pDrawActorCB -> isChecked() )
00281             m_pMultiCB -> setEnabled( false );
00282     } else//sequence diagram
00283     {
00284         m_pDeconCB = new QCheckBox(i18n("Show destruction"), this);
00285         m_pDeconCB->setChecked(o->getShowDestruction());
00286         m_pNameLayout -> addWidget(m_pDeconCB, 2,1);
00287     }
00288     //setup documentation
00289     m_pDocGB = new QGroupBox(this);
00290     topLayout -> addWidget(m_pDocGB, 1, 0);
00291     QHBoxLayout * docLayout = new QHBoxLayout(m_pDocGB);
00292     docLayout -> setMargin(margin);
00293     m_pDocGB -> setTitle(i18n("Documentation"));
00294 
00295     m_pDoc = new QMultiLineEdit(m_pDocGB);
00296     m_pDoc->setWordWrap(QMultiLineEdit::WidgetWidth);
00297     m_pDoc-> setText(o -> getDoc());
00298     docLayout -> addWidget(m_pDoc);
00299     m_pObject = 0;//needs to be set to zero
00300     if( m_pMultiCB )
00301         connect( m_pDrawActorCB, SIGNAL( toggled( bool ) ), this, SLOT( slotActorToggled( bool ) ) );
00302 }
00303 
00304 ClassGenPage::ClassGenPage(UMLDoc* d, QWidget* parent, UMLWidget* widget) : QWidget(parent) {
00305     m_pWidget = 0;
00306     m_pObject = 0;
00307     m_pInstanceWidget = widget;
00308     m_pDeconCB = 0;
00309     m_pMultiCB = 0;
00310     int margin = fontMetrics().height();
00311     //int t = o -> getBaseType();
00312     m_pUmldoc = d;
00313     setMinimumSize(310,330);
00314     QGridLayout* topLayout = new QGridLayout(this, 2, 1);
00315     topLayout->setSpacing(6);
00316 
00317     //setup name
00318     QGridLayout* m_pNameLayout = new QGridLayout(topLayout, 3, 2);
00319     m_pNameLayout->setSpacing(6);
00320     m_pNameL = new QLabel(this);
00321     if (widget->getBaseType() == Uml::wt_Component) {
00322         m_pNameL->setText(i18n("Component name:"));
00323     } else if (widget->getBaseType() == Uml::wt_Node) {
00324         m_pNameL->setText(i18n("Node name:"));
00325     } else {
00326         kWarning() << "ClassGenPage called on unknown widget type" << endl;
00327     }
00328     m_pNameLayout->addWidget(m_pNameL, 0, 0);
00329 
00330     m_pClassNameLE = new QLineEdit(this);
00331     m_pClassNameLE->setText(widget->getName());
00332     m_pNameLayout->addWidget(m_pClassNameLE, 0, 1);
00333 
00334     m_pStereoTypeL = new QLabel(i18n("Stereotype name:"), this);
00335     m_pNameLayout->addWidget(m_pStereoTypeL, 1, 0);
00336 
00337     m_pStereoTypeCB = new KComboBox(true, this);
00338     m_pNameLayout->addWidget(m_pStereoTypeCB, 1, 1);
00339 
00340     m_pStereoTypeCB->setCurrentText( widget->getUMLObject()->getStereotype() );
00341     m_pStereoTypeCB->setCompletionMode( KGlobalSettings::CompletionPopup );
00342 
00343     m_pInstanceL = new QLabel(this);
00344     m_pInstanceL->setText(i18n("Instance name:"));
00345     m_pNameLayout->addWidget(m_pInstanceL, 2, 0);
00346 
00347     m_pInstanceLE = new QLineEdit(this);
00348     m_pInstanceLE->setText(widget->getInstanceName());
00349     m_pNameLayout->addWidget(m_pInstanceLE, 2, 1);
00350 
00351     //setup documentation
00352     m_pDocGB = new QGroupBox(this);
00353     topLayout->addWidget(m_pDocGB, 1, 0);
00354     QHBoxLayout* docLayout = new QHBoxLayout(m_pDocGB);
00355     docLayout->setMargin(margin);
00356     m_pDocGB->setTitle(i18n("Documentation"));
00357 
00358     m_pDoc = new QMultiLineEdit(m_pDocGB);
00359     m_pDoc->setWordWrap(QMultiLineEdit::WidgetWidth);
00360     m_pDoc->setText(widget->getDoc());
00361     docLayout->addWidget(m_pDoc);
00362     m_pObject = 0;//needs to be set to zero
00363 }
00364 
00365 ClassGenPage::~ClassGenPage() {}
00366 
00367 void ClassGenPage::insertStereotype( const QString& type, int index )
00368 {
00369     m_pStereoTypeCB->insertItem( type, index );
00370     m_pStereoTypeCB->completionObject()->addItem( type );
00371 }
00372 
00373 void ClassGenPage::updateObject() {
00374     if(m_pObject) {
00375         QString name = m_pClassNameLE -> text();
00376 
00377         m_pObject -> setDoc(m_pDoc -> text());
00378 
00379         if(m_pStereoTypeCB)
00380             m_pObject -> setStereotype(m_pStereoTypeCB->currentText());
00387         if ( m_pObject->getUMLPackage() == NULL ) {
00388             kDebug() << k_funcinfo << "Parent package not set, setting it to Logical View folder"<<endl;
00389             UMLFolder* folder = m_pUmldoc->getRootFolder(  Uml::mt_Logical );
00390             m_pObject->setUMLPackage( ( UMLPackage* )folder );
00391         }
00392 
00393         if( m_pAbstractCB )
00394             m_pObject -> setAbstract( m_pAbstractCB -> isChecked() );
00395         //make sure unique name
00396         UMLObject *o = m_pUmldoc -> findUMLObject(name);
00397         if(o && m_pObject != o) {
00398             KMessageBox::sorry(this, i18n("The name you have chosen\nis already being used.\nThe name has been reset."),
00399                                i18n("Name is Not Unique"), false);
00400             m_pClassNameLE -> setText( m_pObject -> getName() );
00401         } else
00402             m_pObject -> setName(name);
00403         Uml::Visibility s;
00404         if(m_pPublicRB -> isChecked())
00405           s = Uml::Visibility::Public;
00406         else if(m_pPrivateRB -> isChecked())
00407           s = Uml::Visibility::Private;
00408         else if(m_pProtectedRB->isChecked())
00409           s = Uml::Visibility::Protected;
00410         else
00411           s = Uml::Visibility::Implementation;
00412         m_pObject -> setVisibility(s);
00413 
00414         if (m_pObject->getBaseType() == Uml::ot_Component) {
00415             (static_cast<UMLComponent*>(m_pObject))->setExecutable( m_pExecutableCB->isChecked() );
00416         }
00417 
00418         if (m_pObject->getBaseType() == Uml::ot_Artifact) {
00419             UMLArtifact::Draw_Type drawAsType;
00420             if ( m_pFileRB->isChecked() ) {
00421                 drawAsType = UMLArtifact::file;
00422             } else if ( m_pLibraryRB->isChecked() ) {
00423                 drawAsType = UMLArtifact::library;
00424             } else if (m_pTableRB->isChecked() ) {
00425                 drawAsType = UMLArtifact::table;
00426             } else {
00427                 drawAsType = UMLArtifact::defaultDraw;
00428             }
00429             (static_cast<UMLArtifact*>(m_pObject))->setDrawAsType(drawAsType);
00430         }
00431 
00432     }//end if m_pObject
00433     else if(m_pWidget) {
00434         m_pWidget -> setInstanceName(m_pInstanceLE -> text());
00435         if(m_pMultiCB)
00436             m_pWidget -> setMultipleInstance(m_pMultiCB -> isChecked());
00437         m_pWidget -> setDrawAsActor( m_pDrawActorCB -> isChecked() );
00438         if( m_pDeconCB )
00439             m_pWidget -> setShowDestruction( m_pDeconCB -> isChecked() );
00440         QString name = m_pClassNameLE -> text();
00441         m_pWidget -> setDoc(m_pDoc -> text());
00442         UMLObject * o = m_pWidget -> getUMLObject();
00443         UMLObject * old = m_pUmldoc -> findUMLObject(name);
00444         if(old && o != old) {
00445             KMessageBox::sorry(this, i18n("The name you have chosen\nis already being used.\nThe name has been reset."),
00446                                i18n("Name is Not Unique"), false);
00447         } else
00448             o -> setName(name);
00449     } else if (m_pInstanceWidget) {
00450         m_pInstanceWidget->setInstanceName(m_pInstanceLE->text());
00451         QString name = m_pClassNameLE->text();
00452         m_pInstanceWidget->setDoc(m_pDoc->text());
00453         UMLObject* o = m_pInstanceWidget->getUMLObject();
00454         UMLObject* old = m_pUmldoc->findUMLObject(name);
00455         if(old && o != old) {
00456             KMessageBox::sorry(this, i18n("The name you have chosen\nis already being used.\nThe name has been reset."),
00457                                i18n("Name is Not Unique"), false);
00458         } else {
00459             o->setName(name);
00460         }
00461         o->setStereotype( m_pStereoTypeCB->currentText() );
00462     }
00463 }
00464 
00465 void ClassGenPage::slotActorToggled( bool state ) {
00466     if( m_pMultiCB )
00467         m_pMultiCB -> setEnabled( !state );
00468 }
00469 
00470 
00471 
00472 #include "classgenpage.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