コード例 #1
0
void SpectralLibraryMatchResults::updateContextMenu(Subject& subject, const std::string& signal,
                                                    const boost::any& value)
{
   ContextMenu* pMenu = boost::any_cast<ContextMenu*>(value);
   if (pMenu == NULL)
   {
      return;
   }

   // only add actions if there are some results
   if (mpTabWidget->count() > 0)
   {
      bool isSessionItem(false);
      if (dynamic_cast<SessionExplorer*>(&subject) != NULL)
      {
         std::vector<SessionItem*> items = pMenu->getSessionItems();
         if (items.size() > 1)                                        // make sure only one item selected
         {
            return;
         }
         DockWindow* pWindow = getDockWindow();
         if (items.front() != pWindow)                             // make sure it's the results window
         {
            return;
         }
         isSessionItem = true;
      }

      QObject* pParent = pMenu->getActionParent();

      // add separator
      QAction* pSeparatorAction = new QAction(pParent);
      pSeparatorAction->setSeparator(true);
      pMenu->addAction(pSeparatorAction, SPECTRAL_LIBRARY_MATCH_RESULTS_SEPARATOR_ACTION);

      QAction* pClearAction = new QAction("&Clear", pParent);
      pClearAction->setAutoRepeat(false);
      pClearAction->setStatusTip("Clears the results from the current page");
      VERIFYNR(connect(pClearAction, SIGNAL(triggered()), this, SLOT(clearPage())));
      pMenu->addAction(pClearAction, SPECTRAL_LIBRARY_MATCH_RESULTS_CLEAR_RESULTS_ACTION);

      QAction* pAutoClearAction = new QAction("&AutoClear", pParent);
      pAutoClearAction->setAutoRepeat(false);
      pAutoClearAction->setCheckable(true);
      pAutoClearAction->setStatusTip("Enable/disable clearing existing results before adding new results");
      ResultsPage* pPage = dynamic_cast<ResultsPage*>(mpTabWidget->currentWidget());
      if (pPage != NULL)
      {
         pAutoClearAction->setChecked(pPage->getAutoClear());
         VERIFYNR(connect(pAutoClearAction, SIGNAL(toggled(bool)), pPage, SLOT(setAutoClear(bool))));
         pMenu->addAction(pAutoClearAction, SPECTRAL_LIBRARY_MATCH_RESULTS_AUTOCLEAR_ACTION);
      }

      QAction* pExpandAllAction = new QAction("&Expand All", pParent);
      pExpandAllAction->setAutoRepeat(false);
      pExpandAllAction->setStatusTip("Expands all the results nodes on the current page");
      VERIFYNR(connect(pExpandAllAction, SIGNAL(triggered()), this, SLOT(expandAllPage())));
      pMenu->addAction(pExpandAllAction, SPECTRAL_LIBRARY_MATCH_RESULTS_EXPAND_ALL_ACTION);

      QAction* pCollapseAllAction = new QAction("&Collapse All", pParent);
      pCollapseAllAction->setAutoRepeat(false);
      pCollapseAllAction->setStatusTip("Collapses all the results nodes on the current page");
      VERIFYNR(connect(pCollapseAllAction, SIGNAL(triggered()), this, SLOT(collapseAllPage())));
      pMenu->addAction(pCollapseAllAction, SPECTRAL_LIBRARY_MATCH_RESULTS_COLLAPSE_ALL_ACTION);

      QAction* pDeleteTabAction = new QAction("&Delete Page", pParent);
      pDeleteTabAction->setAutoRepeat(false);
      pDeleteTabAction->setStatusTip("Deletes the current page");
      VERIFYNR(connect(pDeleteTabAction, SIGNAL(triggered()), this, SLOT(deletePage())));
      pMenu->addAction(pDeleteTabAction, SPECTRAL_LIBRARY_MATCH_RESULTS_DELETE_PAGE_ACTION);

      if (isSessionItem == false)
      {
         QAction* pLocateAction = new QAction("&Locate Signatures", pParent);
         pLocateAction->setAutoRepeat(false);
         pLocateAction->setStatusTip("Locates the selected Signatures in the spatial data view");
         VERIFYNR(connect(pLocateAction, SIGNAL(triggered()), this, SLOT(locateSignaturesInScene())));
         pMenu->addAction(pLocateAction, SPECTRAL_LIBRARY_MATCH_RESULTS_LOCATE_ACTION);
         QAction* pCreateAverageAction = new QAction("&Create average Signature", pParent);
         pCreateAverageAction->setAutoRepeat(false);
         pCreateAverageAction->setStatusTip("Creates an average Signature from the selected "
            "Signatures in the spatial data view");
         VERIFYNR(connect(pCreateAverageAction, SIGNAL(triggered()), this, SLOT(createAverageSignature())));
         pMenu->addAction(pCreateAverageAction, SPECTRAL_LIBRARY_MATCH_RESULTS_CREATE_AVERAGE_ACTION);
      }
   }
}
コード例 #2
0
void HistogramWindowImp::updateContextMenu(Subject& subject, const string& signal, const boost::any& value)
{
   ContextMenu* pMenu = boost::any_cast<ContextMenu*>(value);
   if (pMenu == NULL)
   {
      return;
   }

   bool bAddActions = false;
   bool bRemoveActions = false;
   PlotWidget* pActionWidget = NULL;

   if (dynamic_cast<SessionExplorer*>(&subject) != NULL)
   {
      // Make sure all of the selected session items for the menu are plot widgets
      vector<SessionItem*> items = pMenu->getSessionItems();
      vector<PlotWidget*> plots = pMenu->getSessionItems<PlotWidget>();
      if (plots.size() != items.size())
      {
         return;
      }

      // Make sure all selected plot widget items are contained in this plot set
      vector<PlotWidget*>::iterator iter;
      for (iter = plots.begin(); iter != plots.end(); ++iter)
      {
         PlotWidget* pPlot = *iter;
         if (pPlot != NULL)
         {
            if (mpPlotSetGroup->containsPlot(pPlot) == true)
            {
               if (plots.size() == 1)
               {
                  bAddActions = true;
                  pActionWidget = pPlot;
               }

               HistogramPlotImp* pHistogramPlot = dynamic_cast<HistogramPlotImp*>(pPlot->getPlot());
               if (pHistogramPlot != NULL)
               {
                  if (pHistogramPlot->getLayer() != NULL)
                  {
                     bRemoveActions = true;
                  }
               }
            }
            else
            {
               return;
            }
         }
      }
   }
   else if (dynamic_cast<HistogramWindowImp*>(&subject) == this)
   {
      if (mpPlotSetGroup->getNumPlotSets() > 0)
      {
         bRemoveActions = true;
      }
   }
   else
   {
      PlotWidget* pPlotWidget = dynamic_cast<PlotWidget*>(&subject);
      if ((pPlotWidget != NULL) && (mpPlotSetGroup->containsPlot(pPlotWidget) == true))
      {
         bAddActions = true;
         pActionWidget = pPlotWidget;
      }
   }

   // Add the sync zoom action
   if ((bAddActions == true) && (pActionWidget != NULL))
   {
      HistogramPlotImp* pHistogramPlot = dynamic_cast<HistogramPlotImp*>(pActionWidget->getPlot());
      if (pHistogramPlot != NULL)
      {
         RasterLayer* pLayer = dynamic_cast<RasterLayer*>(pHistogramPlot->getLayer());
         if ((pLayer != NULL) && (pHistogramPlot->getRasterChannelType() != GRAY))
         {
            mpSyncAutoZoomAction->setData(QVariant::fromValue(dynamic_cast<SessionItem*>(pHistogramPlot)));
            pMenu->addActionBefore(mpSyncAutoZoomAction, APP_HISTOGRAMPLOT_SYNCHRONIZE_AUTO_ZOOM_ACTION,
               APP_HISTOGRAMPLOT_RASTER_MENUS_SEPARATOR_ACTION);
         }
      }
   }

   // Remove the delete action
   if (bRemoveActions == true)
   {
      pMenu->removeAction(APP_PLOTSET_DELETE_ACTION);
   }

   // Add statistics actions
   if (bAddActions)
   {
      pMenu->addActionBefore(mpStatisticsShowAction, APP_HISTOGRAMPLOT_STATISTICS_ACTION,
         APP_HISTOGRAMPLOT_REFRESH_STATISTICS_ACTION);
   }
}
コード例 #3
0
ファイル: PlotSetImp.cpp プロジェクト: Tom-VdE/opticks
void PlotSetImp::updateContextMenu(Subject& subject, const string& signal, const boost::any& value)
{
   ContextMenu* pMenu = boost::any_cast<ContextMenu*>(value);
   if (pMenu == NULL)
   {
      return;
   }

   QObject* pParent = pMenu->getActionParent();
   vector<SessionItem*> items = pMenu->getSessionItems();

   if (items.empty() == true)
   {
      return;
   }

   bool bAddSeparator = false;
   bool bAddActivate = false;
   bool bAddDelete = false;
   string afterId;

   vector<DockWindow*> windowItems = pMenu->getSessionItems<DockWindow>();
   if (windowItems.size() == 1)
   {
      DockWindow* pDockWindow = windowItems.front();
      if (pDockWindow != NULL)
      {
         PlotSetGroup* pPlotSetGroup = dynamic_cast<PlotSetGroup*>(pDockWindow->getWidget());
         if (pPlotSetGroup != NULL)
         {
            if (dynamic_cast<PlotSetImp*>(pPlotSetGroup->getCurrentPlotSet()) == this)
            {
               bAddSeparator = true;
               bAddDelete = true;
            }
         }
      }
   }
   else if (dynamic_cast<SessionExplorer*>(&subject) != NULL)
   {
      // Make sure all of the selected session items for the menu are plot widgets
      vector<PlotWidget*> plots = pMenu->getSessionItems<PlotWidget>();
      if (plots.size() != items.size())
      {
         return;
      }

      // Make sure all selected plot widget items are contained in this plot set
      vector<PlotWidget*>::iterator iter;
      for (iter = plots.begin(); iter != plots.end(); ++iter)
      {
         PlotWidget* pPlot = *iter;
         if (pPlot != NULL)
         {
            if (containsPlot(pPlot) == false)
            {
               return;
            }
         }
      }

      // Check for only one selected plot widget item
      if (plots.size() == 1)
      {
         bAddSeparator = true;

         // Add an activate action if the selected plot widget is not currently active
         PlotWidget* pPlot = plots.front();
         if (pPlot != NULL)
         {
            if (pPlot != getCurrentPlot())
            {
               bAddActivate = true;
            }
         }
      }

      bAddDelete = true;
      afterId = APP_PLOTWIDGET_PRINT_ACTION;
   }

   // Separator
   if (bAddSeparator == true)
   {
      QAction* pSeparatorAction = new QAction(pParent);
      pSeparatorAction->setSeparator(true);
      pMenu->addActionAfter(pSeparatorAction, APP_PLOTSET_SEPARATOR_ACTION, afterId);

      if (afterId.empty() == false)
      {
         afterId = APP_PLOTSET_SEPARATOR_ACTION;
      }
   }

   // Activate
   if (bAddActivate == true)
   {
      QAction* pActivateAction = new QAction("&Activate", pParent);
      pActivateAction->setAutoRepeat(false);
      pActivateAction->setStatusTip("Activates the selected plot in the plot set");
      VERIFYNR(connect(pActivateAction, SIGNAL(triggered()), this, SLOT(activateSelectedPlot())));
      pMenu->addActionAfter(pActivateAction, APP_PLOTSET_ACTIVATE_ACTION, afterId);

      if (afterId.empty() == false)
      {
         afterId = APP_PLOTSET_ACTIVATE_ACTION;
      }
   }

   // Delete
   if (bAddDelete == true)
   {
      QAction* pDeleteAction = new QAction(QIcon(":/icons/Delete"), "&Delete", pParent);
      pDeleteAction->setAutoRepeat(false);
      VERIFYNR(connect(pDeleteAction, SIGNAL(triggered()), this, SLOT(destroyCurrentPlot())));
      pMenu->addActionAfter(pDeleteAction, APP_PLOTSET_DELETE_ACTION, afterId);
   }
}