[Marble-devel] Measure render plugin - context menu

Dennis Nienhüser earthwings at gentoo.org
Fri Nov 25 09:35:48 UTC 2011


Hi Mike,

On 25.11.2011 02:24, mikehenning at eclipse.net wrote:
> Hello, I'm a student in the Google Code-in competition. I've taken the
> task to move Marble's Measure Tool into a plugin.
>
> So far, I've made some progress - using the example plugin, I've been able
> to move the measure tool rendering into a plugin. I know the drawing code
> works because I called addMeasurePoint() in the constructor to have some
> points to draw.

sounds great :-)

>
> The problem I have now is that I can't figure out how to add the Add
> Measure Point item to the right click menu from within the plugin.
>
> I don't see any API that allows me to do this from the plugin. Am I
> missing someting?

Right now we don't have an API call for plugins to access the 
MarbleWidget. While I expect this to be added at some point, many 
plugins work around this right now by overloading the virtual protected 
bool eventFilter() like this:

bool MyPlugin::eventFilter( QObject *object, QEvent *e )
{
     if ( m_marbleWidget || !enabled() || !visible() ) {
         return AbstractFloatItem::eventFilter( object, e );
     }

     MarbleWidget *widget = qobject_cast<MarbleWidget*>( object );

     if ( widget ) {
         m_marbleWidget = widget;
     }

     return AbstractFloatItem::eventFilter( object, e );
}

See for example the Speedometer plugin. I'd suggest you do the same.

Once you have the widget, you can retrieve the popup menu with its 
MarbleWidgetPopupMenu *popupMenu() method. From it you can call void 
addAction( Qt::MouseButton button, QAction* action );

If you get linker errors, please change
class MarbleWidgetPopupMenu  : public QObject
to
class MARBLE_EXPORT MarbleWidgetPopupMenu  : public QObject
in MarbleWidgetPopupMenu.h and also #include "marble_export.h"

Also make sure to #include "MarbleWidget.h" and #include 
"MarbleWidgetPopupMenu.h" in your plugin to avoid problems with forward 
declarations.

One thing we should think about is how to reset the context menu in case 
the plugin gets disabled by the user. Possibly we need to extend the 
MarbleWidgetPopupMenu API to allow plugins to remove (their) actions as 
well.

Regards,
Dennis

>
> I suppose I could create a very simple API to do that. Otherwise, if I
> leave the menu code in the application, that seems to defeat the purpose
> of the plugin.
> As an ugly fix, I could steal the middle mouse button events, and use
> those to create a context menu.
>
> I'm open to suggestions.
>
> Thanks,
>    Mike H.
> _______________________________________________
> Marble-devel mailing list
> Marble-devel at kde.org
> https://mail.kde.org/mailman/listinfo/marble-devel
>



More information about the Marble-devel mailing list