Qt 4.8
qinputdialog.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui 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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qinputdialog.h"
43 
44 #ifndef QT_NO_INPUTDIALOG
45 
46 #include "qapplication.h"
47 #include "qcombobox.h"
48 #include "qdialogbuttonbox.h"
49 #include "qlabel.h"
50 #include "qlayout.h"
51 #include "qlineedit.h"
52 #include "qlistwidget.h"
53 #include "qpushbutton.h"
54 #include "qspinbox.h"
55 #include "qstackedlayout.h"
56 #include "qvalidator.h"
57 #include "qevent.h"
58 #include "qdialog_p.h"
59 
61 
62 static const char *signalForMember(const char *member)
63 {
64  static const int NumCandidates = 4;
65  static const char * const candidateSignals[NumCandidates] = {
66  SIGNAL(textValueSelected(QString)),
67  SIGNAL(intValueSelected(int)),
68  SIGNAL(doubleValueSelected(double)),
69  SIGNAL(accepted())
70  };
71 
72  QByteArray normalizedMember(QMetaObject::normalizedSignature(member));
73 
74  int i = 0;
75  while (i < NumCandidates - 1) { // sic
76  if (QMetaObject::checkConnectArgs(candidateSignals[i], normalizedMember))
77  break;
78  ++i;
79  }
80  return candidateSignals[i];
81 }
82 
84 
85 /*
86  These internal classes add extra validation to QSpinBox and QDoubleSpinBox by emitting
87  textChanged(bool) after events that may potentially change the visible text. Return or
88  Enter key presses are not propagated if the visible text is invalid. Instead, the visible
89  text is modified to the last valid value.
90 */
92 {
93  Q_OBJECT
94 
95 public:
97  : QSpinBox(parent) {
100  }
101 
102 signals:
103  void textChanged(bool);
104 
105 private slots:
107 
108 private:
110  if ((event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) && !hasAcceptableInput()) {
111 #ifndef QT_NO_PROPERTIES
112  setProperty("value", property("value"));
113 #endif
114  } else {
116  }
118  }
119 
123  }
124 };
125 
127 {
128  Q_OBJECT
129 
130 public:
135  }
136 
137 signals:
138  void textChanged(bool);
139 
140 private slots:
142 
143 private:
145  if ((event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) && !hasAcceptableInput()) {
146 #ifndef QT_NO_PROPERTIES
147  setProperty("value", property("value"));
148 #endif
149  } else {
151  }
153  }
154 
158  }
159 };
160 
162 #include "qinputdialog.moc"
164 
166 {
168 
169 public:
171 
172  void ensureLayout();
173  void ensureLineEdit();
174  void ensureComboBox();
175  void ensureListView();
176  void ensureIntSpinBox();
177  void ensureDoubleSpinBox();
178  void ensureEnabledConnection(QAbstractSpinBox *spinBox);
179  void setInputWidget(QWidget *widget);
180  void chooseRightTextInputWidget();
181  void setComboBoxText(const QString &text);
182  void setListViewText(const QString &text);
183  QString listViewText() const;
184  void ensureLayout() const { const_cast<QInputDialogPrivate *>(this)->ensureLayout(); }
185  bool useComboBoxOrListView() const { return comboBox && comboBox->count() > 0; }
186  void _q_textChanged(const QString &text);
187  void _q_currentRowChanged(const QModelIndex &newIndex, const QModelIndex &oldIndex);
188 
189  mutable QLabel *label;
191  mutable QLineEdit *lineEdit;
194  mutable QComboBox *comboBox;
195  mutable QListView *listView;
198  QInputDialog::InputDialogOptions opts;
202 };
203 
205  : label(0), buttonBox(0), lineEdit(0), intSpinBox(0), doubleSpinBox(0), comboBox(0), listView(0),
206  inputWidget(0), mainLayout(0)
207 {
208 }
209 
211 {
212  Q_Q(QInputDialog);
213 
214  if (mainLayout)
215  return;
216 
217  if (!inputWidget) {
218  ensureLineEdit();
220  }
221 
222  if (!label)
223  label = new QLabel(QInputDialog::tr("Enter a value:"), q);
224 #ifndef QT_NO_SHORTCUT
226 #endif
228 
230  QObject::connect(buttonBox, SIGNAL(accepted()), q, SLOT(accept()));
231  QObject::connect(buttonBox, SIGNAL(rejected()), q, SLOT(reject()));
232 
233  mainLayout = new QVBoxLayout(q);
234  //we want to let the input dialog grow to available size on Symbian.
235 #ifndef Q_OS_SYMBIAN
237 #else
239 #endif
243  ensureEnabledConnection(qobject_cast<QAbstractSpinBox *>(inputWidget));
244  inputWidget->show();
245 }
246 
248 {
249  Q_Q(QInputDialog);
250  if (!lineEdit) {
251  lineEdit = new QLineEdit(q);
252 #ifndef QT_NO_IM
254 #endif
255  lineEdit->hide();
256  QObject::connect(lineEdit, SIGNAL(textChanged(QString)),
258  }
259 }
260 
262 {
263  Q_Q(QInputDialog);
264  if (!comboBox) {
265  comboBox = new QComboBox(q);
266 #ifndef QT_NO_IM
268 #endif
269  comboBox->hide();
270  QObject::connect(comboBox, SIGNAL(editTextChanged(QString)),
272  QObject::connect(comboBox, SIGNAL(currentIndexChanged(QString)),
274  }
275 }
276 
278 {
279  Q_Q(QInputDialog);
280  if (!listView) {
281  ensureComboBox();
282 
283  listView = new QListView(q);
284  listView->hide();
290  SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
292  }
293 }
294 
296 {
297  Q_Q(QInputDialog);
298  if (!intSpinBox) {
300  intSpinBox->hide();
301  QObject::connect(intSpinBox, SIGNAL(valueChanged(int)),
302  q, SIGNAL(intValueChanged(int)));
303  }
304 }
305 
307 {
308  Q_Q(QInputDialog);
309  if (!doubleSpinBox) {
311  doubleSpinBox->hide();
312  QObject::connect(doubleSpinBox, SIGNAL(valueChanged(double)),
313  q, SIGNAL(doubleValueChanged(double)));
314  }
315 }
316 
318 {
319  if (spinBox) {
321  QObject::connect(spinBox, SIGNAL(textChanged(bool)), okButton, SLOT(setEnabled(bool)), Qt::UniqueConnection);
322  }
323 }
324 
326 {
327  Q_ASSERT(widget);
328  if (inputWidget == widget)
329  return;
330 
331  if (mainLayout) {
334  inputWidget->hide();
335  mainLayout->insertWidget(1, widget);
336  widget->show();
337 
338  // disconnect old input widget
340  if (QAbstractSpinBox *spinBox = qobject_cast<QAbstractSpinBox *>(inputWidget))
341  QObject::disconnect(spinBox, SIGNAL(textChanged(bool)), okButton, SLOT(setEnabled(bool)));
342 
343  // connect new input widget and update enabled state of OK button
345  ensureEnabledConnection(spinBox);
346  okButton->setEnabled(!spinBox || spinBox->hasAcceptableInput());
347  }
348 
350 
351  // synchronize the text shown in the new text editor with the current
352  // textValue
353  if (widget == lineEdit) {
355  } else if (widget == comboBox) {
357  } else if (widget == listView) {
359  ensureLayout();
361  }
362 }
363 
365 {
366  QWidget *widget;
367 
368  if (useComboBoxOrListView()) {
370  ensureListView();
371  widget = listView;
372  } else {
373  widget = comboBox;
374  }
375  } else {
376  ensureLineEdit();
377  widget = lineEdit;
378  }
379 
380  setInputWidget(widget);
381 
382  if (inputWidget == comboBox) {
384  } else if (inputWidget == listView) {
386  }
387 }
388 
390 {
391  int index = comboBox->findText(text);
392  if (index != -1) {
393  comboBox->setCurrentIndex(index);
394  } else if (comboBox->isEditable()) {
395  comboBox->setEditText(text);
396  }
397 }
398 
400 {
401  int row = comboBox->findText(text);
402  if (row != -1) {
403  QModelIndex index(comboBox->model()->index(row, 0));
406  }
407 }
408 
410 {
412  int row = listView->selectionModel()->selectedRows().value(0).row();
413  return comboBox->itemText(row);
414  } else {
415  return QString();
416  }
417 }
418 
420 {
421  Q_Q(QInputDialog);
422  if (textValue != text) {
423  textValue = text;
424  emit q->textValueChanged(text);
425  }
426 }
427 
429  const QModelIndex & /* oldIndex */)
430 {
431  _q_textChanged(comboBox->model()->data(newIndex).toString());
433 }
434 
491 QInputDialog::QInputDialog(QWidget *parent, Qt::WindowFlags flags)
492  : QDialog(*new QInputDialogPrivate, parent, flags)
493 {
494 }
495 
505 {
506 }
507 
522 {
523  Q_D(QInputDialog);
524 
525  QWidget *widget;
526 
527  /*
528  Warning: Some functions in QInputDialog rely on implementation details
529  of the code below. Look for the comments that accompany the calls to
530  setInputMode() throughout this file before you change the code below.
531  */
532 
533  switch (mode) {
534  case IntInput:
535  d->ensureIntSpinBox();
536  widget = d->intSpinBox;
537  break;
538  case DoubleInput:
539  d->ensureDoubleSpinBox();
540  widget = d->doubleSpinBox;
541  break;
542  default:
543  Q_ASSERT(mode == TextInput);
544  d->chooseRightTextInputWidget();
545  return;
546  }
547 
548  d->setInputWidget(widget);
549 }
550 
552 {
553  Q_D(const QInputDialog);
554 
555  if (d->inputWidget) {
556  if (d->inputWidget == d->intSpinBox) {
557  return IntInput;
558  } else if (d->inputWidget == d->doubleSpinBox) {
559  return DoubleInput;
560  }
561  }
562 
563  return TextInput;
564 }
565 
577 {
578  Q_D(QInputDialog);
579  if (!d->label) {
580  d->label = new QLabel(text, this);
581  } else {
582  d->label->setText(text);
583  }
584 #ifdef Q_OS_SYMBIAN
585  d->label->setWordWrap(true);
586 #endif
587 }
588 
590 {
591  Q_D(const QInputDialog);
592  d->ensureLayout();
593  return d->label->text();
594 }
595 
621 {
622  Q_D(QInputDialog);
623  if (!(d->opts & option) != !on)
624  setOptions(d->opts ^ option);
625 }
626 
634 {
635  Q_D(const QInputDialog);
636  return (d->opts & option) != 0;
637 }
638 
651 void QInputDialog::setOptions(InputDialogOptions options)
652 {
653  Q_D(QInputDialog);
654 
655  InputDialogOptions changed = (options ^ d->opts);
656  if (!changed)
657  return;
658 
659  d->opts = options;
660  d->ensureLayout();
661 
662  if (changed & NoButtons)
663  d->buttonBox->setVisible(!(options & NoButtons));
664  if ((changed & UseListViewForComboBoxItems) && inputMode() == TextInput)
665  d->chooseRightTextInputWidget();
666 }
667 
668 QInputDialog::InputDialogOptions QInputDialog::options() const
669 {
670  Q_D(const QInputDialog);
671  return d->opts;
672 }
673 
688 {
689  Q_D(QInputDialog);
690 
692  if (d->inputWidget == d->lineEdit) {
693  d->lineEdit->setText(text);
694  } else if (d->inputWidget == d->comboBox) {
695  d->setComboBoxText(text);
696  } else {
697  d->setListViewText(text);
698  }
699 }
700 
702 {
703  Q_D(const QInputDialog);
704  return d->textValue;
705 }
706 
721 {
722  Q_D(QInputDialog);
723  d->ensureLineEdit();
724  d->lineEdit->setEchoMode(mode);
725 }
726 
728 {
729  Q_D(const QInputDialog);
730  if (d->lineEdit) {
731  return d->lineEdit->echoMode();
732  } else {
733  return QLineEdit::Normal;
734  }
735 }
736 
748 {
749  Q_D(QInputDialog);
750  d->ensureComboBox();
751  d->comboBox->setEditable(editable);
752  if (inputMode() == TextInput)
753  d->chooseRightTextInputWidget();
754 }
755 
757 {
758  Q_D(const QInputDialog);
759  if (d->comboBox) {
760  return d->comboBox->isEditable();
761  } else {
762  return false;
763  }
764 }
765 
777 {
778  Q_D(QInputDialog);
779 
780  d->ensureComboBox();
781  d->comboBox->blockSignals(true);
782  d->comboBox->clear();
783  d->comboBox->addItems(items);
784  d->comboBox->blockSignals(false);
785 
786  if (inputMode() == TextInput)
787  d->chooseRightTextInputWidget();
788 }
789 
791 {
792  Q_D(const QInputDialog);
794  if (d->comboBox) {
795  const int count = d->comboBox->count();
796  for (int i = 0; i < count; ++i)
797  result.append(d->comboBox->itemText(i));
798  }
799  return result;
800 }
801 
814 {
815  Q_D(QInputDialog);
817  d->intSpinBox->setValue(value);
818 }
819 
821 {
822  Q_D(const QInputDialog);
823  if (d->intSpinBox) {
824  return d->intSpinBox->value();
825  } else {
826  return 0;
827  }
828 }
829 
842 {
843  Q_D(QInputDialog);
844  d->ensureIntSpinBox();
845  d->intSpinBox->setMinimum(min);
846 }
847 
849 {
850  Q_D(const QInputDialog);
851  if (d->intSpinBox) {
852  return d->intSpinBox->minimum();
853  } else {
854  return 0;
855  }
856 }
857 
870 {
871  Q_D(QInputDialog);
872  d->ensureIntSpinBox();
873  d->intSpinBox->setMaximum(max);
874 }
875 
877 {
878  Q_D(const QInputDialog);
879  if (d->intSpinBox) {
880  return d->intSpinBox->maximum();
881  } else {
882  return 99;
883  }
884 }
885 
891 void QInputDialog::setIntRange(int min, int max)
892 {
893  Q_D(QInputDialog);
894  d->ensureIntSpinBox();
895  d->intSpinBox->setRange(min, max);
896 }
897 
910 {
911  Q_D(QInputDialog);
912  d->ensureIntSpinBox();
913  d->intSpinBox->setSingleStep(step);
914 }
915 
917 {
918  Q_D(const QInputDialog);
919  if (d->intSpinBox) {
920  return d->intSpinBox->singleStep();
921  } else {
922  return 1;
923  }
924 }
925 
938 {
939  Q_D(QInputDialog);
941  d->doubleSpinBox->setValue(value);
942 }
943 
945 {
946  Q_D(const QInputDialog);
947  if (d->doubleSpinBox) {
948  return d->doubleSpinBox->value();
949  } else {
950  return 0.0;
951  }
952 }
953 
966 {
967  Q_D(QInputDialog);
968  d->ensureDoubleSpinBox();
969  d->doubleSpinBox->setMinimum(min);
970 }
971 
973 {
974  Q_D(const QInputDialog);
975  if (d->doubleSpinBox) {
976  return d->doubleSpinBox->minimum();
977  } else {
978  return 0.0;
979  }
980 }
981 
994 {
995  Q_D(QInputDialog);
996  d->ensureDoubleSpinBox();
997  d->doubleSpinBox->setMaximum(max);
998 }
999 
1001 {
1002  Q_D(const QInputDialog);
1003  if (d->doubleSpinBox) {
1004  return d->doubleSpinBox->maximum();
1005  } else {
1006  return 99.99;
1007  }
1008 }
1009 
1015 void QInputDialog::setDoubleRange(double min, double max)
1016 {
1017  Q_D(QInputDialog);
1018  d->ensureDoubleSpinBox();
1019  d->doubleSpinBox->setRange(min, max);
1020 }
1021 
1035 {
1036  Q_D(QInputDialog);
1037  d->ensureDoubleSpinBox();
1038  d->doubleSpinBox->setDecimals(decimals);
1039 }
1040 
1042 {
1043  Q_D(const QInputDialog);
1044  if (d->doubleSpinBox) {
1045  return d->doubleSpinBox->decimals();
1046  } else {
1047  return 2;
1048  }
1049 }
1050 
1062 {
1063  Q_D(const QInputDialog);
1064  d->ensureLayout();
1065  d->buttonBox->button(QDialogButtonBox::Ok)->setText(text);
1066 }
1067 
1069 {
1070  Q_D(const QInputDialog);
1071  d->ensureLayout();
1072  return d->buttonBox->button(QDialogButtonBox::Ok)->text();
1073 }
1074 
1085 {
1086  Q_D(const QInputDialog);
1087  d->ensureLayout();
1088  d->buttonBox->button(QDialogButtonBox::Cancel)->setText(text);
1089 }
1090 
1092 {
1093  Q_D(const QInputDialog);
1094  d->ensureLayout();
1095  return d->buttonBox->button(QDialogButtonBox::Cancel)->text();
1096 }
1097 
1118 void QInputDialog::open(QObject *receiver, const char *member)
1119 {
1120  Q_D(QInputDialog);
1121  connect(this, signalForMember(member), receiver, member);
1122  d->receiverToDisconnectOnClose = receiver;
1123  d->memberToDisconnectOnClose = member;
1124  QDialog::open();
1125 }
1126 
1131 {
1132  Q_D(const QInputDialog);
1133  d->ensureLayout();
1134  return QDialog::minimumSizeHint();
1135 }
1136 
1141 {
1142  Q_D(const QInputDialog);
1143  d->ensureLayout();
1144  return QDialog::sizeHint();
1145 }
1146 
1151 {
1152  Q_D(const QInputDialog);
1153  if (visible) {
1154  d->ensureLayout();
1155  d->inputWidget->setFocus();
1156  if (d->inputWidget == d->lineEdit) {
1157  d->lineEdit->selectAll();
1158  } else if (d->inputWidget == d->intSpinBox) {
1159  d->intSpinBox->selectAll();
1160  } else if (d->inputWidget == d->doubleSpinBox) {
1161  d->doubleSpinBox->selectAll();
1162  }
1163  }
1164  QDialog::setVisible(visible);
1165 }
1166 
1175 {
1176  Q_D(QInputDialog);
1177  QDialog::done(result);
1178  if (result) {
1179  InputMode mode = inputMode();
1180  switch (mode) {
1181  case DoubleInput:
1183  break;
1184  case IntInput:
1186  break;
1187  default:
1188  Q_ASSERT(mode == TextInput);
1190  }
1191  }
1192  if (d->receiverToDisconnectOnClose) {
1193  disconnect(this, signalForMember(d->memberToDisconnectOnClose),
1194  d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose);
1195  d->receiverToDisconnectOnClose = 0;
1196  }
1197  d->memberToDisconnectOnClose.clear();
1198 }
1199 
1231  QLineEdit::EchoMode mode, const QString &text, bool *ok,
1232  Qt::WindowFlags flags, Qt::InputMethodHints inputMethodHints)
1233 {
1234  QInputDialog dialog(parent, flags);
1235  dialog.setWindowTitle(title);
1236  dialog.setLabelText(label);
1237  dialog.setTextValue(text);
1238  dialog.setTextEchoMode(mode);
1239  dialog.setInputMethodHints(inputMethodHints);
1240 
1241  int ret = dialog.exec();
1242  if (ok)
1243  *ok = !!ret;
1244  if (ret) {
1245  return dialog.textValue();
1246  } else {
1247  return QString();
1248  }
1249 }
1250 
1254 // ### Qt 5: Use only the version above.
1255 QString QInputDialog::getText(QWidget *parent, const QString &title, const QString &label,
1256  QLineEdit::EchoMode mode, const QString &text, bool *ok,
1257  Qt::WindowFlags flags)
1258 {
1259  return getText(parent, title, label, mode, text, ok, flags, Qt::ImhNone);
1260 }
1261 
1293 int QInputDialog::getInt(QWidget *parent, const QString &title, const QString &label, int value,
1294  int min, int max, int step, bool *ok, Qt::WindowFlags flags)
1295 {
1296  QInputDialog dialog(parent, flags);
1297  dialog.setWindowTitle(title);
1298  dialog.setLabelText(label);
1299  dialog.setIntRange(min, max);
1300  dialog.setIntValue(value);
1301  dialog.setIntStep(step);
1302 
1303  int ret = dialog.exec();
1304  if (ok)
1305  *ok = !!ret;
1306  if (ret) {
1307  return dialog.intValue();
1308  } else {
1309  return value;
1310  }
1311 }
1312 
1342 double QInputDialog::getDouble(QWidget *parent, const QString &title, const QString &label,
1343  double value, double min, double max, int decimals, bool *ok,
1344  Qt::WindowFlags flags)
1345 {
1346  QInputDialog dialog(parent, flags);
1347  dialog.setWindowTitle(title);
1348  dialog.setLabelText(label);
1349  dialog.setDoubleDecimals(decimals);
1350  dialog.setDoubleRange(min, max);
1351  dialog.setDoubleValue(value);
1352 
1353  int ret = dialog.exec();
1354  if (ok)
1355  *ok = !!ret;
1356  if (ret) {
1357  return dialog.doubleValue();
1358  } else {
1359  return value;
1360  }
1361 }
1362 
1396 QString QInputDialog::getItem(QWidget *parent, const QString &title, const QString &label,
1397  const QStringList &items, int current, bool editable, bool *ok,
1398  Qt::WindowFlags flags, Qt::InputMethodHints inputMethodHints)
1399 {
1400  QString text(items.value(current));
1401 
1402  QInputDialog dialog(parent, flags);
1403  dialog.setWindowTitle(title);
1404  dialog.setLabelText(label);
1405  dialog.setComboBoxItems(items);
1406  dialog.setTextValue(text);
1407  dialog.setComboBoxEditable(editable);
1408  dialog.setInputMethodHints(inputMethodHints);
1409 
1410  int ret = dialog.exec();
1411  if (ok)
1412  *ok = !!ret;
1413  if (ret) {
1414  return dialog.textValue();
1415  } else {
1416  return text;
1417  }
1418 }
1419 
1423 // ### Qt 5: Use only the version above.
1424 QString QInputDialog::getItem(QWidget *parent, const QString &title, const QString &label,
1425  const QStringList &items, int current, bool editable, bool *ok,
1426  Qt::WindowFlags flags)
1427 {
1428  return getItem(parent, title, label, items, current, editable, ok, flags, Qt::ImhNone);
1429 }
1430 
1439 int QInputDialog::getInteger(QWidget *parent, const QString &title, const QString &label,
1440  int value, int min, int max, int step, bool *ok,
1441  Qt::WindowFlags flags)
1442 {
1443  return getInt(parent, title, label, value, min, max, step, ok, flags);
1444 }
1445 
1576 
1577 #include "moc_qinputdialog.cpp"
1578 
1579 #endif // QT_NO_INPUTDIALOG
The QAbstractButton class is the abstract base class of button widgets, providing functionality commo...
QModelIndexList selectedRows(int column=0) const
Returns the indexes in the given column for the rows where all columns are selected.
T qobject_cast(QObject *object)
Definition: qobject.h:375
double d
Definition: qnumeric_p.h:62
void setTextEchoMode(QLineEdit::EchoMode mode)
void done(int result)
Closes the dialog and sets its result code to result.
double doubleMinimum() const
the minimum double precision floating point value accepted as input
void chooseRightTextInputWidget()
void setSelectionMode(QAbstractItemView::SelectionMode mode)
The QKeyEvent class describes a key event.
Definition: qevent.h:224
The TextInput item displays an editable line of text.
void setInputMethodHints(Qt::InputMethodHints hints)
Definition: qwidget.cpp:9736
QInputDialog::InputDialogOptions opts
bool event(QEvent *event)
Reimplemented Function
Definition: qspinbox.cpp:1397
static int getInt(QWidget *parent, const QString &title, const QString &label, int value=0, int minValue=-2147483647, int maxValue=2147483647, int step=1, bool *ok=0, Qt::WindowFlags flags=0)
bool isComboBoxEditable() const
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void setInputWidget(QWidget *widget)
QPointer< QWidget > widget
static QByteArray normalizedSignature(const char *method)
Normalizes the signature of the given method.
QString okButtonText() const
the text for the button used to accept the entry in the dialog
void setCancelButtonText(const QString &text)
The QDialog class is the base class of dialog windows.
Definition: qdialog.h:56
QSize minimumSizeHint() const
Reimplemented Function
Definition: qdialog.cpp:1186
int exec()
Shows the dialog as a modal dialog, blocking until the user closes it.
Definition: qdialog.cpp:524
static QString getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode echo=QLineEdit::Normal, const QString &text=QString(), bool *ok=0, Qt::WindowFlags flags=0, Qt::InputMethodHints inputMethodHints=Qt::ImhNone)
Static convenience function to get a string from the user.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define SLOT(a)
Definition: qobjectdefs.h:226
void mousePressEvent(QMouseEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
void setDoubleMinimum(double min)
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void setEditTriggers(EditTriggers triggers)
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object&#39;s name property to value.
Definition: qobject.cpp:3755
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
void intValueSelected(int value)
This signal is emitted whenever the user selects a integer value by accepting the dialog; for example...
uint inheritsInputMethodHints
Definition: qwidget_p.h:778
void keyPressEvent(QKeyEvent *event)
This function handles keyboard input.
The QInputDialog class provides a simple convenience dialog to get a single value from the user...
Definition: qinputdialog.h:59
void setComboBoxEditable(bool editable)
#define QT_END_INCLUDE_NAMESPACE
This macro is equivalent to QT_BEGIN_NAMESPACE.
Definition: qglobal.h:92
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
InputDialogOption
This enum specifies various options that affect the look and feel of an input dialog.
Definition: qinputdialog.h:83
void ensureEnabledConnection(QAbstractSpinBox *spinBox)
void setDoubleDecimals(int decimals)
void setCurrentIndex(int index)
Definition: qcombobox.cpp:2102
void keyPressEvent(QKeyEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive key press events f...
The QString class provides a Unicode character string.
Definition: qstring.h:83
void mousePressEvent(QMouseEvent *event)
Reimplemented Function
void setIntMinimum(int min)
void setIntMaximum(int max)
void keyPressEvent(QKeyEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive key press events f...
bool useComboBoxOrListView() const
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
QPointer< QObject > receiverToDisconnectOnClose
#define Q_D(Class)
Definition: qglobal.h:2482
void addWidget(QWidget *, int stretch=0, Qt::Alignment alignment=0)
Adds widget to the end of this box layout, with a stretch factor of stretch and alignment alignment...
static double getDouble(QWidget *parent, const QString &title, const QString &label, double value=0, double minValue=-2147483647, double maxValue=2147483647, int decimals=1, bool *ok=0, Qt::WindowFlags flags=0)
Static convenience function to get a floating point number from the user.
void setOptions(InputDialogOptions options)
QString itemText(int index) const
Returns the text for the given index in the combobox.
Definition: qcombobox.cpp:2161
#define Q_Q(Class)
Definition: qglobal.h:2483
QPushButton * button(StandardButton which) const
Returns the QPushButton corresponding to the standard button which, or 0 if the standard button doesn...
void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Sets the model item index to be the current item, and emits currentChanged().
void setDoubleRange(double min, double max)
Sets the range of double precision floating point values accepted by the dialog when used in DoubleIn...
virtual void setModel(QAbstractItemModel *model)
Sets the model for the view to present.
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const =0
Returns the index of the item in the model specified by the given row, column and parent index...
bool testOption(InputDialogOption option) const
Returns true if the given option is enabled; otherwise, returns false.
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void setWindowTitle(const QString &)
Definition: qwidget.cpp:6312
void _q_currentRowChanged(const QModelIndex &newIndex, const QModelIndex &oldIndex)
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
int intValue() const
the current integer value accepted as input
QLineEdit::EchoMode textEchoMode() const
the echo mode for the text value
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
double doubleValue() const
the current double precision floating point value accepted as input
EchoMode
This enum type describes how a line edit should display its contents.
Definition: qlineedit.h:113
bool visible
whether the widget is visible
Definition: qwidget.h:191
void textChanged(bool)
void insertWidget(int index, QWidget *widget, int stretch=0, Qt::Alignment alignment=0)
Inserts widget at position index, with stretch factor stretch and alignment alignment.
int intMaximum() const
the maximum integer value accepted as input
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
QItemSelectionModel * selectionModel() const
Returns the current selection model.
int row() const
Returns the row this model index refers to.
QString textValue() const
the text value for the input dialog
#define emit
Definition: qobjectdefs.h:76
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QString listViewText() const
int findText(const QString &text, Qt::MatchFlags flags=static_cast< Qt::MatchFlags >(Qt::MatchExactly|Qt::MatchCaseSensitive)) const
Returns the index of the item containing the given text; otherwise returns -1.
Definition: qcombobox.h:113
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
QSize sizeHint() const
Reimplemented Function
Definition: qdialog.cpp:1160
void textValueSelected(const QString &text)
This signal is emitted whenever the user selects a text string by accepting the dialog; for example...
void setCurrentIndex(const QModelIndex &index)
Sets the current item to be the item at index.
void editingFinished()
This signal is emitted editing is finished.
void setDoubleMaximum(double max)
static bool checkConnectArgs(const char *signal, const char *method)
Returns true if the signal and method arguments are compatible; otherwise returns false...
T value(int i) const
Returns the value at index position i in the list.
Definition: qlist.h:661
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const =0
Returns the data stored under the given role for the item referred to by the index.
static const char * signalForMember(const char *member)
int doubleDecimals() const
sets the percision of the double spinbox in decimals
void setComboBoxItems(const QStringList &items)
void mousePressEvent(QMouseEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
The QAbstractSpinBox class provides a spinbox and a line edit to display values.
QAbstractItemModel * model() const
Returns the model used by the combobox.
Definition: qcombobox.cpp:1968
void show()
Shows the widget and its child widgets.
int intStep() const
the step by which the integer value is increased and decreased
void doubleValueSelected(double value)
This signal is emitted whenever the user selects a double value by accepting the dialog; for example...
QLineEdit * lineEdit() const
This function returns a pointer to the line edit of the spin box.
QStringList comboBoxItems() const
the items used in the combobox for the input dialog
void setEnabled(bool)
Definition: qwidget.cpp:3447
#define Q_OBJECT
Definition: qobjectdefs.h:157
bool hasAcceptableInput() const
void hide()
Hides the widget.
Definition: qwidget.h:501
QString text() const
InputMode
This enum describes the different modes of input that can be selected for the dialog.
Definition: qinputdialog.h:90
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
virtual void done(int)
Closes the dialog and sets its result code to r.
Definition: qdialog.cpp:617
QDoubleSpinBox * doubleSpinBox
void setText(const QString &)
Definition: qlineedit.cpp:401
void setLabelText(const QString &text)
~QInputDialog()
Destroys the input dialog.
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
void setVisible(bool visible)
Reimplemented Function
bool hasSelection() const
Returns true if the selection model contains any selection ranges; otherwise returns false...
static QString getItem(QWidget *parent, const QString &title, const QString &label, const QStringList &items, int current=0, bool editable=true, bool *ok=0, Qt::WindowFlags flags=0, Qt::InputMethodHints inputMethodHints=Qt::ImhNone)
Static convenience function to let the user select an item from a string list.
static int getInteger(QWidget *parent, const QString &title, const QString &label, int value=0, int minValue=-2147483647, int maxValue=2147483647, int step=1, bool *ok=0, Qt::WindowFlags flags=0)
Use getInt() instead.
QInputDialog(QWidget *parent=0, Qt::WindowFlags flags=0)
Constructs a new input dialog with the given parent and window flags.
void setComboBoxText(const QString &text)
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
The QListView class provides a list or icon view onto a model.
Definition: qlistview.h:57
QByteArray memberToDisconnectOnClose
void setBuddy(QWidget *)
Sets this label&#39;s buddy to buddy.
Definition: qlabel.cpp:1297
double doubleMaximum() const
the maximum double precision floating point value accepted as input
The QDoubleSpinBox class provides a spin box widget that takes doubles.
Definition: qspinbox.h:126
void ensureLayout() const
void _q_textChanged(const QString &text)
The QDialogButtonBox class is a widget that presents buttons in a layout that is appropriate to the c...
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
void setOkButtonText(const QString &text)
QString cancelButtonText() const
the text for the button used to cancel the dialog
int result() const
In general returns the modal dialog&#39;s result code, Accepted or Rejected.
Definition: qdialog.cpp:458
void setIntValue(int value)
The QModelIndex class is used to locate data in a data model.
QString labelText() const
the text to for the label to describe what needs to be input
The QSpinBox class provides a spin box widget.
Definition: qspinbox.h:56
void setIntStep(int step)
The QLabel widget provides a text or image display.
Definition: qlabel.h:55
InputMode inputMode() const
the mode used for input
int intMinimum() const
the minimum integer value accepted as input
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
#define QT_USE_NAMESPACE
This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined and nothing otherwise.
Definition: qglobal.h:88
quint16 index
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
QObject * parent
Definition: qobject.h:92
#define QT_BEGIN_INCLUDE_NAMESPACE
This macro is equivalent to QT_END_NAMESPACE.
Definition: qglobal.h:91
QSize minimumSizeHint() const
Reimplemented Function
QDialogButtonBox * buttonBox
void setSizeConstraint(SizeConstraint)
Definition: qlayout.cpp:1435
void open()
Shows the dialog as a window modal dialog, returning immediately.
Definition: qdialog.cpp:492
QString currentText
the current text
Definition: qcombobox.h:70
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void setTextValue(const QString &text)
Q_GUI_EXPORT QWidgetPrivate * qt_widget_private(QWidget *widget)
Definition: qwidget.cpp:12920
The QVBoxLayout class lines up widgets vertically.
Definition: qboxlayout.h:149
void setIntRange(int min, int max)
Sets the range of integer values accepted by the dialog when used in IntInput mode, with minimum and maximum values specified by min and max respectively.
#define slots
Definition: qobjectdefs.h:68
bool isEditable() const
Definition: qcombobox.cpp:1723
InputDialogOptions options() const
the various options that affect the look and feel of the dialog
QSize sizeHint() const
Reimplemented Function
#define signals
Definition: qobjectdefs.h:69
void setSizePolicy(QSizePolicy)
Definition: qwidget.cpp:10198
void setInputMode(InputMode mode)
QVBoxLayout * mainLayout
Qt::InputMethodHints inputMethodHints() const
void setEditText(const QString &text)
Sets the text in the combobox&#39;s text edit.
Definition: qcombobox.cpp:2776
void setVisible(bool visible)
Reimplemented Function
Definition: qdialog.cpp:756
QInputDialogDoubleSpinBox(QWidget *parent=0)
void setDoubleValue(double value)
void setListViewText(const QString &text)
void removeWidget(QWidget *w)
Removes the widget widget from the layout.
Definition: qlayout.cpp:1516
#define text
Definition: qobjectdefs.h:80
QInputDialogSpinBox(QWidget *parent)
void setOption(InputDialogOption option, bool on=true)
Sets the given option to be enabled if on is true; otherwise, clears the given option.