qinputdialog.cpp

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

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9