Initial implementation of "conditional formatting" by mgrojo · Pull Request #1503 · sqlitebrowser/sqlitebrowser

I find useful for visual data analysis to have some "highlighting mechanism" of certain values. This feature is a little sister of the "conditional formatting" found in spreadsheets, but it's quick and simple, in the same spirit as our plot dock or our filters. Maybe it is a bit complacent(?) to call this "conditional formatting" (only background can be changed). It could be renamed to conditional highlighting or something similar if preferred, since I don't see a great benefit in including other formatting possibilities. But at the same time, "conditional formatting" is already familiar and does not close the door for future expansion if people demand it.

I'm not sure if I'm going to develop further this functionality and I don't want also to delay our highly anticipated 3.11 release, but I'd like to open this pull request so the functionality and the associated code can receive user comments and developer review.

Description from the commit

After setting a filter, the user can select from the context menu in the
filter line a new option "Use for Conditional Format", that assigns
automatically a colour to the background of cells fulfilling that
condition.

The formatting is preserved after the user has removed the filter. Several
conditional formats can be successively added to a column using different
filters.

The conditional formats of a column can be cleared when the filter is empty
selecting "Clear All Conditional Formats" from the filter line context
menu.

The conditional formats are saved and loaded in project files as other
browse table settings.

A new class Palette has been added for reusing the automatic colour
assignment of the Plot Dock. It takes into account the theme kind of the
application (dark, light) for the colour selection.

A new class CondFormat for using the conditional formatting settings from
several classes. The conversion of a filter string from our format to an
SQL condition has been moved here for reuse in filters and conditional
formatting.

Whether the conditional format applies is resolved by SQLite, so filters
and conditional formats give the same exact results.

Code for getting a pragma value has been reused for getting the condition
result, and consequently renamed to selectSingleCell.

Possible future improvements

  • New dialog for editing the conditional formatting (at least colour and
    application order of conditions, but maybe too: adding new conditions and
    editing the condition itself).
  • Icon for the menu entry. Maybe http://www.famfamfam.com/lab/icons/silk/icons/color_swatch.png
  • Full formatting possibilities (foreground and font modifiers).

Showcase of the functionality

Demo project with some formats loaded:
imagen

Let's clear formats in a column:

imagen

Let's add a new format. Write the filter and then select the "Use for Conditional Formatting"

imagen

A new background colour is automatically selected for this conditional format.

imagen

The format is already applied and persist when the filter is cleared.

imagen

If the current settings are saved in a project file, it can be restored if loaded.

Some more comments

Suggestions for the wording of labels is welcome.

The 3.11 release has no need to wait for this pull request, of course.