From 0482db7a1b23707d46c5dbf84cc4502344aa0bbb Mon Sep 17 00:00:00 2001 From: Knud Dollereder Date: Fri, 30 Sep 2022 13:30:54 +0200 Subject: 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: Reviewed-by: Ali Kianian Reviewed-by: Thomas Hartmann --- .../timelineeditor/easingcurvedialog.cpp | 7 ++-- .../components/timelineeditor/preseteditor.cpp | 39 +++++++++------------- .../components/timelineeditor/preseteditor.h | 8 ++--- 3 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/plugins/qmldesigner/components/timelineeditor/easingcurvedialog.cpp b/src/plugins/qmldesigner/components/timelineeditor/easingcurvedialog.cpp index 79f8141bf0..c42c580991 100644 --- a/src/plugins/qmldesigner/components/timelineeditor/easingcurvedialog.cpp +++ b/src/plugins/qmldesigner/components/timelineeditor/easingcurvedialog.cpp @@ -91,6 +91,8 @@ EasingCurveDialog::EasingCurveDialog(const QList &frames, QWidget *pa presetBar->setDrawBase(false); presetBar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); + m_presets->initialize(presetBar); + auto *durationLabel = new QLabel("Duration (ms)"); auto *durationEdit = new QSpinBox; durationEdit->setMaximum(std::numeric_limits::max()); @@ -107,6 +109,8 @@ EasingCurveDialog::EasingCurveDialog(const QList &frames, QWidget *pa m_durationLayout->insertSpacing(4, hSpacing); m_durationLayout->addStretch(hSpacing); + m_splineEditor->setDuration(durationEdit->value()); + m_buttons->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); auto callButtonsClicked = [this](QAbstractButton *button) { buttonsClicked(m_buttons->standardButton(button)); @@ -152,9 +156,6 @@ EasingCurveDialog::EasingCurveDialog(const QList &frames, QWidget *pa connect(animateButton, &QPushButton::clicked, m_splineEditor, &SplineEditor::animate); - m_presets->initialize(presetBar); - - m_splineEditor->setDuration(durationEdit->value()); resize(QSize(1421, 918)); } diff --git a/src/plugins/qmldesigner/components/timelineeditor/preseteditor.cpp b/src/plugins/qmldesigner/components/timelineeditor/preseteditor.cpp index d57caf0e1a..bf968523ab 100644 --- a/src/plugins/qmldesigner/components/timelineeditor/preseteditor.cpp +++ b/src/plugins/qmldesigner/components/timelineeditor/preseteditor.cpp @@ -55,6 +55,19 @@ constexpr int spacingg = 5; 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) : QStyledItemDelegate() , m_background(background) @@ -388,7 +401,7 @@ void PresetList::createItem() { EasingCurve curve; curve.makeDefault(); - createItem(createUniqueName(), curve); + createItem(makeNameUnique("Default", allNames()), 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 names; @@ -551,7 +543,8 @@ bool PresetEditor::writePresets(const EasingCurve &curve) if (ok && !name.isEmpty()) { activate(m_customs->index()); - m_customs->createItem(name, curve); + QString uname = makeNameUnique(name, m_customs->allNames()); + m_customs->createItem(uname, curve); } } diff --git a/src/plugins/qmldesigner/components/timelineeditor/preseteditor.h b/src/plugins/qmldesigner/components/timelineeditor/preseteditor.h index 4e805fcf2b..e9eed26538 100644 --- a/src/plugins/qmldesigner/components/timelineeditor/preseteditor.h +++ b/src/plugins/qmldesigner/components/timelineeditor/preseteditor.h @@ -38,6 +38,8 @@ namespace QmlDesigner { class EasingCurve; class NamedEasingCurve; +QString makeNameUnique(const QString& name, const QStringList& currentNames); + class PresetItemDelegate : public QStyledItemDelegate { Q_OBJECT @@ -87,6 +89,8 @@ public: QColor curveColor() const; + QStringList allNames() const; + void initialize(int index); void readPresets(); @@ -111,12 +115,8 @@ protected: const QVector &roles = QVector()) override; private: - QStringList allNames() const; - QList storedCurves() const; - QString createUniqueName() const; - void removeSelectedItem(); private: -- cgit v1.2.3