KDChartDataRegion.h

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*-
00002    KDChart - a multi-platform charting engine
00003    */
00004 
00005 /****************************************************************************
00006  ** Copyright (C) 2001-2003 Klarälvdalens Datakonsult AB.  All rights reserved.
00007  **
00008  ** This file is part of the KDChart library.
00009  **
00010  ** This file may be distributed and/or modified under the terms of the
00011  ** GNU General Public License version 2 as published by the Free Software
00012  ** Foundation and appearing in the file LICENSE.GPL included in the
00013  ** packaging of this file.
00014  **
00015  ** Licensees holding valid commercial KDChart licenses may use this file in
00016  ** accordance with the KDChart Commercial License Agreement provided with
00017  ** the Software.
00018  **
00019  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021  **
00022  ** See http://www.klaralvdalens-datakonsult.se/?page=products for
00023  **   information about KDChart Commercial License Agreements.
00024  **
00025  ** Contact info@klaralvdalens-datakonsult.se if any conditions of this
00026  ** licensing are not clear to you.
00027  **
00028  **********************************************************************/
00029 #ifndef __KDCHARTDATAREGION__
00030 #define __KDCHARTDATAREGION__
00031 
00032 #include <qregion.h>
00033 #include <qpointarray.h>
00034 
00035 #include "KDChartGlobal.h"
00036 
00040 struct KDCHART_EXPORT KDChartDataRegion
00041 {
00042     typedef QValueList<QPointArray> PointArrayList;
00043 
00044     KDChartDataRegion()
00045     {
00046         init();
00047     }
00048 
00049     KDChartDataRegion( QRegion region, uint r, uint c, uint ch )
00050     {
00051         init();
00052         pRegion = new QRegion( region );
00053         row     = r;
00054         col     = c;
00055         chart   = ch;
00056     }
00057 
00058     KDChartDataRegion( uint r, uint c, uint ch, QPointArray array )
00059     {
00060         init();
00061         pArray = new QPointArray( array );
00062         row     = r;
00063         col     = c;
00064         chart   = ch;
00065     }
00066 
00067     KDChartDataRegion( uint r, uint c, uint ch, QRect rect )
00068     {
00069         init();
00070         pRect = new QRect( rect );
00071         row   = r;
00072         col   = c;
00073         chart = ch;
00074     }
00075     KDChartDataRegion( uint r, uint c, uint ch, PointArrayList * list, bool takeOwnership )
00076     {
00077         init();
00078         if( takeOwnership )
00079             pPointArrayList = list;
00080         else
00081             pPointArrayList = new PointArrayList( * list );
00082         row   = r;
00083         col   = c;
00084         chart = ch;
00085     }
00086 
00087     ~KDChartDataRegion()
00088     {
00089         //qDebug ("~KDChartDataRegion");
00090         if( pPointArrayList )
00091             delete pPointArrayList;
00092         if( pRegion )
00093             delete pRegion;
00094         if( pArray )
00095             delete pArray;
00096         if( pRect )
00097             delete pRect;
00098         if( pTextRegion )
00099             delete pTextRegion;
00100     }
00101 
00102     QRegion region() const
00103     {
00104         if( pPointArrayList && ! pPointArrayList->empty() ){
00105             QRegion region;
00106             PointArrayList::iterator it;
00107             for ( it = pPointArrayList->begin(); it != pPointArrayList->end(); ++it ){
00108                 region += QRegion( *it );
00109             }
00110             return region;
00111         }
00112         if( pRegion )
00113             return *pRegion;
00114         if( pArray )
00115             return QRegion( *pArray );
00116         if( pRect )
00117             return QRegion( *pRect );
00118         return QRegion();
00119     }
00120 
00121     QRect rect() const
00122     {
00123         if( pPointArrayList && ! pPointArrayList->empty() ){
00124             QRect rect;
00125             PointArrayList::iterator it;
00126             for ( it = pPointArrayList->begin(); it != pPointArrayList->end(); ++it ){
00127                 rect = rect.unite( (*it).boundingRect() );
00128             }
00129             return rect;
00130         }
00131         if( pRegion )
00132             return pRegion->boundingRect();
00133         if( pArray )
00134             return pArray->boundingRect();
00135         if( pRect )
00136             return *pRect;
00137         return QRect();
00138     }
00139 
00140     bool contains(const QPoint & p) const
00141     {
00142         if( pPointArrayList && ! pPointArrayList->empty() ){
00143             PointArrayList::iterator it;
00144             for ( it = pPointArrayList->begin(); it != pPointArrayList->end(); ++it ){
00145                 QRegion region( *it );
00146                 if( region.contains( p ) )
00147                     return true;
00148             }
00149             return false;
00150         }
00151         if( pRegion )
00152             return pRegion->contains( p );
00153         if( pArray )
00154             return QRegion( *pArray ).contains( p );
00155         if( pRect )
00156             return pRect->contains( p );
00157         return false;
00158     }
00159 
00160     void init()
00161     {
00162         pRegion     = 0;
00163         pArray      = 0;
00164         pRect       = 0;
00165         pTextRegion = 0;
00166         pPointArrayList = 0;
00167         row    = 0;
00168         col    = 0;
00169         chart  = 0;
00170         negative = false; // default value (useful if value is a string)
00171         points.resize( 9 );
00172         startAngle = 1440;
00173         angleLen   =    1;
00174     }
00175 
00176     QRegion*     pRegion;
00177     QPointArray* pArray;
00178     QRect*       pRect;
00179     QRegion*     pTextRegion;  // for the data values text
00180 
00181     // for three-dimensional bars, and for comparable structures, needing
00182     // more than one QPointArray, we use this list:
00183     PointArrayList* pPointArrayList;
00184 
00185     // For rectangular data representation  (bar, line, area, point, ...)
00186     // we use the above declared 'pRect'.
00187     // For curved data representations (pie slice, ring segment, ...)
00188     // we store the following additional anchor information:
00189 
00190     // store 9 elements: one for each value of KDChartEnums::PositionFlag
00191     QPointArray points;
00192 
00193     int startAngle; // Note: 5760 makes a full circle, 2880 is left 'corner'.
00194     int angleLen;
00195 
00196     uint row;
00197     uint col;
00198     // members needed for calculation of data values texts
00199     uint chart;
00200     QString text;        // the data values text
00201     bool    negative;    // stores whether the data value is less than zero
00202 };
00203 
00204 
00224 typedef QPtrList < KDChartDataRegion > KDChartDataRegionList;
00225 
00226 #endif

Generated on Wed Jan 26 13:03:16 2011 for KMyMoney by  doxygen 1.5.6