Commit 028ecc83 authored by Ralf Habacker's avatar Ralf Habacker

Make access to UMLWidget class member m_Assocs more crash save.

- Use QPointer in typedef AssociationWidgetList
- avoid direct access to class member m_Assocs
- Remove obsolate zero pointers on access to list instances
parent 0648bc9f
...@@ -13,11 +13,12 @@ ...@@ -13,11 +13,12 @@
#define ASSOCIATIONWIDGETLIST_H #define ASSOCIATIONWIDGETLIST_H
#include <QList> #include <QList>
#include <QPointer>
// forward declarations // forward declarations
class AssociationWidget; class AssociationWidget;
typedef QList<AssociationWidget*> AssociationWidgetList; typedef QList<QPointer<AssociationWidget>> AssociationWidgetList;
typedef QListIterator<AssociationWidget*> AssociationWidgetListIt; typedef QListIterator<QPointer<AssociationWidget>> AssociationWidgetListIt;
#endif #endif
...@@ -911,7 +911,7 @@ void ClassifierWidget::drawAsCircle(QPainter *painter, const QStyleOptionGraphic ...@@ -911,7 +911,7 @@ void ClassifierWidget::drawAsCircle(QPainter *painter, const QStyleOptionGraphic
{ {
const int w = width(); const int w = width();
if (m_Assocs.size() > 1) { if (associationWidgetList().size() > 1) {
painter->drawEllipse(w/2 - CIRCLE_SIZE/2, SOCKET_INCREMENT / 2, CIRCLE_SIZE, CIRCLE_SIZE); painter->drawEllipse(w/2 - CIRCLE_SIZE/2, SOCKET_INCREMENT / 2, CIRCLE_SIZE, CIRCLE_SIZE);
// Draw socket for required interface. // Draw socket for required interface.
const qreal angleSpan = 180; // 360.0 / (m_Assocs.size() + 1.0); const qreal angleSpan = 180; // 360.0 / (m_Assocs.size() + 1.0);
...@@ -920,7 +920,7 @@ void ClassifierWidget::drawAsCircle(QPainter *painter, const QStyleOptionGraphic ...@@ -920,7 +920,7 @@ void ClassifierWidget::drawAsCircle(QPainter *painter, const QStyleOptionGraphic
const QPointF center(x() + w/2, y() + arcDiameter/2); const QPointF center(x() + w/2, y() + arcDiameter/2);
const qreal cX = center.x(); const qreal cX = center.x();
const qreal cY = center.y(); const qreal cY = center.y();
foreach (AssociationWidget *aw, m_Assocs) { foreach (AssociationWidget *aw, associationWidgetList()) {
const Uml::AssociationType::Enum aType = aw->associationType(); const Uml::AssociationType::Enum aType = aw->associationType();
if (aType == Uml::AssociationType::UniAssociation || if (aType == Uml::AssociationType::UniAssociation ||
aType == Uml::AssociationType::Association) // provider aType == Uml::AssociationType::Association) // provider
...@@ -981,7 +981,7 @@ void ClassifierWidget::drawAsCircle(QPainter *painter, const QStyleOptionGraphic ...@@ -981,7 +981,7 @@ void ClassifierWidget::drawAsCircle(QPainter *painter, const QStyleOptionGraphic
QSize ClassifierWidget::calculateAsCircleSize() const QSize ClassifierWidget::calculateAsCircleSize() const
{ {
int circleSize = CIRCLE_SIZE; int circleSize = CIRCLE_SIZE;
if (m_Assocs.size() > 1) if (associationWidgetList().size() > 1)
circleSize += SOCKET_INCREMENT; circleSize += SOCKET_INCREMENT;
return QSize(circleSize, circleSize); return QSize(circleSize, circleSize);
} }
......
...@@ -1102,11 +1102,20 @@ void UMLWidget::setActivated(bool active /*=true*/) ...@@ -1102,11 +1102,20 @@ void UMLWidget::setActivated(bool active /*=true*/)
*/ */
void UMLWidget::addAssoc(AssociationWidget* pAssoc) void UMLWidget::addAssoc(AssociationWidget* pAssoc)
{ {
if (pAssoc && !m_Assocs.contains(pAssoc)) { if (pAssoc && !associationWidgetList().contains(pAssoc)) {
m_Assocs.append(pAssoc); associationWidgetList().append(pAssoc);
} }
} }
/**
* Returns the list of associations connected to this widget.
*/
AssociationWidgetList &UMLWidget::associationWidgetList() const
{
m_Assocs.removeAll(0);
return m_Assocs;
}
/** /**
* Removes an already created association from the list of * Removes an already created association from the list of
* associations that include this UMLWidget * associations that include this UMLWidget
...@@ -1114,7 +1123,7 @@ void UMLWidget::addAssoc(AssociationWidget* pAssoc) ...@@ -1114,7 +1123,7 @@ void UMLWidget::addAssoc(AssociationWidget* pAssoc)
void UMLWidget::removeAssoc(AssociationWidget* pAssoc) void UMLWidget::removeAssoc(AssociationWidget* pAssoc)
{ {
if (pAssoc) { if (pAssoc) {
m_Assocs.removeAll(pAssoc); associationWidgetList().removeAll(pAssoc);
} }
} }
...@@ -1139,11 +1148,11 @@ void UMLWidget::adjustAssocs(qreal dx, qreal dy) ...@@ -1139,11 +1148,11 @@ void UMLWidget::adjustAssocs(qreal dx, qreal dy)
return; return;
} }
foreach(AssociationWidget* assocwidget, m_Assocs) { foreach(AssociationWidget* assocwidget, associationWidgetList()) {
assocwidget->saveIdealTextPositions(); assocwidget->saveIdealTextPositions();
} }
foreach(AssociationWidget* assocwidget, m_Assocs) { foreach(AssociationWidget* assocwidget, associationWidgetList()) {
assocwidget->widgetMoved(this, dx, dy); assocwidget->widgetMoved(this, dx, dy);
} }
} }
...@@ -1156,12 +1165,12 @@ void UMLWidget::adjustAssocs(qreal dx, qreal dy) ...@@ -1156,12 +1165,12 @@ void UMLWidget::adjustAssocs(qreal dx, qreal dy)
*/ */
void UMLWidget::adjustUnselectedAssocs(qreal dx, qreal dy) void UMLWidget::adjustUnselectedAssocs(qreal dx, qreal dy)
{ {
foreach(AssociationWidget* assocwidget, m_Assocs) { foreach(AssociationWidget* assocwidget, associationWidgetList()) {
if (!assocwidget->isSelected()) if (!assocwidget->isSelected())
assocwidget->saveIdealTextPositions(); assocwidget->saveIdealTextPositions();
} }
foreach(AssociationWidget* assocwidget, m_Assocs) { foreach(AssociationWidget* assocwidget, associationWidgetList()) {
if (!assocwidget->isSelected()) { if (!assocwidget->isSelected()) {
assocwidget->widgetMoved(this, dx, dy); assocwidget->widgetMoved(this, dx, dy);
} }
......
...@@ -137,12 +137,7 @@ public: ...@@ -137,12 +137,7 @@ public:
void removeAssoc(AssociationWidget* pAssoc); void removeAssoc(AssociationWidget* pAssoc);
void addAssoc(AssociationWidget* pAssoc); void addAssoc(AssociationWidget* pAssoc);
/** AssociationWidgetList &associationWidgetList() const;
* Returns the list of associations connected to this widget.
*/
AssociationWidgetList & associationWidgetList() {
return m_Assocs;
}
/** /**
* Read property of bool m_isInstance * Read property of bool m_isInstance
...@@ -281,9 +276,6 @@ protected: ...@@ -281,9 +276,6 @@ protected:
///////////////// Data Loaded/Saved ///////////////////////////////// ///////////////// Data Loaded/Saved /////////////////////////////////
/// A list of AssociationWidgets between the UMLWidget and other UMLWidgets in the diagram
AssociationWidgetList m_Assocs;
QString m_instanceName; ///< instance name (used if on a deployment diagram) QString m_instanceName; ///< instance name (used if on a deployment diagram)
bool m_isInstance; ///< holds whether this widget is a component instance (i.e. on a deployment diagram) bool m_isInstance; ///< holds whether this widget is a component instance (i.e. on a deployment diagram)
bool m_showStereotype; ///< should the stereotype be displayed bool m_showStereotype; ///< should the stereotype be displayed
...@@ -344,5 +336,7 @@ private: ...@@ -344,5 +336,7 @@ private:
void init(); void init();
void toForeground(); void toForeground();
/// A list of AssociationWidgets between the UMLWidget and other UMLWidgets in the diagram
mutable AssociationWidgetList m_Assocs;
}; };
#endif #endif
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