Skip to content

Commit

Permalink
add StarRating::verifyStarCount() helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Jan 19, 2024
1 parent 09b4cce commit 6e4b816
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/library/starrating.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ StarRating::StarRating(
int maxStarCount)
: m_starCount(starCount),
m_maxStarCount(maxStarCount) {
DEBUG_ASSERT(m_starCount >= kMinStarCount);
DEBUG_ASSERT(m_starCount <= m_maxStarCount);
DEBUG_ASSERT(verifyStarCount(m_starCount));
// 1st star cusp at 0° of the unit circle whose center is shifted to adapt the 0,0-based paint area
m_starPolygon << QPointF(1.0, 0.5);
for (int i = 1; i < 5; ++i) {
Expand Down
10 changes: 8 additions & 2 deletions src/library/starrating.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ class StarRating {
int maxStarCount() const {
return m_maxStarCount;
}

bool verifyStarCount(int starCount) {
return starCount >= kMinStarCount && starCount <= m_maxStarCount;
}

void setStarCount(int starCount) {
DEBUG_ASSERT(starCount >= kMinStarCount);
DEBUG_ASSERT(starCount <= m_maxStarCount);
VERIFY_OR_DEBUG_ASSERT(verifyStarCount(starCount)) {
return;
}
m_starCount = starCount;
}

Expand Down
3 changes: 1 addition & 2 deletions src/widget/wstarrating.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ QSize WStarRating::sizeHint() const {
}

void WStarRating::slotSetRating(int starCount) {
if (starCount == m_starCount) {
// Unchanged
if (starCount == m_starCount || !m_visualStarRating.verifyStarCount(starCount)) {
return;
}
m_starCount = starCount;
Expand Down

0 comments on commit 6e4b816

Please sign in to comment.