Skip to content
Snippets Groups Projects
Commit cd2683e6 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

infoString (x,y values and bin indices) now computed more directly

parent 3b174d36
No related branches found
No related tags found
1 merge request!2113rm PlotEventInfo
......@@ -14,6 +14,7 @@
#include "GUI/View/PlotSpecular/SpecularPlot.h"
#include "Base/Axis/Frame.h"
#include "Base/Py/PyFmt.h"
#include "Base/Util/Assert.h"
#include "Device/Data/Datafield.h"
#include "GUI/Model/Axis/AmplitudeAxisItem.h"
......@@ -92,6 +93,22 @@ PlotEventInfo SpecularPlot::eventInfo(double xpos, double ypos) const
return result;
}
QString SpecularPlot::infoString(QMouseEvent* event) const
{
double x = m_plot->xAxis->pixelToCoord(event->pos().x());
double y = m_plot->yAxis->pixelToCoord(event->pos().y());
int ix = bin(x, m_plot->graph());
QString intensityString = QString::fromStdString(Py::Fmt::printScientificDouble(y));
return QString(" [x: %1, y: %2] [binx: %3]")
.arg(QString::number(x, 'f', 4))
.arg(intensityString)
.arg(ix, 2);
}
void SpecularPlot::setLog()
{
if (!currentData1DItem())
......
......@@ -50,6 +50,8 @@ public:
//! sets logarithmic scale
void setLog();
QString infoString(QMouseEvent* event) const override;
private:
//! Propagate xmin, xmax back to Data2DItem
void onXaxisRangeChanged(QCPRange range);
......
......@@ -13,6 +13,7 @@
// ************************************************************************************************
#include "GUI/View/PlotUtil/ColorMap.h"
#include "Base/Py/PyFmt.h"
#include "Device/Data/Datafield.h"
#include "GUI/Model/Axis/AmplitudeAxisItem.h"
#include "GUI/Model/Axis/BasicAxisItem.h"
......@@ -170,6 +171,26 @@ PlotEventInfo ColorMap::eventInfo(double xpos, double ypos) const
return result;
}
QString ColorMap::infoString(QMouseEvent* event) const
{
double x = m_plot->xAxis->pixelToCoord(event->pos().x());
double y = m_plot->yAxis->pixelToCoord(event->pos().y());
int ix, iy;
m_colorMap->data()->coordToCell(x, y, &ix, &iy);
double intensity = m_colorMap->data()->cell(ix, iy);
QString intensityString = data2DItem()->isLog()
? QString::fromStdString(Py::Fmt::printScientificDouble(intensity))
: QString::number(intensity, 'f', 2);
return QString(" [x: %1, y: %2] [binx: %3, biny:%4] [value: %5]")
.arg(QString::number(x, 'f', 4))
.arg(QString::number(y, 'f', 4), 2)
.arg(ix, 2)
.arg(iy, 2)
.arg(intensityString);
}
//! sets logarithmic scale
void ColorMap::setLogz()
{
......
......@@ -47,6 +47,8 @@ public:
//! Returns PlotEventInfo corresponding to given axes coordinates.
PlotEventInfo eventInfo(double xpos, double ypos) const override;
QString infoString(QMouseEvent* event) const override;
signals:
void marginsChanged(double left, double right);
......
......@@ -51,14 +51,14 @@ void PlotEventHelper::onCustomMouseMove(QMouseEvent* event)
PlotEventInfo currentPos = m_plot->eventInfo(x, y);
if (currentPos.inAxesRange()) {
m_plot->statusString(currentPos.infoString());
m_plot->statusString(m_plot->infoString(event));
if (!m_prevPos.inAxesRange())
enteringPlot();
positionChanged(currentPos.x(), currentPos.y());
} else if (m_prevPos.inAxesRange()) {
m_plot->statusString(QString());
m_plot->statusString("");
leavingPlot();
}
......
......@@ -20,6 +20,7 @@
class PlotEventHelper;
class PlotEventInfo;
class QCustomPlot;
class QMouseEvent;
//! Common interface for plot-descriptor interaction
......@@ -48,6 +49,8 @@ public:
//! Returns the type of current plot
PLOT_TYPE plotType() const { return m_plot_type; }
virtual QString infoString(QMouseEvent* event) const = 0;
signals:
void statusString(const QString& text);
......
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