linestring.h 4.08 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL   : http://qmapcontrol.sourceforge.net/
*
*/

#ifndef LINESTRING_H
#define LINESTRING_H

#include "curve.h"

namespace qmapcontrol
{
    //! A collection of Point objects to describe a line
    /*!
     * A LineString is a Curve with linear interpolation between Points. Each consecutive pair of Points defines a Line segment.
     *	@author Kai Winter <kaiwinter@gmx.de>
     */
    class LineString : public Curve
    {
        Q_OBJECT

    public:
        LineString();
        //! constructor
        /*!
         * The constructor of a LineString takes a list of Points to form a line.
         * @param points a list of points
         * @param name the name of the LineString
         * @param pen a QPen can be used to modify the look of the line.
         * @see http://doc.trolltech.com/4.3/qpen.html
         */
        LineString ( QList<Point*> const points, QString name = QString(), QPen* pen = 0 );
        virtual ~LineString();

        //! returns the points of the LineString
        /*!
         * @return  a list with the points of the LineString
         */
        QList<Point*>	points();

        //! adds a point at the end of the LineString
        /*!
         * @param point the point which should be added to the LineString
         */
        void addPoint ( Point* point );

        //! sets the given list as points of the LineString
        /*!
         * @param points the points which should be set for the LineString
         */
        void setPoints ( QList<Point*> points );

        //! returns the number of Points the LineString consists of
        /*!
         * @return the number of the LineString´s Points
         */
        int numberOfPoints() const;

        // virtual Geometry	Clone();
        virtual QRectF boundingBox();
        // virtual Point EndPoint();
        // virtual Point StartPoint();
        // virtual Point Value();

        //! returns true if the LineString has Childs
        /*!
         * This is equal to: numberOfPoints() > 0
         * @return true it the LineString has Childs (=Points)
         * @see clickedPoints()
         */
        virtual bool hasPoints() const;

        //! returns true if the LineString has clicked Points
        /*!
         * @return true if childs of a LineString were clicked
         * @see clickedPoints()
         */
        virtual bool hasClickedPoints() const;

        //! returns the clicked Points
        /*!
         * If a LineString was clicked it could be neccessary to figure out which of its points where clicked.
         * Do do so the methods hasPoints() and clickedPoints() can be used.
         * When a point is added to a LineString the Point becomes its child.
         * It is possible (depending on the zoomfactor) to click more than one Point of a LineString, so this method returns a list.
         * @return the clicked Points of the LineString
         */
        virtual QList<Geometry*> clickedPoints();

    protected:
        virtual bool Touches ( Geometry* geom, const MapAdapter* mapadapter );
        virtual bool Touches ( Point* geom, const MapAdapter* mapadapter );
        virtual void draw ( QPainter* painter, const MapAdapter* mapadapter, const QRect &screensize, const QPoint offset );

    private:
        QList<Point*>	vertices;
        QList<Geometry*> 	touchedPoints;
    };
}
#endif