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:
27  QCPBarsWithText(QCPAxis* keyAxis, QCPAxis* valueAxis)
28  : QCPBars(keyAxis, valueAxis), m_textOnTheLeft(false) {}
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 
89  QCPGraph* m_graph;
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 };
MouseEvent event
#define signals
#define QTCOMPAT_FONTMETRICS_WIDTH(fm, text)
Definition: QtCompat.h:339
QCustomPlot: vertical bar with text along side.
QCPBarsWithText(QCPAxis *keyAxis, QCPAxis *valueAxis)
QStringList m_text
void setText(QString text)
virtual void draw(QCPPainter *painter)
void setTextAlignment(bool left)
void appendText(QString text)
void mouseDoubleClickEvent(QMouseEvent *event) override
void mousePressEvent(QMouseEvent *event) override
WolmanCustomPlot(const Eigen::ArrayXf &d_sample, const Eigen::Array3d &dq_final, const Eigen::Array3d &edq)
Eigen::Array3d m_dq_final
Eigen::Array3d m_edq
QSharedPointer< QCPGraphDataContainer > dataContainer()