From 344dbea31ae3f05328e549ee991d452e36ee27c2 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 30 Aug 2019 02:24:39 -0400 Subject: [PATCH] ADSREditor: Use std::array for m_percentTexts Same behavior, but allows for stronger typing and dehardcoding of sizes. --- Editor/ADSREditor.cpp | 6 +++--- Editor/ADSREditor.hpp | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Editor/ADSREditor.cpp b/Editor/ADSREditor.cpp index 543226e..928267f 100644 --- a/Editor/ADSREditor.cpp +++ b/Editor/ADSREditor.cpp @@ -55,8 +55,8 @@ void ADSRView::paintEvent(QPaintEvent* ev) { painter.setPen(QPen(QColor(127, 127, 127), penWidth)); painter.setFont(m_gridFont); const qreal yIncrement = (height() - 16.0) / 10.0; - for (int i = 0; i < 11; ++i) { - const qreal thisY = i * yIncrement; + for (size_t i = 0; i < m_percentTexts.size(); ++i) { + const qreal thisY = qreal(i) * yIncrement; const qreal textY = thisY - (i == 0 ? 2.0 : (i == 10 ? 16.0 : 8.0)); painter.drawStaticText(QPointF(0.0, textY), m_percentTexts[i]); painter.drawLine(QPointF(30.0, thisY), QPointF(width(), thisY)); @@ -212,7 +212,7 @@ void ADSRView::mouseMoveEvent(QMouseEvent* ev) { } ADSRView::ADSRView(QWidget* parent) : QWidget(parent) { - for (int i = 0; i < 11; ++i) { + for (size_t i = 0; i < m_percentTexts.size(); ++i) { m_percentTexts[i].setText(QStringLiteral("%1%").arg(100 - i * 10)); m_percentTexts[i].setTextOption(QTextOption(Qt::AlignVCenter | Qt::AlignRight)); m_percentTexts[i].setTextWidth(28.0); diff --git a/Editor/ADSREditor.hpp b/Editor/ADSREditor.hpp index 59726cc..42bc8cd 100644 --- a/Editor/ADSREditor.hpp +++ b/Editor/ADSREditor.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -22,7 +23,7 @@ class ADSRView : public QWidget { friend class ADSRControls; amuse::ObjToken m_node; QFont m_gridFont; - QStaticText m_percentTexts[11]; + std::array m_percentTexts; std::vector m_timeTexts; int m_dragPoint = -1; uint64_t m_cycleIdx = 0;