added all files
[ffqwlibrary] / libffqw-n810-1.0 / sources / ffchartseries.cpp
1 /*
2           GNU GENERAL PUBLIC LICENSE
3                        Version 3, 29 June 2007
4
5  Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
6  Everyone is permitted to copy and distribute verbatim copies
7  of this license document, but changing it is not allowed.
8
9                             Preamble
10
11   The GNU General Public License is a free, copyleft license for
12 software and other kinds of works.
13
14   The licenses for most software and other practical works are designed
15 to take away your freedom to share and change the works.  By contrast,
16 the GNU General Public License is intended to guarantee your freedom to
17 share and change all versions of a program--to make sure it remains free
18 software for all its users.  We, the Free Software Foundation, use the
19 GNU General Public License for most of our software; it applies also to
20 any other work released this way by its authors.  You can apply it to
21 your programs, too.
22
23   When we speak of free software, we are referring to freedom, not
24 price.  Our General Public Licenses are designed to make sure that you
25 have the freedom to distribute copies of free software (and charge for
26 them if you wish), that you receive source code or can get it if you
27 want it, that you can change the software or use pieces of it in new
28 free programs, and that you know you can do these things.
29
30   To protect your rights, we need to prevent others from denying you
31 these rights or asking you to surrender the rights.  Therefore, you have
32 certain responsibilities if you distribute copies of the software, or if
33 you modify it: responsibilities to respect the freedom of others.
34
35   For example, if you distribute copies of such a program, whether
36 gratis or for a fee, you must pass on to the recipients the same
37 freedoms that you received.  You must make sure that they, too, receive
38 or can get the source code.  And you must show them these terms so they
39 know their rights.
40
41   Developers that use the GNU GPL protect your rights with two steps:
42 (1) assert copyright on the software, and (2) offer you this License
43 giving you legal permission to copy, distribute and/or modify it.
44
45   For the developers' and authors' protection, the GPL clearly explains
46 that there is no warranty for this free software.  For both users' and
47 authors' sake, the GPL requires that modified versions be marked as
48 changed, so that their problems will not be attributed erroneously to
49 authors of previous versions.
50
51   Some devices are designed to deny users access to install or run
52 modified versions of the software inside them, although the manufacturer
53 can do so.  This is fundamentally incompatible with the aim of
54 protecting users' freedom to change the software.  The systematic
55 pattern of such abuse occurs in the area of products for individuals to
56 use, which is precisely where it is most unacceptable.  Therefore, we
57 have designed this version of the GPL to prohibit the practice for those
58 products.  If such problems arise substantially in other domains, we
59 stand ready to extend this provision to those domains in future versions
60 of the GPL, as needed to protect the freedom of users.
61
62   Finally, every program is threatened constantly by software patents.
63 States should not allow patents to restrict development and use of
64 software on general-purpose computers, but in those that do, we wish to
65 avoid the special danger that patents applied to a free program could
66 make it effectively proprietary.  To prevent this, the GPL assures that
67 patents cannot be used to render the program non-free.
68
69   The precise terms and conditions for copying, distribution and
70 modification follow.
71
72 http://www.gnu.org/licenses/gpl-3.0.txt
73 */
74 /**
75  * @file ffchartseries.cpp
76  * @brief Implementation of the FFChartSeries class.
77  *
78  * @author ComArch S.A.
79  * @date 2009.09.01
80  * @version 1.1
81  */
82
83 #include "ffchartseries.h"
84
85 /**
86  * Construct FFSeries
87  */
88 FFChartSeries::FFChartSeries()
89 {
90         init();
91 }
92 /**
93  * Constructs a FFChartSeries with points' vector and name.
94  *
95  */
96 FFChartSeries::FFChartSeries(const QVector<QPointF>& series,
97                              const QString& name)
98 {
99         init();
100         pen_ = QPen();
101         set(series,name);
102 }
103 /**
104  * Constructs a FFChartSeries with points' vector, pen and name.
105  */
106 FFChartSeries::FFChartSeries(const QVector<QPointF>& series,
107                              const QPen& pen,
108                              const QString& name)
109 {
110         init();
111         set(series,pen,name);
112 }
113 /**
114  * A virtual destructor.
115  */
116 FFChartSeries::~FFChartSeries()
117 {
118         ;
119 }
120 /**
121  * Sets default values
122  */
123 void FFChartSeries::init()
124 {
125         visibility_ = true;
126 }
127
128 /**
129  * Returns series's name
130  */
131 QString FFChartSeries::name() const
132 {
133         return name_;
134 }
135 /**
136  * Returns series's pen
137  */
138 QPen* FFChartSeries::pen()
139 {
140         return &pen_;
141 }
142 /**
143  * Returns true if series is visible
144  */
145 bool FFChartSeries::isVisible()
146 {
147         return visibility_;
148
149 }
150 /**
151  * Sets series's name
152  */
153 void FFChartSeries::setName(const QString& name)
154 {
155         name_ = name;
156 }
157 /**
158  * Sets series's pen
159  */
160 void FFChartSeries::setPen(const QPen& pen)
161 {
162         pen_ = pen;
163 }
164 /**
165  * Sets series's points and name
166  */
167 void FFChartSeries::set(const QVector<QPointF>& series,
168                         const QString& name)
169 {
170         //call set function with previously created Pen
171         set(series,this->pen_,name);
172 }
173 /**
174  * Sets series's points,pen nad name
175  */
176 void FFChartSeries::set(const QVector<QPointF>& series,
177                         const QPen& pen,
178                         const QString& name)
179 {
180         series_ = series;
181         pen_ = pen;
182         name_ = name;
183
184 }
185 /**
186  * Sets series's color
187  */
188 void FFChartSeries::setColor(const QColor& color)
189 {
190         pen_.setColor(color);
191 }
192 /**
193  * Sets pen's style
194  */
195 void FFChartSeries::setStyle(const Qt::PenStyle& style)
196 {
197         pen_.setStyle(style);
198 }
199 /**
200  * Sets series's visibility
201  */
202 void FFChartSeries::setVisible(bool visibility)
203 {
204         visibility_ = visibility;
205 }
206 /**
207  * Sorts series's points
208  */
209 void FFChartSeries::sort()
210 {
211         sort(0,series_.size()-1);
212 }
213 /**
214  * Validates series's points. Removes points with repeated x value.
215  */
216 void FFChartSeries::validate()
217 {
218         int current;
219
220         for(int i=0; i<series_.size(); i++)
221         {
222                 current = series_[i].x();
223
224                 for(int j=series_.size()-1; j>i; j--)
225                 {
226                         if(series_[j].x() == current)
227                         {
228                                 for(int k=j;k>=i;k--)
229                                 {
230                                         if(series_[j].x()==current)
231                                         {
232                                                 series_.remove(k);
233                                         }
234                                 }
235                                 break;
236                         }
237                 }
238         }
239 }
240 /**
241  * Returns vector of series's points
242  */
243 QVector<QPointF> FFChartSeries::series()
244 {
245         return series_;
246 }
247 /**
248  * Returns point from series at given index
249  * @param num is a index of point in seires
250  */
251 QPointF* FFChartSeries::at(const int& num)
252 {
253         return &series_[num];
254 }
255
256 /**
257  * Returns number of series's points
258  */
259 int FFChartSeries::size() const
260 {
261         return series_.size();
262 }
263 /**
264  * Returns pointer to the data stored in vector
265  */
266 QPointF* FFChartSeries::data()
267 {
268         return series_.data();
269 }
270
271 /**
272  * Sorts points in series
273  */
274 void FFChartSeries::sort(int left, int right)
275 {
276         int i = left;
277         int j = right;
278
279         QPointF* pointsTab;
280         QPointF tempPoint;
281
282         float x = series_[(left + right) / 2].x();
283         do
284         {
285                 while(series_[i].x() < x)
286                         i++;
287                 while(series_[j].x() > x)
288                         j--;
289                 if(i <= j)
290                 {
291                         pointsTab = series_.data();
292
293                         tempPoint = pointsTab[i];
294                         pointsTab[i] = pointsTab[j];
295                         pointsTab[j] = tempPoint;
296
297                         i++;
298                         j--;
299                 }
300         } while(i <= j);
301         if(left < j)
302                 sort(left, j);
303         if(right > i)
304                 sort(i, right);
305 }
306
307
308