kchart

KDChartDataRegion.h
1/*
2 KDChart - a multi-platform charting engine
3 */
4
5/****************************************************************************
6 ** Copyright (C) 2001-2003 Klarälvdalens Datakonsult AB. All rights reserved.
7 **
8 ** This file is part of the KDChart library.
9 **
10 ** This file may be distributed and/or modified under the terms of the
11 ** GNU General Public License version 2 as published by the Free Software
12 ** Foundation and appearing in the file LICENSE.GPL included in the
13 ** packaging of this file.
14 **
15 ** Licensees holding valid commercial KDChart licenses may use this file in
16 ** accordance with the KDChart Commercial License Agreement provided with
17 ** the Software.
18 **
19 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 **
22 ** See http://www.klaralvdalens-datakonsult.se/?page=products for
23 ** information about KDChart Commercial License Agreements.
24 **
25 ** Contact info@klaralvdalens-datakonsult.se if any conditions of this
26 ** licensing are not clear to you.
27 **
28 **********************************************************************/
29#ifndef __KDCHARTDATAREGION__
30#define __KDCHARTDATAREGION__
31
32#include <tqregion.h>
33#include <tqpointarray.h>
34
35#include "KDChartGlobal.h"
36
40struct KDCHART_EXPORT KDChartDataRegion
41{
42 typedef TQValueList<TQPointArray> PointArrayList;
43
44 KDChartDataRegion()
45 {
46 init();
47 }
48
49 KDChartDataRegion( TQRegion region, uint r, uint c, uint ch )
50 {
51 init();
52 pRegion = new TQRegion( region );
53 row = r;
54 col = c;
55 chart = ch;
56 }
57
58 KDChartDataRegion( uint r, uint c, uint ch, TQPointArray array )
59 {
60 init();
61 pArray = new TQPointArray( array );
62 row = r;
63 col = c;
64 chart = ch;
65 }
66
67 KDChartDataRegion( uint r, uint c, uint ch, TQRect rect )
68 {
69 init();
70 pRect = new TQRect( rect );
71 row = r;
72 col = c;
73 chart = ch;
74 }
75 KDChartDataRegion( uint r, uint c, uint ch, PointArrayList * list, bool takeOwnership )
76 {
77 init();
78 if( takeOwnership )
79 pPointArrayList = list;
80 else
81 pPointArrayList = new PointArrayList( * list );
82 row = r;
83 col = c;
84 chart = ch;
85 }
86
87 ~KDChartDataRegion()
88 {
89 //tqDebug ("~KDChartDataRegion");
90 if( pPointArrayList )
91 delete pPointArrayList;
92 if( pRegion )
93 delete pRegion;
94 if( pArray )
95 delete pArray;
96 if( pRect )
97 delete pRect;
98 if( pTextRegion )
99 delete pTextRegion;
100 }
101
102 TQRegion region() const
103 {
104 if( pPointArrayList && ! pPointArrayList->empty() ){
105 TQRegion region;
106 PointArrayList::iterator it;
107 for ( it = pPointArrayList->begin(); it != pPointArrayList->end(); ++it ){
108 region += TQRegion( *it );
109 }
110 return region;
111 }
112 if( pRegion )
113 return *pRegion;
114 if( pArray )
115 return TQRegion( *pArray );
116 if( pRect )
117 return TQRegion( *pRect );
118 return TQRegion();
119 }
120
121 TQRect rect() const
122 {
123 if( pPointArrayList && ! pPointArrayList->empty() ){
124 TQRect rect;
125 PointArrayList::iterator it;
126 for ( it = pPointArrayList->begin(); it != pPointArrayList->end(); ++it ){
127 rect = rect.unite( (*it).boundingRect() );
128 }
129 return rect;
130 }
131 if( pRegion )
132 return pRegion->boundingRect();
133 if( pArray )
134 return pArray->boundingRect();
135 if( pRect )
136 return *pRect;
137 return TQRect();
138 }
139
140 bool contains(const TQPoint & p) const
141 {
142 if( pPointArrayList && ! pPointArrayList->empty() ){
143 PointArrayList::iterator it;
144 for ( it = pPointArrayList->begin(); it != pPointArrayList->end(); ++it ){
145 TQRegion region( *it );
146 if( region.contains( p ) )
147 return true;
148 }
149 return false;
150 }
151 if( pRegion )
152 return pRegion->contains( p );
153 if( pArray )
154 return TQRegion( *pArray ).contains( p );
155 if( pRect )
156 return pRect->contains( p );
157 return false;
158 }
159
160 void init()
161 {
162 pRegion = 0;
163 pArray = 0;
164 pRect = 0;
165 pTextRegion = 0;
166 pPointArrayList = 0;
167 row = 0;
168 col = 0;
169 chart = 0;
170 negative = false; // default value (useful if value is a string)
171 points.resize( 9 );
172 startAngle = 1440;
173 angleLen = 1;
174 }
175
176 TQRegion* pRegion;
177 TQPointArray* pArray;
178 TQRect* pRect;
179 TQRegion* pTextRegion; // for the data values text
180
181 // for three-dimensional bars, and for comparable structures, needing
182 // more than one TQPointArray, we use this list:
183 PointArrayList* pPointArrayList;
184
185 // For rectangular data representation (bar, line, area, point, ...)
186 // we use the above declared 'pRect'.
187 // For curved data representations (pie slice, ring segment, ...)
188 // we store the following additional anchor information:
189
190 // store 9 elements: one for each value of KDChartEnums::PositionFlag
191 TQPointArray points;
192
193 int startAngle; // Note: 5760 makes a full circle, 2880 is left 'corner'.
194 int angleLen;
195
196 uint row;
197 uint col;
198 // members needed for calculation of data values texts
199 uint chart;
200 TQString text; // the data values text
201 bool negative; // stores whether the data value is less than zero
202};
203
204
224typedef TQPtrList < KDChartDataRegion > KDChartDataRegionList;
225
226#endif
The collection class used by KD Chart to store data region information.