2014-05-03 23:57:34 +00:00
|
|
|
#include "spinbox.hpp"
|
|
|
|
|
|
|
|
#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();
|
|
|
|
|
2014-05-07 02:58:50 +00:00
|
|
|
QString value;
|
2014-05-03 23:57:34 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|