Commit c14b580a authored by Ralf Habacker's avatar Ralf Habacker

Fix 'No change of association symbol line colour and width possible'.

The bug is caused by two issues:

1. line color changes are not routed through the virtual method setLineColor()
2. class AssociationLine did not propagate line color changes to the related symbols.

This patch includes a minor refactoring in class AssociationLine
to provide the standard pen based api, which is required to set symbol pen.

BUG:358358
CCBUG:358365
FIXED-IN:2.18.2 (KDE Applications 15.12.2)
parent 401f9410
......@@ -392,22 +392,37 @@ QBrush AssociationLine::brush() const
}
/**
* Returns the type of pen to use depending on the type of Association.
* Returns the pen used for drawing.
*/
QPen AssociationLine::pen() const
{
QPen pen(m_associationWidget->lineColor(),
m_associationWidget->lineWidth(),
Qt::SolidLine,
Qt::RoundCap,
Qt::RoundJoin);
return m_pen;
}
/**
* Setup new pen.
*/
void AssociationLine::setPen(const QPen &pen)
{
if (m_startSymbol)
m_startSymbol->setPen(pen);
if (m_subsetSymbol)
m_subsetSymbol->setPen(pen);
if (m_endSymbol)
m_endSymbol->setPen(pen);
m_pen = pen;
m_pen.setCapStyle(Qt::RoundCap);
m_pen.setJoinStyle(Qt::RoundJoin);
Uml::AssociationType::Enum type = m_associationWidget->associationType();
if (type == Uml::AssociationType::Dependency ||
type == Uml::AssociationType::Realization ||
type == Uml::AssociationType::Anchor) {
pen.setStyle(Qt::DashLine);
m_pen.setStyle(Qt::DashLine);
}
else {
m_pen.setStyle(Qt::SolidLine);
}
return pen;
}
/**
......
......@@ -148,6 +148,7 @@ public:
QBrush brush() const;
QPen pen() const;
void setPen(const QPen &pen);
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
......@@ -195,6 +196,7 @@ private:
QGraphicsLineItem *m_collaborationLineItem; ///< parallel arrow line drawn in case of collaboration message
Symbol *m_collaborationLineHead; ///< arrow head drawn at end of m_collaborationLineItem
LayoutType m_layout;
QPen m_pen; ///< pen used to draw an association line
static QPainterPath createBezierCurve(QVector<QPointF> points);
static QPainterPath createOrthogonalPath(QVector<QPointF> points);
......
......@@ -3239,6 +3239,22 @@ void AssociationWidget::setTextColor(const QColor &color)
m_role[RoleType::B].changeabilityWidget->setTextColor(color);
}
void AssociationWidget::setLineColor(const QColor &color)
{
WidgetBase::setLineColor(color);
QPen pen = m_associationLine->pen();
pen.setColor(color);
m_associationLine->setPen(pen);
}
void AssociationWidget::setLineWidth(uint width)
{
WidgetBase::setLineWidth(width);
QPen pen = m_associationLine->pen();
pen.setWidth(width);
m_associationLine->setPen(pen);
}
bool AssociationWidget::checkAddPoint(const QPointF &scenePos)
{
if (associationType() == AssociationType::Exception) {
......
......@@ -174,6 +174,8 @@ public:
QFont font() const;
virtual void setTextColor(const QColor &color);
virtual void setLineColor(const QColor &color);
virtual void setLineWidth(uint width);
void calculateEndingPoints();
......
......@@ -30,7 +30,7 @@ BoxWidget::BoxWidget(UMLScene * scene, Uml::ID::Type id, WidgetType type)
{
setSize(100, 80);
m_usesDiagramLineColor = false; // boxes be black
m_lineColor = QColor("black");
setLineColor(QColor("black"));
setZValue(-10);
}
......
......@@ -45,7 +45,6 @@ WidgetBase::WidgetBase(UMLScene *scene, WidgetType type)
m_scene(scene),
m_umlObject(0),
m_textColor(QColor("black")),
m_lineColor(QColor("black")),
m_fillColor(QColor("yellow")),
m_brush(m_fillColor),
m_lineWidth(0), // initialize with 0 to have valid start condition
......@@ -54,6 +53,7 @@ WidgetBase::WidgetBase(UMLScene *scene, WidgetType type)
m_usesDiagramLineColor(true),
m_usesDiagramLineWidth(true)
{
setLineColor(QColor("black"));
setSelected(false);
scene->addItem(this);
......@@ -66,8 +66,8 @@ WidgetBase::WidgetBase(UMLScene *scene, WidgetType type)
m_usesDiagramTextColor = true;
const Settings::OptionState& optionState = m_scene->optionState();
m_textColor = optionState.uiState.textColor;
m_lineColor = optionState.uiState.lineColor;
m_lineWidth = optionState.uiState.lineWidth;
setLineColor(optionState.uiState.lineColor);
setLineWidth(optionState.uiState.lineWidth);
m_font = optionState.uiState.font;
} else {
uError() << "WidgetBase constructor: SERIOUS PROBLEM - m_scene is NULL";
......@@ -529,18 +529,18 @@ bool WidgetBase::loadFromXMI(QDomElement& qElement)
QString lineColor = qElement.attribute(QLatin1String("linecolour"), QLatin1String("none"));
lineColor = qElement.attribute(QLatin1String("linecolor"), lineColor);
if (lineColor != QLatin1String("none")) {
m_lineColor = QColor(lineColor);
setLineColor(QColor(lineColor));
m_usesDiagramLineColor = false;
} else if (m_baseType != WidgetBase::wt_Box && m_scene != NULL) {
m_lineColor = m_scene->lineColor();
setLineColor(m_scene->lineColor());
m_usesDiagramLineColor = true;
}
QString lineWidth = qElement.attribute(QLatin1String("linewidth"), QLatin1String("none"));
if (lineWidth != QLatin1String("none")) {
m_lineWidth = lineWidth.toInt();
setLineWidth(lineWidth.toInt());
m_usesDiagramLineWidth = false;
} else if (m_scene) {
m_lineWidth = m_scene->lineWidth();
setLineWidth(m_scene->lineWidth());
m_usesDiagramLineWidth = true;
}
QString textColor = qElement.attribute(QLatin1String("textcolor"), QLatin1String("none"));
......@@ -597,7 +597,7 @@ WidgetBase& WidgetBase::operator=(const WidgetBase& other)
m_Text = other.m_Text;
m_nId = other.m_nId;
m_textColor = other.m_textColor;
m_lineColor = other.m_lineColor;
setLineColor(other.lineColor());
m_fillColor = other.m_fillColor;
m_brush = other.m_brush;
m_font = other.m_font;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment