Exemple #1
0
PlotWidget* PlotSetImp::createPlot(const QString& strPlotName, const PlotType& plotType)
{
   if (strPlotName.isEmpty() == true)
   {
      return NULL;
   }

   // Do not create the plot if a plot with the given name already exists
   PlotWidget* pPlot = getPlot(strPlotName);
   if (pPlot != NULL)
   {
      return NULL;
   }

   // Create the plot widget
   pPlot = new PlotWidgetAdapter(SessionItemImp::generateUniqueId(), strPlotName.toStdString(), plotType,
      dynamic_cast<PlotSet*>(this), this);
   if (pPlot != NULL)
   {
      // Block undo actions from being added to the plot view
      PlotViewImp* pPlotView = dynamic_cast<PlotViewImp*>(pPlot->getPlot());
      if (pPlotView != NULL)
      {
         pPlotView->blockUndo();
      }

      // Add the plot widget to the plot set
      addPlot(pPlot);
   }

   return pPlot;
}
PlotWidget* HistogramWindowImp::getPlot(RasterLayer* pLayer, RasterChannelType channel, bool ignoreStatisticsPlots) const
{
   if (pLayer == NULL)
   {
      return NULL;
   }

   // Iterate over all histogram plots on all plot sets to find the plot
   vector<PlotWidget*> plots = mpPlotSetGroup->getPlots(HISTOGRAM_PLOT);
   for (vector<PlotWidget*>::iterator iter = plots.begin(); iter != plots.end(); ++iter)
   {
      PlotWidget* pPlot = *iter;
      if (pPlot != NULL)
      {
         HistogramPlotImp* pHistogramPlot = dynamic_cast<HistogramPlotImp*>(pPlot->getPlot());
         if (pHistogramPlot != NULL && (!ignoreStatisticsPlots || !pHistogramPlot->ownsStatistics()))
         {
            RasterLayer* pCurrentLayer = dynamic_cast<RasterLayer*>(pHistogramPlot->getLayer());
            if (pCurrentLayer == pLayer)
            {
               RasterChannelType currentChannel = pHistogramPlot->getRasterChannelType();
               if (currentChannel == channel)
               {
                  return pPlot;
               }
            }
         }
      }
   }

   return NULL;
}
Exemple #3
0
void MainWindow::on_actionRemove_plot_triggered()
{
    QAction * action = qobject_cast<QAction *>(sender());
    PlotWidget * plot =qobject_cast<PlotWidget*>
            (action->property("Plot").value<QWidget*>());

    Q_ASSERT(plot);

    PlotList.removeOne(plot);
    plot->deleteLater();
}
Exemple #4
0
void MainWindow::on_actionEdit_plot_triggered()
{
    QAction * action = qobject_cast<QAction *>(sender());
    PlotWidget * plot =qobject_cast<PlotWidget*>
            (action->property("Plot").value<QWidget*>());

    Q_ASSERT(plot);

    PlotConfigurationDialog dlg(*plot,variables,this);
    if(dlg.exec() == QDialog::Accepted)
    {
        plot->replot();
    }
}
Exemple #5
0
void MainWindow::on_actionAdd_new_plot_triggered()
{
    PlotWidget * plot = new PlotWidget(this);

    PlotConfigurationDialog dlg(*plot,variables,this);
    if (dlg.exec() == QDialog::Accepted)
    {
        connect(plot,SIGNAL(customContextMenuRequested(QPoint)),this,
                SLOT(PlotContextMenuRequest(QPoint)));
        PlotList.push_back(plot);
        GraphSplitter->addWidget(plot);
        //connect(this,SIGNAL(TimerStart()),plot,SLOT(Start()));
    }
    else
    {
        plot->deleteLater();
    }
}
void CanvasPicker::move( const QPoint &pos )
{
	if( !m_dragAndDropInProgress )
		return;

	PlotWidget* plotWidget = dynamic_cast<PlotWidget*>( plot() );

	switch( m_typeOfItemsToDrag )
	{
	case Globals::Rtti_PlotMarker:
		{
			const double dX = plot()->invTransform( QwtPlot::xBottom, pos.x() ) - plot()->invTransform( QwtPlot::xBottom, m_previousPoint.x() );
			const double dY = plot()->invTransform( QwtPlot::yLeft, pos.y() ) - plot()->invTransform( QwtPlot::yLeft, m_previousPoint.y() );

			QList<QwtPlotItem*>& listOfSelectedMarkers = plotWidget->listOfSelectedItems( Globals::Rtti_PlotMarker );

			foreach( QwtPlotItem* item, listOfSelectedMarkers )
			{
				MarkerItem* markerItem = dynamic_cast<MarkerItem*>( item );
				markerItem->setValue(  markerItem->xValue() + dX, markerItem->yValue() + dY );
				emit dataChanged( markerItem );
			}

			break;
		}
	case Globals::Rtti_PlotKnot:
		{
			const double dX = plot()->invTransform( QwtPlot::xBottom, pos.x() ) - plot()->invTransform( QwtPlot::xBottom, m_previousPoint.x() );

			QList<QwtPlotItem*>& listOfSelectedKnots = plotWidget->listOfSelectedItems( Globals::Rtti_PlotKnot );

			foreach( QwtPlotItem* item, listOfSelectedKnots )
			{
				KnotItem* knotItem = dynamic_cast<KnotItem*>( item );
				if( knotItem->isEditAllowed() )
				{
					knotItem->setCoordinate( knotItem->coordinate() + dX );
					emit dataChanged( knotItem );
				}
			}

			break;
		}
PlotWidget* HistogramWindowImp::getPlot(Layer* pLayer) const
{
   if (pLayer == NULL)
   {
      return NULL;
   }

   RasterLayer* pRasterLayer = dynamic_cast<RasterLayer*>(pLayer);
   if (pRasterLayer != NULL)
   {
      RasterChannelType channel = GRAY;
      if (pRasterLayer->getDisplayMode() == RGB_MODE)
      {
         channel = RED;
      }

      return getPlot(pRasterLayer, channel);
   }

   // Iterate over all histogram plots on all plot sets to find the plot
   vector<PlotWidget*> plots = mpPlotSetGroup->getPlots(HISTOGRAM_PLOT);
   for (vector<PlotWidget*>::iterator iter = plots.begin(); iter != plots.end(); ++iter)
   {
      PlotWidget* pPlot = *iter;
      if (pPlot != NULL)
      {
         HistogramPlotImp* pHistogramPlot = dynamic_cast<HistogramPlotImp*>(pPlot->getPlot());
         if (pHistogramPlot != NULL)
         {
            Layer* pCurrentLayer = pHistogramPlot->getLayer();
            if (pCurrentLayer == pLayer)
            {
               return pPlot;
            }
         }
      }
   }

   return NULL;
}
Exemple #8
0
void GetPlotWidget::populateTreeWidgetItem(QTreeWidgetItem* pRoot)
{
   VERIFYNR(pRoot != NULL);
   std::vector<Window*> windows;
   Service<DesktopServices>()->getWindows(PLOT_WINDOW, windows);
   for (std::vector<Window*>::const_iterator iter = windows.begin(); iter != windows.end(); ++iter)
   {
      PlotWindow* pPlotWindow = dynamic_cast<PlotWindow*>(*iter);
      if (pPlotWindow == NULL)
      {
         continue;
      }

      std::vector<PlotWidget*> plots;
      pPlotWindow->getPlots(plots);
      for (std::vector<PlotWidget*>::const_iterator plotIter = plots.begin(); plotIter != plots.end(); ++plotIter)
      {
         PlotWidget* pPlotWidget = *plotIter;
         if (pPlotWidget == NULL)
         {
            continue;
         }

         QTreeWidgetItem* pChild = new QTreeWidgetItem;
         std::string name = pPlotWidget->getDisplayName();
         if (name.empty() == true)
         {
            name = pPlotWidget->getName();
         }

         pChild->setText(GetSessionItemBase<PlotWidget>::NameColumn, QString::fromStdString(name));
         pChild->setData(GetSessionItemBase<PlotWidget>::NameColumn,
            GetSessionItemBase<PlotWidget>::SessionItemRole, QVariant::fromValue<void*>(pPlotWidget));
         pChild->setText(GetSessionItemBase<PlotWidget>::TypeColumn,
            QString::fromStdString(TypeConverter::toString<PlotWidget>()));
         pChild->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
         pRoot->addChild(pChild);
      }
   }
}
Exemple #9
0
vector<PlotWidget*> PlotSetImp::getPlots(const PlotType& plotType) const
{
   vector<PlotWidget*> plots;
   for (int i = 0; i < count(); i++)
   {
      PlotWidget* pPlot = dynamic_cast<PlotWidget*>(widget(i));
      if (pPlot != NULL)
      {
         PlotView* pPlotView = pPlot->getPlot();
         if (pPlotView != NULL)
         {
            PlotType currentType = pPlotView->getPlotType();
            if (currentType == plotType)
            {
               plots.push_back(pPlot);
            }
         }
      }
   }

   return plots;
}
Exemple #10
0
PlotWidget* PlotSetImp::getPlot(const QString& strPlotName) const
{
   if (strPlotName.isEmpty() == true)
   {
      return NULL;
   }

   for (int i = 0; i < count(); i++)
   {
      PlotWidget* pPlotWidget = dynamic_cast<PlotWidget*>(widget(i));
      if (pPlotWidget != NULL)
      {
         QString strCurrentName = QString::fromStdString(pPlotWidget->getName());
         if (strCurrentName == strPlotName)
         {
            return pPlotWidget;
         }
      }
   }

   return NULL;
}
bool PicturesPlotWidgetExporter::generateImage(QImage &image)
{
   PlotWidget* pPlotWidget = dynamic_cast<PlotWidget*>(mpItem);
   if (pPlotWidget == NULL)
   {
      return false;
   }

   bool presizedImage = !image.isNull();
   QSize outputSize = image.size();
   pPlotWidget->getCurrentImage(image);
   // we just scale the plot...there's not "hidden" data that's not rendered at
   // a smaller scale like in a spatial data view. if the output size is very large
   // this could result in some aliasing and jaggies...if this becomes a problem
   // for users, we can deal with that situation later.
   if (presizedImage)
   {
      image = image.scaled(outputSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
   }

   return true;
}
bool PropertiesClassification::applyChanges()
{
   ClassificationWidget* pClassificationPage = dynamic_cast<ClassificationWidget*>(getWidget());
   VERIFY(pClassificationPage != NULL);

   bool success = pClassificationPage->applyChanges();
   if (success == false)
   {
      return false;
   }

   DataElement* pElement = dynamic_cast<DataElement*>(getSessionItem());
   if (pElement != NULL)
   {
      pElement->setClassification(mpClassification.get());
   }
   else
   {
      View* pView = dynamic_cast<View*>(getSessionItem());
      if (pView != NULL)
      {
         pView->setClassification(mpClassification.get());
      }
      else
      {
         PlotWidget* pPlotWidget = dynamic_cast<PlotWidget*>(getSessionItem());
         if (pPlotWidget != NULL)
         {
            pPlotWidget->setClassification(mpClassification.get());
         }
         else
         {
            return false;
         }
      }
   }

   return true;
}
bool PropertiesClassification::initialize(SessionItem* pSessionItem)
{
   ClassificationWidget* pClassificationPage = dynamic_cast<ClassificationWidget*>(getWidget());
   if (pClassificationPage == NULL)
   {
      return false;
   }

   DataElement* pElement = dynamic_cast<DataElement*>(pSessionItem);
   if (pElement != NULL)
   {
      mpClassification->setClassification(pElement->getClassification());
   }
   else
   {
      View* pView = dynamic_cast<View*>(pSessionItem);
      if (pView != NULL)
      {
         mpClassification->setClassification(pView->getClassification());
      }
      else
      {
         PlotWidget* pPlotWidget = dynamic_cast<PlotWidget*>(pSessionItem);
         if (pPlotWidget != NULL)
         {
            mpClassification->setClassification(pPlotWidget->getClassification());
         }
         else
         {
            return false;
         }
      }
   }

   pClassificationPage->setClassification(mpClassification.get());
   return PropertiesShell::initialize(pSessionItem);
}
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);
   }
}
GraphicImageWidget::GraphicImageWidget(QWidget* pParent) :
   QWidget(pParent)
{
   // Image File
   mpFileLabel = new QLabel("Filename:", this);
   mpFileBrowser = new FileBrowser(this);

   // Image widget
   mpWidgetLabel = new QLabel("Plot Window:", this);
   mpWidgetCombo = new QComboBox(this);
   mpWidgetCombo->setEditable(false);

   // Opacity
   mpOpacityLabel = new QLabel("Opacity:", this);
   mpOpacitySpin = new QSpinBox(this);
   mpOpacitySpin->setRange(0, 100);
   mpOpacitySpin->setSuffix("%");

   // Layout
   QGridLayout* pGrid = new QGridLayout(this);
   pGrid->setMargin(0);
   pGrid->setSpacing(5);
   pGrid->addWidget(mpFileLabel, 0, 0);
   pGrid->addWidget(mpFileBrowser, 0, 1);
   pGrid->addWidget(mpWidgetLabel, 1, 0);
   pGrid->addWidget(mpWidgetCombo, 1, 1);
   pGrid->addWidget(mpOpacityLabel, 2, 0);
   pGrid->addWidget(mpOpacitySpin, 2, 1, Qt::AlignLeft);
   pGrid->setRowStretch(3, 10);
   pGrid->setColumnStretch(1, 10);

   // Initialization
   const Filename* pSupportFilesPath = ConfigurationSettings::getSettingSupportFilesPath();
   if (pSupportFilesPath != NULL)
   {
      QString browseDir = QString::fromStdString(pSupportFilesPath->getFullPathAndName() + SLASH + "Annotation");
      mpFileBrowser->setBrowseDirectory(browseDir);
   }

   mpFileBrowser->setBrowseFileFilters("Image Files (*.bmp *.jpg);;All Files (*)");

   Service<DesktopServices> pDesktop;

   vector<Window*> dockWindows;
   pDesktop->getWindows(DOCK_WINDOW, dockWindows);
   for (vector<Window*>::iterator iter = dockWindows.begin(); iter != dockWindows.end(); ++iter)
   {
      DockWindowImp* pWindow = dynamic_cast<DockWindowImp*>(*iter);
      if ((pWindow != NULL) && (pWindow->isVisible() == true))
      {
         PlotSetGroup* pPlotSetGroup = dynamic_cast<PlotSetGroup*>(pWindow->getWidget());
         if (pPlotSetGroup != NULL)
         {
            const string& name = pWindow->getDisplayName(true);
            if (name.empty() == false)
            {
               QString windowName = QString::fromStdString(name);
               mpWidgetCombo->addItem(windowName);

               PlotWidget* pPlotWidget = pPlotSetGroup->getCurrentPlot();
               if (pPlotWidget != NULL)
               {
                  mWidgets.insert(windowName, pPlotWidget->getWidget());
               }
            }
         }
      }
   }

   setImageSource(RAW_DATA);

   // Connections
   VERIFYNR(connect(mpFileBrowser, SIGNAL(filenameChanged(const QString&)), this,
      SIGNAL(imageFileChanged(const QString&))));
   VERIFYNR(connect(mpWidgetCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(notifyImageWidgetChange())));
   VERIFYNR(connect(mpOpacitySpin, SIGNAL(valueChanged(int)), this, SIGNAL(opacityChanged(int))));
}
bool PropertiesPlotView::initialize(SessionItem* pSessionItem)
{
   mpPlotView = dynamic_cast<PlotView*>(pSessionItem);
   if (mpPlotView == NULL)
   {
      PlotWidget* pPlotWidget = dynamic_cast<PlotWidget*>(pSessionItem);
      if (pPlotWidget != NULL)
      {
         mpPlotView = pPlotWidget->getPlot();
      }

      if (mpPlotView == NULL)
      {
         return false;
      }
   }

   // Gridlines
   CartesianPlot* pCartesianPlot = dynamic_cast<CartesianPlot*>(mpPlotView);
   if (pCartesianPlot != NULL)
   {
      Gridlines* pHorizGridlines = pCartesianPlot->getGridlines(HORIZONTAL);
      Gridlines* pVertGridlines = pCartesianPlot->getGridlines(VERTICAL);

      if ((pHorizGridlines != NULL) && (pVertGridlines != NULL))
      {
         LineStyle lineStyle = pHorizGridlines->getLineStyle();
         if (pVertGridlines->getLineStyle() == lineStyle)
         {
            mpStyleCombo->setCurrentValue(lineStyle);
         }

         int lineWidth = pHorizGridlines->getLineWidth();
         if (pVertGridlines->getLineWidth() == lineWidth)
         {
            mpWidthCombo->setCurrentValue(lineWidth);
         }

         ColorType gridlineColor = pHorizGridlines->getColor();
         if (pVertGridlines->getColor() == gridlineColor)
         {
            mpColorButton->setColor(gridlineColor);
         }

         return true;
      }
   }

   PolarPlot* pPolarPlot = dynamic_cast<PolarPlot*>(mpPlotView);
   if (pPolarPlot != NULL)
   {
      Gridlines* pGridlines = pPolarPlot->getGridlines();
      if (pGridlines != NULL)
      {
         mpStyleCombo->setCurrentValue(pGridlines->getLineStyle());
         mpWidthCombo->setCurrentValue(pGridlines->getLineWidth());
         mpColorButton->setColor(pGridlines->getColor());
         return true;
      }
   }

   return false;
}
void CanvasPicker::select( const QPoint &pos, Qt::KeyboardModifiers modifiers )
{
	m_selectionPoint = pos;
	m_previousPoint = pos;

    double minDistanceMarkers = 10e10;
	double minDistanceKnots = 10e10;

	MarkerItem* markerWithMinDistance = 0;
	KnotItem* knotWithMinDistance = 0;

	int selectionType = -1;

	PlotWidget* plotWidget = dynamic_cast<PlotWidget*>( plot() );

	const QwtScaleMap xMap = plot()->canvasMap( QwtPlot::xBottom );
    const QwtScaleMap yMap = plot()->canvasMap( QwtPlot::yLeft );

    const QwtPlotItemList& itemList = plot()->itemList();
    for ( QwtPlotItemIterator it = itemList.begin(); it != itemList.end(); ++it )
    {
        if ( ( *it )->rtti() == Globals::Rtti_PlotMarker )
        {
            MarkerItem* marker = static_cast<MarkerItem*>( *it );

			const double deltaX = xMap.transform( marker->xValue() ) - pos.x();
			const double deltaY = yMap.transform( marker->yValue() ) - pos.y();
			const double distance = qSqrt( qwtSqr( deltaX ) + qwtSqr( deltaY ) );
            if ( distance < minDistanceMarkers )
			{
				minDistanceMarkers = distance;
				markerWithMinDistance = marker;
			}
		}
		else if ( ( *it )->rtti() == Globals::Rtti_PlotKnot )
		{
			KnotItem* knot = static_cast<KnotItem*>( *it );

			const double distance = qAbs( xMap.transform( knot->coordinate() ) - pos.x() );

			if( distance < minDistanceKnots )
			{
				minDistanceKnots = distance;
				knotWithMinDistance = knot;
			}
		}
    }

	// Give a priority to the markers
	if( minDistanceMarkers < Globals::SELECTION_PIXEL_TOLERANCE && markerWithMinDistance != 0 )
	{
		m_itemToPick = markerWithMinDistance;
		selectionType = Globals::Rtti_PlotMarker;
	}
	else if(  minDistanceKnots < Globals::SELECTION_PIXEL_TOLERANCE && knotWithMinDistance != 0 )
	{
		m_itemToPick = knotWithMinDistance;
		selectionType = Globals::Rtti_PlotKnot;
	}

	if( selectionType == -1 )
	{
		emit picked( modifiers, 0 );
		return;
	}

	QList<QwtPlotItem*>& listOfSelectedItems = plotWidget->listOfSelectedItems( selectionType );

	if( listOfSelectedItems.count() == 0 )
	{
		// Select and allow the user to drag and drop.
		emit picked( modifiers, m_itemToPick );

		m_typeOfItemsToDrag = selectionType;
		m_dragAndDropInProgress = true;
		m_itemToPick = 0;
	}
	else
	{
		if( listOfSelectedItems.contains( m_itemToPick ) )
		{
			// We don't know yet whether the user wants to do a selection or a drag and drop operation.
			// The picking operation will be detected in CanvasPicker::release().

			m_typeOfItemsToDrag = selectionType;
			m_dragAndDropInProgress = true;
		}
		else
		{
			emit picked( modifiers, m_itemToPick );
			m_itemToPick = 0;

			if( listOfSelectedItems.count() == 1 )
			{
				m_typeOfItemsToDrag = selectionType;
				m_dragAndDropInProgress = true;
			}
		}
	}
}