PDA

View Full Version : QTextEdit column select ?



kib2
25th October 2008, 13:06
Hi,

Does the Q(Plain)TextEdit widget supports column selection ?
I have heard it was the case in Qt3, but I saw nothing about it in Qt4.

If not, any idea about how to implement such a thing ?

thanks.

fullmetalcoder
25th October 2008, 18:31
Neither QPlainTextEdit nor QTextEdit support column selection and I doubt that such a feature is on the TODO list of the Trolls (Noks now...).

Implementing this for QTextEdit/QTextDocument (or the plain text counterpart) will probably be hackish and quite painful (if doable at all). The only Qt-based editor that I know of which features column selection is QCodeEdit (http://qcodeedit.edyuk.org).

kib2
25th October 2008, 19:05
Thanks fullmetalcoder,


Neither QPlainTextEdit nor QTextEdit support column selection and I doubt that such a feature is on the TODO list of the Trolls (Noks now...).

Does that mean that we always have to stay with the awfull Scintilla control to write a descent editor (it's a good control, but you have to write your own parser for any new langage : a pain ).



Implementing this for QTextEdit/QTextDocument (or the plain text counterpart) will probably be hackish and quite painful (if doable at all). The only Qt-based editor that I know of which features column selection is QCodeEdit (http://qcodeedit.edyuk.org).

I've tried it, but got errors when compiling.

How did you implemented the folding ? (I'm' just curious, I found nothing about this).
Do you project to make a QtPlugin for it ?

fullmetalcoder
25th October 2008, 19:39
I've tried it, but got errors when compiling.
Please send me more informations about this (version used, compiler, platform, Qt version, compile log...) so that I may be able to fix things (if they are still broken in the latest version).


it's a good control, but you have to write your own parser for any new langage : a pain
IMO QScintilla sucks for two main reasons :


it lacks flexibility
its API is really crappy

In QCodeEdit I tried to address both issues :


By adding a syntax engine that fetches languages definitions from XML files, thus relieving developers of the complicated parser writing phase
By adding the concept of panels which allow complete customization of the editor (line number, line marks, folding indicators, ... are all done in separate panels which can be easily enabled/disabled)
QCodeEdit API has been designed to be close to QTextEdit API



How did you implemented the folding ? (I'm' just curious, I found nothing about this).
In QCodeEdit I implemented folding in the most straightforward way : giving a HIDDEN flag to the lines (or blocks to speak in QTextDocument). This is possible because I reimplmented my document and editor classes from scratch.

In a previous version that still used QTextEdit as a base class I hacked a crappy code folding by deleting the text to hide but keeping it in a custom QTextBlockUserData object attached to the first line of the folded block. This worked but messed up the undo stack so it was not a viable solution.


Do you project to make a QtPlugin for it ?
Do you mean Qt Designer plugin? It was not on my TODO list but I may consider doing it if some people show interest for such a feature.

kib2
26th October 2008, 01:17
Please send me more informations about this (version used, compiler, platform, Qt version, compile log...) so that I may be able to fix things (if they are still broken in the latest version).

Ok, I'll retry tomorrow and send you a report.



IMO QScintilla sucks for two main reasons :


it lacks flexibility
its API is really crappy



Yes, and it's really annoying ; everyone is using it because it's the only one that provides a rather "good" syntax highlighting (good does not means configurable here, rather functionnal), code folding, and column selection too for free. But once you get it, you're stuck with the given lexers, and writting your own is just a pain.



In QCodeEdit I tried to address both issues :


By adding a syntax engine that fetches languages definitions from XML files, thus relieving developers of the complicated parser writing phase
By adding the concept of panels which allow complete customization of the editor (line number, line marks, folding indicators, ... are all done in separate panels which can be easily enabled/disabled)
QCodeEdit API has been designed to be close to QTextEdit API



I really think it's the way to go for any descent editor.



In QCodeEdit I implemented folding in the most straightforward way : giving a HIDDEN flag to the lines (or blocks to speak in QTextDocument). This is possible because I reimplmented my document and editor classes from scratch.


Yes, I've already think of this : text is a list of lines, and when you fold it, you just
hide some parts of the list contents, but what are the penalties (in speed ) ?



In a previous version that still used QTextEdit as a base class I hacked a crappy code folding by deleting the text to hide but keeping it in a custom QTextBlockUserData object attached to the first line of the folded block. This worked but messed up the undo stack so it was not a viable solution.


I've never used QTextBlockUserData before; when looking at it quickly, it seems good for matching pairs of parenthesis, etc. If I can use it for folding too, it may be a good idea.
I suppose you've also made controls for margins too : folding and line numbers (I've made the last one, but it became slow on large files).



Do you mean Qt Designer plugin? It was not on my TODO list but I may consider doing it if some people show interest for such a feature.


That's what I meant ;) In fact, I'm not programming in C++, I use Python, but if I can use your control with some of the things I've made with my older one (sort of "multi cursors" [you can drag them everywhere, then type something : all the cursors are updated once you enter some text], snippets, etc), I'll be near heaven :rolleyes:

fullmetalcoder
26th October 2008, 11:22
Yes, I've already think of this : text is a list of lines, and when you fold it, you just
hide some parts of the list contents, but what are the penalties (in speed ) ?
The speed is really a matter of implementation. In QCodeEdit I got incredible speed (you can fold tens of thousands of lines in a matter of milliseconds) by storing a map of hidden regions (start line and size) which allows fast coordinate transforms (visual line <=> actual text line) and get rid of the need to iterate over the whole document to draw line numbers (or line marks and similar things... however folding indicator still require complete iteration right now).


I've never used QTextBlockUserData before; when looking at it quickly, it seems good for matching pairs of parenthesis, etc. If I can use it for folding too, it may be a good idea.
Not such a good solution actually (unless you're tied to QTextEdit) for the reasons I've explained above. If you're interested in implementing code folding this way you may be interested in having a look at old Edyuk versions (up until 0.9.x)



That's what I meant ;) In fact, I'm not programming in C++, I use Python, but if I can use your control with some of the things I've made with my older one (sort of "multi cursors" [you can drag them everywhere, then type something : all the cursors are updated once you enter some text], snippets, etc), I'll be near heaven :rolleyes:
Are you sure a designer plugin is enough to use a component within Python? I'd have thought it would be necessary to wrap the whole lib just like QScintilla does...

kib2
26th October 2008, 12:32
The speed is really a matter of implementation. In QCodeEdit I got incredible speed (you can fold tens of thousands of lines in a matter of milliseconds) by storing a map of hidden regions (start line and size) which allows fast coordinate transforms (visual line <=> actual text line) and get rid of the need to iterate over the whole document to draw line numbers (or line marks and similar things... however folding indicator still require complete iteration right now).

That seems impressive.




Not such a good solution actually (unless you're tied to QTextEdit) for the reasons I've explained above. If you're interested in implementing code folding this way you may be interested in having a look at old Edyuk versions (up until 0.9.x).

Ok, thanks I'll take a closer look at it.



Are you sure a designer plugin is enough to use a component within Python? I'd have thought it would be necessary to wrap the whole lib just like QScintilla does...

No, not at all. I think we must wrap it using SIP, like QScintila does.


Here's my report on trying to build QCodeEdit 2.1:
http://share11.appspot.com/3421

fullmetalcoder
26th October 2008, 12:50
That seems impressive.
It did require some work but line wrapping is even more of a challenge (almost done in SVN)


Ok, thanks I'll take a closer look at it.
Just remember that this solution is FAR from ideal (even QScintilla ought to be prefered unless you have pretty good reasons to stick to QTextEdit)


No, not at all. I think we must wrap it using SIP, like QScintila does.
That's what I thought. I thought about giving it a try some time ago but it looked like a lot of work (no automating as far as I could tell).


Here's my report on trying to build QCodeEdit 2.1:
http://share11.appspot.com/3421
The file which causes compilation to fail should not even be compiled actually... It is a remnant from the early genesis of the syntax engine (I had to test it outside of the editing framework to make sure it worked properly before integrating it into the bigger entity). You can safely remove this file (lib/qnfa/main.cpp). Then re-run qmake, then make and everything should go fine.

Thanks for reporting this. I'll remove this file from the next release (it is already removed from SVN btw).

kib2
26th October 2008, 13:25
FullMetalCoder,

I've removed main.cpp from "\lib\qnfa", then the corresponding line from "qcodeedit-2.1.pro" (I suppose I have to do that too).
Here's what I've got : http://share11.appspot.com/3222

I did not find any Edyuk versions < 0.9 to study the old code ...where are they ?

I've installed Edyuk for the first time : really great piece of work ;)

Is it possible to continue talking on IRC or by mail ?

fullmetalcoder
26th October 2008, 13:55
I've removed main.cpp from "\lib\qnfa", then the corresponding line from "qcodeedit-2.1.pro" (I suppose I have to do that too).
Here's what I've got : http://share11.appspot.com/3222

Errr... Would you, by any chance, have generated a qmake project with "qmake -project" ? (The main project file should be qcodeedit.pro which is a subdirs project for the lib and the example app). This would explain why everything goes wrong.


I did not find any Edyuk versions < 0.9 to study the old code ...where are they ?
The TuxFamily download server only provide the most recent packages. All the versions are available on sourceforge : http://sourceforge.net/project/showfiles.php?group_id=168260&package_id=191461


I've installed Edyuk for the first time : really great piece of work ;)
Thanks. And version 1.1.0 will be even better :)


Is it possible to continue talking on IRC or by mail ?
Sure. You can use the MSN address in my profile to contact me by mail or IM

harinlen
30th June 2013, 14:20
Dear fullmetalcoder,
I'm a beginner and now I'm also get stucked in the column select in QPlainTextEdit, could you please help me with this? Thanks a lot!!