ctkMatrixWidget.h 5.9 KB

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