KD Chart 2  [rev.2.7]
KDChartPosition.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2020 Klaralvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Chart library.
5 **
6 ** Licensees holding valid commercial KD Chart licenses may use this file in
7 ** accordance with the KD Chart Commercial License Agreement provided with
8 ** the Software.
9 **
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 and version 3 as published by the
13 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
14 **
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 ** Contact info@kdab.com if any conditions of this licensing are not
19 ** clear to you.
20 **
21 **********************************************************************/
22 
23 #include <KDChartPosition.h>
24 #include <KDChartEnums.h>
25 
26 #include <QString>
27 #include <QStringList>
28 #include <QList>
29 #include <QByteArray>
30 
31 #include <KDABLibFakes>
32 
33 #include <cassert>
34 
35 using namespace KDChart;
36 
37 namespace {
42 static const char * staticPositionNames[] = {
43  QT_TRANSLATE_NOOP("Position","Unknown Position"),
44  QT_TRANSLATE_NOOP("Position","Center"),
45  QT_TRANSLATE_NOOP("Position","NorthWest"),
46  QT_TRANSLATE_NOOP("Position","North"),
47  QT_TRANSLATE_NOOP("Position","NorthEast"),
48  QT_TRANSLATE_NOOP("Position","East"),
49  QT_TRANSLATE_NOOP("Position","SouthEast"),
50  QT_TRANSLATE_NOOP("Position","South"),
51  QT_TRANSLATE_NOOP("Position","SouthWest"),
52  QT_TRANSLATE_NOOP("Position","West"),
53  QT_TRANSLATE_NOOP("Position","Floating")
54 };
55 
56 
61 static Position staticPositionUnknown = Position( KDChartEnums::PositionUnknown );
62 static Position staticPositionCenter = Position( KDChartEnums::PositionCenter );
63 static Position staticPositionNorthWest = Position( KDChartEnums::PositionNorthWest );
64 static Position staticPositionNorth = Position( KDChartEnums::PositionNorth );
65 static Position staticPositionNorthEast = Position( KDChartEnums::PositionNorthEast );
66 static Position staticPositionEast = Position( KDChartEnums::PositionEast );
67 static Position staticPositionSouthEast = Position( KDChartEnums::PositionSouthEast );
68 static Position staticPositionSouth = Position( KDChartEnums::PositionSouth );
69 static Position staticPositionSouthWest = Position( KDChartEnums::PositionSouthWest );
70 static Position staticPositionWest = Position( KDChartEnums::PositionWest );
71 static Position staticPositionFloating = Position( KDChartEnums::PositionFloating );
72 
73 static const int maxPositionValue = 10;
74 
75 } // anon namespace
76 
77 const Position& Position::Unknown = staticPositionUnknown;
78 const Position& Position::Center = staticPositionCenter;
79 const Position& Position::NorthWest = staticPositionNorthWest;
80 const Position& Position::North = staticPositionNorth;
81 const Position& Position::NorthEast = staticPositionNorthEast;
82 const Position& Position::East = staticPositionEast;
83 const Position& Position::SouthEast = staticPositionSouthEast;
84 const Position& Position::South = staticPositionSouth;
85 const Position& Position::SouthWest = staticPositionSouthWest;
86 const Position& Position::West = staticPositionWest;
87 const Position& Position::Floating = staticPositionFloating;
88 
89 
94  : m_value( KDChartEnums::PositionUnknown )
95 {
96 
97 }
98 
100  : m_value( value )
101 {
102  assert( 0 <= value ); assert( value <= maxPositionValue );
103 }
104 
118  : m_value( value )
119 {
120 
121 }
122 
127 {
128  return static_cast<KDChartEnums::PositionValue>( m_value );
129 }
130 
132 {
133  return m_value == Position::Unknown.value();
134 }
135 
137 {
138  return m_value == Position::SouthWest.value() ||
139  m_value == Position::West.value() ||
140  m_value == Position::NorthWest.value();
141 }
143 {
144  return m_value == Position::NorthWest.value() ||
145  m_value == Position::North.value() ||
146  m_value == Position::NorthEast.value();
147 }
149 {
150  return m_value == Position::NorthEast.value() ||
151  m_value == Position::East.value() ||
152  m_value == Position::SouthEast.value();
153 }
155 {
156  return m_value == Position::SouthWest.value() ||
157  m_value == Position::South.value() ||
158  m_value == Position::SouthEast.value();
159 }
160 
161 bool Position::isCorner() const
162 {
163  return m_value == Position::NorthWest.value() ||
164  m_value == Position::NorthEast.value() ||
165  m_value == Position::SouthEast.value() ||
166  m_value == Position::SouthWest.value();
167 }
168 bool Position::isPole() const
169 {
170  return m_value == Position::North.value() ||
171  m_value == Position::South.value();
172 }
173 
175 {
176  return m_value == Position::Floating.value();
177 }
178 
182 const char * Position::name() const
183 {
184  return staticPositionNames[m_value];
185 }
186 
190 QString Position::printableName() const
191 {
192  return tr(staticPositionNames[m_value]);
193 }
194 
195 
204 {
205  QList<QByteArray> list;
206  const int start = ( options & IncludeCenter ) ? 1 : 2;
207  const int end = ( options & IncludeFloating ) ? maxPositionValue : maxPositionValue-1;
208  for ( int i=start; i<=end; ++i)
209  list.append( staticPositionNames[i] );
210  return list;
211 }
212 
220 QStringList Position::printableNames( Options options )
221 {
222  QStringList list;
223  const int start = ( options & IncludeCenter ) ? 1 : 2;
224  const int end = ( options & IncludeFloating ) ? maxPositionValue : maxPositionValue-1;
225  for ( int i=start; i<=end; ++i)
226  list.append( Position(i).printableName() );
227  return list;
228 }
229 
231 {
232  for ( int i=1; i<=maxPositionValue; ++i)
233  if ( !qstricmp( name, staticPositionNames[i] ) )
234  return Position(i);
235  return Position(0);
236 }
237 
238 Position Position::fromName( const QByteArray & name ) {
239  return fromName( name.data() );
240 }
241 
242 bool Position::operator==( const Position& r ) const
243 {
244  return ( value() == r.value() );
245 }
246 
247 
248 bool Position::operator==( int value_ ) const
249 {
250  return ( value() == value_ );
251 }
252 
253 
254 #if !defined(QT_NO_DEBUG_STREAM)
255 QDebug operator<<(QDebug dbg, const KDChart::Position& p )
256 {
257  dbg << "KDChart::Position("
258  << p.name() << ")";
259  return dbg;
260 }
261 #endif /* QT_NO_DEBUG_STREAM */
static const Position & East
KDChartEnums::PositionValue value() const
Returns an integer value corresponding to this Position.
Project global class providing some enums needed both by KDChartParams and by KDChartCustomBox.
Definition: KDChartEnums.h:40
bool isFloating() const
Definition of global enums.
static const Position & South
static const Position & Center
bool isWestSide() const
bool isUnknown() const
bool isPole() const
static const Position & Unknown
Position()
Default constructor.
static const Position & NorthWest
QString printableName() const
Returns a translated string, 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.
bool operator==(const Position &) const
static const Position & West
PositionValue
Numerical values of the static KDChart::Position instances, for using a Position::value() with a swit...
Definition: KDChartEnums.h:192
bool isSouthSide() const
bool isCorner() const
bool isEastSide() const
static const Position & NorthEast
static Position fromName(const char *name)
static const Position & North
Defines a position, using compass terminology.
QDebug operator<<(QDebug stream, const DataDimension &r)
static const Position & SouthEast
bool isNorthSide() const
static const Position & Floating
const char * name() const
Returns a non-translated string in English language, corresponding to this Position.
static QList< QByteArray > names(Options options=Options(IncludeCenter|IncludeFloating))
Returns a list of all string, corresponding to the pre-defined positions.
static const Position & SouthWest

Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/

https://www.kdab.com/development-resources/qt-tools/kd-chart/