Bug 150448

Summary: Preview using Conditional Formatting has weird behavior when multiple cells are selected
Product: LibreOffice Reporter: Rafael Lima <rafael.palma.lima>
Component: CalcAssignee: Not Assigned <libreoffice-bugs>
Status: NEW ---    
Severity: enhancement CC: heiko.tietze
Priority: medium    
Version: 7.3.5.2 release   
Hardware: All   
OS: All   
See Also: https://bugs.documentfoundation.org/show_bug.cgi?id=150271
Whiteboard:
Crash report or crash signature: Regression By:
Bug Depends on:    
Bug Blocks: 87351    
Attachments: Screenshots showing the problem

Description Rafael Lima 2022-08-16 17:53:59 UTC
Created attachment 181815 [details]
Screenshots showing the problem

I have a sheet with a column (see Column D in the screenshot) where values are either "F" or "P" and I would like to format cells based on their values so that cells with "P" are formatted with the "Good" style.

So I select the cells and go to "Format - Conditional - Condition" and apply a conditional formatting so that cells "equal to" "P" receive the "Good" style.

The formatting itself works as expected, but the preview box shows weird content (again, see attached image). Notice that the preview has the values "P P P P F P P P F P ..." as though a single string was being formatted. What's more, "P"s and "F"s are marked as green in the preview, which is weird because I'm only formatting cells with "P". Cells with "F" should remain white.

In summary, we could improve this preview. I'm still unsure what strategy we should take, but here are some options:

1) We could have a default preview value, with generic text or number (or a default value depending on the "Number Format" chosen for the style) to which the style can be applied in the preview

2) We could use the contents of the first matching cell to serve as sample in the preview. The only problem is if there's no matching cell to use as sample.

3) We could use strategy (2) above and if no matching value is found, then we use (1)

System info

Version: 7.3.5.2 / LibreOffice Community
Build ID: 30(Build:2)
CPU threads: 12; OS: Linux 5.15; UI render: default; VCL: kf5 (cairo+xcb)
Locale: pt-BR (pt_BR.UTF-8); UI: en-US
Ubuntu package version: 1:7.3.5-0ubuntu0.22.04.1
Calc: threaded
Comment 1 Heiko Tietze 2022-08-17 06:56:37 UTC
Apparently, the preview picks up the content from all selection. If you define the CF for a single cell, which is rarely useful, only this value is shown. If the CF applies to the whole column it centers the data.

Showing the single "F" and "P" make sense in this example but has limits. For example Cell value > 10 could be any large number. We are probably better off with a static text like "42", "Sample", or "Preview" (the strings could be localized).
Comment 2 Heiko Tietze 2022-08-26 08:00:36 UTC
We discussed the topic at the design meeting and recommend to use the static text "This is a preview".

Code pointer might be sc/source/ui/condformat/condformatdlg.cxx => ScCondFormatList and ScCondFrmtEntry