subsurface/qt-quick/chartitem_ptr.h
Berthold Stoeger bece0a0652 profile: port basic dive editing to QtQuick
This needed a bit of refactoring of the ChartItem code, because
we have to be signaled on drag start. Currently only one handle
can be selected at a time. This was (implicitly) the case anyway,
as far as I can tell.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-09-12 15:17:15 +02:00

60 lines
1.1 KiB
C++

// SPDX-License-Identifier: GPL-2.0
// A stupid pointer class that initializes to null and can be copy
// assigned. This is for historical reasons: unique_ptrs to ChartItems
// were replaced by plain pointers. Instead of nulling the plain pointers
// in the constructors, use this. Ultimately, we might think about making
// this thing smarter, once removal of individual ChartItems is implemented.
#ifndef CHARITEM_PTR_H
#define CHARITEM_PTR_H
template <typename T>
class ChartItemPtr {
friend class ChartView; // Only the chart view can create these pointers
T *ptr;
ChartItemPtr(T *ptr) : ptr(ptr)
{
}
public:
ChartItemPtr() : ptr(nullptr)
{
}
ChartItemPtr(const ChartItemPtr &p) : ptr(p.ptr)
{
}
ChartItemPtr(ChartItemPtr &&p) : ptr(p.ptr)
{
}
void reset()
{
ptr = nullptr;
}
ChartItemPtr &operator=(const ChartItemPtr &p)
{
ptr = p.ptr;
return *this;
}
operator bool() const
{
return !!ptr;
}
bool operator!() const
{
return !ptr;
}
T &operator*() const
{
return *ptr;
}
T *operator->() const
{
return ptr;
}
void del()
{
if (!ptr)
return;
ptr->view.deleteChartItem(*this);
}
};
#endif