| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/dialogs/qinputdialog.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||
| 35 | ** | - | ||||||||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 37 | ** | - | ||||||||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | #include "qinputdialog.h" | - | ||||||||||||||||||
| 41 | - | |||||||||||||||||||
| 42 | #ifndef QT_NO_INPUTDIALOG | - | ||||||||||||||||||
| 43 | - | |||||||||||||||||||
| 44 | #include "qapplication.h" | - | ||||||||||||||||||
| 45 | #include "qcombobox.h" | - | ||||||||||||||||||
| 46 | #include "qdialogbuttonbox.h" | - | ||||||||||||||||||
| 47 | #include "qlabel.h" | - | ||||||||||||||||||
| 48 | #include "qlayout.h" | - | ||||||||||||||||||
| 49 | #include "qlineedit.h" | - | ||||||||||||||||||
| 50 | #include "qplaintextedit.h" | - | ||||||||||||||||||
| 51 | #include "qlistwidget.h" | - | ||||||||||||||||||
| 52 | #include "qpushbutton.h" | - | ||||||||||||||||||
| 53 | #include "qspinbox.h" | - | ||||||||||||||||||
| 54 | #include "qstackedlayout.h" | - | ||||||||||||||||||
| 55 | #include "qvalidator.h" | - | ||||||||||||||||||
| 56 | #include "qevent.h" | - | ||||||||||||||||||
| 57 | #include "qdialog_p.h" | - | ||||||||||||||||||
| 58 | - | |||||||||||||||||||
| 59 | QT_USE_NAMESPACE | - | ||||||||||||||||||
| 60 | - | |||||||||||||||||||
| 61 | enum CandidateSignal { | - | ||||||||||||||||||
| 62 | TextValueSelectedSignal, | - | ||||||||||||||||||
| 63 | IntValueSelectedSignal, | - | ||||||||||||||||||
| 64 | DoubleValueSelectedSignal, | - | ||||||||||||||||||
| 65 | - | |||||||||||||||||||
| 66 | NumCandidateSignals | - | ||||||||||||||||||
| 67 | }; | - | ||||||||||||||||||
| 68 | - | |||||||||||||||||||
| 69 | static const char *candidateSignal(int which) | - | ||||||||||||||||||
| 70 | { | - | ||||||||||||||||||
| 71 | switch (CandidateSignal(which)) { | - | ||||||||||||||||||
| 72 | case TextValueSelectedSignal: return SIGNAL(textValueSelected(QString)); never executed: return qFlagLocation("2""textValueSelected(QString)" "\0" __FILE__ ":" "72");never executed: case TextValueSelectedSignal: | 0 | ||||||||||||||||||
| 73 | case IntValueSelectedSignal: return SIGNAL(intValueSelected(int)); never executed: return qFlagLocation("2""intValueSelected(int)" "\0" __FILE__ ":" "73");never executed: case IntValueSelectedSignal: | 0 | ||||||||||||||||||
| 74 | case DoubleValueSelectedSignal: return SIGNAL(doubleValueSelected(double)); never executed: return qFlagLocation("2""doubleValueSelected(double)" "\0" __FILE__ ":" "74");never executed: case DoubleValueSelectedSignal: | 0 | ||||||||||||||||||
| 75 | - | |||||||||||||||||||
| 76 | case NumCandidateSignals: ; // fall through never executed: case NumCandidateSignals: | 0 | ||||||||||||||||||
| 77 | }; never executed: end of block | 0 | ||||||||||||||||||
| 78 | Q_UNREACHABLE(); | - | ||||||||||||||||||
| 79 | return Q_NULLPTR; never executed: return nullptr; | 0 | ||||||||||||||||||
| 80 | } | - | ||||||||||||||||||
| 81 | - | |||||||||||||||||||
| 82 | static const char *signalForMember(const char *member) | - | ||||||||||||||||||
| 83 | { | - | ||||||||||||||||||
| 84 | QByteArray normalizedMember(QMetaObject::normalizedSignature(member)); | - | ||||||||||||||||||
| 85 | - | |||||||||||||||||||
| 86 | for (int i = 0; i < NumCandidateSignals; ++i)
| 0 | ||||||||||||||||||
| 87 | if (QMetaObject::checkConnectArgs(candidateSignal(i), normalizedMember))
| 0 | ||||||||||||||||||
| 88 | return candidateSignal(i); never executed: return candidateSignal(i); | 0 | ||||||||||||||||||
| 89 | - | |||||||||||||||||||
| 90 | // otherwise, use fit-all accepted signal: | - | ||||||||||||||||||
| 91 | return SIGNAL(accepted()); never executed: return qFlagLocation("2""accepted()" "\0" __FILE__ ":" "91"); | 0 | ||||||||||||||||||
| 92 | } | - | ||||||||||||||||||
| 93 | - | |||||||||||||||||||
| 94 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 95 | - | |||||||||||||||||||
| 96 | /* | - | ||||||||||||||||||
| 97 | These internal classes add extra validation to QSpinBox and QDoubleSpinBox by emitting | - | ||||||||||||||||||
| 98 | textChanged(bool) after events that may potentially change the visible text. Return or | - | ||||||||||||||||||
| 99 | Enter key presses are not propagated if the visible text is invalid. Instead, the visible | - | ||||||||||||||||||
| 100 | text is modified to the last valid value. | - | ||||||||||||||||||
| 101 | */ | - | ||||||||||||||||||
| 102 | class QInputDialogSpinBox : public QSpinBox | - | ||||||||||||||||||
| 103 | { | - | ||||||||||||||||||
| 104 | Q_OBJECT | - | ||||||||||||||||||
| 105 | - | |||||||||||||||||||
| 106 | public: | - | ||||||||||||||||||
| 107 | QInputDialogSpinBox(QWidget *parent) | - | ||||||||||||||||||
| 108 | : QSpinBox(parent) { | - | ||||||||||||||||||
| 109 | connect(lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(notifyTextChanged())); | - | ||||||||||||||||||
| 110 | connect(this, SIGNAL(editingFinished()), this, SLOT(notifyTextChanged())); | - | ||||||||||||||||||
| 111 | } never executed: end of block | 0 | ||||||||||||||||||
| 112 | - | |||||||||||||||||||
| 113 | signals: | - | ||||||||||||||||||
| 114 | void textChanged(bool); | - | ||||||||||||||||||
| 115 | - | |||||||||||||||||||
| 116 | private slots: | - | ||||||||||||||||||
| 117 | void notifyTextChanged() { emit textChanged(hasAcceptableInput()); } never executed: end of block | 0 | ||||||||||||||||||
| 118 | - | |||||||||||||||||||
| 119 | private: | - | ||||||||||||||||||
| 120 | void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE { | - | ||||||||||||||||||
| 121 | if ((event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) && !hasAcceptableInput()) {
| 0 | ||||||||||||||||||
| 122 | #ifndef QT_NO_PROPERTIES | - | ||||||||||||||||||
| 123 | setProperty("value", property("value")); | - | ||||||||||||||||||
| 124 | #endif | - | ||||||||||||||||||
| 125 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 126 | QSpinBox::keyPressEvent(event); | - | ||||||||||||||||||
| 127 | } never executed: end of block | 0 | ||||||||||||||||||
| 128 | notifyTextChanged(); | - | ||||||||||||||||||
| 129 | } never executed: end of block | 0 | ||||||||||||||||||
| 130 | - | |||||||||||||||||||
| 131 | void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE { | - | ||||||||||||||||||
| 132 | QSpinBox::mousePressEvent(event); | - | ||||||||||||||||||
| 133 | notifyTextChanged(); | - | ||||||||||||||||||
| 134 | } never executed: end of block | 0 | ||||||||||||||||||
| 135 | }; | - | ||||||||||||||||||
| 136 | - | |||||||||||||||||||
| 137 | class QInputDialogDoubleSpinBox : public QDoubleSpinBox | - | ||||||||||||||||||
| 138 | { | - | ||||||||||||||||||
| 139 | Q_OBJECT | - | ||||||||||||||||||
| 140 | - | |||||||||||||||||||
| 141 | public: | - | ||||||||||||||||||
| 142 | QInputDialogDoubleSpinBox(QWidget *parent = 0) | - | ||||||||||||||||||
| 143 | : QDoubleSpinBox(parent) { | - | ||||||||||||||||||
| 144 | connect(lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(notifyTextChanged())); | - | ||||||||||||||||||
| 145 | connect(this, SIGNAL(editingFinished()), this, SLOT(notifyTextChanged())); | - | ||||||||||||||||||
| 146 | } never executed: end of block | 0 | ||||||||||||||||||
| 147 | - | |||||||||||||||||||
| 148 | signals: | - | ||||||||||||||||||
| 149 | void textChanged(bool); | - | ||||||||||||||||||
| 150 | - | |||||||||||||||||||
| 151 | private slots: | - | ||||||||||||||||||
| 152 | void notifyTextChanged() { emit textChanged(hasAcceptableInput()); } never executed: end of block | 0 | ||||||||||||||||||
| 153 | - | |||||||||||||||||||
| 154 | private: | - | ||||||||||||||||||
| 155 | void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE { | - | ||||||||||||||||||
| 156 | if ((event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) && !hasAcceptableInput()) {
| 0 | ||||||||||||||||||
| 157 | #ifndef QT_NO_PROPERTIES | - | ||||||||||||||||||
| 158 | setProperty("value", property("value")); | - | ||||||||||||||||||
| 159 | #endif | - | ||||||||||||||||||
| 160 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 161 | QDoubleSpinBox::keyPressEvent(event); | - | ||||||||||||||||||
| 162 | } never executed: end of block | 0 | ||||||||||||||||||
| 163 | notifyTextChanged(); | - | ||||||||||||||||||
| 164 | } never executed: end of block | 0 | ||||||||||||||||||
| 165 | - | |||||||||||||||||||
| 166 | void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE { | - | ||||||||||||||||||
| 167 | QDoubleSpinBox::mousePressEvent(event); | - | ||||||||||||||||||
| 168 | notifyTextChanged(); | - | ||||||||||||||||||
| 169 | } never executed: end of block | 0 | ||||||||||||||||||
| 170 | }; | - | ||||||||||||||||||
| 171 | - | |||||||||||||||||||
| 172 | class QInputDialogPrivate : public QDialogPrivate | - | ||||||||||||||||||
| 173 | { | - | ||||||||||||||||||
| 174 | Q_DECLARE_PUBLIC(QInputDialog) | - | ||||||||||||||||||
| 175 | - | |||||||||||||||||||
| 176 | public: | - | ||||||||||||||||||
| 177 | QInputDialogPrivate(); | - | ||||||||||||||||||
| 178 | - | |||||||||||||||||||
| 179 | void ensureLayout(); | - | ||||||||||||||||||
| 180 | void ensureLineEdit(); | - | ||||||||||||||||||
| 181 | void ensurePlainTextEdit(); | - | ||||||||||||||||||
| 182 | void ensureComboBox(); | - | ||||||||||||||||||
| 183 | void ensureListView(); | - | ||||||||||||||||||
| 184 | void ensureIntSpinBox(); | - | ||||||||||||||||||
| 185 | void ensureDoubleSpinBox(); | - | ||||||||||||||||||
| 186 | void ensureEnabledConnection(QAbstractSpinBox *spinBox); | - | ||||||||||||||||||
| 187 | void setInputWidget(QWidget *widget); | - | ||||||||||||||||||
| 188 | void chooseRightTextInputWidget(); | - | ||||||||||||||||||
| 189 | void setComboBoxText(const QString &text); | - | ||||||||||||||||||
| 190 | void setListViewText(const QString &text); | - | ||||||||||||||||||
| 191 | QString listViewText() const; | - | ||||||||||||||||||
| 192 | void ensureLayout() const { const_cast<QInputDialogPrivate *>(this)->ensureLayout(); } never executed: end of block | 0 | ||||||||||||||||||
| 193 | bool useComboBoxOrListView() const { return comboBox && comboBox->count() > 0; } never executed: return comboBox && comboBox->count() > 0; | 0 | ||||||||||||||||||
| 194 | void _q_textChanged(const QString &text); | - | ||||||||||||||||||
| 195 | void _q_plainTextEditTextChanged(); | - | ||||||||||||||||||
| 196 | void _q_currentRowChanged(const QModelIndex &newIndex, const QModelIndex &oldIndex); | - | ||||||||||||||||||
| 197 | - | |||||||||||||||||||
| 198 | mutable QLabel *label; | - | ||||||||||||||||||
| 199 | mutable QDialogButtonBox *buttonBox; | - | ||||||||||||||||||
| 200 | mutable QLineEdit *lineEdit; | - | ||||||||||||||||||
| 201 | mutable QPlainTextEdit *plainTextEdit; | - | ||||||||||||||||||
| 202 | mutable QSpinBox *intSpinBox; | - | ||||||||||||||||||
| 203 | mutable QDoubleSpinBox *doubleSpinBox; | - | ||||||||||||||||||
| 204 | mutable QComboBox *comboBox; | - | ||||||||||||||||||
| 205 | mutable QListView *listView; | - | ||||||||||||||||||
| 206 | mutable QWidget *inputWidget; | - | ||||||||||||||||||
| 207 | mutable QVBoxLayout *mainLayout; | - | ||||||||||||||||||
| 208 | QInputDialog::InputDialogOptions opts; | - | ||||||||||||||||||
| 209 | QString textValue; | - | ||||||||||||||||||
| 210 | QPointer<QObject> receiverToDisconnectOnClose; | - | ||||||||||||||||||
| 211 | QByteArray memberToDisconnectOnClose; | - | ||||||||||||||||||
| 212 | }; | - | ||||||||||||||||||
| 213 | - | |||||||||||||||||||
| 214 | QInputDialogPrivate::QInputDialogPrivate() | - | ||||||||||||||||||
| 215 | : label(0), buttonBox(0), lineEdit(0), plainTextEdit(0), intSpinBox(0), doubleSpinBox(0), | - | ||||||||||||||||||
| 216 | comboBox(0), listView(0), inputWidget(0), mainLayout(0) | - | ||||||||||||||||||
| 217 | { | - | ||||||||||||||||||
| 218 | } never executed: end of block | 0 | ||||||||||||||||||
| 219 | - | |||||||||||||||||||
| 220 | void QInputDialogPrivate::ensureLayout() | - | ||||||||||||||||||
| 221 | { | - | ||||||||||||||||||
| 222 | Q_Q(QInputDialog); | - | ||||||||||||||||||
| 223 | - | |||||||||||||||||||
| 224 | if (mainLayout)
| 0 | ||||||||||||||||||
| 225 | return; never executed: return; | 0 | ||||||||||||||||||
| 226 | - | |||||||||||||||||||
| 227 | if (!inputWidget) {
| 0 | ||||||||||||||||||
| 228 | ensureLineEdit(); | - | ||||||||||||||||||
| 229 | inputWidget = lineEdit; | - | ||||||||||||||||||
| 230 | } never executed: end of block | 0 | ||||||||||||||||||
| 231 | - | |||||||||||||||||||
| 232 | if (!label)
| 0 | ||||||||||||||||||
| 233 | label = new QLabel(QInputDialog::tr("Enter a value:"), q); never executed: label = new QLabel(QInputDialog::tr("Enter a value:"), q); | 0 | ||||||||||||||||||
| 234 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||
| 235 | label->setBuddy(inputWidget); | - | ||||||||||||||||||
| 236 | #endif | - | ||||||||||||||||||
| 237 | label->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); | - | ||||||||||||||||||
| 238 | - | |||||||||||||||||||
| 239 | buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, q); | - | ||||||||||||||||||
| 240 | QObject::connect(buttonBox, SIGNAL(accepted()), q, SLOT(accept())); | - | ||||||||||||||||||
| 241 | QObject::connect(buttonBox, SIGNAL(rejected()), q, SLOT(reject())); | - | ||||||||||||||||||
| 242 | - | |||||||||||||||||||
| 243 | mainLayout = new QVBoxLayout(q); | - | ||||||||||||||||||
| 244 | //we want to let the input dialog grow to available size on Symbian. | - | ||||||||||||||||||
| 245 | mainLayout->setSizeConstraint(QLayout::SetMinAndMaxSize); | - | ||||||||||||||||||
| 246 | mainLayout->addWidget(label); | - | ||||||||||||||||||
| 247 | mainLayout->addWidget(inputWidget); | - | ||||||||||||||||||
| 248 | mainLayout->addWidget(buttonBox); | - | ||||||||||||||||||
| 249 | ensureEnabledConnection(qobject_cast<QAbstractSpinBox *>(inputWidget)); | - | ||||||||||||||||||
| 250 | inputWidget->show(); | - | ||||||||||||||||||
| 251 | } never executed: end of block | 0 | ||||||||||||||||||
| 252 | - | |||||||||||||||||||
| 253 | void QInputDialogPrivate::ensureLineEdit() | - | ||||||||||||||||||
| 254 | { | - | ||||||||||||||||||
| 255 | Q_Q(QInputDialog); | - | ||||||||||||||||||
| 256 | if (!lineEdit) {
| 0 | ||||||||||||||||||
| 257 | lineEdit = new QLineEdit(q); | - | ||||||||||||||||||
| 258 | #ifndef QT_NO_IM | - | ||||||||||||||||||
| 259 | qt_widget_private(lineEdit)->inheritsInputMethodHints = 1; | - | ||||||||||||||||||
| 260 | #endif | - | ||||||||||||||||||
| 261 | lineEdit->hide(); | - | ||||||||||||||||||
| 262 | QObject::connect(lineEdit, SIGNAL(textChanged(QString)), | - | ||||||||||||||||||
| 263 | q, SLOT(_q_textChanged(QString))); | - | ||||||||||||||||||
| 264 | } never executed: end of block | 0 | ||||||||||||||||||
| 265 | } never executed: end of block | 0 | ||||||||||||||||||
| 266 | - | |||||||||||||||||||
| 267 | void QInputDialogPrivate::ensurePlainTextEdit() | - | ||||||||||||||||||
| 268 | { | - | ||||||||||||||||||
| 269 | Q_Q(QInputDialog); | - | ||||||||||||||||||
| 270 | if (!plainTextEdit) {
| 0 | ||||||||||||||||||
| 271 | plainTextEdit = new QPlainTextEdit(q); | - | ||||||||||||||||||
| 272 | plainTextEdit->setLineWrapMode(QPlainTextEdit::NoWrap); | - | ||||||||||||||||||
| 273 | #ifndef QT_NO_IM | - | ||||||||||||||||||
| 274 | qt_widget_private(plainTextEdit)->inheritsInputMethodHints = 1; | - | ||||||||||||||||||
| 275 | #endif | - | ||||||||||||||||||
| 276 | plainTextEdit->hide(); | - | ||||||||||||||||||
| 277 | QObject::connect(plainTextEdit, SIGNAL(textChanged()), | - | ||||||||||||||||||
| 278 | q, SLOT(_q_plainTextEditTextChanged())); | - | ||||||||||||||||||
| 279 | } never executed: end of block | 0 | ||||||||||||||||||
| 280 | } never executed: end of block | 0 | ||||||||||||||||||
| 281 | - | |||||||||||||||||||
| 282 | void QInputDialogPrivate::ensureComboBox() | - | ||||||||||||||||||
| 283 | { | - | ||||||||||||||||||
| 284 | Q_Q(QInputDialog); | - | ||||||||||||||||||
| 285 | if (!comboBox) {
| 0 | ||||||||||||||||||
| 286 | comboBox = new QComboBox(q); | - | ||||||||||||||||||
| 287 | #ifndef QT_NO_IM | - | ||||||||||||||||||
| 288 | qt_widget_private(comboBox)->inheritsInputMethodHints = 1; | - | ||||||||||||||||||
| 289 | #endif | - | ||||||||||||||||||
| 290 | comboBox->hide(); | - | ||||||||||||||||||
| 291 | QObject::connect(comboBox, SIGNAL(editTextChanged(QString)), | - | ||||||||||||||||||
| 292 | q, SLOT(_q_textChanged(QString))); | - | ||||||||||||||||||
| 293 | QObject::connect(comboBox, SIGNAL(currentIndexChanged(QString)), | - | ||||||||||||||||||
| 294 | q, SLOT(_q_textChanged(QString))); | - | ||||||||||||||||||
| 295 | } never executed: end of block | 0 | ||||||||||||||||||
| 296 | } never executed: end of block | 0 | ||||||||||||||||||
| 297 | - | |||||||||||||||||||
| 298 | void QInputDialogPrivate::ensureListView() | - | ||||||||||||||||||
| 299 | { | - | ||||||||||||||||||
| 300 | Q_Q(QInputDialog); | - | ||||||||||||||||||
| 301 | if (!listView) {
| 0 | ||||||||||||||||||
| 302 | ensureComboBox(); | - | ||||||||||||||||||
| 303 | - | |||||||||||||||||||
| 304 | listView = new QListView(q); | - | ||||||||||||||||||
| 305 | listView->hide(); | - | ||||||||||||||||||
| 306 | listView->setEditTriggers(QAbstractItemView::NoEditTriggers); | - | ||||||||||||||||||
| 307 | listView->setSelectionMode(QAbstractItemView::SingleSelection); | - | ||||||||||||||||||
| 308 | listView->setModel(comboBox->model()); | - | ||||||||||||||||||
| 309 | listView->setCurrentIndex(QModelIndex()); // ### | - | ||||||||||||||||||
| 310 | QObject::connect(listView->selectionModel(), | - | ||||||||||||||||||
| 311 | SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), | - | ||||||||||||||||||
| 312 | q, SLOT(_q_currentRowChanged(QModelIndex,QModelIndex))); | - | ||||||||||||||||||
| 313 | } never executed: end of block | 0 | ||||||||||||||||||
| 314 | } never executed: end of block | 0 | ||||||||||||||||||
| 315 | - | |||||||||||||||||||
| 316 | void QInputDialogPrivate::ensureIntSpinBox() | - | ||||||||||||||||||
| 317 | { | - | ||||||||||||||||||
| 318 | Q_Q(QInputDialog); | - | ||||||||||||||||||
| 319 | if (!intSpinBox) {
| 0 | ||||||||||||||||||
| 320 | intSpinBox = new QInputDialogSpinBox(q); | - | ||||||||||||||||||
| 321 | intSpinBox->hide(); | - | ||||||||||||||||||
| 322 | QObject::connect(intSpinBox, SIGNAL(valueChanged(int)), | - | ||||||||||||||||||
| 323 | q, SIGNAL(intValueChanged(int))); | - | ||||||||||||||||||
| 324 | } never executed: end of block | 0 | ||||||||||||||||||
| 325 | } never executed: end of block | 0 | ||||||||||||||||||
| 326 | - | |||||||||||||||||||
| 327 | void QInputDialogPrivate::ensureDoubleSpinBox() | - | ||||||||||||||||||
| 328 | { | - | ||||||||||||||||||
| 329 | Q_Q(QInputDialog); | - | ||||||||||||||||||
| 330 | if (!doubleSpinBox) {
| 0 | ||||||||||||||||||
| 331 | doubleSpinBox = new QInputDialogDoubleSpinBox(q); | - | ||||||||||||||||||
| 332 | doubleSpinBox->hide(); | - | ||||||||||||||||||
| 333 | QObject::connect(doubleSpinBox, SIGNAL(valueChanged(double)), | - | ||||||||||||||||||
| 334 | q, SIGNAL(doubleValueChanged(double))); | - | ||||||||||||||||||
| 335 | } never executed: end of block | 0 | ||||||||||||||||||
| 336 | } never executed: end of block | 0 | ||||||||||||||||||
| 337 | - | |||||||||||||||||||
| 338 | void QInputDialogPrivate::ensureEnabledConnection(QAbstractSpinBox *spinBox) | - | ||||||||||||||||||
| 339 | { | - | ||||||||||||||||||
| 340 | if (spinBox) {
| 0 | ||||||||||||||||||
| 341 | QAbstractButton *okButton = buttonBox->button(QDialogButtonBox::Ok); | - | ||||||||||||||||||
| 342 | QObject::connect(spinBox, SIGNAL(textChanged(bool)), okButton, SLOT(setEnabled(bool)), Qt::UniqueConnection); | - | ||||||||||||||||||
| 343 | } never executed: end of block | 0 | ||||||||||||||||||
| 344 | } never executed: end of block | 0 | ||||||||||||||||||
| 345 | - | |||||||||||||||||||
| 346 | void QInputDialogPrivate::setInputWidget(QWidget *widget) | - | ||||||||||||||||||
| 347 | { | - | ||||||||||||||||||
| 348 | Q_ASSERT(widget); | - | ||||||||||||||||||
| 349 | if (inputWidget == widget)
| 0 | ||||||||||||||||||
| 350 | return; never executed: return; | 0 | ||||||||||||||||||
| 351 | - | |||||||||||||||||||
| 352 | if (mainLayout) {
| 0 | ||||||||||||||||||
| 353 | Q_ASSERT(inputWidget); | - | ||||||||||||||||||
| 354 | mainLayout->removeWidget(inputWidget); | - | ||||||||||||||||||
| 355 | inputWidget->hide(); | - | ||||||||||||||||||
| 356 | mainLayout->insertWidget(1, widget); | - | ||||||||||||||||||
| 357 | widget->show(); | - | ||||||||||||||||||
| 358 | - | |||||||||||||||||||
| 359 | // disconnect old input widget | - | ||||||||||||||||||
| 360 | QAbstractButton *okButton = buttonBox->button(QDialogButtonBox::Ok); | - | ||||||||||||||||||
| 361 | if (QAbstractSpinBox *spinBox = qobject_cast<QAbstractSpinBox *>(inputWidget))
| 0 | ||||||||||||||||||
| 362 | QObject::disconnect(spinBox, SIGNAL(textChanged(bool)), okButton, SLOT(setEnabled(bool))); never executed: QObject::disconnect(spinBox, qFlagLocation("2""textChanged(bool)" "\0" __FILE__ ":" "362"), okButton, qFlagLocation("1""setEnabled(bool)" "\0" __FILE__ ":" "362")); | 0 | ||||||||||||||||||
| 363 | - | |||||||||||||||||||
| 364 | // connect new input widget and update enabled state of OK button | - | ||||||||||||||||||
| 365 | QAbstractSpinBox *spinBox = qobject_cast<QAbstractSpinBox *>(widget); | - | ||||||||||||||||||
| 366 | ensureEnabledConnection(spinBox); | - | ||||||||||||||||||
| 367 | okButton->setEnabled(!spinBox || spinBox->hasAcceptableInput()); | - | ||||||||||||||||||
| 368 | } never executed: end of block | 0 | ||||||||||||||||||
| 369 | - | |||||||||||||||||||
| 370 | inputWidget = widget; | - | ||||||||||||||||||
| 371 | - | |||||||||||||||||||
| 372 | // synchronize the text shown in the new text editor with the current | - | ||||||||||||||||||
| 373 | // textValue | - | ||||||||||||||||||
| 374 | if (widget == lineEdit) {
| 0 | ||||||||||||||||||
| 375 | lineEdit->setText(textValue); | - | ||||||||||||||||||
| 376 | } else if (widget == plainTextEdit) { never executed: end of block
| 0 | ||||||||||||||||||
| 377 | plainTextEdit->setPlainText(textValue); | - | ||||||||||||||||||
| 378 | } else if (widget == comboBox) { never executed: end of block
| 0 | ||||||||||||||||||
| 379 | setComboBoxText(textValue); | - | ||||||||||||||||||
| 380 | } else if (widget == listView) { never executed: end of block
| 0 | ||||||||||||||||||
| 381 | setListViewText(textValue); | - | ||||||||||||||||||
| 382 | ensureLayout(); | - | ||||||||||||||||||
| 383 | buttonBox->button(QDialogButtonBox::Ok)->setEnabled(listView->selectionModel()->hasSelection()); | - | ||||||||||||||||||
| 384 | } never executed: end of block | 0 | ||||||||||||||||||
| 385 | } never executed: end of block | 0 | ||||||||||||||||||
| 386 | - | |||||||||||||||||||
| 387 | void QInputDialogPrivate::chooseRightTextInputWidget() | - | ||||||||||||||||||
| 388 | { | - | ||||||||||||||||||
| 389 | QWidget *widget; | - | ||||||||||||||||||
| 390 | - | |||||||||||||||||||
| 391 | if (useComboBoxOrListView()) {
| 0 | ||||||||||||||||||
| 392 | if ((opts & QInputDialog::UseListViewForComboBoxItems) && !comboBox->isEditable()) {
| 0 | ||||||||||||||||||
| 393 | ensureListView(); | - | ||||||||||||||||||
| 394 | widget = listView; | - | ||||||||||||||||||
| 395 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 396 | widget = comboBox; | - | ||||||||||||||||||
| 397 | } never executed: end of block | 0 | ||||||||||||||||||
| 398 | } else if (opts & QInputDialog::UsePlainTextEditForTextInput) {
| 0 | ||||||||||||||||||
| 399 | ensurePlainTextEdit(); | - | ||||||||||||||||||
| 400 | widget = plainTextEdit; | - | ||||||||||||||||||
| 401 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 402 | ensureLineEdit(); | - | ||||||||||||||||||
| 403 | widget = lineEdit; | - | ||||||||||||||||||
| 404 | } never executed: end of block | 0 | ||||||||||||||||||
| 405 | - | |||||||||||||||||||
| 406 | setInputWidget(widget); | - | ||||||||||||||||||
| 407 | - | |||||||||||||||||||
| 408 | if (inputWidget == comboBox) {
| 0 | ||||||||||||||||||
| 409 | _q_textChanged(comboBox->currentText()); | - | ||||||||||||||||||
| 410 | } else if (inputWidget == listView) { never executed: end of block
| 0 | ||||||||||||||||||
| 411 | _q_textChanged(listViewText()); | - | ||||||||||||||||||
| 412 | } never executed: end of block | 0 | ||||||||||||||||||
| 413 | } never executed: end of block | 0 | ||||||||||||||||||
| 414 | - | |||||||||||||||||||
| 415 | void QInputDialogPrivate::setComboBoxText(const QString &text) | - | ||||||||||||||||||
| 416 | { | - | ||||||||||||||||||
| 417 | int index = comboBox->findText(text); | - | ||||||||||||||||||
| 418 | if (index != -1) {
| 0 | ||||||||||||||||||
| 419 | comboBox->setCurrentIndex(index); | - | ||||||||||||||||||
| 420 | } else if (comboBox->isEditable()) { never executed: end of block
| 0 | ||||||||||||||||||
| 421 | comboBox->setEditText(text); | - | ||||||||||||||||||
| 422 | } never executed: end of block | 0 | ||||||||||||||||||
| 423 | } never executed: end of block | 0 | ||||||||||||||||||
| 424 | - | |||||||||||||||||||
| 425 | void QInputDialogPrivate::setListViewText(const QString &text) | - | ||||||||||||||||||
| 426 | { | - | ||||||||||||||||||
| 427 | int row = comboBox->findText(text); | - | ||||||||||||||||||
| 428 | if (row != -1) {
| 0 | ||||||||||||||||||
| 429 | QModelIndex index(comboBox->model()->index(row, 0)); | - | ||||||||||||||||||
| 430 | listView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::Clear | - | ||||||||||||||||||
| 431 | | QItemSelectionModel::SelectCurrent); | - | ||||||||||||||||||
| 432 | } never executed: end of block | 0 | ||||||||||||||||||
| 433 | } never executed: end of block | 0 | ||||||||||||||||||
| 434 | - | |||||||||||||||||||
| 435 | QString QInputDialogPrivate::listViewText() const | - | ||||||||||||||||||
| 436 | { | - | ||||||||||||||||||
| 437 | if (listView->selectionModel()->hasSelection()) {
| 0 | ||||||||||||||||||
| 438 | int row = listView->selectionModel()->selectedRows().value(0).row(); | - | ||||||||||||||||||
| 439 | return comboBox->itemText(row); never executed: return comboBox->itemText(row); | 0 | ||||||||||||||||||
| 440 | } else { | - | ||||||||||||||||||
| 441 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
| 442 | } | - | ||||||||||||||||||
| 443 | } | - | ||||||||||||||||||
| 444 | - | |||||||||||||||||||
| 445 | void QInputDialogPrivate::_q_textChanged(const QString &text) | - | ||||||||||||||||||
| 446 | { | - | ||||||||||||||||||
| 447 | Q_Q(QInputDialog); | - | ||||||||||||||||||
| 448 | if (textValue != text) {
| 0 | ||||||||||||||||||
| 449 | textValue = text; | - | ||||||||||||||||||
| 450 | emit q->textValueChanged(text); | - | ||||||||||||||||||
| 451 | } never executed: end of block | 0 | ||||||||||||||||||
| 452 | } never executed: end of block | 0 | ||||||||||||||||||
| 453 | - | |||||||||||||||||||
| 454 | void QInputDialogPrivate::_q_plainTextEditTextChanged() | - | ||||||||||||||||||
| 455 | { | - | ||||||||||||||||||
| 456 | Q_Q(QInputDialog); | - | ||||||||||||||||||
| 457 | QString text = plainTextEdit->toPlainText(); | - | ||||||||||||||||||
| 458 | if (textValue != text) {
| 0 | ||||||||||||||||||
| 459 | textValue = text; | - | ||||||||||||||||||
| 460 | emit q->textValueChanged(text); | - | ||||||||||||||||||
| 461 | } never executed: end of block | 0 | ||||||||||||||||||
| 462 | } never executed: end of block | 0 | ||||||||||||||||||
| 463 | - | |||||||||||||||||||
| 464 | void QInputDialogPrivate::_q_currentRowChanged(const QModelIndex &newIndex, | - | ||||||||||||||||||
| 465 | const QModelIndex & /* oldIndex */) | - | ||||||||||||||||||
| 466 | { | - | ||||||||||||||||||
| 467 | _q_textChanged(comboBox->model()->data(newIndex).toString()); | - | ||||||||||||||||||
| 468 | buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); | - | ||||||||||||||||||
| 469 | } never executed: end of block | 0 | ||||||||||||||||||
| 470 | - | |||||||||||||||||||
| 471 | /*! | - | ||||||||||||||||||
| 472 | \class QInputDialog | - | ||||||||||||||||||
| 473 | \brief The QInputDialog class provides a simple convenience dialog to get a | - | ||||||||||||||||||
| 474 | single value from the user. | - | ||||||||||||||||||
| 475 | \ingroup standard-dialogs | - | ||||||||||||||||||
| 476 | \inmodule QtWidgets | - | ||||||||||||||||||
| 477 | - | |||||||||||||||||||
| 478 | The input value can be a string, a number or an item from a list. A label | - | ||||||||||||||||||
| 479 | must be set to tell the user what they should enter. | - | ||||||||||||||||||
| 480 | - | |||||||||||||||||||
| 481 | Five static convenience functions are provided: getText(), getMultiLineText(), | - | ||||||||||||||||||
| 482 | getInt(), getDouble(), and getItem(). All the functions can be used in a similar way, | - | ||||||||||||||||||
| 483 | for example: | - | ||||||||||||||||||
| 484 | - | |||||||||||||||||||
| 485 | \snippet dialogs/standarddialogs/dialog.cpp 3 | - | ||||||||||||||||||
| 486 | - | |||||||||||||||||||
| 487 | The \c ok variable is set to true if the user clicks \uicontrol OK; otherwise, it | - | ||||||||||||||||||
| 488 | is set to false. | - | ||||||||||||||||||
| 489 | - | |||||||||||||||||||
| 490 | \image inputdialogs.png Input Dialogs | - | ||||||||||||||||||
| 491 | - | |||||||||||||||||||
| 492 | The \l{dialogs/standarddialogs}{Standard Dialogs} example shows how to use | - | ||||||||||||||||||
| 493 | QInputDialog as well as other built-in Qt dialogs. | - | ||||||||||||||||||
| 494 | - | |||||||||||||||||||
| 495 | \sa QMessageBox, {Standard Dialogs Example} | - | ||||||||||||||||||
| 496 | */ | - | ||||||||||||||||||
| 497 | - | |||||||||||||||||||
| 498 | /*! | - | ||||||||||||||||||
| 499 | \enum QInputDialog::InputMode | - | ||||||||||||||||||
| 500 | \since 4.5 | - | ||||||||||||||||||
| 501 | - | |||||||||||||||||||
| 502 | This enum describes the different modes of input that can be selected for | - | ||||||||||||||||||
| 503 | the dialog. | - | ||||||||||||||||||
| 504 | - | |||||||||||||||||||
| 505 | \value TextInput Used to input text strings. | - | ||||||||||||||||||
| 506 | \value IntInput Used to input integers. | - | ||||||||||||||||||
| 507 | \value DoubleInput Used to input floating point numbers with double | - | ||||||||||||||||||
| 508 | precision accuracy. | - | ||||||||||||||||||
| 509 | - | |||||||||||||||||||
| 510 | \sa inputMode | - | ||||||||||||||||||
| 511 | */ | - | ||||||||||||||||||
| 512 | - | |||||||||||||||||||
| 513 | /*! | - | ||||||||||||||||||
| 514 | \since 4.5 | - | ||||||||||||||||||
| 515 | - | |||||||||||||||||||
| 516 | Constructs a new input dialog with the given \a parent and window \a flags. | - | ||||||||||||||||||
| 517 | */ | - | ||||||||||||||||||
| 518 | QInputDialog::QInputDialog(QWidget *parent, Qt::WindowFlags flags) | - | ||||||||||||||||||
| 519 | : QDialog(*new QInputDialogPrivate, parent, flags) | - | ||||||||||||||||||
| 520 | { | - | ||||||||||||||||||
| 521 | } never executed: end of block | 0 | ||||||||||||||||||
| 522 | - | |||||||||||||||||||
| 523 | /*! | - | ||||||||||||||||||
| 524 | \since 4.5 | - | ||||||||||||||||||
| 525 | - | |||||||||||||||||||
| 526 | Destroys the input dialog. | - | ||||||||||||||||||
| 527 | */ | - | ||||||||||||||||||
| 528 | QInputDialog::~QInputDialog() | - | ||||||||||||||||||
| 529 | { | - | ||||||||||||||||||
| 530 | } | - | ||||||||||||||||||
| 531 | - | |||||||||||||||||||
| 532 | /*! | - | ||||||||||||||||||
| 533 | \since 4.5 | - | ||||||||||||||||||
| 534 | - | |||||||||||||||||||
| 535 | \property QInputDialog::inputMode | - | ||||||||||||||||||
| 536 | - | |||||||||||||||||||
| 537 | \brief the mode used for input | - | ||||||||||||||||||
| 538 | - | |||||||||||||||||||
| 539 | This property helps determine which widget is used for entering input into | - | ||||||||||||||||||
| 540 | the dialog. | - | ||||||||||||||||||
| 541 | */ | - | ||||||||||||||||||
| 542 | void QInputDialog::setInputMode(InputMode mode) | - | ||||||||||||||||||
| 543 | { | - | ||||||||||||||||||
| 544 | Q_D(QInputDialog); | - | ||||||||||||||||||
| 545 | - | |||||||||||||||||||
| 546 | QWidget *widget; | - | ||||||||||||||||||
| 547 | - | |||||||||||||||||||
| 548 | /* | - | ||||||||||||||||||
| 549 | Warning: Some functions in QInputDialog rely on implementation details | - | ||||||||||||||||||
| 550 | of the code below. Look for the comments that accompany the calls to | - | ||||||||||||||||||
| 551 | setInputMode() throughout this file before you change the code below. | - | ||||||||||||||||||
| 552 | */ | - | ||||||||||||||||||
| 553 | - | |||||||||||||||||||
| 554 | switch (mode) { | - | ||||||||||||||||||
| 555 | case IntInput: never executed: case IntInput: | 0 | ||||||||||||||||||
| 556 | d->ensureIntSpinBox(); | - | ||||||||||||||||||
| 557 | widget = d->intSpinBox; | - | ||||||||||||||||||
| 558 | break; never executed: break; | 0 | ||||||||||||||||||
| 559 | case DoubleInput: never executed: case DoubleInput: | 0 | ||||||||||||||||||
| 560 | d->ensureDoubleSpinBox(); | - | ||||||||||||||||||
| 561 | widget = d->doubleSpinBox; | - | ||||||||||||||||||
| 562 | break; never executed: break; | 0 | ||||||||||||||||||
| 563 | default: never executed: default: | 0 | ||||||||||||||||||
| 564 | Q_ASSERT(mode == TextInput); | - | ||||||||||||||||||
| 565 | d->chooseRightTextInputWidget(); | - | ||||||||||||||||||
| 566 | return; never executed: return; | 0 | ||||||||||||||||||
| 567 | } | - | ||||||||||||||||||
| 568 | - | |||||||||||||||||||
| 569 | d->setInputWidget(widget); | - | ||||||||||||||||||
| 570 | } never executed: end of block | 0 | ||||||||||||||||||
| 571 | - | |||||||||||||||||||
| 572 | QInputDialog::InputMode QInputDialog::inputMode() const | - | ||||||||||||||||||
| 573 | { | - | ||||||||||||||||||
| 574 | Q_D(const QInputDialog); | - | ||||||||||||||||||
| 575 | - | |||||||||||||||||||
| 576 | if (d->inputWidget) {
| 0 | ||||||||||||||||||
| 577 | if (d->inputWidget == d->intSpinBox) {
| 0 | ||||||||||||||||||
| 578 | return IntInput; never executed: return IntInput; | 0 | ||||||||||||||||||
| 579 | } else if (d->inputWidget == d->doubleSpinBox) {
| 0 | ||||||||||||||||||
| 580 | return DoubleInput; never executed: return DoubleInput; | 0 | ||||||||||||||||||
| 581 | } | - | ||||||||||||||||||
| 582 | } never executed: end of block | 0 | ||||||||||||||||||
| 583 | - | |||||||||||||||||||
| 584 | return TextInput; never executed: return TextInput; | 0 | ||||||||||||||||||
| 585 | } | - | ||||||||||||||||||
| 586 | - | |||||||||||||||||||
| 587 | /*! | - | ||||||||||||||||||
| 588 | \since 4.5 | - | ||||||||||||||||||
| 589 | - | |||||||||||||||||||
| 590 | \property QInputDialog::labelText | - | ||||||||||||||||||
| 591 | - | |||||||||||||||||||
| 592 | \brief the label's text which describes what needs to be input | - | ||||||||||||||||||
| 593 | */ | - | ||||||||||||||||||
| 594 | void QInputDialog::setLabelText(const QString &text) | - | ||||||||||||||||||
| 595 | { | - | ||||||||||||||||||
| 596 | Q_D(QInputDialog); | - | ||||||||||||||||||
| 597 | if (!d->label) {
| 0 | ||||||||||||||||||
| 598 | d->label = new QLabel(text, this); | - | ||||||||||||||||||
| 599 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 600 | d->label->setText(text); | - | ||||||||||||||||||
| 601 | } never executed: end of block | 0 | ||||||||||||||||||
| 602 | } | - | ||||||||||||||||||
| 603 | - | |||||||||||||||||||
| 604 | QString QInputDialog::labelText() const | - | ||||||||||||||||||
| 605 | { | - | ||||||||||||||||||
| 606 | Q_D(const QInputDialog); | - | ||||||||||||||||||
| 607 | d->ensureLayout(); | - | ||||||||||||||||||
| 608 | return d->label->text(); never executed: return d->label->text(); | 0 | ||||||||||||||||||
| 609 | } | - | ||||||||||||||||||
| 610 | - | |||||||||||||||||||
| 611 | /*! | - | ||||||||||||||||||
| 612 | \enum QInputDialog::InputDialogOption | - | ||||||||||||||||||
| 613 | - | |||||||||||||||||||
| 614 | \since 4.5 | - | ||||||||||||||||||
| 615 | - | |||||||||||||||||||
| 616 | This enum specifies various options that affect the look and feel | - | ||||||||||||||||||
| 617 | of an input dialog. | - | ||||||||||||||||||
| 618 | - | |||||||||||||||||||
| 619 | \value NoButtons Don't display \uicontrol{OK} and \uicontrol{Cancel} buttons (useful for "live dialogs"). | - | ||||||||||||||||||
| 620 | \value UseListViewForComboBoxItems Use a QListView rather than a non-editable QComboBox for | - | ||||||||||||||||||
| 621 | displaying the items set with setComboBoxItems(). | - | ||||||||||||||||||
| 622 | \value UsePlainTextEditForTextInput Use a QPlainTextEdit for multiline text input. This value was | - | ||||||||||||||||||
| 623 | introduced in 5.2. | - | ||||||||||||||||||
| 624 | - | |||||||||||||||||||
| 625 | \sa options, setOption(), testOption() | - | ||||||||||||||||||
| 626 | */ | - | ||||||||||||||||||
| 627 | - | |||||||||||||||||||
| 628 | /*! | - | ||||||||||||||||||
| 629 | Sets the given \a option to be enabled if \a on is true; | - | ||||||||||||||||||
| 630 | otherwise, clears the given \a option. | - | ||||||||||||||||||
| 631 | - | |||||||||||||||||||
| 632 | \sa options, testOption() | - | ||||||||||||||||||
| 633 | */ | - | ||||||||||||||||||
| 634 | void QInputDialog::setOption(InputDialogOption option, bool on) | - | ||||||||||||||||||
| 635 | { | - | ||||||||||||||||||
| 636 | Q_D(QInputDialog); | - | ||||||||||||||||||
| 637 | if (!(d->opts & option) != !on)
| 0 | ||||||||||||||||||
| 638 | setOptions(d->opts ^ option); never executed: setOptions(d->opts ^ option); | 0 | ||||||||||||||||||
| 639 | } never executed: end of block | 0 | ||||||||||||||||||
| 640 | - | |||||||||||||||||||
| 641 | /*! | - | ||||||||||||||||||
| 642 | Returns \c true if the given \a option is enabled; otherwise, returns | - | ||||||||||||||||||
| 643 | false. | - | ||||||||||||||||||
| 644 | - | |||||||||||||||||||
| 645 | \sa options, setOption() | - | ||||||||||||||||||
| 646 | */ | - | ||||||||||||||||||
| 647 | bool QInputDialog::testOption(InputDialogOption option) const | - | ||||||||||||||||||
| 648 | { | - | ||||||||||||||||||
| 649 | Q_D(const QInputDialog); | - | ||||||||||||||||||
| 650 | return (d->opts & option) != 0; never executed: return (d->opts & option) != 0; | 0 | ||||||||||||||||||
| 651 | } | - | ||||||||||||||||||
| 652 | - | |||||||||||||||||||
| 653 | /*! | - | ||||||||||||||||||
| 654 | \property QInputDialog::options | - | ||||||||||||||||||
| 655 | \brief the various options that affect the look and feel of the dialog | - | ||||||||||||||||||
| 656 | \since 4.5 | - | ||||||||||||||||||
| 657 | - | |||||||||||||||||||
| 658 | By default, all options are disabled. | - | ||||||||||||||||||
| 659 | - | |||||||||||||||||||
| 660 | \sa setOption(), testOption() | - | ||||||||||||||||||
| 661 | */ | - | ||||||||||||||||||
| 662 | void QInputDialog::setOptions(InputDialogOptions options) | - | ||||||||||||||||||
| 663 | { | - | ||||||||||||||||||
| 664 | Q_D(QInputDialog); | - | ||||||||||||||||||
| 665 | - | |||||||||||||||||||
| 666 | InputDialogOptions changed = (options ^ d->opts); | - | ||||||||||||||||||
| 667 | if (!changed)
| 0 | ||||||||||||||||||
| 668 | return; never executed: return; | 0 | ||||||||||||||||||
| 669 | - | |||||||||||||||||||
| 670 | d->opts = options; | - | ||||||||||||||||||
| 671 | d->ensureLayout(); | - | ||||||||||||||||||
| 672 | - | |||||||||||||||||||
| 673 | if (changed & NoButtons)
| 0 | ||||||||||||||||||
| 674 | d->buttonBox->setVisible(!(options & NoButtons)); never executed: d->buttonBox->setVisible(!(options & NoButtons)); | 0 | ||||||||||||||||||
| 675 | if ((changed & UseListViewForComboBoxItems) && inputMode() == TextInput)
| 0 | ||||||||||||||||||
| 676 | d->chooseRightTextInputWidget(); never executed: d->chooseRightTextInputWidget(); | 0 | ||||||||||||||||||
| 677 | if ((changed & UsePlainTextEditForTextInput) && inputMode() == TextInput)
| 0 | ||||||||||||||||||
| 678 | d->chooseRightTextInputWidget(); never executed: d->chooseRightTextInputWidget(); | 0 | ||||||||||||||||||
| 679 | } never executed: end of block | 0 | ||||||||||||||||||
| 680 | - | |||||||||||||||||||
| 681 | QInputDialog::InputDialogOptions QInputDialog::options() const | - | ||||||||||||||||||
| 682 | { | - | ||||||||||||||||||
| 683 | Q_D(const QInputDialog); | - | ||||||||||||||||||
| 684 | return d->opts; never executed: return d->opts; | 0 | ||||||||||||||||||
| 685 | } | - | ||||||||||||||||||
| 686 | - | |||||||||||||||||||
| 687 | /*! | - | ||||||||||||||||||
| 688 | \since 4.5 | - | ||||||||||||||||||
| 689 | - | |||||||||||||||||||
| 690 | \property QInputDialog::textValue | - | ||||||||||||||||||
| 691 | - | |||||||||||||||||||
| 692 | \brief the text value for the input dialog | - | ||||||||||||||||||
| 693 | - | |||||||||||||||||||
| 694 | This property is only relevant when the input dialog is used in | - | ||||||||||||||||||
| 695 | TextInput mode. | - | ||||||||||||||||||
| 696 | */ | - | ||||||||||||||||||
| 697 | void QInputDialog::setTextValue(const QString &text) | - | ||||||||||||||||||
| 698 | { | - | ||||||||||||||||||
| 699 | Q_D(QInputDialog); | - | ||||||||||||||||||
| 700 | - | |||||||||||||||||||
| 701 | setInputMode(TextInput); | - | ||||||||||||||||||
| 702 | if (d->inputWidget == d->lineEdit) {
| 0 | ||||||||||||||||||
| 703 | d->lineEdit->setText(text); | - | ||||||||||||||||||
| 704 | } else if (d->inputWidget == d->plainTextEdit) { never executed: end of block
| 0 | ||||||||||||||||||
| 705 | d->plainTextEdit->setPlainText(text); | - | ||||||||||||||||||
| 706 | } else if (d->inputWidget == d->comboBox) { never executed: end of block
| 0 | ||||||||||||||||||
| 707 | d->setComboBoxText(text); | - | ||||||||||||||||||
| 708 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 709 | d->setListViewText(text); | - | ||||||||||||||||||
| 710 | } never executed: end of block | 0 | ||||||||||||||||||
| 711 | } | - | ||||||||||||||||||
| 712 | - | |||||||||||||||||||
| 713 | QString QInputDialog::textValue() const | - | ||||||||||||||||||
| 714 | { | - | ||||||||||||||||||
| 715 | Q_D(const QInputDialog); | - | ||||||||||||||||||
| 716 | return d->textValue; never executed: return d->textValue; | 0 | ||||||||||||||||||
| 717 | } | - | ||||||||||||||||||
| 718 | - | |||||||||||||||||||
| 719 | /*! | - | ||||||||||||||||||
| 720 | \since 4.5 | - | ||||||||||||||||||
| 721 | - | |||||||||||||||||||
| 722 | \property QInputDialog::textEchoMode | - | ||||||||||||||||||
| 723 | - | |||||||||||||||||||
| 724 | \brief the echo mode for the text value | - | ||||||||||||||||||
| 725 | - | |||||||||||||||||||
| 726 | This property is only relevant when the input dialog is used in | - | ||||||||||||||||||
| 727 | TextInput mode. | - | ||||||||||||||||||
| 728 | */ | - | ||||||||||||||||||
| 729 | void QInputDialog::setTextEchoMode(QLineEdit::EchoMode mode) | - | ||||||||||||||||||
| 730 | { | - | ||||||||||||||||||
| 731 | Q_D(QInputDialog); | - | ||||||||||||||||||
| 732 | d->ensureLineEdit(); | - | ||||||||||||||||||
| 733 | d->lineEdit->setEchoMode(mode); | - | ||||||||||||||||||
| 734 | } never executed: end of block | 0 | ||||||||||||||||||
| 735 | - | |||||||||||||||||||
| 736 | QLineEdit::EchoMode QInputDialog::textEchoMode() const | - | ||||||||||||||||||
| 737 | { | - | ||||||||||||||||||
| 738 | Q_D(const QInputDialog); | - | ||||||||||||||||||
| 739 | if (d->lineEdit) {
| 0 | ||||||||||||||||||
| 740 | return d->lineEdit->echoMode(); never executed: return d->lineEdit->echoMode(); | 0 | ||||||||||||||||||
| 741 | } else { | - | ||||||||||||||||||
| 742 | return QLineEdit::Normal; never executed: return QLineEdit::Normal; | 0 | ||||||||||||||||||
| 743 | } | - | ||||||||||||||||||
| 744 | } | - | ||||||||||||||||||
| 745 | - | |||||||||||||||||||
| 746 | /*! | - | ||||||||||||||||||
| 747 | \since 4.5 | - | ||||||||||||||||||
| 748 | - | |||||||||||||||||||
| 749 | \property QInputDialog::comboBoxEditable | - | ||||||||||||||||||
| 750 | - | |||||||||||||||||||
| 751 | \brief whether or not the combo box used in the input dialog is editable | - | ||||||||||||||||||
| 752 | */ | - | ||||||||||||||||||
| 753 | void QInputDialog::setComboBoxEditable(bool editable) | - | ||||||||||||||||||
| 754 | { | - | ||||||||||||||||||
| 755 | Q_D(QInputDialog); | - | ||||||||||||||||||
| 756 | d->ensureComboBox(); | - | ||||||||||||||||||
| 757 | d->comboBox->setEditable(editable); | - | ||||||||||||||||||
| 758 | if (inputMode() == TextInput)
| 0 | ||||||||||||||||||
| 759 | d->chooseRightTextInputWidget(); never executed: d->chooseRightTextInputWidget(); | 0 | ||||||||||||||||||
| 760 | } never executed: end of block | 0 | ||||||||||||||||||
| 761 | - | |||||||||||||||||||
| 762 | bool QInputDialog::isComboBoxEditable() const | - | ||||||||||||||||||
| 763 | { | - | ||||||||||||||||||
| 764 | Q_D(const QInputDialog); | - | ||||||||||||||||||
| 765 | if (d->comboBox) {
| 0 | ||||||||||||||||||
| 766 | return d->comboBox->isEditable(); never executed: return d->comboBox->isEditable(); | 0 | ||||||||||||||||||
| 767 | } else { | - | ||||||||||||||||||
| 768 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 769 | } | - | ||||||||||||||||||
| 770 | } | - | ||||||||||||||||||
| 771 | - | |||||||||||||||||||
| 772 | /*! | - | ||||||||||||||||||
| 773 | \since 4.5 | - | ||||||||||||||||||
| 774 | - | |||||||||||||||||||
| 775 | \property QInputDialog::comboBoxItems | - | ||||||||||||||||||
| 776 | - | |||||||||||||||||||
| 777 | \brief the items used in the combo box for the input dialog | - | ||||||||||||||||||
| 778 | */ | - | ||||||||||||||||||
| 779 | void QInputDialog::setComboBoxItems(const QStringList &items) | - | ||||||||||||||||||
| 780 | { | - | ||||||||||||||||||
| 781 | Q_D(QInputDialog); | - | ||||||||||||||||||
| 782 | - | |||||||||||||||||||
| 783 | d->ensureComboBox(); | - | ||||||||||||||||||
| 784 | { | - | ||||||||||||||||||
| 785 | const QSignalBlocker blocker(d->comboBox); | - | ||||||||||||||||||
| 786 | d->comboBox->clear(); | - | ||||||||||||||||||
| 787 | d->comboBox->addItems(items); | - | ||||||||||||||||||
| 788 | } | - | ||||||||||||||||||
| 789 | - | |||||||||||||||||||
| 790 | if (inputMode() == TextInput)
| 0 | ||||||||||||||||||
| 791 | d->chooseRightTextInputWidget(); never executed: d->chooseRightTextInputWidget(); | 0 | ||||||||||||||||||
| 792 | } never executed: end of block | 0 | ||||||||||||||||||
| 793 | - | |||||||||||||||||||
| 794 | QStringList QInputDialog::comboBoxItems() const | - | ||||||||||||||||||
| 795 | { | - | ||||||||||||||||||
| 796 | Q_D(const QInputDialog); | - | ||||||||||||||||||
| 797 | QStringList result; | - | ||||||||||||||||||
| 798 | if (d->comboBox) {
| 0 | ||||||||||||||||||
| 799 | const int count = d->comboBox->count(); | - | ||||||||||||||||||
| 800 | result.reserve(count); | - | ||||||||||||||||||
| 801 | for (int i = 0; i < count; ++i)
| 0 | ||||||||||||||||||
| 802 | result.append(d->comboBox->itemText(i)); never executed: result.append(d->comboBox->itemText(i)); | 0 | ||||||||||||||||||
| 803 | } never executed: end of block | 0 | ||||||||||||||||||
| 804 | return result; never executed: return result; | 0 | ||||||||||||||||||
| 805 | } | - | ||||||||||||||||||
| 806 | - | |||||||||||||||||||
| 807 | /*! | - | ||||||||||||||||||
| 808 | \property QInputDialog::intValue | - | ||||||||||||||||||
| 809 | \since 4.5 | - | ||||||||||||||||||
| 810 | \brief the current integer value accepted as input | - | ||||||||||||||||||
| 811 | - | |||||||||||||||||||
| 812 | This property is only relevant when the input dialog is used in | - | ||||||||||||||||||
| 813 | IntInput mode. | - | ||||||||||||||||||
| 814 | */ | - | ||||||||||||||||||
| 815 | void QInputDialog::setIntValue(int value) | - | ||||||||||||||||||
| 816 | { | - | ||||||||||||||||||
| 817 | Q_D(QInputDialog); | - | ||||||||||||||||||
| 818 | setInputMode(IntInput); | - | ||||||||||||||||||
| 819 | d->intSpinBox->setValue(value); | - | ||||||||||||||||||
| 820 | } never executed: end of block | 0 | ||||||||||||||||||
| 821 | - | |||||||||||||||||||
| 822 | int QInputDialog::intValue() const | - | ||||||||||||||||||
| 823 | { | - | ||||||||||||||||||
| 824 | Q_D(const QInputDialog); | - | ||||||||||||||||||
| 825 | if (d->intSpinBox) {
| 0 | ||||||||||||||||||
| 826 | return d->intSpinBox->value(); never executed: return d->intSpinBox->value(); | 0 | ||||||||||||||||||
| 827 | } else { | - | ||||||||||||||||||
| 828 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 829 | } | - | ||||||||||||||||||
| 830 | } | - | ||||||||||||||||||
| 831 | - | |||||||||||||||||||
| 832 | /*! | - | ||||||||||||||||||
| 833 | \property QInputDialog::intMinimum | - | ||||||||||||||||||
| 834 | \since 4.5 | - | ||||||||||||||||||
| 835 | \brief the minimum integer value accepted as input | - | ||||||||||||||||||
| 836 | - | |||||||||||||||||||
| 837 | This property is only relevant when the input dialog is used in | - | ||||||||||||||||||
| 838 | IntInput mode. | - | ||||||||||||||||||
| 839 | */ | - | ||||||||||||||||||
| 840 | void QInputDialog::setIntMinimum(int min) | - | ||||||||||||||||||
| 841 | { | - | ||||||||||||||||||
| 842 | Q_D(QInputDialog); | - | ||||||||||||||||||
| 843 | d->ensureIntSpinBox(); | - | ||||||||||||||||||
| 844 | d->intSpinBox->setMinimum(min); | - | ||||||||||||||||||
| 845 | } never executed: end of block | 0 | ||||||||||||||||||
| 846 | - | |||||||||||||||||||
| 847 | int QInputDialog::intMinimum() const | - | ||||||||||||||||||
| 848 | { | - | ||||||||||||||||||
| 849 | Q_D(const QInputDialog); | - | ||||||||||||||||||
| 850 | if (d->intSpinBox) {
| 0 | ||||||||||||||||||
| 851 | return d->intSpinBox->minimum(); never executed: return d->intSpinBox->minimum(); | 0 | ||||||||||||||||||
| 852 | } else { | - | ||||||||||||||||||
| 853 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 854 | } | - | ||||||||||||||||||
| 855 | } | - | ||||||||||||||||||
| 856 | - | |||||||||||||||||||
| 857 | /*! | - | ||||||||||||||||||
| 858 | \property QInputDialog::intMaximum | - | ||||||||||||||||||
| 859 | \since 4.5 | - | ||||||||||||||||||
| 860 | \brief the maximum integer value accepted as input | - | ||||||||||||||||||
| 861 | - | |||||||||||||||||||
| 862 | This property is only relevant when the input dialog is used in | - | ||||||||||||||||||
| 863 | IntInput mode. | - | ||||||||||||||||||
| 864 | */ | - | ||||||||||||||||||
| 865 | void QInputDialog::setIntMaximum(int max) | - | ||||||||||||||||||
| 866 | { | - | ||||||||||||||||||
| 867 | Q_D(QInputDialog); | - | ||||||||||||||||||
| 868 | d->ensureIntSpinBox(); | - | ||||||||||||||||||
| 869 | d->intSpinBox->setMaximum(max); | - | ||||||||||||||||||
| 870 | } never executed: end of block | 0 | ||||||||||||||||||
| 871 | - | |||||||||||||||||||
| 872 | int QInputDialog::intMaximum() const | - | ||||||||||||||||||
| 873 | { | - | ||||||||||||||||||
| 874 | Q_D(const QInputDialog); | - | ||||||||||||||||||
| 875 | if (d->intSpinBox) {
| 0 | ||||||||||||||||||
| 876 | return d->intSpinBox->maximum(); never executed: return d->intSpinBox->maximum(); | 0 | ||||||||||||||||||
| 877 | } else { | - | ||||||||||||||||||
| 878 | return 99; never executed: return 99; | 0 | ||||||||||||||||||
| 879 | } | - | ||||||||||||||||||
| 880 | } | - | ||||||||||||||||||
| 881 | - | |||||||||||||||||||
| 882 | /*! | - | ||||||||||||||||||
| 883 | Sets the range of integer values accepted by the dialog when used in | - | ||||||||||||||||||
| 884 | IntInput mode, with minimum and maximum values specified by \a min and | - | ||||||||||||||||||
| 885 | \a max respectively. | - | ||||||||||||||||||
| 886 | */ | - | ||||||||||||||||||
| 887 | void QInputDialog::setIntRange(int min, int max) | - | ||||||||||||||||||
| 888 | { | - | ||||||||||||||||||
| 889 | Q_D(QInputDialog); | - | ||||||||||||||||||
| 890 | d->ensureIntSpinBox(); | - | ||||||||||||||||||
| 891 | d->intSpinBox->setRange(min, max); | - | ||||||||||||||||||
| 892 | } never executed: end of block | 0 | ||||||||||||||||||
| 893 | - | |||||||||||||||||||
| 894 | /*! | - | ||||||||||||||||||
| 895 | \property QInputDialog::intStep | - | ||||||||||||||||||
| 896 | \since 4.5 | - | ||||||||||||||||||
| 897 | \brief the step by which the integer value is increased and decreased | - | ||||||||||||||||||
| 898 | - | |||||||||||||||||||
| 899 | This property is only relevant when the input dialog is used in | - | ||||||||||||||||||
| 900 | IntInput mode. | - | ||||||||||||||||||
| 901 | */ | - | ||||||||||||||||||
| 902 | void QInputDialog::setIntStep(int step) | - | ||||||||||||||||||
| 903 | { | - | ||||||||||||||||||
| 904 | Q_D(QInputDialog); | - | ||||||||||||||||||
| 905 | d->ensureIntSpinBox(); | - | ||||||||||||||||||
| 906 | d->intSpinBox->setSingleStep(step); | - | ||||||||||||||||||
| 907 | } never executed: end of block | 0 | ||||||||||||||||||
| 908 | - | |||||||||||||||||||
| 909 | int QInputDialog::intStep() const | - | ||||||||||||||||||
| 910 | { | - | ||||||||||||||||||
| 911 | Q_D(const QInputDialog); | - | ||||||||||||||||||
| 912 | if (d->intSpinBox) {
| 0 | ||||||||||||||||||
| 913 | return d->intSpinBox->singleStep(); never executed: return d->intSpinBox->singleStep(); | 0 | ||||||||||||||||||
| 914 | } else { | - | ||||||||||||||||||
| 915 | return 1; never executed: return 1; | 0 | ||||||||||||||||||
| 916 | } | - | ||||||||||||||||||
| 917 | } | - | ||||||||||||||||||
| 918 | - | |||||||||||||||||||
| 919 | /*! | - | ||||||||||||||||||
| 920 | \property QInputDialog::doubleValue | - | ||||||||||||||||||
| 921 | \since 4.5 | - | ||||||||||||||||||
| 922 | \brief the current double precision floating point value accepted as input | - | ||||||||||||||||||
| 923 | - | |||||||||||||||||||
| 924 | This property is only relevant when the input dialog is used in | - | ||||||||||||||||||
| 925 | DoubleInput mode. | - | ||||||||||||||||||
| 926 | */ | - | ||||||||||||||||||
| 927 | void QInputDialog::setDoubleValue(double value) | - | ||||||||||||||||||
| 928 | { | - | ||||||||||||||||||
| 929 | Q_D(QInputDialog); | - | ||||||||||||||||||
| 930 | setInputMode(DoubleInput); | - | ||||||||||||||||||
| 931 | d->doubleSpinBox->setValue(value); | - | ||||||||||||||||||
| 932 | } never executed: end of block | 0 | ||||||||||||||||||
| 933 | - | |||||||||||||||||||
| 934 | double QInputDialog::doubleValue() const | - | ||||||||||||||||||
| 935 | { | - | ||||||||||||||||||
| 936 | Q_D(const QInputDialog); | - | ||||||||||||||||||
| 937 | if (d->doubleSpinBox) {
| 0 | ||||||||||||||||||
| 938 | return d->doubleSpinBox->value(); never executed: return d->doubleSpinBox->value(); | 0 | ||||||||||||||||||
| 939 | } else { | - | ||||||||||||||||||
| 940 | return 0.0; never executed: return 0.0; | 0 | ||||||||||||||||||
| 941 | } | - | ||||||||||||||||||
| 942 | } | - | ||||||||||||||||||
| 943 | - | |||||||||||||||||||
| 944 | /*! | - | ||||||||||||||||||
| 945 | \property QInputDialog::doubleMinimum | - | ||||||||||||||||||
| 946 | \since 4.5 | - | ||||||||||||||||||
| 947 | \brief the minimum double precision floating point value accepted as input | - | ||||||||||||||||||
| 948 | - | |||||||||||||||||||
| 949 | This property is only relevant when the input dialog is used in | - | ||||||||||||||||||
| 950 | DoubleInput mode. | - | ||||||||||||||||||
| 951 | */ | - | ||||||||||||||||||
| 952 | void QInputDialog::setDoubleMinimum(double min) | - | ||||||||||||||||||
| 953 | { | - | ||||||||||||||||||
| 954 | Q_D(QInputDialog); | - | ||||||||||||||||||
| 955 | d->ensureDoubleSpinBox(); | - | ||||||||||||||||||
| 956 | d->doubleSpinBox->setMinimum(min); | - | ||||||||||||||||||
| 957 | } never executed: end of block | 0 | ||||||||||||||||||
| 958 | - | |||||||||||||||||||
| 959 | double QInputDialog::doubleMinimum() const | - | ||||||||||||||||||
| 960 | { | - | ||||||||||||||||||
| 961 | Q_D(const QInputDialog); | - | ||||||||||||||||||
| 962 | if (d->doubleSpinBox) {
| 0 | ||||||||||||||||||
| 963 | return d->doubleSpinBox->minimum(); never executed: return d->doubleSpinBox->minimum(); | 0 | ||||||||||||||||||
| 964 | } else { | - | ||||||||||||||||||
| 965 | return 0.0; never executed: return 0.0; | 0 | ||||||||||||||||||
| 966 | } | - | ||||||||||||||||||
| 967 | } | - | ||||||||||||||||||
| 968 | - | |||||||||||||||||||
| 969 | /*! | - | ||||||||||||||||||
| 970 | \property QInputDialog::doubleMaximum | - | ||||||||||||||||||
| 971 | \since 4.5 | - | ||||||||||||||||||
| 972 | \brief the maximum double precision floating point value accepted as input | - | ||||||||||||||||||
| 973 | - | |||||||||||||||||||
| 974 | This property is only relevant when the input dialog is used in | - | ||||||||||||||||||
| 975 | DoubleInput mode. | - | ||||||||||||||||||
| 976 | */ | - | ||||||||||||||||||
| 977 | void QInputDialog::setDoubleMaximum(double max) | - | ||||||||||||||||||
| 978 | { | - | ||||||||||||||||||
| 979 | Q_D(QInputDialog); | - | ||||||||||||||||||
| 980 | d->ensureDoubleSpinBox(); | - | ||||||||||||||||||
| 981 | d->doubleSpinBox->setMaximum(max); | - | ||||||||||||||||||
| 982 | } never executed: end of block | 0 | ||||||||||||||||||
| 983 | - | |||||||||||||||||||
| 984 | double QInputDialog::doubleMaximum() const | - | ||||||||||||||||||
| 985 | { | - | ||||||||||||||||||
| 986 | Q_D(const QInputDialog); | - | ||||||||||||||||||
| 987 | if (d->doubleSpinBox) {
| 0 | ||||||||||||||||||
| 988 | return d->doubleSpinBox->maximum(); never executed: return d->doubleSpinBox->maximum(); | 0 | ||||||||||||||||||
| 989 | } else { | - | ||||||||||||||||||
| 990 | return 99.99; never executed: return 99.99; | 0 | ||||||||||||||||||
| 991 | } | - | ||||||||||||||||||
| 992 | } | - | ||||||||||||||||||
| 993 | - | |||||||||||||||||||
| 994 | /*! | - | ||||||||||||||||||
| 995 | Sets the range of double precision floating point values accepted by the | - | ||||||||||||||||||
| 996 | dialog when used in DoubleInput mode, with minimum and maximum values | - | ||||||||||||||||||
| 997 | specified by \a min and \a max respectively. | - | ||||||||||||||||||
| 998 | */ | - | ||||||||||||||||||
| 999 | void QInputDialog::setDoubleRange(double min, double max) | - | ||||||||||||||||||
| 1000 | { | - | ||||||||||||||||||
| 1001 | Q_D(QInputDialog); | - | ||||||||||||||||||
| 1002 | d->ensureDoubleSpinBox(); | - | ||||||||||||||||||
| 1003 | d->doubleSpinBox->setRange(min, max); | - | ||||||||||||||||||
| 1004 | } never executed: end of block | 0 | ||||||||||||||||||
| 1005 | - | |||||||||||||||||||
| 1006 | /*! | - | ||||||||||||||||||
| 1007 | \since 4.5 | - | ||||||||||||||||||
| 1008 | - | |||||||||||||||||||
| 1009 | \property QInputDialog::doubleDecimals | - | ||||||||||||||||||
| 1010 | - | |||||||||||||||||||
| 1011 | \brief sets the precision of the double spinbox in decimals | - | ||||||||||||||||||
| 1012 | - | |||||||||||||||||||
| 1013 | \sa QDoubleSpinBox::setDecimals() | - | ||||||||||||||||||
| 1014 | */ | - | ||||||||||||||||||
| 1015 | void QInputDialog::setDoubleDecimals(int decimals) | - | ||||||||||||||||||
| 1016 | { | - | ||||||||||||||||||
| 1017 | Q_D(QInputDialog); | - | ||||||||||||||||||
| 1018 | d->ensureDoubleSpinBox(); | - | ||||||||||||||||||
| 1019 | d->doubleSpinBox->setDecimals(decimals); | - | ||||||||||||||||||
| 1020 | } never executed: end of block | 0 | ||||||||||||||||||
| 1021 | - | |||||||||||||||||||
| 1022 | int QInputDialog::doubleDecimals() const | - | ||||||||||||||||||
| 1023 | { | - | ||||||||||||||||||
| 1024 | Q_D(const QInputDialog); | - | ||||||||||||||||||
| 1025 | if (d->doubleSpinBox) {
| 0 | ||||||||||||||||||
| 1026 | return d->doubleSpinBox->decimals(); never executed: return d->doubleSpinBox->decimals(); | 0 | ||||||||||||||||||
| 1027 | } else { | - | ||||||||||||||||||
| 1028 | return 2; never executed: return 2; | 0 | ||||||||||||||||||
| 1029 | } | - | ||||||||||||||||||
| 1030 | } | - | ||||||||||||||||||
| 1031 | - | |||||||||||||||||||
| 1032 | /*! | - | ||||||||||||||||||
| 1033 | \since 4.5 | - | ||||||||||||||||||
| 1034 | - | |||||||||||||||||||
| 1035 | \property QInputDialog::okButtonText | - | ||||||||||||||||||
| 1036 | - | |||||||||||||||||||
| 1037 | \brief the text for the button used to accept the entry in the dialog | - | ||||||||||||||||||
| 1038 | */ | - | ||||||||||||||||||
| 1039 | void QInputDialog::setOkButtonText(const QString &text) | - | ||||||||||||||||||
| 1040 | { | - | ||||||||||||||||||
| 1041 | Q_D(const QInputDialog); | - | ||||||||||||||||||
| 1042 | d->ensureLayout(); | - | ||||||||||||||||||
| 1043 | d->buttonBox->button(QDialogButtonBox::Ok)->setText(text); | - | ||||||||||||||||||
| 1044 | } never executed: end of block | 0 | ||||||||||||||||||
| 1045 | - | |||||||||||||||||||
| 1046 | QString QInputDialog::okButtonText() const | - | ||||||||||||||||||
| 1047 | { | - | ||||||||||||||||||
| 1048 | Q_D(const QInputDialog); | - | ||||||||||||||||||
| 1049 | d->ensureLayout(); | - | ||||||||||||||||||
| 1050 | return d->buttonBox->button(QDialogButtonBox::Ok)->text(); never executed: return d->buttonBox->button(QDialogButtonBox::Ok)->text(); | 0 | ||||||||||||||||||
| 1051 | } | - | ||||||||||||||||||
| 1052 | - | |||||||||||||||||||
| 1053 | /*! | - | ||||||||||||||||||
| 1054 | \since 4.5 | - | ||||||||||||||||||
| 1055 | - | |||||||||||||||||||
| 1056 | \property QInputDialog::cancelButtonText | - | ||||||||||||||||||
| 1057 | \brief the text for the button used to cancel the dialog | - | ||||||||||||||||||
| 1058 | */ | - | ||||||||||||||||||
| 1059 | void QInputDialog::setCancelButtonText(const QString &text) | - | ||||||||||||||||||
| 1060 | { | - | ||||||||||||||||||
| 1061 | Q_D(const QInputDialog); | - | ||||||||||||||||||
| 1062 | d->ensureLayout(); | - | ||||||||||||||||||
| 1063 | d->buttonBox->button(QDialogButtonBox::Cancel)->setText(text); | - | ||||||||||||||||||
| 1064 | } never executed: end of block | 0 | ||||||||||||||||||
| 1065 | - | |||||||||||||||||||
| 1066 | QString QInputDialog::cancelButtonText() const | - | ||||||||||||||||||
| 1067 | { | - | ||||||||||||||||||
| 1068 | Q_D(const QInputDialog); | - | ||||||||||||||||||
| 1069 | d->ensureLayout(); | - | ||||||||||||||||||
| 1070 | return d->buttonBox->button(QDialogButtonBox::Cancel)->text(); never executed: return d->buttonBox->button(QDialogButtonBox::Cancel)->text(); | 0 | ||||||||||||||||||
| 1071 | } | - | ||||||||||||||||||
| 1072 | - | |||||||||||||||||||
| 1073 | /*! | - | ||||||||||||||||||
| 1074 | \since 4.5 | - | ||||||||||||||||||
| 1075 | \overload | - | ||||||||||||||||||
| 1076 | - | |||||||||||||||||||
| 1077 | This function connects one of its signals to the slot specified by \a receiver | - | ||||||||||||||||||
| 1078 | and \a member. The specific signal depends on the arguments that are specified | - | ||||||||||||||||||
| 1079 | in \a member. These are: | - | ||||||||||||||||||
| 1080 | - | |||||||||||||||||||
| 1081 | \list | - | ||||||||||||||||||
| 1082 | \li textValueSelected() if \a member has a QString for its first argument. | - | ||||||||||||||||||
| 1083 | \li intValueSelected() if \a member has an int for its first argument. | - | ||||||||||||||||||
| 1084 | \li doubleValueSelected() if \a member has a double for its first argument. | - | ||||||||||||||||||
| 1085 | \li accepted() if \a member has NO arguments. | - | ||||||||||||||||||
| 1086 | \endlist | - | ||||||||||||||||||
| 1087 | - | |||||||||||||||||||
| 1088 | The signal will be disconnected from the slot when the dialog is closed. | - | ||||||||||||||||||
| 1089 | */ | - | ||||||||||||||||||
| 1090 | void QInputDialog::open(QObject *receiver, const char *member) | - | ||||||||||||||||||
| 1091 | { | - | ||||||||||||||||||
| 1092 | Q_D(QInputDialog); | - | ||||||||||||||||||
| 1093 | connect(this, signalForMember(member), receiver, member); | - | ||||||||||||||||||
| 1094 | d->receiverToDisconnectOnClose = receiver; | - | ||||||||||||||||||
| 1095 | d->memberToDisconnectOnClose = member; | - | ||||||||||||||||||
| 1096 | QDialog::open(); | - | ||||||||||||||||||
| 1097 | } never executed: end of block | 0 | ||||||||||||||||||
| 1098 | - | |||||||||||||||||||
| 1099 | /*! | - | ||||||||||||||||||
| 1100 | \reimp | - | ||||||||||||||||||
| 1101 | */ | - | ||||||||||||||||||
| 1102 | QSize QInputDialog::minimumSizeHint() const | - | ||||||||||||||||||
| 1103 | { | - | ||||||||||||||||||
| 1104 | Q_D(const QInputDialog); | - | ||||||||||||||||||
| 1105 | d->ensureLayout(); | - | ||||||||||||||||||
| 1106 | return QDialog::minimumSizeHint(); never executed: return QDialog::minimumSizeHint(); | 0 | ||||||||||||||||||
| 1107 | } | - | ||||||||||||||||||
| 1108 | - | |||||||||||||||||||
| 1109 | /*! | - | ||||||||||||||||||
| 1110 | \reimp | - | ||||||||||||||||||
| 1111 | */ | - | ||||||||||||||||||
| 1112 | QSize QInputDialog::sizeHint() const | - | ||||||||||||||||||
| 1113 | { | - | ||||||||||||||||||
| 1114 | Q_D(const QInputDialog); | - | ||||||||||||||||||
| 1115 | d->ensureLayout(); | - | ||||||||||||||||||
| 1116 | return QDialog::sizeHint(); never executed: return QDialog::sizeHint(); | 0 | ||||||||||||||||||
| 1117 | } | - | ||||||||||||||||||
| 1118 | - | |||||||||||||||||||
| 1119 | /*! | - | ||||||||||||||||||
| 1120 | \reimp | - | ||||||||||||||||||
| 1121 | */ | - | ||||||||||||||||||
| 1122 | void QInputDialog::setVisible(bool visible) | - | ||||||||||||||||||
| 1123 | { | - | ||||||||||||||||||
| 1124 | Q_D(const QInputDialog); | - | ||||||||||||||||||
| 1125 | if (visible) {
| 0 | ||||||||||||||||||
| 1126 | d->ensureLayout(); | - | ||||||||||||||||||
| 1127 | d->inputWidget->setFocus(); | - | ||||||||||||||||||
| 1128 | if (d->inputWidget == d->lineEdit) {
| 0 | ||||||||||||||||||
| 1129 | d->lineEdit->selectAll(); | - | ||||||||||||||||||
| 1130 | } else if (d->inputWidget == d->plainTextEdit) { never executed: end of block
| 0 | ||||||||||||||||||
| 1131 | d->plainTextEdit->selectAll(); | - | ||||||||||||||||||
| 1132 | } else if (d->inputWidget == d->intSpinBox) { never executed: end of block
| 0 | ||||||||||||||||||
| 1133 | d->intSpinBox->selectAll(); | - | ||||||||||||||||||
| 1134 | } else if (d->inputWidget == d->doubleSpinBox) { never executed: end of block
| 0 | ||||||||||||||||||
| 1135 | d->doubleSpinBox->selectAll(); | - | ||||||||||||||||||
| 1136 | } never executed: end of block | 0 | ||||||||||||||||||
| 1137 | } never executed: end of block | 0 | ||||||||||||||||||
| 1138 | QDialog::setVisible(visible); | - | ||||||||||||||||||
| 1139 | } never executed: end of block | 0 | ||||||||||||||||||
| 1140 | - | |||||||||||||||||||
| 1141 | /*! | - | ||||||||||||||||||
| 1142 | Closes the dialog and sets its result code to \a result. If this dialog | - | ||||||||||||||||||
| 1143 | is shown with exec(), done() causes the local event loop to finish, | - | ||||||||||||||||||
| 1144 | and exec() to return \a result. | - | ||||||||||||||||||
| 1145 | - | |||||||||||||||||||
| 1146 | \sa QDialog::done() | - | ||||||||||||||||||
| 1147 | */ | - | ||||||||||||||||||
| 1148 | void QInputDialog::done(int result) | - | ||||||||||||||||||
| 1149 | { | - | ||||||||||||||||||
| 1150 | Q_D(QInputDialog); | - | ||||||||||||||||||
| 1151 | QDialog::done(result); | - | ||||||||||||||||||
| 1152 | if (result) {
| 0 | ||||||||||||||||||
| 1153 | InputMode mode = inputMode(); | - | ||||||||||||||||||
| 1154 | switch (mode) { | - | ||||||||||||||||||
| 1155 | case DoubleInput: never executed: case DoubleInput: | 0 | ||||||||||||||||||
| 1156 | emit doubleValueSelected(doubleValue()); | - | ||||||||||||||||||
| 1157 | break; never executed: break; | 0 | ||||||||||||||||||
| 1158 | case IntInput: never executed: case IntInput: | 0 | ||||||||||||||||||
| 1159 | emit intValueSelected(intValue()); | - | ||||||||||||||||||
| 1160 | break; never executed: break; | 0 | ||||||||||||||||||
| 1161 | default: never executed: default: | 0 | ||||||||||||||||||
| 1162 | Q_ASSERT(mode == TextInput); | - | ||||||||||||||||||
| 1163 | emit textValueSelected(textValue()); | - | ||||||||||||||||||
| 1164 | } never executed: end of block | 0 | ||||||||||||||||||
| 1165 | } | - | ||||||||||||||||||
| 1166 | if (d->receiverToDisconnectOnClose) {
| 0 | ||||||||||||||||||
| 1167 | disconnect(this, signalForMember(d->memberToDisconnectOnClose), | - | ||||||||||||||||||
| 1168 | d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose); | - | ||||||||||||||||||
| 1169 | d->receiverToDisconnectOnClose = 0; | - | ||||||||||||||||||
| 1170 | } never executed: end of block | 0 | ||||||||||||||||||
| 1171 | d->memberToDisconnectOnClose.clear(); | - | ||||||||||||||||||
| 1172 | } never executed: end of block | 0 | ||||||||||||||||||
| 1173 | - | |||||||||||||||||||
| 1174 | /*! | - | ||||||||||||||||||
| 1175 | Static convenience function to get a string from the user. | - | ||||||||||||||||||
| 1176 | - | |||||||||||||||||||
| 1177 | \a title is the text which is displayed in the title bar of the dialog. | - | ||||||||||||||||||
| 1178 | \a label is the text which is shown to the user (it should say what should | - | ||||||||||||||||||
| 1179 | be entered). | - | ||||||||||||||||||
| 1180 | \a text is the default text which is placed in the line edit. | - | ||||||||||||||||||
| 1181 | \a mode is the echo mode the line edit will use. | - | ||||||||||||||||||
| 1182 | \a inputMethodHints is the input method hints that will be used in the | - | ||||||||||||||||||
| 1183 | edit widget if an input method is active. | - | ||||||||||||||||||
| 1184 | - | |||||||||||||||||||
| 1185 | If \a ok is nonnull \e *\a ok will be set to true if the user pressed | - | ||||||||||||||||||
| 1186 | \uicontrol OK and to false if the user pressed \uicontrol Cancel. The dialog's parent | - | ||||||||||||||||||
| 1187 | is \a parent. The dialog will be modal and uses the specified widget | - | ||||||||||||||||||
| 1188 | \a flags. | - | ||||||||||||||||||
| 1189 | - | |||||||||||||||||||
| 1190 | If the dialog is accepted, this function returns the text in the dialog's | - | ||||||||||||||||||
| 1191 | line edit. If the dialog is rejected, a null QString is returned. | - | ||||||||||||||||||
| 1192 | - | |||||||||||||||||||
| 1193 | Use this static function like this: | - | ||||||||||||||||||
| 1194 | - | |||||||||||||||||||
| 1195 | \snippet dialogs/standarddialogs/dialog.cpp 3 | - | ||||||||||||||||||
| 1196 | - | |||||||||||||||||||
| 1197 | \warning Do not delete \a parent during the execution of the dialog. If you | - | ||||||||||||||||||
| 1198 | want to do this, you should create the dialog yourself using one of the | - | ||||||||||||||||||
| 1199 | QInputDialog constructors. | - | ||||||||||||||||||
| 1200 | - | |||||||||||||||||||
| 1201 | \sa getInt(), getDouble(), getItem(), getMultiLineText() | - | ||||||||||||||||||
| 1202 | */ | - | ||||||||||||||||||
| 1203 | - | |||||||||||||||||||
| 1204 | QString QInputDialog::getText(QWidget *parent, const QString &title, const QString &label, | - | ||||||||||||||||||
| 1205 | QLineEdit::EchoMode mode, const QString &text, bool *ok, | - | ||||||||||||||||||
| 1206 | Qt::WindowFlags flags, Qt::InputMethodHints inputMethodHints) | - | ||||||||||||||||||
| 1207 | { | - | ||||||||||||||||||
| 1208 | QInputDialog dialog(parent, flags); | - | ||||||||||||||||||
| 1209 | dialog.setWindowTitle(title); | - | ||||||||||||||||||
| 1210 | dialog.setLabelText(label); | - | ||||||||||||||||||
| 1211 | dialog.setTextValue(text); | - | ||||||||||||||||||
| 1212 | dialog.setTextEchoMode(mode); | - | ||||||||||||||||||
| 1213 | dialog.setInputMethodHints(inputMethodHints); | - | ||||||||||||||||||
| 1214 | - | |||||||||||||||||||
| 1215 | int ret = dialog.exec(); | - | ||||||||||||||||||
| 1216 | if (ok)
| 0 | ||||||||||||||||||
| 1217 | *ok = !!ret; never executed: *ok = !!ret; | 0 | ||||||||||||||||||
| 1218 | if (ret) {
| 0 | ||||||||||||||||||
| 1219 | return dialog.textValue(); never executed: return dialog.textValue(); | 0 | ||||||||||||||||||
| 1220 | } else { | - | ||||||||||||||||||
| 1221 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
| 1222 | } | - | ||||||||||||||||||
| 1223 | } | - | ||||||||||||||||||
| 1224 | - | |||||||||||||||||||
| 1225 | /*! | - | ||||||||||||||||||
| 1226 | \since 5.2 | - | ||||||||||||||||||
| 1227 | - | |||||||||||||||||||
| 1228 | Static convenience function to get a multiline string from the user. | - | ||||||||||||||||||
| 1229 | - | |||||||||||||||||||
| 1230 | \a title is the text which is displayed in the title bar of the dialog. | - | ||||||||||||||||||
| 1231 | \a label is the text which is shown to the user (it should say what should | - | ||||||||||||||||||
| 1232 | be entered). | - | ||||||||||||||||||
| 1233 | \a text is the default text which is placed in the plain text edit. | - | ||||||||||||||||||
| 1234 | \a inputMethodHints is the input method hints that will be used in the | - | ||||||||||||||||||
| 1235 | edit widget if an input method is active. | - | ||||||||||||||||||
| 1236 | - | |||||||||||||||||||
| 1237 | If \a ok is nonnull \e *\a ok will be set to true if the user pressed | - | ||||||||||||||||||
| 1238 | \uicontrol OK and to false if the user pressed \uicontrol Cancel. The dialog's parent | - | ||||||||||||||||||
| 1239 | is \a parent. The dialog will be modal and uses the specified widget | - | ||||||||||||||||||
| 1240 | \a flags. | - | ||||||||||||||||||
| 1241 | - | |||||||||||||||||||
| 1242 | If the dialog is accepted, this function returns the text in the dialog's | - | ||||||||||||||||||
| 1243 | plain text edit. If the dialog is rejected, a null QString is returned. | - | ||||||||||||||||||
| 1244 | - | |||||||||||||||||||
| 1245 | Use this static function like this: | - | ||||||||||||||||||
| 1246 | - | |||||||||||||||||||
| 1247 | \snippet dialogs/standarddialogs/dialog.cpp 4 | - | ||||||||||||||||||
| 1248 | - | |||||||||||||||||||
| 1249 | \warning Do not delete \a parent during the execution of the dialog. If you | - | ||||||||||||||||||
| 1250 | want to do this, you should create the dialog yourself using one of the | - | ||||||||||||||||||
| 1251 | QInputDialog constructors. | - | ||||||||||||||||||
| 1252 | - | |||||||||||||||||||
| 1253 | \sa getInt(), getDouble(), getItem(), getText() | - | ||||||||||||||||||
| 1254 | */ | - | ||||||||||||||||||
| 1255 | - | |||||||||||||||||||
| 1256 | QString QInputDialog::getMultiLineText(QWidget *parent, const QString &title, const QString &label, | - | ||||||||||||||||||
| 1257 | const QString &text, bool *ok, Qt::WindowFlags flags, | - | ||||||||||||||||||
| 1258 | Qt::InputMethodHints inputMethodHints) | - | ||||||||||||||||||
| 1259 | { | - | ||||||||||||||||||
| 1260 | QInputDialog dialog(parent, flags); | - | ||||||||||||||||||
| 1261 | dialog.setOptions(QInputDialog::UsePlainTextEditForTextInput); | - | ||||||||||||||||||
| 1262 | dialog.setWindowTitle(title); | - | ||||||||||||||||||
| 1263 | dialog.setLabelText(label); | - | ||||||||||||||||||
| 1264 | dialog.setTextValue(text); | - | ||||||||||||||||||
| 1265 | dialog.setInputMethodHints(inputMethodHints); | - | ||||||||||||||||||
| 1266 | - | |||||||||||||||||||
| 1267 | int ret = dialog.exec(); | - | ||||||||||||||||||
| 1268 | if (ok)
| 0 | ||||||||||||||||||
| 1269 | *ok = !!ret; never executed: *ok = !!ret; | 0 | ||||||||||||||||||
| 1270 | if (ret) {
| 0 | ||||||||||||||||||
| 1271 | return dialog.textValue(); never executed: return dialog.textValue(); | 0 | ||||||||||||||||||
| 1272 | } else { | - | ||||||||||||||||||
| 1273 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
| 1274 | } | - | ||||||||||||||||||
| 1275 | } | - | ||||||||||||||||||
| 1276 | - | |||||||||||||||||||
| 1277 | /*! | - | ||||||||||||||||||
| 1278 | \since 4.5 | - | ||||||||||||||||||
| 1279 | - | |||||||||||||||||||
| 1280 | Static convenience function to get an integer input from the user. | - | ||||||||||||||||||
| 1281 | - | |||||||||||||||||||
| 1282 | \a title is the text which is displayed in the title bar of the dialog. | - | ||||||||||||||||||
| 1283 | \a label is the text which is shown to the user (it should say what should | - | ||||||||||||||||||
| 1284 | be entered). | - | ||||||||||||||||||
| 1285 | \a value is the default integer which the spinbox will be set to. | - | ||||||||||||||||||
| 1286 | \a min and \a max are the minimum and maximum values the user may choose. | - | ||||||||||||||||||
| 1287 | \a step is the amount by which the values change as the user presses the | - | ||||||||||||||||||
| 1288 | arrow buttons to increment or decrement the value. | - | ||||||||||||||||||
| 1289 | - | |||||||||||||||||||
| 1290 | If \a ok is nonnull *\a ok will be set to true if the user pressed \uicontrol OK | - | ||||||||||||||||||
| 1291 | and to false if the user pressed \uicontrol Cancel. The dialog's parent is | - | ||||||||||||||||||
| 1292 | \a parent. The dialog will be modal and uses the widget \a flags. | - | ||||||||||||||||||
| 1293 | - | |||||||||||||||||||
| 1294 | On success, this function returns the integer which has been entered by the | - | ||||||||||||||||||
| 1295 | user; on failure, it returns the initial \a value. | - | ||||||||||||||||||
| 1296 | - | |||||||||||||||||||
| 1297 | Use this static function like this: | - | ||||||||||||||||||
| 1298 | - | |||||||||||||||||||
| 1299 | \snippet dialogs/standarddialogs/dialog.cpp 0 | - | ||||||||||||||||||
| 1300 | - | |||||||||||||||||||
| 1301 | \warning Do not delete \a parent during the execution of the dialog. If you | - | ||||||||||||||||||
| 1302 | want to do this, you should create the dialog yourself using one of the | - | ||||||||||||||||||
| 1303 | QInputDialog constructors. | - | ||||||||||||||||||
| 1304 | - | |||||||||||||||||||
| 1305 | \sa getText(), getDouble(), getItem(), getMultiLineText() | - | ||||||||||||||||||
| 1306 | */ | - | ||||||||||||||||||
| 1307 | - | |||||||||||||||||||
| 1308 | int QInputDialog::getInt(QWidget *parent, const QString &title, const QString &label, int value, | - | ||||||||||||||||||
| 1309 | int min, int max, int step, bool *ok, Qt::WindowFlags flags) | - | ||||||||||||||||||
| 1310 | { | - | ||||||||||||||||||
| 1311 | QInputDialog dialog(parent, flags); | - | ||||||||||||||||||
| 1312 | dialog.setWindowTitle(title); | - | ||||||||||||||||||
| 1313 | dialog.setLabelText(label); | - | ||||||||||||||||||
| 1314 | dialog.setIntRange(min, max); | - | ||||||||||||||||||
| 1315 | dialog.setIntValue(value); | - | ||||||||||||||||||
| 1316 | dialog.setIntStep(step); | - | ||||||||||||||||||
| 1317 | - | |||||||||||||||||||
| 1318 | int ret = dialog.exec(); | - | ||||||||||||||||||
| 1319 | if (ok)
| 0 | ||||||||||||||||||
| 1320 | *ok = !!ret; never executed: *ok = !!ret; | 0 | ||||||||||||||||||
| 1321 | if (ret) {
| 0 | ||||||||||||||||||
| 1322 | return dialog.intValue(); never executed: return dialog.intValue(); | 0 | ||||||||||||||||||
| 1323 | } else { | - | ||||||||||||||||||
| 1324 | return value; never executed: return value; | 0 | ||||||||||||||||||
| 1325 | } | - | ||||||||||||||||||
| 1326 | } | - | ||||||||||||||||||
| 1327 | - | |||||||||||||||||||
| 1328 | /*! | - | ||||||||||||||||||
| 1329 | \fn QInputDialog::getInteger(QWidget *parent, const QString &title, const QString &label, int value, int min, int max, int step, bool *ok, Qt::WindowFlags flags) | - | ||||||||||||||||||
| 1330 | \deprecated use getInt() | - | ||||||||||||||||||
| 1331 | - | |||||||||||||||||||
| 1332 | Static convenience function to get an integer input from the user. | - | ||||||||||||||||||
| 1333 | - | |||||||||||||||||||
| 1334 | \a title is the text which is displayed in the title bar of the dialog. | - | ||||||||||||||||||
| 1335 | \a label is the text which is shown to the user (it should say what should | - | ||||||||||||||||||
| 1336 | be entered). | - | ||||||||||||||||||
| 1337 | \a value is the default integer which the spinbox will be set to. | - | ||||||||||||||||||
| 1338 | \a min and \a max are the minimum and maximum values the user may choose. | - | ||||||||||||||||||
| 1339 | \a step is the amount by which the values change as the user presses the | - | ||||||||||||||||||
| 1340 | arrow buttons to increment or decrement the value. | - | ||||||||||||||||||
| 1341 | - | |||||||||||||||||||
| 1342 | If \a ok is nonnull *\a ok will be set to true if the user pressed \uicontrol OK | - | ||||||||||||||||||
| 1343 | and to false if the user pressed \uicontrol Cancel. The dialog's parent is | - | ||||||||||||||||||
| 1344 | \a parent. The dialog will be modal and uses the widget \a flags. | - | ||||||||||||||||||
| 1345 | - | |||||||||||||||||||
| 1346 | On success, this function returns the integer which has been entered by the | - | ||||||||||||||||||
| 1347 | user; on failure, it returns the initial \a value. | - | ||||||||||||||||||
| 1348 | - | |||||||||||||||||||
| 1349 | Use this static function like this: | - | ||||||||||||||||||
| 1350 | - | |||||||||||||||||||
| 1351 | \snippet dialogs/standarddialogs/dialog.cpp 0 | - | ||||||||||||||||||
| 1352 | - | |||||||||||||||||||
| 1353 | \warning Do not delete \a parent during the execution of the dialog. If you | - | ||||||||||||||||||
| 1354 | want to do this, you should create the dialog yourself using one of the | - | ||||||||||||||||||
| 1355 | QInputDialog constructors. | - | ||||||||||||||||||
| 1356 | - | |||||||||||||||||||
| 1357 | \sa getText(), getDouble(), getItem(), getMultiLineText() | - | ||||||||||||||||||
| 1358 | */ | - | ||||||||||||||||||
| 1359 | - | |||||||||||||||||||
| 1360 | /*! | - | ||||||||||||||||||
| 1361 | Static convenience function to get a floating point number from the user. | - | ||||||||||||||||||
| 1362 | - | |||||||||||||||||||
| 1363 | \a title is the text which is displayed in the title bar of the dialog. | - | ||||||||||||||||||
| 1364 | \a label is the text which is shown to the user (it should say what should | - | ||||||||||||||||||
| 1365 | be entered). | - | ||||||||||||||||||
| 1366 | \a value is the default floating point number that the line edit will be | - | ||||||||||||||||||
| 1367 | set to. | - | ||||||||||||||||||
| 1368 | \a min and \a max are the minimum and maximum values the user may choose. | - | ||||||||||||||||||
| 1369 | \a decimals is the maximum number of decimal places the number may have. | - | ||||||||||||||||||
| 1370 | - | |||||||||||||||||||
| 1371 | If \a ok is nonnull, *\a ok will be set to true if the user pressed \uicontrol OK | - | ||||||||||||||||||
| 1372 | and to false if the user pressed \uicontrol Cancel. The dialog's parent is | - | ||||||||||||||||||
| 1373 | \a parent. The dialog will be modal and uses the widget \a flags. | - | ||||||||||||||||||
| 1374 | - | |||||||||||||||||||
| 1375 | This function returns the floating point number which has been entered by | - | ||||||||||||||||||
| 1376 | the user. | - | ||||||||||||||||||
| 1377 | - | |||||||||||||||||||
| 1378 | Use this static function like this: | - | ||||||||||||||||||
| 1379 | - | |||||||||||||||||||
| 1380 | \snippet dialogs/standarddialogs/dialog.cpp 1 | - | ||||||||||||||||||
| 1381 | - | |||||||||||||||||||
| 1382 | \warning Do not delete \a parent during the execution of the dialog. If you | - | ||||||||||||||||||
| 1383 | want to do this, you should create the dialog yourself using one of the | - | ||||||||||||||||||
| 1384 | QInputDialog constructors. | - | ||||||||||||||||||
| 1385 | - | |||||||||||||||||||
| 1386 | \sa getText(), getInt(), getItem(), getMultiLineText() | - | ||||||||||||||||||
| 1387 | */ | - | ||||||||||||||||||
| 1388 | - | |||||||||||||||||||
| 1389 | double QInputDialog::getDouble(QWidget *parent, const QString &title, const QString &label, | - | ||||||||||||||||||
| 1390 | double value, double min, double max, int decimals, bool *ok, | - | ||||||||||||||||||
| 1391 | Qt::WindowFlags flags) | - | ||||||||||||||||||
| 1392 | { | - | ||||||||||||||||||
| 1393 | QInputDialog dialog(parent, flags); | - | ||||||||||||||||||
| 1394 | dialog.setWindowTitle(title); | - | ||||||||||||||||||
| 1395 | dialog.setLabelText(label); | - | ||||||||||||||||||
| 1396 | dialog.setDoubleDecimals(decimals); | - | ||||||||||||||||||
| 1397 | dialog.setDoubleRange(min, max); | - | ||||||||||||||||||
| 1398 | dialog.setDoubleValue(value); | - | ||||||||||||||||||
| 1399 | - | |||||||||||||||||||
| 1400 | int ret = dialog.exec(); | - | ||||||||||||||||||
| 1401 | if (ok)
| 0 | ||||||||||||||||||
| 1402 | *ok = !!ret; never executed: *ok = !!ret; | 0 | ||||||||||||||||||
| 1403 | if (ret) {
| 0 | ||||||||||||||||||
| 1404 | return dialog.doubleValue(); never executed: return dialog.doubleValue(); | 0 | ||||||||||||||||||
| 1405 | } else { | - | ||||||||||||||||||
| 1406 | return value; never executed: return value; | 0 | ||||||||||||||||||
| 1407 | } | - | ||||||||||||||||||
| 1408 | } | - | ||||||||||||||||||
| 1409 | - | |||||||||||||||||||
| 1410 | /*! | - | ||||||||||||||||||
| 1411 | Static convenience function to let the user select an item from a string | - | ||||||||||||||||||
| 1412 | list. | - | ||||||||||||||||||
| 1413 | - | |||||||||||||||||||
| 1414 | \a title is the text which is displayed in the title bar of the dialog. | - | ||||||||||||||||||
| 1415 | \a label is the text which is shown to the user (it should say what should | - | ||||||||||||||||||
| 1416 | be entered). | - | ||||||||||||||||||
| 1417 | \a items is the string list which is inserted into the combo box. | - | ||||||||||||||||||
| 1418 | \a current is the number of the item which should be the current item. | - | ||||||||||||||||||
| 1419 | \a inputMethodHints is the input method hints that will be used if the | - | ||||||||||||||||||
| 1420 | combo box is editable and an input method is active. | - | ||||||||||||||||||
| 1421 | - | |||||||||||||||||||
| 1422 | If \a editable is true the user can enter their own text; otherwise, the | - | ||||||||||||||||||
| 1423 | user may only select one of the existing items. | - | ||||||||||||||||||
| 1424 | - | |||||||||||||||||||
| 1425 | If \a ok is nonnull \e *\a ok will be set to true if the user pressed | - | ||||||||||||||||||
| 1426 | \uicontrol OK and to false if the user pressed \uicontrol Cancel. The dialog's parent | - | ||||||||||||||||||
| 1427 | is \a parent. The dialog will be modal and uses the widget \a flags. | - | ||||||||||||||||||
| 1428 | - | |||||||||||||||||||
| 1429 | This function returns the text of the current item, or if \a editable is | - | ||||||||||||||||||
| 1430 | true, the current text of the combo box. | - | ||||||||||||||||||
| 1431 | - | |||||||||||||||||||
| 1432 | Use this static function like this: | - | ||||||||||||||||||
| 1433 | - | |||||||||||||||||||
| 1434 | \snippet dialogs/standarddialogs/dialog.cpp 2 | - | ||||||||||||||||||
| 1435 | - | |||||||||||||||||||
| 1436 | \warning Do not delete \a parent during the execution of the dialog. If you | - | ||||||||||||||||||
| 1437 | want to do this, you should create the dialog yourself using one of the | - | ||||||||||||||||||
| 1438 | QInputDialog constructors. | - | ||||||||||||||||||
| 1439 | - | |||||||||||||||||||
| 1440 | \sa getText(), getInt(), getDouble(), getMultiLineText() | - | ||||||||||||||||||
| 1441 | */ | - | ||||||||||||||||||
| 1442 | - | |||||||||||||||||||
| 1443 | QString QInputDialog::getItem(QWidget *parent, const QString &title, const QString &label, | - | ||||||||||||||||||
| 1444 | const QStringList &items, int current, bool editable, bool *ok, | - | ||||||||||||||||||
| 1445 | Qt::WindowFlags flags, Qt::InputMethodHints inputMethodHints) | - | ||||||||||||||||||
| 1446 | { | - | ||||||||||||||||||
| 1447 | QString text(items.value(current)); | - | ||||||||||||||||||
| 1448 | - | |||||||||||||||||||
| 1449 | QInputDialog dialog(parent, flags); | - | ||||||||||||||||||
| 1450 | dialog.setWindowTitle(title); | - | ||||||||||||||||||
| 1451 | dialog.setLabelText(label); | - | ||||||||||||||||||
| 1452 | dialog.setComboBoxItems(items); | - | ||||||||||||||||||
| 1453 | dialog.setTextValue(text); | - | ||||||||||||||||||
| 1454 | dialog.setComboBoxEditable(editable); | - | ||||||||||||||||||
| 1455 | dialog.setInputMethodHints(inputMethodHints); | - | ||||||||||||||||||
| 1456 | - | |||||||||||||||||||
| 1457 | int ret = dialog.exec(); | - | ||||||||||||||||||
| 1458 | if (ok)
| 0 | ||||||||||||||||||
| 1459 | *ok = !!ret; never executed: *ok = !!ret; | 0 | ||||||||||||||||||
| 1460 | if (ret) {
| 0 | ||||||||||||||||||
| 1461 | return dialog.textValue(); never executed: return dialog.textValue(); | 0 | ||||||||||||||||||
| 1462 | } else { | - | ||||||||||||||||||
| 1463 | return text; never executed: return text; | 0 | ||||||||||||||||||
| 1464 | } | - | ||||||||||||||||||
| 1465 | } | - | ||||||||||||||||||
| 1466 | - | |||||||||||||||||||
| 1467 | /*! | - | ||||||||||||||||||
| 1468 | \fn void QInputDialog::doubleValueChanged(double value) | - | ||||||||||||||||||
| 1469 | - | |||||||||||||||||||
| 1470 | This signal is emitted whenever the double value changes in the dialog. | - | ||||||||||||||||||
| 1471 | The current value is specified by \a value. | - | ||||||||||||||||||
| 1472 | - | |||||||||||||||||||
| 1473 | This signal is only relevant when the input dialog is used in | - | ||||||||||||||||||
| 1474 | DoubleInput mode. | - | ||||||||||||||||||
| 1475 | */ | - | ||||||||||||||||||
| 1476 | - | |||||||||||||||||||
| 1477 | /*! | - | ||||||||||||||||||
| 1478 | \fn void QInputDialog::doubleValueSelected(double value) | - | ||||||||||||||||||
| 1479 | - | |||||||||||||||||||
| 1480 | This signal is emitted whenever the user selects a double value by | - | ||||||||||||||||||
| 1481 | accepting the dialog; for example, by clicking the \uicontrol{OK} button. | - | ||||||||||||||||||
| 1482 | The selected value is specified by \a value. | - | ||||||||||||||||||
| 1483 | - | |||||||||||||||||||
| 1484 | This signal is only relevant when the input dialog is used in | - | ||||||||||||||||||
| 1485 | DoubleInput mode. | - | ||||||||||||||||||
| 1486 | */ | - | ||||||||||||||||||
| 1487 | - | |||||||||||||||||||
| 1488 | /*! | - | ||||||||||||||||||
| 1489 | \fn void QInputDialog::intValueChanged(int value) | - | ||||||||||||||||||
| 1490 | - | |||||||||||||||||||
| 1491 | This signal is emitted whenever the integer value changes in the dialog. | - | ||||||||||||||||||
| 1492 | The current value is specified by \a value. | - | ||||||||||||||||||
| 1493 | - | |||||||||||||||||||
| 1494 | This signal is only relevant when the input dialog is used in | - | ||||||||||||||||||
| 1495 | IntInput mode. | - | ||||||||||||||||||
| 1496 | */ | - | ||||||||||||||||||
| 1497 | - | |||||||||||||||||||
| 1498 | /*! | - | ||||||||||||||||||
| 1499 | \fn void QInputDialog::intValueSelected(int value) | - | ||||||||||||||||||
| 1500 | - | |||||||||||||||||||
| 1501 | This signal is emitted whenever the user selects a integer value by | - | ||||||||||||||||||
| 1502 | accepting the dialog; for example, by clicking the \uicontrol{OK} button. | - | ||||||||||||||||||
| 1503 | The selected value is specified by \a value. | - | ||||||||||||||||||
| 1504 | - | |||||||||||||||||||
| 1505 | This signal is only relevant when the input dialog is used in | - | ||||||||||||||||||
| 1506 | IntInput mode. | - | ||||||||||||||||||
| 1507 | */ | - | ||||||||||||||||||
| 1508 | - | |||||||||||||||||||
| 1509 | /*! | - | ||||||||||||||||||
| 1510 | \fn void QInputDialog::textValueChanged(const QString &text) | - | ||||||||||||||||||
| 1511 | - | |||||||||||||||||||
| 1512 | This signal is emitted whenever the text string changes in the dialog. | - | ||||||||||||||||||
| 1513 | The current string is specified by \a text. | - | ||||||||||||||||||
| 1514 | - | |||||||||||||||||||
| 1515 | This signal is only relevant when the input dialog is used in | - | ||||||||||||||||||
| 1516 | TextInput mode. | - | ||||||||||||||||||
| 1517 | */ | - | ||||||||||||||||||
| 1518 | - | |||||||||||||||||||
| 1519 | /*! | - | ||||||||||||||||||
| 1520 | \fn void QInputDialog::textValueSelected(const QString &text) | - | ||||||||||||||||||
| 1521 | - | |||||||||||||||||||
| 1522 | This signal is emitted whenever the user selects a text string by | - | ||||||||||||||||||
| 1523 | accepting the dialog; for example, by clicking the \uicontrol{OK} button. | - | ||||||||||||||||||
| 1524 | The selected string is specified by \a text. | - | ||||||||||||||||||
| 1525 | - | |||||||||||||||||||
| 1526 | This signal is only relevant when the input dialog is used in | - | ||||||||||||||||||
| 1527 | TextInput mode. | - | ||||||||||||||||||
| 1528 | */ | - | ||||||||||||||||||
| 1529 | - | |||||||||||||||||||
| 1530 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 1531 | - | |||||||||||||||||||
| 1532 | #include "qinputdialog.moc" | - | ||||||||||||||||||
| 1533 | #include "moc_qinputdialog.cpp" | - | ||||||||||||||||||
| 1534 | - | |||||||||||||||||||
| 1535 | #endif // QT_NO_INPUTDIALOG | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |