Kstars

unitspinboxwidget.cpp
1 /*
2  SPDX-FileCopyrightText: 2015 Utkarsh Simha <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 #include "unitspinboxwidget.h"
7 
8 UnitSpinBoxWidget::UnitSpinBoxWidget(QWidget *parent) : QWidget(parent), ui(new Ui::UnitSpinBoxWidget)
9 {
10  ui->setupUi(this);
11  doubleSpinBox = ui->doubleSpinBox;
12  comboBox = ui->comboBox;
13  //connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(setText()));
14  //connect(comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setText()));
15 }
16 
17 UnitSpinBoxWidget::~UnitSpinBoxWidget()
18 {
19  delete ui;
20 }
21 
22 void UnitSpinBoxWidget::addUnit(const QString &unitName, double conversionFactor)
23 {
24  QVariant qv;
25  qv.setValue(conversionFactor);
26  comboBox->addItem(unitName, qv);
27 }
28 
30 {
31  int index = comboBox->currentIndex();
32  QVariant qv = comboBox->itemData(index);
33  double conversionFactor = qv.value<double>();
34  double value = doubleSpinBox->value();
35  return value * conversionFactor;
36 }
T value() const const
double value() const
value Returns value upon conversion
void setValue(const T &value)
The UnitSpinBoxWidget class It is a widget that provides a DoubleSpinBox and a ComboBox for conversio...
void setupUi(QWidget *widget)
QSGNode * parent() const const
QVariant itemData(int index, int role) const const
void addUnit(const QString &unitName, double conversionFactor)
addUnit Adds a item to the combo box
void addItem(const QString &text, const QVariant &userData)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Oct 1 2023 04:02:45 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.