ctkMatrixWidget.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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.apache.org/licenses/LICENSE-2.0.txt
  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 <QVector>
  18. #include <QWidget>
  19. /// CTK includes
  20. #include "ctkDoubleSpinBox.h"
  21. #include "ctkPimpl.h"
  22. #include "ctkWidgetsExport.h"
  23. class ctkMatrixWidgetPrivate;
  24. /// \ingroup Widgets
  25. ///
  26. /// ctkMatrixWidget is the base class of matrix widgets.
  27. class CTK_WIDGETS_EXPORT ctkMatrixWidget: public QWidget
  28. {
  29. Q_OBJECT
  30. Q_PROPERTY(int columnCount READ columnCount WRITE setColumnCount)
  31. Q_PROPERTY(int rowCount READ rowCount WRITE setRowCount)
  32. Q_PROPERTY(bool editable READ isEditable WRITE setEditable)
  33. Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
  34. Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
  35. Q_PROPERTY(int decimals READ decimals WRITE setDecimals)
  36. /// This property provides more controls over the decimals.
  37. /// \sa ctkDoubleSpinBox::DecimalsOptions, decimals
  38. Q_PROPERTY(ctkDoubleSpinBox::DecimalsOptions decimalsOption READ decimalsOption WRITE setDecimalsOption)
  39. Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
  40. Q_PROPERTY(QVector<double> values READ values WRITE setValues)
  41. public:
  42. /// Superclass typedef
  43. typedef QWidget Superclass;
  44. /// Constructor, builds a 4x4 identity matrix
  45. explicit ctkMatrixWidget(QWidget* parent = 0);
  46. /// Constructor, builds a custom rowsXcolumns matrix
  47. explicit ctkMatrixWidget(int rows, int columns, QWidget* parent = 0);
  48. virtual ~ctkMatrixWidget();
  49. /// Set the number of columns of the matrix
  50. /// \sa rowCount, setRowCount
  51. int columnCount()const;
  52. virtual void setColumnCount(int newColumnCount);
  53. /// Set the number of rows of the matrix
  54. /// \sa columnCount, setColumnCount
  55. int rowCount()const;
  56. virtual void setRowCount(int newRowCount);
  57. ///
  58. /// Set / Get values of the matrix
  59. /// \li i is the row index, \li j is the column index
  60. /// \warning There is no check that the indexes are inside their
  61. /// valid range
  62. /// \warning The value of a matrix element will not be changed on an attempt to set it to a value
  63. /// that is less than the minimum or greater than the maximum.
  64. Q_INVOKABLE double value(int i, int j)const;
  65. Q_INVOKABLE void setValue(int i, int j, double value);
  66. ///
  67. /// Utility function to set/get all the values of the matrix at once.
  68. /// Only one signal matrixChanged() is fired at the end.
  69. QVector<double> values()const;
  70. void setValues(const QVector<double> & vector);
  71. ///
  72. /// This property determines whether the user can edit values by
  73. /// double clicking on the items. True by default
  74. bool isEditable()const;
  75. void setEditable(bool newEditable);
  76. ///
  77. /// This property holds the minimum value of matrix elements.
  78. ///
  79. /// Any matrix elements whose values are less than the new minimum value will be reset to equal
  80. /// the new minimum value.
  81. double minimum()const;
  82. void setMinimum(double newMinimum);
  83. ///
  84. /// This property holds the maximum value of matrix elements.
  85. ///
  86. /// Any matrix elements whose values are greater than the new maximum value will be reset to equal
  87. /// the new maximum value.
  88. double maximum()const;
  89. void setMaximum(double newMaximum);
  90. /// Description
  91. /// Utility function that sets the min/max at once.
  92. void setRange(double newMinimum, double newMaximum);
  93. ///
  94. /// This property holds the step value of the spinbox.
  95. ///
  96. /// When the user uses the arrows to change the value of the spinbox used to adjust the value of
  97. /// a matrix element, the value will be incremented/decremented by the amount of the singleStep.
  98. double singleStep()const;
  99. void setSingleStep(double step);
  100. ///
  101. /// This property holds the precision of the spinbox, in decimals.
  102. ///
  103. /// Dictates how many decimals will be used for displaying and interpreting doubles by the spinbox
  104. /// used to adjust the value of a matrix element.
  105. int decimals()const;
  106. /// Return the decimalsOption property value
  107. /// \sa decimalsOption
  108. ctkDoubleSpinBox::DecimalsOptions decimalsOption()const;
  109. /// Set the decimalsOption property value.
  110. /// \sa decimalsOption
  111. void setDecimalsOption(ctkDoubleSpinBox::DecimalsOptions option);
  112. ///
  113. /// Reimplemented from QAbstractScrollArea
  114. virtual QSize minimumSizeHint () const;
  115. virtual QSize sizeHint () const;
  116. public Q_SLOTS:
  117. ///
  118. /// Reset the matrix to identity
  119. void identity();
  120. ///
  121. /// Set how many decimals will be used for displaying and interpreting
  122. /// doubles by the spinbox used to adjust the value of a matrix element.
  123. void setDecimals(int decimals);
  124. Q_SIGNALS:
  125. void matrixChanged();
  126. protected:
  127. virtual void resizeEvent(QResizeEvent* event);
  128. ///
  129. /// protected constructor to derive private implementations
  130. ctkMatrixWidget(ctkMatrixWidgetPrivate& pvt, QWidget* parent=0);
  131. private:
  132. QScopedPointer<ctkMatrixWidgetPrivate> d_ptr;
  133. Q_DECLARE_PRIVATE(ctkMatrixWidget);
  134. Q_DISABLE_COPY(ctkMatrixWidget);
  135. };
  136. #endif