QInputDialog: Use pmf-style connects

Port all string-based signal/slots connections to pmf-style connects.
Exception: Private::ensureEnabledConnection(QAbstractSpinBox*)

Change-Id: Id88fe88a1f9071085a159e1fa6429a6ec02e61bb
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 4fdcb1212d1a67d2e4b5aed28095e22e609d530a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Christian Ehrlicher 2023-12-22 14:17:36 +01:00 committed by Qt Cherry-pick Bot
parent f433e57e53
commit 144fcb8e79
2 changed files with 35 additions and 34 deletions

View File

@ -70,8 +70,10 @@ class QInputDialogSpinBox : public QSpinBox
public: public:
QInputDialogSpinBox(QWidget *parent) QInputDialogSpinBox(QWidget *parent)
: QSpinBox(parent) { : QSpinBox(parent) {
connect(lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(notifyTextChanged())); connect(lineEdit(), &QLineEdit::textChanged,
connect(this, SIGNAL(editingFinished()), this, SLOT(notifyTextChanged())); this, &QInputDialogSpinBox::notifyTextChanged);
connect(this, &QInputDialogSpinBox::editingFinished,
this, &QInputDialogSpinBox::notifyTextChanged);
} }
signals: signals:
@ -103,8 +105,10 @@ class QInputDialogDoubleSpinBox : public QDoubleSpinBox
public: public:
QInputDialogDoubleSpinBox(QWidget *parent = nullptr) QInputDialogDoubleSpinBox(QWidget *parent = nullptr)
: QDoubleSpinBox(parent) { : QDoubleSpinBox(parent) {
connect(lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(notifyTextChanged())); connect(lineEdit(), &QLineEdit::textChanged,
connect(this, SIGNAL(editingFinished()), this, SLOT(notifyTextChanged())); this, &QInputDialogDoubleSpinBox::notifyTextChanged);
connect(this, &QInputDialogDoubleSpinBox::editingFinished,
this, &QInputDialogDoubleSpinBox::notifyTextChanged);
} }
signals: signals:
@ -163,9 +167,9 @@ public:
QString listViewText() const; QString listViewText() const;
void ensureLayout() const { const_cast<QInputDialogPrivate *>(this)->ensureLayout(); } void ensureLayout() const { const_cast<QInputDialogPrivate *>(this)->ensureLayout(); }
bool useComboBoxOrListView() const { return comboBox && comboBox->count() > 0; } bool useComboBoxOrListView() const { return comboBox && comboBox->count() > 0; }
void _q_textChanged(const QString &text); void textChanged(const QString &text);
void _q_plainTextEditTextChanged(); void plainTextEditTextChanged();
void _q_currentRowChanged(const QModelIndex &newIndex, const QModelIndex &oldIndex); void currentRowChanged(const QModelIndex &newIndex, const QModelIndex &oldIndex);
mutable QLabel *label; mutable QLabel *label;
mutable QDialogButtonBox *buttonBox; mutable QDialogButtonBox *buttonBox;
@ -209,8 +213,8 @@ void QInputDialogPrivate::ensureLayout()
label->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); label->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, q); buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, q);
QObject::connect(buttonBox, SIGNAL(accepted()), q, SLOT(accept())); QObject::connect(buttonBox, &QDialogButtonBox::accepted, q, &QDialog::accept);
QObject::connect(buttonBox, SIGNAL(rejected()), q, SLOT(reject())); QObject::connect(buttonBox, &QDialogButtonBox::rejected, q, &QDialog::reject);
mainLayout = new QVBoxLayout(q); mainLayout = new QVBoxLayout(q);
mainLayout->setSizeConstraint(QLayout::SetMinAndMaxSize); mainLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
@ -230,8 +234,8 @@ void QInputDialogPrivate::ensureLineEdit()
qt_widget_private(lineEdit)->inheritsInputMethodHints = 1; qt_widget_private(lineEdit)->inheritsInputMethodHints = 1;
#endif #endif
lineEdit->hide(); lineEdit->hide();
QObject::connect(lineEdit, SIGNAL(textChanged(QString)), QObjectPrivate::connect(lineEdit, &QLineEdit::textChanged,
q, SLOT(_q_textChanged(QString))); this, &QInputDialogPrivate::textChanged);
} }
} }
@ -245,8 +249,8 @@ void QInputDialogPrivate::ensurePlainTextEdit()
qt_widget_private(plainTextEdit)->inheritsInputMethodHints = 1; qt_widget_private(plainTextEdit)->inheritsInputMethodHints = 1;
#endif #endif
plainTextEdit->hide(); plainTextEdit->hide();
QObject::connect(plainTextEdit, SIGNAL(textChanged()), QObjectPrivate::connect(plainTextEdit, &QPlainTextEdit::textChanged,
q, SLOT(_q_plainTextEditTextChanged())); this, &QInputDialogPrivate::plainTextEditTextChanged);
} }
} }
@ -259,10 +263,10 @@ void QInputDialogPrivate::ensureComboBox()
qt_widget_private(comboBox)->inheritsInputMethodHints = 1; qt_widget_private(comboBox)->inheritsInputMethodHints = 1;
#endif #endif
comboBox->hide(); comboBox->hide();
QObject::connect(comboBox, SIGNAL(editTextChanged(QString)), QObjectPrivate::connect(comboBox, &QComboBox::editTextChanged,
q, SLOT(_q_textChanged(QString))); this, &QInputDialogPrivate::textChanged);
QObject::connect(comboBox, SIGNAL(currentTextChanged(QString)), QObjectPrivate::connect(comboBox, &QComboBox::currentTextChanged,
q, SLOT(_q_textChanged(QString))); this, &QInputDialogPrivate::textChanged);
} }
} }
@ -277,9 +281,9 @@ void QInputDialogPrivate::ensureListView()
listView->setSelectionMode(QAbstractItemView::SingleSelection); listView->setSelectionMode(QAbstractItemView::SingleSelection);
listView->setModel(comboBox->model()); listView->setModel(comboBox->model());
listView->setCurrentIndex(QModelIndex()); // ### listView->setCurrentIndex(QModelIndex()); // ###
QObject::connect(listView->selectionModel(), QObjectPrivate::connect(listView->selectionModel(),
SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), &QItemSelectionModel::currentRowChanged,
q, SLOT(_q_currentRowChanged(QModelIndex,QModelIndex))); this, &QInputDialogPrivate::currentRowChanged);
} }
} }
@ -289,8 +293,8 @@ void QInputDialogPrivate::ensureIntSpinBox()
if (!intSpinBox) { if (!intSpinBox) {
intSpinBox = new QInputDialogSpinBox(q); intSpinBox = new QInputDialogSpinBox(q);
intSpinBox->hide(); intSpinBox->hide();
QObject::connect(intSpinBox, SIGNAL(valueChanged(int)), QObject::connect(intSpinBox, &QInputDialogSpinBox::valueChanged,
q, SIGNAL(intValueChanged(int))); q, &QInputDialog::intValueChanged);
} }
} }
@ -300,8 +304,8 @@ void QInputDialogPrivate::ensureDoubleSpinBox()
if (!doubleSpinBox) { if (!doubleSpinBox) {
doubleSpinBox = new QInputDialogDoubleSpinBox(q); doubleSpinBox = new QInputDialogDoubleSpinBox(q);
doubleSpinBox->hide(); doubleSpinBox->hide();
QObject::connect(doubleSpinBox, SIGNAL(valueChanged(double)), QObject::connect(doubleSpinBox, &QInputDialogDoubleSpinBox::valueChanged,
q, SIGNAL(doubleValueChanged(double))); q, &QInputDialog::doubleValueChanged);
} }
} }
@ -376,9 +380,9 @@ void QInputDialogPrivate::chooseRightTextInputWidget()
setInputWidget(widget); setInputWidget(widget);
if (inputWidget == comboBox) { if (inputWidget == comboBox) {
_q_textChanged(comboBox->currentText()); textChanged(comboBox->currentText());
} else if (inputWidget == listView) { } else if (inputWidget == listView) {
_q_textChanged(listViewText()); textChanged(listViewText());
} }
} }
@ -412,7 +416,7 @@ QString QInputDialogPrivate::listViewText() const
} }
} }
void QInputDialogPrivate::_q_textChanged(const QString &text) void QInputDialogPrivate::textChanged(const QString &text)
{ {
Q_Q(QInputDialog); Q_Q(QInputDialog);
if (textValue != text) { if (textValue != text) {
@ -421,7 +425,7 @@ void QInputDialogPrivate::_q_textChanged(const QString &text)
} }
} }
void QInputDialogPrivate::_q_plainTextEditTextChanged() void QInputDialogPrivate::plainTextEditTextChanged()
{ {
Q_Q(QInputDialog); Q_Q(QInputDialog);
QString text = plainTextEdit->toPlainText(); QString text = plainTextEdit->toPlainText();
@ -431,10 +435,10 @@ void QInputDialogPrivate::_q_plainTextEditTextChanged()
} }
} }
void QInputDialogPrivate::_q_currentRowChanged(const QModelIndex &newIndex, void QInputDialogPrivate::currentRowChanged(const QModelIndex &newIndex,
const QModelIndex & /* oldIndex */) const QModelIndex & /* oldIndex */)
{ {
_q_textChanged(comboBox->model()->data(newIndex).toString()); textChanged(comboBox->model()->data(newIndex).toString());
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
} }

View File

@ -161,9 +161,6 @@ public:
private: private:
Q_DISABLE_COPY(QInputDialog) Q_DISABLE_COPY(QInputDialog)
Q_PRIVATE_SLOT(d_func(), void _q_textChanged(const QString&))
Q_PRIVATE_SLOT(d_func(), void _q_plainTextEditTextChanged())
Q_PRIVATE_SLOT(d_func(), void _q_currentRowChanged(const QModelIndex&, const QModelIndex&))
}; };
Q_DECLARE_OPERATORS_FOR_FLAGS(QInputDialog::InputDialogOptions) Q_DECLARE_OPERATORS_FOR_FLAGS(QInputDialog::InputDialogOptions)