瀏覽代碼

Merge branch 'ctkvtkchartview-removeplot'

* ctkvtkchartview-removeplot:
  Add utility functions to remove plots from chart
Julien Finet 13 年之前
父節點
當前提交
f57077ea85
共有 2 個文件被更改,包括 52 次插入0 次删除
  1. 39 0
      Libs/Visualization/VTK/Widgets/ctkVTKChartView.cpp
  2. 13 0
      Libs/Visualization/VTK/Widgets/ctkVTKChartView.h

+ 39 - 0
Libs/Visualization/VTK/Widgets/ctkVTKChartView.cpp

@@ -225,6 +225,45 @@ void ctkVTKChartView::addPlot(vtkPlot* plot)
 }
 
 // ----------------------------------------------------------------------------
+void ctkVTKChartView::removePlot(vtkPlot* plot)
+{
+  Q_D(ctkVTKChartView);
+  vtkIdType index = this->plotIndex(plot);
+  if (index == vtkIdType(-1))
+    {
+    return;
+    }
+  d->Chart->RemovePlot(index);
+  emit this->plotRemoved(plot);
+  this->onChartUpdated();
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKChartView::removeAllPlots()
+{
+  Q_D(ctkVTKChartView);
+  while(d->Chart->GetNumberOfPlots() > 0)
+    {
+    this->removePlot(d->Chart->GetPlot(0));
+    }
+}
+
+// ----------------------------------------------------------------------------
+vtkIdType ctkVTKChartView::plotIndex(vtkPlot* plot)
+{
+  Q_D(ctkVTKChartView);
+  // GetPlotIndex is missing from vtkChart API
+  for (vtkIdType i = 0; i < d->Chart->GetNumberOfPlots(); ++i)
+    {
+    if (plot == d->Chart->GetPlot(i))
+      {
+      return i;
+      }
+    }
+  return -1;
+}
+
+// ----------------------------------------------------------------------------
 void ctkVTKChartView::onChartUpdated()
 {
   Q_D(ctkVTKChartView);

+ 13 - 0
Libs/Visualization/VTK/Widgets/ctkVTKChartView.h

@@ -46,8 +46,20 @@ public:
   virtual ~ctkVTKChartView();
 
   /// Generic function to add a custom plot. \a plot is added into the chart
+  /// Emit the plotAdded(vtkPlot*) signal.
   virtual void addPlot(vtkPlot* plot);
 
+  /// Remove the plot from the chart. Do nothing if plot is not in the chart.
+  /// Emit the plotRemoved(vtkPlot*) signal.
+  virtual void removePlot(vtkPlot* plot);
+
+  /// Remove all the plots from the chart
+  void removeAllPlots();
+
+  /// Return the id of the plot in the chart.
+  /// -1 if the plot is not found in the chart
+  vtkIdType plotIndex(vtkPlot* plot);
+
   /// Utility function that returns the view chart. It can be used for customizing
   /// the chart display options (axes, legend...)
   vtkChartXY* chart()const;
@@ -77,6 +89,7 @@ public:
 
 Q_SIGNALS:
   void plotAdded(vtkPlot* plot);
+  void plotRemoved(vtkPlot* plot);
   /// Fired anytime the bound of a plot modifies the overal bounds
   void boundsChanged();
   /// Fired anytime an axis is modified.