Allow user to set the BLOB text. Preview for field display in Preferences

A new setting allows the user to set the text for BLOB data in the cell.

The existing line-edit for setting the NULL text and the new one for BLOB
are updated with the cell background and foreground colors, providing a
preview of the desired changes. An additional preview-only box is added for
the regular fields.

See issue #1263

Settings in Database tab are left-aligned for consistency to other tabs.
See comment in #1173.
This commit is contained in:
mgrojo
2017-12-11 22:00:03 +01:00
parent 4a9f1a2a50
commit 7ac93e34ed
5 changed files with 134 additions and 64 deletions

View File

@@ -86,13 +86,14 @@ void PreferencesDialog::loadSettings()
ui->spinDataBrowserFontSize->setValue(Settings::getValue("databrowser", "fontsize").toInt());
loadColorSetting(ui->fr_null_fg, "null_fg");
loadColorSetting(ui->fr_null_bg, "null_bg");
loadColorSetting(ui->fr_reg_fg, "reg_fg");
loadColorSetting(ui->fr_reg_bg, "reg_bg");
loadColorSetting(ui->fr_bin_fg, "bin_fg");
loadColorSetting(ui->fr_bin_bg, "bin_bg");
loadColorSetting(ui->fr_reg_fg, "reg_fg");
loadColorSetting(ui->fr_reg_bg, "reg_bg");
ui->spinSymbolLimit->setValue(Settings::getValue("databrowser", "symbol_limit").toInt());
ui->txtNull->setText(Settings::getValue("databrowser", "null_text").toString());
ui->txtBlob->setText(Settings::getValue("databrowser", "blob_text").toString());
ui->editFilterEscape->setText(Settings::getValue("databrowser", "filter_escape").toString());
ui->spinFilterDelay->setValue(Settings::getValue("databrowser", "filter_delay").toInt());
@@ -195,6 +196,7 @@ void PreferencesDialog::saveSettings()
saveColorSetting(ui->fr_bin_bg, "bin_bg");
Settings::setValue("databrowser", "symbol_limit", ui->spinSymbolLimit->value());
Settings::setValue("databrowser", "null_text", ui->txtNull->text());
Settings::setValue("databrowser", "blob_text", ui->txtBlob->text());
Settings::setValue("databrowser", "filter_escape", ui->editFilterEscape->text());
Settings::setValue("databrowser", "filter_delay", ui->spinFilterDelay->value());
@@ -317,9 +319,7 @@ bool PreferencesDialog::eventFilter(QObject *obj, QEvent *event)
if (colour.isValid())
{
QPalette palette = frame->palette();
palette.setColor(frame->backgroundRole(), colour);
frame->setPalette(palette);
setColorSetting(frame, colour);
}
// Consume
return true;
@@ -413,10 +413,43 @@ void PreferencesDialog::fillLanguageBox()
void PreferencesDialog::loadColorSetting(QFrame *frame, const QString & settingName)
{
QColor color = QColor(Settings::getValue("databrowser", settingName + "_colour").toString());
setColorSetting(frame, color);
}
void PreferencesDialog::setColorSetting(QFrame *frame, const QColor &color)
{
QPalette::ColorRole role;
QLineEdit *line;
if (frame == ui->fr_bin_bg) {
line = ui->txtBlob;
role = line->backgroundRole();
} else if (frame == ui->fr_bin_fg) {
line = ui->txtBlob;
role = line->foregroundRole();
} else if (frame == ui->fr_reg_bg) {
line = ui->txtRegular;
role = line->backgroundRole();
} else if (frame == ui->fr_reg_fg) {
line = ui->txtRegular;
role = line->foregroundRole();
} else if (frame == ui->fr_null_bg) {
line = ui->txtNull;
role = line->backgroundRole();
} else if (frame == ui->fr_null_fg) {
line = ui->txtNull;
role = line->foregroundRole();
} else
return;
QPalette palette = frame->palette();
palette.setColor(frame->backgroundRole(),
QColor(Settings::getValue("databrowser", settingName + "_colour").toString()));
palette.setColor(frame->backgroundRole(), color);
frame->setPalette(palette);
palette = line->palette();
palette.setColor(role, color);
line->setPalette(palette);
}
void PreferencesDialog::saveColorSetting(QFrame *frame, const QString & settingName)

View File

@@ -40,6 +40,7 @@ private:
void fillLanguageBox();
void loadColorSetting(QFrame *frame, const QString &name);
void setColorSetting(QFrame *frame, const QColor &color);
void saveColorSetting(QFrame *frame, const QString &name);
void addClientCertToTable(const QString& path, const QSslCertificate& cert);

View File

@@ -226,12 +226,6 @@
<property name="fieldGrowthPolicy">
<enum>QFormLayout::FieldsStayAtSizeHint</enum>
</property>
<property name="labelAlignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="formAlignment">
<set>Qt::AlignHCenter|Qt::AlignTop</set>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
@@ -287,7 +281,11 @@
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="checkHideSchemaLinebreaks"/>
<widget class="QCheckBox" name="checkHideSchemaLinebreaks">
<property name="text">
<string>enabled</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_2">
@@ -427,6 +425,9 @@
<property name="text">
<string>Symbol limit in cell</string>
</property>
<property name="buddy">
<cstring>spinSymbolLimit</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
@@ -449,46 +450,34 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>NULL fields</string>
<string>Field display</string>
</property>
<layout class="QFormLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QLineEdit" name="txtNull">
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="3">
<widget class="QLabel" name="label_12">
<property name="text">
<string notr="true"/>
</property>
<property name="maxLength">
<number>15</number>
<string>Displayed &amp;text</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>&amp;Text</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>txtNull</cstring>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Field colors</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="3" column="0">
<widget class="QLabel" name="lb_binary">
<property name="text">
<string>Binary</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lb_null">
<property name="text">
@@ -509,13 +498,6 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_16">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QFrame" name="fr_reg_fg">
<property name="focusPolicy">
@@ -535,23 +517,13 @@
<item row="0" column="1">
<widget class="QLabel" name="lb_text">
<property name="text">
<string>Text</string>
<string>Text color</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lb_binary">
<property name="text">
<string>Binary</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QFrame" name="fr_null_fg">
<property name="focusPolicy">
@@ -571,7 +543,7 @@
<item row="0" column="2">
<widget class="QLabel" name="lb_background">
<property name="text">
<string>Background</string>
<string>Background color</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
@@ -642,6 +614,66 @@
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QLineEdit" name="txtNull">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string notr="true">NULL</string>
</property>
</widget>
</item>
<item row="4" column="3">
<widget class="QLineEdit" name="txtRegular">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<italic>false</italic>
</font>
</property>
<property name="text">
<string notr="true">Preview only (N/A)</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QLineEdit" name="txtBlob">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string notr="true">BLOB</string>
</property>
<property name="readOnly">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@@ -1302,6 +1334,7 @@
<tabstop>locationEdit</tabstop>
<tabstop>setLocationButton</tabstop>
<tabstop>languageComboBox</tabstop>
<tabstop>toolbarStyleComboBox</tabstop>
<tabstop>checkUseRemotes</tabstop>
<tabstop>checkUpdates</tabstop>
<tabstop>encodingComboBox</tabstop>
@@ -1313,14 +1346,15 @@
<tabstop>editDatabaseDefaultSqlText</tabstop>
<tabstop>comboDataBrowserFont</tabstop>
<tabstop>spinDataBrowserFontSize</tabstop>
<tabstop>spinSymbolLimit</tabstop>
<tabstop>txtNull</tabstop>
<tabstop>fr_null_fg</tabstop>
<tabstop>fr_null_bg</tabstop>
<tabstop>txtNull</tabstop>
<tabstop>fr_bin_fg</tabstop>
<tabstop>fr_bin_bg</tabstop>
<tabstop>txtBlob</tabstop>
<tabstop>fr_reg_fg</tabstop>
<tabstop>fr_reg_bg</tabstop>
<tabstop>txtRegular</tabstop>
<tabstop>spinFilterDelay</tabstop>
<tabstop>editFilterEscape</tabstop>
<tabstop>treeSyntaxHighlighting</tabstop>

View File

@@ -176,6 +176,8 @@ QVariant Settings::getDefaultValue(const QString& group, const QString& name)
return false;
if(name == "null_text")
return "NULL";
if(name == "blob_text")
return "BLOB";
if(name == "filter_escape")
return "\\";
if(name == "filter_delay")

View File

@@ -258,7 +258,7 @@ QVariant SqliteTableModel::data(const QModelIndex &index, int role) const
{
return Settings::getValue("databrowser", "null_text").toString();
} else if(role == Qt::DisplayRole && isBinary(index)) {
return "BLOB";
return Settings::getValue("databrowser", "blob_text").toString();
} else if(role == Qt::DisplayRole) {
int limit = Settings::getValue("databrowser", "symbol_limit").toInt();
QByteArray displayText = m_data.at(index.row()).at(index.column());