Text annotations

I would like to add notes to my project. I thought this feature could be found in the Annotation module, but I haven’t found anything in Slicer, so I guess this is a feature request.

Plain text will work, but it would also be nice if I could make use of Markdown: either just syntax highlighting (like in vim) or “rendered” Markdown.

What do you think? Currently, I use a readme.md file in my project’s folder but this will not be included if I make a .mrb bundle of my project.

1 Like

Hi - the latest nightlies have a Texts module for this. Multiple Text nodes can be saved with the scene. Let us know if that works for you. It’s just text now, but could be extended. HTML would be easy, markdown would be a little more work. Happy to provide advice if anyone wants to do the work.

2 Likes

Very nice!

I don’t think editing HTML is practical for the end user. Markdown could however be. Qt seems to have functionality for syntax highlighting. I use Markdown when I write notes since Vim does syntax highlighting automatically. This makes my notes clear.

Rendering markdown may be overkill. However, a quick look at Github shows a MIT-licensed library cpp-markdown for markdown to HTML. There is also a newer header-only, MIT-licensed library called maddy. But this library relies on C++14.

PS: Will Slicer start to use/allow C++14? C++14 makes C++ much more effective!

So far we are just requiring C++11 and it’s not clear when we can move that forward. I’d actually like C++17 someday too.

Adding markdown via C++ would be the most general of course, but if we wanted to shortcut things adding python markdown would be relatively easier to implement. A webengine implementation would also be an option.

1 Like

So Slicer allows C++11? That is something I can live with (I mixed C++11 with C++14). C++11 is the new language, C++14 is mainly a bugfix of C++11, and C++17 is mainly a bugfix of C++14. I too can enjoy C++17 since it has some STL-functions I’ve been missing in C++14.

I don’t think it is productive to make the Texts module very advanced. Implementing the Qt syntax highlighting could however be a nice way for me to get into Slicer development.

Yes, C++11 is a requirement now, so any new Slicer code can definitely use it.

I did a quick search and didn’t find an existing C++ markdown example, but as I suspected there is a webengine-based version.

1 Like

I have some suggestions to improve the current Texts module:

  • Use monospaced font. In this way you can make tables etc. This will also let your notes stand out compared to the application font for a better user experience.
  • It should be possible to just type in your notes directly without clicking the Edit button. And remove the Save and Cancel buttons. I didn’t see those buttons, so when I tried to Clone the text node in Data view, the text was not copied.

Where should I put my suggestions? As an Issue at https://github.com/Slicer/Slicer?

Yes, a github issue would be the place to start and the exact behavior can be refined there and in a corresponding pull request with an implementation. The changes you suggest sound reasonable to me, but I don’t use the Text module myself so I’m sure others have opinions. Thanks for jumping in on this :+1:

1 Like

Markdown is actually very easy now, as you can use markdown in QTextEdit. You can also get the markdown rendering as html to be displayed elsewhere in the application where only html is accepted. To get all these, we need to update our Qt version to 5.14.

3 Likes

The last version of Qt5, Qt 5.15 is scheduled for release in a few days on Tuesday. Might make sense to get all platform versions updated to that instead of my previous attempts to get them all to Qt 5.12.

2 Likes

That makes sense. My windows build is using 5.14 with no problems (that I’ve seen so far anyway)

I will start next week the process of updating the factories (this has been on my plate for a while). The Linux build will take the longest, as I am not sure how the changes to the Qt installer (i.e. requiring an account) will affect the generation of the docker image we use to build.

For Windows, this will also require switching to VS 2017 on the factory.

1 Like

Do you think markdown notes is a nice feature? I would like it.

The markdown feature in Qt 5.14 for QTextEdit seems to be a converter to and from Markdown which is possible since QTextEdit can contain rich text (?). Therefore it will be easy to “render” markdown formatted text. I’m not sure if you can edit markdown text in the QTextEdit. If not, I think an editor with Markdown syntax highlighting is more important than rendering, if the Texts module should mainly be used to write own notes. Notes are something you write on the fly.

Yes, you can edit markdown in QTextEdit, because it is plain, unformatted text. When editing is finished then the text is set as markdown text in QTextEdit, which renders it with nice formatting.

OK!

BTW, I built Slicer for the first time yesterday. It built like a charm on macOS with Homebrew (I had some small problems in the beginning; the wiki page should be updated). Not many software projects builds and runs that smoothly. I look forward to learn more.

It would be great if we could migrate all the build instructions from the wiki to the git repository and readthedocs. We don’t even have a placeholder for that yet, but any PRs would be most welcome.

2 Likes

Added a ticket to track this task:

1 Like

FYI, Slicer now uses Qt-5.14.1, so markdown editing and display is available! It works very nicely.

For example, create a textbox:

t=qt.QTextEdit()
t.show()

Type some markdown text into it:

image

Then run this code to render it as markdown (you can also do some limited WYSIWYG editing, but the behavior is not so obvious, as not all formatting can be translated back to markdown; so I would disable editing):

t.setMarkdown(t.toPlainText())

image

Run this to switch back to plain text editing:

t.setPlainText(t.markdown)

We could add a Format attribute to text node, which could be set to plain text, html, or markdown. Editing would probably always happen in plain text mode, but when you finished editing then rich text could be displayed.

@joachim would you be interested in giving a try and implement this?

1 Like

Only the Windows factory has been switched to 5.14.2. The other factories are pending, but require more work (macOS factory needs an OS update, and we need to regenerate the docker images for Linux)

1 Like

@lassoan: I tested QTextEdit with markdown and it works very nice. It could be a nice feature. I suggest having a format selector in qMRMLTextWidget (plain, HTML, markdown) at the bottom. And the QTextEdit is only editable if plain format is selected, i.e. selecting markdown or HTML gives a read-only visual appearance. A Format attribute is nice then.

I would love to give this a try later, since I don’t have too much time right now. It is a nice exercise and opportunity for me to get into Slicer coding, however.

1 Like