From 1747dcf5632a7887906b9b6d412e95e3af9c8249 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Thu, 21 Jan 2021 19:42:41 +0100 Subject: INT_MAX -> std::numeric_limits, plus minor clean. --- src/modlistbypriorityproxy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modlistbypriorityproxy.cpp') diff --git a/src/modlistbypriorityproxy.cpp b/src/modlistbypriorityproxy.cpp index 7dae7a54..d1d045fc 100644 --- a/src/modlistbypriorityproxy.cpp +++ b/src/modlistbypriorityproxy.cpp @@ -234,7 +234,7 @@ bool ModListByPriorityProxy::canDropMimeData(const QMimeData* data, Qt::DropActi bool hasSeparator = false; unsigned int firstRowIndex = -1; - int firstRowPriority = INT_MAX; + int firstRowPriority = std::numeric_limits::max(); for (auto sourceRow : dropInfo.rows()) { hasSeparator = hasSeparator || ModInfo::getByIndex(sourceRow)->isSeparator(); if (m_sortOrder == Qt::AscendingOrder && m_profile->getModPriority(sourceRow) < firstRowPriority -- cgit v1.3.1 From 7864fc0950729621c0297389f5b47d27e4d41d8f Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Fri, 22 Jan 2021 21:18:54 +0100 Subject: Use constant for minimum/maximum priorities. --- src/modlist.cpp | 5 +---- src/modlistbypriorityproxy.cpp | 2 +- src/modlistviewactions.cpp | 6 +++--- src/profile.h | 12 ++++++++++-- 4 files changed, 15 insertions(+), 10 deletions(-) (limited to 'src/modlistbypriorityproxy.cpp') diff --git a/src/modlist.cpp b/src/modlist.cpp index 13b2298f..81dc91bf 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -1023,14 +1023,11 @@ int ModList::dropPriority(int row, const QModelIndex& parent) const int newPriority = 0; { if (row < 0 || row >= rowCount()) { - newPriority = std::numeric_limits::max(); + newPriority = Profile::MaximumPriority; } else { newPriority = m_Profile->getModPriority(row); } - if (newPriority == -1) { - newPriority = std::numeric_limits::max(); - } } return newPriority; diff --git a/src/modlistbypriorityproxy.cpp b/src/modlistbypriorityproxy.cpp index d1d045fc..24e58ed0 100644 --- a/src/modlistbypriorityproxy.cpp +++ b/src/modlistbypriorityproxy.cpp @@ -234,7 +234,7 @@ bool ModListByPriorityProxy::canDropMimeData(const QMimeData* data, Qt::DropActi bool hasSeparator = false; unsigned int firstRowIndex = -1; - int firstRowPriority = std::numeric_limits::max(); + int firstRowPriority = Profile::MaximumPriority; for (auto sourceRow : dropInfo.rows()) { hasSeparator = hasSeparator || ModInfo::getByIndex(sourceRow)->isSeparator(); if (m_sortOrder == Qt::AscendingOrder && m_profile->getModPriority(sourceRow) < firstRowPriority diff --git a/src/modlistviewactions.cpp b/src/modlistviewactions.cpp index e7e74b16..647aac0b 100644 --- a/src/modlistviewactions.cpp +++ b/src/modlistviewactions.cpp @@ -539,12 +539,12 @@ void ModListViewActions::displayModInformation(ModInfo::Ptr modInfo, unsigned in void ModListViewActions::sendModsToTop(const QModelIndexList& indexes) const { - m_core.modList()->changeModsPriority(indexes, 0); + m_core.modList()->changeModsPriority(indexes, Profile::MinimumPriority); } void ModListViewActions::sendModsToBottom(const QModelIndexList& indexes) const { - m_core.modList()->changeModsPriority(indexes, std::numeric_limits::max()); + m_core.modList()->changeModsPriority(indexes, Profile::MaximumPriority); } void ModListViewActions::sendModsToPriority(const QModelIndexList& indexes) const @@ -580,7 +580,7 @@ void ModListViewActions::sendModsToSeparator(const QModelIndexList& indexes) con if (!result.isEmpty()) { result += "_separator"; - int newPriority = std::numeric_limits::max(); + int newPriority = Profile::MaximumPriority; bool foundSection = false; for (auto mod : m_core.modList()->allModsByProfilePriority()) { unsigned int modIndex = ModInfo::getIndex(mod); diff --git a/src/profile.h b/src/profile.h index d1e3f104..672a2c13 100644 --- a/src/profile.h +++ b/src/profile.h @@ -52,7 +52,14 @@ class Profile : public QObject, public MOBase::IProfile public: - typedef boost::shared_ptr Ptr; + using Ptr = boost::shared_ptr; + +public: + + // the minimum and maximum priority achievable by mods + // + static constexpr int MinimumPriority = 0; + static constexpr int MaximumPriority = std::numeric_limits::max(); public: @@ -283,7 +290,8 @@ public: // [old priority, new priority] such that no gaps are possible // // the priority is clamped in the range of valid priority (>= 0, and lower than - // the number of "regular" mods) + // the number of "regular" mods), you should use MinimumPriority or MaximumPriority + // to send a mod to the "top" or "bottom" of the priority list // // the function returns true if the priority was changed, or false if the mod // was already at the given priority (or if the priority of the mod cannot be -- cgit v1.3.1