Recent

Author Topic: RichMemo and QT5 save/load  (Read 1977 times)

TheMouseAUS

  • Jr. Member
  • **
  • Posts: 52
RichMemo and QT5 save/load
« on: May 10, 2023, 01:24:20 am »
From what I have read there is no method of saving the contents of RichMemo and retain the formatting ie save as a .rtf file using QT5. Are there any plans to add this function? The output file does not need to be rtf anything would be ok just a way to save and load back retaining the format.
ATM I am reading each line of the a file saved as text and then applying formatting back to what is was, but this is a very slow process and can take up to 7 secs to read 300 lines and alter.  Its a bit of a nasty hack but it works. Any other suggestions would be appreciated. Thanks

dbannon

  • Hero Member
  • *****
  • Posts: 2802
    • tomboy-ng, a rewrite of the classic Tomboy
Re: RichMemo and QT5 save/load
« Reply #1 on: May 10, 2023, 02:24:16 am »
Hmm, in my app, I can read a 40K xml file and render all the markup in a KMemo in  280mS. Thats on a fast SSD but I have to parse the XML and convert that into KMemos markup which is quite time consuming.

I have not used richmemo very much so don't know how similar it really is but I found a fair bit of time can be saved by ensuring the colours are set before loading.

Ahh, are you 'locking' the richmemo before loading ??  Most (complicated) components allow you to lockupdates while you make changes. That way, the component is not trying to update the screen content until you have it all loaded. I am sure RichMemo will have the ability to do that.

And, finally, perhaps less authoritatively, RTF is not much of a format to use, very messy and ill defined in practice. If you cannot use RichMemo to handle loading rtf (and I am surprised about that ...) them, maybe, consider XML ?

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

TheMouseAUS

  • Jr. Member
  • **
  • Posts: 52
Re: RichMemo and QT5 save/load
« Reply #2 on: May 10, 2023, 04:02:45 am »
Hi Davo, thanks for the reply.

All I am really concerned with is being able to keep colors and style  per line. Some lines text is blue, others red, others black, either in bold or normal.

RichMemo allows this but of course I cannot save it that way.

I will check out xml :-)

dsiders

  • Hero Member
  • *****
  • Posts: 1084
Re: RichMemo and QT5 save/load
« Reply #3 on: May 10, 2023, 04:44:06 am »
Hi Davo, thanks for the reply.

All I am really concerned with is being able to keep colors and style  per line. Some lines text is blue, others red, others black, either in bold or normal.

RichMemo allows this but of course I cannot save it that way.

I will check out xml :-)

Sounds like a perfect candidate for HTML to me...
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

dbannon

  • Hero Member
  • *****
  • Posts: 2802
    • tomboy-ng, a rewrite of the classic Tomboy
Re: RichMemo and QT5 save/load
« Reply #4 on: May 10, 2023, 08:21:04 am »
Hi Davo, thanks for the reply.

All I am really concerned with is being able to keep colors and style  per line. Some lines text is blue, others red, others black, either in bold or normal.

RichMemo allows this but of course I cannot save it that way.

I will check out xml :-)

Hmm, I am guessing RichMemo does allow you to display these coloured lines and allows you to save the content as RTF. I would expect It restore the coloured lines in a save/load cycle, if not, does sound like a bug and worth reporting.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

TheMouseAUS

  • Jr. Member
  • **
  • Posts: 52
Re: RichMemo and QT5 save/load
« Reply #5 on: May 10, 2023, 08:29:22 am »

RichMemo does allow coloured and formated lines but rtf loading and saving is not supported under QT.


Hmm, I am guessing RichMemo does allow you to display these coloured lines and allows you to save the content as RTF. I would expect It restore the coloured lines in a save/load cycle, if not, does sound like a bug and worth reporting.

Davo

TheMouseAUS

  • Jr. Member
  • **
  • Posts: 52
Re: RichMemo and QT5 save/load
« Reply #6 on: May 10, 2023, 08:38:35 am »
Sounds like a perfect candidate for HTML to me...

Yes have been looking at that today. Just having an issue displaying.
I have a TStringList called FaultLogs which I write fault logs to. To display I tried using TIpHtmlPanel as follows :-

This does not work

var pHTML : TIpHtml;
fs : TStringStream;
begin
  fs := TStringStream.Create;
  FaultLog.SaveToStream(FS);
  Try
  pHTML:=TIpHtml.Create;
  pHTML.LoadFromStream(fs);
  finally
  fs.Free;
  end;
  IpHtmlPanel1.SetHtml( pHTML );
end;

this does work
var pHTML : TIpHtml;
fs : TStringStream;
begin
 FaultLog.SaveToFile('LogDisplay.html');
  fs := TStringStream.Create;
  fs.LoadFromFile('LogDisplay.html');
  Try
  pHTML:=TIpHtml.Create;
  pHTML.LoadFromStream(fs);
  finally
  fs.Free;
  end;
  IpHtmlPanel1.SetHtml( pHTML );
end;

I would not expect to have to save it and load again. I tried SaveToStream with encoding utf8 etc still no go.

dsiders

  • Hero Member
  • *****
  • Posts: 1084
Re: RichMemo and QT5 save/load
« Reply #7 on: May 10, 2023, 09:32:09 am »
This does not work

var pHTML : TIpHtml;
fs : TStringStream;
begin
  fs := TStringStream.Create;
  FaultLog.SaveToStream(FS);
  Try
  pHTML:=TIpHtml.Create;
  pHTML.LoadFromStream(fs);
  finally
  fs.Free;
  end;
  IpHtmlPanel1.SetHtml( pHTML );
end;

I would not expect to have to save it and load again. I tried SaveToStream with encoding utf8 etc still no go.

Code: Pascal  [Select][+][-]
  1. fs := TStringStream.Create;
  2. FaultLog.SaveToStream(fs);
  3. fs.Position := 0;
  4. ...
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

TheMouseAUS

  • Jr. Member
  • **
  • Posts: 52
Re: RichMemo and QT5 save/load
« Reply #8 on: May 10, 2023, 11:41:05 am »
Awesome that fixed it, but can anyone explain why the behavior is different from loading a file to using a stream? Once the file is read would that not be at the end of the stream also? Just for my learning and understanding :-)

 

TinyPortal © 2005-2018