SILICON
Toggle main menu visibility
Loading...
Searching...
No Matches
binaryEditor.hpp
Go to the documentation of this file.
1
/*
2
Copyright (c) 2026. Giulio Cocconi
3
4
This program is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
#pragma once
19
20
#include <cstddef>
21
#include <cstdint>
22
#include <memory>
23
#include <optional>
24
#include <vector>
25
26
#include <QByteArray>
27
#include <QWidget>
28
29
#include <
ui/lifetime.hpp
>
30
#include <
utils/num_formatting.hpp
>
31
32
class
QLineEdit;
33
class
QUndoStack;
34
35
namespace
SILICON::ui
{
36
37
class
BinaryHexView
;
38
class
BinaryUndoStack
;
39
41
class
BinaryEditor
:
public
QWidget {
42
public
:
43
explicit
BinaryEditor
(QWidget* parent =
nullptr
);
44
~BinaryEditor
()
override
;
45
46
void
setData
(QByteArray
data
);
47
[[nodiscard]]
const
QByteArray&
data
() const noexcept;
48
49
bool
setByteOffset
(std::
size_t
offset);
50
51
[[nodiscard]]
bool
canReadValue
(std::
size_t
bitWidth) const;
52
[[nodiscard]] std::optional<std::uint64_t>
readValue
(std::
size_t
bitWidth) const;
53
bool
overwriteValue
(std::uint64_t value, std::
size_t
bitWidth,
54
const QString& undoText = {});
55
bool
overwriteHexDigit
(
unsigned
digit);
56
57
[[nodiscard]] QUndoStack*
history
() const noexcept;
58
[[nodiscard]]
bool
isModified
() const;
59
void
setModified
(
bool
modified);
60
61
void
refreshInspectors
();
63
void
zoomBy
(
int
steps);
64
65
private:
66
friend class
BinaryHexView
;
67
friend class
BinaryNibbleEditCommand
;
68
69
struct
Inspector
{
70
QLineEdit*
edit
;
71
SILICON::core::BusValueFormat
format
;
72
std::size_t
width
;
73
};
74
75
[[nodiscard]]
unsigned
nibbleAt
(std::size_t offset)
const
;
76
void
applyNibbles
(std::size_t offset,
const
std::vector<unsigned>& values);
77
void
pushNibbleEdit
(std::size_t offset, std::vector<unsigned> values,
78
const
QString& text);
79
void
commitInspector
(
Inspector
& inspector);
80
void
commitOffset
();
81
void
refreshOffset
();
82
void
updateEditorState
();
83
84
QByteArray
bytes
;
85
std::size_t
selectedByte
= 0;
86
bool
highHexDigitEntered
=
false
;
87
BinaryHexView
*
hexView
;
88
QLineEdit*
offsetEdit
;
89
std::vector<Inspector>
inspectors
;
90
std::unique_ptr<BinaryUndoStack>
undoHistory
;
91
CallbackScope
callbacks
;
92
};
93
94
}
// namespace SILICON::ui
SILICON::ui::BinaryEditor::BinaryHexView
friend class BinaryHexView
Definition
binaryEditor.hpp:66
SILICON::ui::BinaryEditor::overwriteHexDigit
bool overwriteHexDigit(unsigned digit)
Definition
binaryEditor.cpp:516
SILICON::ui::BinaryEditor::highHexDigitEntered
bool highHexDigitEntered
Definition
binaryEditor.hpp:86
SILICON::ui::BinaryEditor::commitInspector
void commitInspector(Inspector &inspector)
Definition
binaryEditor.cpp:585
SILICON::ui::BinaryEditor::updateEditorState
void updateEditorState()
Definition
binaryEditor.cpp:656
SILICON::ui::BinaryEditor::applyNibbles
void applyNibbles(std::size_t offset, const std::vector< unsigned > &values)
Definition
binaryEditor.cpp:556
SILICON::ui::BinaryEditor::readValue
std::optional< std::uint64_t > readValue(std::size_t bitWidth) const
Definition
binaryEditor.cpp:484
SILICON::ui::BinaryEditor::hexView
BinaryHexView * hexView
Definition
binaryEditor.hpp:87
SILICON::ui::BinaryEditor::BinaryNibbleEditCommand
friend class BinaryNibbleEditCommand
Definition
binaryEditor.hpp:67
SILICON::ui::BinaryEditor::commitOffset
void commitOffset()
Definition
binaryEditor.cpp:620
SILICON::ui::BinaryEditor::canReadValue
bool canReadValue(std::size_t bitWidth) const
Definition
binaryEditor.cpp:478
SILICON::ui::BinaryEditor::history
QUndoStack * history() const noexcept
Definition
binaryEditor.cpp:533
SILICON::ui::BinaryEditor::setByteOffset
bool setByteOffset(std::size_t offset)
Definition
binaryEditor.cpp:466
SILICON::ui::BinaryEditor::nibbleAt
unsigned nibbleAt(std::size_t offset) const
Definition
binaryEditor.cpp:549
SILICON::ui::BinaryEditor::refreshOffset
void refreshOffset()
Definition
binaryEditor.cpp:643
SILICON::ui::BinaryEditor::callbacks
CallbackScope callbacks
Definition
binaryEditor.hpp:91
SILICON::ui::BinaryEditor::overwriteValue
bool overwriteValue(std::uint64_t value, std::size_t bitWidth, const QString &undoText={})
Definition
binaryEditor.cpp:498
SILICON::ui::BinaryEditor::undoHistory
std::unique_ptr< BinaryUndoStack > undoHistory
Definition
binaryEditor.hpp:90
SILICON::ui::BinaryEditor::refreshInspectors
void refreshInspectors()
Definition
binaryEditor.cpp:603
SILICON::ui::BinaryEditor::isModified
bool isModified() const
Definition
binaryEditor.cpp:538
SILICON::ui::BinaryEditor::inspectors
std::vector< Inspector > inspectors
Definition
binaryEditor.hpp:89
SILICON::ui::BinaryEditor::bytes
QByteArray bytes
Definition
binaryEditor.hpp:84
SILICON::ui::BinaryEditor::setModified
void setModified(bool modified)
Definition
binaryEditor.cpp:543
SILICON::ui::BinaryEditor::offsetEdit
QLineEdit * offsetEdit
Definition
binaryEditor.hpp:88
SILICON::ui::BinaryEditor::selectedByte
std::size_t selectedByte
Definition
binaryEditor.hpp:85
SILICON::ui::BinaryEditor::zoomBy
void zoomBy(int steps)
Adjusts the hexadecimal view's text size by the given number of points.
Definition
binaryEditor.cpp:441
SILICON::ui::BinaryEditor::setData
void setData(QByteArray data)
Definition
binaryEditor.cpp:450
SILICON::ui::BinaryEditor::BinaryEditor
BinaryEditor(QWidget *parent=nullptr)
Definition
binaryEditor.cpp:363
SILICON::ui::BinaryEditor::~BinaryEditor
~BinaryEditor() override
SILICON::ui::BinaryEditor::pushNibbleEdit
void pushNibbleEdit(std::size_t offset, std::vector< unsigned > values, const QString &text)
Definition
binaryEditor.cpp:572
SILICON::ui::BinaryEditor::data
const QByteArray & data() const noexcept
Definition
binaryEditor.cpp:461
SILICON::ui::BinaryHexView
Definition
binaryEditor.cpp:73
SILICON::ui::BinaryUndoStack
Definition
binaryEditor.cpp:358
SILICON::ui::CallbackScope
Definition
lifetime.hpp:34
lifetime.hpp
SILICON::core::BusValueFormat
BusValueFormat
Definition
num_formatting.hpp:33
SILICON::ui
Definition
actionGroups.hpp:14
num_formatting.hpp
SILICON::ui::BinaryEditor::Inspector
Definition
binaryEditor.hpp:69
SILICON::ui::BinaryEditor::Inspector::edit
QLineEdit * edit
Definition
binaryEditor.hpp:70
SILICON::ui::BinaryEditor::Inspector::width
std::size_t width
Definition
binaryEditor.hpp:72
SILICON::ui::BinaryEditor::Inspector::format
SILICON::core::BusValueFormat format
Definition
binaryEditor.hpp:71
src
ui
documents
binary
binaryEditor.hpp
Generated by
1.17.0