wxGrid scrolling refresh problem with merged cells  [SOLVED]

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
andrewc
Earned a small fee
Earned a small fee
Posts: 11
Joined: Mon Sep 01, 2014 11:47 am

wxGrid scrolling refresh problem with merged cells

Postby andrewc » Fri Jul 13, 2018 11:18 am

Hi all,

I'm using wxWidgets 3.0.2 on Windows 7.

I have a C++ application that has a potentially very large spreadsheet-style grid. I'm in the process of recoding the handling of attributes as I was having serious performance issues when the 18-column grid held several thousand rows—it was taking up to one minute for the initial display. In the previous implementation I was just using the SetBackgroundColour, SetTextColour and SetCellSize methods on the wxGrid-derived object directly, and despite the slowness, all looked OK.

My new approach has been to derive my own class from wxGridTableBase and to override the GetAttr method directly on that. Initial display is massively faster—down from 1 minute to 0.2 seconds—and everything looks fine at the moment it becomes visible. However, when I scroll the table, I'm having a problem that I didn't have before, which is that cells that should be covered by other cells for which a multi-row size has been set are showing through.

In the screenshots below I've coloured my normal light-grey table background a garish cyan so you can see what's going on. Basically, I have a set of attributes for empty cells which are defined as follows:

Code: Select all

m_emptyAttr = new wxGridCellAttr();
m_emptyAttr->SetBackgroundColour(m_backgroundColour);
m_emptyAttr->SetOverflow(false);
m_emptyAttr->SetReadOnly(true);


The cells which should be on top in the first 5 columns, but aren't, use wxGridCellAttr objects that are defined in various ways (not easy to extract brief code), but have had their text colour, background colour and size (rows, cols) set, along with SetOverflow(false) and SetReadOnly(true) as above.

The screenshots show the initial appearance, and then what happens if I scroll down and up again.

Before scrolling
g1.png


After scrolling down and back up
g2.png


Any ideas what I might be missing or doing wrong? Happy to provide more details if I've missed something important.

Many thanks,
Andrew

User avatar
doublemax
Moderator
Moderator
Posts: 12818
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxGrid scrolling refresh problem with merged cells

Postby doublemax » Fri Jul 13, 2018 12:11 pm

The cell size is part of wxGridCellAttr, so i guess that information gets lost in your implementation of GetAttr().
Use the source, Luke!

andrewc
Earned a small fee
Earned a small fee
Posts: 11
Joined: Mon Sep 01, 2014 11:47 am

Re: wxGrid scrolling refresh problem with merged cells

Postby andrewc » Fri Jul 13, 2018 6:32 pm

Hi doublemax

Could you elaborate a bit, please? I know the cell size is part of wxGridCellAttr as I am setting it. How might it "get lost" between initial display—which is just fine—and scrolling, when other features such as the background colour and alignment survive just fine? The cell size is just a couple of integers, so its not as if any pointers are becoming invalid.

Thanks,
Andrew

User avatar
doublemax
Moderator
Moderator
Posts: 12818
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxGrid scrolling refresh problem with merged cells

Postby doublemax » Fri Jul 13, 2018 6:53 pm

Could you elaborate a bit, please?
No, as it was only a wild guess.

Is it really a display error or just a redraw issue? I.e. when you have the "bad" case and force a redraw, e.g. by moving a window from another application over the grid, does it fix itself or does it stay wrong?
Use the source, Luke!

andrewc
Earned a small fee
Earned a small fee
Posts: 11
Joined: Mon Sep 01, 2014 11:47 am

Re: wxGrid scrolling refresh problem with merged cells

Postby andrewc » Fri Jul 13, 2018 9:41 pm

It's a redraw issue. Fixes itself if I minimize and maximize the window. Should have mentioned that, sorry. The point really is that it was fine but slow with my original method, which suggests there ought to be some way to make it work with the more efficient approach.

Andrew

User avatar
doublemax
Moderator
Moderator
Posts: 12818
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxGrid scrolling refresh problem with merged cells

Postby doublemax » Fri Jul 13, 2018 10:18 pm

Honestly, i have no idea how these two things could be related.
Use the source, Luke!

andrewc
Earned a small fee
Earned a small fee
Posts: 11
Joined: Mon Sep 01, 2014 11:47 am

Re: wxGrid scrolling refresh problem with merged cells

Postby andrewc » Sun Jul 15, 2018 6:28 am

Not sure which specific "two things" you are referring to there, but never mind. Thanks for your time.

andrewc
Earned a small fee
Earned a small fee
Posts: 11
Joined: Mon Sep 01, 2014 11:47 am

Re: wxGrid scrolling refresh problem with merged cells

Postby andrewc » Sun Jul 15, 2018 7:14 am

So, having gone and read the source code for wxGrid::SetCellSize, wxGrid::DrawGridCellArea and wxGridCellAttr::SetSize it would seem that this comment in the last of those three functions may hold the key:
If this cell is larger (2,2) then this is the top left cell
the other cells that will be covered (lower right cells) must be
set to negative or zero values such that
row + num_rows of the covered cell points to the larger cell (this cell)
same goes for the col + num_cols.

It's a shame that that crucial bit of information didn't make it through into the online documentation anywhere.

So anyway, I presume that my wxGridTableBase::GetAttr override is going to have to reproduce what wxGrid::SetCellSize does to set the zero or negative offsets back to the main merged cell, and cache a whole load more wxGridCellAttr objects in order to maintain the efficiency. I will try that when I'm back at work tomorrow and report on the outcome.

In general I've found the wxGrid documentation to be fine for telling you what the default implementations do, but really rather poor at telling you how to override them.

Andrew

andrewc
Earned a small fee
Earned a small fee
Posts: 11
Joined: Mon Sep 01, 2014 11:47 am

Re: wxGrid scrolling refresh problem with merged cells  [SOLVED]

Postby andrewc » Mon Jul 16, 2018 8:43 am

Returning wxGridCellAttr objects with zero / negative sizes for the covered cells did the trick. All works OK now.

Andrew


Return to “C++ Development”

Who is online

Users browsing this forum: Emerald2240 and 28 guests