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