Lazarus

Programming => LCL => Topic started by: inferno on February 19, 2020, 12:10:22 am

Title: removing sort indicator in TStringGrid
Post by: inferno on February 19, 2020, 12:10:22 am
Hi all,
I use TStringGrid with allowed columns sorting and row moving (macOS Mojave 10.14.6 + Cocoa). When some column is first sorted and then the rows are moved, the column has no right order and the sorting indicator (default green arrows or some icons when used TitleImageList, ImageIndexSortAsc and ImageIndexSortDesc) should be removed. Have no idea to to do this. Assigning StringGrid.Columns.Title.ImageIndex:=-1; doesn't work - this value is equal -1 for all columns including the sorted one. Any suggestions?

Best regards,
Inferno
Title: Re: removing sort indicator in TStringGrid
Post by: GAN on February 19, 2020, 12:55:30 am
Recently discussed in this thread: https://forum.lazarus.freepascal.org/index.php/topic,48340.0.html (https://forum.lazarus.freepascal.org/index.php/topic,48340.0.html)
Title: Re: removing sort indicator in TStringGrid
Post by: inferno on February 19, 2020, 01:25:06 am
GAN,
Thank you for the suggestion, but I found this thread before posting and unfortunately this is not a solution in my case. As I mentioned, assigning StringGrid.Columns.Title.ImageIndex:=-1 doesn't work at all. Another sugestion TStringGrid.ColumnClickSort := False is a solution only when you want to completely disable sorting. My case is different: columns sorting is allowed, but sometimes user can disturb the order by row moving (also allowed by goRowMoving:=true). In this case sorting icon should be hidden because column is no longer sorted. But when user after moving rows again click in some column header, sorting should be activated and sort indicator should be displayed again according to sort order.

In other words, I need a solution to temporary hide sort indicator until next sort task.

Best regards,
Inferno
Title: Re: removing sort indicator in TStringGrid
Post by: winni on February 19, 2020, 01:31:43 am
Hi!

Do the drawing of the cells on your own:

Set DefaultDrawing to false.

Create OnDrawCell.

No you can draw in row zero every icon you like. But you must keep track of it.

Winni

Title: Re: removing sort indicator in TStringGrid
Post by: wp on February 19, 2020, 07:24:26 am
I added a public method "HideSortArrow" in r62644.

If you do not use Lazarus trunk you can patch your current version easily:
Code: Pascal  [Select][+][-]
  1. procedure HideSortArrow;
Code: Pascal  [Select][+][-]
  1. procedure TCustomGrid.HideSortArrow;
  2. begin
  3.   FSortColumn := -1;
  4.   InvalidateGrid;
  5. end;
In principle this method should be called whenever rows are rearranged in a sorted grid. The place where this should happen is procedure ColRowModed, but I am not 100% sure if this has any side-effects. Therefore, you must call HideSortArrow yourself in the OnColRowMoved method.
Title: Re: removing sort indicator in TStringGrid
Post by: inferno on February 20, 2020, 01:13:02 am
Thank you for suggestions! It looks the solution with adding HideSortArrow to TCustomGrid works well, no side-effects until now. But I hope it will be implemented directly in TCustomGrid as there are many cases where sorting order can be changed. It is definitely something that was missed during sorting implementation.

Best regards,
Inferno
Title: Re: removing sort indicator in TStringGrid
Post by: wp on February 23, 2020, 01:02:09 pm
I now changed the grid's internal method DoOPMoveColRow to remove the sort arrow when a row is moved in a column-sorted grid without user code. I think it works correctly, but please test yourself and report back.

To implement the change in a non-trunk Lazarus version do this:
Code: Pascal  [Select][+][-]
  1.   // adjust sorted column
  2.   if IsColumn and (FSortColumn>=0) then begin       // "begin" added
  3.     if Between(FSortColumn, FromIndex, ToIndex) then begin  
  4.       if FSortColumn=FromIndex then
  5.         FSortColumn := ToIndex
  6.       else
  7.       if FromIndex<FSortColumn then
  8.         Dec(FSortColumn)
  9.       else
  10.         Inc(FSortColumn);
  11.     end;
  12.   end else                // added
  13.     FSortColumn := -1;    // added
                 
Title: Re: removing sort indicator in TStringGrid
Post by: inferno on February 26, 2020, 07:36:01 pm
Hi wp,
Thank you for the update! I checked your solution and it looks it works properly. I thought about such approach (removing sort indicator automatically without invoking dedicated method after any row movement) but probably this could be not expected behaviour in each scenario. Not each movement operation disrupt sort order. For example if you have sorted field with values:

bananas
bananas
oranges
strawberries
tomatoes

and make row movement between first two rows, the sort order will be kept and removing sort indicator is not necessary.

Also I think to be consistent the same modification should be done in TCustomGrid.DoOPExchangeColRow. There is method ExchangeColRow and using it somewhere in the code can cause sort order disruption, so the sort icon should be removed also in this case. But on the other hand ExchangeColRow method is used by the grid during sorting, so it could be not as easy to implement as with MoveColRow method.

So I think that using dedicated method for removing the sort indicator is enough and is more flexible.

BTW Do you have idea how to use the sort indicators in higher resolutions than 16x16 (icons with higher resolution are not scaled)? I develop on macOS with Retina display and such icons looks very poor comparing to the rest of Cocoa GUI which is very sharp. The same issue have with TTrayIcon.

Best regards,
Inferno
Title: Re: removing sort indicator in TStringGrid
Post by: wp on February 26, 2020, 11:57:00 pm
Sounds reasonable. Reverted the change.

Regarding the sort indicator: Which Lazarus version are you using? I checked v2.0.6 and it does contain the high-resolution imagelist for the grids unit.

If you do have v2.0.6 or trunk what happens with the sort indicator when you change the TitleStyle of the grid?
Title: Re: removing sort indicator in TStringGrid
Post by: inferno on April 13, 2020, 04:37:15 pm
Hi,
I use Typhon IDE. Changing TitleStyle doesn't help - tried all three setttings. Image List contains high resolution icons but they are converted to default resolution 16x16 in the grid.

Best regards,
Inferno
Title: Re: removing sort indicator in TStringGrid
Post by: wp on April 13, 2020, 04:57:24 pm
Then ask in the CodeTyphon forum. I have neither an idea nor influence on what they are doing.
Title: Re: removing sort indicator in TStringGrid
Post by: inferno on April 13, 2020, 05:14:33 pm
Hi wp,
I expect mostly they are just port the code without any changes...

Best regards,
Inferno
Title: Re: removing sort indicator in TStringGrid
Post by: wp on April 13, 2020, 05:46:38 pm
At least they remove the name "Lazarus" everywhere and replace it by their own...

But anyway: I just checked your report on a Windows running at 144ppi, and the custom sort images are correctly scaled. Did you set the Scaled property of the Imagelist to true?
Title: Re: removing sort indicator in TStringGrid
Post by: inferno on April 13, 2020, 11:13:09 pm
That's it, thank you wp! I knew it must be something easy to fix. It was confusing that regarless of icon size the ImageList always displayed the resized version 16x16.

How about TTrayIcon - do you have any idea how to add scaled icon? In this case there is no ImageList and icon is not resized or scaled. If you add 16x16 it is fully displayed, if the icon resolution is higher only the part of the picture is displayed.

Regarding Typhon - you are right, they should keep the origin of source codes. I suppose they have ambitions to provide full-featured multiplatform IDE with as many components as possible and with homogenus source codes tracked myself. On the other hand they provide it to everybody for free and each Typhon user is fully aware that it comes from Lazarus and is based on hard work of the Lazarus community. In my opinion it is better choice for macOS.

Best regards,
Inferno
Title: Re: removing sort indicator in TStringGrid
Post by: wp on April 14, 2020, 12:20:51 am
I am not very familiar with TTrayIcon. Maybe it's best if you post a report in bug tracker. Add a simple demo showing the issue.
Title: Re: removing sort indicator in TStringGrid
Post by: mdalacu on December 07, 2021, 11:52:41 am
Hi, in Lazarus 2.0.12 the method HideSortArrow is still missing. Why?
Thank you.
Title: Re: removing sort indicator in TStringGrid
Post by: dsiders on December 07, 2021, 04:35:38 pm
Hi, in Lazarus 2.0.12 the method HideSortArrow is still missing. Why?
Thank you.

Are you using the main branch? We haven't seen an official 2.2 release yet.
Title: Re: removing sort indicator in TStringGrid
Post by: wp on December 07, 2021, 05:09:02 pm
Hi, in Lazarus 2.0.12 the method HideSortArrow is still missing. Why?
Thank you.
Read the upper posts, and you'll see that there were incompatibilities, and thus it was removed again.

The HideSortArrow method is available in Laz2.2RC2 and Laz/main. Since all the Laz 2.0.x versions are bug fix releases, but the HideSortArrow method is a new feature, it cannot be integrated into v2.0.12.
Title: Re: removing sort indicator in TStringGrid
Post by: mdalacu on December 07, 2021, 08:50:26 pm
Thanks!
So i will wait for 2.2, until then...resort!  ;)
TinyPortal © 2005-2018