QmlDesigner: Fix EasingCurve editor

Due to a behavioral change in QTabBar the tabs to choose between the curve editors "factory presets" and "custom presets" got lost.
Reordering the function calls made it appear again.
Prevent the user from assigning the same name to different easing curves.

Fixes: QDS-7720
Fixes: QDS-7721
Change-Id: I247309824868625d2e581f54590dd4c3d99528dd
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Ali Kianian <ali.kianian@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Knud Dollereder
2022-09-30 13:30:54 +02:00
parent 8da35bac0f
commit 0482db7a1b
3 changed files with 24 additions and 30 deletions

View File

@@ -91,6 +91,8 @@ EasingCurveDialog::EasingCurveDialog(const QList<ModelNode> &frames, QWidget *pa
presetBar->setDrawBase(false); presetBar->setDrawBase(false);
presetBar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); presetBar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
m_presets->initialize(presetBar);
auto *durationLabel = new QLabel("Duration (ms)"); auto *durationLabel = new QLabel("Duration (ms)");
auto *durationEdit = new QSpinBox; auto *durationEdit = new QSpinBox;
durationEdit->setMaximum(std::numeric_limits<int>::max()); durationEdit->setMaximum(std::numeric_limits<int>::max());
@@ -107,6 +109,8 @@ EasingCurveDialog::EasingCurveDialog(const QList<ModelNode> &frames, QWidget *pa
m_durationLayout->insertSpacing(4, hSpacing); m_durationLayout->insertSpacing(4, hSpacing);
m_durationLayout->addStretch(hSpacing); m_durationLayout->addStretch(hSpacing);
m_splineEditor->setDuration(durationEdit->value());
m_buttons->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); m_buttons->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
auto callButtonsClicked = [this](QAbstractButton *button) { auto callButtonsClicked = [this](QAbstractButton *button) {
buttonsClicked(m_buttons->standardButton(button)); buttonsClicked(m_buttons->standardButton(button));
@@ -152,9 +156,6 @@ EasingCurveDialog::EasingCurveDialog(const QList<ModelNode> &frames, QWidget *pa
connect(animateButton, &QPushButton::clicked, m_splineEditor, &SplineEditor::animate); connect(animateButton, &QPushButton::clicked, m_splineEditor, &SplineEditor::animate);
m_presets->initialize(presetBar);
m_splineEditor->setDuration(durationEdit->value());
resize(QSize(1421, 918)); resize(QSize(1421, 918));
} }

View File

@@ -55,6 +55,19 @@ constexpr int spacingg = 5;
const QColor background = Qt::white; const QColor background = Qt::white;
QString makeNameUnique(const QString& name, const QStringList& currentNames)
{
QString n = name;
int idx = 0;
while (true) {
if (!currentNames.contains(n))
return n;
n = name + "_" + QString::number(idx++);
}
return {};
}
PresetItemDelegate::PresetItemDelegate(const QColor& background) PresetItemDelegate::PresetItemDelegate(const QColor& background)
: QStyledItemDelegate() : QStyledItemDelegate()
, m_background(background) , m_background(background)
@@ -388,7 +401,7 @@ void PresetList::createItem()
{ {
EasingCurve curve; EasingCurve curve;
curve.makeDefault(); curve.makeDefault();
createItem(createUniqueName(), curve); createItem(makeNameUnique("Default", allNames()), curve);
} }
void PresetList::createItem(const QString &name, const EasingCurve &curve) void PresetList::createItem(const QString &name, const EasingCurve &curve)
@@ -424,27 +437,6 @@ void PresetList::setItemData(const QModelIndex &index, const QVariant &curve, co
} }
} }
QString PresetList::createUniqueName() const
{
QStringList names = allNames();
auto nameIsUnique = [&](const QString &name) {
auto iter = std::find(names.begin(), names.end(), name);
if (iter == names.end())
return true;
else
return false;
};
int counter = 0;
QString tmp("Default");
QString name = tmp;
while (!nameIsUnique(name))
name = tmp + QString(" %1").arg(counter++);
return name;
}
QStringList PresetList::allNames() const QStringList PresetList::allNames() const
{ {
QStringList names; QStringList names;
@@ -551,7 +543,8 @@ bool PresetEditor::writePresets(const EasingCurve &curve)
if (ok && !name.isEmpty()) { if (ok && !name.isEmpty()) {
activate(m_customs->index()); activate(m_customs->index());
m_customs->createItem(name, curve); QString uname = makeNameUnique(name, m_customs->allNames());
m_customs->createItem(uname, curve);
} }
} }

View File

@@ -38,6 +38,8 @@ namespace QmlDesigner {
class EasingCurve; class EasingCurve;
class NamedEasingCurve; class NamedEasingCurve;
QString makeNameUnique(const QString& name, const QStringList& currentNames);
class PresetItemDelegate : public QStyledItemDelegate class PresetItemDelegate : public QStyledItemDelegate
{ {
Q_OBJECT Q_OBJECT
@@ -87,6 +89,8 @@ public:
QColor curveColor() const; QColor curveColor() const;
QStringList allNames() const;
void initialize(int index); void initialize(int index);
void readPresets(); void readPresets();
@@ -111,12 +115,8 @@ protected:
const QVector<int> &roles = QVector<int>()) override; const QVector<int> &roles = QVector<int>()) override;
private: private:
QStringList allNames() const;
QList<NamedEasingCurve> storedCurves() const; QList<NamedEasingCurve> storedCurves() const;
QString createUniqueName() const;
void removeSelectedItem(); void removeSelectedItem();
private: private: