Skip to content
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

Spell check for attribute form / table content #49934

Open
walking-the-talk opened this issue Aug 23, 2022 · 5 comments
Open

Spell check for attribute form / table content #49934

walking-the-talk opened this issue Aug 23, 2022 · 5 comments

Comments

@walking-the-talk
Copy link

Feature description

As far as I can see there is no built-in way to check the spelling of the data within an attribute table / form. For those of us that need to add 'context' to spatial data this is a real problem - typo's never look good in a rport (!)

I have been skulking around trying to find way I could work with external spelling systems but I'm not well enough versed in python or hacking code to make something work. I'm really just looking for in-line spell checking similar to what I have when using a browser or many text editing applications... Even if it just highlights simple spelling errors that would be a major step forward for me (my typing accuracy is not fabulous!)

In refining my search terms for a ready-made solution, I came across a method for incorporating spell checking in PyQT5 via Enchant as a python script called spelltextedit.py and wondered if it could be adapted for QGIS. I went to the author and my enquiry sparked some interest so he explained in simple terms what it might entail (see context below).

So already I'm very grateful to Stephan for his time and effort and I'm wondering if QGIS folk might be able to incorporate any of this 'heavy lifting' that has been done to give QGIS the functionality that lots of people probably assume should be an integral part of this already amazing software. Could anyone even commission him to complete what he's started?

With apologies for any misinformation, over-simplification or simple stupidity. I would be happy to help where I can, but I am a bear of very little brain...

Additional context

This is from an email exchange with the author:

The basic principles of how spelltextedit.py works are:

  1. Qt's QTextEdit and QPlainTextEdit widgets come with ready-made support for hooking in a syntax highlighter like you'd find in a programmer's text editor.

  2. spelltextedit.py includes a very simple QSyntaxHighlighter subclass which, whenever Qt asks it to highlight a block of text, it feeds it to Enchant and then tells Qt which spans of text need a wavy red underline.

  3. spelltextedit.py's subclass of QPlainTextEdit is almost entirely concerned with implementing the context menu where, when you right-click within a word, it finds the boundaries of the word, feeds the word to Enchant, and then prepends a submenu full of suggested corrections to the default context menu.

(I say "almost entirely" because it also adds submenus for things like selecting the spell-check language and specifying plaintext vs. HTML.)

In short, if they're already using QTextEdit or QPlainTextEdit, then it's probably a near-trivial fix aside from adding Enchant (and, if necessary, PyEnchant) to the list of dependencies.

Otherwise, it'd be a bit more complicated, but not overly so as long as you're not intending to use it in things like QComboBox which insist on QLineEdit.

(The simplest solution would be to replace QLineEdit widgets with QPlainTextEdit widgets configured to look and behave like QLineEdit in all relevant ways.)

And then he did some work to explain to a duffer like me what he really meant...
http://blog.ssokolow.com/archives/2022/07/22/a-qlineedit-replacement-with-spell-checking/

Apparently this can be run as a demonstrator. If you know what you're doing...

And then, as if that wasn't enough, he followed that up with some additional code to fix a QT bug that is relevant to this idea...

http://blog.ssokolow.com/archives/2022/08/01/tooltips-for-syntax-highlights-in-qtextedit-qplaintextedit/

@Isaacson33
Copy link

This is great that you've laid out so much ground work, but this has been a feature request for four years #32346 (one I've been keeping an eye on for the same reasons you've encountered).

Just commenting now to see if a little bump might avoid your hard work being 'archived', but for some reason there seems little enthusiasm for this.

By way of solace, I don't know if you use Spatialite, but if so, the great DB Browser application allows you to review long text data in an external application (like Notepad or Kate) and the apply the changes. This is what I've been doing for a while now as a workaround

@walking-the-talk
Copy link
Author

Thanks @Isaacson33 - I have a not-quite-working plugin that I adapted from Go2NextFeature to try to get to proof-of-concept. I have been able to generate an attribute form that has the required QPlainTextEdit() widgets for string fields, and allows me to load attributes and switch between string fields ready to spell-checking. So that would, I think, allow me to swap-out the SpellTextEdit() subclass as per the first post. However, it falls over because (as highlighted in my post at pyenchant), I can't get QGIS to import the module within the working environment, only in OSGeoW shell. A frustrating problem that I can't get past and I confess that it has dropped off my priority list for now.

I'm beyond my competence and comfort to have got this far and don't know where to go from here. It is a real shame there is no appetite for a spell checker and I hoped that my Heath Robinson approach might open some doors to this concept...

To me spell checking is a no-brainer, not even something that should be considered a 'feature', but it appears that we are a tiny minority in wanting this functionality. I have tried a few different work-arounds, but none of them are as 'convenient' as being able to check spelling in context...

Thanks for picking up and saving it from the dreaded archive,,,

@Isaacson33
Copy link

Indeed, I find it baffling that in the time over which the spell-checking feature request has been around, QGIS has actually developed and bug-fixed a full 3-D rendering engine, but still no spell-checker - even a misspelled label on a legend looks bad - but as I'm even further out of my depth than you, I suppose we'll just have to make do.

At least now no-one can say the issue hasn't had considerable effort put to it, thanks to your work... maybe that will get picked up on.

@DelazJ
Copy link
Contributor

DelazJ commented Nov 2, 2023

Indeed, I find it baffling that in the time over which the spell-checking feature request has been around, QGIS has actually developed and bug-fixed a full 3-D rendering engine

@Isaacson33 Certainly because #32346 is ... just a wish. Read http://nyalldawson.net/2016/08/how-to-effectively-get-things-changed-in-qgis/ and you will notice that the 3D features met the requirements, and I think the efforts @walking-the-talk is putting in this feature are indeed on the right track.

@walking-the-talk
Copy link
Author

Thanks @DelazJ - your point is well made and we have all suffered from having our wishes unfulfilled :-)

I have tried to keep my wish realistic within the sphere that I have a vague idea of how to influence (so it is targeted towards attribute forms). However, from what I can see, if anyone who knew how to code it might be possible to adapt QGIS to call QPlainTextEdit widgets across the UI for String inputs then maybe it wouldn't be too hard to integrate SpellTextEdit widgets instead, rather than just my very limited application. But that's WAY beyond me, hence starting with a tiny corner.

It's interesting / intriguing that there is a spell checker for code in QGIS, but not for users - this took me some time to understand / disentangle in the repository - and my guess is confirmed by the recent #55002 - I wonder whether it could be extended to the UI rather than reinvented? Maybe that's a false-friend?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants