Error while making arc

53 views Asked by At

I was trying to make an arc in QGraphicsScene But getting following error:

 error: cannot allocate an object of abstract type 'arc'
                 arcItem = new arc(++id, startP, midP, endP);

I am getting error in cadgraphicsscene at mousepressevent

void CadGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
    // mousePressEvent in the graphicsScene
    if(mouseEvent->button() == Qt::LeftButton)
    {
        switch (entityMode)
        {
         case ArcMode:
            if (mFirstClick)
            {
                startP = mouseEvent->scenePos();
                mFirstClick = false;
                mSecondClick = true;
            }

            else if (!mFirstClick && mSecondClick)
            {
                midP = mouseEvent->scenePos();
                mFirstClick = false;
                mSecondClick = false;
                mThirdClick = true;
            }

            else if (!mSecondClick && mThirdClick)
            {
                endP = mouseEvent->scenePos();
                mThirdClick = false;
                mPaintFlag = true;
            }

            if (mPaintFlag)
            {
                arcItem = new arc(++id, startP, midP, endP);
                itemList.append(arcItem);
                mUndoStack->push(new CadCommandAdd(this, arcItem));
                setFlags();
            }


        default:
            ;
        }
    }

My arc class looks as follows:

arc.cpp

    arc::arc(int i, QPointF point1, QPointF point2, QPointF point3)
    {
        // assigns id
        id = i;

        p1 = point1;
        p2 = point2;
        p3 = point3;

    }
int arc::type() const
{
    // Enable the use of qgraphicsitem_cast with ellipse item.
    return Type;
}

void arc::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
                     QWidget *widget)
{
    QPointF O; // intersection of lines
    QPointF B; // end point of horizontal line
    QPointF A;
    float halfSide = B.x()-O.x();
    QRectF rectangle(O.x() - halfSide,
                     O.y() - halfSide,
                     O.x() + halfSide,
                     O.y() + halfSide);

    int startAngle = 0;
    int spanAngle = (atan2(A.y()-O.y(),A.x()-O.x()) * 180 / M_PI) * 16;

    painter->drawArc(rectangle, startAngle, spanAngle);
}

The header file to above class is defined below:

arc.h

class arc : public QObject, public QGraphicsItem
{
    Q_OBJECT
public:
    arc(int, QPointF, QPointF, QPointF);
    virtual void paint(QPainter *painter,
                       const QStyleOptionGraphicsItem *option,
                       QWidget *widget);
    enum { Type = UserType + 6 };
    int type() const;
    int id;

    QPointF p1, p2, p3;

}

Please help me out to solve the error.

0

There are 0 answers