-
Notifications
You must be signed in to change notification settings - Fork 4
/
mydatamodel.cpp
54 lines (43 loc) · 1.06 KB
/
mydatamodel.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
#include "mydatamodel.h"
MyDataModel::MyDataModel()
{
QObject::connect(this, &MyDataModel::newPointAdded, this, &MyDataModel::addNewPoint,
Qt::QueuedConnection);
}
void MyDataModel::handleNewPoint(const QPointF &point)
{
emit newPointAdded(point);
}
void MyDataModel::addNewPoint(const QPointF& point)
{
beginInsertRows(QModelIndex(), rowCount(), rowCount());
m_data.push_back(point);
endInsertRows();
}
int MyDataModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return m_data.size();
}
int MyDataModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return 2;
}
QVariant MyDataModel::headerData(int section, Qt::Orientation orientation, int role) const
{
Q_UNUSED(orientation)
Q_UNUSED(role)
if(section == 0)
return "x";
else
return "y";
}
QVariant MyDataModel::data(const QModelIndex &index, int role) const
{
Q_UNUSED(role)
if (index.column() == 0)
return m_data[index.row()].x();
else
return m_data[index.row()].y();
}