KChart

KChartPosition.cpp
1 /*
2  * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3  *
4  * This file is part of the KD Chart library.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #include <KChartPosition.h>
21 
22 #include <KChartEnums.h>
23 #include "KChartMath_p.h"
24 
25 #include <QString>
26 #include <QStringList>
27 #include <QList>
28 #include <QByteArray>
29 
30 #include <cassert>
31 
32 using namespace KChart;
33 
34 namespace {
39 static const char * staticPositionNames[] = {
40  QT_TRANSLATE_NOOP("Position","Unknown Position"),
41  QT_TRANSLATE_NOOP("Position","Center"),
42  QT_TRANSLATE_NOOP("Position","NorthWest"),
43  QT_TRANSLATE_NOOP("Position","North"),
44  QT_TRANSLATE_NOOP("Position","NorthEast"),
45  QT_TRANSLATE_NOOP("Position","East"),
46  QT_TRANSLATE_NOOP("Position","SouthEast"),
47  QT_TRANSLATE_NOOP("Position","South"),
48  QT_TRANSLATE_NOOP("Position","SouthWest"),
49  QT_TRANSLATE_NOOP("Position","West"),
50  QT_TRANSLATE_NOOP("Position","Floating")
51 };
52 
53 
58 static Position staticPositionUnknown = Position( KChartEnums::PositionUnknown );
59 static Position staticPositionCenter = Position( KChartEnums::PositionCenter );
60 static Position staticPositionNorthWest = Position( KChartEnums::PositionNorthWest );
61 static Position staticPositionNorth = Position( KChartEnums::PositionNorth );
62 static Position staticPositionNorthEast = Position( KChartEnums::PositionNorthEast );
63 static Position staticPositionEast = Position( KChartEnums::PositionEast );
64 static Position staticPositionSouthEast = Position( KChartEnums::PositionSouthEast );
65 static Position staticPositionSouth = Position( KChartEnums::PositionSouth );
66 static Position staticPositionSouthWest = Position( KChartEnums::PositionSouthWest );
67 static Position staticPositionWest = Position( KChartEnums::PositionWest );
68 static Position staticPositionFloating = Position( KChartEnums::PositionFloating );
69 
70 static const int maxPositionValue = 10;
71 
72 } // anon namespace
73 
74 const Position& Position::Unknown = staticPositionUnknown;
75 const Position& Position::Center = staticPositionCenter;
76 const Position& Position::NorthWest = staticPositionNorthWest;
77 const Position& Position::North = staticPositionNorth;
78 const Position& Position::NorthEast = staticPositionNorthEast;
79 const Position& Position::East = staticPositionEast;
80 const Position& Position::SouthEast = staticPositionSouthEast;
81 const Position& Position::South = staticPositionSouth;
82 const Position& Position::SouthWest = staticPositionSouthWest;
83 const Position& Position::West = staticPositionWest;
84 const Position& Position::Floating = staticPositionFloating;
85 
86 
91  : m_value( KChartEnums::PositionUnknown )
92 {
93 
94 }
95 
97  : m_value( value )
98 {
99  assert( 0 <= value ); assert( value <= maxPositionValue );
100 }
101 
115  : m_value( value )
116 {
117 
118 }
119 
124 {
125  return static_cast<KChartEnums::PositionValue>( m_value );
126 }
127 
128 bool Position::isUnknown() const
129 {
130  return m_value == Position::Unknown.value();
131 }
132 
133 bool Position::isWestSide() const
134 {
135  return m_value == Position::SouthWest.value() ||
136  m_value == Position::West.value() ||
137  m_value == Position::NorthWest.value();
138 }
139 bool Position::isNorthSide() const
140 {
141  return m_value == Position::NorthWest.value() ||
142  m_value == Position::North.value() ||
143  m_value == Position::NorthEast.value();
144 }
145 bool Position::isEastSide() const
146 {
147  return m_value == Position::NorthEast.value() ||
148  m_value == Position::East.value() ||
149  m_value == Position::SouthEast.value();
150 }
151 bool Position::isSouthSide() const
152 {
153  return m_value == Position::SouthWest.value() ||
154  m_value == Position::South.value() ||
155  m_value == Position::SouthEast.value();
156 }
157 
158 bool Position::isCorner() const
159 {
160  return m_value == Position::NorthWest.value() ||
161  m_value == Position::NorthEast.value() ||
162  m_value == Position::SouthEast.value() ||
163  m_value == Position::SouthWest.value();
164 }
165 bool Position::isPole() const
166 {
167  return m_value == Position::North.value() ||
168  m_value == Position::South.value();
169 }
170 
171 bool Position::isFloating() const
172 {
173  return m_value == Position::Floating.value();
174 }
175 
179 const char * Position::name() const
180 {
181  return staticPositionNames[m_value];
182 }
183 
188 {
189  return tr(staticPositionNames[m_value]);
190 }
191 
192 
201 {
202  QList<QByteArray> list;
203  const int start = ( options & IncludeCenter ) ? 1 : 2;
204  const int end = ( options & IncludeFloating ) ? maxPositionValue : maxPositionValue-1;
205  for ( int i=start; i<=end; ++i)
206  list.append( staticPositionNames[i] );
207  return list;
208 }
209 
218 {
219  QStringList list;
220  const int start = ( options & IncludeCenter ) ? 1 : 2;
221  const int end = ( options & IncludeFloating ) ? maxPositionValue : maxPositionValue-1;
222  for ( int i=start; i<=end; ++i)
223  list.append( Position(i).printableName() );
224  return list;
225 }
226 
227 Position Position::fromName(const char * name)
228 {
229  for ( int i=1; i<=maxPositionValue; ++i)
230  if ( !qstricmp( name, staticPositionNames[i] ) )
231  return Position(i);
232  return Position(0);
233 }
234 
235 Position Position::fromName( const QByteArray & name ) {
236  return fromName( name.data() );
237 }
238 
239 bool Position::operator==( const Position& r ) const
240 {
241  return ( value() == r.value() );
242 }
243 
244 
245 bool Position::operator==( int value_ ) const
246 {
247  return ( value() == value_ );
248 }
249 
250 
251 #if !defined(QT_NO_DEBUG_STREAM)
253 {
254  dbg << "KChart::Position("
255  << p.name() << ")";
256  return dbg;
257 }
258 #endif /* QT_NO_DEBUG_STREAM */
KChartEnums::PositionValue value() const
Returns an integer value corresponding to this Position.
static QStringList printableNames(Options options=Options(IncludeCenter|IncludeFloating))
Returns a list of all translated string, corresponding to the pre-defined positions.
PositionValue
Numerical values of the static KChart::Position instances, for using a Position::value() with a switc...
Definition: KChartEnums.h:191
Defines a position, using compass terminology.
Project global class providing some enums needed both by KChartParams and by KChartCustomBox.
Definition: KChartEnums.h:37
void append(const T &value)
Position()
Default constructor.
QString printableName() const
Returns a translated string, corresponding to this Position.
QDataStream & operator<<(QDataStream &out, const KDateTime::Spec &spec)
Definition of global enums.
static QList< QByteArray > names(Options options=Options(IncludeCenter|IncludeFloating))
Returns a list of all string, corresponding to the pre-defined positions.
char * data()
const char * name() const
Returns a non-translated string in English language, corresponding to this Position.
Global namespace.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Nov 30 2020 22:37:02 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.