Commit 3285a4b4 authored by Emmanuel Promayon's avatar Emmanuel Promayon

FIXED delete QTreeItem memory

parent f1731c39
......@@ -48,11 +48,16 @@ Explorer::Explorer(QString name) : Viewer(name, Viewer::DOCKED) {
setDescription("The Explorer viewer shows all the instanciated components");
explorerTree = nullptr;
explorerMenu = nullptr;
explorerMenu = nullptr;
}
//----------------------- destructor ------------------------
Explorer::~Explorer() {
// remove all vector actors
while (!itemComponentMap.values().empty()) {
delete itemComponentMap.values().takeFirst();
}
delete explorerTree;
explorerTree = nullptr;
......@@ -131,32 +136,39 @@ void Explorer::refresh(Viewer* whoIsAsking) {
}
}
}
//-- check the selection
// First: block the signal
explorerTree->blockSignals(true);
explorerTree->clearSelection();
if (!Application::getSelectedComponents().isEmpty()) {
foreach (Component* comp, Application::getSelectedComponents()) {
if (comp->isSelected()) {
QTreeWidgetItem* selected = getItem(comp);
if (selected) {
// select this item in the explorer
selected->setSelected(true);
}
}
}
// ensure of the last one selected
QTreeWidgetItem* lastSelected = getItem(Application::getSelectedComponents().last());
explorerTree->scrollToItem(lastSelected, QAbstractItemView::PositionAtCenter);
}
// Last: unblock the signal
explorerTree->blockSignals(false);
}
//-- check the Component names
QMapIterator<QTreeWidgetItem*, Component*> it(itemComponentMap);
while (it.hasNext()) {
it.next();
if (it.key()->text(0) != it.value()->getName()) {
it.key()->setText(0, it.value()->getName());
}
......@@ -172,9 +184,11 @@ void Explorer::refresh(Viewer* whoIsAsking) {
//----------------------- getItem ------------------------
QTreeWidgetItem* Explorer::getItem(Component* comp) {
QMap<QTreeWidgetItem*, Component*>::iterator it = itemComponentMap.begin();
while (it != itemComponentMap.end() && it.value() != comp) {
++it;
}
if (it != itemComponentMap.end()) {
return it.key();
}
......@@ -189,6 +203,7 @@ QTreeWidgetItem* Explorer::getNewItem(QTreeWidgetItem* parent, Component* abstra
auto* tw = new QTreeWidgetItem(parent);
// set the first column (#0)
QString itemText = abstractNode->getName();
if (abstractNode->getIcon().isNull()) {
tw->setText(0, itemText);
}
......@@ -255,6 +270,7 @@ void Explorer::refreshInterfaceNode(Component* comp) {
// get the index in the parent list
QTreeWidgetItem* parentTW = toDelete->parent();
int index = -1;
if (parentTW == nullptr)
// if no parent, it means toDelete is at top level, get its index
{
......@@ -283,6 +299,7 @@ void Explorer::refreshInterfaceNode(Component* comp) {
remove(toDelete);
parentTW->insertChild(index, add(nullptr, comp));
}
explorerTree->blockSignals(false);
}
}
......@@ -291,6 +308,7 @@ void Explorer::refreshInterfaceNode(Component* comp) {
//----------------------- removeTopLevel ------------------------
void Explorer::removeTopLevel(Component* comp) {
QTreeWidgetItem* toDelete = topLevelCompItemMap.value(comp);
if (toDelete != nullptr) {
explorerTree->blockSignals(true);
// remove from the explorer
......@@ -307,6 +325,7 @@ void Explorer::remove(QTreeWidgetItem* tw) {
if (Application::isAlive(itemComponentMap.value(tw))) {
itemComponentMap.value(tw)->setVisibility(this->getName(), false);
}
// remove from the map
itemComponentMap.remove(tw);
......@@ -327,9 +346,11 @@ void Explorer::selectionChanged() {
Application::clearSelectedComponents();
// create the new list
ComponentList selectedComponent;
for (auto selectedItem : selectedItems) {
selectedComponent.append((Component*)itemComponentMap.value(selectedItem));
}
// add everything to the selection and update the views
Viewer::selectionChanged(selectedComponent);
......@@ -347,6 +368,7 @@ void Explorer::doubleClicked(QTreeWidgetItem* tw, int) {
if (comp->doubleClicked()) {
refreshInterfaceNode(comp);
}
// update selection
selectionChanged();
}
......@@ -359,6 +381,7 @@ void Explorer::rightButtonPressed(const QPoint& clickedPoint) {
if (selected) {
Component* comp = (Component*) itemComponentMap.value(selected);
QMenu* actionsMenu = comp->getActionMenu();
if (actionsMenu) {
actionsMenu->exec(QCursor::pos());
}
......@@ -390,3 +413,5 @@ void Explorer::renameItem() {
}
}
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