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: public QObject
30 {
31 Q_OBJECT
32 public:
33  // Constructors and file settings
34  Chunks(QObject *parent);
35  Chunks(QIODevice &ioDevice, QObject *parent);
36  bool setIODevice(QIODevice &ioDevice);
37 
38  // Getting data out of Chunks
39  QByteArray data(qint64 pos=0, qint64 count=-1, QByteArray *highlighted=0);
40  bool write(QIODevice &iODevice, qint64 pos=0, qint64 count=-1);
41 
42  // Set and get highlighting infos
43  void setDataChanged(qint64 pos, bool dataChanged);
44  bool dataChanged(qint64 pos);
45 
46  // Search API
47  qint64 indexOf(const QByteArray &ba, qint64 from);
48  qint64 lastIndexOf(const QByteArray &ba, qint64 from);
49 
50  // Char manipulations
51  bool insert(qint64 pos, char b);
52  bool overwrite(qint64 pos, char b);
53  bool removeAt(qint64 pos);
54 
55  // Utility functions
56  char operator[](qint64 pos);
57  qint64 pos();
58  qint64 size();
59 
60 
61 private:
62  int getChunkIndex(qint64 absPos);
63 
64  QIODevice * _ioDevice;
65  qint64 _pos;
66  qint64 _size;
67  QList<Chunk> _chunks;
68 
69 #ifdef MODUL_TEST
70 public:
71  int chunkSize();
72 #endif
73 };
74 
77 #endif // CHUNKS_H