Warning, /sdk/rust-qt-binding-generator/demo/rust/src/implementation/time_series.rs is written in an unsupported language. File is not indexed.

0001 // Copyright 2017  Jos van den Oever <jos@vandenoever.info>
0002 //
0003 // This program is free software; you can redistribute it and/or
0004 // modify it under the terms of the GNU General Public License as
0005 // published by the Free Software Foundation; either version 2 of
0006 // the License or (at your option) version 3 or any later version
0007 // accepted by the membership of KDE e.V. (or its successor approved
0008 // by the membership of KDE e.V.), which shall act as a proxy
0009 // defined in Section 14 of version 3 of the license.
0010 //
0011 // This program is distributed in the hope that it will be useful,
0012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
0013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014 // GNU General Public License for more details.
0015 //
0016 // You should have received a copy of the GNU General Public License
0017 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
0018 
0019 use interface::*;
0020 
0021 #[derive(Default, Clone)]
0022 struct TimeSeriesItem {
0023     time: f32,
0024     sin: f32,
0025     cos: f32,
0026 }
0027 
0028 pub struct TimeSeries {
0029     emit: TimeSeriesEmitter,
0030     list: Vec<TimeSeriesItem>,
0031 }
0032 
0033 impl TimeSeriesTrait for TimeSeries {
0034     fn new(emit: TimeSeriesEmitter, _: TimeSeriesList) -> TimeSeries {
0035         let mut series = TimeSeries {
0036             emit,
0037             list: Vec::new(),
0038         };
0039         for i in 0..101 {
0040             let x = i as f32 / 10.;
0041             series.list.push(TimeSeriesItem {
0042                 time: x,
0043                 sin: x.sin(),
0044                 cos: x.cos(),
0045             });
0046         }
0047         series
0048     }
0049     fn emit(&mut self) -> &mut TimeSeriesEmitter {
0050         &mut self.emit
0051     }
0052     fn row_count(&self) -> usize {
0053         self.list.len() as usize
0054     }
0055     fn time(&self, row: usize) -> f32 {
0056         self.list[row as usize].time
0057     }
0058     fn set_time(&mut self, row: usize, v: f32) -> bool {
0059         self.list[row as usize].time = v;
0060         true
0061     }
0062     fn sin(&self, row: usize) -> f32 {
0063         self.list[row as usize].sin
0064     }
0065     fn set_sin(&mut self, row: usize, v: f32) -> bool {
0066         self.list[row as usize].sin = v;
0067         true
0068     }
0069     fn cos(&self, row: usize) -> f32 {
0070         self.list[row as usize].cos
0071     }
0072     fn set_cos(&mut self, row: usize, v: f32) -> bool {
0073         self.list[row as usize].cos = v;
0074         true
0075     }
0076 }