Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Detecting deleted lines in a QTextDocument
Forum Updated to NodeBB v4.3 + New Features

Detecting deleted lines in a QTextDocument

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 550 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    johnb003
    wrote on last edited by
    #1

    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.

    I've been thinking of a few possible ways to get the information:

    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. This seems like a lot of unnecessary overhead.
    3. Maybe I need to dig into the source and create a new signal before something is about to be deleted.
    4. I put some more userState or userData in every block that map to my array, and if I notice missing consecutive blocks indices, I can infer the deleted blocks, update my mapping, and then update all of the remaining blocks in the file with new consecutive indices.

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

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved