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 8e85dbd commit 3c1d44c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/library/stareditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class StarEditor : public QWidget {
void setStarRating(const StarRating& starRating) {
m_starRating = starRating;
int stars = m_starRating.starCount();
VERIFY_OR_DEBUG_ASSERT(stars >= m_starRating.kMinStarCount &&
stars <= m_starRating.maxStarCount()) {
VERIFY_OR_DEBUG_ASSERT(m_starRating.verifyStarCount(stars)) {
return;
}
m_starCount = stars;
Expand Down
3 changes: 1 addition & 2 deletions src/library/starrating.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,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
9 changes: 7 additions & 2 deletions src/library/starrating.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ class StarRating {
/// x is the x-position inside the parent rectangle rect
int starAtPosition(int x, const QRect& rect) const;

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 @@ -49,8 +49,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 3c1d44c

Please sign in to comment.