| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qcombobox.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 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 "qcombobox.h" | - | ||||||||||||||||||
| 35 | - | |||||||||||||||||||
| 36 | #ifndef QT_NO_COMBOBOX | - | ||||||||||||||||||
| 37 | #include <qstylepainter.h> | - | ||||||||||||||||||
| 38 | #include <qpa/qplatformtheme.h> | - | ||||||||||||||||||
| 39 | #include <qpa/qplatformmenu.h> | - | ||||||||||||||||||
| 40 | #include <qlineedit.h> | - | ||||||||||||||||||
| 41 | #include <qapplication.h> | - | ||||||||||||||||||
| 42 | #include <qdesktopwidget.h> | - | ||||||||||||||||||
| 43 | #include <qlistview.h> | - | ||||||||||||||||||
| 44 | #include <qtableview.h> | - | ||||||||||||||||||
| 45 | #include <qitemdelegate.h> | - | ||||||||||||||||||
| 46 | #include <qmap.h> | - | ||||||||||||||||||
| 47 | #include <qmenu.h> | - | ||||||||||||||||||
| 48 | #include <qevent.h> | - | ||||||||||||||||||
| 49 | #include <qlayout.h> | - | ||||||||||||||||||
| 50 | #include <qscrollbar.h> | - | ||||||||||||||||||
| 51 | #include <qtreeview.h> | - | ||||||||||||||||||
| 52 | #include <qheaderview.h> | - | ||||||||||||||||||
| 53 | #include <qmath.h> | - | ||||||||||||||||||
| 54 | #include <qmetaobject.h> | - | ||||||||||||||||||
| 55 | #include <qabstractproxymodel.h> | - | ||||||||||||||||||
| 56 | #include <qstylehints.h> | - | ||||||||||||||||||
| 57 | #include <private/qguiapplication_p.h> | - | ||||||||||||||||||
| 58 | #include <private/qapplication_p.h> | - | ||||||||||||||||||
| 59 | #include <private/qcombobox_p.h> | - | ||||||||||||||||||
| 60 | #include <private/qabstractitemmodel_p.h> | - | ||||||||||||||||||
| 61 | #include <private/qabstractscrollarea_p.h> | - | ||||||||||||||||||
| 62 | #include <qdebug.h> | - | ||||||||||||||||||
| 63 | #if defined(Q_DEAD_CODE_FROM_QT4_MAC) && !defined(QT_NO_EFFECTS) && !defined(QT_NO_STYLE_MAC) | - | ||||||||||||||||||
| 64 | #include <private/qcore_mac_p.h> | - | ||||||||||||||||||
| 65 | #include <private/qmacstyle_mac_p.h> | - | ||||||||||||||||||
| 66 | #include <private/qt_cocoa_helpers_mac_p.h> | - | ||||||||||||||||||
| 67 | #endif | - | ||||||||||||||||||
| 68 | #ifndef QT_NO_EFFECTS | - | ||||||||||||||||||
| 69 | # include <private/qeffects_p.h> | - | ||||||||||||||||||
| 70 | #endif | - | ||||||||||||||||||
| 71 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||
| 72 | #include "qaccessible.h" | - | ||||||||||||||||||
| 73 | #endif | - | ||||||||||||||||||
| 74 | - | |||||||||||||||||||
| 75 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 76 | - | |||||||||||||||||||
| 77 | QComboBoxPrivate::QComboBoxPrivate() | - | ||||||||||||||||||
| 78 | : QWidgetPrivate(), | - | ||||||||||||||||||
| 79 | model(0), | - | ||||||||||||||||||
| 80 | lineEdit(0), | - | ||||||||||||||||||
| 81 | container(0), | - | ||||||||||||||||||
| 82 | insertPolicy(QComboBox::InsertAtBottom), | - | ||||||||||||||||||
| 83 | sizeAdjustPolicy(QComboBox::AdjustToContentsOnFirstShow), | - | ||||||||||||||||||
| 84 | minimumContentsLength(0), | - | ||||||||||||||||||
| 85 | shownOnce(false), | - | ||||||||||||||||||
| 86 | autoCompletion(true), | - | ||||||||||||||||||
| 87 | duplicatesEnabled(false), | - | ||||||||||||||||||
| 88 | frame(true), | - | ||||||||||||||||||
| 89 | maxVisibleItems(10), | - | ||||||||||||||||||
| 90 | maxCount(INT_MAX), | - | ||||||||||||||||||
| 91 | modelColumn(0), | - | ||||||||||||||||||
| 92 | inserting(false), | - | ||||||||||||||||||
| 93 | arrowState(QStyle::State_None), | - | ||||||||||||||||||
| 94 | hoverControl(QStyle::SC_None), | - | ||||||||||||||||||
| 95 | autoCompletionCaseSensitivity(Qt::CaseInsensitive), | - | ||||||||||||||||||
| 96 | indexBeforeChange(-1) | - | ||||||||||||||||||
| 97 | #ifdef Q_OS_MAC | - | ||||||||||||||||||
| 98 | , m_platformMenu(0) | - | ||||||||||||||||||
| 99 | #endif | - | ||||||||||||||||||
| 100 | #ifndef QT_NO_COMPLETER | - | ||||||||||||||||||
| 101 | , completer(0) | - | ||||||||||||||||||
| 102 | #endif | - | ||||||||||||||||||
| 103 | { | - | ||||||||||||||||||
| 104 | } never executed: end of block | 0 | ||||||||||||||||||
| 105 | - | |||||||||||||||||||
| 106 | QComboBoxPrivate::~QComboBoxPrivate() | - | ||||||||||||||||||
| 107 | { | - | ||||||||||||||||||
| 108 | #ifdef Q_OS_MAC | - | ||||||||||||||||||
| 109 | cleanupNativePopup(); | - | ||||||||||||||||||
| 110 | #endif | - | ||||||||||||||||||
| 111 | } | - | ||||||||||||||||||
| 112 | - | |||||||||||||||||||
| 113 | QStyleOptionMenuItem QComboMenuDelegate::getStyleOption(const QStyleOptionViewItem &option, | - | ||||||||||||||||||
| 114 | const QModelIndex &index) const | - | ||||||||||||||||||
| 115 | { | - | ||||||||||||||||||
| 116 | QStyleOptionMenuItem menuOption; | - | ||||||||||||||||||
| 117 | - | |||||||||||||||||||
| 118 | QPalette resolvedpalette = option.palette.resolve(QApplication::palette("QMenu")); | - | ||||||||||||||||||
| 119 | QVariant value = index.data(Qt::ForegroundRole); | - | ||||||||||||||||||
| 120 | if (value.canConvert<QBrush>()) {
| 0 | ||||||||||||||||||
| 121 | resolvedpalette.setBrush(QPalette::WindowText, qvariant_cast<QBrush>(value)); | - | ||||||||||||||||||
| 122 | resolvedpalette.setBrush(QPalette::ButtonText, qvariant_cast<QBrush>(value)); | - | ||||||||||||||||||
| 123 | resolvedpalette.setBrush(QPalette::Text, qvariant_cast<QBrush>(value)); | - | ||||||||||||||||||
| 124 | } never executed: end of block | 0 | ||||||||||||||||||
| 125 | menuOption.palette = resolvedpalette; | - | ||||||||||||||||||
| 126 | menuOption.state = QStyle::State_None; | - | ||||||||||||||||||
| 127 | if (mCombo->window()->isActiveWindow())
| 0 | ||||||||||||||||||
| 128 | menuOption.state = QStyle::State_Active; never executed: menuOption.state = QStyle::State_Active; | 0 | ||||||||||||||||||
| 129 | if ((option.state & QStyle::State_Enabled) && (index.model()->flags(index) & Qt::ItemIsEnabled))
| 0 | ||||||||||||||||||
| 130 | menuOption.state |= QStyle::State_Enabled; never executed: menuOption.state |= QStyle::State_Enabled; | 0 | ||||||||||||||||||
| 131 | else | - | ||||||||||||||||||
| 132 | menuOption.palette.setCurrentColorGroup(QPalette::Disabled); never executed: menuOption.palette.setCurrentColorGroup(QPalette::Disabled); | 0 | ||||||||||||||||||
| 133 | if (option.state & QStyle::State_Selected)
| 0 | ||||||||||||||||||
| 134 | menuOption.state |= QStyle::State_Selected; never executed: menuOption.state |= QStyle::State_Selected; | 0 | ||||||||||||||||||
| 135 | menuOption.checkType = QStyleOptionMenuItem::NonExclusive; | - | ||||||||||||||||||
| 136 | menuOption.checked = mCombo->currentIndex() == index.row(); | - | ||||||||||||||||||
| 137 | if (QComboBoxDelegate::isSeparator(index))
| 0 | ||||||||||||||||||
| 138 | menuOption.menuItemType = QStyleOptionMenuItem::Separator; never executed: menuOption.menuItemType = QStyleOptionMenuItem::Separator; | 0 | ||||||||||||||||||
| 139 | else | - | ||||||||||||||||||
| 140 | menuOption.menuItemType = QStyleOptionMenuItem::Normal; never executed: menuOption.menuItemType = QStyleOptionMenuItem::Normal; | 0 | ||||||||||||||||||
| 141 | - | |||||||||||||||||||
| 142 | QVariant variant = index.model()->data(index, Qt::DecorationRole); | - | ||||||||||||||||||
| 143 | switch (variant.type()) { | - | ||||||||||||||||||
| 144 | case QVariant::Icon: never executed: case QVariant::Icon: | 0 | ||||||||||||||||||
| 145 | menuOption.icon = qvariant_cast<QIcon>(variant); | - | ||||||||||||||||||
| 146 | break; never executed: break; | 0 | ||||||||||||||||||
| 147 | case QVariant::Color: { never executed: case QVariant::Color: | 0 | ||||||||||||||||||
| 148 | static QPixmap pixmap(option.decorationSize); | - | ||||||||||||||||||
| 149 | pixmap.fill(qvariant_cast<QColor>(variant)); | - | ||||||||||||||||||
| 150 | menuOption.icon = pixmap; | - | ||||||||||||||||||
| 151 | break; } never executed: break; | 0 | ||||||||||||||||||
| 152 | default: never executed: default: | 0 | ||||||||||||||||||
| 153 | menuOption.icon = qvariant_cast<QPixmap>(variant); | - | ||||||||||||||||||
| 154 | break; never executed: break; | 0 | ||||||||||||||||||
| 155 | } | - | ||||||||||||||||||
| 156 | if (index.data(Qt::BackgroundRole).canConvert<QBrush>()) {
| 0 | ||||||||||||||||||
| 157 | menuOption.palette.setBrush(QPalette::All, QPalette::Background, | - | ||||||||||||||||||
| 158 | qvariant_cast<QBrush>(index.data(Qt::BackgroundRole))); | - | ||||||||||||||||||
| 159 | } never executed: end of block | 0 | ||||||||||||||||||
| 160 | menuOption.text = index.model()->data(index, Qt::DisplayRole).toString() | - | ||||||||||||||||||
| 161 | .replace(QLatin1Char('&'), QLatin1String("&&")); | - | ||||||||||||||||||
| 162 | menuOption.tabWidth = 0; | - | ||||||||||||||||||
| 163 | menuOption.maxIconWidth = option.decorationSize.width() + 4; | - | ||||||||||||||||||
| 164 | menuOption.menuRect = option.rect; | - | ||||||||||||||||||
| 165 | menuOption.rect = option.rect; | - | ||||||||||||||||||
| 166 | - | |||||||||||||||||||
| 167 | // Make sure fonts set on the combo box also overrides the font for the popup menu. | - | ||||||||||||||||||
| 168 | if (mCombo->testAttribute(Qt::WA_SetFont)
| 0 | ||||||||||||||||||
| 169 | || mCombo->testAttribute(Qt::WA_MacSmallSize)
| 0 | ||||||||||||||||||
| 170 | || mCombo->testAttribute(Qt::WA_MacMiniSize)
| 0 | ||||||||||||||||||
| 171 | || mCombo->font() != qt_app_fonts_hash()->value("QComboBox", QFont())) {
| 0 | ||||||||||||||||||
| 172 | menuOption.font = mCombo->font(); | - | ||||||||||||||||||
| 173 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 174 | QVariant fontRoleData = index.data(Qt::FontRole); | - | ||||||||||||||||||
| 175 | if (fontRoleData.isValid())
| 0 | ||||||||||||||||||
| 176 | menuOption.font = fontRoleData.value<QFont>(); never executed: menuOption.font = fontRoleData.value<QFont>(); | 0 | ||||||||||||||||||
| 177 | else | - | ||||||||||||||||||
| 178 | menuOption.font = qt_app_fonts_hash()->value("QComboMenuItem", mCombo->font()); never executed: menuOption.font = qt_app_fonts_hash()->value("QComboMenuItem", mCombo->font()); | 0 | ||||||||||||||||||
| 179 | } | - | ||||||||||||||||||
| 180 | - | |||||||||||||||||||
| 181 | menuOption.fontMetrics = QFontMetrics(menuOption.font); | - | ||||||||||||||||||
| 182 | - | |||||||||||||||||||
| 183 | return menuOption; never executed: return menuOption; | 0 | ||||||||||||||||||
| 184 | } | - | ||||||||||||||||||
| 185 | - | |||||||||||||||||||
| 186 | #ifndef QT_NO_COMPLETER | - | ||||||||||||||||||
| 187 | void QComboBoxPrivate::_q_completerActivated(const QModelIndex &index) | - | ||||||||||||||||||
| 188 | { | - | ||||||||||||||||||
| 189 | Q_Q(QComboBox); | - | ||||||||||||||||||
| 190 | if (index.isValid() && q->completer()) {
| 0 | ||||||||||||||||||
| 191 | QAbstractProxyModel *proxy = qobject_cast<QAbstractProxyModel *>(q->completer()->completionModel()); | - | ||||||||||||||||||
| 192 | if (proxy) {
| 0 | ||||||||||||||||||
| 193 | q->setCurrentIndex(proxy->mapToSource(index).row()); | - | ||||||||||||||||||
| 194 | emitActivated(currentIndex); | - | ||||||||||||||||||
| 195 | } never executed: end of block | 0 | ||||||||||||||||||
| 196 | } never executed: end of block | 0 | ||||||||||||||||||
| 197 | - | |||||||||||||||||||
| 198 | # ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
| 199 | if ( QApplication::keypadNavigationEnabled() | - | ||||||||||||||||||
| 200 | && q->isEditable() | - | ||||||||||||||||||
| 201 | && q->completer() | - | ||||||||||||||||||
| 202 | && q->completer()->completionMode() == QCompleter::UnfilteredPopupCompletion ) { | - | ||||||||||||||||||
| 203 | q->setEditFocus(false); | - | ||||||||||||||||||
| 204 | } | - | ||||||||||||||||||
| 205 | # endif // QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
| 206 | } never executed: end of block | 0 | ||||||||||||||||||
| 207 | #endif // !QT_NO_COMPLETER | - | ||||||||||||||||||
| 208 | - | |||||||||||||||||||
| 209 | void QComboBoxPrivate::updateArrow(QStyle::StateFlag state) | - | ||||||||||||||||||
| 210 | { | - | ||||||||||||||||||
| 211 | Q_Q(QComboBox); | - | ||||||||||||||||||
| 212 | if (arrowState == state)
| 0 | ||||||||||||||||||
| 213 | return; never executed: return; | 0 | ||||||||||||||||||
| 214 | arrowState = state; | - | ||||||||||||||||||
| 215 | QStyleOptionComboBox opt; | - | ||||||||||||||||||
| 216 | q->initStyleOption(&opt); | - | ||||||||||||||||||
| 217 | q->update(q->rect()); | - | ||||||||||||||||||
| 218 | } never executed: end of block | 0 | ||||||||||||||||||
| 219 | - | |||||||||||||||||||
| 220 | void QComboBoxPrivate::_q_modelReset() | - | ||||||||||||||||||
| 221 | { | - | ||||||||||||||||||
| 222 | Q_Q(QComboBox); | - | ||||||||||||||||||
| 223 | if (lineEdit) {
| 0 | ||||||||||||||||||
| 224 | lineEdit->setText(QString()); | - | ||||||||||||||||||
| 225 | updateLineEditGeometry(); | - | ||||||||||||||||||
| 226 | } never executed: end of block | 0 | ||||||||||||||||||
| 227 | if (currentIndex.row() != indexBeforeChange)
| 0 | ||||||||||||||||||
| 228 | _q_emitCurrentIndexChanged(currentIndex); never executed: _q_emitCurrentIndexChanged(currentIndex); | 0 | ||||||||||||||||||
| 229 | modelChanged(); | - | ||||||||||||||||||
| 230 | q->update(); | - | ||||||||||||||||||
| 231 | } never executed: end of block | 0 | ||||||||||||||||||
| 232 | - | |||||||||||||||||||
| 233 | void QComboBoxPrivate::_q_modelDestroyed() | - | ||||||||||||||||||
| 234 | { | - | ||||||||||||||||||
| 235 | model = QAbstractItemModelPrivate::staticEmptyModel(); | - | ||||||||||||||||||
| 236 | } never executed: end of block | 0 | ||||||||||||||||||
| 237 | - | |||||||||||||||||||
| 238 | - | |||||||||||||||||||
| 239 | //Windows and KDE allows menus to cover the taskbar, while GNOME and Mac don't | - | ||||||||||||||||||
| 240 | QRect QComboBoxPrivate::popupGeometry(int screen) const | - | ||||||||||||||||||
| 241 | { | - | ||||||||||||||||||
| 242 | bool useFullScreenForPopupMenu = false; | - | ||||||||||||||||||
| 243 | if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme())
| 0 | ||||||||||||||||||
| 244 | useFullScreenForPopupMenu = theme->themeHint(QPlatformTheme::UseFullScreenForPopupMenu).toBool(); never executed: useFullScreenForPopupMenu = theme->themeHint(QPlatformTheme::UseFullScreenForPopupMenu).toBool(); | 0 | ||||||||||||||||||
| 245 | return useFullScreenForPopupMenu ? never executed: return useFullScreenForPopupMenu ? QApplication::desktop()->screenGeometry(screen) : QApplication::desktop()->availableGeometry(screen);
| 0 | ||||||||||||||||||
| 246 | QApplication::desktop()->screenGeometry(screen) : never executed: return useFullScreenForPopupMenu ? QApplication::desktop()->screenGeometry(screen) : QApplication::desktop()->availableGeometry(screen); | 0 | ||||||||||||||||||
| 247 | QApplication::desktop()->availableGeometry(screen); never executed: return useFullScreenForPopupMenu ? QApplication::desktop()->screenGeometry(screen) : QApplication::desktop()->availableGeometry(screen); | 0 | ||||||||||||||||||
| 248 | } | - | ||||||||||||||||||
| 249 | - | |||||||||||||||||||
| 250 | bool QComboBoxPrivate::updateHoverControl(const QPoint &pos) | - | ||||||||||||||||||
| 251 | { | - | ||||||||||||||||||
| 252 | - | |||||||||||||||||||
| 253 | Q_Q(QComboBox); | - | ||||||||||||||||||
| 254 | QRect lastHoverRect = hoverRect; | - | ||||||||||||||||||
| 255 | QStyle::SubControl lastHoverControl = hoverControl; | - | ||||||||||||||||||
| 256 | bool doesHover = q->testAttribute(Qt::WA_Hover); | - | ||||||||||||||||||
| 257 | if (lastHoverControl != newHoverControl(pos) && doesHover) {
| 0 | ||||||||||||||||||
| 258 | q->update(lastHoverRect); | - | ||||||||||||||||||
| 259 | q->update(hoverRect); | - | ||||||||||||||||||
| 260 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 261 | } | - | ||||||||||||||||||
| 262 | return !doesHover; never executed: return !doesHover; | 0 | ||||||||||||||||||
| 263 | } | - | ||||||||||||||||||
| 264 | - | |||||||||||||||||||
| 265 | QStyle::SubControl QComboBoxPrivate::newHoverControl(const QPoint &pos) | - | ||||||||||||||||||
| 266 | { | - | ||||||||||||||||||
| 267 | Q_Q(QComboBox); | - | ||||||||||||||||||
| 268 | QStyleOptionComboBox opt; | - | ||||||||||||||||||
| 269 | q->initStyleOption(&opt); | - | ||||||||||||||||||
| 270 | opt.subControls = QStyle::SC_All; | - | ||||||||||||||||||
| 271 | hoverControl = q->style()->hitTestComplexControl(QStyle::CC_ComboBox, &opt, pos, q); | - | ||||||||||||||||||
| 272 | hoverRect = (hoverControl != QStyle::SC_None)
| 0 | ||||||||||||||||||
| 273 | ? q->style()->subControlRect(QStyle::CC_ComboBox, &opt, hoverControl, q) | - | ||||||||||||||||||
| 274 | : QRect(); | - | ||||||||||||||||||
| 275 | return hoverControl; never executed: return hoverControl; | 0 | ||||||||||||||||||
| 276 | } | - | ||||||||||||||||||
| 277 | - | |||||||||||||||||||
| 278 | /* | - | ||||||||||||||||||
| 279 | Computes a size hint based on the maximum width | - | ||||||||||||||||||
| 280 | for the items in the combobox. | - | ||||||||||||||||||
| 281 | */ | - | ||||||||||||||||||
| 282 | int QComboBoxPrivate::computeWidthHint() const | - | ||||||||||||||||||
| 283 | { | - | ||||||||||||||||||
| 284 | Q_Q(const QComboBox); | - | ||||||||||||||||||
| 285 | - | |||||||||||||||||||
| 286 | int width = 0; | - | ||||||||||||||||||
| 287 | const int count = q->count(); | - | ||||||||||||||||||
| 288 | const int iconWidth = q->iconSize().width() + 4; | - | ||||||||||||||||||
| 289 | const QFontMetrics &fontMetrics = q->fontMetrics(); | - | ||||||||||||||||||
| 290 | - | |||||||||||||||||||
| 291 | for (int i = 0; i < count; ++i) {
| 0 | ||||||||||||||||||
| 292 | const int textWidth = fontMetrics.width(q->itemText(i)); | - | ||||||||||||||||||
| 293 | if (q->itemIcon(i).isNull())
| 0 | ||||||||||||||||||
| 294 | width = (qMax(width, textWidth)); never executed: width = (qMax(width, textWidth)); | 0 | ||||||||||||||||||
| 295 | else | - | ||||||||||||||||||
| 296 | width = (qMax(width, textWidth + iconWidth)); never executed: width = (qMax(width, textWidth + iconWidth)); | 0 | ||||||||||||||||||
| 297 | } | - | ||||||||||||||||||
| 298 | - | |||||||||||||||||||
| 299 | QStyleOptionComboBox opt; | - | ||||||||||||||||||
| 300 | q->initStyleOption(&opt); | - | ||||||||||||||||||
| 301 | QSize tmp(width, 0); | - | ||||||||||||||||||
| 302 | tmp = q->style()->sizeFromContents(QStyle::CT_ComboBox, &opt, tmp, q); | - | ||||||||||||||||||
| 303 | return tmp.width(); never executed: return tmp.width(); | 0 | ||||||||||||||||||
| 304 | } | - | ||||||||||||||||||
| 305 | - | |||||||||||||||||||
| 306 | QSize QComboBoxPrivate::recomputeSizeHint(QSize &sh) const | - | ||||||||||||||||||
| 307 | { | - | ||||||||||||||||||
| 308 | Q_Q(const QComboBox); | - | ||||||||||||||||||
| 309 | if (!sh.isValid()) {
| 0 | ||||||||||||||||||
| 310 | bool hasIcon = sizeAdjustPolicy == QComboBox::AdjustToMinimumContentsLengthWithIcon; | - | ||||||||||||||||||
| 311 | int count = q->count(); | - | ||||||||||||||||||
| 312 | QSize iconSize = q->iconSize(); | - | ||||||||||||||||||
| 313 | const QFontMetrics &fm = q->fontMetrics(); | - | ||||||||||||||||||
| 314 | - | |||||||||||||||||||
| 315 | // text width | - | ||||||||||||||||||
| 316 | if (&sh == &sizeHint || minimumContentsLength == 0) {
| 0 | ||||||||||||||||||
| 317 | switch (sizeAdjustPolicy) { | - | ||||||||||||||||||
| 318 | case QComboBox::AdjustToContents: never executed: case QComboBox::AdjustToContents: | 0 | ||||||||||||||||||
| 319 | case QComboBox::AdjustToContentsOnFirstShow: never executed: case QComboBox::AdjustToContentsOnFirstShow: | 0 | ||||||||||||||||||
| 320 | if (count == 0) {
| 0 | ||||||||||||||||||
| 321 | sh.rwidth() = 7 * fm.width(QLatin1Char('x')); | - | ||||||||||||||||||
| 322 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 323 | for (int i = 0; i < count; ++i) {
| 0 | ||||||||||||||||||
| 324 | if (!q->itemIcon(i).isNull()) {
| 0 | ||||||||||||||||||
| 325 | hasIcon = true; | - | ||||||||||||||||||
| 326 | sh.setWidth(qMax(sh.width(), fm.boundingRect(q->itemText(i)).width() + iconSize.width() + 4)); | - | ||||||||||||||||||
| 327 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 328 | sh.setWidth(qMax(sh.width(), fm.boundingRect(q->itemText(i)).width())); | - | ||||||||||||||||||
| 329 | } never executed: end of block | 0 | ||||||||||||||||||
| 330 | } | - | ||||||||||||||||||
| 331 | } never executed: end of block | 0 | ||||||||||||||||||
| 332 | break; never executed: break; | 0 | ||||||||||||||||||
| 333 | case QComboBox::AdjustToMinimumContentsLength: never executed: case QComboBox::AdjustToMinimumContentsLength: | 0 | ||||||||||||||||||
| 334 | for (int i = 0; i < count && !hasIcon; ++i)
| 0 | ||||||||||||||||||
| 335 | hasIcon = !q->itemIcon(i).isNull(); never executed: hasIcon = !q->itemIcon(i).isNull(); | 0 | ||||||||||||||||||
| 336 | default: code before this statement never executed: default:never executed: default: | 0 | ||||||||||||||||||
| 337 | ; | - | ||||||||||||||||||
| 338 | } never executed: end of block | 0 | ||||||||||||||||||
| 339 | } else { | - | ||||||||||||||||||
| 340 | for (int i = 0; i < count && !hasIcon; ++i)
| 0 | ||||||||||||||||||
| 341 | hasIcon = !q->itemIcon(i).isNull(); never executed: hasIcon = !q->itemIcon(i).isNull(); | 0 | ||||||||||||||||||
| 342 | } never executed: end of block | 0 | ||||||||||||||||||
| 343 | if (minimumContentsLength > 0)
| 0 | ||||||||||||||||||
| 344 | sh.setWidth(qMax(sh.width(), minimumContentsLength * fm.width(QLatin1Char('X')) + (hasIcon ? iconSize.width() + 4 : 0))); never executed: sh.setWidth(qMax(sh.width(), minimumContentsLength * fm.width(QLatin1Char('X')) + (hasIcon ? iconSize.width() + 4 : 0))); | 0 | ||||||||||||||||||
| 345 | - | |||||||||||||||||||
| 346 | - | |||||||||||||||||||
| 347 | // height | - | ||||||||||||||||||
| 348 | sh.setHeight(qMax(qCeil(QFontMetricsF(fm).height()), 14) + 2); | - | ||||||||||||||||||
| 349 | if (hasIcon) {
| 0 | ||||||||||||||||||
| 350 | sh.setHeight(qMax(sh.height(), iconSize.height() + 2)); | - | ||||||||||||||||||
| 351 | } never executed: end of block | 0 | ||||||||||||||||||
| 352 | - | |||||||||||||||||||
| 353 | // add style and strut values | - | ||||||||||||||||||
| 354 | QStyleOptionComboBox opt; | - | ||||||||||||||||||
| 355 | q->initStyleOption(&opt); | - | ||||||||||||||||||
| 356 | sh = q->style()->sizeFromContents(QStyle::CT_ComboBox, &opt, sh, q); | - | ||||||||||||||||||
| 357 | } never executed: end of block | 0 | ||||||||||||||||||
| 358 | return sh.expandedTo(QApplication::globalStrut()); never executed: return sh.expandedTo(QApplication::globalStrut()); | 0 | ||||||||||||||||||
| 359 | } | - | ||||||||||||||||||
| 360 | - | |||||||||||||||||||
| 361 | void QComboBoxPrivate::adjustComboBoxSize() | - | ||||||||||||||||||
| 362 | { | - | ||||||||||||||||||
| 363 | viewContainer()->adjustSizeTimer.start(20, container); | - | ||||||||||||||||||
| 364 | } never executed: end of block | 0 | ||||||||||||||||||
| 365 | - | |||||||||||||||||||
| 366 | void QComboBoxPrivate::updateLayoutDirection() | - | ||||||||||||||||||
| 367 | { | - | ||||||||||||||||||
| 368 | Q_Q(const QComboBox); | - | ||||||||||||||||||
| 369 | QStyleOptionComboBox opt; | - | ||||||||||||||||||
| 370 | q->initStyleOption(&opt); | - | ||||||||||||||||||
| 371 | Qt::LayoutDirection dir = Qt::LayoutDirection( | - | ||||||||||||||||||
| 372 | q->style()->styleHint(QStyle::SH_ComboBox_LayoutDirection, &opt, q)); | - | ||||||||||||||||||
| 373 | if (lineEdit)
| 0 | ||||||||||||||||||
| 374 | lineEdit->setLayoutDirection(dir); never executed: lineEdit->setLayoutDirection(dir); | 0 | ||||||||||||||||||
| 375 | if (container)
| 0 | ||||||||||||||||||
| 376 | container->setLayoutDirection(dir); never executed: container->setLayoutDirection(dir); | 0 | ||||||||||||||||||
| 377 | } never executed: end of block | 0 | ||||||||||||||||||
| 378 | - | |||||||||||||||||||
| 379 | - | |||||||||||||||||||
| 380 | void QComboBoxPrivateContainer::timerEvent(QTimerEvent *timerEvent) | - | ||||||||||||||||||
| 381 | { | - | ||||||||||||||||||
| 382 | if (timerEvent->timerId() == adjustSizeTimer.timerId()) {
| 0 | ||||||||||||||||||
| 383 | adjustSizeTimer.stop(); | - | ||||||||||||||||||
| 384 | if (combo->sizeAdjustPolicy() == QComboBox::AdjustToContents) {
| 0 | ||||||||||||||||||
| 385 | combo->updateGeometry(); | - | ||||||||||||||||||
| 386 | combo->adjustSize(); | - | ||||||||||||||||||
| 387 | combo->update(); | - | ||||||||||||||||||
| 388 | } never executed: end of block | 0 | ||||||||||||||||||
| 389 | } never executed: end of block | 0 | ||||||||||||||||||
| 390 | } never executed: end of block | 0 | ||||||||||||||||||
| 391 | - | |||||||||||||||||||
| 392 | void QComboBoxPrivateContainer::resizeEvent(QResizeEvent *e) | - | ||||||||||||||||||
| 393 | { | - | ||||||||||||||||||
| 394 | QStyleOptionComboBox opt = comboStyleOption(); | - | ||||||||||||||||||
| 395 | if (combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo)) {
| 0 | ||||||||||||||||||
| 396 | QStyleOption myOpt; | - | ||||||||||||||||||
| 397 | myOpt.initFrom(this); | - | ||||||||||||||||||
| 398 | QStyleHintReturnMask mask; | - | ||||||||||||||||||
| 399 | if (combo->style()->styleHint(QStyle::SH_Menu_Mask, &myOpt, this, &mask)) {
| 0 | ||||||||||||||||||
| 400 | setMask(mask.region); | - | ||||||||||||||||||
| 401 | } never executed: end of block | 0 | ||||||||||||||||||
| 402 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 403 | clearMask(); | - | ||||||||||||||||||
| 404 | } never executed: end of block | 0 | ||||||||||||||||||
| 405 | QFrame::resizeEvent(e); | - | ||||||||||||||||||
| 406 | } never executed: end of block | 0 | ||||||||||||||||||
| 407 | - | |||||||||||||||||||
| 408 | void QComboBoxPrivateContainer::leaveEvent(QEvent *) | - | ||||||||||||||||||
| 409 | { | - | ||||||||||||||||||
| 410 | // On Mac using the Mac style we want to clear the selection | - | ||||||||||||||||||
| 411 | // when the mouse moves outside the popup. | - | ||||||||||||||||||
| 412 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||
| 413 | QStyleOptionComboBox opt = comboStyleOption(); | - | ||||||||||||||||||
| 414 | if (combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo)) | - | ||||||||||||||||||
| 415 | view->clearSelection(); | - | ||||||||||||||||||
| 416 | #endif | - | ||||||||||||||||||
| 417 | } | - | ||||||||||||||||||
| 418 | - | |||||||||||||||||||
| 419 | QComboBoxPrivateContainer::QComboBoxPrivateContainer(QAbstractItemView *itemView, QComboBox *parent) | - | ||||||||||||||||||
| 420 | : QFrame(parent, Qt::Popup), combo(parent), view(0), top(0), bottom(0), maybeIgnoreMouseButtonRelease(false) | - | ||||||||||||||||||
| 421 | { | - | ||||||||||||||||||
| 422 | // we need the combobox and itemview | - | ||||||||||||||||||
| 423 | Q_ASSERT(parent); | - | ||||||||||||||||||
| 424 | Q_ASSERT(itemView); | - | ||||||||||||||||||
| 425 | - | |||||||||||||||||||
| 426 | setAttribute(Qt::WA_WindowPropagation); | - | ||||||||||||||||||
| 427 | setAttribute(Qt::WA_X11NetWmWindowTypeCombo); | - | ||||||||||||||||||
| 428 | - | |||||||||||||||||||
| 429 | // setup container | - | ||||||||||||||||||
| 430 | blockMouseReleaseTimer.setSingleShot(true); | - | ||||||||||||||||||
| 431 | - | |||||||||||||||||||
| 432 | // we need a vertical layout | - | ||||||||||||||||||
| 433 | QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom, this); | - | ||||||||||||||||||
| 434 | layout->setSpacing(0); | - | ||||||||||||||||||
| 435 | layout->setMargin(0); | - | ||||||||||||||||||
| 436 | - | |||||||||||||||||||
| 437 | // set item view | - | ||||||||||||||||||
| 438 | setItemView(itemView); | - | ||||||||||||||||||
| 439 | - | |||||||||||||||||||
| 440 | // add scroller arrows if style needs them | - | ||||||||||||||||||
| 441 | QStyleOptionComboBox opt = comboStyleOption(); | - | ||||||||||||||||||
| 442 | const bool usePopup = combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo); | - | ||||||||||||||||||
| 443 | if (usePopup) {
| 0 | ||||||||||||||||||
| 444 | top = new QComboBoxPrivateScroller(QAbstractSlider::SliderSingleStepSub, this); | - | ||||||||||||||||||
| 445 | bottom = new QComboBoxPrivateScroller(QAbstractSlider::SliderSingleStepAdd, this); | - | ||||||||||||||||||
| 446 | top->hide(); | - | ||||||||||||||||||
| 447 | bottom->hide(); | - | ||||||||||||||||||
| 448 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 449 | setLineWidth(1); | - | ||||||||||||||||||
| 450 | } never executed: end of block | 0 | ||||||||||||||||||
| 451 | - | |||||||||||||||||||
| 452 | setFrameStyle(combo->style()->styleHint(QStyle::SH_ComboBox_PopupFrameStyle, &opt, combo)); | - | ||||||||||||||||||
| 453 | - | |||||||||||||||||||
| 454 | if (top) {
| 0 | ||||||||||||||||||
| 455 | layout->insertWidget(0, top); | - | ||||||||||||||||||
| 456 | connect(top, SIGNAL(doScroll(int)), this, SLOT(scrollItemView(int))); | - | ||||||||||||||||||
| 457 | } never executed: end of block | 0 | ||||||||||||||||||
| 458 | if (bottom) {
| 0 | ||||||||||||||||||
| 459 | layout->addWidget(bottom); | - | ||||||||||||||||||
| 460 | connect(bottom, SIGNAL(doScroll(int)), this, SLOT(scrollItemView(int))); | - | ||||||||||||||||||
| 461 | } never executed: end of block | 0 | ||||||||||||||||||
| 462 | - | |||||||||||||||||||
| 463 | // Some styles (Mac) have a margin at the top and bottom of the popup. | - | ||||||||||||||||||
| 464 | layout->insertSpacing(0, 0); | - | ||||||||||||||||||
| 465 | layout->addSpacing(0); | - | ||||||||||||||||||
| 466 | updateTopBottomMargin(); | - | ||||||||||||||||||
| 467 | } never executed: end of block | 0 | ||||||||||||||||||
| 468 | - | |||||||||||||||||||
| 469 | void QComboBoxPrivateContainer::scrollItemView(int action) | - | ||||||||||||||||||
| 470 | { | - | ||||||||||||||||||
| 471 | #ifndef QT_NO_SCROLLBAR | - | ||||||||||||||||||
| 472 | if (view->verticalScrollBar())
| 0 | ||||||||||||||||||
| 473 | view->verticalScrollBar()->triggerAction(static_cast<QAbstractSlider::SliderAction>(action)); never executed: view->verticalScrollBar()->triggerAction(static_cast<QAbstractSlider::SliderAction>(action)); | 0 | ||||||||||||||||||
| 474 | #endif | - | ||||||||||||||||||
| 475 | } never executed: end of block | 0 | ||||||||||||||||||
| 476 | - | |||||||||||||||||||
| 477 | /* | - | ||||||||||||||||||
| 478 | Hides or shows the scrollers when we emulate a popupmenu | - | ||||||||||||||||||
| 479 | */ | - | ||||||||||||||||||
| 480 | void QComboBoxPrivateContainer::updateScrollers() | - | ||||||||||||||||||
| 481 | { | - | ||||||||||||||||||
| 482 | #ifndef QT_NO_SCROLLBAR | - | ||||||||||||||||||
| 483 | if (!top || !bottom)
| 0 | ||||||||||||||||||
| 484 | return; never executed: return; | 0 | ||||||||||||||||||
| 485 | - | |||||||||||||||||||
| 486 | if (isVisible() == false)
| 0 | ||||||||||||||||||
| 487 | return; never executed: return; | 0 | ||||||||||||||||||
| 488 | - | |||||||||||||||||||
| 489 | QStyleOptionComboBox opt = comboStyleOption(); | - | ||||||||||||||||||
| 490 | if (combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo) &&
| 0 | ||||||||||||||||||
| 491 | view->verticalScrollBar()->minimum() < view->verticalScrollBar()->maximum()) {
| 0 | ||||||||||||||||||
| 492 | - | |||||||||||||||||||
| 493 | bool needTop = view->verticalScrollBar()->value() | - | ||||||||||||||||||
| 494 | > (view->verticalScrollBar()->minimum() + topMargin()); | - | ||||||||||||||||||
| 495 | bool needBottom = view->verticalScrollBar()->value() | - | ||||||||||||||||||
| 496 | < (view->verticalScrollBar()->maximum() - bottomMargin() - topMargin()); | - | ||||||||||||||||||
| 497 | if (needTop)
| 0 | ||||||||||||||||||
| 498 | top->show(); never executed: top->show(); | 0 | ||||||||||||||||||
| 499 | else | - | ||||||||||||||||||
| 500 | top->hide(); never executed: top->hide(); | 0 | ||||||||||||||||||
| 501 | if (needBottom)
| 0 | ||||||||||||||||||
| 502 | bottom->show(); never executed: bottom->show(); | 0 | ||||||||||||||||||
| 503 | else | - | ||||||||||||||||||
| 504 | bottom->hide(); never executed: bottom->hide(); | 0 | ||||||||||||||||||
| 505 | } else { | - | ||||||||||||||||||
| 506 | top->hide(); | - | ||||||||||||||||||
| 507 | bottom->hide(); | - | ||||||||||||||||||
| 508 | } never executed: end of block | 0 | ||||||||||||||||||
| 509 | #endif // QT_NO_SCROLLBAR | - | ||||||||||||||||||
| 510 | } | - | ||||||||||||||||||
| 511 | - | |||||||||||||||||||
| 512 | /* | - | ||||||||||||||||||
| 513 | Cleans up when the view is destroyed. | - | ||||||||||||||||||
| 514 | */ | - | ||||||||||||||||||
| 515 | void QComboBoxPrivateContainer::viewDestroyed() | - | ||||||||||||||||||
| 516 | { | - | ||||||||||||||||||
| 517 | view = 0; | - | ||||||||||||||||||
| 518 | setItemView(new QComboBoxListView()); | - | ||||||||||||||||||
| 519 | } never executed: end of block | 0 | ||||||||||||||||||
| 520 | - | |||||||||||||||||||
| 521 | /* | - | ||||||||||||||||||
| 522 | Returns the item view used for the combobox popup. | - | ||||||||||||||||||
| 523 | */ | - | ||||||||||||||||||
| 524 | QAbstractItemView *QComboBoxPrivateContainer::itemView() const | - | ||||||||||||||||||
| 525 | { | - | ||||||||||||||||||
| 526 | return view; never executed: return view; | 0 | ||||||||||||||||||
| 527 | } | - | ||||||||||||||||||
| 528 | - | |||||||||||||||||||
| 529 | /*! | - | ||||||||||||||||||
| 530 | Sets the item view to be used for the combobox popup. | - | ||||||||||||||||||
| 531 | */ | - | ||||||||||||||||||
| 532 | void QComboBoxPrivateContainer::setItemView(QAbstractItemView *itemView) | - | ||||||||||||||||||
| 533 | { | - | ||||||||||||||||||
| 534 | Q_ASSERT(itemView); | - | ||||||||||||||||||
| 535 | - | |||||||||||||||||||
| 536 | // clean up old one | - | ||||||||||||||||||
| 537 | if (view) {
| 0 | ||||||||||||||||||
| 538 | view->removeEventFilter(this); | - | ||||||||||||||||||
| 539 | view->viewport()->removeEventFilter(this); | - | ||||||||||||||||||
| 540 | #ifndef QT_NO_SCROLLBAR | - | ||||||||||||||||||
| 541 | disconnect(view->verticalScrollBar(), SIGNAL(valueChanged(int)), | - | ||||||||||||||||||
| 542 | this, SLOT(updateScrollers())); | - | ||||||||||||||||||
| 543 | disconnect(view->verticalScrollBar(), SIGNAL(rangeChanged(int,int)), | - | ||||||||||||||||||
| 544 | this, SLOT(updateScrollers())); | - | ||||||||||||||||||
| 545 | #endif | - | ||||||||||||||||||
| 546 | disconnect(view, SIGNAL(destroyed()), | - | ||||||||||||||||||
| 547 | this, SLOT(viewDestroyed())); | - | ||||||||||||||||||
| 548 | - | |||||||||||||||||||
| 549 | if (isAncestorOf(view))
| 0 | ||||||||||||||||||
| 550 | delete view; never executed: delete view; | 0 | ||||||||||||||||||
| 551 | view = 0; | - | ||||||||||||||||||
| 552 | } never executed: end of block | 0 | ||||||||||||||||||
| 553 | - | |||||||||||||||||||
| 554 | // setup the item view | - | ||||||||||||||||||
| 555 | view = itemView; | - | ||||||||||||||||||
| 556 | view->setParent(this); | - | ||||||||||||||||||
| 557 | view->setAttribute(Qt::WA_MacShowFocusRect, false); | - | ||||||||||||||||||
| 558 | qobject_cast<QBoxLayout*>(layout())->insertWidget(top ? 2 : 0, view); | - | ||||||||||||||||||
| 559 | view->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); | - | ||||||||||||||||||
| 560 | view->installEventFilter(this); | - | ||||||||||||||||||
| 561 | view->viewport()->installEventFilter(this); | - | ||||||||||||||||||
| 562 | view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | - | ||||||||||||||||||
| 563 | QStyleOptionComboBox opt = comboStyleOption(); | - | ||||||||||||||||||
| 564 | const bool usePopup = combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo); | - | ||||||||||||||||||
| 565 | #ifndef QT_NO_SCROLLBAR | - | ||||||||||||||||||
| 566 | if (usePopup)
| 0 | ||||||||||||||||||
| 567 | view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); never executed: view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 0 | ||||||||||||||||||
| 568 | #endif | - | ||||||||||||||||||
| 569 | if (combo->style()->styleHint(QStyle::SH_ComboBox_ListMouseTracking, &opt, combo) ||
| 0 | ||||||||||||||||||
| 570 | usePopup) {
| 0 | ||||||||||||||||||
| 571 | view->setMouseTracking(true); | - | ||||||||||||||||||
| 572 | } never executed: end of block | 0 | ||||||||||||||||||
| 573 | view->setSelectionMode(QAbstractItemView::SingleSelection); | - | ||||||||||||||||||
| 574 | view->setFrameStyle(QFrame::NoFrame); | - | ||||||||||||||||||
| 575 | view->setLineWidth(0); | - | ||||||||||||||||||
| 576 | view->setEditTriggers(QAbstractItemView::NoEditTriggers); | - | ||||||||||||||||||
| 577 | #ifndef QT_NO_SCROLLBAR | - | ||||||||||||||||||
| 578 | connect(view->verticalScrollBar(), SIGNAL(valueChanged(int)), | - | ||||||||||||||||||
| 579 | this, SLOT(updateScrollers())); | - | ||||||||||||||||||
| 580 | connect(view->verticalScrollBar(), SIGNAL(rangeChanged(int,int)), | - | ||||||||||||||||||
| 581 | this, SLOT(updateScrollers())); | - | ||||||||||||||||||
| 582 | #endif | - | ||||||||||||||||||
| 583 | connect(view, SIGNAL(destroyed()), | - | ||||||||||||||||||
| 584 | this, SLOT(viewDestroyed())); | - | ||||||||||||||||||
| 585 | } never executed: end of block | 0 | ||||||||||||||||||
| 586 | - | |||||||||||||||||||
| 587 | /*! | - | ||||||||||||||||||
| 588 | Returns the top/bottom vertical margin of the view. | - | ||||||||||||||||||
| 589 | */ | - | ||||||||||||||||||
| 590 | int QComboBoxPrivateContainer::topMargin() const | - | ||||||||||||||||||
| 591 | { | - | ||||||||||||||||||
| 592 | if (const QListView *lview = qobject_cast<const QListView*>(view))
| 0 | ||||||||||||||||||
| 593 | return lview->spacing(); never executed: return lview->spacing(); | 0 | ||||||||||||||||||
| 594 | #ifndef QT_NO_TABLEVIEW | - | ||||||||||||||||||
| 595 | if (const QTableView *tview = qobject_cast<const QTableView*>(view))
| 0 | ||||||||||||||||||
| 596 | return tview->showGrid() ? 1 : 0; never executed: return tview->showGrid() ? 1 : 0;
| 0 | ||||||||||||||||||
| 597 | #endif | - | ||||||||||||||||||
| 598 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 599 | } | - | ||||||||||||||||||
| 600 | - | |||||||||||||||||||
| 601 | /*! | - | ||||||||||||||||||
| 602 | Returns the spacing between the items in the view. | - | ||||||||||||||||||
| 603 | */ | - | ||||||||||||||||||
| 604 | int QComboBoxPrivateContainer::spacing() const | - | ||||||||||||||||||
| 605 | { | - | ||||||||||||||||||
| 606 | QListView *lview = qobject_cast<QListView*>(view); | - | ||||||||||||||||||
| 607 | if (lview)
| 0 | ||||||||||||||||||
| 608 | return 2 * lview->spacing(); // QListView::spacing is the padding around the item. never executed: return 2 * lview->spacing(); | 0 | ||||||||||||||||||
| 609 | #ifndef QT_NO_TABLEVIEW | - | ||||||||||||||||||
| 610 | QTableView *tview = qobject_cast<QTableView*>(view); | - | ||||||||||||||||||
| 611 | if (tview)
| 0 | ||||||||||||||||||
| 612 | return tview->showGrid() ? 1 : 0; never executed: return tview->showGrid() ? 1 : 0;
| 0 | ||||||||||||||||||
| 613 | #endif | - | ||||||||||||||||||
| 614 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 615 | } | - | ||||||||||||||||||
| 616 | - | |||||||||||||||||||
| 617 | void QComboBoxPrivateContainer::updateTopBottomMargin() | - | ||||||||||||||||||
| 618 | { | - | ||||||||||||||||||
| 619 | if (!layout() || layout()->count() < 1)
| 0 | ||||||||||||||||||
| 620 | return; never executed: return; | 0 | ||||||||||||||||||
| 621 | - | |||||||||||||||||||
| 622 | QBoxLayout *boxLayout = qobject_cast<QBoxLayout *>(layout()); | - | ||||||||||||||||||
| 623 | if (!boxLayout)
| 0 | ||||||||||||||||||
| 624 | return; never executed: return; | 0 | ||||||||||||||||||
| 625 | - | |||||||||||||||||||
| 626 | const QStyleOptionComboBox opt = comboStyleOption(); | - | ||||||||||||||||||
| 627 | const bool usePopup = combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo); | - | ||||||||||||||||||
| 628 | const int margin = usePopup ? combo->style()->pixelMetric(QStyle::PM_MenuVMargin, &opt, combo) : 0;
| 0 | ||||||||||||||||||
| 629 | - | |||||||||||||||||||
| 630 | QSpacerItem *topSpacer = boxLayout->itemAt(0)->spacerItem(); | - | ||||||||||||||||||
| 631 | if (topSpacer)
| 0 | ||||||||||||||||||
| 632 | topSpacer->changeSize(0, margin, QSizePolicy::Minimum, QSizePolicy::Fixed); never executed: topSpacer->changeSize(0, margin, QSizePolicy::Minimum, QSizePolicy::Fixed); | 0 | ||||||||||||||||||
| 633 | - | |||||||||||||||||||
| 634 | QSpacerItem *bottomSpacer = boxLayout->itemAt(boxLayout->count() - 1)->spacerItem(); | - | ||||||||||||||||||
| 635 | if (bottomSpacer && bottomSpacer != topSpacer)
| 0 | ||||||||||||||||||
| 636 | bottomSpacer->changeSize(0, margin, QSizePolicy::Minimum, QSizePolicy::Fixed); never executed: bottomSpacer->changeSize(0, margin, QSizePolicy::Minimum, QSizePolicy::Fixed); | 0 | ||||||||||||||||||
| 637 | - | |||||||||||||||||||
| 638 | boxLayout->invalidate(); | - | ||||||||||||||||||
| 639 | } never executed: end of block | 0 | ||||||||||||||||||
| 640 | - | |||||||||||||||||||
| 641 | void QComboBoxPrivateContainer::changeEvent(QEvent *e) | - | ||||||||||||||||||
| 642 | { | - | ||||||||||||||||||
| 643 | if (e->type() == QEvent::StyleChange) {
| 0 | ||||||||||||||||||
| 644 | QStyleOptionComboBox opt = comboStyleOption(); | - | ||||||||||||||||||
| 645 | view->setMouseTracking(combo->style()->styleHint(QStyle::SH_ComboBox_ListMouseTracking, &opt, combo) || | - | ||||||||||||||||||
| 646 | combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo)); | - | ||||||||||||||||||
| 647 | setFrameStyle(combo->style()->styleHint(QStyle::SH_ComboBox_PopupFrameStyle, &opt, combo)); | - | ||||||||||||||||||
| 648 | } never executed: end of block | 0 | ||||||||||||||||||
| 649 | - | |||||||||||||||||||
| 650 | QWidget::changeEvent(e); | - | ||||||||||||||||||
| 651 | } never executed: end of block | 0 | ||||||||||||||||||
| 652 | - | |||||||||||||||||||
| 653 | - | |||||||||||||||||||
| 654 | bool QComboBoxPrivateContainer::eventFilter(QObject *o, QEvent *e) | - | ||||||||||||||||||
| 655 | { | - | ||||||||||||||||||
| 656 | switch (e->type()) { | - | ||||||||||||||||||
| 657 | case QEvent::ShortcutOverride: { never executed: case QEvent::ShortcutOverride: | 0 | ||||||||||||||||||
| 658 | QKeyEvent *keyEvent = static_cast<QKeyEvent*>(e); | - | ||||||||||||||||||
| 659 | switch (keyEvent->key()) { | - | ||||||||||||||||||
| 660 | case Qt::Key_Enter: never executed: case Qt::Key_Enter: | 0 | ||||||||||||||||||
| 661 | case Qt::Key_Return: never executed: case Qt::Key_Return: | 0 | ||||||||||||||||||
| 662 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
| 663 | case Qt::Key_Select: | - | ||||||||||||||||||
| 664 | #endif | - | ||||||||||||||||||
| 665 | if (view->currentIndex().isValid() && (view->currentIndex().flags() & Qt::ItemIsEnabled) ) {
| 0 | ||||||||||||||||||
| 666 | combo->hidePopup(); | - | ||||||||||||||||||
| 667 | emit itemSelected(view->currentIndex()); | - | ||||||||||||||||||
| 668 | } never executed: end of block | 0 | ||||||||||||||||||
| 669 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 670 | case Qt::Key_Down: never executed: case Qt::Key_Down: | 0 | ||||||||||||||||||
| 671 | if (!(keyEvent->modifiers() & Qt::AltModifier))
| 0 | ||||||||||||||||||
| 672 | break; never executed: break; | 0 | ||||||||||||||||||
| 673 | // fall through | - | ||||||||||||||||||
| 674 | case Qt::Key_F4: code before this statement never executed: case Qt::Key_F4:never executed: case Qt::Key_F4: | 0 | ||||||||||||||||||
| 675 | combo->hidePopup(); | - | ||||||||||||||||||
| 676 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 677 | default: never executed: default: | 0 | ||||||||||||||||||
| 678 | if (keyEvent->matches(QKeySequence::Cancel)) {
| 0 | ||||||||||||||||||
| 679 | combo->hidePopup(); | - | ||||||||||||||||||
| 680 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 681 | } | - | ||||||||||||||||||
| 682 | break; never executed: break; | 0 | ||||||||||||||||||
| 683 | } | - | ||||||||||||||||||
| 684 | break; never executed: break; | 0 | ||||||||||||||||||
| 685 | } | - | ||||||||||||||||||
| 686 | case QEvent::MouseMove: never executed: case QEvent::MouseMove: | 0 | ||||||||||||||||||
| 687 | if (isVisible()) {
| 0 | ||||||||||||||||||
| 688 | QMouseEvent *m = static_cast<QMouseEvent *>(e); | - | ||||||||||||||||||
| 689 | QWidget *widget = static_cast<QWidget *>(o); | - | ||||||||||||||||||
| 690 | QPoint vector = widget->mapToGlobal(m->pos()) - initialClickPosition; | - | ||||||||||||||||||
| 691 | if (vector.manhattanLength() > 9 && blockMouseReleaseTimer.isActive())
| 0 | ||||||||||||||||||
| 692 | blockMouseReleaseTimer.stop(); never executed: blockMouseReleaseTimer.stop(); | 0 | ||||||||||||||||||
| 693 | QModelIndex indexUnderMouse = view->indexAt(m->pos()); | - | ||||||||||||||||||
| 694 | if (indexUnderMouse.isValid()
| 0 | ||||||||||||||||||
| 695 | && !QComboBoxDelegate::isSeparator(indexUnderMouse)) {
| 0 | ||||||||||||||||||
| 696 | view->setCurrentIndex(indexUnderMouse); | - | ||||||||||||||||||
| 697 | } never executed: end of block | 0 | ||||||||||||||||||
| 698 | } never executed: end of block | 0 | ||||||||||||||||||
| 699 | break; never executed: break; | 0 | ||||||||||||||||||
| 700 | case QEvent::MouseButtonPress: never executed: case QEvent::MouseButtonPress: | 0 | ||||||||||||||||||
| 701 | maybeIgnoreMouseButtonRelease = false; | - | ||||||||||||||||||
| 702 | break; never executed: break; | 0 | ||||||||||||||||||
| 703 | case QEvent::MouseButtonRelease: { never executed: case QEvent::MouseButtonRelease: | 0 | ||||||||||||||||||
| 704 | bool ignoreEvent = maybeIgnoreMouseButtonRelease && popupTimer.elapsed() < QApplication::doubleClickInterval();
| 0 | ||||||||||||||||||
| 705 | - | |||||||||||||||||||
| 706 | QMouseEvent *m = static_cast<QMouseEvent *>(e); | - | ||||||||||||||||||
| 707 | if (isVisible() && view->rect().contains(m->pos()) && view->currentIndex().isValid()
| 0 | ||||||||||||||||||
| 708 | && !blockMouseReleaseTimer.isActive() && !ignoreEvent
| 0 | ||||||||||||||||||
| 709 | && (view->currentIndex().flags() & Qt::ItemIsEnabled)
| 0 | ||||||||||||||||||
| 710 | && (view->currentIndex().flags() & Qt::ItemIsSelectable)) {
| 0 | ||||||||||||||||||
| 711 | combo->hidePopup(); | - | ||||||||||||||||||
| 712 | emit itemSelected(view->currentIndex()); | - | ||||||||||||||||||
| 713 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 714 | } | - | ||||||||||||||||||
| 715 | break; never executed: break; | 0 | ||||||||||||||||||
| 716 | } | - | ||||||||||||||||||
| 717 | default: never executed: default: | 0 | ||||||||||||||||||
| 718 | break; never executed: break; | 0 | ||||||||||||||||||
| 719 | } | - | ||||||||||||||||||
| 720 | return QFrame::eventFilter(o, e); never executed: return QFrame::eventFilter(o, e); | 0 | ||||||||||||||||||
| 721 | } | - | ||||||||||||||||||
| 722 | - | |||||||||||||||||||
| 723 | void QComboBoxPrivateContainer::showEvent(QShowEvent *) | - | ||||||||||||||||||
| 724 | { | - | ||||||||||||||||||
| 725 | combo->update(); | - | ||||||||||||||||||
| 726 | } never executed: end of block | 0 | ||||||||||||||||||
| 727 | - | |||||||||||||||||||
| 728 | void QComboBoxPrivateContainer::hideEvent(QHideEvent *) | - | ||||||||||||||||||
| 729 | { | - | ||||||||||||||||||
| 730 | emit resetButton(); | - | ||||||||||||||||||
| 731 | combo->update(); | - | ||||||||||||||||||
| 732 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||
| 733 | // QGraphicsScenePrivate::removePopup closes the combo box popup, it hides it non-explicitly. | - | ||||||||||||||||||
| 734 | // Hiding/showing the QComboBox after this will unexpectedly show the popup as well. | - | ||||||||||||||||||
| 735 | // Re-hiding the popup container makes sure it is explicitly hidden. | - | ||||||||||||||||||
| 736 | if (QGraphicsProxyWidget *proxy = graphicsProxyWidget())
| 0 | ||||||||||||||||||
| 737 | proxy->hide(); never executed: proxy->hide(); | 0 | ||||||||||||||||||
| 738 | #endif | - | ||||||||||||||||||
| 739 | } never executed: end of block | 0 | ||||||||||||||||||
| 740 | - | |||||||||||||||||||
| 741 | void QComboBoxPrivateContainer::mousePressEvent(QMouseEvent *e) | - | ||||||||||||||||||
| 742 | { | - | ||||||||||||||||||
| 743 | - | |||||||||||||||||||
| 744 | QStyleOptionComboBox opt = comboStyleOption(); | - | ||||||||||||||||||
| 745 | opt.subControls = QStyle::SC_All; | - | ||||||||||||||||||
| 746 | opt.activeSubControls = QStyle::SC_ComboBoxArrow; | - | ||||||||||||||||||
| 747 | QStyle::SubControl sc = combo->style()->hitTestComplexControl(QStyle::CC_ComboBox, &opt, | - | ||||||||||||||||||
| 748 | combo->mapFromGlobal(e->globalPos()), | - | ||||||||||||||||||
| 749 | combo); | - | ||||||||||||||||||
| 750 | if ((combo->isEditable() && sc == QStyle::SC_ComboBoxArrow)
| 0 | ||||||||||||||||||
| 751 | || (!combo->isEditable() && sc != QStyle::SC_None))
| 0 | ||||||||||||||||||
| 752 | setAttribute(Qt::WA_NoMouseReplay); never executed: setAttribute(Qt::WA_NoMouseReplay); | 0 | ||||||||||||||||||
| 753 | combo->hidePopup(); | - | ||||||||||||||||||
| 754 | } never executed: end of block | 0 | ||||||||||||||||||
| 755 | - | |||||||||||||||||||
| 756 | void QComboBoxPrivateContainer::mouseReleaseEvent(QMouseEvent *e) | - | ||||||||||||||||||
| 757 | { | - | ||||||||||||||||||
| 758 | Q_UNUSED(e); | - | ||||||||||||||||||
| 759 | if (!blockMouseReleaseTimer.isActive()){
| 0 | ||||||||||||||||||
| 760 | combo->hidePopup(); | - | ||||||||||||||||||
| 761 | emit resetButton(); | - | ||||||||||||||||||
| 762 | } never executed: end of block | 0 | ||||||||||||||||||
| 763 | } never executed: end of block | 0 | ||||||||||||||||||
| 764 | - | |||||||||||||||||||
| 765 | QStyleOptionComboBox QComboBoxPrivateContainer::comboStyleOption() const | - | ||||||||||||||||||
| 766 | { | - | ||||||||||||||||||
| 767 | // ### This should use QComboBox's initStyleOption(), but it's protected | - | ||||||||||||||||||
| 768 | // perhaps, we could cheat by having the QCombo private instead? | - | ||||||||||||||||||
| 769 | QStyleOptionComboBox opt; | - | ||||||||||||||||||
| 770 | opt.initFrom(combo); | - | ||||||||||||||||||
| 771 | opt.subControls = QStyle::SC_All; | - | ||||||||||||||||||
| 772 | opt.activeSubControls = QStyle::SC_None; | - | ||||||||||||||||||
| 773 | opt.editable = combo->isEditable(); | - | ||||||||||||||||||
| 774 | return opt; never executed: return opt; | 0 | ||||||||||||||||||
| 775 | } | - | ||||||||||||||||||
| 776 | - | |||||||||||||||||||
| 777 | /*! | - | ||||||||||||||||||
| 778 | \enum QComboBox::InsertPolicy | - | ||||||||||||||||||
| 779 | - | |||||||||||||||||||
| 780 | This enum specifies what the QComboBox should do when a new string is | - | ||||||||||||||||||
| 781 | entered by the user. | - | ||||||||||||||||||
| 782 | - | |||||||||||||||||||
| 783 | \value NoInsert The string will not be inserted into the combobox. | - | ||||||||||||||||||
| 784 | \value InsertAtTop The string will be inserted as the first item in the combobox. | - | ||||||||||||||||||
| 785 | \value InsertAtCurrent The current item will be \e replaced by the string. | - | ||||||||||||||||||
| 786 | \value InsertAtBottom The string will be inserted after the last item in the combobox. | - | ||||||||||||||||||
| 787 | \value InsertAfterCurrent The string is inserted after the current item in the combobox. | - | ||||||||||||||||||
| 788 | \value InsertBeforeCurrent The string is inserted before the current item in the combobox. | - | ||||||||||||||||||
| 789 | \value InsertAlphabetically The string is inserted in the alphabetic order in the combobox. | - | ||||||||||||||||||
| 790 | */ | - | ||||||||||||||||||
| 791 | - | |||||||||||||||||||
| 792 | /*! | - | ||||||||||||||||||
| 793 | \enum QComboBox::SizeAdjustPolicy | - | ||||||||||||||||||
| 794 | - | |||||||||||||||||||
| 795 | This enum specifies how the size hint of the QComboBox should | - | ||||||||||||||||||
| 796 | adjust when new content is added or content changes. | - | ||||||||||||||||||
| 797 | - | |||||||||||||||||||
| 798 | \value AdjustToContents The combobox will always adjust to the contents | - | ||||||||||||||||||
| 799 | \value AdjustToContentsOnFirstShow The combobox will adjust to its contents the first time it is shown. | - | ||||||||||||||||||
| 800 | \value AdjustToMinimumContentsLength Use AdjustToContents or AdjustToContentsOnFirstShow instead. | - | ||||||||||||||||||
| 801 | \value AdjustToMinimumContentsLengthWithIcon The combobox will adjust to \l minimumContentsLength plus space for an icon. For performance reasons use this policy on large models. | - | ||||||||||||||||||
| 802 | */ | - | ||||||||||||||||||
| 803 | - | |||||||||||||||||||
| 804 | /*! | - | ||||||||||||||||||
| 805 | \fn void QComboBox::activated(int index) | - | ||||||||||||||||||
| 806 | - | |||||||||||||||||||
| 807 | This signal is sent when the user chooses an item in the combobox. | - | ||||||||||||||||||
| 808 | The item's \a index is passed. Note that this signal is sent even | - | ||||||||||||||||||
| 809 | when the choice is not changed. If you need to know when the | - | ||||||||||||||||||
| 810 | choice actually changes, use signal currentIndexChanged(). | - | ||||||||||||||||||
| 811 | - | |||||||||||||||||||
| 812 | */ | - | ||||||||||||||||||
| 813 | - | |||||||||||||||||||
| 814 | /*! | - | ||||||||||||||||||
| 815 | \fn void QComboBox::activated(const QString &text) | - | ||||||||||||||||||
| 816 | - | |||||||||||||||||||
| 817 | This signal is sent when the user chooses an item in the combobox. | - | ||||||||||||||||||
| 818 | The item's \a text is passed. Note that this signal is sent even | - | ||||||||||||||||||
| 819 | when the choice is not changed. If you need to know when the | - | ||||||||||||||||||
| 820 | choice actually changes, use signal currentIndexChanged(). | - | ||||||||||||||||||
| 821 | - | |||||||||||||||||||
| 822 | */ | - | ||||||||||||||||||
| 823 | - | |||||||||||||||||||
| 824 | /*! | - | ||||||||||||||||||
| 825 | \fn void QComboBox::highlighted(int index) | - | ||||||||||||||||||
| 826 | - | |||||||||||||||||||
| 827 | This signal is sent when an item in the combobox popup list is | - | ||||||||||||||||||
| 828 | highlighted by the user. The item's \a index is passed. | - | ||||||||||||||||||
| 829 | */ | - | ||||||||||||||||||
| 830 | - | |||||||||||||||||||
| 831 | /*! | - | ||||||||||||||||||
| 832 | \fn void QComboBox::highlighted(const QString &text) | - | ||||||||||||||||||
| 833 | - | |||||||||||||||||||
| 834 | This signal is sent when an item in the combobox popup list is | - | ||||||||||||||||||
| 835 | highlighted by the user. The item's \a text is passed. | - | ||||||||||||||||||
| 836 | */ | - | ||||||||||||||||||
| 837 | - | |||||||||||||||||||
| 838 | /*! | - | ||||||||||||||||||
| 839 | \fn void QComboBox::currentIndexChanged(int index) | - | ||||||||||||||||||
| 840 | \since 4.1 | - | ||||||||||||||||||
| 841 | - | |||||||||||||||||||
| 842 | This signal is sent whenever the currentIndex in the combobox | - | ||||||||||||||||||
| 843 | changes either through user interaction or programmatically. The | - | ||||||||||||||||||
| 844 | item's \a index is passed or -1 if the combobox becomes empty or the | - | ||||||||||||||||||
| 845 | currentIndex was reset. | - | ||||||||||||||||||
| 846 | */ | - | ||||||||||||||||||
| 847 | - | |||||||||||||||||||
| 848 | /*! | - | ||||||||||||||||||
| 849 | \fn void QComboBox::currentIndexChanged(const QString &text) | - | ||||||||||||||||||
| 850 | \since 4.1 | - | ||||||||||||||||||
| 851 | - | |||||||||||||||||||
| 852 | This signal is sent whenever the currentIndex in the combobox | - | ||||||||||||||||||
| 853 | changes either through user interaction or programmatically. The | - | ||||||||||||||||||
| 854 | item's \a text is passed. | - | ||||||||||||||||||
| 855 | */ | - | ||||||||||||||||||
| 856 | - | |||||||||||||||||||
| 857 | /*! | - | ||||||||||||||||||
| 858 | \fn void QComboBox::currentTextChanged(const QString &text) | - | ||||||||||||||||||
| 859 | \since 5.0 | - | ||||||||||||||||||
| 860 | - | |||||||||||||||||||
| 861 | This signal is sent whenever currentText changes. The new value | - | ||||||||||||||||||
| 862 | is passed as \a text. | - | ||||||||||||||||||
| 863 | */ | - | ||||||||||||||||||
| 864 | - | |||||||||||||||||||
| 865 | /*! | - | ||||||||||||||||||
| 866 | Constructs a combobox with the given \a parent, using the default | - | ||||||||||||||||||
| 867 | model QStandardItemModel. | - | ||||||||||||||||||
| 868 | */ | - | ||||||||||||||||||
| 869 | QComboBox::QComboBox(QWidget *parent) | - | ||||||||||||||||||
| 870 | : QWidget(*new QComboBoxPrivate(), parent, 0) | - | ||||||||||||||||||
| 871 | { | - | ||||||||||||||||||
| 872 | Q_D(QComboBox); | - | ||||||||||||||||||
| 873 | d->init(); | - | ||||||||||||||||||
| 874 | } never executed: end of block | 0 | ||||||||||||||||||
| 875 | - | |||||||||||||||||||
| 876 | /*! | - | ||||||||||||||||||
| 877 | \internal | - | ||||||||||||||||||
| 878 | */ | - | ||||||||||||||||||
| 879 | QComboBox::QComboBox(QComboBoxPrivate &dd, QWidget *parent) | - | ||||||||||||||||||
| 880 | : QWidget(dd, parent, 0) | - | ||||||||||||||||||
| 881 | { | - | ||||||||||||||||||
| 882 | Q_D(QComboBox); | - | ||||||||||||||||||
| 883 | d->init(); | - | ||||||||||||||||||
| 884 | } never executed: end of block | 0 | ||||||||||||||||||
| 885 | - | |||||||||||||||||||
| 886 | - | |||||||||||||||||||
| 887 | /*! | - | ||||||||||||||||||
| 888 | \class QComboBox | - | ||||||||||||||||||
| 889 | \brief The QComboBox widget is a combined button and popup list. | - | ||||||||||||||||||
| 890 | - | |||||||||||||||||||
| 891 | \ingroup basicwidgets | - | ||||||||||||||||||
| 892 | \inmodule QtWidgets | - | ||||||||||||||||||
| 893 | - | |||||||||||||||||||
| 894 | A QComboBox provides a means of presenting a list of options to the user | - | ||||||||||||||||||
| 895 | in a way that takes up the minimum amount of screen space. | - | ||||||||||||||||||
| 896 | - | |||||||||||||||||||
| 897 | A combobox is a selection widget that displays the current item, | - | ||||||||||||||||||
| 898 | and can pop up a list of selectable items. A combobox may be editable, | - | ||||||||||||||||||
| 899 | allowing the user to modify each item in the list. | - | ||||||||||||||||||
| 900 | - | |||||||||||||||||||
| 901 | Comboboxes can contain pixmaps as well as strings; the | - | ||||||||||||||||||
| 902 | insertItem() and setItemText() functions are suitably overloaded. | - | ||||||||||||||||||
| 903 | For editable comboboxes, the function clearEditText() is provided, | - | ||||||||||||||||||
| 904 | to clear the displayed string without changing the combobox's | - | ||||||||||||||||||
| 905 | contents. | - | ||||||||||||||||||
| 906 | - | |||||||||||||||||||
| 907 | There are two signals emitted if the current item of a combobox | - | ||||||||||||||||||
| 908 | changes, currentIndexChanged() and activated(). | - | ||||||||||||||||||
| 909 | currentIndexChanged() is always emitted regardless if the change | - | ||||||||||||||||||
| 910 | was done programmatically or by user interaction, while | - | ||||||||||||||||||
| 911 | activated() is only emitted when the change is caused by user | - | ||||||||||||||||||
| 912 | interaction. The highlighted() signal is emitted when the user | - | ||||||||||||||||||
| 913 | highlights an item in the combobox popup list. All three signals | - | ||||||||||||||||||
| 914 | exist in two versions, one with a QString argument and one with an | - | ||||||||||||||||||
| 915 | \c int argument. If the user selects or highlights a pixmap, only | - | ||||||||||||||||||
| 916 | the \c int signals are emitted. Whenever the text of an editable | - | ||||||||||||||||||
| 917 | combobox is changed the editTextChanged() signal is emitted. | - | ||||||||||||||||||
| 918 | - | |||||||||||||||||||
| 919 | When the user enters a new string in an editable combobox, the | - | ||||||||||||||||||
| 920 | widget may or may not insert it, and it can insert it in several | - | ||||||||||||||||||
| 921 | locations. The default policy is \l InsertAtBottom but you can change | - | ||||||||||||||||||
| 922 | this using setInsertPolicy(). | - | ||||||||||||||||||
| 923 | - | |||||||||||||||||||
| 924 | It is possible to constrain the input to an editable combobox | - | ||||||||||||||||||
| 925 | using QValidator; see setValidator(). By default, any input is | - | ||||||||||||||||||
| 926 | accepted. | - | ||||||||||||||||||
| 927 | - | |||||||||||||||||||
| 928 | A combobox can be populated using the insert functions, | - | ||||||||||||||||||
| 929 | insertItem() and insertItems() for example. Items can be | - | ||||||||||||||||||
| 930 | changed with setItemText(). An item can be removed with | - | ||||||||||||||||||
| 931 | removeItem() and all items can be removed with clear(). The text | - | ||||||||||||||||||
| 932 | of the current item is returned by currentText(), and the text of | - | ||||||||||||||||||
| 933 | a numbered item is returned with text(). The current item can be | - | ||||||||||||||||||
| 934 | set with setCurrentIndex(). The number of items in the combobox is | - | ||||||||||||||||||
| 935 | returned by count(); the maximum number of items can be set with | - | ||||||||||||||||||
| 936 | setMaxCount(). You can allow editing using setEditable(). For | - | ||||||||||||||||||
| 937 | editable comboboxes you can set auto-completion using | - | ||||||||||||||||||
| 938 | setCompleter() and whether or not the user can add duplicates | - | ||||||||||||||||||
| 939 | is set with setDuplicatesEnabled(). | - | ||||||||||||||||||
| 940 | - | |||||||||||||||||||
| 941 | QComboBox uses the \l{Model/View Programming}{model/view | - | ||||||||||||||||||
| 942 | framework} for its popup list and to store its items. By default | - | ||||||||||||||||||
| 943 | a QStandardItemModel stores the items and a QListView subclass | - | ||||||||||||||||||
| 944 | displays the popuplist. You can access the model and view directly | - | ||||||||||||||||||
| 945 | (with model() and view()), but QComboBox also provides functions | - | ||||||||||||||||||
| 946 | to set and get item data (e.g., setItemData() and itemText()). You | - | ||||||||||||||||||
| 947 | can also set a new model and view (with setModel() and setView()). | - | ||||||||||||||||||
| 948 | For the text and icon in the combobox label, the data in the model | - | ||||||||||||||||||
| 949 | that has the Qt::DisplayRole and Qt::DecorationRole is used. Note | - | ||||||||||||||||||
| 950 | that you cannot alter the \l{QAbstractItemView::}{SelectionMode} | - | ||||||||||||||||||
| 951 | of the view(), e.g., by using | - | ||||||||||||||||||
| 952 | \l{QAbstractItemView::}{setSelectionMode()}. | - | ||||||||||||||||||
| 953 | - | |||||||||||||||||||
| 954 | \image qstyle-comboboxes.png Comboboxes in the different built-in styles. | - | ||||||||||||||||||
| 955 | - | |||||||||||||||||||
| 956 | \sa QLineEdit, QSpinBox, QRadioButton, QButtonGroup, | - | ||||||||||||||||||
| 957 | {fowler}{GUI Design Handbook: Combo Box, Drop-Down List Box} | - | ||||||||||||||||||
| 958 | */ | - | ||||||||||||||||||
| 959 | - | |||||||||||||||||||
| 960 | void QComboBoxPrivate::init() | - | ||||||||||||||||||
| 961 | { | - | ||||||||||||||||||
| 962 | Q_Q(QComboBox); | - | ||||||||||||||||||
| 963 | #ifdef Q_OS_OSX | - | ||||||||||||||||||
| 964 | // On OS X, only line edits and list views always get tab focus. It's only | - | ||||||||||||||||||
| 965 | // when we enable full keyboard access that other controls can get tab focus. | - | ||||||||||||||||||
| 966 | // When it's not editable, a combobox looks like a button, and it behaves as | - | ||||||||||||||||||
| 967 | // such in this respect. | - | ||||||||||||||||||
| 968 | if (!q->isEditable()) | - | ||||||||||||||||||
| 969 | q->setFocusPolicy(Qt::TabFocus); | - | ||||||||||||||||||
| 970 | else | - | ||||||||||||||||||
| 971 | #endif | - | ||||||||||||||||||
| 972 | q->setFocusPolicy(Qt::WheelFocus); | - | ||||||||||||||||||
| 973 | - | |||||||||||||||||||
| 974 | q->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed, | - | ||||||||||||||||||
| 975 | QSizePolicy::ComboBox)); | - | ||||||||||||||||||
| 976 | setLayoutItemMargins(QStyle::SE_ComboBoxLayoutItem); | - | ||||||||||||||||||
| 977 | q->setModel(new QStandardItemModel(0, 1, q)); | - | ||||||||||||||||||
| 978 | if (!q->isEditable())
| 0 | ||||||||||||||||||
| 979 | q->setAttribute(Qt::WA_InputMethodEnabled, false); never executed: q->setAttribute(Qt::WA_InputMethodEnabled, false); | 0 | ||||||||||||||||||
| 980 | else | - | ||||||||||||||||||
| 981 | q->setAttribute(Qt::WA_InputMethodEnabled); never executed: q->setAttribute(Qt::WA_InputMethodEnabled); | 0 | ||||||||||||||||||
| 982 | } | - | ||||||||||||||||||
| 983 | - | |||||||||||||||||||
| 984 | QComboBoxPrivateContainer* QComboBoxPrivate::viewContainer() | - | ||||||||||||||||||
| 985 | { | - | ||||||||||||||||||
| 986 | if (container)
| 0 | ||||||||||||||||||
| 987 | return container; never executed: return container; | 0 | ||||||||||||||||||
| 988 | - | |||||||||||||||||||
| 989 | Q_Q(QComboBox); | - | ||||||||||||||||||
| 990 | container = new QComboBoxPrivateContainer(new QComboBoxListView(q), q); | - | ||||||||||||||||||
| 991 | container->itemView()->setModel(model); | - | ||||||||||||||||||
| 992 | container->itemView()->setTextElideMode(Qt::ElideMiddle); | - | ||||||||||||||||||
| 993 | updateDelegate(true); | - | ||||||||||||||||||
| 994 | updateLayoutDirection(); | - | ||||||||||||||||||
| 995 | updateViewContainerPaletteAndOpacity(); | - | ||||||||||||||||||
| 996 | QObject::connect(container, SIGNAL(itemSelected(QModelIndex)), | - | ||||||||||||||||||
| 997 | q, SLOT(_q_itemSelected(QModelIndex))); | - | ||||||||||||||||||
| 998 | QObject::connect(container->itemView()->selectionModel(), | - | ||||||||||||||||||
| 999 | SIGNAL(currentChanged(QModelIndex,QModelIndex)), | - | ||||||||||||||||||
| 1000 | q, SLOT(_q_emitHighlighted(QModelIndex))); | - | ||||||||||||||||||
| 1001 | QObject::connect(container, SIGNAL(resetButton()), q, SLOT(_q_resetButton())); | - | ||||||||||||||||||
| 1002 | return container; never executed: return container; | 0 | ||||||||||||||||||
| 1003 | } | - | ||||||||||||||||||
| 1004 | - | |||||||||||||||||||
| 1005 | - | |||||||||||||||||||
| 1006 | void QComboBoxPrivate::_q_resetButton() | - | ||||||||||||||||||
| 1007 | { | - | ||||||||||||||||||
| 1008 | updateArrow(QStyle::State_None); | - | ||||||||||||||||||
| 1009 | } never executed: end of block | 0 | ||||||||||||||||||
| 1010 | - | |||||||||||||||||||
| 1011 | void QComboBoxPrivate::_q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) | - | ||||||||||||||||||
| 1012 | { | - | ||||||||||||||||||
| 1013 | Q_Q(QComboBox); | - | ||||||||||||||||||
| 1014 | if (inserting || topLeft.parent() != root)
| 0 | ||||||||||||||||||
| 1015 | return; never executed: return; | 0 | ||||||||||||||||||
| 1016 | - | |||||||||||||||||||
| 1017 | if (sizeAdjustPolicy == QComboBox::AdjustToContents) {
| 0 | ||||||||||||||||||
| 1018 | sizeHint = QSize(); | - | ||||||||||||||||||
| 1019 | adjustComboBoxSize(); | - | ||||||||||||||||||
| 1020 | q->updateGeometry(); | - | ||||||||||||||||||
| 1021 | } never executed: end of block | 0 | ||||||||||||||||||
| 1022 | - | |||||||||||||||||||
| 1023 | if (currentIndex.row() >= topLeft.row() && currentIndex.row() <= bottomRight.row()) {
| 0 | ||||||||||||||||||
| 1024 | const QString text = q->itemText(currentIndex.row()); | - | ||||||||||||||||||
| 1025 | if (lineEdit) {
| 0 | ||||||||||||||||||
| 1026 | lineEdit->setText(text); | - | ||||||||||||||||||
| 1027 | updateLineEditGeometry(); | - | ||||||||||||||||||
| 1028 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1029 | emit q->currentTextChanged(text); | - | ||||||||||||||||||
| 1030 | } never executed: end of block | 0 | ||||||||||||||||||
| 1031 | q->update(); | - | ||||||||||||||||||
| 1032 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||
| 1033 | QAccessibleValueChangeEvent event(q, text); | - | ||||||||||||||||||
| 1034 | QAccessible::updateAccessibility(&event); | - | ||||||||||||||||||
| 1035 | #endif | - | ||||||||||||||||||
| 1036 | } never executed: end of block | 0 | ||||||||||||||||||
| 1037 | } never executed: end of block | 0 | ||||||||||||||||||
| 1038 | - | |||||||||||||||||||
| 1039 | void QComboBoxPrivate::_q_rowsInserted(const QModelIndex &parent, int start, int end) | - | ||||||||||||||||||
| 1040 | { | - | ||||||||||||||||||
| 1041 | Q_Q(QComboBox); | - | ||||||||||||||||||
| 1042 | if (inserting || parent != root)
| 0 | ||||||||||||||||||
| 1043 | return; never executed: return; | 0 | ||||||||||||||||||
| 1044 | - | |||||||||||||||||||
| 1045 | if (sizeAdjustPolicy == QComboBox::AdjustToContents) {
| 0 | ||||||||||||||||||
| 1046 | sizeHint = QSize(); | - | ||||||||||||||||||
| 1047 | adjustComboBoxSize(); | - | ||||||||||||||||||
| 1048 | q->updateGeometry(); | - | ||||||||||||||||||
| 1049 | } never executed: end of block | 0 | ||||||||||||||||||
| 1050 | - | |||||||||||||||||||
| 1051 | // set current index if combo was previously empty | - | ||||||||||||||||||
| 1052 | if (start == 0 && (end - start + 1) == q->count() && !currentIndex.isValid()) {
| 0 | ||||||||||||||||||
| 1053 | q->setCurrentIndex(0); | - | ||||||||||||||||||
| 1054 | // need to emit changed if model updated index "silently" | - | ||||||||||||||||||
| 1055 | } else if (currentIndex.row() != indexBeforeChange) { never executed: end of block
| 0 | ||||||||||||||||||
| 1056 | q->update(); | - | ||||||||||||||||||
| 1057 | _q_emitCurrentIndexChanged(currentIndex); | - | ||||||||||||||||||
| 1058 | } never executed: end of block | 0 | ||||||||||||||||||
| 1059 | } never executed: end of block | 0 | ||||||||||||||||||
| 1060 | - | |||||||||||||||||||
| 1061 | void QComboBoxPrivate::_q_updateIndexBeforeChange() | - | ||||||||||||||||||
| 1062 | { | - | ||||||||||||||||||
| 1063 | indexBeforeChange = currentIndex.row(); | - | ||||||||||||||||||
| 1064 | } never executed: end of block | 0 | ||||||||||||||||||
| 1065 | - | |||||||||||||||||||
| 1066 | void QComboBoxPrivate::_q_rowsRemoved(const QModelIndex &parent, int /*start*/, int /*end*/) | - | ||||||||||||||||||
| 1067 | { | - | ||||||||||||||||||
| 1068 | Q_Q(QComboBox); | - | ||||||||||||||||||
| 1069 | if (parent != root)
| 0 | ||||||||||||||||||
| 1070 | return; never executed: return; | 0 | ||||||||||||||||||
| 1071 | - | |||||||||||||||||||
| 1072 | if (sizeAdjustPolicy == QComboBox::AdjustToContents) {
| 0 | ||||||||||||||||||
| 1073 | sizeHint = QSize(); | - | ||||||||||||||||||
| 1074 | adjustComboBoxSize(); | - | ||||||||||||||||||
| 1075 | q->updateGeometry(); | - | ||||||||||||||||||
| 1076 | } never executed: end of block | 0 | ||||||||||||||||||
| 1077 | - | |||||||||||||||||||
| 1078 | // model has changed the currentIndex | - | ||||||||||||||||||
| 1079 | if (currentIndex.row() != indexBeforeChange) {
| 0 | ||||||||||||||||||
| 1080 | if (!currentIndex.isValid() && q->count()) {
| 0 | ||||||||||||||||||
| 1081 | q->setCurrentIndex(qMin(q->count() - 1, qMax(indexBeforeChange, 0))); | - | ||||||||||||||||||
| 1082 | return; never executed: return; | 0 | ||||||||||||||||||
| 1083 | } | - | ||||||||||||||||||
| 1084 | if (lineEdit) {
| 0 | ||||||||||||||||||
| 1085 | lineEdit->setText(q->itemText(currentIndex.row())); | - | ||||||||||||||||||
| 1086 | updateLineEditGeometry(); | - | ||||||||||||||||||
| 1087 | } never executed: end of block | 0 | ||||||||||||||||||
| 1088 | q->update(); | - | ||||||||||||||||||
| 1089 | _q_emitCurrentIndexChanged(currentIndex); | - | ||||||||||||||||||
| 1090 | } never executed: end of block | 0 | ||||||||||||||||||
| 1091 | } never executed: end of block | 0 | ||||||||||||||||||
| 1092 | - | |||||||||||||||||||
| 1093 | - | |||||||||||||||||||
| 1094 | void QComboBoxPrivate::updateViewContainerPaletteAndOpacity() | - | ||||||||||||||||||
| 1095 | { | - | ||||||||||||||||||
| 1096 | if (!container)
| 0 | ||||||||||||||||||
| 1097 | return; never executed: return; | 0 | ||||||||||||||||||
| 1098 | Q_Q(QComboBox); | - | ||||||||||||||||||
| 1099 | QStyleOptionComboBox opt; | - | ||||||||||||||||||
| 1100 | q->initStyleOption(&opt); | - | ||||||||||||||||||
| 1101 | #ifndef QT_NO_MENU | - | ||||||||||||||||||
| 1102 | if (q->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, q)) {
| 0 | ||||||||||||||||||
| 1103 | QMenu menu; | - | ||||||||||||||||||
| 1104 | menu.ensurePolished(); | - | ||||||||||||||||||
| 1105 | container->setPalette(menu.palette()); | - | ||||||||||||||||||
| 1106 | container->setWindowOpacity(menu.windowOpacity()); | - | ||||||||||||||||||
| 1107 | } else never executed: end of block | 0 | ||||||||||||||||||
| 1108 | #endif | - | ||||||||||||||||||
| 1109 | { | - | ||||||||||||||||||
| 1110 | container->setPalette(q->palette()); | - | ||||||||||||||||||
| 1111 | container->setWindowOpacity(1.0); | - | ||||||||||||||||||
| 1112 | } never executed: end of block | 0 | ||||||||||||||||||
| 1113 | if (lineEdit)
| 0 | ||||||||||||||||||
| 1114 | lineEdit->setPalette(q->palette()); never executed: lineEdit->setPalette(q->palette()); | 0 | ||||||||||||||||||
| 1115 | } never executed: end of block | 0 | ||||||||||||||||||
| 1116 | - | |||||||||||||||||||
| 1117 | void QComboBoxPrivate::updateFocusPolicy() | - | ||||||||||||||||||
| 1118 | { | - | ||||||||||||||||||
| 1119 | #ifdef Q_OS_OSX | - | ||||||||||||||||||
| 1120 | Q_Q(QComboBox); | - | ||||||||||||||||||
| 1121 | - | |||||||||||||||||||
| 1122 | // See comment in QComboBoxPrivate::init() | - | ||||||||||||||||||
| 1123 | if (q->isEditable()) | - | ||||||||||||||||||
| 1124 | q->setFocusPolicy(Qt::WheelFocus); | - | ||||||||||||||||||
| 1125 | else | - | ||||||||||||||||||
| 1126 | q->setFocusPolicy(Qt::TabFocus); | - | ||||||||||||||||||
| 1127 | #endif | - | ||||||||||||||||||
| 1128 | } | - | ||||||||||||||||||
| 1129 | - | |||||||||||||||||||
| 1130 | /*! | - | ||||||||||||||||||
| 1131 | Initialize \a option with the values from this QComboBox. This method | - | ||||||||||||||||||
| 1132 | is useful for subclasses when they need a QStyleOptionComboBox, but don't want | - | ||||||||||||||||||
| 1133 | to fill in all the information themselves. | - | ||||||||||||||||||
| 1134 | - | |||||||||||||||||||
| 1135 | \sa QStyleOption::initFrom() | - | ||||||||||||||||||
| 1136 | */ | - | ||||||||||||||||||
| 1137 | void QComboBox::initStyleOption(QStyleOptionComboBox *option) const | - | ||||||||||||||||||
| 1138 | { | - | ||||||||||||||||||
| 1139 | if (!option)
| 0 | ||||||||||||||||||
| 1140 | return; never executed: return; | 0 | ||||||||||||||||||
| 1141 | - | |||||||||||||||||||
| 1142 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 1143 | option->initFrom(this); | - | ||||||||||||||||||
| 1144 | option->editable = isEditable(); | - | ||||||||||||||||||
| 1145 | option->frame = d->frame; | - | ||||||||||||||||||
| 1146 | if (hasFocus() && !option->editable)
| 0 | ||||||||||||||||||
| 1147 | option->state |= QStyle::State_Selected; never executed: option->state |= QStyle::State_Selected; | 0 | ||||||||||||||||||
| 1148 | option->subControls = QStyle::SC_All; | - | ||||||||||||||||||
| 1149 | if (d->arrowState == QStyle::State_Sunken) {
| 0 | ||||||||||||||||||
| 1150 | option->activeSubControls = QStyle::SC_ComboBoxArrow; | - | ||||||||||||||||||
| 1151 | option->state |= d->arrowState; | - | ||||||||||||||||||
| 1152 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1153 | option->activeSubControls = d->hoverControl; | - | ||||||||||||||||||
| 1154 | } never executed: end of block | 0 | ||||||||||||||||||
| 1155 | if (d->currentIndex.isValid()) {
| 0 | ||||||||||||||||||
| 1156 | option->currentText = currentText(); | - | ||||||||||||||||||
| 1157 | option->currentIcon = d->itemIcon(d->currentIndex); | - | ||||||||||||||||||
| 1158 | } never executed: end of block | 0 | ||||||||||||||||||
| 1159 | option->iconSize = iconSize(); | - | ||||||||||||||||||
| 1160 | if (d->container && d->container->isVisible())
| 0 | ||||||||||||||||||
| 1161 | option->state |= QStyle::State_On; never executed: option->state |= QStyle::State_On; | 0 | ||||||||||||||||||
| 1162 | } never executed: end of block | 0 | ||||||||||||||||||
| 1163 | - | |||||||||||||||||||
| 1164 | void QComboBoxPrivate::updateLineEditGeometry() | - | ||||||||||||||||||
| 1165 | { | - | ||||||||||||||||||
| 1166 | if (!lineEdit)
| 0 | ||||||||||||||||||
| 1167 | return; never executed: return; | 0 | ||||||||||||||||||
| 1168 | - | |||||||||||||||||||
| 1169 | Q_Q(QComboBox); | - | ||||||||||||||||||
| 1170 | QStyleOptionComboBox opt; | - | ||||||||||||||||||
| 1171 | q->initStyleOption(&opt); | - | ||||||||||||||||||
| 1172 | QRect editRect = q->style()->subControlRect(QStyle::CC_ComboBox, &opt, | - | ||||||||||||||||||
| 1173 | QStyle::SC_ComboBoxEditField, q); | - | ||||||||||||||||||
| 1174 | if (!q->itemIcon(q->currentIndex()).isNull()) {
| 0 | ||||||||||||||||||
| 1175 | QRect comboRect(editRect); | - | ||||||||||||||||||
| 1176 | editRect.setWidth(editRect.width() - q->iconSize().width() - 4); | - | ||||||||||||||||||
| 1177 | editRect = QStyle::alignedRect(q->layoutDirection(), Qt::AlignRight, | - | ||||||||||||||||||
| 1178 | editRect.size(), comboRect); | - | ||||||||||||||||||
| 1179 | } never executed: end of block | 0 | ||||||||||||||||||
| 1180 | lineEdit->setGeometry(editRect); | - | ||||||||||||||||||
| 1181 | } never executed: end of block | 0 | ||||||||||||||||||
| 1182 | - | |||||||||||||||||||
| 1183 | Qt::MatchFlags QComboBoxPrivate::matchFlags() const | - | ||||||||||||||||||
| 1184 | { | - | ||||||||||||||||||
| 1185 | // Base how duplicates are determined on the autocompletion case sensitivity | - | ||||||||||||||||||
| 1186 | Qt::MatchFlags flags = Qt::MatchFixedString; | - | ||||||||||||||||||
| 1187 | #ifndef QT_NO_COMPLETER | - | ||||||||||||||||||
| 1188 | if (!lineEdit->completer() || lineEdit->completer()->caseSensitivity() == Qt::CaseSensitive)
| 0 | ||||||||||||||||||
| 1189 | #endif | - | ||||||||||||||||||
| 1190 | flags |= Qt::MatchCaseSensitive; never executed: flags |= Qt::MatchCaseSensitive; | 0 | ||||||||||||||||||
| 1191 | return flags; never executed: return flags; | 0 | ||||||||||||||||||
| 1192 | } | - | ||||||||||||||||||
| 1193 | - | |||||||||||||||||||
| 1194 | - | |||||||||||||||||||
| 1195 | void QComboBoxPrivate::_q_editingFinished() | - | ||||||||||||||||||
| 1196 | { | - | ||||||||||||||||||
| 1197 | Q_Q(QComboBox); | - | ||||||||||||||||||
| 1198 | if (lineEdit && !lineEdit->text().isEmpty() && itemText(currentIndex) != lineEdit->text()) {
| 0 | ||||||||||||||||||
| 1199 | const int index = q_func()->findText(lineEdit->text(), matchFlags()); | - | ||||||||||||||||||
| 1200 | if (index != -1) {
| 0 | ||||||||||||||||||
| 1201 | q->setCurrentIndex(index); | - | ||||||||||||||||||
| 1202 | emitActivated(currentIndex); | - | ||||||||||||||||||
| 1203 | } never executed: end of block | 0 | ||||||||||||||||||
| 1204 | } never executed: end of block | 0 | ||||||||||||||||||
| 1205 | - | |||||||||||||||||||
| 1206 | } never executed: end of block | 0 | ||||||||||||||||||
| 1207 | - | |||||||||||||||||||
| 1208 | void QComboBoxPrivate::_q_returnPressed() | - | ||||||||||||||||||
| 1209 | { | - | ||||||||||||||||||
| 1210 | Q_Q(QComboBox); | - | ||||||||||||||||||
| 1211 | - | |||||||||||||||||||
| 1212 | // The insertion code below does not apply when the policy is QComboBox::NoInsert. | - | ||||||||||||||||||
| 1213 | // In case a completer is installed, item activation via the completer is handled | - | ||||||||||||||||||
| 1214 | // in _q_completerActivated(). Otherwise _q_editingFinished() updates the current | - | ||||||||||||||||||
| 1215 | // index as appropriate. | - | ||||||||||||||||||
| 1216 | if (insertPolicy == QComboBox::NoInsert)
| 0 | ||||||||||||||||||
| 1217 | return; never executed: return; | 0 | ||||||||||||||||||
| 1218 | - | |||||||||||||||||||
| 1219 | if (lineEdit && !lineEdit->text().isEmpty()) {
| 0 | ||||||||||||||||||
| 1220 | if (q->count() >= maxCount && !(this->insertPolicy == QComboBox::InsertAtCurrent))
| 0 | ||||||||||||||||||
| 1221 | return; never executed: return; | 0 | ||||||||||||||||||
| 1222 | lineEdit->deselect(); | - | ||||||||||||||||||
| 1223 | lineEdit->end(false); | - | ||||||||||||||||||
| 1224 | QString text = lineEdit->text(); | - | ||||||||||||||||||
| 1225 | // check for duplicates (if not enabled) and quit | - | ||||||||||||||||||
| 1226 | int index = -1; | - | ||||||||||||||||||
| 1227 | if (!duplicatesEnabled) {
| 0 | ||||||||||||||||||
| 1228 | index = q->findText(text, matchFlags()); | - | ||||||||||||||||||
| 1229 | if (index != -1) {
| 0 | ||||||||||||||||||
| 1230 | q->setCurrentIndex(index); | - | ||||||||||||||||||
| 1231 | emitActivated(currentIndex); | - | ||||||||||||||||||
| 1232 | return; never executed: return; | 0 | ||||||||||||||||||
| 1233 | } | - | ||||||||||||||||||
| 1234 | } never executed: end of block | 0 | ||||||||||||||||||
| 1235 | switch (insertPolicy) { | - | ||||||||||||||||||
| 1236 | case QComboBox::InsertAtTop: never executed: case QComboBox::InsertAtTop: | 0 | ||||||||||||||||||
| 1237 | index = 0; | - | ||||||||||||||||||
| 1238 | break; never executed: break; | 0 | ||||||||||||||||||
| 1239 | case QComboBox::InsertAtBottom: never executed: case QComboBox::InsertAtBottom: | 0 | ||||||||||||||||||
| 1240 | index = q->count(); | - | ||||||||||||||||||
| 1241 | break; never executed: break; | 0 | ||||||||||||||||||
| 1242 | case QComboBox::InsertAtCurrent: never executed: case QComboBox::InsertAtCurrent: | 0 | ||||||||||||||||||
| 1243 | case QComboBox::InsertAfterCurrent: never executed: case QComboBox::InsertAfterCurrent: | 0 | ||||||||||||||||||
| 1244 | case QComboBox::InsertBeforeCurrent: never executed: case QComboBox::InsertBeforeCurrent: | 0 | ||||||||||||||||||
| 1245 | if (!q->count() || !currentIndex.isValid())
| 0 | ||||||||||||||||||
| 1246 | index = 0; never executed: index = 0; | 0 | ||||||||||||||||||
| 1247 | else if (insertPolicy == QComboBox::InsertAtCurrent)
| 0 | ||||||||||||||||||
| 1248 | q->setItemText(q->currentIndex(), text); never executed: q->setItemText(q->currentIndex(), text); | 0 | ||||||||||||||||||
| 1249 | else if (insertPolicy == QComboBox::InsertAfterCurrent)
| 0 | ||||||||||||||||||
| 1250 | index = q->currentIndex() + 1; never executed: index = q->currentIndex() + 1; | 0 | ||||||||||||||||||
| 1251 | else if (insertPolicy == QComboBox::InsertBeforeCurrent)
| 0 | ||||||||||||||||||
| 1252 | index = q->currentIndex(); never executed: index = q->currentIndex(); | 0 | ||||||||||||||||||
| 1253 | break; never executed: break; | 0 | ||||||||||||||||||
| 1254 | case QComboBox::InsertAlphabetically: never executed: case QComboBox::InsertAlphabetically: | 0 | ||||||||||||||||||
| 1255 | index = 0; | - | ||||||||||||||||||
| 1256 | for (int i=0; i< q->count(); i++, index++ ) {
| 0 | ||||||||||||||||||
| 1257 | if (text.toLower() < q->itemText(i).toLower())
| 0 | ||||||||||||||||||
| 1258 | break; never executed: break; | 0 | ||||||||||||||||||
| 1259 | } never executed: end of block | 0 | ||||||||||||||||||
| 1260 | break; never executed: break; | 0 | ||||||||||||||||||
| 1261 | default: never executed: default: | 0 | ||||||||||||||||||
| 1262 | break; never executed: break; | 0 | ||||||||||||||||||
| 1263 | } | - | ||||||||||||||||||
| 1264 | if (index >= 0) {
| 0 | ||||||||||||||||||
| 1265 | q->insertItem(index, text); | - | ||||||||||||||||||
| 1266 | q->setCurrentIndex(index); | - | ||||||||||||||||||
| 1267 | emitActivated(currentIndex); | - | ||||||||||||||||||
| 1268 | } never executed: end of block | 0 | ||||||||||||||||||
| 1269 | } never executed: end of block | 0 | ||||||||||||||||||
| 1270 | } never executed: end of block | 0 | ||||||||||||||||||
| 1271 | - | |||||||||||||||||||
| 1272 | void QComboBoxPrivate::_q_itemSelected(const QModelIndex &item) | - | ||||||||||||||||||
| 1273 | { | - | ||||||||||||||||||
| 1274 | Q_Q(QComboBox); | - | ||||||||||||||||||
| 1275 | if (item != currentIndex) {
| 0 | ||||||||||||||||||
| 1276 | setCurrentIndex(item); | - | ||||||||||||||||||
| 1277 | } else if (lineEdit) { never executed: end of block
| 0 | ||||||||||||||||||
| 1278 | lineEdit->selectAll(); | - | ||||||||||||||||||
| 1279 | lineEdit->setText(q->itemText(currentIndex.row())); | - | ||||||||||||||||||
| 1280 | } never executed: end of block | 0 | ||||||||||||||||||
| 1281 | emitActivated(currentIndex); | - | ||||||||||||||||||
| 1282 | } never executed: end of block | 0 | ||||||||||||||||||
| 1283 | - | |||||||||||||||||||
| 1284 | void QComboBoxPrivate::emitActivated(const QModelIndex &index) | - | ||||||||||||||||||
| 1285 | { | - | ||||||||||||||||||
| 1286 | Q_Q(QComboBox); | - | ||||||||||||||||||
| 1287 | if (!index.isValid())
| 0 | ||||||||||||||||||
| 1288 | return; never executed: return; | 0 | ||||||||||||||||||
| 1289 | QString text(itemText(index)); | - | ||||||||||||||||||
| 1290 | emit q->activated(index.row()); | - | ||||||||||||||||||
| 1291 | emit q->activated(text); | - | ||||||||||||||||||
| 1292 | } never executed: end of block | 0 | ||||||||||||||||||
| 1293 | - | |||||||||||||||||||
| 1294 | void QComboBoxPrivate::_q_emitHighlighted(const QModelIndex &index) | - | ||||||||||||||||||
| 1295 | { | - | ||||||||||||||||||
| 1296 | Q_Q(QComboBox); | - | ||||||||||||||||||
| 1297 | if (!index.isValid())
| 0 | ||||||||||||||||||
| 1298 | return; never executed: return; | 0 | ||||||||||||||||||
| 1299 | QString text(itemText(index)); | - | ||||||||||||||||||
| 1300 | emit q->highlighted(index.row()); | - | ||||||||||||||||||
| 1301 | emit q->highlighted(text); | - | ||||||||||||||||||
| 1302 | } never executed: end of block | 0 | ||||||||||||||||||
| 1303 | - | |||||||||||||||||||
| 1304 | void QComboBoxPrivate::_q_emitCurrentIndexChanged(const QModelIndex &index) | - | ||||||||||||||||||
| 1305 | { | - | ||||||||||||||||||
| 1306 | Q_Q(QComboBox); | - | ||||||||||||||||||
| 1307 | const QString text = itemText(index); | - | ||||||||||||||||||
| 1308 | emit q->currentIndexChanged(index.row()); | - | ||||||||||||||||||
| 1309 | emit q->currentIndexChanged(text); | - | ||||||||||||||||||
| 1310 | // signal lineEdit.textChanged already connected to signal currentTextChanged, so don't emit double here | - | ||||||||||||||||||
| 1311 | if (!lineEdit)
| 0 | ||||||||||||||||||
| 1312 | emit q->currentTextChanged(text); never executed: q->currentTextChanged(text); | 0 | ||||||||||||||||||
| 1313 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||
| 1314 | QAccessibleValueChangeEvent event(q, text); | - | ||||||||||||||||||
| 1315 | QAccessible::updateAccessibility(&event); | - | ||||||||||||||||||
| 1316 | #endif | - | ||||||||||||||||||
| 1317 | } never executed: end of block | 0 | ||||||||||||||||||
| 1318 | - | |||||||||||||||||||
| 1319 | QString QComboBoxPrivate::itemText(const QModelIndex &index) const | - | ||||||||||||||||||
| 1320 | { | - | ||||||||||||||||||
| 1321 | return index.isValid() ? model->data(index, itemRole()).toString() : QString(); never executed: return index.isValid() ? model->data(index, itemRole()).toString() : QString();
| 0 | ||||||||||||||||||
| 1322 | } | - | ||||||||||||||||||
| 1323 | - | |||||||||||||||||||
| 1324 | int QComboBoxPrivate::itemRole() const | - | ||||||||||||||||||
| 1325 | { | - | ||||||||||||||||||
| 1326 | return q_func()->isEditable() ? Qt::EditRole : Qt::DisplayRole; never executed: return q_func()->isEditable() ? Qt::EditRole : Qt::DisplayRole;
| 0 | ||||||||||||||||||
| 1327 | } | - | ||||||||||||||||||
| 1328 | - | |||||||||||||||||||
| 1329 | /*! | - | ||||||||||||||||||
| 1330 | Destroys the combobox. | - | ||||||||||||||||||
| 1331 | */ | - | ||||||||||||||||||
| 1332 | QComboBox::~QComboBox() | - | ||||||||||||||||||
| 1333 | { | - | ||||||||||||||||||
| 1334 | // ### check delegateparent and delete delegate if us? | - | ||||||||||||||||||
| 1335 | Q_D(QComboBox); | - | ||||||||||||||||||
| 1336 | - | |||||||||||||||||||
| 1337 | QT_TRY { | - | ||||||||||||||||||
| 1338 | disconnect(d->model, SIGNAL(destroyed()), | - | ||||||||||||||||||
| 1339 | this, SLOT(_q_modelDestroyed())); | - | ||||||||||||||||||
| 1340 | } QT_CATCH(...) { never executed: end of blockdead code: { ; } | - | ||||||||||||||||||
| 1341 | ; // objects can't throw in destructor dead code: { ; } | - | ||||||||||||||||||
| 1342 | } dead code: { ; } | - | ||||||||||||||||||
| 1343 | } | - | ||||||||||||||||||
| 1344 | - | |||||||||||||||||||
| 1345 | /*! | - | ||||||||||||||||||
| 1346 | \property QComboBox::maxVisibleItems | - | ||||||||||||||||||
| 1347 | \brief the maximum allowed size on screen of the combo box, measured in items | - | ||||||||||||||||||
| 1348 | - | |||||||||||||||||||
| 1349 | By default, this property has a value of 10. | - | ||||||||||||||||||
| 1350 | - | |||||||||||||||||||
| 1351 | \note This property is ignored for non-editable comboboxes in styles that returns | - | ||||||||||||||||||
| 1352 | true for QStyle::SH_ComboBox_Popup such as the Mac style or the Gtk+ Style. | - | ||||||||||||||||||
| 1353 | */ | - | ||||||||||||||||||
| 1354 | int QComboBox::maxVisibleItems() const | - | ||||||||||||||||||
| 1355 | { | - | ||||||||||||||||||
| 1356 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 1357 | return d->maxVisibleItems; never executed: return d->maxVisibleItems; | 0 | ||||||||||||||||||
| 1358 | } | - | ||||||||||||||||||
| 1359 | - | |||||||||||||||||||
| 1360 | void QComboBox::setMaxVisibleItems(int maxItems) | - | ||||||||||||||||||
| 1361 | { | - | ||||||||||||||||||
| 1362 | Q_D(QComboBox); | - | ||||||||||||||||||
| 1363 | if (maxItems < 0) {
| 0 | ||||||||||||||||||
| 1364 | qWarning("QComboBox::setMaxVisibleItems: " | - | ||||||||||||||||||
| 1365 | "Invalid max visible items (%d) must be >= 0", maxItems); | - | ||||||||||||||||||
| 1366 | return; never executed: return; | 0 | ||||||||||||||||||
| 1367 | } | - | ||||||||||||||||||
| 1368 | d->maxVisibleItems = maxItems; | - | ||||||||||||||||||
| 1369 | } never executed: end of block | 0 | ||||||||||||||||||
| 1370 | - | |||||||||||||||||||
| 1371 | /*! | - | ||||||||||||||||||
| 1372 | \property QComboBox::count | - | ||||||||||||||||||
| 1373 | \brief the number of items in the combobox | - | ||||||||||||||||||
| 1374 | - | |||||||||||||||||||
| 1375 | By default, for an empty combo box, this property has a value of 0. | - | ||||||||||||||||||
| 1376 | */ | - | ||||||||||||||||||
| 1377 | int QComboBox::count() const | - | ||||||||||||||||||
| 1378 | { | - | ||||||||||||||||||
| 1379 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 1380 | return d->model->rowCount(d->root); never executed: return d->model->rowCount(d->root); | 0 | ||||||||||||||||||
| 1381 | } | - | ||||||||||||||||||
| 1382 | - | |||||||||||||||||||
| 1383 | /*! | - | ||||||||||||||||||
| 1384 | \property QComboBox::maxCount | - | ||||||||||||||||||
| 1385 | \brief the maximum number of items allowed in the combobox | - | ||||||||||||||||||
| 1386 | - | |||||||||||||||||||
| 1387 | \note If you set the maximum number to be less then the current | - | ||||||||||||||||||
| 1388 | amount of items in the combobox, the extra items will be | - | ||||||||||||||||||
| 1389 | truncated. This also applies if you have set an external model on | - | ||||||||||||||||||
| 1390 | the combobox. | - | ||||||||||||||||||
| 1391 | - | |||||||||||||||||||
| 1392 | By default, this property's value is derived from the highest | - | ||||||||||||||||||
| 1393 | signed integer available (typically 2147483647). | - | ||||||||||||||||||
| 1394 | */ | - | ||||||||||||||||||
| 1395 | void QComboBox::setMaxCount(int max) | - | ||||||||||||||||||
| 1396 | { | - | ||||||||||||||||||
| 1397 | Q_D(QComboBox); | - | ||||||||||||||||||
| 1398 | if (max < 0) {
| 0 | ||||||||||||||||||
| 1399 | qWarning("QComboBox::setMaxCount: Invalid count (%d) must be >= 0", max); | - | ||||||||||||||||||
| 1400 | return; never executed: return; | 0 | ||||||||||||||||||
| 1401 | } | - | ||||||||||||||||||
| 1402 | - | |||||||||||||||||||
| 1403 | if (max < count())
| 0 | ||||||||||||||||||
| 1404 | d->model->removeRows(max, count() - max, d->root); never executed: d->model->removeRows(max, count() - max, d->root); | 0 | ||||||||||||||||||
| 1405 | - | |||||||||||||||||||
| 1406 | d->maxCount = max; | - | ||||||||||||||||||
| 1407 | } never executed: end of block | 0 | ||||||||||||||||||
| 1408 | - | |||||||||||||||||||
| 1409 | int QComboBox::maxCount() const | - | ||||||||||||||||||
| 1410 | { | - | ||||||||||||||||||
| 1411 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 1412 | return d->maxCount; never executed: return d->maxCount; | 0 | ||||||||||||||||||
| 1413 | } | - | ||||||||||||||||||
| 1414 | - | |||||||||||||||||||
| 1415 | #ifndef QT_NO_COMPLETER | - | ||||||||||||||||||
| 1416 | - | |||||||||||||||||||
| 1417 | /*! | - | ||||||||||||||||||
| 1418 | \property QComboBox::autoCompletion | - | ||||||||||||||||||
| 1419 | \brief whether the combobox provides auto-completion for editable items | - | ||||||||||||||||||
| 1420 | \since 4.1 | - | ||||||||||||||||||
| 1421 | \obsolete | - | ||||||||||||||||||
| 1422 | - | |||||||||||||||||||
| 1423 | Use setCompleter() instead. | - | ||||||||||||||||||
| 1424 | - | |||||||||||||||||||
| 1425 | By default, this property is \c true. | - | ||||||||||||||||||
| 1426 | - | |||||||||||||||||||
| 1427 | \sa editable | - | ||||||||||||||||||
| 1428 | */ | - | ||||||||||||||||||
| 1429 | - | |||||||||||||||||||
| 1430 | /*! | - | ||||||||||||||||||
| 1431 | \obsolete | - | ||||||||||||||||||
| 1432 | - | |||||||||||||||||||
| 1433 | Use setCompleter() instead. | - | ||||||||||||||||||
| 1434 | */ | - | ||||||||||||||||||
| 1435 | bool QComboBox::autoCompletion() const | - | ||||||||||||||||||
| 1436 | { | - | ||||||||||||||||||
| 1437 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 1438 | return d->autoCompletion; never executed: return d->autoCompletion; | 0 | ||||||||||||||||||
| 1439 | } | - | ||||||||||||||||||
| 1440 | - | |||||||||||||||||||
| 1441 | /*! | - | ||||||||||||||||||
| 1442 | \obsolete | - | ||||||||||||||||||
| 1443 | - | |||||||||||||||||||
| 1444 | Use setCompleter() instead. | - | ||||||||||||||||||
| 1445 | */ | - | ||||||||||||||||||
| 1446 | void QComboBox::setAutoCompletion(bool enable) | - | ||||||||||||||||||
| 1447 | { | - | ||||||||||||||||||
| 1448 | Q_D(QComboBox); | - | ||||||||||||||||||
| 1449 | - | |||||||||||||||||||
| 1450 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
| 1451 | if (QApplication::keypadNavigationEnabled() && !enable && isEditable()) | - | ||||||||||||||||||
| 1452 | qWarning("QComboBox::setAutoCompletion: auto completion is mandatory when combo box editable"); | - | ||||||||||||||||||
| 1453 | #endif | - | ||||||||||||||||||
| 1454 | - | |||||||||||||||||||
| 1455 | d->autoCompletion = enable; | - | ||||||||||||||||||
| 1456 | if (!d->lineEdit)
| 0 | ||||||||||||||||||
| 1457 | return; never executed: return; | 0 | ||||||||||||||||||
| 1458 | if (enable) {
| 0 | ||||||||||||||||||
| 1459 | if (d->lineEdit->completer())
| 0 | ||||||||||||||||||
| 1460 | return; never executed: return; | 0 | ||||||||||||||||||
| 1461 | d->completer = new QCompleter(d->model, d->lineEdit); | - | ||||||||||||||||||
| 1462 | connect(d->completer, SIGNAL(activated(QModelIndex)), this, SLOT(_q_completerActivated(QModelIndex))); | - | ||||||||||||||||||
| 1463 | d->completer->setCaseSensitivity(d->autoCompletionCaseSensitivity); | - | ||||||||||||||||||
| 1464 | d->completer->setCompletionMode(QCompleter::InlineCompletion); | - | ||||||||||||||||||
| 1465 | d->completer->setCompletionColumn(d->modelColumn); | - | ||||||||||||||||||
| 1466 | d->lineEdit->setCompleter(d->completer); | - | ||||||||||||||||||
| 1467 | d->completer->setWidget(this); | - | ||||||||||||||||||
| 1468 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1469 | d->lineEdit->setCompleter(0); | - | ||||||||||||||||||
| 1470 | } never executed: end of block | 0 | ||||||||||||||||||
| 1471 | } | - | ||||||||||||||||||
| 1472 | - | |||||||||||||||||||
| 1473 | /*! | - | ||||||||||||||||||
| 1474 | \property QComboBox::autoCompletionCaseSensitivity | - | ||||||||||||||||||
| 1475 | \brief whether string comparisons are case-sensitive or case-insensitive for auto-completion | - | ||||||||||||||||||
| 1476 | \obsolete | - | ||||||||||||||||||
| 1477 | - | |||||||||||||||||||
| 1478 | By default, this property is Qt::CaseInsensitive. | - | ||||||||||||||||||
| 1479 | - | |||||||||||||||||||
| 1480 | Use setCompleter() instead. Case sensitivity of the auto completion can be | - | ||||||||||||||||||
| 1481 | changed using QCompleter::setCaseSensitivity(). | - | ||||||||||||||||||
| 1482 | - | |||||||||||||||||||
| 1483 | \sa autoCompletion | - | ||||||||||||||||||
| 1484 | */ | - | ||||||||||||||||||
| 1485 | - | |||||||||||||||||||
| 1486 | /*! | - | ||||||||||||||||||
| 1487 | \obsolete | - | ||||||||||||||||||
| 1488 | - | |||||||||||||||||||
| 1489 | Use setCompleter() and QCompleter::setCaseSensitivity() instead. | - | ||||||||||||||||||
| 1490 | */ | - | ||||||||||||||||||
| 1491 | Qt::CaseSensitivity QComboBox::autoCompletionCaseSensitivity() const | - | ||||||||||||||||||
| 1492 | { | - | ||||||||||||||||||
| 1493 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 1494 | return d->autoCompletionCaseSensitivity; never executed: return d->autoCompletionCaseSensitivity; | 0 | ||||||||||||||||||
| 1495 | } | - | ||||||||||||||||||
| 1496 | - | |||||||||||||||||||
| 1497 | /*! | - | ||||||||||||||||||
| 1498 | \obsolete | - | ||||||||||||||||||
| 1499 | - | |||||||||||||||||||
| 1500 | Use setCompleter() and QCompleter::setCaseSensitivity() instead. | - | ||||||||||||||||||
| 1501 | */ | - | ||||||||||||||||||
| 1502 | void QComboBox::setAutoCompletionCaseSensitivity(Qt::CaseSensitivity sensitivity) | - | ||||||||||||||||||
| 1503 | { | - | ||||||||||||||||||
| 1504 | Q_D(QComboBox); | - | ||||||||||||||||||
| 1505 | d->autoCompletionCaseSensitivity = sensitivity; | - | ||||||||||||||||||
| 1506 | if (d->lineEdit && d->lineEdit->completer())
| 0 | ||||||||||||||||||
| 1507 | d->lineEdit->completer()->setCaseSensitivity(sensitivity); never executed: d->lineEdit->completer()->setCaseSensitivity(sensitivity); | 0 | ||||||||||||||||||
| 1508 | } never executed: end of block | 0 | ||||||||||||||||||
| 1509 | - | |||||||||||||||||||
| 1510 | #endif // QT_NO_COMPLETER | - | ||||||||||||||||||
| 1511 | - | |||||||||||||||||||
| 1512 | /*! | - | ||||||||||||||||||
| 1513 | \property QComboBox::duplicatesEnabled | - | ||||||||||||||||||
| 1514 | \brief whether the user can enter duplicate items into the combobox | - | ||||||||||||||||||
| 1515 | - | |||||||||||||||||||
| 1516 | Note that it is always possible to programmatically insert duplicate items into the | - | ||||||||||||||||||
| 1517 | combobox. | - | ||||||||||||||||||
| 1518 | - | |||||||||||||||||||
| 1519 | By default, this property is \c false (duplicates are not allowed). | - | ||||||||||||||||||
| 1520 | */ | - | ||||||||||||||||||
| 1521 | bool QComboBox::duplicatesEnabled() const | - | ||||||||||||||||||
| 1522 | { | - | ||||||||||||||||||
| 1523 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 1524 | return d->duplicatesEnabled; never executed: return d->duplicatesEnabled; | 0 | ||||||||||||||||||
| 1525 | } | - | ||||||||||||||||||
| 1526 | - | |||||||||||||||||||
| 1527 | void QComboBox::setDuplicatesEnabled(bool enable) | - | ||||||||||||||||||
| 1528 | { | - | ||||||||||||||||||
| 1529 | Q_D(QComboBox); | - | ||||||||||||||||||
| 1530 | d->duplicatesEnabled = enable; | - | ||||||||||||||||||
| 1531 | } never executed: end of block | 0 | ||||||||||||||||||
| 1532 | - | |||||||||||||||||||
| 1533 | /*! \fn int QComboBox::findText(const QString &text, Qt::MatchFlags flags = Qt::MatchExactly|Qt::MatchCaseSensitive) const | - | ||||||||||||||||||
| 1534 | - | |||||||||||||||||||
| 1535 | Returns the index of the item containing the given \a text; otherwise | - | ||||||||||||||||||
| 1536 | returns -1. | - | ||||||||||||||||||
| 1537 | - | |||||||||||||||||||
| 1538 | The \a flags specify how the items in the combobox are searched. | - | ||||||||||||||||||
| 1539 | */ | - | ||||||||||||||||||
| 1540 | - | |||||||||||||||||||
| 1541 | /*! | - | ||||||||||||||||||
| 1542 | Returns the index of the item containing the given \a data for the | - | ||||||||||||||||||
| 1543 | given \a role; otherwise returns -1. | - | ||||||||||||||||||
| 1544 | - | |||||||||||||||||||
| 1545 | The \a flags specify how the items in the combobox are searched. | - | ||||||||||||||||||
| 1546 | */ | - | ||||||||||||||||||
| 1547 | int QComboBox::findData(const QVariant &data, int role, Qt::MatchFlags flags) const | - | ||||||||||||||||||
| 1548 | { | - | ||||||||||||||||||
| 1549 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 1550 | QModelIndexList result; | - | ||||||||||||||||||
| 1551 | QModelIndex start = d->model->index(0, d->modelColumn, d->root); | - | ||||||||||||||||||
| 1552 | result = d->model->match(start, role, data, 1, flags); | - | ||||||||||||||||||
| 1553 | if (result.isEmpty())
| 0 | ||||||||||||||||||
| 1554 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 1555 | return result.first().row(); never executed: return result.first().row(); | 0 | ||||||||||||||||||
| 1556 | } | - | ||||||||||||||||||
| 1557 | - | |||||||||||||||||||
| 1558 | /*! | - | ||||||||||||||||||
| 1559 | \property QComboBox::insertPolicy | - | ||||||||||||||||||
| 1560 | \brief the policy used to determine where user-inserted items should | - | ||||||||||||||||||
| 1561 | appear in the combobox | - | ||||||||||||||||||
| 1562 | - | |||||||||||||||||||
| 1563 | The default value is \l InsertAtBottom, indicating that new items will appear | - | ||||||||||||||||||
| 1564 | at the bottom of the list of items. | - | ||||||||||||||||||
| 1565 | - | |||||||||||||||||||
| 1566 | \sa InsertPolicy | - | ||||||||||||||||||
| 1567 | */ | - | ||||||||||||||||||
| 1568 | - | |||||||||||||||||||
| 1569 | QComboBox::InsertPolicy QComboBox::insertPolicy() const | - | ||||||||||||||||||
| 1570 | { | - | ||||||||||||||||||
| 1571 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 1572 | return d->insertPolicy; never executed: return d->insertPolicy; | 0 | ||||||||||||||||||
| 1573 | } | - | ||||||||||||||||||
| 1574 | - | |||||||||||||||||||
| 1575 | void QComboBox::setInsertPolicy(InsertPolicy policy) | - | ||||||||||||||||||
| 1576 | { | - | ||||||||||||||||||
| 1577 | Q_D(QComboBox); | - | ||||||||||||||||||
| 1578 | d->insertPolicy = policy; | - | ||||||||||||||||||
| 1579 | } never executed: end of block | 0 | ||||||||||||||||||
| 1580 | - | |||||||||||||||||||
| 1581 | /*! | - | ||||||||||||||||||
| 1582 | \property QComboBox::sizeAdjustPolicy | - | ||||||||||||||||||
| 1583 | \brief the policy describing how the size of the combobox changes | - | ||||||||||||||||||
| 1584 | when the content changes | - | ||||||||||||||||||
| 1585 | - | |||||||||||||||||||
| 1586 | The default value is \l AdjustToContentsOnFirstShow. | - | ||||||||||||||||||
| 1587 | - | |||||||||||||||||||
| 1588 | \sa SizeAdjustPolicy | - | ||||||||||||||||||
| 1589 | */ | - | ||||||||||||||||||
| 1590 | - | |||||||||||||||||||
| 1591 | QComboBox::SizeAdjustPolicy QComboBox::sizeAdjustPolicy() const | - | ||||||||||||||||||
| 1592 | { | - | ||||||||||||||||||
| 1593 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 1594 | return d->sizeAdjustPolicy; never executed: return d->sizeAdjustPolicy; | 0 | ||||||||||||||||||
| 1595 | } | - | ||||||||||||||||||
| 1596 | - | |||||||||||||||||||
| 1597 | void QComboBox::setSizeAdjustPolicy(QComboBox::SizeAdjustPolicy policy) | - | ||||||||||||||||||
| 1598 | { | - | ||||||||||||||||||
| 1599 | Q_D(QComboBox); | - | ||||||||||||||||||
| 1600 | if (policy == d->sizeAdjustPolicy)
| 0 | ||||||||||||||||||
| 1601 | return; never executed: return; | 0 | ||||||||||||||||||
| 1602 | - | |||||||||||||||||||
| 1603 | d->sizeAdjustPolicy = policy; | - | ||||||||||||||||||
| 1604 | d->sizeHint = QSize(); | - | ||||||||||||||||||
| 1605 | d->adjustComboBoxSize(); | - | ||||||||||||||||||
| 1606 | updateGeometry(); | - | ||||||||||||||||||
| 1607 | } never executed: end of block | 0 | ||||||||||||||||||
| 1608 | - | |||||||||||||||||||
| 1609 | /*! | - | ||||||||||||||||||
| 1610 | \property QComboBox::minimumContentsLength | - | ||||||||||||||||||
| 1611 | \brief the minimum number of characters that should fit into the combobox. | - | ||||||||||||||||||
| 1612 | - | |||||||||||||||||||
| 1613 | The default value is 0. | - | ||||||||||||||||||
| 1614 | - | |||||||||||||||||||
| 1615 | If this property is set to a positive value, the | - | ||||||||||||||||||
| 1616 | minimumSizeHint() and sizeHint() take it into account. | - | ||||||||||||||||||
| 1617 | - | |||||||||||||||||||
| 1618 | \sa sizeAdjustPolicy | - | ||||||||||||||||||
| 1619 | */ | - | ||||||||||||||||||
| 1620 | int QComboBox::minimumContentsLength() const | - | ||||||||||||||||||
| 1621 | { | - | ||||||||||||||||||
| 1622 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 1623 | return d->minimumContentsLength; never executed: return d->minimumContentsLength; | 0 | ||||||||||||||||||
| 1624 | } | - | ||||||||||||||||||
| 1625 | - | |||||||||||||||||||
| 1626 | void QComboBox::setMinimumContentsLength(int characters) | - | ||||||||||||||||||
| 1627 | { | - | ||||||||||||||||||
| 1628 | Q_D(QComboBox); | - | ||||||||||||||||||
| 1629 | if (characters == d->minimumContentsLength || characters < 0)
| 0 | ||||||||||||||||||
| 1630 | return; never executed: return; | 0 | ||||||||||||||||||
| 1631 | - | |||||||||||||||||||
| 1632 | d->minimumContentsLength = characters; | - | ||||||||||||||||||
| 1633 | - | |||||||||||||||||||
| 1634 | if (d->sizeAdjustPolicy == AdjustToContents
| 0 | ||||||||||||||||||
| 1635 | || d->sizeAdjustPolicy == AdjustToMinimumContentsLength
| 0 | ||||||||||||||||||
| 1636 | || d->sizeAdjustPolicy == AdjustToMinimumContentsLengthWithIcon) {
| 0 | ||||||||||||||||||
| 1637 | d->sizeHint = QSize(); | - | ||||||||||||||||||
| 1638 | d->adjustComboBoxSize(); | - | ||||||||||||||||||
| 1639 | updateGeometry(); | - | ||||||||||||||||||
| 1640 | } never executed: end of block | 0 | ||||||||||||||||||
| 1641 | } never executed: end of block | 0 | ||||||||||||||||||
| 1642 | - | |||||||||||||||||||
| 1643 | /*! | - | ||||||||||||||||||
| 1644 | \property QComboBox::iconSize | - | ||||||||||||||||||
| 1645 | \brief the size of the icons shown in the combobox. | - | ||||||||||||||||||
| 1646 | - | |||||||||||||||||||
| 1647 | Unless explicitly set this returns the default value of the | - | ||||||||||||||||||
| 1648 | current style. This size is the maximum size that icons can have; | - | ||||||||||||||||||
| 1649 | icons of smaller size are not scaled up. | - | ||||||||||||||||||
| 1650 | */ | - | ||||||||||||||||||
| 1651 | - | |||||||||||||||||||
| 1652 | QSize QComboBox::iconSize() const | - | ||||||||||||||||||
| 1653 | { | - | ||||||||||||||||||
| 1654 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 1655 | if (d->iconSize.isValid())
| 0 | ||||||||||||||||||
| 1656 | return d->iconSize; never executed: return d->iconSize; | 0 | ||||||||||||||||||
| 1657 | - | |||||||||||||||||||
| 1658 | int iconWidth = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this); | - | ||||||||||||||||||
| 1659 | return QSize(iconWidth, iconWidth); never executed: return QSize(iconWidth, iconWidth); | 0 | ||||||||||||||||||
| 1660 | } | - | ||||||||||||||||||
| 1661 | - | |||||||||||||||||||
| 1662 | void QComboBox::setIconSize(const QSize &size) | - | ||||||||||||||||||
| 1663 | { | - | ||||||||||||||||||
| 1664 | Q_D(QComboBox); | - | ||||||||||||||||||
| 1665 | if (size == d->iconSize)
| 0 | ||||||||||||||||||
| 1666 | return; never executed: return; | 0 | ||||||||||||||||||
| 1667 | - | |||||||||||||||||||
| 1668 | view()->setIconSize(size); | - | ||||||||||||||||||
| 1669 | d->iconSize = size; | - | ||||||||||||||||||
| 1670 | d->sizeHint = QSize(); | - | ||||||||||||||||||
| 1671 | updateGeometry(); | - | ||||||||||||||||||
| 1672 | } never executed: end of block | 0 | ||||||||||||||||||
| 1673 | - | |||||||||||||||||||
| 1674 | /*! | - | ||||||||||||||||||
| 1675 | \property QComboBox::editable | - | ||||||||||||||||||
| 1676 | \brief whether the combo box can be edited by the user | - | ||||||||||||||||||
| 1677 | - | |||||||||||||||||||
| 1678 | By default, this property is \c false. The effect of editing depends | - | ||||||||||||||||||
| 1679 | on the insert policy. | - | ||||||||||||||||||
| 1680 | - | |||||||||||||||||||
| 1681 | \note When disabling the \a editable state, the validator and | - | ||||||||||||||||||
| 1682 | completer are removed. | - | ||||||||||||||||||
| 1683 | - | |||||||||||||||||||
| 1684 | \sa InsertPolicy | - | ||||||||||||||||||
| 1685 | */ | - | ||||||||||||||||||
| 1686 | bool QComboBox::isEditable() const | - | ||||||||||||||||||
| 1687 | { | - | ||||||||||||||||||
| 1688 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 1689 | return d->lineEdit != 0; never executed: return d->lineEdit != 0; | 0 | ||||||||||||||||||
| 1690 | } | - | ||||||||||||||||||
| 1691 | - | |||||||||||||||||||
| 1692 | /*! \internal | - | ||||||||||||||||||
| 1693 | update the default delegate | - | ||||||||||||||||||
| 1694 | depending on the style's SH_ComboBox_Popup hint, we use a different default delegate. | - | ||||||||||||||||||
| 1695 | - | |||||||||||||||||||
| 1696 | but we do not change the delegate is the combobox use a custom delegate, | - | ||||||||||||||||||
| 1697 | unless \a force is set to true. | - | ||||||||||||||||||
| 1698 | */ | - | ||||||||||||||||||
| 1699 | void QComboBoxPrivate::updateDelegate(bool force) | - | ||||||||||||||||||
| 1700 | { | - | ||||||||||||||||||
| 1701 | Q_Q(QComboBox); | - | ||||||||||||||||||
| 1702 | QStyleOptionComboBox opt; | - | ||||||||||||||||||
| 1703 | q->initStyleOption(&opt); | - | ||||||||||||||||||
| 1704 | if (q->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, q)) {
| 0 | ||||||||||||||||||
| 1705 | if (force || qobject_cast<QComboBoxDelegate *>(q->itemDelegate()))
| 0 | ||||||||||||||||||
| 1706 | q->setItemDelegate(new QComboMenuDelegate(q->view(), q)); never executed: q->setItemDelegate(new QComboMenuDelegate(q->view(), q)); | 0 | ||||||||||||||||||
| 1707 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1708 | if (force || qobject_cast<QComboMenuDelegate *>(q->itemDelegate()))
| 0 | ||||||||||||||||||
| 1709 | q->setItemDelegate(new QComboBoxDelegate(q->view(), q)); never executed: q->setItemDelegate(new QComboBoxDelegate(q->view(), q)); | 0 | ||||||||||||||||||
| 1710 | } never executed: end of block | 0 | ||||||||||||||||||
| 1711 | } | - | ||||||||||||||||||
| 1712 | - | |||||||||||||||||||
| 1713 | QIcon QComboBoxPrivate::itemIcon(const QModelIndex &index) const | - | ||||||||||||||||||
| 1714 | { | - | ||||||||||||||||||
| 1715 | QVariant decoration = model->data(index, Qt::DecorationRole); | - | ||||||||||||||||||
| 1716 | if (decoration.type() == QVariant::Pixmap)
| 0 | ||||||||||||||||||
| 1717 | return QIcon(qvariant_cast<QPixmap>(decoration)); never executed: return QIcon(qvariant_cast<QPixmap>(decoration)); | 0 | ||||||||||||||||||
| 1718 | else | - | ||||||||||||||||||
| 1719 | return qvariant_cast<QIcon>(decoration); never executed: return qvariant_cast<QIcon>(decoration); | 0 | ||||||||||||||||||
| 1720 | } | - | ||||||||||||||||||
| 1721 | - | |||||||||||||||||||
| 1722 | void QComboBox::setEditable(bool editable) | - | ||||||||||||||||||
| 1723 | { | - | ||||||||||||||||||
| 1724 | Q_D(QComboBox); | - | ||||||||||||||||||
| 1725 | if (isEditable() == editable)
| 0 | ||||||||||||||||||
| 1726 | return; never executed: return; | 0 | ||||||||||||||||||
| 1727 | - | |||||||||||||||||||
| 1728 | QStyleOptionComboBox opt; | - | ||||||||||||||||||
| 1729 | initStyleOption(&opt); | - | ||||||||||||||||||
| 1730 | if (editable) {
| 0 | ||||||||||||||||||
| 1731 | if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) {
| 0 | ||||||||||||||||||
| 1732 | d->viewContainer()->updateScrollers(); | - | ||||||||||||||||||
| 1733 | view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); | - | ||||||||||||||||||
| 1734 | } never executed: end of block | 0 | ||||||||||||||||||
| 1735 | QLineEdit *le = new QLineEdit(this); | - | ||||||||||||||||||
| 1736 | setLineEdit(le); | - | ||||||||||||||||||
| 1737 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1738 | if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) {
| 0 | ||||||||||||||||||
| 1739 | d->viewContainer()->updateScrollers(); | - | ||||||||||||||||||
| 1740 | view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | - | ||||||||||||||||||
| 1741 | } never executed: end of block | 0 | ||||||||||||||||||
| 1742 | setAttribute(Qt::WA_InputMethodEnabled, false); | - | ||||||||||||||||||
| 1743 | d->lineEdit->hide(); | - | ||||||||||||||||||
| 1744 | d->lineEdit->deleteLater(); | - | ||||||||||||||||||
| 1745 | d->lineEdit = 0; | - | ||||||||||||||||||
| 1746 | } never executed: end of block | 0 | ||||||||||||||||||
| 1747 | - | |||||||||||||||||||
| 1748 | d->updateDelegate(); | - | ||||||||||||||||||
| 1749 | d->updateFocusPolicy(); | - | ||||||||||||||||||
| 1750 | - | |||||||||||||||||||
| 1751 | d->viewContainer()->updateTopBottomMargin(); | - | ||||||||||||||||||
| 1752 | if (!testAttribute(Qt::WA_Resized))
| 0 | ||||||||||||||||||
| 1753 | adjustSize(); never executed: adjustSize(); | 0 | ||||||||||||||||||
| 1754 | } never executed: end of block | 0 | ||||||||||||||||||
| 1755 | - | |||||||||||||||||||
| 1756 | /*! | - | ||||||||||||||||||
| 1757 | Sets the line \a edit to use instead of the current line edit widget. | - | ||||||||||||||||||
| 1758 | - | |||||||||||||||||||
| 1759 | The combo box takes ownership of the line edit. | - | ||||||||||||||||||
| 1760 | */ | - | ||||||||||||||||||
| 1761 | void QComboBox::setLineEdit(QLineEdit *edit) | - | ||||||||||||||||||
| 1762 | { | - | ||||||||||||||||||
| 1763 | Q_D(QComboBox); | - | ||||||||||||||||||
| 1764 | if (!edit) {
| 0 | ||||||||||||||||||
| 1765 | qWarning("QComboBox::setLineEdit: cannot set a 0 line edit"); | - | ||||||||||||||||||
| 1766 | return; never executed: return; | 0 | ||||||||||||||||||
| 1767 | } | - | ||||||||||||||||||
| 1768 | - | |||||||||||||||||||
| 1769 | if (edit == d->lineEdit)
| 0 | ||||||||||||||||||
| 1770 | return; never executed: return; | 0 | ||||||||||||||||||
| 1771 | - | |||||||||||||||||||
| 1772 | edit->setText(currentText()); | - | ||||||||||||||||||
| 1773 | delete d->lineEdit; | - | ||||||||||||||||||
| 1774 | - | |||||||||||||||||||
| 1775 | d->lineEdit = edit; | - | ||||||||||||||||||
| 1776 | qt_widget_private(d->lineEdit)->inheritsInputMethodHints = 1; | - | ||||||||||||||||||
| 1777 | if (d->lineEdit->parent() != this)
| 0 | ||||||||||||||||||
| 1778 | d->lineEdit->setParent(this); never executed: d->lineEdit->setParent(this); | 0 | ||||||||||||||||||
| 1779 | connect(d->lineEdit, SIGNAL(returnPressed()), this, SLOT(_q_returnPressed())); | - | ||||||||||||||||||
| 1780 | connect(d->lineEdit, SIGNAL(editingFinished()), this, SLOT(_q_editingFinished())); | - | ||||||||||||||||||
| 1781 | connect(d->lineEdit, SIGNAL(textChanged(QString)), this, SIGNAL(editTextChanged(QString))); | - | ||||||||||||||||||
| 1782 | connect(d->lineEdit, SIGNAL(textChanged(QString)), this, SIGNAL(currentTextChanged(QString))); | - | ||||||||||||||||||
| 1783 | connect(d->lineEdit, SIGNAL(cursorPositionChanged(int,int)), this, SLOT(updateMicroFocus())); | - | ||||||||||||||||||
| 1784 | connect(d->lineEdit, SIGNAL(selectionChanged()), this, SLOT(updateMicroFocus())); | - | ||||||||||||||||||
| 1785 | d->lineEdit->setFrame(false); | - | ||||||||||||||||||
| 1786 | d->lineEdit->setContextMenuPolicy(Qt::NoContextMenu); | - | ||||||||||||||||||
| 1787 | d->updateFocusPolicy(); | - | ||||||||||||||||||
| 1788 | d->lineEdit->setFocusProxy(this); | - | ||||||||||||||||||
| 1789 | d->lineEdit->setAttribute(Qt::WA_MacShowFocusRect, false); | - | ||||||||||||||||||
| 1790 | #ifndef QT_NO_COMPLETER | - | ||||||||||||||||||
| 1791 | setAutoCompletion(d->autoCompletion); | - | ||||||||||||||||||
| 1792 | #endif | - | ||||||||||||||||||
| 1793 | - | |||||||||||||||||||
| 1794 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
| 1795 | #ifndef QT_NO_COMPLETER | - | ||||||||||||||||||
| 1796 | if (QApplication::keypadNavigationEnabled()) { | - | ||||||||||||||||||
| 1797 | // Editable combo boxes will have a completer that is set to UnfilteredPopupCompletion. | - | ||||||||||||||||||
| 1798 | // This means that when the user enters edit mode they are immediately presented with a | - | ||||||||||||||||||
| 1799 | // list of possible completions. | - | ||||||||||||||||||
| 1800 | setAutoCompletion(true); | - | ||||||||||||||||||
| 1801 | if (d->completer) { | - | ||||||||||||||||||
| 1802 | d->completer->setCompletionMode(QCompleter::UnfilteredPopupCompletion); | - | ||||||||||||||||||
| 1803 | connect(d->completer, SIGNAL(activated(QModelIndex)), this, SLOT(_q_completerActivated())); | - | ||||||||||||||||||
| 1804 | } | - | ||||||||||||||||||
| 1805 | } | - | ||||||||||||||||||
| 1806 | #endif | - | ||||||||||||||||||
| 1807 | #endif | - | ||||||||||||||||||
| 1808 | - | |||||||||||||||||||
| 1809 | setAttribute(Qt::WA_InputMethodEnabled); | - | ||||||||||||||||||
| 1810 | d->updateLayoutDirection(); | - | ||||||||||||||||||
| 1811 | d->updateLineEditGeometry(); | - | ||||||||||||||||||
| 1812 | if (isVisible())
| 0 | ||||||||||||||||||
| 1813 | d->lineEdit->show(); never executed: d->lineEdit->show(); | 0 | ||||||||||||||||||
| 1814 | - | |||||||||||||||||||
| 1815 | update(); | - | ||||||||||||||||||
| 1816 | } never executed: end of block | 0 | ||||||||||||||||||
| 1817 | - | |||||||||||||||||||
| 1818 | /*! | - | ||||||||||||||||||
| 1819 | Returns the line edit used to edit items in the combobox, or 0 if there | - | ||||||||||||||||||
| 1820 | is no line edit. | - | ||||||||||||||||||
| 1821 | - | |||||||||||||||||||
| 1822 | Only editable combo boxes have a line edit. | - | ||||||||||||||||||
| 1823 | */ | - | ||||||||||||||||||
| 1824 | QLineEdit *QComboBox::lineEdit() const | - | ||||||||||||||||||
| 1825 | { | - | ||||||||||||||||||
| 1826 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 1827 | return d->lineEdit; never executed: return d->lineEdit; | 0 | ||||||||||||||||||
| 1828 | } | - | ||||||||||||||||||
| 1829 | - | |||||||||||||||||||
| 1830 | #ifndef QT_NO_VALIDATOR | - | ||||||||||||||||||
| 1831 | /*! | - | ||||||||||||||||||
| 1832 | \fn void QComboBox::setValidator(const QValidator *validator) | - | ||||||||||||||||||
| 1833 | - | |||||||||||||||||||
| 1834 | Sets the \a validator to use instead of the current validator. | - | ||||||||||||||||||
| 1835 | - | |||||||||||||||||||
| 1836 | \note The validator is removed when the editable property becomes \c false. | - | ||||||||||||||||||
| 1837 | */ | - | ||||||||||||||||||
| 1838 | - | |||||||||||||||||||
| 1839 | void QComboBox::setValidator(const QValidator *v) | - | ||||||||||||||||||
| 1840 | { | - | ||||||||||||||||||
| 1841 | Q_D(QComboBox); | - | ||||||||||||||||||
| 1842 | if (d->lineEdit)
| 0 | ||||||||||||||||||
| 1843 | d->lineEdit->setValidator(v); never executed: d->lineEdit->setValidator(v); | 0 | ||||||||||||||||||
| 1844 | } never executed: end of block | 0 | ||||||||||||||||||
| 1845 | - | |||||||||||||||||||
| 1846 | /*! | - | ||||||||||||||||||
| 1847 | Returns the validator that is used to constrain text input for the | - | ||||||||||||||||||
| 1848 | combobox. | - | ||||||||||||||||||
| 1849 | - | |||||||||||||||||||
| 1850 | \sa editable | - | ||||||||||||||||||
| 1851 | */ | - | ||||||||||||||||||
| 1852 | const QValidator *QComboBox::validator() const | - | ||||||||||||||||||
| 1853 | { | - | ||||||||||||||||||
| 1854 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 1855 | return d->lineEdit ? d->lineEdit->validator() : 0; never executed: return d->lineEdit ? d->lineEdit->validator() : 0;
| 0 | ||||||||||||||||||
| 1856 | } | - | ||||||||||||||||||
| 1857 | #endif // QT_NO_VALIDATOR | - | ||||||||||||||||||
| 1858 | - | |||||||||||||||||||
| 1859 | #ifndef QT_NO_COMPLETER | - | ||||||||||||||||||
| 1860 | - | |||||||||||||||||||
| 1861 | /*! | - | ||||||||||||||||||
| 1862 | \fn void QComboBox::setCompleter(QCompleter *completer) | - | ||||||||||||||||||
| 1863 | \since 4.2 | - | ||||||||||||||||||
| 1864 | - | |||||||||||||||||||
| 1865 | Sets the \a completer to use instead of the current completer. | - | ||||||||||||||||||
| 1866 | If \a completer is 0, auto completion is disabled. | - | ||||||||||||||||||
| 1867 | - | |||||||||||||||||||
| 1868 | By default, for an editable combo box, a QCompleter that | - | ||||||||||||||||||
| 1869 | performs case insensitive inline completion is automatically created. | - | ||||||||||||||||||
| 1870 | - | |||||||||||||||||||
| 1871 | \note The completer is removed when the \a editable property becomes \c false. | - | ||||||||||||||||||
| 1872 | */ | - | ||||||||||||||||||
| 1873 | void QComboBox::setCompleter(QCompleter *c) | - | ||||||||||||||||||
| 1874 | { | - | ||||||||||||||||||
| 1875 | Q_D(QComboBox); | - | ||||||||||||||||||
| 1876 | if (!d->lineEdit)
| 0 | ||||||||||||||||||
| 1877 | return; never executed: return; | 0 | ||||||||||||||||||
| 1878 | d->lineEdit->setCompleter(c); | - | ||||||||||||||||||
| 1879 | if (c) {
| 0 | ||||||||||||||||||
| 1880 | connect(c, SIGNAL(activated(QModelIndex)), this, SLOT(_q_completerActivated(QModelIndex))); | - | ||||||||||||||||||
| 1881 | c->setWidget(this); | - | ||||||||||||||||||
| 1882 | } never executed: end of block | 0 | ||||||||||||||||||
| 1883 | } never executed: end of block | 0 | ||||||||||||||||||
| 1884 | - | |||||||||||||||||||
| 1885 | /*! | - | ||||||||||||||||||
| 1886 | \since 4.2 | - | ||||||||||||||||||
| 1887 | - | |||||||||||||||||||
| 1888 | Returns the completer that is used to auto complete text input for the | - | ||||||||||||||||||
| 1889 | combobox. | - | ||||||||||||||||||
| 1890 | - | |||||||||||||||||||
| 1891 | \sa editable | - | ||||||||||||||||||
| 1892 | */ | - | ||||||||||||||||||
| 1893 | QCompleter *QComboBox::completer() const | - | ||||||||||||||||||
| 1894 | { | - | ||||||||||||||||||
| 1895 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 1896 | return d->lineEdit ? d->lineEdit->completer() : 0; never executed: return d->lineEdit ? d->lineEdit->completer() : 0;
| 0 | ||||||||||||||||||
| 1897 | } | - | ||||||||||||||||||
| 1898 | - | |||||||||||||||||||
| 1899 | #endif // QT_NO_COMPLETER | - | ||||||||||||||||||
| 1900 | - | |||||||||||||||||||
| 1901 | /*! | - | ||||||||||||||||||
| 1902 | Returns the item delegate used by the popup list view. | - | ||||||||||||||||||
| 1903 | - | |||||||||||||||||||
| 1904 | \sa setItemDelegate() | - | ||||||||||||||||||
| 1905 | */ | - | ||||||||||||||||||
| 1906 | QAbstractItemDelegate *QComboBox::itemDelegate() const | - | ||||||||||||||||||
| 1907 | { | - | ||||||||||||||||||
| 1908 | return view()->itemDelegate(); never executed: return view()->itemDelegate(); | 0 | ||||||||||||||||||
| 1909 | } | - | ||||||||||||||||||
| 1910 | - | |||||||||||||||||||
| 1911 | /*! | - | ||||||||||||||||||
| 1912 | Sets the item \a delegate for the popup list view. | - | ||||||||||||||||||
| 1913 | The combobox takes ownership of the delegate. | - | ||||||||||||||||||
| 1914 | - | |||||||||||||||||||
| 1915 | \warning You should not share the same instance of a delegate between comboboxes, | - | ||||||||||||||||||
| 1916 | widget mappers or views. Doing so can cause incorrect or unintuitive editing behavior | - | ||||||||||||||||||
| 1917 | since each view connected to a given delegate may receive the | - | ||||||||||||||||||
| 1918 | \l{QAbstractItemDelegate::}{closeEditor()} signal, and attempt to access, modify or | - | ||||||||||||||||||
| 1919 | close an editor that has already been closed. | - | ||||||||||||||||||
| 1920 | - | |||||||||||||||||||
| 1921 | \sa itemDelegate() | - | ||||||||||||||||||
| 1922 | */ | - | ||||||||||||||||||
| 1923 | void QComboBox::setItemDelegate(QAbstractItemDelegate *delegate) | - | ||||||||||||||||||
| 1924 | { | - | ||||||||||||||||||
| 1925 | if (!delegate) {
| 0 | ||||||||||||||||||
| 1926 | qWarning("QComboBox::setItemDelegate: cannot set a 0 delegate"); | - | ||||||||||||||||||
| 1927 | return; never executed: return; | 0 | ||||||||||||||||||
| 1928 | } | - | ||||||||||||||||||
| 1929 | delete view()->itemDelegate(); | - | ||||||||||||||||||
| 1930 | view()->setItemDelegate(delegate); | - | ||||||||||||||||||
| 1931 | } never executed: end of block | 0 | ||||||||||||||||||
| 1932 | - | |||||||||||||||||||
| 1933 | /*! | - | ||||||||||||||||||
| 1934 | Returns the model used by the combobox. | - | ||||||||||||||||||
| 1935 | */ | - | ||||||||||||||||||
| 1936 | - | |||||||||||||||||||
| 1937 | QAbstractItemModel *QComboBox::model() const | - | ||||||||||||||||||
| 1938 | { | - | ||||||||||||||||||
| 1939 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 1940 | if (d->model == QAbstractItemModelPrivate::staticEmptyModel()) {
| 0 | ||||||||||||||||||
| 1941 | QComboBox *that = const_cast<QComboBox*>(this); | - | ||||||||||||||||||
| 1942 | that->setModel(new QStandardItemModel(0, 1, that)); | - | ||||||||||||||||||
| 1943 | } never executed: end of block | 0 | ||||||||||||||||||
| 1944 | return d->model; never executed: return d->model; | 0 | ||||||||||||||||||
| 1945 | } | - | ||||||||||||||||||
| 1946 | - | |||||||||||||||||||
| 1947 | /*! | - | ||||||||||||||||||
| 1948 | Sets the model to be \a model. \a model must not be 0. | - | ||||||||||||||||||
| 1949 | If you want to clear the contents of a model, call clear(). | - | ||||||||||||||||||
| 1950 | - | |||||||||||||||||||
| 1951 | \sa clear() | - | ||||||||||||||||||
| 1952 | */ | - | ||||||||||||||||||
| 1953 | void QComboBox::setModel(QAbstractItemModel *model) | - | ||||||||||||||||||
| 1954 | { | - | ||||||||||||||||||
| 1955 | Q_D(QComboBox); | - | ||||||||||||||||||
| 1956 | - | |||||||||||||||||||
| 1957 | if (!model) {
| 0 | ||||||||||||||||||
| 1958 | qWarning("QComboBox::setModel: cannot set a 0 model"); | - | ||||||||||||||||||
| 1959 | return; never executed: return; | 0 | ||||||||||||||||||
| 1960 | } | - | ||||||||||||||||||
| 1961 | - | |||||||||||||||||||
| 1962 | if (model == d->model)
| 0 | ||||||||||||||||||
| 1963 | return; never executed: return; | 0 | ||||||||||||||||||
| 1964 | - | |||||||||||||||||||
| 1965 | #ifndef QT_NO_COMPLETER | - | ||||||||||||||||||
| 1966 | if (d->lineEdit && d->lineEdit->completer()
| 0 | ||||||||||||||||||
| 1967 | && d->lineEdit->completer() == d->completer)
| 0 | ||||||||||||||||||
| 1968 | d->lineEdit->completer()->setModel(model); never executed: d->lineEdit->completer()->setModel(model); | 0 | ||||||||||||||||||
| 1969 | #endif | - | ||||||||||||||||||
| 1970 | if (d->model) {
| 0 | ||||||||||||||||||
| 1971 | disconnect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), | - | ||||||||||||||||||
| 1972 | this, SLOT(_q_dataChanged(QModelIndex,QModelIndex))); | - | ||||||||||||||||||
| 1973 | disconnect(d->model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), | - | ||||||||||||||||||
| 1974 | this, SLOT(_q_updateIndexBeforeChange())); | - | ||||||||||||||||||
| 1975 | disconnect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)), | - | ||||||||||||||||||
| 1976 | this, SLOT(_q_rowsInserted(QModelIndex,int,int))); | - | ||||||||||||||||||
| 1977 | disconnect(d->model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), | - | ||||||||||||||||||
| 1978 | this, SLOT(_q_updateIndexBeforeChange())); | - | ||||||||||||||||||
| 1979 | disconnect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)), | - | ||||||||||||||||||
| 1980 | this, SLOT(_q_rowsRemoved(QModelIndex,int,int))); | - | ||||||||||||||||||
| 1981 | disconnect(d->model, SIGNAL(destroyed()), | - | ||||||||||||||||||
| 1982 | this, SLOT(_q_modelDestroyed())); | - | ||||||||||||||||||
| 1983 | disconnect(d->model, SIGNAL(modelAboutToBeReset()), | - | ||||||||||||||||||
| 1984 | this, SLOT(_q_updateIndexBeforeChange())); | - | ||||||||||||||||||
| 1985 | disconnect(d->model, SIGNAL(modelReset()), | - | ||||||||||||||||||
| 1986 | this, SLOT(_q_modelReset())); | - | ||||||||||||||||||
| 1987 | if (d->model->QObject::parent() == this)
| 0 | ||||||||||||||||||
| 1988 | delete d->model; never executed: delete d->model; | 0 | ||||||||||||||||||
| 1989 | } never executed: end of block | 0 | ||||||||||||||||||
| 1990 | - | |||||||||||||||||||
| 1991 | d->model = model; | - | ||||||||||||||||||
| 1992 | - | |||||||||||||||||||
| 1993 | connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), | - | ||||||||||||||||||
| 1994 | this, SLOT(_q_dataChanged(QModelIndex,QModelIndex))); | - | ||||||||||||||||||
| 1995 | connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), | - | ||||||||||||||||||
| 1996 | this, SLOT(_q_updateIndexBeforeChange())); | - | ||||||||||||||||||
| 1997 | connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), | - | ||||||||||||||||||
| 1998 | this, SLOT(_q_rowsInserted(QModelIndex,int,int))); | - | ||||||||||||||||||
| 1999 | connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), | - | ||||||||||||||||||
| 2000 | this, SLOT(_q_updateIndexBeforeChange())); | - | ||||||||||||||||||
| 2001 | connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), | - | ||||||||||||||||||
| 2002 | this, SLOT(_q_rowsRemoved(QModelIndex,int,int))); | - | ||||||||||||||||||
| 2003 | connect(model, SIGNAL(destroyed()), | - | ||||||||||||||||||
| 2004 | this, SLOT(_q_modelDestroyed())); | - | ||||||||||||||||||
| 2005 | connect(model, SIGNAL(modelAboutToBeReset()), | - | ||||||||||||||||||
| 2006 | this, SLOT(_q_updateIndexBeforeChange())); | - | ||||||||||||||||||
| 2007 | connect(model, SIGNAL(modelReset()), | - | ||||||||||||||||||
| 2008 | this, SLOT(_q_modelReset())); | - | ||||||||||||||||||
| 2009 | - | |||||||||||||||||||
| 2010 | if (d->container) {
| 0 | ||||||||||||||||||
| 2011 | d->container->itemView()->setModel(model); | - | ||||||||||||||||||
| 2012 | connect(d->container->itemView()->selectionModel(), | - | ||||||||||||||||||
| 2013 | SIGNAL(currentChanged(QModelIndex,QModelIndex)), | - | ||||||||||||||||||
| 2014 | this, SLOT(_q_emitHighlighted(QModelIndex)), Qt::UniqueConnection); | - | ||||||||||||||||||
| 2015 | } never executed: end of block | 0 | ||||||||||||||||||
| 2016 | - | |||||||||||||||||||
| 2017 | setRootModelIndex(QModelIndex()); | - | ||||||||||||||||||
| 2018 | - | |||||||||||||||||||
| 2019 | bool currentReset = false; | - | ||||||||||||||||||
| 2020 | - | |||||||||||||||||||
| 2021 | const int rowCount = count(); | - | ||||||||||||||||||
| 2022 | for (int pos=0; pos < rowCount; pos++) {
| 0 | ||||||||||||||||||
| 2023 | if (d->model->index(pos, d->modelColumn, d->root).flags() & Qt::ItemIsEnabled) {
| 0 | ||||||||||||||||||
| 2024 | setCurrentIndex(pos); | - | ||||||||||||||||||
| 2025 | currentReset = true; | - | ||||||||||||||||||
| 2026 | break; never executed: break; | 0 | ||||||||||||||||||
| 2027 | } | - | ||||||||||||||||||
| 2028 | } never executed: end of block | 0 | ||||||||||||||||||
| 2029 | - | |||||||||||||||||||
| 2030 | if (!currentReset)
| 0 | ||||||||||||||||||
| 2031 | setCurrentIndex(-1); never executed: setCurrentIndex(-1); | 0 | ||||||||||||||||||
| 2032 | - | |||||||||||||||||||
| 2033 | d->modelChanged(); | - | ||||||||||||||||||
| 2034 | } never executed: end of block | 0 | ||||||||||||||||||
| 2035 | - | |||||||||||||||||||
| 2036 | /*! | - | ||||||||||||||||||
| 2037 | Returns the root model item index for the items in the combobox. | - | ||||||||||||||||||
| 2038 | - | |||||||||||||||||||
| 2039 | \sa setRootModelIndex() | - | ||||||||||||||||||
| 2040 | */ | - | ||||||||||||||||||
| 2041 | - | |||||||||||||||||||
| 2042 | QModelIndex QComboBox::rootModelIndex() const | - | ||||||||||||||||||
| 2043 | { | - | ||||||||||||||||||
| 2044 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 2045 | return QModelIndex(d->root); never executed: return QModelIndex(d->root); | 0 | ||||||||||||||||||
| 2046 | } | - | ||||||||||||||||||
| 2047 | - | |||||||||||||||||||
| 2048 | /*! | - | ||||||||||||||||||
| 2049 | Sets the root model item \a index for the items in the combobox. | - | ||||||||||||||||||
| 2050 | - | |||||||||||||||||||
| 2051 | \sa rootModelIndex() | - | ||||||||||||||||||
| 2052 | */ | - | ||||||||||||||||||
| 2053 | void QComboBox::setRootModelIndex(const QModelIndex &index) | - | ||||||||||||||||||
| 2054 | { | - | ||||||||||||||||||
| 2055 | Q_D(QComboBox); | - | ||||||||||||||||||
| 2056 | if (d->root == index)
| 0 | ||||||||||||||||||
| 2057 | return; never executed: return; | 0 | ||||||||||||||||||
| 2058 | d->root = QPersistentModelIndex(index); | - | ||||||||||||||||||
| 2059 | view()->setRootIndex(index); | - | ||||||||||||||||||
| 2060 | update(); | - | ||||||||||||||||||
| 2061 | } never executed: end of block | 0 | ||||||||||||||||||
| 2062 | - | |||||||||||||||||||
| 2063 | /*! | - | ||||||||||||||||||
| 2064 | \property QComboBox::currentIndex | - | ||||||||||||||||||
| 2065 | \brief the index of the current item in the combobox. | - | ||||||||||||||||||
| 2066 | - | |||||||||||||||||||
| 2067 | The current index can change when inserting or removing items. | - | ||||||||||||||||||
| 2068 | - | |||||||||||||||||||
| 2069 | By default, for an empty combo box or a combo box in which no current | - | ||||||||||||||||||
| 2070 | item is set, this property has a value of -1. | - | ||||||||||||||||||
| 2071 | */ | - | ||||||||||||||||||
| 2072 | int QComboBox::currentIndex() const | - | ||||||||||||||||||
| 2073 | { | - | ||||||||||||||||||
| 2074 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 2075 | return d->currentIndex.row(); never executed: return d->currentIndex.row(); | 0 | ||||||||||||||||||
| 2076 | } | - | ||||||||||||||||||
| 2077 | - | |||||||||||||||||||
| 2078 | void QComboBox::setCurrentIndex(int index) | - | ||||||||||||||||||
| 2079 | { | - | ||||||||||||||||||
| 2080 | Q_D(QComboBox); | - | ||||||||||||||||||
| 2081 | QModelIndex mi = d->model->index(index, d->modelColumn, d->root); | - | ||||||||||||||||||
| 2082 | d->setCurrentIndex(mi); | - | ||||||||||||||||||
| 2083 | } never executed: end of block | 0 | ||||||||||||||||||
| 2084 | - | |||||||||||||||||||
| 2085 | void QComboBox::setCurrentText(const QString &text) | - | ||||||||||||||||||
| 2086 | { | - | ||||||||||||||||||
| 2087 | if (isEditable()) {
| 0 | ||||||||||||||||||
| 2088 | setEditText(text); | - | ||||||||||||||||||
| 2089 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2090 | const int i = findText(text); | - | ||||||||||||||||||
| 2091 | if (i > -1)
| 0 | ||||||||||||||||||
| 2092 | setCurrentIndex(i); never executed: setCurrentIndex(i); | 0 | ||||||||||||||||||
| 2093 | } never executed: end of block | 0 | ||||||||||||||||||
| 2094 | } | - | ||||||||||||||||||
| 2095 | - | |||||||||||||||||||
| 2096 | void QComboBoxPrivate::setCurrentIndex(const QModelIndex &mi) | - | ||||||||||||||||||
| 2097 | { | - | ||||||||||||||||||
| 2098 | Q_Q(QComboBox); | - | ||||||||||||||||||
| 2099 | - | |||||||||||||||||||
| 2100 | QModelIndex normalized = mi.sibling(mi.row(), modelColumn); // no-op if mi.column() == modelColumn | - | ||||||||||||||||||
| 2101 | if (!normalized.isValid())
| 0 | ||||||||||||||||||
| 2102 | normalized = mi; // Fallback to passed index. never executed: normalized = mi; | 0 | ||||||||||||||||||
| 2103 | - | |||||||||||||||||||
| 2104 | bool indexChanged = (normalized != currentIndex); | - | ||||||||||||||||||
| 2105 | if (indexChanged)
| 0 | ||||||||||||||||||
| 2106 | currentIndex = QPersistentModelIndex(normalized); never executed: currentIndex = QPersistentModelIndex(normalized); | 0 | ||||||||||||||||||
| 2107 | if (lineEdit) {
| 0 | ||||||||||||||||||
| 2108 | const QString newText = itemText(normalized); | - | ||||||||||||||||||
| 2109 | if (lineEdit->text() != newText) {
| 0 | ||||||||||||||||||
| 2110 | lineEdit->setText(newText); // may cause lineEdit -> nullptr (QTBUG-54191) | - | ||||||||||||||||||
| 2111 | #ifndef QT_NO_COMPLETER | - | ||||||||||||||||||
| 2112 | if (lineEdit && lineEdit->completer())
| 0 | ||||||||||||||||||
| 2113 | lineEdit->completer()->setCompletionPrefix(newText); never executed: lineEdit->completer()->setCompletionPrefix(newText); | 0 | ||||||||||||||||||
| 2114 | #endif | - | ||||||||||||||||||
| 2115 | } never executed: end of block | 0 | ||||||||||||||||||
| 2116 | updateLineEditGeometry(); | - | ||||||||||||||||||
| 2117 | } never executed: end of block | 0 | ||||||||||||||||||
| 2118 | if (indexChanged) {
| 0 | ||||||||||||||||||
| 2119 | q->update(); | - | ||||||||||||||||||
| 2120 | _q_emitCurrentIndexChanged(currentIndex); | - | ||||||||||||||||||
| 2121 | } never executed: end of block | 0 | ||||||||||||||||||
| 2122 | } never executed: end of block | 0 | ||||||||||||||||||
| 2123 | - | |||||||||||||||||||
| 2124 | /*! | - | ||||||||||||||||||
| 2125 | \property QComboBox::currentText | - | ||||||||||||||||||
| 2126 | \brief the current text | - | ||||||||||||||||||
| 2127 | - | |||||||||||||||||||
| 2128 | If the combo box is editable, the current text is the value displayed | - | ||||||||||||||||||
| 2129 | by the line edit. Otherwise, it is the value of the current item or | - | ||||||||||||||||||
| 2130 | an empty string if the combo box is empty or no current item is set. | - | ||||||||||||||||||
| 2131 | - | |||||||||||||||||||
| 2132 | The setter setCurrentText() simply calls setEditText() if the combo box is editable. | - | ||||||||||||||||||
| 2133 | Otherwise, if there is a matching text in the list, currentIndex is set to the | - | ||||||||||||||||||
| 2134 | corresponding index. | - | ||||||||||||||||||
| 2135 | - | |||||||||||||||||||
| 2136 | \sa editable, setEditText() | - | ||||||||||||||||||
| 2137 | */ | - | ||||||||||||||||||
| 2138 | QString QComboBox::currentText() const | - | ||||||||||||||||||
| 2139 | { | - | ||||||||||||||||||
| 2140 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 2141 | if (d->lineEdit)
| 0 | ||||||||||||||||||
| 2142 | return d->lineEdit->text(); never executed: return d->lineEdit->text(); | 0 | ||||||||||||||||||
| 2143 | else if (d->currentIndex.isValid())
| 0 | ||||||||||||||||||
| 2144 | return d->itemText(d->currentIndex); never executed: return d->itemText(d->currentIndex); | 0 | ||||||||||||||||||
| 2145 | else | - | ||||||||||||||||||
| 2146 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
| 2147 | } | - | ||||||||||||||||||
| 2148 | - | |||||||||||||||||||
| 2149 | /*! | - | ||||||||||||||||||
| 2150 | \property QComboBox::currentData | - | ||||||||||||||||||
| 2151 | \brief the data for the current item | - | ||||||||||||||||||
| 2152 | \since 5.2 | - | ||||||||||||||||||
| 2153 | - | |||||||||||||||||||
| 2154 | By default, for an empty combo box or a combo box in which no current | - | ||||||||||||||||||
| 2155 | item is set, this property contains an invalid QVariant. | - | ||||||||||||||||||
| 2156 | */ | - | ||||||||||||||||||
| 2157 | QVariant QComboBox::currentData(int role) const | - | ||||||||||||||||||
| 2158 | { | - | ||||||||||||||||||
| 2159 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 2160 | return d->currentIndex.data(role); never executed: return d->currentIndex.data(role); | 0 | ||||||||||||||||||
| 2161 | } | - | ||||||||||||||||||
| 2162 | - | |||||||||||||||||||
| 2163 | /*! | - | ||||||||||||||||||
| 2164 | Returns the text for the given \a index in the combobox. | - | ||||||||||||||||||
| 2165 | */ | - | ||||||||||||||||||
| 2166 | QString QComboBox::itemText(int index) const | - | ||||||||||||||||||
| 2167 | { | - | ||||||||||||||||||
| 2168 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 2169 | QModelIndex mi = d->model->index(index, d->modelColumn, d->root); | - | ||||||||||||||||||
| 2170 | return d->itemText(mi); never executed: return d->itemText(mi); | 0 | ||||||||||||||||||
| 2171 | } | - | ||||||||||||||||||
| 2172 | - | |||||||||||||||||||
| 2173 | /*! | - | ||||||||||||||||||
| 2174 | Returns the icon for the given \a index in the combobox. | - | ||||||||||||||||||
| 2175 | */ | - | ||||||||||||||||||
| 2176 | QIcon QComboBox::itemIcon(int index) const | - | ||||||||||||||||||
| 2177 | { | - | ||||||||||||||||||
| 2178 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 2179 | QModelIndex mi = d->model->index(index, d->modelColumn, d->root); | - | ||||||||||||||||||
| 2180 | return d->itemIcon(mi); never executed: return d->itemIcon(mi); | 0 | ||||||||||||||||||
| 2181 | } | - | ||||||||||||||||||
| 2182 | - | |||||||||||||||||||
| 2183 | /*! | - | ||||||||||||||||||
| 2184 | Returns the data for the given \a role in the given \a index in the | - | ||||||||||||||||||
| 2185 | combobox, or QVariant::Invalid if there is no data for this role. | - | ||||||||||||||||||
| 2186 | */ | - | ||||||||||||||||||
| 2187 | QVariant QComboBox::itemData(int index, int role) const | - | ||||||||||||||||||
| 2188 | { | - | ||||||||||||||||||
| 2189 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 2190 | QModelIndex mi = d->model->index(index, d->modelColumn, d->root); | - | ||||||||||||||||||
| 2191 | return d->model->data(mi, role); never executed: return d->model->data(mi, role); | 0 | ||||||||||||||||||
| 2192 | } | - | ||||||||||||||||||
| 2193 | - | |||||||||||||||||||
| 2194 | /*! | - | ||||||||||||||||||
| 2195 | \fn void QComboBox::insertItem(int index, const QString &text, const QVariant &userData) | - | ||||||||||||||||||
| 2196 | - | |||||||||||||||||||
| 2197 | Inserts the \a text and \a userData (stored in the Qt::UserRole) | - | ||||||||||||||||||
| 2198 | into the combobox at the given \a index. | - | ||||||||||||||||||
| 2199 | - | |||||||||||||||||||
| 2200 | If the index is equal to or higher than the total number of items, | - | ||||||||||||||||||
| 2201 | the new item is appended to the list of existing items. If the | - | ||||||||||||||||||
| 2202 | index is zero or negative, the new item is prepended to the list | - | ||||||||||||||||||
| 2203 | of existing items. | - | ||||||||||||||||||
| 2204 | - | |||||||||||||||||||
| 2205 | \sa insertItems() | - | ||||||||||||||||||
| 2206 | */ | - | ||||||||||||||||||
| 2207 | - | |||||||||||||||||||
| 2208 | /*! | - | ||||||||||||||||||
| 2209 | - | |||||||||||||||||||
| 2210 | Inserts the \a icon, \a text and \a userData (stored in the | - | ||||||||||||||||||
| 2211 | Qt::UserRole) into the combobox at the given \a index. | - | ||||||||||||||||||
| 2212 | - | |||||||||||||||||||
| 2213 | If the index is equal to or higher than the total number of items, | - | ||||||||||||||||||
| 2214 | the new item is appended to the list of existing items. If the | - | ||||||||||||||||||
| 2215 | index is zero or negative, the new item is prepended to the list | - | ||||||||||||||||||
| 2216 | of existing items. | - | ||||||||||||||||||
| 2217 | - | |||||||||||||||||||
| 2218 | \sa insertItems() | - | ||||||||||||||||||
| 2219 | */ | - | ||||||||||||||||||
| 2220 | void QComboBox::insertItem(int index, const QIcon &icon, const QString &text, const QVariant &userData) | - | ||||||||||||||||||
| 2221 | { | - | ||||||||||||||||||
| 2222 | Q_D(QComboBox); | - | ||||||||||||||||||
| 2223 | int itemCount = count(); | - | ||||||||||||||||||
| 2224 | index = qBound(0, index, itemCount); | - | ||||||||||||||||||
| 2225 | if (index >= d->maxCount)
| 0 | ||||||||||||||||||
| 2226 | return; never executed: return; | 0 | ||||||||||||||||||
| 2227 | - | |||||||||||||||||||
| 2228 | // For the common case where we are using the built in QStandardItemModel | - | ||||||||||||||||||
| 2229 | // construct a QStandardItem, reducing the number of expensive signals from the model | - | ||||||||||||||||||
| 2230 | if (QStandardItemModel *m = qobject_cast<QStandardItemModel*>(d->model)) {
| 0 | ||||||||||||||||||
| 2231 | QStandardItem *item = new QStandardItem(text); | - | ||||||||||||||||||
| 2232 | if (!icon.isNull()) item->setData(icon, Qt::DecorationRole); never executed: item->setData(icon, Qt::DecorationRole);
| 0 | ||||||||||||||||||
| 2233 | if (userData.isValid()) item->setData(userData, Qt::UserRole); never executed: item->setData(userData, Qt::UserRole);
| 0 | ||||||||||||||||||
| 2234 | m->insertRow(index, item); | - | ||||||||||||||||||
| 2235 | ++itemCount; | - | ||||||||||||||||||
| 2236 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2237 | d->inserting = true; | - | ||||||||||||||||||
| 2238 | if (d->model->insertRows(index, 1, d->root)) {
| 0 | ||||||||||||||||||
| 2239 | QModelIndex item = d->model->index(index, d->modelColumn, d->root); | - | ||||||||||||||||||
| 2240 | if (icon.isNull() && !userData.isValid()) {
| 0 | ||||||||||||||||||
| 2241 | d->model->setData(item, text, Qt::EditRole); | - | ||||||||||||||||||
| 2242 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2243 | QMap<int, QVariant> values; | - | ||||||||||||||||||
| 2244 | if (!text.isNull()) values.insert(Qt::EditRole, text); never executed: values.insert(Qt::EditRole, text);
| 0 | ||||||||||||||||||
| 2245 | if (!icon.isNull()) values.insert(Qt::DecorationRole, icon); never executed: values.insert(Qt::DecorationRole, icon);
| 0 | ||||||||||||||||||
| 2246 | if (userData.isValid()) values.insert(Qt::UserRole, userData); never executed: values.insert(Qt::UserRole, userData);
| 0 | ||||||||||||||||||
| 2247 | if (!values.isEmpty()) d->model->setItemData(item, values); never executed: d->model->setItemData(item, values);
| 0 | ||||||||||||||||||
| 2248 | } never executed: end of block | 0 | ||||||||||||||||||
| 2249 | d->inserting = false; | - | ||||||||||||||||||
| 2250 | d->_q_rowsInserted(d->root, index, index); | - | ||||||||||||||||||
| 2251 | ++itemCount; | - | ||||||||||||||||||
| 2252 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2253 | d->inserting = false; | - | ||||||||||||||||||
| 2254 | } never executed: end of block | 0 | ||||||||||||||||||
| 2255 | } | - | ||||||||||||||||||
| 2256 | - | |||||||||||||||||||
| 2257 | if (itemCount > d->maxCount)
| 0 | ||||||||||||||||||
| 2258 | d->model->removeRows(itemCount - 1, itemCount - d->maxCount, d->root); never executed: d->model->removeRows(itemCount - 1, itemCount - d->maxCount, d->root); | 0 | ||||||||||||||||||
| 2259 | } never executed: end of block | 0 | ||||||||||||||||||
| 2260 | - | |||||||||||||||||||
| 2261 | /*! | - | ||||||||||||||||||
| 2262 | Inserts the strings from the \a list into the combobox as separate items, | - | ||||||||||||||||||
| 2263 | starting at the \a index specified. | - | ||||||||||||||||||
| 2264 | - | |||||||||||||||||||
| 2265 | If the index is equal to or higher than the total number of items, the new items | - | ||||||||||||||||||
| 2266 | are appended to the list of existing items. If the index is zero or negative, the | - | ||||||||||||||||||
| 2267 | new items are prepended to the list of existing items. | - | ||||||||||||||||||
| 2268 | - | |||||||||||||||||||
| 2269 | \sa insertItem() | - | ||||||||||||||||||
| 2270 | */ | - | ||||||||||||||||||
| 2271 | void QComboBox::insertItems(int index, const QStringList &list) | - | ||||||||||||||||||
| 2272 | { | - | ||||||||||||||||||
| 2273 | Q_D(QComboBox); | - | ||||||||||||||||||
| 2274 | if (list.isEmpty())
| 0 | ||||||||||||||||||
| 2275 | return; never executed: return; | 0 | ||||||||||||||||||
| 2276 | index = qBound(0, index, count()); | - | ||||||||||||||||||
| 2277 | int insertCount = qMin(d->maxCount - index, list.count()); | - | ||||||||||||||||||
| 2278 | if (insertCount <= 0)
| 0 | ||||||||||||||||||
| 2279 | return; never executed: return; | 0 | ||||||||||||||||||
| 2280 | // For the common case where we are using the built in QStandardItemModel | - | ||||||||||||||||||
| 2281 | // construct a QStandardItem, reducing the number of expensive signals from the model | - | ||||||||||||||||||
| 2282 | if (QStandardItemModel *m = qobject_cast<QStandardItemModel*>(d->model)) {
| 0 | ||||||||||||||||||
| 2283 | QList<QStandardItem *> items; | - | ||||||||||||||||||
| 2284 | items.reserve(insertCount); | - | ||||||||||||||||||
| 2285 | QStandardItem *hiddenRoot = m->invisibleRootItem(); | - | ||||||||||||||||||
| 2286 | for (int i = 0; i < insertCount; ++i)
| 0 | ||||||||||||||||||
| 2287 | items.append(new QStandardItem(list.at(i))); never executed: items.append(new QStandardItem(list.at(i))); | 0 | ||||||||||||||||||
| 2288 | hiddenRoot->insertRows(index, items); | - | ||||||||||||||||||
| 2289 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2290 | d->inserting = true; | - | ||||||||||||||||||
| 2291 | if (d->model->insertRows(index, insertCount, d->root)) {
| 0 | ||||||||||||||||||
| 2292 | QModelIndex item; | - | ||||||||||||||||||
| 2293 | for (int i = 0; i < insertCount; ++i) {
| 0 | ||||||||||||||||||
| 2294 | item = d->model->index(i+index, d->modelColumn, d->root); | - | ||||||||||||||||||
| 2295 | d->model->setData(item, list.at(i), Qt::EditRole); | - | ||||||||||||||||||
| 2296 | } never executed: end of block | 0 | ||||||||||||||||||
| 2297 | d->inserting = false; | - | ||||||||||||||||||
| 2298 | d->_q_rowsInserted(d->root, index, index + insertCount - 1); | - | ||||||||||||||||||
| 2299 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2300 | d->inserting = false; | - | ||||||||||||||||||
| 2301 | } never executed: end of block | 0 | ||||||||||||||||||
| 2302 | } | - | ||||||||||||||||||
| 2303 | - | |||||||||||||||||||
| 2304 | int mc = count(); | - | ||||||||||||||||||
| 2305 | if (mc > d->maxCount)
| 0 | ||||||||||||||||||
| 2306 | d->model->removeRows(d->maxCount, mc - d->maxCount, d->root); never executed: d->model->removeRows(d->maxCount, mc - d->maxCount, d->root); | 0 | ||||||||||||||||||
| 2307 | } never executed: end of block | 0 | ||||||||||||||||||
| 2308 | - | |||||||||||||||||||
| 2309 | /*! | - | ||||||||||||||||||
| 2310 | \since 4.4 | - | ||||||||||||||||||
| 2311 | - | |||||||||||||||||||
| 2312 | Inserts a separator item into the combobox at the given \a index. | - | ||||||||||||||||||
| 2313 | - | |||||||||||||||||||
| 2314 | If the index is equal to or higher than the total number of items, the new item | - | ||||||||||||||||||
| 2315 | is appended to the list of existing items. If the index is zero or negative, the | - | ||||||||||||||||||
| 2316 | new item is prepended to the list of existing items. | - | ||||||||||||||||||
| 2317 | - | |||||||||||||||||||
| 2318 | \sa insertItem() | - | ||||||||||||||||||
| 2319 | */ | - | ||||||||||||||||||
| 2320 | void QComboBox::insertSeparator(int index) | - | ||||||||||||||||||
| 2321 | { | - | ||||||||||||||||||
| 2322 | Q_D(QComboBox); | - | ||||||||||||||||||
| 2323 | int itemCount = count(); | - | ||||||||||||||||||
| 2324 | index = qBound(0, index, itemCount); | - | ||||||||||||||||||
| 2325 | if (index >= d->maxCount)
| 0 | ||||||||||||||||||
| 2326 | return; never executed: return; | 0 | ||||||||||||||||||
| 2327 | insertItem(index, QIcon(), QString()); | - | ||||||||||||||||||
| 2328 | QComboBoxDelegate::setSeparator(d->model, d->model->index(index, 0, d->root)); | - | ||||||||||||||||||
| 2329 | } never executed: end of block | 0 | ||||||||||||||||||
| 2330 | - | |||||||||||||||||||
| 2331 | /*! | - | ||||||||||||||||||
| 2332 | Removes the item at the given \a index from the combobox. | - | ||||||||||||||||||
| 2333 | This will update the current index if the index is removed. | - | ||||||||||||||||||
| 2334 | - | |||||||||||||||||||
| 2335 | This function does nothing if \a index is out of range. | - | ||||||||||||||||||
| 2336 | */ | - | ||||||||||||||||||
| 2337 | void QComboBox::removeItem(int index) | - | ||||||||||||||||||
| 2338 | { | - | ||||||||||||||||||
| 2339 | Q_D(QComboBox); | - | ||||||||||||||||||
| 2340 | if (index < 0 || index >= count())
| 0 | ||||||||||||||||||
| 2341 | return; never executed: return; | 0 | ||||||||||||||||||
| 2342 | d->model->removeRows(index, 1, d->root); | - | ||||||||||||||||||
| 2343 | } never executed: end of block | 0 | ||||||||||||||||||
| 2344 | - | |||||||||||||||||||
| 2345 | /*! | - | ||||||||||||||||||
| 2346 | Sets the \a text for the item on the given \a index in the combobox. | - | ||||||||||||||||||
| 2347 | */ | - | ||||||||||||||||||
| 2348 | void QComboBox::setItemText(int index, const QString &text) | - | ||||||||||||||||||
| 2349 | { | - | ||||||||||||||||||
| 2350 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 2351 | QModelIndex item = d->model->index(index, d->modelColumn, d->root); | - | ||||||||||||||||||
| 2352 | if (item.isValid()) {
| 0 | ||||||||||||||||||
| 2353 | d->model->setData(item, text, Qt::EditRole); | - | ||||||||||||||||||
| 2354 | } never executed: end of block | 0 | ||||||||||||||||||
| 2355 | } never executed: end of block | 0 | ||||||||||||||||||
| 2356 | - | |||||||||||||||||||
| 2357 | /*! | - | ||||||||||||||||||
| 2358 | Sets the \a icon for the item on the given \a index in the combobox. | - | ||||||||||||||||||
| 2359 | */ | - | ||||||||||||||||||
| 2360 | void QComboBox::setItemIcon(int index, const QIcon &icon) | - | ||||||||||||||||||
| 2361 | { | - | ||||||||||||||||||
| 2362 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 2363 | QModelIndex item = d->model->index(index, d->modelColumn, d->root); | - | ||||||||||||||||||
| 2364 | if (item.isValid()) {
| 0 | ||||||||||||||||||
| 2365 | d->model->setData(item, icon, Qt::DecorationRole); | - | ||||||||||||||||||
| 2366 | } never executed: end of block | 0 | ||||||||||||||||||
| 2367 | } never executed: end of block | 0 | ||||||||||||||||||
| 2368 | - | |||||||||||||||||||
| 2369 | /*! | - | ||||||||||||||||||
| 2370 | Sets the data \a role for the item on the given \a index in the combobox | - | ||||||||||||||||||
| 2371 | to the specified \a value. | - | ||||||||||||||||||
| 2372 | */ | - | ||||||||||||||||||
| 2373 | void QComboBox::setItemData(int index, const QVariant &value, int role) | - | ||||||||||||||||||
| 2374 | { | - | ||||||||||||||||||
| 2375 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 2376 | QModelIndex item = d->model->index(index, d->modelColumn, d->root); | - | ||||||||||||||||||
| 2377 | if (item.isValid()) {
| 0 | ||||||||||||||||||
| 2378 | d->model->setData(item, value, role); | - | ||||||||||||||||||
| 2379 | } never executed: end of block | 0 | ||||||||||||||||||
| 2380 | } never executed: end of block | 0 | ||||||||||||||||||
| 2381 | - | |||||||||||||||||||
| 2382 | /*! | - | ||||||||||||||||||
| 2383 | Returns the list view used for the combobox popup. | - | ||||||||||||||||||
| 2384 | */ | - | ||||||||||||||||||
| 2385 | QAbstractItemView *QComboBox::view() const | - | ||||||||||||||||||
| 2386 | { | - | ||||||||||||||||||
| 2387 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 2388 | return const_cast<QComboBoxPrivate*>(d)->viewContainer()->itemView(); never executed: return const_cast<QComboBoxPrivate*>(d)->viewContainer()->itemView(); | 0 | ||||||||||||||||||
| 2389 | } | - | ||||||||||||||||||
| 2390 | - | |||||||||||||||||||
| 2391 | /*! | - | ||||||||||||||||||
| 2392 | Sets the view to be used in the combobox popup to the given \a | - | ||||||||||||||||||
| 2393 | itemView. The combobox takes ownership of the view. | - | ||||||||||||||||||
| 2394 | - | |||||||||||||||||||
| 2395 | Note: If you want to use the convenience views (like QListWidget, | - | ||||||||||||||||||
| 2396 | QTableWidget or QTreeWidget), make sure to call setModel() on the | - | ||||||||||||||||||
| 2397 | combobox with the convenience widgets model before calling this | - | ||||||||||||||||||
| 2398 | function. | - | ||||||||||||||||||
| 2399 | */ | - | ||||||||||||||||||
| 2400 | void QComboBox::setView(QAbstractItemView *itemView) | - | ||||||||||||||||||
| 2401 | { | - | ||||||||||||||||||
| 2402 | Q_D(QComboBox); | - | ||||||||||||||||||
| 2403 | if (!itemView) {
| 0 | ||||||||||||||||||
| 2404 | qWarning("QComboBox::setView: cannot set a 0 view"); | - | ||||||||||||||||||
| 2405 | return; never executed: return; | 0 | ||||||||||||||||||
| 2406 | } | - | ||||||||||||||||||
| 2407 | - | |||||||||||||||||||
| 2408 | if (itemView->model() != d->model)
| 0 | ||||||||||||||||||
| 2409 | itemView->setModel(d->model); never executed: itemView->setModel(d->model); | 0 | ||||||||||||||||||
| 2410 | d->viewContainer()->setItemView(itemView); | - | ||||||||||||||||||
| 2411 | } never executed: end of block | 0 | ||||||||||||||||||
| 2412 | - | |||||||||||||||||||
| 2413 | /*! | - | ||||||||||||||||||
| 2414 | \reimp | - | ||||||||||||||||||
| 2415 | */ | - | ||||||||||||||||||
| 2416 | QSize QComboBox::minimumSizeHint() const | - | ||||||||||||||||||
| 2417 | { | - | ||||||||||||||||||
| 2418 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 2419 | return d->recomputeSizeHint(d->minimumSizeHint); never executed: return d->recomputeSizeHint(d->minimumSizeHint); | 0 | ||||||||||||||||||
| 2420 | } | - | ||||||||||||||||||
| 2421 | - | |||||||||||||||||||
| 2422 | /*! | - | ||||||||||||||||||
| 2423 | \reimp | - | ||||||||||||||||||
| 2424 | - | |||||||||||||||||||
| 2425 | This implementation caches the size hint to avoid resizing when | - | ||||||||||||||||||
| 2426 | the contents change dynamically. To invalidate the cached value | - | ||||||||||||||||||
| 2427 | change the \l sizeAdjustPolicy. | - | ||||||||||||||||||
| 2428 | */ | - | ||||||||||||||||||
| 2429 | QSize QComboBox::sizeHint() const | - | ||||||||||||||||||
| 2430 | { | - | ||||||||||||||||||
| 2431 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 2432 | return d->recomputeSizeHint(d->sizeHint); never executed: return d->recomputeSizeHint(d->sizeHint); | 0 | ||||||||||||||||||
| 2433 | } | - | ||||||||||||||||||
| 2434 | - | |||||||||||||||||||
| 2435 | #ifdef Q_OS_MAC | - | ||||||||||||||||||
| 2436 | - | |||||||||||||||||||
| 2437 | namespace { | - | ||||||||||||||||||
| 2438 | struct IndexSetter { | - | ||||||||||||||||||
| 2439 | int index; | - | ||||||||||||||||||
| 2440 | QComboBox *cb; | - | ||||||||||||||||||
| 2441 | - | |||||||||||||||||||
| 2442 | void operator()(void) | - | ||||||||||||||||||
| 2443 | { | - | ||||||||||||||||||
| 2444 | cb->setCurrentIndex(index); | - | ||||||||||||||||||
| 2445 | emit cb->activated(index); | - | ||||||||||||||||||
| 2446 | emit cb->activated(cb->itemText(index)); | - | ||||||||||||||||||
| 2447 | } | - | ||||||||||||||||||
| 2448 | }; | - | ||||||||||||||||||
| 2449 | } | - | ||||||||||||||||||
| 2450 | - | |||||||||||||||||||
| 2451 | void QComboBoxPrivate::cleanupNativePopup() | - | ||||||||||||||||||
| 2452 | { | - | ||||||||||||||||||
| 2453 | if (!m_platformMenu) | - | ||||||||||||||||||
| 2454 | return; | - | ||||||||||||||||||
| 2455 | - | |||||||||||||||||||
| 2456 | int count = int(m_platformMenu->tag()); | - | ||||||||||||||||||
| 2457 | for (int i = 0; i < count; ++i) | - | ||||||||||||||||||
| 2458 | m_platformMenu->menuItemAt(i)->deleteLater(); | - | ||||||||||||||||||
| 2459 | - | |||||||||||||||||||
| 2460 | delete m_platformMenu; | - | ||||||||||||||||||
| 2461 | m_platformMenu = 0; | - | ||||||||||||||||||
| 2462 | } | - | ||||||||||||||||||
| 2463 | - | |||||||||||||||||||
| 2464 | /*! | - | ||||||||||||||||||
| 2465 | * \internal | - | ||||||||||||||||||
| 2466 | * | - | ||||||||||||||||||
| 2467 | * Tries to show a native popup. Returns true if it could, false otherwise. | - | ||||||||||||||||||
| 2468 | * | - | ||||||||||||||||||
| 2469 | */ | - | ||||||||||||||||||
| 2470 | bool QComboBoxPrivate::showNativePopup() | - | ||||||||||||||||||
| 2471 | { | - | ||||||||||||||||||
| 2472 | Q_Q(QComboBox); | - | ||||||||||||||||||
| 2473 | - | |||||||||||||||||||
| 2474 | cleanupNativePopup(); | - | ||||||||||||||||||
| 2475 | - | |||||||||||||||||||
| 2476 | QPlatformTheme *theme = QGuiApplicationPrivate::instance()->platformTheme(); | - | ||||||||||||||||||
| 2477 | m_platformMenu = theme->createPlatformMenu(); | - | ||||||||||||||||||
| 2478 | if (!m_platformMenu) | - | ||||||||||||||||||
| 2479 | return false; | - | ||||||||||||||||||
| 2480 | - | |||||||||||||||||||
| 2481 | int itemsCount = q->count(); | - | ||||||||||||||||||
| 2482 | m_platformMenu->setTag(quintptr(itemsCount)); | - | ||||||||||||||||||
| 2483 | - | |||||||||||||||||||
| 2484 | QPlatformMenuItem *currentItem = 0; | - | ||||||||||||||||||
| 2485 | int currentIndex = q->currentIndex(); | - | ||||||||||||||||||
| 2486 | - | |||||||||||||||||||
| 2487 | for (int i = 0; i < itemsCount; ++i) { | - | ||||||||||||||||||
| 2488 | QPlatformMenuItem *item = theme->createPlatformMenuItem(); | - | ||||||||||||||||||
| 2489 | QModelIndex rowIndex = model->index(i, modelColumn, root); | - | ||||||||||||||||||
| 2490 | QVariant textVariant = model->data(rowIndex, Qt::EditRole); | - | ||||||||||||||||||
| 2491 | item->setText(textVariant.toString()); | - | ||||||||||||||||||
| 2492 | QVariant iconVariant = model->data(rowIndex, Qt::DecorationRole); | - | ||||||||||||||||||
| 2493 | if (iconVariant.canConvert<QIcon>()) | - | ||||||||||||||||||
| 2494 | item->setIcon(iconVariant.value<QIcon>()); | - | ||||||||||||||||||
| 2495 | item->setCheckable(true); | - | ||||||||||||||||||
| 2496 | item->setChecked(i == currentIndex); | - | ||||||||||||||||||
| 2497 | if (!currentItem || i == currentIndex) | - | ||||||||||||||||||
| 2498 | currentItem = item; | - | ||||||||||||||||||
| 2499 | - | |||||||||||||||||||
| 2500 | IndexSetter setter = { i, q }; | - | ||||||||||||||||||
| 2501 | QObject::connect(item, &QPlatformMenuItem::activated, setter); | - | ||||||||||||||||||
| 2502 | - | |||||||||||||||||||
| 2503 | m_platformMenu->insertMenuItem(item, 0); | - | ||||||||||||||||||
| 2504 | m_platformMenu->syncMenuItem(item); | - | ||||||||||||||||||
| 2505 | } | - | ||||||||||||||||||
| 2506 | - | |||||||||||||||||||
| 2507 | QWindow *tlw = q->window()->windowHandle(); | - | ||||||||||||||||||
| 2508 | m_platformMenu->setFont(q->font()); | - | ||||||||||||||||||
| 2509 | m_platformMenu->setMinimumWidth(q->rect().width()); | - | ||||||||||||||||||
| 2510 | QPoint offset = QPoint(0, 7); | - | ||||||||||||||||||
| 2511 | if (q->testAttribute(Qt::WA_MacSmallSize)) | - | ||||||||||||||||||
| 2512 | offset = QPoint(-1, 7); | - | ||||||||||||||||||
| 2513 | else if (q->testAttribute(Qt::WA_MacMiniSize)) | - | ||||||||||||||||||
| 2514 | offset = QPoint(-2, 6); | - | ||||||||||||||||||
| 2515 | - | |||||||||||||||||||
| 2516 | m_platformMenu->showPopup(tlw, QRect(tlw->mapFromGlobal(q->mapToGlobal(offset)), QSize()), currentItem); | - | ||||||||||||||||||
| 2517 | - | |||||||||||||||||||
| 2518 | #ifdef Q_OS_OSX | - | ||||||||||||||||||
| 2519 | // The Cocoa popup will swallow any mouse release event. | - | ||||||||||||||||||
| 2520 | // We need to fake one here to un-press the button. | - | ||||||||||||||||||
| 2521 | QMouseEvent mouseReleased(QEvent::MouseButtonRelease, q->pos(), Qt::LeftButton, | - | ||||||||||||||||||
| 2522 | Qt::MouseButtons(Qt::LeftButton), Qt::KeyboardModifiers()); | - | ||||||||||||||||||
| 2523 | qApp->sendEvent(q, &mouseReleased); | - | ||||||||||||||||||
| 2524 | #endif | - | ||||||||||||||||||
| 2525 | - | |||||||||||||||||||
| 2526 | return true; | - | ||||||||||||||||||
| 2527 | } | - | ||||||||||||||||||
| 2528 | - | |||||||||||||||||||
| 2529 | #endif // Q_OS_MAC | - | ||||||||||||||||||
| 2530 | - | |||||||||||||||||||
| 2531 | /*! | - | ||||||||||||||||||
| 2532 | Displays the list of items in the combobox. If the list is empty | - | ||||||||||||||||||
| 2533 | then the no items will be shown. | - | ||||||||||||||||||
| 2534 | - | |||||||||||||||||||
| 2535 | If you reimplement this function to show a custom pop-up, make | - | ||||||||||||||||||
| 2536 | sure you call hidePopup() to reset the internal state. | - | ||||||||||||||||||
| 2537 | - | |||||||||||||||||||
| 2538 | \sa hidePopup() | - | ||||||||||||||||||
| 2539 | */ | - | ||||||||||||||||||
| 2540 | void QComboBox::showPopup() | - | ||||||||||||||||||
| 2541 | { | - | ||||||||||||||||||
| 2542 | Q_D(QComboBox); | - | ||||||||||||||||||
| 2543 | if (count() <= 0)
| 0 | ||||||||||||||||||
| 2544 | return; never executed: return; | 0 | ||||||||||||||||||
| 2545 | - | |||||||||||||||||||
| 2546 | QStyle * const style = this->style(); | - | ||||||||||||||||||
| 2547 | QStyleOptionComboBox opt; | - | ||||||||||||||||||
| 2548 | initStyleOption(&opt); | - | ||||||||||||||||||
| 2549 | const bool usePopup = style->styleHint(QStyle::SH_ComboBox_Popup, &opt, this); | - | ||||||||||||||||||
| 2550 | - | |||||||||||||||||||
| 2551 | #ifdef Q_OS_MAC | - | ||||||||||||||||||
| 2552 | if (usePopup | - | ||||||||||||||||||
| 2553 | && (!d->container | - | ||||||||||||||||||
| 2554 | || (view()->metaObject()->className() == QByteArray("QComboBoxListView") | - | ||||||||||||||||||
| 2555 | && view()->itemDelegate()->metaObject()->className() == QByteArray("QComboMenuDelegate"))) | - | ||||||||||||||||||
| 2556 | && style->styleHint(QStyle::SH_ComboBox_UseNativePopup, &opt, this) | - | ||||||||||||||||||
| 2557 | && d->showNativePopup()) | - | ||||||||||||||||||
| 2558 | return; | - | ||||||||||||||||||
| 2559 | #endif // Q_OS_MAC | - | ||||||||||||||||||
| 2560 | - | |||||||||||||||||||
| 2561 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
| 2562 | #ifndef QT_NO_COMPLETER | - | ||||||||||||||||||
| 2563 | if (QApplication::keypadNavigationEnabled() && d->completer) { | - | ||||||||||||||||||
| 2564 | // editable combo box is line edit plus completer | - | ||||||||||||||||||
| 2565 | setEditFocus(true); | - | ||||||||||||||||||
| 2566 | d->completer->complete(); // show popup | - | ||||||||||||||||||
| 2567 | return; | - | ||||||||||||||||||
| 2568 | } | - | ||||||||||||||||||
| 2569 | #endif | - | ||||||||||||||||||
| 2570 | #endif | - | ||||||||||||||||||
| 2571 | - | |||||||||||||||||||
| 2572 | // set current item and select it | - | ||||||||||||||||||
| 2573 | view()->selectionModel()->setCurrentIndex(d->currentIndex, | - | ||||||||||||||||||
| 2574 | QItemSelectionModel::ClearAndSelect); | - | ||||||||||||||||||
| 2575 | QComboBoxPrivateContainer* container = d->viewContainer(); | - | ||||||||||||||||||
| 2576 | QRect listRect(style->subControlRect(QStyle::CC_ComboBox, &opt, | - | ||||||||||||||||||
| 2577 | QStyle::SC_ComboBoxListBoxPopup, this)); | - | ||||||||||||||||||
| 2578 | QRect screen = d->popupGeometry(QApplication::desktop()->screenNumber(this)); | - | ||||||||||||||||||
| 2579 | - | |||||||||||||||||||
| 2580 | QPoint below = mapToGlobal(listRect.bottomLeft()); | - | ||||||||||||||||||
| 2581 | int belowHeight = screen.bottom() - below.y(); | - | ||||||||||||||||||
| 2582 | QPoint above = mapToGlobal(listRect.topLeft()); | - | ||||||||||||||||||
| 2583 | int aboveHeight = above.y() - screen.y(); | - | ||||||||||||||||||
| 2584 | bool boundToScreen = !window()->testAttribute(Qt::WA_DontShowOnScreen); | - | ||||||||||||||||||
| 2585 | - | |||||||||||||||||||
| 2586 | { | - | ||||||||||||||||||
| 2587 | int listHeight = 0; | - | ||||||||||||||||||
| 2588 | int count = 0; | - | ||||||||||||||||||
| 2589 | QStack<QModelIndex> toCheck; | - | ||||||||||||||||||
| 2590 | toCheck.push(view()->rootIndex()); | - | ||||||||||||||||||
| 2591 | #ifndef QT_NO_TREEVIEW | - | ||||||||||||||||||
| 2592 | QTreeView *treeView = qobject_cast<QTreeView*>(view()); | - | ||||||||||||||||||
| 2593 | if (treeView && treeView->header() && !treeView->header()->isHidden())
| 0 | ||||||||||||||||||
| 2594 | listHeight += treeView->header()->height(); never executed: listHeight += treeView->header()->height(); | 0 | ||||||||||||||||||
| 2595 | #endif | - | ||||||||||||||||||
| 2596 | while (!toCheck.isEmpty()) {
| 0 | ||||||||||||||||||
| 2597 | QModelIndex parent = toCheck.pop(); | - | ||||||||||||||||||
| 2598 | for (int i = 0; i < d->model->rowCount(parent); ++i) {
| 0 | ||||||||||||||||||
| 2599 | QModelIndex idx = d->model->index(i, d->modelColumn, parent); | - | ||||||||||||||||||
| 2600 | if (!idx.isValid())
| 0 | ||||||||||||||||||
| 2601 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 2602 | listHeight += view()->visualRect(idx).height(); | - | ||||||||||||||||||
| 2603 | #ifndef QT_NO_TREEVIEW | - | ||||||||||||||||||
| 2604 | if (d->model->hasChildren(idx) && treeView && treeView->isExpanded(idx))
| 0 | ||||||||||||||||||
| 2605 | toCheck.push(idx); never executed: toCheck.push(idx); | 0 | ||||||||||||||||||
| 2606 | #endif | - | ||||||||||||||||||
| 2607 | ++count; | - | ||||||||||||||||||
| 2608 | if (!usePopup && count >= d->maxVisibleItems) {
| 0 | ||||||||||||||||||
| 2609 | toCheck.clear(); | - | ||||||||||||||||||
| 2610 | break; never executed: break; | 0 | ||||||||||||||||||
| 2611 | } | - | ||||||||||||||||||
| 2612 | } never executed: end of block | 0 | ||||||||||||||||||
| 2613 | } never executed: end of block | 0 | ||||||||||||||||||
| 2614 | if (count > 1)
| 0 | ||||||||||||||||||
| 2615 | listHeight += (count - 1) * container->spacing(); never executed: listHeight += (count - 1) * container->spacing(); | 0 | ||||||||||||||||||
| 2616 | listRect.setHeight(listHeight); | - | ||||||||||||||||||
| 2617 | } | - | ||||||||||||||||||
| 2618 | - | |||||||||||||||||||
| 2619 | { | - | ||||||||||||||||||
| 2620 | // add the spacing for the grid on the top and the bottom; | - | ||||||||||||||||||
| 2621 | int heightMargin = container->topMargin() + container->bottomMargin(); | - | ||||||||||||||||||
| 2622 | - | |||||||||||||||||||
| 2623 | // add the frame of the container | - | ||||||||||||||||||
| 2624 | int marginTop, marginBottom; | - | ||||||||||||||||||
| 2625 | container->getContentsMargins(0, &marginTop, 0, &marginBottom); | - | ||||||||||||||||||
| 2626 | heightMargin += marginTop + marginBottom; | - | ||||||||||||||||||
| 2627 | - | |||||||||||||||||||
| 2628 | //add the frame of the view | - | ||||||||||||||||||
| 2629 | view()->getContentsMargins(0, &marginTop, 0, &marginBottom); | - | ||||||||||||||||||
| 2630 | marginTop += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->top; | - | ||||||||||||||||||
| 2631 | marginBottom += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->bottom; | - | ||||||||||||||||||
| 2632 | heightMargin += marginTop + marginBottom; | - | ||||||||||||||||||
| 2633 | - | |||||||||||||||||||
| 2634 | listRect.setHeight(listRect.height() + heightMargin); | - | ||||||||||||||||||
| 2635 | } | - | ||||||||||||||||||
| 2636 | - | |||||||||||||||||||
| 2637 | // Add space for margin at top and bottom if the style wants it. | - | ||||||||||||||||||
| 2638 | if (usePopup)
| 0 | ||||||||||||||||||
| 2639 | listRect.setHeight(listRect.height() + style->pixelMetric(QStyle::PM_MenuVMargin, &opt, this) * 2); never executed: listRect.setHeight(listRect.height() + style->pixelMetric(QStyle::PM_MenuVMargin, &opt, this) * 2); | 0 | ||||||||||||||||||
| 2640 | - | |||||||||||||||||||
| 2641 | // Make sure the popup is wide enough to display its contents. | - | ||||||||||||||||||
| 2642 | if (usePopup) {
| 0 | ||||||||||||||||||
| 2643 | const int diff = d->computeWidthHint() - width(); | - | ||||||||||||||||||
| 2644 | if (diff > 0)
| 0 | ||||||||||||||||||
| 2645 | listRect.setWidth(listRect.width() + diff); never executed: listRect.setWidth(listRect.width() + diff); | 0 | ||||||||||||||||||
| 2646 | } never executed: end of block | 0 | ||||||||||||||||||
| 2647 | - | |||||||||||||||||||
| 2648 | //we need to activate the layout to make sure the min/maximum size are set when the widget was not yet show | - | ||||||||||||||||||
| 2649 | container->layout()->activate(); | - | ||||||||||||||||||
| 2650 | //takes account of the minimum/maximum size of the container | - | ||||||||||||||||||
| 2651 | listRect.setSize( listRect.size().expandedTo(container->minimumSize()) | - | ||||||||||||||||||
| 2652 | .boundedTo(container->maximumSize())); | - | ||||||||||||||||||
| 2653 | - | |||||||||||||||||||
| 2654 | // make sure the widget fits on screen | - | ||||||||||||||||||
| 2655 | if (boundToScreen) {
| 0 | ||||||||||||||||||
| 2656 | if (listRect.width() > screen.width() )
| 0 | ||||||||||||||||||
| 2657 | listRect.setWidth(screen.width()); never executed: listRect.setWidth(screen.width()); | 0 | ||||||||||||||||||
| 2658 | if (mapToGlobal(listRect.bottomRight()).x() > screen.right()) {
| 0 | ||||||||||||||||||
| 2659 | below.setX(screen.x() + screen.width() - listRect.width()); | - | ||||||||||||||||||
| 2660 | above.setX(screen.x() + screen.width() - listRect.width()); | - | ||||||||||||||||||
| 2661 | } never executed: end of block | 0 | ||||||||||||||||||
| 2662 | if (mapToGlobal(listRect.topLeft()).x() < screen.x() ) {
| 0 | ||||||||||||||||||
| 2663 | below.setX(screen.x()); | - | ||||||||||||||||||
| 2664 | above.setX(screen.x()); | - | ||||||||||||||||||
| 2665 | } never executed: end of block | 0 | ||||||||||||||||||
| 2666 | } never executed: end of block | 0 | ||||||||||||||||||
| 2667 | - | |||||||||||||||||||
| 2668 | if (usePopup) {
| 0 | ||||||||||||||||||
| 2669 | // Position horizontally. | - | ||||||||||||||||||
| 2670 | listRect.moveLeft(above.x()); | - | ||||||||||||||||||
| 2671 | - | |||||||||||||||||||
| 2672 | // Position vertically so the curently selected item lines up | - | ||||||||||||||||||
| 2673 | // with the combo box. | - | ||||||||||||||||||
| 2674 | const QRect currentItemRect = view()->visualRect(view()->currentIndex()); | - | ||||||||||||||||||
| 2675 | const int offset = listRect.top() - currentItemRect.top(); | - | ||||||||||||||||||
| 2676 | listRect.moveTop(above.y() + offset - listRect.top()); | - | ||||||||||||||||||
| 2677 | - | |||||||||||||||||||
| 2678 | // Clamp the listRect height and vertical position so we don't expand outside the | - | ||||||||||||||||||
| 2679 | // available screen geometry.This may override the vertical position, but it is more | - | ||||||||||||||||||
| 2680 | // important to show as much as possible of the popup. | - | ||||||||||||||||||
| 2681 | const int height = !boundToScreen ? listRect.height() : qMin(listRect.height(), screen.height());
| 0 | ||||||||||||||||||
| 2682 | listRect.setHeight(height); | - | ||||||||||||||||||
| 2683 | - | |||||||||||||||||||
| 2684 | if (boundToScreen) {
| 0 | ||||||||||||||||||
| 2685 | if (listRect.top() < screen.top())
| 0 | ||||||||||||||||||
| 2686 | listRect.moveTop(screen.top()); never executed: listRect.moveTop(screen.top()); | 0 | ||||||||||||||||||
| 2687 | if (listRect.bottom() > screen.bottom())
| 0 | ||||||||||||||||||
| 2688 | listRect.moveBottom(screen.bottom()); never executed: listRect.moveBottom(screen.bottom()); | 0 | ||||||||||||||||||
| 2689 | } never executed: end of block | 0 | ||||||||||||||||||
| 2690 | } else if (!boundToScreen || listRect.height() <= belowHeight) { never executed: end of block
| 0 | ||||||||||||||||||
| 2691 | listRect.moveTopLeft(below); | - | ||||||||||||||||||
| 2692 | } else if (listRect.height() <= aboveHeight) { never executed: end of block
| 0 | ||||||||||||||||||
| 2693 | listRect.moveBottomLeft(above); | - | ||||||||||||||||||
| 2694 | } else if (belowHeight >= aboveHeight) { never executed: end of block
| 0 | ||||||||||||||||||
| 2695 | listRect.setHeight(belowHeight); | - | ||||||||||||||||||
| 2696 | listRect.moveTopLeft(below); | - | ||||||||||||||||||
| 2697 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2698 | listRect.setHeight(aboveHeight); | - | ||||||||||||||||||
| 2699 | listRect.moveBottomLeft(above); | - | ||||||||||||||||||
| 2700 | } never executed: end of block | 0 | ||||||||||||||||||
| 2701 | - | |||||||||||||||||||
| 2702 | if (qApp) {
| 0 | ||||||||||||||||||
| 2703 | QGuiApplication::inputMethod()->reset(); | - | ||||||||||||||||||
| 2704 | } never executed: end of block | 0 | ||||||||||||||||||
| 2705 | - | |||||||||||||||||||
| 2706 | QScrollBar *sb = view()->horizontalScrollBar(); | - | ||||||||||||||||||
| 2707 | Qt::ScrollBarPolicy policy = view()->horizontalScrollBarPolicy(); | - | ||||||||||||||||||
| 2708 | bool needHorizontalScrollBar = (policy == Qt::ScrollBarAsNeeded || policy == Qt::ScrollBarAlwaysOn)
| 0 | ||||||||||||||||||
| 2709 | && sb->minimum() < sb->maximum();
| 0 | ||||||||||||||||||
| 2710 | if (needHorizontalScrollBar) {
| 0 | ||||||||||||||||||
| 2711 | listRect.adjust(0, 0, 0, sb->height()); | - | ||||||||||||||||||
| 2712 | } never executed: end of block | 0 | ||||||||||||||||||
| 2713 | container->setGeometry(listRect); | - | ||||||||||||||||||
| 2714 | - | |||||||||||||||||||
| 2715 | #ifndef Q_OS_MAC | - | ||||||||||||||||||
| 2716 | const bool updatesEnabled = container->updatesEnabled(); | - | ||||||||||||||||||
| 2717 | #endif | - | ||||||||||||||||||
| 2718 | - | |||||||||||||||||||
| 2719 | #if !defined(QT_NO_EFFECTS) | - | ||||||||||||||||||
| 2720 | bool scrollDown = (listRect.topLeft() == below); | - | ||||||||||||||||||
| 2721 | if (QApplication::isEffectEnabled(Qt::UI_AnimateCombo)
| 0 | ||||||||||||||||||
| 2722 | && !style->styleHint(QStyle::SH_ComboBox_Popup, &opt, this) && !window()->testAttribute(Qt::WA_DontShowOnScreen))
| 0 | ||||||||||||||||||
| 2723 | qScrollEffect(container, scrollDown ? QEffects::DownScroll : QEffects::UpScroll, 150); never executed: qScrollEffect(container, scrollDown ? QEffects::DownScroll : QEffects::UpScroll, 150); | 0 | ||||||||||||||||||
| 2724 | #endif | - | ||||||||||||||||||
| 2725 | - | |||||||||||||||||||
| 2726 | // Don't disable updates on OS X. Windows are displayed immediately on this platform, | - | ||||||||||||||||||
| 2727 | // which means that the window will be visible before the call to container->show() returns. | - | ||||||||||||||||||
| 2728 | // If updates are disabled at this point we'll miss our chance at painting the popup | - | ||||||||||||||||||
| 2729 | // menu before it's shown, causing flicker since the window then displays the standard gray | - | ||||||||||||||||||
| 2730 | // background. | - | ||||||||||||||||||
| 2731 | #ifndef Q_OS_MAC | - | ||||||||||||||||||
| 2732 | container->setUpdatesEnabled(false); | - | ||||||||||||||||||
| 2733 | #endif | - | ||||||||||||||||||
| 2734 | - | |||||||||||||||||||
| 2735 | bool startTimer = !container->isVisible(); | - | ||||||||||||||||||
| 2736 | container->raise(); | - | ||||||||||||||||||
| 2737 | container->show(); | - | ||||||||||||||||||
| 2738 | container->updateScrollers(); | - | ||||||||||||||||||
| 2739 | view()->setFocus(); | - | ||||||||||||||||||
| 2740 | - | |||||||||||||||||||
| 2741 | view()->scrollTo(view()->currentIndex(), | - | ||||||||||||||||||
| 2742 | style->styleHint(QStyle::SH_ComboBox_Popup, &opt, this) | - | ||||||||||||||||||
| 2743 | ? QAbstractItemView::PositionAtCenter | - | ||||||||||||||||||
| 2744 | : QAbstractItemView::EnsureVisible); | - | ||||||||||||||||||
| 2745 | - | |||||||||||||||||||
| 2746 | #ifndef Q_OS_MAC | - | ||||||||||||||||||
| 2747 | container->setUpdatesEnabled(updatesEnabled); | - | ||||||||||||||||||
| 2748 | #endif | - | ||||||||||||||||||
| 2749 | - | |||||||||||||||||||
| 2750 | container->update(); | - | ||||||||||||||||||
| 2751 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
| 2752 | if (QApplication::keypadNavigationEnabled()) | - | ||||||||||||||||||
| 2753 | view()->setEditFocus(true); | - | ||||||||||||||||||
| 2754 | #endif | - | ||||||||||||||||||
| 2755 | if (startTimer) {
| 0 | ||||||||||||||||||
| 2756 | container->popupTimer.start(); | - | ||||||||||||||||||
| 2757 | container->maybeIgnoreMouseButtonRelease = true; | - | ||||||||||||||||||
| 2758 | } never executed: end of block | 0 | ||||||||||||||||||
| 2759 | } never executed: end of block | 0 | ||||||||||||||||||
| 2760 | - | |||||||||||||||||||
| 2761 | /*! | - | ||||||||||||||||||
| 2762 | Hides the list of items in the combobox if it is currently visible | - | ||||||||||||||||||
| 2763 | and resets the internal state, so that if the custom pop-up was | - | ||||||||||||||||||
| 2764 | shown inside the reimplemented showPopup(), then you also need to | - | ||||||||||||||||||
| 2765 | reimplement the hidePopup() function to hide your custom pop-up | - | ||||||||||||||||||
| 2766 | and call the base class implementation to reset the internal state | - | ||||||||||||||||||
| 2767 | whenever your custom pop-up widget is hidden. | - | ||||||||||||||||||
| 2768 | - | |||||||||||||||||||
| 2769 | \sa showPopup() | - | ||||||||||||||||||
| 2770 | */ | - | ||||||||||||||||||
| 2771 | void QComboBox::hidePopup() | - | ||||||||||||||||||
| 2772 | { | - | ||||||||||||||||||
| 2773 | Q_D(QComboBox); | - | ||||||||||||||||||
| 2774 | if (d->container && d->container->isVisible()) {
| 0 | ||||||||||||||||||
| 2775 | #if !defined(QT_NO_EFFECTS) | - | ||||||||||||||||||
| 2776 | QSignalBlocker modelBlocker(d->model); | - | ||||||||||||||||||
| 2777 | QSignalBlocker viewBlocker(d->container->itemView()); | - | ||||||||||||||||||
| 2778 | QSignalBlocker containerBlocker(d->container); | - | ||||||||||||||||||
| 2779 | // Flash selected/triggered item (if any). | - | ||||||||||||||||||
| 2780 | if (style()->styleHint(QStyle::SH_Menu_FlashTriggeredItem)) {
| 0 | ||||||||||||||||||
| 2781 | QItemSelectionModel *selectionModel = view() ? view()->selectionModel() : 0;
| 0 | ||||||||||||||||||
| 2782 | if (selectionModel && selectionModel->hasSelection()) {
| 0 | ||||||||||||||||||
| 2783 | QEventLoop eventLoop; | - | ||||||||||||||||||
| 2784 | const QItemSelection selection = selectionModel->selection(); | - | ||||||||||||||||||
| 2785 | - | |||||||||||||||||||
| 2786 | // Deselect item and wait 60 ms. | - | ||||||||||||||||||
| 2787 | selectionModel->select(selection, QItemSelectionModel::Toggle); | - | ||||||||||||||||||
| 2788 | QTimer::singleShot(60, &eventLoop, SLOT(quit())); | - | ||||||||||||||||||
| 2789 | eventLoop.exec(); | - | ||||||||||||||||||
| 2790 | - | |||||||||||||||||||
| 2791 | // Select item and wait 20 ms. | - | ||||||||||||||||||
| 2792 | selectionModel->select(selection, QItemSelectionModel::Toggle); | - | ||||||||||||||||||
| 2793 | QTimer::singleShot(20, &eventLoop, SLOT(quit())); | - | ||||||||||||||||||
| 2794 | eventLoop.exec(); | - | ||||||||||||||||||
| 2795 | } never executed: end of block | 0 | ||||||||||||||||||
| 2796 | } never executed: end of block | 0 | ||||||||||||||||||
| 2797 | - | |||||||||||||||||||
| 2798 | // Fade out. | - | ||||||||||||||||||
| 2799 | bool needFade = style()->styleHint(QStyle::SH_Menu_FadeOutOnHide); | - | ||||||||||||||||||
| 2800 | bool didFade = false; | - | ||||||||||||||||||
| 2801 | if (needFade) {
| 0 | ||||||||||||||||||
| 2802 | #if defined(Q_OS_MAC) | - | ||||||||||||||||||
| 2803 | QPlatformNativeInterface *platformNativeInterface = qApp->platformNativeInterface(); | - | ||||||||||||||||||
| 2804 | int at = platformNativeInterface->metaObject()->indexOfMethod("fadeWindow()"); | - | ||||||||||||||||||
| 2805 | if (at != -1) { | - | ||||||||||||||||||
| 2806 | QMetaMethod windowFade = platformNativeInterface->metaObject()->method(at); | - | ||||||||||||||||||
| 2807 | windowFade.invoke(platformNativeInterface, Q_ARG(QWindow *, d->container->windowHandle())); | - | ||||||||||||||||||
| 2808 | didFade = true; | - | ||||||||||||||||||
| 2809 | } | - | ||||||||||||||||||
| 2810 | - | |||||||||||||||||||
| 2811 | #endif // Q_OS_MAC | - | ||||||||||||||||||
| 2812 | // Other platform implementations welcome :-) | - | ||||||||||||||||||
| 2813 | } never executed: end of block | 0 | ||||||||||||||||||
| 2814 | containerBlocker.unblock(); | - | ||||||||||||||||||
| 2815 | viewBlocker.unblock(); | - | ||||||||||||||||||
| 2816 | modelBlocker.unblock(); | - | ||||||||||||||||||
| 2817 | - | |||||||||||||||||||
| 2818 | if (!didFade)
| 0 | ||||||||||||||||||
| 2819 | #endif // QT_NO_EFFECTS | - | ||||||||||||||||||
| 2820 | // Fade should implicitly hide as well ;-) | - | ||||||||||||||||||
| 2821 | d->container->hide(); never executed: d->container->hide(); | 0 | ||||||||||||||||||
| 2822 | } never executed: end of block | 0 | ||||||||||||||||||
| 2823 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
| 2824 | if (QApplication::keypadNavigationEnabled() && isEditable() && hasFocus()) | - | ||||||||||||||||||
| 2825 | setEditFocus(true); | - | ||||||||||||||||||
| 2826 | #endif | - | ||||||||||||||||||
| 2827 | d->_q_resetButton(); | - | ||||||||||||||||||
| 2828 | } never executed: end of block | 0 | ||||||||||||||||||
| 2829 | - | |||||||||||||||||||
| 2830 | /*! | - | ||||||||||||||||||
| 2831 | Clears the combobox, removing all items. | - | ||||||||||||||||||
| 2832 | - | |||||||||||||||||||
| 2833 | Note: If you have set an external model on the combobox this model | - | ||||||||||||||||||
| 2834 | will still be cleared when calling this function. | - | ||||||||||||||||||
| 2835 | */ | - | ||||||||||||||||||
| 2836 | void QComboBox::clear() | - | ||||||||||||||||||
| 2837 | { | - | ||||||||||||||||||
| 2838 | Q_D(QComboBox); | - | ||||||||||||||||||
| 2839 | d->model->removeRows(0, d->model->rowCount(d->root), d->root); | - | ||||||||||||||||||
| 2840 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||
| 2841 | QAccessibleValueChangeEvent event(this, QString()); | - | ||||||||||||||||||
| 2842 | QAccessible::updateAccessibility(&event); | - | ||||||||||||||||||
| 2843 | #endif | - | ||||||||||||||||||
| 2844 | } never executed: end of block | 0 | ||||||||||||||||||
| 2845 | - | |||||||||||||||||||
| 2846 | /*! | - | ||||||||||||||||||
| 2847 | Clears the contents of the line edit used for editing in the combobox. | - | ||||||||||||||||||
| 2848 | */ | - | ||||||||||||||||||
| 2849 | void QComboBox::clearEditText() | - | ||||||||||||||||||
| 2850 | { | - | ||||||||||||||||||
| 2851 | Q_D(QComboBox); | - | ||||||||||||||||||
| 2852 | if (d->lineEdit)
| 0 | ||||||||||||||||||
| 2853 | d->lineEdit->clear(); never executed: d->lineEdit->clear(); | 0 | ||||||||||||||||||
| 2854 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||
| 2855 | QAccessibleValueChangeEvent event(this, QString()); | - | ||||||||||||||||||
| 2856 | QAccessible::updateAccessibility(&event); | - | ||||||||||||||||||
| 2857 | #endif | - | ||||||||||||||||||
| 2858 | } never executed: end of block | 0 | ||||||||||||||||||
| 2859 | - | |||||||||||||||||||
| 2860 | /*! | - | ||||||||||||||||||
| 2861 | Sets the \a text in the combobox's text edit. | - | ||||||||||||||||||
| 2862 | */ | - | ||||||||||||||||||
| 2863 | void QComboBox::setEditText(const QString &text) | - | ||||||||||||||||||
| 2864 | { | - | ||||||||||||||||||
| 2865 | Q_D(QComboBox); | - | ||||||||||||||||||
| 2866 | if (d->lineEdit)
| 0 | ||||||||||||||||||
| 2867 | d->lineEdit->setText(text); never executed: d->lineEdit->setText(text); | 0 | ||||||||||||||||||
| 2868 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||
| 2869 | QAccessibleValueChangeEvent event(this, text); | - | ||||||||||||||||||
| 2870 | QAccessible::updateAccessibility(&event); | - | ||||||||||||||||||
| 2871 | #endif | - | ||||||||||||||||||
| 2872 | } never executed: end of block | 0 | ||||||||||||||||||
| 2873 | - | |||||||||||||||||||
| 2874 | /*! | - | ||||||||||||||||||
| 2875 | \reimp | - | ||||||||||||||||||
| 2876 | */ | - | ||||||||||||||||||
| 2877 | void QComboBox::focusInEvent(QFocusEvent *e) | - | ||||||||||||||||||
| 2878 | { | - | ||||||||||||||||||
| 2879 | Q_D(QComboBox); | - | ||||||||||||||||||
| 2880 | update(); | - | ||||||||||||||||||
| 2881 | if (d->lineEdit) {
| 0 | ||||||||||||||||||
| 2882 | d->lineEdit->event(e); | - | ||||||||||||||||||
| 2883 | #ifndef QT_NO_COMPLETER | - | ||||||||||||||||||
| 2884 | if (d->lineEdit->completer())
| 0 | ||||||||||||||||||
| 2885 | d->lineEdit->completer()->setWidget(this); never executed: d->lineEdit->completer()->setWidget(this); | 0 | ||||||||||||||||||
| 2886 | #endif | - | ||||||||||||||||||
| 2887 | } never executed: end of block | 0 | ||||||||||||||||||
| 2888 | } never executed: end of block | 0 | ||||||||||||||||||
| 2889 | - | |||||||||||||||||||
| 2890 | /*! | - | ||||||||||||||||||
| 2891 | \reimp | - | ||||||||||||||||||
| 2892 | */ | - | ||||||||||||||||||
| 2893 | void QComboBox::focusOutEvent(QFocusEvent *e) | - | ||||||||||||||||||
| 2894 | { | - | ||||||||||||||||||
| 2895 | Q_D(QComboBox); | - | ||||||||||||||||||
| 2896 | update(); | - | ||||||||||||||||||
| 2897 | if (d->lineEdit)
| 0 | ||||||||||||||||||
| 2898 | d->lineEdit->event(e); never executed: d->lineEdit->event(e); | 0 | ||||||||||||||||||
| 2899 | } never executed: end of block | 0 | ||||||||||||||||||
| 2900 | - | |||||||||||||||||||
| 2901 | /*! \reimp */ | - | ||||||||||||||||||
| 2902 | void QComboBox::changeEvent(QEvent *e) | - | ||||||||||||||||||
| 2903 | { | - | ||||||||||||||||||
| 2904 | Q_D(QComboBox); | - | ||||||||||||||||||
| 2905 | switch (e->type()) { | - | ||||||||||||||||||
| 2906 | case QEvent::StyleChange: never executed: case QEvent::StyleChange: | 0 | ||||||||||||||||||
| 2907 | d->updateDelegate(); | - | ||||||||||||||||||
| 2908 | #ifdef Q_OS_MAC | - | ||||||||||||||||||
| 2909 | case QEvent::MacSizeChange: | - | ||||||||||||||||||
| 2910 | #endif | - | ||||||||||||||||||
| 2911 | d->sizeHint = QSize(); // invalidate size hint | - | ||||||||||||||||||
| 2912 | d->minimumSizeHint = QSize(); | - | ||||||||||||||||||
| 2913 | d->updateLayoutDirection(); | - | ||||||||||||||||||
| 2914 | if (d->lineEdit)
| 0 | ||||||||||||||||||
| 2915 | d->updateLineEditGeometry(); never executed: d->updateLineEditGeometry(); | 0 | ||||||||||||||||||
| 2916 | d->setLayoutItemMargins(QStyle::SE_ComboBoxLayoutItem); | - | ||||||||||||||||||
| 2917 | - | |||||||||||||||||||
| 2918 | if (e->type() == QEvent::MacSizeChange){
| 0 | ||||||||||||||||||
| 2919 | QPlatformTheme::Font f = QPlatformTheme::SystemFont; | - | ||||||||||||||||||
| 2920 | if (testAttribute(Qt::WA_MacSmallSize))
| 0 | ||||||||||||||||||
| 2921 | f = QPlatformTheme::SmallFont; never executed: f = QPlatformTheme::SmallFont; | 0 | ||||||||||||||||||
| 2922 | else if (testAttribute(Qt::WA_MacMiniSize))
| 0 | ||||||||||||||||||
| 2923 | f = QPlatformTheme::MiniFont; never executed: f = QPlatformTheme::MiniFont; | 0 | ||||||||||||||||||
| 2924 | if (const QFont *platformFont = QApplicationPrivate::platformTheme()->font(f)) {
| 0 | ||||||||||||||||||
| 2925 | QFont f = font(); | - | ||||||||||||||||||
| 2926 | f.setPointSizeF(platformFont->pointSizeF()); | - | ||||||||||||||||||
| 2927 | setFont(f); | - | ||||||||||||||||||
| 2928 | } never executed: end of block | 0 | ||||||||||||||||||
| 2929 | } never executed: end of block | 0 | ||||||||||||||||||
| 2930 | // ### need to update scrollers etc. as well here | - | ||||||||||||||||||
| 2931 | break; never executed: break; | 0 | ||||||||||||||||||
| 2932 | case QEvent::EnabledChange: never executed: case QEvent::EnabledChange: | 0 | ||||||||||||||||||
| 2933 | if (!isEnabled())
| 0 | ||||||||||||||||||
| 2934 | hidePopup(); never executed: hidePopup(); | 0 | ||||||||||||||||||
| 2935 | break; never executed: break; | 0 | ||||||||||||||||||
| 2936 | case QEvent::PaletteChange: { never executed: case QEvent::PaletteChange: | 0 | ||||||||||||||||||
| 2937 | d->updateViewContainerPaletteAndOpacity(); | - | ||||||||||||||||||
| 2938 | break; never executed: break; | 0 | ||||||||||||||||||
| 2939 | } | - | ||||||||||||||||||
| 2940 | case QEvent::FontChange: never executed: case QEvent::FontChange: | 0 | ||||||||||||||||||
| 2941 | d->sizeHint = QSize(); // invalidate size hint | - | ||||||||||||||||||
| 2942 | d->viewContainer()->setFont(font()); | - | ||||||||||||||||||
| 2943 | if (d->lineEdit)
| 0 | ||||||||||||||||||
| 2944 | d->updateLineEditGeometry(); never executed: d->updateLineEditGeometry(); | 0 | ||||||||||||||||||
| 2945 | break; never executed: break; | 0 | ||||||||||||||||||
| 2946 | default: never executed: default: | 0 | ||||||||||||||||||
| 2947 | break; never executed: break; | 0 | ||||||||||||||||||
| 2948 | } | - | ||||||||||||||||||
| 2949 | QWidget::changeEvent(e); | - | ||||||||||||||||||
| 2950 | } never executed: end of block | 0 | ||||||||||||||||||
| 2951 | - | |||||||||||||||||||
| 2952 | /*! | - | ||||||||||||||||||
| 2953 | \reimp | - | ||||||||||||||||||
| 2954 | */ | - | ||||||||||||||||||
| 2955 | void QComboBox::resizeEvent(QResizeEvent *) | - | ||||||||||||||||||
| 2956 | { | - | ||||||||||||||||||
| 2957 | Q_D(QComboBox); | - | ||||||||||||||||||
| 2958 | d->updateLineEditGeometry(); | - | ||||||||||||||||||
| 2959 | } never executed: end of block | 0 | ||||||||||||||||||
| 2960 | - | |||||||||||||||||||
| 2961 | /*! | - | ||||||||||||||||||
| 2962 | \reimp | - | ||||||||||||||||||
| 2963 | */ | - | ||||||||||||||||||
| 2964 | void QComboBox::paintEvent(QPaintEvent *) | - | ||||||||||||||||||
| 2965 | { | - | ||||||||||||||||||
| 2966 | QStylePainter painter(this); | - | ||||||||||||||||||
| 2967 | painter.setPen(palette().color(QPalette::Text)); | - | ||||||||||||||||||
| 2968 | - | |||||||||||||||||||
| 2969 | // draw the combobox frame, focusrect and selected etc. | - | ||||||||||||||||||
| 2970 | QStyleOptionComboBox opt; | - | ||||||||||||||||||
| 2971 | initStyleOption(&opt); | - | ||||||||||||||||||
| 2972 | painter.drawComplexControl(QStyle::CC_ComboBox, opt); | - | ||||||||||||||||||
| 2973 | - | |||||||||||||||||||
| 2974 | // draw the icon and text | - | ||||||||||||||||||
| 2975 | painter.drawControl(QStyle::CE_ComboBoxLabel, opt); | - | ||||||||||||||||||
| 2976 | } never executed: end of block | 0 | ||||||||||||||||||
| 2977 | - | |||||||||||||||||||
| 2978 | /*! | - | ||||||||||||||||||
| 2979 | \reimp | - | ||||||||||||||||||
| 2980 | */ | - | ||||||||||||||||||
| 2981 | void QComboBox::showEvent(QShowEvent *e) | - | ||||||||||||||||||
| 2982 | { | - | ||||||||||||||||||
| 2983 | Q_D(QComboBox); | - | ||||||||||||||||||
| 2984 | if (!d->shownOnce && d->sizeAdjustPolicy == QComboBox::AdjustToContentsOnFirstShow) {
| 0 | ||||||||||||||||||
| 2985 | d->sizeHint = QSize(); | - | ||||||||||||||||||
| 2986 | updateGeometry(); | - | ||||||||||||||||||
| 2987 | } never executed: end of block | 0 | ||||||||||||||||||
| 2988 | d->shownOnce = true; | - | ||||||||||||||||||
| 2989 | QWidget::showEvent(e); | - | ||||||||||||||||||
| 2990 | } never executed: end of block | 0 | ||||||||||||||||||
| 2991 | - | |||||||||||||||||||
| 2992 | /*! | - | ||||||||||||||||||
| 2993 | \reimp | - | ||||||||||||||||||
| 2994 | */ | - | ||||||||||||||||||
| 2995 | void QComboBox::hideEvent(QHideEvent *) | - | ||||||||||||||||||
| 2996 | { | - | ||||||||||||||||||
| 2997 | hidePopup(); | - | ||||||||||||||||||
| 2998 | } never executed: end of block | 0 | ||||||||||||||||||
| 2999 | - | |||||||||||||||||||
| 3000 | /*! | - | ||||||||||||||||||
| 3001 | \reimp | - | ||||||||||||||||||
| 3002 | */ | - | ||||||||||||||||||
| 3003 | bool QComboBox::event(QEvent *event) | - | ||||||||||||||||||
| 3004 | { | - | ||||||||||||||||||
| 3005 | Q_D(QComboBox); | - | ||||||||||||||||||
| 3006 | switch(event->type()) { | - | ||||||||||||||||||
| 3007 | case QEvent::LayoutDirectionChange: never executed: case QEvent::LayoutDirectionChange: | 0 | ||||||||||||||||||
| 3008 | case QEvent::ApplicationLayoutDirectionChange: never executed: case QEvent::ApplicationLayoutDirectionChange: | 0 | ||||||||||||||||||
| 3009 | d->updateLayoutDirection(); | - | ||||||||||||||||||
| 3010 | d->updateLineEditGeometry(); | - | ||||||||||||||||||
| 3011 | break; never executed: break; | 0 | ||||||||||||||||||
| 3012 | case QEvent::HoverEnter: never executed: case QEvent::HoverEnter: | 0 | ||||||||||||||||||
| 3013 | case QEvent::HoverLeave: never executed: case QEvent::HoverLeave: | 0 | ||||||||||||||||||
| 3014 | case QEvent::HoverMove: never executed: case QEvent::HoverMove: | 0 | ||||||||||||||||||
| 3015 | if (const QHoverEvent *he = static_cast<const QHoverEvent *>(event))
| 0 | ||||||||||||||||||
| 3016 | d->updateHoverControl(he->pos()); never executed: d->updateHoverControl(he->pos()); | 0 | ||||||||||||||||||
| 3017 | break; never executed: break; | 0 | ||||||||||||||||||
| 3018 | case QEvent::ShortcutOverride: never executed: case QEvent::ShortcutOverride: | 0 | ||||||||||||||||||
| 3019 | if (d->lineEdit)
| 0 | ||||||||||||||||||
| 3020 | return d->lineEdit->event(event); never executed: return d->lineEdit->event(event); | 0 | ||||||||||||||||||
| 3021 | break; never executed: break; | 0 | ||||||||||||||||||
| 3022 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
| 3023 | case QEvent::EnterEditFocus: | - | ||||||||||||||||||
| 3024 | if (!d->lineEdit) | - | ||||||||||||||||||
| 3025 | setEditFocus(false); // We never want edit focus if we are not editable | - | ||||||||||||||||||
| 3026 | else | - | ||||||||||||||||||
| 3027 | d->lineEdit->event(event); //so cursor starts | - | ||||||||||||||||||
| 3028 | break; | - | ||||||||||||||||||
| 3029 | case QEvent::LeaveEditFocus: | - | ||||||||||||||||||
| 3030 | if (d->lineEdit) | - | ||||||||||||||||||
| 3031 | d->lineEdit->event(event); //so cursor stops | - | ||||||||||||||||||
| 3032 | break; | - | ||||||||||||||||||
| 3033 | #endif | - | ||||||||||||||||||
| 3034 | default: never executed: default: | 0 | ||||||||||||||||||
| 3035 | break; never executed: break; | 0 | ||||||||||||||||||
| 3036 | } | - | ||||||||||||||||||
| 3037 | return QWidget::event(event); never executed: return QWidget::event(event); | 0 | ||||||||||||||||||
| 3038 | } | - | ||||||||||||||||||
| 3039 | - | |||||||||||||||||||
| 3040 | /*! | - | ||||||||||||||||||
| 3041 | \reimp | - | ||||||||||||||||||
| 3042 | */ | - | ||||||||||||||||||
| 3043 | void QComboBox::mousePressEvent(QMouseEvent *e) | - | ||||||||||||||||||
| 3044 | { | - | ||||||||||||||||||
| 3045 | Q_D(QComboBox); | - | ||||||||||||||||||
| 3046 | if (!QGuiApplication::styleHints()->setFocusOnTouchRelease())
| 0 | ||||||||||||||||||
| 3047 | d->showPopupFromMouseEvent(e); never executed: d->showPopupFromMouseEvent(e); | 0 | ||||||||||||||||||
| 3048 | } never executed: end of block | 0 | ||||||||||||||||||
| 3049 | - | |||||||||||||||||||
| 3050 | void QComboBoxPrivate::showPopupFromMouseEvent(QMouseEvent *e) | - | ||||||||||||||||||
| 3051 | { | - | ||||||||||||||||||
| 3052 | Q_Q(QComboBox); | - | ||||||||||||||||||
| 3053 | QStyleOptionComboBox opt; | - | ||||||||||||||||||
| 3054 | q->initStyleOption(&opt); | - | ||||||||||||||||||
| 3055 | QStyle::SubControl sc = q->style()->hitTestComplexControl(QStyle::CC_ComboBox, &opt, e->pos(), q); | - | ||||||||||||||||||
| 3056 | - | |||||||||||||||||||
| 3057 | if (e->button() == Qt::LeftButton
| 0 | ||||||||||||||||||
| 3058 | && !(sc == QStyle::SC_None && e->type() == QEvent::MouseButtonRelease)
| 0 | ||||||||||||||||||
| 3059 | && (sc == QStyle::SC_ComboBoxArrow || !q->isEditable())
| 0 | ||||||||||||||||||
| 3060 | && !viewContainer()->isVisible()) {
| 0 | ||||||||||||||||||
| 3061 | if (sc == QStyle::SC_ComboBoxArrow)
| 0 | ||||||||||||||||||
| 3062 | updateArrow(QStyle::State_Sunken); never executed: updateArrow(QStyle::State_Sunken); | 0 | ||||||||||||||||||
| 3063 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
| 3064 | //if the container already exists, then d->viewContainer() is safe to call | - | ||||||||||||||||||
| 3065 | if (container) { | - | ||||||||||||||||||
| 3066 | #endif | - | ||||||||||||||||||
| 3067 | // We've restricted the next couple of lines, because by not calling | - | ||||||||||||||||||
| 3068 | // viewContainer(), we avoid creating the QComboBoxPrivateContainer. | - | ||||||||||||||||||
| 3069 | viewContainer()->blockMouseReleaseTimer.start(QApplication::doubleClickInterval()); | - | ||||||||||||||||||
| 3070 | viewContainer()->initialClickPosition = q->mapToGlobal(e->pos()); | - | ||||||||||||||||||
| 3071 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
| 3072 | } | - | ||||||||||||||||||
| 3073 | #endif | - | ||||||||||||||||||
| 3074 | q->showPopup(); | - | ||||||||||||||||||
| 3075 | // The code below ensures that regular mousepress and pick item still works | - | ||||||||||||||||||
| 3076 | // If it was not called the viewContainer would ignore event since it didn't have | - | ||||||||||||||||||
| 3077 | // a mousePressEvent first. | - | ||||||||||||||||||
| 3078 | if (viewContainer())
| 0 | ||||||||||||||||||
| 3079 | viewContainer()->maybeIgnoreMouseButtonRelease = false; never executed: viewContainer()->maybeIgnoreMouseButtonRelease = false; | 0 | ||||||||||||||||||
| 3080 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 3081 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
| 3082 | if (QApplication::keypadNavigationEnabled() && sc == QStyle::SC_ComboBoxEditField && lineEdit) { | - | ||||||||||||||||||
| 3083 | lineEdit->event(e); //so lineedit can move cursor, etc | - | ||||||||||||||||||
| 3084 | return; | - | ||||||||||||||||||
| 3085 | } | - | ||||||||||||||||||
| 3086 | #endif | - | ||||||||||||||||||
| 3087 | e->ignore(); | - | ||||||||||||||||||
| 3088 | } never executed: end of block | 0 | ||||||||||||||||||
| 3089 | } | - | ||||||||||||||||||
| 3090 | - | |||||||||||||||||||
| 3091 | /*! | - | ||||||||||||||||||
| 3092 | \reimp | - | ||||||||||||||||||
| 3093 | */ | - | ||||||||||||||||||
| 3094 | void QComboBox::mouseReleaseEvent(QMouseEvent *e) | - | ||||||||||||||||||
| 3095 | { | - | ||||||||||||||||||
| 3096 | Q_D(QComboBox); | - | ||||||||||||||||||
| 3097 | d->updateArrow(QStyle::State_None); | - | ||||||||||||||||||
| 3098 | if (QGuiApplication::styleHints()->setFocusOnTouchRelease() && hasFocus())
| 0 | ||||||||||||||||||
| 3099 | d->showPopupFromMouseEvent(e); never executed: d->showPopupFromMouseEvent(e); | 0 | ||||||||||||||||||
| 3100 | } never executed: end of block | 0 | ||||||||||||||||||
| 3101 | - | |||||||||||||||||||
| 3102 | /*! | - | ||||||||||||||||||
| 3103 | \reimp | - | ||||||||||||||||||
| 3104 | */ | - | ||||||||||||||||||
| 3105 | void QComboBox::keyPressEvent(QKeyEvent *e) | - | ||||||||||||||||||
| 3106 | { | - | ||||||||||||||||||
| 3107 | Q_D(QComboBox); | - | ||||||||||||||||||
| 3108 | - | |||||||||||||||||||
| 3109 | #ifndef QT_NO_COMPLETER | - | ||||||||||||||||||
| 3110 | if (d->lineEdit
| 0 | ||||||||||||||||||
| 3111 | && d->lineEdit->completer()
| 0 | ||||||||||||||||||
| 3112 | && d->lineEdit->completer()->popup()
| 0 | ||||||||||||||||||
| 3113 | && d->lineEdit->completer()->popup()->isVisible()) {
| 0 | ||||||||||||||||||
| 3114 | // provide same autocompletion support as line edit | - | ||||||||||||||||||
| 3115 | d->lineEdit->event(e); | - | ||||||||||||||||||
| 3116 | return; never executed: return; | 0 | ||||||||||||||||||
| 3117 | } | - | ||||||||||||||||||
| 3118 | #endif | - | ||||||||||||||||||
| 3119 | - | |||||||||||||||||||
| 3120 | enum Move { NoMove=0 , MoveUp , MoveDown , MoveFirst , MoveLast}; | - | ||||||||||||||||||
| 3121 | - | |||||||||||||||||||
| 3122 | Move move = NoMove; | - | ||||||||||||||||||
| 3123 | int newIndex = currentIndex(); | - | ||||||||||||||||||
| 3124 | switch (e->key()) { | - | ||||||||||||||||||
| 3125 | case Qt::Key_Up: never executed: case Qt::Key_Up: | 0 | ||||||||||||||||||
| 3126 | if (e->modifiers() & Qt::ControlModifier)
| 0 | ||||||||||||||||||
| 3127 | break; // pass to line edit for auto completion never executed: break; | 0 | ||||||||||||||||||
| 3128 | // fall through | - | ||||||||||||||||||
| 3129 | case Qt::Key_PageUp: code before this statement never executed: case Qt::Key_PageUp:never executed: case Qt::Key_PageUp: | 0 | ||||||||||||||||||
| 3130 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
| 3131 | if (QApplication::keypadNavigationEnabled()) | - | ||||||||||||||||||
| 3132 | e->ignore(); | - | ||||||||||||||||||
| 3133 | else | - | ||||||||||||||||||
| 3134 | #endif | - | ||||||||||||||||||
| 3135 | move = MoveUp; | - | ||||||||||||||||||
| 3136 | break; never executed: break; | 0 | ||||||||||||||||||
| 3137 | case Qt::Key_Down: never executed: case Qt::Key_Down: | 0 | ||||||||||||||||||
| 3138 | if (e->modifiers() & Qt::AltModifier) {
| 0 | ||||||||||||||||||
| 3139 | showPopup(); | - | ||||||||||||||||||
| 3140 | return; never executed: return; | 0 | ||||||||||||||||||
| 3141 | } else if (e->modifiers() & Qt::ControlModifier)
| 0 | ||||||||||||||||||
| 3142 | break; // pass to line edit for auto completion never executed: break; | 0 | ||||||||||||||||||
| 3143 | // fall through | - | ||||||||||||||||||
| 3144 | case Qt::Key_PageDown: code before this statement never executed: case Qt::Key_PageDown:never executed: case Qt::Key_PageDown: | 0 | ||||||||||||||||||
| 3145 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
| 3146 | if (QApplication::keypadNavigationEnabled()) | - | ||||||||||||||||||
| 3147 | e->ignore(); | - | ||||||||||||||||||
| 3148 | else | - | ||||||||||||||||||
| 3149 | #endif | - | ||||||||||||||||||
| 3150 | move = MoveDown; | - | ||||||||||||||||||
| 3151 | break; never executed: break; | 0 | ||||||||||||||||||
| 3152 | case Qt::Key_Home: never executed: case Qt::Key_Home: | 0 | ||||||||||||||||||
| 3153 | if (!d->lineEdit)
| 0 | ||||||||||||||||||
| 3154 | move = MoveFirst; never executed: move = MoveFirst; | 0 | ||||||||||||||||||
| 3155 | break; never executed: break; | 0 | ||||||||||||||||||
| 3156 | case Qt::Key_End: never executed: case Qt::Key_End: | 0 | ||||||||||||||||||
| 3157 | if (!d->lineEdit)
| 0 | ||||||||||||||||||
| 3158 | move = MoveLast; never executed: move = MoveLast; | 0 | ||||||||||||||||||
| 3159 | break; never executed: break; | 0 | ||||||||||||||||||
| 3160 | case Qt::Key_F4: never executed: case Qt::Key_F4: | 0 | ||||||||||||||||||
| 3161 | if (!e->modifiers()) {
| 0 | ||||||||||||||||||
| 3162 | showPopup(); | - | ||||||||||||||||||
| 3163 | return; never executed: return; | 0 | ||||||||||||||||||
| 3164 | } | - | ||||||||||||||||||
| 3165 | break; never executed: break; | 0 | ||||||||||||||||||
| 3166 | case Qt::Key_Space: never executed: case Qt::Key_Space: | 0 | ||||||||||||||||||
| 3167 | if (!d->lineEdit) {
| 0 | ||||||||||||||||||
| 3168 | showPopup(); | - | ||||||||||||||||||
| 3169 | return; never executed: return; | 0 | ||||||||||||||||||
| 3170 | } | - | ||||||||||||||||||
| 3171 | break; never executed: break; | 0 | ||||||||||||||||||
| 3172 | case Qt::Key_Enter: never executed: case Qt::Key_Enter: | 0 | ||||||||||||||||||
| 3173 | case Qt::Key_Return: never executed: case Qt::Key_Return: | 0 | ||||||||||||||||||
| 3174 | case Qt::Key_Escape: never executed: case Qt::Key_Escape: | 0 | ||||||||||||||||||
| 3175 | if (!d->lineEdit)
| 0 | ||||||||||||||||||
| 3176 | e->ignore(); never executed: e->ignore(); | 0 | ||||||||||||||||||
| 3177 | break; never executed: break; | 0 | ||||||||||||||||||
| 3178 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
| 3179 | case Qt::Key_Select: | - | ||||||||||||||||||
| 3180 | if (QApplication::keypadNavigationEnabled() | - | ||||||||||||||||||
| 3181 | && (!hasEditFocus() || !d->lineEdit)) { | - | ||||||||||||||||||
| 3182 | showPopup(); | - | ||||||||||||||||||
| 3183 | return; | - | ||||||||||||||||||
| 3184 | } | - | ||||||||||||||||||
| 3185 | break; | - | ||||||||||||||||||
| 3186 | case Qt::Key_Left: | - | ||||||||||||||||||
| 3187 | case Qt::Key_Right: | - | ||||||||||||||||||
| 3188 | if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) | - | ||||||||||||||||||
| 3189 | e->ignore(); | - | ||||||||||||||||||
| 3190 | break; | - | ||||||||||||||||||
| 3191 | case Qt::Key_Back: | - | ||||||||||||||||||
| 3192 | if (QApplication::keypadNavigationEnabled()) { | - | ||||||||||||||||||
| 3193 | if (!hasEditFocus() || !d->lineEdit) | - | ||||||||||||||||||
| 3194 | e->ignore(); | - | ||||||||||||||||||
| 3195 | } else { | - | ||||||||||||||||||
| 3196 | e->ignore(); // let the surounding dialog have it | - | ||||||||||||||||||
| 3197 | } | - | ||||||||||||||||||
| 3198 | break; | - | ||||||||||||||||||
| 3199 | #endif | - | ||||||||||||||||||
| 3200 | default: never executed: default: | 0 | ||||||||||||||||||
| 3201 | if (!d->lineEdit) {
| 0 | ||||||||||||||||||
| 3202 | if (!e->text().isEmpty())
| 0 | ||||||||||||||||||
| 3203 | d->keyboardSearchString(e->text()); never executed: d->keyboardSearchString(e->text()); | 0 | ||||||||||||||||||
| 3204 | else | - | ||||||||||||||||||
| 3205 | e->ignore(); never executed: e->ignore(); | 0 | ||||||||||||||||||
| 3206 | } | - | ||||||||||||||||||
| 3207 | } never executed: end of block | 0 | ||||||||||||||||||
| 3208 | - | |||||||||||||||||||
| 3209 | if (move != NoMove) {
| 0 | ||||||||||||||||||
| 3210 | e->accept(); | - | ||||||||||||||||||
| 3211 | switch (move) { | - | ||||||||||||||||||
| 3212 | case MoveFirst: never executed: case MoveFirst: | 0 | ||||||||||||||||||
| 3213 | newIndex = -1; | - | ||||||||||||||||||
| 3214 | // fall through | - | ||||||||||||||||||
| 3215 | case MoveDown: code before this statement never executed: case MoveDown:never executed: case MoveDown: | 0 | ||||||||||||||||||
| 3216 | newIndex++; | - | ||||||||||||||||||
| 3217 | while ((newIndex < count()) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled))
| 0 | ||||||||||||||||||
| 3218 | newIndex++; never executed: newIndex++; | 0 | ||||||||||||||||||
| 3219 | break; never executed: break; | 0 | ||||||||||||||||||
| 3220 | case MoveLast: never executed: case MoveLast: | 0 | ||||||||||||||||||
| 3221 | newIndex = count(); | - | ||||||||||||||||||
| 3222 | // fall through | - | ||||||||||||||||||
| 3223 | case MoveUp: code before this statement never executed: case MoveUp:never executed: case MoveUp: | 0 | ||||||||||||||||||
| 3224 | newIndex--; | - | ||||||||||||||||||
| 3225 | while ((newIndex >= 0) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled))
| 0 | ||||||||||||||||||
| 3226 | newIndex--; never executed: newIndex--; | 0 | ||||||||||||||||||
| 3227 | break; never executed: break; | 0 | ||||||||||||||||||
| 3228 | default: never executed: default: | 0 | ||||||||||||||||||
| 3229 | e->ignore(); | - | ||||||||||||||||||
| 3230 | break; never executed: break; | 0 | ||||||||||||||||||
| 3231 | } | - | ||||||||||||||||||
| 3232 | - | |||||||||||||||||||
| 3233 | if (newIndex >= 0 && newIndex < count() && newIndex != currentIndex()) {
| 0 | ||||||||||||||||||
| 3234 | setCurrentIndex(newIndex); | - | ||||||||||||||||||
| 3235 | d->emitActivated(d->currentIndex); | - | ||||||||||||||||||
| 3236 | } never executed: end of block | 0 | ||||||||||||||||||
| 3237 | } else if (d->lineEdit) { never executed: end of block
| 0 | ||||||||||||||||||
| 3238 | d->lineEdit->event(e); | - | ||||||||||||||||||
| 3239 | } never executed: end of block | 0 | ||||||||||||||||||
| 3240 | } never executed: end of block | 0 | ||||||||||||||||||
| 3241 | - | |||||||||||||||||||
| 3242 | - | |||||||||||||||||||
| 3243 | /*! | - | ||||||||||||||||||
| 3244 | \reimp | - | ||||||||||||||||||
| 3245 | */ | - | ||||||||||||||||||
| 3246 | void QComboBox::keyReleaseEvent(QKeyEvent *e) | - | ||||||||||||||||||
| 3247 | { | - | ||||||||||||||||||
| 3248 | Q_D(QComboBox); | - | ||||||||||||||||||
| 3249 | if (d->lineEdit)
| 0 | ||||||||||||||||||
| 3250 | d->lineEdit->event(e); never executed: d->lineEdit->event(e); | 0 | ||||||||||||||||||
| 3251 | else | - | ||||||||||||||||||
| 3252 | QWidget::keyReleaseEvent(e); never executed: QWidget::keyReleaseEvent(e); | 0 | ||||||||||||||||||
| 3253 | } | - | ||||||||||||||||||
| 3254 | - | |||||||||||||||||||
| 3255 | /*! | - | ||||||||||||||||||
| 3256 | \reimp | - | ||||||||||||||||||
| 3257 | */ | - | ||||||||||||||||||
| 3258 | #ifndef QT_NO_WHEELEVENT | - | ||||||||||||||||||
| 3259 | void QComboBox::wheelEvent(QWheelEvent *e) | - | ||||||||||||||||||
| 3260 | { | - | ||||||||||||||||||
| 3261 | #ifdef Q_OS_DARWIN | - | ||||||||||||||||||
| 3262 | Q_UNUSED(e); | - | ||||||||||||||||||
| 3263 | #else | - | ||||||||||||||||||
| 3264 | Q_D(QComboBox); | - | ||||||||||||||||||
| 3265 | if (!d->viewContainer()->isVisible()) {
| 0 | ||||||||||||||||||
| 3266 | int newIndex = currentIndex(); | - | ||||||||||||||||||
| 3267 | - | |||||||||||||||||||
| 3268 | if (e->delta() > 0) {
| 0 | ||||||||||||||||||
| 3269 | newIndex--; | - | ||||||||||||||||||
| 3270 | while ((newIndex >= 0) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled))
| 0 | ||||||||||||||||||
| 3271 | newIndex--; never executed: newIndex--; | 0 | ||||||||||||||||||
| 3272 | } else if (e->delta() < 0) { never executed: end of block
| 0 | ||||||||||||||||||
| 3273 | newIndex++; | - | ||||||||||||||||||
| 3274 | while ((newIndex < count()) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled))
| 0 | ||||||||||||||||||
| 3275 | newIndex++; never executed: newIndex++; | 0 | ||||||||||||||||||
| 3276 | } never executed: end of block | 0 | ||||||||||||||||||
| 3277 | - | |||||||||||||||||||
| 3278 | if (newIndex >= 0 && newIndex < count() && newIndex != currentIndex()) {
| 0 | ||||||||||||||||||
| 3279 | setCurrentIndex(newIndex); | - | ||||||||||||||||||
| 3280 | d->emitActivated(d->currentIndex); | - | ||||||||||||||||||
| 3281 | } never executed: end of block | 0 | ||||||||||||||||||
| 3282 | e->accept(); | - | ||||||||||||||||||
| 3283 | } never executed: end of block | 0 | ||||||||||||||||||
| 3284 | #endif | - | ||||||||||||||||||
| 3285 | } never executed: end of block | 0 | ||||||||||||||||||
| 3286 | #endif | - | ||||||||||||||||||
| 3287 | - | |||||||||||||||||||
| 3288 | #ifndef QT_NO_CONTEXTMENU | - | ||||||||||||||||||
| 3289 | /*! | - | ||||||||||||||||||
| 3290 | \reimp | - | ||||||||||||||||||
| 3291 | */ | - | ||||||||||||||||||
| 3292 | void QComboBox::contextMenuEvent(QContextMenuEvent *e) | - | ||||||||||||||||||
| 3293 | { | - | ||||||||||||||||||
| 3294 | Q_D(QComboBox); | - | ||||||||||||||||||
| 3295 | if (d->lineEdit) {
| 0 | ||||||||||||||||||
| 3296 | Qt::ContextMenuPolicy p = d->lineEdit->contextMenuPolicy(); | - | ||||||||||||||||||
| 3297 | d->lineEdit->setContextMenuPolicy(Qt::DefaultContextMenu); | - | ||||||||||||||||||
| 3298 | d->lineEdit->event(e); | - | ||||||||||||||||||
| 3299 | d->lineEdit->setContextMenuPolicy(p); | - | ||||||||||||||||||
| 3300 | } never executed: end of block | 0 | ||||||||||||||||||
| 3301 | } never executed: end of block | 0 | ||||||||||||||||||
| 3302 | #endif // QT_NO_CONTEXTMENU | - | ||||||||||||||||||
| 3303 | - | |||||||||||||||||||
| 3304 | void QComboBoxPrivate::keyboardSearchString(const QString &text) | - | ||||||||||||||||||
| 3305 | { | - | ||||||||||||||||||
| 3306 | // use keyboardSearch from the listView so we do not duplicate code | - | ||||||||||||||||||
| 3307 | QAbstractItemView *view = viewContainer()->itemView(); | - | ||||||||||||||||||
| 3308 | view->setCurrentIndex(currentIndex); | - | ||||||||||||||||||
| 3309 | int currentRow = view->currentIndex().row(); | - | ||||||||||||||||||
| 3310 | view->keyboardSearch(text); | - | ||||||||||||||||||
| 3311 | if (currentRow != view->currentIndex().row()) {
| 0 | ||||||||||||||||||
| 3312 | setCurrentIndex(view->currentIndex()); | - | ||||||||||||||||||
| 3313 | emitActivated(currentIndex); | - | ||||||||||||||||||
| 3314 | } never executed: end of block | 0 | ||||||||||||||||||
| 3315 | } never executed: end of block | 0 | ||||||||||||||||||
| 3316 | - | |||||||||||||||||||
| 3317 | void QComboBoxPrivate::modelChanged() | - | ||||||||||||||||||
| 3318 | { | - | ||||||||||||||||||
| 3319 | Q_Q(QComboBox); | - | ||||||||||||||||||
| 3320 | - | |||||||||||||||||||
| 3321 | if (sizeAdjustPolicy == QComboBox::AdjustToContents) {
| 0 | ||||||||||||||||||
| 3322 | sizeHint = QSize(); | - | ||||||||||||||||||
| 3323 | adjustComboBoxSize(); | - | ||||||||||||||||||
| 3324 | q->updateGeometry(); | - | ||||||||||||||||||
| 3325 | } never executed: end of block | 0 | ||||||||||||||||||
| 3326 | } never executed: end of block | 0 | ||||||||||||||||||
| 3327 | - | |||||||||||||||||||
| 3328 | /*! | - | ||||||||||||||||||
| 3329 | \reimp | - | ||||||||||||||||||
| 3330 | */ | - | ||||||||||||||||||
| 3331 | void QComboBox::inputMethodEvent(QInputMethodEvent *e) | - | ||||||||||||||||||
| 3332 | { | - | ||||||||||||||||||
| 3333 | Q_D(QComboBox); | - | ||||||||||||||||||
| 3334 | if (d->lineEdit) {
| 0 | ||||||||||||||||||
| 3335 | d->lineEdit->event(e); | - | ||||||||||||||||||
| 3336 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 3337 | if (!e->commitString().isEmpty())
| 0 | ||||||||||||||||||
| 3338 | d->keyboardSearchString(e->commitString()); never executed: d->keyboardSearchString(e->commitString()); | 0 | ||||||||||||||||||
| 3339 | else | - | ||||||||||||||||||
| 3340 | e->ignore(); never executed: e->ignore(); | 0 | ||||||||||||||||||
| 3341 | } | - | ||||||||||||||||||
| 3342 | } | - | ||||||||||||||||||
| 3343 | - | |||||||||||||||||||
| 3344 | /*! | - | ||||||||||||||||||
| 3345 | \reimp | - | ||||||||||||||||||
| 3346 | */ | - | ||||||||||||||||||
| 3347 | QVariant QComboBox::inputMethodQuery(Qt::InputMethodQuery query) const | - | ||||||||||||||||||
| 3348 | { | - | ||||||||||||||||||
| 3349 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 3350 | if (d->lineEdit)
| 0 | ||||||||||||||||||
| 3351 | return d->lineEdit->inputMethodQuery(query); never executed: return d->lineEdit->inputMethodQuery(query); | 0 | ||||||||||||||||||
| 3352 | return QWidget::inputMethodQuery(query); never executed: return QWidget::inputMethodQuery(query); | 0 | ||||||||||||||||||
| 3353 | } | - | ||||||||||||||||||
| 3354 | - | |||||||||||||||||||
| 3355 | /*! | - | ||||||||||||||||||
| 3356 | \fn void QComboBox::addItem(const QString &text, const QVariant &userData) | - | ||||||||||||||||||
| 3357 | - | |||||||||||||||||||
| 3358 | Adds an item to the combobox with the given \a text, and | - | ||||||||||||||||||
| 3359 | containing the specified \a userData (stored in the Qt::UserRole). | - | ||||||||||||||||||
| 3360 | The item is appended to the list of existing items. | - | ||||||||||||||||||
| 3361 | */ | - | ||||||||||||||||||
| 3362 | - | |||||||||||||||||||
| 3363 | /*! | - | ||||||||||||||||||
| 3364 | \fn void QComboBox::addItem(const QIcon &icon, const QString &text, | - | ||||||||||||||||||
| 3365 | const QVariant &userData) | - | ||||||||||||||||||
| 3366 | - | |||||||||||||||||||
| 3367 | Adds an item to the combobox with the given \a icon and \a text, | - | ||||||||||||||||||
| 3368 | and containing the specified \a userData (stored in the | - | ||||||||||||||||||
| 3369 | Qt::UserRole). The item is appended to the list of existing items. | - | ||||||||||||||||||
| 3370 | */ | - | ||||||||||||||||||
| 3371 | - | |||||||||||||||||||
| 3372 | /*! | - | ||||||||||||||||||
| 3373 | \fn void QComboBox::addItems(const QStringList &texts) | - | ||||||||||||||||||
| 3374 | - | |||||||||||||||||||
| 3375 | Adds each of the strings in the given \a texts to the combobox. Each item | - | ||||||||||||||||||
| 3376 | is appended to the list of existing items in turn. | - | ||||||||||||||||||
| 3377 | */ | - | ||||||||||||||||||
| 3378 | - | |||||||||||||||||||
| 3379 | /*! | - | ||||||||||||||||||
| 3380 | \fn void QComboBox::editTextChanged(const QString &text) | - | ||||||||||||||||||
| 3381 | - | |||||||||||||||||||
| 3382 | This signal is emitted when the text in the combobox's line edit | - | ||||||||||||||||||
| 3383 | widget is changed. The new text is specified by \a text. | - | ||||||||||||||||||
| 3384 | */ | - | ||||||||||||||||||
| 3385 | - | |||||||||||||||||||
| 3386 | /*! | - | ||||||||||||||||||
| 3387 | \property QComboBox::frame | - | ||||||||||||||||||
| 3388 | \brief whether the combo box draws itself with a frame | - | ||||||||||||||||||
| 3389 | - | |||||||||||||||||||
| 3390 | - | |||||||||||||||||||
| 3391 | If enabled (the default) the combo box draws itself inside a | - | ||||||||||||||||||
| 3392 | frame, otherwise the combo box draws itself without any frame. | - | ||||||||||||||||||
| 3393 | */ | - | ||||||||||||||||||
| 3394 | bool QComboBox::hasFrame() const | - | ||||||||||||||||||
| 3395 | { | - | ||||||||||||||||||
| 3396 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 3397 | return d->frame; never executed: return d->frame; | 0 | ||||||||||||||||||
| 3398 | } | - | ||||||||||||||||||
| 3399 | - | |||||||||||||||||||
| 3400 | - | |||||||||||||||||||
| 3401 | void QComboBox::setFrame(bool enable) | - | ||||||||||||||||||
| 3402 | { | - | ||||||||||||||||||
| 3403 | Q_D(QComboBox); | - | ||||||||||||||||||
| 3404 | d->frame = enable; | - | ||||||||||||||||||
| 3405 | update(); | - | ||||||||||||||||||
| 3406 | updateGeometry(); | - | ||||||||||||||||||
| 3407 | } never executed: end of block | 0 | ||||||||||||||||||
| 3408 | - | |||||||||||||||||||
| 3409 | /*! | - | ||||||||||||||||||
| 3410 | \property QComboBox::modelColumn | - | ||||||||||||||||||
| 3411 | \brief the column in the model that is visible. | - | ||||||||||||||||||
| 3412 | - | |||||||||||||||||||
| 3413 | If set prior to populating the combo box, the pop-up view will | - | ||||||||||||||||||
| 3414 | not be affected and will show the first column (using this property's | - | ||||||||||||||||||
| 3415 | default value). | - | ||||||||||||||||||
| 3416 | - | |||||||||||||||||||
| 3417 | By default, this property has a value of 0. | - | ||||||||||||||||||
| 3418 | */ | - | ||||||||||||||||||
| 3419 | int QComboBox::modelColumn() const | - | ||||||||||||||||||
| 3420 | { | - | ||||||||||||||||||
| 3421 | Q_D(const QComboBox); | - | ||||||||||||||||||
| 3422 | return d->modelColumn; never executed: return d->modelColumn; | 0 | ||||||||||||||||||
| 3423 | } | - | ||||||||||||||||||
| 3424 | - | |||||||||||||||||||
| 3425 | void QComboBox::setModelColumn(int visibleColumn) | - | ||||||||||||||||||
| 3426 | { | - | ||||||||||||||||||
| 3427 | Q_D(QComboBox); | - | ||||||||||||||||||
| 3428 | d->modelColumn = visibleColumn; | - | ||||||||||||||||||
| 3429 | QListView *lv = qobject_cast<QListView *>(d->viewContainer()->itemView()); | - | ||||||||||||||||||
| 3430 | if (lv)
| 0 | ||||||||||||||||||
| 3431 | lv->setModelColumn(visibleColumn); never executed: lv->setModelColumn(visibleColumn); | 0 | ||||||||||||||||||
| 3432 | #ifndef QT_NO_COMPLETER | - | ||||||||||||||||||
| 3433 | if (d->lineEdit && d->lineEdit->completer()
| 0 | ||||||||||||||||||
| 3434 | && d->lineEdit->completer() == d->completer)
| 0 | ||||||||||||||||||
| 3435 | d->lineEdit->completer()->setCompletionColumn(visibleColumn); never executed: d->lineEdit->completer()->setCompletionColumn(visibleColumn); | 0 | ||||||||||||||||||
| 3436 | #endif | - | ||||||||||||||||||
| 3437 | setCurrentIndex(currentIndex()); //update the text to the text of the new column; | - | ||||||||||||||||||
| 3438 | } never executed: end of block | 0 | ||||||||||||||||||
| 3439 | - | |||||||||||||||||||
| 3440 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 3441 | - | |||||||||||||||||||
| 3442 | #include "moc_qcombobox.cpp" | - | ||||||||||||||||||
| 3443 | #include "moc_qcombobox_p.cpp" | - | ||||||||||||||||||
| 3444 | - | |||||||||||||||||||
| 3445 | #endif // QT_NO_COMBOBOX | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |