From a102a4c04fb63364cc2d4e6e0872b9577ad156bf Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Tue, 2 May 2023 20:38:07 -0400 Subject: [PATCH 1/2] A variety of clang-tidy fixes - Use .empty() instead of .size() comparisons - Header cleanups - Remove some unused "using" decl - Use qualified auto (i.e., show pointers) - Add const decl where possible Signed-off-by: Geoff Hutchison --- .clang-tidy | 35 ++++++++--- avogadro/calc/chargemanager.cpp | 2 +- avogadro/calc/defaultmodel.cpp | 11 ++-- avogadro/calc/defaultmodel.h | 2 +- avogadro/core/atomutilities.cpp | 12 ++-- avogadro/core/avospglib.cpp | 4 +- avogadro/core/cube.cpp | 6 +- avogadro/core/elements.cpp | 1 - avogadro/core/gaussiansettools.cpp | 10 +--- avogadro/core/graph.cpp | 16 ++--- avogadro/core/layermanager.cpp | 2 +- avogadro/core/mesh.cpp | 9 +-- avogadro/core/molecule.cpp | 14 ++--- avogadro/core/neighborperceiver.cpp | 2 +- avogadro/core/ringperceiver.cpp | 2 +- avogadro/core/secondarystructure.cpp | 16 ++--- avogadro/core/slatersettools.cpp | 10 +--- avogadro/io/cjsonformat.cpp | 26 ++++----- avogadro/io/cmlformat.cpp | 3 +- avogadro/io/fileformatmanager.cpp | 2 +- avogadro/io/gromacsformat.cpp | 2 +- avogadro/io/lammpsformat.cpp | 1 - avogadro/io/mdlformat.cpp | 1 - avogadro/io/mmtfformat.cpp | 3 +- avogadro/io/pdbformat.cpp | 4 +- avogadro/io/turbomoleformat.cpp | 4 -- avogadro/io/vaspformat.cpp | 4 +- avogadro/io/xyzformat.cpp | 1 - avogadro/molequeue/inputgenerator.cpp | 2 +- .../molequeue/molequeuequeuelistmodel.cpp | 7 +-- avogadro/molequeue/molequeuewidget.cpp | 4 +- avogadro/qtgui/colorbutton.cpp | 5 +- avogadro/qtgui/colorbutton.h | 2 +- avogadro/qtgui/fileformatdialog.cpp | 4 +- avogadro/qtgui/hydrogentools.cpp | 1 - avogadro/qtgui/interfacescript.cpp | 2 +- avogadro/qtgui/jsonwidget.cpp | 4 +- avogadro/qtgui/layermodel.cpp | 1 - avogadro/qtgui/moleculemodel.cpp | 3 +- avogadro/qtgui/multiviewwidget.cpp | 2 +- avogadro/qtgui/pluginlayermanager.cpp | 3 +- avogadro/qtgui/pluginlayermanager.h | 2 +- avogadro/qtgui/pythonscript.cpp | 5 +- avogadro/qtgui/pythonscript.h | 2 +- avogadro/qtgui/rwlayermanager.cpp | 9 +-- avogadro/qtgui/rwmolecule.cpp | 3 +- avogadro/qtplugins/3dmol/3dmoldialog.cpp | 1 - .../qtplugins/applycolors/applycolors.cpp | 2 +- .../qtplugins/ballandstick/ballandstick.cpp | 3 +- .../bondcentrictool/bondcentrictool.cpp | 4 -- avogadro/qtplugins/cartoons/cartoons.cpp | 9 ++- .../qtplugins/closecontacts/closecontacts.cpp | 1 - .../coloropacitymap/coloropacitymap.cpp | 18 +++--- .../qtplugins/coloropacitymap/comdialog.cpp | 20 +++---- .../coloropacitymap/histogramwidget.cpp | 2 +- avogadro/qtplugins/editor/editor.cpp | 1 - avogadro/qtplugins/focus/focus.cpp | 1 - avogadro/qtplugins/force/force.cpp | 2 - .../insertfragment/insertfragment.cpp | 1 - .../insertfragment/insertfragmentdialog.cpp | 5 +- avogadro/qtplugins/label/label.cpp | 34 +++++------ .../lammpsinput/lammpsinputdialog.cpp | 5 +- avogadro/qtplugins/licorice/licorice.cpp | 3 +- .../qtplugins/measuretool/measuretool.cpp | 3 +- avogadro/qtplugins/meshes/meshes.cpp | 2 +- .../molecularpropertiesdialog.cpp | 3 +- .../qtplugins/noncovalent/noncovalent.cpp | 1 - avogadro/qtplugins/openbabel/obcharges.cpp | 3 +- avogadro/qtplugins/openbabel/obfileformat.cpp | 19 +++--- avogadro/qtplugins/openbabel/obfileformat.h | 8 +-- avogadro/qtplugins/openbabel/obprocess.cpp | 2 +- avogadro/qtplugins/plotpdf/plotpdf.cpp | 6 +- avogadro/qtplugins/plotrmsd/plotrmsd.cpp | 2 +- avogadro/qtplugins/plotxrd/plotxrd.cpp | 3 +- .../plugindownloader/downloaderwidget.cpp | 2 +- .../propertytables/propertymodel.cpp | 5 +- .../qtaim/qtaimcriticalpointlocator.cpp | 32 +++------- avogadro/qtplugins/qtaim/qtaimcubature.cpp | 10 ++-- avogadro/qtplugins/qtaim/qtaimextension.cpp | 6 +- .../qtplugins/qtaim/qtaimwavefunction.cpp | 24 ++++---- avogadro/qtplugins/resetview/resetview.cpp | 3 +- .../scriptcharges/scriptchargemodel.cpp | 3 +- .../qtplugins/selectiontool/selectiontool.cpp | 1 - avogadro/qtplugins/spectra/spectra.cpp | 2 +- avogadro/qtplugins/spectra/vibrationmodel.cpp | 2 +- avogadro/qtplugins/surfaces/surfacedialog.cpp | 6 +- avogadro/qtplugins/surfaces/surfaces.cpp | 14 ++--- avogadro/qtplugins/symmetry/symmetryscene.cpp | 3 - .../qtplugins/symmetry/symmetrywidget.cpp | 23 ++++---- .../qtplugins/templatetool/templatetool.cpp | 58 ++++++++----------- .../templatetool/templatetoolwidget.cpp | 12 ++-- .../qtplugins/vanderwaals/vanderwaals.cpp | 3 +- avogadro/qtplugins/wireframe/wireframe.cpp | 5 +- avogadro/qtplugins/yaehmop/banddialog.cpp | 4 +- avogadro/qtplugins/yaehmop/specialkpoints.cpp | 4 +- avogadro/qtplugins/yaehmop/yaehmop.cpp | 12 ++-- avogadro/qtplugins/yaehmop/yaehmopout.cpp | 4 +- avogadro/quantumio/gamessus.cpp | 12 ++-- avogadro/quantumio/gaussianfchk.cpp | 12 ++-- avogadro/quantumio/molden.cpp | 4 +- avogadro/quantumio/mopacaux.cpp | 6 +- avogadro/quantumio/nwchemjson.cpp | 2 +- avogadro/quantumio/nwchemlog.cpp | 3 +- avogadro/rendering/cartoongeometry.cpp | 2 +- avogadro/rendering/cylindergeometry.cpp | 2 +- avogadro/rendering/geometrynode.cpp | 4 +- avogadro/rendering/geometryvisitor.cpp | 8 +-- avogadro/rendering/glrenderer.cpp | 2 +- avogadro/rendering/groupnode.cpp | 2 +- avogadro/rendering/plyvisitor.cpp | 34 +++++------ avogadro/rendering/shader.cpp | 6 +- avogadro/rendering/shader.h | 2 +- avogadro/rendering/solidpipeline.cpp | 4 +- avogadro/rendering/textlabelbase.cpp | 2 +- avogadro/rendering/vrmlvisitor.cpp | 2 +- avogadro/vtk/chartwidget.cpp | 8 +-- avogadro/vtk/vtkglwidget.cpp | 6 +- utilities/bodr/bodrparse.cxx | 5 +- utilities/resdata/resdataparse.cxx | 6 +- 119 files changed, 354 insertions(+), 448 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 83bb7f09f5..ac2e6b2816 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,18 +1,37 @@ -Checks: 'clang-analyzer*,modernize-avoid-bind,modernize-concat-nested-namespaces, - modernize-loop-convert,modernize-macro-to-enum,modernize-use-bool-literals, - modernize-use-auto,modernize-use-nullptr,modernize-use-override, - modernize-raw-string-literal,modernize-use-emplace,modernize-pass-by-value - misc-unused-using-decls, - misc-unused-alias-decls, +Checks: 'clang-analyzer*, + misc-unused*, misc-redundant-expression, + modernize-avoid-bind, + modernize-concat-nested-namespaces, + modernize-loop-convert, + modernize-macro-to-enum, + modernize-pass-by-value + modernize-raw-string-literal, + modernize-use-auto, + modernize-use-bool-literals, + modernize-use-emplace, + modernize-use-nullptr, + modernize-use-override, + performance-avoid-endl, performance-for-range-copy, - performance-inefficient*,performance-type-promotion*, - performance-unnecessary-copy-initialization, + performance-inefficient*, performance-move-const-arg, + performance-type-promotion*, + performance-unnecessary-copy-initialization, + readability-container-data-pointer, + readability-container-size-empty, readability-const-return-type, readability-delete-null-pointer, + readability-duplicate-include, + readability-qualified-auto, + readability-redundant-access-specifiers, + readability-redundant-declaration, readability-redundant-string-cstr, + readability-redundant-string-init, readability-simplify* + -bugprone-easily-swappable-parameters, + -cppcoreguidelines-avoid-magic-numbers, + -cppcoreguidelines-owning-memory, -readability-else-after-return, -portability-restrict-system-includes, -modernize-use-trailing-return-type' diff --git a/avogadro/calc/chargemanager.cpp b/avogadro/calc/chargemanager.cpp index 53f4421e77..40d62bc76b 100644 --- a/avogadro/calc/chargemanager.cpp +++ b/avogadro/calc/chargemanager.cpp @@ -101,7 +101,7 @@ std::set ChargeManager::identifiersForMolecule( std::set identifiers = molecule.partialChargeTypes(); // check our models for compatibility - for (auto m_model : m_models) { + for (auto *m_model : m_models) { // We check that every element in the molecule // is handled by the model diff --git a/avogadro/calc/defaultmodel.cpp b/avogadro/calc/defaultmodel.cpp index b51f4b8a55..eb9e860cf3 100644 --- a/avogadro/calc/defaultmodel.cpp +++ b/avogadro/calc/defaultmodel.cpp @@ -8,14 +8,12 @@ #include #include -namespace Avogadro { +#include -using Core::Molecule; +namespace Avogadro::Calc { -namespace Calc { - -DefaultModel::DefaultModel(const std::string& id) - : ChargeModel(), m_identifier(id) +DefaultModel::DefaultModel(std::string id) + : ChargeModel(), m_identifier(std::move(id)) { // we don't know which elements are in the molecule // but we can just say all of them are okay @@ -30,5 +28,4 @@ MatrixX DefaultModel::partialCharges(Core::Molecule& mol) const return mol.partialCharges(m_identifier); } -} // namespace Calc } // namespace Avogadro diff --git a/avogadro/calc/defaultmodel.h b/avogadro/calc/defaultmodel.h index 66315a535a..3c50c4c349 100644 --- a/avogadro/calc/defaultmodel.h +++ b/avogadro/calc/defaultmodel.h @@ -32,7 +32,7 @@ namespace Calc { class AVOGADROCALC_EXPORT DefaultModel : public ChargeModel { public: - DefaultModel(const std::string& identifier = ""); + DefaultModel(std::string identifier = ""); virtual ~DefaultModel(); /** diff --git a/avogadro/core/atomutilities.cpp b/avogadro/core/atomutilities.cpp index 9c0f43e8ba..e0f89c61d7 100644 --- a/avogadro/core/atomutilities.cpp +++ b/avogadro/core/atomutilities.cpp @@ -75,7 +75,7 @@ Vector3 AtomUtilities::generateNewBondVector( return newPos; } else if (currentValence == 1) { // One bonded atom - Vector3 bond1 = allVectors[0]; + const Vector3& bond1 = allVectors[0]; // Check what's attached to our neighbor -- we want to set trans to the // neighbor @@ -147,8 +147,8 @@ Vector3 AtomUtilities::generateNewBondVector( return -1.0 * newPos.normalized(); } // end one bond else if (currentValence == 2) { - Vector3 bond1 = allVectors[0]; - Vector3 bond2 = allVectors[1]; + const Vector3& bond1 = allVectors[0]; + const Vector3& bond2 = allVectors[1]; Vector3 v1 = bond1 + bond2; v1.normalize(); @@ -170,9 +170,9 @@ Vector3 AtomUtilities::generateNewBondVector( return -1.0 * newPos.normalized(); } // end two bonds else if (currentValence == 3) { - Vector3 bond1 = allVectors[0]; - Vector3 bond2 = allVectors[1]; - Vector3 bond3 = allVectors[2]; + const Vector3& bond1 = allVectors[0]; + const Vector3& bond2 = allVectors[1]; + const Vector3& bond3 = allVectors[2]; // need to handle different hybridizations here diff --git a/avogadro/core/avospglib.cpp b/avogadro/core/avospglib.cpp index e65f2adf60..2451f11697 100644 --- a/avogadro/core/avospglib.cpp +++ b/avogadro/core/avospglib.cpp @@ -36,7 +36,7 @@ unsigned short AvoSpglib::getHallNumber(Molecule& mol, double cartTol) } Index numAtoms = mol.atomCount(); - auto positions = new double[numAtoms][3]; + auto *positions = new double[numAtoms][3]; int* types = new int[numAtoms]; const Array& atomicNums = mol.atomicNumbers(); @@ -111,7 +111,7 @@ bool AvoSpglib::standardizeCell(Molecule& mol, double cartTol, bool toPrimitive, // If toPrimitive is true, then we will just use the number of atoms. // See http://atztogo.github.io/spglib/api.html#spg-standardize-cell int numAtomsMultiplier = toPrimitive ? 1 : 4; - auto positions = new double[numAtoms * numAtomsMultiplier][3]; + auto *positions = new double[numAtoms * numAtomsMultiplier][3]; int* types = new int[numAtoms * numAtomsMultiplier]; const Array& atomicNums = mol.atomicNumbers(); diff --git a/avogadro/core/cube.cpp b/avogadro/core/cube.cpp index e05ab01eb5..bf3e1c2af7 100644 --- a/avogadro/core/cube.cpp +++ b/avogadro/core/cube.cpp @@ -118,7 +118,7 @@ const std::vector* Cube::data() const bool Cube::setData(const std::vector& values) { - if (!values.size()) + if (values.empty()) return false; if (static_cast(values.size()) == @@ -141,9 +141,9 @@ bool Cube::setData(const std::vector& values) bool Cube::addData(const std::vector& values) { // Initialise the cube to zero if necessary - if (!m_data.size()) + if (m_data.empty()) m_data.resize(m_points.x() * m_points.y() * m_points.z()); - if (values.size() != m_data.size() || !values.size()) + if (values.size() != m_data.size() || values.empty()) return false; for (unsigned int i = 0; i < m_data.size(); i++) { m_data[i] += values[i]; diff --git a/avogadro/core/elements.cpp b/avogadro/core/elements.cpp index e9b9b8ab84..19bc1ef6ec 100644 --- a/avogadro/core/elements.cpp +++ b/avogadro/core/elements.cpp @@ -13,7 +13,6 @@ #include #include -using Avogadro::Core::isCustomElement; namespace Avogadro::Core { diff --git a/avogadro/core/gaussiansettools.cpp b/avogadro/core/gaussiansettools.cpp index 72382090f5..3611dd6bb7 100644 --- a/avogadro/core/gaussiansettools.cpp +++ b/avogadro/core/gaussiansettools.cpp @@ -120,18 +120,12 @@ double GaussianSetTools::calculateSpinDensity(const Vector3& position) const bool GaussianSetTools::isValid() const { - if (m_molecule && dynamic_cast(m_molecule->basisSet())) - return true; - else - return false; + return m_molecule && dynamic_cast(m_molecule->basisSet()); } inline bool GaussianSetTools::isSmall(double val) const { - if (val > -1e-20 && val < 1e-20) - return true; - else - return false; + return val > -1e-20 && val < 1e-20; } inline vector GaussianSetTools::calculateValues( diff --git a/avogadro/core/graph.cpp b/avogadro/core/graph.cpp index e3ebced664..9646965b69 100644 --- a/avogadro/core/graph.cpp +++ b/avogadro/core/graph.cpp @@ -284,7 +284,7 @@ void Graph::removeEdge(size_t a, size_t b) std::vector& neighborsA = m_adjacencyList[a]; std::vector& neighborsB = m_adjacencyList[b]; - std::vector::iterator iter = + auto iter = std::find(neighborsA.begin(), neighborsA.end(), b); if (iter == neighborsA.end()) @@ -360,8 +360,8 @@ void Graph::removeEdges(size_t index) m_subgraphDirty[m_vertexToSubgraph[index]] = true; const std::vector& edges = m_edgeMap[index]; - for (size_t i = 0; i < edges.size(); ++i) - removeEdge(edges[i]); + for (unsigned long edge : edges) + removeEdge(edge); } void Graph::editEdgeInPlace(size_t edgeIndex, size_t a, size_t b) @@ -473,7 +473,7 @@ int Graph::createNewSubgraph() const { // Try to find an empty subgraph to reuse for (size_t i = 0; i < m_subgraphToVertices.size(); i++) { - if (!m_subgraphToVertices[i].size()) { + if (m_subgraphToVertices[i].empty()) { m_subgraphDirty[i] = false; return int(i); } @@ -515,7 +515,7 @@ void Graph::checkSplitSubgraph(int subgraph) const verticesToVisit.insert(verticesToVisit.end(), neighborList.begin(), neighborList.end()); } - } while (verticesToVisit.size()); + } while (!verticesToVisit.empty()); currentSubgraph = -1; } } @@ -538,7 +538,7 @@ std::vector> Graph::connectedComponents() const { updateSubgraphs(); std::vector> r; - for (std::set s : m_subgraphToVertices) { + for (const std::set& s : m_subgraphToVertices) { if (!s.empty()) r.push_back(s); } @@ -555,7 +555,7 @@ size_t Graph::subgraphsCount() const { updateSubgraphs(); size_t r = 0; - for (std::set s : m_subgraphToVertices) { + for (const std::set& s : m_subgraphToVertices) { if (!s.empty()) r++; } @@ -568,7 +568,7 @@ size_t Graph::subgraph(size_t element) const // Index -1 means disconnected (its own subgraph) if (r < 0) { r = m_subgraphToVertices.size(); - m_subgraphToVertices.push_back(std::set()); + m_subgraphToVertices.emplace_back(); m_subgraphToVertices[r].insert(element); m_subgraphDirty[r] = false; return r; diff --git a/avogadro/core/layermanager.cpp b/avogadro/core/layermanager.cpp index 938f845ab4..70644a5d31 100644 --- a/avogadro/core/layermanager.cpp +++ b/avogadro/core/layermanager.cpp @@ -73,7 +73,7 @@ void LayerManager::deleteMolecule(const Molecule* mol) auto aux = m_molToInfo.find(mol); if (aux != m_molToInfo.end()) { - auto id = aux->second->mol; + const auto *id = aux->second->mol; if (id == mol) { auto it = m_molToInfo.begin(); while (it != m_molToInfo.end()) { diff --git a/avogadro/core/mesh.cpp b/avogadro/core/mesh.cpp index f28c202513..3b2aa38241 100644 --- a/avogadro/core/mesh.cpp +++ b/avogadro/core/mesh.cpp @@ -121,7 +121,7 @@ const Color3f* Mesh::color(int n) const { // If there is only one color return that, otherwise colored by vertex. if (m_colors.size() == 1) - return &(m_colors[0]); + return m_colors.data(); else return &(m_colors[n * 3]); } @@ -149,10 +149,7 @@ bool Mesh::addColors(const Core::Array& values) bool Mesh::valid() const { if (m_vertices.size() == m_normals.size()) { - if (m_colors.size() == 1 || m_colors.size() == m_vertices.size()) - return true; - else - return false; + return m_colors.size() == 1 || m_colors.size() == m_vertices.size(); } else { return false; } @@ -179,7 +176,7 @@ Mesh& Mesh::operator=(const Mesh& other) void Mesh::smooth(int iterationCount) { - if (m_vertices.size() == 0) + if (m_vertices.empty()) return; if (iterationCount <= 0) return; diff --git a/avogadro/core/molecule.cpp b/avogadro/core/molecule.cpp index d4465c29d2..8759fa2308 100644 --- a/avogadro/core/molecule.cpp +++ b/avogadro/core/molecule.cpp @@ -262,7 +262,7 @@ MatrixX Molecule::partialCharges(const std::string& type) const std::set Molecule::partialChargeTypes() const { std::set types; - for (auto& it : m_partialCharges) + for (const auto& it : m_partialCharges) types.insert(it.first); return types; } @@ -324,9 +324,9 @@ signed char Molecule::totalCharge() const // check the data map first if (m_data.hasValue("totalCharge")) { charge = m_data.value("totalCharge").toInt(); - } else if (m_formalCharges.size() > 0) { - for (Index i = 0; i < m_formalCharges.size(); ++i) - charge += m_formalCharges[i]; + } else if (!m_formalCharges.empty()) { + for (signed char m_formalCharge : m_formalCharges) + charge += m_formalCharge; return charge; } return charge; // should be zero @@ -342,8 +342,8 @@ char Molecule::totalSpinMultiplicity() const } else { // add up the electrons unsigned long electrons = 0; - for (Index i = 0; i < m_atomicNumbers.size(); ++i) - electrons += m_atomicNumbers[i]; + for (unsigned char m_atomicNumber : m_atomicNumbers) + electrons += m_atomicNumber; // adjust by the total charge electrons -= totalCharge(); @@ -1274,7 +1274,7 @@ bool Molecule::removeBonds(Index atom) while (true) { const std::vector& bondList = m_graph.edges(atom); - if (!bondList.size()) + if (bondList.empty()) break; size_t bond = bondList[0]; removeBond(bond); diff --git a/avogadro/core/neighborperceiver.cpp b/avogadro/core/neighborperceiver.cpp index 969f70f48d..72de2fad2c 100644 --- a/avogadro/core/neighborperceiver.cpp +++ b/avogadro/core/neighborperceiver.cpp @@ -10,7 +10,7 @@ namespace Avogadro::Core { NeighborPerceiver::NeighborPerceiver(const Array points, float maxDistance) : m_maxDistance(maxDistance), m_cachedArray(nullptr) { - if (!points.size()) return; + if (points.empty()) return; // find bounding box m_minPos = points[0]; diff --git a/avogadro/core/ringperceiver.cpp b/avogadro/core/ringperceiver.cpp index 5fc9508ee6..e365b41727 100644 --- a/avogadro/core/ringperceiver.cpp +++ b/avogadro/core/ringperceiver.cpp @@ -384,7 +384,7 @@ std::vector> perceiveRings(const Graph& graph) std::vector candidates; for (size_t i = 0; i < n; i++) { for (size_t j = i + 1; j < n; j++) { - if (P(i, j).size() == 1 && Pt(i, j).size() == 0) { + if (P(i, j).size() == 1 && Pt(i, j).empty()) { continue; } else { size_t size; diff --git a/avogadro/core/secondarystructure.cpp b/avogadro/core/secondarystructure.cpp index c92dd7be1f..1b432e8220 100644 --- a/avogadro/core/secondarystructure.cpp +++ b/avogadro/core/secondarystructure.cpp @@ -23,7 +23,7 @@ SecondaryStructureAssigner::SecondaryStructureAssigner(Molecule* mol) SecondaryStructureAssigner::~SecondaryStructureAssigner() { - for (auto hBond : m_hBonds) + for (auto *hBond : m_hBonds) delete hBond; m_hBonds.clear(); } @@ -44,7 +44,7 @@ void SecondaryStructureAssigner::assign(Molecule* mol) float infinity = std::numeric_limits::max(); // Then assign the alpha helix by going through the hBond records - for (auto hBond : m_hBonds) { + for (auto *hBond : m_hBonds) { if (hBond->distSquared < infinity) { // check to see how far apart the residues are int separation = std::abs(int(hBond->residue - hBond->residuePair)); @@ -79,7 +79,7 @@ void SecondaryStructureAssigner::assign(Molecule* mol) } // Then assign the beta sheet - but only if a residue isn't assigned - for (auto hBond : m_hBonds) { + for (auto *hBond : m_hBonds) { if (hBond->distSquared < infinity) { if (m_molecule->residue(hBond->residue).secondaryStructure() == Residue::SecondaryStructure::undefined) @@ -89,7 +89,7 @@ void SecondaryStructureAssigner::assign(Molecule* mol) } // Check that sheets bond to other sheets - for (auto hBond : m_hBonds) { + for (auto *hBond : m_hBonds) { if (hBond->distSquared < infinity) { // find the match auto current = m_molecule->residue(hBond->residue); @@ -169,7 +169,7 @@ void SecondaryStructureAssigner::assignBackboneHydrogenBonds() const float maxDistSq = maxDist * maxDist; // 10.24 // delete any previous records - for (auto hBond : m_hBonds) + for (auto *hBond : m_hBonds) delete hBond; m_hBonds.clear(); @@ -204,7 +204,7 @@ void SecondaryStructureAssigner::assignBackboneHydrogenBonds() } } - if (m_hBonds.size() == 0) + if (m_hBonds.empty()) return; // sort by z-coordinate @@ -217,11 +217,11 @@ void SecondaryStructureAssigner::assignBackboneHydrogenBonds() // now loop through the sorted list (so we can exit quickly) int n = m_hBonds.size(); for (int i = 0; i < n; ++i) { - auto recordI = m_hBonds[i]; + auto *recordI = m_hBonds[i]; const Residue& residueI = m_molecule->residue(recordI->residue); for (int j = i + 1; j < n; ++j) { - auto recordJ = m_hBonds[j]; + auto *recordJ = m_hBonds[j]; const Residue& residueJ = m_molecule->residue(recordJ->residue); // skip if we're not on the same chain diff --git a/avogadro/core/slatersettools.cpp b/avogadro/core/slatersettools.cpp index a0a544f150..a0d0d9c567 100644 --- a/avogadro/core/slatersettools.cpp +++ b/avogadro/core/slatersettools.cpp @@ -74,18 +74,12 @@ double SlaterSetTools::calculateSpinDensity(const Vector3&) const bool SlaterSetTools::isValid() const { - if (m_molecule && dynamic_cast(m_molecule->basisSet())) - return true; - else - return false; + return m_molecule && dynamic_cast(m_molecule->basisSet()); } inline bool SlaterSetTools::isSmall(double val) const { - if (val > -1e-20 && val < 1e-20) - return true; - else - return false; + return val > -1e-20 && val < 1e-20; } vector SlaterSetTools::calculateValues(const Vector3& position) const diff --git a/avogadro/io/cjsonformat.cpp b/avogadro/io/cjsonformat.cpp index 2e45a1b950..3465d67247 100644 --- a/avogadro/io/cjsonformat.cpp +++ b/avogadro/io/cjsonformat.cpp @@ -55,7 +55,7 @@ bool setJsonKey(json& j, Molecule& m, const std::string& key) bool isNumericArray(json& j) { - if (j.is_array() && j.size() > 0) { + if (j.is_array() && !j.empty()) { for (const auto& v : j) { if (!v.is_number()) { return false; @@ -68,7 +68,7 @@ bool isNumericArray(json& j) bool isBooleanArray(json& j) { - if (j.is_array() && j.size() > 0) { + if (j.is_array() && !j.empty()) { for (const auto& v : j) { if (!v.is_boolean()) { return false; @@ -118,7 +118,7 @@ bool CjsonFormat::read(std::istream& file, Molecule& molecule) json atomicNumbers = atoms["elements"]["number"]; // This represents our minimal spec for a molecule - atoms that have an // atomic number. - if (isNumericArray(atomicNumbers) && atomicNumbers.size() > 0) { + if (isNumericArray(atomicNumbers) && !atomicNumbers.empty()) { for (auto& atomicNumber : atomicNumbers) molecule.addAtom(atomicNumber); } else { @@ -156,7 +156,7 @@ bool CjsonFormat::read(std::istream& file, Molecule& molecule) // Check for coordinate sets, and read them in if found, e.g. trajectories. json coordSets = atoms["coords"]["3dSets"]; - if (coordSets.is_array() && coordSets.size()) { + if (coordSets.is_array() && !coordSets.empty()) { for (unsigned int i = 0; i < coordSets.size(); ++i) { Array setArray; json set = coordSets[i]; @@ -408,7 +408,7 @@ bool CjsonFormat::read(std::istream& file, Molecule& molecule) } // Check for orbital coefficient sets, these are paired with coordinates // when they exist, but have constant basis set, atom types, etc. - if (orbitals["sets"].is_array() && orbitals["sets"].size()) { + if (orbitals["sets"].is_array() && !orbitals["sets"].empty()) { json orbSets = orbitals["sets"]; for (unsigned int idx = 0; idx < orbSets.size(); ++idx) { moCoefficients = orbSets[idx]["moCoefficients"]; @@ -472,7 +472,7 @@ bool CjsonFormat::read(std::istream& file, Molecule& molecule) if (isNumericArray(arr)) { Array mode; mode.resize(arr.size() / 3); - double* ptr = &mode[0][0]; + double* ptr = mode[0].data(); for (auto& j : arr) { *(ptr++) = static_cast(j); } @@ -590,7 +590,7 @@ bool CjsonFormat::write(std::ostream& file, const Molecule& molecule) if (molecule.basisSet() && dynamic_cast(molecule.basisSet())) { json basis; - auto gaussian = dynamic_cast(molecule.basisSet()); + const auto *gaussian = dynamic_cast(molecule.basisSet()); // Map the shell types from enumeration to integer values. auto symmetry = gaussian->symmetry(); @@ -617,7 +617,7 @@ bool CjsonFormat::write(std::ostream& file, const Molecule& molecule) basis["shellTypes"] = shellTypes; // This bit is slightly tricky, map from our index to primitives per shell. - if (gaussian->gtoIndices().size() && gaussian->atomIndices().size()) { + if (!gaussian->gtoIndices().empty() && !gaussian->atomIndices().empty()) { auto gtoIndices = gaussian->gtoIndices(); auto gtoA = gaussian->gtoA(); json primitivesPerShell; @@ -669,7 +669,7 @@ bool CjsonFormat::write(std::ostream& file, const Molecule& molecule) // Some energy, occupation, and number data potentially. auto energies = gaussian->moEnergy(); - if (energies.size() > 0) { + if (!energies.empty()) { json energyData; for (double& energie : energies) { energyData.push_back(energie); @@ -677,14 +677,14 @@ bool CjsonFormat::write(std::ostream& file, const Molecule& molecule) root["orbitals"]["energies"] = energyData; } auto occ = gaussian->moOccupancy(); - if (occ.size() > 0) { + if (!occ.empty()) { json occData; for (unsigned char& it : occ) occData.push_back(static_cast(it)); root["orbitals"]["occupations"] = occData; } auto num = gaussian->moNumber(); - if (num.size() > 0) { + if (!num.empty()) { json numData; for (unsigned int& it : num) numData.push_back(it); @@ -820,7 +820,7 @@ bool CjsonFormat::write(std::ostream& file, const Molecule& molecule) } // Create and populate any residue arrays - if (molecule.residues().size() > 0) { + if (!molecule.residues().empty()) { json residues; // array of objects for (auto residue : molecule.residues()) { json entry; @@ -849,7 +849,7 @@ bool CjsonFormat::write(std::ostream& file, const Molecule& molecule) } // If there is vibrational data write this out too. - if (molecule.vibrationFrequencies().size() > 0) { + if (!molecule.vibrationFrequencies().empty()) { // A few sanity checks before we begin. assert(molecule.vibrationFrequencies().size() == molecule.vibrationIRIntensities().size()); diff --git a/avogadro/io/cmlformat.cpp b/avogadro/io/cmlformat.cpp index fe42fbb83c..284bd075b4 100644 --- a/avogadro/io/cmlformat.cpp +++ b/avogadro/io/cmlformat.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #ifndef M_PI #define M_PI 3.14159265358979323846 @@ -51,7 +52,7 @@ class CmlFormatPrivate { public: CmlFormatPrivate(Molecule* mol, xml_document& document, std::string filename_) - : success(false), molecule(mol), moleculeNode(nullptr), filename(filename_) + : success(false), molecule(mol), moleculeNode(nullptr), filename(std::move(filename_)) { // Parse the CML document, and create molecules/elements as necessary. moleculeNode = document.child("molecule"); diff --git a/avogadro/io/fileformatmanager.cpp b/avogadro/io/fileformatmanager.cpp index 1841213ee0..2a98435dea 100644 --- a/avogadro/io/fileformatmanager.cpp +++ b/avogadro/io/fileformatmanager.cpp @@ -248,7 +248,7 @@ std::vector FileFormatManager::fileFormats( { std::vector result; - for (auto m_format : m_formats) { + for (auto *m_format : m_formats) { if (filter == FileFormat::None || (filter & m_format->supportedOperations()) == filter) { result.push_back(m_format); diff --git a/avogadro/io/gromacsformat.cpp b/avogadro/io/gromacsformat.cpp index d3e9430ee7..f0abe9280c 100644 --- a/avogadro/io/gromacsformat.cpp +++ b/avogadro/io/gromacsformat.cpp @@ -192,7 +192,7 @@ bool GromacsFormat::read(std::istream& in, Molecule& molecule) // v1(y) == v1(z) == v2(z) == 0 always. getline(in, buffer); vector tokens(split(buffer, ' ', true)); - if (tokens.size() > 0) { + if (!tokens.empty()) { if (tokens.size() != 3 && tokens.size() != 9) { appendError("Invalid box specification -- need either 3 or 9 values: '" + buffer + "'"); diff --git a/avogadro/io/lammpsformat.cpp b/avogadro/io/lammpsformat.cpp index 5c7d5a409e..d412fc05e3 100644 --- a/avogadro/io/lammpsformat.cpp +++ b/avogadro/io/lammpsformat.cpp @@ -18,7 +18,6 @@ #include #include -using std::endl; using std::getline; using std::map; using std::string; diff --git a/avogadro/io/mdlformat.cpp b/avogadro/io/mdlformat.cpp index dc5f9cf309..29da13223a 100644 --- a/avogadro/io/mdlformat.cpp +++ b/avogadro/io/mdlformat.cpp @@ -22,7 +22,6 @@ using Avogadro::Core::Atom; using Avogadro::Core::Bond; using Avogadro::Core::Elements; using Avogadro::Core::lexicalCast; -using Avogadro::Core::Molecule; using Avogadro::Core::startsWith; using Avogadro::Core::trimmed; diff --git a/avogadro/io/mmtfformat.cpp b/avogadro/io/mmtfformat.cpp index 10958f658b..5b6e2e84fb 100644 --- a/avogadro/io/mmtfformat.cpp +++ b/avogadro/io/mmtfformat.cpp @@ -29,7 +29,6 @@ using Core::Array; using Core::Elements; using Core::lexicalCast; using Core::Molecule; -using Core::Residue; MMTFFormat::MMTFFormat() = default; @@ -87,7 +86,7 @@ bool MMTFFormat::read(std::istream& file, Molecule& molecule) molecule.setUnitCell(unitCellObject); } // spaceGroup - if (structure.spaceGroup.size() > 0) { + if (!structure.spaceGroup.empty()) { unsigned short hall = 0; hall = Core::SpaceGroups::hallNumber(structure.spaceGroup); diff --git a/avogadro/io/pdbformat.cpp b/avogadro/io/pdbformat.cpp index 72366ded3e..ba6b5324aa 100644 --- a/avogadro/io/pdbformat.cpp +++ b/avogadro/io/pdbformat.cpp @@ -21,12 +21,10 @@ using Avogadro::Core::Array; using Avogadro::Core::Atom; using Avogadro::Core::Elements; using Avogadro::Core::lexicalCast; -using Avogadro::Core::Molecule; using Avogadro::Core::Residue; using Avogadro::Core::SecondaryStructureAssigner; using Avogadro::Core::startsWith; using Avogadro::Core::trimmed; -using Avogadro::Core::UnitCell; using std::getline; using std::istringstream; @@ -209,7 +207,7 @@ bool PdbFormat::read(std::istream& in, Core::Molecule& mol) int bCoords[] = { 11, 16, 21, 26 }; for (int i = 0; i < 4; i++) { - if (trimmed(buffer.substr(bCoords[i], 5)) == "") + if (trimmed(buffer.substr(bCoords[i], 5)).empty()) break; else { diff --git a/avogadro/io/turbomoleformat.cpp b/avogadro/io/turbomoleformat.cpp index 7722fac509..e9dfe6dfef 100644 --- a/avogadro/io/turbomoleformat.cpp +++ b/avogadro/io/turbomoleformat.cpp @@ -21,20 +21,16 @@ using json = nlohmann::json; -using std::endl; using std::getline; using std::string; using std::vector; namespace Avogadro::Io { -using Core::Array; using Core::Atom; using Core::Elements; using Core::lexicalCast; -using Core::Molecule; using Core::split; -using Core::trimmed; #ifndef _WIN32 using std::isalpha; diff --git a/avogadro/io/vaspformat.cpp b/avogadro/io/vaspformat.cpp index 60c98e1c8d..72e1141ee2 100644 --- a/avogadro/io/vaspformat.cpp +++ b/avogadro/io/vaspformat.cpp @@ -117,7 +117,7 @@ bool PoscarFormat::read(std::istream& inStream, Core::Molecule& mol) // In Vasp 4.x, symbols are in the title like so: " O4H2 " else { stringSplit = split(title, ' '); - if (stringSplit.size() != 0) { + if (!stringSplit.empty()) { string trimmedFormula = trimmed(stringSplit.at(0)); // Let's replace all numbers with spaces for (char & i : trimmedFormula) { @@ -141,7 +141,7 @@ bool PoscarFormat::read(std::istream& inStream, Core::Molecule& mol) // If we never filled up the atomic numbers, fill them up // now with "1, 2, 3…" - if (atomicNumbers.size() == 0) + if (atomicNumbers.empty()) for (size_t i = 1; i <= atomCounts.size(); ++i) atomicNumbers.push_back(i); diff --git a/avogadro/io/xyzformat.cpp b/avogadro/io/xyzformat.cpp index 448e05fdbc..cc61071cc1 100644 --- a/avogadro/io/xyzformat.cpp +++ b/avogadro/io/xyzformat.cpp @@ -32,7 +32,6 @@ namespace Avogadro::Io { using Core::Array; using Core::Atom; using Core::Elements; -using Core::Molecule; using Core::lexicalCast; using Core::split; using Core::trimmed; diff --git a/avogadro/molequeue/inputgenerator.cpp b/avogadro/molequeue/inputgenerator.cpp index 448da3115f..cb7b80bd21 100644 --- a/avogadro/molequeue/inputgenerator.cpp +++ b/avogadro/molequeue/inputgenerator.cpp @@ -279,7 +279,7 @@ bool InputGenerator::generateInput(const QJsonObject& options_, m_errors << tr("Response must be a JSON object at top-level."); } - if (result == false) + if (!result) m_errors << tr("Script output:\n%1").arg(QString(json)); return result; diff --git a/avogadro/molequeue/molequeuequeuelistmodel.cpp b/avogadro/molequeue/molequeuequeuelistmodel.cpp index efc09d85bf..8044de54e2 100644 --- a/avogadro/molequeue/molequeuequeuelistmodel.cpp +++ b/avogadro/molequeue/molequeuequeuelistmodel.cpp @@ -306,11 +306,8 @@ void MoleQueueQueueListModel::removeProgram(int queueRow, int progRow) bool MoleQueueQueueListModel::isQueueIndex(const QModelIndex& i) const { - if (i.isValid() && static_cast(i.internalId()) == QueueInternalId && - i.row() < m_queueList.size() && i.column() == 0) { - return true; - } - return false; + return i.isValid() && static_cast(i.internalId()) == QueueInternalId && + i.row() < m_queueList.size() && i.column() == 0; } bool MoleQueueQueueListModel::isProgramIndex(const QModelIndex& i) const diff --git a/avogadro/molequeue/molequeuewidget.cpp b/avogadro/molequeue/molequeuewidget.cpp index 6034239897..c983452ad7 100644 --- a/avogadro/molequeue/molequeuewidget.cpp +++ b/avogadro/molequeue/molequeuewidget.cpp @@ -137,7 +137,7 @@ MoleQueue::JobObject MoleQueueWidget::configuredJob() const // get queue/program QModelIndexList sel(m_ui->queueListView->selectionModel()->selectedIndexes()); - if (sel.size() < 1) { + if (sel.empty()) { QMessageBox::information(parentWidget(), tr("No program selected."), tr("Please select the target program from the " "\"Queue and Program\" list.")); @@ -296,7 +296,7 @@ void MoleQueueWidget::listenForJobStateChange(bool listen) bool MoleQueueWidget::programSelected() { QModelIndexList sel(m_ui->queueListView->selectionModel()->selectedIndexes()); - return sel.size() > 0; + return !sel.empty(); } } // namespace Avogadro diff --git a/avogadro/qtgui/colorbutton.cpp b/avogadro/qtgui/colorbutton.cpp index 321a3f17ad..65c21c8805 100644 --- a/avogadro/qtgui/colorbutton.cpp +++ b/avogadro/qtgui/colorbutton.cpp @@ -10,6 +10,7 @@ #include #include +#include namespace Avogadro::QtGui { @@ -21,8 +22,8 @@ ColorButton::ColorButton(QWidget* parent) connect(this, SIGNAL(clicked()), this, SLOT(changeColor())); } -ColorButton::ColorButton(const QColor& initial, QWidget* parent) - : QAbstractButton(parent), m_color(initial) +ColorButton::ColorButton(QColor initial, QWidget* parent) + : QAbstractButton(parent), m_color(std::move(initial)) { setMinimumSize(35, 20); diff --git a/avogadro/qtgui/colorbutton.h b/avogadro/qtgui/colorbutton.h index dc975616e0..0f6d3f4f6b 100644 --- a/avogadro/qtgui/colorbutton.h +++ b/avogadro/qtgui/colorbutton.h @@ -35,7 +35,7 @@ class AVOGADROQTGUI_EXPORT ColorButton : public QAbstractButton public: ColorButton(QWidget* parent = 0); - explicit ColorButton(const QColor& initial, QWidget* parent = 0); + explicit ColorButton(QColor initial, QWidget* parent = 0); /** * Redraw the widget (i.e., refresh the colored rectangle) diff --git a/avogadro/qtgui/fileformatdialog.cpp b/avogadro/qtgui/fileformatdialog.cpp index c5ca455097..eb29a5e16e 100644 --- a/avogadro/qtgui/fileformatdialog.cpp +++ b/avogadro/qtgui/fileformatdialog.cpp @@ -219,7 +219,7 @@ QString FileFormatDialog::generateFilterString( QString filterString; // Create a map that groups the file extensions by name: QMultiMap formatMap; - for (auto ff : ffs) { + for (const auto *ff : ffs) { QString name(QString::fromStdString(ff->name())); std::vector exts = ff->fileExtensions(); for (auto & eit : exts) { @@ -297,7 +297,7 @@ const Io::FileFormat* FileFormatDialog::selectFileFormat( // If more than one format found, prompt user to select one. QStringList idents; - for (auto ff : ffs) { + for (const auto *ff : ffs) { idents << QString::fromStdString(ff->identifier()); } diff --git a/avogadro/qtgui/hydrogentools.cpp b/avogadro/qtgui/hydrogentools.cpp index 3187889dbf..9d03677dbf 100644 --- a/avogadro/qtgui/hydrogentools.cpp +++ b/avogadro/qtgui/hydrogentools.cpp @@ -27,7 +27,6 @@ using Avogadro::Core::Array; using Avogadro::Core::atomValence; using Avogadro::QtGui::RWAtom; using Avogadro::QtGui::RWBond; -using Avogadro::QtGui::RWMolecule; namespace { diff --git a/avogadro/qtgui/interfacescript.cpp b/avogadro/qtgui/interfacescript.cpp index 96b9adb40e..ff3af1bc6f 100644 --- a/avogadro/qtgui/interfacescript.cpp +++ b/avogadro/qtgui/interfacescript.cpp @@ -406,7 +406,7 @@ bool InterfaceScript::generateInput(const QJsonObject& options_, m_errors << tr("Response must be a JSON object at top-level."); } - if (result == false) + if (!result) m_errors << tr("Script output:\n%1").arg(QString(json)); return result; diff --git a/avogadro/qtgui/jsonwidget.cpp b/avogadro/qtgui/jsonwidget.cpp index 424c85444e..9f31fdf163 100644 --- a/avogadro/qtgui/jsonwidget.cpp +++ b/avogadro/qtgui/jsonwidget.cpp @@ -259,7 +259,7 @@ void JsonWidget::combinedOptionRow(const QString& label1, const QString& label2, m_widgets.insert(label1, widget1); } if (bothLabels) { - QLabel* label = new QLabel(tr2 + ":"); + auto* label = new QLabel(tr2 + ":"); hbox->addWidget(label); } if (option2) { @@ -316,7 +316,7 @@ void JsonWidget::addOptionRow(const QString& key, const QString& name, if (hide) { widget->hide(); // find the label and hide that too - auto fLabel = form->labelForField(widget); + auto *fLabel = form->labelForField(widget); if (fLabel) fLabel->hide(); } diff --git a/avogadro/qtgui/layermodel.cpp b/avogadro/qtgui/layermodel.cpp index 17ca8a13bf..b5cd2f35db 100644 --- a/avogadro/qtgui/layermodel.cpp +++ b/avogadro/qtgui/layermodel.cpp @@ -14,7 +14,6 @@ namespace Avogadro::QtGui { -using Core::LayerManager; namespace { const int QTTY_COLUMNS = 6; diff --git a/avogadro/qtgui/moleculemodel.cpp b/avogadro/qtgui/moleculemodel.cpp index e163e1c39a..29d4f1cce7 100644 --- a/avogadro/qtgui/moleculemodel.cpp +++ b/avogadro/qtgui/moleculemodel.cpp @@ -150,8 +150,7 @@ QList MoleculeModel::activeMolecules() const { QList result; foreach (Molecule* mol, m_molecules) { - if (true) - result << mol; + result << mol; } return result; } diff --git a/avogadro/qtgui/multiviewwidget.cpp b/avogadro/qtgui/multiviewwidget.cpp index 25f283951e..aa50c9cc24 100644 --- a/avogadro/qtgui/multiviewwidget.cpp +++ b/avogadro/qtgui/multiviewwidget.cpp @@ -120,7 +120,7 @@ void MultiViewWidget::createView() auto* container = qobject_cast(optionsWidget->parentWidget()); if (container) { - auto widget = m_factory->createView(button->property("name").toString()); + auto *widget = m_factory->createView(button->property("name").toString()); if (widget) { widget->installEventFilter(m_activeFilter); container->layout()->removeWidget(optionsWidget); diff --git a/avogadro/qtgui/pluginlayermanager.cpp b/avogadro/qtgui/pluginlayermanager.cpp index 90a0f8b5d2..c360bb3424 100644 --- a/avogadro/qtgui/pluginlayermanager.cpp +++ b/avogadro/qtgui/pluginlayermanager.cpp @@ -10,6 +10,7 @@ #include #include +#include #include namespace Avogadro::QtGui { @@ -17,7 +18,7 @@ namespace Avogadro::QtGui { using std::string; using std::vector; -PluginLayerManager::PluginLayerManager(const string& name) : m_name(name) {} +PluginLayerManager::PluginLayerManager(string name) : m_name(std::move(name)) {} PluginLayerManager::~PluginLayerManager() { diff --git a/avogadro/qtgui/pluginlayermanager.h b/avogadro/qtgui/pluginlayermanager.h index fa97b52625..b0cb4350ef 100644 --- a/avogadro/qtgui/pluginlayermanager.h +++ b/avogadro/qtgui/pluginlayermanager.h @@ -23,7 +23,7 @@ namespace QtGui { class AVOGADROQTGUI_EXPORT PluginLayerManager : protected Core::LayerManager { public: - PluginLayerManager(const std::string& name = "undef"); + PluginLayerManager(std::string name = "undef"); ~PluginLayerManager(); diff --git a/avogadro/qtgui/pythonscript.cpp b/avogadro/qtgui/pythonscript.cpp index fa51d26ed8..d3c08faf85 100644 --- a/avogadro/qtgui/pythonscript.cpp +++ b/avogadro/qtgui/pythonscript.cpp @@ -13,12 +13,13 @@ #include #include #include +#include namespace Avogadro::QtGui { -PythonScript::PythonScript(const QString& scriptFilePath_, QObject* parent_) +PythonScript::PythonScript(QString scriptFilePath_, QObject* parent_) : QObject(parent_), m_debug(!qgetenv("AVO_PYTHON_SCRIPT_DEBUG").isEmpty()), - m_scriptFilePath(scriptFilePath_), m_process(nullptr) + m_scriptFilePath(std::move(scriptFilePath_)), m_process(nullptr) { setDefaultPythonInterpretor(); } diff --git a/avogadro/qtgui/pythonscript.h b/avogadro/qtgui/pythonscript.h index 28a259ce3e..a2befdd791 100644 --- a/avogadro/qtgui/pythonscript.h +++ b/avogadro/qtgui/pythonscript.h @@ -32,7 +32,7 @@ class AVOGADROQTGUI_EXPORT PythonScript : public QObject * @param scriptFilePath_ Absolute path to python script. * @{ */ - explicit PythonScript(const QString& scriptFilePath_, + explicit PythonScript(QString scriptFilePath_, QObject* parent_ = nullptr); explicit PythonScript(QObject* parent_ = nullptr); /**@}*/ diff --git a/avogadro/qtgui/rwlayermanager.cpp b/avogadro/qtgui/rwlayermanager.cpp index 6f9ccb787e..cae630f3ad 100644 --- a/avogadro/qtgui/rwlayermanager.cpp +++ b/avogadro/qtgui/rwlayermanager.cpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace Avogadro::QtGui { @@ -29,7 +30,7 @@ class AddLayerCommand : public QUndoCommand { public: AddLayerCommand(shared_ptr mol) - : QUndoCommand(QObject::tr("Modify Layers")), m_moleculeInfo(mol) + : QUndoCommand(QObject::tr("Modify Layers")), m_moleculeInfo(std::move(mol)) { m_visible = true; m_locked = false; @@ -42,7 +43,7 @@ class AddLayerCommand : public QUndoCommand } // now we do the same thing for settings for (const auto& names : m_moleculeInfo->settings) { - auto value = names.second[activeLayer]; + auto *value = names.second[activeLayer]; m_settings[names.first] = value; } @@ -102,7 +103,7 @@ class ActiveLayerCommand : public QUndoCommand { public: ActiveLayerCommand(shared_ptr mol, size_t layer) - : QUndoCommand(QObject::tr("Modify Layers")), m_moleculeInfo(mol), + : QUndoCommand(QObject::tr("Modify Layers")), m_moleculeInfo(std::move(mol)), m_newActiveLayer(layer) { m_oldActiveLayer = m_moleculeInfo->layer.activeLayer(); @@ -128,7 +129,7 @@ class RemoveLayerCommand : public QUndoCommand { public: RemoveLayerCommand(shared_ptr mol, size_t layer) - : QUndoCommand(QObject::tr("Modify Layers")), m_moleculeInfo(mol), + : QUndoCommand(QObject::tr("Modify Layers")), m_moleculeInfo(std::move(mol)), m_layer(layer) {} diff --git a/avogadro/qtgui/rwmolecule.cpp b/avogadro/qtgui/rwmolecule.cpp index 703b8a6649..26f9df93b4 100644 --- a/avogadro/qtgui/rwmolecule.cpp +++ b/avogadro/qtgui/rwmolecule.cpp @@ -18,7 +18,6 @@ namespace Avogadro::QtGui { using Core::Array; -using Core::AtomHybridization; using Core::CrystalTools; using Core::UnitCell; using std::swap; @@ -70,7 +69,7 @@ bool RWMolecule::removeAtom(Index atomId) // Remove any bonds containing this atom first. Array atomBonds = bonds(atomId); - while (atomBonds.size()) { + while (!atomBonds.empty()) { // Ensure that indices aren't invalidated as we remove them: assert("atomBonds have ascending indices" && (atomBonds.size() == 1 || diff --git a/avogadro/qtplugins/3dmol/3dmoldialog.cpp b/avogadro/qtplugins/3dmol/3dmoldialog.cpp index a148f15535..d24d4a23e2 100644 --- a/avogadro/qtplugins/3dmol/3dmoldialog.cpp +++ b/avogadro/qtplugins/3dmol/3dmoldialog.cpp @@ -26,7 +26,6 @@ #include -using Avogadro::QtGui::Molecule; namespace Avogadro::QtPlugins { diff --git a/avogadro/qtplugins/applycolors/applycolors.cpp b/avogadro/qtplugins/applycolors/applycolors.cpp index 889fe71ca1..204cc631ae 100644 --- a/avogadro/qtplugins/applycolors/applycolors.cpp +++ b/avogadro/qtplugins/applycolors/applycolors.cpp @@ -289,7 +289,7 @@ void ApplyColors::applyChargeColors() void ApplyColors::applyDistanceColors() { - if (m_molecule == nullptr && m_molecule->atomCount() == 0) + if (m_molecule == nullptr || m_molecule->atomCount() == 0) return; bool isSelection = !m_molecule->isSelectionEmpty(); diff --git a/avogadro/qtplugins/ballandstick/ballandstick.cpp b/avogadro/qtplugins/ballandstick/ballandstick.cpp index 69972d1514..9bc6501c7d 100644 --- a/avogadro/qtplugins/ballandstick/ballandstick.cpp +++ b/avogadro/qtplugins/ballandstick/ballandstick.cpp @@ -27,7 +27,6 @@ using Core::Elements; using QtGui::PluginLayerManager; using Rendering::CylinderGeometry; using Rendering::GeometryNode; -using Rendering::GroupNode; using Rendering::SphereGeometry; struct LayerBallAndStick : Core::LayerData @@ -134,7 +133,7 @@ void BallAndStick::process(const QtGui::Molecule& molecule, auto* geometry = new GeometryNode; node.addChild(geometry); auto* spheres = new SphereGeometry; - auto selectedSpheres = new SphereGeometry; + auto *selectedSpheres = new SphereGeometry; selectedSpheres->setOpacity(0.42); spheres->identifier().molecule = reinterpret_cast(&molecule); spheres->identifier().type = Rendering::AtomType; diff --git a/avogadro/qtplugins/bondcentrictool/bondcentrictool.cpp b/avogadro/qtplugins/bondcentrictool/bondcentrictool.cpp index ea83c7b0b1..1368142433 100644 --- a/avogadro/qtplugins/bondcentrictool/bondcentrictool.cpp +++ b/avogadro/qtplugins/bondcentrictool/bondcentrictool.cpp @@ -56,10 +56,6 @@ using QtGui::RWMolecule; using Rendering::ArcSector; using Rendering::ArcStrip; using Rendering::GeometryNode; -using Rendering::GroupNode; -using Rendering::Identifier; -using Rendering::LineStripGeometry; -using Rendering::MeshGeometry; using Rendering::Quad; using Rendering::QuadOutline; diff --git a/avogadro/qtplugins/cartoons/cartoons.cpp b/avogadro/qtplugins/cartoons/cartoons.cpp index 801bde9f05..ee3ebb5a5e 100644 --- a/avogadro/qtplugins/cartoons/cartoons.cpp +++ b/avogadro/qtplugins/cartoons/cartoons.cpp @@ -36,7 +36,6 @@ using Rendering::BSplineGeometry; using Rendering::Cartoon; using Rendering::CylinderGeometry; using Rendering::GeometryNode; -using Rendering::GroupNode; using Rendering::SphereGeometry; using std::list; using std::map; @@ -143,10 +142,10 @@ struct LayerCartoon : Core::LayerData struct BackboneResidue { BackboneResidue() {} - BackboneResidue(const Vector3f p, const Vector3ub& c1, const Vector3ub& c2, + BackboneResidue(const Vector3f p, Vector3ub c1, Vector3ub c2, const size_t& g, size_t id, bool sel, Residue::SecondaryStructure sec) - : pos(p), color1(c1), color2(c2), group(g), residueID(id), selected(sel), + : pos(p), color1(std::move(c1)), color2(std::move(c2)), group(g), residueID(id), selected(sel), secondaryStructure(sec) {} @@ -357,10 +356,10 @@ void Cartoons::process(const Molecule& molecule, Rendering::GroupNode& node) interface.showRibbon || interface.showSimpleCartoon || interface.showCartoon || interface.showRope) { map backbones; - if (molecule.residues().size() > 0) { + if (!molecule.residues().empty()) { backbones = getBackboneByResidues(molecule, layer); } - if (backbones.size() == 0) { + if (backbones.empty()) { continue; // maybe something in a different layer } size_t i = 0; diff --git a/avogadro/qtplugins/closecontacts/closecontacts.cpp b/avogadro/qtplugins/closecontacts/closecontacts.cpp index 48af058a9b..e6ebf8beb1 100644 --- a/avogadro/qtplugins/closecontacts/closecontacts.cpp +++ b/avogadro/qtplugins/closecontacts/closecontacts.cpp @@ -33,7 +33,6 @@ using QtGui::Molecule; using QtGui::PluginLayerManager; using Rendering::DashedLineGeometry; using Rendering::GeometryNode; -using Rendering::GroupNode; CloseContacts::CloseContacts(QObject *p) : ScenePlugin(p) { diff --git a/avogadro/qtplugins/coloropacitymap/coloropacitymap.cpp b/avogadro/qtplugins/coloropacitymap/coloropacitymap.cpp index 2198c02ad1..a6f667ba65 100644 --- a/avogadro/qtplugins/coloropacitymap/coloropacitymap.cpp +++ b/avogadro/qtplugins/coloropacitymap/coloropacitymap.cpp @@ -33,7 +33,7 @@ namespace Avogadro::QtPlugins { vtkImageData* cubeImageData(Core::Cube* cube) { - auto data = vtkImageData::New(); + auto *data = vtkImageData::New(); // data->SetNumberOfScalarComponents(1, nullptr); Eigen::Vector3i dim = cube->dimensions(); data->SetExtent(0, dim.x() - 1, 0, dim.y() - 1, 0, dim.z() - 1); @@ -121,8 +121,8 @@ void ColorOpacityMap::updateActions() void ColorOpacityMap::updateHistogram() { - auto widget = ActiveObjects::instance().activeWidget(); - auto vtkWidget = qobject_cast(widget); + auto *widget = ActiveObjects::instance().activeWidget(); + auto *vtkWidget = qobject_cast(widget); if (widget && vtkWidget && widget != m_activeWidget) { if (m_activeWidget) @@ -133,9 +133,9 @@ void ColorOpacityMap::updateHistogram() if (vtkWidget && m_molecule && m_molecule->cubeCount()) { vtkNew table; - auto imageData = vtkWidget->imageData(); - auto lut = vtkWidget->lut(); - auto opacity = vtkWidget->opacityFunction(); + auto *imageData = vtkWidget->imageData(); + auto *lut = vtkWidget->lut(); + auto *opacity = vtkWidget->opacityFunction(); m_histogramWidget->setLUT(lut); m_histogramWidget->setOpacityFunction(opacity); @@ -149,7 +149,7 @@ void ColorOpacityMap::updateHistogram() void ColorOpacityMap::displayDialog() { if (!m_comDialog) { - auto p = qobject_cast(parent()); + auto *p = qobject_cast(parent()); m_comDialog = new ComDialog(p); m_comDialog->setMolecule(m_molecule); m_histogramWidget = m_comDialog->histogramWidget(); @@ -164,8 +164,8 @@ void ColorOpacityMap::displayDialog() void ColorOpacityMap::render() { - auto widget = ActiveObjects::instance().activeWidget(); - auto vtkWidget = qobject_cast(widget); + auto *widget = ActiveObjects::instance().activeWidget(); + auto *vtkWidget = qobject_cast(widget); if (vtkWidget) { vtkWidget->renderWindow()->Render(); vtkWidget->update(); diff --git a/avogadro/qtplugins/coloropacitymap/comdialog.cpp b/avogadro/qtplugins/coloropacitymap/comdialog.cpp index 8b9c995da0..afb2c6ea8d 100644 --- a/avogadro/qtplugins/coloropacitymap/comdialog.cpp +++ b/avogadro/qtplugins/coloropacitymap/comdialog.cpp @@ -53,28 +53,28 @@ void ComDialog::setMolecule(QtGui::Molecule* mol) void ComDialog::enableVolume(int enable) { - auto w = ActiveObjects::instance().activeWidget(); - auto vtkgl = qobject_cast(w); + auto *w = ActiveObjects::instance().activeWidget(); + auto *vtkgl = qobject_cast(w); if (vtkgl) { - vtkgl->renderVolume(enable == 0 ? false : true); + vtkgl->renderVolume(enable != 0); emit renderNeeded(); } } void ComDialog::enableIsosurface(int enable) { - auto w = ActiveObjects::instance().activeWidget(); - auto vtkgl = qobject_cast(w); + auto *w = ActiveObjects::instance().activeWidget(); + auto *vtkgl = qobject_cast(w); if (vtkgl) { - vtkgl->renderIsosurface(enable == 0 ? false : true); + vtkgl->renderIsosurface(enable != 0); emit renderNeeded(); } } void ComDialog::setIsoValue(double value) { - auto w = ActiveObjects::instance().activeWidget(); - auto vtkgl = qobject_cast(w); + auto *w = ActiveObjects::instance().activeWidget(); + auto *vtkgl = qobject_cast(w); if (vtkgl) { vtkgl->setIsoValue(value); emit renderNeeded(); @@ -83,8 +83,8 @@ void ComDialog::setIsoValue(double value) void ComDialog::setOpacity(double value) { - auto w = ActiveObjects::instance().activeWidget(); - auto vtkgl = qobject_cast(w); + auto *w = ActiveObjects::instance().activeWidget(); + auto *vtkgl = qobject_cast(w); if (vtkgl) { vtkgl->setOpacity(value); emit renderNeeded(); diff --git a/avogadro/qtplugins/coloropacitymap/histogramwidget.cpp b/avogadro/qtplugins/coloropacitymap/histogramwidget.cpp index 486e2e2585..fbacef7001 100644 --- a/avogadro/qtplugins/coloropacitymap/histogramwidget.cpp +++ b/avogadro/qtplugins/coloropacitymap/histogramwidget.cpp @@ -54,7 +54,7 @@ HistogramWidget::HistogramWidget(QWidget* parent) vtkControlPointsItem::CurrentPointEditEvent, this, SLOT(onCurrentPointEditEvent())); - auto hLayout = new QHBoxLayout(this); + auto *hLayout = new QHBoxLayout(this); hLayout->addWidget(m_qvtk); setLayout(hLayout); } diff --git a/avogadro/qtplugins/editor/editor.cpp b/avogadro/qtplugins/editor/editor.cpp index 1538177693..7dd9891a5e 100644 --- a/avogadro/qtplugins/editor/editor.cpp +++ b/avogadro/qtplugins/editor/editor.cpp @@ -55,7 +55,6 @@ using QtGui::RWBond; using Avogadro::Core::Elements; using Avogadro::Rendering::GeometryNode; -using Avogadro::Rendering::GroupNode; using Avogadro::Rendering::Identifier; using Avogadro::Rendering::TextLabel2D; using Avogadro::Rendering::TextProperties; diff --git a/avogadro/qtplugins/focus/focus.cpp b/avogadro/qtplugins/focus/focus.cpp index 3a8e3b59f1..e59a18e296 100644 --- a/avogadro/qtplugins/focus/focus.cpp +++ b/avogadro/qtplugins/focus/focus.cpp @@ -15,7 +15,6 @@ namespace Avogadro::QtPlugins { -using Avogadro::QtGui::ExtensionPlugin; Focus::Focus(QObject* parent_) : ExtensionPlugin(parent_), diff --git a/avogadro/qtplugins/force/force.cpp b/avogadro/qtplugins/force/force.cpp index 6430ac88cf..3308b03241 100644 --- a/avogadro/qtplugins/force/force.cpp +++ b/avogadro/qtplugins/force/force.cpp @@ -20,10 +20,8 @@ namespace Avogadro::QtPlugins { -using QtGui::Molecule; using Rendering::ArrowGeometry; using Rendering::GeometryNode; -using Rendering::GroupNode; Force::Force(QObject* p) : ScenePlugin(p) { diff --git a/avogadro/qtplugins/insertfragment/insertfragment.cpp b/avogadro/qtplugins/insertfragment/insertfragment.cpp index 99b6f5e58d..07f1ff3203 100644 --- a/avogadro/qtplugins/insertfragment/insertfragment.cpp +++ b/avogadro/qtplugins/insertfragment/insertfragment.cpp @@ -20,7 +20,6 @@ #include #include -using Avogadro::Io::FileFormatManager; using Avogadro::QtGui::Molecule; namespace Avogadro::QtPlugins { diff --git a/avogadro/qtplugins/insertfragment/insertfragmentdialog.cpp b/avogadro/qtplugins/insertfragment/insertfragmentdialog.cpp index 78a96cce52..eb9d8e81ed 100644 --- a/avogadro/qtplugins/insertfragment/insertfragmentdialog.cpp +++ b/avogadro/qtplugins/insertfragment/insertfragmentdialog.cpp @@ -62,10 +62,7 @@ InsertFragmentDialog::InsertFragmentDialog(QWidget* aParent, QString directory, m_ui->setupUi(this); m_implementation->currentFileName.clear(); - if (directory.contains(QLatin1String("crystals"))) - m_implementation->crystalFiles = true; - else - m_implementation->crystalFiles = false; + m_implementation->crystalFiles = directory.contains(QLatin1String("crystals")); // we check for the downloaded version first QStringList dirs; diff --git a/avogadro/qtplugins/label/label.cpp b/avogadro/qtplugins/label/label.cpp index d7aa6cf742..56e3cfbe42 100644 --- a/avogadro/qtplugins/label/label.cpp +++ b/avogadro/qtplugins/label/label.cpp @@ -30,7 +30,6 @@ using Core::Elements; using Core::Molecule; using QtGui::PluginLayerManager; using Rendering::GeometryNode; -using Rendering::GroupNode; using std::map; typedef Array NeighborListType; @@ -95,12 +94,9 @@ struct LayerLabel : Core::LayerData std::string serialize() final { - /// FIXME: What is this attempting to do? It causes compiler warnings. - std::string aux = (const char*)atomOptions; - std::string aux2 = (const char*)residueOptions; - return aux + " " + aux2 + " " + std::to_string(radiusScalar) + " " + - std::to_string(color[0]) + " " + std::to_string(color[1]) + " " + - std::to_string(color[2]); + return std::to_string(atomOptions) + " " + std::to_string(residueOptions) + + " " + std::to_string(radiusScalar) + " " + std::to_string(color[0]) + + " " + std::to_string(color[1]) + " " + std::to_string(color[2]); } void deserialize(std::string text) final { @@ -157,17 +153,17 @@ struct LayerLabel : Core::LayerData val = LabelOptions::Custom; } if (option & LabelOptions::Index) { - text << ((text.size() == 0) ? QObject::tr("Index") + text << ((text.empty()) ? QObject::tr("Index") : QObject::tr("In.")); val |= LabelOptions::Index; } if (option & LabelOptions::Name) { - text << ((text.size() == 0) ? QObject::tr("Element") + text << ((text.empty()) ? QObject::tr("Element") : QObject::tr("El.")); val |= LabelOptions::Name; } if (option & LabelOptions::Ordinal) { - text << ((text.size() == 0) ? QObject::tr("Element & Number") + text << ((text.empty()) ? QObject::tr("Element & Number") : QObject::tr("El.&No.")); val |= LabelOptions::Ordinal; } @@ -275,12 +271,12 @@ void Label::processResidue(const Core::Molecule& molecule, auto& interface = m_layerManager.getSetting(layer); Vector3ub color = interface.color; - std::string text = ""; + std::string text; if (interface.residueOptions & LayerLabel::LabelOptions::Index) { text = std::to_string(residue.residueId()); } if (interface.residueOptions & LayerLabel::LabelOptions::Name) { - text += (text == "" ? "" : " / ") + name; + text += (text.empty() ? "" : " / ") + name; } TextLabel3D* residueLabel = createLabel(text, pos, radius, color); geometry->addDrawable(residueLabel); @@ -309,23 +305,23 @@ void Label::processAtom(const Core::Molecule& molecule, } auto& interface = m_layerManager.getSetting(layer); - std::string text = ""; + std::string text; if (interface.atomOptions & LayerLabel::LabelOptions::Custom) { - text += (text == "" ? "" : " / ") + atom.label(); + text += (text.empty() ? "" : " / ") + atom.label(); } if (interface.atomOptions & LayerLabel::LabelOptions::Index) { - text += (text == "" ? "" : " / ") + std::to_string(atom.index() + 1); + text += (text.empty() ? "" : " / ") + std::to_string(atom.index() + 1); } if (interface.atomOptions & LayerLabel::LabelOptions::Name) { text += - (text == "" ? "" : " / ") + std::string(Elements::symbol(atomicNumber)); + (text.empty() ? "" : " / ") + std::string(Elements::symbol(atomicNumber)); } if (interface.atomOptions & LayerLabel::LabelOptions::Ordinal) { - text += (text == "" ? "" : " / ") + + text += (text.empty() ? "" : " / ") + std::string(Elements::symbol(atomicNumber) + std::to_string(atomCount[atomicNumber])); } - if (text != "") { + if (!text.empty()) { const Vector3f pos(atom.position3d().cast()); Vector3ub color = interface.color; float radius = static_cast(Elements::radiusVDW(atomicNumber)) * @@ -388,4 +384,4 @@ QWidget* Label::setupWidget() return interface.widget; } -} // namespace Avogadro +} // namespace Avogadro::QtPlugins diff --git a/avogadro/qtplugins/lammpsinput/lammpsinputdialog.cpp b/avogadro/qtplugins/lammpsinput/lammpsinputdialog.cpp index 95da2615e0..e583403ce4 100644 --- a/avogadro/qtplugins/lammpsinput/lammpsinputdialog.cpp +++ b/avogadro/qtplugins/lammpsinput/lammpsinputdialog.cpp @@ -455,10 +455,7 @@ void LammpsInputDialog::setWaterPotential(int n) void LammpsInputDialog::setReadData() { m_readData = ui.readDataLine->text(); - if (m_readData != "") - readData = true; - else - readData = false; + readData = m_readData != ""; updatePreviewText(); } diff --git a/avogadro/qtplugins/licorice/licorice.cpp b/avogadro/qtplugins/licorice/licorice.cpp index 3c5c16ee0e..f2446cc659 100644 --- a/avogadro/qtplugins/licorice/licorice.cpp +++ b/avogadro/qtplugins/licorice/licorice.cpp @@ -18,7 +18,6 @@ using QtGui::Molecule; using QtGui::PluginLayerManager; using Rendering::CylinderGeometry; using Rendering::GeometryNode; -using Rendering::GroupNode; using Rendering::SphereGeometry; Licorice::Licorice(QObject* p) : ScenePlugin(p) @@ -40,7 +39,7 @@ void Licorice::process(const Molecule& molecule, Rendering::GroupNode& node) auto* spheres = new SphereGeometry; spheres->identifier().molecule = &molecule; spheres->identifier().type = Rendering::AtomType; - auto selectedSpheres = new SphereGeometry; + auto *selectedSpheres = new SphereGeometry; selectedSpheres->setOpacity(0.42); geometry->addDrawable(spheres); geometry->addDrawable(selectedSpheres); diff --git a/avogadro/qtplugins/measuretool/measuretool.cpp b/avogadro/qtplugins/measuretool/measuretool.cpp index 2886a77375..4fb39cd704 100644 --- a/avogadro/qtplugins/measuretool/measuretool.cpp +++ b/avogadro/qtplugins/measuretool/measuretool.cpp @@ -39,7 +39,6 @@ using Avogadro::Core::Elements; using Avogadro::Rendering::GeometryNode; -using Avogadro::Rendering::GroupNode; using Avogadro::Rendering::Identifier; using Avogadro::Rendering::TextLabel2D; using Avogadro::Rendering::TextLabel3D; @@ -147,7 +146,7 @@ void MeasureTool::createLabels(T* mol, GeometryNode* geo, void MeasureTool::draw(Rendering::GroupNode& node) { - if (m_atoms.size() == 0) + if (m_atoms.empty()) return; auto* geo = new GeometryNode; diff --git a/avogadro/qtplugins/meshes/meshes.cpp b/avogadro/qtplugins/meshes/meshes.cpp index 6348df675b..e0d26c1631 100644 --- a/avogadro/qtplugins/meshes/meshes.cpp +++ b/avogadro/qtplugins/meshes/meshes.cpp @@ -77,7 +77,7 @@ void Meshes::process(const QtGui::Molecule& mol, GroupNode& node) Core::Array indices(mesh->numVertices()); std::generate(indices.begin(), indices.end(), indexGenerator); - bool hasColors = (mesh->colors().size() != 0); + bool hasColors = (!mesh->colors().empty()); auto* mesh1 = new MeshGeometry; geometry->addDrawable(mesh1); diff --git a/avogadro/qtplugins/molecularproperties/molecularpropertiesdialog.cpp b/avogadro/qtplugins/molecularproperties/molecularpropertiesdialog.cpp index d1510382fa..58d019e79e 100644 --- a/avogadro/qtplugins/molecularproperties/molecularpropertiesdialog.cpp +++ b/avogadro/qtplugins/molecularproperties/molecularpropertiesdialog.cpp @@ -22,7 +22,6 @@ #include #include -using Avogadro::QtGui::Molecule; namespace Avogadro::QtPlugins { @@ -238,7 +237,7 @@ void MolecularPropertiesDialog::copy() tr("Number of Bonds:") + QString(" %1\n").arg(m_molecule->bondCount()); // include both HTML and plain text - QMimeData* mimeData = new QMimeData(); + auto* mimeData = new QMimeData(); mimeData->setText(text); mimeData->setHtml(html); QApplication::clipboard()->setMimeData(mimeData); diff --git a/avogadro/qtplugins/noncovalent/noncovalent.cpp b/avogadro/qtplugins/noncovalent/noncovalent.cpp index 8d10cb8553..12dd7bf24b 100644 --- a/avogadro/qtplugins/noncovalent/noncovalent.cpp +++ b/avogadro/qtplugins/noncovalent/noncovalent.cpp @@ -44,7 +44,6 @@ using QtGui::Molecule; using QtGui::PluginLayerManager; using Rendering::DashedLineGeometry; using Rendering::GeometryNode; -using Rendering::GroupNode; NonCovalent::NonCovalent(QObject *p) : ScenePlugin(p) { diff --git a/avogadro/qtplugins/openbabel/obcharges.cpp b/avogadro/qtplugins/openbabel/obcharges.cpp index b2c2c9d405..0a1c330630 100644 --- a/avogadro/qtplugins/openbabel/obcharges.cpp +++ b/avogadro/qtplugins/openbabel/obcharges.cpp @@ -18,7 +18,6 @@ namespace Avogadro { using Core::Array; -using Core::Molecule; namespace QtPlugins { @@ -38,7 +37,7 @@ class OBCharges::ProcessListener : public QObject return true; } -public slots: + void responseReceived(const Array output) { m_finished = true; diff --git a/avogadro/qtplugins/openbabel/obfileformat.cpp b/avogadro/qtplugins/openbabel/obfileformat.cpp index d0e6410340..4077a24c1d 100644 --- a/avogadro/qtplugins/openbabel/obfileformat.cpp +++ b/avogadro/qtplugins/openbabel/obfileformat.cpp @@ -13,6 +13,7 @@ #include #include #include +#include using json = nlohmann::json; @@ -37,7 +38,7 @@ class OBFileFormat::ProcessListener : public QObject return true; } -public slots: + void responseReceived(const QByteArray& output) { m_finished = true; @@ -61,17 +62,17 @@ public slots: QByteArray m_output; }; -OBFileFormat::OBFileFormat(const std::string& name_, - const std::string& identifier_, - const std::string& description_, - const std::string& specificationUrl_, +OBFileFormat::OBFileFormat(std::string name_, + std::string identifier_, + std::string description_, + std::string specificationUrl_, const std::vector fileExtensions_, const std::vector mimeTypes_, - const std::string& defaultFormat_, bool fileOnly_) - : Io::FileFormat(), m_description(description_), + std::string defaultFormat_, bool fileOnly_) + : Io::FileFormat(), m_description(std::move(description_)), m_fileExtensions(fileExtensions_), m_mimeTypes(mimeTypes_), - m_identifier(identifier_), m_name(name_), - m_specificationUrl(specificationUrl_), m_defaultFormat(defaultFormat_), + m_identifier(std::move(identifier_)), m_name(std::move(name_)), + m_specificationUrl(std::move(specificationUrl_)), m_defaultFormat(std::move(defaultFormat_)), m_fileOnly(fileOnly_) {} diff --git a/avogadro/qtplugins/openbabel/obfileformat.h b/avogadro/qtplugins/openbabel/obfileformat.h index aec69e7bbb..5cc60671b0 100644 --- a/avogadro/qtplugins/openbabel/obfileformat.h +++ b/avogadro/qtplugins/openbabel/obfileformat.h @@ -22,12 +22,12 @@ namespace QtPlugins { class OBFileFormat : public Avogadro::Io::FileFormat { public: - OBFileFormat(const std::string& name_, const std::string& identifier_, - const std::string& description_, - const std::string& specificationUrl_, + OBFileFormat(std::string name_, std::string identifier_, + std::string description_, + std::string specificationUrl_, const std::vector fileExtensions_, const std::vector mimeTypes_, - const std::string& defaultFormat_, + std::string defaultFormat_, bool fileOnly_ = false); ~OBFileFormat() override; diff --git a/avogadro/qtplugins/openbabel/obprocess.cpp b/avogadro/qtplugins/openbabel/obprocess.cpp index 30cb3f5222..5f19d84325 100644 --- a/avogadro/qtplugins/openbabel/obprocess.cpp +++ b/avogadro/qtplugins/openbabel/obprocess.cpp @@ -54,7 +54,7 @@ OBProcess::OBProcess(QObject* parent_) } dir.setPath(QCoreApplication::applicationDirPath() + "/../lib/openbabel"); dirs = dir.entryList(filters); - if (dirs.size() == 0) { + if (dirs.empty()) { env.insert("BABEL_LIBDIR", QCoreApplication::applicationDirPath() + "/../lib/openbabel/"); } else if (dirs.size() == 1) { diff --git a/avogadro/qtplugins/plotpdf/plotpdf.cpp b/avogadro/qtplugins/plotpdf/plotpdf.cpp index 45edaf27c3..b3a2db0c6f 100644 --- a/avogadro/qtplugins/plotpdf/plotpdf.cpp +++ b/avogadro/qtplugins/plotpdf/plotpdf.cpp @@ -192,12 +192,12 @@ bool PlotPdf::generatePdfPattern(QtGui::Molecule& mol, PdfData& results, for (k = 0; k < static_cast(maxRadius / rStep); k++) { if (pdfCount.find(k) == pdfCount.end()) { - results.push_back(std::make_pair(k * rStep, 0.0)); + results.emplace_back(k * rStep, 0.0); } else { - results.push_back(std::make_pair( + results.emplace_back( k * rStep, pdfCount[k] * newMolecule.unitCell()->volume() / (4 * M_PI * pow(k * rStep, 2) * rStep * - refAtomCoords.size() * newAtomCoords.size()))); + refAtomCoords.size() * newAtomCoords.size())); } } diff --git a/avogadro/qtplugins/plotrmsd/plotrmsd.cpp b/avogadro/qtplugins/plotrmsd/plotrmsd.cpp index 2a9422e017..2562a2e44b 100644 --- a/avogadro/qtplugins/plotrmsd/plotrmsd.cpp +++ b/avogadro/qtplugins/plotrmsd/plotrmsd.cpp @@ -141,7 +141,7 @@ void PlotRmsd::generateRmsdPattern(RmsdData& results) (positions[j][2] - ref[j][2]) * (positions[j][2] - ref[j][2]); } sum = sqrt(sum / m_molecule->coordinate3dCount()); - results.push_back(std::make_pair(static_cast(i), sum)); + results.emplace_back(static_cast(i), sum); } } diff --git a/avogadro/qtplugins/plotxrd/plotxrd.cpp b/avogadro/qtplugins/plotxrd/plotxrd.cpp index 9f7c957b47..3084eb6877 100644 --- a/avogadro/qtplugins/plotxrd/plotxrd.cpp +++ b/avogadro/qtplugins/plotxrd/plotxrd.cpp @@ -196,8 +196,7 @@ bool PlotXrd::generateXrdPattern(const QtGui::Molecule& mol, XrdData& results, qDebug() << lineTmp; return false; } - results.push_back( - std::make_pair(rowData[0].toDouble(), rowData[1].toDouble())); + results.emplace_back(rowData[0].toDouble(), rowData[1].toDouble()); } } diff --git a/avogadro/qtplugins/plugindownloader/downloaderwidget.cpp b/avogadro/qtplugins/plugindownloader/downloaderwidget.cpp index 9fe9a5593f..59d1abc8ab 100644 --- a/avogadro/qtplugins/plugindownloader/downloaderwidget.cpp +++ b/avogadro/qtplugins/plugindownloader/downloaderwidget.cpp @@ -164,7 +164,7 @@ void DownloaderWidget::updateRepoData() } // Grab README data from Github -void DownloaderWidget::downloadREADME(int row, int col) +void DownloaderWidget::downloadREADME(int row, int /*col*/) { m_ui->readmeBrowser->clear(); QString url = m_repoList[row].readmeUrl; diff --git a/avogadro/qtplugins/propertytables/propertymodel.cpp b/avogadro/qtplugins/propertytables/propertymodel.cpp index 9793106ca4..710b481cac 100644 --- a/avogadro/qtplugins/propertytables/propertymodel.cpp +++ b/avogadro/qtplugins/propertytables/propertymodel.cpp @@ -28,9 +28,6 @@ using Avogadro::QtGui::Molecule; using QtGui::Molecule; using QtGui::RWAtom; using QtGui::RWBond; -using std::numeric_limits; -using std::pair; -using std::vector; using SecondaryStructure = Avogadro::Core::Residue::SecondaryStructure; @@ -131,7 +128,7 @@ QString partialCharge(Molecule* molecule, int atom) // TODO: we need to track type and/or calling the charge calculator float charge = 0.0; std::set types = molecule->partialChargeTypes(); - if (types.size() > 0) { + if (!types.empty()) { auto first = types.cbegin(); MatrixX charges = molecule->partialCharges((*first)); charge = charges(atom, 0); diff --git a/avogadro/qtplugins/qtaim/qtaimcriticalpointlocator.cpp b/avogadro/qtplugins/qtaim/qtaimcriticalpointlocator.cpp index f8e2f7ce5d..7849037f39 100644 --- a/avogadro/qtplugins/qtaim/qtaimcriticalpointlocator.cpp +++ b/avogadro/qtplugins/qtaim/qtaimcriticalpointlocator.cpp @@ -73,12 +73,8 @@ QList QTAIMLocateNuclearCriticalPoint(QList input) Matrix xyz; xyz << result.x(), result.y(), result.z(); - if (QTAIMMathUtilities::signatureOfASymmetricThreeByThreeMatrix( - eval.hessianOfElectronDensity(xyz)) == -3) { - correctSignature = true; - } else { - correctSignature = false; - } + correctSignature = QTAIMMathUtilities::signatureOfASymmetricThreeByThreeMatrix( + eval.hessianOfElectronDensity(xyz)) == -3; QList value; @@ -221,12 +217,8 @@ QList QTAIMLocateBondCriticalPoint(QList input) qint64 backwardNucleusIndex = smallestDistanceIndex; bool bondPathConnectsPair; - if ((forwardNucleusIndex == nucleusA && backwardNucleusIndex == nucleusB) || - (forwardNucleusIndex == nucleusB && backwardNucleusIndex == nucleusA)) { - bondPathConnectsPair = true; - } else { - bondPathConnectsPair = false; - } + bondPathConnectsPair = (forwardNucleusIndex == nucleusA && backwardNucleusIndex == nucleusB) || + (forwardNucleusIndex == nucleusB && backwardNucleusIndex == nucleusA); if (bondPathConnectsPair) { value.append(true); @@ -320,12 +312,8 @@ QList QTAIMLocateElectronDensitySink(QList input) if (eval.electronDensity(xyz_) > 1.e-1 && eval.gradientOfElectronDensityLaplacian(xyz_).norm() < 1.e-3) { - if (QTAIMMathUtilities::signatureOfASymmetricThreeByThreeMatrix( - eval.hessianOfElectronDensityLaplacian(xyz_)) == -3) { - correctSignature = true; - } else { - correctSignature = false; - } + correctSignature = QTAIMMathUtilities::signatureOfASymmetricThreeByThreeMatrix( + eval.hessianOfElectronDensityLaplacian(xyz_)) == -3; } else { correctSignature = false; } @@ -384,12 +372,8 @@ QList QTAIMLocateElectronDensitySource(QList input) if (eval.electronDensity(xyz_) > 1.e-1 && eval.gradientOfElectronDensityLaplacian(xyz_).norm() < 1.e-3) { - if (QTAIMMathUtilities::signatureOfASymmetricThreeByThreeMatrix( - eval.hessianOfElectronDensityLaplacian(xyz_)) == 3) { - correctSignature = true; - } else { - correctSignature = false; - } + correctSignature = QTAIMMathUtilities::signatureOfASymmetricThreeByThreeMatrix( + eval.hessianOfElectronDensityLaplacian(xyz_)) == 3; } else { correctSignature = false; } diff --git a/avogadro/qtplugins/qtaim/qtaimcubature.cpp b/avogadro/qtplugins/qtaim/qtaimcubature.cpp index 79e965e0cb..88f72f13c2 100644 --- a/avogadro/qtplugins/qtaim/qtaimcubature.cpp +++ b/avogadro/qtplugins/qtaim/qtaimcubature.cpp @@ -60,14 +60,10 @@ #include #include -#include -#include -#include #include #include #include #include -#include #include #include @@ -153,8 +149,10 @@ using namespace Avogadro::QtPlugins; /* error return codes */ -#define SUCCESS 0 -#define FAILURE 1 +enum { +SUCCESS = 0, +FAILURE = 1 +}; /***************************************************************************/ /* Basic datatypes */ diff --git a/avogadro/qtplugins/qtaim/qtaimextension.cpp b/avogadro/qtplugins/qtaim/qtaimextension.cpp index 96d2702d60..ec7ba93b51 100644 --- a/avogadro/qtplugins/qtaim/qtaimextension.cpp +++ b/avogadro/qtplugins/qtaim/qtaimextension.cpp @@ -90,11 +90,7 @@ void QTAIMExtension::triggered() bool wavefunctionAlreadyLoaded; - if (m_molecule->property("QTAIMComment").isValid()) { - wavefunctionAlreadyLoaded = true; - } else { - wavefunctionAlreadyLoaded = false; - } + wavefunctionAlreadyLoaded = m_molecule->property("QTAIMComment").isValid(); int i = action->data().toInt(); diff --git a/avogadro/qtplugins/qtaim/qtaimwavefunction.cpp b/avogadro/qtplugins/qtaim/qtaimwavefunction.cpp index 76350805a3..f8cb9ae27d 100644 --- a/avogadro/qtplugins/qtaim/qtaimwavefunction.cpp +++ b/avogadro/qtplugins/qtaim/qtaimwavefunction.cpp @@ -136,8 +136,8 @@ bool QTAIMWavefunction::initializeWithWFNFile(const QString& fileName) QString line(fileContentsByLine.first().mid(20, -1)); QStringList splitLine(line.split(" ", QString::SkipEmptyParts)); - for (qint64 i = 0; i < splitLine.length(); ++i) { - typeAssignmentsList.append(splitLine.at(i).toLongLong()); + for (const auto & i : splitLine) { + typeAssignmentsList.append(i.toLongLong()); } fileContentsByLine.removeFirst(); @@ -263,8 +263,7 @@ bool QTAIMWavefunction::initializeWithWFNFile(const QString& fileName) QString line(fileContentsByLine.first().mid(9, -1)); QStringList splitLine(line.split(" ", QString::SkipEmptyParts)); - for (qint64 i = 0; i < splitLine.length(); ++i) { - QString str(splitLine.at(i)); + for (auto str : splitLine) { QString replacedString(str.replace("d", "e", Qt::CaseSensitive) .replace("D", "e", Qt::CaseSensitive) .replace("E", "e", Qt::CaseSensitive)); @@ -294,22 +293,22 @@ bool QTAIMWavefunction::initializeWithWFNFile(const QString& fileName) QList moCoefficientsList; - for (qint64 i = 0; i < fileContentsByLine.length(); ++i) { - if (fileContentsByLine.at(i).trimmed().startsWith("MO")) { - moHeaderStringList.append(fileContentsByLine.at(i)); + for (const auto & i : fileContentsByLine) { + if (i.trimmed().startsWith("MO")) { + moHeaderStringList.append(i); } else { - moCoefficientsStringList.append(fileContentsByLine.at(i)); + moCoefficientsStringList.append(i); } } QList molecularOrbitalOccupationNumbersList; QList molecularOrbitalEigenvaluesList; - for (qint64 i = 0; i < moHeaderStringList.length(); ++i) { + for (const auto & i : moHeaderStringList) { molecularOrbitalOccupationNumbersList.append( - moHeaderStringList.at(i).mid(34, 13).toDouble()); + i.mid(34, 13).toDouble()); molecularOrbitalEigenvaluesList.append( - moHeaderStringList.at(i).mid(62, -1).toDouble()); + i.mid(62, -1).toDouble()); } m_molecularOrbitalOccupationNumbers.resize(m_numberOfMolecularOrbitals); @@ -326,8 +325,7 @@ bool QTAIMWavefunction::initializeWithWFNFile(const QString& fileName) moCoefficientsStringList = moCoefficientsStringList.join(" ").split(" ", QString::SkipEmptyParts); - for (qint64 i = 0; i < moCoefficientsStringList.length(); ++i) { - QString str(moCoefficientsStringList.at(i)); + for (auto str : moCoefficientsStringList) { QString replacedString(str.replace("d", "e", Qt::CaseSensitive) .replace("D", "e", Qt::CaseSensitive) .replace("E", "e", Qt::CaseSensitive)); diff --git a/avogadro/qtplugins/resetview/resetview.cpp b/avogadro/qtplugins/resetview/resetview.cpp index 53b48713b3..cd8f5f1490 100644 --- a/avogadro/qtplugins/resetview/resetview.cpp +++ b/avogadro/qtplugins/resetview/resetview.cpp @@ -19,7 +19,6 @@ namespace Avogadro::QtPlugins { -using Avogadro::QtGui::ExtensionPlugin; using Core::Array; using Eigen::Affine3f; using Eigen::EigenSolver; @@ -106,7 +105,7 @@ inline float getZDistance(const Affine3f& projection, float x, } inline void getBB(const Array& mols, Vector3& min, Vector3& max) { - if (mols.size() > 0) { + if (!mols.empty()) { min = mols[0]; max = mols[0]; for (size_t i = 1; i < mols.size(); ++i) { diff --git a/avogadro/qtplugins/scriptcharges/scriptchargemodel.cpp b/avogadro/qtplugins/scriptcharges/scriptchargemodel.cpp index 2c789616d0..635d3f1749 100644 --- a/avogadro/qtplugins/scriptcharges/scriptchargemodel.cpp +++ b/avogadro/qtplugins/scriptcharges/scriptchargemodel.cpp @@ -92,8 +92,7 @@ MatrixX ScriptChargeModel::partialCharges(Core::Molecule& mol) const // keep a separate atom counter in case there is other text // (e.g., "normal termination, etc.") unsigned int atom = 0; - for (unsigned int i = 0; i < lines.size(); ++i) { - const QString& line = lines.at(i); + for (const auto & line : lines) { if (line.isEmpty()) continue; diff --git a/avogadro/qtplugins/selectiontool/selectiontool.cpp b/avogadro/qtplugins/selectiontool/selectiontool.cpp index fa066fa1dd..0f2a250503 100644 --- a/avogadro/qtplugins/selectiontool/selectiontool.cpp +++ b/avogadro/qtplugins/selectiontool/selectiontool.cpp @@ -35,7 +35,6 @@ using Avogadro::Core::Atom; using Avogadro::QtGui::Molecule; using Avogadro::QtGui::RWMolecule; using Avogadro::Rendering::GeometryNode; -using Avogadro::Rendering::GroupNode; using Avogadro::Rendering::Identifier; using Avogadro::Rendering::MeshGeometry; diff --git a/avogadro/qtplugins/spectra/spectra.cpp b/avogadro/qtplugins/spectra/spectra.cpp index 6203518e97..72bdd30f68 100644 --- a/avogadro/qtplugins/spectra/spectra.cpp +++ b/avogadro/qtplugins/spectra/spectra.cpp @@ -47,7 +47,7 @@ QStringList Spectra::menuPath(QAction*) const void Spectra::setMolecule(QtGui::Molecule* mol) { bool isVibrational(false); - if (mol->vibrationFrequencies().size()) + if (!mol->vibrationFrequencies().empty()) isVibrational = true; m_actions[0]->setEnabled(isVibrational); diff --git a/avogadro/qtplugins/spectra/vibrationmodel.cpp b/avogadro/qtplugins/spectra/vibrationmodel.cpp index cac28f4f5b..7de46b570b 100644 --- a/avogadro/qtplugins/spectra/vibrationmodel.cpp +++ b/avogadro/qtplugins/spectra/vibrationmodel.cpp @@ -44,7 +44,7 @@ Qt::ItemFlags VibrationModel::flags(const QModelIndex&) const void VibrationModel::setMolecule(QtGui::Molecule* mol) { m_molecule = mol; - m_hasRaman = mol->vibrationRamanIntensities().size() > 0; + m_hasRaman = !mol->vibrationRamanIntensities().empty(); } QVariant VibrationModel::headerData(int section, Qt::Orientation orientation, diff --git a/avogadro/qtplugins/surfaces/surfacedialog.cpp b/avogadro/qtplugins/surfaces/surfacedialog.cpp index 560f24f0da..b16f423533 100644 --- a/avogadro/qtplugins/surfaces/surfacedialog.cpp +++ b/avogadro/qtplugins/surfaces/surfacedialog.cpp @@ -187,7 +187,7 @@ void SurfaceDialog::setupBasis(int numElectrons, int numMOs, bool beta) void SurfaceDialog::setupCubes(QStringList cubeNames) { - if (cubeNames.size() < 1) + if (cubeNames.empty()) return; m_ui->orbitalCombo->setVisible(true); @@ -195,8 +195,8 @@ void SurfaceDialog::setupCubes(QStringList cubeNames) m_ui->surfaceCombo->addItem(tr("From File"), Surfaces::Type::FromFile); - for (int i = 0; i < cubeNames.size(); ++i) { - m_ui->orbitalCombo->addItem(cubeNames[i]); + for (const auto & cubeName : cubeNames) { + m_ui->orbitalCombo->addItem(cubeName); } m_ui->orbitalCombo->setCurrentIndex(0); } diff --git a/avogadro/qtplugins/surfaces/surfaces.cpp b/avogadro/qtplugins/surfaces/surfaces.cpp index d8eb303910..a4618daf1f 100644 --- a/avogadro/qtplugins/surfaces/surfaces.cpp +++ b/avogadro/qtplugins/surfaces/surfaces.cpp @@ -78,7 +78,7 @@ class Surfaces::PIMPL Surfaces::Surfaces(QObject* p) : ExtensionPlugin(p), d(new PIMPL()) { - auto action = new QAction(this); + auto *action = new QAction(this); action->setText(tr("Create Surfaces…")); connect(action, SIGNAL(triggered()), SLOT(surfacesActivated())); connect(&m_displayMeshWatcher, SIGNAL(finished()), SLOT(displayMesh())); @@ -106,7 +106,7 @@ void Surfaces::setMolecule(QtGui::Molecule* mol) { if (mol->basisSet()) { m_basis = mol->basisSet(); - } else if (mol->cubes().size() != 0) { + } else if (!mol->cubes().empty()) { m_cubes = mol->cubes(); } @@ -140,7 +140,7 @@ void Surfaces::surfacesActivated() if (m_basis) { // we have quantum data, set up the dialog accordingly - auto gaussian = dynamic_cast(m_basis); + auto *gaussian = dynamic_cast(m_basis); bool beta = false; if (gaussian) { auto b = gaussian->moMatrix(GaussianSet::Beta); @@ -150,7 +150,7 @@ void Surfaces::surfacesActivated() m_dialog->setupBasis(m_basis->electronCount(), m_basis->molecularOrbitalCount(), beta); } - if (m_cubes.size() > 0) { + if (!m_cubes.empty()) { QStringList cubeNames; for (auto* cube : m_cubes) { cubeNames << cube->name().c_str(); @@ -470,7 +470,7 @@ void Surfaces::calculateQM() void Surfaces::calculateCube() { - if (!m_dialog || m_cubes.size() == 0) + if (!m_dialog || m_cubes.empty()) return; // check bounds @@ -485,7 +485,7 @@ void Surfaces::stepChanged(int n) return; qDebug() << "\n\t==== Step changed to" << n << "===="; - auto g = dynamic_cast(m_basis); + auto *g = dynamic_cast(m_basis); if (g) { g->setActiveSetStep(n - 1); m_molecule->clearCubes(); @@ -695,7 +695,7 @@ void Surfaces::movieFrame() QCoreApplication::sendPostedEvents(); QCoreApplication::processEvents(); - auto glWidget = QtOpenGL::ActiveObjects::instance().activeGLWidget(); + auto *glWidget = QtOpenGL::ActiveObjects::instance().activeGLWidget(); if (!glWidget) { QMessageBox::warning(qobject_cast(parent()), tr("Avogadro"), "Couldn't find the active render widget, failing."); diff --git a/avogadro/qtplugins/symmetry/symmetryscene.cpp b/avogadro/qtplugins/symmetry/symmetryscene.cpp index 8634d5e6dd..f8751f3678 100644 --- a/avogadro/qtplugins/symmetry/symmetryscene.cpp +++ b/avogadro/qtplugins/symmetry/symmetryscene.cpp @@ -26,12 +26,9 @@ using namespace Avogadro; namespace Avogadro::QtPlugins { -using Core::Array; using Rendering::ArcSector; using Rendering::CylinderGeometry; using Rendering::GeometryNode; -using Rendering::GroupNode; -using Rendering::MeshGeometry; using Rendering::SphereGeometry; SymmetryScene::SymmetryScene(QObject* p) diff --git a/avogadro/qtplugins/symmetry/symmetrywidget.cpp b/avogadro/qtplugins/symmetry/symmetrywidget.cpp index 15d824cc9c..a4f622080f 100644 --- a/avogadro/qtplugins/symmetry/symmetrywidget.cpp +++ b/avogadro/qtplugins/symmetry/symmetrywidget.cpp @@ -14,7 +14,6 @@ #include -using Avogadro::QtGui::Molecule; using namespace msym; using namespace Avogadro::QtPlugins::SymmetryUtil; @@ -138,8 +137,8 @@ void SymmetryWidget::moleculeChanged(unsigned int changes) } void SymmetryWidget::operationsSelectionChanged( - const QItemSelection& selected, - const QItemSelection& deselected) + const QItemSelection& /*selected*/, + const QItemSelection& /*deselected*/) { if (!m_molecule) @@ -169,7 +168,7 @@ void SymmetryWidget::operationsSelectionChanged( // qDebug() << "cleared elements"; - if (m_sopsl > 0 && selection.size() > 0) { + if (m_sopsl > 0 && !selection.empty()) { m_molecule->setProperty("SymmetryOrigo", m_cm); m_molecule->setProperty("SymmetryRadius", m_radius); } @@ -198,13 +197,13 @@ void SymmetryWidget::operationsSelectionChanged( break; } } - if (properRotationVariantList.size() > 0) + if (!properRotationVariantList.empty()) m_molecule->setProperty("SymmetryProperRotationVariantList", properRotationVariantList); - if (improperRotationVariantList.size() > 0) + if (!improperRotationVariantList.empty()) m_molecule->setProperty("SymmetryImproperRotationVariantList", improperRotationVariantList); - if (reflectionVariantList.size() > 0) + if (!reflectionVariantList.empty()) m_molecule->setProperty("SymmetryReflectionVariantList", reflectionVariantList); @@ -212,8 +211,8 @@ void SymmetryWidget::operationsSelectionChanged( m_molecule->emitChanged(QtGui::Molecule::Atoms); } -void SymmetryWidget::subgroupsSelectionChanged(const QItemSelection& selected, - const QItemSelection& deselected) +void SymmetryWidget::subgroupsSelectionChanged(const QItemSelection& /*selected*/, + const QItemSelection& /*deselected*/) { // QModelIndexList selection = // m_ui->subgroupsTree->selectionModel()->selectedIndexes(); @@ -256,8 +255,8 @@ void SymmetryWidget::subgroupsSelectionChanged(const QItemSelection& selected, } void SymmetryWidget::equivalenceSelectionChanged( - const QItemSelection& selected, - const QItemSelection& deselected) + const QItemSelection& /*selected*/, + const QItemSelection& /*deselected*/) { QModelIndex i = m_ui->equivalenceTree->selectionModel()->selectedIndexes().first(); @@ -365,7 +364,7 @@ void SymmetryWidget::setSubgroups(int sgl, const msym::msym_subgroup_t* sg) parent->setText(pointGroupSymbol(sg[i].name)); parent->setData(i, Qt::UserRole); m_subgroupsTreeModel->appendRow(parent); - for (auto generator : sg[i].generators) { + for (auto *generator : sg[i].generators) { if (generator == nullptr) continue; // qDebug() << "child " << sg[i].generators[j] - m_sg << " " diff --git a/avogadro/qtplugins/templatetool/templatetool.cpp b/avogadro/qtplugins/templatetool/templatetool.cpp index 6882f601be..49c29e42d7 100644 --- a/avogadro/qtplugins/templatetool/templatetool.cpp +++ b/avogadro/qtplugins/templatetool/templatetool.cpp @@ -48,30 +48,20 @@ const unsigned char INVALID_ATOMIC_NUMBER = std::numeric_limits::max(); } -namespace Avogadro { -namespace QtPlugins { +namespace Avogadro::QtPlugins { -using QtGui::RWAtom; -using QtGui::RWBond; using QtGui::Molecule; -using QtGui::RWMolecule; -using QtOpenGL::GLWidget; -using Avogadro::Rendering::GeometryNode; -using Avogadro::Rendering::GroupNode; using Avogadro::Rendering::Identifier; -using Avogadro::Rendering::TextLabel2D; -using Avogadro::Rendering::TextLabel3D; -using Avogadro::Rendering::TextProperties; using Avogadro::Core::Elements; using Avogadro::Io::CjsonFormat; TemplateTool::TemplateTool(QObject *parent_) : QtGui::ToolPlugin(parent_), m_activateAction(new QAction(this)), - m_molecule(NULL), - m_glWidget(NULL), - m_renderer(NULL), + m_molecule(nullptr), + m_glWidget(nullptr), + m_renderer(nullptr), m_toolWidget(new TemplateToolWidget(qobject_cast(parent_))), m_pressedButtons(Qt::NoButton), m_clickedAtomicNumber(INVALID_ATOMIC_NUMBER), @@ -96,7 +86,7 @@ QUndoCommand *TemplateTool::mousePressEvent(QMouseEvent *e) { clearKeyPressBuffer(); if (!m_renderer) - return NULL; + return nullptr; updatePressedButtons(e, false); m_clickPosition = e->pos(); @@ -111,10 +101,10 @@ QUndoCommand *TemplateTool::mousePressEvent(QMouseEvent *e) switch (m_clickedObject.type) { case Rendering::InvalidType: emptyLeftClick(e); - return NULL; + return nullptr; case Rendering::AtomType: atomLeftClick(e); - return NULL; + return nullptr; default: break; } @@ -125,19 +115,19 @@ QUndoCommand *TemplateTool::mousePressEvent(QMouseEvent *e) switch (m_clickedObject.type) { case Rendering::AtomType: atomRightClick(e); - return NULL; + return nullptr; default: break; } } - return NULL; + return nullptr; } QUndoCommand *TemplateTool::mouseReleaseEvent(QMouseEvent *e) { if (!m_renderer) - return NULL; + return nullptr; updatePressedButtons(e, true); @@ -146,7 +136,7 @@ QUndoCommand *TemplateTool::mouseReleaseEvent(QMouseEvent *e) } if (m_clickedObject.type == Rendering::InvalidType) - return NULL; + return nullptr; switch (e->button()) { case Qt::LeftButton: @@ -158,25 +148,25 @@ QUndoCommand *TemplateTool::mouseReleaseEvent(QMouseEvent *e) break; } - return NULL; + return nullptr; } QUndoCommand *TemplateTool::mouseMoveEvent(QMouseEvent *e) { if (!m_renderer) - return NULL; + return nullptr; if (m_pressedButtons & Qt::LeftButton) if (m_clickedObject.type == Rendering::AtomType) atomLeftDrag(e); - return NULL; + return nullptr; } QUndoCommand *TemplateTool::keyPressEvent(QKeyEvent *e) { if (e->text().isEmpty()) - return NULL; + return nullptr; e->accept(); @@ -190,7 +180,7 @@ QUndoCommand *TemplateTool::keyPressEvent(QKeyEvent *e) if (m_keyPressBuffer.size() >= 3) { clearKeyPressBuffer(); - return NULL; + return nullptr; } int atomicNum = Core::Elements::atomicNumberFromSymbol( @@ -199,7 +189,7 @@ QUndoCommand *TemplateTool::keyPressEvent(QKeyEvent *e) if (atomicNum != Avogadro::InvalidElement) m_toolWidget->setAtomicNumber(static_cast(atomicNum)); - return NULL; + return nullptr; } void TemplateTool::draw(Rendering::GroupNode&) @@ -398,14 +388,14 @@ void TemplateTool::atomLeftClick(QMouseEvent*) // Estimate and try to realize bond distances Vector3 displacement(0.0, 0.0, 0.0); - for (size_t i = 0; i < templateLigandIndices.size(); i++) { - unsigned char ligandAtomicNumber = templateMolecule.atomicNumber(templateLigandIndices[i]); + for (unsigned long templateLigandIndice : templateLigandIndices) { + unsigned char ligandAtomicNumber = templateMolecule.atomicNumber(templateLigandIndice); ligandAtomicNumber = (ligandAtomicNumber == 0)? 6 : ligandAtomicNumber; // Estimate as the sum of covalent radii double bondDistance = Elements::radiusCovalent(ligandAtomicNumber) + Elements::radiusCovalent(m_molecule->atomicNumber(moleculeCenterIndex)); Vector3 inVector = templateMolecule.atomPosition3d(templateDummyIndex) - - templateMolecule.atomPosition3d(templateLigandIndices[i]); + - templateMolecule.atomPosition3d(templateLigandIndice); Vector3 correctionVector = inVector; correctionVector.normalize(); correctionVector *= bondDistance - inVector.norm(); @@ -429,12 +419,13 @@ void TemplateTool::atomLeftClick(QMouseEvent*) // Create arrays with the points to align and apply Kabsch algorithm std::vector templateLigandPositions; - for (size_t index: templateLigandIndices) - templateLigandPositions.push_back(templateMolecule.atomPosition3d(index) + templateLigandPositions.reserve(templateLigandIndices.size()); +for (size_t index: templateLigandIndices) + templateLigandPositions.emplace_back(templateMolecule.atomPosition3d(index) - m_molecule->atomPosition3d(moleculeCenterIndex)); std::vector moleculeLigandPositions; for (size_t UID: m_toolWidget->selectedUIDs()) - moleculeLigandPositions.push_back(m_molecule->atomPosition3d( + moleculeLigandPositions.emplace_back(m_molecule->atomPosition3d( m_molecule->atomByUniqueId(UID).index() ) - m_molecule->atomPosition3d(moleculeCenterIndex)); Matrix3 rotation = applyKabsch(templateLigandPositions, moleculeLigandPositions); @@ -512,5 +503,4 @@ void TemplateTool::atomLeftDrag(QMouseEvent*) return; } -} // namespace QtOpenGL } // namespace Avogadro diff --git a/avogadro/qtplugins/templatetool/templatetoolwidget.cpp b/avogadro/qtplugins/templatetool/templatetoolwidget.cpp index 578045d191..0322cd13ef 100644 --- a/avogadro/qtplugins/templatetool/templatetoolwidget.cpp +++ b/avogadro/qtplugins/templatetool/templatetoolwidget.cpp @@ -20,11 +20,10 @@ namespace { const int ELEMENT_SELECTOR_TAG = 255; } // namespace -namespace Avogadro { -namespace QtPlugins { +namespace Avogadro::QtPlugins { TemplateToolWidget::TemplateToolWidget(QWidget* parent_) - : QWidget(parent_), m_ui(new Ui::TemplateToolWidget), m_elementSelector(NULL), + : QWidget(parent_), m_ui(new Ui::TemplateToolWidget), m_elementSelector(nullptr), m_currentElement(26) { m_ui->setupUi(this); @@ -85,7 +84,7 @@ unsigned char TemplateToolWidget::atomicNumber() const if (!itemData.isValid()) return 0; - unsigned char atomicNum = static_cast(itemData.toUInt()); + auto atomicNum = static_cast(itemData.toUInt()); // "Other..." selected.... if (atomicNum == 0 && m_elementSelector) @@ -340,8 +339,8 @@ void TemplateToolWidget::buildElements() void TemplateToolWidget::saveElements() { QVariantList atomicNums; - for (int i = 0; i < m_userElements.size(); ++i) - atomicNums << QVariant(m_userElements[i]); + for (unsigned char m_userElement : m_userElements) + atomicNums << QVariant(m_userElement); QSettings().setValue("templatetool/userElements", atomicNums); } @@ -356,5 +355,4 @@ std::vector& TemplateToolWidget::selectedUIDs() return m_selectedUIDs; } -} // namespace QtPlugins } // namespace Avogadro diff --git a/avogadro/qtplugins/vanderwaals/vanderwaals.cpp b/avogadro/qtplugins/vanderwaals/vanderwaals.cpp index b7a8bbc86d..3aa14b7f1e 100644 --- a/avogadro/qtplugins/vanderwaals/vanderwaals.cpp +++ b/avogadro/qtplugins/vanderwaals/vanderwaals.cpp @@ -16,7 +16,6 @@ namespace Avogadro::QtPlugins { using Core::Elements; using QtGui::PluginLayerManager; using Rendering::GeometryNode; -using Rendering::GroupNode; using Rendering::SphereGeometry; VanDerWaals::VanDerWaals(QObject* p) : ScenePlugin(p) @@ -35,7 +34,7 @@ void VanDerWaals::process(const QtGui::Molecule& molecule, auto* spheres = new SphereGeometry; spheres->identifier().molecule = &molecule; spheres->identifier().type = Rendering::AtomType; - auto selectedSpheres = new SphereGeometry; + auto *selectedSpheres = new SphereGeometry; selectedSpheres->setOpacity(0.42); geometry->addDrawable(spheres); diff --git a/avogadro/qtplugins/wireframe/wireframe.cpp b/avogadro/qtplugins/wireframe/wireframe.cpp index e34f084e63..91d5051a00 100644 --- a/avogadro/qtplugins/wireframe/wireframe.cpp +++ b/avogadro/qtplugins/wireframe/wireframe.cpp @@ -27,7 +27,6 @@ using Core::Array; using Core::Elements; using QtGui::PluginLayerManager; using Rendering::GeometryNode; -using Rendering::GroupNode; using Rendering::LineStripGeometry; using Rendering::SphereGeometry; @@ -127,10 +126,10 @@ void Wireframe::process(const QtGui::Molecule& molecule, lines->identifier().molecule = &molecule; lines->identifier().type = Rendering::BondType; // add tiny atom sites for selection - auto atoms = new SphereGeometry; + auto *atoms = new SphereGeometry; atoms->identifier().molecule = &molecule; atoms->identifier().type = Rendering::AtomType; - auto selectedAtoms = new SphereGeometry; + auto *selectedAtoms = new SphereGeometry; selectedAtoms->setOpacity(0.42); Vector3ub selectedColor(0, 0, 255); diff --git a/avogadro/qtplugins/yaehmop/banddialog.cpp b/avogadro/qtplugins/yaehmop/banddialog.cpp index 64eb95244c..c65a6a6d33 100644 --- a/avogadro/qtplugins/yaehmop/banddialog.cpp +++ b/avogadro/qtplugins/yaehmop/banddialog.cpp @@ -8,8 +8,7 @@ #include -namespace Avogadro { -namespace QtPlugins { +namespace Avogadro::QtPlugins { BandDialog::BandDialog(QWidget* aParent, YaehmopSettings& yaehmopSettings) : QDialog(aParent), m_ui(new Ui::BandDialog), @@ -56,5 +55,4 @@ void BandDialog::accept() QDialog::accept(); } -} // namespace QtPlugins } // namespace Avogadro diff --git a/avogadro/qtplugins/yaehmop/specialkpoints.cpp b/avogadro/qtplugins/yaehmop/specialkpoints.cpp index b02c566d29..e673c85d07 100644 --- a/avogadro/qtplugins/yaehmop/specialkpoints.cpp +++ b/avogadro/qtplugins/yaehmop/specialkpoints.cpp @@ -21,8 +21,7 @@ using Avogadro::Core::Molecule; using Avogadro::Core::SpaceGroups; using Avogadro::Core::UnitCell; -namespace Avogadro { -namespace QtPlugins { +namespace Avogadro::QtPlugins { QString SpecialKPoints::getSpecialKPoints(Molecule& mol) { @@ -223,5 +222,4 @@ void SpecialKPoints::processConditionKPoints(QString& specialKPoints, } } -} // namespace QtPlugins } // namespace Avogadro diff --git a/avogadro/qtplugins/yaehmop/yaehmop.cpp b/avogadro/qtplugins/yaehmop/yaehmop.cpp index c48278e46f..425905dba0 100644 --- a/avogadro/qtplugins/yaehmop/yaehmop.cpp +++ b/avogadro/qtplugins/yaehmop/yaehmop.cpp @@ -38,8 +38,7 @@ using Avogadro::Core::Elements; using Avogadro::Core::UnitCell; using Avogadro::QtGui::Molecule; -namespace Avogadro { -namespace QtPlugins { +namespace Avogadro::QtPlugins { Yaehmop::Yaehmop(QObject* parent_) : Avogadro::QtGui::ExtensionPlugin(parent_), m_actions(QList()), @@ -132,7 +131,7 @@ void Yaehmop::moleculeChanged(unsigned int c) { Q_ASSERT(m_molecule == qobject_cast(sender())); - Molecule::MoleculeChanges changes = static_cast(c); + auto changes = static_cast(c); if (changes & Molecule::UnitCell) { if (changes & Molecule::Added || changes & Molecule::Removed) @@ -586,15 +585,15 @@ bool Yaehmop::executeYaehmop(const QByteArray& input, QByteArray& output, void Yaehmop::showYaehmopInput(const QString& input) { - QDialog* dialog = new QDialog(qobject_cast(this->parent())); + auto* dialog = new QDialog(qobject_cast(this->parent())); // Make sure this gets deleted upon closing dialog->setAttribute(Qt::WA_DeleteOnClose); - QVBoxLayout* layout = new QVBoxLayout(dialog); + auto* layout = new QVBoxLayout(dialog); dialog->setLayout(layout); dialog->setWindowTitle(tr("Yaehmop Input")); - QTextEdit* edit = new QTextEdit(dialog); + auto* edit = new QTextEdit(dialog); layout->addWidget(edit); dialog->resize(500, 500); @@ -603,5 +602,4 @@ void Yaehmop::showYaehmopInput(const QString& input) dialog->show(); } -} // namespace QtPlugins } // namespace Avogadro diff --git a/avogadro/qtplugins/yaehmop/yaehmopout.cpp b/avogadro/qtplugins/yaehmop/yaehmopout.cpp index 1eacfa2fe4..74f38c699e 100644 --- a/avogadro/qtplugins/yaehmop/yaehmopout.cpp +++ b/avogadro/qtplugins/yaehmop/yaehmopout.cpp @@ -12,8 +12,7 @@ #include -namespace Avogadro { -namespace QtPlugins { +namespace Avogadro::QtPlugins { inline bool printAndReturnFalse(const QString& error) { @@ -134,5 +133,4 @@ bool YaehmopOut::readBandData(const QString& data, return true; } -} // namespace QtPlugins } // namespace Avogadro diff --git a/avogadro/quantumio/gamessus.cpp b/avogadro/quantumio/gamessus.cpp index 2082c1904a..fa57f4594c 100644 --- a/avogadro/quantumio/gamessus.cpp +++ b/avogadro/quantumio/gamessus.cpp @@ -304,11 +304,11 @@ void GAMESSUSOutput::load(GaussianSet* basis) // qDebug() << " loading MOs " << m_MOcoeffs.size(); // Now to load in the MO coefficients - if (m_MOcoeffs.size()) + if (!m_MOcoeffs.empty()) basis->setMolecularOrbitals(m_MOcoeffs); - if (m_alphaMOcoeffs.size()) + if (!m_alphaMOcoeffs.empty()) basis->setMolecularOrbitals(m_alphaMOcoeffs, BasisSet::Alpha); - if (m_betaMOcoeffs.size()) + if (!m_betaMOcoeffs.empty()) basis->setMolecularOrbitals(m_betaMOcoeffs, BasisSet::Beta); // generateDensity(); @@ -410,7 +410,7 @@ void GAMESSUSOutput::outputAll() << ", atom = " << m_shelltoAtom.at(i) << endl; } int nGTOs = 0; - if (m_MOcoeffs.size()) { + if (!m_MOcoeffs.empty()) { nGTOs = m_MOcoeffs.size() / m_nMOs; cout << m_nMOs << " MOs, " << nGTOs << " GTOs" << endl; } @@ -422,11 +422,11 @@ void GAMESSUSOutput::outputAll() cout << "\n"; } - if (m_alphaMOcoeffs.size()) + if (!m_alphaMOcoeffs.empty()) cout << "Alpha MO coefficients.\n"; for (double m_alphaMOcoeff : m_alphaMOcoeffs) cout << m_alphaMOcoeff; - if (m_betaMOcoeffs.size()) + if (!m_betaMOcoeffs.empty()) cout << "Beta MO coefficients.\n"; for (double m_betaMOcoeff : m_betaMOcoeffs) cout << m_betaMOcoeff; diff --git a/avogadro/quantumio/gaussianfchk.cpp b/avogadro/quantumio/gaussianfchk.cpp index d59396d3ad..ab7f9747dc 100644 --- a/avogadro/quantumio/gaussianfchk.cpp +++ b/avogadro/quantumio/gaussianfchk.cpp @@ -270,13 +270,13 @@ void GaussianFchk::load(GaussianSet* basis) } // Now to load in the MO coefficients if (basis->isValid()) { - if (m_MOcoeffs.size()) + if (!m_MOcoeffs.empty()) basis->setMolecularOrbitals(m_MOcoeffs); else cout << "Error no MO coefficients...\n"; - if (m_alphaMOcoeffs.size()) + if (!m_alphaMOcoeffs.empty()) basis->setMolecularOrbitals(m_alphaMOcoeffs, BasisSet::Alpha); - if (m_betaMOcoeffs.size()) + if (!m_betaMOcoeffs.empty()) basis->setMolecularOrbitals(m_betaMOcoeffs, BasisSet::Beta); if (m_density.rows()) basis->setDensityMatrix(m_density); @@ -547,19 +547,19 @@ void GaussianFchk::outputAll() cout << i << " : type = " << m_shellTypes.at(i) << ", number = " << m_shellNums.at(i) << ", atom = " << m_shelltoAtom.at(i) << endl; - if (m_MOcoeffs.size()) { + if (!m_MOcoeffs.empty()) { cout << "MO coefficients:\n"; for (double m_MOcoeff : m_MOcoeffs) cout << m_MOcoeff << "\t"; cout << endl << endl; } - if (m_alphaMOcoeffs.size()) { + if (!m_alphaMOcoeffs.empty()) { cout << "Alpha MO coefficients:\n"; for (double m_alphaMOcoeff : m_alphaMOcoeffs) cout << m_alphaMOcoeff << "\t"; cout << endl << endl; } - if (m_betaMOcoeffs.size()) { + if (!m_betaMOcoeffs.empty()) { cout << "Beta MO coefficients:\n"; for (double m_betaMOcoeff : m_betaMOcoeffs) cout << m_betaMOcoeff << "\t"; diff --git a/avogadro/quantumio/molden.cpp b/avogadro/quantumio/molden.cpp index 9fe9bada24..7a7c64657c 100644 --- a/avogadro/quantumio/molden.cpp +++ b/avogadro/quantumio/molden.cpp @@ -108,7 +108,7 @@ void MoldenFile::processLine(std::istream& in) line = Core::trimmed(line); while (!line.empty()) { // Read the shell types in this GTO. list = Core::split(line, ' '); - if (list.size() < 1) + if (list.empty()) break; shell = list[0]; shellType = GaussianSet::UU; @@ -222,7 +222,7 @@ void MoldenFile::load(GaussianSet* basis) } } // Now to load in the MO coefficients - if (m_MOcoeffs.size()) + if (!m_MOcoeffs.empty()) basis->setMolecularOrbitals(m_MOcoeffs); } diff --git a/avogadro/quantumio/mopacaux.cpp b/avogadro/quantumio/mopacaux.cpp index a90f424add..b980e4e906 100644 --- a/avogadro/quantumio/mopacaux.cpp +++ b/avogadro/quantumio/mopacaux.cpp @@ -58,7 +58,7 @@ bool MopacAux::read(std::istream& in, Core::Molecule& molecule) load(basis); // check if there is vibrational data - if (m_frequencies.size() > 0) { + if (!m_frequencies.empty()) { // convert the std::vector to Array Core::Array frequencies(m_frequencies.size()); for (unsigned int i = 0; i < m_frequencies.size(); ++i) @@ -79,7 +79,7 @@ bool MopacAux::read(std::istream& in, Core::Molecule& molecule) Index atomCount = molecule.atomCount(); for (unsigned int i = 0; i < m_normalModes.size(); ++i) { normalMode.push_back(m_normalModes[i]); - if (i % atomCount == 0 && normalMode.size() > 0) { + if (i % atomCount == 0 && !normalMode.empty()) { normalModes.push_back(normalMode); normalMode.clear(); } @@ -162,7 +162,7 @@ void MopacAux::processLine(std::istream& in) void MopacAux::load(SlaterSet* basis) { - if (m_atomPos.size() == 0) { + if (m_atomPos.empty()) { cout << "No atoms found in .aux file. Bailing out." << endl; // basis->setIsValid(false); return; diff --git a/avogadro/quantumio/nwchemjson.cpp b/avogadro/quantumio/nwchemjson.cpp index dce7f580c6..a49788ed23 100644 --- a/avogadro/quantumio/nwchemjson.cpp +++ b/avogadro/quantumio/nwchemjson.cpp @@ -159,7 +159,7 @@ bool NWChemJson::read(std::istream& file, Molecule& molecule) vector parts = split(desc, ' '); assert(parts.size() == 3); int num = Core::lexicalCast(parts[0]); - if (atomNumber.size() > 0 && atomNumber.back() == num) + if (!atomNumber.empty() && atomNumber.back() == num) continue; atomNumber.push_back(num); atomSymbol.push_back(parts[1]); diff --git a/avogadro/quantumio/nwchemlog.cpp b/avogadro/quantumio/nwchemlog.cpp index 79c5229101..42df64e8dc 100644 --- a/avogadro/quantumio/nwchemlog.cpp +++ b/avogadro/quantumio/nwchemlog.cpp @@ -16,7 +16,6 @@ using std::string; namespace Avogadro::QuantumIO { -using Core::Atom; NWChemLog::NWChemLog() { @@ -51,7 +50,7 @@ bool NWChemLog::read(std::istream& in, Core::Molecule& molecule) return false; } - if (m_frequencies.size() > 0 && m_frequencies.size() == m_Lx.size() && + if (!m_frequencies.empty() && m_frequencies.size() == m_Lx.size() && m_frequencies.size() == m_intensities.size()) { molecule.setVibrationFrequencies(m_frequencies); molecule.setVibrationIRIntensities(m_intensities); diff --git a/avogadro/rendering/cartoongeometry.cpp b/avogadro/rendering/cartoongeometry.cpp index 46b9f118a5..1923a19bb5 100644 --- a/avogadro/rendering/cartoongeometry.cpp +++ b/avogadro/rendering/cartoongeometry.cpp @@ -112,7 +112,7 @@ void Cartoon::addPoint(const Vector3f& pos, const Vector3ub& color, { CartoonType ct = secondaryToCartoonType(sec); size_t idCartoon = 0; - if (m_type.size() > 0) { + if (!m_type.empty()) { idCartoon = ct == m_type.back().first && m_type.size() > (SKIPPED + 1) ? m_type.back().second + 1 : 0; diff --git a/avogadro/rendering/cylindergeometry.cpp b/avogadro/rendering/cylindergeometry.cpp index c56d15ac4d..3d7369cc07 100644 --- a/avogadro/rendering/cylindergeometry.cpp +++ b/avogadro/rendering/cylindergeometry.cpp @@ -281,7 +281,7 @@ std::multimap CylinderGeometry::hits( id.molecule = m_identifier.molecule; id.type = m_identifier.type; id.index = i; - if (m_indexMap.size()) + if (!m_indexMap.empty()) id.index = m_indexMap.find(i)->second; if (id.type != InvalidType) { float depth = distance.norm(); diff --git a/avogadro/rendering/geometrynode.cpp b/avogadro/rendering/geometrynode.cpp index ef45bca55d..2bc0b53c78 100644 --- a/avogadro/rendering/geometrynode.cpp +++ b/avogadro/rendering/geometrynode.cpp @@ -86,7 +86,7 @@ std::multimap GeometryNode::hits( const Vector3f& rayDirection) const { std::multimap result; - for (auto m_drawable : m_drawables) { + for (auto *m_drawable : m_drawables) { std::multimap drawableHits; if (m_drawable->isVisible()) drawableHits = m_drawable->hits(rayOrigin, rayEnd, rayDirection); @@ -99,7 +99,7 @@ std::multimap GeometryNode::hits( Array GeometryNode::areaHits(const Frustrum& f) const { Array result; - for (auto m_drawable : m_drawables) { + for (auto *m_drawable : m_drawables) { Array drawableHits; if (m_drawable->isVisible()) drawableHits = m_drawable->areaHits(f); diff --git a/avogadro/rendering/geometryvisitor.cpp b/avogadro/rendering/geometryvisitor.cpp index c5dedf209b..9e566e3710 100644 --- a/avogadro/rendering/geometryvisitor.cpp +++ b/avogadro/rendering/geometryvisitor.cpp @@ -28,7 +28,7 @@ void GeometryVisitor::visit(Drawable&) void GeometryVisitor::visit(SphereGeometry& geometry) { const Core::Array& spheres = geometry.spheres(); - if (!spheres.size()) + if (spheres.empty()) return; m_dirty = true; @@ -57,7 +57,7 @@ void GeometryVisitor::visit(SphereGeometry& geometry) void GeometryVisitor::visit(AmbientOcclusionSphereGeometry& geometry) { const Core::Array& spheres = geometry.spheres(); - if (!spheres.size()) + if (spheres.empty()) return; m_dirty = true; @@ -86,7 +86,7 @@ void GeometryVisitor::visit(AmbientOcclusionSphereGeometry& geometry) void GeometryVisitor::visit(CurveGeometry& cg) { const auto& lines = cg.lines(); - if (lines.size() == 0) { + if (lines.empty()) { return; } m_dirty = true; @@ -116,7 +116,7 @@ void GeometryVisitor::visit(LineStripGeometry& lsg) { typedef Core::Array VertexArray; const VertexArray verts(lsg.vertices()); - if (!verts.size()) + if (verts.empty()) return; m_dirty = true; diff --git a/avogadro/rendering/glrenderer.cpp b/avogadro/rendering/glrenderer.cpp index 310bcfcae2..cdf103b9c8 100644 --- a/avogadro/rendering/glrenderer.cpp +++ b/avogadro/rendering/glrenderer.cpp @@ -247,7 +247,7 @@ Array GLRenderer::hits(const GroupNode* group, result.insert(result.end(), loopHits.begin(), loopHits.end()); continue; } - const auto childGeometry = itNode->cast(); + const auto *const childGeometry = itNode->cast(); if (childGeometry) { loopHits = childGeometry->areaHits(f); result.insert(result.end(), loopHits.begin(), loopHits.end()); diff --git a/avogadro/rendering/groupnode.cpp b/avogadro/rendering/groupnode.cpp index cac2fa4423..d36ea8f900 100644 --- a/avogadro/rendering/groupnode.cpp +++ b/avogadro/rendering/groupnode.cpp @@ -82,7 +82,7 @@ void GroupNode::clear(NodeType ui) for (auto it = m_children.begin(); it != m_children.end();) { auto itNext = std::next(it); if (it->ui == ui || ui == ALL) { - auto groupNode = it->node->cast(); + auto *groupNode = it->node->cast(); if (groupNode != nullptr && ui != ALL) { switch (ui) { case UI: diff --git a/avogadro/rendering/plyvisitor.cpp b/avogadro/rendering/plyvisitor.cpp index 058e6e097a..363e1947ad 100644 --- a/avogadro/rendering/plyvisitor.cpp +++ b/avogadro/rendering/plyvisitor.cpp @@ -184,31 +184,31 @@ void PLYVisitor::visitSphereIcosphereRecursionMethod(const SphereColor& sphere, ostringstream faceStr; //Project every vertex onto the sphere and record it - for (unsigned int i = 0; i < vertices.size(); ++i) { + for (auto & vertice : vertices) { //Normalize the vertex and then project it - float x = vertices.at(i)[0]; - float y = vertices.at(i)[1]; - float z = vertices.at(i)[2]; + float x = vertice[0]; + float y = vertice[1]; + float z = vertice[2]; float distance = sqrt(pow(x, 2.0f) + pow(y, 2.0f) + pow(z, 2.0f)); - vertices.at(i)[0] = (x / distance) * radius; - vertices.at(i)[1] = (y / distance) * radius; - vertices.at(i)[2] = (z / distance) * radius; + vertice[0] = (x / distance) * radius; + vertice[1] = (y / distance) * radius; + vertice[2] = (z / distance) * radius; //Adjust to be around sphere's radius - vertices.at(i)[0] += center[0]; - vertices.at(i)[1] += center[1]; - vertices.at(i)[2] += center[2]; + vertice[0] += center[0]; + vertice[1] += center[1]; + vertice[2] += center[2]; //Add the vertex - vertexStr << vertices.at(i) << " " << sphere.color << '\n'; + vertexStr << vertice << " " << sphere.color << '\n'; } //Adjust every face to have indices for the PLY file and add it - for (unsigned int i = 0; i < faces.size(); ++i) { + for (auto & face : faces) { faceStr << 3 << " " - << faces.at(i)[0] + m_vertexCount << " " - << faces.at(i)[1] + m_vertexCount << " " - << faces.at(i)[2] + m_vertexCount << '\n'; + << face[0] + m_vertexCount << " " + << face[1] + m_vertexCount << " " + << face[2] + m_vertexCount << '\n'; } //Adjust the counts and add the new vertices and faces @@ -348,8 +348,8 @@ void PLYVisitor::visit(MeshGeometry& geometry) ostringstream faceStr; //Record every vertex in the mesh - for (size_t i = 0; i < v.size(); ++i) { - vertexStr << v[i].vertex << " " << v[i].color << '\n'; + for (auto & i : v) { + vertexStr << i.vertex << " " << i.color << '\n'; } //Record every face and adjust the indices diff --git a/avogadro/rendering/shader.cpp b/avogadro/rendering/shader.cpp index e07d79db60..ecac331fd9 100644 --- a/avogadro/rendering/shader.cpp +++ b/avogadro/rendering/shader.cpp @@ -5,12 +5,14 @@ #include "shader.h" +#include + #include "avogadrogl.h" namespace Avogadro::Rendering { -Shader::Shader(Type type_, const std::string& source_) - : m_type(type_), m_handle(0), m_dirty(true), m_source(source_) +Shader::Shader(Type type_, std::string source_) + : m_type(type_), m_handle(0), m_dirty(true), m_source(std::move(source_)) { } diff --git a/avogadro/rendering/shader.h b/avogadro/rendering/shader.h index 493d32e13b..cdfee1c67f 100644 --- a/avogadro/rendering/shader.h +++ b/avogadro/rendering/shader.h @@ -34,7 +34,7 @@ class AVOGADRORENDERING_EXPORT Shader Unknown /**< Unknown (default) */ }; - explicit Shader(Type type = Unknown, const std::string& source = ""); + explicit Shader(Type type = Unknown, std::string source = ""); ~Shader(); /** Set the shader type. */ diff --git a/avogadro/rendering/solidpipeline.cpp b/avogadro/rendering/solidpipeline.cpp index a313d99b82..9815c05228 100644 --- a/avogadro/rendering/solidpipeline.cpp +++ b/avogadro/rendering/solidpipeline.cpp @@ -170,11 +170,11 @@ void SolidPipeline::resize(int width, int height) glBindTexture(GL_TEXTURE_2D, d->renderTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_width, m_height, 0, GL_RGBA, - GL_UNSIGNED_BYTE, 0); + GL_UNSIGNED_BYTE, nullptr); glBindTexture(GL_TEXTURE_2D, d->depthTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, m_width, m_height, 0, - GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0); + GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, nullptr); } void SolidPipeline::setPixelRatio(float ratio) diff --git a/avogadro/rendering/textlabelbase.cpp b/avogadro/rendering/textlabelbase.cpp index ae10fa5dc2..7330fe4813 100644 --- a/avogadro/rendering/textlabelbase.cpp +++ b/avogadro/rendering/textlabelbase.cpp @@ -301,7 +301,7 @@ void TextLabelBase::buildTexture(const TextRenderStrategy& tren) bytesPerPixel); // Render the text to the buffer - if (m_imageRgba.size() > 0) { + if (!m_imageRgba.empty()) { tren.render(m_text, m_textProperties, m_imageRgba.data(), m_imageDimensions); } diff --git a/avogadro/rendering/vrmlvisitor.cpp b/avogadro/rendering/vrmlvisitor.cpp index 1772f0697e..4814211d9c 100644 --- a/avogadro/rendering/vrmlvisitor.cpp +++ b/avogadro/rendering/vrmlvisitor.cpp @@ -164,7 +164,7 @@ void VRMLVisitor::visit(MeshGeometry& geometry) Core::Array v = geometry.vertices(); // If there are no triangles then don't bother doing anything - if (v.size() == 0) + if (v.empty()) return; ostringstream str, verts, iverts, colors; diff --git a/avogadro/vtk/chartwidget.cpp b/avogadro/vtk/chartwidget.cpp index 8275e91594..cc141277ae 100644 --- a/avogadro/vtk/chartwidget.cpp +++ b/avogadro/vtk/chartwidget.cpp @@ -25,7 +25,7 @@ ChartWidget::ChartWidget(QWidget* p) : QWidget(p), m_qvtk(new QVTKWidget(this)) m_view->SetRenderWindow(m_qvtk->renderWindow()); m_view->SetInteractor(m_qvtk->interactor()); m_view->GetScene()->AddItem(m_chart); - auto hLayout = new QHBoxLayout(this); + auto *hLayout = new QHBoxLayout(this); hLayout->setContentsMargins(0, 0, 0, 0); hLayout->addWidget(m_qvtk); setLayout(hLayout); @@ -92,7 +92,7 @@ bool ChartWidget::addPlots(const std::vector< std::vector >& plotData, m_table->SetNumberOfRows(xSize); for (size_t i = 0; i < plotData.size(); ++i) { - auto& s = plotData[i]; + const auto& s = plotData[i]; auto* d = vtkArrays[i]; // This is a fast path in VTK for setting array values with a known type. for (size_t j = 0; j < s.size(); ++j) { @@ -128,7 +128,7 @@ void ChartWidget::setYAxisTitle(const char* title) void ChartWidget::setTickLabels(Axis a, const std::vector& tickPositions, const std::vector& tickLabels) { - auto customAxis = axis(a); + auto *customAxis = axis(a); // We need a valid axis and equal sizes vectors of points/labels. if (!customAxis) @@ -151,7 +151,7 @@ void ChartWidget::setTickLabels(Axis a, const std::vector& tickPositions, void ChartWidget::setAxisLimits(Axis a, float min, float max) { - auto customAxis = axis(a); + auto *customAxis = axis(a); // We need a valid axis and equal sizes vectors of points/labels. if (!customAxis) diff --git a/avogadro/vtk/vtkglwidget.cpp b/avogadro/vtk/vtkglwidget.cpp index 7e16dc757d..306741d499 100644 --- a/avogadro/vtk/vtkglwidget.cpp +++ b/avogadro/vtk/vtkglwidget.cpp @@ -38,7 +38,7 @@ using QtGui::Molecule; // The caller assumes ownership of the vtkImageData returned. vtkImageData* createCubeImageData(Core::Cube* cube) { - auto data = vtkImageData::New(); + auto *data = vtkImageData::New(); // data->SetNumberOfScalarComponents(1, nullptr); Eigen::Vector3i dim = cube->dimensions(); data->SetExtent(0, dim.x() - 1, 0, dim.y() - 1, 0, dim.z() - 1); @@ -79,8 +79,8 @@ void vtkGLWidget::cubeVolume(Core::Cube* cube) volumeProperty->ShadeOff(); volumeProperty->SetInterpolationTypeToLinear(); - auto compositeOpacity = m_opacityFunction.Get(); - auto color = m_lut.Get(); + auto *compositeOpacity = m_opacityFunction.Get(); + auto *color = m_lut.Get(); if (color->GetSize() == 0) { // Initialize the color and opacity function. double range[2]; diff --git a/utilities/bodr/bodrparse.cxx b/utilities/bodr/bodrparse.cxx index 7620cb4433..89cd505abb 100644 --- a/utilities/bodr/bodrparse.cxx +++ b/utilities/bodr/bodrparse.cxx @@ -19,8 +19,9 @@ #include #include -#include #include +#include +#include #include using std::ifstream; @@ -44,7 +45,7 @@ struct Color { }; struct Element { - Element(const string &_id) : symbol(_id), atomicNumber(0), mass(-1.0), + Element(string _id) : symbol(std::move(_id)), atomicNumber(0), mass(-1.0), radiusCovalent(-1.0), radiusVDW(-1.0) { } diff --git a/utilities/resdata/resdataparse.cxx b/utilities/resdata/resdataparse.cxx index 27a6117b27..35dbfcb5e0 100644 --- a/utilities/resdata/resdataparse.cxx +++ b/utilities/resdata/resdataparse.cxx @@ -112,16 +112,16 @@ int main(int argc, char* argv[]) return 1; } - string buffer, currResidue = ""; + string buffer, currResidue; vector atoms, residueClassNames; vector> singleBonds, doubleBonds; while (getline(file, buffer)) { vector params(Avogadro::Core::split(buffer, ' ')); - if (params.size() == 0) { + if (params.empty()) { } else { if (params[0] == "RES") { - if (currResidue != "") { + if (!currResidue.empty()) { output << "ResidueData " << currResidue << "Data(\"" << currResidue << "\",\n" << "// Atoms\n{"; From ae8e8fba479f14ffe274003981b3034d0c92ecce Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Wed, 10 May 2023 14:25:25 +0200 Subject: [PATCH 2/2] Revert changes to graph code Signed-off-by: Geoff Hutchison --- avogadro/core/graph.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/avogadro/core/graph.cpp b/avogadro/core/graph.cpp index 9646965b69..e3ebced664 100644 --- a/avogadro/core/graph.cpp +++ b/avogadro/core/graph.cpp @@ -284,7 +284,7 @@ void Graph::removeEdge(size_t a, size_t b) std::vector& neighborsA = m_adjacencyList[a]; std::vector& neighborsB = m_adjacencyList[b]; - auto iter = + std::vector::iterator iter = std::find(neighborsA.begin(), neighborsA.end(), b); if (iter == neighborsA.end()) @@ -360,8 +360,8 @@ void Graph::removeEdges(size_t index) m_subgraphDirty[m_vertexToSubgraph[index]] = true; const std::vector& edges = m_edgeMap[index]; - for (unsigned long edge : edges) - removeEdge(edge); + for (size_t i = 0; i < edges.size(); ++i) + removeEdge(edges[i]); } void Graph::editEdgeInPlace(size_t edgeIndex, size_t a, size_t b) @@ -473,7 +473,7 @@ int Graph::createNewSubgraph() const { // Try to find an empty subgraph to reuse for (size_t i = 0; i < m_subgraphToVertices.size(); i++) { - if (m_subgraphToVertices[i].empty()) { + if (!m_subgraphToVertices[i].size()) { m_subgraphDirty[i] = false; return int(i); } @@ -515,7 +515,7 @@ void Graph::checkSplitSubgraph(int subgraph) const verticesToVisit.insert(verticesToVisit.end(), neighborList.begin(), neighborList.end()); } - } while (!verticesToVisit.empty()); + } while (verticesToVisit.size()); currentSubgraph = -1; } } @@ -538,7 +538,7 @@ std::vector> Graph::connectedComponents() const { updateSubgraphs(); std::vector> r; - for (const std::set& s : m_subgraphToVertices) { + for (std::set s : m_subgraphToVertices) { if (!s.empty()) r.push_back(s); } @@ -555,7 +555,7 @@ size_t Graph::subgraphsCount() const { updateSubgraphs(); size_t r = 0; - for (const std::set& s : m_subgraphToVertices) { + for (std::set s : m_subgraphToVertices) { if (!s.empty()) r++; } @@ -568,7 +568,7 @@ size_t Graph::subgraph(size_t element) const // Index -1 means disconnected (its own subgraph) if (r < 0) { r = m_subgraphToVertices.size(); - m_subgraphToVertices.emplace_back(); + m_subgraphToVertices.push_back(std::set()); m_subgraphToVertices[r].insert(element); m_subgraphDirty[r] = false; return r;