### Install QHexEdit for Python Source: https://github.com/simsys/qhexedit2/blob/master/readme.md Commands to install the QHexEdit library for PyQt5 or PyQt6 environments via pip. ```bash $ # for PyQt5 $ pip install PyQt5 PyQt5-QHexEdit $ $ # for PyQt6 $ pip install PyQt6 PyQt6-QHexEdit ``` -------------------------------- ### QHexEdit Constructor and Basic Configuration Source: https://context7.com/simsys/qhexedit2/llms.txt Demonstrates how to create a QHexEdit widget instance and configure its basic display and editing properties. ```APIDOC ## QHexEdit Constructor Creates a new QHexEdit widget instance that can be embedded in any Qt application as a central widget or child component. ### Method Constructor ### Parameters None ### Request Example ```cpp #include #include #include "qhexedit.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); QMainWindow mainWindow; QHexEdit *hexEdit = new QHexEdit(&mainWindow); mainWindow.setCentralWidget(hexEdit); // Configure the widget hexEdit->setAddressArea(true); // Show address column hexEdit->setAsciiArea(true); // Show ASCII representation hexEdit->setHighlighting(true); // Enable change highlighting hexEdit->setOverwriteMode(true); // Start in overwrite mode hexEdit->setReadOnly(false); // Allow editing mainWindow.resize(610, 460); mainWindow.show(); return app.exec(); } ``` ### Response None (Widget is created and configured) ``` -------------------------------- ### Set and Get Cursor Position Source: https://context7.com/simsys/qhexedit2/llms.txt Controls the cursor position within the hex editor. Position is counted in nibbles (half-bytes). Use `ensureVisible()` to make the cursor visible after programmatic changes. Connect to `currentAddressChanged` to track address changes. ```cpp #include "qhexedit.h" // Set cursor to byte position 100 (upper nibble) hexEdit->setCursorPosition(100 * 2); // Get current cursor position qint64 cursorPos = hexEdit->cursorPosition(); qint64 bytePos = cursorPos / 2; bool lowerNibble = (cursorPos % 2) == 1; qDebug() << "Cursor at byte:" << bytePos << (lowerNibble ? "(lower nibble)" : "(upper nibble)"); // Calculate cursor position from mouse click QPoint mousePos(150, 75); qint64 clickPos = hexEdit->cursorPosition(mousePos); if (clickPos >= 0) { hexEdit->setCursorPosition(clickPos); } // Ensure cursor is visible after programmatic positioning hexEdit->ensureVisible(); // Connect to address change signal connect(hexEdit, &QHexEdit::currentAddressChanged, [](qint64 address) { qDebug() << "Current address:" << QString::number(address, 16); }); ``` -------------------------------- ### Implement QHexEdit in Python Source: https://context7.com/simsys/qhexedit2/llms.txt Demonstrates embedding QHexEdit in a PyQt main window, handling file I/O, and connecting signals. ```python import sys from PyQt5 import QtWidgets, QtCore, QtGui from QHexEdit import QHexEdit class MainWindow(QtWidgets.QMainWindow): def __init__(self): super().__init__() # Create hex editor widget self.hexEdit = QHexEdit() self.setCentralWidget(self.hexEdit) # Configure widget self.hexEdit.setAddressArea(True) self.hexEdit.setAsciiArea(True) self.hexEdit.setHighlighting(True) # Connect signals self.hexEdit.currentAddressChanged.connect(self.on_address_changed) self.hexEdit.currentSizeChanged.connect(self.on_size_changed) self.hexEdit.overwriteModeChanged.connect(self.on_mode_changed) self.create_menus() self.resize(610, 460) def open_file(self): filename, _ = QtWidgets.QFileDialog.getOpenFileName(self) if filename: with open(filename, 'rb') as f: self.hexEdit.setData(f.read()) self.setWindowTitle(f"{filename} - QHexEdit") def save_file(self): filename, _ = QtWidgets.QFileDialog.getSaveFileName(self) if filename: with open(filename, 'wb') as f: f.write(self.hexEdit.data()) def on_address_changed(self, address): self.statusBar().showMessage(f"Address: 0x{address:08X}") def on_size_changed(self, size): print(f"Size: {size} bytes") def on_mode_changed(self, overwrite): mode = "Overwrite" if overwrite else "Insert" print(f"Mode: {mode}") def create_menus(self): file_menu = self.menuBar().addMenu("&File") file_menu.addAction("&Open...", self.open_file, QtGui.QKeySequence.Open) file_menu.addAction("&Save", self.save_file, QtGui.QKeySequence.Save) file_menu.addSeparator() file_menu.addAction("E&xit", self.close) edit_menu = self.menuBar().addMenu("&Edit") edit_menu.addAction("&Undo", self.hexEdit.undo, QtGui.QKeySequence.Undo) edit_menu.addAction("&Redo", self.hexEdit.redo, QtGui.QKeySequence.Redo) if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) app.setApplicationName("QHexEdit") window = MainWindow() window.show() sys.exit(app.exec()) ``` -------------------------------- ### QHexEdit Constructor Source: https://github.com/simsys/qhexedit2/blob/master/doc/html/class_q_hex_edit.html Creates an instance of the QHexEdit widget. ```APIDOC ## QHexEdit Constructor ### Description Creates an instance of [QHexEdit](class_q_hex_edit.html). ### Method QHexEdit::QHexEdit ### Parameters - **parent** (QWidget *) - Optional - Parent widget of [QHexEdit](class_q_hex_edit.html). ### Request Example ```cpp QHexEdit *hexEdit = new QHexEdit(this); ``` ### Response N/A ``` -------------------------------- ### Initialize QHexEdit Widget Source: https://context7.com/simsys/qhexedit2/llms.txt Embeds a QHexEdit widget into a QMainWindow and configures display settings like address and ASCII areas. ```cpp #include #include #include "qhexedit.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); QMainWindow mainWindow; QHexEdit *hexEdit = new QHexEdit(&mainWindow); mainWindow.setCentralWidget(hexEdit); // Configure the widget hexEdit->setAddressArea(true); // Show address column hexEdit->setAsciiArea(true); // Show ASCII representation hexEdit->setHighlighting(true); // Enable change highlighting hexEdit->setOverwriteMode(true); // Start in overwrite mode hexEdit->setReadOnly(false); // Allow editing mainWindow.resize(610, 460); mainWindow.show(); return app.exec(); } ``` -------------------------------- ### QHexEdit Class Members - Methods Source: https://github.com/simsys/qhexedit2/blob/master/doc/html/functions.html This section details the methods of the QHexEdit class. ```APIDOC ## QHexEdit Methods ### addUserArea() * **Description**: Adds a user-defined area to the hex editor. * **Returns**: [QHexEdit] ### clearUserAreas() * **Description**: Clears all user-defined areas from the hex editor. * **Returns**: [QHexEdit] ### currentAddressChanged() * **Description**: Signal emitted when the current address changes. * **Returns**: [QHexEdit] ### currentSizeChanged() * **Description**: Signal emitted when the current size changes. * **Returns**: [QHexEdit] ### dataAt() * **Description**: Retrieves data at a specific address. * **Returns**: [QHexEdit] ### dataChanged() * **Description**: Signal emitted when the data in the hex editor changes. * **Returns**: [QHexEdit] ### ensureVisible() * **Description**: Ensures that a specific address or range is visible in the editor. * **Returns**: [QHexEdit] ### indexOf() * **Description**: Finds the index of a given byte sequence. * **Returns**: [QHexEdit] ### insert() * **Description**: Inserts data at a specific position. * **Returns**: [QHexEdit] ### isModified() * **Description**: Checks if the data in the hex editor has been modified. * **Returns**: [QHexEdit] ### lastIndexOf() * **Description**: Finds the last index of a given byte sequence. * **Returns**: [QHexEdit] ### overwriteModeChanged() * **Description**: Signal emitted when the overwrite mode changes. * **Returns**: [QHexEdit] ### QHexEdit() * **Description**: Constructor for the QHexEdit class. * **Returns**: [QHexEdit] ### redo() * **Description**: Re-applies the last undone action. * **Returns**: [QHexEdit] ### remove() * **Description**: Removes data from a specific position. * **Returns**: [QHexEdit] ### replace() * **Description**: Replaces data at a specific position. * **Returns**: [QHexEdit] ### selectedData() * **Description**: Retrieves the currently selected data. * **Returns**: [QHexEdit] ### selectionToReadableString() * **Description**: Converts the selected data to a human-readable string. * **Returns**: [QHexEdit] ### setData() * **Description**: Sets the data for the hex editor. * **Returns**: [QHexEdit] ### setFont() * **Description**: Sets the font for the hex editor. * **Returns**: [QHexEdit] ### toReadableString() * **Description**: Converts all data in the hex editor to a human-readable string. * **Returns**: [QHexEdit] ### undo() * **Description**: Undoes the last action. * **Returns**: [QHexEdit] ### write() * **Description**: Writes data to a specific position. * **Returns**: [QHexEdit] ``` -------------------------------- ### Editor Properties Source: https://github.com/simsys/qhexedit2/blob/master/doc/html/qhexedit_8h_source.html Methods for configuring the appearance and behavior of the QHexEdit widget. ```APIDOC ## void setAddressArea(bool addressArea) ### Description Enables or disables the display of the address area. ## void setBytesPerLine(int count) ### Description Sets the number of bytes displayed per line in the editor. ## void setData(const QByteArray &ba) ### Description Sets the binary data to be displayed and edited. ## void setReadOnly(bool readOnly) ### Description Sets the read-only state of the editor. ``` -------------------------------- ### Property: data Source: https://github.com/simsys/qhexedit2/blob/master/doc/html/class_q_hex_edit.html Manages the content of the QHexEdit widget. ```APIDOC ## GET/SET /QHexEdit/data ### Description Holds the content of the QHexEdit. Setting data creates an internal copy; for large files, use QIODevice-based methods. ``` -------------------------------- ### QHexEdit License Information Source: https://github.com/simsys/qhexedit2/blob/master/readme.md The GNU Lesser General Public License terms for the QHexEdit library. ```text QHexEdit is a Hex Editor Widget for the Qt Framework Copyright (C) 2010-2025 Winfried Simon This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, see https://www.gnu.org/licenses/ ``` -------------------------------- ### QHexEdit Properties Source: https://github.com/simsys/qhexedit2/blob/master/doc/html/functions_prop.html This section lists and describes the properties available for the QHexEdit class. ```APIDOC ## QHexEdit Properties ### Description This section lists and describes the properties available for the QHexEdit class. ### Properties - **addressArea** (QHexEdit) - Description of the address area property. - **addressOffset** (QHexEdit) - Description of the address offset property. - **addressWidth** (QHexEdit) - Description of the address width property. - **asciiArea** (QHexEdit) - Description of the ASCII area property. - **bytesPerLine** (QHexEdit) - Description of the bytes per line property. - **cursorPosition** (QHexEdit) - Description of the cursor position property. - **data** (QHexEdit) - Description of the data property. - **dynamicBytesPerLine** (QHexEdit) - Description of the dynamic bytes per line property. - **font** (QHexEdit) - Description of the font property. - **hexCaps** (QHexEdit) - Description of the hex caps property. - **highlighting** (QHexEdit) - Description of the highlighting property. - **highlightingColor** (QHexEdit) - Description of the highlighting color property. - **overwriteMode** (QHexEdit) - Description of the overwrite mode property. - **readOnly** (QHexEdit) - Description of the read-only property. ``` -------------------------------- ### QHexEdit Public Member Functions Source: https://github.com/simsys/qhexedit2/blob/master/doc/html/class_q_hex_edit.html Core functions for interacting with and manipulating the QHexEdit widget. ```APIDOC ## QHexEdit ### Description Constructs a QHexEdit widget. ### Parameters - **parent** (QWidget *) - The parent widget. ### Method Constructor ### Endpoint N/A (Class constructor) ## setData ### Description Sets the data for the QHexEdit widget from a QIODevice. ### Parameters - **iODevice** (QIODevice &) - The input/output device containing the data. ### Returns - bool - True if the data was set successfully, false otherwise. ### Method Public Member Function ### Endpoint N/A (Class method) ## dataAt ### Description Retrieves a block of data from the QHexEdit widget at a specified position. ### Parameters - **pos** (qint64) - The starting position to read data from. - **count** (qint64) - The number of bytes to read. Defaults to -1 (read all remaining data). ### Returns - QByteArray - The requested data block. ### Method Public Member Function ### Endpoint N/A (Class method) ## write ### Description Writes data from the QHexEdit widget to a QIODevice. ### Parameters - **iODevice** (QIODevice &) - The output device to write data to. - **pos** (qint64) - The starting position in the QHexEdit widget to write from. Defaults to 0. - **count** (qint64) - The number of bytes to write. Defaults to -1 (write all data from pos). ### Returns - bool - True if the data was written successfully, false otherwise. ### Method Public Member Function ### Endpoint N/A (Class method) ## insert (char) ### Description Inserts a single character into the data at the specified position. ### Parameters - **pos** (qint64) - The position at which to insert the character. - **ch** (char) - The character to insert. ### Method Public Member Function ### Endpoint N/A (Class method) ## remove ### Description Removes a specified number of bytes from the data starting at a given position. ### Parameters - **pos** (qint64) - The starting position to remove data from. - **len** (qint64) - The number of bytes to remove. Defaults to 1. ### Method Public Member Function ### Endpoint N/A (Class method) ## replace (char) ### Description Replaces a single byte at the specified position with a new character. ### Parameters - **pos** (qint64) - The position of the byte to replace. - **ch** (char) - The new character to place at the position. ### Method Public Member Function ### Endpoint N/A (Class method) ## insert (QByteArray) ### Description Inserts a QByteArray into the data at the specified position. ### Parameters - **pos** (qint64) - The position at which to insert the byte array. - **ba** (const QByteArray &) - The byte array to insert. ### Method Public Member Function ### Endpoint N/A (Class method) ## replace (len, QByteArray) ### Description Replaces a specified number of bytes starting from a position with a new QByteArray. ### Parameters - **pos** (qint64) - The starting position for replacement. - **len** (qint64) - The number of bytes to replace. - **ba** (const QByteArray &) - The byte array to insert. ### Method Public Member Function ### Endpoint N/A (Class method) ## addUserArea ### Description Adds a user-defined area to the hex editor with specified styling. ### Parameters - **posStart** (qint64) - The starting position of the user area. - **posEnd** (qint64) - The ending position of the user area. - **fontColor** (QColor) - The color of the font in the user area. - **areaStyle** (QBrush) - The brush style for the user area background. ### Method Public Member Function ### Endpoint N/A (Class method) ## clearUserAreas ### Description Removes all user-defined areas from the hex editor. ### Method Public Member Function ### Endpoint N/A (Class method) ## cursorPosition (QPoint) ### Description Calculates the data position corresponding to a given widget point. ### Parameters - **point** (QPoint) - The widget point to convert. ### Returns - qint64 - The calculated data position. ### Method Public Member Function ### Endpoint N/A (Class method) ## ensureVisible ### Description Ensures that the current cursor position or selection is visible within the widget. ### Method Public Member Function ### Endpoint N/A (Class method) ## indexOf ### Description Finds the first occurrence of a byte array within the data, starting from a specified position. ### Parameters - **ba** (const QByteArray &) - The byte array to search for. - **from** (qint64) - The position to start the search from. ### Returns - qint64 - The index of the first occurrence, or -1 if not found. ### Method Public Member Function ### Endpoint N/A (Class method) ## isModified ### Description Checks if the data in the QHexEdit widget has been modified since it was loaded or last saved. ### Returns - bool - True if the data is modified, false otherwise. ### Method Public Member Function ### Endpoint N/A (Class method) ## lastIndexOf ### Description Finds the last occurrence of a byte array within the data, starting from a specified position and searching backwards. ### Parameters - **ba** (const QByteArray &) - The byte array to search for. - **from** (qint64) - The position to start the search from (searching backwards). ### Returns - qint64 - The index of the last occurrence, or -1 if not found. ### Method Public Member Function ### Endpoint N/A (Class method) ## selectionToReadableString ### Description Converts the currently selected data into a human-readable string format. ### Returns - QString - The readable string representation of the selection. ### Method Public Member Function ### Endpoint N/A (Class method) ## selectedData ### Description Retrieves the currently selected data as a QByteArray. ### Returns - QByteArray - The selected data. ### Method Public Member Function ### Endpoint N/A (Class method) ## setFont ### Description Sets the font for the QHexEdit widget. ### Parameters - **font** (const QFont &) - The font to set. ### Method Public Member Function ### Endpoint N/A (Class method) ## toReadableString ### Description Converts all the data in the QHexEdit widget into a human-readable string format. ### Returns - QString - The readable string representation of all data. ### Method Public Member Function ### Endpoint N/A (Class method) ``` -------------------------------- ### QHexEdit Class Definition Source: https://github.com/simsys/qhexedit2/blob/master/doc/html/qhexedit_8h_source.html The header file defines the QHexEdit class, including its properties, public methods for data manipulation, and character/byte array handling. ```cpp #ifndef QHEXEDIT_H #define QHEXEDIT_H #include #include #include #include "chunks.h" #include "commands.h" #include "color_manager.h" #ifdef QHEXEDIT_EXPORTS #define QHEXEDIT_API Q_DECL_EXPORT #elif QHEXEDIT_IMPORTS #define QHEXEDIT_API Q_DECL_IMPORT #else #define QHEXEDIT_API #endif class QHEXEDIT_API QHexEdit : public QAbstractScrollArea { Q_OBJECT Q_PROPERTY(bool addressArea READ addressArea WRITE setAddressArea) Q_PROPERTY(qint64 addressOffset READ addressOffset WRITE setAddressOffset) Q_PROPERTY(int addressWidth READ addressWidth WRITE setAddressWidth) Q_PROPERTY(bool asciiArea READ asciiArea WRITE setAsciiArea) Q_PROPERTY(int bytesPerLine READ bytesPerLine WRITE setBytesPerLine) Q_PROPERTY(qint64 cursorPosition READ cursorPosition WRITE setCursorPosition) Q_PROPERTY(QByteArray data READ data WRITE setData NOTIFY dataChanged) Q_PROPERTY(bool hexCaps READ hexCaps WRITE setHexCaps) Q_PROPERTY(bool dynamicBytesPerLine READ dynamicBytesPerLine WRITE setDynamicBytesPerLine) Q_PROPERTY(bool highlighting READ highlighting WRITE setHighlighting) Q_PROPERTY(QColor highlightingColor READ highlightingColor WRITE setHighlightingColor) Q_PROPERTY(bool overwriteMode READ overwriteMode WRITE setOverwriteMode) Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) Q_PROPERTY(QFont font READ font WRITE setFont) public: QHexEdit(QWidget *parent=NULL); // Access to data of qhexedit bool setData(QIODevice &iODevice); QByteArray dataAt(qint64 pos, qint64 count=-1); bool write(QIODevice &iODevice, qint64 pos=0, qint64 count=-1); // Char handling void insert(qint64 pos, char ch); void remove(qint64 pos, qint64 len=1); void replace(qint64 pos, char ch); // ByteArray handling void insert(qint64 pos, const QByteArray &ba); void replace(qint64 pos, qint64 len, const QByteArray &ba); // User marking areas void addUserArea(qint64 posStart, qint64 posEnd, QColor fontColor, QBrush areaStyle); void clearUserAreas(); // Utility functions qint64 cursorPosition(QPoint point); void ensureVisible(); ``` -------------------------------- ### Connect QHexEdit Signals in C++ Source: https://context7.com/simsys/qhexedit2/llms.txt Connects QHexEdit signals to UI elements like labels and status bars to reflect state changes. ```cpp #include "qhexedit.h" #include #include // Connect to current address changed signal connect(hexEdit, &QHexEdit::currentAddressChanged, [this](qint64 address) { addressLabel->setText(QString("0x%1").arg(address, 8, 16, QChar('0'))); }); // Connect to size changed signal connect(hexEdit, &QHexEdit::currentSizeChanged, [this](qint64 size) { sizeLabel->setText(QString("%1 bytes").arg(size)); }); // Connect to data changed signal connect(hexEdit, &QHexEdit::dataChanged, [this]() { setWindowModified(true); statusBar()->showMessage("Document modified", 2000); }); // Connect to overwrite mode changed signal connect(hexEdit, &QHexEdit::overwriteModeChanged, [this](bool overwrite) { modeLabel->setText(overwrite ? "OVR" : "INS"); }); ``` -------------------------------- ### Handle Large Files with QIODevice Source: https://context7.com/simsys/qhexedit2/llms.txt Uses setData with a QFile to handle files larger than 2GB. Changes are managed in memory chunks and can be written back to the device. ```cpp #include "qhexedit.h" #include #include void MainWindow::loadFile(const QString &fileName) { QFile file(fileName); if (!hexEdit->setData(file)) { QMessageBox::warning(this, tr("QHexEdit"), tr("Cannot read file %1:\n%2.") .arg(fileName) .arg(file.errorString())); return; } statusBar()->showMessage(tr("File loaded"), 2000); } // Save edited data back to a file void MainWindow::saveFile(const QString &fileName) { QFile file(fileName); if (!file.open(QFile::WriteOnly)) { QMessageBox::warning(this, tr("Error"), tr("Cannot write file")); return; } // Write all data to the file bool success = hexEdit->write(file); file.close(); if (success) { statusBar()->showMessage(tr("File saved"), 2000); } } ``` -------------------------------- ### QHexEdit Class Members Source: https://github.com/simsys/qhexedit2/blob/master/doc/html/class_q_hex_edit-members.html A summary of the available methods, signals, and slots for the QHexEdit component. ```APIDOC ## QHexEdit Class Members ### Description This list contains the primary methods, signals, and slots available for the QHexEdit class. ### Key Methods - **addUserArea(qint64 posStart, qint64 posEnd, QColor fontColor, QBrush areaStyle)** - Adds a highlighted area. - **clearUserAreas()** - Clears all user-defined areas. - **dataAt(qint64 pos, qint64 count=-1)** - Retrieves data at a specific position. - **insert(qint64 pos, const QByteArray &ba)** - Inserts data at a specific position. - **remove(qint64 pos, qint64 len=1)** - Removes data at a specific position. - **replace(qint64 pos, qint64 len, const QByteArray &ba)** - Replaces data at a specific position. - **setData(QIODevice &iODevice)** - Sets the data source for the editor. ### Signals - **currentAddressChanged(qint64 address)** - **currentSizeChanged(qint64 size)** - **dataChanged()** - **overwriteModeChanged(bool state)** ### Slots - **redo()** ``` -------------------------------- ### QHexEdit Class Overview Source: https://github.com/simsys/qhexedit2/blob/master/doc/html/annotated.html The QHexEdit class provides a widget for editing binary data in a hexadecimal format. ```APIDOC ## QHexEdit Class ### Description QHexEdit is the main class provided by the library for displaying and editing binary data in a hex editor interface. ### Class Reference - **Name**: QHexEdit - **Type**: Class ``` -------------------------------- ### QHexEdit Search and State Methods Source: https://github.com/simsys/qhexedit2/blob/master/doc/html/class_q_hex_edit.html Methods for searching data and checking the modification state of the document. ```APIDOC ## qint64 QHexEdit::indexOf(const QByteArray & ba, qint64 from) ### Description Finds the first occurrence of a byte array in the data. ### Parameters #### Path Parameters - **ba** (QByteArray) - Required - Data to find - **from** (qint64) - Required - Point where the search starts ### Response - **pos** (qint64) - Returns the position if found, else -1 ## bool QHexEdit::isModified() ### Description Returns whether any changes have been made to the document. ### Response - **result** (bool) - true if modified, false otherwise ``` -------------------------------- ### Search for byte patterns in QHexEdit2 Source: https://context7.com/simsys/qhexedit2/llms.txt Searches for byte patterns using indexOf or lastIndexOf. Matches are automatically selected and scrolled to. ```cpp #include "qhexedit.h" // Search for a hex pattern QByteArray searchPattern = QByteArray::fromHex("504B0304"); // ZIP file signature // Search forward from beginning qint64 pos = hexEdit->indexOf(searchPattern, 0); if (pos >= 0) { qDebug() << "Found ZIP signature at position:" << pos; // Widget automatically selects and scrolls to the match } else { qDebug() << "Pattern not found"; } // Search backward from current position qint64 currentPos = hexEdit->cursorPosition() / 2; qint64 prevPos = hexEdit->lastIndexOf(searchPattern, currentPos); if (prevPos >= 0) { qDebug() << "Previous match at:" << prevPos; } // Find all occurrences QList allMatches; qint64 searchPos = 0; while ((searchPos = hexEdit->indexOf(searchPattern, searchPos)) >= 0) { allMatches.append(searchPos); searchPos += searchPattern.length(); } qDebug() << "Found" << allMatches.size() << "matches"; ``` -------------------------------- ### Update Documentation Source: https://github.com/simsys/qhexedit2/blob/master/doc/howtorelease.txt Steps to update the project documentation on GitHub Pages. This involves copying generated HTML files and committing them to the simsys.github.io repository. ```bash git clone https://github.com/Simsys/simsys.github.io $ git add * $ git commit -m "v0.x.y" $ git push origin master ``` -------------------------------- ### Method: write Source: https://github.com/simsys/qhexedit2/blob/master/doc/html/class_q_hex_edit.html Writes data from the editor to a QIODevice. ```APIDOC ## POST /QHexEdit/write ### Description Writes the data from the editor into a QIODevice starting at a specific position. ### Parameters #### Request Body - **iODevice** (QIODevice&) - Required - The target device to write to. - **pos** (qint64) - Optional - Starting position (default 0). - **count** (qint64) - Optional - Number of bytes to deliver (default -1). ``` -------------------------------- ### Data Access Methods Source: https://github.com/simsys/qhexedit2/blob/master/doc/html/qhexedit_8h_source.html Methods for accessing and manipulating the data within QHexEdit. ```APIDOC ## Data Access Methods ### Description Methods to interact with the data stored in the QHexEdit widget. ### Methods - **setData(QIODevice &iODevice)**: Sets the data for the hex editor from a QIODevice. - **dataAt(qint64 pos, qint64 count = -1)**: Returns a QByteArray containing data from the specified position and count. - **write(QIODevice &iODevice, qint64 pos = 0, qint64 count = -1)**: Writes data from the hex editor to a QIODevice starting at a specified position and count. ``` -------------------------------- ### Load and Access In-Memory Data Source: https://context7.com/simsys/qhexedit2/llms.txt Uses setData with a QByteArray for smaller files that fit into memory. Access the modified data using the data() method. ```cpp #include "qhexedit.h" // Create widget and load data from QByteArray QHexEdit *hexEdit = new QHexEdit(this); // Set data directly from a byte array QByteArray data; data.append('\x48'); // H data.append('\x65'); // e data.append('\x6c'); // l data.append('\x6c'); // l data.append('\x6f'); // o data.append('\x00'); // null terminator hexEdit->setData(data); // Access the data after editing QByteArray editedData = hexEdit->data(); qDebug() << "Data size:" << editedData.size(); qDebug() << "First byte:" << QString::number(editedData[0], 16); ``` -------------------------------- ### Utility Functions Source: https://github.com/simsys/qhexedit2/blob/master/doc/html/qhexedit_8h_source.html Helper functions for cursor positioning and ensuring visibility. ```APIDOC ## Utility Functions ### Description Utility methods for common operations within the hex editor. ### Methods - **cursorPosition(QPoint point)**: Returns the cursor position corresponding to a given QPoint. - **ensureVisible()**: Scrolls the widget to ensure the current cursor position is visible. ``` -------------------------------- ### Manage undo and redo in QHexEdit2 Source: https://context7.com/simsys/qhexedit2/llms.txt Provides undo/redo functionality for editing operations. Can be connected to UI actions or triggered programmatically. ```cpp #include "qhexedit.h" #include // Connect undo/redo to UI actions QAction *undoAction = new QAction(QIcon(":/images/undo.png"), tr("&Undo"), this); undoAction->setShortcuts(QKeySequence::Undo); connect(undoAction, SIGNAL(triggered()), hexEdit, SLOT(undo())); QAction *redoAction = new QAction(QIcon(":/images/redo.png"), tr("&Redo"), this); redoAction->setShortcuts(QKeySequence::Redo); connect(redoAction, SIGNAL(triggered()), hexEdit, SLOT(redo())); // Programmatic undo/redo hexEdit->setData(QByteArray(100, '\x00')); // Clear undo stack with new data hexEdit->replace(0, '\xFF'); // Change 1 hexEdit->replace(1, '\xFE'); // Change 2 hexEdit->insert(2, '\xFD'); // Change 3 hexEdit->undo(); // Reverts insert hexEdit->undo(); // Reverts second replace hexEdit->redo(); // Re-applies second replace // Check modification status if (hexEdit->isModified()) { qDebug() << "Document has unsaved changes"; } ``` -------------------------------- ### Include Headers Source: https://github.com/simsys/qhexedit2/blob/master/doc/html/color__manager_8h_source.html Includes necessary Qt headers for core functionalities like event handling, graphics, and custom data structures. These are required for the classes defined in this header. ```cpp #include #include ``` ```cpp #include "chunks.h" ``` -------------------------------- ### write Source: https://github.com/simsys/qhexedit2/blob/master/doc/html/class_q_hex_edit-members.html Writes data from the hex editor to a specified I/O device. ```APIDOC ## write ### Description Writes data from the hex editor to a QIODevice. ### Method public qint64 write(QIODevice &iODevice, qint64 pos = 0, qint64 count = -1) ### Endpoint N/A (Class method) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) - **qint64** - The number of bytes written. #### Response Example { "example": "Number of bytes written" } ``` -------------------------------- ### Display Properties Configuration Source: https://context7.com/simsys/qhexedit2/llms.txt Configure the visual appearance of the hex editor, including address and ASCII areas, bytes per line, highlighting, fonts, and editing modes. ```APIDOC ## Address Area Configuration ### Description Controls the visibility and formatting of the address column. ### Method `setAddressArea(bool visible)` `setAddressWidth(int width)` `setAddressOffset(qint64 offset)` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```cpp // Address area configuration hexEdit->setAddressArea(true); // Show/hide address column hexEdit->setAddressWidth(8); // Minimum address digits hexEdit->setAddressOffset(0x10000); // Offset added to displayed addresses ``` ### Response #### Success Response (200) - `void` #### Response Example None ## ASCII Area Configuration ### Description Controls the visibility and the default character for non-printable bytes in the ASCII representation area. ### Method `setAsciiArea(bool visible)` `setDefaultChar(char ch)` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```cpp // ASCII area configuration hexEdit->setAsciiArea(true); // Show/hide ASCII representation hexEdit->setDefaultChar('.'); // Character for non-printable bytes ``` ### Response #### Success Response (200) - `void` #### Response Example None ## Data Layout Configuration ### Description Configures the number of bytes displayed per line, with an option for dynamic adjustment. ### Method `setBytesPerLine(int bytes)` `setDynamicBytesPerLine(bool enabled)` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```cpp // Data layout hexEdit->setBytesPerLine(16); // Fixed bytes per line hexEdit->setDynamicBytesPerLine(true); // Auto-adjust to widget width ``` ### Response #### Success Response (200) - `void` #### Response Example None ## Appearance Configuration ### Description Sets properties related to the visual appearance, such as hexadecimal character casing and highlighting. ### Method `setHexCaps(bool caps)` `setHighlighting(bool enabled)` `setHighlightingColor(const QColor &color)` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```cpp // Appearance hexEdit->setHexCaps(true); // Display A-F instead of a-f hexEdit->setHighlighting(true); // Highlight modified bytes hexEdit->setHighlightingColor(QColor(255, 255, 0, 100)); // Yellow highlight ``` ### Response #### Success Response (200) - `void` #### Response Example None ## Font Configuration ### Description Sets the font used for displaying hex data and ASCII representation. ### Method `setFont(const QFont &font)` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```cpp QFont monoFont("Courier New", 10); monoFont.setStyleHint(QFont::Monospace); hexEdit->setFont(monoFont); ``` ### Response #### Success Response (200) - `void` #### Response Example None ## Edit Mode Configuration ### Description Configures whether the editor operates in overwrite or insert mode, and whether it is read-only. ### Method `setOverwriteMode(bool overwrite)` `setReadOnly(bool readOnly)` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```cpp // Edit mode hexEdit->setOverwriteMode(true); // Overwrite vs insert mode hexEdit->setReadOnly(false); // Allow/prevent editing ``` ### Response #### Success Response (200) - `void` #### Response Example None ## Connect to Mode Change Signal ### Description Connects a slot to the `overwriteModeChanged` signal, which is emitted when the edit mode changes. ### Method `connect(hexEdit, &QHexEdit::overwriteModeChanged, handler)` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```cpp connect(hexEdit, &QHexEdit::overwriteModeChanged, [](bool overwrite) { qDebug() << (overwrite ? "Overwrite mode" : "Insert mode"); }); ``` ### Response #### Success Response (200) - `void` #### Response Example ```cpp // Example output: // Overwrite mode ``` ``` -------------------------------- ### QHexEdit Internal Data Structures Source: https://github.com/simsys/qhexedit2/blob/master/doc/html/qhexedit_8h_source.html Overview of the internal state variables used by the QHexEdit class for data handling and UI rendering. ```APIDOC ## Internal State Variables ### Description These variables represent the internal state of the QHexEdit component, including data buffers, cursor positioning, and modification tracking. ### Data Members - **_chunks** (Chunks*) - IODevice based access to data - **_cursorTimer** (QTimer) - Timer for blinking cursor - **_cursorPosition** (qint64) - Absolute position of cursor (1 Byte == 2 tics) - **_cursorRect** (QRect) - Physical dimensions of cursor - **_data** (QByteArray) - QHexEdit's data when setup with QByteArray - **_dataShown** (QByteArray) - Data in the current View - **_hexDataShown** (QByteArray) - Data in view, transformed to hex - **_lastEventSize** (qint64) - Size emitted last time - **_markedShown** (QByteArray) - Marked data in view - **_modified** (bool) - Indicates if data in editor is modified - **_rowsShown** (int) - Number of lines of text shown - **_undoStack** (UndoStack*) - Stack to store edit actions for undo/redo - **_colorManager** (ColorManager*) - Manages highlighting, selection, and area colors ``` -------------------------------- ### setData (QByteArray) Source: https://context7.com/simsys/qhexedit2/llms.txt Sets the binary data to be displayed and edited using a QByteArray. Suitable for smaller, in-memory data. ```APIDOC ## setData (QByteArray) Sets the binary data to be displayed and edited using a QByteArray. This creates an internal copy of the data suitable for smaller files. Use this method when working with in-memory data or files that fit comfortably in memory. ### Method `setData` ### Endpoint N/A (Method of QHexEdit class) ### Parameters #### Request Body - **data** (QByteArray) - Required - The byte array containing the data to set. ### Request Example ```cpp #include "qhexedit.h" // Create widget and load data from QByteArray QHexEdit *hexEdit = new QHexEdit(this); // Set data directly from a byte array QByteArray data; data.append('\x48'); // H data.append('\x65'); // e data.append('\x6c'); // l data.append('\x6c'); // l data.append('\x6f'); // o data.append('\x00'); // null terminator hexEdit->setData(data); // Access the data after editing QByteArray editedData = hexEdit->data(); qDebug() << "Data size:" << editedData.size(); qDebug() << "First byte:" << QString::number(editedData[0], 16); ``` ### Response #### Success Response (void) Sets the internal data of the QHexEdit widget. #### Response Example N/A (Method returns void) ``` -------------------------------- ### QHexEdit Public Slots Source: https://github.com/simsys/qhexedit2/blob/master/doc/html/class_q_hex_edit.html Functions that can be invoked to control the QHexEdit widget's state. ```APIDOC ## redo ### Description Reverts the last undo operation. ### Method Public Slot ### Endpoint N/A (Class method) ## undo ### Description Reverts the last modification made to the data. ### Method Public Slot ### Endpoint N/A (Class method) ``` -------------------------------- ### dataAt and write Source: https://context7.com/simsys/qhexedit2/llms.txt Retrieves a portion of data from a specific position or writes data to a QIODevice. Use dataAt() to extract segments, and write() to save to files. ```APIDOC ## dataAt and write Retrieves a portion of data from a specific position or writes data to a QIODevice. Use dataAt() to extract segments of the binary data, and write() to save to files with optional position and count parameters. ### Method `dataAt(qint64 position, qint64 count)` `write(QIODevice &device, qint64 position = 0, qint64 count = -1)` ### Endpoint N/A (Methods of QHexEdit class) ### Parameters #### `dataAt` Parameters - **position** (qint64) - Required - The starting byte position to read from. - **count** (qint64) - Required - The number of bytes to read. #### `write` Parameters - **device** (QIODevice&) - Required - The QIODevice to write data to. - **position** (qint64) - Optional - The starting byte position to write from. Defaults to 0. - **count** (qint64) - Optional - The number of bytes to write. If -1, all data is written. Defaults to -1. ### Request Example ```cpp #include "qhexedit.h" #include // Extract data from a specific position qint64 startPosition = 0x100; // Start at byte 256 qint64 byteCount = 64; // Get 64 bytes QByteArray segment = hexEdit->dataAt(startPosition, byteCount); qDebug() << "Extracted" << segment.size() << "bytes from position" << startPosition; // Write a portion of data to a separate file QFile outputFile("segment.bin"); if (outputFile.open(QFile::WriteOnly)) { // Write 1024 bytes starting from position 0x200 hexEdit->write(outputFile, 0x200, 1024); outputFile.close(); } // Write all data (count = -1 means everything) QFile fullOutput("complete.bin"); if (fullOutput.open(QFile::WriteOnly)) { hexEdit->write(fullOutput, 0, -1); fullOutput.close(); } ``` ### Response #### Success Response (`dataAt` returns QByteArray, `write` returns bool) - **`dataAt`**: Returns a QByteArray containing the requested data segment. - **`write`**: Returns `true` if the data was written successfully, `false` otherwise. #### Response Example N/A (Return values indicate data or success status) ``` -------------------------------- ### QHexEdit Data Manipulation Methods Source: https://github.com/simsys/qhexedit2/blob/master/doc/html/class_q_hex_edit.html Methods for inserting, removing, and replacing data within the QHexEdit component. ```APIDOC ## void QHexEdit::insert(qint64 pos, char ch) ### Description Inserts a single character at the specified position. The size of the data grows. ### Parameters #### Path Parameters - **pos** (qint64) - Required - Index position where to insert - **ch** (char) - Required - Char to insert ## void QHexEdit::remove(qint64 pos, qint64 len) ### Description Removes a specified number of bytes from the content. ### Parameters #### Path Parameters - **pos** (qint64) - Required - Index position where to remove - **len** (qint64) - Optional - Amount of bytes to remove (default 1) ## void QHexEdit::replace(qint64 pos, qint64 len, const QByteArray & ba) ### Description Replaces len bytes with a byte array. The data is overwritten and the size may change. ### Parameters #### Path Parameters - **pos** (qint64) - Required - Index position where to overwrite - **len** (qint64) - Required - Count of bytes to overwrite - **ba** (QByteArray) - Required - Data to insert ```