BinEditor: Use 64-bit wide addresses only when they are required.

Reviewed-by: mae
This commit is contained in:
ck
2009-09-30 11:14:20 +02:00
parent 698d7a2ad6
commit fb7e4ef256
2 changed files with 18 additions and 6 deletions

View File

@@ -83,6 +83,7 @@ BinEditor::BinEditor(QWidget *parent)
m_baseAddr = 0; m_baseAddr = 0;
m_blockSize = 4096; m_blockSize = 4096;
m_size = 0; m_size = 0;
m_addressBytes = 4;
init(); init();
m_unmodifiedState = 0; m_unmodifiedState = 0;
m_readOnly = false; m_readOnly = false;
@@ -93,7 +94,6 @@ BinEditor::BinEditor(QWidget *parent)
m_cursorVisible = false; m_cursorVisible = false;
m_caseSensitiveSearch = false; m_caseSensitiveSearch = false;
setFocusPolicy(Qt::WheelFocus); setFocusPolicy(Qt::WheelFocus);
m_addressString = QString(16 + 3, QLatin1Char(':'));
} }
BinEditor::~BinEditor() BinEditor::~BinEditor()
@@ -102,6 +102,9 @@ BinEditor::~BinEditor()
void BinEditor::init() void BinEditor::init()
{ {
const int addressStringWidth =
2*m_addressBytes + (m_addressBytes - 1) / 2;
m_addressString = QString(addressStringWidth, QLatin1Char(':'));
QFontMetrics fm(fontMetrics()); QFontMetrics fm(fontMetrics());
m_margin = 4; m_margin = 4;
m_descent = fm.descent(); m_descent = fm.descent();
@@ -113,7 +116,8 @@ void BinEditor::init()
m_numVisibleLines = viewport()->height() / m_lineHeight; m_numVisibleLines = viewport()->height() / m_lineHeight;
m_textWidth = 16 * m_charWidth + m_charWidth; m_textWidth = 16 * m_charWidth + m_charWidth;
int m_numberWidth = fm.width(QChar(QLatin1Char('9'))); int m_numberWidth = fm.width(QChar(QLatin1Char('9')));
m_labelWidth = 16 * m_numberWidth + 4 * m_charWidth; m_labelWidth =
2*m_addressBytes * m_numberWidth + (m_addressBytes - 1)/2 * m_charWidth;
int expectedCharWidth = m_columnWidth / 3; int expectedCharWidth = m_columnWidth / 3;
const char *hex = "0123456789abcdef"; const char *hex = "0123456789abcdef";
@@ -132,7 +136,9 @@ void BinEditor::init()
m_isMonospacedFont = false; m_isMonospacedFont = false;
m_columnWidth = fm.width("MMM"); m_columnWidth = fm.width("MMM");
m_labelWidth = fm.width("MMMM:MMMM:MMMM:MMMM"); m_labelWidth = m_addressBytes == 4
? fm.width("MMMM:MMMM")
: fm.width("MMMM:MMMM:MMMM:MMMM");
} }
horizontalScrollBar()->setRange(0, 2 * m_margin + 16 * m_columnWidth horizontalScrollBar()->setRange(0, 2 * m_margin + 16 * m_columnWidth
@@ -333,6 +339,7 @@ void BinEditor::setData(const QByteArray &data)
m_lazyRequests.clear(); m_lazyRequests.clear();
m_data = data; m_data = data;
m_size = data.size(); m_size = data.size();
m_addressBytes = 4;
m_unmodifiedState = 0; m_unmodifiedState = 0;
m_undoStack.clear(); m_undoStack.clear();
@@ -411,6 +418,8 @@ void BinEditor::setLazyData(quint64 startAddr, int range, int blockSize)
m_baseAddr = (m_baseAddr / blockSize) * blockSize; m_baseAddr = (m_baseAddr / blockSize) * blockSize;
m_size = m_baseAddr != 0 && static_cast<quint64>(range) >= -m_baseAddr m_size = m_baseAddr != 0 && static_cast<quint64>(range) >= -m_baseAddr
? -m_baseAddr : range; ? -m_baseAddr : range;
m_addressBytes = (m_baseAddr + m_size < quint64(1) << 32
&& m_baseAddr + m_size >= m_baseAddr) ? 4 : 8;
m_unmodifiedState = 0; m_unmodifiedState = 0;
m_undoStack.clear(); m_undoStack.clear();
@@ -677,9 +686,11 @@ QString BinEditor::addressString(quint64 address)
0, 1, 2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18 0, 1, 2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18
}; };
for (int b = 0; b < 8; ++b) { for (int b = 0; b < m_addressBytes; ++b) {
addressStringData[indices[15 - b*2]] = hex[(address >> (8*b)) & 0xf]; addressStringData[indices[2*m_addressBytes - 1 - b*2]] =
addressStringData[indices[14 - b*2]] = hex[(address >> (8*b + 4)) & 0xf]; hex[(address >> (8*b)) & 0xf];
addressStringData[indices[2*m_addressBytes - 2 - b*2]] =
hex[(address >> (8*b + 4)) & 0xf];
} }
return m_addressString; return m_addressString;
} }

View File

@@ -213,6 +213,7 @@ private:
QBasicTimer m_autoScrollTimer; QBasicTimer m_autoScrollTimer;
Core::IEditor *m_ieditor; Core::IEditor *m_ieditor;
QString m_addressString; QString m_addressString;
int m_addressBytes;
}; };
} // namespace BINEditor } // namespace BINEditor