legendmarker.cpp
109 lines
| 2.3 KiB
| text/x-c
|
CppLexer
/ src / legendmarker.cpp
sauimone
|
r547 | #include "qchartglobal.h" | ||
#include "legendmarker_p.h" | ||||
#include <QPainter> | ||||
#include <QGraphicsSceneEvent> | ||||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
LegendMarker::LegendMarker(QSeries* series, QGraphicsItem *parent) | ||||
: QGraphicsObject(parent) | ||||
sauimone
|
r565 | ,mBoundingRect(0,0,1,1) | ||
,mName("") | ||||
sauimone
|
r547 | ,mSeries(series) | ||
sauimone
|
r565 | ,mBarset(0) | ||
,mPieslice(0) | ||||
,mType(LegendMarkerTypeSeries) | ||||
{ | ||||
setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); | ||||
} | ||||
sauimone
|
r576 | LegendMarker::LegendMarker(QSeries *series, QBarSet *barset, QGraphicsItem *parent) | ||
sauimone
|
r565 | : QGraphicsObject(parent) | ||
,mBoundingRect(0,0,1,1) | ||||
,mName("") | ||||
sauimone
|
r576 | ,mSeries(series) | ||
sauimone
|
r565 | ,mBarset(barset) | ||
,mPieslice(0) | ||||
,mType(LegendMarkerTypeBarset) | ||||
{ | ||||
setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); | ||||
} | ||||
sauimone
|
r576 | LegendMarker::LegendMarker(QSeries *series, QPieSlice *pieslice, QGraphicsItem *parent) | ||
sauimone
|
r565 | : QGraphicsObject(parent) | ||
sauimone
|
r547 | ,mBoundingRect(0,0,1,1) | ||
sauimone
|
r565 | ,mName("") | ||
sauimone
|
r576 | ,mSeries(series) | ||
sauimone
|
r565 | ,mBarset(0) | ||
,mPieslice(pieslice) | ||||
,mType(LegendMarkerTypePieslice) | ||||
sauimone
|
r547 | { | ||
setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); | ||||
} | ||||
void LegendMarker::setBoundingRect(const QRectF rect) | ||||
{ | ||||
mBoundingRect = rect; | ||||
} | ||||
void LegendMarker::setBrush(const QBrush brush) | ||||
{ | ||||
mBrush = brush; | ||||
} | ||||
sauimone
|
r565 | QBrush LegendMarker::brush() const | ||
{ | ||||
return mBrush; | ||||
} | ||||
sauimone
|
r547 | void LegendMarker::setName(const QString name) | ||
{ | ||||
mName = name; | ||||
} | ||||
QString LegendMarker::name() const | ||||
{ | ||||
return mName; | ||||
} | ||||
sauimone
|
r576 | QSeries* LegendMarker::series() const | ||
{ | ||||
return mSeries; | ||||
} | ||||
sauimone
|
r547 | void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | ||
{ | ||||
painter->setBrush(mBrush); | ||||
painter->drawRect(mBoundingRect); | ||||
} | ||||
QRectF LegendMarker::boundingRect() const | ||||
{ | ||||
return mBoundingRect; | ||||
} | ||||
void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event) | ||||
{ | ||||
sauimone
|
r565 | switch (mType) | ||
{ | ||||
case LegendMarkerTypeSeries: { | ||||
sauimone
|
r567 | emit clicked(mSeries,event->button()); | ||
sauimone
|
r565 | break; | ||
sauimone
|
r569 | } | ||
sauimone
|
r565 | case LegendMarkerTypeBarset: { | ||
sauimone
|
r567 | emit clicked(mBarset,event->button()); | ||
sauimone
|
r565 | break; | ||
sauimone
|
r569 | } | ||
sauimone
|
r565 | case LegendMarkerTypePieslice: { | ||
sauimone
|
r567 | emit clicked(mPieslice,event->button()); | ||
sauimone
|
r565 | break; | ||
} | ||||
default: { | ||||
break; | ||||
sauimone
|
r569 | } | ||
sauimone
|
r565 | } | ||
sauimone
|
r547 | } | ||
#include "moc_legendmarker_p.cpp" | ||||
QTCOMMERCIALCHART_END_NAMESPACE | ||||