-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatainspectorwidget.cpp
70 lines (61 loc) · 1.76 KB
/
datainspectorwidget.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
#include "datainspectorwidget.h"
#include "ui_datainspectorwidget.h"
#include <QMenu>
DataInspectorWidget::DataInspectorWidget(QWidget *parent) :
QDialog(parent),
ui(new Ui::DataInspectorWidget)
{
m_points = NULL;
ui->setupUi(this);
ui->tableWidget->setColumnCount(2);
QStringList header;
header << "x" << "y";
ui->tableWidget->setHorizontalHeaderLabels(header);
ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->tableWidget->verticalHeader()->hide();
}
DataInspectorWidget::~DataInspectorWidget()
{
delete ui;
}
void DataInspectorWidget::setDataPoints(RawData* pData)
{
m_points = pData;
UpdateTable();
}
void DataInspectorWidget::UpdateTable(void)
{
ui->tableWidget->reset();
int row = m_points->count();
ui->tableWidget->setRowCount(row);
// Populate table
int i;
for (i = 0; i < row; i++)
{
HPoint p = m_points->at(i);
QTableWidgetItem* item = new QTableWidgetItem;
item->setText(p.x().toString("%.5Rf"));
ui->tableWidget->setItem(i,0,item);
item = new QTableWidgetItem;
item->setText(p.y().toString("%.5Rf"));
ui->tableWidget->setItem(i,1,item);
}
}
void DataInspectorWidget::on_tableWidget_customContextMenuRequested(const QPoint &pos)
{
QPoint globalPos = ui->tableWidget->mapToGlobal(pos);
QMenu myMenu;
myMenu.addAction("Delete");
QAction* selectedItem = myMenu.exec(globalPos);
if (selectedItem)
{
if (selectedItem->text() == "Delete")
{
int row = ui->tableWidget->itemAt(pos)->row();
m_points->remove(row);
m_points->updateRange();
UpdateTable();
emit dataChanged(m_points->RawRange());
}
}
}