I have following class declaration:
class GraphicsArc : public GraphicsComponent
{
public:
enum { Type = Arc };
explicit GraphicsArc();
explicit GraphicsArc(const ArcF &arc);
explicit GraphicsArc(qreal cx, qreal cy, qreal radius, qreal startAngle, qreal spanAngle);
~GraphicsArc();
ArcF arc() const;
void setArc(const ArcF &arc);
int type() const { return Type; }
private:
void updateBoundingRect();
ArcF m_arc;
};
class GraphicsArc : public GraphicsComponent
{
public:
enum { Type = Arc };
explicit GraphicsArc();
explicit GraphicsArc(const ArcF &arc);
explicit GraphicsArc(qreal cx, qreal cy, qreal radius, qreal startAngle, qreal spanAngle);
~GraphicsArc();
QRectF boundingRect() const;
QPainterPath shape() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
ArcF arc() const;
void setArc(const ArcF &arc);
int type() const { return Type; }
private:
void updateBoundingRect();
QPointF endPoint(const QPointF ¢er, qreal radius, qreal angle);
ArcF m_arc;
QRectF bounding_rect;
};
To copy to clipboard, switch view to plain text mode
and problem is here:
...
{
QPointF sp1
(endPoint
(m_arc.
center(), m_arc.
radius() - 5,
-m_arc.
startAngle()));
QPointF sp2
(endPoint
(m_arc.
center(), m_arc.
radius() + 5,
-m_arc.
startAngle()));
...
...
QPainterPath GraphicsArc::shape() const
{
QPainterPath path;
QPointF sp1 (endPoint(m_arc.center(), m_arc.radius() - 5, -m_arc.startAngle()));
QPointF sp2 (endPoint(m_arc.center(), m_arc.radius() + 5, -m_arc.startAngle()));
...
To copy to clipboard, switch view to plain text mode
Compiler says:
..\TestGraphicView\graphicsarc.cpp: In member function 'virtual QPainterPath GraphicsArc::shape() const':
..\TestGraphicView\graphicsarc.cpp:42: error: passing 'const GraphicsArc' as 'this' argument of 'QPointF GraphicsArc::endPoint(const QPointF&, qreal, qreal)' discards qualifiers
..\TestGraphicView\graphicsarc.cpp:43: error: passing 'const GraphicsArc' as 'this' argument of 'QPointF GraphicsArc::endPoint(const QPointF&, qreal, qreal)' discards qualifiers
I do not understand that, because there also a function updateBoundingRect, which also use endPoint(), and does not have same problem. I think it has something to do with virtual function, but I am not sure what.
Bookmarks