File: datawindow.cpp

package info (click to toggle)
aoflagger 3.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 4,476 kB
  • sloc: cpp: 51,868; python: 152; sh: 25; makefile: 17
file content (62 lines) | stat: -rw-r--r-- 1,509 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "datawindow.h"

#include "../plot/plot2d.h"

#include <sstream>
#include <iomanip>

void DataWindow::SetData(const Plot2D &plot)
{
	_plot = &plot;
	int selectedIndex = _comboBox.get_active_row_number();
	if(selectedIndex < 0)
		selectedIndex = 0;
	_comboListStore->clear();
	for(size_t i=0;i<plot.PointSetCount();++i)
	{
		std::stringstream str;
		str << (i+1) << ". " << plot.GetPointSet(i).Label();
		Gtk::TreeModel::Row row = *_comboListStore->append();
		row[_comboColumnRecord._comboListNameColumn] = str.str();
	}
	if(selectedIndex < (int) plot.PointSetCount())
		_comboBox.set_active(selectedIndex);
	else if(plot.PointSetCount() > 0)
		_comboBox.set_active(0);
	onComboChange();
}

void DataWindow::onComboChange()
{
	int active = _comboBox.get_active_row_number();
	if(active >= 0)
		loadData(active);
	else
		loadData(_plot->PointSetCount());
}

void DataWindow::loadData(size_t plotSetIndex)
{
	std::stringstream _dataStream;
	_dataStream << std::setprecision(14);
	if(_plot->PointSetCount() > plotSetIndex)
	{
		const Plot2DPointSet &pointSet = _plot->GetPointSet(plotSetIndex);
		const size_t valueCount = pointSet.Size();
		for(size_t i=0; i<valueCount; ++i)
		{
			const double
				x = pointSet.GetX(i),
				y = pointSet.GetY(i);
			if(pointSet.HasTickLabels())
			{
				std::string label = pointSet.TickLabels()[i];
				_dataStream << i << '\t' << label << '\t' << y << '\n';
			}
			else
				_dataStream << i << '\t' << x << '\t' << y << '\n';
		}
	}
	SetData(_dataStream.str());
}