diff --git a/.clang-tidy b/.clang-tidy index 6b599afe0ad94c2c0e674f186945788cdf352e17..daa01b78f148ad952222ff368a8d7dae16558973 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -11,7 +11,8 @@ # As we are not aware of an official way to insert comments in a long string literal, # we do a dirty little trick: we write comments as if they were no-check specifiers. # -Checks: '*, +Checks: ' + -SectionComment_We_disagree_with_the_following_checks__They_shall_remain_permanently_disabled, @@ -25,11 +26,14 @@ Checks: '*, -bugprone-branch-clone, -bugprone-suspicious-include, -clang-analyzer-alpha*, +-cert-msc30-cpp, +-cert-msc50-cpp, -cert-err58-cpp, -cert-err61-cpp, -clang-analyzer-alpha.deadcode.UnreachableCode, -clang-analyzer-security.insecureAPI.strcpy, -cppcoreguidelines-init-variables, +-cppcoreguidelines-macro-usage, -cppcoreguidelines-non-private-member-variables-in-classes, -cppcoreguidelines-pro-bounds-constant-array-index, -cppcoreguidelines-pro-bounds-pointer-arithmetic, @@ -51,12 +55,15 @@ Checks: '*, -performance-unnecessary-value-param, -readability-use-anyofallof, + -SectionComment_Disabled_unless_3rdparty_libraries_are_improved, +-clang-analyzer-cplusplus.NewDeleteLeaks, -cppcoreguidelines-avoid-non-const-global-variables, -llvm-include-order, -readability-redundant-access-specifiers, + -SectionComment_Resolving_the_following_checks_would_be_too_much_work_right_now, -cppcoreguidelines-owning-memory, @@ -79,7 +86,7 @@ Checks: '*, -*-statically-constructed-objects, -*-use-auto, -*-use-emplace, --*-use-override, ++*-use-override, -bugprone-argument-comment, -bugprone-copy-constructor-init, -bugprone-exception-escape, @@ -88,18 +95,11 @@ Checks: '*, -bugprone-narrowing-conversions, -bugprone-unhandled-self-assignment, -bugprone-unused-return-value, --bugprone-use-after-move, --bugprone-parent-virtual-call, --cert-dcl21-cpp, --cert-msc30-c, --cert-msc50-cpp, --cert-oop54-cpp, --clang-analyzer-core.CallAndMessage, --clang-analyzer-cplusplus.NewDeleteLeaks, --clang-analyzer-optin.cplusplus.VirtualCall, --cppcoreguidelines-explicit-virtual-functions, --cppcoreguidelines-init-variables, --cppcoreguidelines-macro-usage, ++bugprone-parent-virtual-call, ++clang-analyzer-core.CallAndMessage, ++clang-analyzer-optin.cplusplus.VirtualCall, ++cppcoreguidelines-explicit-virtual-functions, ++cppcoreguidelines-init-variables, -cppcoreguidelines-pro-type-const-cast, -cppcoreguidelines-pro-type-cstyle-cast, -cppcoreguidelines-pro-type-static-cast-downcast, diff --git a/App/main.cpp b/App/main.cpp index 59431d8c85621ba6b484c22a407257ef4c3651df..43d85e01475b94994f00bdcbff468847c492b6df 100644 --- a/App/main.cpp +++ b/App/main.cpp @@ -43,9 +43,9 @@ int main(int argc, char* argv[]) QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); QApplication app(argc, argv); - app.setApplicationName("BornAgain"); - app.setApplicationVersion(GUI::Util::Path::getBornAgainVersionString()); - app.setOrganizationName("BornAgain"); + QApplication::setApplicationName("BornAgain"); + QApplication::setApplicationVersion(GUI::Util::Path::getBornAgainVersionString()); + QApplication::setOrganizationName("BornAgain"); if (!GUI::Util::OS::HostOsInfo::isMacHost()) QApplication::setWindowIcon(QIcon(":/images/BornAgain.ico")); diff --git a/GUI/Model/Group/GroupItem.cpp b/GUI/Model/Group/GroupItem.cpp index f42f75cb97b95cf704113cf9c0c43d4d8c8f05fc..61b58dfebe922de0a2c3b79bc05dbfee77db2e60 100644 --- a/GUI/Model/Group/GroupItem.cpp +++ b/GUI/Model/Group/GroupItem.cpp @@ -52,7 +52,7 @@ SessionItem* GroupItem::setCurrentType(const QString& modelType) return currentItem(); } -SessionItem* GroupItem::getItemOfType(const QString& type) +SessionItem* GroupItem::getItemOfType(const QString& type) const { return m_controller->getItemOfType(type); } diff --git a/GUI/Model/Group/GroupItem.h b/GUI/Model/Group/GroupItem.h index 26a99685c454c530fda256cc1785f77d96731782..7971efe314157df0d760a2359bc411dc98025a85 100644 --- a/GUI/Model/Group/GroupItem.h +++ b/GUI/Model/Group/GroupItem.h @@ -39,7 +39,7 @@ public: SessionItem* setCurrentType(const QString& modelType); - SessionItem* getItemOfType(const QString& type); + SessionItem* getItemOfType(const QString& type) const; template <typename T> T* itemOfType() const; diff --git a/GUI/Model/Session/SessionItem.cpp b/GUI/Model/Session/SessionItem.cpp index 51098d6d37035ece603000961acf14dd9723fb6a..dd2570de1a24a8bda5a66578fe4401dd694fcd2c 100644 --- a/GUI/Model/Session/SessionItem.cpp +++ b/GUI/Model/Session/SessionItem.cpp @@ -159,7 +159,7 @@ bool SessionItem::isTag(const QString& name) const return m_tags->isValid(name); } -SessionItemTags* SessionItem::sessionItemTags() +const SessionItemTags* SessionItem::sessionItemTags() const { return m_tags.get(); } diff --git a/GUI/Model/Session/SessionItem.h b/GUI/Model/Session/SessionItem.h index 3304cf83dd2cfb9fe9f5bc5eba4559f9ea9632d4..732316529118b1aae03b2624b4cc763c150333c6 100644 --- a/GUI/Model/Session/SessionItem.h +++ b/GUI/Model/Session/SessionItem.h @@ -231,7 +231,7 @@ public: // manage and check tags bool registerTag(const QString& name, int min = 0, int max = -1, QStringList modelTypes = {}); bool isTag(const QString& name) const; - SessionItemTags* sessionItemTags(); + const SessionItemTags* sessionItemTags() const; QString tagFromItem(const SessionItem* item) const; bool acceptsAsDefaultItem(const QString& item_name) const; QVector<QString> acceptableDefaultItemTypes() const; diff --git a/GUI/Model/Session/SessionItemTags.cpp b/GUI/Model/Session/SessionItemTags.cpp index e436e7a7fee90286d0c79c303041bb4995022183..852cb54df0809a97389f1117b78c8844f9ff78c6 100644 --- a/GUI/Model/Session/SessionItemTags.cpp +++ b/GUI/Model/Session/SessionItemTags.cpp @@ -128,7 +128,7 @@ void SessionItemTags::removeChild(const QString& tagName) tag.childCount--; } -bool SessionItemTags::isSingleItemTag(const QString& tagName) +bool SessionItemTags::isSingleItemTag(const QString& tagName) const { if (!isValid(tagName)) return false; diff --git a/GUI/Model/Session/SessionItemTags.h b/GUI/Model/Session/SessionItemTags.h index b10d6c1c3499735ad5e3d316efad6091261b65a2..bdee3b108ad25c60b44c1e38ee3d21e274a6138b 100644 --- a/GUI/Model/Session/SessionItemTags.h +++ b/GUI/Model/Session/SessionItemTags.h @@ -42,7 +42,7 @@ public: void addChild(const QString& tagName); void removeChild(const QString& tagName); - bool isSingleItemTag(const QString& tagName); + bool isSingleItemTag(const QString& tagName) const; bool maximumReached(const QString& tagName) const; diff --git a/GUI/Model/Session/SessionXML.cpp b/GUI/Model/Session/SessionXML.cpp index 3b9cf517c0aa99fccdc16f61d213af0fc881515e..9fbe143a3b1bfd851c4bf1e769636e89f8a774e8 100644 --- a/GUI/Model/Session/SessionXML.cpp +++ b/GUI/Model/Session/SessionXML.cpp @@ -40,18 +40,18 @@ void report_error(MessageService* messageService, SessionItem* item, const QStri messageService->addWarning(item->model(), message); } -SessionItem* createItem(SessionItem* item, const QString& modelType, const QString& tag) +SessionItem* createItem(SessionItem* parent, const QString& modelType, const QString& tag) { - ASSERT(item); - if (item->hasModelType<GroupItem>()) { - if (auto groupItem = dynamic_cast<GroupItem*>(item)) + ASSERT(parent); + if (parent->hasModelType<GroupItem>()) { + if (auto groupItem = dynamic_cast<const GroupItem*>(parent)) return groupItem->getItemOfType(modelType); return nullptr; } - if (item->sessionItemTags()->isSingleItemTag(tag)) - return item->getItem(tag); + if (parent->sessionItemTags()->isSingleItemTag(tag)) + return parent->getItem(tag); try { - return item->model()->insertNewItem(modelType, item, -1, tag); + return parent->model()->insertNewItem(modelType, parent, -1, tag); } catch (const std::exception&) { return nullptr; // error will be reported later } diff --git a/GUI/View/Common/ItemViewOverlayButtons.cpp b/GUI/View/Common/ItemViewOverlayButtons.cpp index 93348953b217af1e32a61ab310f6b7a2ac31eaa8..16a0d55dbad0b328e25c5c1782445c0450bf4edf 100644 --- a/GUI/View/Common/ItemViewOverlayButtons.cpp +++ b/GUI/View/Common/ItemViewOverlayButtons.cpp @@ -35,9 +35,9 @@ public: void setHorizontalAlignment(Qt::Alignment a); protected: - virtual void enterEvent(QEvent* event) override; - virtual void leaveEvent(QEvent* event) override; - virtual void mouseDoubleClickEvent(QMouseEvent* event) override; + void enterEvent(QEvent* event) override; + void leaveEvent(QEvent* event) override; + void mouseDoubleClickEvent(QMouseEvent* event) override; private: bool m_hover; @@ -48,8 +48,7 @@ private: class ItemViewOverlayDelegate : public QStyledItemDelegate { public: - virtual QSize sizeHint(const QStyleOptionViewItem& option, - const QModelIndex& index) const override + QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override { QSize s = QStyledItemDelegate::sizeHint(option, index); if (index.parent().isValid()) { diff --git a/GUI/View/Instrument/DetectorAlignmentEditor.cpp b/GUI/View/Instrument/DetectorAlignmentEditor.cpp index 9fa4461be64ef406d66d962644250b51ff2c43e8..079028eb0483efc0096d04dc68baac2b668089ad 100644 --- a/GUI/View/Instrument/DetectorAlignmentEditor.cpp +++ b/GUI/View/Instrument/DetectorAlignmentEditor.cpp @@ -54,7 +54,7 @@ DetectorAlignmentForm::DetectorAlignmentForm(QWidget* parent, Qt::WindowFlags f) class GenericDetectorAlignmentForm : public DetectorAlignmentForm { public: GenericDetectorAlignmentForm(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); - virtual void setItem(RectangularDetectorItem* item) override; + void setItem(RectangularDetectorItem* item) override; private slots: void onU0ValueChanged(double u0); @@ -147,7 +147,7 @@ void GenericDetectorAlignmentForm::onV0ValueChanged(double v0) /// Abstract alignment form for the perpendicular case class PerpendicularDetectorAlignmentForm : public DetectorAlignmentForm { public: - virtual void setItem(RectangularDetectorItem* item) override; + void setItem(RectangularDetectorItem* item) override; protected: PerpendicularDetectorAlignmentForm(const QString& title, const QString& tooltip, @@ -268,10 +268,10 @@ public: Qt::WindowFlags f = Qt::WindowFlags()); private: - virtual double getU0() const override; - virtual double getV0() const override; - virtual void setU0(double u0) override; - virtual void setV0(double v0) override; + double getU0() const override; + double getV0() const override; + void setU0(double u0) override; + void setV0(double v0) override; }; //-------------------------------------------------------------------------------------------------- @@ -325,10 +325,10 @@ public: Qt::WindowFlags f = Qt::WindowFlags()); private: - virtual double getU0() const override; - virtual double getV0() const override; - virtual void setU0(double u0) override; - virtual void setV0(double v0) override; + double getU0() const override; + double getV0() const override; + void setU0(double u0) override; + void setV0(double v0) override; }; //-------------------------------------------------------------------------------------------------- diff --git a/GUI/View/Instrument/EnvironmentEditor.cpp b/GUI/View/Instrument/EnvironmentEditor.cpp index 7bd3c43e107b020e1e6e8565b69c1519e092c798..65eacdd2099fa889b24aca801c1c2e106f405797 100644 --- a/GUI/View/Instrument/EnvironmentEditor.cpp +++ b/GUI/View/Instrument/EnvironmentEditor.cpp @@ -22,9 +22,6 @@ #include <QGroupBox> #include <QStackedLayout> -#include <boost/polymorphic_cast.hpp> -using boost::polymorphic_downcast; - //================================================================================================== // ConstantBackgroundForm //================================================================================================== diff --git a/GUI/View/Instrument/InstrumentListModel.cpp b/GUI/View/Instrument/InstrumentListModel.cpp index 32a1752ec0560f01fb88a3c138e0fa74a1321d0a..d09617a5444538a4e8a5ef059269fc359718815c 100644 --- a/GUI/View/Instrument/InstrumentListModel.cpp +++ b/GUI/View/Instrument/InstrumentListModel.cpp @@ -86,24 +86,25 @@ QVariant InstrumentListModel::data(const QModelIndex& index, int role) const { QVector<InstrumentItem*> instruments = m_instruments->instrumentItems(); if (!index.isValid() || index.row() >= instruments.size() || index.row() < 0) - return QVariant(); + return {}; InstrumentItem* item = instruments[index.row()]; if (role == Qt::DecorationRole) { if (item->hasModelType<GISASInstrumentItem>()) return m_gisasIcon; - else if (item->hasModelType<OffSpecularInstrumentItem>()) + if (item->hasModelType<OffSpecularInstrumentItem>()) return m_offSpecularIcon; - else if (item->hasModelType<SpecularInstrumentItem>()) + if (item->hasModelType<SpecularInstrumentItem>()) return m_specularIcon; - else if (item->hasModelType<DepthProbeInstrumentItem>()) + if (item->hasModelType<DepthProbeInstrumentItem>()) return m_depthProbeIcon; - else - return QVariant(); - } else if (role == Qt::DisplayRole) + return {}; + } + + if (role == Qt::DisplayRole) return item->itemName(); - return QVariant(); + return {}; } InstrumentItem* InstrumentListModel::instrumentForIndex(const QModelIndex& index) const @@ -111,8 +112,7 @@ InstrumentItem* InstrumentListModel::instrumentForIndex(const QModelIndex& index QVector<InstrumentItem*> instruments = m_instruments->instrumentItems(); if (index.row() >= 0 && index.row() < instruments.size()) return instruments[index.row()]; - else - return nullptr; + return nullptr; } QModelIndex InstrumentListModel::addNewGISASInstrument() diff --git a/GUI/View/Job/JobListModel.cpp b/GUI/View/Job/JobListModel.cpp index 3668b1971a204d6ea4692ac2c10c00d1e0d982e9..72dc6ad37da80d7215523dda595ff9cf0b37bbe0 100644 --- a/GUI/View/Job/JobListModel.cpp +++ b/GUI/View/Job/JobListModel.cpp @@ -50,13 +50,13 @@ QVariant JobListModel::data(const QModelIndex& index, int role) const { QVector<JobItem*> jobs = m_jobs->jobItems(); if (!index.isValid() || index.row() >= jobs.size() || index.row() < 0) - return QVariant(); + return {}; JobItem* item = jobs[index.row()]; if (role == Qt::DisplayRole) return item->itemName(); - return QVariant(); + return {}; } JobItem* JobListModel::jobForIndex(const QModelIndex& index) const @@ -64,8 +64,7 @@ JobItem* JobListModel::jobForIndex(const QModelIndex& index) const QVector<JobItem*> jobs = m_jobs->jobItems(); if (index.row() >= 0 && index.row() < jobs.size()) return jobs[index.row()]; - else - return nullptr; + return nullptr; } QModelIndex JobListModel::indexForJob(JobItem* job) @@ -74,8 +73,7 @@ QModelIndex JobListModel::indexForJob(JobItem* job) int idx = jobs.indexOf(job); if (idx != -1) return index(idx, 0); - else - return QModelIndex(); + return {}; } void JobListModel::runJob(const QModelIndex& index) @@ -124,7 +122,7 @@ void JobListModel::onRowsInserted(const QModelIndex& parent, int start, int end) void JobListModel::attachToJob(JobItem* job) { job->mapper()->setOnPropertyChange( - std::bind(&JobListModel::notifyJobPropertyChange, this, job, std::placeholders::_1), this); + [=](const QString& arg) { notifyJobPropertyChange(job, arg); }); } void JobListModel::detachFromJob(JobItem* job) diff --git a/GUI/View/SampleDesigner/SampleListView.cpp b/GUI/View/SampleDesigner/SampleListView.cpp index 58b5aeafcb43277a684d3d5f2d05c1d98e45ad6c..312acbbdc0c1c45963bc5157fa92d6d6ae3c2fde 100644 --- a/GUI/View/SampleDesigner/SampleListView.cpp +++ b/GUI/View/SampleDesigner/SampleListView.cpp @@ -38,7 +38,7 @@ public: protected: void paint(QPainter* painter, const QStyleOptionViewItem& option, - const QModelIndex& index) const + const QModelIndex& index) const override { ItemDelegateForHTML::paint(painter, option, index); @@ -53,7 +53,7 @@ protected: painter->restore(); } - QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const + QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override { auto s = ItemDelegateForHTML::sizeHint(option, index); s.setHeight(std::max(s.height(), 32)); diff --git a/GUI/View/SampleDesigner/SampleToolBox.cpp b/GUI/View/SampleDesigner/SampleToolBox.cpp index e8c6c6385a4970bccf6e4d1371996223b4585cac..c3b54023a74c931e793dbfd2662afeb589f31cf5 100644 --- a/GUI/View/SampleDesigner/SampleToolBox.cpp +++ b/GUI/View/SampleDesigner/SampleToolBox.cpp @@ -35,14 +35,14 @@ public: explicit FilterEdit(QWidget* parent = 0) : QLineEdit(parent) { setFocusPolicy(Qt::NoFocus); } protected: - virtual void mousePressEvent(QMouseEvent* event) + void mousePressEvent(QMouseEvent* event) override { if (!hasFocus()) // Explicitly focus on click. setFocus(Qt::OtherFocusReason); QLineEdit::mousePressEvent(event); } - virtual void focusInEvent(QFocusEvent* e) + virtual void focusInEvent(QFocusEvent* e) override { // Refuse the focus if the mouse it outside. In addition to the mouse // press logic, this prevents a re-focussing which occurs once diff --git a/GUI/View/SampleDesigner/SampleToolBoxGroupView.cpp b/GUI/View/SampleDesigner/SampleToolBoxGroupView.cpp index ed4fd64213669cef54255a1f069b4b0ba4818e06..20ee33dc39c68003d4e4c76c57510ebdaba3c813 100644 --- a/GUI/View/SampleDesigner/SampleToolBoxGroupView.cpp +++ b/GUI/View/SampleDesigner/SampleToolBoxGroupView.cpp @@ -43,9 +43,9 @@ public: }; // QAbstractListModel - virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; - virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override; - virtual Qt::ItemFlags flags(const QModelIndex& index) const override; + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; + int rowCount(const QModelIndex& parent = QModelIndex()) const override; + Qt::ItemFlags flags(const QModelIndex& index) const override; // The model returns no text in icon mode, so, it also needs to know the view mode void setViewMode(QListView::ViewMode viewMode); diff --git a/GUI/View/SampleDesigner/SampleToolBoxTreeWidget.cpp b/GUI/View/SampleDesigner/SampleToolBoxTreeWidget.cpp index b6e4aa64f59f29df6daf96aafabc7f1074ae3933..c1daf75f3dae9d45e46a8d504ce8ac511f431492 100644 --- a/GUI/View/SampleDesigner/SampleToolBoxTreeWidget.cpp +++ b/GUI/View/SampleDesigner/SampleToolBoxTreeWidget.cpp @@ -34,8 +34,8 @@ class GroupTitleDelegate : public QItemDelegate { public: GroupTitleDelegate(QTreeView* view, QWidget* parent) : QItemDelegate(parent), m_view(view) {} - virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, - const QModelIndex& index) const override + void paint(QPainter* painter, const QStyleOptionViewItem& option, + const QModelIndex& index) const override { const QAbstractItemModel* model = index.model(); const bool isGroupTitleItem = !model->parent(index).isValid();