Skip to content

Commit

Permalink
Fixes and improvement of NULL value handling in Edit DB Cell dock
Browse files Browse the repository at this point in the history
Fix: NULL data are correctly indicated in the Cell Info footer when loading
data from the database. Previously, the automatic trigger of
editModeChanged when setting the text in the widget was causing the change
to Text data type. Now the modified flag of the widget is taken into
account.

Fix: NULL values could not be overwritten with empty strings, since the
old vs. new check was incorrectly returning false as the conversion to
string was discarding the NULL information.

Improvement: NULL values are visually indicated using the placeholder as
already done in the Add Record dialog. The italic style is applied to both
cases now for better indication and coherence to the browse data widget.

Known problem: when the cell is changed from a JSON cell to a NULL cell
and the automatic switch is on, the NULL information and visual indication
are still lost.
  • Loading branch information
mgrojo committed Sep 21, 2018
1 parent dd3417e commit a5d6b50
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/AddRecordDialog.cpp
Expand Up @@ -22,9 +22,11 @@ class NullLineEdit: public QLineEdit {
void setNull(bool value) {
if (value) {
clear();
setStyleSheet("QLineEdit{ font-style: italic; }");
setPlaceholderText(Settings::getValue("databrowser", "null_text").toString());
setModified(false);
} else
setStyleSheet("");
setPlaceholderText("");
m_isNull = value;
}
Expand All @@ -51,6 +53,7 @@ class NullLineEdit: public QLineEdit {
setNull(true);
else {
// Remove any possible NULL mark when user starts typing
setStyleSheet("");
setPlaceholderText("");
QLineEdit::keyPressEvent(evt);
}
Expand Down
27 changes: 20 additions & 7 deletions src/EditDialog.cpp
Expand Up @@ -434,6 +434,8 @@ void EditDialog::setNull()
sciEdit->setEnabled(true);

// Update the cell data info in the bottom left of the Edit Cell
// The mode is also (if required) updated to text since it gives
// the better visual clue of containing a NULL value (placeholder).
updateCellInfoAndMode(hexEdit->data());

ui->editorText->setFocus();
Expand Down Expand Up @@ -470,7 +472,8 @@ void EditDialog::accept()
{
QString oldData = currentIndex.data(Qt::EditRole).toString();
QString newData = removedBom + ui->editorText->toPlainText();
if (oldData != newData)
// Check first for null case, otherwise empty strings cannot overwrite NULL values
if ((currentIndex.data(Qt::EditRole).isNull() && dataType != Null) || oldData != newData)
// The data is different, so commit it back to the database
emit recordTextUpdated(currentIndex, removedBom + newData.toUtf8(), false);
break;
Expand Down Expand Up @@ -716,23 +719,31 @@ void EditDialog::editModeChanged(int newMode)
void EditDialog::editTextChanged()
{
if (dataSource == TextBuffer || dataSource == SciBuffer) {
// Data has been changed in the text editor, so it can't be a NULL
// any more. It hasn't been validated yet, so it cannot be JSON nor XML.
if (dataType == Null) {
dataType = Text;
ui->labelType->setText(tr("Type of data currently in cell: Text / Numeric"));
}

// Update the cell info in the bottom left manually. This is because
// updateCellInfoAndMode() only works with QByteArray's (for now)
int dataLength;
bool isModified;
switch (dataSource) {
case TextBuffer:
dataLength = ui->editorText->toPlainText().length();
isModified = ui->editorText->document()->isModified();
break;
case SciBuffer:
dataLength = sciEdit->text().length();
isModified = sciEdit->isModified();
break;
}
// Data has been changed in the text editor, so it can't be a NULL
// any more. It hasn't been validated yet, so it cannot be JSON nor XML.
if (dataType == Null && isModified)
dataType = Text;

if (dataType != Null) {
ui->editorText->setStyleSheet("");
ui->editorText->setPlaceholderText("");
ui->labelType->setText(tr("Type of data currently in cell: Text / Numeric"));
}
ui->labelSize->setText(tr("%n char(s)", "", dataLength));
}
}
Expand Down Expand Up @@ -914,6 +925,8 @@ void EditDialog::updateCellInfoAndMode(const QByteArray& data)
// NULL data type
ui->labelType->setText(tr("Type of data currently in cell: NULL"));
ui->labelSize->setText(tr("%n byte(s)", "", 0));
ui->editorText->setStyleSheet("QTextEdit{ font-style: italic; }");
ui->editorText->setPlaceholderText(Settings::getValue("databrowser", "null_text").toString());
break;

case Text: {
Expand Down

0 comments on commit a5d6b50

Please sign in to comment.