Ver código fonte

Merge branch 'master' into bugfix

Jean-Christophe Fillion-Robin 15 anos atrás
pai
commit
79dfd0fb8a

+ 13 - 3
Libs/Visualization/VTK/Core/ctkVTKColorTransferFunction.cpp

@@ -243,11 +243,21 @@ int ctkVTKColorTransferFunction::insertControlPoint(const ctkControlPoint& cp)
   return index;
 }
 //-----------------------------------------------------------------------------
-// insert point with value = 0
 int ctkVTKColorTransferFunction::insertControlPoint(qreal pos)
 {
-  // nothing
-  int index = 0;
+  CTK_D(ctkVTKColorTransferFunction);
+  int index = -1;
+  if (d->ColorTransferFunction.GetPointer() == 0)
+    {
+    return index;
+    }
+
+  // Get color at the given position
+  double* rgb = d->ColorTransferFunction->GetColor( pos );
+
+  // Add new point with the appropriate color
+  index = d->ColorTransferFunction->AddRGBPoint(
+    pos, rgb[0], rgb[1], rgb[2]);
 
   return index;
 }

+ 47 - 27
Libs/Widgets/ctkMatrixWidget.cpp

@@ -1,7 +1,7 @@
 /*=========================================================================
 
   Library:   CTK
- 
+
   Copyright (c) 2010  Kitware Inc.
 
   Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,7 +15,7 @@
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
- 
+
 =========================================================================*/
 
 // CTK includes
@@ -50,6 +50,12 @@ ctkMatrixWidget::ctkMatrixWidget(QWidget* _parent) : Superclass(4, 4, _parent)
   this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
   this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
 
+  // Don't expand for no reason
+  this->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
+
+  // Disable the frame by default
+  this->setFrameStyle(QFrame::NoFrame);
+
   // Define prototype item
   QTableWidgetItem* _item = new QTableWidgetItem();
   _item->setData(Qt::DisplayRole, QVariant(0.0));
@@ -65,7 +71,17 @@ ctkMatrixWidget::ctkMatrixWidget(QWidget* _parent) : Superclass(4, 4, _parent)
 // --------------------------------------------------------------------------
 QSize ctkMatrixWidget::minimumSizeHint () const
 {
-  return QSize(this->columnCount() * 25, this->rowCount() * 25);
+  int maxWidth = this->sizeHintForColumn(0);
+  for (int j = 1; j < this->columnCount(); ++j)
+    {
+    maxWidth = qMax(maxWidth, this->sizeHintForColumn(j));
+    }
+  int maxHeight = this->sizeHintForRow(0);
+  for (int i = 1; i < this->rowCount(); ++i)
+    {
+    maxHeight = qMax(maxHeight, this->sizeHintForRow(i));
+    }
+  return QSize(maxWidth*this->columnCount(), maxHeight*this->rowCount());
 }
 
 // --------------------------------------------------------------------------
@@ -75,32 +91,34 @@ QSize ctkMatrixWidget::sizeHint () const
 }
 
 // --------------------------------------------------------------------------
-void ctkMatrixWidget::resizeEvent(QResizeEvent * _event)
+void ctkMatrixWidget::updateGeometries()
 {
-  this->Superclass::resizeEvent(_event);
-  this->adjustRowsColumnsSize(_event->size().width(), _event->size().height());
-}
-
-// --------------------------------------------------------------------------
-void ctkMatrixWidget::adjustRowsColumnsSize(int _width, int _height)
-{
-  int colwidth = _width / this->columnCount();
-  int lastColwidth = colwidth + (_width - colwidth * this->columnCount());
-  //qDebug() << "width:" << width << ",col-width:" << colwidth;
-  for (int j=0; j < this->columnCount(); j++)
+  QSize viewportSize = this->viewport()->size();
+  // columns
+  const int ccount = this->columnCount();
+  int colWidth = viewportSize.width() / ccount;
+  int lastColWidth = colWidth
+    + (viewportSize.width() - colWidth * ccount);
+  for (int j=0; j < ccount; j++)
     {
-    bool lastColumn = (j==(this->columnCount()-1));
-    this->setColumnWidth(j, lastColumn ? lastColwidth : colwidth);
+    bool lastColumn = (j==(ccount-1));
+    int newWidth = lastColumn ? lastColWidth : colWidth;
+    this->setColumnWidth(j, newWidth);
+    Q_ASSERT(this->columnWidth(j) == newWidth);
     }
-
-  int rowheight = _height / this->rowCount();
-  int lastRowheight = rowheight + (_height - rowheight * this->rowCount());
-  //qDebug() << "height:" << height << ", row-height:" << rowheight;
-  for (int i=0; i < this->rowCount(); i++)
+  // rows
+  const int rcount = this->rowCount();
+  int rowHeight = viewportSize.height() / rcount;
+  int lastRowHeight = rowHeight + (viewportSize.height() - rowHeight * rcount);
+  for (int i=0; i < rcount; i++)
     {
-    bool lastRow = (i==(this->rowCount()-1));
-    this->setRowHeight(i, lastRow ? lastRowheight : rowheight);
+    bool lastRow = (i==(rcount-1));
+    int newHeight = lastRow ? lastRowHeight : rowHeight;
+    this->setRowHeight(i, newHeight);
+    Q_ASSERT(this->rowHeight(i) == newHeight);
     }
+
+  this->Superclass::updateGeometries();
 }
 
 // --------------------------------------------------------------------------
@@ -121,9 +139,10 @@ void ctkMatrixWidget::reset()
 }
 
 // --------------------------------------------------------------------------
-double ctkMatrixWidget::value(int i, int j)
+double ctkMatrixWidget::value(int i, int j)const
 {
-  if (i<0 || i>=(this->rowCount()) || j<0 || j>=this->columnCount()) { return 0; }
+  Q_ASSERT( i>=0 && i<this->rowCount() &&
+            j>=0 && j<this->columnCount());
 
   return this->item(i, j)->data(Qt::DisplayRole).toDouble();
 }
@@ -131,7 +150,8 @@ double ctkMatrixWidget::value(int i, int j)
 // --------------------------------------------------------------------------
 void ctkMatrixWidget::setValue(int i, int j, double _value)
 {
-  if (i<0 || i>=(this->rowCount()) || j<0 || j>=this->columnCount()) { return; }
+  Q_ASSERT( i>=0 && i<this->rowCount() &&
+            j>=0 && j<this->columnCount());
 
   this->item(i, j)->setData(Qt::DisplayRole, QVariant(_value));
 }

+ 22 - 19
Libs/Widgets/ctkMatrixWidget.h

@@ -1,7 +1,7 @@
 /*=========================================================================
 
   Library:   CTK
- 
+
   Copyright (c) 2010  Kitware Inc.
 
   Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,7 +15,7 @@
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
- 
+
 =========================================================================*/
 
 #ifndef __ctkMatrixWidget_h
@@ -30,10 +30,15 @@
 
 class ctkMatrixWidgetPrivate;
 
+///
+/// ctkMatrixWidget is the base class of matrix widgets.
+/// \todo Add a property to handle wether the user can edit values
+/// \todo Wrap model signals to emit signals when the matrix is changed.
+/// Right now you can connect to the signal:
+/// matrixWidget->model()->dataChanged(...)
 class CTK_WIDGETS_EXPORT ctkMatrixWidget : public QTableWidget
 {
   Q_OBJECT
-
 public:
   /// Superclass typedef
   typedef QTableWidget Superclass;
@@ -42,32 +47,30 @@ public:
   explicit ctkMatrixWidget(QWidget* parent = 0);
   virtual ~ctkMatrixWidget(){}
 
-  /// 
-  /// Set / Get values
-  double value(int i, int j);
+  ///
+  /// Set / Get values of the matrix
+  /// \li i is the row index, \li j is the column index
+  /// \warning there is no check that the indexes are inside their
+  /// valid range
+  double value(int i, int j)const;
   void setValue(int i, int j, double value);
   void setVector(const QVector<double> & vector);
 
-  /// 
-  /// Overloaded - See QWidget
+  ///
+  /// Reimplemented from QAbstractScrollArea
   virtual QSize minimumSizeHint () const;
   virtual QSize sizeHint () const;
 
-
 public slots:
-
-  /// 
-  /// Reset to zero
+  ///
+  /// Reset the matrix to identity
   void reset();
 
-protected slots:
-  /// 
-  /// Adjust columns/rows size according to width/height
-  void adjustRowsColumnsSize(int width, int height);
-
 protected:
-  /// 
-  virtual void resizeEvent(QResizeEvent * event);
+  ///
+  /// Reimplemented from QTableView
+  /// Share the width/height evenly between columns/rows.
+  virtual void updateGeometries();
 
 private:
   CTK_DECLARE_PRIVATE(ctkMatrixWidget);