-
-
Notifications
You must be signed in to change notification settings - Fork 175
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
Make VtkPlot more object-oriented #379
Make VtkPlot more object-oriented #379
Conversation
This will allow us to add more customization to the class without having a static function with an exceedingly long list of arguments... Signed-off-by: Patrick Avery <psavery@buffalo.edu>
@cryos Can you take a look at this when you get a chance? I'll need this sometime soon for another PR... |
Unfortunately, this isn't quite as stable as I wish that it was. It crashes every once in a while after the previous plot is deleted. It appears that the crash is during event handling (a crash log is pasted below - this crash log is consistently produced). So I will probably need to modify the way cleanup is performed. Maybe ensuring all signals/slots are disconnected. Maybe using
|
I will try and take a look at this soon, any QObject should preferably use deleteLater to allow for all signals that might be connected to execute before the object goes away (rather than trying to disconnect things). |
Unfortunately, adding something like this to my destructor doesn't seem to fix the issue:
Perhaps because the other parts like the render window, chart, and view get deleted... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general the use of QScopedPointer and/or std::unique_ptr is going to cause issues with QObject derived classes. You need to remember that Qt uses a parent-child ownership model for QObjects. We should have a member pointer, initialize it to null, and instantiate in the show/display call (as you are). Ensure the correct ownership of the dialog is passed in so that the window shows up where it should, and let the parent take care of calling destruct. We can change the window flags, but ideally on subsequent calls the same object is reused, and you simply update the data, rather than calling delete, and making another new one.
When dealing with QObject-based classes, we should prefer the Qt-based pointer classes too. When dealing with VTK the VTK-based pointer classes, when dealing with STL/C++ objects certainly prefer the STL pointer classes.
Thanks for taking a look, Marcus! Yes, it makes sense for me to do all of that. However, since a QWidget requires a QWidget as its parent, we should perhaps figure out which QWidget should be the parent for widgets in plugins. I see in many plugins where we set the parent of a widget like so: That means we have a lot of QWidgets in our plugins without a parent (although I think the QApplication does keep a record of them). Should we do something about this? Also, I was considering to allow multiple VTK plots of the same kind to exist simultaneously (in case a user wants to compare, for instance, different settings for the same kind of plot). But for now, we can just allow one plot and re-use it when another plot command is called. |
Now, the old VtkPlot objects are re-used instead of being deleted and re-created. This prevents an issue where deleting the old object would sometimes result in crashing due to the Qt event loop. Signed-off-by: Patrick Avery <psavery@buffalo.edu>
@cryos I have not set a Qt parent for them yet (and removed the smart pointer) because I haven't been able to figure out a suitable parent for them to have, as they can only have a widget as their parent. In addition, the Vtk plot still stays open after the main Avogadro window is closed. This is probably partially caused by #389. |
Can we bump this to check the AppVeyor build? I'd like to get a few of these merged... |
This will allow us to add more customization to the class without
having a static function with an exceedingly long list of arguments...
Signed-off-by: Patrick Avery psavery@buffalo.edu
Developer Certificate of Origin
Version 1.1
Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129
Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.
Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.