summaryrefslogtreecommitdiffstats
path: root/kchart/kdchart/KDChartDataRegion.h
blob: 0854a86babf112ab50e4888255309f011581aa25 (plain)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/* -*- Mode: C++ -*-
   KDChart - a multi-platform charting engine
   */

/****************************************************************************
 ** Copyright (C) 2001-2003 Klarälvdalens Datakonsult AB.  All rights reserved.
 **
 ** This file is part of the KDChart library.
 **
 ** This file may be distributed and/or modified under the terms of the
 ** GNU General Public License version 2 as published by the Free Software
 ** Foundation and appearing in the file LICENSE.GPL included in the
 ** packaging of this file.
 **
 ** Licensees holding valid commercial KDChart licenses may use this file in
 ** accordance with the KDChart Commercial License Agreement provided with
 ** the Software.
 **
 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 **
 ** See http://www.klaralvdalens-datakonsult.se/?page=products for
 **   information about KDChart Commercial License Agreements.
 **
 ** Contact [email protected] if any conditions of this
 ** licensing are not clear to you.
 **
 **********************************************************************/
#ifndef __KDCHARTDATAREGION__
#define __KDCHARTDATAREGION__

#include <tqregion.h>
#include <tqpointarray.h>

#include "KDChartGlobal.h"

/*!
  \internal
  */
struct KDCHART_EXPORT KDChartDataRegion
{
    typedef TQValueList<TQPointArray> PointArrayList;

    KDChartDataRegion()
    {
        init();
    }

    KDChartDataRegion( TQRegion region, uint r, uint c, uint ch )
    {
        init();
        pRegion = new TQRegion( region );
        row     = r;
        col     = c;
        chart   = ch;
    }

    KDChartDataRegion( uint r, uint c, uint ch, TQPointArray array )
    {
        init();
        pArray = new TQPointArray( array );
        row     = r;
        col     = c;
        chart   = ch;
    }

    KDChartDataRegion( uint r, uint c, uint ch, TQRect rect )
    {
        init();
        pRect = new TQRect( rect );
        row   = r;
        col   = c;
        chart = ch;
    }
    KDChartDataRegion( uint r, uint c, uint ch, PointArrayList * list, bool takeOwnership )
    {
        init();
        if( takeOwnership )
            pPointArrayList = list;
        else
            pPointArrayList = new PointArrayList( * list );
        row   = r;
        col   = c;
        chart = ch;
    }

    ~KDChartDataRegion()
    {
        //tqDebug ("~KDChartDataRegion");
        if( pPointArrayList )
            delete pPointArrayList;
        if( pRegion )
            delete pRegion;
        if( pArray )
            delete pArray;
        if( pRect )
            delete pRect;
        if( pTextRegion )
            delete pTextRegion;
    }

    TQRegion region() const
    {
        if( pPointArrayList && ! pPointArrayList->empty() ){
            TQRegion region;
            PointArrayList::iterator it;
            for ( it = pPointArrayList->begin(); it != pPointArrayList->end(); ++it ){
                region += TQRegion( *it );
            }
            return region;
        }
        if( pRegion )
            return *pRegion;
        if( pArray )
            return TQRegion( *pArray );
        if( pRect )
            return TQRegion( *pRect );
        return TQRegion();
    }

    TQRect rect() const
    {
        if( pPointArrayList && ! pPointArrayList->empty() ){
            TQRect rect;
            PointArrayList::iterator it;
            for ( it = pPointArrayList->begin(); it != pPointArrayList->end(); ++it ){
                rect = rect.unite( (*it).boundingRect() );
            }
            return rect;
        }
        if( pRegion )
            return pRegion->boundingRect();
        if( pArray )
            return pArray->boundingRect();
        if( pRect )
            return *pRect;
        return TQRect();
    }

    bool contains(const TQPoint & p) const
    {
        if( pPointArrayList && ! pPointArrayList->empty() ){
            PointArrayList::iterator it;
            for ( it = pPointArrayList->begin(); it != pPointArrayList->end(); ++it ){
                TQRegion region( *it );
                if( region.contains( p ) )
                    return true;
            }
            return false;
        }
        if( pRegion )
            return pRegion->contains( p );
        if( pArray )
            return TQRegion( *pArray ).contains( p );
        if( pRect )
            return pRect->contains( p );
        return false;
    }

    void init()
    {
        pRegion     = 0;
        pArray      = 0;
        pRect       = 0;
        pTextRegion = 0;
        pPointArrayList = 0;
        row    = 0;
        col    = 0;
        chart  = 0;
        negative = false; // default value (useful if value is a string)
        points.resize( 9 );
        startAngle = 1440;
        angleLen   =    1;
    }

    TQRegion*     pRegion;
    TQPointArray* pArray;
    TQRect*       pRect;
    TQRegion*     pTextRegion;  // for the data values text

    // for three-dimensional bars, and for comparable structures, needing
    // more than one TQPointArray, we use this list:
    PointArrayList* pPointArrayList;

    // For rectangular data representation  (bar, line, area, point, ...)
    // we use the above declared 'pRect'.
    // For curved data representations (pie slice, ring segment, ...)
    // we store the following additional anchor information:

    // store 9 elements: one for each value of KDChartEnums::PositionFlag
    TQPointArray points;

    int startAngle; // Note: 5760 makes a full circle, 2880 is left 'corner'.
    int angleLen;

    uint row;
    uint col;
    // members needed for calculation of data values texts
    uint chart;
    TQString text;        // the data values text
    bool    negative;    // stores whether the data value is less than zero
};


/**
  \class KDChartDataRegionList KDChartDataRegion.h

  \brief The collection class used by KD Chart to store data region information.

  This class is derived from TQPtrList, so all of the TQt documentation for this class
  is valid for KDChartDataRegionList too.

  \note Normally there is no need to use this class yourself, since it
  is instantiated by the KDChartWidget. If however you are not using the
  KDChartWidget class but calling the painting methods of KDChart directly,
  make sure to either free the pointer stored in KDChartDataRegionList manually,
  or to call setAutoDelete( true ) to let your KDChartDataRegionList own these pointers:
  in this case please also make sure to call the clear() method whenever you want
  your KDChartDataRegionList to free these pointers.
  Note that all of this ONLY applies in case of NOT using the KDChartWidget.

  \sa KDChart, KDChartWidget
  */
typedef TQPtrList < KDChartDataRegion > KDChartDataRegionList;

#endif