umbrello API Documentation

associationwidget.h

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 #ifndef ASSOCIATIONWIDGET_H
00013 #define ASSOCIATIONWIDGET_H
00014 
00015 #include "widgetbase.h"
00016 #include "linkwidget.h"
00017 #include "umlwidgetlist.h"
00018 #include "messagewidgetlist.h"
00019 #include "associationwidgetlist.h"
00020 #include "linepath.h"
00021 
00022 class IDChangeLog;
00023 class ListPopupMenu;
00024 class QBitmap;
00025 class QPixmap;
00026 class QDataStream;
00027 class QCanvasLine;
00028 class ClassifierWidget;
00029 class UMLDoc;
00030 class UMLView;
00031 class UMLAssociation;
00032 class UMLClassifierListItem;
00033 class UMLAttribute;
00034 class UMLOperation;
00035 
00055 class AssociationWidget : public WidgetBase, public LinkWidget {
00056     Q_OBJECT
00057 public:
00061     enum Region {
00062         Error = 0,
00063         West, North, East, South,
00064         NorthWest, NorthEast, SouthEast, SouthWest,
00065         Center
00066     };
00067 
00073     AssociationWidget(UMLView *view);
00074 
00084     AssociationWidget(UMLView *view, UMLWidget* WidgetA,
00085                       Uml::Association_Type Type, UMLWidget* WidgetB,
00086                       UMLAssociation *umlassoc = NULL);
00087 
00091     virtual ~AssociationWidget();
00092 
00096     AssociationWidget& operator=(AssociationWidget & Other);
00097 
00101     bool operator==(AssociationWidget & Other);
00102 
00106     bool operator!=(AssociationWidget & Other);
00107 
00113     bool activate();
00114 
00121     void setWidget(UMLWidget* widget, Uml::Role_Type role);
00122 
00128     FloatingTextWidget* getMultiWidget(Uml::Role_Type role);
00129 
00135     QString getMulti(Uml::Role_Type role) const;
00136 
00142     FloatingTextWidget* getNameWidget();
00143 
00149     QString getName() const;
00150 
00156     FloatingTextWidget* getRoleWidget(Uml::Role_Type role);
00157 
00163     FloatingTextWidget* getTextWidgetByRole(Uml::Text_Role tr);
00164 
00170     QString getRoleName(Uml::Role_Type role) const;
00171 
00175     QString getRoleDoc(Uml::Role_Type role) const;
00176 
00181     void setName (const QString &strRole);
00182 
00187     void setMulti(const QString &strMulti, Uml::Role_Type role);
00188 
00192     Uml::Visibility getVisibility (Uml::Role_Type role) const;
00193 
00197     void setVisibility (Uml::Visibility visibility, Uml::Role_Type role );
00198 
00202     Uml::Changeability_Type getChangeability(Uml::Role_Type role) const;
00203 
00207     void setChangeability (Uml::Changeability_Type value, Uml::Role_Type role);
00208 
00212     Uml::IDType getWidgetID(Uml::Role_Type role) const;
00213 
00219     UMLWidget* getWidget(Uml::Role_Type role);
00220 
00228     bool setWidgets( UMLWidget* widgetA, Uml::Association_Type assocType, UMLWidget* widgetB);
00229 
00238     bool checkAssoc(UMLWidget * widgetA, UMLWidget *widgetB);
00239 
00246     bool contains(UMLWidget* widget);
00247 
00251     bool isCollaboration();
00252 
00258     Uml::Association_Type getAssocType() const;
00259 
00265     void setAssocType(Uml::Association_Type type);
00266 
00272     QString toString();
00273 
00279     bool isActivated();
00280 
00287     void setActivated(bool active /*=true*/);
00288 
00294     void setSelected(bool _select = true);
00295 
00301     bool getSelected() const {
00302         return m_bSelected;
00303     }
00304 
00308     LinePath* getLinePath() {
00309         return &m_LinePath;
00310     }
00311 
00319     void widgetMoved(UMLWidget* widget, int x, int y);
00320 
00330     void saveIdealTextPositions();
00331 
00345     void calculateNameTextSegment();
00346 
00350     void mouseDoubleClickEvent(QMouseEvent * me);
00351 
00355     void mousePressEvent(QMouseEvent * me);
00356 
00360     void mouseReleaseEvent(QMouseEvent * me);
00361 
00365     void mouseMoveEvent(QMouseEvent * me);
00366 
00370     bool onAssociation(const QPoint & point);
00371 
00378     bool onAssocClassLine(const QPoint & point);
00379 
00383     void createAssocClassLine();
00384 
00393     void createAssocClassLine(ClassifierWidget* classifierWidget,
00394                               int linePathSegmentIndex);
00395 
00399     void selectAssocClassLine(bool sel = true);
00400 
00404     void moveMidPointsBy( int x, int y );
00405 
00409     void moveEntireAssoc( int x, int y );
00410 
00414     QRect getAssocLineRectangle();
00415 
00420     QFont getFont () const;
00421 
00425     void setLineColor(const QColor &colour);
00426 
00430     void setLineWidth(uint width);
00431 
00435     void lwSetFont (QFont font);
00436 
00440     FloatingTextWidget* getChangeWidget(Uml::Role_Type role);
00441 
00448     void setRoleName(const QString &strRole, Uml::Role_Type role);
00449 
00453     void setRoleDoc(const QString &doc, Uml::Role_Type role);
00454 
00460     UMLClassifier *getOperationOwner();
00461 
00466     UMLOperation *getOperation();
00467 
00472     void setOperation(UMLOperation *op);
00473 
00478     QString getCustomOpText();
00479 
00484     void setCustomOpText(const QString &opText);
00485 
00492     void setMessageText(FloatingTextWidget *ft);
00493 
00500     UMLAssociation * getAssociation() const;
00501 
00508     UMLAttribute * getAttribute() const;
00509 
00515     void setText(FloatingTextWidget *ft, const QString &text);
00516 
00521     void resetTextPositions();
00522 
00533     void constrainTextPos(int &textX, int &textY, int textWidth, int textHeight,
00534                           Uml::Text_Role tr);
00535 
00541     bool showDialog();
00542 
00546     void setIndex(int index, Uml::Role_Type role);
00547 
00551     int getIndex(Uml::Role_Type role) const;
00552 
00556     void setTotalCount(int count, Uml::Role_Type role);
00557 
00561     int getTotalCount(Uml::Role_Type role) const;
00562 
00566     void setTotalCount(int count);
00567 
00575     void setSeqNumAndOp(const QString &seqNum, const QString &op);
00576 
00584     UMLClassifier * getSeqNumAndOp(QString& seqNum, QString& op);
00585 
00593     void calculateEndingPoints();
00594 
00598     void removeAssocClassLine();
00599 
00604     void computeAssocClassLine();
00605 
00611     void setUMLObject(UMLObject *obj);
00612 
00616     void saveToXMI( QDomDocument & qDoc, QDomElement & qElement );
00617 
00621     bool loadFromXMI( QDomElement & qElement );
00622 
00629     bool loadFromXMI( QDomElement & qElement, const UMLWidgetList& widgets,
00630                       const MessageWidgetList* pMessages = NULL);
00631 
00635     void cleanup();
00636 
00637 private:
00638 
00640     void setUMLAssociation (UMLAssociation * assoc);
00641 
00647     void mergeAssociationDataIntoUMLRepresentation();
00648 
00681     static Region findPointRegion(QRect Rect, int PosX, int PosY);
00682 
00694     static int findInterceptOnEdge(const QRect &rect, Region region, const QPoint &point);
00695 
00696     static QPoint findIntercept(const QRect &rect, const QPoint &point);
00697 
00701     void moveEvent(QMoveEvent *me);
00702 
00707     Uml::Text_Role CalculateNameType(Uml::Text_Role defaultRoleType);
00708 
00713     bool isPointInsideBoundaries(int PosX, int PosY, QPoint & SPoint,
00714                                  uint & StartSegmentIndex, uint & EndSegmentIndex);
00715 
00719     static QPoint swapXY(const QPoint &p);
00720 
00725     float totalLength();
00726 
00734     static QPoint calculatePointAtDistance(const QPoint &P1, const QPoint &P2, float Distance);
00735 
00742     static QPoint calculatePointAtDistanceOnPerpendicular(const QPoint &P1, const QPoint &P2, float Distance);
00743 
00751     static float perpendicularProjection(QPoint P1, QPoint P2, QPoint P3, QPoint& ResultingPoint);
00752 
00756     static QPoint midPoint(QPoint p0, QPoint p1);
00757 
00763     QPoint calculateTextPosition(Uml::Text_Role role);
00764 
00771     void setTextPosition(Uml::Text_Role role);
00772 
00777     void setTextPositionRelatively(Uml::Text_Role role, const QPoint &oldPosition);
00778 
00788     Region getWidgetRegion(AssociationWidget * widget) const;
00789 
00794     FloatingTextWidget* m_pName;
00795 
00801     struct WidgetRole {
00802 
00808         FloatingTextWidget* m_pMulti;
00809 
00815         FloatingTextWidget* m_pChangeWidget;
00816 
00821         FloatingTextWidget* m_pRole;
00822 
00827         UMLWidget* m_pWidget;
00828 
00832         QPoint m_OldCorner;
00833 
00837         Region m_WidgetRegion;
00838 
00842         int m_nIndex;
00843 
00847         int m_nTotalCount;
00848 
00849         // The following items are only used if m_pObject is not set.
00850         Uml::Visibility m_Visibility;
00851         Uml::Changeability_Type m_Changeability;
00852         QString m_RoleDoc;
00853 
00854     } m_role[2];
00855 
00869     void setFloatingText(Uml::Text_Role tr, const QString &text, FloatingTextWidget* &ft);
00870 
00879     void updateRegionLineCount(int index, int totalCount,
00880                                AssociationWidget::Region region, Uml::Role_Type role);
00881 
00886     void updateAssociations(int totalCount, Region region, Uml::Role_Type role);
00887 
00892     int getRegionCount(Region region, Uml::Role_Type role);
00893 
00897     void init (UMLView *view);
00898 
00902     void doUpdates(int otherX, int otherY, Uml::Role_Type role);
00903 
00908     void setChangeWidget(const QString &strChangeWidget, Uml::Role_Type role);
00909 
00916     void checkPoints(const QPoint &p);
00917 
00921     bool linePathStartsAt(const UMLWidget* widget);
00922 
00930     void insertIntoLists(int position, const AssociationWidget* assoc);
00931 
00932     int m_positions[100];             
00933     int m_positions_len;              
00934     AssociationWidgetList m_ordered;  
00935 
00940     bool m_bActivated;
00941 
00949     uint                m_unNameLineSegment;
00950     UMLDoc * m_umldoc;  
00951     ListPopupMenu       *m_pMenu;
00952     bool                m_bSelected;
00953     int                 m_nMovingPoint;
00954 
00958     QPoint m_oldNamePoint;
00963     QPoint m_oldMultiAPoint;
00968     QPoint m_oldMultiBPoint;
00973     QPoint m_oldChangeAPoint;
00978     QPoint m_oldChangeBPoint;
00983     QPoint m_oldRoleAPoint;
00988     QPoint m_oldRoleBPoint;
00989 
00990     int         m_nLinePathSegmentIndex; 
00991     QCanvasLine *m_pAssocClassLine;  
00992 
00993     QCanvasRectangle *m_pAssocClassLineSel0, *m_pAssocClassLineSel1;
00994 
00995     ClassifierWidget *m_pAssocClassWidget;  
00996 
01000     LinePath m_LinePath;
01001 
01002     // The following items are only used if m_pObject is not set.
01003     Uml::Association_Type m_AssocType;
01004 
01005 public slots:
01009     void slotMenuSelection(int sel);
01010 
01017     void slotRemovePopupMenu();
01018 
01022     void slotClearAllSelected();
01023 
01030     void slotAttributeRemoved(UMLClassifierListItem* obj);
01031 
01035     void syncToModel();
01036 };
01037 #endif
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