diff options
Diffstat (limited to 'src/widgets/dialogs/qinputdialog.cpp')
-rw-r--r-- | src/widgets/dialogs/qinputdialog.cpp | 186 |
1 files changed, 45 insertions, 141 deletions
diff --git a/src/widgets/dialogs/qinputdialog.cpp b/src/widgets/dialogs/qinputdialog.cpp index 3cfe8367e0..6d1a0b2873 100644 --- a/src/widgets/dialogs/qinputdialog.cpp +++ b/src/widgets/dialogs/qinputdialog.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWidgets module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qinputdialog.h" @@ -54,6 +18,8 @@ #include "qevent.h" #include "qdialog_p.h" +#include <QtCore/qpointer.h> + QT_USE_NAMESPACE enum CandidateSignal { @@ -74,8 +40,7 @@ static const char *candidateSignal(int which) case NumCandidateSignals: break; }; - Q_UNREACHABLE(); - return nullptr; + Q_UNREACHABLE_RETURN(nullptr); } static const char *signalForMember(const char *member) @@ -105,8 +70,10 @@ class QInputDialogSpinBox : public QSpinBox public: QInputDialogSpinBox(QWidget *parent) : QSpinBox(parent) { - connect(lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(notifyTextChanged())); - connect(this, SIGNAL(editingFinished()), this, SLOT(notifyTextChanged())); + connect(lineEdit(), &QLineEdit::textChanged, + this, &QInputDialogSpinBox::notifyTextChanged); + connect(this, &QInputDialogSpinBox::editingFinished, + this, &QInputDialogSpinBox::notifyTextChanged); } signals: @@ -118,9 +85,7 @@ private slots: private: void keyPressEvent(QKeyEvent *event) override { if ((event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) && !hasAcceptableInput()) { -#ifndef QT_NO_PROPERTIES setProperty("value", property("value")); -#endif } else { QSpinBox::keyPressEvent(event); } @@ -138,10 +103,12 @@ class QInputDialogDoubleSpinBox : public QDoubleSpinBox Q_OBJECT public: - QInputDialogDoubleSpinBox(QWidget *parent = 0) + QInputDialogDoubleSpinBox(QWidget *parent = nullptr) : QDoubleSpinBox(parent) { - connect(lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(notifyTextChanged())); - connect(this, SIGNAL(editingFinished()), this, SLOT(notifyTextChanged())); + connect(lineEdit(), &QLineEdit::textChanged, + this, &QInputDialogDoubleSpinBox::notifyTextChanged); + connect(this, &QInputDialogDoubleSpinBox::editingFinished, + this, &QInputDialogDoubleSpinBox::notifyTextChanged); } signals: @@ -153,9 +120,7 @@ private slots: private: void keyPressEvent(QKeyEvent *event) override { if ((event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) && !hasAcceptableInput()) { -#ifndef QT_NO_PROPERTIES setProperty("value", property("value")); -#endif } else { QDoubleSpinBox::keyPressEvent(event); } @@ -171,7 +136,7 @@ private: class QInputDialogListView : public QListView { public: - QInputDialogListView(QWidget *parent = 0) : QListView(parent) {} + QInputDialogListView(QWidget *parent = nullptr) : QListView(parent) {} QVariant inputMethodQuery(Qt::InputMethodQuery query) const override { if (query == Qt::ImEnabled) @@ -202,9 +167,9 @@ public: QString listViewText() const; void ensureLayout() const { const_cast<QInputDialogPrivate *>(this)->ensureLayout(); } bool useComboBoxOrListView() const { return comboBox && comboBox->count() > 0; } - void _q_textChanged(const QString &text); - void _q_plainTextEditTextChanged(); - void _q_currentRowChanged(const QModelIndex &newIndex, const QModelIndex &oldIndex); + void textChanged(const QString &text); + void plainTextEditTextChanged(); + void currentRowChanged(const QModelIndex &newIndex, const QModelIndex &oldIndex); mutable QLabel *label; mutable QDialogButtonBox *buttonBox; @@ -223,8 +188,8 @@ public: }; QInputDialogPrivate::QInputDialogPrivate() - : label(0), buttonBox(0), lineEdit(0), plainTextEdit(0), intSpinBox(0), doubleSpinBox(0), - comboBox(0), listView(0), inputWidget(0), mainLayout(0) + : label(nullptr), buttonBox(nullptr), lineEdit(nullptr), plainTextEdit(nullptr), intSpinBox(nullptr), doubleSpinBox(nullptr), + comboBox(nullptr), listView(nullptr), inputWidget(nullptr), mainLayout(nullptr) { } @@ -248,8 +213,8 @@ void QInputDialogPrivate::ensureLayout() label->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, q); - QObject::connect(buttonBox, SIGNAL(accepted()), q, SLOT(accept())); - QObject::connect(buttonBox, SIGNAL(rejected()), q, SLOT(reject())); + QObject::connect(buttonBox, &QDialogButtonBox::accepted, q, &QDialog::accept); + QObject::connect(buttonBox, &QDialogButtonBox::rejected, q, &QDialog::reject); mainLayout = new QVBoxLayout(q); mainLayout->setSizeConstraint(QLayout::SetMinAndMaxSize); @@ -269,8 +234,8 @@ void QInputDialogPrivate::ensureLineEdit() qt_widget_private(lineEdit)->inheritsInputMethodHints = 1; #endif lineEdit->hide(); - QObject::connect(lineEdit, SIGNAL(textChanged(QString)), - q, SLOT(_q_textChanged(QString))); + QObjectPrivate::connect(lineEdit, &QLineEdit::textChanged, + this, &QInputDialogPrivate::textChanged); } } @@ -284,8 +249,8 @@ void QInputDialogPrivate::ensurePlainTextEdit() qt_widget_private(plainTextEdit)->inheritsInputMethodHints = 1; #endif plainTextEdit->hide(); - QObject::connect(plainTextEdit, SIGNAL(textChanged()), - q, SLOT(_q_plainTextEditTextChanged())); + QObjectPrivate::connect(plainTextEdit, &QPlainTextEdit::textChanged, + this, &QInputDialogPrivate::plainTextEditTextChanged); } } @@ -298,10 +263,10 @@ void QInputDialogPrivate::ensureComboBox() qt_widget_private(comboBox)->inheritsInputMethodHints = 1; #endif comboBox->hide(); - QObject::connect(comboBox, SIGNAL(editTextChanged(QString)), - q, SLOT(_q_textChanged(QString))); - QObject::connect(comboBox, SIGNAL(currentIndexChanged(QString)), - q, SLOT(_q_textChanged(QString))); + QObjectPrivate::connect(comboBox, &QComboBox::editTextChanged, + this, &QInputDialogPrivate::textChanged); + QObjectPrivate::connect(comboBox, &QComboBox::currentTextChanged, + this, &QInputDialogPrivate::textChanged); } } @@ -316,9 +281,9 @@ void QInputDialogPrivate::ensureListView() listView->setSelectionMode(QAbstractItemView::SingleSelection); listView->setModel(comboBox->model()); listView->setCurrentIndex(QModelIndex()); // ### - QObject::connect(listView->selectionModel(), - SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), - q, SLOT(_q_currentRowChanged(QModelIndex,QModelIndex))); + QObjectPrivate::connect(listView->selectionModel(), + &QItemSelectionModel::currentRowChanged, + this, &QInputDialogPrivate::currentRowChanged); } } @@ -328,8 +293,8 @@ void QInputDialogPrivate::ensureIntSpinBox() if (!intSpinBox) { intSpinBox = new QInputDialogSpinBox(q); intSpinBox->hide(); - QObject::connect(intSpinBox, SIGNAL(valueChanged(int)), - q, SIGNAL(intValueChanged(int))); + QObject::connect(intSpinBox, &QInputDialogSpinBox::valueChanged, + q, &QInputDialog::intValueChanged); } } @@ -339,8 +304,8 @@ void QInputDialogPrivate::ensureDoubleSpinBox() if (!doubleSpinBox) { doubleSpinBox = new QInputDialogDoubleSpinBox(q); doubleSpinBox->hide(); - QObject::connect(doubleSpinBox, SIGNAL(valueChanged(double)), - q, SIGNAL(doubleValueChanged(double))); + QObject::connect(doubleSpinBox, &QInputDialogDoubleSpinBox::valueChanged, + q, &QInputDialog::doubleValueChanged); } } @@ -415,9 +380,9 @@ void QInputDialogPrivate::chooseRightTextInputWidget() setInputWidget(widget); if (inputWidget == comboBox) { - _q_textChanged(comboBox->currentText()); + textChanged(comboBox->currentText()); } else if (inputWidget == listView) { - _q_textChanged(listViewText()); + textChanged(listViewText()); } } @@ -451,7 +416,7 @@ QString QInputDialogPrivate::listViewText() const } } -void QInputDialogPrivate::_q_textChanged(const QString &text) +void QInputDialogPrivate::textChanged(const QString &text) { Q_Q(QInputDialog); if (textValue != text) { @@ -460,7 +425,7 @@ void QInputDialogPrivate::_q_textChanged(const QString &text) } } -void QInputDialogPrivate::_q_plainTextEditTextChanged() +void QInputDialogPrivate::plainTextEditTextChanged() { Q_Q(QInputDialog); QString text = plainTextEdit->toPlainText(); @@ -470,10 +435,10 @@ void QInputDialogPrivate::_q_plainTextEditTextChanged() } } -void QInputDialogPrivate::_q_currentRowChanged(const QModelIndex &newIndex, - const QModelIndex & /* oldIndex */) +void QInputDialogPrivate::currentRowChanged(const QModelIndex &newIndex, + const QModelIndex & /* oldIndex */) { - _q_textChanged(comboBox->model()->data(newIndex).toString()); + textChanged(comboBox->model()->data(newIndex).toString()); buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); } @@ -1174,7 +1139,7 @@ void QInputDialog::done(int result) if (d->receiverToDisconnectOnClose) { disconnect(this, signalForMember(d->memberToDisconnectOnClose), d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose); - d->receiverToDisconnectOnClose = 0; + d->receiverToDisconnectOnClose = nullptr; } d->memberToDisconnectOnClose.clear(); } @@ -1322,67 +1287,6 @@ int QInputDialog::getInt(QWidget *parent, const QString &title, const QString &l } /*! - \fn int QInputDialog::getInteger(QWidget *parent, const QString &title, const QString &label, int value, int min, int max, int step, bool *ok, Qt::WindowFlags flags) - \deprecated use getInt() - - Static convenience function to get an integer input from the user. - - \a title is the text which is displayed in the title bar of the dialog. - \a label is the text which is shown to the user (it should say what should - be entered). - \a value is the default integer which the spinbox will be set to. - \a min and \a max are the minimum and maximum values the user may choose. - \a step is the amount by which the values change as the user presses the - arrow buttons to increment or decrement the value. - - If \a ok is nonnull *\a ok will be set to true if the user pressed \uicontrol OK - and to false if the user pressed \uicontrol Cancel. The dialog's parent is - \a parent. The dialog will be modal and uses the widget \a flags. - - On success, this function returns the integer which has been entered by the - user; on failure, it returns the initial \a value. - - Use this static function like this: - - \snippet dialogs/standarddialogs/dialog.cpp 0 - - \sa getText(), getDouble(), getItem(), getMultiLineText() -*/ - -/*! - Static convenience function to get a floating point number from the user. - - \a title is the text which is displayed in the title bar of the dialog. - \a label is the text which is shown to the user (it should say what should - be entered). - \a value is the default floating point number that the line edit will be - set to. - \a min and \a max are the minimum and maximum values the user may choose. - \a decimals is the maximum number of decimal places the number may have. - - If \a ok is nonnull, *\a ok will be set to true if the user pressed \uicontrol OK - and to false if the user pressed \uicontrol Cancel. The dialog's parent is - \a parent. The dialog will be modal and uses the widget \a flags. - - This function returns the floating point number which has been entered by - the user. - - Use this static function like this: - - \snippet dialogs/standarddialogs/dialog.cpp 1 - - \sa getText(), getInt(), getItem(), getMultiLineText() -*/ - -double QInputDialog::getDouble(QWidget *parent, const QString &title, const QString &label, - double value, double min, double max, int decimals, bool *ok, - Qt::WindowFlags flags) -{ - return QInputDialog::getDouble(parent, title, label, value, min, max, decimals, ok, flags, 1.0); -} - -/*! - \overload Static convenience function to get a floating point number from the user. \a title is the text which is displayed in the title bar of the dialog. |