Commit 959be508 authored by Oliver Kellogg's avatar Oliver Kellogg
Browse files

Change StereotypesModel member m_stereotypes from pointer to reference:

umbrello/models/stereotypesmodel.h
- Change member m_stereotypes from pointer to reference.
- At constructor change UMLStereotypeList argument from pointer to
  reference.

umbrello/models/stereotypesmodel.cpp
- Adjust code manipulating m_stereotypes to the above change.
- In function addStereotype, if the passed in pointer is not found in
  m_stereotypes then compare the passed in stereotype's name to the
  names in m_stereotypes. If a match is found then do not add the
  pointer passed in.
- In function removeStereotype, if the passed in pointer is not found in
  m_stereotypes then compare the passed in stereotype's name to the
  names in m_stereotypes:
  - If no match is found then return false without attempting removal.
  - If a match is found then remove the matching pointer.

umbrello/umldoc.cpp
- In constructor, on initializing m_stereotypesModel pass m_stereoList
  to constructor of StereotypesModel by reference instead of address.
parent d6ff4174
......@@ -4,7 +4,7 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* copyright (C) 2015 *
* copyright (C) 2015-2021 *
* Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
***************************************************************************/
......@@ -21,7 +21,7 @@
// qt includes
#include <QtDebug>
StereotypesModel::StereotypesModel(UMLStereotypeList *stereotypes)
StereotypesModel::StereotypesModel(UMLStereotypeList& stereotypes)
: m_count(0),
m_stereotypes(stereotypes)
{
......@@ -31,7 +31,7 @@ int StereotypesModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
int count = m_stereotypes->count();
int count = m_stereotypes.count();
return count;
}
......@@ -63,7 +63,7 @@ QVariant StereotypesModel::data(const QModelIndex & index, int role) const
{
if (role == Qt::UserRole && index.column() == 0) {
QVariant v;
v.setValue(m_stereotypes->at(index.row()));
v.setValue(m_stereotypes.at(index.row()));
return v;
}
......@@ -74,7 +74,7 @@ QVariant StereotypesModel::data(const QModelIndex & index, int role) const
if (index.column() >= cCount)
return QVariant();
UMLStereotype *s = m_stereotypes->at(index.row());
UMLStereotype *s = m_stereotypes.at(index.row());
if (cCount == 1) {
QString a = s->name() + QString(QLatin1String(" (%1)")).arg(s->refCount());
return a;
......@@ -89,22 +89,37 @@ QVariant StereotypesModel::data(const QModelIndex & index, int role) const
bool StereotypesModel::addStereotype(UMLStereotype *stereotype)
{
if (m_stereotypes->contains(stereotype))
if (m_stereotypes.contains(stereotype))
return false;
int index = m_stereotypes->count();
foreach (UMLStereotype *s, m_stereotypes) {
if (s->name() == stereotype->name()) {
return false;
}
}
int index = m_stereotypes.count();
beginInsertRows(QModelIndex(), index, index);
m_stereotypes->append(stereotype);
m_stereotypes.append(stereotype);
endInsertRows();
return true;
}
bool StereotypesModel::removeStereotype(UMLStereotype *stereotype)
{
if (!m_stereotypes->contains(stereotype))
return false;
int index = m_stereotypes->indexOf(stereotype);
if (!m_stereotypes.contains(stereotype)) {
UMLStereotype *stFound = 0;
foreach (UMLStereotype *s, m_stereotypes) {
if (s->name() == stereotype->name()) {
stFound = s;
break;
}
}
if (stFound == 0)
return false;
stereotype = stFound;
}
int index = m_stereotypes.indexOf(stereotype);
beginRemoveRows(QModelIndex(), index, index);
m_stereotypes->removeAll(stereotype);
m_stereotypes.removeAll(stereotype);
endRemoveRows();
return true;
}
......
......@@ -4,7 +4,7 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* copyright (C) 2015 *
* copyright (C) 2015-2021 *
* Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
***************************************************************************/
......@@ -25,7 +25,7 @@ class StereotypesModel : public QAbstractTableModel
{
Q_OBJECT
public:
explicit StereotypesModel(UMLStereotypeList *stereotypes);
explicit StereotypesModel(UMLStereotypeList& stereotypes);
int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const;
......@@ -41,7 +41,7 @@ public:
protected:
int m_count;
UMLStereotypeList *m_stereotypes;
UMLStereotypeList& m_stereotypes;
};
#endif // STEREOTYPESMODEL_H
......@@ -131,7 +131,7 @@ UMLDoc::UMLDoc()
m_bClosing(false),
m_diagramsModel(new DiagramsModel),
m_objectsModel(new ObjectsModel),
m_stereotypesModel(new StereotypesModel(&m_stereoList)),
m_stereotypesModel(new StereotypesModel(m_stereoList)),
m_resolution(0.0)
{
for (int i = 0; i < Uml::ModelType::N_MODELTYPES; ++i)
......
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