Commit 9fc14383 authored by Emmanuel Promayon's avatar Emmanuel Promayon

Merge branch '84-bug-in-refreshinterfacenode-in-explorer-cpp-2' into 'develop'

Bug/#84

Closes #84

See merge request !115
parents 9a47c4ed 87be8277
......@@ -59,7 +59,7 @@ Explorer::~Explorer() {
//----------------------- getInstance ------------------------
Explorer* Explorer::getInstance() {
// static instantiation, static method variable
// static instanciation, static method variable
static Explorer* explorer = nullptr;
if (!explorer) {
explorer = new Explorer();
......@@ -135,18 +135,18 @@ void Explorer::refresh(Viewer* whoIsAsking) {
if (whoIsAsking != this) {
//-- check the top-level component number
ComponentList topLevelCpt = Application::getTopLevelComponents();
ComponentList viewedcomp = itemCompMap.uniqueKeys();
ComponentList viewedcomp = topLevelCompItemMap.uniqueKeys();
if (viewedcomp.size() != topLevelCpt.size()) {
// remove the closed/deleted top-level component
foreach (Component* comp, viewedcomp) {
if (!topLevelCpt.contains(comp)) {
remove(comp);
removeTopLevel(comp);
}
}
// add the new top-level component
foreach (Component* comp, topLevelCpt) {
if (!viewedcomp.contains(comp)) {
add(comp);
addTopLevel(comp);
}
}
}
......@@ -217,6 +217,7 @@ QTreeWidgetItem* Explorer::getNewItem(QTreeWidgetItem* parent, Component* abstra
// add the pixmap
tw->setIcon(0, abstractNode->getIcon());
}
// check the italic property
QFont f = tw->font(0);
f.setItalic(abstractNode->inItalic());
......@@ -227,6 +228,24 @@ QTreeWidgetItem* Explorer::getNewItem(QTreeWidgetItem* parent, Component* abstra
return tw;
}
//----------------------- addTopLevel ------------------------
void Explorer::addTopLevel(Component* comp, int index) {
if (!comp->getParent()) {
// create the items
QTreeWidgetItem* compItem = add(nullptr, comp);
// add to / insert in the tree
if (index < 0) {
explorerTree->addTopLevelItem(compItem);
}
else {
explorerTree->insertTopLevelItem(index, compItem);
}
// insert top-level component in the map
topLevelCompItemMap.insert(comp, compItem);
}
}
//----------------------- add ------------------------
QTreeWidgetItem* Explorer::add(QTreeWidgetItem* parent, Component* abstractNode) {
......@@ -247,18 +266,6 @@ QTreeWidgetItem* Explorer::add(QTreeWidgetItem* parent, Component* abstractNode)
return tw;
}
//----------------------- add ------------------------
void Explorer::add(Component* comp) {
if (!comp->getParent()) {
// create the items
QTreeWidgetItem* compItem = add(nullptr, comp);
explorerTree->addTopLevelItem(compItem);
// insert top-level component in the map
itemCompMap.insert(comp, compItem);
}
}
//----------------------- refreshInterfaceNode ------------------------
void Explorer::refreshInterfaceNode(Component* comp) {
QTreeWidgetItem* toDelete = getItem(comp);
......@@ -280,17 +287,19 @@ void Explorer::refreshInterfaceNode(Component* comp) {
// remove from the list and from the explorer
explorerTree->blockSignals(true);
remove(toDelete);
// recreate and add at the same place
if (parentTW == nullptr)
// if there is no parent, then add at the correct index on the top level
{
explorerTree->insertTopLevelItem(index, add(nullptr, comp));
// remove from the map
removeTopLevel(comp);
addTopLevel(comp, index);
}
else
// add where it was deleted in the parent index
{
remove(toDelete);
parentTW->insertChild(index, add(nullptr, comp));
}
explorerTree->blockSignals(false);
......@@ -298,16 +307,16 @@ void Explorer::refreshInterfaceNode(Component* comp) {
}
//----------------------- remove ------------------------
void Explorer::remove(Component* comp) {
QTreeWidgetItem* toDelete = itemCompMap.value(comp);
//----------------------- removeTopLevel ------------------------
void Explorer::removeTopLevel(Component* comp) {
QTreeWidgetItem* toDelete = topLevelCompItemMap.value(comp);
if (toDelete != nullptr) {
explorerTree->blockSignals(true);
// remove from the explorer
remove(toDelete);
explorerTree->blockSignals(false);
// remove from the map
itemCompMap.remove(comp);
topLevelCompItemMap.remove(comp);
}
}
......
......@@ -124,7 +124,7 @@ private:
QMap<QTreeWidgetItem*, Component*> itemComponentMap;
/// the map to get the QTreeWidgetItem corresponding to a parentComp
QMap<Component*, QTreeWidgetItem*> itemCompMap;
QMap<Component*, QTreeWidgetItem*> topLevelCompItemMap;
/// Return the QTreeWidgetItem of a given Component (return NULL if not found)
QTreeWidgetItem* getItem(Component*);
......@@ -132,7 +132,7 @@ private:
/// @name QTreeWidget and QTreeWidgetItem management
///@{
/// instantiate a new QTreeWidgetItem using names and properties from the InterfaceNode, and using parent
/// instanciate a new QTreeWidgetItem using names and properties from the InterfaceNode, and using parent
QTreeWidgetItem* getNewItem(QTreeWidgetItem* parent, Component*);
/// recursively add the Component in the tree explorer and return the QTreeWidgetItem of the InterfaceNode
......@@ -141,7 +141,7 @@ private:
/** Add the given Component to the explorer (at top level) and automatically create children Component items.
* @param comp The Component to add in the tree view.
*/
void add(Component* comp);
void addTopLevel(Component* comp, int index = -1);
/// remove a given item from the explorer (return its index in the parent item list)
void remove(QTreeWidgetItem*);
......@@ -149,7 +149,7 @@ private:
/** Remove the Component (its Component and its sub-item) from the explorer list (if present).
* The Component itself is of course not deleted here.
*/
void remove(Component* comp);
void removeTopLevel(Component* comp);
/// the list view
......
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