profile: move dragging code from stats to general qt-code

So far, the only dragable item was the legend in the statistics
code. On the profile, we will have multiple dragable items.

Therefore, move the code up and make it more general. This
took some reorganization. Now, the size of the ChartItem
is saved in the base class. Also, setPos() became a virtual
function.

The dragable items are kept as an unsorted list.
If there will be many of them, this should be changed to
some sort of sorted list (maybe quadtree?).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2023-06-25 08:56:21 +02:00
parent 13c9218ecf
commit a527415ac9
7 changed files with 114 additions and 65 deletions

View file

@ -43,6 +43,10 @@ protected:
// This is called when Qt decided to reset our rootNode, which invalidates all items on the chart.
// The base class must invalidate all pointers and references.
virtual void resetPointers() = 0;
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
private:
// QtQuick related things
size_t maxZ;
@ -77,10 +81,17 @@ private:
ChartItemList cleanItems, dirtyItems, deletedItems;
void deleteChartItemInternal(ChartItem &item);
void freeDeletedChartItems();
// Keep a list of dragable items. For now, there are no many,
// so keep it unsorted. In the future we might want to sort by
// coordinates.
std::vector<ChartItem *> dragableItems;
ChartItemPtr<ChartItem> draggedItem;
QPointF dragStartMouse, dragStartItem;
};
// This implementation detail must be known to users of the class.
// Perhaps move it into a statsview_impl.h file.
// Perhaps move it into a chartview_impl.h file.
template <typename T, class... Args>
ChartItemPtr<T> ChartView::createChartItem(Args&&... args)
{