11 #include <qcustomplot.h>
39 qDebug() << Q_FUNC_INFO <<
"invalid key or value axis";
46 int fontHeight = painter->fontMetrics().height();
48 if (!
data()->isEmpty()) {
49 double &key =
data()->begin()->key;
50 double &value =
data()->begin()->value;
55 P.setX(P.x() + margin);
57 P.setY(P.y() + fontHeight);
59 for (
int i = 0; i <
m_text.size(); ++i) {
63 painter->fontMetrics().horizontalAdvance(
65 painter->drawText(Pstart,
m_text[i]);
66 P.setY(P.y() + fontHeight);
88 void setData(
const QVector<double> &key,
const QVector<double> &value) {
95 const QVector<double> &value,
96 const QVector<QColor> &
colors) {
97 Q_ASSERT(
colors.size() == key.size());
102 int n = qMin(key.size(), value.size());
104 for (
int i = 0; i < n; ++i) {
106 newData.
key = key[i];
107 newData.
value = value[i];
132 qDebug() << Q_FUNC_INFO <<
"invalid key or value axis";
136 QCPColoredBarDataMap::const_iterator it;
144 QRectF barRect =
getBarRect(it.key(), it.value().value);
146 if (
brush().style() != Qt::NoBrush &&
148 QBrush theBrush =
brush();
149 theBrush.setColor(it.value().color);
152 painter->
setPen(Qt::NoPen);
153 painter->setBrush(theBrush);
154 painter->drawRect(barRect);
157 if (
pen().style() != Qt::NoPen &&
pen().
color().alpha() != 0) {
159 thePen.setColor(it.value().color);
163 painter->setBrush(Qt::NoBrush);
164 painter->drawPolyline(barRect);
225 QVariant *details = 0)
const override {
232 const QRectF &rect)
const override {}
261 mPen = QPen(QColor(80, 80, 80), Qt::SolidLine);
278 int x2 =
static_cast<int>(
ceil(currentPosd));
280 if (x2 < rect.x())
return;
281 rect.setWidth(x2 - rect.x());
283 int x1 =
static_cast<int>(
floor(currentPosd));
285 if (x1 < rect.x())
return;
286 int newWidth = rect.width() - (x1 - rect.x());
288 rect.setWidth(newWidth);
295 painter->
setPen(Qt::NoPen);
297 QBrush(QColor(128, 128, 128, 128),
299 painter->drawPolygon(rect);
303 if (
pen().style() != Qt::NoPen &&
pen().
color().alpha() != 0) {
305 QPoint C(
mLeftSide ? rect.x() + rect.width() : rect.x(),
306 rect.y() + rect.height() / 2);
307 int r = rect.height() / 10;
310 painter->setBrush(
brush());
311 painter->drawEllipse(C, r, r);
313 painter->
setPen(QPen(QColor(128, 128, 128, 128),
315 painter->
drawLine(C + QPoint(0, r), C - QPoint(0, r));
338 mPen.setColor(QColor(128, 128, 0));
339 mPen.setStyle(Qt::SolidLine);
343 mBrush.setColor(QColor(255, 255, 0, 196));
344 mBrush.setStyle(Qt::SolidPattern);
350 mBrush.setColor(QColor(r, g, b, 196));
363 int r = rect.height() / 10;
367 QPen
pen(QColor(128, 128, 128, 128), Qt::DashLine);
370 painter->
drawLine(QPoint(currentPos, rect.y() + 2 * r),
371 QPoint(currentPos, rect.y() + rect.height()));
375 if (
pen().style() != Qt::NoPen &&
pen().
color().alpha() != 0) {
380 QPoint O(currentPos, rect.y() + r);
381 QPoint T[3] = {O + QPoint(0, r), O - QPoint(r, r),
385 painter->setBrush(
brush());
386 painter->drawPolygon(T, 3);
The abstract base class for all data representing objects in a plot.
QCPAxis * keyAxis() const
void applyDefaultAntialiasingHint(QCPPainter *painter) const
void setBrush(const QBrush &brush)
void coordsToPixels(double key, double value, double &x, double &y) const
QPointer< QCPAxis > mValueAxis
void applyFillAntialiasingHint(QCPPainter *painter) const
virtual QRect clipRect() const
void setPen(const QPen &pen)
QPointer< QCPAxis > mKeyAxis
QCPAxis * valueAxis() const
QCustomPlot: small arrows at the bottom.
virtual void draw(QCPPainter *painter)
QCPArrow(QCPAxis *keyAxis, QCPAxis *valueAxis)
void setColor(int r, int g, int b)
Sets triangle 'inside' color.
Manages a single axis inside a QCustomPlot.
double pixelToCoord(double value) const
double coordToPixel(double value) const
Holds the data of one single data point (one bar) for QCPBars.
QCustomPlot: vertical bar with text along side.
QCPBarsWithText(QCPAxis *keyAxis, QCPAxis *valueAxis)
void setText(QString text)
virtual void draw(QCPPainter *painter)
void setTextAlignment(bool left)
void appendText(QString text)
A plottable representing a bar chart in a plot.
QRectF getBarRect(double key, double value) const
void addData(const QVector< double > &keys, const QVector< double > &values, bool alreadySorted=false)
virtual void draw(QCPPainter *painter)
void setData(QSharedPointer< QCPBarsDataContainer > data)
QSharedPointer< QCPBarsDataContainer > data() const
QCustomPlot: colored histogram.
QCPColoredBarDataMap m_coloredData
virtual void draw(QCPPainter *painter)
QCPColoredBars(QCPAxis *keyAxis, QCPAxis *valueAxis)
QMultiMap< double, QCPColoredBarData > QCPColoredBarDataMap
void setData(const QVector< double > &key, const QVector< double > &value)
void setData(const QVector< double > &key, const QVector< double > &value, const QVector< QColor > &colors)
QCustomPlot: greyed areas.
QCPHiddenArea(bool leftSide, QCPAxis *keyAxis, QCPAxis *valueAxis)
virtual void draw(QCPPainter *painter)
bool mLeftSide
Whether the cursor is displayed on the left side or not.
QPainter subclass used internally.
void drawLine(const QLineF &line)
void setPen(const QPen &pen)
Represents the range an axis is encompassing.
QCustomPlot: selectable cursor interface.
double pixelToValue(int pixY) const
Converts a pixel value (Y) to the equivalent value.
void range(double &minVal, double &maxVal) const
double pixelToKey(int pixX) const
Converts a pixel value (X) to the equivalent key.
void setRange(double minVal, double maxVal)
virtual bool isSelectable(QPoint click) const
double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const override
QCPSelectableCursor(QCPAxis *keyAxis, QCPAxis *valueAxis)
Default constructor.
QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const override
QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const override
void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const override
void setCurrentVal(double val)
double currentVal() const
@ sdBoth
Both sign domains, including zero, i.e. all numbers.
MiniVec< float, N > floor(const MiniVec< float, N > &a)
MiniVec< float, N > ceil(const MiniVec< float, N > &a)
constexpr Rgb white(MAX, MAX, MAX)
constexpr Rgb blue(0, 0, MAX)