QtWidgets: use Q_UNLIKELY for every qWarning() (1)
If, after checking a condition, we issue a qWarning(), by definition that check is unlikely to be true. Tell the compiler so it can move the error handling code out of the normal code path to increase the effective icache size. This change contains the changes to the util/, dialogs/ and widgets/ subdirs. Moved conditional code around where possible so that we could always use Q_UNLIKELY, instead of having to revert to Q_LIKELY here and there. In QSystemTrayIcon::setVisible(), as a drive-by, I swapped the evaluation order of an &&-expression (newly wrapped in Q_UNLIKELY) to be more readable and more efficient (cheaper check first) at the same time. Change-Id: I3564c5a5deacba49d67d3989fb0b53e680c57fcb Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
parent
f5a650735e
commit
496823b9a8
@ -516,7 +516,7 @@ int QDialog::exec()
|
||||
{
|
||||
Q_D(QDialog);
|
||||
|
||||
if (d->eventLoop) {
|
||||
if (Q_UNLIKELY(d->eventLoop)) {
|
||||
qWarning("QDialog::exec: Recursive call detected");
|
||||
return -1;
|
||||
}
|
||||
|
@ -976,7 +976,7 @@ void QFileDialog::setDirectoryUrl(const QUrl &directory)
|
||||
d->setDirectory_sys(directory);
|
||||
else if (directory.isLocalFile())
|
||||
setDirectory(directory.toLocalFile());
|
||||
else if (d->usingWidgets())
|
||||
else if (Q_UNLIKELY(d->usingWidgets()))
|
||||
qWarning("Non-native QFileDialog supports only local files");
|
||||
}
|
||||
|
||||
|
@ -353,7 +353,7 @@ void QProgressDialog::setLabel(QLabel *label)
|
||||
{
|
||||
Q_D(QProgressDialog);
|
||||
if (label == d->label) {
|
||||
if (label)
|
||||
if (Q_UNLIKELY(label))
|
||||
qWarning("QProgressDialog::setLabel: Attempt to set the same label again");
|
||||
return;
|
||||
}
|
||||
@ -402,7 +402,7 @@ void QProgressDialog::setCancelButton(QPushButton *cancelButton)
|
||||
{
|
||||
Q_D(QProgressDialog);
|
||||
if (d->cancel == cancelButton) {
|
||||
if (cancelButton)
|
||||
if (Q_UNLIKELY(cancelButton))
|
||||
qWarning("QProgressDialog::setCancelButton: Attempt to set the same button again");
|
||||
return;
|
||||
}
|
||||
@ -465,16 +465,16 @@ void QProgressDialogPrivate::setCancelButtonText(const QString &cancelButtonText
|
||||
void QProgressDialog::setBar(QProgressBar *bar)
|
||||
{
|
||||
Q_D(QProgressDialog);
|
||||
if (!bar) {
|
||||
if (Q_UNLIKELY(!bar)) {
|
||||
qWarning("QProgressDialog::setBar: Cannot set a null progress bar");
|
||||
return;
|
||||
}
|
||||
#ifndef QT_NO_DEBUG
|
||||
if (value() > 0)
|
||||
if (Q_UNLIKELY(value() > 0))
|
||||
qWarning("QProgressDialog::setBar: Cannot set a new progress bar "
|
||||
"while the old one is active");
|
||||
#endif
|
||||
if (bar == d->bar) {
|
||||
if (Q_UNLIKELY(bar == d->bar)) {
|
||||
qWarning("QProgressDialog::setBar: Attempt to set the same progress bar again");
|
||||
return;
|
||||
}
|
||||
|
@ -799,7 +799,7 @@ void QWizardPrivate::addField(const QWizardField &field)
|
||||
QWizardField myField = field;
|
||||
myField.resolve(defaultPropertyTable);
|
||||
|
||||
if (fieldIndexMap.contains(myField.name)) {
|
||||
if (Q_UNLIKELY(fieldIndexMap.contains(myField.name))) {
|
||||
qWarning("QWizardPage::addField: Duplicate field '%ls'", qUtf16Printable(myField.name));
|
||||
return;
|
||||
}
|
||||
@ -2256,17 +2256,17 @@ void QWizard::setPage(int theid, QWizardPage *page)
|
||||
{
|
||||
Q_D(QWizard);
|
||||
|
||||
if (!page) {
|
||||
if (Q_UNLIKELY(!page)) {
|
||||
qWarning("QWizard::setPage: Cannot insert null page");
|
||||
return;
|
||||
}
|
||||
|
||||
if (theid == -1) {
|
||||
if (Q_UNLIKELY(theid == -1)) {
|
||||
qWarning("QWizard::setPage: Cannot insert page with ID -1");
|
||||
return;
|
||||
}
|
||||
|
||||
if (d->pageMap.contains(theid)) {
|
||||
if (Q_UNLIKELY(d->pageMap.contains(theid))) {
|
||||
qWarning("QWizard::setPage: Page with duplicate ID %d ignored", theid);
|
||||
return;
|
||||
}
|
||||
@ -2450,7 +2450,7 @@ void QWizard::setStartId(int theid)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!d->pageMap.contains(newStart)) {
|
||||
if (Q_UNLIKELY(!d->pageMap.contains(newStart))) {
|
||||
qWarning("QWizard::setStartId: Invalid page ID %d", newStart);
|
||||
return;
|
||||
}
|
||||
@ -2508,15 +2508,15 @@ void QWizard::setField(const QString &name, const QVariant &value)
|
||||
Q_D(QWizard);
|
||||
|
||||
int index = d->fieldIndexMap.value(name, -1);
|
||||
if (index != -1) {
|
||||
const QWizardField &field = d->fields.at(index);
|
||||
if (!field.object->setProperty(field.property, value))
|
||||
qWarning("QWizard::setField: Couldn't write to property '%s'",
|
||||
field.property.constData());
|
||||
if (Q_UNLIKELY(index == -1)) {
|
||||
qWarning("QWizard::setField: No such field '%ls'", qUtf16Printable(name));
|
||||
return;
|
||||
}
|
||||
|
||||
qWarning("QWizard::setField: No such field '%ls'", qUtf16Printable(name));
|
||||
const QWizardField &field = d->fields.at(index);
|
||||
if (Q_UNLIKELY(!field.object->setProperty(field.property, value)))
|
||||
qWarning("QWizard::setField: Couldn't write to property '%s'",
|
||||
field.property.constData());
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -2531,13 +2531,13 @@ QVariant QWizard::field(const QString &name) const
|
||||
Q_D(const QWizard);
|
||||
|
||||
int index = d->fieldIndexMap.value(name, -1);
|
||||
if (index != -1) {
|
||||
const QWizardField &field = d->fields.at(index);
|
||||
return field.object->property(field.property);
|
||||
if (Q_UNLIKELY(index == -1)) {
|
||||
qWarning("QWizard::field: No such field '%ls'", qUtf16Printable(name));
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
qWarning("QWizard::field: No such field '%ls'", qUtf16Printable(name));
|
||||
return QVariant();
|
||||
const QWizardField &field = d->fields.at(index);
|
||||
return field.object->property(field.property);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -2763,7 +2763,7 @@ void QWizard::setButtonLayout(const QList<WizardButton> &layout)
|
||||
// O(n^2), but n is very small
|
||||
for (int j = 0; j < i; ++j) {
|
||||
WizardButton button2 = layout.at(j);
|
||||
if (button2 == button1) {
|
||||
if (Q_UNLIKELY(button2 == button1)) {
|
||||
qWarning("QWizard::setButtonLayout: Duplicate button in layout");
|
||||
return;
|
||||
}
|
||||
@ -3140,11 +3140,11 @@ void QWizard::next()
|
||||
if (validateCurrentPage()) {
|
||||
int next = nextId();
|
||||
if (next != -1) {
|
||||
if (d->history.contains(next)) {
|
||||
if (Q_UNLIKELY(d->history.contains(next))) {
|
||||
qWarning("QWizard::next: Page %d already met", next);
|
||||
return;
|
||||
}
|
||||
if (!d->pageMap.contains(next)) {
|
||||
if (Q_UNLIKELY(!d->pageMap.contains(next))) {
|
||||
qWarning("QWizard::next: No such page %d", next);
|
||||
return;
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ static QColormapPrivate *screenMap = 0;
|
||||
void QColormap::initialize()
|
||||
{
|
||||
screenMap = new QColormapPrivate;
|
||||
if (!QGuiApplication::primaryScreen()) {
|
||||
if (Q_UNLIKELY(!QGuiApplication::primaryScreen())) {
|
||||
qWarning("no screens available, assuming 24-bit color");
|
||||
screenMap->depth = 24;
|
||||
screenMap->mode = QColormap::Direct;
|
||||
|
@ -1144,9 +1144,9 @@ void QCompleter::setFilterMode(Qt::MatchFlags filterMode)
|
||||
if (d->filterMode == filterMode)
|
||||
return;
|
||||
|
||||
if (filterMode != Qt::MatchStartsWith
|
||||
&& filterMode != Qt::MatchContains
|
||||
&& filterMode != Qt::MatchEndsWith) {
|
||||
if (Q_UNLIKELY(filterMode != Qt::MatchStartsWith &&
|
||||
filterMode != Qt::MatchContains &&
|
||||
filterMode != Qt::MatchEndsWith)) {
|
||||
qWarning("Unhandled QCompleter::filterMode flag is used.");
|
||||
return;
|
||||
}
|
||||
@ -1641,7 +1641,7 @@ int QCompleter::maxVisibleItems() const
|
||||
void QCompleter::setMaxVisibleItems(int maxItems)
|
||||
{
|
||||
Q_D(QCompleter);
|
||||
if (maxItems < 0) {
|
||||
if (Q_UNLIKELY(maxItems < 0)) {
|
||||
qWarning("QCompleter::setMaxVisibleItems: "
|
||||
"Invalid max visible items (%d) must be >= 0", maxItems);
|
||||
return;
|
||||
|
@ -159,8 +159,8 @@ static qreal differentialForProgress(const QEasingCurve &curve, qreal pos)
|
||||
|
||||
static qreal progressForValue(const QEasingCurve &curve, qreal value)
|
||||
{
|
||||
if (curve.type() >= QEasingCurve::InElastic &&
|
||||
curve.type() < QEasingCurve::Custom) {
|
||||
if (Q_UNLIKELY(curve.type() >= QEasingCurve::InElastic &&
|
||||
curve.type() < QEasingCurve::Custom)) {
|
||||
qWarning("progressForValue(): QEasingCurves of type %d do not have an inverse, since they are not injective.", curve.type());
|
||||
return value;
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ void QSystemTrayIcon::setVisible(bool visible)
|
||||
Q_D(QSystemTrayIcon);
|
||||
if (visible == d->visible)
|
||||
return;
|
||||
if (d->icon.isNull() && visible)
|
||||
if (Q_UNLIKELY(visible && d->icon.isNull()))
|
||||
qWarning("QSystemTrayIcon::setVisible: No Icon set");
|
||||
d->visible = visible;
|
||||
if (d->visible)
|
||||
|
@ -633,7 +633,7 @@ void QUndoStack::push(QUndoCommand *cmd)
|
||||
void QUndoStack::setClean()
|
||||
{
|
||||
Q_D(QUndoStack);
|
||||
if (!d->macro_stack.isEmpty()) {
|
||||
if (Q_UNLIKELY(!d->macro_stack.isEmpty())) {
|
||||
qWarning("QUndoStack::setClean(): cannot set clean in the middle of a macro");
|
||||
return;
|
||||
}
|
||||
@ -688,7 +688,7 @@ void QUndoStack::undo()
|
||||
if (d->index == 0)
|
||||
return;
|
||||
|
||||
if (!d->macro_stack.isEmpty()) {
|
||||
if (Q_UNLIKELY(!d->macro_stack.isEmpty())) {
|
||||
qWarning("QUndoStack::undo(): cannot undo in the middle of a macro");
|
||||
return;
|
||||
}
|
||||
@ -714,7 +714,7 @@ void QUndoStack::redo()
|
||||
if (d->index == d->command_list.size())
|
||||
return;
|
||||
|
||||
if (!d->macro_stack.isEmpty()) {
|
||||
if (Q_UNLIKELY(!d->macro_stack.isEmpty())) {
|
||||
qWarning("QUndoStack::redo(): cannot redo in the middle of a macro");
|
||||
return;
|
||||
}
|
||||
@ -761,7 +761,7 @@ int QUndoStack::index() const
|
||||
void QUndoStack::setIndex(int idx)
|
||||
{
|
||||
Q_D(QUndoStack);
|
||||
if (!d->macro_stack.isEmpty()) {
|
||||
if (Q_UNLIKELY(!d->macro_stack.isEmpty())) {
|
||||
qWarning("QUndoStack::setIndex(): cannot set index in the middle of a macro");
|
||||
return;
|
||||
}
|
||||
@ -981,7 +981,7 @@ void QUndoStack::beginMacro(const QString &text)
|
||||
void QUndoStack::endMacro()
|
||||
{
|
||||
Q_D(QUndoStack);
|
||||
if (d->macro_stack.isEmpty()) {
|
||||
if (Q_UNLIKELY(d->macro_stack.isEmpty())) {
|
||||
qWarning("QUndoStack::endMacro(): no matching beginMacro()");
|
||||
return;
|
||||
}
|
||||
@ -1049,7 +1049,7 @@ void QUndoStack::setUndoLimit(int limit)
|
||||
{
|
||||
Q_D(QUndoStack);
|
||||
|
||||
if (!d->command_list.isEmpty()) {
|
||||
if (Q_UNLIKELY(!d->command_list.isEmpty())) {
|
||||
qWarning("QUndoStack::setUndoLimit(): an undo limit can only be set when the stack is empty");
|
||||
return;
|
||||
}
|
||||
|
@ -705,7 +705,7 @@ QScrollBar *QAbstractScrollArea::verticalScrollBar() const
|
||||
void QAbstractScrollArea::setVerticalScrollBar(QScrollBar *scrollBar)
|
||||
{
|
||||
Q_D(QAbstractScrollArea);
|
||||
if (!scrollBar) {
|
||||
if (Q_UNLIKELY(!scrollBar)) {
|
||||
qWarning("QAbstractScrollArea::setVerticalScrollBar: Cannot set a null scroll bar");
|
||||
return;
|
||||
}
|
||||
@ -766,7 +766,7 @@ QScrollBar *QAbstractScrollArea::horizontalScrollBar() const
|
||||
void QAbstractScrollArea::setHorizontalScrollBar(QScrollBar *scrollBar)
|
||||
{
|
||||
Q_D(QAbstractScrollArea);
|
||||
if (!scrollBar) {
|
||||
if (Q_UNLIKELY(!scrollBar)) {
|
||||
qWarning("QAbstractScrollArea::setHorizontalScrollBar: Cannot set a null scroll bar");
|
||||
return;
|
||||
}
|
||||
|
@ -1931,7 +1931,7 @@ void QSpinBoxValidator::fixup(QString &input) const
|
||||
QVariant operator+(const QVariant &arg1, const QVariant &arg2)
|
||||
{
|
||||
QVariant ret;
|
||||
if (arg1.type() != arg2.type())
|
||||
if (Q_UNLIKELY(arg1.type() != arg2.type()))
|
||||
qWarning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)",
|
||||
arg1.typeName(), arg2.typeName(), __FILE__, __LINE__);
|
||||
switch (arg1.type()) {
|
||||
@ -1970,7 +1970,7 @@ QVariant operator+(const QVariant &arg1, const QVariant &arg2)
|
||||
QVariant operator-(const QVariant &arg1, const QVariant &arg2)
|
||||
{
|
||||
QVariant ret;
|
||||
if (arg1.type() != arg2.type())
|
||||
if (Q_UNLIKELY(arg1.type() != arg2.type()))
|
||||
qWarning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)",
|
||||
arg1.typeName(), arg2.typeName(), __FILE__, __LINE__);
|
||||
switch (arg1.type()) {
|
||||
|
@ -2917,7 +2917,7 @@ void QCalendarWidget::setDateEditAcceptDelay(int delay)
|
||||
*/
|
||||
void QCalendarWidget::updateCell(const QDate &date)
|
||||
{
|
||||
if (!date.isValid()) {
|
||||
if (Q_UNLIKELY(!date.isValid())) {
|
||||
qWarning("QCalendarWidget::updateCell: Invalid date");
|
||||
return;
|
||||
}
|
||||
|
@ -1360,7 +1360,7 @@ int QComboBox::maxVisibleItems() const
|
||||
void QComboBox::setMaxVisibleItems(int maxItems)
|
||||
{
|
||||
Q_D(QComboBox);
|
||||
if (maxItems < 0) {
|
||||
if (Q_UNLIKELY(maxItems < 0)) {
|
||||
qWarning("QComboBox::setMaxVisibleItems: "
|
||||
"Invalid max visible items (%d) must be >= 0", maxItems);
|
||||
return;
|
||||
@ -1395,7 +1395,7 @@ int QComboBox::count() const
|
||||
void QComboBox::setMaxCount(int max)
|
||||
{
|
||||
Q_D(QComboBox);
|
||||
if (max < 0) {
|
||||
if (Q_UNLIKELY(max < 0)) {
|
||||
qWarning("QComboBox::setMaxCount: Invalid count (%d) must be >= 0", max);
|
||||
return;
|
||||
}
|
||||
@ -1448,7 +1448,7 @@ void QComboBox::setAutoCompletion(bool enable)
|
||||
Q_D(QComboBox);
|
||||
|
||||
#ifdef QT_KEYPAD_NAVIGATION
|
||||
if (QApplication::keypadNavigationEnabled() && !enable && isEditable())
|
||||
if (Q_UNLIKELY(QApplication::keypadNavigationEnabled() && !enable && isEditable()))
|
||||
qWarning("QComboBox::setAutoCompletion: auto completion is mandatory when combo box editable");
|
||||
#endif
|
||||
|
||||
@ -1758,7 +1758,7 @@ void QComboBox::setEditable(bool editable)
|
||||
void QComboBox::setLineEdit(QLineEdit *edit)
|
||||
{
|
||||
Q_D(QComboBox);
|
||||
if (!edit) {
|
||||
if (Q_UNLIKELY(!edit)) {
|
||||
qWarning("QComboBox::setLineEdit: cannot set a 0 line edit");
|
||||
return;
|
||||
}
|
||||
@ -1917,7 +1917,7 @@ QAbstractItemDelegate *QComboBox::itemDelegate() const
|
||||
*/
|
||||
void QComboBox::setItemDelegate(QAbstractItemDelegate *delegate)
|
||||
{
|
||||
if (!delegate) {
|
||||
if (Q_UNLIKELY(!delegate)) {
|
||||
qWarning("QComboBox::setItemDelegate: cannot set a 0 delegate");
|
||||
return;
|
||||
}
|
||||
@ -1949,7 +1949,7 @@ void QComboBox::setModel(QAbstractItemModel *model)
|
||||
{
|
||||
Q_D(QComboBox);
|
||||
|
||||
if (!model) {
|
||||
if (Q_UNLIKELY(!model)) {
|
||||
qWarning("QComboBox::setModel: cannot set a 0 model");
|
||||
return;
|
||||
}
|
||||
@ -2395,7 +2395,7 @@ QAbstractItemView *QComboBox::view() const
|
||||
void QComboBox::setView(QAbstractItemView *itemView)
|
||||
{
|
||||
Q_D(QComboBox);
|
||||
if (!itemView) {
|
||||
if (Q_UNLIKELY(!itemView)) {
|
||||
qWarning("QComboBox::setView: cannot set a 0 view");
|
||||
return;
|
||||
}
|
||||
|
@ -760,17 +760,17 @@ QCalendarWidget *QDateTimeEdit::calendarWidget() const
|
||||
void QDateTimeEdit::setCalendarWidget(QCalendarWidget *calendarWidget)
|
||||
{
|
||||
Q_D(QDateTimeEdit);
|
||||
if (!calendarWidget) {
|
||||
if (Q_UNLIKELY(!calendarWidget)) {
|
||||
qWarning("QDateTimeEdit::setCalendarWidget: Cannot set a null calendar widget");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!d->calendarPopup) {
|
||||
if (Q_UNLIKELY(!d->calendarPopup)) {
|
||||
qWarning("QDateTimeEdit::setCalendarWidget: calendarPopup is set to false");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(d->display & QDateTimeParser::DateSectionMask)) {
|
||||
if (Q_UNLIKELY(!(d->display & QDateTimeParser::DateSectionMask))) {
|
||||
qWarning("QDateTimeEdit::setCalendarWidget: no date sections specified");
|
||||
return;
|
||||
}
|
||||
@ -1864,7 +1864,7 @@ void QDateTimeEditPrivate::clearSection(int index)
|
||||
const QSignalBlocker blocker(edit);
|
||||
QString t = edit->text();
|
||||
const int pos = sectionPos(index);
|
||||
if (pos == -1) {
|
||||
if (Q_UNLIKELY(pos == -1)) {
|
||||
qWarning("QDateTimeEdit: Internal error (%s:%d)", __FILE__, __LINE__);
|
||||
return;
|
||||
}
|
||||
|
@ -405,11 +405,10 @@ QPushButton *QDialogButtonBoxPrivate::createButton(QDialogButtonBox::StandardBut
|
||||
button->setStyle(style);
|
||||
standardButtonHash.insert(button, sbutton);
|
||||
QPlatformDialogHelper::ButtonRole role = QPlatformDialogHelper::buttonRole(static_cast<QPlatformDialogHelper::StandardButton>(sbutton));
|
||||
if (role != QPlatformDialogHelper::InvalidRole) {
|
||||
addButton(button, static_cast<QDialogButtonBox::ButtonRole>(role), doLayout);
|
||||
} else {
|
||||
if (Q_UNLIKELY(role == QPlatformDialogHelper::InvalidRole))
|
||||
qWarning("QDialogButtonBox::createButton: Invalid ButtonRole, button not added");
|
||||
}
|
||||
else
|
||||
addButton(button, static_cast<QDialogButtonBox::ButtonRole>(role), doLayout);
|
||||
|
||||
#ifdef Q_DEAD_CODE_FROM_QT4_MAC
|
||||
// Since mnemonics is off by default on Mac, we add a Cmd-D
|
||||
@ -753,7 +752,7 @@ void QDialogButtonBox::removeButton(QAbstractButton *button)
|
||||
void QDialogButtonBox::addButton(QAbstractButton *button, ButtonRole role)
|
||||
{
|
||||
Q_D(QDialogButtonBox);
|
||||
if (role <= InvalidRole || role >= NRoles) {
|
||||
if (Q_UNLIKELY(role <= InvalidRole || role >= NRoles)) {
|
||||
qWarning("QDialogButtonBox::addButton: Invalid ButtonRole, button not added");
|
||||
return;
|
||||
}
|
||||
@ -772,7 +771,7 @@ void QDialogButtonBox::addButton(QAbstractButton *button, ButtonRole role)
|
||||
QPushButton *QDialogButtonBox::addButton(const QString &text, ButtonRole role)
|
||||
{
|
||||
Q_D(QDialogButtonBox);
|
||||
if (role <= InvalidRole || role >= NRoles) {
|
||||
if (Q_UNLIKELY(role <= InvalidRole || role >= NRoles)) {
|
||||
qWarning("QDialogButtonBox::addButton: Invalid ButtonRole, button not added");
|
||||
return 0;
|
||||
}
|
||||
|
@ -1802,7 +1802,7 @@ void QDockAreaLayoutInfo::saveState(QDataStream &stream) const
|
||||
stream << (uchar) WidgetMarker;
|
||||
QWidget *w = item.widgetItem->widget();
|
||||
QString name = w->objectName();
|
||||
if (name.isEmpty()) {
|
||||
if (Q_UNLIKELY(name.isEmpty())) {
|
||||
qWarning("QMainWindow::saveState(): 'objectName' not set for QDockWidget %p '%ls;",
|
||||
w, qUtf16Printable(w->windowTitle()));
|
||||
}
|
||||
@ -3109,7 +3109,7 @@ void QDockAreaLayout::tabifyDockWidget(QDockWidget *first, QDockWidget *second)
|
||||
void QDockAreaLayout::resizeDocks(const QList<QDockWidget *> &docks,
|
||||
const QList<int> &sizes, Qt::Orientation o)
|
||||
{
|
||||
if (docks.count() != sizes.count()) {
|
||||
if (Q_UNLIKELY(docks.count() != sizes.count())) {
|
||||
qWarning("QMainWidget::resizeDocks: size of the lists are not the same");
|
||||
return;
|
||||
}
|
||||
@ -3117,12 +3117,12 @@ void QDockAreaLayout::resizeDocks(const QList<QDockWidget *> &docks,
|
||||
fallbackToSizeHints = false;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
QList<int> path = indexOf(docks[i]);
|
||||
if (path.isEmpty()) {
|
||||
if (Q_UNLIKELY(path.isEmpty())) {
|
||||
qWarning("QMainWidget::resizeDocks: one QDockWidget is not part of the layout");
|
||||
continue;
|
||||
}
|
||||
int size = sizes[i];
|
||||
if (size <= 0) {
|
||||
if (Q_UNLIKELY(size <= 0)) {
|
||||
qWarning("QMainWidget::resizeDocks: all sizes need to be larger than 0");
|
||||
size = 1;
|
||||
}
|
||||
|
@ -402,12 +402,12 @@ QLCDNumber::~QLCDNumber()
|
||||
void QLCDNumber::setDigitCount(int numDigits)
|
||||
{
|
||||
Q_D(QLCDNumber);
|
||||
if (numDigits > 99) {
|
||||
if (Q_UNLIKELY(numDigits > 99)) {
|
||||
qWarning("QLCDNumber::setNumDigits: (%s) Max 99 digits allowed",
|
||||
objectName().toLocal8Bit().constData());
|
||||
numDigits = 99;
|
||||
}
|
||||
if (numDigits < 0) {
|
||||
if (Q_UNLIKELY(numDigits < 0)) {
|
||||
qWarning("QLCDNumber::setNumDigits: (%s) Min 0 digits allowed",
|
||||
objectName().toLocal8Bit().constData());
|
||||
numDigits = 0;
|
||||
|
@ -982,7 +982,7 @@ int QLineEdit::selectionStart() const
|
||||
void QLineEdit::setSelection(int start, int length)
|
||||
{
|
||||
Q_D(QLineEdit);
|
||||
if (start < 0 || start > (int)d->control->end()) {
|
||||
if (Q_UNLIKELY(start < 0 || start > (int)d->control->end())) {
|
||||
qWarning("QLineEdit::setSelection: Invalid start position (%d)", start);
|
||||
return;
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ inline QPlatformNativeInterface::NativeResourceForIntegrationFunction resolvePla
|
||||
QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
|
||||
QPlatformNativeInterface::NativeResourceForIntegrationFunction function =
|
||||
nativeInterface->nativeResourceFunctionForIntegration(functionName);
|
||||
if (!function)
|
||||
if (Q_UNLIKELY(!function))
|
||||
qWarning() << "Qt could not resolve function" << functionName
|
||||
<< "from QGuiApplication::platformNativeInterface()->nativeResourceFunctionForIntegration()";
|
||||
return function;
|
||||
|
@ -82,7 +82,7 @@ inline QPlatformNativeInterface::NativeResourceForIntegrationFunction resolvePla
|
||||
QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
|
||||
QPlatformNativeInterface::NativeResourceForIntegrationFunction function =
|
||||
nativeInterface->nativeResourceFunctionForIntegration(functionName);
|
||||
if (!function)
|
||||
if (Q_UNLIKELY(!function))
|
||||
qWarning() << "Qt could not resolve function" << functionName
|
||||
<< "from QGuiApplication::platformNativeInterface()->nativeResourceFunctionForIntegration()";
|
||||
return function;
|
||||
|
@ -693,7 +693,7 @@ void QMainWindow::setCorner(Qt::Corner corner, Qt::DockWidgetArea area)
|
||||
valid = (area == Qt::BottomDockWidgetArea || area == Qt::RightDockWidgetArea);
|
||||
break;
|
||||
}
|
||||
if (!valid)
|
||||
if (Q_UNLIKELY(!valid))
|
||||
qWarning("QMainWindow::setCorner(): 'area' is not valid for 'corner'");
|
||||
else
|
||||
d_func()->layout->setCorner(corner, area);
|
||||
|
@ -179,7 +179,7 @@ using namespace QMdi;
|
||||
// Asserts in debug mode, gives warning otherwise.
|
||||
static bool sanityCheck(const QMdiSubWindow * const child, const char *where)
|
||||
{
|
||||
if (!child) {
|
||||
if (Q_UNLIKELY(!child)) {
|
||||
const char error[] = "null pointer";
|
||||
Q_ASSERT_X(false, where, error);
|
||||
qWarning("%s:%s", where, error);
|
||||
@ -190,13 +190,13 @@ static bool sanityCheck(const QMdiSubWindow * const child, const char *where)
|
||||
|
||||
static bool sanityCheck(const QList<QWidget *> &widgets, const int index, const char *where)
|
||||
{
|
||||
if (index < 0 || index >= widgets.size()) {
|
||||
if (Q_UNLIKELY(index < 0 || index >= widgets.size())) {
|
||||
const char error[] = "index out of range";
|
||||
Q_ASSERT_X(false, where, error);
|
||||
qWarning("%s:%s", where, error);
|
||||
return false;
|
||||
}
|
||||
if (!widgets.at(index)) {
|
||||
if (Q_UNLIKELY(!widgets.at(index))) {
|
||||
const char error[] = "null pointer";
|
||||
Q_ASSERT_X(false, where, error);
|
||||
qWarning("%s:%s", where, error);
|
||||
@ -1831,12 +1831,12 @@ void QMdiArea::setActiveSubWindow(QMdiSubWindow *window)
|
||||
return;
|
||||
}
|
||||
|
||||
if (d->childWindows.isEmpty()) {
|
||||
if (Q_UNLIKELY(d->childWindows.isEmpty())) {
|
||||
qWarning("QMdiArea::setActiveSubWindow: workspace is empty");
|
||||
return;
|
||||
}
|
||||
|
||||
if (d->childWindows.indexOf(window) == -1) {
|
||||
if (Q_UNLIKELY(d->childWindows.indexOf(window) == -1)) {
|
||||
qWarning("QMdiArea::setActiveSubWindow: window is not inside workspace");
|
||||
return;
|
||||
}
|
||||
@ -1960,7 +1960,7 @@ void QMdiArea::activatePreviousSubWindow()
|
||||
*/
|
||||
QMdiSubWindow *QMdiArea::addSubWindow(QWidget *widget, Qt::WindowFlags windowFlags)
|
||||
{
|
||||
if (!widget) {
|
||||
if (Q_UNLIKELY(!widget)) {
|
||||
qWarning("QMdiArea::addSubWindow: null pointer to widget");
|
||||
return 0;
|
||||
}
|
||||
@ -1972,7 +1972,7 @@ QMdiSubWindow *QMdiArea::addSubWindow(QWidget *widget, Qt::WindowFlags windowFla
|
||||
|
||||
// Widget is already a QMdiSubWindow
|
||||
if (child) {
|
||||
if (d->childWindows.indexOf(child) != -1) {
|
||||
if (Q_UNLIKELY(d->childWindows.indexOf(child) != -1)) {
|
||||
qWarning("QMdiArea::addSubWindow: window is already added");
|
||||
return child;
|
||||
}
|
||||
@ -2003,7 +2003,7 @@ QMdiSubWindow *QMdiArea::addSubWindow(QWidget *widget, Qt::WindowFlags windowFla
|
||||
*/
|
||||
void QMdiArea::removeSubWindow(QWidget *widget)
|
||||
{
|
||||
if (!widget) {
|
||||
if (Q_UNLIKELY(!widget)) {
|
||||
qWarning("QMdiArea::removeSubWindow: null pointer to widget");
|
||||
return;
|
||||
}
|
||||
@ -2014,7 +2014,7 @@ void QMdiArea::removeSubWindow(QWidget *widget)
|
||||
|
||||
if (QMdiSubWindow *child = qobject_cast<QMdiSubWindow *>(widget)) {
|
||||
int index = d->childWindows.indexOf(child);
|
||||
if (index == -1) {
|
||||
if (Q_UNLIKELY(index == -1)) {
|
||||
qWarning("QMdiArea::removeSubWindow: window is not inside workspace");
|
||||
return;
|
||||
}
|
||||
@ -2038,7 +2038,7 @@ void QMdiArea::removeSubWindow(QWidget *widget)
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
if (Q_UNLIKELY(!found))
|
||||
qWarning("QMdiArea::removeSubWindow: widget is not child of any window inside QMdiArea");
|
||||
}
|
||||
|
||||
|
@ -2309,7 +2309,7 @@ void QMdiSubWindow::setWidget(QWidget *widget)
|
||||
return;
|
||||
}
|
||||
|
||||
if (widget == d->baseWidget) {
|
||||
if (Q_UNLIKELY(widget == d->baseWidget)) {
|
||||
qWarning("QMdiSubWindow::setWidget: widget is already set");
|
||||
return;
|
||||
}
|
||||
@ -2507,7 +2507,7 @@ void QMdiSubWindow::setKeyboardPageStep(int step)
|
||||
void QMdiSubWindow::setSystemMenu(QMenu *systemMenu)
|
||||
{
|
||||
Q_D(QMdiSubWindow);
|
||||
if (systemMenu && systemMenu == d->systemMenu) {
|
||||
if (Q_UNLIKELY(systemMenu && systemMenu == d->systemMenu)) {
|
||||
qWarning("QMdiSubWindow::setSystemMenu: system menu is already set");
|
||||
return;
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ inline QPlatformNativeInterface::NativeResourceForIntegrationFunction resolvePla
|
||||
QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
|
||||
QPlatformNativeInterface::NativeResourceForIntegrationFunction function =
|
||||
nativeInterface->nativeResourceFunctionForIntegration(functionName);
|
||||
if (!function)
|
||||
if (Q_UNLIKELY(!function))
|
||||
qWarning() << "Qt could not resolve function" << functionName
|
||||
<< "from QGuiApplication::platformNativeInterface()->nativeResourceFunctionForIntegration()";
|
||||
return function;
|
||||
|
@ -1291,7 +1291,7 @@ void QPlainTextEdit::setDocument(QTextDocument *document)
|
||||
document->setDocumentLayout(documentLayout);
|
||||
} else {
|
||||
documentLayout = qobject_cast<QPlainTextDocumentLayout*>(document->documentLayout());
|
||||
if (!documentLayout) {
|
||||
if (Q_UNLIKELY(!documentLayout)) {
|
||||
qWarning("QPlainTextEdit::setDocument: Document set does not support QPlainTextDocumentLayout");
|
||||
return;
|
||||
}
|
||||
|
@ -438,7 +438,7 @@ void QSpinBox::setDisplayIntegerBase(int base)
|
||||
{
|
||||
Q_D(QSpinBox);
|
||||
// Falls back to base 10 on invalid bases (like QString)
|
||||
if (base < 2 || base > 36) {
|
||||
if (Q_UNLIKELY(base < 2 || base > 36)) {
|
||||
qWarning("QSpinBox::setDisplayIntegerBase: Invalid base (%d)", base);
|
||||
base = 10;
|
||||
}
|
||||
|
@ -1058,7 +1058,7 @@ void QSplitter::setCollapsible(int index, bool collapse)
|
||||
{
|
||||
Q_D(QSplitter);
|
||||
|
||||
if (index < 0 || index >= d->list.size()) {
|
||||
if (Q_UNLIKELY(index < 0 || index >= d->list.size())) {
|
||||
qWarning("QSplitter::setCollapsible: Index %d out of range", index);
|
||||
return;
|
||||
}
|
||||
@ -1071,7 +1071,7 @@ void QSplitter::setCollapsible(int index, bool collapse)
|
||||
bool QSplitter::isCollapsible(int index) const
|
||||
{
|
||||
Q_D(const QSplitter);
|
||||
if (index < 0 || index >= d->list.size()) {
|
||||
if (Q_UNLIKELY(index < 0 || index >= d->list.size())) {
|
||||
qWarning("QSplitter::isCollapsible: Index %d out of range", index);
|
||||
return false;
|
||||
}
|
||||
@ -1215,7 +1215,7 @@ void QSplitter::childEvent(QChildEvent *c)
|
||||
{
|
||||
Q_D(QSplitter);
|
||||
if (!c->child()->isWidgetType()) {
|
||||
if (c->type() == QEvent::ChildAdded && qobject_cast<QLayout *>(c->child()))
|
||||
if (Q_UNLIKELY(c->type() == QEvent::ChildAdded && qobject_cast<QLayout *>(c->child())))
|
||||
qWarning("Adding a QLayout to a QSplitter is not supported.");
|
||||
return;
|
||||
}
|
||||
|
@ -237,7 +237,7 @@ QWidget *QStackedWidget::currentWidget() const
|
||||
void QStackedWidget::setCurrentWidget(QWidget *widget)
|
||||
{
|
||||
Q_D(QStackedWidget);
|
||||
if (d->layout->indexOf(widget) == -1) {
|
||||
if (Q_UNLIKELY(d->layout->indexOf(widget) == -1)) {
|
||||
qWarning("QStackedWidget::setCurrentWidget: widget %p not contained in stack", widget);
|
||||
return;
|
||||
}
|
||||
|
@ -296,7 +296,7 @@ int QStatusBar::insertWidget(int index, QWidget *widget, int stretch)
|
||||
QStatusBarPrivate::SBItem* item = new QStatusBarPrivate::SBItem(widget, stretch, false);
|
||||
|
||||
int idx = d->indexToLastNonPermanentWidget();
|
||||
if (index < 0 || index > d->items.size() || (idx >= 0 && index > idx + 1)) {
|
||||
if (Q_UNLIKELY(index < 0 || index > d->items.size() || (idx >= 0 && index > idx + 1))) {
|
||||
qWarning("QStatusBar::insertWidget: Index out of range (%d), appending widget", index);
|
||||
index = idx + 1;
|
||||
}
|
||||
@ -361,7 +361,7 @@ int QStatusBar::insertPermanentWidget(int index, QWidget *widget, int stretch)
|
||||
QStatusBarPrivate::SBItem* item = new QStatusBarPrivate::SBItem(widget, stretch, true);
|
||||
|
||||
int idx = d->indexToLastNonPermanentWidget();
|
||||
if (index < 0 || index > d->items.size() || (idx >= 0 && index <= idx)) {
|
||||
if (Q_UNLIKELY(index < 0 || index > d->items.size() || (idx >= 0 && index <= idx))) {
|
||||
qWarning("QStatusBar::insertPermanentWidget: Index out of range (%d), appending widget", index);
|
||||
index = d->items.size();
|
||||
}
|
||||
|
@ -292,7 +292,7 @@ void QTextBrowserPrivate::setSource(const QUrl &url)
|
||||
txt = data.toString();
|
||||
#endif
|
||||
}
|
||||
if (txt.isEmpty())
|
||||
if (Q_UNLIKELY(txt.isEmpty()))
|
||||
qWarning("QTextBrowser: No document for %s", url.toString().toLatin1().constData());
|
||||
|
||||
if (q->isVisible()) {
|
||||
|
@ -1128,7 +1128,7 @@ QRect QToolBarAreaLayout::itemRect(const QList<int> &path) const
|
||||
QLayoutItem *QToolBarAreaLayout::plug(const QList<int> &path)
|
||||
{
|
||||
QToolBarAreaLayoutItem *item = this->item(path);
|
||||
if (!item) {
|
||||
if (Q_UNLIKELY(!item)) {
|
||||
qWarning() << Q_FUNC_INFO << "No item at" << path;
|
||||
return 0;
|
||||
}
|
||||
@ -1260,7 +1260,7 @@ void QToolBarAreaLayout::saveState(QDataStream &stream) const
|
||||
const QToolBarAreaLayoutItem &item = line.toolBarItems.at(k);
|
||||
QWidget *widget = const_cast<QLayoutItem*>(item.widgetItem)->widget();
|
||||
QString objectName = widget->objectName();
|
||||
if (objectName.isEmpty()) {
|
||||
if (Q_UNLIKELY(objectName.isEmpty())) {
|
||||
qWarning("QMainWindow::saveState(): 'objectName' not set for QToolBar %p '%s'",
|
||||
widget, widget->windowTitle().toLocal8Bit().constData());
|
||||
}
|
||||
|
@ -521,10 +521,10 @@ QWidget * QToolBox::currentWidget() const
|
||||
void QToolBox::setCurrentWidget(QWidget *widget)
|
||||
{
|
||||
int i = indexOf(widget);
|
||||
if (i >= 0)
|
||||
setCurrentIndex(i);
|
||||
else
|
||||
if (Q_UNLIKELY(i < 0))
|
||||
qWarning("QToolBox::setCurrentWidget: widget not contained in tool box");
|
||||
else
|
||||
setCurrentIndex(i);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -309,7 +309,7 @@ void QWidgetLineControl::setSelection(int start, int length)
|
||||
{
|
||||
commitPreedit();
|
||||
|
||||
if(start < 0 || start > (int)m_text.length()){
|
||||
if (Q_UNLIKELY(start < 0 || start > m_text.size())) {
|
||||
qWarning("QWidgetLineControl::setSelection: Invalid start position");
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user