3

I have a mapping in my application that must be maintained for every line. When the user deletes a line, I'm trying to detect which line so I can update my mapping.

The contentsChange signal has where in the document a change occurred and how many characters are added or deleted, but at this point it's too late to determine what was there before the delete.

So far here's what I've been thinking about trying:

  1. If I peek at the undo stack maybe I can get at the lines that were deleted, but this may not be reliably for large change blocks.
  2. I could keep a previous state of the file for every change, and then try to look there when the signal is raised, but this seems like a lot of unnecessary overhead.
  3. I could try to dig into the source and create a new signal before something is about to be deleted, but then I have to build my code and release this modification since I'm using LGPL.
  4. I can put consecutive values in userState in every block and if when contentsChanged is fired, and I detect a gap in the consecutive values between the previous and next block from where the change occurs, I can infer the deleted blocks. The downside here is that I have to then update all of the remaining blocks after I detect a change to restore the consecutive values.

What's the most graceful (simplest and inexpensive) way to do this?

I'm using Qt5.2.1 with c++.

Edit: I'm trying a major redesign of my application by putting more of my custom info in the user state directly in the block (per line since I don't have word wrap). If I can get by with this approach, it will avoid the problem of having detect when a line is deleted all together, but the problem is still an interesting one and I think it still begs for an an answer.

In other GUI frameworks, the operation stack that fed the undo stack had pre-change callbacks, and post-change callbacks. I think the pre-change callback is what's missing here. Or is there some better way I don't know about???

johnb003
  • 1,821
  • 16
  • 30
  • Once bruteforce is a container for everyline, such lines, delete from once it is removed. – László Papp Apr 15 '14 at 05:03
  • Laszlo, I'm not sure I understand. I'm guessing you're trying to say something like: "One bruteforce idea is: Make a container for every line, and when the line is removed the container will be deleted and you can detect that." Is that what you mean? – johnb003 Apr 16 '14 at 01:59

0 Answers0