-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compelete Aggregation and Composition Relation of classdiagram
- Loading branch information
Showing
6 changed files
with
199 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,75 @@ | ||
#include "aggregation.h" | ||
|
||
Aggregation::Aggregation(QObject *parent) : QObject(parent) | ||
#include <QPainter> | ||
#include <QPen> | ||
#include <QtMath> | ||
#include <QDebug> | ||
|
||
Aggregation::Aggregation(QPointF startItem, QPointF endItem, QGraphicsItem *parent): | ||
myStartItem(startItem), myEndItem(endItem) | ||
{ | ||
setAcceptHoverEvents(true); | ||
setZValue(105); | ||
setFlag(QGraphicsItem::ItemIsMovable); | ||
setFlag(QGraphicsItem::ItemIsSelectable); | ||
setFlag(QGraphicsItem::ItemIsFocusable); | ||
} | ||
|
||
QRectF Aggregation::boundingRect() const | ||
{ | ||
return QRectF(myStartItem, myEndItem); | ||
} | ||
|
||
QPainterPath Aggregation::shape() const | ||
{ | ||
QPainterPath path; | ||
|
||
path.addRect(boundingRect()); | ||
|
||
return path; | ||
} | ||
|
||
void Aggregation::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | ||
{ | ||
Q_UNUSED(widget); | ||
|
||
QPen myPen; | ||
|
||
myPen.setColor(myColor); | ||
myPen.setWidth(2); | ||
myPen.setCosmetic(true); | ||
painter->setPen(myPen); | ||
painter->setBrush(myColor); | ||
|
||
painter->save(); | ||
|
||
painter->setRenderHints(QPainter::Antialiasing); | ||
|
||
painter->setBrush(Qt::NoBrush); | ||
|
||
painter->drawLine(myStartItem, myEndItem); | ||
painter->restore(); | ||
|
||
double angle = std::atan2(-(myEndItem.y() - myStartItem.y()), (myEndItem.x() - myStartItem.x())); | ||
QPointF arrowP1 = myStartItem + QPointF(sin(angle + M_PI / 3) * 20, | ||
cos(angle + M_PI / 3) * 20); | ||
QPointF arrowP2 = myStartItem + QPointF(sin(angle + M_PI - M_PI / 3) * 20, | ||
cos(angle + M_PI - M_PI / 3) * 20); | ||
|
||
arrowHead.clear(); | ||
|
||
painter->save(); | ||
painter->setBrush(Qt::white); | ||
QLineF tmp(myStartItem, myEndItem); | ||
tmp.setLength(35); | ||
auto test_point = tmp.p2(); | ||
|
||
arrowHead << myStartItem << arrowP1 << test_point << arrowP2; | ||
painter->drawPolygon(arrowHead); | ||
painter->restore(); | ||
} | ||
|
||
void Aggregation::setMyColor(const QColor &value) | ||
{ | ||
myColor = value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,71 @@ | ||
#include "composition.h" | ||
#include <QPainter> | ||
#include <QPen> | ||
#include <QtMath> | ||
#include <QDebug> | ||
|
||
Composition::Composition(QObject *parent) : QObject(parent) | ||
Composition::Composition(QPointF startItem, QPointF endItem, QGraphicsItem *parent): | ||
myStartItem(startItem), myEndItem(endItem) | ||
{ | ||
setAcceptHoverEvents(true); | ||
setZValue(105); | ||
setFlag(QGraphicsItem::ItemIsMovable); | ||
setFlag(QGraphicsItem::ItemIsSelectable); | ||
setFlag(QGraphicsItem::ItemIsFocusable); | ||
} | ||
|
||
QRectF Composition::boundingRect() const | ||
{ | ||
return QRectF(myStartItem, myEndItem); | ||
} | ||
|
||
QPainterPath Composition::shape() const | ||
{ | ||
QPainterPath path; | ||
|
||
path.addRect(boundingRect()); | ||
|
||
return path; | ||
} | ||
|
||
void Composition::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | ||
{ | ||
Q_UNUSED(widget); | ||
|
||
QPen myPen; | ||
|
||
myPen.setColor(myColor); | ||
myPen.setWidth(2); | ||
myPen.setCosmetic(true); | ||
painter->setPen(myPen); | ||
painter->setBrush(myColor); | ||
|
||
painter->save(); | ||
|
||
painter->setRenderHints(QPainter::Antialiasing); | ||
|
||
painter->setBrush(Qt::NoBrush); | ||
|
||
painter->drawLine(myStartItem, myEndItem); | ||
painter->restore(); | ||
|
||
double angle = std::atan2(-(myEndItem.y() - myStartItem.y()), (myEndItem.x() - myStartItem.x())); | ||
QPointF arrowP1 = myStartItem + QPointF(sin(angle + M_PI / 3) * 20, | ||
cos(angle + M_PI / 3) * 20); | ||
QPointF arrowP2 = myStartItem + QPointF(sin(angle + M_PI - M_PI / 3) * 20, | ||
cos(angle + M_PI - M_PI / 3) * 20); | ||
|
||
arrowHead.clear(); | ||
|
||
QLineF tmp(myStartItem, myEndItem); | ||
tmp.setLength(35); | ||
auto test_point = tmp.p2(); | ||
|
||
arrowHead << myStartItem << arrowP1 << test_point << arrowP2; | ||
painter->drawPolygon(arrowHead); | ||
} | ||
|
||
void Composition::setMyColor(const QColor &value) | ||
{ | ||
myColor = value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters