home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / KDChartDataRegion.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-30  |  6.6 KB  |  227 lines

  1. /* -*- Mode: C++ -*-
  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 <qregion.h>
  33. #include <qpointarray.h>
  34.  
  35. #include "KDChartGlobal.h"
  36.  
  37. /*!
  38.   \internal
  39.   */
  40. struct KDCHART_EXPORT KDChartDataRegion
  41. {
  42.     typedef QValueList<QPointArray> PointArrayList;
  43.  
  44.     KDChartDataRegion()
  45.     {
  46.         init();
  47.     }
  48.  
  49.     KDChartDataRegion( QRegion region, uint r, uint c, uint ch )
  50.     {
  51.         init();
  52.         pRegion = new QRegion( region );
  53.         row     = r;
  54.         col     = c;
  55.         chart   = ch;
  56.     }
  57.  
  58.     KDChartDataRegion( uint r, uint c, uint ch, QPointArray array )
  59.     {
  60.         init();
  61.         pArray = new QPointArray( array );
  62.         row     = r;
  63.         col     = c;
  64.         chart   = ch;
  65.     }
  66.  
  67.     KDChartDataRegion( uint r, uint c, uint ch, QRect rect )
  68.     {
  69.         init();
  70.         pRect = new QRect( 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.         //qDebug ("~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.     QRegion region() const
  103.     {
  104.         if( pPointArrayList && ! pPointArrayList->empty() ){
  105.             QRegion region;
  106.             PointArrayList::iterator it;
  107.             for ( it = pPointArrayList->begin(); it != pPointArrayList->end(); ++it ){
  108.                 region += QRegion( *it );
  109.             }
  110.             return region;
  111.         }
  112.         if( pRegion )
  113.             return *pRegion;
  114.         if( pArray )
  115.             return QRegion( *pArray );
  116.         if( pRect )
  117.             return QRegion( *pRect );
  118.         return QRegion();
  119.     }
  120.  
  121.     QRect rect() const
  122.     {
  123.         if( pPointArrayList && ! pPointArrayList->empty() ){
  124.             QRect 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 QRect();
  138.     }
  139.  
  140.     bool contains(const QPoint & p) const
  141.     {
  142.         if( pPointArrayList && ! pPointArrayList->empty() ){
  143.             PointArrayList::iterator it;
  144.             for ( it = pPointArrayList->begin(); it != pPointArrayList->end(); ++it ){
  145.                 QRegion 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 QRegion( *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.     QRegion*     pRegion;
  177.     QPointArray* pArray;
  178.     QRect*       pRect;
  179.     QRegion*     pTextRegion;  // for the data values text
  180.  
  181.     // for three-dimensional bars, and for comparable structures, needing
  182.     // more than one QPointArray, 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.     QPointArray 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.     QString text;        // the data values text
  201.     bool    negative;    // stores whether the data value is less than zero
  202. };
  203.  
  204.  
  205. /**
  206.   \class KDChartDataRegionList KDChartDataRegion.h
  207.  
  208.   \brief The collection class used by KD Chart to store data region information.
  209.  
  210.   This class is derived from QPtrList, so all of the Qt documentation for this class
  211.   is valid for KDChartDataRegionList too.
  212.  
  213.   \note Normally there is no need to use this class yourself, since it
  214.   is instantiated by the KDChartWidget. If however you are not using the
  215.   KDChartWidget class but calling the painting methods of KDChart directly,
  216.   make sure to either free the pointer stored in KDChartDataRegionList manually,
  217.   or to call setAutoDelete( true ) to let your KDChartDataRegionList own these pointers:
  218.   in this case please also make sure to call the clear() method whenever you want
  219.   your KDChartDataRegionList to free these pointers.
  220.   Note that all of this ONLY applies in case of NOT using the KDChartWidget.
  221.  
  222.   \sa KDChart, KDChartWidget
  223.   */
  224. typedef QPtrList < KDChartDataRegion > KDChartDataRegionList;
  225.  
  226. #endif
  227.