[Kstars-devel] [kstars] kstars: Refactor observing list popup-menu and simplify code in calling it.

Jasem Mutlaq mutlaqja at ikarustech.com
Thu Dec 11 07:03:47 UTC 2014


Preliminary testing is OK, no issues thus far.

Regards,
Jasem


On Thu, Dec 11, 2014 at 9:11 AM, Akarsh Simha <akarsh.simha at kdemail.net>
wrote:

> Git commit 7df7ecc1a32f15be6627744776df4e22aef0730d by Akarsh Simha.
> Committed on 11/12/2014 at 06:05.
> Pushed by asimha into branch 'master'.
>
> Refactor observing list popup-menu and simplify code in calling it.
>
> Note: I'm copying the list because testing may be necessary. The patch
> is hopefully not controversial.
>
> The observing list popup menu took many parameters to decide which
> options were displayed and which were not. It is much more simple (and
> this can be changed if future needs differ) to accept fewer flags that
> tell the menu the context in which it is being called -- i.e. were
> multiple objects selected? were we in session view or wishlist view?
> is INDI available?
>
> This commit implements these changes and also simplifies the code that
> calls the popup menu.
>
> Importantly, this prevents a crash which involved calling "Eyepiece
> View (Beta)" on multiple objects. Eyepiece view only operates on a
> single object, and hence, it is now not possible to call Eyepiece view
> on multiple objects.
>
> CCMAIL: kstars-devel at kde.org
>
> M  +26   -28   kstars/obslistpopupmenu.cpp
> M  +15   -13   kstars/obslistpopupmenu.h
> M  +10   -23   kstars/tools/observinglist.cpp
>
> http://commits.kde.org/kstars/7df7ecc1a32f15be6627744776df4e22aef0730d
>
> diff --git a/kstars/obslistpopupmenu.cpp b/kstars/obslistpopupmenu.cpp
> index f5127e1..51b4f5d 100644
> --- a/kstars/obslistpopupmenu.cpp
> +++ b/kstars/obslistpopupmenu.cpp
> @@ -31,40 +31,41 @@ ObsListPopupMenu::ObsListPopupMenu()
>
>  ObsListPopupMenu::~ObsListPopupMenu() { }
>
> -void ObsListPopupMenu::initPopupMenu( bool showAddToSession,
> -                                      bool showCenter,
> -                                      bool showDetails,
> -                                      bool showScope,
> -                                      bool showRemove,
> -                                      bool showLinks,
> -                                      bool sessionView )
> +void ObsListPopupMenu::initPopupMenu( bool sessionView, bool
> multiSelection, bool showScope )
>  {
>      KStars* ks = KStars::Instance();
>
>      clear();
> +
>      //Insert item for adding the object to the session view
> -    if( showAddToSession )
> +    if( !sessionView ) {
>          addAction( xi18n( "Add to session plan" ), ks->observingList(),
> SLOT( slotAddToSession() ) );
> -    if( !sessionView )
>          addAction( xi18n( "Add objects visible tonight to session plan"
> ), ks->observingList(), SLOT( slotAddVisibleObj() ) );
> +    }
> +
>      addSeparator();
> -    //Insert item for centering on object
> -    if( showCenter )
> -        addAction( xi18n( "Center" ), ks->observingList(), SLOT(
> slotCenterObject() ) );
> -    //Insert item for Slewing to the object
> -    if( showScope )
> +
> +    if( !multiSelection )
> +        addAction( xi18n( "Center" ), ks->observingList(), SLOT(
> slotCenterObject() ) ); //Insert item for centering on object
> +
> +    if( !multiSelection && showScope ) // Insert item for slewing
> telescope
>          addAction( xi18nc( "Show the selected object in the telescope",
> "Scope" ), ks->observingList(), SLOT( slotSlewToObject() ) );
> +
>      addSeparator();
> -    //Insert item for Showing details dialog
> -    if( showDetails )
> -        addAction( xi18nc( "Show Detailed Information Dialog", "Details"
> ), ks->observingList(), SLOT( slotDetails() ) );
> +
> +
> +    if( !multiSelection ) {
> +        addAction( xi18nc( "Show Detailed Information Dialog", "Details"
> ), ks->observingList(), SLOT( slotDetails() ) ); // Insert item for showing
> details dialog
> +        addAction( xi18n( "Eyepiece view (Beta)" ), ks->observingList(),
> SLOT( slotEyepieceView() ) ); // Insert item for showing eyepiece view
> +    }
> +
>      //Insert item for opening the Altitude vs time dialog
>      addAction( xi18n( "Altitude vs. Time" ), ks->observingList(), SLOT(
> slotAVT() ) );
> -    // Insert item for opening the eyepiece view tool
> -    addAction( xi18n( "Eyepiece view (Beta)" ), ks->observingList(),
> SLOT( slotEyepieceView() ) );
> +
>      addSeparator();
> +
>      //Insert item for dowloading different images
> -    if( showLinks ) {
> +    if( !multiSelection ) {
>          if( ks->observingList()->currentObject() != NULL && !
> ks->observingList()->currentObject()->isSolarSystem() )
>          {
>              addAction( xi18n( "Show SDSS image" ), ks->observingList(),
> SLOT( slotGetImage() ) );
> @@ -73,13 +74,10 @@ void ObsListPopupMenu::initPopupMenu( bool
> showAddToSession,
>          addAction( xi18n( "Show images from web " ), ks->observingList(),
> SLOT( slotGoogleImage() ) );
>          addSeparator();
>      }
> +
>      //Insert item for Removing the object(s)
> -    if( showRemove ) {
> -        if( ! sessionView )
> -            addAction( xi18n("Remove from WishList"),
> ks->observingList(), SLOT( slotRemoveSelectedObjects() ) );
> -        else
> -            addAction( xi18n("Remove from Session Plan"),
> ks->observingList(), SLOT( slotRemoveSelectedObjects() ) );
> -    }
> +    if( !sessionView )
> +        addAction( xi18n("Remove from WishList"), ks->observingList(),
> SLOT( slotRemoveSelectedObjects() ) );
> +    else
> +        addAction( xi18n("Remove from Session Plan"),
> ks->observingList(), SLOT( slotRemoveSelectedObjects() ) );
>  }
> -
> -
> diff --git a/kstars/obslistpopupmenu.h b/kstars/obslistpopupmenu.h
> index ab64662..9cf4d62 100644
> --- a/kstars/obslistpopupmenu.h
> +++ b/kstars/obslistpopupmenu.h
> @@ -21,12 +21,13 @@
>
>  #include <QMenu>
>
> -/**@class ObsListPopupMenu
> -       *The Popup Menu for the observing list in KStars. The menu is
> sensitive to the
> -       *type of selection in the observing list.
> -    *@author Prakash Mohan
> -    *@version 1.0
> -       */
> +/**
> + * @class ObsListPopupMenu
> + * The Popup Menu for the observing list in KStars. The menu is sensitive
> to the
> + * type of selection in the observing list.
> + * @author Prakash Mohan
> + * @version 1.0
> + */
>  class ObsListPopupMenu : public QMenu
>  {
>      Q_OBJECT
> @@ -38,13 +39,14 @@ public:
>      virtual ~ObsListPopupMenu();
>
>      /**Initialize the popup menus. */
> -    void initPopupMenu( bool showAddToSession = false,
> -                        bool showCenter       = false,
> -                        bool showDetails      = false,
> -                        bool showScope        = false,
> -                        bool showRemove       = false,
> -                        bool showLinks        = false,
> -                        bool sessionView      = false );
> +    /**
> +     * @short initializes the popup menu based on the kind of selection
> in the observation planner
> +     * @param sessionView true if we are viewing the session, false if we
> are viewing the wish list
> +     * @param multiSelection true if multiple objects were selected,
> false if a single object was selected
> +     * @param showScope true if we should show INDI/telescope-related
> options, false otherwise.
> +     * @note Showing this popup-menu without a selection may lead to
> crashes.
> +     */
> +    void initPopupMenu( bool sessionView, bool multiSelection, bool
> showScope );
>  };
>
>  #endif
> diff --git a/kstars/tools/observinglist.cpp
> b/kstars/tools/observinglist.cpp
> index f654c62..37515c6 100644
> --- a/kstars/tools/observinglist.cpp
> +++ b/kstars/tools/observinglist.cpp
> @@ -1180,37 +1180,24 @@ bool ObservingList::eventFilter( QObject *obj,
> QEvent *event ) {
>              return true;
>          }
>      }
> -    if( obj == ui->TableView->viewport() && ! noSelection ) {
> -        if( event->type() == QEvent::MouseButtonRelease ) {
> -            QMouseEvent *mouseEvent = static_cast<QMouseEvent* >(event);
> -            if( mouseEvent->button() == Qt::RightButton ) {
> -                QPoint pos( mouseEvent->globalX() , mouseEvent->globalY()
> );
> -                if( singleSelection )
> -                    pmenu->initPopupMenu( true, true, true, showScope,
> true, true );
> -                else
> -                    pmenu->initPopupMenu( true, false, false, false, true
> );
> -                pmenu->popup( pos );
> -                return true;
> -            }
> -        }
> -    }
> +    if( obj == ui->TableView->viewport() || obj ==
> ui->SessionView->viewport() ) {
> +        bool sessionViewEvent = ( obj == ui->SessionView->viewport() );
>
> -    if( obj == ui->SessionView->viewport() && ! noSelection ) {
> -        if( event->type() == QEvent::MouseButtonRelease ) {
> +        if( event->type() == QEvent::MouseButtonRelease  ) { // Mouse
> button release event
>              QMouseEvent *mouseEvent = static_cast<QMouseEvent* >(event);
> +            QPoint pos( mouseEvent->globalX() , mouseEvent->globalY() );
> +
>              if( mouseEvent->button() == Qt::RightButton ) {
> -                QPoint pos( mouseEvent->globalX() , mouseEvent->globalY()
> );
> -                if( singleSelection )
> -                    pmenu->initPopupMenu( false, true, true, showScope,
> true, true, true );
> -                else
> -                    pmenu->initPopupMenu( false, false, false, false,
> true, false, true );
> -                pmenu->popup( pos );
> +                if( !noSelection ) {
> +                    pmenu->initPopupMenu( sessionViewEvent,
> !singleSelection, showScope );
> +                    pmenu->popup( pos );
> +                }
>                  return true;
>              }
>          }
>      }
>
> -    if( obj == ui->TableView || obj == ui->SessionView)
> +    if( obj == ui->TableView || obj == ui->SessionView )
>      {
>          if (event->type() == QEvent::KeyPress)
>          {
>
> _______________________________________________
> Kstars-devel mailing list
> Kstars-devel at kde.org
> https://mail.kde.org/mailman/listinfo/kstars-devel
>



-- 
Best Regards,
Jasem Mutlaq
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kstars-devel/attachments/20141211/02059cfc/attachment-0001.html>


More information about the Kstars-devel mailing list