diff options
Diffstat (limited to 'src/widgets/widgets/qcombobox.cpp')
-rw-r--r-- | src/widgets/widgets/qcombobox.cpp | 50 |
1 files changed, 34 insertions, 16 deletions
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 74b3dc77d3..f22fc196a2 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -64,7 +64,6 @@ #include <private/qcombobox_p.h> #include <private/qabstractitemmodel_p.h> #include <private/qabstractscrollarea_p.h> -#include <private/qsoftkeymanager_p.h> #include <qdebug.h> #if defined(Q_WS_MAC) && !defined(QT_NO_EFFECTS) && !defined(QT_NO_STYLE_MAC) #include <private/qcore_mac_p.h> @@ -561,13 +560,6 @@ void QComboBoxPrivateContainer::setItemView(QAbstractItemView *itemView) #endif connect(view, SIGNAL(destroyed()), this, SLOT(viewDestroyed())); - -#ifdef QT_SOFTKEYS_ENABLED - selectAction = QSoftKeyManager::createKeyedAction(QSoftKeyManager::SelectSoftKey, Qt::Key_Select, itemView); - cancelAction = QSoftKeyManager::createKeyedAction(QSoftKeyManager::CancelSoftKey, Qt::Key_Escape, itemView); - addAction(selectAction); - addAction(cancelAction); -#endif } /*! @@ -617,11 +609,6 @@ void QComboBoxPrivateContainer::changeEvent(QEvent *e) view->setMouseTracking(combo->style()->styleHint(QStyle::SH_ComboBox_ListMouseTracking, &opt, combo) || combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo)); setFrameStyle(combo->style()->styleHint(QStyle::SH_ComboBox_PopupFrameStyle, &opt, combo)); -#ifdef QT_SOFTKEYS_ENABLED - } else if (e->type() == QEvent::LanguageChange) { - selectAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::SelectSoftKey)); - cancelAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::CancelSoftKey)); -#endif } QWidget::changeEvent(e); @@ -822,6 +809,14 @@ QStyleOptionComboBox QComboBoxPrivateContainer::comboStyleOption() const */ /*! + \fn void QComboBox::currentTextChanged(const QString &text) + \since 5.0 + + This signal is sent whenever currentText changes. The new value + is passed as \a text. +*/ + +/*! Constructs a combobox with the given \a parent, using the default model QStandardItemModel. */ @@ -980,9 +975,12 @@ void QComboBoxPrivate::_q_dataChanged(const QModelIndex &topLeft, const QModelIn } if (currentIndex.row() >= topLeft.row() && currentIndex.row() <= bottomRight.row()) { + const QString text = q->itemText(currentIndex.row()); if (lineEdit) { - lineEdit->setText(q->itemText(currentIndex.row())); + lineEdit->setText(text); updateLineEditGeometry(); + } else { + emit q->currentTextChanged(text); } q->update(); } @@ -1242,7 +1240,11 @@ void QComboBoxPrivate::_q_emitCurrentIndexChanged(const QModelIndex &index) { Q_Q(QComboBox); emit q->currentIndexChanged(index.row()); - emit q->currentIndexChanged(itemText(index)); + const QString text = itemText(index); + emit q->currentIndexChanged(text); + // signal lineEdit.textChanged already connected to signal currentTextChanged, so don't emit double here + if (!lineEdit) + emit q->currentTextChanged(text); #ifndef QT_NO_ACCESSIBILITY QAccessibleEvent event(q, QAccessible::NameChanged); QAccessible::updateAccessibility(&event); @@ -1714,6 +1716,7 @@ void QComboBox::setLineEdit(QLineEdit *edit) connect(d->lineEdit, SIGNAL(returnPressed()), this, SLOT(_q_returnPressed())); connect(d->lineEdit, SIGNAL(editingFinished()), this, SLOT(_q_editingFinished())); connect(d->lineEdit, SIGNAL(textChanged(QString)), this, SIGNAL(editTextChanged(QString))); + connect(d->lineEdit, SIGNAL(textChanged(QString)), this, SIGNAL(currentTextChanged(QString))); d->lineEdit->setFrame(false); d->lineEdit->setContextMenuPolicy(Qt::NoContextMenu); d->lineEdit->setFocusProxy(this); @@ -2001,6 +2004,17 @@ void QComboBox::setCurrentIndex(int index) d->setCurrentIndex(mi); } +void QComboBox::setCurrentText(const QString &text) +{ + if (isEditable()) { + setEditText(text); + } else { + const int i = findText(text); + if (i > -1) + setCurrentIndex(i); + } +} + void QComboBoxPrivate::setCurrentIndex(const QModelIndex &mi) { Q_Q(QComboBox); @@ -2034,7 +2048,11 @@ void QComboBoxPrivate::setCurrentIndex(const QModelIndex &mi) by the line edit. Otherwise, it is the value of the current item or an empty string if the combo box is empty or no current item is set. - \sa editable + The setter setCurrentText() simply calls setEditText() if the combo box is editable. + Otherwise, if there is a matching text in the list, currentIndex is set to the + corresponding index. + + \sa editable, setEditText() */ QString QComboBox::currentText() const { |