QHexEdit
chunks.h
1 #ifndef CHUNKS_H
2 #define CHUNKS_H
3 
20 #include <QtCore>
21 
22 struct Chunk
23 {
24  QByteArray data;
25  QByteArray dataChanged;
26  qint64 absPos;
27 };
28 
29 class Chunks
30 {
31 public:
32  // Constructors and file settings
33  Chunks();
34  Chunks(QIODevice &ioDevice);
35  bool setIODevice(QIODevice &ioDevice);
36 
37  // Getting data out of Chunks
38  QByteArray data(qint64 pos=0, qint64 count=-1, QByteArray *highlighted=0);
39  bool write(QIODevice &iODevice, qint64 pos=0, qint64 count=-1);
40 
41  // Set and get highlighting infos
42  void setDataChanged(qint64 pos, bool dataChanged);
43  bool dataChanged(qint64 pos);
44 
45  // Search API
46  qint64 indexOf(const QByteArray &ba, qint64 from);
47  qint64 lastIndexOf(const QByteArray &ba, qint64 from);
48 
49  // Char manipulations
50  bool insert(qint64 pos, char b);
51  bool overwrite(qint64 pos, char b);
52  bool removeAt(qint64 pos);
53 
54  // Utility functions
55  char operator[](qint64 pos);
56  qint64 pos();
57  qint64 size();
58 
59 
60 private:
61  int getChunkIndex(qint64 absPos);
62 
63  QIODevice * _ioDevice;
64  qint64 _pos;
65  qint64 _size;
66  QList<Chunk> _chunks;
67 
68 #ifdef MODUL_TEST
69 public:
70  int chunkSize();
71 #endif
72 };
73 
76 #endif // CHUNKS_H