Repository navigation
TOPPView: fixes a few error messages boxes (im IM frames, and 2D projections) - #8047
Conversation
…h has no RT information)
WalkthroughThe changes refactor context menu handling in the 2D plot view, update the method signature for collecting fragment scans, and add exception safety for projections. The context menu logic now uses lambda callbacks for actions, skips invalid RT neighbor entries, and adds support for ion mobility view switching. Exception handling prevents InvalidRange errors during projections. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Plot2DCanvas
participant LayerDataPeak
participant QMenu
User->>Plot2DCanvas: Right-click (context menu event)
Plot2DCanvas->>LayerDataPeak: Query for RT/mz area and spectrum info
Plot2DCanvas->>QMenu: Create context menu with survey/fragment scan actions (using lambdas)
alt Ion mobility data present
Plot2DCanvas->>QMenu: Add ion mobility view switch action
end
User->>QMenu: Selects action
QMenu->>Plot2DCanvas: Lambda callback executes action directly
Assessment against linked issues
Poem
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (3)
src/openms_gui/include/OpenMS/VISUAL/Plot2DCanvas.h (1)
112-114: Clarify return-value semantics in the header comment
collectFragmentScansInArea_()now returns abool, yet the doxygen comment only states that the method “adds them to the menus”. Please extend the comment to explain what the boolean indicates (e.g. “true if at least one scan was added, false otherwise”).src/openms_gui/source/VISUAL/LayerDataPeak.cpp (1)
108-143: Over-broadcatch (...)hides real errorsThe three projection blocks swallow all exceptions and continue silently.
While avoiding pop-ups is desirable, catching every exception type makes debugging
hard and may mask unrelated bugs.Consider catching the specific exception thrown by
operator[]/push_back
(e.g.Exception::InvalidRange) and log others:try { … } catch (const Exception::InvalidRange&) { /* ignore – projection outside area */ } catch (...) { OPENMS_LOG_ERROR << "Unexpected error while building projection.\n"; }src/openms_gui/source/VISUAL/Plot2DCanvas.cpp (1)
1526-1544: Iterator captured in lambda – prefer stable indexEach lambda copies the iterator
it. Although that works, computing the
index once makes the capture lighter and avoids surprises ifconst_iterator
internals change:- msn_scans->addAction(QString("RT: ") + …, - [=]() { emit showSpectrumAsNew1D(it - layer.getPeakData()->begin()); }); + const int spec_idx = static_cast<int>(it - layer.getPeakData()->begin()); + msn_scans->addAction(QString("RT: ") + …, + [=]() { emit showSpectrumAsNew1D(spec_idx); });Same remark for the meta-data action.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
📒 Files selected for processing (3)
src/openms_gui/include/OpenMS/VISUAL/Plot2DCanvas.h(1 hunks)src/openms_gui/source/VISUAL/LayerDataPeak.cpp(2 hunks)src/openms_gui/source/VISUAL/Plot2DCanvas.cpp(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
- GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
- GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
- GitHub Check: build-and-test (macos-14, xcode, 15.0.1)
- GitHub Check: build-and-test (windows-2022, cl.exe, 14.36)
- GitHub Check: build-and-test (macos-13, xcode, 14.2)
| // in a IM-frame (IM vs. m/z), the RT is empty in `e_units`, and showing neighbouring RT scans is not possible (this layer only has this IM frame) | ||
| // --> skip entries for RT neighbours. | ||
| if (!e_units.RangeRT::isEmpty()) | ||
| { | ||
| current = std::max(SignedSize{0}, size - 1); // we want the rightmost valid scan index | ||
| } | ||
|
|
||
| SignedSize i = 0; | ||
| while (current + i < size || current - i >= 0) | ||
| { | ||
| if (current + i < size && (*lp->getPeakData())[current + i].getMSLevel() == 1) | ||
| { | ||
| current += i; | ||
| break; | ||
| } | ||
| if (current - i >= 0 && (*lp->getPeakData())[current - i].getMSLevel() == 1) | ||
| // add surrounding survey scans | ||
| // find nearest survey scan | ||
| SignedSize size = lp->getPeakData()->size(); | ||
| Int current = lp->getPeakData()->RTBegin(e_units.getMinRT()) - lp->getPeakData()->begin(); | ||
| if (current == size) // if the user clicked right of the last MS1 scan | ||
| { | ||
| current -= i; | ||
| break; | ||
| current = std::max(SignedSize {0}, size - 1); // we want the rightmost valid scan index | ||
| } | ||
| ++i; | ||
| } | ||
| // search for four scans in both directions | ||
| vector<Int> indices; | ||
| indices.push_back(current); | ||
| i = 1; | ||
| while (current - i >= 0 && indices.size() < 5) | ||
| { | ||
| if ((*lp->getPeakData())[current - i].getMSLevel() == 1) | ||
|
|
||
| SignedSize i = 0; | ||
| while (current + i < size || current - i >= 0) | ||
| { | ||
| indices.push_back(current - i); | ||
| if (current + i < size && (*lp->getPeakData())[current + i].getMSLevel() == 1) | ||
| { | ||
| current += i; | ||
| break; | ||
| } | ||
| if (current - i >= 0 && (*lp->getPeakData())[current - i].getMSLevel() == 1) | ||
| { | ||
| current -= i; | ||
| break; | ||
| } | ||
| ++i; | ||
| } | ||
| ++i; | ||
| } | ||
| i = 1; | ||
| while (current + i < size && indices.size() < 9) | ||
| { | ||
| if ((*lp->getPeakData())[current + i].getMSLevel() == 1) | ||
| // search for four scans in both directions |
There was a problem hiding this comment.
current calculation may dereference an empty experiment
If the peak map is empty (size == 0) the loop dereferences
(*lp->getPeakData())[current ± i], leading to UB.
Add a quick exit:
SignedSize size = lp->getPeakData()->size();
if (size == 0) return; // nothing to show – avoid crashand/or move the dereference inside a bounds-checked helper.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // in a IM-frame (IM vs. m/z), the RT is empty in `e_units`, and showing neighbouring RT scans is not possible (this layer only has this IM frame) | |
| // --> skip entries for RT neighbours. | |
| if (!e_units.RangeRT::isEmpty()) | |
| { | |
| current = std::max(SignedSize{0}, size - 1); // we want the rightmost valid scan index | |
| } | |
| SignedSize i = 0; | |
| while (current + i < size || current - i >= 0) | |
| { | |
| if (current + i < size && (*lp->getPeakData())[current + i].getMSLevel() == 1) | |
| { | |
| current += i; | |
| break; | |
| } | |
| if (current - i >= 0 && (*lp->getPeakData())[current - i].getMSLevel() == 1) | |
| // add surrounding survey scans | |
| // find nearest survey scan | |
| SignedSize size = lp->getPeakData()->size(); | |
| Int current = lp->getPeakData()->RTBegin(e_units.getMinRT()) - lp->getPeakData()->begin(); | |
| if (current == size) // if the user clicked right of the last MS1 scan | |
| { | |
| current -= i; | |
| break; | |
| current = std::max(SignedSize {0}, size - 1); // we want the rightmost valid scan index | |
| } | |
| ++i; | |
| } | |
| // search for four scans in both directions | |
| vector<Int> indices; | |
| indices.push_back(current); | |
| i = 1; | |
| while (current - i >= 0 && indices.size() < 5) | |
| { | |
| if ((*lp->getPeakData())[current - i].getMSLevel() == 1) | |
| SignedSize i = 0; | |
| while (current + i < size || current - i >= 0) | |
| { | |
| indices.push_back(current - i); | |
| if (current + i < size && (*lp->getPeakData())[current + i].getMSLevel() == 1) | |
| { | |
| current += i; | |
| break; | |
| } | |
| if (current - i >= 0 && (*lp->getPeakData())[current - i].getMSLevel() == 1) | |
| { | |
| current -= i; | |
| break; | |
| } | |
| ++i; | |
| } | |
| ++i; | |
| } | |
| i = 1; | |
| while (current + i < size && indices.size() < 9) | |
| { | |
| if ((*lp->getPeakData())[current + i].getMSLevel() == 1) | |
| // search for four scans in both directions | |
| // add surrounding survey scans | |
| // find nearest survey scan | |
| SignedSize size = lp->getPeakData()->size(); | |
| if (size == 0) return; // nothing to show – avoid crash | |
| Int current = lp->getPeakData()->RTBegin(e_units.getMinRT()) - lp->getPeakData()->begin(); | |
| if (current == size) // if the user clicked right of the last MS1 scan | |
| { | |
| current = std::max(SignedSize{0}, size - 1); // we want the rightmost valid scan index | |
| } | |
| // … |
🤖 Prompt for AI Agents
In src/openms_gui/source/VISUAL/Plot2DCanvas.cpp around lines 887 to 915, the
code calculates 'current' and then dereferences peak data without checking if
the peak map is empty, which can cause undefined behavior if size is zero. To
fix this, add a check right after obtaining 'size' to return early or skip
processing if size is zero, preventing any dereference on empty data.
Alternatively, ensure all dereferences of peak data are guarded by bounds checks
or moved inside a helper function that performs these checks.
timosachsenberg
left a comment
There was a problem hiding this comment.
looks good to me
Description
fixes #8046
Checklist
How can I get additional information on failed tests during CI
Click to expand
If your PR is failing you can check outIf you click in the column that lists the failed tests you will get detailed error messages.
Advanced commands (admins / reviewer only)
Click to expand
/reformat(experimental) applies the clang-format style changes as additional commit. Note: your branch must have a different name (e.g., yourrepo:feature/XYZ) than the receiving branch (e.g., OpenMS:develop). Otherwise, reformat fails to push.rebuild jenkinswill retrigger Jenkins-based CI buildsSummary by CodeRabbit
New Features
Bug Fixes
Refactor