New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP][RFC] Sort unused cylinders to the end of cylinder list #890
[WIP][RFC] Sort unused cylinders to the end of cylinder list #890
Conversation
No idea regarding the tests. But one other important point: Ok, this is clearly an RFC item... |
qt-models/cylindermodel.cpp
Outdated
if (rows > 0) { | ||
beginInsertRows(QModelIndex(), 0, rows - 1); | ||
endInsertRows(); | ||
} | ||
if (current_dive) | ||
copy_dive(&displayed_dive, current_dive); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has a few interesting side effects that I'm not sure you want.
The idea is that the displayed_dive is what you see, the current_dive is what's in our data storage.
So at any time a partial edit could be active that hasn't been accepted, yet. So no, please don't do that.
As for the test failure... the GitStorage test is especially sensitive to race conditions. If anyone, anywhere else is running that test at the same time, or messing with our rather well documented test account, this test can fail. |
Yes, you are totally right about the copy_dive usage. I guess you saw from my comments that immediately after finishing the first version of this I had strong doubts that this copy_dive at this point is totally wrong. How do you like the general idea of moving the "unused" cylinders to the end of the list? Regarding the copy_dive I may have good news. The story is that I introduced the copy_dive in the middle of my work while there was still a pile of other bugs in my code. At that moment I incorrectly thought that I really need to do it. After removing all the other bugs I never removed the copy_dive - until now. |
6a1704b
to
aaf1677
Compare
qt-models/cylindermodel.cpp
Outdated
return; | ||
|
||
beginMoveRows(QModelIndex(), cylid, cylid, QModelIndex(), pos + 1); | ||
memmove(&temp_cyl, &displayed_dive.cylinder[cylid], sizeof(temp_cyl)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... In C++ you can simply assign structs: temp_cyl=displayed_dive.cylinder[cylid]
. Wouldn't that be more readable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, you could shorten the whole reorder logic significantly, but I don't know which of these constructs are acceptable:
#include <algorithm>
#include <numeric>
...
int mapping[MAX_CYLINDERS];
std::iota(&mapping[0], &mapping[MAX_CYLINDERS], 0); // Fill with 0..MAX_CYLINDERS-1
auto &cylinder = displayed_dive.cylinder;
if (pos > cylid) {
std::rotate(&cylinder[cylid], &cylinder[cylid + 1], &cylinder[pos + 1]);
std::rotate(&mapping[cylid], &mapping[cylid + 1], &mapping[pos + 1]);
} else {
std::rotate(&cylinder[pos], &cylinder[cylid], &cylinder[cylid + 1]);
std::rotate(&mapping[pos], &mapping[cylid], &mapping[cylid + 1]);
}
...
In my opinion, this is more readable than the various for-loops, but YMMV.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am infamous for not wanting to add too much C++-y-ness to our code. But yeah, wow, that looks much nicer to me :-)
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing a quick grep also shows me that we are already using such constructs like std:sort and others in Subsurface code.
So ok for me to change this, but:
- Will take me some time because I want to really learn and understand this, not just copy&paste and I then want to update at least also similar functions in same file (->seperate commits)
- I first like to finally know if all this open cylinder handling changes will get approved (and I'm not in a hurry here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- yes on consciously using C++ things like std::rotate, std::sort, etc
- yes on UNDERSTANDING them before using them
- yes on cleaning up things as you go - @bstoeger is doing such an amazing job of this
- I think I would like to delay merging the open cylinder handling until after 4.7.5, but overall I think this is a good thing to work on as there are clearly cases where the current code is just wrong
aaf1677
to
94c120b
Compare
This has been quiet for six weeks... is this abandoned, or did you just get busy? Or is this waiting for something from me? I can't quite tell by the comment flow |
@dirkhh |
I think it would make sense to try to have that conversation on the mailing list, mentioning this PR. |
Sort the unused cylinders to the end of the cylinder list when option to display unused cylinders is set to off. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
94c120b
to
409bc49
Compare
Strange - I after very long time of using this in my "private" build finally found some bugs in this code.
I added 4 dives which can be used to debug this feature: |
I give up on this one... |
Did you give up for technical or conceptual reasons? I could help with the first, but not the second (never did a multi tank dive, and never will). |
Describe the pull request:
Pull request long description:
Sort the unused cylinders to the end of the cylinder list when
option to display unused cylinders is set to off.
Changes made:
Related issues:
Closes #880
Additional information:
Release note:
Documentation change:
Mentions: