EasingCurveDialog: Avoid using sender()

Amends a0e551a1e8

Change-Id: I2178d4417214c77a104c0d0840f1de6f460fadb5
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Jarek Kobus
2023-12-13 23:09:45 +01:00
committed by Tim Jenssen
parent 77aeba3c88
commit e436bf47fe
2 changed files with 25 additions and 43 deletions

View File

@@ -41,12 +41,12 @@ EasingCurveDialog::EasingCurveDialog(const QList<ModelNode> &frames, QWidget *pa
{ {
setWindowFlag(Qt::Tool, true); setWindowFlag(Qt::Tool, true);
auto tw = new QTabWidget; m_tabWidget = new QTabWidget;
tw->setTabPosition(QTabWidget::East); m_tabWidget->setTabPosition(QTabWidget::East);
tw->addTab(m_splineEditor, "Curve"); m_tabWidget->addTab(m_splineEditor, "Curve");
tw->addTab(m_text, "Text"); m_tabWidget->addTab(m_text, "Text");
connect(tw, &QTabWidget::currentChanged, this, &EasingCurveDialog::tabClicked); connect(m_tabWidget, &QTabWidget::currentChanged, this, &EasingCurveDialog::tabClicked);
connect(m_text, &QPlainTextEdit::textChanged, this, &EasingCurveDialog::textChanged); connect(m_text, &QPlainTextEdit::textChanged, this, &EasingCurveDialog::textChanged);
auto labelFont = m_label->font(); auto labelFont = m_label->font();
@@ -105,7 +105,7 @@ EasingCurveDialog::EasingCurveDialog(const QList<ModelNode> &frames, QWidget *pa
grid->addLayout(vbox, 0, 0); grid->addLayout(vbox, 0, 0);
grid->addWidget(presetBar, 0, 1, Qt::AlignBottom); grid->addWidget(presetBar, 0, 1, Qt::AlignBottom);
grid->addWidget(tw); grid->addWidget(m_tabWidget);
grid->addWidget(m_presets, 1, 1); grid->addWidget(m_presets, 1, 1);
grid->addLayout(m_durationLayout, 2, 0); grid->addLayout(m_durationLayout, 2, 0);
grid->addLayout(buttonLayout, 2, 1); grid->addLayout(buttonLayout, 2, 1);
@@ -126,7 +126,6 @@ EasingCurveDialog::EasingCurveDialog(const QList<ModelNode> &frames, QWidget *pa
connect(durationEdit, &QSpinBox::valueChanged, m_splineEditor, &SplineEditor::setDuration); connect(durationEdit, &QSpinBox::valueChanged, m_splineEditor, &SplineEditor::setDuration);
connect(animateButton, &QPushButton::clicked, m_splineEditor, &SplineEditor::animate); connect(animateButton, &QPushButton::clicked, m_splineEditor, &SplineEditor::animate);
resize(QSize(1421, 918)); resize(QSize(1421, 918));
} }
@@ -185,7 +184,7 @@ bool EasingCurveDialog::apply()
} }
AbstractView *view = m_frames.first().view(); AbstractView *view = m_frames.first().view();
return view->executeInTransaction("EasingCurveDialog::apply", [this](){ return view->executeInTransaction("EasingCurveDialog::apply", [this] {
auto expression = m_splineEditor->easingCurve().toString(); auto expression = m_splineEditor->easingCurve().toString();
for (const auto &frame : std::as_const(m_frames)) for (const auto &frame : std::as_const(m_frames))
frame.bindingProperty(m_easingCurveProperty).setExpression(expression); frame.bindingProperty(m_easingCurveProperty).setExpression(expression);
@@ -201,30 +200,23 @@ void EasingCurveDialog::textChanged()
void EasingCurveDialog::tabClicked(int id) void EasingCurveDialog::tabClicked(int id)
{ {
if (auto tw = qobject_cast<const QTabWidget *>(sender())) { const int seid = m_tabWidget->indexOf(m_splineEditor);
int seid = tw->indexOf(m_splineEditor);
if (seid == id) { if (seid == id) {
for (int i = 0; i < m_durationLayout->count(); ++i) { for (int i = 0; i < m_durationLayout->count(); ++i) {
auto *item = m_durationLayout->itemAt(i); if (auto *widget = m_durationLayout->itemAt(i)->widget())
if (auto *widget = item->widget())
widget->show(); widget->show();
} }
auto curve = m_splineEditor->easingCurve(); auto curve = m_splineEditor->easingCurve();
curve.fromString(m_text->toPlainText()); curve.fromString(m_text->toPlainText());
m_splineEditor->setEasingCurve(curve); m_splineEditor->setEasingCurve(curve);
} else { } else {
for (int i = 0; i < m_durationLayout->count(); ++i) { for (int i = 0; i < m_durationLayout->count(); ++i) {
auto *item = m_durationLayout->itemAt(i); if (auto *widget = m_durationLayout->itemAt(i)->widget())
if (auto *widget = item->widget())
widget->hide(); widget->hide();
} }
auto curve = m_splineEditor->easingCurve(); auto curve = m_splineEditor->easingCurve();
m_text->setPlainText(curve.toString()); m_text->setPlainText(curve.toString());
} }
}
} }
void EasingCurveDialog::presetTabClicked(int id) void EasingCurveDialog::presetTabClicked(int id)

View File

@@ -9,9 +9,10 @@
#include <modelnode.h> #include <modelnode.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QHBoxLayout;
class QLabel; class QLabel;
class QPlainTextEdit; class QPlainTextEdit;
class QHBoxLayout; class QTabWidget;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace QmlDesigner { namespace QmlDesigner {
@@ -33,32 +34,21 @@ public:
private: private:
bool apply(); bool apply();
void textChanged(); void textChanged();
void tabClicked(int id); void tabClicked(int id);
void presetTabClicked(int id); void presetTabClicked(int id);
void buttonsClicked(QDialogButtonBox::StandardButton button); void buttonsClicked(QDialogButtonBox::StandardButton button);
void updateEasingCurve(const EasingCurve &curve); void updateEasingCurve(const EasingCurve &curve);
private: private:
QTabWidget *m_tabWidget = nullptr;
SplineEditor *m_splineEditor = nullptr; SplineEditor *m_splineEditor = nullptr;
QPlainTextEdit *m_text = nullptr; QPlainTextEdit *m_text = nullptr;
PresetEditor *m_presets = nullptr; PresetEditor *m_presets = nullptr;
QHBoxLayout *m_durationLayout = nullptr; QHBoxLayout *m_durationLayout = nullptr;
QDialogButtonBox *m_buttons = nullptr; QDialogButtonBox *m_buttons = nullptr;
QLabel *m_label = nullptr; QLabel *m_label = nullptr;
QList<ModelNode> m_frames; QList<ModelNode> m_frames;
PropertyName m_easingCurveProperty; PropertyName m_easingCurveProperty;
}; };