Repository navigation
Expand file tree
/
Copy pathModelModbus.h
More file actions
59 lines (47 loc) · 1.81 KB
/
Copy pathModelModbus.h
File metadata and controls
59 lines (47 loc) · 1.81 KB
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
#ifndef MODELMODBUS_H
#define MODELMODBUS_H
#include <QAbstractItemModel>
#include <QtXml/QDomDocument>
#include <QTimer>
#include "TreeItem.h"
#include "ModBusLib/ModBusLib.h"
class ModBusModel : public QAbstractItemModel
{
Q_OBJECT
public:
ModBusModel(const QString xmlFile, QObject *parent = nullptr);
~ModBusModel();
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column, const QModelIndex &parent) const;
QModelIndex parent(const QModelIndex &child) const;
int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const;
//editable
Qt::ItemFlags flags(const QModelIndex &index) const;
bool setData(const QModelIndex &index, const QVariant &value,
int role = Qt::EditRole);
bool insertRows(int position, int rows,
const QModelIndex &parent = QModelIndex());
bool removeRows(int position, int rows,
const QModelIndex &parent = QModelIndex());
void loadModelData(const QString xmlFile);
public slots:
void StartTask();
void StopTask();
private slots:
void update(QString itemName);
void update();
private:
void setupModelData(const QString xmlFile, TreeItem *parent);
void setupDefaultNode(TreeItem* parentItem, INode* parentNode);
void setupNode(QDomElement parentElem, TreeItem* parentItem, INode* parentNode);
TreeItem *getItem(const QModelIndex &index) const;
void updateNode(QString itemName, QModelIndex parentIndex);
void OnValueChanged(INode* node, UINT64 val);
void OnErrorChanged(INode* node);
private:
TreeItem *rootItem;
ModBusLib *modBusLib;
};
#endif // MODELMODBUS_H