wxWidgets / wxWidgets

Cross-Platform C++ GUI Library
https://www.wxwidgets.org/
6.05k stars 1.76k forks source link

Incorrect updating of wxGrid when sorting rows using the SetRowPos function #24303

Closed alexkd11 closed 4 months ago

alexkd11 commented 7 months ago

Description

My issue #2525 from wxPython was forwarded to you. This is a problem in wxWidgets' 3.2.0 (used in wxPython 4.2.0)

Bug description:

To sort table rows by a selected column, I make a list of column values and rearrange row positions (SetRowPos) using the sorted list. When sorting in ascending order everything works well, but when sorting in descending order further redraws of the table truncate it (and the ability to scroll lower with the scroller) to the former last row (the row with the highest ID). Repeated direct sort restores the table's functionality. Dragging the last line to the beginning with the mouse also leads to the same problems. However, there is no similar problem for rearranging columns. I assume that when redrawing, the calculation is carried out from the line with the largest ID, not the lines with the new last position.. Code analysis showed that the problem is probably just in wxWidgets. In file wxWidgets/src/generic /grid.cpp in function void wxGrid::CalcDimensions()

// compute the size of the scrollable area
int w = m_numCols > 0 ? GetColRight(GetColAt(m_numCols - 1)) : 0;
int h = m_numRows > 0 ? GetRowBottom(m_numRows - 1) : 0;

The last line should probably also have GetRowBottom(GetRowAt(m_numRows - 1))

Platform and version information

DietmarSchwertberger commented 7 months ago

I could not reproduce your problem, but I see that the size calculation fails when I reorder the lines and resize one to trigger a re-calculation. Your proposed change fixes it. The question is whether there are more similar locations... Anyway, I will can submit a PR or you could do that yourself.

alexkd11 commented 7 months ago

I can try to fix it myself (locally), rebuild it according to the description, check this change, but test it only under Windows in a Python program (wxPython). Will this be enough?

DietmarSchwertberger commented 7 months ago

Yes, but I have tested already, so the main part is the pull request itself. If you have cloned the repository on GitHub to your account and then to your PC, then you can easily create a new branch, commit and upload the modification. Then GitHub will offer you to create a pull request. If you have never done so and don't plan to contribute more often, then I can do the PR.