Skip to content

Commit

Permalink
do not use smart pointers in graphics view let qGraphics Scene handel…
Browse files Browse the repository at this point in the history
… the memory managment
  • Loading branch information
Sinerum committed Oct 30, 2023
1 parent 5f649cd commit 963ce63
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
4 changes: 2 additions & 2 deletions tools/fm-editor/FeatureModelEditor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
<x>0</x>
<y>0</y>
<width>943</width>
<height>30</height>
<height>34</height>
</rect>
</property>
<widget class="QMenu" name="menuEdit">
Expand Down Expand Up @@ -224,7 +224,7 @@
<bool>false</bool>
</property>
<property name="text">
<string>Save</string>
<string>Save As</string>
</property>
<property name="shortcut">
<string>Ctrl+Alt+S</string>
Expand Down
39 changes: 19 additions & 20 deletions tools/fm-editor/graph/FeatureModelGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ FeatureModelGraph::FeatureModelGraph(vara::feature::FeatureModel *FeatureModel,
}

void FeatureModelGraph::reload() {
Nodes.push_back(std::unique_ptr<FeatureNode>(EntryNode));
Nodes.push_back(EntryNode);
auto *Scene = this->scene();
Scene->clear();
Scene->addItem(EntryNode);
Expand All @@ -49,22 +49,22 @@ void FeatureModelGraph::buildRec(FeatureNode *CurrentFeatureNode) {
for (auto *Feature :
CurrentFeatureNode->getFeature()->getChildren<vara::feature::Feature>(
1)) {
auto Node = std::make_unique<FeatureNode>(Feature);
auto *Edge = new FeatureEdge(CurrentFeatureNode, Node.get());
auto *Node = new FeatureNode(Feature);
auto *Edge = new FeatureEdge(CurrentFeatureNode, Node);
scene()->addItem(Edge);
scene()->addItem(Node.get());
buildRec(Node.get());
Nodes.push_back(std::move(Node));
scene()->addItem(Node);
Nodes.push_back(Node);
buildRec(Node);
}
for (auto *Relation : CurrentFeatureNode->getFeature()
->getChildren<vara::feature::Relationship>(1)) {
for (auto *Feature : Relation->getChildren<vara::feature::Feature>(1)) {
auto Node = std::make_unique<FeatureNode>(Feature);
auto *Edge = new FeatureEdge(CurrentFeatureNode, Node.get());
auto *Node = new FeatureNode(Feature);
auto *Edge = new FeatureEdge(CurrentFeatureNode, Node);
scene()->addItem(Edge);
scene()->addItem(Node.get());
buildRec(Node.get());
Nodes.push_back(std::move(Node));
scene()->addItem(Node);
buildRec(Node);
Nodes.push_back(Node);
}
}
}
Expand All @@ -85,7 +85,7 @@ int FeatureModelGraph::positionRec(const int CurrentDepth,
NextChildren.begin(),
[](FeatureEdge *Edge) { return Edge->targetNode(); });
int const Depth = positionRec(CurrentDepth + 1, NextChildren, NextOffset);
int Width = Node->childrenWidth();
int const Width = Node->childrenWidth();
Node->setPos(double(NextOffset) + Width / 2.0, 100 * CurrentDepth);
NextOffset += Width;
MaxDepth = MaxDepth < Depth ? Depth : MaxDepth;
Expand Down Expand Up @@ -162,12 +162,11 @@ void FeatureModelGraph::zoomIn() { scaleView(qreal(1.2)); }
void FeatureModelGraph::zoomOut() { scaleView(1 / qreal(1.2)); }

FeatureNode *FeatureModelGraph::addNode(Feature *Feature, FeatureNode *Parent) {
auto NewNode = std::make_unique<FeatureNode>(Feature);
auto *NewEdge = new FeatureEdge(Parent, NewNode.get());
auto *NewNode = new FeatureNode(Feature);
auto *NewEdge = new FeatureEdge(Parent, NewNode);
scene()->addItem(NewEdge);
scene()->addItem(NewNode.get());
auto *NewNodeRaw = NewNode.get();
Nodes.push_back(std::move(NewNode));
scene()->addItem(NewNode);
Nodes.push_back(NewNode);
auto NextChildren = std::vector<FeatureNode *>(EntryNode->children().size());
auto CurrentChildren = EntryNode->children();
std::transform(CurrentChildren.begin(), CurrentChildren.end(),
Expand All @@ -176,15 +175,15 @@ FeatureNode *FeatureModelGraph::addNode(Feature *Feature, FeatureNode *Parent) {
positionRec(1, NextChildren, 5);
EntryNode->setPos(EntryNode->childrenWidth() / 2.0, 10);

return NewNodeRaw;
return NewNode;
}

FeatureNode *FeatureModelGraph::getNode(std::string Name) {
auto It = std::find_if(Nodes.begin(), Nodes.end(), [&Name](const auto &Node) {
return Node->getName() == Name;
});
if (It != Nodes.end()) {
return It->get();
return *It;
}

return nullptr;
Expand All @@ -208,7 +207,7 @@ void FeatureModelGraph::deleteNode(bool Recursive, FeatureNode *Node) {
scene()->removeItem(Node->parent());

Nodes.erase(std::find_if(Nodes.begin(), Nodes.end(),
[Node](auto &N) { return N.get() == Node; }));
[Node](auto &N) { return N == Node; }));
}

void FeatureModelGraph::deleteNode(bool Recursive,
Expand Down
2 changes: 1 addition & 1 deletion tools/fm-editor/graph/FeatureModelGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public slots:
int positionRec(int CurrentDepth, const std::vector<FeatureNode *> &Children,
unsigned long Offset);
vara::feature::FeatureModel *FeatureModel;
std::vector<std::unique_ptr<FeatureNode>> Nodes;
std::vector<FeatureNode *> Nodes;
std::unique_ptr<QGraphicsScene> Scene;
};

Expand Down

0 comments on commit 963ce63

Please sign in to comment.