File indexing completed on 2024-07-07 07:09:18

0001 /*
0002     SPDX-FileCopyrightText: 2015 Utkarsh Simha <utkarshsimha@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 #include "unitspinboxwidget.h"
0007 
0008 UnitSpinBoxWidget::UnitSpinBoxWidget(QWidget *parent) : QWidget(parent), ui(new Ui::UnitSpinBoxWidget)
0009 {
0010     ui->setupUi(this);
0011     doubleSpinBox = ui->doubleSpinBox;
0012     comboBox      = ui->comboBox;
0013     //connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(setText()));
0014     //connect(comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setText()));
0015 }
0016 
0017 UnitSpinBoxWidget::~UnitSpinBoxWidget()
0018 {
0019     delete ui;
0020 }
0021 
0022 void UnitSpinBoxWidget::addUnit(const QString &unitName, double conversionFactor)
0023 {
0024     QVariant qv;
0025     qv.setValue(conversionFactor);
0026     comboBox->addItem(unitName, qv);
0027 }
0028 
0029 double UnitSpinBoxWidget::value() const
0030 {
0031     int index               = comboBox->currentIndex();
0032     QVariant qv             = comboBox->itemData(index);
0033     double conversionFactor = qv.value<double>();
0034     double value            = doubleSpinBox->value();
0035     return value * conversionFactor;
0036 }