mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-11 09:36:37 +00:00
52 lines
1.0 KiB
C++
52 lines
1.0 KiB
C++
|
#include "spinbox.hpp"
|
||
|
|
||
|
#include <QSpinBox>
|
||
|
#include <QLineEdit>
|
||
|
|
||
|
CSVSettings::SpinBox::SpinBox(QWidget *parent)
|
||
|
: mValueList(QStringList()), QSpinBox(parent)
|
||
|
{
|
||
|
setRange (0, 0);
|
||
|
}
|
||
|
|
||
|
QString CSVSettings::SpinBox::textFromValue(int val) const
|
||
|
{
|
||
|
if (mValueList.isEmpty())
|
||
|
return QVariant (val).toString();
|
||
|
|
||
|
QString value = "";
|
||
|
|
||
|
if (val < mValueList.size())
|
||
|
value = mValueList.at (val);
|
||
|
|
||
|
return value;
|
||
|
}
|
||
|
|
||
|
int CSVSettings::SpinBox::valueFromText(const QString &text) const
|
||
|
{
|
||
|
if (mValueList.isEmpty())
|
||
|
return -1;
|
||
|
|
||
|
if (mValueList.contains (text))
|
||
|
return mValueList.indexOf(text);
|
||
|
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
void CSVSettings::SpinBox::setValue (const QString &value)
|
||
|
{
|
||
|
if (!mValueList.isEmpty())
|
||
|
{
|
||
|
lineEdit()->setText (value);
|
||
|
QSpinBox::setValue(valueFromText(value));
|
||
|
}
|
||
|
else
|
||
|
QSpinBox::setValue (value.toInt());
|
||
|
}
|
||
|
|
||
|
void CSVSettings::SpinBox::setValueList (const QStringList &list)
|
||
|
{
|
||
|
mValueList = list;
|
||
|
setMaximum (list.size() - 1);
|
||
|
}
|