BinEditor: Disentangle widget and document a bit further

Change-Id: I39b283645e6d4ac1e6f2f2d22d4befb16be18076
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2024-07-17 10:02:31 +02:00
parent d240cbb261
commit ceef13538c

View File

@@ -133,6 +133,15 @@ public:
void requestNewRange(quint64 address) { if (m_newRangeRequestHandler) m_newRangeRequestHandler(address); } void requestNewRange(quint64 address) { if (m_newRangeRequestHandler) m_newRangeRequestHandler(address); }
void announceChangedData(quint64 address, const QByteArray &ba) { if (m_dataChangedHandler) m_dataChangedHandler(address, ba); } void announceChangedData(quint64 address, const QByteArray &ba) { if (m_dataChangedHandler) m_dataChangedHandler(address, ba); }
void setFinished()
{
m_fetchDataHandler = {};
m_newWindowRequestHandler = {};
m_newRangeRequestHandler = {};
m_dataChangedHandler = {};
m_watchPointRequestHandler = {};
}
qint64 dataIndexOf(const QByteArray &pattern, qint64 from, bool caseSensitive = true) const; qint64 dataIndexOf(const QByteArray &pattern, qint64 from, bool caseSensitive = true) const;
qint64 dataLastIndexOf(const QByteArray &pattern, qint64 from, bool caseSensitive = true) const; qint64 dataLastIndexOf(const QByteArray &pattern, qint64 from, bool caseSensitive = true) const;
void changeData(qint64 position, uchar character, bool highNibble = false); void changeData(qint64 position, uchar character, bool highNibble = false);
@@ -205,8 +214,6 @@ public:
quint64 baseAddress() const { return m_doc->m_baseAddr; } quint64 baseAddress() const { return m_doc->m_baseAddr; }
int addressLength() const { return m_doc->m_addressBytes; } int addressLength() const { return m_doc->m_addressBytes; }
int dataBlockSize() const { return m_doc->m_blockSize; }
qint64 documentSize() const { return m_doc->m_size; } qint64 documentSize() const { return m_doc->m_size; }
bool newWindowRequestAllowed() const { return m_canRequestNewWindow; } bool newWindowRequestAllowed() const { return m_canRequestNewWindow; }
@@ -244,16 +251,6 @@ public:
void setNewWindowRequestAllowed(bool c); void setNewWindowRequestAllowed(bool c);
void setCodec(QTextCodec *codec); void setCodec(QTextCodec *codec);
void setFinished()
{
setReadOnly(true);
m_doc->m_fetchDataHandler = {};
m_doc->m_newWindowRequestHandler = {};
m_doc->m_newRangeRequestHandler = {};
m_doc->m_dataChangedHandler = {};
m_doc->m_watchPointRequestHandler = {};
}
void clearMarkup() { m_markup.clear(); } void clearMarkup() { m_markup.clear(); }
void addMarkup(quint64 a, quint64 l, const QColor &c, const QString &t) { m_markup.append(Markup(a, l, c, t)); } void addMarkup(quint64 a, quint64 l, const QColor &c, const QString &t) { m_markup.append(Markup(a, l, c, t)); }
void commitMarkup() { setMarkup(m_markup); } void commitMarkup() { setMarkup(m_markup); }
@@ -956,7 +953,6 @@ qint64 BinEditorWidget::findPattern(const QByteArray &data, const QByteArray &da
return -1; return -1;
} }
void BinEditorWidget::drawItems(QPainter *painter, int x, int y, const QString &itemString) void BinEditorWidget::drawItems(QPainter *painter, int x, int y, const QString &itemString)
{ {
if (m_isMonospacedFont) { if (m_isMonospacedFont) {
@@ -2178,11 +2174,10 @@ void BinEditorDocument::provideData(quint64 address)
const FilePath fn = filePath(); const FilePath fn = filePath();
if (fn.isEmpty()) if (fn.isEmpty())
return; return;
const int blockSize = m_widget->dataBlockSize(); QByteArray data = fn.fileContents(m_blockSize, address).value_or(QByteArray());
QByteArray data = fn.fileContents(blockSize, address).value_or(QByteArray());
const int dataSize = data.size(); const int dataSize = data.size();
if (dataSize != blockSize) if (dataSize != m_blockSize)
data += QByteArray(blockSize - dataSize, 0); data += QByteArray(m_blockSize - dataSize, 0);
addData(address, data); addData(address, data);
// QMessageBox::critical(ICore::dialogParent(), Tr::tr("File Error"), // QMessageBox::critical(ICore::dialogParent(), Tr::tr("File Error"),
// Tr::tr("Cannot open %1: %2").arg( // Tr::tr("Cannot open %1: %2").arg(
@@ -2279,7 +2274,7 @@ public:
// "Slots" // "Slots"
void setSizes(quint64 address, qint64 range, int blockSize) final { m_document->setSizes(address, range, blockSize); } void setSizes(quint64 address, qint64 range, int blockSize) final { m_document->setSizes(address, range, blockSize); }
void setReadOnly(bool on) final { m_widget->setReadOnly(on); } void setReadOnly(bool on) final { m_widget->setReadOnly(on); }
void setFinished() final { m_widget->setFinished(); } void setFinished() final { m_widget->setReadOnly(true); m_document->setFinished(); }
void setNewWindowRequestAllowed(bool on) final { m_widget->setNewWindowRequestAllowed(on); } void setNewWindowRequestAllowed(bool on) final { m_widget->setNewWindowRequestAllowed(on); }
void setCursorPosition(qint64 pos, MoveMode moveMode = MoveAnchor) final { m_widget->setCursorPosition(pos, moveMode); } void setCursorPosition(qint64 pos, MoveMode moveMode = MoveAnchor) final { m_widget->setCursorPosition(pos, moveMode); }
void updateContents() final { m_document->updateContents(); } void updateContents() final { m_document->updateContents(); }