ctkMatrixWidget.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 2010 Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.commontk.org/LICENSE
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #ifndef __ctkMatrixWidget_h
  15. #define __ctkMatrixWidget_h
  16. /// Qt includes
  17. #include <QTableWidget>
  18. /// CTK includes
  19. #include "ctkPimpl.h"
  20. #include "CTKWidgetsExport.h"
  21. class ctkMatrixWidgetPrivate;
  22. ///
  23. /// ctkMatrixWidget is the base class of matrix widgets.
  24. /// \todo Wrap model signals to emit signals when the matrix is changed.
  25. /// Right now you can connect to the signal:
  26. /// matrixWidget->model()->dataChanged(...)
  27. class CTK_WIDGETS_EXPORT ctkMatrixWidget : public QTableWidget
  28. {
  29. Q_OBJECT
  30. Q_PROPERTY(bool editable READ editable WRITE setEditable)
  31. Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
  32. Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
  33. Q_PROPERTY(int decimals READ decimals WRITE setDecimals)
  34. Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
  35. public:
  36. /// Superclass typedef
  37. typedef QTableWidget Superclass;
  38. /// Constructor, builds a 4x4 matrix
  39. explicit ctkMatrixWidget(QWidget* parent = 0);
  40. /// Constructor, builds a custom rowsXcolumns matrix
  41. explicit ctkMatrixWidget(int rows, int columns, QWidget* parent = 0);
  42. virtual ~ctkMatrixWidget(){}
  43. ///
  44. /// Set / Get values of the matrix
  45. /// \li i is the row index, \li j is the column index
  46. /// \warning There is no check that the indexes are inside their
  47. /// valid range
  48. /// \warning The value of a matrix element will not be changed on an attempt to set it to a value
  49. /// that is less than the minimum or greater than the maximum.
  50. double value(int i, int j)const;
  51. void setValue(int i, int j, double value);
  52. void setVector(const QVector<double> & vector);
  53. ///
  54. /// This property determines whether the user can edit values
  55. bool editable()const;
  56. void setEditable(bool newEditable);
  57. ///
  58. /// This property holds the minimum value of matrix elements.
  59. ///
  60. /// Any matrix elements whose values are less than the new minimum value will be reset to equal
  61. /// the new minimum value.
  62. double minimum()const;
  63. void setMinimum(double newMinimum);
  64. ///
  65. /// This property holds the maximum value of matrix elements.
  66. ///
  67. /// Any matrix elements whose values are greater than the new maximum value will be reset to equal
  68. /// the new maximum value.
  69. double maximum()const;
  70. void setMaximum(double newMaximum);
  71. /// Description
  72. /// Utility function that sets the min/max at once.
  73. void setRange(double newMinimum, double newMaximum);
  74. ///
  75. /// This property holds the step value of the spinbox.
  76. ///
  77. /// When the user uses the arrows to change the value of the spinbox used to adjust the value of
  78. /// a matrix element, the value will be incremented/decremented by the amount of the singleStep.
  79. double singleStep()const;
  80. void setSingleStep(double step);
  81. ///
  82. /// This property holds the precision of the spinbox, in decimals.
  83. ///
  84. /// Dictates how many decimals will be used for displaying and interpreting doubles by the spinbox
  85. /// used to adjust the value of a matrix element.
  86. int decimals()const;
  87. void setDecimals(int decimals);
  88. ///
  89. /// Reimplemented from QAbstractScrollArea
  90. virtual QSize minimumSizeHint () const;
  91. virtual QSize sizeHint () const;
  92. public slots:
  93. ///
  94. /// Reset the matrix to identity
  95. void reset();
  96. protected:
  97. ///
  98. /// Reimplemented from QTableView
  99. /// Share the width/height evenly between columns/rows.
  100. virtual void updateGeometries();
  101. private:
  102. CTK_DECLARE_PRIVATE(ctkMatrixWidget);
  103. };
  104. #endif