diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-06-04 13:52:47 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-06-05 10:42:31 +0200 |
commit | 3912157208a91f47274645e3e14a918438816c1d (patch) | |
tree | 69184514145d98386c3508be906706ae810edc76 | |
parent | 6b98a4915042a97058d51257d51befed9a364c86 (diff) | |
download | qttools-3912157208a91f47274645e3e14a918438816c1d.tar.gz |
Qt Designer: Fix some clang warnings
- else after return/break
- Misleading indentation
- Use reference for const-copies
- Mixing const/non-const iterators
- Unnecessary pointer check before delete
- Unhandled enum value
Change-Id: Iecc684d4acf4284b2cd6b1dbd14e392db7ea580c
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
13 files changed, 44 insertions, 53 deletions
diff --git a/src/designer/src/components/formeditor/qdesigner_resource.cpp b/src/designer/src/components/formeditor/qdesigner_resource.cpp index bfb86ee33..4b747d04c 100644 --- a/src/designer/src/components/formeditor/qdesigner_resource.cpp +++ b/src/designer/src/components/formeditor/qdesigner_resource.cpp @@ -278,7 +278,7 @@ DomProperty *QDesignerResourceBuilder::saveResource(const QDir &workingDirectory const QIcon::Mode mode = itPix.key().first; const QIcon::State state = itPix.key().second; DomResourcePixmap *rp = new DomResourcePixmap; - const PropertySheetPixmapValue pix = itPix.value(); + const PropertySheetPixmapValue &pix = itPix.value(); const PropertySheetPixmapValue::PixmapSource ps = pix.pixmapSource(m_core); const QString pixPath = pix.path(); rp->setText(ps == PropertySheetPixmapValue::FilePixmap && m_saveRelative ? workingDirectory.relativeFilePath(pixPath) : pixPath); @@ -1101,12 +1101,10 @@ DomWidget *QDesignerResource::createDom(QWidget *widget, DomWidget *ui_parentWid while (customInfo && customInfo->isCustom()) { m_usedCustomWidgets.insert(customInfo, true); const QString extends = customInfo->extends(); - if (extends == customInfo->name()) { + if (extends == customInfo->name()) break; // There are faulty files around that have name==extends - } else { - const int extendsIndex = wdb->indexOfClassName(customInfo->extends()); - customInfo = extendsIndex != -1 ? wdb->item(extendsIndex) : nullptr; - } + const int extendsIndex = wdb->indexOfClassName(customInfo->extends()); + customInfo = extendsIndex != -1 ? wdb->item(extendsIndex) : nullptr; } } @@ -1582,7 +1580,8 @@ bool QDesignerResource::addItem(DomLayoutItem *ui_item, QLayoutItem *item, QLayo const int colSpan = ui_item->hasAttributeColSpan() ? ui_item->attributeColSpan() : 1; grid->addWidget(item->widget(), ui_item->attributeRow(), ui_item->attributeColumn(), rowSpan, colSpan, item->alignment()); return true; - } else if (box != nullptr) { + } + if (box != nullptr) { box->addItem(item); return true; } @@ -1997,7 +1996,8 @@ DomProperty *QDesignerResource::createProperty(QObject *object, const QString &p p->setAttributeName(propertyName); return applyProperStdSetAttribute(object, propertyName, p); - } else if (value.canConvert<PropertySheetStringListValue>()) { + } + if (value.canConvert<PropertySheetStringListValue>()) { const PropertySheetStringListValue listValue = qvariant_cast<PropertySheetStringListValue>(value); DomProperty *p = new DomProperty; if (!hasSetter(core(), object, propertyName)) @@ -2010,7 +2010,8 @@ DomProperty *QDesignerResource::createProperty(QObject *object, const QString &p translationParametersToDom(listValue, domStringList); p->setElementStringList(domStringList); return applyProperStdSetAttribute(object, propertyName, p); - } else if (value.canConvert<PropertySheetKeySequenceValue>()) { + } + if (value.canConvert<PropertySheetKeySequenceValue>()) { const PropertySheetKeySequenceValue keyVal = qvariant_cast<PropertySheetKeySequenceValue>(value); DomProperty *p = stringToDomProperty(keyVal.value().toString(), keyVal); if (!hasSetter(core(), object, propertyName)) diff --git a/src/designer/src/components/propertyeditor/propertyeditor.cpp b/src/designer/src/components/propertyeditor/propertyeditor.cpp index 3f1e97981..af590a7d5 100644 --- a/src/designer/src/components/propertyeditor/propertyeditor.cpp +++ b/src/designer/src/components/propertyeditor/propertyeditor.cpp @@ -224,7 +224,7 @@ PropertyEditor::PropertyEditor(QDesignerFormEditorInterface *core, QWidget *pare m_colors.reserve(colors.count()); const int darknessFactor = 250; for (int i = 0; i < colors.count(); i++) { - QColor c = colors.at(i); + const QColor &c = colors.at(i); m_colors.push_back(qMakePair(c, c.darker(darknessFactor))); } QColor dynamicColor(191, 207, 255); @@ -1057,7 +1057,7 @@ void PropertyEditor::setObject(QObject *object) QtVariantProperty *groupProperty = nullptr; if (newProperty) { - QMap<QString, QtVariantProperty*>::const_iterator itPrev = m_nameToProperty.insert(propertyName, property); + QMap<QString, QtVariantProperty*>::const_iterator itPrev(m_nameToProperty.insert(propertyName, property)); m_propertyToGroup[property] = groupName; if (m_sorting) { QtProperty *previous = nullptr; diff --git a/src/designer/src/components/taskmenu/tablewidgeteditor.h b/src/designer/src/components/taskmenu/tablewidgeteditor.h index 72dbb58da..cedea521d 100644 --- a/src/designer/src/components/taskmenu/tablewidgeteditor.h +++ b/src/designer/src/components/taskmenu/tablewidgeteditor.h @@ -56,7 +56,7 @@ public: private slots: - void on_tableWidget_currentCellChanged(int currentRow, int currnetCol, int, int); + void on_tableWidget_currentCellChanged(int currentRow, int currentCol, int, int); void on_tableWidget_itemChanged(QTableWidgetItem *item); void on_columnEditor_indexChanged(int idx); diff --git a/src/designer/src/lib/sdk/abstractformeditor.cpp b/src/designer/src/lib/sdk/abstractformeditor.cpp index 9c5b1e29e..2d4b20812 100644 --- a/src/designer/src/lib/sdk/abstractformeditor.cpp +++ b/src/designer/src/lib/sdk/abstractformeditor.cpp @@ -334,8 +334,7 @@ QDesignerPromotionInterface *QDesignerFormEditorInterface::promotion() const void QDesignerFormEditorInterface::setPromotion(QDesignerPromotionInterface *promotion) { - if (d->m_promotion) - delete d->m_promotion; + delete d->m_promotion; d->m_promotion = promotion; } @@ -525,8 +524,7 @@ QDesignerIntrospectionInterface *QDesignerFormEditorInterface::introspection() c */ void QDesignerFormEditorInterface::setIntrospection(QDesignerIntrospectionInterface *introspection) { - if (d->m_introspection) - delete d->m_introspection; + delete d->m_introspection; d->m_introspection = introspection; } diff --git a/src/designer/src/lib/sdk/abstractformwindow.cpp b/src/designer/src/lib/sdk/abstractformwindow.cpp index 39a14f49a..0b24920aa 100644 --- a/src/designer/src/lib/sdk/abstractformwindow.cpp +++ b/src/designer/src/lib/sdk/abstractformwindow.cpp @@ -199,17 +199,15 @@ static inline bool stopFindAtTopLevel(const QObject *w, bool stopAtMenu) QDesignerFormWindowInterface *QDesignerFormWindowInterface::findFormWindow(QWidget *w) { while (w != nullptr) { - if (QDesignerFormWindowInterface *fw = qobject_cast<QDesignerFormWindowInterface*>(w)) { + if (QDesignerFormWindowInterface *fw = qobject_cast<QDesignerFormWindowInterface*>(w)) return fw; - } else { - if (w->isWindow() && stopFindAtTopLevel(w, true)) - break; - } + if (w->isWindow() && stopFindAtTopLevel(w, true)) + break; w = w->parentWidget(); } - return 0; + return nullptr; } /*! @@ -223,18 +221,16 @@ QDesignerFormWindowInterface *QDesignerFormWindowInterface::findFormWindow(QWidg QDesignerFormWindowInterface *QDesignerFormWindowInterface::findFormWindow(QObject *object) { while (object != nullptr) { - if (QDesignerFormWindowInterface *fw = qobject_cast<QDesignerFormWindowInterface*>(object)) { + if (QDesignerFormWindowInterface *fw = qobject_cast<QDesignerFormWindowInterface*>(object)) return fw; - } else { - QWidget *w = qobject_cast<QWidget *>(object); - // QDesignerMenu is a window, so stopFindAtTopLevel(w) returns 0. - // However, we want to find the form window for QActions of a menu. - // If this check is inside stopFindAtTopLevel(w), it will break designer - // menu editing (e.g. when clicking on items inside an opened menu) - if (w && w->isWindow() && stopFindAtTopLevel(w, false)) - break; - - } + + QWidget *w = qobject_cast<QWidget *>(object); + // QDesignerMenu is a window, so stopFindAtTopLevel(w) returns 0. + // However, we want to find the form window for QActions of a menu. + // If this check is inside stopFindAtTopLevel(w), it will break designer + // menu editing (e.g. when clicking on items inside an opened menu) + if (w && w->isWindow() && stopFindAtTopLevel(w, false)) + break; object = object->parent(); } diff --git a/src/designer/src/lib/shared/formlayoutmenu.cpp b/src/designer/src/lib/shared/formlayoutmenu.cpp index c6bc492ab..8d4bab6c7 100644 --- a/src/designer/src/lib/shared/formlayoutmenu.cpp +++ b/src/designer/src/lib/shared/formlayoutmenu.cpp @@ -359,12 +359,11 @@ QStringList FormLayoutRowDialog::fieldWidgetClasses(QDesignerFormEditorInterface typedef QMultiHash<QString, QString> ClassMap; static QStringList rc; - if (rc.empty()) { - const int fwCount = sizeof(fieldWidgetBaseClasses)/sizeof(const char*); + if (rc.isEmpty()) { // Turn known base classes into list QStringList baseClasses; - for (int i = 0; i < fwCount; i++) - baseClasses.push_back(QLatin1String(fieldWidgetBaseClasses[i])); + for (auto fw : fieldWidgetBaseClasses) + baseClasses.append(QLatin1String(fw)); // Scan for custom widgets that inherit them and store them in a // multimap of base class->custom widgets unless we have a language // extension installed which might do funny things with custom widgets. @@ -385,9 +384,9 @@ QStringList FormLayoutRowDialog::fieldWidgetClasses(QDesignerFormEditorInterface } // Compile final list, taking each base class and append custom widgets // based on it. - for (int i = 0; i < fwCount; i++) { - rc.push_back(baseClasses.at(i)); - rc += customClassMap.values(baseClasses.at(i)); + for (const auto &baseClass : baseClasses) { + rc.append(baseClass); + rc += customClassMap.values(baseClass); } } return rc; diff --git a/src/designer/src/lib/shared/qdesigner_menu.cpp b/src/designer/src/lib/shared/qdesigner_menu.cpp index 5a3b39438..88668ea45 100644 --- a/src/designer/src/lib/shared/qdesigner_menu.cpp +++ b/src/designer/src/lib/shared/qdesigner_menu.cpp @@ -1101,11 +1101,10 @@ QDesignerMenu *QDesignerMenu::parentMenu() const QDesignerMenuBar *QDesignerMenu::parentMenuBar() const { - if (QDesignerMenuBar *mb = qobject_cast<QDesignerMenuBar*>(parentWidget())) { + if (QDesignerMenuBar *mb = qobject_cast<QDesignerMenuBar*>(parentWidget())) return mb; - } else if (QDesignerMenu *m = parentMenu()) { + if (QDesignerMenu *m = parentMenu()) return m->parentMenuBar(); - } return nullptr; } diff --git a/src/designer/src/lib/shared/qdesigner_propertycommand.cpp b/src/designer/src/lib/shared/qdesigner_propertycommand.cpp index d7f94136e..8b564ab6f 100644 --- a/src/designer/src/lib/shared/qdesigner_propertycommand.cpp +++ b/src/designer/src/lib/shared/qdesigner_propertycommand.cpp @@ -978,7 +978,7 @@ bool PropertyListCommand::add(QObject *object, const QString &propertyName) return false; if (!sheet->isEnabled(index)) - return false; + return false; const PropertyDescription description(propertyName, sheet, index); diff --git a/src/designer/src/lib/shared/qdesigner_propertysheet.cpp b/src/designer/src/lib/shared/qdesigner_propertysheet.cpp index fbb0746aa..1293b689c 100644 --- a/src/designer/src/lib/shared/qdesigner_propertysheet.cpp +++ b/src/designer/src/lib/shared/qdesigner_propertysheet.cpp @@ -1259,7 +1259,8 @@ bool QDesignerPropertySheet::reset(int index) if (d->isResourceProperty(index)) { setProperty(index, d->emptyResourceProperty(index)); return true; - } else if (isDynamic(index)) { + } + if (isDynamic(index)) { const QString propName = propertyName(index); const QVariant oldValue = d->m_addProperties.value(index); const QVariant defaultValue = d->m_info.value(index).defaultValue; diff --git a/src/designer/src/lib/shared/qdesigner_utils_p.h b/src/designer/src/lib/shared/qdesigner_utils_p.h index 521f8b3eb..38cb31c9d 100644 --- a/src/designer/src/lib/shared/qdesigner_utils_p.h +++ b/src/designer/src/lib/shared/qdesigner_utils_p.h @@ -473,7 +473,7 @@ inline int valueOf(const QVariant &value, bool *ok = nullptr) *ok = true; return qvariant_cast<PropertySheetEnumValue>(value).value; } - else if (value.canConvert<PropertySheetFlagValue>()) { + if (value.canConvert<PropertySheetFlagValue>()) { if (ok) *ok = true; return qvariant_cast<PropertySheetFlagValue>(value).value; diff --git a/src/designer/src/lib/shared/richtexteditor.cpp b/src/designer/src/lib/shared/richtexteditor.cpp index 0c7400b85..ca2a82b09 100644 --- a/src/designer/src/lib/shared/richtexteditor.cpp +++ b/src/designer/src/lib/shared/richtexteditor.cpp @@ -738,7 +738,7 @@ QString RichTextEditor::text(Qt::TextFormat format) const return toPlainText(); case Qt::RichText: return m_simplifyRichText ? simplifyRichTextFilter(toHtml()) : toHtml(); - case Qt::AutoText: + default: break; } const QString html = toHtml(); diff --git a/src/designer/src/lib/shared/sheet_delegate.cpp b/src/designer/src/lib/shared/sheet_delegate.cpp index 255110cfb..31afad7f8 100644 --- a/src/designer/src/lib/shared/sheet_delegate.cpp +++ b/src/designer/src/lib/shared/sheet_delegate.cpp @@ -118,7 +118,6 @@ void SheetDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, QSize SheetDelegate::sizeHint(const QStyleOptionViewItem &opt, const QModelIndex &index) const { - QStyleOptionViewItem option = opt; QSize sz = QItemDelegate::sizeHint(opt, index) + QSize(2, 2); return sz; } diff --git a/src/designer/src/lib/shared/widgetfactory.cpp b/src/designer/src/lib/shared/widgetfactory.cpp index 44c438e42..14cd72124 100644 --- a/src/designer/src/lib/shared/widgetfactory.cpp +++ b/src/designer/src/lib/shared/widgetfactory.cpp @@ -323,12 +323,10 @@ QWidget *WidgetFactory::createWidget(const QString &widgetName, QWidget *parentW // return 0, do not try to find fallback, which might be worse in the case of Q3 widget. bool customWidgetCreationError; w = createCustomWidget(widgetName, parentWidget, &customWidgetCreationError); - if (w) { + if (w) break; - } else { - if (customWidgetCreationError) - return 0; - } + if (customWidgetCreationError) + return nullptr; // 2) Special widgets if (widgetName == m_strings.m_line) { |