OpenCoverage

qcombobox.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qcombobox.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qcombobox.h"-
41-
42#ifndef QT_NO_COMBOBOX-
43#include <qstylepainter.h>-
44#include <qpa/qplatformtheme.h>-
45#include <qpa/qplatformmenu.h>-
46#include <qlineedit.h>-
47#include <qapplication.h>-
48#include <qdesktopwidget.h>-
49#include <qlistview.h>-
50#include <qtableview.h>-
51#include <qitemdelegate.h>-
52#include <qmap.h>-
53#include <qmenu.h>-
54#include <qevent.h>-
55#include <qlayout.h>-
56#include <qscrollbar.h>-
57#include <qtreeview.h>-
58#include <qheaderview.h>-
59#include <qmath.h>-
60#include <qmetaobject.h>-
61#include <qabstractproxymodel.h>-
62#include <qstylehints.h>-
63#include <private/qguiapplication_p.h>-
64#include <private/qapplication_p.h>-
65#include <private/qcombobox_p.h>-
66#include <private/qabstractitemmodel_p.h>-
67#include <private/qabstractscrollarea_p.h>-
68#include <qdebug.h>-
69#if defined(Q_DEAD_CODE_FROM_QT4_MAC) && !defined(QT_NO_EFFECTS) && !defined(QT_NO_STYLE_MAC)-
70#include <private/qcore_mac_p.h>-
71#include <private/qmacstyle_mac_p.h>-
72#include <private/qt_cocoa_helpers_mac_p.h>-
73#endif-
74#ifndef QT_NO_EFFECTS-
75# include <private/qeffects_p.h>-
76#endif-
77#ifndef QT_NO_ACCESSIBILITY-
78#include "qaccessible.h"-
79#endif-
80-
81QT_BEGIN_NAMESPACE-
82-
83QComboBoxPrivate::QComboBoxPrivate()-
84 : QWidgetPrivate(),-
85 model(0),-
86 lineEdit(0),-
87 container(0),-
88 insertPolicy(QComboBox::InsertAtBottom),-
89 sizeAdjustPolicy(QComboBox::AdjustToContentsOnFirstShow),-
90 minimumContentsLength(0),-
91 shownOnce(false),-
92 autoCompletion(true),-
93 duplicatesEnabled(false),-
94 frame(true),-
95 maxVisibleItems(10),-
96 maxCount(INT_MAX),-
97 modelColumn(0),-
98 inserting(false),-
99 arrowState(QStyle::State_None),-
100 hoverControl(QStyle::SC_None),-
101 autoCompletionCaseSensitivity(Qt::CaseInsensitive),-
102 indexBeforeChange(-1)-
103#ifdef Q_OS_MAC-
104 , m_platformMenu(0)-
105#endif-
106#ifndef QT_NO_COMPLETER-
107 , completer(0)-
108#endif-
109{-
110}
never executed: end of block
0
111-
112QComboBoxPrivate::~QComboBoxPrivate()-
113{-
114#ifdef Q_OS_MAC-
115 cleanupNativePopup();-
116#endif-
117}-
118-
119QStyleOptionMenuItem QComboMenuDelegate::getStyleOption(const QStyleOptionViewItem &option,-
120 const QModelIndex &index) const-
121{-
122 QStyleOptionMenuItem menuOption;-
123-
124 QPalette resolvedpalette = option.palette.resolve(QApplication::palette("QMenu"));-
125 QVariant value = index.data(Qt::ForegroundRole);-
126 if (value.canConvert<QBrush>()) {
value.canConvert<QBrush>()Description
TRUEnever evaluated
FALSEnever evaluated
0
127 resolvedpalette.setBrush(QPalette::WindowText, qvariant_cast<QBrush>(value));-
128 resolvedpalette.setBrush(QPalette::ButtonText, qvariant_cast<QBrush>(value));-
129 resolvedpalette.setBrush(QPalette::Text, qvariant_cast<QBrush>(value));-
130 }
never executed: end of block
0
131 menuOption.palette = resolvedpalette;-
132 menuOption.state = QStyle::State_None;-
133 if (mCombo->window()->isActiveWindow())
mCombo->window...ActiveWindow()Description
TRUEnever evaluated
FALSEnever evaluated
0
134 menuOption.state = QStyle::State_Active;
never executed: menuOption.state = QStyle::State_Active;
0
135 if ((option.state & QStyle::State_Enabled) && (index.model()->flags(index) & Qt::ItemIsEnabled))
(option.state ...State_Enabled)Description
TRUEnever evaluated
FALSEnever evaluated
(index.model()...ItemIsEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
0
136 menuOption.state |= QStyle::State_Enabled;
never executed: menuOption.state |= QStyle::State_Enabled;
0
137 else-
138 menuOption.palette.setCurrentColorGroup(QPalette::Disabled);
never executed: menuOption.palette.setCurrentColorGroup(QPalette::Disabled);
0
139 if (option.state & QStyle::State_Selected)
option.state &...State_SelectedDescription
TRUEnever evaluated
FALSEnever evaluated
0
140 menuOption.state |= QStyle::State_Selected;
never executed: menuOption.state |= QStyle::State_Selected;
0
141 menuOption.checkType = QStyleOptionMenuItem::NonExclusive;-
142 menuOption.checked = mCombo->currentIndex() == index.row();-
143 if (QComboBoxDelegate::isSeparator(index))
QComboBoxDeleg...parator(index)Description
TRUEnever evaluated
FALSEnever evaluated
0
144 menuOption.menuItemType = QStyleOptionMenuItem::Separator;
never executed: menuOption.menuItemType = QStyleOptionMenuItem::Separator;
0
145 else-
146 menuOption.menuItemType = QStyleOptionMenuItem::Normal;
never executed: menuOption.menuItemType = QStyleOptionMenuItem::Normal;
0
147-
148 QVariant variant = index.model()->data(index, Qt::DecorationRole);-
149 switch (variant.type()) {-
150 case QVariant::Icon:
never executed: case QVariant::Icon:
0
151 menuOption.icon = qvariant_cast<QIcon>(variant);-
152 break;
never executed: break;
0
153 case QVariant::Color: {
never executed: case QVariant::Color:
0
154 static QPixmap pixmap(option.decorationSize);-
155 pixmap.fill(qvariant_cast<QColor>(variant));-
156 menuOption.icon = pixmap;-
157 break; }
never executed: break;
0
158 default:
never executed: default:
0
159 menuOption.icon = qvariant_cast<QPixmap>(variant);-
160 break;
never executed: break;
0
161 }-
162 if (index.data(Qt::BackgroundRole).canConvert<QBrush>()) {
index.data(Qt:...vert<QBrush>()Description
TRUEnever evaluated
FALSEnever evaluated
0
163 menuOption.palette.setBrush(QPalette::All, QPalette::Background,-
164 qvariant_cast<QBrush>(index.data(Qt::BackgroundRole)));-
165 }
never executed: end of block
0
166 menuOption.text = index.model()->data(index, Qt::DisplayRole).toString()-
167 .replace(QLatin1Char('&'), QLatin1String("&&"));-
168 menuOption.tabWidth = 0;-
169 menuOption.maxIconWidth = option.decorationSize.width() + 4;-
170 menuOption.menuRect = option.rect;-
171 menuOption.rect = option.rect;-
172-
173 // Make sure fonts set on the combo box also overrides the font for the popup menu.-
174 if (mCombo->testAttribute(Qt::WA_SetFont)
mCombo->testAt...t::WA_SetFont)Description
TRUEnever evaluated
FALSEnever evaluated
0
175 || mCombo->testAttribute(Qt::WA_MacSmallSize)
mCombo->testAt..._MacSmallSize)Description
TRUEnever evaluated
FALSEnever evaluated
0
176 || mCombo->testAttribute(Qt::WA_MacMiniSize)
mCombo->testAt...A_MacMiniSize)Description
TRUEnever evaluated
FALSEnever evaluated
0
177 || mCombo->font() != qt_app_fonts_hash()->value("QComboBox", QFont())) {
mCombo->font()...Box", QFont())Description
TRUEnever evaluated
FALSEnever evaluated
0
178 menuOption.font = mCombo->font();-
179 } else {
never executed: end of block
0
180 QVariant fontRoleData = index.data(Qt::FontRole);-
181 if (fontRoleData.isValid())
fontRoleData.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
182 menuOption.font = fontRoleData.value<QFont>();
never executed: menuOption.font = fontRoleData.value<QFont>();
0
183 else-
184 menuOption.font = qt_app_fonts_hash()->value("QComboMenuItem", mCombo->font());
never executed: menuOption.font = qt_app_fonts_hash()->value("QComboMenuItem", mCombo->font());
0
185 }-
186-
187 menuOption.fontMetrics = QFontMetrics(menuOption.font);-
188-
189 return menuOption;
never executed: return menuOption;
0
190}-
191-
192#ifndef QT_NO_COMPLETER-
193void QComboBoxPrivate::_q_completerActivated(const QModelIndex &index)-
194{-
195 Q_Q(QComboBox);-
196 if (index.isValid() && q->completer()) {
index.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
q->completer()Description
TRUEnever evaluated
FALSEnever evaluated
0
197 QAbstractProxyModel *proxy = qobject_cast<QAbstractProxyModel *>(q->completer()->completionModel());-
198 if (proxy) {
proxyDescription
TRUEnever evaluated
FALSEnever evaluated
0
199 q->setCurrentIndex(proxy->mapToSource(index).row());-
200 emitActivated(currentIndex);-
201 }
never executed: end of block
0
202 }
never executed: end of block
0
203-
204# ifdef QT_KEYPAD_NAVIGATION-
205 if ( QApplication::keypadNavigationEnabled()-
206 && q->isEditable()-
207 && q->completer()-
208 && q->completer()->completionMode() == QCompleter::UnfilteredPopupCompletion ) {-
209 q->setEditFocus(false);-
210 }-
211# endif // QT_KEYPAD_NAVIGATION-
212}
never executed: end of block
0
213#endif // !QT_NO_COMPLETER-
214-
215void QComboBoxPrivate::updateArrow(QStyle::StateFlag state)-
216{-
217 Q_Q(QComboBox);-
218 if (arrowState == state)
arrowState == stateDescription
TRUEnever evaluated
FALSEnever evaluated
0
219 return;
never executed: return;
0
220 arrowState = state;-
221 QStyleOptionComboBox opt;-
222 q->initStyleOption(&opt);-
223 q->update(q->rect());-
224}
never executed: end of block
0
225-
226void QComboBoxPrivate::_q_modelReset()-
227{-
228 Q_Q(QComboBox);-
229 if (lineEdit) {
lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
0
230 lineEdit->setText(QString());-
231 updateLineEditGeometry();-
232 }
never executed: end of block
0
233 if (currentIndex.row() != indexBeforeChange)
currentIndex.r...exBeforeChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
234 _q_emitCurrentIndexChanged(currentIndex);
never executed: _q_emitCurrentIndexChanged(currentIndex);
0
235 modelChanged();-
236 q->update();-
237}
never executed: end of block
0
238-
239void QComboBoxPrivate::_q_modelDestroyed()-
240{-
241 model = QAbstractItemModelPrivate::staticEmptyModel();-
242}
never executed: end of block
0
243-
244-
245//Windows and KDE allows menus to cover the taskbar, while GNOME and Mac don't-
246QRect QComboBoxPrivate::popupGeometry(int screen) const-
247{-
248 bool useFullScreenForPopupMenu = false;-
249 if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme())
const QPlatfor...latformTheme()Description
TRUEnever evaluated
FALSEnever evaluated
0
250 useFullScreenForPopupMenu = theme->themeHint(QPlatformTheme::UseFullScreenForPopupMenu).toBool();
never executed: useFullScreenForPopupMenu = theme->themeHint(QPlatformTheme::UseFullScreenForPopupMenu).toBool();
0
251 return useFullScreenForPopupMenu ?
never executed: return useFullScreenForPopupMenu ? QApplication::desktop()->screenGeometry(screen) : QApplication::desktop()->availableGeometry(screen);
0
252 QApplication::desktop()->screenGeometry(screen) :
never executed: return useFullScreenForPopupMenu ? QApplication::desktop()->screenGeometry(screen) : QApplication::desktop()->availableGeometry(screen);
0
253 QApplication::desktop()->availableGeometry(screen);
never executed: return useFullScreenForPopupMenu ? QApplication::desktop()->screenGeometry(screen) : QApplication::desktop()->availableGeometry(screen);
0
254}-
255-
256bool QComboBoxPrivate::updateHoverControl(const QPoint &pos)-
257{-
258-
259 Q_Q(QComboBox);-
260 QRect lastHoverRect = hoverRect;-
261 QStyle::SubControl lastHoverControl = hoverControl;-
262 bool doesHover = q->testAttribute(Qt::WA_Hover);-
263 if (lastHoverControl != newHoverControl(pos) && doesHover) {
lastHoverContr...erControl(pos)Description
TRUEnever evaluated
FALSEnever evaluated
doesHoverDescription
TRUEnever evaluated
FALSEnever evaluated
0
264 q->update(lastHoverRect);-
265 q->update(hoverRect);-
266 return true;
never executed: return true;
0
267 }-
268 return !doesHover;
never executed: return !doesHover;
0
269}-
270-
271QStyle::SubControl QComboBoxPrivate::newHoverControl(const QPoint &pos)-
272{-
273 Q_Q(QComboBox);-
274 QStyleOptionComboBox opt;-
275 q->initStyleOption(&opt);-
276 opt.subControls = QStyle::SC_All;-
277 hoverControl = q->style()->hitTestComplexControl(QStyle::CC_ComboBox, &opt, pos, q);-
278 hoverRect = (hoverControl != QStyle::SC_None)
(hoverControl ...tyle::SC_None)Description
TRUEnever evaluated
FALSEnever evaluated
0
279 ? q->style()->subControlRect(QStyle::CC_ComboBox, &opt, hoverControl, q)-
280 : QRect();-
281 return hoverControl;
never executed: return hoverControl;
0
282}-
283-
284/*-
285 Computes a size hint based on the maximum width-
286 for the items in the combobox.-
287*/-
288int QComboBoxPrivate::computeWidthHint() const-
289{-
290 Q_Q(const QComboBox);-
291-
292 int width = 0;-
293 const int count = q->count();-
294 const int iconWidth = q->iconSize().width() + 4;-
295 const QFontMetrics &fontMetrics = q->fontMetrics();-
296-
297 for (int i = 0; i < count; ++i) {
i < countDescription
TRUEnever evaluated
FALSEnever evaluated
0
298 const int textWidth = fontMetrics.width(q->itemText(i));-
299 if (q->itemIcon(i).isNull())
q->itemIcon(i).isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
300 width = (qMax(width, textWidth));
never executed: width = (qMax(width, textWidth));
0
301 else-
302 width = (qMax(width, textWidth + iconWidth));
never executed: width = (qMax(width, textWidth + iconWidth));
0
303 }-
304-
305 QStyleOptionComboBox opt;-
306 q->initStyleOption(&opt);-
307 QSize tmp(width, 0);-
308 tmp = q->style()->sizeFromContents(QStyle::CT_ComboBox, &opt, tmp, q);-
309 return tmp.width();
never executed: return tmp.width();
0
310}-
311-
312QSize QComboBoxPrivate::recomputeSizeHint(QSize &sh) const-
313{-
314 Q_Q(const QComboBox);-
315 if (!sh.isValid()) {
!sh.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
316 bool hasIcon = sizeAdjustPolicy == QComboBox::AdjustToMinimumContentsLengthWithIcon;-
317 int count = q->count();-
318 QSize iconSize = q->iconSize();-
319 const QFontMetrics &fm = q->fontMetrics();-
320-
321 // text width-
322 if (&sh == &sizeHint || minimumContentsLength == 0) {
&sh == &sizeHintDescription
TRUEnever evaluated
FALSEnever evaluated
minimumContentsLength == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
323 switch (sizeAdjustPolicy) {-
324 case QComboBox::AdjustToContents:
never executed: case QComboBox::AdjustToContents:
0
325 case QComboBox::AdjustToContentsOnFirstShow:
never executed: case QComboBox::AdjustToContentsOnFirstShow:
0
326 if (count == 0) {
count == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
327 sh.rwidth() = 7 * fm.width(QLatin1Char('x'));-
328 } else {
never executed: end of block
0
329 for (int i = 0; i < count; ++i) {
i < countDescription
TRUEnever evaluated
FALSEnever evaluated
0
330 if (!q->itemIcon(i).isNull()) {
!q->itemIcon(i).isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
331 hasIcon = true;-
332 sh.setWidth(qMax(sh.width(), fm.boundingRect(q->itemText(i)).width() + iconSize.width() + 4));-
333 } else {
never executed: end of block
0
334 sh.setWidth(qMax(sh.width(), fm.boundingRect(q->itemText(i)).width()));-
335 }
never executed: end of block
0
336 }-
337 }
never executed: end of block
0
338 break;
never executed: break;
0
339 case QComboBox::AdjustToMinimumContentsLength:
never executed: case QComboBox::AdjustToMinimumContentsLength:
0
340 for (int i = 0; i < count && !hasIcon; ++i)
i < countDescription
TRUEnever evaluated
FALSEnever evaluated
!hasIconDescription
TRUEnever evaluated
FALSEnever evaluated
0
341 hasIcon = !q->itemIcon(i).isNull();
never executed: hasIcon = !q->itemIcon(i).isNull();
0
342 default:
code before this statement never executed: default:
never executed: default:
0
343 ;-
344 }
never executed: end of block
0
345 } else {-
346 for (int i = 0; i < count && !hasIcon; ++i)
i < countDescription
TRUEnever evaluated
FALSEnever evaluated
!hasIconDescription
TRUEnever evaluated
FALSEnever evaluated
0
347 hasIcon = !q->itemIcon(i).isNull();
never executed: hasIcon = !q->itemIcon(i).isNull();
0
348 }
never executed: end of block
0
349 if (minimumContentsLength > 0)
minimumContentsLength > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
350 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
351-
352-
353 // height-
354 sh.setHeight(qMax(qCeil(QFontMetricsF(fm).height()), 14) + 2);-
355 if (hasIcon) {
hasIconDescription
TRUEnever evaluated
FALSEnever evaluated
0
356 sh.setHeight(qMax(sh.height(), iconSize.height() + 2));-
357 }
never executed: end of block
0
358-
359 // add style and strut values-
360 QStyleOptionComboBox opt;-
361 q->initStyleOption(&opt);-
362 sh = q->style()->sizeFromContents(QStyle::CT_ComboBox, &opt, sh, q);-
363 }
never executed: end of block
0
364 return sh.expandedTo(QApplication::globalStrut());
never executed: return sh.expandedTo(QApplication::globalStrut());
0
365}-
366-
367void QComboBoxPrivate::adjustComboBoxSize()-
368{-
369 viewContainer()->adjustSizeTimer.start(20, container);-
370}
never executed: end of block
0
371-
372void QComboBoxPrivate::updateLayoutDirection()-
373{-
374 Q_Q(const QComboBox);-
375 QStyleOptionComboBox opt;-
376 q->initStyleOption(&opt);-
377 Qt::LayoutDirection dir = Qt::LayoutDirection(-
378 q->style()->styleHint(QStyle::SH_ComboBox_LayoutDirection, &opt, q));-
379 if (lineEdit)
lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
0
380 lineEdit->setLayoutDirection(dir);
never executed: lineEdit->setLayoutDirection(dir);
0
381 if (container)
containerDescription
TRUEnever evaluated
FALSEnever evaluated
0
382 container->setLayoutDirection(dir);
never executed: container->setLayoutDirection(dir);
0
383}
never executed: end of block
0
384-
385-
386void QComboBoxPrivateContainer::timerEvent(QTimerEvent *timerEvent)-
387{-
388 if (timerEvent->timerId() == adjustSizeTimer.timerId()) {
timerEvent->ti...imer.timerId()Description
TRUEnever evaluated
FALSEnever evaluated
0
389 adjustSizeTimer.stop();-
390 if (combo->sizeAdjustPolicy() == QComboBox::AdjustToContents) {
combo->sizeAdj...justToContentsDescription
TRUEnever evaluated
FALSEnever evaluated
0
391 combo->updateGeometry();-
392 combo->adjustSize();-
393 combo->update();-
394 }
never executed: end of block
0
395 }
never executed: end of block
0
396}
never executed: end of block
0
397-
398void QComboBoxPrivateContainer::resizeEvent(QResizeEvent *e)-
399{-
400 QStyleOptionComboBox opt = comboStyleOption();-
401 if (combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo)) {
combo->style()..., &opt, combo)Description
TRUEnever evaluated
FALSEnever evaluated
0
402 QStyleOption myOpt;-
403 myOpt.initFrom(this);-
404 QStyleHintReturnMask mask;-
405 if (combo->style()->styleHint(QStyle::SH_Menu_Mask, &myOpt, this, &mask)) {
combo->style()..., this, &mask)Description
TRUEnever evaluated
FALSEnever evaluated
0
406 setMask(mask.region);-
407 }
never executed: end of block
0
408 } else {
never executed: end of block
0
409 clearMask();-
410 }
never executed: end of block
0
411 QFrame::resizeEvent(e);-
412}
never executed: end of block
0
413-
414void QComboBoxPrivateContainer::leaveEvent(QEvent *)-
415{-
416// On Mac using the Mac style we want to clear the selection-
417// when the mouse moves outside the popup.-
418#ifdef Q_DEAD_CODE_FROM_QT4_MAC-
419 QStyleOptionComboBox opt = comboStyleOption();-
420 if (combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo))-
421 view->clearSelection();-
422#endif-
423}-
424-
425QComboBoxPrivateContainer::QComboBoxPrivateContainer(QAbstractItemView *itemView, QComboBox *parent)-
426 : QFrame(parent, Qt::Popup), combo(parent), view(0), top(0), bottom(0), maybeIgnoreMouseButtonRelease(false)-
427{-
428 // we need the combobox and itemview-
429 Q_ASSERT(parent);-
430 Q_ASSERT(itemView);-
431-
432 setAttribute(Qt::WA_WindowPropagation);-
433 setAttribute(Qt::WA_X11NetWmWindowTypeCombo);-
434-
435 // setup container-
436 blockMouseReleaseTimer.setSingleShot(true);-
437-
438 // we need a vertical layout-
439 QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom, this);-
440 layout->setSpacing(0);-
441 layout->setMargin(0);-
442-
443 // set item view-
444 setItemView(itemView);-
445-
446 // add scroller arrows if style needs them-
447 QStyleOptionComboBox opt = comboStyleOption();-
448 const bool usePopup = combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo);-
449 if (usePopup) {
usePopupDescription
TRUEnever evaluated
FALSEnever evaluated
0
450 top = new QComboBoxPrivateScroller(QAbstractSlider::SliderSingleStepSub, this);-
451 bottom = new QComboBoxPrivateScroller(QAbstractSlider::SliderSingleStepAdd, this);-
452 top->hide();-
453 bottom->hide();-
454 } else {
never executed: end of block
0
455 setLineWidth(1);-
456 }
never executed: end of block
0
457-
458 setFrameStyle(combo->style()->styleHint(QStyle::SH_ComboBox_PopupFrameStyle, &opt, combo));-
459-
460 if (top) {
topDescription
TRUEnever evaluated
FALSEnever evaluated
0
461 layout->insertWidget(0, top);-
462 connect(top, SIGNAL(doScroll(int)), this, SLOT(scrollItemView(int)));-
463 }
never executed: end of block
0
464 if (bottom) {
bottomDescription
TRUEnever evaluated
FALSEnever evaluated
0
465 layout->addWidget(bottom);-
466 connect(bottom, SIGNAL(doScroll(int)), this, SLOT(scrollItemView(int)));-
467 }
never executed: end of block
0
468-
469 // Some styles (Mac) have a margin at the top and bottom of the popup.-
470 layout->insertSpacing(0, 0);-
471 layout->addSpacing(0);-
472 updateTopBottomMargin();-
473}
never executed: end of block
0
474-
475void QComboBoxPrivateContainer::scrollItemView(int action)-
476{-
477#ifndef QT_NO_SCROLLBAR-
478 if (view->verticalScrollBar())
view->verticalScrollBar()Description
TRUEnever evaluated
FALSEnever evaluated
0
479 view->verticalScrollBar()->triggerAction(static_cast<QAbstractSlider::SliderAction>(action));
never executed: view->verticalScrollBar()->triggerAction(static_cast<QAbstractSlider::SliderAction>(action));
0
480#endif-
481}
never executed: end of block
0
482-
483/*-
484 Hides or shows the scrollers when we emulate a popupmenu-
485*/-
486void QComboBoxPrivateContainer::updateScrollers()-
487{-
488#ifndef QT_NO_SCROLLBAR-
489 if (!top || !bottom)
!topDescription
TRUEnever evaluated
FALSEnever evaluated
!bottomDescription
TRUEnever evaluated
FALSEnever evaluated
0
490 return;
never executed: return;
0
491-
492 if (isVisible() == false)
isVisible() == falseDescription
TRUEnever evaluated
FALSEnever evaluated
0
493 return;
never executed: return;
0
494-
495 QStyleOptionComboBox opt = comboStyleOption();-
496 if (combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo) &&
combo->style()..., &opt, combo)Description
TRUEnever evaluated
FALSEnever evaluated
0
497 view->verticalScrollBar()->minimum() < view->verticalScrollBar()->maximum()) {
view->vertical...r()->maximum()Description
TRUEnever evaluated
FALSEnever evaluated
0
498-
499 bool needTop = view->verticalScrollBar()->value()-
500 > (view->verticalScrollBar()->minimum() + topMargin());-
501 bool needBottom = view->verticalScrollBar()->value()-
502 < (view->verticalScrollBar()->maximum() - bottomMargin() - topMargin());-
503 if (needTop)
needTopDescription
TRUEnever evaluated
FALSEnever evaluated
0
504 top->show();
never executed: top->show();
0
505 else-
506 top->hide();
never executed: top->hide();
0
507 if (needBottom)
needBottomDescription
TRUEnever evaluated
FALSEnever evaluated
0
508 bottom->show();
never executed: bottom->show();
0
509 else-
510 bottom->hide();
never executed: bottom->hide();
0
511 } else {-
512 top->hide();-
513 bottom->hide();-
514 }
never executed: end of block
0
515#endif // QT_NO_SCROLLBAR-
516}-
517-
518/*-
519 Cleans up when the view is destroyed.-
520*/-
521void QComboBoxPrivateContainer::viewDestroyed()-
522{-
523 view = 0;-
524 setItemView(new QComboBoxListView());-
525}
never executed: end of block
0
526-
527/*-
528 Returns the item view used for the combobox popup.-
529*/-
530QAbstractItemView *QComboBoxPrivateContainer::itemView() const-
531{-
532 return view;
never executed: return view;
0
533}-
534-
535/*!-
536 Sets the item view to be used for the combobox popup.-
537*/-
538void QComboBoxPrivateContainer::setItemView(QAbstractItemView *itemView)-
539{-
540 Q_ASSERT(itemView);-
541-
542 // clean up old one-
543 if (view) {
viewDescription
TRUEnever evaluated
FALSEnever evaluated
0
544 view->removeEventFilter(this);-
545 view->viewport()->removeEventFilter(this);-
546#ifndef QT_NO_SCROLLBAR-
547 disconnect(view->verticalScrollBar(), SIGNAL(valueChanged(int)),-
548 this, SLOT(updateScrollers()));-
549 disconnect(view->verticalScrollBar(), SIGNAL(rangeChanged(int,int)),-
550 this, SLOT(updateScrollers()));-
551#endif-
552 disconnect(view, SIGNAL(destroyed()),-
553 this, SLOT(viewDestroyed()));-
554-
555 if (isAncestorOf(view))
isAncestorOf(view)Description
TRUEnever evaluated
FALSEnever evaluated
0
556 delete view;
never executed: delete view;
0
557 view = 0;-
558 }
never executed: end of block
0
559-
560 // setup the item view-
561 view = itemView;-
562 view->setParent(this);-
563 view->setAttribute(Qt::WA_MacShowFocusRect, false);-
564 qobject_cast<QBoxLayout*>(layout())->insertWidget(top ? 2 : 0, view);-
565 view->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);-
566 view->installEventFilter(this);-
567 view->viewport()->installEventFilter(this);-
568 view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);-
569 QStyleOptionComboBox opt = comboStyleOption();-
570 const bool usePopup = combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo);-
571#ifndef QT_NO_SCROLLBAR-
572 if (usePopup)
usePopupDescription
TRUEnever evaluated
FALSEnever evaluated
0
573 view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
never executed: view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
0
574#endif-
575 if (combo->style()->styleHint(QStyle::SH_ComboBox_ListMouseTracking, &opt, combo) ||
combo->style()..., &opt, combo)Description
TRUEnever evaluated
FALSEnever evaluated
0
576 usePopup) {
usePopupDescription
TRUEnever evaluated
FALSEnever evaluated
0
577 view->setMouseTracking(true);-
578 }
never executed: end of block
0
579 view->setSelectionMode(QAbstractItemView::SingleSelection);-
580 view->setFrameStyle(QFrame::NoFrame);-
581 view->setLineWidth(0);-
582 view->setEditTriggers(QAbstractItemView::NoEditTriggers);-
583#ifndef QT_NO_SCROLLBAR-
584 connect(view->verticalScrollBar(), SIGNAL(valueChanged(int)),-
585 this, SLOT(updateScrollers()));-
586 connect(view->verticalScrollBar(), SIGNAL(rangeChanged(int,int)),-
587 this, SLOT(updateScrollers()));-
588#endif-
589 connect(view, SIGNAL(destroyed()),-
590 this, SLOT(viewDestroyed()));-
591}
never executed: end of block
0
592-
593/*!-
594 Returns the top/bottom vertical margin of the view.-
595*/-
596int QComboBoxPrivateContainer::topMargin() const-
597{-
598 if (const QListView *lview = qobject_cast<const QListView*>(view))
const QListVie...stView*>(view)Description
TRUEnever evaluated
FALSEnever evaluated
0
599 return lview->spacing();
never executed: return lview->spacing();
0
600#ifndef QT_NO_TABLEVIEW-
601 if (const QTableView *tview = qobject_cast<const QTableView*>(view))
const QTableVi...leView*>(view)Description
TRUEnever evaluated
FALSEnever evaluated
0
602 return tview->showGrid() ? 1 : 0;
never executed: return tview->showGrid() ? 1 : 0;
0
603#endif-
604 return 0;
never executed: return 0;
0
605}-
606-
607/*!-
608 Returns the spacing between the items in the view.-
609*/-
610int QComboBoxPrivateContainer::spacing() const-
611{-
612 QListView *lview = qobject_cast<QListView*>(view);-
613 if (lview)
lviewDescription
TRUEnever evaluated
FALSEnever evaluated
0
614 return 2 * lview->spacing(); // QListView::spacing is the padding around the item.
never executed: return 2 * lview->spacing();
0
615#ifndef QT_NO_TABLEVIEW-
616 QTableView *tview = qobject_cast<QTableView*>(view);-
617 if (tview)
tviewDescription
TRUEnever evaluated
FALSEnever evaluated
0
618 return tview->showGrid() ? 1 : 0;
never executed: return tview->showGrid() ? 1 : 0;
0
619#endif-
620 return 0;
never executed: return 0;
0
621}-
622-
623void QComboBoxPrivateContainer::updateTopBottomMargin()-
624{-
625 if (!layout() || layout()->count() < 1)
!layout()Description
TRUEnever evaluated
FALSEnever evaluated
layout()->count() < 1Description
TRUEnever evaluated
FALSEnever evaluated
0
626 return;
never executed: return;
0
627-
628 QBoxLayout *boxLayout = qobject_cast<QBoxLayout *>(layout());-
629 if (!boxLayout)
!boxLayoutDescription
TRUEnever evaluated
FALSEnever evaluated
0
630 return;
never executed: return;
0
631-
632 const QStyleOptionComboBox opt = comboStyleOption();-
633 const bool usePopup = combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo);-
634 const int margin = usePopup ? combo->style()->pixelMetric(QStyle::PM_MenuVMargin, &opt, combo) : 0;
usePopupDescription
TRUEnever evaluated
FALSEnever evaluated
0
635-
636 QSpacerItem *topSpacer = boxLayout->itemAt(0)->spacerItem();-
637 if (topSpacer)
topSpacerDescription
TRUEnever evaluated
FALSEnever evaluated
0
638 topSpacer->changeSize(0, margin, QSizePolicy::Minimum, QSizePolicy::Fixed);
never executed: topSpacer->changeSize(0, margin, QSizePolicy::Minimum, QSizePolicy::Fixed);
0
639-
640 QSpacerItem *bottomSpacer = boxLayout->itemAt(boxLayout->count() - 1)->spacerItem();-
641 if (bottomSpacer && bottomSpacer != topSpacer)
bottomSpacerDescription
TRUEnever evaluated
FALSEnever evaluated
bottomSpacer != topSpacerDescription
TRUEnever evaluated
FALSEnever evaluated
0
642 bottomSpacer->changeSize(0, margin, QSizePolicy::Minimum, QSizePolicy::Fixed);
never executed: bottomSpacer->changeSize(0, margin, QSizePolicy::Minimum, QSizePolicy::Fixed);
0
643-
644 boxLayout->invalidate();-
645}
never executed: end of block
0
646-
647void QComboBoxPrivateContainer::changeEvent(QEvent *e)-
648{-
649 if (e->type() == QEvent::StyleChange) {
e->type() == Q...t::StyleChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
650 QStyleOptionComboBox opt = comboStyleOption();-
651 view->setMouseTracking(combo->style()->styleHint(QStyle::SH_ComboBox_ListMouseTracking, &opt, combo) ||-
652 combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo));-
653 setFrameStyle(combo->style()->styleHint(QStyle::SH_ComboBox_PopupFrameStyle, &opt, combo));-
654 }
never executed: end of block
0
655-
656 QWidget::changeEvent(e);-
657}
never executed: end of block
0
658-
659-
660bool QComboBoxPrivateContainer::eventFilter(QObject *o, QEvent *e)-
661{-
662 switch (e->type()) {-
663 case QEvent::ShortcutOverride: {
never executed: case QEvent::ShortcutOverride:
0
664 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(e);-
665 switch (keyEvent->key()) {-
666 case Qt::Key_Enter:
never executed: case Qt::Key_Enter:
0
667 case Qt::Key_Return:
never executed: case Qt::Key_Return:
0
668#ifdef QT_KEYPAD_NAVIGATION-
669 case Qt::Key_Select:-
670#endif-
671 if (view->currentIndex().isValid() && (view->currentIndex().flags() & Qt::ItemIsEnabled) ) {
view->currentIndex().isValid()Description
TRUEnever evaluated
FALSEnever evaluated
(view->current...ItemIsEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
0
672 combo->hidePopup();-
673 emit itemSelected(view->currentIndex());-
674 }
never executed: end of block
0
675 return true;
never executed: return true;
0
676 case Qt::Key_Down:
never executed: case Qt::Key_Down:
0
677 if (!(keyEvent->modifiers() & Qt::AltModifier))
!(keyEvent->mo...::AltModifier)Description
TRUEnever evaluated
FALSEnever evaluated
0
678 break;
never executed: break;
0
679 // fall through-
680 case Qt::Key_F4:
code before this statement never executed: case Qt::Key_F4:
never executed: case Qt::Key_F4:
0
681 combo->hidePopup();-
682 return true;
never executed: return true;
0
683 default:
never executed: default:
0
684 if (keyEvent->matches(QKeySequence::Cancel)) {
keyEvent->matc...uence::Cancel)Description
TRUEnever evaluated
FALSEnever evaluated
0
685 combo->hidePopup();-
686 return true;
never executed: return true;
0
687 }-
688 break;
never executed: break;
0
689 }-
690 break;
never executed: break;
0
691 }-
692 case QEvent::MouseMove:
never executed: case QEvent::MouseMove:
0
693 if (isVisible()) {
isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
694 QMouseEvent *m = static_cast<QMouseEvent *>(e);-
695 QWidget *widget = static_cast<QWidget *>(o);-
696 QPoint vector = widget->mapToGlobal(m->pos()) - initialClickPosition;-
697 if (vector.manhattanLength() > 9 && blockMouseReleaseTimer.isActive())
vector.manhattanLength() > 9Description
TRUEnever evaluated
FALSEnever evaluated
blockMouseRele...mer.isActive()Description
TRUEnever evaluated
FALSEnever evaluated
0
698 blockMouseReleaseTimer.stop();
never executed: blockMouseReleaseTimer.stop();
0
699 QModelIndex indexUnderMouse = view->indexAt(m->pos());-
700 if (indexUnderMouse.isValid()
indexUnderMouse.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
701 && !QComboBoxDelegate::isSeparator(indexUnderMouse)) {
!QComboBoxDele...dexUnderMouse)Description
TRUEnever evaluated
FALSEnever evaluated
0
702 view->setCurrentIndex(indexUnderMouse);-
703 }
never executed: end of block
0
704 }
never executed: end of block
0
705 break;
never executed: break;
0
706 case QEvent::MouseButtonPress:
never executed: case QEvent::MouseButtonPress:
0
707 maybeIgnoreMouseButtonRelease = false;-
708 break;
never executed: break;
0
709 case QEvent::MouseButtonRelease: {
never executed: case QEvent::MouseButtonRelease:
0
710 bool ignoreEvent = maybeIgnoreMouseButtonRelease && popupTimer.elapsed() < QApplication::doubleClickInterval();
maybeIgnoreMouseButtonReleaseDescription
TRUEnever evaluated
FALSEnever evaluated
popupTimer.ela...lickInterval()Description
TRUEnever evaluated
FALSEnever evaluated
0
711-
712 QMouseEvent *m = static_cast<QMouseEvent *>(e);-
713 if (isVisible() && view->rect().contains(m->pos()) && view->currentIndex().isValid()
isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
view->rect().c...ains(m->pos())Description
TRUEnever evaluated
FALSEnever evaluated
view->currentIndex().isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
714 && !blockMouseReleaseTimer.isActive() && !ignoreEvent
!blockMouseRel...mer.isActive()Description
TRUEnever evaluated
FALSEnever evaluated
!ignoreEventDescription
TRUEnever evaluated
FALSEnever evaluated
0
715 && (view->currentIndex().flags() & Qt::ItemIsEnabled)
(view->current...ItemIsEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
0
716 && (view->currentIndex().flags() & Qt::ItemIsSelectable)) {
(view->current...mIsSelectable)Description
TRUEnever evaluated
FALSEnever evaluated
0
717 combo->hidePopup();-
718 emit itemSelected(view->currentIndex());-
719 return true;
never executed: return true;
0
720 }-
721 break;
never executed: break;
0
722 }-
723 default:
never executed: default:
0
724 break;
never executed: break;
0
725 }-
726 return QFrame::eventFilter(o, e);
never executed: return QFrame::eventFilter(o, e);
0
727}-
728-
729void QComboBoxPrivateContainer::showEvent(QShowEvent *)-
730{-
731 combo->update();-
732}
never executed: end of block
0
733-
734void QComboBoxPrivateContainer::hideEvent(QHideEvent *)-
735{-
736 emit resetButton();-
737 combo->update();-
738#ifndef QT_NO_GRAPHICSVIEW-
739 // QGraphicsScenePrivate::removePopup closes the combo box popup, it hides it non-explicitly.-
740 // Hiding/showing the QComboBox after this will unexpectedly show the popup as well.-
741 // Re-hiding the popup container makes sure it is explicitly hidden.-
742 if (QGraphicsProxyWidget *proxy = graphicsProxyWidget())
QGraphicsProxy...sProxyWidget()Description
TRUEnever evaluated
FALSEnever evaluated
0
743 proxy->hide();
never executed: proxy->hide();
0
744#endif-
745}
never executed: end of block
0
746-
747void QComboBoxPrivateContainer::mousePressEvent(QMouseEvent *e)-
748{-
749-
750 QStyleOptionComboBox opt = comboStyleOption();-
751 opt.subControls = QStyle::SC_All;-
752 opt.activeSubControls = QStyle::SC_ComboBoxArrow;-
753 QStyle::SubControl sc = combo->style()->hitTestComplexControl(QStyle::CC_ComboBox, &opt,-
754 combo->mapFromGlobal(e->globalPos()),-
755 combo);-
756 if ((combo->isEditable() && sc == QStyle::SC_ComboBoxArrow)
combo->isEditable()Description
TRUEnever evaluated
FALSEnever evaluated
sc == QStyle::SC_ComboBoxArrowDescription
TRUEnever evaluated
FALSEnever evaluated
0
757 || (!combo->isEditable() && sc != QStyle::SC_None))
!combo->isEditable()Description
TRUEnever evaluated
FALSEnever evaluated
sc != QStyle::SC_NoneDescription
TRUEnever evaluated
FALSEnever evaluated
0
758 setAttribute(Qt::WA_NoMouseReplay);
never executed: setAttribute(Qt::WA_NoMouseReplay);
0
759 combo->hidePopup();-
760}
never executed: end of block
0
761-
762void QComboBoxPrivateContainer::mouseReleaseEvent(QMouseEvent *e)-
763{-
764 Q_UNUSED(e);-
765 if (!blockMouseReleaseTimer.isActive()){
!blockMouseRel...mer.isActive()Description
TRUEnever evaluated
FALSEnever evaluated
0
766 combo->hidePopup();-
767 emit resetButton();-
768 }
never executed: end of block
0
769}
never executed: end of block
0
770-
771QStyleOptionComboBox QComboBoxPrivateContainer::comboStyleOption() const-
772{-
773 // ### This should use QComboBox's initStyleOption(), but it's protected-
774 // perhaps, we could cheat by having the QCombo private instead?-
775 QStyleOptionComboBox opt;-
776 opt.initFrom(combo);-
777 opt.subControls = QStyle::SC_All;-
778 opt.activeSubControls = QStyle::SC_None;-
779 opt.editable = combo->isEditable();-
780 return opt;
never executed: return opt;
0
781}-
782-
783/*!-
784 \enum QComboBox::InsertPolicy-
785-
786 This enum specifies what the QComboBox should do when a new string is-
787 entered by the user.-
788-
789 \value NoInsert The string will not be inserted into the combobox.-
790 \value InsertAtTop The string will be inserted as the first item in the combobox.-
791 \value InsertAtCurrent The current item will be \e replaced by the string.-
792 \value InsertAtBottom The string will be inserted after the last item in the combobox.-
793 \value InsertAfterCurrent The string is inserted after the current item in the combobox.-
794 \value InsertBeforeCurrent The string is inserted before the current item in the combobox.-
795 \value InsertAlphabetically The string is inserted in the alphabetic order in the combobox.-
796*/-
797-
798/*!-
799 \enum QComboBox::SizeAdjustPolicy-
800-
801 This enum specifies how the size hint of the QComboBox should-
802 adjust when new content is added or content changes.-
803-
804 \value AdjustToContents The combobox will always adjust to the contents-
805 \value AdjustToContentsOnFirstShow The combobox will adjust to its contents the first time it is shown.-
806 \value AdjustToMinimumContentsLength Use AdjustToContents or AdjustToContentsOnFirstShow instead.-
807 \value AdjustToMinimumContentsLengthWithIcon The combobox will adjust to \l minimumContentsLength plus space for an icon. For performance reasons use this policy on large models.-
808*/-
809-
810/*!-
811 \fn void QComboBox::activated(int index)-
812-
813 This signal is sent when the user chooses an item in the combobox.-
814 The item's \a index is passed. Note that this signal is sent even-
815 when the choice is not changed. If you need to know when the-
816 choice actually changes, use signal currentIndexChanged().-
817-
818*/-
819-
820/*!-
821 \fn void QComboBox::activated(const QString &text)-
822-
823 This signal is sent when the user chooses an item in the combobox.-
824 The item's \a text is passed. Note that this signal is sent even-
825 when the choice is not changed. If you need to know when the-
826 choice actually changes, use signal currentIndexChanged().-
827-
828*/-
829-
830/*!-
831 \fn void QComboBox::highlighted(int index)-
832-
833 This signal is sent when an item in the combobox popup list is-
834 highlighted by the user. The item's \a index is passed.-
835*/-
836-
837/*!-
838 \fn void QComboBox::highlighted(const QString &text)-
839-
840 This signal is sent when an item in the combobox popup list is-
841 highlighted by the user. The item's \a text is passed.-
842*/-
843-
844/*!-
845 \fn void QComboBox::currentIndexChanged(int index)-
846 \since 4.1-
847-
848 This signal is sent whenever the currentIndex in the combobox-
849 changes either through user interaction or programmatically. The-
850 item's \a index is passed or -1 if the combobox becomes empty or the-
851 currentIndex was reset.-
852*/-
853-
854/*!-
855 \fn void QComboBox::currentIndexChanged(const QString &text)-
856 \since 4.1-
857-
858 This signal is sent whenever the currentIndex in the combobox-
859 changes either through user interaction or programmatically. The-
860 item's \a text is passed.-
861*/-
862-
863/*!-
864 \fn void QComboBox::currentTextChanged(const QString &text)-
865 \since 5.0-
866-
867 This signal is sent whenever currentText changes. The new value-
868 is passed as \a text.-
869*/-
870-
871/*!-
872 Constructs a combobox with the given \a parent, using the default-
873 model QStandardItemModel.-
874*/-
875QComboBox::QComboBox(QWidget *parent)-
876 : QWidget(*new QComboBoxPrivate(), parent, 0)-
877{-
878 Q_D(QComboBox);-
879 d->init();-
880}
never executed: end of block
0
881-
882/*!-
883 \internal-
884*/-
885QComboBox::QComboBox(QComboBoxPrivate &dd, QWidget *parent)-
886 : QWidget(dd, parent, 0)-
887{-
888 Q_D(QComboBox);-
889 d->init();-
890}
never executed: end of block
0
891-
892-
893/*!-
894 \class QComboBox-
895 \brief The QComboBox widget is a combined button and popup list.-
896-
897 \ingroup basicwidgets-
898 \inmodule QtWidgets-
899-
900 A QComboBox provides a means of presenting a list of options to the user-
901 in a way that takes up the minimum amount of screen space.-
902-
903 A combobox is a selection widget that displays the current item,-
904 and can pop up a list of selectable items. A combobox may be editable,-
905 allowing the user to modify each item in the list.-
906-
907 Comboboxes can contain pixmaps as well as strings; the-
908 insertItem() and setItemText() functions are suitably overloaded.-
909 For editable comboboxes, the function clearEditText() is provided,-
910 to clear the displayed string without changing the combobox's-
911 contents.-
912-
913 There are two signals emitted if the current item of a combobox-
914 changes, currentIndexChanged() and activated().-
915 currentIndexChanged() is always emitted regardless if the change-
916 was done programmatically or by user interaction, while-
917 activated() is only emitted when the change is caused by user-
918 interaction. The highlighted() signal is emitted when the user-
919 highlights an item in the combobox popup list. All three signals-
920 exist in two versions, one with a QString argument and one with an-
921 \c int argument. If the user selects or highlights a pixmap, only-
922 the \c int signals are emitted. Whenever the text of an editable-
923 combobox is changed the editTextChanged() signal is emitted.-
924-
925 When the user enters a new string in an editable combobox, the-
926 widget may or may not insert it, and it can insert it in several-
927 locations. The default policy is \l InsertAtBottom but you can change-
928 this using setInsertPolicy().-
929-
930 It is possible to constrain the input to an editable combobox-
931 using QValidator; see setValidator(). By default, any input is-
932 accepted.-
933-
934 A combobox can be populated using the insert functions,-
935 insertItem() and insertItems() for example. Items can be-
936 changed with setItemText(). An item can be removed with-
937 removeItem() and all items can be removed with clear(). The text-
938 of the current item is returned by currentText(), and the text of-
939 a numbered item is returned with text(). The current item can be-
940 set with setCurrentIndex(). The number of items in the combobox is-
941 returned by count(); the maximum number of items can be set with-
942 setMaxCount(). You can allow editing using setEditable(). For-
943 editable comboboxes you can set auto-completion using-
944 setCompleter() and whether or not the user can add duplicates-
945 is set with setDuplicatesEnabled().-
946-
947 QComboBox uses the \l{Model/View Programming}{model/view-
948 framework} for its popup list and to store its items. By default-
949 a QStandardItemModel stores the items and a QListView subclass-
950 displays the popuplist. You can access the model and view directly-
951 (with model() and view()), but QComboBox also provides functions-
952 to set and get item data (e.g., setItemData() and itemText()). You-
953 can also set a new model and view (with setModel() and setView()).-
954 For the text and icon in the combobox label, the data in the model-
955 that has the Qt::DisplayRole and Qt::DecorationRole is used. Note-
956 that you cannot alter the \l{QAbstractItemView::}{SelectionMode}-
957 of the view(), e.g., by using-
958 \l{QAbstractItemView::}{setSelectionMode()}.-
959-
960 \image qstyle-comboboxes.png Comboboxes in the different built-in styles.-
961-
962 \sa QLineEdit, QSpinBox, QRadioButton, QButtonGroup,-
963 {fowler}{GUI Design Handbook: Combo Box, Drop-Down List Box}-
964*/-
965-
966void QComboBoxPrivate::init()-
967{-
968 Q_Q(QComboBox);-
969#ifdef Q_OS_OSX-
970 // On OS X, only line edits and list views always get tab focus. It's only-
971 // when we enable full keyboard access that other controls can get tab focus.-
972 // When it's not editable, a combobox looks like a button, and it behaves as-
973 // such in this respect.-
974 if (!q->isEditable())-
975 q->setFocusPolicy(Qt::TabFocus);-
976 else-
977#endif-
978 q->setFocusPolicy(Qt::WheelFocus);-
979-
980 q->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed,-
981 QSizePolicy::ComboBox));-
982 setLayoutItemMargins(QStyle::SE_ComboBoxLayoutItem);-
983 q->setModel(new QStandardItemModel(0, 1, q));-
984 if (!q->isEditable())
!q->isEditable()Description
TRUEnever evaluated
FALSEnever evaluated
0
985 q->setAttribute(Qt::WA_InputMethodEnabled, false);
never executed: q->setAttribute(Qt::WA_InputMethodEnabled, false);
0
986 else-
987 q->setAttribute(Qt::WA_InputMethodEnabled);
never executed: q->setAttribute(Qt::WA_InputMethodEnabled);
0
988}-
989-
990QComboBoxPrivateContainer* QComboBoxPrivate::viewContainer()-
991{-
992 if (container)
containerDescription
TRUEnever evaluated
FALSEnever evaluated
0
993 return container;
never executed: return container;
0
994-
995 Q_Q(QComboBox);-
996 container = new QComboBoxPrivateContainer(new QComboBoxListView(q), q);-
997 container->itemView()->setModel(model);-
998 container->itemView()->setTextElideMode(Qt::ElideMiddle);-
999 updateDelegate(true);-
1000 updateLayoutDirection();-
1001 updateViewContainerPaletteAndOpacity();-
1002 QObject::connect(container, SIGNAL(itemSelected(QModelIndex)),-
1003 q, SLOT(_q_itemSelected(QModelIndex)));-
1004 QObject::connect(container->itemView()->selectionModel(),-
1005 SIGNAL(currentChanged(QModelIndex,QModelIndex)),-
1006 q, SLOT(_q_emitHighlighted(QModelIndex)));-
1007 QObject::connect(container, SIGNAL(resetButton()), q, SLOT(_q_resetButton()));-
1008 return container;
never executed: return container;
0
1009}-
1010-
1011-
1012void QComboBoxPrivate::_q_resetButton()-
1013{-
1014 updateArrow(QStyle::State_None);-
1015}
never executed: end of block
0
1016-
1017void QComboBoxPrivate::_q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)-
1018{-
1019 Q_Q(QComboBox);-
1020 if (inserting || topLeft.parent() != root)
insertingDescription
TRUEnever evaluated
FALSEnever evaluated
topLeft.parent() != rootDescription
TRUEnever evaluated
FALSEnever evaluated
0
1021 return;
never executed: return;
0
1022-
1023 if (sizeAdjustPolicy == QComboBox::AdjustToContents) {
sizeAdjustPoli...justToContentsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1024 sizeHint = QSize();-
1025 adjustComboBoxSize();-
1026 q->updateGeometry();-
1027 }
never executed: end of block
0
1028-
1029 if (currentIndex.row() >= topLeft.row() && currentIndex.row() <= bottomRight.row()) {
currentIndex.r... topLeft.row()Description
TRUEnever evaluated
FALSEnever evaluated
currentIndex.r...tomRight.row()Description
TRUEnever evaluated
FALSEnever evaluated
0
1030 const QString text = q->itemText(currentIndex.row());-
1031 if (lineEdit) {
lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
0
1032 lineEdit->setText(text);-
1033 updateLineEditGeometry();-
1034 } else {
never executed: end of block
0
1035 emit q->currentTextChanged(text);-
1036 }
never executed: end of block
0
1037 q->update();-
1038#ifndef QT_NO_ACCESSIBILITY-
1039 QAccessibleValueChangeEvent event(q, text);-
1040 QAccessible::updateAccessibility(&event);-
1041#endif-
1042 }
never executed: end of block
0
1043}
never executed: end of block
0
1044-
1045void QComboBoxPrivate::_q_rowsInserted(const QModelIndex &parent, int start, int end)-
1046{-
1047 Q_Q(QComboBox);-
1048 if (inserting || parent != root)
insertingDescription
TRUEnever evaluated
FALSEnever evaluated
parent != rootDescription
TRUEnever evaluated
FALSEnever evaluated
0
1049 return;
never executed: return;
0
1050-
1051 if (sizeAdjustPolicy == QComboBox::AdjustToContents) {
sizeAdjustPoli...justToContentsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1052 sizeHint = QSize();-
1053 adjustComboBoxSize();-
1054 q->updateGeometry();-
1055 }
never executed: end of block
0
1056-
1057 // set current index if combo was previously empty-
1058 if (start == 0 && (end - start + 1) == q->count() && !currentIndex.isValid()) {
start == 0Description
TRUEnever evaluated
FALSEnever evaluated
(end - start +... == q->count()Description
TRUEnever evaluated
FALSEnever evaluated
!currentIndex.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1059 q->setCurrentIndex(0);-
1060 // need to emit changed if model updated index "silently"-
1061 } else if (currentIndex.row() != indexBeforeChange) {
never executed: end of block
currentIndex.r...exBeforeChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1062 q->update();-
1063 _q_emitCurrentIndexChanged(currentIndex);-
1064 }
never executed: end of block
0
1065}
never executed: end of block
0
1066-
1067void QComboBoxPrivate::_q_updateIndexBeforeChange()-
1068{-
1069 indexBeforeChange = currentIndex.row();-
1070}
never executed: end of block
0
1071-
1072void QComboBoxPrivate::_q_rowsRemoved(const QModelIndex &parent, int /*start*/, int /*end*/)-
1073{-
1074 Q_Q(QComboBox);-
1075 if (parent != root)
parent != rootDescription
TRUEnever evaluated
FALSEnever evaluated
0
1076 return;
never executed: return;
0
1077-
1078 if (sizeAdjustPolicy == QComboBox::AdjustToContents) {
sizeAdjustPoli...justToContentsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1079 sizeHint = QSize();-
1080 adjustComboBoxSize();-
1081 q->updateGeometry();-
1082 }
never executed: end of block
0
1083-
1084 // model has changed the currentIndex-
1085 if (currentIndex.row() != indexBeforeChange) {
currentIndex.r...exBeforeChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1086 if (!currentIndex.isValid() && q->count()) {
!currentIndex.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
q->count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1087 q->setCurrentIndex(qMin(q->count() - 1, qMax(indexBeforeChange, 0)));-
1088 return;
never executed: return;
0
1089 }-
1090 if (lineEdit) {
lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
0
1091 lineEdit->setText(q->itemText(currentIndex.row()));-
1092 updateLineEditGeometry();-
1093 }
never executed: end of block
0
1094 q->update();-
1095 _q_emitCurrentIndexChanged(currentIndex);-
1096 }
never executed: end of block
0
1097}
never executed: end of block
0
1098-
1099-
1100void QComboBoxPrivate::updateViewContainerPaletteAndOpacity()-
1101{-
1102 if (!container)
!containerDescription
TRUEnever evaluated
FALSEnever evaluated
0
1103 return;
never executed: return;
0
1104 Q_Q(QComboBox);-
1105 QStyleOptionComboBox opt;-
1106 q->initStyleOption(&opt);-
1107#ifndef QT_NO_MENU-
1108 if (q->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, q)) {
q->style()->st...opup, &opt, q)Description
TRUEnever evaluated
FALSEnever evaluated
0
1109 QMenu menu;-
1110 menu.ensurePolished();-
1111 container->setPalette(menu.palette());-
1112 container->setWindowOpacity(menu.windowOpacity());-
1113 } else
never executed: end of block
0
1114#endif-
1115 {-
1116 container->setPalette(q->palette());-
1117 container->setWindowOpacity(1.0);-
1118 }
never executed: end of block
0
1119 if (lineEdit)
lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
0
1120 lineEdit->setPalette(q->palette());
never executed: lineEdit->setPalette(q->palette());
0
1121}
never executed: end of block
0
1122-
1123void QComboBoxPrivate::updateFocusPolicy()-
1124{-
1125#ifdef Q_OS_OSX-
1126 Q_Q(QComboBox);-
1127-
1128 // See comment in QComboBoxPrivate::init()-
1129 if (q->isEditable())-
1130 q->setFocusPolicy(Qt::WheelFocus);-
1131 else-
1132 q->setFocusPolicy(Qt::TabFocus);-
1133#endif-
1134}-
1135-
1136/*!-
1137 Initialize \a option with the values from this QComboBox. This method-
1138 is useful for subclasses when they need a QStyleOptionComboBox, but don't want-
1139 to fill in all the information themselves.-
1140-
1141 \sa QStyleOption::initFrom()-
1142*/-
1143void QComboBox::initStyleOption(QStyleOptionComboBox *option) const-
1144{-
1145 if (!option)
!optionDescription
TRUEnever evaluated
FALSEnever evaluated
0
1146 return;
never executed: return;
0
1147-
1148 Q_D(const QComboBox);-
1149 option->initFrom(this);-
1150 option->editable = isEditable();-
1151 option->frame = d->frame;-
1152 if (hasFocus() && !option->editable)
hasFocus()Description
TRUEnever evaluated
FALSEnever evaluated
!option->editableDescription
TRUEnever evaluated
FALSEnever evaluated
0
1153 option->state |= QStyle::State_Selected;
never executed: option->state |= QStyle::State_Selected;
0
1154 option->subControls = QStyle::SC_All;-
1155 if (d->arrowState == QStyle::State_Sunken) {
d->arrowState ...::State_SunkenDescription
TRUEnever evaluated
FALSEnever evaluated
0
1156 option->activeSubControls = QStyle::SC_ComboBoxArrow;-
1157 option->state |= d->arrowState;-
1158 } else {
never executed: end of block
0
1159 option->activeSubControls = d->hoverControl;-
1160 }
never executed: end of block
0
1161 if (d->currentIndex.isValid()) {
d->currentIndex.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1162 option->currentText = currentText();-
1163 option->currentIcon = d->itemIcon(d->currentIndex);-
1164 }
never executed: end of block
0
1165 option->iconSize = iconSize();-
1166 if (d->container && d->container->isVisible())
d->containerDescription
TRUEnever evaluated
FALSEnever evaluated
d->container->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
1167 option->state |= QStyle::State_On;
never executed: option->state |= QStyle::State_On;
0
1168}
never executed: end of block
0
1169-
1170void QComboBoxPrivate::updateLineEditGeometry()-
1171{-
1172 if (!lineEdit)
!lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
0
1173 return;
never executed: return;
0
1174-
1175 Q_Q(QComboBox);-
1176 QStyleOptionComboBox opt;-
1177 q->initStyleOption(&opt);-
1178 QRect editRect = q->style()->subControlRect(QStyle::CC_ComboBox, &opt,-
1179 QStyle::SC_ComboBoxEditField, q);-
1180 if (!q->itemIcon(q->currentIndex()).isNull()) {
!q->itemIcon(q...ex()).isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1181 QRect comboRect(editRect);-
1182 editRect.setWidth(editRect.width() - q->iconSize().width() - 4);-
1183 editRect = QStyle::alignedRect(q->layoutDirection(), Qt::AlignRight,-
1184 editRect.size(), comboRect);-
1185 }
never executed: end of block
0
1186 lineEdit->setGeometry(editRect);-
1187}
never executed: end of block
0
1188-
1189Qt::MatchFlags QComboBoxPrivate::matchFlags() const-
1190{-
1191 // Base how duplicates are determined on the autocompletion case sensitivity-
1192 Qt::MatchFlags flags = Qt::MatchFixedString;-
1193#ifndef QT_NO_COMPLETER-
1194 if (!lineEdit->completer() || lineEdit->completer()->caseSensitivity() == Qt::CaseSensitive)
!lineEdit->completer()Description
TRUEnever evaluated
FALSEnever evaluated
lineEdit->comp...:CaseSensitiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
1195#endif-
1196 flags |= Qt::MatchCaseSensitive;
never executed: flags |= Qt::MatchCaseSensitive;
0
1197 return flags;
never executed: return flags;
0
1198}-
1199-
1200-
1201void QComboBoxPrivate::_q_editingFinished()-
1202{-
1203 Q_Q(QComboBox);-
1204 if (lineEdit && !lineEdit->text().isEmpty() && itemText(currentIndex) != lineEdit->text()) {
lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
!lineEdit->text().isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
itemText(curre...neEdit->text()Description
TRUEnever evaluated
FALSEnever evaluated
0
1205 const int index = q_func()->findText(lineEdit->text(), matchFlags());-
1206 if (index != -1) {
index != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1207 q->setCurrentIndex(index);-
1208 emitActivated(currentIndex);-
1209 }
never executed: end of block
0
1210 }
never executed: end of block
0
1211-
1212}
never executed: end of block
0
1213-
1214void QComboBoxPrivate::_q_returnPressed()-
1215{-
1216 Q_Q(QComboBox);-
1217-
1218 // The insertion code below does not apply when the policy is QComboBox::NoInsert.-
1219 // In case a completer is installed, item activation via the completer is handled-
1220 // in _q_completerActivated(). Otherwise _q_editingFinished() updates the current-
1221 // index as appropriate.-
1222 if (insertPolicy == QComboBox::NoInsert)
insertPolicy =...oBox::NoInsertDescription
TRUEnever evaluated
FALSEnever evaluated
0
1223 return;
never executed: return;
0
1224-
1225 if (lineEdit && !lineEdit->text().isEmpty()) {
lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
!lineEdit->text().isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1226 if (q->count() >= maxCount && !(this->insertPolicy == QComboBox::InsertAtCurrent))
q->count() >= maxCountDescription
TRUEnever evaluated
FALSEnever evaluated
!(this->insert...sertAtCurrent)Description
TRUEnever evaluated
FALSEnever evaluated
0
1227 return;
never executed: return;
0
1228 lineEdit->deselect();-
1229 lineEdit->end(false);-
1230 QString text = lineEdit->text();-
1231 // check for duplicates (if not enabled) and quit-
1232 int index = -1;-
1233 if (!duplicatesEnabled) {
!duplicatesEnabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
1234 index = q->findText(text, matchFlags());-
1235 if (index != -1) {
index != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1236 q->setCurrentIndex(index);-
1237 emitActivated(currentIndex);-
1238 return;
never executed: return;
0
1239 }-
1240 }
never executed: end of block
0
1241 switch (insertPolicy) {-
1242 case QComboBox::InsertAtTop:
never executed: case QComboBox::InsertAtTop:
0
1243 index = 0;-
1244 break;
never executed: break;
0
1245 case QComboBox::InsertAtBottom:
never executed: case QComboBox::InsertAtBottom:
0
1246 index = q->count();-
1247 break;
never executed: break;
0
1248 case QComboBox::InsertAtCurrent:
never executed: case QComboBox::InsertAtCurrent:
0
1249 case QComboBox::InsertAfterCurrent:
never executed: case QComboBox::InsertAfterCurrent:
0
1250 case QComboBox::InsertBeforeCurrent:
never executed: case QComboBox::InsertBeforeCurrent:
0
1251 if (!q->count() || !currentIndex.isValid())
!q->count()Description
TRUEnever evaluated
FALSEnever evaluated
!currentIndex.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1252 index = 0;
never executed: index = 0;
0
1253 else if (insertPolicy == QComboBox::InsertAtCurrent)
insertPolicy =...nsertAtCurrentDescription
TRUEnever evaluated
FALSEnever evaluated
0
1254 q->setItemText(q->currentIndex(), text);
never executed: q->setItemText(q->currentIndex(), text);
0
1255 else if (insertPolicy == QComboBox::InsertAfterCurrent)
insertPolicy =...rtAfterCurrentDescription
TRUEnever evaluated
FALSEnever evaluated
0
1256 index = q->currentIndex() + 1;
never executed: index = q->currentIndex() + 1;
0
1257 else if (insertPolicy == QComboBox::InsertBeforeCurrent)
insertPolicy =...tBeforeCurrentDescription
TRUEnever evaluated
FALSEnever evaluated
0
1258 index = q->currentIndex();
never executed: index = q->currentIndex();
0
1259 break;
never executed: break;
0
1260 case QComboBox::InsertAlphabetically:
never executed: case QComboBox::InsertAlphabetically:
0
1261 index = 0;-
1262 for (int i=0; i< q->count(); i++, index++ ) {
i< q->count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1263 if (text.toLower() < q->itemText(i).toLower())
text.toLower()...t(i).toLower()Description
TRUEnever evaluated
FALSEnever evaluated
0
1264 break;
never executed: break;
0
1265 }
never executed: end of block
0
1266 break;
never executed: break;
0
1267 default:
never executed: default:
0
1268 break;
never executed: break;
0
1269 }-
1270 if (index >= 0) {
index >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1271 q->insertItem(index, text);-
1272 q->setCurrentIndex(index);-
1273 emitActivated(currentIndex);-
1274 }
never executed: end of block
0
1275 }
never executed: end of block
0
1276}
never executed: end of block
0
1277-
1278void QComboBoxPrivate::_q_itemSelected(const QModelIndex &item)-
1279{-
1280 Q_Q(QComboBox);-
1281 if (item != currentIndex) {
item != currentIndexDescription
TRUEnever evaluated
FALSEnever evaluated
0
1282 setCurrentIndex(item);-
1283 } else if (lineEdit) {
never executed: end of block
lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
0
1284 lineEdit->selectAll();-
1285 lineEdit->setText(q->itemText(currentIndex.row()));-
1286 }
never executed: end of block
0
1287 emitActivated(currentIndex);-
1288}
never executed: end of block
0
1289-
1290void QComboBoxPrivate::emitActivated(const QModelIndex &index)-
1291{-
1292 Q_Q(QComboBox);-
1293 if (!index.isValid())
!index.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1294 return;
never executed: return;
0
1295 QString text(itemText(index));-
1296 emit q->activated(index.row());-
1297 emit q->activated(text);-
1298}
never executed: end of block
0
1299-
1300void QComboBoxPrivate::_q_emitHighlighted(const QModelIndex &index)-
1301{-
1302 Q_Q(QComboBox);-
1303 if (!index.isValid())
!index.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1304 return;
never executed: return;
0
1305 QString text(itemText(index));-
1306 emit q->highlighted(index.row());-
1307 emit q->highlighted(text);-
1308}
never executed: end of block
0
1309-
1310void QComboBoxPrivate::_q_emitCurrentIndexChanged(const QModelIndex &index)-
1311{-
1312 Q_Q(QComboBox);-
1313 const QString text = itemText(index);-
1314 emit q->currentIndexChanged(index.row());-
1315 emit q->currentIndexChanged(text);-
1316 // signal lineEdit.textChanged already connected to signal currentTextChanged, so don't emit double here-
1317 if (!lineEdit)
!lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
0
1318 emit q->currentTextChanged(text);
never executed: q->currentTextChanged(text);
0
1319#ifndef QT_NO_ACCESSIBILITY-
1320 QAccessibleValueChangeEvent event(q, text);-
1321 QAccessible::updateAccessibility(&event);-
1322#endif-
1323}
never executed: end of block
0
1324-
1325QString QComboBoxPrivate::itemText(const QModelIndex &index) const-
1326{-
1327 return index.isValid() ? model->data(index, itemRole()).toString() : QString();
never executed: return index.isValid() ? model->data(index, itemRole()).toString() : QString();
0
1328}-
1329-
1330int QComboBoxPrivate::itemRole() const-
1331{-
1332 return q_func()->isEditable() ? Qt::EditRole : Qt::DisplayRole;
never executed: return q_func()->isEditable() ? Qt::EditRole : Qt::DisplayRole;
0
1333}-
1334-
1335/*!-
1336 Destroys the combobox.-
1337*/-
1338QComboBox::~QComboBox()-
1339{-
1340 // ### check delegateparent and delete delegate if us?-
1341 Q_D(QComboBox);-
1342-
1343 QT_TRY {-
1344 disconnect(d->model, SIGNAL(destroyed()),-
1345 this, SLOT(_q_modelDestroyed()));-
1346 } QT_CATCH(...) {
never executed: end of block
dead code: { ; }
-
1347 ; // objects can't throw in destructor
dead code: { ; }
-
1348 }
dead code: { ; }
-
1349}-
1350-
1351/*!-
1352 \property QComboBox::maxVisibleItems-
1353 \brief the maximum allowed size on screen of the combo box, measured in items-
1354-
1355 By default, this property has a value of 10.-
1356-
1357 \note This property is ignored for non-editable comboboxes in styles that returns-
1358 true for QStyle::SH_ComboBox_Popup such as the Mac style or the Gtk+ Style.-
1359*/-
1360int QComboBox::maxVisibleItems() const-
1361{-
1362 Q_D(const QComboBox);-
1363 return d->maxVisibleItems;
never executed: return d->maxVisibleItems;
0
1364}-
1365-
1366void QComboBox::setMaxVisibleItems(int maxItems)-
1367{-
1368 Q_D(QComboBox);-
1369 if (Q_UNLIKELY(maxItems < 0)) {
__builtin_expe...s < 0), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
1370 qWarning("QComboBox::setMaxVisibleItems: "-
1371 "Invalid max visible items (%d) must be >= 0", maxItems);-
1372 return;
never executed: return;
0
1373 }-
1374 d->maxVisibleItems = maxItems;-
1375}
never executed: end of block
0
1376-
1377/*!-
1378 \property QComboBox::count-
1379 \brief the number of items in the combobox-
1380-
1381 By default, for an empty combo box, this property has a value of 0.-
1382*/-
1383int QComboBox::count() const-
1384{-
1385 Q_D(const QComboBox);-
1386 return d->model->rowCount(d->root);
never executed: return d->model->rowCount(d->root);
0
1387}-
1388-
1389/*!-
1390 \property QComboBox::maxCount-
1391 \brief the maximum number of items allowed in the combobox-
1392-
1393 \note If you set the maximum number to be less then the current-
1394 amount of items in the combobox, the extra items will be-
1395 truncated. This also applies if you have set an external model on-
1396 the combobox.-
1397-
1398 By default, this property's value is derived from the highest-
1399 signed integer available (typically 2147483647).-
1400*/-
1401void QComboBox::setMaxCount(int max)-
1402{-
1403 Q_D(QComboBox);-
1404 if (Q_UNLIKELY(max < 0)) {
__builtin_expe...x < 0), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
1405 qWarning("QComboBox::setMaxCount: Invalid count (%d) must be >= 0", max);-
1406 return;
never executed: return;
0
1407 }-
1408-
1409 const int rowCount = count();-
1410 if (rowCount > max)
rowCount > maxDescription
TRUEnever evaluated
FALSEnever evaluated
0
1411 d->model->removeRows(max, rowCount - max, d->root);
never executed: d->model->removeRows(max, rowCount - max, d->root);
0
1412-
1413 d->maxCount = max;-
1414}
never executed: end of block
0
1415-
1416int QComboBox::maxCount() const-
1417{-
1418 Q_D(const QComboBox);-
1419 return d->maxCount;
never executed: return d->maxCount;
0
1420}-
1421-
1422#ifndef QT_NO_COMPLETER-
1423-
1424/*!-
1425 \property QComboBox::autoCompletion-
1426 \brief whether the combobox provides auto-completion for editable items-
1427 \since 4.1-
1428 \obsolete-
1429-
1430 Use setCompleter() instead.-
1431-
1432 By default, this property is \c true.-
1433-
1434 \sa editable-
1435*/-
1436-
1437/*!-
1438 \obsolete-
1439-
1440 Use setCompleter() instead.-
1441*/-
1442bool QComboBox::autoCompletion() const-
1443{-
1444 Q_D(const QComboBox);-
1445 return d->autoCompletion;
never executed: return d->autoCompletion;
0
1446}-
1447-
1448/*!-
1449 \obsolete-
1450-
1451 Use setCompleter() instead.-
1452*/-
1453void QComboBox::setAutoCompletion(bool enable)-
1454{-
1455 Q_D(QComboBox);-
1456-
1457#ifdef QT_KEYPAD_NAVIGATION-
1458 if (Q_UNLIKELY(QApplication::keypadNavigationEnabled() && !enable && isEditable()))-
1459 qWarning("QComboBox::setAutoCompletion: auto completion is mandatory when combo box editable");-
1460#endif-
1461-
1462 d->autoCompletion = enable;-
1463 if (!d->lineEdit)
!d->lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
0
1464 return;
never executed: return;
0
1465 if (enable) {
enableDescription
TRUEnever evaluated
FALSEnever evaluated
0
1466 if (d->lineEdit->completer())
d->lineEdit->completer()Description
TRUEnever evaluated
FALSEnever evaluated
0
1467 return;
never executed: return;
0
1468 d->completer = new QCompleter(d->model, d->lineEdit);-
1469 connect(d->completer, SIGNAL(activated(QModelIndex)), this, SLOT(_q_completerActivated(QModelIndex)));-
1470 d->completer->setCaseSensitivity(d->autoCompletionCaseSensitivity);-
1471 d->completer->setCompletionMode(QCompleter::InlineCompletion);-
1472 d->completer->setCompletionColumn(d->modelColumn);-
1473 d->lineEdit->setCompleter(d->completer);-
1474 d->completer->setWidget(this);-
1475 } else {
never executed: end of block
0
1476 d->lineEdit->setCompleter(0);-
1477 }
never executed: end of block
0
1478}-
1479-
1480/*!-
1481 \property QComboBox::autoCompletionCaseSensitivity-
1482 \brief whether string comparisons are case-sensitive or case-insensitive for auto-completion-
1483 \obsolete-
1484-
1485 By default, this property is Qt::CaseInsensitive.-
1486-
1487 Use setCompleter() instead. Case sensitivity of the auto completion can be-
1488 changed using QCompleter::setCaseSensitivity().-
1489-
1490 \sa autoCompletion-
1491*/-
1492-
1493/*!-
1494 \obsolete-
1495-
1496 Use setCompleter() and QCompleter::setCaseSensitivity() instead.-
1497*/-
1498Qt::CaseSensitivity QComboBox::autoCompletionCaseSensitivity() const-
1499{-
1500 Q_D(const QComboBox);-
1501 return d->autoCompletionCaseSensitivity;
never executed: return d->autoCompletionCaseSensitivity;
0
1502}-
1503-
1504/*!-
1505 \obsolete-
1506-
1507 Use setCompleter() and QCompleter::setCaseSensitivity() instead.-
1508*/-
1509void QComboBox::setAutoCompletionCaseSensitivity(Qt::CaseSensitivity sensitivity)-
1510{-
1511 Q_D(QComboBox);-
1512 d->autoCompletionCaseSensitivity = sensitivity;-
1513 if (d->lineEdit && d->lineEdit->completer())
d->lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
d->lineEdit->completer()Description
TRUEnever evaluated
FALSEnever evaluated
0
1514 d->lineEdit->completer()->setCaseSensitivity(sensitivity);
never executed: d->lineEdit->completer()->setCaseSensitivity(sensitivity);
0
1515}
never executed: end of block
0
1516-
1517#endif // QT_NO_COMPLETER-
1518-
1519/*!-
1520 \property QComboBox::duplicatesEnabled-
1521 \brief whether the user can enter duplicate items into the combobox-
1522-
1523 Note that it is always possible to programmatically insert duplicate items into the-
1524 combobox.-
1525-
1526 By default, this property is \c false (duplicates are not allowed).-
1527*/-
1528bool QComboBox::duplicatesEnabled() const-
1529{-
1530 Q_D(const QComboBox);-
1531 return d->duplicatesEnabled;
never executed: return d->duplicatesEnabled;
0
1532}-
1533-
1534void QComboBox::setDuplicatesEnabled(bool enable)-
1535{-
1536 Q_D(QComboBox);-
1537 d->duplicatesEnabled = enable;-
1538}
never executed: end of block
0
1539-
1540/*! \fn int QComboBox::findText(const QString &text, Qt::MatchFlags flags = Qt::MatchExactly|Qt::MatchCaseSensitive) const-
1541-
1542 Returns the index of the item containing the given \a text; otherwise-
1543 returns -1.-
1544-
1545 The \a flags specify how the items in the combobox are searched.-
1546*/-
1547-
1548/*!-
1549 Returns the index of the item containing the given \a data for the-
1550 given \a role; otherwise returns -1.-
1551-
1552 The \a flags specify how the items in the combobox are searched.-
1553*/-
1554int QComboBox::findData(const QVariant &data, int role, Qt::MatchFlags flags) const-
1555{-
1556 Q_D(const QComboBox);-
1557 QModelIndex start = d->model->index(0, d->modelColumn, d->root);-
1558 const QModelIndexList result = d->model->match(start, role, data, 1, flags);-
1559 if (result.isEmpty())
result.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1560 return -1;
never executed: return -1;
0
1561 return result.first().row();
never executed: return result.first().row();
0
1562}-
1563-
1564/*!-
1565 \property QComboBox::insertPolicy-
1566 \brief the policy used to determine where user-inserted items should-
1567 appear in the combobox-
1568-
1569 The default value is \l InsertAtBottom, indicating that new items will appear-
1570 at the bottom of the list of items.-
1571-
1572 \sa InsertPolicy-
1573*/-
1574-
1575QComboBox::InsertPolicy QComboBox::insertPolicy() const-
1576{-
1577 Q_D(const QComboBox);-
1578 return d->insertPolicy;
never executed: return d->insertPolicy;
0
1579}-
1580-
1581void QComboBox::setInsertPolicy(InsertPolicy policy)-
1582{-
1583 Q_D(QComboBox);-
1584 d->insertPolicy = policy;-
1585}
never executed: end of block
0
1586-
1587/*!-
1588 \property QComboBox::sizeAdjustPolicy-
1589 \brief the policy describing how the size of the combobox changes-
1590 when the content changes-
1591-
1592 The default value is \l AdjustToContentsOnFirstShow.-
1593-
1594 \sa SizeAdjustPolicy-
1595*/-
1596-
1597QComboBox::SizeAdjustPolicy QComboBox::sizeAdjustPolicy() const-
1598{-
1599 Q_D(const QComboBox);-
1600 return d->sizeAdjustPolicy;
never executed: return d->sizeAdjustPolicy;
0
1601}-
1602-
1603void QComboBox::setSizeAdjustPolicy(QComboBox::SizeAdjustPolicy policy)-
1604{-
1605 Q_D(QComboBox);-
1606 if (policy == d->sizeAdjustPolicy)
policy == d->sizeAdjustPolicyDescription
TRUEnever evaluated
FALSEnever evaluated
0
1607 return;
never executed: return;
0
1608-
1609 d->sizeAdjustPolicy = policy;-
1610 d->sizeHint = QSize();-
1611 d->adjustComboBoxSize();-
1612 updateGeometry();-
1613}
never executed: end of block
0
1614-
1615/*!-
1616 \property QComboBox::minimumContentsLength-
1617 \brief the minimum number of characters that should fit into the combobox.-
1618-
1619 The default value is 0.-
1620-
1621 If this property is set to a positive value, the-
1622 minimumSizeHint() and sizeHint() take it into account.-
1623-
1624 \sa sizeAdjustPolicy-
1625*/-
1626int QComboBox::minimumContentsLength() const-
1627{-
1628 Q_D(const QComboBox);-
1629 return d->minimumContentsLength;
never executed: return d->minimumContentsLength;
0
1630}-
1631-
1632void QComboBox::setMinimumContentsLength(int characters)-
1633{-
1634 Q_D(QComboBox);-
1635 if (characters == d->minimumContentsLength || characters < 0)
characters == ...ContentsLengthDescription
TRUEnever evaluated
FALSEnever evaluated
characters < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1636 return;
never executed: return;
0
1637-
1638 d->minimumContentsLength = characters;-
1639-
1640 if (d->sizeAdjustPolicy == AdjustToContents
d->sizeAdjustP...justToContentsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1641 || d->sizeAdjustPolicy == AdjustToMinimumContentsLength
d->sizeAdjustP...ContentsLengthDescription
TRUEnever evaluated
FALSEnever evaluated
0
1642 || d->sizeAdjustPolicy == AdjustToMinimumContentsLengthWithIcon) {
d->sizeAdjustP...LengthWithIconDescription
TRUEnever evaluated
FALSEnever evaluated
0
1643 d->sizeHint = QSize();-
1644 d->adjustComboBoxSize();-
1645 updateGeometry();-
1646 }
never executed: end of block
0
1647}
never executed: end of block
0
1648-
1649/*!-
1650 \property QComboBox::iconSize-
1651 \brief the size of the icons shown in the combobox.-
1652-
1653 Unless explicitly set this returns the default value of the-
1654 current style. This size is the maximum size that icons can have;-
1655 icons of smaller size are not scaled up.-
1656*/-
1657-
1658QSize QComboBox::iconSize() const-
1659{-
1660 Q_D(const QComboBox);-
1661 if (d->iconSize.isValid())
d->iconSize.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1662 return d->iconSize;
never executed: return d->iconSize;
0
1663-
1664 int iconWidth = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this);-
1665 return QSize(iconWidth, iconWidth);
never executed: return QSize(iconWidth, iconWidth);
0
1666}-
1667-
1668void QComboBox::setIconSize(const QSize &size)-
1669{-
1670 Q_D(QComboBox);-
1671 if (size == d->iconSize)
size == d->iconSizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1672 return;
never executed: return;
0
1673-
1674 view()->setIconSize(size);-
1675 d->iconSize = size;-
1676 d->sizeHint = QSize();-
1677 updateGeometry();-
1678}
never executed: end of block
0
1679-
1680/*!-
1681 \property QComboBox::editable-
1682 \brief whether the combo box can be edited by the user-
1683-
1684 By default, this property is \c false. The effect of editing depends-
1685 on the insert policy.-
1686-
1687 \note When disabling the \a editable state, the validator and-
1688 completer are removed.-
1689-
1690 \sa InsertPolicy-
1691*/-
1692bool QComboBox::isEditable() const-
1693{-
1694 Q_D(const QComboBox);-
1695 return d->lineEdit != 0;
never executed: return d->lineEdit != 0;
0
1696}-
1697-
1698/*! \internal-
1699 update the default delegate-
1700 depending on the style's SH_ComboBox_Popup hint, we use a different default delegate.-
1701-
1702 but we do not change the delegate is the combobox use a custom delegate,-
1703 unless \a force is set to true.-
1704 */-
1705void QComboBoxPrivate::updateDelegate(bool force)-
1706{-
1707 Q_Q(QComboBox);-
1708 QStyleOptionComboBox opt;-
1709 q->initStyleOption(&opt);-
1710 if (q->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, q)) {
q->style()->st...opup, &opt, q)Description
TRUEnever evaluated
FALSEnever evaluated
0
1711 if (force || qobject_cast<QComboBoxDelegate *>(q->itemDelegate()))
forceDescription
TRUEnever evaluated
FALSEnever evaluated
qobject_cast<Q...temDelegate())Description
TRUEnever evaluated
FALSEnever evaluated
0
1712 q->setItemDelegate(new QComboMenuDelegate(q->view(), q));
never executed: q->setItemDelegate(new QComboMenuDelegate(q->view(), q));
0
1713 } else {
never executed: end of block
0
1714 if (force || qobject_cast<QComboMenuDelegate *>(q->itemDelegate()))
forceDescription
TRUEnever evaluated
FALSEnever evaluated
qobject_cast<Q...temDelegate())Description
TRUEnever evaluated
FALSEnever evaluated
0
1715 q->setItemDelegate(new QComboBoxDelegate(q->view(), q));
never executed: q->setItemDelegate(new QComboBoxDelegate(q->view(), q));
0
1716 }
never executed: end of block
0
1717}-
1718-
1719QIcon QComboBoxPrivate::itemIcon(const QModelIndex &index) const-
1720{-
1721 QVariant decoration = model->data(index, Qt::DecorationRole);-
1722 if (decoration.type() == QVariant::Pixmap)
decoration.typ...ariant::PixmapDescription
TRUEnever evaluated
FALSEnever evaluated
0
1723 return QIcon(qvariant_cast<QPixmap>(decoration));
never executed: return QIcon(qvariant_cast<QPixmap>(decoration));
0
1724 else-
1725 return qvariant_cast<QIcon>(decoration);
never executed: return qvariant_cast<QIcon>(decoration);
0
1726}-
1727-
1728void QComboBox::setEditable(bool editable)-
1729{-
1730 Q_D(QComboBox);-
1731 if (isEditable() == editable)
isEditable() == editableDescription
TRUEnever evaluated
FALSEnever evaluated
0
1732 return;
never executed: return;
0
1733-
1734 QStyleOptionComboBox opt;-
1735 initStyleOption(&opt);-
1736 if (editable) {
editableDescription
TRUEnever evaluated
FALSEnever evaluated
0
1737 if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) {
style()->style...p, &opt, this)Description
TRUEnever evaluated
FALSEnever evaluated
0
1738 d->viewContainer()->updateScrollers();-
1739 view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);-
1740 }
never executed: end of block
0
1741 QLineEdit *le = new QLineEdit(this);-
1742 setLineEdit(le);-
1743 } else {
never executed: end of block
0
1744 if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) {
style()->style...p, &opt, this)Description
TRUEnever evaluated
FALSEnever evaluated
0
1745 d->viewContainer()->updateScrollers();-
1746 view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);-
1747 }
never executed: end of block
0
1748 setAttribute(Qt::WA_InputMethodEnabled, false);-
1749 d->lineEdit->hide();-
1750 d->lineEdit->deleteLater();-
1751 d->lineEdit = 0;-
1752 }
never executed: end of block
0
1753-
1754 d->updateDelegate();-
1755 d->updateFocusPolicy();-
1756-
1757 d->viewContainer()->updateTopBottomMargin();-
1758 if (!testAttribute(Qt::WA_Resized))
!testAttribute(Qt::WA_Resized)Description
TRUEnever evaluated
FALSEnever evaluated
0
1759 adjustSize();
never executed: adjustSize();
0
1760}
never executed: end of block
0
1761-
1762/*!-
1763 Sets the line \a edit to use instead of the current line edit widget.-
1764-
1765 The combo box takes ownership of the line edit.-
1766*/-
1767void QComboBox::setLineEdit(QLineEdit *edit)-
1768{-
1769 Q_D(QComboBox);-
1770 if (Q_UNLIKELY(!edit)) {
__builtin_expe...!edit), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
1771 qWarning("QComboBox::setLineEdit: cannot set a 0 line edit");-
1772 return;
never executed: return;
0
1773 }-
1774-
1775 if (edit == d->lineEdit)
edit == d->lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
0
1776 return;
never executed: return;
0
1777-
1778 edit->setText(currentText());-
1779 delete d->lineEdit;-
1780-
1781 d->lineEdit = edit;-
1782#ifndef QT_NO_IM-
1783 qt_widget_private(d->lineEdit)->inheritsInputMethodHints = 1;-
1784#endif-
1785 if (d->lineEdit->parent() != this)
d->lineEdit->parent() != thisDescription
TRUEnever evaluated
FALSEnever evaluated
0
1786 d->lineEdit->setParent(this);
never executed: d->lineEdit->setParent(this);
0
1787 connect(d->lineEdit, SIGNAL(returnPressed()), this, SLOT(_q_returnPressed()));-
1788 connect(d->lineEdit, SIGNAL(editingFinished()), this, SLOT(_q_editingFinished()));-
1789 connect(d->lineEdit, SIGNAL(textChanged(QString)), this, SIGNAL(editTextChanged(QString)));-
1790 connect(d->lineEdit, SIGNAL(textChanged(QString)), this, SIGNAL(currentTextChanged(QString)));-
1791 connect(d->lineEdit, SIGNAL(cursorPositionChanged(int,int)), this, SLOT(updateMicroFocus()));-
1792 connect(d->lineEdit, SIGNAL(selectionChanged()), this, SLOT(updateMicroFocus()));-
1793 d->lineEdit->setFrame(false);-
1794 d->lineEdit->setContextMenuPolicy(Qt::NoContextMenu);-
1795 d->updateFocusPolicy();-
1796 d->lineEdit->setFocusProxy(this);-
1797 d->lineEdit->setAttribute(Qt::WA_MacShowFocusRect, false);-
1798#ifndef QT_NO_COMPLETER-
1799 setAutoCompletion(d->autoCompletion);-
1800#endif-
1801-
1802#ifdef QT_KEYPAD_NAVIGATION-
1803#ifndef QT_NO_COMPLETER-
1804 if (QApplication::keypadNavigationEnabled()) {-
1805 // Editable combo boxes will have a completer that is set to UnfilteredPopupCompletion.-
1806 // This means that when the user enters edit mode they are immediately presented with a-
1807 // list of possible completions.-
1808 setAutoCompletion(true);-
1809 if (d->completer) {-
1810 d->completer->setCompletionMode(QCompleter::UnfilteredPopupCompletion);-
1811 connect(d->completer, SIGNAL(activated(QModelIndex)), this, SLOT(_q_completerActivated()));-
1812 }-
1813 }-
1814#endif-
1815#endif-
1816-
1817 setAttribute(Qt::WA_InputMethodEnabled);-
1818 d->updateLayoutDirection();-
1819 d->updateLineEditGeometry();-
1820 if (isVisible())
isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
1821 d->lineEdit->show();
never executed: d->lineEdit->show();
0
1822-
1823 update();-
1824}
never executed: end of block
0
1825-
1826/*!-
1827 Returns the line edit used to edit items in the combobox, or 0 if there-
1828 is no line edit.-
1829-
1830 Only editable combo boxes have a line edit.-
1831*/-
1832QLineEdit *QComboBox::lineEdit() const-
1833{-
1834 Q_D(const QComboBox);-
1835 return d->lineEdit;
never executed: return d->lineEdit;
0
1836}-
1837-
1838#ifndef QT_NO_VALIDATOR-
1839/*!-
1840 \fn void QComboBox::setValidator(const QValidator *validator)-
1841-
1842 Sets the \a validator to use instead of the current validator.-
1843-
1844 \note The validator is removed when the editable property becomes \c false.-
1845*/-
1846-
1847void QComboBox::setValidator(const QValidator *v)-
1848{-
1849 Q_D(QComboBox);-
1850 if (d->lineEdit)
d->lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
0
1851 d->lineEdit->setValidator(v);
never executed: d->lineEdit->setValidator(v);
0
1852}
never executed: end of block
0
1853-
1854/*!-
1855 Returns the validator that is used to constrain text input for the-
1856 combobox.-
1857-
1858 \sa editable-
1859*/-
1860const QValidator *QComboBox::validator() const-
1861{-
1862 Q_D(const QComboBox);-
1863 return d->lineEdit ? d->lineEdit->validator() : 0;
never executed: return d->lineEdit ? d->lineEdit->validator() : 0;
0
1864}-
1865#endif // QT_NO_VALIDATOR-
1866-
1867#ifndef QT_NO_COMPLETER-
1868-
1869/*!-
1870 \fn void QComboBox::setCompleter(QCompleter *completer)-
1871 \since 4.2-
1872-
1873 Sets the \a completer to use instead of the current completer.-
1874 If \a completer is 0, auto completion is disabled.-
1875-
1876 By default, for an editable combo box, a QCompleter that-
1877 performs case insensitive inline completion is automatically created.-
1878-
1879 \note The completer is removed when the \a editable property becomes \c false.-
1880*/-
1881void QComboBox::setCompleter(QCompleter *c)-
1882{-
1883 Q_D(QComboBox);-
1884 if (!d->lineEdit)
!d->lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
0
1885 return;
never executed: return;
0
1886 d->lineEdit->setCompleter(c);-
1887 if (c) {
cDescription
TRUEnever evaluated
FALSEnever evaluated
0
1888 connect(c, SIGNAL(activated(QModelIndex)), this, SLOT(_q_completerActivated(QModelIndex)));-
1889 c->setWidget(this);-
1890 }
never executed: end of block
0
1891}
never executed: end of block
0
1892-
1893/*!-
1894 \since 4.2-
1895-
1896 Returns the completer that is used to auto complete text input for the-
1897 combobox.-
1898-
1899 \sa editable-
1900*/-
1901QCompleter *QComboBox::completer() const-
1902{-
1903 Q_D(const QComboBox);-
1904 return d->lineEdit ? d->lineEdit->completer() : 0;
never executed: return d->lineEdit ? d->lineEdit->completer() : 0;
0
1905}-
1906-
1907#endif // QT_NO_COMPLETER-
1908-
1909/*!-
1910 Returns the item delegate used by the popup list view.-
1911-
1912 \sa setItemDelegate()-
1913*/-
1914QAbstractItemDelegate *QComboBox::itemDelegate() const-
1915{-
1916 return view()->itemDelegate();
never executed: return view()->itemDelegate();
0
1917}-
1918-
1919/*!-
1920 Sets the item \a delegate for the popup list view.-
1921 The combobox takes ownership of the delegate.-
1922-
1923 \warning You should not share the same instance of a delegate between comboboxes,-
1924 widget mappers or views. Doing so can cause incorrect or unintuitive editing behavior-
1925 since each view connected to a given delegate may receive the-
1926 \l{QAbstractItemDelegate::}{closeEditor()} signal, and attempt to access, modify or-
1927 close an editor that has already been closed.-
1928-
1929 \sa itemDelegate()-
1930*/-
1931void QComboBox::setItemDelegate(QAbstractItemDelegate *delegate)-
1932{-
1933 if (Q_UNLIKELY(!delegate)) {
__builtin_expe...egate), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
1934 qWarning("QComboBox::setItemDelegate: cannot set a 0 delegate");-
1935 return;
never executed: return;
0
1936 }-
1937 delete view()->itemDelegate();-
1938 view()->setItemDelegate(delegate);-
1939}
never executed: end of block
0
1940-
1941/*!-
1942 Returns the model used by the combobox.-
1943*/-
1944-
1945QAbstractItemModel *QComboBox::model() const-
1946{-
1947 Q_D(const QComboBox);-
1948 if (d->model == QAbstractItemModelPrivate::staticEmptyModel()) {
d->model == QA...icEmptyModel()Description
TRUEnever evaluated
FALSEnever evaluated
0
1949 QComboBox *that = const_cast<QComboBox*>(this);-
1950 that->setModel(new QStandardItemModel(0, 1, that));-
1951 }
never executed: end of block
0
1952 return d->model;
never executed: return d->model;
0
1953}-
1954-
1955/*!-
1956 Sets the model to be \a model. \a model must not be 0.-
1957 If you want to clear the contents of a model, call clear().-
1958-
1959 \sa clear()-
1960*/-
1961void QComboBox::setModel(QAbstractItemModel *model)-
1962{-
1963 Q_D(QComboBox);-
1964-
1965 if (Q_UNLIKELY(!model)) {
__builtin_expe...model), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
1966 qWarning("QComboBox::setModel: cannot set a 0 model");-
1967 return;
never executed: return;
0
1968 }-
1969-
1970 if (model == d->model)
model == d->modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1971 return;
never executed: return;
0
1972-
1973#ifndef QT_NO_COMPLETER-
1974 if (d->lineEdit && d->lineEdit->completer()
d->lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
d->lineEdit->completer()Description
TRUEnever evaluated
FALSEnever evaluated
0
1975 && d->lineEdit->completer() == d->completer)
d->lineEdit->c...= d->completerDescription
TRUEnever evaluated
FALSEnever evaluated
0
1976 d->lineEdit->completer()->setModel(model);
never executed: d->lineEdit->completer()->setModel(model);
0
1977#endif-
1978 if (d->model) {
d->modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1979 disconnect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),-
1980 this, SLOT(_q_dataChanged(QModelIndex,QModelIndex)));-
1981 disconnect(d->model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),-
1982 this, SLOT(_q_updateIndexBeforeChange()));-
1983 disconnect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)),-
1984 this, SLOT(_q_rowsInserted(QModelIndex,int,int)));-
1985 disconnect(d->model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),-
1986 this, SLOT(_q_updateIndexBeforeChange()));-
1987 disconnect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)),-
1988 this, SLOT(_q_rowsRemoved(QModelIndex,int,int)));-
1989 disconnect(d->model, SIGNAL(destroyed()),-
1990 this, SLOT(_q_modelDestroyed()));-
1991 disconnect(d->model, SIGNAL(modelAboutToBeReset()),-
1992 this, SLOT(_q_updateIndexBeforeChange()));-
1993 disconnect(d->model, SIGNAL(modelReset()),-
1994 this, SLOT(_q_modelReset()));-
1995 if (d->model->QObject::parent() == this)
d->model->QObj...rent() == thisDescription
TRUEnever evaluated
FALSEnever evaluated
0
1996 delete d->model;
never executed: delete d->model;
0
1997 }
never executed: end of block
0
1998-
1999 d->model = model;-
2000-
2001 connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),-
2002 this, SLOT(_q_dataChanged(QModelIndex,QModelIndex)));-
2003 connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),-
2004 this, SLOT(_q_updateIndexBeforeChange()));-
2005 connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),-
2006 this, SLOT(_q_rowsInserted(QModelIndex,int,int)));-
2007 connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),-
2008 this, SLOT(_q_updateIndexBeforeChange()));-
2009 connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),-
2010 this, SLOT(_q_rowsRemoved(QModelIndex,int,int)));-
2011 connect(model, SIGNAL(destroyed()),-
2012 this, SLOT(_q_modelDestroyed()));-
2013 connect(model, SIGNAL(modelAboutToBeReset()),-
2014 this, SLOT(_q_updateIndexBeforeChange()));-
2015 connect(model, SIGNAL(modelReset()),-
2016 this, SLOT(_q_modelReset()));-
2017-
2018 if (d->container) {
d->containerDescription
TRUEnever evaluated
FALSEnever evaluated
0
2019 d->container->itemView()->setModel(model);-
2020 connect(d->container->itemView()->selectionModel(),-
2021 SIGNAL(currentChanged(QModelIndex,QModelIndex)),-
2022 this, SLOT(_q_emitHighlighted(QModelIndex)), Qt::UniqueConnection);-
2023 }
never executed: end of block
0
2024-
2025 setRootModelIndex(QModelIndex());-
2026-
2027 bool currentReset = false;-
2028-
2029 const int rowCount = count();-
2030 for (int pos=0; pos < rowCount; pos++) {
pos < rowCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
2031 if (d->model->index(pos, d->modelColumn, d->root).flags() & Qt::ItemIsEnabled) {
d->model->inde...:ItemIsEnabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
2032 setCurrentIndex(pos);-
2033 currentReset = true;-
2034 break;
never executed: break;
0
2035 }-
2036 }
never executed: end of block
0
2037-
2038 if (!currentReset)
!currentResetDescription
TRUEnever evaluated
FALSEnever evaluated
0
2039 setCurrentIndex(-1);
never executed: setCurrentIndex(-1);
0
2040-
2041 d->modelChanged();-
2042}
never executed: end of block
0
2043-
2044/*!-
2045 Returns the root model item index for the items in the combobox.-
2046-
2047 \sa setRootModelIndex()-
2048*/-
2049-
2050QModelIndex QComboBox::rootModelIndex() const-
2051{-
2052 Q_D(const QComboBox);-
2053 return QModelIndex(d->root);
never executed: return QModelIndex(d->root);
0
2054}-
2055-
2056/*!-
2057 Sets the root model item \a index for the items in the combobox.-
2058-
2059 \sa rootModelIndex()-
2060*/-
2061void QComboBox::setRootModelIndex(const QModelIndex &index)-
2062{-
2063 Q_D(QComboBox);-
2064 if (d->root == index)
d->root == indexDescription
TRUEnever evaluated
FALSEnever evaluated
0
2065 return;
never executed: return;
0
2066 d->root = QPersistentModelIndex(index);-
2067 view()->setRootIndex(index);-
2068 update();-
2069}
never executed: end of block
0
2070-
2071/*!-
2072 \property QComboBox::currentIndex-
2073 \brief the index of the current item in the combobox.-
2074-
2075 The current index can change when inserting or removing items.-
2076-
2077 By default, for an empty combo box or a combo box in which no current-
2078 item is set, this property has a value of -1.-
2079*/-
2080int QComboBox::currentIndex() const-
2081{-
2082 Q_D(const QComboBox);-
2083 return d->currentIndex.row();
never executed: return d->currentIndex.row();
0
2084}-
2085-
2086void QComboBox::setCurrentIndex(int index)-
2087{-
2088 Q_D(QComboBox);-
2089 QModelIndex mi = d->model->index(index, d->modelColumn, d->root);-
2090 d->setCurrentIndex(mi);-
2091}
never executed: end of block
0
2092-
2093void QComboBox::setCurrentText(const QString &text)-
2094{-
2095 if (isEditable()) {
isEditable()Description
TRUEnever evaluated
FALSEnever evaluated
0
2096 setEditText(text);-
2097 } else {
never executed: end of block
0
2098 const int i = findText(text);-
2099 if (i > -1)
i > -1Description
TRUEnever evaluated
FALSEnever evaluated
0
2100 setCurrentIndex(i);
never executed: setCurrentIndex(i);
0
2101 }
never executed: end of block
0
2102}-
2103-
2104void QComboBoxPrivate::setCurrentIndex(const QModelIndex &mi)-
2105{-
2106 Q_Q(QComboBox);-
2107-
2108 QModelIndex normalized = mi.sibling(mi.row(), modelColumn); // no-op if mi.column() == modelColumn-
2109 if (!normalized.isValid())
!normalized.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
2110 normalized = mi; // Fallback to passed index.
never executed: normalized = mi;
0
2111-
2112 bool indexChanged = (normalized != currentIndex);-
2113 if (indexChanged)
indexChangedDescription
TRUEnever evaluated
FALSEnever evaluated
0
2114 currentIndex = QPersistentModelIndex(normalized);
never executed: currentIndex = QPersistentModelIndex(normalized);
0
2115 if (lineEdit) {
lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
0
2116 const QString newText = itemText(normalized);-
2117 if (lineEdit->text() != newText) {
lineEdit->text() != newTextDescription
TRUEnever evaluated
FALSEnever evaluated
0
2118 lineEdit->setText(newText); // may cause lineEdit -> nullptr (QTBUG-54191)-
2119#ifndef QT_NO_COMPLETER-
2120 if (lineEdit && lineEdit->completer())
lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
lineEdit->completer()Description
TRUEnever evaluated
FALSEnever evaluated
0
2121 lineEdit->completer()->setCompletionPrefix(newText);
never executed: lineEdit->completer()->setCompletionPrefix(newText);
0
2122#endif-
2123 }
never executed: end of block
0
2124 updateLineEditGeometry();-
2125 }
never executed: end of block
0
2126 if (indexChanged) {
indexChangedDescription
TRUEnever evaluated
FALSEnever evaluated
0
2127 q->update();-
2128 _q_emitCurrentIndexChanged(currentIndex);-
2129 }
never executed: end of block
0
2130}
never executed: end of block
0
2131-
2132/*!-
2133 \property QComboBox::currentText-
2134 \brief the current text-
2135-
2136 If the combo box is editable, the current text is the value displayed-
2137 by the line edit. Otherwise, it is the value of the current item or-
2138 an empty string if the combo box is empty or no current item is set.-
2139-
2140 The setter setCurrentText() simply calls setEditText() if the combo box is editable.-
2141 Otherwise, if there is a matching text in the list, currentIndex is set to the-
2142 corresponding index.-
2143-
2144 \sa editable, setEditText()-
2145*/-
2146QString QComboBox::currentText() const-
2147{-
2148 Q_D(const QComboBox);-
2149 if (d->lineEdit)
d->lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
0
2150 return d->lineEdit->text();
never executed: return d->lineEdit->text();
0
2151 else if (d->currentIndex.isValid())
d->currentIndex.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
2152 return d->itemText(d->currentIndex);
never executed: return d->itemText(d->currentIndex);
0
2153 else-
2154 return QString();
never executed: return QString();
0
2155}-
2156-
2157/*!-
2158 \property QComboBox::currentData-
2159 \brief the data for the current item-
2160 \since 5.2-
2161-
2162 By default, for an empty combo box or a combo box in which no current-
2163 item is set, this property contains an invalid QVariant.-
2164*/-
2165QVariant QComboBox::currentData(int role) const-
2166{-
2167 Q_D(const QComboBox);-
2168 return d->currentIndex.data(role);
never executed: return d->currentIndex.data(role);
0
2169}-
2170-
2171/*!-
2172 Returns the text for the given \a index in the combobox.-
2173*/-
2174QString QComboBox::itemText(int index) const-
2175{-
2176 Q_D(const QComboBox);-
2177 QModelIndex mi = d->model->index(index, d->modelColumn, d->root);-
2178 return d->itemText(mi);
never executed: return d->itemText(mi);
0
2179}-
2180-
2181/*!-
2182 Returns the icon for the given \a index in the combobox.-
2183*/-
2184QIcon QComboBox::itemIcon(int index) const-
2185{-
2186 Q_D(const QComboBox);-
2187 QModelIndex mi = d->model->index(index, d->modelColumn, d->root);-
2188 return d->itemIcon(mi);
never executed: return d->itemIcon(mi);
0
2189}-
2190-
2191/*!-
2192 Returns the data for the given \a role in the given \a index in the-
2193 combobox, or QVariant::Invalid if there is no data for this role.-
2194*/-
2195QVariant QComboBox::itemData(int index, int role) const-
2196{-
2197 Q_D(const QComboBox);-
2198 QModelIndex mi = d->model->index(index, d->modelColumn, d->root);-
2199 return d->model->data(mi, role);
never executed: return d->model->data(mi, role);
0
2200}-
2201-
2202/*!-
2203 \fn void QComboBox::insertItem(int index, const QString &text, const QVariant &userData)-
2204-
2205 Inserts the \a text and \a userData (stored in the Qt::UserRole)-
2206 into the combobox at the given \a index.-
2207-
2208 If the index is equal to or higher than the total number of items,-
2209 the new item is appended to the list of existing items. If the-
2210 index is zero or negative, the new item is prepended to the list-
2211 of existing items.-
2212-
2213 \sa insertItems()-
2214*/-
2215-
2216/*!-
2217-
2218 Inserts the \a icon, \a text and \a userData (stored in the-
2219 Qt::UserRole) into the combobox at the given \a index.-
2220-
2221 If the index is equal to or higher than the total number of items,-
2222 the new item is appended to the list of existing items. If the-
2223 index is zero or negative, the new item is prepended to the list-
2224 of existing items.-
2225-
2226 \sa insertItems()-
2227*/-
2228void QComboBox::insertItem(int index, const QIcon &icon, const QString &text, const QVariant &userData)-
2229{-
2230 Q_D(QComboBox);-
2231 int itemCount = count();-
2232 index = qBound(0, index, itemCount);-
2233 if (index >= d->maxCount)
index >= d->maxCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
2234 return;
never executed: return;
0
2235-
2236 // For the common case where we are using the built in QStandardItemModel-
2237 // construct a QStandardItem, reducing the number of expensive signals from the model-
2238 if (QStandardItemModel *m = qobject_cast<QStandardItemModel*>(d->model)) {
QStandardItemM...el*>(d->model)Description
TRUEnever evaluated
FALSEnever evaluated
0
2239 QStandardItem *item = new QStandardItem(text);-
2240 if (!icon.isNull()) item->setData(icon, Qt::DecorationRole);
never executed: item->setData(icon, Qt::DecorationRole);
!icon.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
2241 if (userData.isValid()) item->setData(userData, Qt::UserRole);
never executed: item->setData(userData, Qt::UserRole);
userData.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
2242 m->insertRow(index, item);-
2243 ++itemCount;-
2244 } else {
never executed: end of block
0
2245 d->inserting = true;-
2246 if (d->model->insertRows(index, 1, d->root)) {
d->model->inse...x, 1, d->root)Description
TRUEnever evaluated
FALSEnever evaluated
0
2247 QModelIndex item = d->model->index(index, d->modelColumn, d->root);-
2248 if (icon.isNull() && !userData.isValid()) {
icon.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
!userData.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
2249 d->model->setData(item, text, Qt::EditRole);-
2250 } else {
never executed: end of block
0
2251 QMap<int, QVariant> values;-
2252 if (!text.isNull()) values.insert(Qt::EditRole, text);
never executed: values.insert(Qt::EditRole, text);
!text.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
2253 if (!icon.isNull()) values.insert(Qt::DecorationRole, icon);
never executed: values.insert(Qt::DecorationRole, icon);
!icon.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
2254 if (userData.isValid()) values.insert(Qt::UserRole, userData);
never executed: values.insert(Qt::UserRole, userData);
userData.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
2255 if (!values.isEmpty()) d->model->setItemData(item, values);
never executed: d->model->setItemData(item, values);
!values.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
2256 }
never executed: end of block
0
2257 d->inserting = false;-
2258 d->_q_rowsInserted(d->root, index, index);-
2259 ++itemCount;-
2260 } else {
never executed: end of block
0
2261 d->inserting = false;-
2262 }
never executed: end of block
0
2263 }-
2264-
2265 if (itemCount > d->maxCount)
itemCount > d->maxCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
2266 d->model->removeRows(itemCount - 1, itemCount - d->maxCount, d->root);
never executed: d->model->removeRows(itemCount - 1, itemCount - d->maxCount, d->root);
0
2267}
never executed: end of block
0
2268-
2269/*!-
2270 Inserts the strings from the \a list into the combobox as separate items,-
2271 starting at the \a index specified.-
2272-
2273 If the index is equal to or higher than the total number of items, the new items-
2274 are appended to the list of existing items. If the index is zero or negative, the-
2275 new items are prepended to the list of existing items.-
2276-
2277 \sa insertItem()-
2278 */-
2279void QComboBox::insertItems(int index, const QStringList &list)-