ctkMatrixWidget.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 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 <QWidget>
  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. class CTK_WIDGETS_EXPORT ctkMatrixWidget: public QWidget
  25. {
  26. Q_OBJECT
  27. Q_PROPERTY(int columnCount READ columnCount WRITE setColumnCount)
  28. Q_PROPERTY(int rowCount READ rowCount WRITE setRowCount)
  29. Q_PROPERTY(bool editable READ isEditable WRITE setEditable)
  30. Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
  31. Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
  32. Q_PROPERTY(int decimals READ decimals WRITE setDecimals)
  33. Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
  34. public:
  35. /// Superclass typedef
  36. typedef QWidget Superclass;
  37. /// Constructor, builds a 4x4 identity matrix
  38. explicit ctkMatrixWidget(QWidget* parent = 0);
  39. /// Constructor, builds a custom rowsXcolumns matrix
  40. explicit ctkMatrixWidget(int rows, int columns, QWidget* parent = 0);
  41. virtual ~ctkMatrixWidget();
  42. /// Set the number of columns of the matrix
  43. /// \sa rowCount, setRowCount
  44. int columnCount()const;
  45. virtual void setColumnCount(int newColumnCount);
  46. /// Set the number of rows of the matrix
  47. /// \sa columnCount, setColumnCount
  48. int rowCount()const;
  49. virtual void setRowCount(int newRowCount);
  50. ///
  51. /// Set / Get values of the matrix
  52. /// \li i is the row index, \li j is the column index
  53. /// \warning There is no check that the indexes are inside their
  54. /// valid range
  55. /// \warning The value of a matrix element will not be changed on an attempt to set it to a value
  56. /// that is less than the minimum or greater than the maximum.
  57. double value(int i, int j)const;
  58. void setValue(int i, int j, double value);
  59. void setVector(const QVector<double> & vector);
  60. ///
  61. /// This property determines whether the user can edit values by
  62. /// double clicking on the items. True by default
  63. bool isEditable()const;
  64. void setEditable(bool newEditable);
  65. ///
  66. /// This property holds the minimum value of matrix elements.
  67. ///
  68. /// Any matrix elements whose values are less than the new minimum value will be reset to equal
  69. /// the new minimum value.
  70. double minimum()const;
  71. void setMinimum(double newMinimum);
  72. ///
  73. /// This property holds the maximum value of matrix elements.
  74. ///
  75. /// Any matrix elements whose values are greater than the new maximum value will be reset to equal
  76. /// the new maximum value.
  77. double maximum()const;
  78. void setMaximum(double newMaximum);
  79. /// Description
  80. /// Utility function that sets the min/max at once.
  81. void setRange(double newMinimum, double newMaximum);
  82. ///
  83. /// This property holds the step value of the spinbox.
  84. ///
  85. /// When the user uses the arrows to change the value of the spinbox used to adjust the value of
  86. /// a matrix element, the value will be incremented/decremented by the amount of the singleStep.
  87. double singleStep()const;
  88. void setSingleStep(double step);
  89. ///
  90. /// This property holds the precision of the spinbox, in decimals.
  91. ///
  92. /// Dictates how many decimals will be used for displaying and interpreting doubles by the spinbox
  93. /// used to adjust the value of a matrix element.
  94. int decimals()const;
  95. void setDecimals(int decimals);
  96. ///
  97. /// Reimplemented from QAbstractScrollArea
  98. virtual QSize minimumSizeHint () const;
  99. virtual QSize sizeHint () const;
  100. public slots:
  101. ///
  102. /// Reset the matrix to identity
  103. void identity();
  104. signals:
  105. void matrixChanged();
  106. protected:
  107. virtual void resizeEvent(QResizeEvent* event);
  108. ///
  109. /// protected constructor to derive private implementations
  110. ctkMatrixWidget(ctkMatrixWidgetPrivate& pvt, QWidget* parent=0);
  111. private:
  112. QScopedPointer<ctkMatrixWidgetPrivate> d_ptr;
  113. Q_DECLARE_PRIVATE(ctkMatrixWidget);
  114. Q_DISABLE_COPY(ctkMatrixWidget);
  115. };
  116. #endif