1 /*
2  * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB.  All rights reserved.
3  *
4  * This file is part of the KD Chart library.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef REVERSEMAPPER_H
21 #define REVERSEMAPPER_H
22 
23 #include <QModelIndex>
24 #include <QHash>
25 
26 QT_BEGIN_NAMESPACE
27 class QRectF;
28 class QGraphicsScene;
29 class QPolygonF;
30 QT_END_NAMESPACE
31 
32 namespace KChart {
33 
34     class AbstractDiagram;
35     class ChartGraphicsItem;
36 
37     /**
38       * @brief The ReverseMapper stores information about objects on a chart and their respective model indexes
39       * \internal
40       */
41     class ReverseMapper
42     {
43 
44     public:
45         ReverseMapper();
46         explicit ReverseMapper( AbstractDiagram* diagram );
47 
48         ~ReverseMapper();
49 
50         void setDiagram( AbstractDiagram* diagram );
51 
52         void clear();
53 
54         QModelIndexList indexesAt( const QPointF& point ) const;
55         QModelIndexList indexesIn( const QRect& rect ) const;
56 
57         QPolygonF polygon( int row, int column ) const;
58         QRectF boundingRect( int row, int column ) const;
59 
60         void addItem( ChartGraphicsItem* item );
61 
62         // convenience methods:
63         void addPolygon( int row, int column, const QPolygonF& polygon );
64         void addRect( int row, int column, const QRectF& rect );
65         void addCircle( int row, int column, const QPointF& location, const QSizeF& diameter );
66         void addLine( int row, int column, const QPointF& from, const QPointF& to );
67 
68     private:
69         QGraphicsScene* m_scene;
70         AbstractDiagram* m_diagram;
71         QHash<QModelIndex, ChartGraphicsItem*> m_itemMap;
72     };
73 
74 }
75 
76 #endif
77