Skip to content
Snippets Groups Projects
Commit 6b96b08e authored by Rainer Kartmann's avatar Rainer Kartmann
Browse files

Improve selection handling

parent 314f4327
No related branches found
No related tags found
No related merge requests found
......@@ -134,7 +134,7 @@ namespace armarx
connect(memoryTree, &armem::gui::MemoryTreeWidget::updated, this, &This::memoryTreeUpdated);
connect(memoryTree, &armem::gui::MemoryTreeWidget::updated, this, &This::updateInstanceTree);
connect(memoryTree, &armem::gui::MemoryTreeWidget::instanceSelected, this, &This::updateInstanceTree);
connect(memoryTree, &armem::gui::MemoryTreeWidget::itemSelected, this, &This::updateInstanceTree);
connect(widget.instanceUseTypeInfoCheckBox, &QCheckBox::toggled, instanceTree, &armem::gui::InstanceTreeWidget::setUseTypeInfo);
connect(instanceTree, &armem::gui::InstanceTreeWidget::updated, this, &This::instanceTreeUpdated);
......@@ -245,7 +245,33 @@ namespace armarx
{
if (memoryData && memoryTree->selectedID())
{
instanceTree->update(*memoryTree->selectedID(), *memoryData);
armem::MemoryID id = *memoryTree->selectedID();
if (!id.hasEntityName())
{
return;
}
const armem::EntitySnapshot* snapshot = nullptr;
if (!id.hasTimestamp())
{
snapshot = &memoryData->getEntity(id).getLatestSnapshot();
id.timestamp = snapshot->time();
}
if (!id.hasInstanceIndex())
{
if (!snapshot)
{
snapshot = &memoryData->getEntitySnapshot(id);
}
if (snapshot->size() > 0)
{
id.instanceIndex = 0;
}
}
if (id.hasInstanceIndex())
{
instanceTree->update(id, *memoryData);
}
}
}
......
......@@ -118,6 +118,7 @@ namespace armarx::armem::gui
}
}
void InstanceTreeWidget::updateInstanceID(const MemoryID& id)
{
const std::vector<std::string> items = id.getAllItems();
......
......@@ -36,7 +36,14 @@ namespace armarx::armem::gui
header()->setTextElideMode(Qt::TextElideMode::ElideRight);
connect(this, &QTreeWidget::currentItemChanged, this, &MemoryTreeWidget::handleSelection);
connect(this, &QTreeWidget::currentItemChanged, this, &This::handleSelection);
connect(this, &This::memorySelected, this, &This::itemSelected);
connect(this, &This::coreSegmentSelected, this, &This::itemSelected);
connect(this, &This::providerSegmentSelected, this, &This::itemSelected);
connect(this, &This::entitySelected, this, &This::itemSelected);
connect(this, &This::snapshotSelected, this, &This::itemSelected);
connect(this, &This::instanceSelected, this, &This::itemSelected);
}
void MemoryTreeWidget::initBuilders()
......@@ -115,7 +122,6 @@ namespace armarx::armem::gui
instanceBuilder.setMakeItemFn([this](const EntityInstance & instance)
{
QTreeWidgetItem* item = makeItem("", instance);
item->setData(int(Columns::ID), Qt::UserRole, QString::fromStdString(instance.id().str()));
return item;
});
instanceBuilder.setCompareFn([](const EntityInstance & lhs, QTreeWidgetItem * rhsItem)
......@@ -152,16 +158,38 @@ namespace armarx::armem::gui
void MemoryTreeWidget::handleSelection()
{
QTreeWidgetItem* item = this->currentItem();
if (!item
|| item->data(int(Columns::LEVEL), Qt::UserRole).toString().toStdString() != EntityInstance().getLevelName())
if (!item)
{
return;
}
QString itemData = item->data(int(Columns::ID), Qt::UserRole).toString();
_selectedID = MemoryID(itemData.toStdString());
const std::string levelName = item->data(int(Columns::LEVEL), Qt::UserRole).toString().toStdString();
_selectedID = MemoryID(item->data(int(Columns::ID), Qt::UserRole).toString().toStdString());
emit instanceSelected(*_selectedID);
if (levelName == Memory().getLevelName())
{
emit memorySelected(*_selectedID);
}
else if (levelName == CoreSegment().getLevelName())
{
emit coreSegmentSelected(*_selectedID);
}
else if (levelName == ProviderSegment().getLevelName())
{
emit providerSegmentSelected(*_selectedID);
}
else if (levelName == Entity().getLevelName())
{
emit entitySelected(*_selectedID);
}
else if (levelName == EntitySnapshot().getLevelName())
{
emit snapshotSelected(*_selectedID);
}
else if (levelName == EntityInstance().getLevelName())
{
emit instanceSelected(*_selectedID);
}
}
......@@ -218,6 +246,7 @@ namespace armarx::armem::gui
QTreeWidgetItem* item = new QTreeWidgetItem(columns);
item->setData(int(Columns::LEVEL), Qt::UserRole, QString::fromStdString(memoryItem.getLevelName()));
item->setData(int(Columns::ID), Qt::UserRole, QString::fromStdString(memoryItem.id().str()));
item->setTextAlignment(int(Columns::SIZE), Qt::AlignRight);
return item;
}
......
......@@ -17,6 +17,8 @@ namespace armarx::armem::gui
class MemoryTreeWidget : public QTreeWidget
{
Q_OBJECT
using This = MemoryTreeWidget;
public:
MemoryTreeWidget();
......@@ -30,6 +32,14 @@ namespace armarx::armem::gui
signals:
void updated();
void itemSelected(const MemoryID& id);
void memorySelected(const MemoryID& id);
void coreSegmentSelected(const MemoryID& id);
void providerSegmentSelected(const MemoryID& id);
void entitySelected(const MemoryID& id);
void snapshotSelected(const MemoryID& id);
void instanceSelected(const MemoryID& id);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment