KD Chart 2
[rev.2.5]
|
00001 /**************************************************************************** 00002 ** Copyright (C) 2001-2012 Klaralvdalens Datakonsult AB. All rights reserved. 00003 ** 00004 ** This file is part of the KD Chart library. 00005 ** 00006 ** Licensees holding valid commercial KD Chart licenses may use this file in 00007 ** accordance with the KD Chart Commercial License Agreement provided with 00008 ** the Software. 00009 ** 00010 ** 00011 ** This file may be distributed and/or modified under the terms of the 00012 ** GNU General Public License version 2 and version 3 as published by the 00013 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included. 00014 ** 00015 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00016 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00017 ** 00018 ** Contact info@kdab.com if any conditions of this licensing are not 00019 ** clear to you. 00020 ** 00021 **********************************************************************/ 00022 00023 #include <KDChartPosition.h> 00024 #include <KDChartEnums.h> 00025 00026 #include <QString> 00027 #include <QStringList> 00028 #include <QList> 00029 #include <QByteArray> 00030 00031 #include <KDABLibFakes> 00032 00033 #include <cassert> 00034 00035 using namespace KDChart; 00036 00037 namespace { 00042 static const char * staticPositionNames[] = { 00043 QT_TRANSLATE_NOOP("Position","Unknown Position"), 00044 QT_TRANSLATE_NOOP("Position","Center"), 00045 QT_TRANSLATE_NOOP("Position","NorthWest"), 00046 QT_TRANSLATE_NOOP("Position","North"), 00047 QT_TRANSLATE_NOOP("Position","NorthEast"), 00048 QT_TRANSLATE_NOOP("Position","East"), 00049 QT_TRANSLATE_NOOP("Position","SouthEast"), 00050 QT_TRANSLATE_NOOP("Position","South"), 00051 QT_TRANSLATE_NOOP("Position","SouthWest"), 00052 QT_TRANSLATE_NOOP("Position","West"), 00053 QT_TRANSLATE_NOOP("Position","Floating") 00054 }; 00055 00056 00061 static Position staticPositionUnknown = Position( KDChartEnums::PositionUnknown ); 00062 static Position staticPositionCenter = Position( KDChartEnums::PositionCenter ); 00063 static Position staticPositionNorthWest = Position( KDChartEnums::PositionNorthWest ); 00064 static Position staticPositionNorth = Position( KDChartEnums::PositionNorth ); 00065 static Position staticPositionNorthEast = Position( KDChartEnums::PositionNorthEast ); 00066 static Position staticPositionEast = Position( KDChartEnums::PositionEast ); 00067 static Position staticPositionSouthEast = Position( KDChartEnums::PositionSouthEast ); 00068 static Position staticPositionSouth = Position( KDChartEnums::PositionSouth ); 00069 static Position staticPositionSouthWest = Position( KDChartEnums::PositionSouthWest ); 00070 static Position staticPositionWest = Position( KDChartEnums::PositionWest ); 00071 static Position staticPositionFloating = Position( KDChartEnums::PositionFloating ); 00072 00073 static const int maxPositionValue = 10; 00074 00075 } // anon namespace 00076 00077 const Position& Position::Unknown = staticPositionUnknown; 00078 const Position& Position::Center = staticPositionCenter; 00079 const Position& Position::NorthWest = staticPositionNorthWest; 00080 const Position& Position::North = staticPositionNorth; 00081 const Position& Position::NorthEast = staticPositionNorthEast; 00082 const Position& Position::East = staticPositionEast; 00083 const Position& Position::SouthEast = staticPositionSouthEast; 00084 const Position& Position::South = staticPositionSouth; 00085 const Position& Position::SouthWest = staticPositionSouthWest; 00086 const Position& Position::West = staticPositionWest; 00087 const Position& Position::Floating = staticPositionFloating; 00088 00089 00093 Position::Position() 00094 : m_value( KDChartEnums::PositionUnknown ) 00095 { 00096 00097 } 00098 00099 Position::Position( int value ) 00100 : m_value( value ) 00101 { 00102 assert( 0 <= value ); assert( value <= maxPositionValue ); 00103 } 00104 00117 Position::Position( KDChartEnums::PositionValue value ) 00118 : m_value( value ) 00119 { 00120 00121 } 00122 00126 KDChartEnums::PositionValue Position::value() const 00127 { 00128 return static_cast<KDChartEnums::PositionValue>( m_value ); 00129 } 00130 00131 bool Position::isUnknown() const 00132 { 00133 return m_value == Position::Unknown.value(); 00134 } 00135 00136 bool Position::isWestSide() const 00137 { 00138 return m_value == Position::SouthWest.value() || 00139 m_value == Position::West.value() || 00140 m_value == Position::NorthWest.value(); 00141 } 00142 bool Position::isNorthSide() const 00143 { 00144 return m_value == Position::NorthWest.value() || 00145 m_value == Position::North.value() || 00146 m_value == Position::NorthEast.value(); 00147 } 00148 bool Position::isEastSide() const 00149 { 00150 return m_value == Position::NorthEast.value() || 00151 m_value == Position::East.value() || 00152 m_value == Position::SouthEast.value(); 00153 } 00154 bool Position::isSouthSide() const 00155 { 00156 return m_value == Position::SouthWest.value() || 00157 m_value == Position::South.value() || 00158 m_value == Position::SouthEast.value(); 00159 } 00160 00161 bool Position::isCorner() const 00162 { 00163 return m_value == Position::NorthWest.value() || 00164 m_value == Position::NorthEast.value() || 00165 m_value == Position::SouthEast.value() || 00166 m_value == Position::SouthWest.value(); 00167 } 00168 bool Position::isPole() const 00169 { 00170 return m_value == Position::North.value() || 00171 m_value == Position::South.value(); 00172 } 00173 00174 bool Position::isFloating() const 00175 { 00176 return m_value == Position::Floating.value(); 00177 } 00178 00182 const char * Position::name() const 00183 { 00184 return staticPositionNames[m_value]; 00185 } 00186 00190 QString Position::printableName() const 00191 { 00192 return tr(staticPositionNames[m_value]); 00193 } 00194 00195 00203 QList<QByteArray> Position::names( Options options ) 00204 { 00205 QList<QByteArray> list; 00206 const int start = ( options & IncludeCenter ) ? 1 : 2; 00207 const int end = ( options & IncludeFloating ) ? maxPositionValue : maxPositionValue-1; 00208 for( int i=start; i<=end; ++i) 00209 list.append( staticPositionNames[i] ); 00210 return list; 00211 } 00212 00220 QStringList Position::printableNames( Options options ) 00221 { 00222 QStringList list; 00223 const int start = ( options & IncludeCenter ) ? 1 : 2; 00224 const int end = ( options & IncludeFloating ) ? maxPositionValue : maxPositionValue-1; 00225 for( int i=start; i<=end; ++i) 00226 list.append( Position(i).printableName() ); 00227 return list; 00228 } 00229 00230 Position Position::fromName(const char * name) 00231 { 00232 for( int i=1; i<=maxPositionValue; ++i) 00233 if ( !qstricmp( name, staticPositionNames[i] ) ) 00234 return Position(i); 00235 return Position(0); 00236 } 00237 00238 Position Position::fromName( const QByteArray & name ) { 00239 return fromName( name.data() ); 00240 } 00241 00242 bool Position::operator==( const Position& r ) const 00243 { 00244 return ( value() == r.value() ); 00245 } 00246 00247 00248 bool Position::operator==( int value_ ) const 00249 { 00250 return ( value() == value_ ); 00251 } 00252 00253 00254 #if !defined(QT_NO_DEBUG_STREAM) 00255 QDebug operator<<(QDebug dbg, const KDChart::Position& p ) 00256 { 00257 dbg << "KDChart::Position(" 00258 << p.name() << ")"; 00259 return dbg; 00260 } 00261 #endif /* QT_NO_DEBUG_STREAM */