mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-07 02:45:51 +00:00
add string formatter
This commit is contained in:
@ -52,8 +52,13 @@ QString AWFloatFormatter::convert(const QVariant &_value) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Convert value" << _value;
|
||||
|
||||
return QString("%1").arg(_value.toDouble() * multiplier() + summand(),
|
||||
count(), format(), precision(), fillChar());
|
||||
QString output
|
||||
= QString("%1").arg(_value.toDouble() * multiplier() + summand(),
|
||||
count(), format(), precision(), fillChar());
|
||||
if (forceWidth())
|
||||
output = output.left(count());
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
@ -68,6 +73,7 @@ AWFloatFormatter *AWFloatFormatter::copy(const QString _fileName,
|
||||
item->setCount(count());
|
||||
item->setFormat(format());
|
||||
item->setFillChar(fillChar());
|
||||
item->setForceWidth(forceWidth());
|
||||
item->setMultiplier(multiplier());
|
||||
item->setNumber(_number);
|
||||
item->setPrecision(precision());
|
||||
@ -89,6 +95,12 @@ QChar AWFloatFormatter::fillChar() const
|
||||
}
|
||||
|
||||
|
||||
bool AWFloatFormatter::forceWidth() const
|
||||
{
|
||||
return m_forceWidth;
|
||||
}
|
||||
|
||||
|
||||
char AWFloatFormatter::format() const
|
||||
{
|
||||
return m_format;
|
||||
@ -129,6 +141,14 @@ void AWFloatFormatter::setFillChar(const QChar _fillChar)
|
||||
}
|
||||
|
||||
|
||||
void AWFloatFormatter::setForceWidth(const bool _forceWidth)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set force strip" << _forceWidth;
|
||||
|
||||
m_forceWidth = _forceWidth;
|
||||
}
|
||||
|
||||
|
||||
void AWFloatFormatter::setFormat(char _format)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set format" << _format;
|
||||
@ -177,6 +197,8 @@ void AWFloatFormatter::readConfiguration()
|
||||
setCount(settings.value(QString("X-AW-Width"), count()).toInt());
|
||||
setFillChar(
|
||||
settings.value(QString("X-AW-FillChar"), fillChar()).toString().at(0));
|
||||
setForceWidth(
|
||||
settings.value(QString("X-AW-ForceWidth"), forceWidth()).toBool());
|
||||
setFormat(settings.value(QString("X-AW-Format"), QString(format()))
|
||||
.toString()
|
||||
.at(0)
|
||||
@ -204,6 +226,8 @@ int AWFloatFormatter::showConfiguration(const QVariant args)
|
||||
ui->spinBox_precision->setValue(precision());
|
||||
ui->spinBox_width->setValue(count());
|
||||
ui->lineEdit_fill->setText(QString(fillChar()));
|
||||
ui->checkBox_forceWidth->setCheckState(forceWidth() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->doubleSpinBox_multiplier->setValue(multiplier());
|
||||
ui->doubleSpinBox_summand->setValue(summand());
|
||||
|
||||
@ -217,6 +241,7 @@ int AWFloatFormatter::showConfiguration(const QVariant args)
|
||||
setPrecision(ui->spinBox_precision->value());
|
||||
setCount(ui->spinBox_width->value());
|
||||
setFillChar(ui->lineEdit_fill->text().at(0));
|
||||
setForceWidth(ui->checkBox_forceWidth->checkState() == Qt::Checked);
|
||||
setMultiplier(ui->doubleSpinBox_multiplier->value());
|
||||
setSummand(ui->doubleSpinBox_summand->value());
|
||||
|
||||
@ -236,6 +261,7 @@ void AWFloatFormatter::writeConfiguration() const
|
||||
settings.setValue(QString("X-AW-Width"), count());
|
||||
settings.setValue(QString("X-AW-FillChar"), fillChar());
|
||||
settings.setValue(QString("X-AW-Format"), format());
|
||||
settings.setValue(QString("X-AW-ForceWidth"), forceWidth());
|
||||
settings.setValue(QString("X-AW-Multiplier"), multiplier());
|
||||
settings.setValue(QString("X-AW-Precision"), precision());
|
||||
settings.setValue(QString("X-AW-Summand"), summand());
|
||||
@ -254,6 +280,7 @@ void AWFloatFormatter::translate()
|
||||
ui->label_precision->setText(i18n("Precision"));
|
||||
ui->label_width->setText(i18n("Width"));
|
||||
ui->label_fill->setText(i18n("Fill char"));
|
||||
ui->checkBox_forceWidth->setText(i18n("Force width"));
|
||||
ui->label_multiplier->setText(i18n("Multiplier"));
|
||||
ui->label_summand->setText(i18n("Summand"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user