~ubuntu-branches/ubuntu/vivid/kdesdk/vivid

« back to all changes in this revision

Viewing changes to umbrello/umbrello/widgets/associationwidget.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-06-06 11:49:54 UTC
  • mfrom: (0.4.21)
  • Revision ID: package-import@ubuntu.com-20120606114954-rdls73fzlpzxglbx
Tags: 4:4.8.80-0ubuntu1
* New uptream beta release
* Update dont_export_private_classes.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
#ifndef ASSOCIATIONWIDGET_H
12
12
#define ASSOCIATIONWIDGET_H
13
13
 
14
 
#include "widgetbase.h"
15
 
 
16
14
#include "associationline.h"
17
15
#include "associationwidgetlist.h"
18
16
#include "linkwidget.h"
19
17
#include "messagewidgetlist.h"
20
18
#include "umlwidgetlist.h"
 
19
#include "widgetbase.h"
21
20
 
22
21
class ListPopupMenu;
23
22
class ClassifierWidget;
24
23
class UMLDoc;
25
24
class UMLScene;
26
25
class UMLAssociation;
 
26
class UMLAttribute;
27
27
class UMLClassifierListItem;
28
 
class UMLAttribute;
29
28
class UMLOperation;
30
29
 
31
30
/**
74
73
    //---------- LinkWidget Interface methods implemementation from now on.
75
74
 
76
75
    virtual void lwSetFont(QFont font);
77
 
 
78
 
    virtual UMLClassifier *getOperationOwner();
 
76
    virtual UMLClassifier *operationOwner();
79
77
 
80
78
    virtual UMLOperation *operation();
81
79
    virtual void setOperation(UMLOperation *op);
93
91
    virtual UMLClassifier* seqNumAndOp(QString& seqNum, QString& op);
94
92
    virtual void setSeqNumAndOp(const QString &seqNum, const QString &op);
95
93
 
 
94
    virtual void constrainTextPos(UMLSceneValue &textX, UMLSceneValue &textY,
 
95
                                  UMLSceneValue textWidth, UMLSceneValue textHeight,
 
96
                                  Uml::TextRole tr);
 
97
 
96
98
    virtual void calculateNameTextSegment();
97
99
 
98
100
    //---------- End LinkWidget Interface methods implemementation.
99
101
 
100
 
    UMLAssociation * getAssociation() const;
101
 
    UMLAttribute * getAttribute() const;
 
102
    UMLAssociation* association() const;
 
103
    UMLAttribute* attribute() const;
102
104
 
103
105
    //AssociationWidget& operator=(const AssociationWidget & Other);
104
106
    bool operator==(const AssociationWidget & Other) const;
105
107
    bool operator!=(AssociationWidget & Other) const;
106
108
 
107
 
    bool activate();
108
 
 
109
 
    void setWidget(UMLWidget* widget, Uml::Role_Type role);
110
 
 
111
 
    FloatingTextWidget* getMultiWidget(Uml::Role_Type role);
112
 
    FloatingTextWidget* getNameWidget();
113
 
    FloatingTextWidget* getRoleWidget(Uml::Role_Type role);
114
 
    FloatingTextWidget* getTextWidgetByRole(Uml::TextRole tr);
115
 
 
116
 
    QString getName() const;
 
109
    FloatingTextWidget* textWidgetByRole(Uml::TextRole tr) const;
 
110
 
 
111
    FloatingTextWidget* nameWidget() const;
 
112
    QString name() const;
117
113
    void setName(const QString &strRole);
118
114
 
 
115
    FloatingTextWidget* roleWidget(Uml::Role_Type role) const;
119
116
    QString roleName(Uml::Role_Type role) const;
120
117
    void setRoleName(const QString &strRole, Uml::Role_Type role);
 
118
 
121
119
    QString roleDocumentation(Uml::Role_Type role) const;
 
120
    void setRoleDocumentation(const QString& doc, Uml::Role_Type role);
122
121
 
 
122
    FloatingTextWidget* multiplicityWidget(Uml::Role_Type role) const;
123
123
    QString multiplicity(Uml::Role_Type role) const;
124
 
    void setMultiplicity(const QString &strMulti, Uml::Role_Type role);
 
124
    void setMultiplicity(const QString& text, Uml::Role_Type role);
125
125
 
126
126
    Uml::Visibility visibility(Uml::Role_Type role) const;
127
 
    void setVisibility(Uml::Visibility visibility, Uml::Role_Type role );
 
127
    void setVisibility(Uml::Visibility value, Uml::Role_Type role);
128
128
 
 
129
    FloatingTextWidget* changeabilityWidget(Uml::Role_Type role) const;
129
130
    Uml::Changeability changeability(Uml::Role_Type role) const;
130
 
    void setChangeability (Uml::Changeability value, Uml::Role_Type role);
 
131
    void setChangeability(Uml::Changeability value, Uml::Role_Type role);
131
132
 
132
 
    Uml::IDType getWidgetID(Uml::Role_Type role) const;
 
133
    Uml::IDType widgetIDForRole(Uml::Role_Type role) const;
133
134
    UMLWidget* widgetForRole(Uml::Role_Type role) const;
 
135
    void setWidgetForRole(UMLWidget* widget, Uml::Role_Type role);
134
136
 
135
137
    bool setWidgets(UMLWidget* widgetA, Uml::AssociationType assocType, UMLWidget* widgetB);
136
138
 
138
140
 
139
141
    bool contains(UMLWidget* widget);
140
142
 
141
 
    bool isCollaboration();
142
 
 
143
143
    Uml::AssociationType associationType() const;
144
 
 
145
144
    void setAssociationType(Uml::AssociationType type);
146
145
 
147
 
    QString toString();
 
146
    bool isCollaboration() const;
 
147
 
 
148
    QString toString() const;
148
149
 
149
150
    bool isActivated();
150
151
    void setActivated(bool active /*=true*/);
151
152
 
 
153
    bool isSelected() const;
152
154
    void setSelected(bool _select = true);
153
155
 
154
 
    /**
155
 
     * Returns the state of whether the widget is selected.
156
 
     *
157
 
     * @return  Returns the state of whether the widget is selected.
158
 
     */
159
 
    bool getSelected() const {
160
 
        return m_selected;
161
 
    }
 
156
    AssociationLine* associationLine() const;
162
157
 
163
 
    /**
164
 
     * Returns a pointer to the association widget's line path.
165
 
     */
166
 
    AssociationLine* getLinePath() {
167
 
        return m_associationLine;
168
 
    }
 
158
    virtual bool activate();
 
159
    QRect boundingRect();
169
160
 
170
161
    void widgetMoved(UMLWidget* widget, int x, int y);
171
162
 
172
 
    void updatePointsException ();
 
163
    void updatePointsException();
173
164
 
174
165
    void saveIdealTextPositions();
175
166
 
176
 
    void mouseDoubleClickEvent(QMouseEvent * me);
177
 
    void mousePressEvent(QMouseEvent * me);
178
 
    void mouseReleaseEvent(QMouseEvent * me);
179
 
    void mouseMoveEvent(QMouseEvent * me);
 
167
    void mouseDoubleClickEvent(QMouseEvent* me);
 
168
    void mousePressEvent(QMouseEvent* me);
 
169
    void mouseReleaseEvent(QMouseEvent* me);
 
170
    void mouseMoveEvent(QMouseEvent* me);
180
171
 
181
 
    bool onAssociation(const QPoint & point);
182
 
    bool onAssocClassLine(const QPoint & point);
 
172
    bool onAssociation(const QPoint& point);
 
173
    bool onAssocClassLine(const QPoint& point);
183
174
 
184
175
    void createAssocClassLine();
185
176
    void createAssocClassLine(ClassifierWidget* classifierWidget,
187
178
 
188
179
    void selectAssocClassLine(bool sel = true);
189
180
 
190
 
    void moveMidPointsBy( int x, int y );
191
 
 
192
 
    void moveEntireAssoc( int x, int y );
193
 
 
194
 
    QRect getAssocLineRectangle();
 
181
    void moveMidPointsBy(int x, int y);
 
182
    void moveEntireAssoc(int x, int y);
195
183
 
196
184
    QFont font() const;
197
185
 
198
 
    virtual void setLineColor(const QColor &colour);
 
186
    virtual void setTextColor(const QColor &color);
 
187
    virtual void setLineColor(const QColor &color);
199
188
    void setLineWidth(uint width);
200
189
 
201
 
    FloatingTextWidget* getChangeWidget(Uml::Role_Type role);
202
 
 
203
 
    void setRoleDocumentation(const QString &doc, Uml::Role_Type role);
204
 
 
205
 
    void constrainTextPos(int &textX, int &textY, int textWidth, int textHeight,
206
 
                          Uml::TextRole tr);
207
 
 
208
190
    void setIndex(int index, Uml::Role_Type role);
209
191
    int getIndex(Uml::Role_Type role) const;
210
192
 
211
 
    void setTotalCount(int count, Uml::Role_Type role);
212
 
    int getTotalCount(Uml::Role_Type role) const;
213
 
 
214
 
    void setTotalCount(int count);
215
 
 
216
193
    void calculateEndingPoints();
217
194
 
218
195
    void removeAssocClassLine();
219
 
 
220
196
    void computeAssocClassLine();
221
197
 
222
198
    void clipSize();
223
199
 
224
 
    void saveToXMI( QDomDocument & qDoc, QDomElement & qElement );
225
 
    bool loadFromXMI( QDomElement & qElement );
226
 
 
227
 
    bool loadFromXMI( QDomElement & qElement, const UMLWidgetList& widgets,
228
 
                      const MessageWidgetList* pMessages = NULL);
 
200
    bool loadFromXMI(QDomElement& qElement, const UMLWidgetList& widgets,
 
201
                     const MessageWidgetList* messages);
 
202
    virtual bool loadFromXMI(QDomElement& qElement);
 
203
    virtual void saveToXMI(QDomDocument &qDoc, QDomElement &qElement);
229
204
 
230
205
    void cleanup();
231
206
 
 
207
public slots:
 
208
    void slotMenuSelection(QAction* action);
 
209
    void slotRemovePopupMenu();
 
210
    void slotClearAllSelected();
 
211
    void slotClassifierListItemRemoved(UMLClassifierListItem* obj);
 
212
    void slotAttributeChanged();
 
213
 
 
214
    void syncToModel();
 
215
 
232
216
private:
 
217
    void init();
 
218
 
 
219
    UMLScenePoint calculateTextPosition(Uml::TextRole role);
 
220
    void setTextPosition(Uml::TextRole role);
 
221
    void setTextPositionRelatively(Uml::TextRole role, const QPoint &oldPosition);
 
222
    void setFloatingText(Uml::TextRole role, const QString& text, FloatingTextWidget* &ft);
233
223
 
234
224
    /**
235
225
     * Constructor is made non accessible:
237
227
     */
238
228
    AssociationWidget(UMLScene *scene);
239
229
 
240
 
    void setUMLAssociation (UMLAssociation * assoc);
 
230
    void setUMLAssociation(UMLAssociation * assoc);
241
231
 
242
232
    void mergeAssociationDataIntoUMLRepresentation();
243
233
 
244
234
    static Region findPointRegion(const QRect& Rect, int PosX, int PosY);
245
 
 
246
235
    static int findInterceptOnEdge(const QRect &rect, Region region, const QPoint &point);
247
 
 
248
236
    static QPoint findIntercept(const QRect &rect, const QPoint &point);
249
237
 
250
238
    void moveEvent(QMoveEvent *me);
251
239
 
252
 
    Uml::TextRole CalculateNameType(Uml::TextRole defaultRoleType);
 
240
    Uml::TextRole calculateNameType(Uml::TextRole defaultRoleType);
253
241
 
254
 
    bool isPointInsideBoundaries(int PosX, int PosY, QPoint & SPoint,
255
 
                                 uint & StartSegmentIndex, uint & EndSegmentIndex);
 
242
//    bool isPointInsideBoundaries(int PosX, int PosY, QPoint & SPoint,
 
243
//                                 uint & StartSegmentIndex, uint & EndSegmentIndex);
256
244
 
257
245
    static QPoint swapXY(const QPoint &p);
258
246
 
259
 
    float totalLength();
 
247
//    float totalLength();
260
248
 
261
249
    static QPoint calculatePointAtDistance(const QPoint &P1, const QPoint &P2, float Distance);
262
 
 
263
250
    static QPoint calculatePointAtDistanceOnPerpendicular(const QPoint &P1, const QPoint &P2, float Distance);
264
251
 
265
252
    static float perpendicularProjection(const QPoint& P1, const QPoint& P2, const QPoint& P3, QPoint& ResultingPoint);
266
253
 
267
254
    static QPoint midPoint(const QPoint& p0, const QPoint& p1);
268
255
 
269
 
    QPoint calculateTextPosition(Uml::TextRole role);
270
 
 
271
 
    void setTextPosition(Uml::TextRole role);
272
 
 
273
 
    void setTextPositionRelatively(Uml::TextRole role, const QPoint &oldPosition);
274
 
 
275
 
    Region getWidgetRegion(AssociationWidget * widget) const;
276
 
 
277
 
    /**
278
 
     * This is a pointer to the Floating Text widget which displays the
279
 
     * name of this association.
280
 
     */
281
 
    FloatingTextWidget* m_pName;
 
256
//    Region getWidgetRegion(AssociationWidget * widget) const;
282
257
 
283
258
    /**
284
259
     * The WidgetRole struct gathers all information pertaining to the role.
287
262
     */
288
263
    struct WidgetRole {
289
264
 
290
 
        /**
291
 
         * This is a pointer to the Floating Text widget at the role's side
292
 
         * of the association.
293
 
         * This FloatingTextWidget displays the information regarding multiplicity.
294
 
         */
295
 
        FloatingTextWidget* m_pMulti;
296
 
 
297
 
        /**
298
 
         * This is a pointer to the Floating Text widget at the role's side
299
 
         * of the association.
300
 
         * This FloatingTextWidget displays the information regarding changeability.
301
 
         */
302
 
        FloatingTextWidget* m_pChangeWidget;
303
 
 
304
 
        /**
305
 
         * This member holds a pointer to the floating text that displays
306
 
         * the role's label of this association.
307
 
         */
308
 
        FloatingTextWidget* m_pRole;
309
 
 
310
 
        /**
311
 
         * This member holds a pointer to the UMLWidget at this role's side
312
 
         * of the association.
313
 
         */
314
 
        UMLWidget* m_pWidget;
315
 
 
316
 
        /**
317
 
         * This role's old top left corner before moving.
318
 
         */
319
 
        QPoint m_OldCorner;
320
 
 
321
 
        /**
322
 
         * The region of this role's widget.
323
 
         */
324
 
        Region m_WidgetRegion;
325
 
 
326
 
        /**
327
 
         * The index of where the line is on the region for this role.
328
 
         */
329
 
        int m_nIndex;
330
 
 
331
 
        /**
332
 
         * The total amount of associations on the region this role's line is on.
333
 
         */
334
 
        int m_nTotalCount;
 
265
        FloatingTextWidget* multiplicityWidget;   ///< information regarding multiplicity
 
266
        FloatingTextWidget* changeabilityWidget;  ///< information regarding changeability
 
267
        FloatingTextWidget* roleWidget;           ///< role's label of this association
 
268
 
 
269
        UMLWidget* umlWidget;    ///< UMLWidget at this role's side of this association
 
270
 
 
271
        QPoint m_OldCorner;      ///< old top left corner before moving
 
272
        Region m_WidgetRegion;   ///< region of this role's widget
 
273
 
 
274
        int m_nIndex;        ///< the index of where the line is on the region for this role
 
275
        int m_nTotalCount;   ///< total amount of associations on the region this role's line is on
335
276
 
336
277
        // The following items are only used if m_pObject is not set.
337
 
        Uml::Visibility m_Visibility;
338
 
        Uml::Changeability m_Changeability;
339
 
        QString m_RoleDoc;
340
 
 
341
 
    } m_role[2];
342
 
 
343
 
    void setFloatingText(Uml::TextRole tr, const QString &text, FloatingTextWidget* &ft);
 
278
        Uml::Visibility      visibility;
 
279
        Uml::Changeability   changeability;
 
280
        QString              roleDocumentation;
 
281
 
 
282
    };
344
283
 
345
284
    void updateRegionLineCount(int index, int totalCount,
346
285
                               AssociationWidget::Region region, Uml::Role_Type role);
349
288
 
350
289
    int getRegionCount(Region region, Uml::Role_Type role);
351
290
 
352
 
    void init();
353
 
 
354
291
    void doUpdates(int otherX, int otherY, Uml::Role_Type role);
355
292
 
356
293
    void setChangeWidget(const QString &strChangeWidget, Uml::Role_Type role);
365
302
    int m_positions_len;              ///< auxiliary variable for updateAssociations()
366
303
    AssociationWidgetList m_ordered;  ///< auxiliary variable for updateAssociations()
367
304
 
368
 
    /**
369
 
     * Flag which is true if the activate method has been called for this
370
 
     * class instance.
371
 
     */
372
 
    bool m_activated;
 
305
    bool m_activated;   ///< flag which is true if the activate method has been called for this class instance
373
306
 
374
307
    /**
375
308
     * When the association has a Role Floating Text this text should move
379
312
     * m_associationLine[m_unNameLineSegment] -- m_associationLine[m_unNameLineSegment+1]
380
313
     */
381
314
    uint                m_unNameLineSegment;
382
 
    UMLDoc * m_umldoc;  ///< just a shorthand for UMLApp::app()->getDocument()
 
315
    UMLDoc              *m_umldoc;  ///< just a shorthand for UMLApp::app()->getDocument()
383
316
    ListPopupMenu       *m_pMenu;
384
317
    bool                m_selected;
385
318
    int                 m_nMovingPoint;
386
319
 
387
 
    /**
388
 
     * Position of Name floatingtext saved by saveIdealTextPositions()
389
 
     */
390
 
    QPoint m_oldNamePoint;
391
 
    /**
392
 
     * Position of role A multiplicity floatingtext saved by
393
 
     * saveIdealTextPositions()
394
 
     */
395
 
    QPoint m_oldMultiAPoint;
396
 
    /**
397
 
     * Position of role B multiplicity floatingtext saved by
398
 
     * saveIdealTextPositions()
399
 
     */
400
 
    QPoint m_oldMultiBPoint;
401
 
    /**
402
 
     * Position of role A changeability floatingtext saved by
403
 
     * saveIdealTextPositions()
404
 
     */
405
 
    QPoint m_oldChangeAPoint;
406
 
    /**
407
 
     * Position of role B changeability floatingtext saved by
408
 
     * saveIdealTextPositions()
409
 
     */
410
 
    QPoint m_oldChangeBPoint;
411
 
    /**
412
 
     * Position of role A name floatingtext saved by
413
 
     * saveIdealTextPositions()
414
 
     */
415
 
    QPoint m_oldRoleAPoint;
416
 
    /**
417
 
     * Position of role B name floatingtext saved by
418
 
     * saveIdealTextPositions()
419
 
     */
420
 
    QPoint m_oldRoleBPoint;
 
320
    QPoint m_oldNamePoint;    ///< Position of name floatingtext saved by saveIdealTextPositions()
 
321
    QPoint m_oldMultiAPoint;  ///< Position of role A multiplicity floatingtext saved by saveIdealTextPositions()
 
322
    QPoint m_oldMultiBPoint;  ///< Position of role B multiplicity floatingtext saved by saveIdealTextPositions()
 
323
    QPoint m_oldChangeAPoint; ///< Position of role A changeability floatingtext saved by saveIdealTextPositions()
 
324
    QPoint m_oldChangeBPoint; ///< Position of role B changeability floatingtext saved by saveIdealTextPositions()
 
325
    QPoint m_oldRoleAPoint;   ///< Position of role A name floatingtext saved by saveIdealTextPositions()
 
326
    QPoint m_oldRoleBPoint;   ///< Position of role B name floatingtext saved by saveIdealTextPositions()
421
327
 
422
328
    int         m_nLinePathSegmentIndex; ///< anchor for m_pAssocClassLine
423
329
    UMLSceneLineItem *m_pAssocClassLine;  ///< used for connecting assoc. class
424
330
    /// selection adornment for the endpoints of the assoc. class connecting line
425
 
    UMLSceneRectItem *m_pAssocClassLineSel0, *m_pAssocClassLineSel1;
426
 
 
427
 
    ClassifierWidget *m_pAssocClassWidget;  ///< used if we have an assoc. class
428
 
 
429
 
    /**
430
 
     * The definition points for the association line.
431
 
     */
432
 
    AssociationLine *m_associationLine;
433
 
 
434
 
    // The following items are only used if m_pObject is not set.
435
 
    Uml::AssociationType m_AssocType;
436
 
 
437
 
public slots:
438
 
    void slotMenuSelection(QAction* action);
439
 
    void slotRemovePopupMenu();
440
 
    void slotClearAllSelected();
441
 
    void slotClassifierListItemRemoved(UMLClassifierListItem* obj);
442
 
    void slotAttributeChanged();
443
 
 
444
 
    void syncToModel();
 
331
    UMLSceneRectItem *m_pAssocClassLineSel0;
 
332
    UMLSceneRectItem *m_pAssocClassLineSel1;
 
333
 
 
334
    AssociationLine *m_associationLine;      ///< the definition points for the association line
 
335
    ClassifierWidget *m_associationClass;    ///< used if we have an assoc. class
 
336
    Uml::AssociationType m_associationType;  ///< is only used if m_pObject is not set
 
337
    WidgetRole  m_role[2];
 
338
    FloatingTextWidget* m_nameWidget;  ///< displays the name of this association
 
339
 
445
340
};
 
341
 
446
342
#endif