Skip to content

Commit

Permalink
fix tooltip visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
facontidavide committed May 27, 2024
1 parent d115b54 commit b6f37b1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
41 changes: 31 additions & 10 deletions plotjuggler_app/curvetree_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "curvetree_view.h"
#include "curvelist_panel.h"
#include <QTimer>
#include <QFontDatabase>
#include <QObject>
#include <QDebug>
Expand Down Expand Up @@ -68,6 +69,27 @@ CurveTreeView::CurveTreeView(CurveListPanel* parent)
setFocusPolicy(Qt::ClickFocus);
}
});
_tooltip_timer = new QTimer(this);
connect(_tooltip_timer, &QTimer::timeout, this, [this]() {
if (_tooltip_item)
{
auto tooltip = _tooltip_item->data(0, CustomRoles::ToolTip);
if (tooltip.isValid())
{
QToolTip::showText(_tooltip_pos, tooltip.toString(), this, QRect(), 10000);
}
}
});
_tooltip_timer->start(100);
}

void CurveTreeView::clear()
{
_tooltip_item = nullptr;
_tooltip_timer->stop();
QTreeWidget::clear();
_leaf_count = 0;
_hidden_count = 0;
}

void CurveTreeView::addItem(const QString& group_name, const QString& tree_name,
Expand Down Expand Up @@ -176,7 +198,6 @@ void CurveTreeView::refreshColumns()
invisibleRootItem()->sortChildren(0, Qt::AscendingOrder);
treeVisitor([&](QTreeWidgetItem* item) { item->sortChildren(0, Qt::AscendingOrder); });
header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
// TODO emit updateFilter();
}

std::vector<std::string> CurveTreeView::getSelectedNames()
Expand Down Expand Up @@ -286,16 +307,14 @@ bool CurveTreeView::eventFilter(QObject* object, QEvent* event)
auto* item = itemAt(mouse_event->pos());
if (item)
{
auto tooltip = item->data(0, CustomRoles::ToolTip);
if (tooltip.isValid())
{
QToolTip::showText(mapToGlobal(mouse_event->pos()), tooltip.toString());
}
else
{
QToolTip::hideText();
}
_tooltip_pos = mapToGlobal(mouse_event->pos());
}
_tooltip_item = item;
}

if (event->type() == QEvent::Leave)
{
_tooltip_item = nullptr;
}

bool ret = CurvesView::eventFilterBase(object, event);
Expand Down Expand Up @@ -336,6 +355,8 @@ void CurveTreeView::removeCurve(const QString& to_be_deleted)
}
};

// just in case
_tooltip_item = nullptr;
treeVisitor(removeFunc);
}

Expand Down
11 changes: 5 additions & 6 deletions plotjuggler_app/curvetree_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ class CurveTreeView : public QTreeWidget, public CurvesView
public:
CurveTreeView(CurveListPanel* parent);

void clear() override
{
QTreeWidget::clear();
_leaf_count = 0;
_hidden_count = 0;
}
void clear() override;

void addItem(const QString& prefix, const QString& tree_name,
const QString& plot_ID) override;
Expand Down Expand Up @@ -58,6 +53,10 @@ class CurveTreeView : public QTreeWidget, public CurvesView

int _hidden_count = 0;
int _leaf_count = 0;

QTimer* _tooltip_timer = nullptr;
QTreeWidgetItem* _tooltip_item = nullptr;
QPoint _tooltip_pos;
};

#endif // CURVETREE_VIEW_H

0 comments on commit b6f37b1

Please sign in to comment.