BinEditor: Fix opening files

Task-number: QTCREATORBUG-5772
Change-Id: I5aba3c9efeac76f261aca9f02fa193e721d735ca
Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
Daniel Teske
2012-03-13 12:47:55 +01:00
committed by hjk
parent ca09c718b8
commit 630ff22d61
2 changed files with 25 additions and 13 deletions

View File

@@ -386,28 +386,40 @@ bool BinEditor::save(QString *errorString, const QString &oldFileName, const QSt
void BinEditor::setSizes(quint64 startAddr, int range, int blockSize)
{
m_blockSize = blockSize;
int newBlockSize = blockSize;
QTC_ASSERT((blockSize/m_bytesPerLine) * m_bytesPerLine == blockSize,
blockSize = (blockSize/m_bytesPerLine + 1) * m_bytesPerLine);
// Users can edit data in the range
// [startAddr - range/2, startAddr + range/2].
quint64 newBaseAddr = quint64(range/2) > startAddr ? 0 : startAddr - range/2;
newBaseAddr = (newBaseAddr / blockSize) * blockSize;
const quint64 maxRange = Q_UINT64_C(0xffffffffffffffff) - newBaseAddr + 1;
int newSize = newBaseAddr != 0 && quint64(range) >= maxRange
? maxRange : range;
int newAddressBytes = (newBaseAddr + newSize < quint64(1) << 32
&& newBaseAddr + newSize >= newBaseAddr) ? 4 : 8;
if (newBlockSize == m_blockSize
&& newBaseAddr == m_baseAddr
&& newSize == m_size
&& newAddressBytes == m_addressBytes)
return;
m_blockSize = blockSize;
m_emptyBlock = QByteArray(blockSize, '\0');
m_modifiedData.clear();
m_requests.clear();
// Users can edit data in the range
// [startAddr - range/2, startAddr + range/2].
m_baseAddr = quint64(range/2) > startAddr ? 0 : startAddr - range/2;
m_baseAddr = (m_baseAddr / blockSize) * blockSize;
const quint64 maxRange = Q_UINT64_C(0xffffffffffffffff) - m_baseAddr + 1;
m_size = m_baseAddr != 0 && quint64(range) >= maxRange
? maxRange : range;
m_addressBytes = (m_baseAddr + m_size < quint64(1) << 32
&& m_baseAddr + m_size >= m_baseAddr) ? 4 : 8;
m_baseAddr = newBaseAddr;
m_size = newSize;
m_addressBytes = newAddressBytes;
m_unmodifiedState = 0;
m_undoStack.clear();
m_redoStack.clear();
init();
setCursorPosition(startAddr - m_baseAddr);

View File

@@ -234,10 +234,10 @@ public:
if (offset >= static_cast<quint64>(file.size()))
return false;
if (file.open(QIODevice::ReadOnly)) {
file.close();
m_fileName = fileName;
m_editor->setSizes(offset, file.size());
m_editor->editor()->setDisplayName(QFileInfo(fileName).fileName());
file.close();
return true;
}
QString errStr = tr("Cannot open %1: %2").arg(