return;
for (const std::pair<std::string, std::shared_ptr<SignalController>>& p : sr->allControllers()) {
- dlg.addSignal(p.second->fromXAbs(), p.second->fromYAbs(), p.second->toXAbs(), p.second->toYAbs(), p.first);
+ GUIViewport vp = p.second->guiViewport();
+ dlg.addSignal(vp.absFromTime, vp.absFromValue, vp.absToTime, vp.absToValue, p.first);
}
do {
std::shared_ptr<SignalController> ctrl = sr->controllerAt(key);
GraphLayers gl = GraphLayers::GRAPH | GraphLayers::SCALE;
ImageDrawer::ReturnCode drwRet;
+ double relFromX, relFromY, relToX, relToY;
if (ctrl == nullptr) {
Logger::log(Logger::Level::CRITICAL, ME_SENDER_STR, "Invalid key " + QString::fromStdString(key) + " passed to image exporter");
if (dlg.includePeaks())
gl |= GraphLayers::INTEGRATION;
+ relFromX = ctrl->timeToRel(dlg.fromX());
+ relToX = ctrl->timeToRel(dlg.toX());
+ relFromY = ctrl->valueToRel(dlg.fromY());
+ relToY = ctrl->valueToRel(dlg.toY());
+
ImageDrawer imageDrawer(ctrl);
- drwRet = imageDrawer.render(dlg.path() + "." + dlg.imageFormat(), dlg.imageFormat().toLatin1(), dlg.imageWidth(), dlg.imageHeight(), gl);
+ drwRet = imageDrawer.render(dlg.path() + "." + dlg.imageFormat(), dlg.imageFormat().toLatin1(), dlg.imageWidth(), dlg.imageHeight(),
+ relFromX, relFromY, relToX, relToY, gl);
switch (drwRet) {
case ImageDrawer::ReturnCode::SUCCESS:
ret = 0;
setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding));
setMinimumWidth(SignalDrawer::SCALE_MARGIN_VALUE);
setMinimumHeight(SignalDrawer::SCALE_MARGIN_TIME);
+ m_controller->setGUIViewport(m_relXMin, m_relYMin, m_relXMax, m_relXMax);
connect(&m_ctxMenu, SIGNAL(deletePeak(QPoint)), this, SLOT(onCtxMenuDeletePeak(QPoint)));
connect(&m_ctxMenu, SIGNAL(zoomOut()), this, SLOT(onCtxMenuZoomOut()));
void GraphView::unzoom()
{
setDefaultZoom();
- if (draw(m_relXMin, m_relYMin, m_relXMax, m_relYMax))
+ if (draw(m_relXMin, m_relYMin, m_relXMax, m_relYMax)) {
update();
- else
+ m_controller->setGUIViewport(m_relXMin, m_relYMin, m_relXMax, m_relYMax);
+ } else
Logger::log(Logger::Level::CRITICAL, ME_SENDER_STR, __QFUNC__ + " unable to draw pixmap");
}
void GraphView::zoom(const int fromXPix, const int fromYPix, const int toXPix, const int toYPix)
{
bool ret = draw(xPixToRel(fromXPix), yPixToRel(fromYPix), xPixToRel(toXPix), yPixToRel(toYPix));
- if (ret)
+ if (ret) {
update();
- else
+ m_controller->setGUIViewport(m_relXMin, m_relYMin, m_relXMax, m_relYMax);
+ } else
Logger::log(Logger::Level::CRITICAL, ME_SENDER_STR, __QFUNC__ + " unable to draw pixmap");
}
m_imageWriter.setCompression(0);
}
-ImageDrawer::ReturnCode ImageDrawer::render(const QString& filename, const QByteArray format, const int width, const int height, const GraphLayers layers)
+ImageDrawer::ReturnCode ImageDrawer::render(const QString& filename, const QByteArray format, const int width, const int height,
+ const double fromX, const double fromY, const double toX, const double toY, const GraphLayers layers)
{
QImage image;
QFile file(filename);
if (!setDimensions(width, height))
return ReturnCode::E_INVAL_DIMENSIONS;
- if (!draw(SignalController::RELATIVE_MIN, SignalController::RELATIVE_MIN, SignalController::RELATIVE_MAX, SignalController::RELATIVE_MAX, layers))
+ if (!draw(fromX, fromY, toX, toY, layers))
return ReturnCode::E_CANNOT_DRAW;
m_imageWriter.setFileName(filename);
};
explicit ImageDrawer(std::shared_ptr<SignalController> controller);
- ReturnCode render(const QString& filename, const QByteArray format, const int width, const int height, const GraphLayers layers);
+ ReturnCode render(const QString& filename, const QByteArray format, const int width, const int height,
+ const double fromX, const double fromY, const double toX, const double toY, const GraphLayers layers);
static QList<QByteArray> supportedImageFormats();
return ret;
}
+double SignalController::timeToRel(const double time)
+{
+ const double fromTime = m_signal->timeAt(0);
+ const double toTime = m_signal->timeAt(m_signal->count()-1);
+ const double y = toTime - fromTime;
+ return (time - fromTime) * (RELATIVE_MAX - RELATIVE_MIN) / y;
+}
+
size_t SignalController::relToIdx(const double rel)
{
size_t ret = (m_signal->count() - 1) * (rel - RELATIVE_MIN) / (RELATIVE_MAX - RELATIVE_MIN);
return val;
}
+double SignalController::relToTime(const double rel)
+{
+ return m_signal->timeAt(relToIdx(rel));
+}
+
+void SignalController::setGUIViewport(const double fromX, const double fromY, const double toX, const double toY)
+{
+ m_guiViewport.absFromTime = relToTime(fromX);
+ m_guiViewport.absToTime = relToTime(toX);
+ m_guiViewport.absFromValue = relToValue(fromY);
+ m_guiViewport.absToValue = relToValue(toY);
+
+ m_guiViewport.relFromX = fromX;
+ m_guiViewport.relFromY = fromY;
+ m_guiViewport.relToX = toX;
+ m_guiViewport.relToY = toY;
+}
+
/** Public slots **/
SignalController::~SignalController()
#include <QDebug>
+struct GUIViewport {
+ double relFromX;
+ double relFromY;
+ double relToX;
+ double relToY;
+
+ double absFromTime;
+ double absToTime;
+ double absFromValue;
+ double absToValue;
+};
+
struct GraphDrawData {
GraphDrawData() :
ddata(nullptr), ddataLen(0) {}
std::shared_ptr<GraphDrawData> getGraphDrawData(const double fromX, const double toX);
std::vector<PeakDrawData> getPeaksDrawData(const double fromX, const double fromY, const double toX, const double toY);
RulerDrawData getRulerDrawData(const double from, const double to, SignalController::Axis axis);
+ GUIViewport guiViewport() const { return m_guiViewport; }
double fromXAbs() const { return m_signal->timeAt(0); }
double toXAbs() const { return m_signal->timeAt(m_signal->count()-1); }
double fromYAbs() const { return m_signal->valueAt(0); }
double toYAbs() const { return m_signal->valueAt(m_signal->count()-1); }
PeakDrawData integratePeak(const double fromX, const double fromY, const double toX, const double toY);
IntegrationTableModel* integrationTableModel() { return m_integTblModel;}
+ void setGUIViewport(const double fromX, const double fromY, const double toX, const double toY);
const std::shared_ptr<Signal> signal() const { return m_signal; }
const std::shared_ptr<Integrator> cIntegrator() const { return m_integrator; }
+ double idxToRel(const size_t idx);
+ double valueToRel(const double value);
+ double timeToRel(const double time);
+ size_t relToIdx(const double rel);
+ double relToValue(const double rel);
+ double relToTime(const double rel);
+
static const double RELATIVE_MAX;
static const double RELATIVE_MIN;
std::shared_ptr<Integrator> m_integrator;
std::shared_ptr<Signal> m_signal;
- double idxToRel(const size_t idx);
- double valueToRel(const double value);
- size_t relToIdx(const double rel);
- double relToValue(const double rel);
+ GUIViewport m_guiViewport;
+
void drawIntegratedPeak(const std::shared_ptr<const IntegratedPeak> peak);
PeakDrawData genPeakDrawData(const std::shared_ptr<const IntegratedPeak> peak);