Programming questions

Sven Langkamp longamp at reallygood.de
Sun Jul 10 10:52:47 CEST 2005


Am Sonntag, 10. Juli 2005 10:25 schrieb Casper Boemann:
> On Sunday 10 July 2005 09:52, Michael Thaler wrote:
> > Hello,
> >
> > I still try to port the cubism filter and I have some questions:
> >
> > I wrote a KisPolygon class, that basically stores points and can rotate
> > and translate the points:
> >
> > class KisPolygon
> > {
> >         public:
> >                 KisPolygon();
> >                 void addPoint(double x, double y);
> >                 void translate(double tx, double ty);
> >                 void rotate(double theta);
> >                 Q_INT32 extents(double &minX, double &minY, double &maxX,
> > double &maxY);
> >                 void clear();
> >                 Q_INT32 numberOfPoints();
> >         private:
> >                 typedef QValueVector<KisPoint> KisPointVector;
> >                 KisPointVector* m_data;
> > };
> >
> > KisPolygon::KisPolygon()
> > {
> >         m_data = new KisPointVector(4);
> > }
> >
> > void KisPolygon::addPoint(double x, double y)
> > {
> >         KisPoint point(x, y);
> >         m_data->append(point);
> > }
> >
> > void KisPolygon::translate(double tx, double ty)
> > {
> >         KisPointVector::iterator it;
> >
> >         for( it = m_data->begin(); it != m_data->end(); ++it )
> >         {
> >                 (*it).setX( (*it).x() + tx );
> >                 (*it).setY( (*it).y() + ty );
> >         }
> > }
> >
> > and so on. Now I have the following function
> >
> > void KisCubismFilter::fillPolyColor (KisPaintDeviceSP src,
> > KisPaintDeviceSP dst, KisPolygon* poly, Q_UINT8* col, Q_UINT8* dest)
> >
> > which gets a pointer to my KisPolygon class. When I try to access the
> > first point in the KisPolygon class
> >
> > poly[0].x();
> >
> > I get the following error
> >
> > KisCubismFilter::fillPolyColor(KSharedPtr<KisPaintDevice>,
> >    KSharedPtr<KisPaintDevice>, KisPolygon*, Q_UINT8*, Q_UINT8*)':
> > kis_cubism_filter.cc:171: error: `x' undeclared (first use this function)
> > kis_cubism_filter.cc:171: error: (Each undeclared identifier is reported
> > only once for each function it appears in.)
> >
> > poly[0]->x(); does not work either:
> >
> > Then I get
> >
> > KisCubismFilter::fillPolyColor(KSharedPtr<KisPaintDevice>,
> >    KSharedPtr<KisPaintDevice>, KisPolygon*, Q_UINT8*, Q_UINT8*)':
> > kis_cubism_filter.cc:171: error: base operand of `->' has non-pointer
> > type ` KisPolygon'
> >
> > In http://doc.trolltech.org/3.3/qvaluevector.html#details it is explained
> > that you can access elements with []. Whoever, they did create the vector
> > on the stack, not with new. I think my bad C++ programming skills just
> > catched me:-) Can someone help me?
>
> you are trying to use [] on your KisPolygon class. There you haven't
> defined the [] operator.
> Trolltech have defined the [] on the QValueVector.
>
> If I were you I would make a function:
>
> KisPoint KisPolygon::getPoint(int i)
> {
> 	return m_data[i];
> }
To keep the [] you could use this:

KisPoint& KisPolygon::operator[](int i)
{
        return m_data[i];
}

Maybe it would be better to inherit KisPolygon from KisPointVector.


More information about the kimageshop mailing list