KDChartPosition.h

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*-
00002   KDChart - a multi-platform charting engine
00003   */
00004 
00005 /****************************************************************************
00006 ** Copyright (C) 2005-2007 Klarälvdalens Datakonsult AB.  All rights reserved.
00007 **
00008 ** This file is part of the KD Chart 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 KD Chart licenses may use this file in
00016 ** accordance with the KD Chart 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.kdab.net/kdchart for
00023 **   information about KD Chart Commercial License Agreements.
00024 **
00025 ** Contact info@kdab.net if any conditions of this
00026 ** licensing are not clear to you.
00027 **
00028 **********************************************************************/
00029 
00030 #ifndef KDCHARTPOSITION_H
00031 #define KDCHARTPOSITION_H
00032 
00033 #include <QDebug>
00034 #include <Qt>
00035 #include <QMetaType>
00036 #include <QCoreApplication>
00037 #include "KDChartGlobal.h"
00038 #include "KDChartEnums.h"
00039 
00040 class QStringList;
00041 class QByteArray;
00042 template <typename T> class QList;
00043 
00044 namespace KDChart {
00045 
00075 class KDCHART_EXPORT Position
00076 {
00077     Q_DECLARE_TR_FUNCTIONS( Position )
00078     Position( int value );
00079 public:
00080     Position();
00081     Position( KDChartEnums::PositionValue value ); // intentionally non-explicit
00082 
00083     KDChartEnums::PositionValue value() const;
00084 
00085     const char * name() const;
00086     QString printableName() const;
00087 
00088     bool isUnknown() const;
00089 
00090     bool isWestSide() const;
00091     bool isNorthSide() const;
00092     bool isEastSide() const;
00093     bool isSouthSide() const;
00094 
00095     bool isCorner() const;
00096     bool isPole() const;
00097 
00098     bool isFloating() const;
00099 
00100     static const Position& Unknown;
00101     static const Position& Center;
00102     static const Position& NorthWest;
00103     static const Position& North;
00104     static const Position& NorthEast;
00105     static const Position& East;
00106     static const Position& SouthEast;
00107     static const Position& South;
00108     static const Position& SouthWest;
00109     static const Position& West;
00110 
00111     static const Position& Floating;
00112 
00113     // boolean flags: 1, 2, 4, 8, ...
00114     enum Option {
00115         IncludeCenter   = 0x1,
00116         IncludeFloating = 0x2 };
00117     Q_DECLARE_FLAGS( Options, Option )
00118 
00119     // Unfortunately the following typecast from int to Options is needed
00120     // as the | operator is not defined yet, this will be done by
00121     // the makro Q_DECLARE_OPERATORS_FOR_FLAGS( KDChart::Position::Options )
00122     // at the bottom of this file.
00123     static QList<QByteArray> names( Options options    = Options(IncludeCenter | IncludeFloating) );
00124     static QStringList printableNames( Options options = Options(IncludeCenter | IncludeFloating) );
00125 
00126     static Position fromName(const char * name);
00127     static Position fromName(const QByteArray & name);
00128 
00129     bool operator==( const Position& ) const;
00130     bool operator==( int ) const;
00131     bool operator!=( const Position& ) const;
00132     bool operator!=( int ) const;
00133 
00134 private:
00135     int m_value;
00136 }; // End of class Position
00137 
00138 inline bool Position::operator!=( const Position & other ) const { return !operator==( other ); }
00139 inline bool Position::operator!=( int other ) const { return !operator==( other ); }
00140 
00145 class KDCHART_EXPORT PositionPoints
00146 {
00147   public:
00148     PositionPoints(){} // all points get initialized with the default automatically
00149 
00150     PositionPoints(
00151         QPointF center,
00152         QPointF northWest,
00153         QPointF north,
00154         QPointF northEast,
00155         QPointF east,
00156         QPointF southEast,
00157         QPointF south,
00158         QPointF southWest,
00159         QPointF west )
00160       : mPositionCenter(    center )
00161       , mPositionNorthWest( northWest )
00162       , mPositionNorth(     north )
00163       , mPositionNorthEast( northEast )
00164       , mPositionEast(      east )
00165       , mPositionSouthEast( southEast )
00166       , mPositionSouth(     south )
00167       , mPositionSouthWest( southWest )
00168       , mPositionWest(      west )
00169         {}
00170     PositionPoints(
00171         const QPointF& onePointForAllPositions )
00172       : mPositionCenter(    onePointForAllPositions )
00173       , mPositionNorthWest( onePointForAllPositions )
00174       , mPositionNorth(     onePointForAllPositions )
00175       , mPositionNorthEast( onePointForAllPositions )
00176       , mPositionEast(      onePointForAllPositions )
00177       , mPositionSouthEast( onePointForAllPositions )
00178       , mPositionSouth(     onePointForAllPositions )
00179       , mPositionSouthWest( onePointForAllPositions )
00180       , mPositionWest(      onePointForAllPositions )
00181         {}
00182     PositionPoints(
00183         const QRectF& rect )
00184     {
00185         const QRectF r( rect.normalized() );
00186         mPositionCenter    = r.center();
00187         mPositionNorthWest = r.topLeft();
00188         mPositionNorth     = QPointF(r.center().x(), r.top());
00189         mPositionNorthEast = r.topRight();
00190         mPositionEast      = QPointF(r.right(), r.center().y());
00191         mPositionSouthEast = r.bottomRight();
00192         mPositionSouth     = QPointF(r.center().x(), r.bottom());
00193         mPositionSouthWest = r.bottomLeft();
00194         mPositionWest      = QPointF(r.left(), r.center().y());
00195     }
00196     PositionPoints(
00197         QPointF northWest,
00198         QPointF northEast,
00199         QPointF southEast,
00200         QPointF southWest )
00201       : mPositionCenter(    (northWest + southEast) / 2.0 )
00202       , mPositionNorthWest( northWest )
00203       , mPositionNorth(     (northWest + northEast) / 2.0 )
00204       , mPositionNorthEast( northEast )
00205       , mPositionEast(      (northEast + southEast) / 2.0 )
00206       , mPositionSouthEast( southEast )
00207       , mPositionSouth(     (southWest + southEast) / 2.0 )
00208       , mPositionSouthWest( southWest )
00209       , mPositionWest(      (northWest + southWest) / 2.0 )
00210         {}
00211 
00212     void setDegrees( KDChartEnums::PositionValue pos, qreal degrees )
00213     {
00214         mapOfDegrees[pos] = degrees;
00215     }
00216 
00217 #if QT_VERSION < 0x040400 || defined(Q_COMPILER_MANGLES_RETURN_TYPE)
00218     const qreal degrees( KDChartEnums::PositionValue pos ) const
00219 #else
00220     qreal degrees( KDChartEnums::PositionValue pos ) const
00221 #endif
00222     {
00223         if( mapOfDegrees.contains(pos) )
00224             return mapOfDegrees[pos];
00225         return 0.0;
00226     }
00227 
00228 #if QT_VERSION < 0x040400 || defined(Q_COMPILER_MANGLES_RETURN_TYPE)
00229     const QPointF point( Position position ) const
00230 #else
00231     QPointF point( Position position ) const
00232 #endif
00233     {
00234       //qDebug() << "point( " << position.name() << " )";
00235       if( position ==  Position::Center)
00236         return mPositionCenter;
00237       if( position ==  Position::NorthWest)
00238         return mPositionNorthWest;
00239       if( position ==  Position::North)
00240         return mPositionNorth;
00241       if( position ==  Position::NorthEast)
00242         return mPositionNorthEast;
00243       if( position ==  Position::East)
00244         return mPositionEast;
00245       if( position ==  Position::SouthEast)
00246         return mPositionSouthEast;
00247       if( position ==  Position::South)
00248         return mPositionSouth;
00249       if( position ==  Position::SouthWest)
00250         return mPositionSouthWest;
00251       if( position ==  Position::West)
00252         return mPositionWest;
00253       return mPositionUnknown;
00254     }
00255 
00256     bool isNull() const
00257     {
00258         return
00259             mPositionUnknown.isNull() &&
00260             mPositionCenter.isNull() &&
00261             mPositionNorthWest.isNull() &&
00262             mPositionNorth.isNull() &&
00263             mPositionNorthEast.isNull() &&
00264             mPositionEast.isNull() &&
00265             mPositionSouthEast.isNull() &&
00266             mPositionSouth.isNull() &&
00267             mPositionSouthWest.isNull() &&
00268             mPositionWest.isNull();
00269     }
00270 
00271     QPointF mPositionUnknown;
00272     QPointF mPositionCenter;
00273     QPointF mPositionNorthWest;
00274     QPointF mPositionNorth;
00275     QPointF mPositionNorthEast;
00276     QPointF mPositionEast;
00277     QPointF mPositionSouthEast;
00278     QPointF mPositionSouth;
00279     QPointF mPositionSouthWest;
00280     QPointF mPositionWest;
00281     QMap<KDChartEnums::PositionValue, qreal> mapOfDegrees;
00282 
00283 }; // End of class PositionPoints
00284 
00285 
00286 }
00287 
00288 Q_DECLARE_TYPEINFO( KDChart::Position, Q_MOVABLE_TYPE );
00289 Q_DECLARE_METATYPE( KDChart::Position )
00290 Q_DECLARE_OPERATORS_FOR_FLAGS( KDChart::Position::Options )
00291 
00292 #if !defined(QT_NO_DEBUG_STREAM)
00293 KDCHART_EXPORT QDebug operator<<(QDebug, const KDChart::Position& );
00294 #endif /* QT_NO_DEBUG_STREAM */
00295 
00296 #endif // KDCHARTPOSITION_H

Generated on Thu Mar 4 23:19:12 2010 for KD Chart 2 by  doxygen 1.5.4