fw4spl
QHexSpinBox.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2016.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "fwDicomIOFilterQt/widget/QHexSpinBox.hpp"
8 
9 namespace fwDicomIOFilterQt
10 {
11 namespace widget
12 {
13 
14 
15 //-----------------------------------------------------------------------------
16 
17 QHexSpinBox::QHexSpinBox(QWidget* parent) : QSpinBox(parent)
18 {
19  this->setRange(0,0xFFFF);
20  m_validator = new QRegExpValidator(QRegExp("[0-9A-Fa-f]{1,4}"), this);
21 }
22 
23 //-----------------------------------------------------------------------------
24 
25 QValidator::State QHexSpinBox::validate(QString& text, int& pos) const
26 {
27  return m_validator->validate(text, pos);
28 }
29 
30 //-----------------------------------------------------------------------------
31 
32 int QHexSpinBox::valueFromText(const QString& text) const
33 {
34  bool ok;
35  return text.toInt(&ok, 16);
36 }
37 
38 //-----------------------------------------------------------------------------
39 
40 QString QHexSpinBox::textFromValue(int value) const
41 {
42  QString res = QString::number(value, 16).toUpper();
43  for(unsigned int i = res.size(); i < 4; ++i)
44  {
45  res = "0" + res;
46  }
47  return res;
48 }
49 
50 } // namespace widget
51 } // namespace fwDicomIOFilterQt
QString textFromValue(int value) const
Override.
Definition: QHexSpinBox.cpp:40
int valueFromText(const QString &text) const
Override.
Definition: QHexSpinBox.cpp:32
QValidator::State validate(QString &text, int &pos) const
Override.
Definition: QHexSpinBox.cpp:25
fwDicomIOFilterQt contains filters used to pre-process images before reading.
QHexSpinBox(QWidget *parent=0)
Constructor.
Definition: QHexSpinBox.cpp:17