diff --git a/src/chunks.cpp b/src/chunks.cpp index 30bb538..40847dd 100644 --- a/src/chunks.cpp +++ b/src/chunks.cpp @@ -62,7 +62,7 @@ bool Chunks::setIODevice(QIODevice &ioDevice) // ***************************************** Getting data out of Chunks -QByteArray Chunks::data(qint64 pos, qint64 maxSize, QByteArray *highlighted) +QByteArray Chunks::data(qint64 pos, qint64 maxSize, QByteArray *highlighted) const { qint64 ioDelta = 0; int chunkIdx = 0; @@ -147,7 +147,7 @@ QByteArray Chunks::data(qint64 pos, qint64 maxSize, QByteArray *highlighted) return buffer; } -bool Chunks::write(QIODevice &iODevice, qint64 pos, qint64 count) +bool Chunks::write(QIODevice &iODevice, qint64 pos, qint64 count) const { if (count == -1) count = _size; @@ -176,7 +176,7 @@ void Chunks::setDataChanged(qint64 pos, bool dataChanged) _chunks[chunkIdx].dataChanged[(int)posInBa] = char(dataChanged); } -bool Chunks::dataChanged(qint64 pos) +bool Chunks::dataChanged(qint64 pos) const { foreach (Chunk chunk, _chunks) { @@ -191,7 +191,7 @@ bool Chunks::dataChanged(qint64 pos) // ***************************************** Search API -qint64 Chunks::indexOf(const QByteArray &ba, qint64 from) +qint64 Chunks::indexOf(const QByteArray &ba, qint64 from) const { qint64 result = -1; QByteArray buffer; @@ -206,7 +206,7 @@ qint64 Chunks::indexOf(const QByteArray &ba, qint64 from) return result; } -qint64 Chunks::lastIndexOf(const QByteArray &ba, qint64 from) +qint64 Chunks::lastIndexOf(const QByteArray &ba, qint64 from) const { qint64 result = -1; QByteArray buffer; @@ -276,22 +276,22 @@ bool Chunks::removeAt(qint64 pos) // ***************************************** Utility functions -char Chunks::operator[](qint64 pos) +char Chunks::operator[](qint64 pos) const { return data(pos, 1).at(0); } -qint64 Chunks::pos() +qint64 Chunks::pos() const { return _pos; } -qint64 Chunks::size() +qint64 Chunks::size() const { return _size; } -int Chunks::getChunkIndex(qint64 absPos) +int Chunks::getChunkIndex(qint64 absPos) const { // This routine checks, if there is already a copied chunk available. If os, it // returns a reference to it. If there is no copied chunk available, original diff --git a/src/chunks.h b/src/chunks.h index c516371..1291328 100644 --- a/src/chunks.h +++ b/src/chunks.h @@ -54,16 +54,16 @@ Q_OBJECT bool setIODevice(QIODevice &ioDevice); // Getting data out of Chunks - QByteArray data(qint64 pos=0, qint64 count=-1, QByteArray *highlighted=0); - bool write(QIODevice &iODevice, qint64 pos=0, qint64 count=-1); + QByteArray data(qint64 pos=0, qint64 count=-1, QByteArray *highlighted=0) const; + bool write(QIODevice &iODevice, qint64 pos=0, qint64 count=-1) const; // Set and get highlighting infos void setDataChanged(qint64 pos, bool dataChanged); - bool dataChanged(qint64 pos); + bool dataChanged(qint64 pos) const; // Search API - qint64 indexOf(const QByteArray &ba, qint64 from); - qint64 lastIndexOf(const QByteArray &ba, qint64 from); + qint64 indexOf(const QByteArray &ba, qint64 from) const; + qint64 lastIndexOf(const QByteArray &ba, qint64 from) const; // Char manipulations bool insert(qint64 pos, char b); @@ -71,18 +71,18 @@ Q_OBJECT bool removeAt(qint64 pos); // Utility functions - char operator[](qint64 pos); - qint64 pos(); - qint64 size(); + char operator[](qint64 pos) const; + qint64 pos() const; + qint64 size() const; private: - int getChunkIndex(qint64 absPos); + int getChunkIndex(qint64 absPos) const; QIODevice * _ioDevice; qint64 _pos; qint64 _size; - QList _chunks; + mutable QList _chunks; #ifdef MODUL_TEST public: diff --git a/src/color_manager.cpp b/src/color_manager.cpp index 2d35bf8..a148409 100644 --- a/src/color_manager.cpp +++ b/src/color_manager.cpp @@ -47,12 +47,12 @@ ColoredArea::ColoredArea(qint64 posStart, qint64 posEnd, QPen pen, QBrush backgr _areaStyle = background; } -QPen ColoredArea::fontPen() +QPen ColoredArea::fontPen() const { return _fontColor; } -QColor ColoredArea::fontColor() +QColor ColoredArea::fontColor() const { return _fontColor.color(); } @@ -62,12 +62,12 @@ void ColoredArea::setFontColor(QColor color) _fontColor = QPen(color); } -QColor ColoredArea::areaColor() +QColor ColoredArea::areaColor() const { return _areaStyle.color(); } -QBrush ColoredArea::areaStyle() +QBrush ColoredArea::areaStyle() const { return _areaStyle; } @@ -82,21 +82,21 @@ void ColoredArea::setAreaStyle(QBrush backround) _areaStyle = backround; } -qint64 ColoredArea::posStart() +qint64 ColoredArea::posStart() const { return _posStart; -}; +} -qint64 ColoredArea::posEnd() +qint64 ColoredArea::posEnd() const { return _posEnd; -}; +} void ColoredArea::setRange(qint64 posStart, qint64 posEnd) { _posStart = posStart; _posEnd = posEnd; -}; +} void ColoredArea::clear() { @@ -111,7 +111,7 @@ ColorManager::ColorManager() { QPalette palette = qApp->palette(); setPalette(palette); -}; +} void ColorManager::setPalette(const QPalette &palette) { @@ -123,7 +123,7 @@ void ColorManager::setPalette(const QPalette &palette) } // read only, copy of relevant ColoredArea is returned: you can't change anything -ColoredArea ColorManager::markedArea(qint64 pos, Area area, Chunks *chunks) +ColoredArea ColorManager::markedArea(qint64 pos, Area area, Chunks *chunks) const { // prio 1 selection if (pos >= _selection.posStart() && pos < _selection.posEnd()) @@ -145,9 +145,9 @@ ColoredArea ColorManager::markedArea(qint64 pos, Area area, Chunks *chunks) } // nothing found -> standard colors return this->notMarked(area); -}; +} -ColoredArea& ColorManager::notMarked(Area area) +const ColoredArea &ColorManager::notMarked(Area area) const { switch (area) { case Area::Address: @@ -163,15 +163,25 @@ ColoredArea& ColorManager::notMarked(Area area) return _hex; // should never happen } -ColoredArea& ColorManager::selection() +const ColoredArea &ColorManager::selection() const +{ + return _selection; +} + +ColoredArea &ColorManager::selection() { return _selection; -}; +} + +const ColoredArea& ColorManager::highlighting() const +{ + return _highlighting; +} ColoredArea& ColorManager::highlighting() { return _highlighting; -}; +} void ColorManager::addUserArea(qint64 posStart, qint64 posEnd, QColor fontColor, QBrush areaStyle) { @@ -182,4 +192,4 @@ void ColorManager::addUserArea(qint64 posStart, qint64 posEnd, QColor fontColor, void ColorManager::clearUserAreas() { _userAreas.clear(); -} \ No newline at end of file +} diff --git a/src/color_manager.h b/src/color_manager.h index b7140f1..01961c6 100644 --- a/src/color_manager.h +++ b/src/color_manager.h @@ -47,25 +47,25 @@ enum Area { class ColoredArea { public: - // Cunstructors + // Constructors ColoredArea(); ColoredArea(QPen pen, QBrush background); ColoredArea(qint64 posStart, qint64 posEnd, QPen pen, QBrush background); // Property to set/get font color - QColor fontColor(); + QColor fontColor() const; void setFontColor(QColor color); // Property to set/get area style - QColor areaColor(); - QBrush areaStyle(); + QColor areaColor() const; + QBrush areaStyle() const; void setAreaColor(QColor color); void setAreaStyle(QBrush background); // other Methods to acces and set internal data - QPen fontPen(); - qint64 posStart(); - qint64 posEnd(); + QPen fontPen() const; + qint64 posStart() const; + qint64 posEnd() const; void setRange(qint64 posStart, qint64 posEnd); void clear(); @@ -87,15 +87,17 @@ class ColorManager void setPalette(const QPalette &palette); // Method returns color definitions for data at position pos in area area - ColoredArea markedArea(qint64 pos, Area area, Chunks *chunks); + ColoredArea markedArea(qint64 pos, Area area, Chunks *chunks) const; // Method returns standard collors (without marking) - ColoredArea& notMarked(Area); + const ColoredArea& notMarked(Area) const; // Get the selection color definitions + const ColoredArea& selection() const; ColoredArea& selection(); // Get the highlighting color definitions + const ColoredArea& highlighting() const; ColoredArea& highlighting(); // Add a user defined area @@ -116,4 +118,4 @@ class ColorManager /** \endcond docNever */ -#endif // COLOR_MANAGER_H \ No newline at end of file +#endif // COLOR_MANAGER_H diff --git a/src/commands.cpp b/src/commands.cpp index 55f90ad..0f7eedb 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -113,7 +113,6 @@ UndoStack::UndoStack(Chunks * chunks, QObject * parent) : QUndoStack(parent) { _chunks = chunks; - _parent = parent; this->setUndoLimit(1000); } diff --git a/src/commands.h b/src/commands.h index e6732dc..45b4359 100644 --- a/src/commands.h +++ b/src/commands.h @@ -57,7 +57,6 @@ class UndoStack : public QUndoStack private: Chunks * _chunks; - QObject * _parent; }; /** \endcond docNever */ diff --git a/src/qhexedit.cpp b/src/qhexedit.cpp index c563875..9736579 100644 --- a/src/qhexedit.cpp +++ b/src/qhexedit.cpp @@ -88,7 +88,7 @@ void QHexEdit::setAddressArea(bool addressArea) viewport()->update(); } -bool QHexEdit::addressArea() +bool QHexEdit::addressArea() const { return _addressArea; } @@ -101,7 +101,7 @@ void QHexEdit::setAddressOffset(qint64 addressOffset) viewport()->update(); } -qint64 QHexEdit::addressOffset() +qint64 QHexEdit::addressOffset() const { return _addressOffset; } @@ -114,7 +114,7 @@ void QHexEdit::setAddressWidth(int addressWidth) viewport()->update(); } -int QHexEdit::addressWidth() +int QHexEdit::addressWidth() const { qint64 size = _chunks->size(); int n = 1; @@ -139,7 +139,7 @@ void QHexEdit::setAsciiArea(bool asciiArea) viewport()->update(); } -bool QHexEdit::asciiArea() +bool QHexEdit::asciiArea() const { return _asciiArea; } @@ -154,12 +154,12 @@ void QHexEdit::setBytesPerLine(int count) viewport()->update(); } -int QHexEdit::bytesPerLine() +int QHexEdit::bytesPerLine() const { return _bytesPerLine; } -char QHexEdit::defaultChar() +char QHexEdit::defaultChar() const { return _defaultChar; } @@ -254,7 +254,7 @@ qint64 QHexEdit::cursorPosition(QPoint pos) return result; } -qint64 QHexEdit::cursorPosition() +qint64 QHexEdit::cursorPosition() const { return _cursorPosition; } @@ -277,7 +277,7 @@ void QHexEdit::setHighlighting(bool highlighting) viewport()->update(); } -bool QHexEdit::highlighting() +bool QHexEdit::highlighting() const { return _highlighting; } @@ -288,7 +288,7 @@ void QHexEdit::setHighlightingColor(const QColor &color) viewport()->update(); } -QColor QHexEdit::highlightingColor() +QColor QHexEdit::highlightingColor() const { return _colorManager->highlighting().areaColor(); } @@ -299,12 +299,12 @@ void QHexEdit::setOverwriteMode(bool overwriteMode) emit overwriteModeChanged(overwriteMode); } -bool QHexEdit::overwriteMode() +bool QHexEdit::overwriteMode() const { return _overwriteMode; } -bool QHexEdit::isReadOnly() +bool QHexEdit::isReadOnly() const { return _readOnly; } @@ -320,7 +320,7 @@ void QHexEdit::setHexCaps(const bool isCaps) viewport()->update(); } -bool QHexEdit::hexCaps() +bool QHexEdit::hexCaps() const { return _hexCaps; } @@ -331,7 +331,7 @@ void QHexEdit::setDynamicBytesPerLine(const bool isDynamic) resizeEvent(nullptr); } -bool QHexEdit::dynamicBytesPerLine() +bool QHexEdit::dynamicBytesPerLine() const { return _dynamicBytesPerLine; } @@ -344,12 +344,12 @@ bool QHexEdit::setData(QIODevice &iODevice) return ok; } -QByteArray QHexEdit::dataAt(qint64 pos, qint64 count) +QByteArray QHexEdit::dataAt(qint64 pos, qint64 count) const { return _chunks->data(pos, count); } -bool QHexEdit::write(QIODevice &iODevice, qint64 pos, qint64 count) +bool QHexEdit::write(QIODevice &iODevice, qint64 pos, qint64 count) const { return _chunks->write(iODevice, pos, count); } @@ -427,7 +427,7 @@ qint64 QHexEdit::indexOf(const QByteArray &ba, qint64 from) return pos; } -bool QHexEdit::isModified() +bool QHexEdit::isModified() const { return _modified; } @@ -453,7 +453,7 @@ void QHexEdit::redo() refresh(); } -QString QHexEdit::selectionToReadableString() +QString QHexEdit::selectionToReadableString() const { QByteArray ba = _chunks->data(getSelectionBegin(), getSelectionEnd() - getSelectionBegin()); return toReadable(ba); @@ -1094,12 +1094,12 @@ void QHexEdit::setSelection(qint64 pos) _colorManager->selection().setRange(_bSelectionBegin, _bSelectionEnd); } -qint64 QHexEdit::getSelectionBegin() +qint64 QHexEdit::getSelectionBegin() const { return _bSelectionBegin; } -qint64 QHexEdit::getSelectionEnd() +qint64 QHexEdit::getSelectionEnd() const { return _bSelectionEnd; } @@ -1179,7 +1179,7 @@ void QHexEdit::readBuffers() _hexDataShown = QByteArray(_dataShown.toHex()); } -QString QHexEdit::toReadable(const QByteArray &ba) +QString QHexEdit::toReadable(const QByteArray &ba) const { QString result; diff --git a/src/qhexedit.h b/src/qhexedit.h index fadaba2..94d4cd7 100644 --- a/src/qhexedit.h +++ b/src/qhexedit.h @@ -174,12 +174,12 @@ class QHEXEDIT_API QHexEdit : public QAbstractScrollArea /*! Gives back the data as a QByteArray starting at position \param pos and delivering \param count bytes. */ - QByteArray dataAt(qint64 pos, qint64 count=-1); + QByteArray dataAt(qint64 pos, qint64 count=-1) const; /*! Gives back the data into a \param iODevice starting at position \param pos and delivering \param count bytes. */ - bool write(QIODevice &iODevice, qint64 pos=0, qint64 count=-1); + bool write(QIODevice &iODevice, qint64 pos=0, qint64 count=-1) const; // Char handling @@ -262,18 +262,18 @@ class QHEXEDIT_API QHexEdit : public QAbstractScrollArea /*! Returns if any changes where done on document * \return true when document is modified else false */ - bool isModified(); + bool isModified() const; /*! Find last occurrence of ba in QHexEdit data * \param ba Data to find * \param from Point where the search starts - * \return pos if fond, else -1 + * \return pos if found, else -1 */ qint64 lastIndexOf(const QByteArray &ba, qint64 from); /*! Gives back a formatted image of the selected content of QHexEdit */ - QString selectionToReadableString(); + QString selectionToReadableString() const; /*! Return the selected content of QHexEdit as QByteArray */ @@ -319,46 +319,46 @@ public slots: ~QHexEdit(); // Properties - bool addressArea(); + bool addressArea() const; void setAddressArea(bool addressArea); - qint64 addressOffset(); + qint64 addressOffset() const; void setAddressOffset(qint64 addressArea); - int addressWidth(); + int addressWidth() const; void setAddressWidth(int addressWidth); - bool asciiArea(); + bool asciiArea() const; void setAsciiArea(bool asciiArea); - int bytesPerLine(); + int bytesPerLine() const; void setBytesPerLine(int count); - char defaultChar(); + char defaultChar() const; void setDefaultChar(char defaultChar); - qint64 cursorPosition(); + qint64 cursorPosition() const; void setCursorPosition(qint64 position); QByteArray data(); void setData(const QByteArray &ba); void setHexCaps(const bool isCaps); - bool hexCaps(); + bool hexCaps() const; void setDynamicBytesPerLine(const bool isDynamic); - bool dynamicBytesPerLine(); + bool dynamicBytesPerLine() const; - bool highlighting(); + bool highlighting() const; void setHighlighting(bool mode); - QColor highlightingColor(); + QColor highlightingColor() const; void setHighlightingColor(const QColor &color); - bool overwriteMode(); + bool overwriteMode() const; void setOverwriteMode(bool overwriteMode); - bool isReadOnly(); + bool isReadOnly() const; void setReadOnly(bool readOnly); protected: @@ -375,13 +375,13 @@ public slots: void resetSelection(qint64 pos); // set selectionStart and selectionEnd to pos void resetSelection(); // set selectionEnd to selectionStart void setSelection(qint64 pos); // set min (if below init) or max (if greater init) - qint64 getSelectionBegin(); - qint64 getSelectionEnd(); + qint64 getSelectionBegin() const; + qint64 getSelectionEnd() const; // Private utility functions void init(); void readBuffers(); - QString toReadable(const QByteArray &ba); + QString toReadable(const QByteArray &ba) const; private slots: void adjust(); // recalc pixel positions