KDChartPosition.cpp

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*-
00002    KDChart - a multi-platform charting engine
00003    */
00004 
00005 /****************************************************************************
00006  ** Copyright (C) 2001-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 #include <KDChartPosition.h>
00031 #include <KDChartEnums.h>
00032 
00033 #include <QString>
00034 #include <QStringList>
00035 #include <QList>
00036 #include <QByteArray>
00037 
00038 #include <KDABLibFakes>
00039 
00040 #include <cassert>
00041 
00042 using namespace KDChart;
00043 
00044 namespace {
00049 static const char * staticPositionNames[] = {
00050     QT_TRANSLATE_NOOP("Position","Unknown Position"),
00051     QT_TRANSLATE_NOOP("Position","Center"),
00052     QT_TRANSLATE_NOOP("Position","NorthWest"),
00053     QT_TRANSLATE_NOOP("Position","North"),
00054     QT_TRANSLATE_NOOP("Position","NorthEast"),
00055     QT_TRANSLATE_NOOP("Position","East"),
00056     QT_TRANSLATE_NOOP("Position","SouthEast"),
00057     QT_TRANSLATE_NOOP("Position","South"),
00058     QT_TRANSLATE_NOOP("Position","SouthWest"),
00059     QT_TRANSLATE_NOOP("Position","West"),
00060     QT_TRANSLATE_NOOP("Position","Floating")
00061 };
00062 
00063 
00068 static Position staticPositionUnknown   = Position( KDChartEnums::PositionUnknown );
00069 static Position staticPositionCenter    = Position( KDChartEnums::PositionCenter );
00070 static Position staticPositionNorthWest = Position( KDChartEnums::PositionNorthWest );
00071 static Position staticPositionNorth     = Position( KDChartEnums::PositionNorth );
00072 static Position staticPositionNorthEast = Position( KDChartEnums::PositionNorthEast );
00073 static Position staticPositionEast      = Position( KDChartEnums::PositionEast );
00074 static Position staticPositionSouthEast = Position( KDChartEnums::PositionSouthEast );
00075 static Position staticPositionSouth     = Position( KDChartEnums::PositionSouth );
00076 static Position staticPositionSouthWest = Position( KDChartEnums::PositionSouthWest );
00077 static Position staticPositionWest      = Position( KDChartEnums::PositionWest );
00078 static Position staticPositionFloating  = Position( KDChartEnums::PositionFloating );
00079 
00080 static int maxPositionValue = 10;
00081 
00082 } // anon namespace
00083 
00084 const Position& Position::Unknown   = staticPositionUnknown;
00085 const Position& Position::Center    = staticPositionCenter;
00086 const Position& Position::NorthWest = staticPositionNorthWest;
00087 const Position& Position::North     = staticPositionNorth;
00088 const Position& Position::NorthEast = staticPositionNorthEast;
00089 const Position& Position::East      = staticPositionEast;
00090 const Position& Position::SouthEast = staticPositionSouthEast;
00091 const Position& Position::South     = staticPositionSouth;
00092 const Position& Position::SouthWest = staticPositionSouthWest;
00093 const Position& Position::West      = staticPositionWest;
00094 const Position& Position::Floating  = staticPositionFloating;
00095 
00096 
00100 Position::Position()
00101     : m_value( KDChartEnums::PositionUnknown )
00102 {
00103 
00104 }
00105 
00106 Position::Position( int value )
00107     : m_value( value )
00108 {
00109     assert( 0 <= value ); assert( value <= maxPositionValue );
00110 }
00111 
00124 Position::Position( KDChartEnums::PositionValue value )
00125     : m_value( value )
00126 {
00127 
00128 }
00129 
00133 KDChartEnums::PositionValue Position::value() const
00134 {
00135     return static_cast<KDChartEnums::PositionValue>( m_value );
00136 }
00137 
00138 bool Position::isUnknown() const
00139 {
00140     return  m_value == Position::Unknown.value();
00141 }
00142 
00143 bool Position::isWestSide() const
00144 {
00145     return  m_value == Position::SouthWest.value() ||
00146             m_value == Position::West.value() ||
00147             m_value == Position::NorthWest.value();
00148 }
00149 bool Position::isNorthSide() const
00150 {
00151     return  m_value == Position::NorthWest.value() ||
00152             m_value == Position::North.value() ||
00153             m_value == Position::NorthEast.value();
00154 }
00155 bool Position::isEastSide() const
00156 {
00157     return  m_value == Position::NorthEast.value() ||
00158             m_value == Position::East.value() ||
00159             m_value == Position::SouthEast.value();
00160 }
00161 bool Position::isSouthSide() const
00162 {
00163     return  m_value == Position::SouthWest.value() ||
00164             m_value == Position::South.value() ||
00165             m_value == Position::SouthEast.value();
00166 }
00167 
00168 bool Position::isCorner() const
00169 {
00170     return  m_value == Position::NorthWest.value() ||
00171             m_value == Position::NorthEast.value() ||
00172             m_value == Position::SouthEast.value() ||
00173             m_value == Position::SouthWest.value();
00174 }
00175 bool Position::isPole() const
00176 {
00177     return  m_value == Position::North.value() ||
00178         m_value == Position::South.value();
00179 }
00180 
00181 bool Position::isFloating() const
00182 {
00183     return  m_value == Position::Floating.value();
00184 }
00185 
00189 const char * Position::name() const
00190 {
00191     return staticPositionNames[m_value];
00192 }
00193 
00197 QString Position::printableName() const
00198 {
00199     return tr(staticPositionNames[m_value]);
00200 }
00201 
00202 
00210 QList<QByteArray> Position::names( Options options )
00211 {
00212     QList<QByteArray> list;
00213     const int start = ( options & IncludeCenter   ) ? 1 : 2;
00214     const int end   = ( options & IncludeFloating ) ? maxPositionValue : maxPositionValue-1;
00215     for( int i=start; i<=end; ++i)
00216         list.append( staticPositionNames[i] );
00217     return list;
00218 }
00219 
00227 QStringList Position::printableNames( Options options )
00228 {
00229     QStringList list;
00230     const int start = ( options & IncludeCenter   ) ? 1 : 2;
00231     const int end   = ( options & IncludeFloating ) ? maxPositionValue : maxPositionValue-1;
00232     for( int i=start; i<=end; ++i)
00233         list.append( Position(i).printableName() );
00234     return list;
00235 }
00236 
00237 Position Position::fromName(const char * name)
00238 {
00239     for( int i=1; i<=maxPositionValue; ++i)
00240         if ( !qstricmp( name, staticPositionNames[i] ) )
00241             return Position(i);
00242     return Position(0);
00243 }
00244 
00245 Position Position::fromName( const QByteArray & name ) {
00246     return fromName( name.data() );
00247 }
00248 
00249 bool Position::operator==( const Position& r ) const
00250 {
00251     return ( value() == r.value() );
00252 }
00253 
00254 
00255 bool Position::operator==( int value_ ) const
00256 {
00257     return ( value() == value_ );
00258 }
00259 
00260 
00261 #if !defined(QT_NO_DEBUG_STREAM)
00262 QDebug operator<<(QDebug dbg, const KDChart::Position& p )
00263 {
00264     dbg << "KDChart::Position("
00265         << p.name() << ")";
00266     return dbg;
00267 }
00268 #endif /* QT_NO_DEBUG_STREAM */

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