mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 11:00:44 -06:00
preferencesdialog: Add NULL fields style options to Data Browser tab
This adds the ability to customize the text, font colour and background colour of NULL fields.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <QFileDialog>
|
||||
#include <QColorDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QKeyEvent>
|
||||
|
||||
QHash<QString, QVariant> PreferencesDialog::m_hCache;
|
||||
|
||||
@@ -17,6 +18,9 @@ PreferencesDialog::PreferencesDialog(QWidget* parent)
|
||||
ui->setupUi(this);
|
||||
ui->treeSyntaxHighlighting->setColumnHidden(0, true);
|
||||
|
||||
ui->frameNullBgColour->installEventFilter(this);
|
||||
ui->frameNullFgColour->installEventFilter(this);
|
||||
|
||||
#ifndef CHECKNEWVERSION
|
||||
ui->labelUpdates->setVisible(false);
|
||||
ui->checkUpdates->setVisible(false);
|
||||
@@ -54,6 +58,18 @@ void PreferencesDialog::loadSettings()
|
||||
ui->foreignKeysCheckBox->setChecked(getSettingsValue("db", "foreignkeys").toBool());
|
||||
ui->spinPrefetchSize->setValue(getSettingsValue("db", "prefetchsize").toInt());
|
||||
|
||||
QPalette palette = ui->frameNullBgColour->palette();
|
||||
palette.setColor(ui->frameNullBgColour->backgroundRole(),
|
||||
QColor(getSettingsValue("databrowser", "null_bg_colour").toString()));
|
||||
ui->frameNullBgColour->setPalette(palette);
|
||||
|
||||
palette = ui->frameNullFgColour->palette();
|
||||
palette.setColor(ui->frameNullFgColour->backgroundRole(),
|
||||
QColor(getSettingsValue("databrowser", "null_fg_colour").toString()));
|
||||
ui->frameNullFgColour->setPalette(palette);
|
||||
|
||||
ui->txtNull->setText(getSettingsValue("databrowser", "null_text").toString());
|
||||
|
||||
for(int i=0; i < ui->treeSyntaxHighlighting->topLevelItemCount(); ++i)
|
||||
{
|
||||
QString name = ui->treeSyntaxHighlighting->topLevelItem(i)->text(0);
|
||||
@@ -86,6 +102,12 @@ void PreferencesDialog::saveSettings()
|
||||
|
||||
setSettingsValue("checkversion", "enabled", ui->checkUpdates->isChecked());
|
||||
|
||||
setSettingsValue("databrowser", "null_bg_colour",
|
||||
ui->frameNullBgColour->palette().color(ui->frameNullBgColour->backgroundRole()));
|
||||
setSettingsValue("databrowser", "null_fg_colour",
|
||||
ui->frameNullFgColour->palette().color(ui->frameNullFgColour->backgroundRole()));
|
||||
setSettingsValue("databrowser", "null_text", ui->txtNull->text());
|
||||
|
||||
for(int i=0; i < ui->treeSyntaxHighlighting->topLevelItemCount(); ++i)
|
||||
{
|
||||
QString name = ui->treeSyntaxHighlighting->topLevelItem(i)->text(0);
|
||||
@@ -190,6 +212,17 @@ QVariant PreferencesDialog::getSettingsDefaultValue(const QString& group, const
|
||||
if(group == "checkversion" && name == "enabled")
|
||||
return true;
|
||||
|
||||
// Data Browser/NULL Fields
|
||||
if(group == "databrowser")
|
||||
{
|
||||
if (name == "null_text")
|
||||
return "NULL";
|
||||
if (name == "null_fg_colour")
|
||||
return QColor(Qt::lightGray).name();
|
||||
if (name == "null_bg_colour")
|
||||
return QColor(Qt::white).name();
|
||||
}
|
||||
|
||||
// syntaxhighlighter?
|
||||
if(group == "syntaxhighlighter")
|
||||
{
|
||||
@@ -255,6 +288,44 @@ void PreferencesDialog::showColourDialog(QTreeWidgetItem* item, int column)
|
||||
}
|
||||
}
|
||||
|
||||
bool PreferencesDialog::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
// Use mouse click and enter press on the frames to pop up a colour dialog
|
||||
if (obj == ui->frameNullBgColour || obj == ui->frameNullFgColour)
|
||||
{
|
||||
if (event->type() == QEvent::KeyPress)
|
||||
{
|
||||
QKeyEvent *key = static_cast<QKeyEvent *>(event);
|
||||
// Not interesting, so send to the parent (might be shortcuts)
|
||||
if((key->key() != Qt::Key_Enter) && (key->key() != Qt::Key_Return))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (event->type() != QEvent::MouseButtonPress)
|
||||
{
|
||||
// Not a key event neither a mouse event, send to the parent
|
||||
return false;
|
||||
}
|
||||
|
||||
QFrame *frame = qobject_cast<QFrame *>(obj);
|
||||
QColor oldColour = frame->palette().color(frame->backgroundRole());
|
||||
QColor colour = QColorDialog::getColor(oldColour, frame);
|
||||
|
||||
if (colour.isValid())
|
||||
{
|
||||
QPalette palette = frame->palette();
|
||||
palette.setColor(frame->backgroundRole(), colour);
|
||||
frame->setPalette(palette);
|
||||
}
|
||||
// Consume
|
||||
return true;
|
||||
}
|
||||
|
||||
// Send any other events to the parent
|
||||
return QDialog::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
void PreferencesDialog::addExtension()
|
||||
{
|
||||
QString file = QFileDialog::getOpenFileName(
|
||||
|
||||
@@ -38,10 +38,13 @@ private:
|
||||
// This works similar to getSettingsValue but returns the default value instead of the value set by the user
|
||||
static QVariant getSettingsDefaultValue(const QString& group, const QString& name);
|
||||
|
||||
void fillLanguageBox();
|
||||
|
||||
// Cache for storing the settings to avoid repeatedly reading the settings file all the time
|
||||
static QHash<QString, QVariant> m_hCache;
|
||||
|
||||
void fillLanguageBox();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -228,6 +228,179 @@
|
||||
<attribute name="title">
|
||||
<string>Data &Browser</string>
|
||||
</attribute>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="autoFillBackground">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QGroupBox {
|
||||
border: 1px solid gray;
|
||||
border-radius: 4px;
|
||||
margin-top: 1ex;
|
||||
}
|
||||
|
||||
QGroupBox::title {
|
||||
subcontrol-origin: margin;
|
||||
subcontrol-position: top left;
|
||||
left: 10px;
|
||||
padding: 0 3px 0 3px;
|
||||
}</string>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>NULL fields</string>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>50</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>50</number>
|
||||
</property>
|
||||
<item row="1" column="1">
|
||||
<widget class="QFrame" name="frameNullFgColour">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>70</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Box</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="txtNull">
|
||||
<property name="text">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="maxLength">
|
||||
<number>15</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QFrame" name="frameNullBgColour">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>70</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Box</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_10">
|
||||
<property name="text">
|
||||
<string>Text &colour</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>frameNullFgColour</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_12">
|
||||
<property name="text">
|
||||
<string>&Text</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>txtNull</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_11">
|
||||
<property name="text">
|
||||
<string>Bac&kground colour</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>frameNullBgColour</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
@@ -530,6 +703,9 @@
|
||||
<tabstop>foreignKeysCheckBox</tabstop>
|
||||
<tabstop>checkHideSchemaLinebreaks</tabstop>
|
||||
<tabstop>spinPrefetchSize</tabstop>
|
||||
<tabstop>txtNull</tabstop>
|
||||
<tabstop>frameNullFgColour</tabstop>
|
||||
<tabstop>frameNullBgColour</tabstop>
|
||||
<tabstop>treeSyntaxHighlighting</tabstop>
|
||||
<tabstop>spinEditorFontSize</tabstop>
|
||||
<tabstop>spinLogFontSize</tabstop>
|
||||
|
||||
@@ -231,6 +231,8 @@ QVariant SqliteTableModel::data(const QModelIndex &index, int role) const
|
||||
|
||||
if(role == Qt::DisplayRole && isBinary(index))
|
||||
return "BLOB";
|
||||
else if(m_data.at(index.row()).at(index.column()).isNull() || isBinary(index))
|
||||
return PreferencesDialog::getSettingsValue("databrowser", "null_text").toString();
|
||||
else
|
||||
return m_data.at(index.row()).at(index.column());
|
||||
} else if(role == Qt::FontRole) {
|
||||
@@ -240,11 +242,11 @@ QVariant SqliteTableModel::data(const QModelIndex &index, int role) const
|
||||
return font;
|
||||
} else if(role == Qt::TextColorRole) {
|
||||
if(m_data.at(index.row()).at(index.column()).isNull() || isBinary(index))
|
||||
return QColor(Qt::gray);
|
||||
return QColor(Qt::black);
|
||||
return QColor(PreferencesDialog::getSettingsValue("databrowser", "null_fg_colour").toString());
|
||||
return QVariant();
|
||||
} else if (role == Qt::BackgroundRole) {
|
||||
if(m_data.at(index.row()).at(index.column()).isNull() || isBinary(index))
|
||||
return QColor(PreferencesDialog::getSettingsValue("syntaxhighlighter", "null_colour").toString());
|
||||
return QColor(PreferencesDialog::getSettingsValue("databrowser", "null_bg_colour").toString());
|
||||
return QVariant();
|
||||
} else {
|
||||
return QVariant();
|
||||
|
||||
Reference in New Issue
Block a user