qcombobox.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qcombobox.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10-
11-
12-
13-
14-
15QComboBoxPrivate::QComboBoxPrivate()-
16 : QWidgetPrivate(),-
17 model(0),-
18 lineEdit(0),-
19 container(0),-
20 insertPolicy(QComboBox::InsertAtBottom),-
21 sizeAdjustPolicy(QComboBox::AdjustToContentsOnFirstShow),-
22 minimumContentsLength(0),-
23 shownOnce(false),-
24 autoCompletion(true),-
25 duplicatesEnabled(false),-
26 frame(true),-
27 maxVisibleItems(10),-
28 maxCount(2147483647),-
29 modelColumn(0),-
30 inserting(false),-
31 arrowState(QStyle::State_None),-
32 hoverControl(QStyle::SC_None),-
33 autoCompletionCaseSensitivity(Qt::CaseInsensitive),-
34 indexBeforeChange(-1)-
35-
36-
37-
38-
39 , completer(0)-
40-
41{-
42}-
43-
44QComboBoxPrivate::~QComboBoxPrivate()-
45{-
46-
47-
48-
49}-
50-
51QStyleOptionMenuItem QComboMenuDelegate::getStyleOption(const QStyleOptionViewItem &option,-
52 const QModelIndex &index) const-
53{-
54 QStyleOptionMenuItem menuOption;-
55-
56 QPalette resolvedpalette = option.palette.resolve(QApplication::palette("QMenu"));-
57 QVariant value = index.data(Qt::ForegroundRole);-
58 if (value.canConvert<QBrush>()) {-
59 resolvedpalette.setBrush(QPalette::WindowText, qvariant_cast<QBrush>(value));-
60 resolvedpalette.setBrush(QPalette::ButtonText, qvariant_cast<QBrush>(value));-
61 resolvedpalette.setBrush(QPalette::Text, qvariant_cast<QBrush>(value));-
62 }-
63 menuOption.palette = resolvedpalette;-
64 menuOption.state = QStyle::State_None;-
65 if (mCombo->window()->isActiveWindow())-
66 menuOption.state = QStyle::State_Active;-
67 if ((option.state & QStyle::State_Enabled) && (index.model()->flags(index) & Qt::ItemIsEnabled))-
68 menuOption.state |= QStyle::State_Enabled;-
69 else-
70 menuOption.palette.setCurrentColorGroup(QPalette::Disabled);-
71 if (option.state & QStyle::State_Selected)-
72 menuOption.state |= QStyle::State_Selected;-
73 menuOption.checkType = QStyleOptionMenuItem::NonExclusive;-
74 menuOption.checked = mCombo->currentIndex() == index.row();-
75 if (QComboBoxDelegate::isSeparator(index))-
76 menuOption.menuItemType = QStyleOptionMenuItem::Separator;-
77 else-
78 menuOption.menuItemType = QStyleOptionMenuItem::Normal;-
79-
80 QVariant variant = index.model()->data(index, Qt::DecorationRole);-
81 switch (variant.type()) {-
82 case QVariant::Icon:-
83 menuOption.icon = qvariant_cast<QIcon>(variant);-
84 break;-
85 case QVariant::Color: {-
86 static QPixmap pixmap(option.decorationSize);-
87 pixmap.fill(qvariant_cast<QColor>(variant));-
88 menuOption.icon = pixmap;-
89 break; }-
90 default:-
91 menuOption.icon = qvariant_cast<QPixmap>(variant);-
92 break;-
93 }-
94 if (index.data(Qt::BackgroundRole).canConvert<QBrush>()) {-
95 menuOption.palette.setBrush(QPalette::All, QPalette::Background,-
96 qvariant_cast<QBrush>(index.data(Qt::BackgroundRole)));-
97 }-
98 menuOption.text = index.model()->data(index, Qt::DisplayRole).toString()-
99 .replace(QLatin1Char('&'), QLatin1String("&&"));-
100 menuOption.tabWidth = 0;-
101 menuOption.maxIconWidth = option.decorationSize.width() + 4;-
102 menuOption.menuRect = option.rect;-
103 menuOption.rect = option.rect;-
104-
105-
106 if (mCombo->testAttribute(Qt::WA_SetFont)-
107 || mCombo->testAttribute(Qt::WA_MacSmallSize)-
108 || mCombo->testAttribute(Qt::WA_MacMiniSize)-
109 || mCombo->font() != qt_app_fonts_hash()->value("QComboBox", QFont())) {-
110 menuOption.font = mCombo->font();-
111 } else {-
112 QVariant fontRoleData = index.data(Qt::FontRole);-
113 if (fontRoleData.isValid())-
114 menuOption.font = fontRoleData.value<QFont>();-
115 else-
116 menuOption.font = qt_app_fonts_hash()->value("QComboMenuItem", mCombo->font());-
117 }-
118-
119 menuOption.fontMetrics = QFontMetrics(menuOption.font);-
120-
121 return menuOption;-
122}-
123-
124-
125void QComboBoxPrivate::_q_completerActivated(const QModelIndex &index)-
126{-
127 QComboBox * const q = q_func();-
128 if (index.isValid() && q->completer()) {-
129 QAbstractProxyModel *proxy = qobject_cast<QAbstractProxyModel *>(q->completer()->completionModel());-
130 if (proxy) {-
131 q->setCurrentIndex(proxy->mapToSource(index).row());-
132 emitActivated(currentIndex);-
133 }-
134 }-
135}-
136-
137-
138void QComboBoxPrivate::updateArrow(QStyle::StateFlag state)-
139{-
140 QComboBox * const q = q_func();-
141 if (arrowState == state)-
142 return;-
143 arrowState = state;-
144 QStyleOptionComboBox opt;-
145 q->initStyleOption(&opt);-
146 q->update(q->rect());-
147}-
148-
149void QComboBoxPrivate::_q_modelReset()-
150{-
151 QComboBox * const q = q_func();-
152 if (lineEdit) {-
153 lineEdit->setText(QString());-
154 updateLineEditGeometry();-
155 }-
156 if (currentIndex.row() != indexBeforeChange)-
157 _q_emitCurrentIndexChanged(currentIndex);-
158 modelChanged();-
159 q->update();-
160}-
161-
162void QComboBoxPrivate::_q_modelDestroyed()-
163{-
164 model = QAbstractItemModelPrivate::staticEmptyModel();-
165}-
166-
167-
168-
169QRect QComboBoxPrivate::popupGeometry(int screen) const-
170{-
171 bool useFullScreenForPopupMenu = false;-
172 if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme())-
173 useFullScreenForPopupMenu = theme->themeHint(QPlatformTheme::UseFullScreenForPopupMenu).toBool();-
174 return useFullScreenForPopupMenu ?-
175 QApplication::desktop()->screenGeometry(screen) :-
176 QApplication::desktop()->availableGeometry(screen);-
177}-
178-
179bool QComboBoxPrivate::updateHoverControl(const QPoint &pos)-
180{-
181-
182 QComboBox * const q = q_func();-
183 QRect lastHoverRect = hoverRect;-
184 QStyle::SubControl lastHoverControl = hoverControl;-
185 bool doesHover = q->testAttribute(Qt::WA_Hover);-
186 if (lastHoverControl != newHoverControl(pos) && doesHover) {-
187 q->update(lastHoverRect);-
188 q->update(hoverRect);-
189 return true;-
190 }-
191 return !doesHover;-
192}-
193-
194QStyle::SubControl QComboBoxPrivate::newHoverControl(const QPoint &pos)-
195{-
196 QComboBox * const q = q_func();-
197 QStyleOptionComboBox opt;-
198 q->initStyleOption(&opt);-
199 opt.subControls = QStyle::SC_All;-
200 hoverControl = q->style()->hitTestComplexControl(QStyle::CC_ComboBox, &opt, pos, q);-
201 hoverRect = (hoverControl != QStyle::SC_None)-
202 ? q->style()->subControlRect(QStyle::CC_ComboBox, &opt, hoverControl, q)-
203 : QRect();-
204 return hoverControl;-
205}-
206-
207-
208-
209-
210-
211int QComboBoxPrivate::computeWidthHint() const-
212{-
213 const QComboBox * const q = q_func();-
214-
215 int width = 0;-
216 const int count = q->count();-
217 const int iconWidth = q->iconSize().width() + 4;-
218 const QFontMetrics &fontMetrics = q->fontMetrics();-
219-
220 for (int i = 0; i < count; ++i) {-
221 const int textWidth = fontMetrics.width(q->itemText(i));-
222 if (q->itemIcon(i).isNull())-
223 width = (qMax(width, textWidth));-
224 else-
225 width = (qMax(width, textWidth + iconWidth));-
226 }-
227-
228 QStyleOptionComboBox opt;-
229 q->initStyleOption(&opt);-
230 QSize tmp(width, 0);-
231 tmp = q->style()->sizeFromContents(QStyle::CT_ComboBox, &opt, tmp, q);-
232 return tmp.width();-
233}-
234-
235QSize QComboBoxPrivate::recomputeSizeHint(QSize &sh) const-
236{-
237 const QComboBox * const q = q_func();-
238 if (!sh.isValid()) {-
239 bool hasIcon = sizeAdjustPolicy == QComboBox::AdjustToMinimumContentsLengthWithIcon;-
240 int count = q->count();-
241 QSize iconSize = q->iconSize();-
242 const QFontMetrics &fm = q->fontMetrics();-
243-
244-
245 if (&sh == &sizeHint || minimumContentsLength == 0) {-
246 switch (sizeAdjustPolicy) {-
247 case QComboBox::AdjustToContents:-
248 case QComboBox::AdjustToContentsOnFirstShow:-
249 if (count == 0) {-
250 sh.rwidth() = 7 * fm.width(QLatin1Char('x'));-
251 } else {-
252 for (int i = 0; i < count; ++i) {-
253 if (!q->itemIcon(i).isNull()) {-
254 hasIcon = true;-
255 sh.setWidth(qMax(sh.width(), fm.boundingRect(q->itemText(i)).width() + iconSize.width() + 4));-
256 } else {-
257 sh.setWidth(qMax(sh.width(), fm.boundingRect(q->itemText(i)).width()));-
258 }-
259 }-
260 }-
261 break;-
262 case QComboBox::AdjustToMinimumContentsLength:-
263 for (int i = 0; i < count && !hasIcon; ++i)-
264 hasIcon = !q->itemIcon(i).isNull();-
265 default:-
266 ;-
267 }-
268 } else {-
269 for (int i = 0; i < count && !hasIcon; ++i)-
270 hasIcon = !q->itemIcon(i).isNull();-
271 }-
272 if (minimumContentsLength > 0)-
273 sh.setWidth(qMax(sh.width(), minimumContentsLength * fm.width(QLatin1Char('X')) + (hasIcon ? iconSize.width() + 4 : 0)));-
274-
275-
276-
277 sh.setHeight(qMax(qCeil(QFontMetricsF(fm).height()), 14) + 2);-
278 if (hasIcon) {-
279 sh.setHeight(qMax(sh.height(), iconSize.height() + 2));-
280 }-
281-
282-
283 QStyleOptionComboBox opt;-
284 q->initStyleOption(&opt);-
285 sh = q->style()->sizeFromContents(QStyle::CT_ComboBox, &opt, sh, q);-
286 }-
287 return sh.expandedTo(QApplication::globalStrut());-
288}-
289-
290void QComboBoxPrivate::adjustComboBoxSize()-
291{-
292 viewContainer()->adjustSizeTimer.start(20, container);-
293}-
294-
295void QComboBoxPrivate::updateLayoutDirection()-
296{-
297 const QComboBox * const q = q_func();-
298 QStyleOptionComboBox opt;-
299 q->initStyleOption(&opt);-
300 Qt::LayoutDirection dir = Qt::LayoutDirection(-
301 q->style()->styleHint(QStyle::SH_ComboBox_LayoutDirection, &opt, q));-
302 if (lineEdit)-
303 lineEdit->setLayoutDirection(dir);-
304 if (container)-
305 container->setLayoutDirection(dir);-
306}-
307-
308-
309void QComboBoxPrivateContainer::timerEvent(QTimerEvent *timerEvent)-
310{-
311 if (timerEvent->timerId() == adjustSizeTimer.timerId()) {-
312 adjustSizeTimer.stop();-
313 if (combo->sizeAdjustPolicy() == QComboBox::AdjustToContents) {-
314 combo->updateGeometry();-
315 combo->adjustSize();-
316 combo->update();-
317 }-
318 }-
319}-
320-
321void QComboBoxPrivateContainer::resizeEvent(QResizeEvent *e)-
322{-
323 QStyleOptionComboBox opt = comboStyleOption();-
324 if (combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo)) {-
325 QStyleOption myOpt;-
326 myOpt.initFrom(this);-
327 QStyleHintReturnMask mask;-
328 if (combo->style()->styleHint(QStyle::SH_Menu_Mask, &myOpt, this, &mask)) {-
329 setMask(mask.region);-
330 }-
331 } else {-
332 clearMask();-
333 }-
334 QFrame::resizeEvent(e);-
335}-
336-
337void QComboBoxPrivateContainer::leaveEvent(QEvent *)-
338{-
339-
340-
341-
342-
343-
344-
345-
346}-
347-
348QComboBoxPrivateContainer::QComboBoxPrivateContainer(QAbstractItemView *itemView, QComboBox *parent)-
349 : QFrame(parent, Qt::Popup), combo(parent), view(0), top(0), bottom(0), maybeIgnoreMouseButtonRelease(false)-
350{-
351-
352 ((!(parent)) ? qt_assert("parent",__FILE__,423429) : qt_noop());-
353 ((!(itemView)) ? qt_assert("itemView",__FILE__,424430) : qt_noop());-
354-
355 setAttribute(Qt::WA_WindowPropagation);-
356 setAttribute(Qt::WA_X11NetWmWindowTypeCombo);-
357-
358-
359 blockMouseReleaseTimer.setSingleShot(true);-
360-
361-
362 QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom, this);-
363 layout->setSpacing(0);-
364 layout->setMargin(0);-
365-
366-
367 setItemView(itemView);-
368-
369-
370 QStyleOptionComboBox opt = comboStyleOption();-
371 const bool usePopup = combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo);-
372 if (usePopup) {-
373 top = new QComboBoxPrivateScroller(QAbstractSlider::SliderSingleStepSub, this);-
374 bottom = new QComboBoxPrivateScroller(QAbstractSlider::SliderSingleStepAdd, this);-
375 top->hide();-
376 bottom->hide();-
377 } else {-
378 setLineWidth(1);-
379 }-
380-
381 setFrameStyle(combo->style()->styleHint(QStyle::SH_ComboBox_PopupFrameStyle, &opt, combo));-
382-
383 if (top) {-
384 layout->insertWidget(0, top);-
385 connect(top, qFlagLocation("2""doScroll(int)" "\0" __FILE__ ":" "456""462"), this, qFlagLocation("1""scrollItemView(int)" "\0" __FILE__ ":" "456""462"));-
386 }-
387 if (bottom) {-
388 layout->addWidget(bottom);-
389 connect(bottom, qFlagLocation("2""doScroll(int)" "\0" __FILE__ ":" "460""466"), this, qFlagLocation("1""scrollItemView(int)" "\0" __FILE__ ":" "460""466"));-
390 }-
391-
392-
393 layout->insertSpacing(0, 0);-
394 layout->addSpacing(0);-
395 updateTopBottomMargin();-
396}-
397-
398void QComboBoxPrivateContainer::scrollItemView(int action)-
399{-
400-
401 if (view->verticalScrollBar())-
402 view->verticalScrollBar()->triggerAction(static_cast<QAbstractSlider::SliderAction>(action));-
403-
404}-
405-
406-
407-
408-
409void QComboBoxPrivateContainer::updateScrollers()-
410{-
411-
412 if (!top || !bottom)-
413 return;-
414-
415 if (isVisible() == false)-
416 return;-
417-
418 QStyleOptionComboBox opt = comboStyleOption();-
419 if (combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo) &&-
420 view->verticalScrollBar()->minimum() < view->verticalScrollBar()->maximum()) {-
421-
422 bool needTop = view->verticalScrollBar()->value()-
423 > (view->verticalScrollBar()->minimum() + topMargin());-
424 bool needBottom = view->verticalScrollBar()->value()-
425 < (view->verticalScrollBar()->maximum() - bottomMargin() - topMargin());-
426 if (needTop)-
427 top->show();-
428 else-
429 top->hide();-
430 if (needBottom)-
431 bottom->show();-
432 else-
433 bottom->hide();-
434 } else {-
435 top->hide();-
436 bottom->hide();-
437 }-
438-
439}-
440-
441-
442-
443-
444void QComboBoxPrivateContainer::viewDestroyed()-
445{-
446 view = 0;-
447 setItemView(new QComboBoxListView());-
448}-
449-
450-
451-
452-
453QAbstractItemView *QComboBoxPrivateContainer::itemView() const-
454{-
455 return view;-
456}-
457-
458-
459-
460-
461void QComboBoxPrivateContainer::setItemView(QAbstractItemView *itemView)-
462{-
463 ((!(itemView)) ? qt_assert("itemView",__FILE__,534540) : qt_noop());-
464-
465-
466 if (view) {-
467 view->removeEventFilter(this);-
468 view->viewport()->removeEventFilter(this);-
469-
470 disconnect(view->verticalScrollBar(), qFlagLocation("2""valueChanged(int)" "\0" __FILE__ ":" "541""547"),-
471 this, qFlagLocation("1""updateScrollers()" "\0" __FILE__ ":" "542""548"));-
472 disconnect(view->verticalScrollBar(), qFlagLocation("2""rangeChanged(int,int)" "\0" __FILE__ ":" "543""549"),-
473 this, qFlagLocation("1""updateScrollers()" "\0" __FILE__ ":" "544""550"));-
474-
475 disconnect(view, qFlagLocation("2""destroyed()" "\0" __FILE__ ":" "546""552"),-
476 this, qFlagLocation("1""viewDestroyed()" "\0" __FILE__ ":" "547""553"));-
477-
478 if (isAncestorOf(view))-
479 delete view;-
480 view = 0;-
481 }-
482-
483-
484 view = itemView;-
485 view->setParent(this);-
486 view->setAttribute(Qt::WA_MacShowFocusRect, false);-
487 qobject_cast<QBoxLayout*>(layout())->insertWidget(top ? 2 : 0, view);-
488 view->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);-
489 view->installEventFilter(this);-
490 view->viewport()->installEventFilter(this);-
491 view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);-
492 QStyleOptionComboBox opt = comboStyleOption();-
493 const bool usePopup = combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo);-
494-
495 if (usePopup)-
496 view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);-
497-
498 if (combo->style()->styleHint(QStyle::SH_ComboBox_ListMouseTracking, &opt, combo) ||-
499 usePopup) {-
500 view->setMouseTracking(true);-
501 }-
502 view->setSelectionMode(QAbstractItemView::SingleSelection);-
503 view->setFrameStyle(QFrame::NoFrame);-
504 view->setLineWidth(0);-
505 view->setEditTriggers(QAbstractItemView::NoEditTriggers);-
506-
507 connect(view->verticalScrollBar(), qFlagLocation("2""valueChanged(int)" "\0" __FILE__ ":" "578""584"),-
508 this, qFlagLocation("1""updateScrollers()" "\0" __FILE__ ":" "579""585"));-
509 connect(view->verticalScrollBar(), qFlagLocation("2""rangeChanged(int,int)" "\0" __FILE__ ":" "580""586"),-
510 this, qFlagLocation("1""updateScrollers()" "\0" __FILE__ ":" "581""587"));-
511-
512 connect(view, qFlagLocation("2""destroyed()" "\0" __FILE__ ":" "583""589"),-
513 this, qFlagLocation("1""viewDestroyed()" "\0" __FILE__ ":" "584""590"));-
514}-
515-
516-
517-
518-
519int QComboBoxPrivateContainer::topMargin() const-
520{-
521 if (const QListView *lview = qobject_cast<const QListView*>(view))-
522 return lview->spacing();-
523-
524 if (const QTableView *tview = qobject_cast<const QTableView*>(view))-
525 return tview->showGrid() ? 1 : 0;-
526-
527 return 0;-
528}-
529-
530-
531-
532-
533int QComboBoxPrivateContainer::spacing() const-
534{-
535 QListView *lview = qobject_cast<QListView*>(view);-
536 if (lview)-
537 return 2 * lview->spacing();-
538-
539 QTableView *tview = qobject_cast<QTableView*>(view);-
540 if (tview)-
541 return tview->showGrid() ? 1 : 0;-
542-
543 return 0;-
544}-
545-
546void QComboBoxPrivateContainer::updateTopBottomMargin()-
547{-
548 if (!layout() || layout()->count() < 1)-
549 return;-
550-
551 QBoxLayout *boxLayout = qobject_cast<QBoxLayout *>(layout());-
552 if (!boxLayout)-
553 return;-
554-
555 const QStyleOptionComboBox opt = comboStyleOption();-
556 const bool usePopup = combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo);-
557 const int margin = usePopup ? combo->style()->pixelMetric(QStyle::PM_MenuVMargin, &opt, combo) : 0;-
558-
559 QSpacerItem *topSpacer = boxLayout->itemAt(0)->spacerItem();-
560 if (topSpacer)-
561 topSpacer->changeSize(0, margin, QSizePolicy::Minimum, QSizePolicy::Fixed);-
562-
563 QSpacerItem *bottomSpacer = boxLayout->itemAt(boxLayout->count() - 1)->spacerItem();-
564 if (bottomSpacer && bottomSpacer != topSpacer)-
565 bottomSpacer->changeSize(0, margin, QSizePolicy::Minimum, QSizePolicy::Fixed);-
566-
567 boxLayout->invalidate();-
568}-
569-
570void QComboBoxPrivateContainer::changeEvent(QEvent *e)-
571{-
572 if (e->type() == QEvent::StyleChange) {-
573 QStyleOptionComboBox opt = comboStyleOption();-
574 view->setMouseTracking(combo->style()->styleHint(QStyle::SH_ComboBox_ListMouseTracking, &opt, combo) ||-
575 combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo));-
576 setFrameStyle(combo->style()->styleHint(QStyle::SH_ComboBox_PopupFrameStyle, &opt, combo));-
577 }-
578-
579 QWidget::changeEvent(e);-
580}-
581-
582-
583bool QComboBoxPrivateContainer::eventFilter(QObject *o, QEvent *e)-
584{-
585 switch (e->type()) {-
586 case QEvent::ShortcutOverride: {-
587 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(e);-
588 switch (keyEvent->key()) {-
589 case Qt::Key_Enter:-
590 case Qt::Key_Return:-
591-
592-
593-
594 if (view->currentIndex().isValid() && (view->currentIndex().flags() & Qt::ItemIsEnabled) ) {-
595 combo->hidePopup();-
596 itemSelected(view->currentIndex());-
597 }-
598 return true;-
599 case Qt::Key_Down:-
600 if (!(keyEvent->modifiers() & Qt::AltModifier))-
601 break;-
602-
603 case Qt::Key_F4:-
604 combo->hidePopup();-
605 return true;-
606 default:-
607 if (keyEvent->matches(QKeySequence::Cancel)) {-
608 combo->hidePopup();-
609 return true;-
610 }-
611 break;-
612 }-
613 break;-
614 }-
615 case QEvent::MouseMove:-
616 if (isVisible()) {-
617 QMouseEvent *m = static_cast<QMouseEvent *>(e);-
618 QWidget *widget = static_cast<QWidget *>(o);-
619 QPoint vector = widget->mapToGlobal(m->pos()) - initialClickPosition;-
620 if (vector.manhattanLength() > 9 && blockMouseReleaseTimer.isActive())-
621 blockMouseReleaseTimer.stop();-
622 QModelIndex indexUnderMouse = view->indexAt(m->pos());-
623 if (indexUnderMouse.isValid()-
624 && !QComboBoxDelegate::isSeparator(indexUnderMouse)) {-
625 view->setCurrentIndex(indexUnderMouse);-
626 }-
627 }-
628 break;-
629 case QEvent::MouseButtonPress:-
630 maybeIgnoreMouseButtonRelease = false;-
631 break;-
632 case QEvent::MouseButtonRelease: {-
633 bool ignoreEvent = maybeIgnoreMouseButtonRelease && popupTimer.elapsed() < QApplication::doubleClickInterval();-
634-
635 QMouseEvent *m = static_cast<QMouseEvent *>(e);-
636 if (isVisible() && view->rect().contains(m->pos()) && view->currentIndex().isValid()-
637 && !blockMouseReleaseTimer.isActive() && !ignoreEvent-
638 && (view->currentIndex().flags() & Qt::ItemIsEnabled)-
639 && (view->currentIndex().flags() & Qt::ItemIsSelectable)) {-
640 combo->hidePopup();-
641 itemSelected(view->currentIndex());-
642 return true;-
643 }-
644 break;-
645 }-
646 default:-
647 break;-
648 }-
649 return QFrame::eventFilter(o, e);-
650}-
651-
652void QComboBoxPrivateContainer::showEvent(QShowEvent *)-
653{-
654 combo->update();-
655}-
656-
657void QComboBoxPrivateContainer::hideEvent(QHideEvent *)-
658{-
659 resetButton();-
660 combo->update();-
661-
662-
663-
664-
665 if (QGraphicsProxyWidget *proxy = graphicsProxyWidget())-
666 proxy->hide();-
667-
668}-
669-
670void QComboBoxPrivateContainer::mousePressEvent(QMouseEvent *e)-
671{-
672-
673 QStyleOptionComboBox opt = comboStyleOption();-
674 opt.subControls = QStyle::SC_All;-
675 opt.activeSubControls = QStyle::SC_ComboBoxArrow;-
676 QStyle::SubControl sc = combo->style()->hitTestComplexControl(QStyle::CC_ComboBox, &opt,-
677 combo->mapFromGlobal(e->globalPos()),-
678 combo);-
679 if ((combo->isEditable() && sc == QStyle::SC_ComboBoxArrow)-
680 || (!combo->isEditable() && sc != QStyle::SC_None))-
681 setAttribute(Qt::WA_NoMouseReplay);-
682 combo->hidePopup();-
683}-
684-
685void QComboBoxPrivateContainer::mouseReleaseEvent(QMouseEvent *e)-
686{-
687 (void)e;;-
688 if (!blockMouseReleaseTimer.isActive()){-
689 combo->hidePopup();-
690 resetButton();-
691 }-
692}-
693-
694QStyleOptionComboBox QComboBoxPrivateContainer::comboStyleOption() const-
695{-
696-
697-
698 QStyleOptionComboBox opt;-
699 opt.initFrom(combo);-
700 opt.subControls = QStyle::SC_All;-
701 opt.activeSubControls = QStyle::SC_None;-
702 opt.editable = combo->isEditable();-
703 return opt;-
704}-
705QComboBox::QComboBox(QWidget *parent)-
706 : QWidget(*new QComboBoxPrivate(), parent, 0)-
707{-
708 QComboBoxPrivate * const d = d_func();-
709 d->init();-
710}-
711-
712-
713-
714-
715QComboBox::QComboBox(QComboBoxPrivate &dd, QWidget *parent)-
716 : QWidget(dd, parent, 0)-
717{-
718 QComboBoxPrivate * const d = d_func();-
719 d->init();-
720}-
721void QComboBoxPrivate::init()-
722{-
723 QComboBox * const q = q_func();-
724 q->setFocusPolicy(Qt::WheelFocus);-
725-
726 q->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed,-
727 QSizePolicy::ComboBox));-
728 setLayoutItemMargins(QStyle::SE_ComboBoxLayoutItem);-
729 q->setModel(new QStandardItemModel(0, 1, q));-
730 if (!q->isEditable())-
731 q->setAttribute(Qt::WA_InputMethodEnabled, false);-
732 else-
733 q->setAttribute(Qt::WA_InputMethodEnabled);-
734}-
735-
736QComboBoxPrivateContainer* QComboBoxPrivate::viewContainer()-
737{-
738 if (container)-
739 return container;-
740-
741 QComboBox * const q = q_func();-
742 container = new QComboBoxPrivateContainer(new QComboBoxListView(q), q);-
743 container->itemView()->setModel(model);-
744 container->itemView()->setTextElideMode(Qt::ElideMiddle);-
745 updateDelegate(true);-
746 updateLayoutDirection();-
747 updateViewContainerPaletteAndOpacity();-
748 QObject::connect(container, qFlagLocation("2""itemSelected(QModelIndex)" "\0" __FILE__ ":" "996""1002"),-
749 q, qFlagLocation("1""_q_itemSelected(QModelIndex)" "\0" __FILE__ ":" "997""1003"));-
750 QObject::connect(container->itemView()->selectionModel(),-
751 qFlagLocation("2""currentChanged(QModelIndex,QModelIndex)" "\0" __FILE__ ":" "999""1005"),-
752 q, qFlagLocation("1""_q_emitHighlighted(QModelIndex)" "\0" __FILE__ ":" "1000""1006"));-
753 QObject::connect(container, qFlagLocation("2""resetButton()" "\0" __FILE__ ":" "1001""1007"), q, qFlagLocation("1""_q_resetButton()" "\0" __FILE__ ":" "1001""1007"));-
754 return container;-
755}-
756-
757-
758void QComboBoxPrivate::_q_resetButton()-
759{-
760 updateArrow(QStyle::State_None);-
761}-
762-
763void QComboBoxPrivate::_q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)-
764{-
765 QComboBox * const q = q_func();-
766 if (inserting || topLeft.parent() != root)-
767 return;-
768-
769 if (sizeAdjustPolicy == QComboBox::AdjustToContents) {-
770 sizeHint = QSize();-
771 adjustComboBoxSize();-
772 q->updateGeometry();-
773 }-
774-
775 if (currentIndex.row() >= topLeft.row() && currentIndex.row() <= bottomRight.row()) {-
776 const QString text = q->itemText(currentIndex.row());-
777 if (lineEdit) {-
778 lineEdit->setText(text);-
779 updateLineEditGeometry();-
780 } else {-
781 q->currentTextChanged(text);-
782 }-
783 q->update();-
784-
785 QAccessibleValueChangeEvent event(q, text);-
786 QAccessible::updateAccessibility(&event);-
787-
788 }-
789}-
790-
791void QComboBoxPrivate::_q_rowsInserted(const QModelIndex &parent, int start, int end)-
792{-
793 QComboBox * const q = q_func();-
794 if (inserting || parent != root)-
795 return;-
796-
797 if (sizeAdjustPolicy == QComboBox::AdjustToContents) {-
798 sizeHint = QSize();-
799 adjustComboBoxSize();-
800 q->updateGeometry();-
801 }-
802-
803-
804 if (start == 0 && (end - start + 1) == q->count() && !currentIndex.isValid()) {-
805 q->setCurrentIndex(0);-
806-
807 } else if (currentIndex.row() != indexBeforeChange) {-
808 q->update();-
809 _q_emitCurrentIndexChanged(currentIndex);-
810 }-
811}-
812-
813void QComboBoxPrivate::_q_updateIndexBeforeChange()-
814{-
815 indexBeforeChange = currentIndex.row();-
816}-
817-
818void QComboBoxPrivate::_q_rowsRemoved(const QModelIndex &parent, int , int )-
819{-
820 QComboBox * const q = q_func();-
821 if (parent != root)-
822 return;-
823-
824 if (sizeAdjustPolicy == QComboBox::AdjustToContents) {-
825 sizeHint = QSize();-
826 adjustComboBoxSize();-
827 q->updateGeometry();-
828 }-
829-
830-
831 if (currentIndex.row() != indexBeforeChange) {-
832 if (!currentIndex.isValid() && q->count()) {-
833 q->setCurrentIndex(qMin(q->count() - 1, qMax(indexBeforeChange, 0)));-
834 return;-
835 }-
836 if (lineEdit) {-
837 lineEdit->setText(q->itemText(currentIndex.row()));-
838 updateLineEditGeometry();-
839 }-
840 q->update();-
841 _q_emitCurrentIndexChanged(currentIndex);-
842 }-
843}-
844-
845-
846void QComboBoxPrivate::updateViewContainerPaletteAndOpacity()-
847{-
848 if (!container)-
849 return;-
850 QComboBox * const q = q_func();-
851 QStyleOptionComboBox opt;-
852 q->initStyleOption(&opt);-
853-
854 if (q->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, q)) {-
855 QMenu menu;-
856 menu.ensurePolished();-
857 container->setPalette(menu.palette());-
858 container->setWindowOpacity(menu.windowOpacity());-
859 } else-
860-
861 {-
862 container->setPalette(q->palette());-
863 container->setWindowOpacity(1.0);-
864 }-
865 if (lineEdit)-
866 lineEdit->setPalette(q->palette());-
867}-
868-
869void QComboBoxPrivate::updateFocusPolicy()-
870{-
871}-
872void QComboBox::initStyleOption(QStyleOptionComboBox *option) const-
873{-
874 if (!option)-
875 return;-
876-
877 const QComboBoxPrivate * const d = d_func();-
878 option->initFrom(this);-
879 option->editable = isEditable();-
880 option->frame = d->frame;-
881 if (hasFocus() && !option->editable)-
882 option->state |= QStyle::State_Selected;-
883 option->subControls = QStyle::SC_All;-
884 if (d->arrowState == QStyle::State_Sunken) {-
885 option->activeSubControls = QStyle::SC_ComboBoxArrow;-
886 option->state |= d->arrowState;-
887 } else {-
888 option->activeSubControls = d->hoverControl;-
889 }-
890 if (d->currentIndex.isValid()) {-
891 option->currentText = currentText();-
892 option->currentIcon = d->itemIcon(d->currentIndex);-
893 }-
894 option->iconSize = iconSize();-
895 if (d->container && d->container->isVisible())-
896 option->state |= QStyle::State_On;-
897}-
898-
899void QComboBoxPrivate::updateLineEditGeometry()-
900{-
901 if (!lineEdit)-
902 return;-
903-
904 QComboBox * const q = q_func();-
905 QStyleOptionComboBox opt;-
906 q->initStyleOption(&opt);-
907 QRect editRect = q->style()->subControlRect(QStyle::CC_ComboBox, &opt,-
908 QStyle::SC_ComboBoxEditField, q);-
909 if (!q->itemIcon(q->currentIndex()).isNull()) {-
910 QRect comboRect(editRect);-
911 editRect.setWidth(editRect.width() - q->iconSize().width() - 4);-
912 editRect = QStyle::alignedRect(q->layoutDirection(), Qt::AlignRight,-
913 editRect.size(), comboRect);-
914 }-
915 lineEdit->setGeometry(editRect);-
916}-
917-
918Qt::MatchFlags QComboBoxPrivate::matchFlags() const-
919{-
920-
921 Qt::MatchFlags flags = Qt::MatchFixedString;-
922-
923 if (!lineEdit->completer() || lineEdit->completer()->caseSensitivity() == Qt::CaseSensitive)-
924-
925 flags |= Qt::MatchCaseSensitive;-
926 return flags;-
927}-
928-
929-
930void QComboBoxPrivate::_q_editingFinished()-
931{-
932 QComboBox * const q = q_func();-
933 if (lineEdit && !lineEdit->text().isEmpty() && itemText(currentIndex) != lineEdit->text()) {-
934 const int index = q_func()->findText(lineEdit->text(), matchFlags());-
935 if (index != -1) {-
936 q->setCurrentIndex(index);-
937 emitActivated(currentIndex);-
938 }-
939 }-
940-
941}-
942-
943void QComboBoxPrivate::_q_returnPressed()-
944{-
945 QComboBox * const q = q_func();-
946-
947-
948-
949-
950-
951 if (insertPolicy == QComboBox::NoInsert)-
952 return;-
953-
954 if (lineEdit && !lineEdit->text().isEmpty()) {-
955 if (q->count() >= maxCount && !(this->insertPolicy == QComboBox::InsertAtCurrent))-
956 return;-
957 lineEdit->deselect();-
958 lineEdit->end(false);-
959 QString text = lineEdit->text();-
960-
961 int index = -1;-
962 if (!duplicatesEnabled) {-
963 index = q->findText(text, matchFlags());-
964 if (index != -1) {-
965 q->setCurrentIndex(index);-
966 emitActivated(currentIndex);-
967 return;-
968 }-
969 }-
970 switch (insertPolicy) {-
971 case QComboBox::InsertAtTop:-
972 index = 0;-
973 break;-
974 case QComboBox::InsertAtBottom:-
975 index = q->count();-
976 break;-
977 case QComboBox::InsertAtCurrent:-
978 case QComboBox::InsertAfterCurrent:-
979 case QComboBox::InsertBeforeCurrent:-
980 if (!q->count() || !currentIndex.isValid())-
981 index = 0;-
982 else if (insertPolicy == QComboBox::InsertAtCurrent)-
983 q->setItemText(q->currentIndex(), text);-
984 else if (insertPolicy == QComboBox::InsertAfterCurrent)-
985 index = q->currentIndex() + 1;-
986 else if (insertPolicy == QComboBox::InsertBeforeCurrent)-
987 index = q->currentIndex();-
988 break;-
989 case QComboBox::InsertAlphabetically:-
990 index = 0;-
991 for (int i=0; i< q->count(); i++, index++ ) {-
992 if (text.toLower() < q->itemText(i).toLower())-
993 break;-
994 }-
995 break;-
996 default:-
997 break;-
998 }-
999 if (index >= 0) {-
1000 q->insertItem(index, text);-
1001 q->setCurrentIndex(index);-
1002 emitActivated(currentIndex);-
1003 }-
1004 }-
1005}-
1006-
1007void QComboBoxPrivate::_q_itemSelected(const QModelIndex &item)-
1008{-
1009 QComboBox * const q = q_func();-
1010 if (item != currentIndex) {-
1011 setCurrentIndex(item);-
1012 } else if (lineEdit) {-
1013 lineEdit->selectAll();-
1014 lineEdit->setText(q->itemText(currentIndex.row()));-
1015 }-
1016 emitActivated(currentIndex);-
1017}-
1018-
1019void QComboBoxPrivate::emitActivated(const QModelIndex &index)-
1020{-
1021 QComboBox * const q = q_func();-
1022 if (!index.isValid())-
1023 return;-
1024 QString text(itemText(index));-
1025 q->activated(index.row());-
1026 q->activated(text);-
1027}-
1028-
1029void QComboBoxPrivate::_q_emitHighlighted(const QModelIndex &index)-
1030{-
1031 QComboBox * const q = q_func();-
1032 if (!index.isValid())-
1033 return;-
1034 QString text(itemText(index));-
1035 q->highlighted(index.row());-
1036 q->highlighted(text);-
1037}-
1038-
1039void QComboBoxPrivate::_q_emitCurrentIndexChanged(const QModelIndex &index)-
1040{-
1041 QComboBox * const q = q_func();-
1042 const QString text = itemText(index);-
1043 q->currentIndexChanged(index.row());-
1044 q->currentIndexChanged(text);-
1045-
1046 if (!lineEdit)-
1047 q->currentTextChanged(text);-
1048-
1049 QAccessibleValueChangeEvent event(q, text);-
1050 QAccessible::updateAccessibility(&event);-
1051-
1052}-
1053-
1054QString QComboBoxPrivate::itemText(const QModelIndex &index) const-
1055{-
1056 return index.isValid() ? model->data(index, itemRole()).toString() : QString();-
1057}-
1058-
1059int QComboBoxPrivate::itemRole() const-
1060{-
1061 return q_func()->isEditable() ? Qt::EditRole : Qt::DisplayRole;-
1062}-
1063-
1064-
1065-
1066-
1067QComboBox::~QComboBox()-
1068{-
1069-
1070 QComboBoxPrivate * const d = d_func();-
1071-
1072 if (true) {-
1073 disconnect(d->model, qFlagLocation("2""destroyed()" "\0" __FILE__ ":" "1338""1344"),-
1074 this, qFlagLocation("1""_q_modelDestroyed()" "\0" __FILE__ ":" "1339""1345"));-
1075 } else {
dead code: { ; }
-
1076 ;
dead code: { ; }
-
1077 }
dead code: { ; }
-
1078}-
1079int QComboBox::maxVisibleItems() const-
1080{-
1081 const QComboBoxPrivate * const d = d_func();-
1082 return d->maxVisibleItems;-
1083}-
1084-
1085void QComboBox::setMaxVisibleItems(int maxItems)-
1086{-
1087 QComboBoxPrivate * const d = d_func();-
1088 if (__builtin_expect(!!(
__builtin_expe...s < 0), false)Description
TRUEnever evaluated
FALSEnever evaluated
maxItems < 0)), false)
__builtin_expe...s < 0), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1089 QMessageLogger(__FILE__, 13641370, __PRETTY_FUNCTION__).warning("QComboBox::setMaxVisibleItems: "-
1090 "Invalid max visible items (%d) must be >= 0", maxItems);-
1091 return;
never executed: return;
0
1092 }-
1093 d->maxVisibleItems = maxItems;-
1094}
never executed: end of block
0
1095-
1096-
1097-
1098-
1099-
1100-
1101-
1102int QComboBox::count() const-
1103{-
1104 const QComboBoxPrivate * const d = d_func();-
1105 return d->model->rowCount(d->root);-
1106}-
1107void QComboBox::setMaxCount(int max)-
1108{-
1109 QComboBoxPrivate * const d = d_func();-
1110 if (__builtin_expect(!!(
__builtin_expe...x < 0), false)Description
TRUEnever evaluated
FALSEnever evaluated
max < 0)), false)
__builtin_expe...x < 0), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1111 QMessageLogger(__FILE__, 13991405, __PRETTY_FUNCTION__).warning("QComboBox::setMaxCount: Invalid count (%d) must be >= 0", max);-
1112 return;
never executed: return;
0
1113 }-
1114-
1115 const int rowCount = count();-
1116 if (rowCount >
rowCount > maxDescription
TRUEnever evaluated
FALSEnever evaluated
max< count())
rowCount > maxDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1117 d->model->removeRows(max, count()rowCount - max, d->root);
never executed: d->model->removeRows(max, rowCount - max, d->root);
0
1118-
1119 d->maxCount = max;-
1120}
never executed: end of block
0
1121-
1122int QComboBox::maxCount() const-
1123{-
1124 const QComboBoxPrivate * const d = d_func();-
1125 return d->maxCount;-
1126}-
1127bool QComboBox::autoCompletion() const-
1128{-
1129 const QComboBoxPrivate * const d = d_func();-
1130 return d->autoCompletion;-
1131}-
1132-
1133-
1134-
1135-
1136-
1137-
1138void QComboBox::setAutoCompletion(bool enable)-
1139{-
1140 QComboBoxPrivate * const d = d_func();-
1141-
1142-
1143-
1144-
1145-
1146-
1147 d->autoCompletion = enable;-
1148 if (!d->lineEdit
!d->lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1149 return;
never executed: return;
0
1150 if (enable
enableDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1151 if (d->lineEdit->completer()
d->lineEdit->completer()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1152 return;
never executed: return;
0
1153 d->completer = new QCompleter(d->model, d->lineEdit);-
1154 connect(d->completer, qFlagLocation("2""activated(QModelIndex)" "\0" __FILE__ ":" "1462""1469"), this, qFlagLocation("1""_q_completerActivated(QModelIndex)" "\0" __FILE__ ":" "1462""1469"));-
1155 d->completer->setCaseSensitivity(d->autoCompletionCaseSensitivity);-
1156 d->completer->setCompletionMode(QCompleter::InlineCompletion);-
1157 d->completer->setCompletionColumn(d->modelColumn);-
1158 d->lineEdit->setCompleter(d->completer);-
1159 d->completer->setWidget(this);-
1160 }
never executed: end of block
else {
0
1161 d->lineEdit->setCompleter(0);-
1162 }
never executed: end of block
0
1163}-
1164Qt::CaseSensitivity QComboBox::autoCompletionCaseSensitivity() const-
1165{-
1166 const QComboBoxPrivate * const d = d_func();-
1167 return d->autoCompletionCaseSensitivity;-
1168}-
1169-
1170-
1171-
1172-
1173-
1174-
1175void QComboBox::setAutoCompletionCaseSensitivity(Qt::CaseSensitivity sensitivity)-
1176{-
1177 QComboBoxPrivate * const d = d_func();-
1178 d->autoCompletionCaseSensitivity = sensitivity;-
1179 if (d->lineEdit && d->lineEdit->completer())-
1180 d->lineEdit->completer()->setCaseSensitivity(sensitivity);-
1181}-
1182bool QComboBox::duplicatesEnabled() const-
1183{-
1184 const QComboBoxPrivate * const d = d_func();-
1185 return d->duplicatesEnabled;-
1186}-
1187-
1188void QComboBox::setDuplicatesEnabled(bool enable)-
1189{-
1190 QComboBoxPrivate * const d = d_func();-
1191 d->duplicatesEnabled = enable;-
1192}-
1193int QComboBox::findData(const QVariant &data, int role, Qt::MatchFlags flags) const-
1194{-
1195 const QComboBoxPrivate * const d = d_func();-
1196 QModelIndexList result;QModelIndex start = d->model->index(0, d->modelColumn, d->root);-
1197 const QModelIndexList result = d->model->match(start, role, data, 1, flags);-
1198 if (result.isEmpty()
result.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1199 return
never executed: return -1;
-1;
never executed: return -1;
0
1200 return
never executed: return result.first().row();
result.first().row();
never executed: return result.first().row();
0
1201}-
1202QComboBox::InsertPolicy QComboBox::insertPolicy() const-
1203{-
1204 const QComboBoxPrivate * const d = d_func();-
1205 return d->insertPolicy;-
1206}-
1207-
1208void QComboBox::setInsertPolicy(InsertPolicy policy)-
1209{-
1210 QComboBoxPrivate * const d = d_func();-
1211 d->insertPolicy = policy;-
1212}-
1213QComboBox::SizeAdjustPolicy QComboBox::sizeAdjustPolicy() const-
1214{-
1215 const QComboBoxPrivate * const d = d_func();-
1216 return d->sizeAdjustPolicy;-
1217}-
1218-
1219void QComboBox::setSizeAdjustPolicy(QComboBox::SizeAdjustPolicy policy)-
1220{-
1221 QComboBoxPrivate * const d = d_func();-
1222 if (policy == d->sizeAdjustPolicy)-
1223 return;-
1224-
1225 d->sizeAdjustPolicy = policy;-
1226 d->sizeHint = QSize();-
1227 d->adjustComboBoxSize();-
1228 updateGeometry();-
1229}-
1230int QComboBox::minimumContentsLength() const-
1231{-
1232 const QComboBoxPrivate * const d = d_func();-
1233 return d->minimumContentsLength;-
1234}-
1235-
1236void QComboBox::setMinimumContentsLength(int characters)-
1237{-
1238 QComboBoxPrivate * const d = d_func();-
1239 if (characters == d->minimumContentsLength || characters < 0)-
1240 return;-
1241-
1242 d->minimumContentsLength = characters;-
1243-
1244 if (d->sizeAdjustPolicy == AdjustToContents-
1245 || d->sizeAdjustPolicy == AdjustToMinimumContentsLength-
1246 || d->sizeAdjustPolicy == AdjustToMinimumContentsLengthWithIcon) {-
1247 d->sizeHint = QSize();-
1248 d->adjustComboBoxSize();-
1249 updateGeometry();-
1250 }-
1251}-
1252QSize QComboBox::iconSize() const-
1253{-
1254 const QComboBoxPrivate * const d = d_func();-
1255 if (d->iconSize.isValid())-
1256 return d->iconSize;-
1257-
1258 int iconWidth = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this);-
1259 return QSize(iconWidth, iconWidth);-
1260}-
1261-
1262void QComboBox::setIconSize(const QSize &size)-
1263{-
1264 QComboBoxPrivate * const d = d_func();-
1265 if (size == d->iconSize)-
1266 return;-
1267-
1268 view()->setIconSize(size);-
1269 d->iconSize = size;-
1270 d->sizeHint = QSize();-
1271 updateGeometry();-
1272}-
1273bool QComboBox::isEditable() const-
1274{-
1275 const QComboBoxPrivate * const d = d_func();-
1276 return d->lineEdit != 0;-
1277}-
1278void QComboBoxPrivate::updateDelegate(bool force)-
1279{-
1280 QComboBox * const q = q_func();-
1281 QStyleOptionComboBox opt;-
1282 q->initStyleOption(&opt);-
1283 if (q->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, q)) {-
1284 if (force || qobject_cast<QComboBoxDelegate *>(q->itemDelegate()))-
1285 q->setItemDelegate(new QComboMenuDelegate(q->view(), q));-
1286 } else {-
1287 if (force || qobject_cast<QComboMenuDelegate *>(q->itemDelegate()))-
1288 q->setItemDelegate(new QComboBoxDelegate(q->view(), q));-
1289 }-
1290}-
1291-
1292QIcon QComboBoxPrivate::itemIcon(const QModelIndex &index) const-
1293{-
1294 QVariant decoration = model->data(index, Qt::DecorationRole);-
1295 if (decoration.type() == QVariant::Pixmap)-
1296 return QIcon(qvariant_cast<QPixmap>(decoration));-
1297 else-
1298 return qvariant_cast<QIcon>(decoration);-
1299}-
1300-
1301void QComboBox::setEditable(bool editable)-
1302{-
1303 QComboBoxPrivate * const d = d_func();-
1304 if (isEditable() == editable)-
1305 return;-
1306-
1307 QStyleOptionComboBox opt;-
1308 initStyleOption(&opt);-
1309 if (editable) {-
1310 if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) {-
1311 d->viewContainer()->updateScrollers();-
1312 view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);-
1313 }-
1314 QLineEdit *le = new QLineEdit(this);-
1315 setLineEdit(le);-
1316 } else {-
1317 if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) {-
1318 d->viewContainer()->updateScrollers();-
1319 view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);-
1320 }-
1321 setAttribute(Qt::WA_InputMethodEnabled, false);-
1322 d->lineEdit->hide();-
1323 d->lineEdit->deleteLater();-
1324 d->lineEdit = 0;-
1325 }-
1326-
1327 d->updateDelegate();-
1328 d->updateFocusPolicy();-
1329-
1330 d->viewContainer()->updateTopBottomMargin();-
1331 if (!testAttribute(Qt::WA_Resized))-
1332 adjustSize();-
1333}-
1334-
1335-
1336-
1337-
1338-
1339-
1340void QComboBox::setLineEdit(QLineEdit *edit)-
1341{-
1342 QComboBoxPrivate * const d = d_func();-
1343 if (!(__builtin_expect(!!(!
__builtin_expe...!edit), false)Description
TRUEnever evaluated
FALSEnever evaluated
edit)), false)
__builtin_expe...!edit), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1344 QMessageLogger(__FILE__, 17651771, __PRETTY_FUNCTION__).warning("QComboBox::setLineEdit: cannot set a 0 line edit");-
1345 return;
never executed: return;
0
1346 }-
1347-
1348 if (edit == d->lineEdit
edit == d->lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1349 return;
never executed: return;
0
1350-
1351 edit->setText(currentText());-
1352 delete d->lineEdit;-
1353-
1354 d->lineEdit = edit;-
1355-
1356 qt_widget_private(d->lineEdit)->inheritsInputMethodHints = 1;-
1357-
1358 if (d->lineEdit->parent() != this
d->lineEdit->parent() != thisDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1359 d->lineEdit->setParent(this);
never executed: d->lineEdit->setParent(this);
0
1360 connect(d->lineEdit, qFlagLocation("2""returnPressed()" "\0" __FILE__ ":" "1779""1787"), this, qFlagLocation("1""_q_returnPressed()" "\0" __FILE__ ":" "1779""1787"));-
1361 connect(d->lineEdit, qFlagLocation("2""editingFinished()" "\0" __FILE__ ":" "1780""1788"), this, qFlagLocation("1""_q_editingFinished()" "\0" __FILE__ ":" "1780""1788"));-
1362 connect(d->lineEdit, qFlagLocation("2""textChanged(QString)" "\0" __FILE__ ":" "1781""1789"), this, qFlagLocation("2""editTextChanged(QString)" "\0" __FILE__ ":" "1781""1789"));-
1363 connect(d->lineEdit, qFlagLocation("2""textChanged(QString)" "\0" __FILE__ ":" "1782""1790"), this, qFlagLocation("2""currentTextChanged(QString)" "\0" __FILE__ ":" "1782""1790"));-
1364 connect(d->lineEdit, qFlagLocation("2""cursorPositionChanged(int,int)" "\0" __FILE__ ":" "1783""1791"), this, qFlagLocation("1""updateMicroFocus()" "\0" __FILE__ ":" "1783""1791"));-
1365 connect(d->lineEdit, qFlagLocation("2""selectionChanged()" "\0" __FILE__ ":" "1784""1792"), this, qFlagLocation("1""updateMicroFocus()" "\0" __FILE__ ":" "1784""1792"));-
1366 d->lineEdit->setFrame(false);-
1367 d->lineEdit->setContextMenuPolicy(Qt::NoContextMenu);-
1368 d->updateFocusPolicy();-
1369 d->lineEdit->setFocusProxy(this);-
1370 d->lineEdit->setAttribute(Qt::WA_MacShowFocusRect, false);-
1371-
1372 setAutoCompletion(d->autoCompletion);-
1373 setAttribute(Qt::WA_InputMethodEnabled);-
1374 d->updateLayoutDirection();-
1375 d->updateLineEditGeometry();-
1376 if (isVisible()
isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1377 d->lineEdit->show();
never executed: d->lineEdit->show();
0
1378-
1379 update();-
1380}
never executed: end of block
0
1381-
1382-
1383-
1384-
1385-
1386-
1387-
1388QLineEdit *QComboBox::lineEdit() const-
1389{-
1390 const QComboBoxPrivate * const d = d_func();-
1391 return d->lineEdit;-
1392}-
1393void QComboBox::setValidator(const QValidator *v)-
1394{-
1395 QComboBoxPrivate * const d = d_func();-
1396 if (d->lineEdit)-
1397 d->lineEdit->setValidator(v);-
1398}-
1399-
1400-
1401-
1402-
1403-
1404-
1405-
1406const QValidator *QComboBox::validator() const-
1407{-
1408 const QComboBoxPrivate * const d = d_func();-
1409 return d->lineEdit ? d->lineEdit->validator() : 0;-
1410}-
1411void QComboBox::setCompleter(QCompleter *c)-
1412{-
1413 QComboBoxPrivate * const d = d_func();-
1414 if (!d->lineEdit)-
1415 return;-
1416 d->lineEdit->setCompleter(c);-
1417 if (c) {-
1418 connect(c, qFlagLocation("2""activated(QModelIndex)" "\0" __FILE__ ":" "1880""1888"), this, qFlagLocation("1""_q_completerActivated(QModelIndex)" "\0" __FILE__ ":" "1880""1888"));-
1419 c->setWidget(this);-
1420 }-
1421}-
1422QCompleter *QComboBox::completer() const-
1423{-
1424 const QComboBoxPrivate * const d = d_func();-
1425 return d->lineEdit ? d->lineEdit->completer() : 0;-
1426}-
1427QAbstractItemDelegate *QComboBox::itemDelegate() const-
1428{-
1429 return view()->itemDelegate();-
1430}-
1431void QComboBox::setItemDelegate(QAbstractItemDelegate *delegate)-
1432{-
1433 if (!(__builtin_expect(!!(!
__builtin_expe...egate), false)Description
TRUEnever evaluated
FALSEnever evaluated
delegate)), false)
__builtin_expe...egate), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1434 QMessageLogger(__FILE__, 19261934, __PRETTY_FUNCTION__).warning("QComboBox::setItemDelegate: cannot set a 0 delegate");-
1435 return;
never executed: return;
0
1436 }-
1437 delete view()->itemDelegate();-
1438 view()->setItemDelegate(delegate);-
1439}
never executed: end of block
0
1440-
1441-
1442-
1443-
1444-
1445QAbstractItemModel *QComboBox::model() const-
1446{-
1447 const QComboBoxPrivate * const d = d_func();-
1448 if (d->model == QAbstractItemModelPrivate::staticEmptyModel()) {-
1449 QComboBox *that = const_cast<QComboBox*>(this);-
1450 that->setModel(new QStandardItemModel(0, 1, that));-
1451 }-
1452 return d->model;-
1453}-
1454-
1455-
1456-
1457-
1458-
1459-
1460-
1461void QComboBox::setModel(QAbstractItemModel *model)-
1462{-
1463 QComboBoxPrivate * const d = d_func();-
1464-
1465 if (!(__builtin_expect(!!(!
__builtin_expe...model), false)Description
TRUEnever evaluated
FALSEnever evaluated
model)), false)
__builtin_expe...model), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1466 QMessageLogger(__FILE__, 19581966, __PRETTY_FUNCTION__).warning("QComboBox::setModel: cannot set a 0 model");-
1467 return;
never executed: return;
0
1468 }-
1469-
1470 if (model == d->model
model == d->modelDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1471 return;
never executed: return;
0
1472-
1473-
1474 if (d->lineEdit
d->lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
&& d->lineEdit->completer()
d->lineEdit->completer()Description
TRUEnever evaluated
FALSEnever evaluated
0
1475 && d->lineEdit->completer() == d->completer
d->lineEdit->c...= d->completerDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1476 d->lineEdit->completer()->setModel(model);
never executed: d->lineEdit->completer()->setModel(model);
0
1477-
1478 if (d->model
d->modelDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1479 disconnect(d->model, qFlagLocation("2""dataChanged(QModelIndex,QModelIndex)" "\0" __FILE__ ":" "1971""1979"),-
1480 this, qFlagLocation("1""_q_dataChanged(QModelIndex,QModelIndex)" "\0" __FILE__ ":" "1972""1980"));-
1481 disconnect(d->model, qFlagLocation("2""rowsAboutToBeInserted(QModelIndex,int,int)" "\0" __FILE__ ":" "1973""1981"),-
1482 this, qFlagLocation("1""_q_updateIndexBeforeChange()" "\0" __FILE__ ":" "1974""1982"));-
1483 disconnect(d->model, qFlagLocation("2""rowsInserted(QModelIndex,int,int)" "\0" __FILE__ ":" "1975""1983"),-
1484 this, qFlagLocation("1""_q_rowsInserted(QModelIndex,int,int)" "\0" __FILE__ ":" "1976""1984"));-
1485 disconnect(d->model, qFlagLocation("2""rowsAboutToBeRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "1977""1985"),-
1486 this, qFlagLocation("1""_q_updateIndexBeforeChange()" "\0" __FILE__ ":" "1978""1986"));-
1487 disconnect(d->model, qFlagLocation("2""rowsRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "1979""1987"),-
1488 this, qFlagLocation("1""_q_rowsRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "1980""1988"));-
1489 disconnect(d->model, qFlagLocation("2""destroyed()" "\0" __FILE__ ":" "1981""1989"),-
1490 this, qFlagLocation("1""_q_modelDestroyed()" "\0" __FILE__ ":" "1982""1990"));-
1491 disconnect(d->model, qFlagLocation("2""modelAboutToBeReset()" "\0" __FILE__ ":" "1983""1991"),-
1492 this, qFlagLocation("1""_q_updateIndexBeforeChange()" "\0" __FILE__ ":" "1984""1992"));-
1493 disconnect(d->model, qFlagLocation("2""modelReset()" "\0" __FILE__ ":" "1985""1993"),-
1494 this, qFlagLocation("1""_q_modelReset()" "\0" __FILE__ ":" "1986""1994"));-
1495 if (d->model->QObject::parent() == this
d->model->QObj...rent() == thisDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1496 delete d->model;
never executed: delete d->model;
0
1497 }
never executed: end of block
0
1498-
1499 d->model = model;-
1500-
1501 connect(model, qFlagLocation("2""dataChanged(QModelIndex,QModelIndex)" "\0" __FILE__ ":" "1993""2001"),-
1502 this, qFlagLocation("1""_q_dataChanged(QModelIndex,QModelIndex)" "\0" __FILE__ ":" "1994""2002"));-
1503 connect(model, qFlagLocation("2""rowsAboutToBeInserted(QModelIndex,int,int)" "\0" __FILE__ ":" "1995""2003"),-
1504 this, qFlagLocation("1""_q_updateIndexBeforeChange()" "\0" __FILE__ ":" "1996""2004"));-
1505 connect(model, qFlagLocation("2""rowsInserted(QModelIndex,int,int)" "\0" __FILE__ ":" "1997""2005"),-
1506 this, qFlagLocation("1""_q_rowsInserted(QModelIndex,int,int)" "\0" __FILE__ ":" "1998""2006"));-
1507 connect(model, qFlagLocation("2""rowsAboutToBeRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "1999""2007"),-
1508 this, qFlagLocation("1""_q_updateIndexBeforeChange()" "\0" __FILE__ ":" "2000""2008"));-
1509 connect(model, qFlagLocation("2""rowsRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "2001""2009"),-
1510 this, qFlagLocation("1""_q_rowsRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "2002""2010"));-
1511 connect(model, qFlagLocation("2""destroyed()" "\0" __FILE__ ":" "2003""2011"),-
1512 this, qFlagLocation("1""_q_modelDestroyed()" "\0" __FILE__ ":" "2004""2012"));-
1513 connect(model, qFlagLocation("2""modelAboutToBeReset()" "\0" __FILE__ ":" "2005""2013"),-
1514 this, qFlagLocation("1""_q_updateIndexBeforeChange()" "\0" __FILE__ ":" "2006""2014"));-
1515 connect(model, qFlagLocation("2""modelReset()" "\0" __FILE__ ":" "2007""2015"),-
1516 this, qFlagLocation("1""_q_modelReset()" "\0" __FILE__ ":" "2008""2016"));-
1517-
1518 if (d->container
d->containerDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1519 d->container->itemView()->setModel(model);-
1520 connect(d->container->itemView()->selectionModel(),-
1521 qFlagLocation("2""currentChanged(QModelIndex,QModelIndex)" "\0" __FILE__ ":" "2013""2021"),-
1522 this, qFlagLocation("1""_q_emitHighlighted(QModelIndex)" "\0" __FILE__ ":" "2014""2022"), Qt::UniqueConnection);-
1523 }
never executed: end of block
0
1524-
1525 setRootModelIndex(QModelIndex());-
1526-
1527 bool currentReset = false;-
1528-
1529 const int rowCount = count();-
1530 for (int pos=0; pos < rowCount
pos < rowCountDescription
TRUEnever evaluated
FALSEnever evaluated
; pos++) {
0
1531 if (d->model->index(pos, d->modelColumn, d->root).flags() & Qt::ItemIsEnabled
d->model->inde...:ItemIsEnabledDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1532 setCurrentIndex(pos);-
1533 currentReset = true;-
1534 break;
never executed: break;
0
1535 }-
1536 }
never executed: end of block
0
1537-
1538 if (!currentReset
!currentResetDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1539 setCurrentIndex(-1);
never executed: setCurrentIndex(-1);
0
1540-
1541 d->modelChanged();-
1542}
never executed: end of block
0
1543-
1544-
1545-
1546-
1547-
1548-
1549-
1550QModelIndex QComboBox::rootModelIndex() const-
1551{-
1552 const QComboBoxPrivate * const d = d_func();-
1553 return QModelIndex(d->root);-
1554}-
1555-
1556-
1557-
1558-
1559-
1560-
1561void QComboBox::setRootModelIndex(const QModelIndex &index)-
1562{-
1563 QComboBoxPrivate * const d = d_func();-
1564 if (d->root == index)-
1565 return;-
1566 d->root = QPersistentModelIndex(index);-
1567 view()->setRootIndex(index);-
1568 update();-
1569}-
1570int QComboBox::currentIndex() const-
1571{-
1572 const QComboBoxPrivate * const d = d_func();-
1573 return d->currentIndex.row();-
1574}-
1575-
1576void QComboBox::setCurrentIndex(int index)-
1577{-
1578 QComboBoxPrivate * const d = d_func();-
1579 QModelIndex mi = d->model->index(index, d->modelColumn, d->root);-
1580 d->setCurrentIndex(mi);-
1581}-
1582-
1583void QComboBox::setCurrentText(const QString &text)-
1584{-
1585 if (isEditable()) {-
1586 setEditText(text);-
1587 } else {-
1588 const int i = findText(text);-
1589 if (i > -1)-
1590 setCurrentIndex(i);-
1591 }-
1592}-
1593-
1594void QComboBoxPrivate::setCurrentIndex(const QModelIndex &mi)-
1595{-
1596 QComboBox * const q = q_func();-
1597-
1598 QModelIndex normalized = mi.sibling(mi.row(), modelColumn);-
1599 if (!normalized.isValid())-
1600 normalized = mi;-
1601-
1602 bool indexChanged = (normalized != currentIndex);-
1603 if (indexChanged)-
1604 currentIndex = QPersistentModelIndex(normalized);-
1605 if (lineEdit) {-
1606 const QString newText = itemText(normalized);-
1607 if (lineEdit->text() != newText) {-
1608 lineEdit->setText(newText);-
1609-
1610 if (lineEdit && lineEdit->completer())-
1611 lineEdit->completer()->setCompletionPrefix(newText);-
1612-
1613 }-
1614 updateLineEditGeometry();-
1615 }-
1616 if (indexChanged) {-
1617 q->update();-
1618 _q_emitCurrentIndexChanged(currentIndex);-
1619 }-
1620}-
1621QString QComboBox::currentText() const-
1622{-
1623 const QComboBoxPrivate * const d = d_func();-
1624 if (d->lineEdit)-
1625 return d->lineEdit->text();-
1626 else if (d->currentIndex.isValid())-
1627 return d->itemText(d->currentIndex);-
1628 else-
1629 return QString();-
1630}-
1631QVariant QComboBox::currentData(int role) const-
1632{-
1633 const QComboBoxPrivate * const d = d_func();-
1634 return d->currentIndex.data(role);-
1635}-
1636-
1637-
1638-
1639-
1640QString QComboBox::itemText(int index) const-
1641{-
1642 const QComboBoxPrivate * const d = d_func();-
1643 QModelIndex mi = d->model->index(index, d->modelColumn, d->root);-
1644 return d->itemText(mi);-
1645}-
1646-
1647-
1648-
1649-
1650QIcon QComboBox::itemIcon(int index) const-
1651{-
1652 const QComboBoxPrivate * const d = d_func();-
1653 QModelIndex mi = d->model->index(index, d->modelColumn, d->root);-
1654 return d->itemIcon(mi);-
1655}-
1656-
1657-
1658-
1659-
1660-
1661QVariant QComboBox::itemData(int index, int role) const-
1662{-
1663 const QComboBoxPrivate * const d = d_func();-
1664 QModelIndex mi = d->model->index(index, d->modelColumn, d->root);-
1665 return d->model->data(mi, role);-
1666}-
1667void QComboBox::insertItem(int index, const QIcon &icon, const QString &text, const QVariant &userData)-
1668{-
1669 QComboBoxPrivate * const d = d_func();-
1670 int itemCount = count();-
1671 index = qBound(0, index, itemCount);-
1672 if (index >= d->maxCount)-
1673 return;-
1674-
1675-
1676-
1677 if (QStandardItemModel *m = qobject_cast<QStandardItemModel*>(d->model)) {-
1678 QStandardItem *item = new QStandardItem(text);-
1679 if (!icon.isNull()) item->setData(icon, Qt::DecorationRole);-
1680 if (userData.isValid()) item->setData(userData, Qt::UserRole);-
1681 m->insertRow(index, item);-
1682 ++itemCount;-
1683 } else {-
1684 d->inserting = true;-
1685 if (d->model->insertRows(index, 1, d->root)) {-
1686 QModelIndex item = d->model->index(index, d->modelColumn, d->root);-
1687 if (icon.isNull() && !userData.isValid()) {-
1688 d->model->setData(item, text, Qt::EditRole);-
1689 } else {-
1690 QMap<int, QVariant> values;-
1691 if (!text.isNull()) values.insert(Qt::EditRole, text);-
1692 if (!icon.isNull()) values.insert(Qt::DecorationRole, icon);-
1693 if (userData.isValid()) values.insert(Qt::UserRole, userData);-
1694 if (!values.isEmpty()) d->model->setItemData(item, values);-
1695 }-
1696 d->inserting = false;-
1697 d->_q_rowsInserted(d->root, index, index);-
1698 ++itemCount;-
1699 } else {-
1700 d->inserting = false;-
1701 }-
1702 }-
1703-
1704 if (itemCount > d->maxCount)-
1705 d->model->removeRows(itemCount - 1, itemCount - d->maxCount, d->root);-
1706}-
1707void QComboBox::insertItems(int index, const QStringList &list)-
1708{-
1709 QComboBoxPrivate * const d = d_func();-
1710 if (list.isEmpty())-
1711 return;-
1712 index = qBound(0, index, count());-
1713 int insertCount = qMin(d->maxCount - index, list.count());-
1714 if (insertCount <= 0)-
1715 return;-
1716-
1717-
1718 if (QStandardItemModel *m = qobject_cast<QStandardItemModel*>(d->model)) {-
1719 QList<QStandardItem *> items;-
1720 items.reserve(insertCount);-
1721 QStandardItem *hiddenRoot = m->invisibleRootItem();-
1722 for (int i = 0; i < insertCount; ++i)-
1723 items.append(new QStandardItem(list.at(i)));-
1724 hiddenRoot->insertRows(index, items);-
1725 } else {-
1726 d->inserting = true;-
1727 if (d->model->insertRows(index, insertCount, d->root)) {-
1728 QModelIndex item;-
1729 for (int i = 0; i < insertCount; ++i) {-
1730 item = d->model->index(i+index, d->modelColumn, d->root);-
1731 d->model->setData(item, list.at(i), Qt::EditRole);-
1732 }-
1733 d->inserting = false;-
1734 d->_q_rowsInserted(d->root, index, index + insertCount - 1);-
1735 } else {-
1736 d->inserting = false;-
1737 }-
1738 }-
1739-
1740 int mc = count();-
1741 if (mc > d->maxCount)-
1742 d->model->removeRows(d->maxCount, mc - d->maxCount, d->root);-
1743}-
1744void QComboBox::insertSeparator(int index)-
1745{-
1746 QComboBoxPrivate * const d = d_func();-
1747 int itemCount = count();-
1748 index = qBound(0, index, itemCount);-
1749 if (index >= d->maxCount)-
1750 return;-
1751 insertItem(index, QIcon(), QString());-
1752 QComboBoxDelegate::setSeparator(d->model, d->model->index(index, 0, d->root));-
1753}-
1754-
1755-
1756-
1757-
1758-
1759-
1760-
1761void QComboBox::removeItem(int index)-
1762{-
1763 QComboBoxPrivate * const d = d_func();-
1764 if (index < 0 || index >= count())-
1765 return;-
1766 d->model->removeRows(index, 1, d->root);-
1767}-
1768-
1769-
1770-
1771-
1772void QComboBox::setItemText(int index, const QString &text)-
1773{-
1774 const QComboBoxPrivate * const d = d_func();-
1775 QModelIndex item = d->model->index(index, d->modelColumn, d->root);-
1776 if (item.isValid()) {-
1777 d->model->setData(item, text, Qt::EditRole);-
1778 }-
1779}-
1780-
1781-
1782-
1783-
1784void QComboBox::setItemIcon(int index, const QIcon &icon)-
1785{-
1786 const QComboBoxPrivate * const d = d_func();-
1787 QModelIndex item = d->model->index(index, d->modelColumn, d->root);-
1788 if (item.isValid()) {-
1789 d->model->setData(item, icon, Qt::DecorationRole);-
1790 }-
1791}-
1792-
1793-
1794-
1795-
1796-
1797void QComboBox::setItemData(int index, const QVariant &value, int role)-
1798{-
1799 const QComboBoxPrivate * const d = d_func();-
1800 QModelIndex item = d->model->index(index, d->modelColumn, d->root);-
1801 if (item.isValid()) {-
1802 d->model->setData(item, value, role);-
1803 }-
1804}-
1805-
1806-
1807-
1808-
1809QAbstractItemView *QComboBox::view() const-
1810{-
1811 const QComboBoxPrivate * const d = d_func();-
1812 return const_cast<QComboBoxPrivate*>(d)->viewContainer()->itemView();-
1813}-
1814void QComboBox::setView(QAbstractItemView *itemView)-
1815{-
1816 QComboBoxPrivate * const d = d_func();-
1817 if (!(__builtin_expect(!!(!
__builtin_expe...mView), false)Description
TRUEnever evaluated
FALSEnever evaluated
itemView)), false)
__builtin_expe...mView), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1818 QMessageLogger(__FILE__, 24042412, __PRETTY_FUNCTION__).warning("QComboBox::setView: cannot set a 0 view");-
1819 return;
never executed: return;
0
1820 }-
1821-
1822 if (itemView->model() != d->model
itemView->model() != d->modelDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1823 itemView->setModel(d->model);
never executed: itemView->setModel(d->model);
0
1824 d->viewContainer()->setItemView(itemView);-
1825}
never executed: end of block
0
1826-
1827-
1828-
1829-
1830QSize QComboBox::minimumSizeHint() const-
1831{-
1832 const QComboBoxPrivate * const d = d_func();-
1833 return d->recomputeSizeHint(d->minimumSizeHint);-
1834}-
1835QSize QComboBox::sizeHint() const-
1836{-
1837 const QComboBoxPrivate * const d = d_func();-
1838 return d->recomputeSizeHint(d->sizeHint);-
1839}-
1840void QComboBox::showPopup()-
1841{-
1842 QComboBoxPrivate * const d = d_func();-
1843 if (count() <= 0
count() <= 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1844 return;
never executed: return;
0
1845-
1846 QStyle * const style = this->style();-
1847 QStyleOptionComboBox opt;-
1848 initStyleOption(&opt);-
1849 const bool usePopup = style->styleHint(QStyle::SH_ComboBox_Popup, &opt, this);-
1850 view()->selectionModel()->setCurrentIndex(d->currentIndex,-
1851 QItemSelectionModel::ClearAndSelect);-
1852 QComboBoxPrivateContainer* container = d->viewContainer();-
1853 QRect listRect(style->subControlRect(QStyle::CC_ComboBox, &opt,-
1854 QStyle::SC_ComboBoxListBoxPopup, this));-
1855 QRect screen = d->popupGeometry(QApplication::desktop()->screenNumber(this));-
1856-
1857 QPoint below = mapToGlobal(listRect.bottomLeft());-
1858 int belowHeight = screen.bottom() - below.y();-
1859 QPoint above = mapToGlobal(listRect.topLeft());-
1860 int aboveHeight = above.y() - screen.y();-
1861 bool boundToScreen = !window()->testAttribute(Qt::WA_DontShowOnScreen);-
1862-
1863 {-
1864 int listHeight = 0;-
1865 int count = 0;-
1866 QStack<QModelIndex> toCheck;-
1867 toCheck.push(view()->rootIndex());-
1868-
1869 QTreeView *treeView = qobject_cast<QTreeView*>(view());-
1870 if (treeView
treeViewDescription
TRUEnever evaluated
FALSEnever evaluated
&& treeView->header()
treeView->header()Description
TRUEnever evaluated
FALSEnever evaluated
&& !treeView->header()->isHidden()
!treeView->hea...()->isHidden()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1871 listHeight += treeView->header()->height();
never executed: listHeight += treeView->header()->height();
0
1872-
1873 while (!toCheck.isEmpty()
!toCheck.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1874 QModelIndex parent = toCheck.pop();-
1875 for (int i = 0; i <, end = d->model->rowCount(parent); i < end
i < endDescription
TRUEnever evaluated
FALSEnever evaluated
;
++i) {
0
1876 QModelIndex idx = d->model->index(i, d->modelColumn, parent);-
1877 if (!idx.isValid()
!idx.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1878 continue;
never executed: continue;
0
1879 listHeight += view()->visualRect(idx).height();-
1880-
1881 if (d->model->hasChildren(idx)
d->model->hasChildren(idx)Description
TRUEnever evaluated
FALSEnever evaluated
&& treeView
treeViewDescription
TRUEnever evaluated
FALSEnever evaluated
&& treeView->isExpanded(idx)
treeView->isExpanded(idx)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1882 toCheck.push(idx);
never executed: toCheck.push(idx);
0
1883-
1884 ++count;-
1885 if (!usePopup
!usePopupDescription
TRUEnever evaluated
FALSEnever evaluated
&& count >= d->maxVisibleItems
count >= d->maxVisibleItemsDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1886 toCheck.clear();-
1887 break;
never executed: break;
0
1888 }-
1889 }
never executed: end of block
0
1890 }
never executed: end of block
0
1891 if (count > 1
count > 1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1892 listHeight += (count - 1) * container->spacing();
never executed: listHeight += (count - 1) * container->spacing();
0
1893 listRect.setHeight(listHeight);-
1894 }-
1895-
1896 {-
1897-
1898 int heightMargin = container->topMargin() + container->bottomMargin();-
1899-
1900-
1901 int marginTop, marginBottom;-
1902 container->getContentsMargins(0, &marginTop, 0, &marginBottom);-
1903 heightMargin += marginTop + marginBottom;-
1904-
1905-
1906 view()->getContentsMargins(0, &marginTop, 0, &marginBottom);-
1907 marginTop += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->top;-
1908 marginBottom += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->bottom;-
1909 heightMargin += marginTop + marginBottom;-
1910-
1911 listRect.setHeight(listRect.height() + heightMargin);-
1912 }-
1913-
1914-
1915 if (usePopup
usePopupDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1916 listRect.setHeight(listRect.height() + style->pixelMetric(QStyle::PM_MenuVMargin, &opt, this) * 2);
never executed: listRect.setHeight(listRect.height() + style->pixelMetric(QStyle::PM_MenuVMargin, &opt, this) * 2);
0
1917-
1918-
1919 if (usePopup
usePopupDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1920 const int diff = d->computeWidthHint() - width();-
1921 if (diff > 0
diff > 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1922 listRect.setWidth(listRect.width() + diff);
never executed: listRect.setWidth(listRect.width() + diff);
0
1923 }
never executed: end of block
0
1924-
1925-
1926 container->layout()->activate();-
1927-
1928 listRect.setSize( listRect.size().expandedTo(container->minimumSize())-
1929 .boundedTo(container->maximumSize()));-
1930-
1931-
1932 if (boundToScreen
boundToScreenDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1933 if (listRect.width() > screen.width()
listRect.width...screen.width()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1934 listRect.setWidth(screen.width());
never executed: listRect.setWidth(screen.width());
0
1935 if (mapToGlobal(listRect.bottomRight()).x() > screen.right()
mapToGlobal(li...screen.right()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1936 below.setX(screen.x() + screen.width() - listRect.width());-
1937 above.setX(screen.x() + screen.width() - listRect.width());-
1938 }
never executed: end of block
0
1939 if (mapToGlobal(listRect.topLeft()).x() < screen.x()
mapToGlobal(li...) < screen.x()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1940 below.setX(screen.x());-
1941 above.setX(screen.x());-
1942 }
never executed: end of block
0
1943 }
never executed: end of block
0
1944-
1945 if (usePopup
usePopupDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1946-
1947 listRect.moveLeft(above.x());-
1948-
1949-
1950-
1951 const QRect currentItemRect = view()->visualRect(view()->currentIndex());-
1952 const int offset = listRect.top() - currentItemRect.top();-
1953 listRect.moveTop(above.y() + offset - listRect.top());-
1954-
1955-
1956-
1957-
1958 const int height = !boundToScreen
!boundToScreenDescription
TRUEnever evaluated
FALSEnever evaluated
? listRect.height() : qMin(listRect.height(), screen.height());
0
1959 listRect.setHeight(height);-
1960-
1961 if (boundToScreen
boundToScreenDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1962 if (listRect.top() < screen.top()
listRect.top() < screen.top()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1963 listRect.moveTop(screen.top());
never executed: listRect.moveTop(screen.top());
0
1964 if (listRect.bottom() > screen.bottom()
listRect.botto...creen.bottom()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1965 listRect.moveBottom(screen.bottom());
never executed: listRect.moveBottom(screen.bottom());
0
1966 }
never executed: end of block
0
1967 }
never executed: end of block
else if (!boundToScreen
!boundToScreenDescription
TRUEnever evaluated
FALSEnever evaluated
|| listRect.height() <= belowHeight
listRect.heigh...<= belowHeightDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1968 listRect.moveTopLeft(below);-
1969 }
never executed: end of block
else if (listRect.height() <= aboveHeight
listRect.heigh...<= aboveHeightDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1970 listRect.moveBottomLeft(above);-
1971 }
never executed: end of block
else if (belowHeight >= aboveHeight
belowHeight >= aboveHeightDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1972 listRect.setHeight(belowHeight);-
1973 listRect.moveTopLeft(below);-
1974 }
never executed: end of block
else {
0
1975 listRect.setHeight(aboveHeight);-
1976 listRect.moveBottomLeft(above);-
1977 }
never executed: end of block
0
1978-
1979 if ((static_cast<
(static_cast<Q...::instance()))Description
TRUEnever evaluated
FALSEnever evaluated
QApplication *>(QCoreApplication::instance()))
(static_cast<Q...::instance()))Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1980 QGuiApplication::inputMethod()->reset();-
1981 }
never executed: end of block
0
1982-
1983 QScrollBar *sb = view()->horizontalScrollBar();-
1984 Qt::ScrollBarPolicy policy = view()->horizontalScrollBarPolicy();-
1985 bool needHorizontalScrollBar = (policy == Qt::ScrollBarAsNeeded
policy == Qt::...ollBarAsNeededDescription
TRUEnever evaluated
FALSEnever evaluated
|| policy == Qt::ScrollBarAlwaysOn
policy == Qt::...ollBarAlwaysOnDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1986 && sb->minimum() < sb->maximum()
sb->minimum() < sb->maximum()Description
TRUEnever evaluated
FALSEnever evaluated
;
0
1987 if (needHorizontalScrollBar
needHorizontalScrollBarDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1988 listRect.adjust(0, 0, 0, sb->height());-
1989 }
never executed: end of block
0
1990 container->setGeometry(listRect);-
1991-
1992-
1993 const bool updatesEnabled = container->updatesEnabled();-
1994-
1995-
1996-
1997 bool scrollDown = (listRect.topLeft() == below);-
1998 if (QApplication::isEffectEnabled(Qt::UI_AnimateCombo)
QApplication::..._AnimateCombo)Description
TRUEnever evaluated
FALSEnever evaluated
0
1999 && !style->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)
!style->styleH...p, &opt, this)Description
TRUEnever evaluated
FALSEnever evaluated
&& !window()->testAttribute(Qt::WA_DontShowOnScreen)
!window()->tes...tShowOnScreen)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
2000 qScrollEffect(container, scrollDown ? QEffects::DownScroll : QEffects::UpScroll, 150);
never executed: qScrollEffect(container, scrollDown ? QEffects::DownScroll : QEffects::UpScroll, 150);
0
2001 container->setUpdatesEnabled(false);-
2002-
2003-
2004 bool startTimer = !container->isVisible();-
2005 container->raise();-
2006 container->show();-
2007 container->updateScrollers();-
2008 view()->setFocus();-
2009-
2010 view()->scrollTo(view()->currentIndex(),-
2011 style->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)-
2012 ? QAbstractItemView::PositionAtCenter-
2013 : QAbstractItemView::EnsureVisible);-
2014-
2015-
2016 container->setUpdatesEnabled(updatesEnabled);-
2017-
2018-
2019 container->update();-
2020-
2021-
2022-
2023-
2024 if (startTimer
startTimerDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
2025 container->popupTimer.start();-
2026 container->maybeIgnoreMouseButtonRelease = true;-
2027 }
never executed: end of block
0
2028}
never executed: end of block
0
2029void QComboBox::hidePopup()-
2030{-
2031 QComboBoxPrivate * const d = d_func();-
2032 if (d->container && d->container->isVisible()) {-
2033-
2034 QSignalBlocker modelBlocker(d->model);-
2035 QSignalBlocker viewBlocker(d->container->itemView());-
2036 QSignalBlocker containerBlocker(d->container);-
2037-
2038 if (style()->styleHint(QStyle::SH_Menu_FlashTriggeredItem)) {-
2039 QItemSelectionModel *selectionModel = view() ? view()->selectionModel() : 0;-
2040 if (selectionModel && selectionModel->hasSelection()) {-
2041 QEventLoop eventLoop;-
2042 const QItemSelection selection = selectionModel->selection();-
2043-
2044-
2045 selectionModel->select(selection, QItemSelectionModel::Toggle);-
2046 QTimer::singleShot(60, &eventLoop, qFlagLocation("1""quit()" "\0" __FILE__ ":" "2788""2796"));-
2047 eventLoop.exec();-
2048-
2049-
2050 selectionModel->select(selection, QItemSelectionModel::Toggle);-
2051 QTimer::singleShot(20, &eventLoop, qFlagLocation("1""quit()" "\0" __FILE__ ":" "2793""2801"));-
2052 eventLoop.exec();-
2053 }-
2054 }-
2055-
2056-
2057 bool needFade = style()->styleHint(QStyle::SH_Menu_FadeOutOnHide);-
2058 bool didFade = false;-
2059 if (needFade) {-
2060 }-
2061 containerBlocker.unblock();-
2062 viewBlocker.unblock();-
2063 modelBlocker.unblock();-
2064-
2065 if (!didFade)-
2066-
2067-
2068 d->container->hide();-
2069 }-
2070-
2071-
2072-
2073-
2074 d->_q_resetButton();-
2075}-
2076-
2077-
2078-
2079-
2080-
2081-
2082-
2083void QComboBox::clear()-
2084{-
2085 QComboBoxPrivate * const d = d_func();-
2086 d->model->removeRows(0, d->model->rowCount(d->root), d->root);-
2087-
2088 QAccessibleValueChangeEvent event(this, QString());-
2089 QAccessible::updateAccessibility(&event);-
2090-
2091}-
2092-
2093-
2094-
2095-
2096void QComboBox::clearEditText()-
2097{-
2098 QComboBoxPrivate * const d = d_func();-
2099 if (d->lineEdit)-
2100 d->lineEdit->clear();-
2101-
2102 QAccessibleValueChangeEvent event(this, QString());-
2103 QAccessible::updateAccessibility(&event);-
2104-
2105}-
2106-
2107-
2108-
2109-
2110void QComboBox::setEditText(const QString &text)-
2111{-
2112 QComboBoxPrivate * const d = d_func();-
2113 if (d->lineEdit)-
2114 d->lineEdit->setText(text);-
2115-
2116 QAccessibleValueChangeEvent event(this, text);-
2117 QAccessible::updateAccessibility(&event);-
2118-
2119}-
2120-
2121-
2122-
2123-
2124void QComboBox::focusInEvent(QFocusEvent *e)-
2125{-
2126 QComboBoxPrivate * const d = d_func();-
2127 update();-
2128 if (d->lineEdit) {-
2129 d->lineEdit->event(e);-
2130-
2131 if (d->lineEdit->completer())-
2132 d->lineEdit->completer()->setWidget(this);-
2133-
2134 }-
2135}-
2136-
2137-
2138-
2139-
2140void QComboBox::focusOutEvent(QFocusEvent *e)-
2141{-
2142 QComboBoxPrivate * const d = d_func();-
2143 update();-
2144 if (d->lineEdit)-
2145 d->lineEdit->event(e);-
2146}-
2147-
2148-
2149void QComboBox::changeEvent(QEvent *e)-
2150{-
2151 QComboBoxPrivate * const d = d_func();-
2152 switch (e->type()) {-
2153 case QEvent::StyleChange:-
2154 d->updateDelegate();-
2155-
2156-
2157-
2158 d->sizeHint = QSize();-
2159 d->minimumSizeHint = QSize();-
2160 d->updateLayoutDirection();-
2161 if (d->lineEdit)-
2162 d->updateLineEditGeometry();-
2163 d->setLayoutItemMargins(QStyle::SE_ComboBoxLayoutItem);-
2164-
2165 if (e->type() == QEvent::MacSizeChange){-
2166 QPlatformTheme::Font f = QPlatformTheme::SystemFont;-
2167 if (testAttribute(Qt::WA_MacSmallSize))-
2168 f = QPlatformTheme::SmallFont;-
2169 else if (testAttribute(Qt::WA_MacMiniSize))-
2170 f = QPlatformTheme::MiniFont;-
2171 if (const QFont *platformFont = QApplicationPrivate::platformTheme()->font(f)) {-
2172 QFont f = font();-
2173 f.setPointSizeF(platformFont->pointSizeF());-
2174 setFont(f);-
2175 }-
2176 }-
2177-
2178 break;-
2179 case QEvent::EnabledChange:-
2180 if (!isEnabled())-
2181 hidePopup();-
2182 break;-
2183 case QEvent::PaletteChange: {-
2184 d->updateViewContainerPaletteAndOpacity();-
2185 break;-
2186 }-
2187 case QEvent::FontChange:-
2188 d->sizeHint = QSize();-
2189 d->viewContainer()->setFont(font());-
2190 if (d->lineEdit)-
2191 d->updateLineEditGeometry();-
2192 break;-
2193 default:-
2194 break;-
2195 }-
2196 QWidget::changeEvent(e);-
2197}-
2198-
2199-
2200-
2201-
2202void QComboBox::resizeEvent(QResizeEvent *)-
2203{-
2204 QComboBoxPrivate * const d = d_func();-
2205 d->updateLineEditGeometry();-
2206}-
2207-
2208-
2209-
2210-
2211void QComboBox::paintEvent(QPaintEvent *)-
2212{-
2213 QStylePainter painter(this);-
2214 painter.setPen(palette().color(QPalette::Text));-
2215-
2216-
2217 QStyleOptionComboBox opt;-
2218 initStyleOption(&opt);-
2219 painter.drawComplexControl(QStyle::CC_ComboBox, opt);-
2220-
2221-
2222 painter.drawControl(QStyle::CE_ComboBoxLabel, opt);-
2223}-
2224-
2225-
2226-
2227-
2228void QComboBox::showEvent(QShowEvent *e)-
2229{-
2230 QComboBoxPrivate * const d = d_func();-
2231 if (!d->shownOnce && d->sizeAdjustPolicy == QComboBox::AdjustToContentsOnFirstShow) {-
2232 d->sizeHint = QSize();-
2233 updateGeometry();-
2234 }-
2235 d->shownOnce = true;-
2236 QWidget::showEvent(e);-
2237}-
2238-
2239-
2240-
2241-
2242void QComboBox::hideEvent(QHideEvent *)-
2243{-
2244 hidePopup();-
2245}-
2246-
2247-
2248-
2249-
2250bool QComboBox::event(QEvent *event)-
2251{-
2252 QComboBoxPrivate * const d = d_func();-
2253 switch(event->type()) {-
2254 case QEvent::LayoutDirectionChange:-
2255 case QEvent::ApplicationLayoutDirectionChange:-
2256 d->updateLayoutDirection();-
2257 d->updateLineEditGeometry();-
2258 break;-
2259 case QEvent::HoverEnter:-
2260 case QEvent::HoverLeave:-
2261 case QEvent::HoverMove:-
2262 if (const QHoverEvent *he = static_cast<const QHoverEvent *>(event))-
2263 d->updateHoverControl(he->pos());-
2264 break;-
2265 case QEvent::ShortcutOverride:-
2266 if (d->lineEdit)-
2267 return d->lineEdit->event(event);-
2268 break;-
2269 default:-
2270 break;-
2271 }-
2272 return QWidget::event(event);-
2273}-
2274-
2275-
2276-
2277-
2278void QComboBox::mousePressEvent(QMouseEvent *e)-
2279{-
2280 QComboBoxPrivate * const d = d_func();-
2281 if (!QGuiApplication::styleHints()->setFocusOnTouchRelease())-
2282 d->showPopupFromMouseEvent(e);-
2283}-
2284-
2285void QComboBoxPrivate::showPopupFromMouseEvent(QMouseEvent *e)-
2286{-
2287 QComboBox * const q = q_func();-
2288 QStyleOptionComboBox opt;-
2289 q->initStyleOption(&opt);-
2290 QStyle::SubControl sc = q->style()->hitTestComplexControl(QStyle::CC_ComboBox, &opt, e->pos(), q);-
2291-
2292 if (e->button() == Qt::LeftButton-
2293 && !(sc == QStyle::SC_None && e->type() == QEvent::MouseButtonRelease)-
2294 && (sc == QStyle::SC_ComboBoxArrow || !q->isEditable())-
2295 && !viewContainer()->isVisible()) {-
2296 if (sc == QStyle::SC_ComboBoxArrow)-
2297 updateArrow(QStyle::State_Sunken);-
2298-
2299-
2300-
2301-
2302-
2303-
2304 viewContainer()->blockMouseReleaseTimer.start(QApplication::doubleClickInterval());-
2305 viewContainer()->initialClickPosition = q->mapToGlobal(e->pos());-
2306-
2307-
2308-
2309 q->showPopup();-
2310-
2311-
2312-
2313 if (viewContainer())-
2314 viewContainer()->maybeIgnoreMouseButtonRelease = false;-
2315 } else {-
2316-
2317-
2318-
2319-
2320-
2321-
2322 e->ignore();-
2323 }-
2324}-
2325-
2326-
2327-
2328-
2329void QComboBox::mouseReleaseEvent(QMouseEvent *e)-
2330{-
2331 QComboBoxPrivate * const d = d_func();-
2332 d->updateArrow(QStyle::State_None);-
2333 if (QGuiApplication::styleHints()->setFocusOnTouchRelease() && hasFocus())-
2334 d->showPopupFromMouseEvent(e);-
2335}-
2336-
2337-
2338-
2339-
2340void QComboBox::keyPressEvent(QKeyEvent *e)-
2341{-
2342 QComboBoxPrivate * const d = d_func();-
2343-
2344-
2345 if (d->lineEdit
d->lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
0
2346 && d->lineEdit->completer()
d->lineEdit->completer()Description
TRUEnever evaluated
FALSEnever evaluated
0
2347 && d->lineEdit->completer()->popup()
d->lineEdit->c...ter()->popup()Description
TRUEnever evaluated
FALSEnever evaluated
0
2348 && d->lineEdit->completer()->popup()->isVisible()
d->lineEdit->c...)->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2349-
2350 d->lineEdit->event(e);-
2351 return;
never executed: return;
0
2352 }-
2353-
2354-
2355 enum Move { NoMove=0 , MoveUp , MoveDown , MoveFirst , MoveLast};-
2356-
2357 Move move = NoMove;-
2358 int newIndex = currentIndex();-
2359 switch (e->key()) {-
2360 case
never executed: case Qt::Key_Up:
Qt::Key_Up:
never executed: case Qt::Key_Up:
0
2361 if (e->modifiers() & Qt::ControlModifier
e->modifiers()...ontrolModifierDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
2362 break;
never executed: break;
0
2363-
2364 case
never executed: case Qt::Key_PageUp:
Qt::Key_PageUp:
never executed: case Qt::Key_PageUp:
code before this statement never executed: case Qt::Key_PageUp:
0
2365-
2366-
2367-
2368-
2369-
2370 move = MoveUp;-
2371 break;
never executed: break;
0
2372 case
never executed: case Qt::Key_Down:
Qt::Key_Down:
never executed: case Qt::Key_Down:
0
2373 if (e->modifiers() & Qt::AltModifier
e->modifiers()...t::AltModifierDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
2374 showPopup();-
2375 return;
never executed: return;
0
2376 } else if (e->modifiers() & Qt::ControlModifier
e->modifiers()...ontrolModifierDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
2377 break;
never executed: break;
0
2378-
2379 case
never executed: case Qt::Key_PageDown:
Qt::Key_PageDown:
never executed: case Qt::Key_PageDown:
code before this statement never executed: case Qt::Key_PageDown:
0
2380-
2381-
2382-
2383-
2384-
2385 move = MoveDown;-
2386 break;
never executed: break;
0
2387 case
never executed: case Qt::Key_Home:
Qt::Key_Home:
never executed: case Qt::Key_Home:
0
2388 if (!d->lineEdit
!d->lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
2389 move = MoveFirst;
never executed: move = MoveFirst;
0
2390 break;
never executed: break;
0
2391 case
never executed: case Qt::Key_End:
Qt::Key_End:
never executed: case Qt::Key_End:
0
2392 if (!d->lineEdit
!d->lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
2393 move = MoveLast;
never executed: move = MoveLast;
0
2394 break;
never executed: break;
0
2395 case
never executed: case Qt::Key_F4:
Qt::Key_F4:
never executed: case Qt::Key_F4:
0
2396 if (!e->modifiers()
!e->modifiers()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2397 showPopup();-
2398 return;
never executed: return;
0
2399 }-
2400 break;
never executed: break;
0
2401 case
never executed: case Qt::Key_Space:
Qt::Key_Space:
never executed: case Qt::Key_Space:
0
2402 if (!d->lineEdit
!d->lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
2403 showPopup();-
2404 return;
never executed: return;
0
2405 }-
2406 break;
never executed: break;
0
2407 case
never executed: case Qt::Key_Enter:
Qt::Key_Enter:
never executed: case Qt::Key_Enter:
0
2408 case
never executed: case Qt::Key_Return:
Qt::Key_Return:
never executed: case Qt::Key_Return:
0
2409 case
never executed: case Qt::Key_Escape:
Qt::Key_Escape:
never executed: case Qt::Key_Escape:
0
2410 if (!d->lineEdit
!d->lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
2411 e->ignore();
never executed: e->ignore();
0
2412 break;
never executed: break;
0
2413 default
never executed: default:
:
never executed: default:
0
2414 if (!d->lineEdit
!d->lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
2415 if (!e->text().isEmpty()
!e->text().isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
2416 d->keyboardSearchString(e->text());
never executed: d->keyboardSearchString(e->text());
0
2417 else-
2418 e->ignore();
never executed: e->ignore();
0
2419 }-
2420 }
never executed: end of block
0
2421-
2422 const int rowCount = count();-
2423-
2424 if (move != NoMove
move != NoMoveDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
2425 e->accept();-
2426 switch (move) {-
2427 case
never executed: case MoveFirst:
MoveFirst:
never executed: case MoveFirst:
0
2428 newIndex = -1;-
2429-
2430 case
never executed: case MoveDown:
MoveDown:
never executed: case MoveDown:
code before this statement never executed: case MoveDown:
0
2431 newIndex++;-
2432 while (((newIndex < count())rowCount
newIndex < rowCountDescription
TRUEnever evaluated
FALSEnever evaluated
&& !(d->model->flags(d->model->index(newIndex, d->modelColumn, d->root))).flags() & Qt::ItemIsEnabled)
!(d->model->in...ItemIsEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
2433 newIndex++;
never executed: newIndex++;
0
2434 break;
never executed: break;
0
2435 case
never executed: case MoveLast:
MoveLast:
never executed: case MoveLast:
0
2436 newIndex = count();rowCount;-
2437-
2438 case
never executed: case MoveUp:
MoveUp:
never executed: case MoveUp:
code before this statement never executed: case MoveUp:
0
2439 newIndex--;-
2440 while ((
(newIndex >= 0)Description
TRUEnever evaluated
FALSEnever evaluated
newIndex >= 0)
(newIndex >= 0)Description
TRUEnever evaluated
FALSEnever evaluated
&& !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled)
!(d->model->fl...ItemIsEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
2441 newIndex--;
never executed: newIndex--;
0
2442 break;
never executed: break;
0
2443 default
never executed: default:
:
never executed: default:
0
2444 e->ignore();-
2445 break;
never executed: break;
0
2446 }-
2447-
2448 if (newIndex >= 0
newIndex >= 0Description
TRUEnever evaluated
FALSEnever evaluated
&& newIndex < count()rowCount
newIndex < rowCountDescription
TRUEnever evaluated
FALSEnever evaluated
&& newIndex != currentIndex()
newIndex != currentIndex()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2449 setCurrentIndex(newIndex);-
2450 d->emitActivated(d->currentIndex);-
2451 }
never executed: end of block
0
2452 }
never executed: end of block
else if (d->lineEdit
d->lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
2453 d->lineEdit->event(e);-
2454 }
never executed: end of block
0
2455}
never executed: end of block
0
2456-
2457-
2458-
2459-
2460-
2461void QComboBox::keyReleaseEvent(QKeyEvent *e)-
2462{-
2463 QComboBoxPrivate * const d = d_func();-
2464 if (d->lineEdit)-
2465 d->lineEdit->event(e);-
2466 else-
2467 QWidget::keyReleaseEvent(e);-
2468}-
2469-
2470-
2471-
2472-
2473-
2474void QComboBox::wheelEvent(QWheelEvent *e)-
2475{-
2476-
2477-
2478-
2479 QComboBoxPrivate * const d = d_func();-
2480 if (!d->viewContainer()->isVisible()
!d->viewContai...)->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2481 const int rowCount = count();-
2482 int newIndex = currentIndex();-
2483-
2484 if (e->delta() > 0
e->delta() > 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2485 newIndex--;-
2486 while ((
(newIndex >= 0)Description
TRUEnever evaluated
FALSEnever evaluated
newIndex >= 0)
(newIndex >= 0)Description
TRUEnever evaluated
FALSEnever evaluated
&& !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled)
!(d->model->fl...ItemIsEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
2487 newIndex--;
never executed: newIndex--;
0
2488 }
never executed: end of block
else if (e->delta() < 0
e->delta() < 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2489 newIndex++;-
2490 while (((newIndex < count())rowCount
newIndex < rowCountDescription
TRUEnever evaluated
FALSEnever evaluated
&& !(d->model->flags(d->model->index(newIndex, d->modelColumn, d->root))).flags() & Qt::ItemIsEnabled)
!(d->model->in...ItemIsEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
2491 newIndex++;
never executed: newIndex++;
0
2492 }
never executed: end of block
0
2493-
2494 if (newIndex >= 0
newIndex >= 0Description
TRUEnever evaluated
FALSEnever evaluated
&& newIndex < count()rowCount
newIndex < rowCountDescription
TRUEnever evaluated
FALSEnever evaluated
&& newIndex != currentIndex()
newIndex != currentIndex()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2495 setCurrentIndex(newIndex);-
2496 d->emitActivated(d->currentIndex);-
2497 }
never executed: end of block
0
2498 e->accept();-
2499 }
never executed: end of block
0
2500-
2501}
never executed: end of block
0
2502-
2503-
2504-
2505-
2506-
2507-
2508void QComboBox::contextMenuEvent(QContextMenuEvent *e)-
2509{-
2510 QComboBoxPrivate * const d = d_func();-
2511 if (d->lineEdit) {-
2512 Qt::ContextMenuPolicy p = d->lineEdit->contextMenuPolicy();-
2513 d->lineEdit->setContextMenuPolicy(Qt::DefaultContextMenu);-
2514 d->lineEdit->event(e);-
2515 d->lineEdit->setContextMenuPolicy(p);-
2516 }-
2517}-
2518-
2519-
2520void QComboBoxPrivate::keyboardSearchString(const QString &text)-
2521{-
2522-
2523 QAbstractItemView *view = viewContainer()->itemView();-
2524 view->setCurrentIndex(currentIndex);-
2525 int currentRow = view->currentIndex().row();-
2526 view->keyboardSearch(text);-
2527 if (currentRow != view->currentIndex().row()) {-
2528 setCurrentIndex(view->currentIndex());-
2529 emitActivated(currentIndex);-
2530 }-
2531}-
2532-
2533void QComboBoxPrivate::modelChanged()-
2534{-
2535 QComboBox * const q = q_func();-
2536-
2537 if (sizeAdjustPolicy == QComboBox::AdjustToContents) {-
2538 sizeHint = QSize();-
2539 adjustComboBoxSize();-
2540 q->updateGeometry();-
2541 }-
2542}-
2543-
2544-
2545-
2546-
2547void QComboBox::inputMethodEvent(QInputMethodEvent *e)-
2548{-
2549 QComboBoxPrivate * const d = d_func();-
2550 if (d->lineEdit) {-
2551 d->lineEdit->event(e);-
2552 } else {-
2553 if (!e->commitString().isEmpty())-
2554 d->keyboardSearchString(e->commitString());-
2555 else-
2556 e->ignore();-
2557 }-
2558}-
2559-
2560-
2561-
2562-
2563QVariant QComboBox::inputMethodQuery(Qt::InputMethodQuery query) const-
2564{-
2565 const QComboBoxPrivate * const d = d_func();-
2566 if (d->lineEdit)-
2567 return d->lineEdit->inputMethodQuery(query);-
2568 return QWidget::inputMethodQuery(query);-
2569}-
2570-
2571-
2572-
2573QVariant QComboBox::inputMethodQuery(Qt::InputMethodQuery query, const QVariant &argument) const-
2574{-
2575 const QComboBoxPrivate * const d = d_func();-
2576 if (d->lineEdit
d->lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
2577 return
never executed: return d->lineEdit->inputMethodQuery(query, argument);
d->lineEdit->inputMethodQuery(query, argument);
never executed: return d->lineEdit->inputMethodQuery(query, argument);
0
2578 return
never executed: return QWidget::inputMethodQuery(query);
QWidget::inputMethodQuery(query);
never executed: return QWidget::inputMethodQuery(query);
0
2579}-
2580bool QComboBox::hasFrame() const-
2581{-
2582 const QComboBoxPrivate * const d = d_func();-
2583 return d->frame;-
2584}-
2585-
2586-
2587void QComboBox::setFrame(bool enable)-
2588{-
2589 QComboBoxPrivate * const d = d_func();-
2590 d->frame = enable;-
2591 update();-
2592 updateGeometry();-
2593}-
2594int QComboBox::modelColumn() const-
2595{-
2596 const QComboBoxPrivate * const d = d_func();-
2597 return d->modelColumn;-
2598}-
2599-
2600void QComboBox::setModelColumn(int visibleColumn)-
2601{-
2602 QComboBoxPrivate * const d = d_func();-
2603 d->modelColumn = visibleColumn;-
2604 QListView *lv = qobject_cast<QListView *>(d->viewContainer()->itemView());-
2605 if (lv)-
2606 lv->setModelColumn(visibleColumn);-
2607-
2608 if (d->lineEdit && d->lineEdit->completer()-
2609 && d->lineEdit->completer() == d->completer)-
2610 d->lineEdit->completer()->setCompletionColumn(visibleColumn);-
2611-
2612 setCurrentIndex(currentIndex());-
2613}-
2614-
2615-
2616-
Switch to Source codePreprocessed file

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