| 71 | } |
| 72 | |
| 73 | void QmitkLinearScaleQuestionWidget::CreateWidgets() |
| 74 | { |
| 75 | this->RemoveWidgets(); |
| 76 | |
| 77 | auto [from, to] = m_Question->GetRange(); |
| 78 | auto [fromText, toText] = m_Question->GetRangeLabels(); |
| 79 | int column = 0; |
| 80 | |
| 81 | if (!fromText.empty()) |
| 82 | { |
| 83 | auto fromLabel = new QLabel(QString::fromStdString(fromText)); |
| 84 | m_Layout->addWidget(fromLabel, 1, column++, Qt::AlignRight); |
| 85 | } |
| 86 | |
| 87 | for (int i = from; i <= to; ++i) |
| 88 | { |
| 89 | auto label = new QLabel(QString("%1").arg(i)); |
| 90 | |
| 91 | auto radioButton = new QRadioButton; |
| 92 | radioButton->setFixedWidth(radioButton->sizeHint().height()); |
| 93 | |
| 94 | m_Layout->addWidget(label, 0, column, Qt::AlignHCenter); |
| 95 | m_Layout->addWidget(radioButton, 1, column++, Qt::AlignHCenter); |
| 96 | |
| 97 | m_ButtonGroup->addButton(radioButton, i); |
| 98 | } |
| 99 | |
| 100 | if (!toText.empty()) |
| 101 | { |
| 102 | auto toLabel = new QLabel(QString::fromStdString(toText)); |
| 103 | m_Layout->addWidget(toLabel, 1, column++, Qt::AlignLeft); |
| 104 | } |
| 105 | |
| 106 | if (m_Question->IsRequired()) |
| 107 | return; |
| 108 | |
| 109 | m_ClearButton = new QPushButton("Clear selection"); |
| 110 | m_ClearButton->setFlat(true); |
| 111 | m_ClearButton->hide(); |
| 112 | |
| 113 | m_Layout->addWidget(m_ClearButton, 2, 0, 1, column, Qt::AlignRight); |
| 114 | |
| 115 | connect(m_ClearButton, &QPushButton::clicked, this, &Self::OnClearButtonClicked); |
| 116 | } |
| 117 | |
| 118 | void QmitkLinearScaleQuestionWidget::RemoveWidgets() |
| 119 | { |
no test coverage detected