fix: Resolve variable redeclaration and font metrics scope in paintGL

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2026-02-16 17:45:05 -07:00
parent 9d72fe2155
commit d89b7e42bc

View File

@@ -407,8 +407,8 @@ void ViewportWidget::paintGL()
// Arrowheads for arc // Arrowheads for arc
QVector<GLfloat> arrowVertices; QVector<GLfloat> arrowVertices;
float arrowLength = 0.02f * -m_camera->zoom(); float arcArrowLength = 0.02f * -m_camera->zoom();
float arrowWidth = 0.005f * -m_camera->zoom(); float arcArrowWidth = 0.005f * -m_camera->zoom();
// End arrowhead // End arrowhead
QVector3D endPoint(vertices[vertices.size()-3], vertices[vertices.size()-2], vertices[vertices.size()-1]); QVector3D endPoint(vertices[vertices.size()-3], vertices[vertices.size()-2], vertices[vertices.size()-1]);
@@ -424,11 +424,11 @@ void ViewportWidget::paintGL()
radialDir_end = QVector3D(0, cos(endAngle), sin(endAngle)); radialDir_end = QVector3D(0, cos(endAngle), sin(endAngle));
tangentDir_end = QVector3D(0, -sin(endAngle), cos(endAngle)); tangentDir_end = QVector3D(0, -sin(endAngle), cos(endAngle));
} }
QVector3D arrow_base_end = endPoint - arrowLength * tangentDir_end; QVector3D arc_arrow_base_end = endPoint - arcArrowLength * tangentDir_end;
QVector3D arrowP1_end = arrow_base_end + arrowWidth * radialDir_end; QVector3D arc_arrowP1_end = arc_arrow_base_end + arcArrowWidth * radialDir_end;
QVector3D arrowP2_end = arrow_base_end - arrowWidth * radialDir_end; QVector3D arc_arrowP2_end = arc_arrow_base_end - arcArrowWidth * radialDir_end;
arrowVertices << endPoint.x() << endPoint.y() << endPoint.z() << arrowP1_end.x() << arrowP1_end.y() << arrowP1_end.z(); arrowVertices << endPoint.x() << endPoint.y() << endPoint.z() << arc_arrowP1_end.x() << arc_arrowP1_end.y() << arc_arrowP1_end.z();
arrowVertices << endPoint.x() << endPoint.y() << endPoint.z() << arrowP2_end.x() << arrowP2_end.y() << arrowP2_end.z(); arrowVertices << endPoint.x() << endPoint.y() << endPoint.z() << arc_arrowP2_end.x() << arc_arrowP2_end.y() << arc_arrowP2_end.z();
// Start arrowhead // Start arrowhead
QVector3D startPoint(vertices[0], vertices[1], vertices[2]); QVector3D startPoint(vertices[0], vertices[1], vertices[2]);
@@ -444,11 +444,11 @@ void ViewportWidget::paintGL()
radialDir_start = QVector3D(0, cos(startAngle), sin(startAngle)); radialDir_start = QVector3D(0, cos(startAngle), sin(startAngle));
tangentDir_start = QVector3D(0, -sin(startAngle), cos(startAngle)); tangentDir_start = QVector3D(0, -sin(startAngle), cos(startAngle));
} }
QVector3D arrow_base_start = startPoint + arrowLength * tangentDir_start; QVector3D arc_arrow_base_start = startPoint + arcArrowLength * tangentDir_start;
QVector3D arrowP1_start = arrow_base_start + arrowWidth * radialDir_start; QVector3D arc_arrowP1_start = arc_arrow_base_start + arcArrowWidth * radialDir_start;
QVector3D arrowP2_start = arrow_base_start - arrowWidth * radialDir_start; QVector3D arc_arrowP2_start = arc_arrow_base_start - arcArrowWidth * radialDir_start;
arrowVertices << startPoint.x() << startPoint.y() << startPoint.z() << arrowP1_start.x() << arrowP1_start.y() << arrowP1_start.z(); arrowVertices << startPoint.x() << startPoint.y() << startPoint.z() << arc_arrowP1_start.x() << arc_arrowP1_start.y() << arc_arrowP1_start.z();
arrowVertices << startPoint.x() << startPoint.y() << startPoint.z() << arrowP2_start.x() << arrowP2_start.y() << arrowP2_start.z(); arrowVertices << startPoint.x() << startPoint.y() << startPoint.z() << arc_arrowP2_start.x() << arc_arrowP2_start.y() << arc_arrowP2_start.z();
m_vbo.bind(); m_vbo.bind();
m_vbo.allocate(arrowVertices.constData(), arrowVertices.size() * sizeof(GLfloat)); m_vbo.allocate(arrowVertices.constData(), arrowVertices.size() * sizeof(GLfloat));
@@ -638,11 +638,12 @@ void ViewportWidget::paintGL()
QVector3D screenPos = project(textPos3D, model, projection, rect()); QVector3D screenPos = project(textPos3D, model, projection, rect());
painter.setRenderHint(QPainter::Antialiasing);
QFontMetrics fm(painter.font());
if (screenPos.z() < 1.0f) { if (screenPos.z() < 1.0f) {
dimText = lengthFromInput ? dimInput : QString::number(lineLength, 'f', 2); dimText = lengthFromInput ? dimInput : QString::number(lineLength, 'f', 2);
painter.setRenderHint(QPainter::Antialiasing);
QFontMetrics fm(painter.font());
QRect textRect = fm.boundingRect(dimText + "_"); QRect textRect = fm.boundingRect(dimText + "_");
textRect.moveCenter(screenPos.toPoint()); textRect.moveCenter(screenPos.toPoint());