Pre and Post Save functions

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
jcn
Newbie Member
Posts: 7
Joined: Thu Apr 08, 2021 8:14 pm

Pre and Post Save functions

Post by jcn » Fri May 21, 2021 7:05 pm

I recently inquired about using the NewFile.addPostNewAction and Andrew provided example code that helped me get it to work for my application.

After seeing how useful that code was, I went looking for similar functions which would add something like the following when a file is saved:

Save.addPreSaveAction()
Save.addPostSaveAction()


But I couldn't find anything. A search on the forum found a very old thread at:

viewtopic.php?f=30&t=2351&p=7668&hilit= ... ve*#p7668

(I didn't know if I should reply to such an old thread or start this one. Let me know if a reply is always preferred.)

That inquiry was basically the same, but the solution offered at the time seems much more complicated than the similar functionality that is now found in NewFile.js regarding post actions for New and Open files.

Also, apparently that old solution didn't handle non-GUI cases where the file is saved.

So, my question is if there has been an update to QCAD that I've not found or anything else which implements functionality similar to NewFile.addPostNewAction, but for actions which are Pre and Post Save for a file?

Thanks in advance.
jcn

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: Pre and Post Save functions

Post by andrew » Fri May 21, 2021 7:47 pm

There's no such high-level notification mechanism for saving / exporting as saving can also happen in the background (auto save).

You'd have to resort to the lower level "listener" mechanism to get notified when a file is saved (i.e. exported). You can find an example implementation here:

https://github.com/qcad/qcad/blob/maste ... istener.js

The interfaces on this level are:
RExportListenerAdapter which triggers signals preExport and postExport
and analogous
RImportListenerAdapter which triggers signals preImport and postImport

jcn
Newbie Member
Posts: 7
Joined: Thu Apr 08, 2021 8:14 pm

Re: Pre and Post Save functions

Post by jcn » Sat May 22, 2021 3:33 pm

OK, thanks.

I will try that approach.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”