widgets/qtoolbox.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtGui module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qtoolbox.h" -
43 -
44#ifndef QT_NO_TOOLBOX -
45 -
46#include <qapplication.h> -
47#include <qeventloop.h> -
48#include <qlayout.h> -
49#include <qlist.h> -
50#include <qpainter.h> -
51#include <qscrollarea.h> -
52#include <qstyle.h> -
53#include <qstyleoption.h> -
54#include <qtooltip.h> -
55#include <qabstractbutton.h> -
56 -
57#include "qframe_p.h" -
58 -
59QT_BEGIN_NAMESPACE -
60 -
61class QToolBoxButton : public QAbstractButton -
62{ -
63 Q_OBJECT -
64public: -
65 QToolBoxButton(QWidget *parent) -
66 : QAbstractButton(parent), selected(false), indexInPage(-1) -
67 { -
68 setBackgroundRole(QPalette::Window);
executed (the execution status of this line is deduced): setBackgroundRole(QPalette::Window);
-
69 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
executed (the execution status of this line is deduced): setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
-
70 setFocusPolicy(Qt::NoFocus);
executed (the execution status of this line is deduced): setFocusPolicy(Qt::NoFocus);
-
71 }
executed: }
Execution Count:22
22
72 -
73 inline void setSelected(bool b) { selected = b; update(); }
executed: }
Execution Count:28
28
74 inline void setIndex(int newIndex) { indexInPage = newIndex; }
executed: }
Execution Count:124
124
75 -
76 QSize sizeHint() const; -
77 QSize minimumSizeHint() const; -
78 -
79protected: -
80 void initStyleOption(QStyleOptionToolBox *opt) const; -
81 void paintEvent(QPaintEvent *); -
82 -
83private: -
84 bool selected; -
85 int indexInPage; -
86}; -
87 -
88 -
89class QToolBoxPrivate : public QFramePrivate -
90{ -
91 Q_DECLARE_PUBLIC(QToolBox) -
92public: -
93 struct Page -
94 { -
95 QToolBoxButton *button; -
96 QScrollArea *sv; -
97 QWidget *widget; -
98 -
99 inline void setText(const QString &text) { button->setText(text); }
executed: }
Execution Count:26
26
100 inline void setIcon(const QIcon &is) { button->setIcon(is); }
executed: }
Execution Count:22
22
101#ifndef QT_NO_TOOLTIP -
102 inline void setToolTip(const QString &tip) { button->setToolTip(tip); }
never executed: }
0
103 inline QString toolTip() const { return button->toolTip(); }
never executed: return button->toolTip();
0
104#endif -
105 inline QString text() const { return button->text(); }
executed: return button->text();
Execution Count:4
4
106 inline QIcon icon() const { return button->icon(); }
never executed: return button->icon();
0
107 -
108 inline bool operator==(const Page& other) const -
109 { -
110 return widget == other.widget;
executed: return widget == other.widget;
Execution Count:152
152
111 } -
112 }; -
113 typedef QList<Page> PageList; -
114 -
115 inline QToolBoxPrivate() -
116 : currentPage(0) -
117 { -
118 }
executed: }
Execution Count:6
6
119 void _q_buttonClicked(); -
120 void _q_widgetDestroyed(QObject*); -
121 -
122 Page *page(QWidget *widget) const; -
123 const Page *page(int index) const; -
124 Page *page(int index); -
125 -
126 void updateTabs(); -
127 void relayout(); -
128 -
129 PageList pageList; -
130 QVBoxLayout *layout; -
131 Page *currentPage; -
132}; -
133 -
134QToolBoxPrivate::Page *QToolBoxPrivate::page(QWidget *widget) const -
135{ -
136 if (!widget)
partially evaluated: !widget
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:73
0-73
137 return 0;
never executed: return 0;
0
138 -
139 for (PageList::ConstIterator i = pageList.constBegin(); i != pageList.constEnd(); ++i)
evaluated: i != pageList.constEnd()
TRUEFALSE
yes
Evaluation Count:153
yes
Evaluation Count:2
2-153
140 if ((*i).widget == widget)
evaluated: (*i).widget == widget
TRUEFALSE
yes
Evaluation Count:71
yes
Evaluation Count:82
71-82
141 return (Page*) &(*i);
executed: return (Page*) &(*i);
Execution Count:71
71
142 return 0;
executed: return 0;
Execution Count:2
2
143} -
144 -
145QToolBoxPrivate::Page *QToolBoxPrivate::page(int index) -
146{ -
147 if (index >= 0 && index < pageList.size())
evaluated: index >= 0
TRUEFALSE
yes
Evaluation Count:39
yes
Evaluation Count:1
evaluated: index < pageList.size()
TRUEFALSE
yes
Evaluation Count:37
yes
Evaluation Count:2
1-39
148 return &pageList[index];
executed: return &pageList[index];
Execution Count:37
37
149 return 0;
executed: return 0;
Execution Count:3
3
150} -
151 -
152const QToolBoxPrivate::Page *QToolBoxPrivate::page(int index) const -
153{ -
154 if (index >= 0 && index < pageList.size())
partially evaluated: index >= 0
TRUEFALSE
yes
Evaluation Count:4
no
Evaluation Count:0
partially evaluated: index < pageList.size()
TRUEFALSE
yes
Evaluation Count:4
no
Evaluation Count:0
0-4
155 return &pageList.at(index);
executed: return &pageList.at(index);
Execution Count:4
4
156 return 0;
never executed: return 0;
0
157} -
158 -
159void QToolBoxPrivate::updateTabs() -
160{ -
161 QToolBoxButton *lastButton = currentPage ? currentPage->button : 0;
partially evaluated: currentPage
TRUEFALSE
yes
Evaluation Count:41
no
Evaluation Count:0
0-41
162 bool after = false;
executed (the execution status of this line is deduced): bool after = false;
-
163 int index = 0;
executed (the execution status of this line is deduced): int index = 0;
-
164 for (index = 0; index < pageList.count(); ++index) {
evaluated: index < pageList.count()
TRUEFALSE
yes
Evaluation Count:124
yes
Evaluation Count:41
41-124
165 const Page &page = pageList.at(index);
executed (the execution status of this line is deduced): const Page &page = pageList.at(index);
-
166 QToolBoxButton *tB = page.button;
executed (the execution status of this line is deduced): QToolBoxButton *tB = page.button;
-
167 // update indexes, since the updates are delayed, the indexes will be correct -
168 // when we actually paint. -
169 tB->setIndex(index);
executed (the execution status of this line is deduced): tB->setIndex(index);
-
170 QWidget *tW = page.widget;
executed (the execution status of this line is deduced): QWidget *tW = page.widget;
-
171 if (after) {
evaluated: after
TRUEFALSE
yes
Evaluation Count:30
yes
Evaluation Count:94
30-94
172 QPalette p = tB->palette();
executed (the execution status of this line is deduced): QPalette p = tB->palette();
-
173 p.setColor(tB->backgroundRole(), tW->palette().color(tW->backgroundRole()));
executed (the execution status of this line is deduced): p.setColor(tB->backgroundRole(), tW->palette().color(tW->backgroundRole()));
-
174 tB->setPalette(p);
executed (the execution status of this line is deduced): tB->setPalette(p);
-
175 tB->update();
executed (the execution status of this line is deduced): tB->update();
-
176 } else if (tB->backgroundRole() != QPalette::Window) {
executed: }
Execution Count:30
partially evaluated: tB->backgroundRole() != QPalette::Window
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:94
0-94
177 tB->setBackgroundRole(QPalette::Window);
never executed (the execution status of this line is deduced): tB->setBackgroundRole(QPalette::Window);
-
178 tB->update();
never executed (the execution status of this line is deduced): tB->update();
-
179 }
never executed: }
0
180 after = tB == lastButton;
executed (the execution status of this line is deduced): after = tB == lastButton;
-
181 }
executed: }
Execution Count:124
124
182}
executed: }
Execution Count:41
41
183 -
184QSize QToolBoxButton::sizeHint() const -
185{ -
186 QSize iconSize(8, 8);
never executed (the execution status of this line is deduced): QSize iconSize(8, 8);
-
187 if (!icon().isNull()) {
never evaluated: !icon().isNull()
0
188 int icone = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, parentWidget() /* QToolBox */);
never executed (the execution status of this line is deduced): int icone = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, parentWidget() );
-
189 iconSize += QSize(icone + 2, icone);
never executed (the execution status of this line is deduced): iconSize += QSize(icone + 2, icone);
-
190 }
never executed: }
0
191 QSize textSize = fontMetrics().size(Qt::TextShowMnemonic, text()) + QSize(0, 8);
never executed (the execution status of this line is deduced): QSize textSize = fontMetrics().size(Qt::TextShowMnemonic, text()) + QSize(0, 8);
-
192 -
193 QSize total(iconSize.width() + textSize.width(), qMax(iconSize.height(), textSize.height()));
never executed (the execution status of this line is deduced): QSize total(iconSize.width() + textSize.width(), qMax(iconSize.height(), textSize.height()));
-
194 return total.expandedTo(QApplication::globalStrut());
never executed: return total.expandedTo(QApplication::globalStrut());
0
195} -
196 -
197QSize QToolBoxButton::minimumSizeHint() const -
198{ -
199 if (icon().isNull())
never evaluated: icon().isNull()
0
200 return QSize();
never executed: return QSize();
0
201 int icone = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, parentWidget() /* QToolBox */);
never executed (the execution status of this line is deduced): int icone = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, parentWidget() );
-
202 return QSize(icone + 8, icone + 8);
never executed: return QSize(icone + 8, icone + 8);
0
203} -
204 -
205void QToolBoxButton::initStyleOption(QStyleOptionToolBox *option) const -
206{ -
207 if (!option)
never evaluated: !option
0
208 return;
never executed: return;
0
209 option->initFrom(this);
never executed (the execution status of this line is deduced): option->initFrom(this);
-
210 if (selected)
never evaluated: selected
0
211 option->state |= QStyle::State_Selected;
never executed: option->state |= QStyle::State_Selected;
0
212 if (isDown())
never evaluated: isDown()
0
213 option->state |= QStyle::State_Sunken;
never executed: option->state |= QStyle::State_Sunken;
0
214 option->text = text();
never executed (the execution status of this line is deduced): option->text = text();
-
215 option->icon = icon();
never executed (the execution status of this line is deduced): option->icon = icon();
-
216 -
217 if (QStyleOptionToolBoxV2 *optionV2 = qstyleoption_cast<QStyleOptionToolBoxV2 *>(option)) {
never evaluated: QStyleOptionToolBoxV2 *optionV2 = qstyleoption_cast<QStyleOptionToolBoxV2 *>(option)
0
218 QToolBox *toolBox = static_cast<QToolBox *>(parentWidget()); // I know I'm in a tool box.
never executed (the execution status of this line is deduced): QToolBox *toolBox = static_cast<QToolBox *>(parentWidget());
-
219 int widgetCount = toolBox->count();
never executed (the execution status of this line is deduced): int widgetCount = toolBox->count();
-
220 int currIndex = toolBox->currentIndex();
never executed (the execution status of this line is deduced): int currIndex = toolBox->currentIndex();
-
221 if (widgetCount == 1) {
never evaluated: widgetCount == 1
0
222 optionV2->position = QStyleOptionToolBoxV2::OnlyOneTab;
never executed (the execution status of this line is deduced): optionV2->position = QStyleOptionToolBoxV2::OnlyOneTab;
-
223 } else if (indexInPage == 0) {
never executed: }
never evaluated: indexInPage == 0
0
224 optionV2->position = QStyleOptionToolBoxV2::Beginning;
never executed (the execution status of this line is deduced): optionV2->position = QStyleOptionToolBoxV2::Beginning;
-
225 } else if (indexInPage == widgetCount - 1) {
never executed: }
never evaluated: indexInPage == widgetCount - 1
0
226 optionV2->position = QStyleOptionToolBoxV2::End;
never executed (the execution status of this line is deduced): optionV2->position = QStyleOptionToolBoxV2::End;
-
227 } else {
never executed: }
0
228 optionV2->position = QStyleOptionToolBoxV2::Middle;
never executed (the execution status of this line is deduced): optionV2->position = QStyleOptionToolBoxV2::Middle;
-
229 }
never executed: }
0
230 if (currIndex == indexInPage - 1) {
never evaluated: currIndex == indexInPage - 1
0
231 optionV2->selectedPosition = QStyleOptionToolBoxV2::PreviousIsSelected;
never executed (the execution status of this line is deduced): optionV2->selectedPosition = QStyleOptionToolBoxV2::PreviousIsSelected;
-
232 } else if (currIndex == indexInPage + 1) {
never executed: }
never evaluated: currIndex == indexInPage + 1
0
233 optionV2->selectedPosition = QStyleOptionToolBoxV2::NextIsSelected;
never executed (the execution status of this line is deduced): optionV2->selectedPosition = QStyleOptionToolBoxV2::NextIsSelected;
-
234 } else {
never executed: }
0
235 optionV2->selectedPosition = QStyleOptionToolBoxV2::NotAdjacent;
never executed (the execution status of this line is deduced): optionV2->selectedPosition = QStyleOptionToolBoxV2::NotAdjacent;
-
236 }
never executed: }
0
237 } -
238}
never executed: }
0
239 -
240void QToolBoxButton::paintEvent(QPaintEvent *) -
241{ -
242 QPainter paint(this);
never executed (the execution status of this line is deduced): QPainter paint(this);
-
243 QString text = QAbstractButton::text();
never executed (the execution status of this line is deduced): QString text = QAbstractButton::text();
-
244 QPainter *p = &paint;
never executed (the execution status of this line is deduced): QPainter *p = &paint;
-
245 QStyleOptionToolBoxV2 opt;
never executed (the execution status of this line is deduced): QStyleOptionToolBoxV2 opt;
-
246 initStyleOption(&opt);
never executed (the execution status of this line is deduced): initStyleOption(&opt);
-
247 style()->drawControl(QStyle::CE_ToolBoxTab, &opt, p, parentWidget());
never executed (the execution status of this line is deduced): style()->drawControl(QStyle::CE_ToolBoxTab, &opt, p, parentWidget());
-
248}
never executed: }
0
249 -
250/*! -
251 \class QToolBox -
252 -
253 \brief The QToolBox class provides a column of tabbed widget items. -
254 -
255 -
256 \ingroup basicwidgets -
257 \inmodule QtWidgets -
258 -
259 A toolbox is a widget that displays a column of tabs one above the -
260 other, with the current item displayed below the current tab. -
261 Every tab has an index position within the column of tabs. A tab's -
262 item is a QWidget. -
263 -
264 Each item has an itemText(), an optional itemIcon(), an optional -
265 itemToolTip(), and a widget(). The item's attributes can be -
266 changed with setItemText(), setItemIcon(), and -
267 setItemToolTip(). Each item can be enabled or disabled -
268 individually with setItemEnabled(). -
269 -
270 Items are added using addItem(), or inserted at particular -
271 positions using insertItem(). The total number of items is given -
272 by count(). Items can be deleted with delete, or removed from the -
273 toolbox with removeItem(). Combining removeItem() and insertItem() -
274 allows you to move items to different positions. -
275 -
276 The index of the current item widget is returned by currentIndex(), -
277 and set with setCurrentIndex(). The index of a particular item can -
278 be found using indexOf(), and the item at a given index is returned -
279 by item(). -
280 -
281 The currentChanged() signal is emitted when the current item is -
282 changed. -
283 -
284 \sa QTabWidget -
285*/ -
286 -
287/*! -
288 \fn void QToolBox::currentChanged(int index) -
289 -
290 This signal is emitted when the current item is changed. The new -
291 current item's index is passed in \a index, or -1 if there is no -
292 current item. -
293*/ -
294 -
295 -
296/*! -
297 Constructs a new toolbox with the given \a parent and the flags, \a f. -
298*/ -
299QToolBox::QToolBox(QWidget *parent, Qt::WindowFlags f) -
300 : QFrame(*new QToolBoxPrivate, parent, f) -
301{ -
302 Q_D(QToolBox);
executed (the execution status of this line is deduced): QToolBoxPrivate * const d = d_func();
-
303 d->layout = new QVBoxLayout(this);
executed (the execution status of this line is deduced): d->layout = new QVBoxLayout(this);
-
304 d->layout->setMargin(0);
executed (the execution status of this line is deduced): d->layout->setMargin(0);
-
305 setBackgroundRole(QPalette::Button);
executed (the execution status of this line is deduced): setBackgroundRole(QPalette::Button);
-
306}
executed: }
Execution Count:6
6
307 -
308/*! -
309 Destroys the toolbox. -
310*/ -
311 -
312QToolBox::~QToolBox() -
313{ -
314} -
315 -
316/*! -
317 \fn int QToolBox::addItem(QWidget *w, const QString &text) -
318 \overload -
319 -
320 Adds the widget \a w in a new tab at bottom of the toolbox. The -
321 new tab's text is set to \a text. Returns the new tab's index. -
322*/ -
323 -
324/*! -
325 \fn int QToolBox::addItem(QWidget *widget, const QIcon &iconSet,const QString &text) -
326 Adds the \a widget in a new tab at bottom of the toolbox. The -
327 new tab's text is set to \a text, and the \a iconSet is -
328 displayed to the left of the \a text. Returns the new tab's index. -
329*/ -
330 -
331/*! -
332 \fn int QToolBox::insertItem(int index, QWidget *widget, const QString &text) -
333 \overload -
334 -
335 Inserts the \a widget at position \a index, or at the bottom -
336 of the toolbox if \a index is out of range. The new item's text is -
337 set to \a text. Returns the new item's index. -
338*/ -
339 -
340/*! -
341 Inserts the \a widget at position \a index, or at the bottom -
342 of the toolbox if \a index is out of range. The new item's text -
343 is set to \a text, and the \a icon is displayed to the left of -
344 the \a text. Returns the new item's index. -
345*/ -
346 -
347int QToolBox::insertItem(int index, QWidget *widget, const QIcon &icon, const QString &text) -
348{ -
349 if (!widget)
partially evaluated: !widget
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:22
0-22
350 return -1;
never executed: return -1;
0
351 -
352 Q_D(QToolBox);
executed (the execution status of this line is deduced): QToolBoxPrivate * const d = d_func();
-
353 connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(_q_widgetDestroyed(QObject*)));
executed (the execution status of this line is deduced): connect(widget, "2""destroyed(QObject*)", this, "1""_q_widgetDestroyed(QObject*)");
-
354 -
355 QToolBoxPrivate::Page c;
executed (the execution status of this line is deduced): QToolBoxPrivate::Page c;
-
356 c.widget = widget;
executed (the execution status of this line is deduced): c.widget = widget;
-
357 c.button = new QToolBoxButton(this);
executed (the execution status of this line is deduced): c.button = new QToolBoxButton(this);
-
358 c.button->setObjectName(QLatin1String("qt_toolbox_toolboxbutton"));
executed (the execution status of this line is deduced): c.button->setObjectName(QLatin1String("qt_toolbox_toolboxbutton"));
-
359 connect(c.button, SIGNAL(clicked()), this, SLOT(_q_buttonClicked()));
executed (the execution status of this line is deduced): connect(c.button, "2""clicked()", this, "1""_q_buttonClicked()");
-
360 -
361 c.sv = new QScrollArea(this);
executed (the execution status of this line is deduced): c.sv = new QScrollArea(this);
-
362 c.sv->setWidget(widget);
executed (the execution status of this line is deduced): c.sv->setWidget(widget);
-
363 c.sv->setWidgetResizable(true);
executed (the execution status of this line is deduced): c.sv->setWidgetResizable(true);
-
364 c.sv->hide();
executed (the execution status of this line is deduced): c.sv->hide();
-
365 c.sv->setFrameStyle(QFrame::NoFrame);
executed (the execution status of this line is deduced): c.sv->setFrameStyle(QFrame::NoFrame);
-
366 -
367 c.setText(text);
executed (the execution status of this line is deduced): c.setText(text);
-
368 c.setIcon(icon);
executed (the execution status of this line is deduced): c.setIcon(icon);
-
369 -
370 if (index < 0 || index >= (int)d->pageList.count()) {
evaluated: index < 0
TRUEFALSE
yes
Evaluation Count:14
yes
Evaluation Count:8
partially evaluated: index >= (int)d->pageList.count()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
0-14
371 index = d->pageList.count();
executed (the execution status of this line is deduced): index = d->pageList.count();
-
372 d->pageList.append(c);
executed (the execution status of this line is deduced): d->pageList.append(c);
-
373 d->layout->addWidget(c.button);
executed (the execution status of this line is deduced): d->layout->addWidget(c.button);
-
374 d->layout->addWidget(c.sv);
executed (the execution status of this line is deduced): d->layout->addWidget(c.sv);
-
375 if (index == 0)
evaluated: index == 0
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:9
5-9
376 setCurrentIndex(index);
executed: setCurrentIndex(index);
Execution Count:5
5
377 } else {
executed: }
Execution Count:14
14
378 d->pageList.insert(index, c);
executed (the execution status of this line is deduced): d->pageList.insert(index, c);
-
379 d->relayout();
executed (the execution status of this line is deduced): d->relayout();
-
380 if (d->currentPage) {
partially evaluated: d->currentPage
TRUEFALSE
yes
Evaluation Count:8
no
Evaluation Count:0
0-8
381 QWidget *current = d->currentPage->widget;
executed (the execution status of this line is deduced): QWidget *current = d->currentPage->widget;
-
382 int oldindex = indexOf(current);
executed (the execution status of this line is deduced): int oldindex = indexOf(current);
-
383 if (index <= oldindex) {
evaluated: index <= oldindex
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:4
4
384 d->currentPage = 0; // trigger change
executed (the execution status of this line is deduced): d->currentPage = 0;
-
385 setCurrentIndex(oldindex);
executed (the execution status of this line is deduced): setCurrentIndex(oldindex);
-
386 }
executed: }
Execution Count:4
4
387 }
executed: }
Execution Count:8
8
388 }
executed: }
Execution Count:8
8
389 -
390 c.button->show();
executed (the execution status of this line is deduced): c.button->show();
-
391 -
392 d->updateTabs();
executed (the execution status of this line is deduced): d->updateTabs();
-
393 itemInserted(index);
executed (the execution status of this line is deduced): itemInserted(index);
-
394 return index;
executed: return index;
Execution Count:22
22
395} -
396 -
397void QToolBoxPrivate::_q_buttonClicked() -
398{ -
399 Q_Q(QToolBox);
never executed (the execution status of this line is deduced): QToolBox * const q = q_func();
-
400 QToolBoxButton *tb = qobject_cast<QToolBoxButton*>(q->sender());
never executed (the execution status of this line is deduced): QToolBoxButton *tb = qobject_cast<QToolBoxButton*>(q->sender());
-
401 QWidget* item = 0;
never executed (the execution status of this line is deduced): QWidget* item = 0;
-
402 for (QToolBoxPrivate::PageList::ConstIterator i = pageList.constBegin(); i != pageList.constEnd(); ++i)
never evaluated: i != pageList.constEnd()
0
403 if ((*i).button == tb) {
never evaluated: (*i).button == tb
0
404 item = (*i).widget;
never executed (the execution status of this line is deduced): item = (*i).widget;
-
405 break;
never executed: break;
0
406 } -
407 -
408 q->setCurrentIndex(q->indexOf(item));
never executed (the execution status of this line is deduced): q->setCurrentIndex(q->indexOf(item));
-
409}
never executed: }
0
410 -
411/*! -
412 \property QToolBox::count -
413 \brief The number of items contained in the toolbox. -
414 -
415 By default, this property has a value of 0. -
416*/ -
417 -
418int QToolBox::count() const -
419{ -
420 Q_D(const QToolBox);
executed (the execution status of this line is deduced): const QToolBoxPrivate * const d = d_func();
-
421 return d->pageList.count();
executed: return d->pageList.count();
Execution Count:36
36
422} -
423 -
424void QToolBox::setCurrentIndex(int index) -
425{ -
426 Q_D(QToolBox);
executed (the execution status of this line is deduced): QToolBoxPrivate * const d = d_func();
-
427 QToolBoxPrivate::Page *c = d->page(index);
executed (the execution status of this line is deduced): QToolBoxPrivate::Page *c = d->page(index);
-
428 if (!c || d->currentPage == c)
evaluated: !c
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:21
evaluated: d->currentPage == c
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:19
2-21
429 return;
executed: return;
Execution Count:5
5
430 -
431 c->button->setSelected(true);
executed (the execution status of this line is deduced): c->button->setSelected(true);
-
432 if (d->currentPage) {
evaluated: d->currentPage
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:10
9-10
433 d->currentPage->sv->hide();
executed (the execution status of this line is deduced): d->currentPage->sv->hide();
-
434 d->currentPage->button->setSelected(false);
executed (the execution status of this line is deduced): d->currentPage->button->setSelected(false);
-
435 }
executed: }
Execution Count:9
9
436 d->currentPage = c;
executed (the execution status of this line is deduced): d->currentPage = c;
-
437 d->currentPage->sv->show();
executed (the execution status of this line is deduced): d->currentPage->sv->show();
-
438 d->updateTabs();
executed (the execution status of this line is deduced): d->updateTabs();
-
439 emit currentChanged(index);
executed (the execution status of this line is deduced): currentChanged(index);
-
440}
executed: }
Execution Count:19
19
441 -
442void QToolBoxPrivate::relayout() -
443{ -
444 Q_Q(QToolBox);
executed (the execution status of this line is deduced): QToolBox * const q = q_func();
-
445 delete layout;
executed (the execution status of this line is deduced): delete layout;
-
446 layout = new QVBoxLayout(q);
executed (the execution status of this line is deduced): layout = new QVBoxLayout(q);
-
447 layout->setMargin(0);
executed (the execution status of this line is deduced): layout->setMargin(0);
-
448 for (QToolBoxPrivate::PageList::ConstIterator i = pageList.constBegin(); i != pageList.constEnd(); ++i) {
evaluated: i != pageList.constEnd()
TRUEFALSE
yes
Evaluation Count:28
yes
Evaluation Count:8
8-28
449 layout->addWidget((*i).button);
executed (the execution status of this line is deduced): layout->addWidget((*i).button);
-
450 layout->addWidget((*i).sv);
executed (the execution status of this line is deduced): layout->addWidget((*i).sv);
-
451 }
executed: }
Execution Count:28
28
452}
executed: }
Execution Count:8
8
453 -
454void QToolBoxPrivate::_q_widgetDestroyed(QObject *object) -
455{ -
456 Q_Q(QToolBox);
executed (the execution status of this line is deduced): QToolBox * const q = q_func();
-
457 // no verification - vtbl corrupted already -
458 QWidget *p = (QWidget*)object;
executed (the execution status of this line is deduced): QWidget *p = (QWidget*)object;
-
459 -
460 QToolBoxPrivate::Page *c = page(p);
executed (the execution status of this line is deduced): QToolBoxPrivate::Page *c = page(p);
-
461 if (!p || !c)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
partially evaluated: !c
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
462 return;
never executed: return;
0
463 -
464 layout->removeWidget(c->sv);
executed (the execution status of this line is deduced): layout->removeWidget(c->sv);
-
465 layout->removeWidget(c->button);
executed (the execution status of this line is deduced): layout->removeWidget(c->button);
-
466 c->sv->deleteLater(); // page might still be a child of sv
executed (the execution status of this line is deduced): c->sv->deleteLater();
-
467 delete c->button;
executed (the execution status of this line is deduced): delete c->button;
-
468 -
469 bool removeCurrent = c == currentPage;
executed (the execution status of this line is deduced): bool removeCurrent = c == currentPage;
-
470 pageList.removeAll(*c);
executed (the execution status of this line is deduced): pageList.removeAll(*c);
-
471 -
472 if (!pageList.count()) {
evaluated: !pageList.count()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:3
1-3
473 currentPage = 0;
executed (the execution status of this line is deduced): currentPage = 0;
-
474 emit q->currentChanged(-1);
executed (the execution status of this line is deduced): q->currentChanged(-1);
-
475 } else if (removeCurrent) {
executed: }
Execution Count:1
evaluated: removeCurrent
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2
1-2
476 currentPage = 0;
executed (the execution status of this line is deduced): currentPage = 0;
-
477 q->setCurrentIndex(0);
executed (the execution status of this line is deduced): q->setCurrentIndex(0);
-
478 }
executed: }
Execution Count:1
1
479} -
480 -
481/*! -
482 Removes the item at position \a index from the toolbox. Note that -
483 the widget is \e not deleted. -
484*/ -
485 -
486void QToolBox::removeItem(int index) -
487{ -
488 Q_D(QToolBox);
executed (the execution status of this line is deduced): QToolBoxPrivate * const d = d_func();
-
489 if (QWidget *w = widget(index)) {
partially evaluated: QWidget *w = widget(index)
TRUEFALSE
yes
Evaluation Count:3
no
Evaluation Count:0
0-3
490 disconnect(w, SIGNAL(destroyed(QObject*)), this, SLOT(_q_widgetDestroyed(QObject*)));
executed (the execution status of this line is deduced): disconnect(w, "2""destroyed(QObject*)", this, "1""_q_widgetDestroyed(QObject*)");
-
491 w->setParent(this);
executed (the execution status of this line is deduced): w->setParent(this);
-
492 // destroy internal data -
493 d->_q_widgetDestroyed(w);
executed (the execution status of this line is deduced): d->_q_widgetDestroyed(w);
-
494 itemRemoved(index);
executed (the execution status of this line is deduced): itemRemoved(index);
-
495 }
executed: }
Execution Count:3
3
496}
executed: }
Execution Count:3
3
497 -
498 -
499/*! -
500 \property QToolBox::currentIndex -
501 \brief the index of the current item -
502 -
503 By default, for an empty toolbox, this property has a value of -1. -
504 -
505 \sa indexOf(), widget() -
506*/ -
507 -
508 -
509int QToolBox::currentIndex() const -
510{ -
511 Q_D(const QToolBox);
executed (the execution status of this line is deduced): const QToolBoxPrivate * const d = d_func();
-
512 return d->currentPage ? indexOf(d->currentPage->widget) : -1;
executed: return d->currentPage ? indexOf(d->currentPage->widget) : -1;
Execution Count:20
20
513} -
514 -
515/*! -
516 Returns a pointer to the current widget, or 0 if there is no such item. -
517 -
518 \sa currentIndex(), setCurrentWidget() -
519*/ -
520 -
521QWidget * QToolBox::currentWidget() const -
522{ -
523 Q_D(const QToolBox);
executed (the execution status of this line is deduced): const QToolBoxPrivate * const d = d_func();
-
524 return d->currentPage ? d->currentPage->widget : 0;
executed: return d->currentPage ? d->currentPage->widget : 0;
Execution Count:3
3
525} -
526 -
527/*! -
528 Makes\a widget the current widget. The \a widget must be an item in this tool box. -
529 -
530 \sa addItem(), setCurrentIndex(), currentWidget() -
531 */ -
532void QToolBox::setCurrentWidget(QWidget *widget) -
533{ -
534 int i = indexOf(widget);
executed (the execution status of this line is deduced): int i = indexOf(widget);
-
535 if (i >= 0)
evaluated: i >= 0
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:1
1-2
536 setCurrentIndex(i);
executed: setCurrentIndex(i);
Execution Count:2
2
537 else -
538 qWarning("QToolBox::setCurrentWidget: widget not contained in tool box");
executed: QMessageLogger("widgets/qtoolbox.cpp", 538, __PRETTY_FUNCTION__).warning("QToolBox::setCurrentWidget: widget not contained in tool box");
Execution Count:1
1
539} -
540 -
541/*! -
542 Returns the widget at position \a index, or 0 if there is no such -
543 item. -
544*/ -
545 -
546QWidget *QToolBox::widget(int index) const -
547{ -
548 Q_D(const QToolBox);
executed (the execution status of this line is deduced): const QToolBoxPrivate * const d = d_func();
-
549 if (index < 0 || index >= (int) d->pageList.size())
partially evaluated: index < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:14
evaluated: index >= (int) d->pageList.size()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:13
0-14
550 return 0;
executed: return 0;
Execution Count:1
1
551 return d->pageList.at(index).widget;
executed: return d->pageList.at(index).widget;
Execution Count:13
13
552} -
553 -
554/*! -
555 Returns the index of \a widget, or -1 if the item does not -
556 exist. -
557*/ -
558 -
559int QToolBox::indexOf(QWidget *widget) const -
560{ -
561 Q_D(const QToolBox);
executed (the execution status of this line is deduced): const QToolBoxPrivate * const d = d_func();
-
562 QToolBoxPrivate::Page *c = (widget ? d->page(widget) : 0);
evaluated: widget
TRUEFALSE
yes
Evaluation Count:69
yes
Evaluation Count:1
1-69
563 return c ? d->pageList.indexOf(*c) : -1;
executed: return c ? d->pageList.indexOf(*c) : -1;
Execution Count:70
70
564} -
565 -
566/*! -
567 If \a enabled is true then the item at position \a index is enabled; otherwise -
568 the item at position \a index is disabled. -
569*/ -
570 -
571void QToolBox::setItemEnabled(int index, bool enabled) -
572{ -
573 Q_D(QToolBox);
executed (the execution status of this line is deduced): QToolBoxPrivate * const d = d_func();
-
574 QToolBoxPrivate::Page *c = d->page(index);
executed (the execution status of this line is deduced): QToolBoxPrivate::Page *c = d->page(index);
-
575 if (!c)
partially evaluated: !c
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5
0-5
576 return;
never executed: return;
0
577 -
578 c->button->setEnabled(enabled);
executed (the execution status of this line is deduced): c->button->setEnabled(enabled);
-
579 if (!enabled && c == d->currentPage) {
evaluated: !enabled
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:1
evaluated: c == d->currentPage
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:1
1-4
580 int curIndexUp = index;
executed (the execution status of this line is deduced): int curIndexUp = index;
-
581 int curIndexDown = curIndexUp;
executed (the execution status of this line is deduced): int curIndexDown = curIndexUp;
-
582 const int count = d->pageList.count();
executed (the execution status of this line is deduced): const int count = d->pageList.count();
-
583 while (curIndexUp > 0 || curIndexDown < count-1) {
evaluated: curIndexUp > 0
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:4
evaluated: curIndexDown < count-1
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:1
1-4
584 if (curIndexDown < count-1) {
evaluated: curIndexDown < count-1
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:1
1-5
585 if (d->page(++curIndexDown)->button->isEnabled()) {
evaluated: d->page(++curIndexDown)->button->isEnabled()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:4
1-4
586 index = curIndexDown;
executed (the execution status of this line is deduced): index = curIndexDown;
-
587 break;
executed: break;
Execution Count:1
1
588 } -
589 }
executed: }
Execution Count:4
4
590 if (curIndexUp > 0) {
evaluated: curIndexUp > 0
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:3
2-3
591 if (d->page(--curIndexUp)->button->isEnabled()) {
evaluated: d->page(--curIndexUp)->button->isEnabled()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
592 index = curIndexUp;
executed (the execution status of this line is deduced): index = curIndexUp;
-
593 break;
executed: break;
Execution Count:1
1
594 } -
595 }
executed: }
Execution Count:1
1
596 }
executed: }
Execution Count:4
4
597 setCurrentIndex(index);
executed (the execution status of this line is deduced): setCurrentIndex(index);
-
598 }
executed: }
Execution Count:3
3
599}
executed: }
Execution Count:5
5
600 -
601 -
602/*! -
603 Sets the text of the item at position \a index to \a text. -
604 -
605 If the provided text contains an ampersand character ('&'), a -
606 mnemonic is automatically created for it. The character that -
607 follows the '&' will be used as the shortcut key. Any previous -
608 mnemonic will be overwritten, or cleared if no mnemonic is defined -
609 by the text. See the \l {QShortcut#mnemonic}{QShortcut} -
610 documentation for details (to display an actual ampersand, use -
611 '&&'). -
612*/ -
613 -
614void QToolBox::setItemText(int index, const QString &text) -
615{ -
616 Q_D(QToolBox);
executed (the execution status of this line is deduced): QToolBoxPrivate * const d = d_func();
-
617 QToolBoxPrivate::Page *c = d->page(index);
executed (the execution status of this line is deduced): QToolBoxPrivate::Page *c = d->page(index);
-
618 if (c)
partially evaluated: c
TRUEFALSE
yes
Evaluation Count:4
no
Evaluation Count:0
0-4
619 c->setText(text);
executed: c->setText(text);
Execution Count:4
4
620}
executed: }
Execution Count:4
4
621 -
622/*! -
623 Sets the icon of the item at position \a index to \a icon. -
624*/ -
625 -
626void QToolBox::setItemIcon(int index, const QIcon &icon) -
627{ -
628 Q_D(QToolBox);
never executed (the execution status of this line is deduced): QToolBoxPrivate * const d = d_func();
-
629 QToolBoxPrivate::Page *c = d->page(index);
never executed (the execution status of this line is deduced): QToolBoxPrivate::Page *c = d->page(index);
-
630 if (c)
never evaluated: c
0
631 c->setIcon(icon);
never executed: c->setIcon(icon);
0
632}
never executed: }
0
633 -
634#ifndef QT_NO_TOOLTIP -
635/*! -
636 Sets the tooltip of the item at position \a index to \a toolTip. -
637*/ -
638 -
639void QToolBox::setItemToolTip(int index, const QString &toolTip) -
640{ -
641 Q_D(QToolBox);
never executed (the execution status of this line is deduced): QToolBoxPrivate * const d = d_func();
-
642 QToolBoxPrivate::Page *c = d->page(index);
never executed (the execution status of this line is deduced): QToolBoxPrivate::Page *c = d->page(index);
-
643 if (c)
never evaluated: c
0
644 c->setToolTip(toolTip);
never executed: c->setToolTip(toolTip);
0
645}
never executed: }
0
646#endif // QT_NO_TOOLTIP -
647 -
648/*! -
649 Returns true if the item at position \a index is enabled; otherwise returns false. -
650*/ -
651 -
652bool QToolBox::isItemEnabled(int index) const -
653{ -
654 Q_D(const QToolBox);
never executed (the execution status of this line is deduced): const QToolBoxPrivate * const d = d_func();
-
655 const QToolBoxPrivate::Page *c = d->page(index);
never executed (the execution status of this line is deduced): const QToolBoxPrivate::Page *c = d->page(index);
-
656 return c && c->button->isEnabled();
never executed: return c && c->button->isEnabled();
0
657} -
658 -
659/*! -
660 Returns the text of the item at position \a index, or an empty string if -
661 \a index is out of range. -
662*/ -
663 -
664QString QToolBox::itemText(int index) const -
665{ -
666 Q_D(const QToolBox);
executed (the execution status of this line is deduced): const QToolBoxPrivate * const d = d_func();
-
667 const QToolBoxPrivate::Page *c = d->page(index);
executed (the execution status of this line is deduced): const QToolBoxPrivate::Page *c = d->page(index);
-
668 return (c ? c->text() : QString());
executed: return (c ? c->text() : QString());
Execution Count:4
4
669} -
670 -
671/*! -
672 Returns the icon of the item at position \a index, or a null -
673 icon if \a index is out of range. -
674*/ -
675 -
676QIcon QToolBox::itemIcon(int index) const -
677{ -
678 Q_D(const QToolBox);
never executed (the execution status of this line is deduced): const QToolBoxPrivate * const d = d_func();
-
679 const QToolBoxPrivate::Page *c = d->page(index);
never executed (the execution status of this line is deduced): const QToolBoxPrivate::Page *c = d->page(index);
-
680 return (c ? c->icon() : QIcon());
never executed: return (c ? c->icon() : QIcon());
0
681} -
682 -
683#ifndef QT_NO_TOOLTIP -
684/*! -
685 Returns the tooltip of the item at position \a index, or an -
686 empty string if \a index is out of range. -
687*/ -
688 -
689QString QToolBox::itemToolTip(int index) const -
690{ -
691 Q_D(const QToolBox);
never executed (the execution status of this line is deduced): const QToolBoxPrivate * const d = d_func();
-
692 const QToolBoxPrivate::Page *c = d->page(index);
never executed (the execution status of this line is deduced): const QToolBoxPrivate::Page *c = d->page(index);
-
693 return (c ? c->toolTip() : QString());
never executed: return (c ? c->toolTip() : QString());
0
694} -
695#endif // QT_NO_TOOLTIP -
696 -
697/*! \reimp */ -
698void QToolBox::showEvent(QShowEvent *e) -
699{ -
700 QWidget::showEvent(e);
executed (the execution status of this line is deduced): QWidget::showEvent(e);
-
701}
executed: }
Execution Count:1
1
702 -
703/*! \reimp */ -
704void QToolBox::changeEvent(QEvent *ev) -
705{ -
706 Q_D(QToolBox);
executed (the execution status of this line is deduced): QToolBoxPrivate * const d = d_func();
-
707 if(ev->type() == QEvent::StyleChange)
partially evaluated: ev->type() == QEvent::StyleChange
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
0-6
708 d->updateTabs();
never executed: d->updateTabs();
0
709 QFrame::changeEvent(ev);
executed (the execution status of this line is deduced): QFrame::changeEvent(ev);
-
710}
executed: }
Execution Count:6
6
711 -
712/*! -
713 This virtual handler is called after a new item was added or -
714 inserted at position \a index. -
715 -
716 \sa itemRemoved() -
717 */ -
718void QToolBox::itemInserted(int index) -
719{ -
720 Q_UNUSED(index)
executed (the execution status of this line is deduced): (void)index;
-
721}
executed: }
Execution Count:22
22
722 -
723/*! -
724 This virtual handler is called after an item was removed from -
725 position \a index. -
726 -
727 \sa itemInserted() -
728 */ -
729void QToolBox::itemRemoved(int index) -
730{ -
731 Q_UNUSED(index)
executed (the execution status of this line is deduced): (void)index;
-
732}
executed: }
Execution Count:3
3
733 -
734/*! \reimp */ -
735bool QToolBox::event(QEvent *e) -
736{ -
737 return QFrame::event(e);
executed: return QFrame::event(e);
Execution Count:160
160
738} -
739 -
740QT_END_NAMESPACE -
741 -
742#include "moc_qtoolbox.cpp" -
743#include "qtoolbox.moc" -
744 -
745#endif //QT_NO_TOOLBOX -
746 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial