00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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 }
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