-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbinarydata.h
More file actions
99 lines (78 loc) · 2.6 KB
/
Copy pathbinarydata.h
File metadata and controls
99 lines (78 loc) · 2.6 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
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
#ifndef BINARYDATA_H
#define BINARYDATA_H
#include <QtCore>
#include <QStandardItemModel>
class BinaryData : public QAbstractListModel
{
Q_OBJECT
Q_ENUMS(Param)
Q_ENUMS(Mode)
public:
enum Roles {
Line = Qt::UserRole + 1
};
enum Mode {
BrowseMode,
InsertMode,
SearchMode
};
enum Param {
LineSize = 16
};
explicit BinaryData(QAbstractListModel *parent = 0);
Q_PROPERTY (QString address READ address WRITE setAddress NOTIFY addressChange);
Q_PROPERTY (int offset READ offset WRITE setOffset NOTIFY offsetChange);
Q_PROPERTY (Mode mode READ mode WRITE setMode NOTIFY modeChange);
Q_PROPERTY (QString entered READ entered NOTIFY enteredChange);
Q_PROPERTY (QString prompt READ prompt NOTIFY promptChange);
Q_INVOKABLE int search(const QString& pattern, bool findFirst);
Q_INVOKABLE void keyPress(int keyCode, const QString& keyText);
Q_INVOKABLE int findPattern(int start);
void load(const QByteArray& data);
QString address() const {return QString("%1").arg(mAddress, 4, 16, QChar('0')).toUpper();}
void setAddress(const QString& addr);
int offset() const {return mOffset;}
void setOffset(int off) {mOffset = off; offsetChange();}
Mode mode() const {return mMode;}
void setMode(Mode mode);
QVariant data(const QModelIndex &index, int role) const;
QStringList containingRow(const QModelIndex &index);
QString entered() const {return mEntered;}
QString prompt() const {return mPrompt;}
int rowCount(const QModelIndex &parent) const;
protected:
virtual QHash<int, QByteArray> roleNames() const;
private:
int mAddress;
int mOffset;
QString mEntered;
QStringList mLastResponse;
QModelIndex mLastRequest;
QMap<int, int> mKeyMap;
Mode mMode;
QByteArray mData;
QString mStrData;
QModelIndex mLastIdx;
QStringList mLastResult;
int mLastSearchIdx;
QString mSearchPattern;
QString mPrompt;
bool canEdit(int keyCode) const;
bool hexadecimal(int keyCode) const;
bool hexRegEx(int keyCode) const;
bool isNavigation(int keyCode) const;
void insertSampleData();
bool editCell();
void keyboardNavigation(int keyCode);
void dataToString();
void keyPressBrowseMode(int keyCode, const QString& keyText);
void keyPressInsertMode(int keyCode, const QString& keyText);
void keyPressSearchMode(int keyCode, const QString& keyText);
signals:
void addressChange(int address);
void offsetChange();
void modeChange();
void enteredChange();
void promptChange();
};
#endif // BINARYDATA_H