Radium Engine  1.5.20
Loading...
Searching...
No Matches
MatrixEditor.cpp
1#include <Gui/Widgets/MatrixEditor.hpp>
2
3#include <QDoubleSpinBox>
4#include <QGridLayout>
5#include <QLabel>
6#include <QValidator>
7#include <QWidget>
8
9#include <memory>
10
11namespace Ra::Gui::Widgets {
12
13MatrixEditor::MatrixEditor( const Ra::Core::MatrixN& matrix, int dec, QWidget* parent ) :
14 QWidget( parent ), m_matrix( matrix ) {
15
16 QGridLayout* layout = new QGridLayout;
17 layout->setContentsMargins( {} ); // margins are set to 0, see Qt documentation
18 layout->setSpacing( 0 );
19
20 for ( long i = 0; i < m_matrix.rows(); ++i ) {
21 for ( int j = 0; j < m_matrix.cols(); ++j ) {
22 auto& elem = m_matrix( i, j );
23 auto spinbox = new QDoubleSpinBox();
24 spinbox->setDecimals( dec );
25 spinbox->setValue( elem );
26 spinbox->setMinimum( std::numeric_limits<Scalar>::lowest() );
27 spinbox->setMaximum( std::numeric_limits<Scalar>::max() );
28
29 layout->addWidget( spinbox, i, j );
30 auto updateMatrixOnChange = [this, &elem]( double value ) {
31 elem = value;
32 emit valueChanged( m_matrix );
33 };
34 connect( spinbox,
35 QOverload<double>::of( &QDoubleSpinBox::valueChanged ),
36 updateMatrixOnChange );
37 }
38 }
39
40 setLayout( layout );
41}
42
43const Ra::Core::MatrixN& MatrixEditor::matrix() const {
44 return m_matrix;
45}
46} // namespace Ra::Gui::Widgets
const Ra::Core::MatrixN & matrix() const
Get the edited matrix.
MatrixEditor(const Ra::Core::MatrixN &matrix, int dec, QWidget *parent=nullptr)