forked from Dax89/QHexView
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qhexeditdatawriter.cpp
107 lines (85 loc) · 2.74 KB
/
qhexeditdatawriter.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
#include "qhexeditdatawriter.h"
QHexEditDataWriter::QHexEditDataWriter(QHexEditData *hexeditdata, QObject *parent): QObject(parent), _hexeditdata(hexeditdata)
{
}
const QHexEditData *QHexEditDataWriter::hexEditData() const
{
return this->_hexeditdata;
}
void QHexEditDataWriter::append(const QByteArray &ba)
{
this->insert(this->_hexeditdata->length(), ba);
}
void QHexEditDataWriter::insert(qint64 pos, uchar ch)
{
this->insert(pos, QByteArray().append(ch));
}
void QHexEditDataWriter::insert(qint64 pos, const QByteArray &ba)
{
QHexEditData::InsertCommand* ic = this->_hexeditdata->internalInsert(pos, ba, QHexEditData::Insert);
if(ic)
{
this->_hexeditdata->recordAction(QHexEditData::Insert, pos + ba.length());
this->_hexeditdata->_undostack.push(ic);
}
}
void QHexEditDataWriter::remove(qint64 pos, qint64 len)
{
QHexEditData::RemoveCommand* rc = this->_hexeditdata->internalRemove(pos, len, QHexEditData::Remove);
if(rc)
{
this->_hexeditdata->recordAction(QHexEditData::Remove, pos);
this->_hexeditdata->_undostack.push(rc);
}
}
void QHexEditDataWriter::replace(qint64 pos, uchar b)
{
this->replace(pos, 1, b);
}
void QHexEditDataWriter::replace(qint64 pos, qint64 len, uchar b)
{
this->replace(pos, len, QByteArray().append(b));
}
void QHexEditDataWriter::replace(qint64 pos, const QByteArray &ba)
{
this->replace(pos, ba.length(), ba);
}
void QHexEditDataWriter::replace(qint64 pos, qint64 len, const QByteArray &ba)
{
if(pos > this->_hexeditdata->length() || ba.isEmpty() || !this->_hexeditdata->modifiedItem(pos))
return;
this->_hexeditdata->_undostack.push(new QHexEditData::ReplaceCommand(pos, len, ba, this->_hexeditdata));
this->_hexeditdata->recordAction(QHexEditData::Replace, pos + ba.length());
}
void QHexEditDataWriter::writeUInt8(qint64 pos, char d)
{
this->replace(pos, QByteArray().append(d));
}
void QHexEditDataWriter::writeUInt16(qint64 pos, quint16 d, QSysInfo::Endian endian)
{
this->writeType(pos, d, endian);
}
void QHexEditDataWriter::writeUInt32(qint64 pos, quint32 d, QSysInfo::Endian endian)
{
this->writeType(pos, d, endian);
}
void QHexEditDataWriter::writeUInt64(qint64 pos, quint64 d, QSysInfo::Endian endian)
{
this->writeType(pos, d, endian);
}
void QHexEditDataWriter::writeInt8(qint64 pos, uchar d)
{
this->replace(pos, QByteArray().append(d));
}
void QHexEditDataWriter::writeInt16(qint64 pos, qint16 d, QSysInfo::Endian endian)
{
this->writeType(pos, d, endian);
}
void QHexEditDataWriter::writeInt32(qint64 pos, qint32 d, QSysInfo::Endian endian)
{
this->writeType(pos, d, endian);
}
void QHexEditDataWriter::writeInt64(qint64 pos, qint64 d, QSysInfo::Endian endian)
{
this->writeType(pos, d, endian);
}