summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalf Habacker <[email protected]>2017-03-07 14:03:30 +0100
committerRalf Habacker <[email protected]>2017-05-08 10:53:50 +0200
commit028ecc83cb37b6ef9c6a4c69169e8a503a496336 (patch)
treec059a635e5cb6c1fba5b58deda11a9c71ab621d0
parent0648bc9f33d1e9a448b2b183d1bc89e0c6c62a74 (diff)
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
-rw-r--r--umbrello/associationwidgetlist.h5
-rw-r--r--umbrello/umlwidgets/classifierwidget.cpp6
-rw-r--r--umbrello/umlwidgets/umlwidget.cpp23
-rw-r--r--umbrello/umlwidgets/umlwidget.h12
4 files changed, 25 insertions, 21 deletions
diff --git a/umbrello/associationwidgetlist.h b/umbrello/associationwidgetlist.h
index 838e7c0..63979bf 100644
--- a/umbrello/associationwidgetlist.h
+++ b/umbrello/associationwidgetlist.h
@@ -13,11 +13,12 @@
#define ASSOCIATIONWIDGETLIST_H
#include <QList>
+#include <QPointer>
// forward declarations
class AssociationWidget;
-typedef QList<AssociationWidget*> AssociationWidgetList;
-typedef QListIterator<AssociationWidget*> AssociationWidgetListIt;
+typedef QList<QPointer<AssociationWidget>> AssociationWidgetList;
+typedef QListIterator<QPointer<AssociationWidget>> AssociationWidgetListIt;
#endif
diff --git a/umbrello/umlwidgets/classifierwidget.cpp b/umbrello/umlwidgets/classifierwidget.cpp
index e3ac90d..30c5669 100644
--- a/umbrello/umlwidgets/classifierwidget.cpp
+++ b/umbrello/umlwidgets/classifierwidget.cpp
@@ -911,7 +911,7 @@ void ClassifierWidget::drawAsCircle(QPainter *painter, const QStyleOptionGraphic
{
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);
// Draw socket for required interface.
const qreal angleSpan = 180; // 360.0 / (m_Assocs.size() + 1.0);
@@ -920,7 +920,7 @@ void ClassifierWidget::drawAsCircle(QPainter *painter, const QStyleOptionGraphic
const QPointF center(x() + w/2, y() + arcDiameter/2);
const qreal cX = center.x();
const qreal cY = center.y();
- foreach (AssociationWidget *aw, m_Assocs) {
+ foreach (AssociationWidget *aw, associationWidgetList()) {
const Uml::AssociationType::Enum aType = aw->associationType();
if (aType == Uml::AssociationType::UniAssociation ||
aType == Uml::AssociationType::Association) // provider
@@ -981,7 +981,7 @@ void ClassifierWidget::drawAsCircle(QPainter *painter, const QStyleOptionGraphic
QSize ClassifierWidget::calculateAsCircleSize() const
{
int circleSize = CIRCLE_SIZE;
- if (m_Assocs.size() > 1)
+ if (associationWidgetList().size() > 1)
circleSize += SOCKET_INCREMENT;
return QSize(circleSize, circleSize);
}
diff --git a/umbrello/umlwidgets/umlwidget.cpp b/umbrello/umlwidgets/umlwidget.cpp
index 6ff8fa8..8979ec0 100644
--- a/umbrello/umlwidgets/umlwidget.cpp
+++ b/umbrello/umlwidgets/umlwidget.cpp
@@ -1102,19 +1102,28 @@ void UMLWidget::setActivated(bool active /*=true*/)
*/
void UMLWidget::addAssoc(AssociationWidget* pAssoc)
{
- if (pAssoc && !m_Assocs.contains(pAssoc)) {
- m_Assocs.append(pAssoc);
+ if (pAssoc && !associationWidgetList().contains(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
* associations that include this UMLWidget
*/
void UMLWidget::removeAssoc(AssociationWidget* pAssoc)
{
if (pAssoc) {
- m_Assocs.removeAll(pAssoc);
+ associationWidgetList().removeAll(pAssoc);
}
}
@@ -1139,11 +1148,11 @@ void UMLWidget::adjustAssocs(qreal dx, qreal dy)
return;
}
- foreach(AssociationWidget* assocwidget, m_Assocs) {
+ foreach(AssociationWidget* assocwidget, associationWidgetList()) {
assocwidget->saveIdealTextPositions();
}
- foreach(AssociationWidget* assocwidget, m_Assocs) {
+ foreach(AssociationWidget* assocwidget, associationWidgetList()) {
assocwidget->widgetMoved(this, dx, dy);
}
}
@@ -1156,12 +1165,12 @@ void UMLWidget::adjustAssocs(qreal dx, qreal dy)
*/
void UMLWidget::adjustUnselectedAssocs(qreal dx, qreal dy)
{
- foreach(AssociationWidget* assocwidget, m_Assocs) {
+ foreach(AssociationWidget* assocwidget, associationWidgetList()) {
if (!assocwidget->isSelected())
assocwidget->saveIdealTextPositions();
}
- foreach(AssociationWidget* assocwidget, m_Assocs) {
+ foreach(AssociationWidget* assocwidget, associationWidgetList()) {
if (!assocwidget->isSelected()) {
assocwidget->widgetMoved(this, dx, dy);
}
diff --git a/umbrello/umlwidgets/umlwidget.h b/umbrello/umlwidgets/umlwidget.h
index a84ff5e..614c5c8 100644
--- a/umbrello/umlwidgets/umlwidget.h
+++ b/umbrello/umlwidgets/umlwidget.h
@@ -137,12 +137,7 @@ public:
void removeAssoc(AssociationWidget* pAssoc);
void addAssoc(AssociationWidget* pAssoc);
- /**
- * Returns the list of associations connected to this widget.
- */
- AssociationWidgetList & associationWidgetList() {
- return m_Assocs;
- }
+ AssociationWidgetList &associationWidgetList() const;
/**
* Read property of bool m_isInstance
@@ -281,9 +276,6 @@ protected:
///////////////// 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)
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
@@ -344,5 +336,7 @@ private:
void init();
void toForeground();
+ /// A list of AssociationWidgets between the UMLWidget and other UMLWidgets in the diagram
+ mutable AssociationWidgetList m_Assocs;
};
#endif