void RangeProfilePlotManager::updateContextMenu(Subject& subject, const std::string& signal, const boost::any& value) { ContextMenu* pMenu = boost::any_cast<ContextMenu*>(value); if (pMenu == NULL) { return; } QAction* pDiffAction = new QAction("Calculate Difference", pMenu->getActionParent()); VERIFYNRV(mpView); int numSelectedObjects = mpView->getNumSelectedObjects(true); if (numSelectedObjects != 2) { pDiffAction->setEnabled(false); } else { std::list<PlotObject*> objects; mpView->getSelectedObjects(objects, true); for (std::list<PlotObject*>::const_iterator obj = objects.begin(); obj != objects.end(); ++obj) { std::string name; (*obj)->getObjectName(name); if (name == "Difference") { pDiffAction->setEnabled(false); break; } } } VERIFYNR(connect(pDiffAction, SIGNAL(triggered()), this, SLOT(calculateDifferences()))); pMenu->addActionBefore(pDiffAction, "SPECTRAL_RANGEPROFILEPLOT_DIFFERENCE_ACTION", APP_PLOTWIDGET_PRINT_ACTION); QAction* pDelAction = new QAction( (numSelectedObjects > 1) ? "Delete Plots" : "Delete Plot", pMenu->getActionParent()); if (mpView != NULL && numSelectedObjects == 0) { pDelAction->setEnabled(false); } VERIFYNR(connect(pDelAction, SIGNAL(triggered()), this, SLOT(deleteSelectedPlots()))); pMenu->addActionAfter(pDelAction, "SPECTRAL_RANGEPROFILEPLOT_DELETE_ACTION", "SPECTRAL_RANGEPROFILEPLOT_DIFFERENCE_ACTION"); }
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); } }