From 7b9a120d42ec7b6aeb3c2993cc1616af7581dbad Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Sun, 25 May 2014 11:53:31 +0200 Subject: [PATCH] EditDialog: Improve handling of binary data in text mode Make the EditDialog a bit more user friendly when editing binary data in text mode: Don't change back to the hex editor after changing any character. Show the full binary data even if it contains a NULL byte. Also (though a bit unrelated) disable rich text input for the text widget. This partially fixes issue #19. --- src/EditDialog.cpp | 8 ++++++-- src/EditDialog.ui | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/EditDialog.cpp b/src/EditDialog.cpp index 92571516..64d72257 100644 --- a/src/EditDialog.cpp +++ b/src/EditDialog.cpp @@ -54,10 +54,15 @@ void EditDialog::loadText(const QByteArray& data, int row, int col) curCol = col; oldData = data; - ui->editorText->setPlainText(data); + QString textData = QString::fromUtf8(data.constData(), data.size()); + ui->editorText->setPlainText(textData); ui->editorText->setFocus(); ui->editorText->selectAll(); hexEdit->setData(data); + + // Assume it's binary data and only call checkDatyType afterwards. This means the correct input widget is selected here in all cases + // but once the user changed it to text input it will stay there. + ui->editorStack->setCurrentIndex(1); checkDataType(); } @@ -162,7 +167,6 @@ void EditDialog::checkDataType() ui->comboEditor->setVisible(false); } else { // It's not. So it's probably some random binary data. - ui->editorStack->setCurrentIndex(1); ui->labelType->setText(tr("Type of data currently in cell: Binary")); ui->labelSize->setText(tr("%n byte(s)", "", hexEdit->data().length())); diff --git a/src/EditDialog.ui b/src/EditDialog.ui index 1855e9a9..83a5ab16 100644 --- a/src/EditDialog.ui +++ b/src/EditDialog.ui @@ -93,6 +93,9 @@ This area displays information about the data present in this database cell + + false +