8 : Name(std::move(Name)),
9 BarSeries(std::make_unique<QBarSeries>()), LineSeries(std::make_unique<QLineSeries>()),
10 BarSet(new QBarSet(this->Name))
18 int iIndex = Util::NumToT<int>(
PlotSeries.size());
20 beginInsertRows({}, iIndex, iIndex);
34 int iIndex = Util::NumToT<int>(Index);
36 beginRemoveRows({}, iIndex, iIndex);
43 QStringList SeriesNames;
83 return std::any_of(
PlotSeries.cbegin(),
PlotSeries.cend(), [](
auto& Series) { return Series.LineSeries->isVisible(); });
91 int iIndex = Util::NumToT<int>(Index);
93 emit dataChanged(QAbstractItemModel::createIndex(iIndex, 0), QAbstractItemModel::createIndex(iIndex, 0));
108 return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsEditable;
118 if (!index.isValid())
121 const auto& Series =
PlotSeries.at(index.row());
128 case ColorRole:
return Series.LineSeries->color();
136 if (!index.isValid())
143 case VisibleRole: Series.Visible = value.toBool();
break;
144 default:
return false;
147 emit dataChanged(index, index, { role });
153 XCategoryAxis(std::make_unique<QBarCategoryAxis>()), XValueAxis(std::make_unique<QValueAxis>()),
154 YValueAxis(std::make_unique<QValueAxis>())
162 if (this->CursorPosition == CursorPosition)
165 this->CursorPosition = CursorPosition;
167 emit qcursorPositionChanged(CursorPosition);
172 if (this->HoveredPoint == HoveredPoint)
175 this->HoveredPoint = HoveredPoint;
177 emit qhoveredPointChanged(HoveredPoint);
182 if (this->HoveredSample == HoveredSample)
185 this->HoveredSample = HoveredSample;
187 emit qhoveredSampleChanged(HoveredSample);
192 const auto Index =
PlotModel.InsertSeries(Name, Color);
193 auto& Series =
PlotModel.GetSeries(Index);
195 emit
qinsertSeries(Series.BarSeries.get(), Series.LineSeries.get());
200 const auto Index =
PlotModel.GetIndex(Name);
204 auto& Series =
PlotModel.GetSeries(Index);
206 emit
qremoveSeries(Series.BarSeries.get(), Series.LineSeries.get());
219 if (!Samples.empty())
221 Series.BarSet->replace(0, std::abs(Samples.front().y()));
222 Series.LineSeries->replace(Samples);
227 Series.LineSeries->replace({ {0., 0.} });
234 Series.BarSeries->setVisible(Series.Visible && Samples.size() == 1);
235 Series.LineSeries->setVisible(Series.Visible && Samples.size() > 1);
243 bool Autoscale,
bool UpdateAxes)
245 const bool AnyLineSeriesVisible =
PlotModel.IsAnyLineSeriesVisible();
251 if (AnyLineSeriesVisible)
253 if (PlotInfo.
XLabel.isEmpty())
283 if (AnyLineSeriesVisible)
C++ backend of the QDynExpLineGraph QML component.
const DynExpLineGraphPlotSeries & UpdateSeries(size_t Index, const QList< QPointF > &Samples, const DynExpModule::Graph::LineGraphPlotInfo &PlotInfo, bool UpdateSamples=true)
void UpdateData(DynExpModule::Graph::LineGraphPlotInfo &PlotInfo, bool Autoscale=true, bool UpdateAxes=true)
QML_ELEMENTDynExpLineGraphPlotModel * PlotModel
QPointF GetCursorPosition() const noexcept
void SetHoveredPoint(QPointF HoveredPoint) noexcept
DynExpLineGraphBackend(QObject *parent=nullptr)
void SetHoveredSample(QPointF HoveredSample) noexcept
void qremoveSeries(QBarSeries *, QLineSeries *)
QBarCategoryAxis * XCategoryAxis
void SetCursorPosition(QPointF CursorPosition) noexcept
void qinsertSeries(QBarSeries *, QLineSeries *)
void InsertSeries(QString Name, QColor Color={})
void SeriesChanged(size_t Index)
const auto & GetSeries(size_t Index) const
void RemoveSeries(QString Name)
const DynExpLineGraphPlotSeries & GetSeries(size_t Index) const
bool IsAnyLineSeriesVisible() const
QStringList GetSeriesNames() const
std::vector< DynExpLineGraphPlotSeries > PlotSeries
QHash< int, QByteArray > roleNames() const override
void RemoveSeries(size_t Index)
Qt::ItemFlags flags(const QModelIndex &) const override
size_t GetIndex(QString Name) const
size_t InsertSeries(QString Name, QColor Color)
QVariant data(const QModelIndex &index, int role) const override
bool setData(const QModelIndex &index, const QVariant &value, int role) override
int rowCount(const QModelIndex &) const override
void SeriesChanged(size_t Index)
static std::string RemoveCategoryAndName(const std::string &ObjectDesc)
Removes the category and name part built by Object::CategoryAndNameToStr() from the string ObjectDesc...
Thrown when an argument passed to a function exceeds the valid range.
constexpr QColor ColorFromIndex(size_t Index)
Returns the plot color from the cycle list to be assigned to the plot with index Index.
@ LogicLevel
Logic level (TTL) units (1 or 0)
std::string UnitToStr(UnitType Unit)
Returns a descriptive string of a respective unit category and type to be e.g. used in plots.
const char * UnitCategoryToStr(UnitType Unit)
Returns a descriptive string of the given unit's category (e.g. 'intensity').
bool IsIntegerUnit(UnitType Unit)
Checks whether Unit implies integer values.
const char * UnitTypeToStr(UnitType Unit)
Returns a descriptive string of the given unit's type (e.g. 'dBm').
DynExp::Units::UnitType XUnit
Joint unit of the plot's x axis.
QPointF CursorPosition
Relative position of the mouse cursor inside the coordinate system (between 0. and 1....
QPointF HoveredPoint
Hovered point belonging to any series in normalized coordinate system coordinates (between 0....
size_t HoveredSeries
Index of the data series the hovered point belongs to.
QPointF MinValues
Current lower axes limits of x and y axes.
QString YLabel
If empty, the y label is constructed from YUnit. Otherwise, YLabel is used.
QString GetMultiplierLabel() const
Returns the multiplier prefix associated with Multiplier.
bool XIsLogarithmic
Determines whether x axis is logarithmic.
QPointF HoveredSample
Hovered sample belonging to any series in the graphs's real coordinate system.
bool YIsLogarithmic
Determines whether y axis is logarithmic.
DynExp::Units::UnitType YUnit
Joint unit of the plot's y axis.
QString XLabel
If empty, the x label is constructed from XUnit. Otherwise, XLabel is used.
QPointF MaxValues
Current upper axes limits of x and y axes.
DynExpLineGraphPlotSeries(QString Name)
std::shared_ptr< QBarSeries > BarSeries