qobject_cast and tools

Hi Donald
I have compiled the last svn version ( 96 I think)
I have found a problem with the qobject_cast in the loadPlugins and loadTools
functions. I had to change them to dynamic_cast in order the program not to
crash at run time.
Note that in loadTools() ( mainwindow.cpp) and loadEngines() (glwidget.cpp)
you were doing a qobject_cast to type Tool and Engine respectivelty but nor
Tool neither Engine are derived from QObject, so attending to Qt
documentation

T qobject_cast ( QObject * object )
Returns the given object cast to type T if the object is of type T (or of a
subclass); otherwise returns 0.
The class T must inherit (directly or indirectly) QObject and be declared with
the Q_OBJECT macro.

Therefore the right choiche is the standard dynamic_cast

Respect to the new tools (drawing and selectotate)
I like the drawing tool I found it very easy to handle. However, I have a
question about the selection tool. This tools sends a generated display list
to the parent glwidget, so a blue sphere is drawn on atoms. However, I think
that it would be better that the widget in libavogadro do not draw any
selection on screen, process of the selection should be handled by the
clients of the class.

So for instance maybe GLWidget could simply store the list of hits, so for
instance we can do

MySpecialWidget::mousePressEvent( QMouseEvent* e)
{
GLWidget::mousePressEvent(e);
if ( mode == myspecialselectionmode)
{
QList hits= getHits();
ProcessHits(hits);
}
}
or something like that.

Dr. Armando Navarro-Vázquez
RIAIDT. Univdade de Resonancia Magnetica
Universidade de Santiago de Compostela
http://desoft03.usc.es/armando/index.html

(Tue, Jan 09, 2007 at 05:25:16PM +0100) Armando Navarro Vázquez qoajnv@usc.es:

Hi Donald
I have compiled the last svn version ( 96 I think)
I have found a problem with the qobject_cast in the loadPlugins and loadTools
functions. I had to change them to dynamic_cast in order the program not to
crash at run time.
Note that in loadTools() ( mainwindow.cpp) and loadEngines() (glwidget.cpp)
you were doing a qobject_cast to type Tool and Engine respectivelty but nor
Tool neither Engine are derived from QObject, so attending to Qt
documentation

T qobject_cast ( QObject * object )
Returns the given object cast to type T if the object is of type T (or of a
subclass); otherwise returns 0.
The class T must inherit (directly or indirectly) QObject and be declared with
the Q_OBJECT macro.

Therefore the right choiche is the standard dynamic_cast

Hrm, i believe engines and tools should in fact be subclasses of
Q_OBJECT for use with the QT plugin system. I noticed this segfaul
problem when i was using installed versions of the Tools and couldn’t
figure out why. Thanks for the help. I believe i will update them then
change that back to qobject_cast as that is the QT way. You’ll notice
that bsengine is in fact Q_OBJECT subclass.

Respect to the new tools (drawing and selectotate)
I like the drawing tool I found it very easy to handle. However, I have a
question about the selection tool. This tools sends a generated display list
to the parent glwidget, so a blue sphere is drawn on atoms. However, I think
that it would be better that the widget in libavogadro do not draw any
selection on screen, process of the selection should be handled by the
clients of the class.

So for instance maybe GLWidget could simply store the list of hits, so for
instance we can do

MySpecialWidget::mousePressEvent( QMouseEvent* e)
{
GLWidget::mousePressEvent(e);
if ( mode == myspecialselectionmode)
{
QList hits= getHits();
ProcessHits(hits);
}
}

Actually, the selectrotate tool is not generating the display list for
the “selected” atoms. The DL that is generated is for when you click in
an empty area which is not an atom, drag to another area and release.
This DL shows a box representing the area that will be selected. The
actual translucent spheres are generated by the rendering engine (in
this case bsengine). In this case i would argue that in some cases a
plugin needs to have some liberty with the GLWidget and that means
giving them some access to what is drawn on the screen. When the
selectrotate tool gets a “click” or hits it simply goes through each
atom and sets the “selected” flag.

Armando, thanks a bunch. Keep the critisism / input coming.