Procházet zdrojové kódy

Unnecessary boundsChanged signals

If we have a zoomed view, and we set the same function to
the plots, it was resetting the bounds to the axes.
Julien Finet před 14 roky
rodič
revize
d1385e4f66

+ 24 - 3
Libs/Visualization/VTK/Widgets/ctkVTKChartView.cpp

@@ -54,6 +54,7 @@ public:
   vtkSmartPointer<vtkContextView> ContextView;
   vtkSmartPointer<vtkContextView> ContextView;
   vtkSmartPointer<vtkChartXY> Chart;
   vtkSmartPointer<vtkChartXY> Chart;
   double UserBounds[8];
   double UserBounds[8];
+  mutable double OldBounds[8];
 };
 };
 
 
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
@@ -68,6 +69,8 @@ ctkVTKChartViewPrivate::ctkVTKChartViewPrivate(ctkVTKChartView& object)
   this->ContextView->GetScene()->AddItem(this->Chart);
   this->ContextView->GetScene()->AddItem(this->Chart);
   this->UserBounds[0] = this->UserBounds[2] = this->UserBounds[4] = this->UserBounds[6] = 0.;
   this->UserBounds[0] = this->UserBounds[2] = this->UserBounds[4] = this->UserBounds[6] = 0.;
   this->UserBounds[1] = this->UserBounds[3] = this->UserBounds[5] = this->UserBounds[7] = -1.;
   this->UserBounds[1] = this->UserBounds[3] = this->UserBounds[5] = this->UserBounds[7] = -1.;
+  this->OldBounds[0] = this->OldBounds[2] = this->OldBounds[4] = this->OldBounds[6] = 0.;
+  this->OldBounds[1] = this->OldBounds[3] = this->OldBounds[5] = this->OldBounds[7] = -1.;
 }
 }
 
 
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
@@ -215,7 +218,22 @@ void ctkVTKChartView::addPlot(vtkPlot* plot)
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 void ctkVTKChartView::onChartUpdated()
 void ctkVTKChartView::onChartUpdated()
 {
 {
-  emit boundsChanged();
+  Q_D(ctkVTKChartView);
+  double oldBounds[8];
+  memcpy(oldBounds, d->OldBounds, 8 * sizeof(double));
+  double newBounds[8];
+  this->chartBounds(newBounds);
+  if (oldBounds[0] != newBounds[0] ||
+      oldBounds[1] != newBounds[1] ||
+      oldBounds[2] != newBounds[2] ||
+      oldBounds[3] != newBounds[3] ||
+      oldBounds[4] != newBounds[4] ||
+      oldBounds[5] != newBounds[5] ||
+      oldBounds[6] != newBounds[6] ||
+      oldBounds[7] != newBounds[7])
+    {
+    emit boundsChanged();
+    }
 }
 }
 
 
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
@@ -226,9 +244,12 @@ void ctkVTKChartView::chartBounds(double* bounds)const
     {
     {
     // Invalid user bounds, return the real chart bounds
     // Invalid user bounds, return the real chart bounds
     d->chartBounds(bounds);
     d->chartBounds(bounds);
-    return;
     }
     }
-  this->chartUserBounds(bounds);
+  else
+    {
+    this->chartUserBounds(bounds);
+    }
+  memcpy(d->OldBounds, bounds, 8 * sizeof(double));
 }
 }
 
 
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------

+ 2 - 2
Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsView.cpp

@@ -74,6 +74,7 @@ void ctkVTKScalarsToColorsViewPrivate::init()
     {
     {
     chart->GetAxis(i)->SetVisible(false);
     chart->GetAxis(i)->SetVisible(false);
     }
     }
+  QObject::connect(q, SIGNAL(boundsChanged()), q, SLOT(onBoundsChanged()));
   q->onChartUpdated();
   q->onChartUpdated();
 }
 }
 
 
@@ -106,11 +107,10 @@ void ctkVTKScalarsToColorsView::addPlot(vtkPlot* plot)
 }
 }
 
 
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
-void ctkVTKScalarsToColorsView::onChartUpdated()
+void ctkVTKScalarsToColorsView::onBoundsChanged()
 {
 {
   this->boundAxesToChartBounds();
   this->boundAxesToChartBounds();
   this->setAxesToChartBounds();
   this->setAxesToChartBounds();
-  this->Superclass::onChartUpdated();
 }
 }
 
 
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------

+ 3 - 2
Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsView.h

@@ -83,11 +83,12 @@ public:
 public slots:
 public slots:
   void editPoint(vtkObject* plot, void * pointId);
   void editPoint(vtkObject* plot, void * pointId);
 
 
+protected slots:
+  void onBoundsChanged();
+
 protected:
 protected:
   QScopedPointer<ctkVTKScalarsToColorsViewPrivate> d_ptr;
   QScopedPointer<ctkVTKScalarsToColorsViewPrivate> d_ptr;
 
 
-  virtual void onChartUpdated();
-
 private:
 private:
   Q_DECLARE_PRIVATE(ctkVTKScalarsToColorsView);
   Q_DECLARE_PRIVATE(ctkVTKScalarsToColorsView);
   Q_DISABLE_COPY(ctkVTKScalarsToColorsView);
   Q_DISABLE_COPY(ctkVTKScalarsToColorsView);