forked from qt-creator/qt-creator
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:
@@ -91,6 +91,8 @@ EasingCurveDialog::EasingCurveDialog(const QList<ModelNode> &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<int>::max());
|
||||
@@ -107,6 +109,8 @@ EasingCurveDialog::EasingCurveDialog(const QList<ModelNode> &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<ModelNode> &frames, QWidget *pa
|
||||
|
||||
connect(animateButton, &QPushButton::clicked, m_splineEditor, &SplineEditor::animate);
|
||||
|
||||
m_presets->initialize(presetBar);
|
||||
|
||||
m_splineEditor->setDuration(durationEdit->value());
|
||||
|
||||
resize(QSize(1421, 918));
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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<int> &roles = QVector<int>()) override;
|
||||
|
||||
private:
|
||||
QStringList allNames() const;
|
||||
|
||||
QList<NamedEasingCurve> storedCurves() const;
|
||||
|
||||
QString createUniqueName() const;
|
||||
|
||||
void removeSelectedItem();
|
||||
|
||||
private:
|
||||
|
Reference in New Issue
Block a user