D15690: Removed old style casts

Pino Toscano noreply at phabricator.kde.org
Sun Sep 23 07:14:45 BST 2018


pino requested changes to this revision.
pino added a comment.
This revision now requires changes to proceed.


  This patch does more things that "remove old style casts". Some of the other changes are OK, but please do split them in own changes, properly documenting them.

INLINE COMMENTS

> exportdialog.cpp:183
>          *m_outputStream << "<tr>\n<th colspan=\"2\">"
> -        << ((ElementListEntry*)element)->m_element->dataAsString(ChemicalDataObject::name)
> +        << (dynamic_cast<ElementListEntry*>(element))->m_element->dataAsString(ChemicalDataObject::name)
>          << "</th>\n</tr>\n";

you use dynamic_cast when you expect that the cast can fail; since in this case it is assumed it will work, then use static_cast directly instead

> exportdialog.cpp:187
>              *m_outputStream << "<tr>\n<td class=\"property\">"
> -            << ((PropertyListEntry*) property)->text()
> +            << (dynamic_cast<PropertyListEntry*> (property))->text()
>              << "</td>\n<td class=\"value\">"

ditto

also, `property` is casted more than once within this foreach loop, so factorize it

> exportdialog.cpp:190-191
>              << KalziumUtils::prettyUnit(
> -                ((ElementListEntry*) element)->m_element,
> -                ((PropertyListEntry*) property)->m_type)
> +                (dynamic_cast<ElementListEntry*> (element))->m_element,
> +                (dynamic_cast<PropertyListEntry*> (property))->m_type)
>              << "</td>\n</tr>\n";

ditto

> exportdialog.cpp:203
>          *m_outputStream << "  <element name=\""
> -        << ((ElementListEntry*) element)->m_element->dataAsString(ChemicalDataObject::name)
> +        << (dynamic_cast<ElementListEntry*> (element))->m_element->dataAsString(ChemicalDataObject::name)
>          << "\">\n";

ditto

> exportdialog.cpp:207
>              *m_outputStream << "    <property name=\""
> -            << ((PropertyListEntry*) property)->text()
> +            << (dynamic_cast<PropertyListEntry*> (property))->text()
>              << "\">"

ditto (dynamic_cast + factorize)

> exportdialog.cpp:210-211
>              << KalziumUtils::prettyUnit(
> -                ((ElementListEntry*) element)->m_element,
> -                ((PropertyListEntry*) property)->m_type)
> +               (dynamic_cast<ElementListEntry*> (element))->m_element,
> +               (dynamic_cast<PropertyListEntry*> (property))->m_type)
>              << "</property>\n";

ditto

> exportdialog.cpp:224
>          *m_outputStream << ", \""
> -        << ((PropertyListEntry*) property)->text()
> +        << (dynamic_cast<PropertyListEntry*> (property))->text()
>          << "\"";

ditto

> exportdialog.cpp:230
>          *m_outputStream << "\""
> -        << ((ElementListEntry*) element)->m_element->dataAsString(ChemicalDataObject::name)
> +        << (dynamic_cast<ElementListEntry*> (element))->m_element->dataAsString(ChemicalDataObject::name)
>          << "\"";

ditto (dynamic_cast + factorize)

> exportdialog.cpp:235-236
>              << KalziumUtils::prettyUnit(
> -                ((ElementListEntry*) element)->m_element,
> -                ((PropertyListEntry*) property)->m_type)
> +                (dynamic_cast<ElementListEntry*> (element))->m_element,
> +                (dynamic_cast<PropertyListEntry*> (property))->m_type)
>              << "\"";

ditto

> kdeeduglossary.cpp:236-237
>  
> -    const uint num = itemList.count();
> +    const uint num = static_cast<uint>(itemList.count());
>      for (uint i = 0; i < num; ++i) {
>          reflist.clear();

or, simpler, turn both `num` and `i` to int, since the only usage of `i` is with `QDomNodeList::item(int)`

> kdeeduglossary.cpp:241
>  
> -        itemElement = (const QDomElement&) itemList.item(i).toElement();
> +        itemElement = static_cast<const QDomElement&> (itemList.item(i).toElement());
>  

`QDomNode::toElement()` already returns a QDomElement, so this cast can go away altogether

> kdeeduglossary.cpp:247
>          QString picName = itemElement.namedItem("picture").toElement().text();
> -        QDomElement refNode = (const QDomElement&) itemElement.namedItem("references").toElement();
> +        QDomElement refNode = static_cast<const QDomElement&> (itemElement.namedItem("references").toElement());
>  

ditto

> molcalcwidget.cpp:101
>                  fullForm = fullList.takeFirst ();
> -                ui.user_defined->setItem((int)i, 0, new QTableWidgetItem
> +                ui.user_defined->setItem(static_cast<int>(i), 0, new QTableWidgetItem
>                      (i18n("%1",shortForm + " : " + fullForm)));

`i` is already int, so this cast can go altogether

> molcalcwidget.cpp:137
>                  fullForm = fullList.takeFirst();
> -                ui.pre_defined->setItem((int)i, 0, new QTableWidgetItem
> +                ui.pre_defined->setItem(static_cast<int>(i), 0, new QTableWidgetItem
>                      (i18n("%1",shortForm + " : " + fullForm)));

ditto

> spectrumviewimpl.cpp:75
>                            << QString::number(peak->intensity);
> -
> -        items.append(new QTreeWidgetItem((QTreeWidget*)0, row));
> +        items.append(new QTreeWidgetItem(static_cast <QTreeWidget*> (nullptr), row));
>      }

as mentioned this goes to another patch... hoever you do not need to cast nullptr to anything...

REPOSITORY
  R326 Kalzium

REVISION DETAIL
  https://phabricator.kde.org/D15690

To: carlos_hdc, tcanabrava, pino
Cc: pino, kde-edu, narvaez, apol
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-edu/attachments/20180923/3164312b/attachment-0001.html>


More information about the kde-edu mailing list