ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
WolmanCustomPlot.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <qcustomplot.h>
11 
12 // Qt5/Qt6 Compatibility
13 #include <QtCompat.h>
14 
15 // Eigen
16 #include <Eigen/Geometry>
17 
18 namespace Ui {
19 class WolmanCustomPlot;
20 }
21 
23 class QCPBarsWithText : public QCPBars {
24  Q_OBJECT
25 
26 public:
29 
30  void setText(QString text) { m_text = QStringList(text); }
31  void appendText(QString text) { m_text.append(text); }
32  void setTextAlignment(bool left) { m_textOnTheLeft = left; }
33 
34 protected:
35  QStringList m_text;
36  bool m_textOnTheLeft;
37 
38  // reimplemented virtual draw method
39  virtual void draw(QCPPainter* painter) {
40  if (!mKeyAxis || !mValueAxis) {
41  qDebug() << Q_FUNC_INFO << "invalid key or value axis";
42  return;
43  }
44 
45  // switch to standard display
46  QCPBars::draw(painter);
47 
48  int fontHeight = painter->fontMetrics().height();
49 
50  if (!data()->isEmpty()) {
51  double& key = data()->begin()->key;
52  double& value = data()->begin()->value;
53  QPointF P = coordsToPixels(key, value);
54  // apply a small shift
55  int margin = 5; // in pixels
56  if (m_textOnTheLeft) margin = -margin;
57  P.setX(P.x() + margin);
58  // we draw at the 'base' line
59  P.setY(P.y() + fontHeight);
60 
61  for (int i = 0; i < m_text.size(); ++i) {
62  QPointF Pstart = P;
63  if (m_textOnTheLeft)
64  Pstart.setX(P.x() -
66  painter->fontMetrics(), m_text[i]));
67  painter->drawText(Pstart, m_text[i]);
68  P.setY(P.y() + fontHeight);
69  }
70  }
71  }
72 };
73 
74 class WolmanCustomPlot : public QCustomPlot {
75  Q_OBJECT
76 public:
77  WolmanCustomPlot(const Eigen::ArrayXf& d_sample,
78  const Eigen::Array3d& dq_final,
79  const Eigen::Array3d& edq);
80 
81  QSharedPointer<QCPGraphDataContainer> dataContainer() {
82  return m_graph->data();
83  }
84 
85  Eigen::Array3d m_dq_final;
86 
87  Eigen::Array3d m_edq;
88 
90 
91  void rescale();
92 
93  void emitCloseTab() { emit closeTab(); }
94 
95  void mouseDoubleClickEvent(QMouseEvent* event) override;
96 
97  void mousePressEvent(QMouseEvent* event) override;
98 
99 signals:
100  void closeTab();
101 
102 private:
103  Ui::WolmanCustomPlot* ui;
104 };
WolmanCustomPlot::m_edq
Eigen::Array3d m_edq
Definition: WolmanCustomPlot.h:87
QCPBarsWithText::QCPBarsWithText
QCPBarsWithText(QCPAxis *keyAxis, QCPAxis *valueAxis)
Definition: WolmanCustomPlot.h:27
qcustomplot.h
QtCompat.h
QCPBars::data
QCPBarDataMap * data() const
Definition: qcustomplot.h:3455
QCPGraph::data
QCPDataMap * data() const
Definition: qcustomplot.h:3035
QTCOMPAT_FONTMETRICS_WIDTH
#define QTCOMPAT_FONTMETRICS_WIDTH(fm, text)
Definition: QtCompat.h:339
QCPAbstractPlottable::valueAxis
QCPAxis * valueAxis() const
Definition: qcustomplot.h:1709
QCPAxis
Manages a single axis inside a QCustomPlot.
Definition: qcustomplot.h:1199
WolmanCustomPlot::WolmanCustomPlot
WolmanCustomPlot(const Eigen::ArrayXf &d_sample, const Eigen::Array3d &dq_final, const Eigen::Array3d &edq)
Definition: WolmanCustomPlot.cpp:14
QCPBarsWithText::appendText
void appendText(QString text)
Definition: WolmanCustomPlot.h:31
QCPBars::draw
virtual void draw(QCPPainter *painter)
Definition: qcustomplot.cpp:19814
signals
#define signals
Definition: PythonPlugin.cpp:26
WolmanCustomPlot
Definition: WolmanCustomPlot.h:74
WolmanCustomPlot::m_dq_final
Eigen::Array3d m_dq_final
Definition: WolmanCustomPlot.h:85
QCPBars
A plottable representing a bar chart in a plot.
Definition: qcustomplot.h:3417
QCPBarsWithText::draw
virtual void draw(QCPPainter *painter)
Definition: WolmanCustomPlot.h:39
QCPGraph
A plottable representing a graph in a plot.
Definition: qcustomplot.h:2973
QCPBarsWithText::setText
void setText(QString text)
Definition: WolmanCustomPlot.h:30
QCPAbstractPlottable::mKeyAxis
QPointer< QCPAxis > mKeyAxis
Definition: qcustomplot.h:1765
WolmanCustomPlot::dataContainer
QSharedPointer< QCPGraphDataContainer > dataContainer()
Definition: WolmanCustomPlot.h:81
event
MouseEvent event
Definition: BitmapWindowSystem.cpp:61
WolmanCustomPlot::m_graph
QCPGraph * m_graph
Definition: WolmanCustomPlot.h:89
QCPBarsWithText
QCustomPlot: vertical bar with text along side.
Definition: ecvQCustomPlot.h:21
Ui
Definition: sfEditDlg.h:16
QCPBarsWithText::setTextAlignment
void setTextAlignment(bool left)
Definition: WolmanCustomPlot.h:32
QCPBarsWithText::m_textOnTheLeft
bool m_textOnTheLeft
Definition: ecvQCustomPlot.h:34
QCPAbstractPlottable::keyAxis
QCPAxis * keyAxis() const
Definition: qcustomplot.h:1708
WolmanCustomPlot::emitCloseTab
void emitCloseTab()
Definition: WolmanCustomPlot.h:93
WolmanCustomPlot::mouseDoubleClickEvent
void mouseDoubleClickEvent(QMouseEvent *event) override
Definition: WolmanCustomPlot.cpp:88
QCPBarsWithText::m_text
QStringList m_text
Definition: ecvQCustomPlot.h:33
QCPAbstractPlottable::coordsToPixels
void coordsToPixels(double key, double value, double &x, double &y) const
Definition: qcustomplot.cpp:7424
QCPAbstractPlottable::mValueAxis
QPointer< QCPAxis > mValueAxis
Definition: qcustomplot.h:1765
QCustomPlot
The central class of the library. This is the QWidget which displays the plot and interacts with the ...
Definition: qcustomplot.h:2020
WolmanCustomPlot::closeTab
void closeTab()
WolmanCustomPlot::rescale
void rescale()
Definition: WolmanCustomPlot.cpp:80
WolmanCustomPlot::mousePressEvent
void mousePressEvent(QMouseEvent *event) override
Definition: WolmanCustomPlot.cpp:95
QCPPainter
QPainter subclass used internally.
Definition: qcustomplot.h:463