forked from qt-creator/qt-creator
ModelEditor: Introduce QMT_ASSERT
This change shall solve a lot of Coverity findings Change-Id: I1e699f7363426e9b6008fc77d3f498fe3d968b4f Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -66,7 +66,7 @@ void DFactory::visitMElement(const MElement *element)
|
||||
void DFactory::visitMObject(const MObject *object)
|
||||
{
|
||||
auto diagramObject = dynamic_cast<DObject *>(m_product);
|
||||
QMT_CHECK(diagramObject);
|
||||
QMT_ASSERT(diagramObject, return);
|
||||
diagramObject->setModelUid(object->uid());
|
||||
visitMElement(object);
|
||||
}
|
||||
@@ -120,7 +120,7 @@ void DFactory::visitMItem(const MItem *item)
|
||||
void DFactory::visitMRelation(const MRelation *relation)
|
||||
{
|
||||
auto diagramRelation = dynamic_cast<DRelation *>(m_product);
|
||||
QMT_CHECK(diagramRelation);
|
||||
QMT_ASSERT(diagramRelation, return);
|
||||
diagramRelation->setModelUid(relation->uid());
|
||||
visitMElement(relation);
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ void DFlatAssignmentVisitor::visitDObject(const DObject *object)
|
||||
{
|
||||
visitDElement(object);
|
||||
auto target = dynamic_cast<DObject *>(m_target);
|
||||
QMT_CHECK(target);
|
||||
QMT_ASSERT(target, return);
|
||||
target->setStereotypes(object->stereotypes());
|
||||
target->setName(object->name());
|
||||
target->setPos(object->pos());
|
||||
@@ -81,7 +81,7 @@ void DFlatAssignmentVisitor::visitDClass(const DClass *klass)
|
||||
{
|
||||
visitDObject(klass);
|
||||
auto target = dynamic_cast<DClass *>(m_target);
|
||||
QMT_CHECK(target);
|
||||
QMT_ASSERT(target, return);
|
||||
target->setUmlNamespace(klass->umlNamespace());
|
||||
target->setTemplateParameters(klass->templateParameters());
|
||||
target->setTemplateDisplay(klass->templateDisplay());
|
||||
@@ -94,7 +94,7 @@ void DFlatAssignmentVisitor::visitDComponent(const DComponent *component)
|
||||
{
|
||||
visitDObject(component);
|
||||
auto target = dynamic_cast<DComponent *>(m_target);
|
||||
QMT_CHECK(target);
|
||||
QMT_ASSERT(target, return);
|
||||
target->setPlainShape(component->isPlainShape());
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ void DFlatAssignmentVisitor::visitDItem(const DItem *item)
|
||||
{
|
||||
visitDObject(item);
|
||||
auto target = dynamic_cast<DItem *>(m_target);
|
||||
QMT_CHECK(target);
|
||||
QMT_ASSERT(target, return);
|
||||
target->setVariety(target->variety());
|
||||
target->setShapeEditable(target->isShapeEditable());
|
||||
target->setShape(target->shape());
|
||||
@@ -117,7 +117,7 @@ void DFlatAssignmentVisitor::visitDRelation(const DRelation *relation)
|
||||
{
|
||||
visitDElement(relation);
|
||||
auto target = dynamic_cast<DRelation *>(m_target);
|
||||
QMT_CHECK(target);
|
||||
QMT_ASSERT(target, return);
|
||||
target->setStereotypes(relation->stereotypes());
|
||||
target->setIntermediatePoints(relation->intermediatePoints());
|
||||
}
|
||||
@@ -131,7 +131,7 @@ void DFlatAssignmentVisitor::visitDDependency(const DDependency *dependency)
|
||||
{
|
||||
visitDRelation(dependency);
|
||||
auto target = dynamic_cast<DDependency *>(m_target);
|
||||
QMT_CHECK(target);
|
||||
QMT_ASSERT(target, return);
|
||||
target->setDirection(dependency->direction());
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ void DFlatAssignmentVisitor::visitDAssociation(const DAssociation *association)
|
||||
{
|
||||
visitDRelation(association);
|
||||
auto target = dynamic_cast<DAssociation *>(m_target);
|
||||
QMT_CHECK(target);
|
||||
QMT_ASSERT(target, return);
|
||||
target->setEndA(association->endA());
|
||||
target->setEndB(association->endB());
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ private:
|
||||
MDiagram *diagram = this->diagram();
|
||||
foreach (DElement *clonedElement, m_clonedElements) {
|
||||
DElement *activeElement = diagramController->findElement(clonedElement->uid(), diagram);
|
||||
QMT_CHECK(activeElement);
|
||||
QMT_ASSERT(activeElement, return);
|
||||
int row = diagram->diagramElements().indexOf(activeElement);
|
||||
emit diagramController->beginUpdateElement(row, diagram);
|
||||
// clone active element
|
||||
@@ -198,9 +198,9 @@ protected:
|
||||
Clone &clone = m_clonedElements[i];
|
||||
QMT_CHECK(!clone.m_clonedElement);
|
||||
DElement *activeElement = diagramController->findElement(clone.m_elementKey, diagram);
|
||||
QMT_CHECK(activeElement);
|
||||
QMT_ASSERT(activeElement, return);
|
||||
clone.m_indexOfElement = diagram->diagramElements().indexOf(activeElement);
|
||||
QMT_CHECK(clone.m_indexOfElement >= 0);
|
||||
QMT_ASSERT(clone.m_indexOfElement >= 0, return);
|
||||
emit diagramController->beginRemoveElement(clone.m_indexOfElement, diagram);
|
||||
DCloneDeepVisitor cloneVisitor;
|
||||
activeElement->accept(&cloneVisitor);
|
||||
@@ -221,7 +221,7 @@ protected:
|
||||
bool inserted = false;
|
||||
for (int i = m_clonedElements.count() - 1; i >= 0; --i) {
|
||||
Clone &clone = m_clonedElements[i];
|
||||
QMT_CHECK(clone.m_clonedElement);
|
||||
QMT_ASSERT(clone.m_clonedElement, return);
|
||||
QMT_CHECK(clone.m_clonedElement->uid() == clone.m_elementKey);
|
||||
emit diagramController->beginInsertElement(clone.m_indexOfElement, diagram);
|
||||
diagram->insertDiagramElement(clone.m_indexOfElement, clone.m_clonedElement);
|
||||
@@ -287,7 +287,7 @@ public:
|
||||
DCloneDeepVisitor visitor;
|
||||
element->accept(&visitor);
|
||||
clone.m_clonedElement = visitor.cloned();
|
||||
QMT_CHECK(clone.m_clonedElement);
|
||||
QMT_ASSERT(clone.m_clonedElement, return);
|
||||
m_clonedElements.append(clone);
|
||||
}
|
||||
|
||||
@@ -424,7 +424,7 @@ void DiagramController::removeElement(DElement *element, MDiagram *diagram)
|
||||
|
||||
DElement *DiagramController::findElement(const Uid &key, const MDiagram *diagram) const
|
||||
{
|
||||
QMT_CHECK(diagram);
|
||||
QMT_ASSERT(diagram, return nullptr);
|
||||
|
||||
return diagram->findDiagramElement(key);
|
||||
}
|
||||
@@ -476,7 +476,7 @@ DContainer DiagramController::cutElements(const DSelection &diagramSelection, MD
|
||||
|
||||
DContainer DiagramController::copyElements(const DSelection &diagramSelection, const MDiagram *diagram)
|
||||
{
|
||||
QMT_CHECK(diagram);
|
||||
QMT_ASSERT(diagram, return DContainer());
|
||||
|
||||
DReferences simplifiedSelection = simplify(diagramSelection, diagram);
|
||||
DContainer copiedElements;
|
||||
@@ -491,7 +491,7 @@ DContainer DiagramController::copyElements(const DSelection &diagramSelection, c
|
||||
|
||||
void DiagramController::pasteElements(const DContainer &diagramContainer, MDiagram *diagram)
|
||||
{
|
||||
QMT_CHECK(diagram);
|
||||
QMT_ASSERT(diagram, return);
|
||||
|
||||
// clone all elements and renew their keys
|
||||
QHash<Uid, Uid> renewedKeys;
|
||||
@@ -593,7 +593,7 @@ void DiagramController::onBeginUpdateObject(int row, const MObject *parent)
|
||||
void DiagramController::onEndUpdateObject(int row, const MObject *parent)
|
||||
{
|
||||
MObject *modelObject = m_modelController->object(row, parent);
|
||||
QMT_CHECK(modelObject);
|
||||
QMT_ASSERT(modelObject, return);
|
||||
auto modelPackage = dynamic_cast<MPackage *>(modelObject);
|
||||
foreach (MDiagram *diagram, m_allDiagrams) {
|
||||
DObject *object = findDelegate<DObject>(modelObject, diagram);
|
||||
@@ -622,7 +622,7 @@ void DiagramController::onBeginInsertObject(int row, const MObject *owner)
|
||||
|
||||
void DiagramController::onEndInsertObject(int row, const MObject *owner)
|
||||
{
|
||||
QMT_CHECK(owner);
|
||||
QMT_ASSERT(owner, return);
|
||||
|
||||
MObject *modelObject = m_modelController->object(row, owner);
|
||||
if (auto modelDiagram = dynamic_cast<MDiagram *>(modelObject)) {
|
||||
@@ -634,7 +634,7 @@ void DiagramController::onEndInsertObject(int row, const MObject *owner)
|
||||
|
||||
void DiagramController::onBeginRemoveObject(int row, const MObject *parent)
|
||||
{
|
||||
QMT_CHECK(parent);
|
||||
QMT_ASSERT(parent, return);
|
||||
|
||||
MObject *modelObject = m_modelController->object(row, parent);
|
||||
removeObjects(modelObject);
|
||||
@@ -658,7 +658,7 @@ void DiagramController::onEndMoveObject(int row, const MObject *owner)
|
||||
|
||||
// if diagram was moved update all elements because of changed context
|
||||
MObject *modelObject = m_modelController->object(row, owner);
|
||||
QMT_CHECK(modelObject);
|
||||
QMT_ASSERT(modelObject, return);
|
||||
auto modelDiagram = dynamic_cast<MDiagram *>(modelObject);
|
||||
if (modelDiagram) {
|
||||
emit beginResetDiagram(modelDiagram);
|
||||
@@ -691,7 +691,7 @@ void DiagramController::onEndUpdateRelation(int row, const MObject *owner)
|
||||
|
||||
void DiagramController::onBeginRemoveRelation(int row, const MObject *owner)
|
||||
{
|
||||
QMT_CHECK(owner);
|
||||
QMT_ASSERT(owner, return);
|
||||
|
||||
MRelation *modelRelation = owner->relations().at(row);
|
||||
removeRelations(modelRelation);
|
||||
@@ -719,7 +719,7 @@ void DiagramController::onEndMoveRelation(int row, const MObject *owner)
|
||||
void DiagramController::deleteElements(const DSelection &diagramSelection, MDiagram *diagram,
|
||||
const QString &commandLabel)
|
||||
{
|
||||
QMT_CHECK(diagram);
|
||||
QMT_ASSERT(diagram, return);
|
||||
|
||||
DReferences simplifiedSelection = simplify(diagramSelection, diagram);
|
||||
if (simplifiedSelection.elements().isEmpty())
|
||||
@@ -818,7 +818,7 @@ void DiagramController::removeRelations(DElement *element, MDiagram *diagram)
|
||||
|
||||
void DiagramController::renewElementKey(DElement *element, QHash<Uid, Uid> *renewedKeys)
|
||||
{
|
||||
QMT_CHECK(renewedKeys);
|
||||
QMT_ASSERT(renewedKeys, return);
|
||||
|
||||
if (element) {
|
||||
DElement *existingElementOnDiagram = findElementOnAnyDiagram(element->uid());
|
||||
@@ -850,7 +850,7 @@ void DiagramController::updateElementFromModel(DElement *element, const MDiagram
|
||||
DUpdateVisitor visitor(element, diagram);
|
||||
|
||||
MElement *melement = m_modelController->findElement(element->modelUid());
|
||||
QMT_CHECK(melement);
|
||||
QMT_ASSERT(melement, return);
|
||||
|
||||
if (emitUpdateSignal) {
|
||||
visitor.setCheckNeedsUpdate(true);
|
||||
@@ -925,7 +925,7 @@ void DiagramController::verifyDiagramsIntegrity()
|
||||
FindDiagramsVisitor visitor(&allDiagrams);
|
||||
m_modelController->rootPackage()->accept(&visitor);
|
||||
}
|
||||
QMT_CHECK(allDiagrams == m_allDiagrams);
|
||||
QMT_ASSERT(allDiagrams == m_allDiagrams, return);
|
||||
foreach (const MDiagram *diagram, allDiagrams)
|
||||
verifyDiagramIntegrity(diagram);
|
||||
}
|
||||
@@ -937,8 +937,8 @@ void DiagramController::verifyDiagramIntegrity(const MDiagram *diagram)
|
||||
foreach (const DElement *delement, diagram->diagramElements()) {
|
||||
delementsMap.insert(delement->uid(), delement);
|
||||
if (dynamic_cast<const DObject *>(delement) != 0 || dynamic_cast<const DRelation *>(delement) != 0) {
|
||||
QMT_CHECK(delement->modelUid().isValid());
|
||||
QMT_CHECK(m_modelController->findElement(delement->modelUid()) != 0);
|
||||
QMT_ASSERT(delement->modelUid().isValid(), return);
|
||||
QMT_ASSERT(m_modelController->findElement(delement->modelUid()) != 0, return);
|
||||
if (!delement->modelUid().isValid() || m_modelController->findElement(delement->modelUid()) == 0) {
|
||||
if (const DObject *dobject = dynamic_cast<const DObject *>(delement))
|
||||
qWarning() << "Diagram" << diagram->name() << diagram->uid().toString() << ": object" << dobject->name() << dobject->uid().toString() << "has invalid reference to model element.";
|
||||
@@ -946,17 +946,17 @@ void DiagramController::verifyDiagramIntegrity(const MDiagram *diagram)
|
||||
qWarning() << "Diagram" << diagram->name() << diagram->uid().toString() << ": relation" << drelation->uid().toString() << "has invalid refeference to model element.";
|
||||
}
|
||||
} else {
|
||||
QMT_CHECK(!delement->modelUid().isValid());
|
||||
QMT_ASSERT(!delement->modelUid().isValid(), return);
|
||||
}
|
||||
}
|
||||
foreach (const DElement *delement, diagram->diagramElements()) {
|
||||
if (const DRelation *drelation = dynamic_cast<const DRelation *>(delement)) {
|
||||
QMT_CHECK(drelation->endAUid().isValid());
|
||||
QMT_CHECK(delementsMap.contains(drelation->endAUid()));
|
||||
QMT_ASSERT(drelation->endAUid().isValid(), return);
|
||||
QMT_ASSERT(delementsMap.contains(drelation->endAUid()), return);
|
||||
if (!drelation->endAUid().isValid() || !delementsMap.contains(drelation->endAUid()))
|
||||
qWarning() << "Diagram" << diagram->name() << diagram->uid().toString() << ": relation" << drelation->uid().toString() << "has invalid end A.";
|
||||
QMT_CHECK(drelation->endBUid().isValid());
|
||||
QMT_CHECK(delementsMap.contains(drelation->endBUid()));
|
||||
QMT_ASSERT(drelation->endBUid().isValid(), return);
|
||||
QMT_ASSERT(delementsMap.contains(drelation->endBUid()), return);
|
||||
if (!drelation->endBUid().isValid() || !delementsMap.contains(drelation->endBUid()))
|
||||
qWarning() << "Diagram" << diagram->name() << diagram->uid().toString() << ": relation" << drelation->uid().toString() << "has invalid end B.";
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ void DUpdateVisitor::visitMElement(const MElement *element)
|
||||
void DUpdateVisitor::visitMObject(const MObject *object)
|
||||
{
|
||||
auto dobject = dynamic_cast<DObject *>(m_target);
|
||||
QMT_CHECK(dobject);
|
||||
QMT_ASSERT(dobject, return);
|
||||
if (isUpdating(object->stereotypes() != dobject->stereotypes()))
|
||||
dobject->setStereotypes(object->stereotypes());
|
||||
const MObject *objectOwner = object->owner();
|
||||
@@ -107,7 +107,7 @@ void DUpdateVisitor::visitMPackage(const MPackage *package)
|
||||
void DUpdateVisitor::visitMClass(const MClass *klass)
|
||||
{
|
||||
auto dclass = dynamic_cast<DClass *>(m_target);
|
||||
QMT_CHECK(dclass);
|
||||
QMT_ASSERT(dclass, return);
|
||||
if (isUpdating(klass->umlNamespace() != dclass->umlNamespace()))
|
||||
dclass->setUmlNamespace(klass->umlNamespace());
|
||||
if (isUpdating(klass->templateParameters() != dclass->templateParameters()))
|
||||
@@ -135,7 +135,7 @@ void DUpdateVisitor::visitMCanvasDiagram(const MCanvasDiagram *diagram)
|
||||
void DUpdateVisitor::visitMItem(const MItem *item)
|
||||
{
|
||||
auto ditem = dynamic_cast<DItem *>(m_target);
|
||||
QMT_CHECK(ditem);
|
||||
QMT_ASSERT(ditem, return);
|
||||
if (isUpdating(item->isShapeEditable() != ditem->isShapeEditable()))
|
||||
ditem->setShapeEditable(item->isShapeEditable());
|
||||
if (isUpdating(item->variety() != ditem->variety()))
|
||||
@@ -146,7 +146,7 @@ void DUpdateVisitor::visitMItem(const MItem *item)
|
||||
void DUpdateVisitor::visitMRelation(const MRelation *relation)
|
||||
{
|
||||
auto drelation = dynamic_cast<DRelation *>(m_target);
|
||||
QMT_CHECK(drelation);
|
||||
QMT_ASSERT(drelation, return);
|
||||
if (isUpdating(relation->stereotypes() != drelation->stereotypes()))
|
||||
drelation->setStereotypes(relation->stereotypes());
|
||||
if (isUpdating(relation->name() != drelation->name()))
|
||||
@@ -190,7 +190,7 @@ void DUpdateVisitor::visitMRelation(const MRelation *relation)
|
||||
void DUpdateVisitor::visitMDependency(const MDependency *dependency)
|
||||
{
|
||||
auto ddependency = dynamic_cast<DDependency *>(m_target);
|
||||
QMT_CHECK(ddependency);
|
||||
QMT_ASSERT(ddependency, return);
|
||||
if (isUpdating(dependency->direction() != ddependency->direction()))
|
||||
ddependency->setDirection(dependency->direction());
|
||||
visitMRelation(dependency);
|
||||
@@ -204,7 +204,7 @@ void DUpdateVisitor::visitMInheritance(const MInheritance *inheritance)
|
||||
void DUpdateVisitor::visitMAssociation(const MAssociation *association)
|
||||
{
|
||||
auto dassociation = dynamic_cast<DAssociation *>(m_target);
|
||||
QMT_CHECK(dassociation);
|
||||
QMT_ASSERT(dassociation, return);
|
||||
DAssociationEnd endA;
|
||||
endA.setName(association->endA().name());
|
||||
endA.setCardinatlity(association->endA().cardinality());
|
||||
|
||||
Reference in New Issue
Block a user