-
Notifications
You must be signed in to change notification settings - Fork 0
/
PositionPlotWidget.cpp
140 lines (117 loc) · 3.24 KB
/
PositionPlotWidget.cpp
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* PositionPlotWidget.cpp
*
* Created on: Apr 25, 2010
* Author: Vincent
*/
#include "PositionPlotWidget.h"
#include "stat.h"
PositionPlotWidget::PositionPlotWidget(QWidget *parent) :
QWidget(parent) {
ui.setupUi(this);
// ui.orderTable->resizeColumnsToContents();
mads = ui.madsSpin->value();
connect(ui.orderTable, SIGNAL(itemSelectionChanged()), SLOT(
updateSelection()));
posMad = posMedian = 0;
connect(ui.madsSpin, SIGNAL(valueChanged(double)), SIGNAL(madsChanged(double)));
}
PositionPlotWidget::~PositionPlotWidget() {
}
void PositionPlotWidget::setRowCount(int rows) {
rowCount = rows;
}
void PositionPlotWidget::setColumnCount(int columns) {
colCount = columns;
}
int PositionPlotWidget::getColumnCount() const {
return colCount;
}
int PositionPlotWidget::getRowCount() const {
return rowCount;
}
void PositionPlotWidget::setData(const QStringList &labels,
const QList<double> &data) {
this->labels.clear();
this->data.clear();
QList<double> tempData = data;
QStringList tempLabels = labels;
ui.orderTable->setColumnCount(labels.size());
int minIndex;
for (int i = 0; i < data.size(); ++i) {
minIndex = minIndexOf(tempData);
this->data << tempData.takeAt(minIndex);
this->labels << tempLabels.takeAt(minIndex);
ui.orderTable->setItem(0, i, new QTableWidgetItem(this->labels.last()));
}
ui.orderTable->resizeColumnsToContents();
ui.orderTable->setFixedHeight(ui.orderTable->rowHeight(0));
updatePlot();
}
void PositionPlotWidget::setPlotName(const QString &name) {
this->name = name;
ui.nameLabel->setText(name);
}
void PositionPlotWidget::setMads(double madMultiplier) {
mads = madMultiplier;
ui.madsSpin->setValue(madMultiplier);
updatePlot();
}
double PositionPlotWidget::getMads() const {
return mads;
}
//void PositionPlotWidget::update() {
// ui.densityPlot->update();
//}
void PositionPlotWidget::setRange(int low, int high) {
ui.densityPlot->setRange(low, high);
updatePlot();
}
void PositionPlotWidget::on_madsSpin_valueChanged(double value) {
setMads(value);
}
void PositionPlotWidget::updatePlot() {
if (data.size() == 0) {
return;
}
ui.densityPlot->clear();
QList<double> highlighted;
posMad = mad(data);
posMedian = median(data);
mads = ui.madsSpin->value();
highlighted << posMedian << posMedian - posMad * mads << posMedian + posMad
* mads;
ui.densityPlot->drawValues(data);
ui.densityPlot->drawHighlightedValues(highlighted);
updateSelection();
ui.densityPlot->update();
}
void PositionPlotWidget::setPlotHeight(int height) {
ui.densityPlot->setPlotHeight(height);
}
void PositionPlotWidget::setPlotWidth(int width) {
ui.densityPlot->setPlotWidth(width);
}
void PositionPlotWidget::setAxisTicks(int ticks) {
ui.densityPlot->setTickNumber(ticks);
}
void PositionPlotWidget::updateSelection() {
QList<QTableWidgetItem *> items = ui.orderTable->selectedItems();
QList<double> selected;
for (int i = 0; i < items.size(); ++i) {
selected << data[items[i]->column()];
}
ui.densityPlot->drawSelectedValues(selected);
}
double PositionPlotWidget::getMad() const {
return posMad;
}
double PositionPlotWidget::getMedian() const {
return posMedian;
}
QList<double> PositionPlotWidget::getData() const {
return data;
}
QStringList PositionPlotWidget::getLabels() const {
return labels;
}