Fix double parameters incorrectly handling factor, like gain

parent d8cb94bf
<!DOCTYPE kpartgui>
<effect tag="volume" id="gain" type="audio">
<name>Gain</name>
<description>Adjust the audio volume without keyframes</description>
<author>Dan Dennedy</author>
<parameter type="constant" name="gain" max="1000" min="0" factor="100" default="100" suffix="%">
<name>Gain</name>
</parameter>
</effect>
\ No newline at end of file
<name>Gain</name>
<description>Adjust the audio volume without keyframes</description>
<author>Dan Dennedy</author>
<parameter type="constant" name="gain" max="1000" min="0" factor="100" default="100" suffix="%">
<name>Gain</name>
</parameter>
</effect>
......@@ -309,9 +309,7 @@ QVariant AssetParameterModel::data(const QModelIndex &index, int role) const
return element.attribute(QStringLiteral("alpha")) == QLatin1String("1");
case ValueRole: {
QString value(m_asset->get(paramName.toUtf8().constData()));
return value.isEmpty() ? (element.attribute(QStringLiteral("value")).isNull() ? parseAttribute(m_ownerId, QStringLiteral("default"), element)
: element.attribute(QStringLiteral("value")))
: value;
return value.isEmpty() ? (element.attribute(QStringLiteral("value")).isNull() ? parseAttribute(m_ownerId, QStringLiteral("default"), element) : element.attribute(QStringLiteral("value"))) : value;
}
case ListValuesRole:
return element.attribute(QStringLiteral("paramlist")).split(QLatin1Char(';'));
......@@ -465,6 +463,12 @@ QVariant AssetParameterModel::parseAttribute(const ObjectId owner, const QString
} else if (type == ParamType::Double) {
QLocale locale;
locale.setNumberOptions(QLocale::OmitGroupSeparator);
if (attribute == QLatin1String("default")) {
int factor = element.attribute(QStringLiteral("factor"), QStringLiteral("1")).toInt();
if (factor > 0) {
return locale.toDouble(content) / factor;
}
}
return locale.toDouble(content);
}
if (attribute == QLatin1String("default")) {
......
......@@ -793,14 +793,12 @@ void AnimationWidget::buildSliderWidget(const QString &paramTag, QModelIndex ix)
int index = m_params.count() - 1;
double factor = m_model->data(ix, AssetParameterModel::FactorRole).toDouble();
DoubleWidget *doubleparam =
new DoubleWidget(paramName, 0, m_model->data(ix, AssetParameterModel::MinRole).toDouble(), m_model->data(ix, AssetParameterModel::MaxRole).toDouble(),
m_model->data(ix, AssetParameterModel::DefaultRole).toDouble() * factor, comment, index,
new DoubleWidget(paramName, 0, m_model->data(ix, AssetParameterModel::MinRole).toDouble(), m_model->data(ix, AssetParameterModel::MaxRole).toDouble(), m_model->data(ix, AssetParameterModel::FactorRole).toDouble()
m_model->data(ix, AssetParameterModel::DefaultRole).toDouble(), comment, index,
m_model->data(ix, AssetParameterModel::SuffixRole).toString(), m_model->data(ix, AssetParameterModel::DecimalsRole).toInt(), this);
doubleparam->setObjectName(paramTag);
doubleparam->setProperty("index", ix);
doubleparam->factor = factor;
connect(doubleparam, &DoubleWidget::valueChanged, this, &AnimationWidget::slotAdjustKeyframeValue);
layout()->addWidget(doubleparam);
......
......@@ -45,13 +45,12 @@ DoubleParamWidget::DoubleParamWidget(std::shared_ptr<AssetParameterModel> model,
int decimals = m_model->data(m_index, AssetParameterModel::DecimalsRole).toInt();
double factor = m_model->data(m_index, AssetParameterModel::FactorRole).toDouble();
// Construct object
m_doubleWidget = new DoubleWidget(name, value, min, max, defaultValue, comment, -1, suffix, decimals, this);
m_doubleWidget->factor = factor;
m_doubleWidget = new DoubleWidget(name, value, min, max, factor, defaultValue, comment, -1, suffix, decimals, this);
m_lay->addWidget(m_doubleWidget);
// Connect signal
connect(m_doubleWidget, &DoubleWidget::valueChanged,
[this, locale](double val) { emit valueChanged(m_index, locale.toString(val / m_doubleWidget->factor), true); });
[this, locale](double val) { emit valueChanged(m_index, locale.toString(val), true); });
slotRefresh();
}
......
......@@ -128,7 +128,7 @@ void KeyframeEdit::addParameter(QModelIndex index, int activeKeyframe)
m_paramIndexes << index;
keyframe_list->insertColumn(columnId);
keyframe_list->setHorizontalHeaderItem(columnId, new QTableWidgetItem(name));
DoubleWidget *doubleparam = new DoubleWidget(name, value, min, max, defaultValue, comment, -1, suffix, decimals, this);
DoubleWidget *doubleparam = new DoubleWidget(name, value, min, max, m_model->data(index, AssetParameterModel::FactorRole).toDouble(), defaultValue, comment, -1, suffix, decimals, this);
/*DoubleParameterWidget *doubleparam = new DoubleParameterWidget(
paramName, 0, m_params.at(columnId).attribute(QStringLiteral("min")).toDouble(), m_params.at(columnId).attribute(QStringLiteral("max")).toDouble(),
......
......@@ -291,10 +291,9 @@ void KeyframeWidget::addParameter(const QPersistentModelIndex &index)
int decimals = m_model->data(index, AssetParameterModel::DecimalsRole).toInt();
double factor = locale.toDouble(m_model->data(index, AssetParameterModel::FactorRole).toString());
factor = qFuzzyIsNull(factor) ? 1 : factor;
auto doubleWidget = new DoubleWidget(name, value * factor, min, max, defaultValue, comment, -1, suffix, decimals, this);
doubleWidget->factor = factor;
auto doubleWidget = new DoubleWidget(name, value * factor, min, max, factor, defaultValue, comment, -1, suffix, decimals, this);
connect(doubleWidget, &DoubleWidget::valueChanged,
[this, index, factor](double v) { m_keyframes->updateKeyframe(GenTime(getPosition(), pCore->getCurrentFps()), QVariant(v), index); });
[this, index](double v) { m_keyframes->updateKeyframe(GenTime(getPosition(), pCore->getCurrentFps()), QVariant(v), index); });
paramWidget = doubleWidget;
}
if (paramWidget) {
......
......@@ -91,7 +91,9 @@ ClipStabilize::ClipStabilize(const std::vector<QString> &binIds, const QString &
QHash<QString, QString> val = hi.value();
if (val[QStringLiteral("type")] == QLatin1String("int") || val[QStringLiteral("type")] == QLatin1String("double")) {
DoubleWidget *dbl = new DoubleWidget(hi.key() /*name*/, val[QStringLiteral("value")].toDouble(), val[QStringLiteral("min")].toDouble(),
val[QStringLiteral("max")].toDouble(), val[QStringLiteral("value")].toDouble(), /*default*/
val[QStringLiteral("max")].toDouble(), val[QStringLiteral("value")].toDouble(),
1,
/*default*/
QString(), /*comment*/
0 /*id*/, QString(), /*suffix*/
val[QStringLiteral("decimals")] != QString() ? val[QStringLiteral("decimals")].toInt() : 0, this);
......
......@@ -22,10 +22,10 @@
#include <QGridLayout>
DoubleWidget::DoubleWidget(const QString &name, double value, double min, double max, double defaultValue, const QString &comment, int id,
DoubleWidget::DoubleWidget(const QString &name, double value, double min, double max, double factor, double defaultValue, const QString &comment, int id,
const QString &suffix, int decimals, QWidget *parent)
: QWidget(parent)
, factor(1)
, m_factor(factor)
{
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
auto *layout = new QGridLayout(this);
......@@ -38,7 +38,7 @@ DoubleWidget::DoubleWidget(const QString &name, double value, double min, double
if (!comment.isEmpty()) {
setToolTip(comment);
}
m_dragVal->setValue(value, false);
m_dragVal->setValue(value * factor, false);
connect(m_dragVal, &DragValue::valueChanged, this, &DoubleWidget::slotSetValue);
}
......@@ -65,7 +65,7 @@ void DoubleWidget::setSpinSize(int width)
void DoubleWidget::setValue(double value)
{
m_dragVal->blockSignals(true);
m_dragVal->setValue(value * factor);
m_dragVal->setValue(value * m_factor);
m_dragVal->blockSignals(false);
}
......@@ -77,7 +77,7 @@ void DoubleWidget::enableEdit(bool enable)
void DoubleWidget::slotSetValue(double value, bool final)
{
if (final) {
emit valueChanged(value / factor);
emit valueChanged(value / m_factor);
}
}
......
......@@ -41,17 +41,15 @@ public:
* @param value Value of the parameter
* @param min Minimum value
* @param max maximum value
* @param factor value, if we want a range 0-1000 for a 0-1 parameter, we can set a factor of 1000
* @param defaultValue Value used when using reset functionality
* @param comment A comment explaining the parameter. Will be shown in a tooltip.
* @param suffix (optional) Suffix to display in spinbox
* @param parent (optional) Parent Widget */
explicit DoubleWidget(const QString &name, double value, double min, double max, double defaultValue, const QString &comment, int id,
explicit DoubleWidget(const QString &name, double value, double min, double max, double factor, double defaultValue, const QString &comment, int id,
const QString &suffix = QString(), int decimals = 0, QWidget *parent = nullptr);
~DoubleWidget();
/** @brief The factor by which real param value is multiplicated to give the slider value. */
double factor;
/** @brief Gets the parameter's value. */
double getValue();
/** @brief Returns minimum size for QSpinBox, used to set all spinboxes to the same width. */
......@@ -77,6 +75,7 @@ private slots:
private:
DragValue *m_dragVal;
double m_factor;
signals:
void valueChanged(double);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment