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