From 99151b9c04b5ad730f34d3f6c998216da0cb3865 Mon Sep 17 00:00:00 2001 From: Andre Rummler Date: Fri, 7 Aug 2026 11:39:08 +0200 Subject: [PATCH] Report "no constraint" (still needs the translations; to be added in the next translation round I guess) from minimumWidth() for a title template instead of an arbitrary value. Following up on the earlier division-by-zero fix: return -1 from the bad denominator branch of minimumWidth(), matching the "no constraint" convention maximumWidth() already uses, instead of std::numeric_limits::max() or 0. Update TitleBlockTemplateView::updateDisplayedMinMaxWidth() to skip the "Longueur minimale" line when minimumWidth() reports -1, mirroring its existing handling of maximumWidth() == -1. --- sources/titleblock/templateview.cpp | 18 ++++++++++++++++-- sources/titleblocktemplate.cpp | 10 ++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/sources/titleblock/templateview.cpp b/sources/titleblock/templateview.cpp index 096f96c0f..b41881d82 100644 --- a/sources/titleblock/templateview.cpp +++ b/sources/titleblock/templateview.cpp @@ -999,20 +999,34 @@ void TitleBlockTemplateView::updateDisplayedMinMaxWidth() int max_width = tbtemplate_ -> maximumWidth(); QString min_max_width_sentence; - if (max_width != -1) { + if (min_width != -1 && max_width != -1) { min_max_width_sentence = QString( tr( "Longueur minimale : %1px\nLongueur maximale : %2px\n", "tooltip showing the minimum and/or maximum width of the edited template" ) ).arg(min_width).arg(max_width); - } else { + } else if (min_width != -1) { min_max_width_sentence = QString( tr( "Longueur minimale : %1px\n", "tooltip showing the minimum width of the edited template" ) ).arg(min_width); + } else if (max_width != -1) { + min_max_width_sentence = QString( + tr( + "Longueur maximale : %1px\n", + "tooltip showing the maximum width of the edited template" + ) + ).arg(max_width); + } else { + min_max_width_sentence = QString( + tr( + "Longueur non contrainte.\n", + "tooltip shown when the edited template has neither a minimum nor a maximum width constraint" + ) + ); } // the tooltip may also display the split label for readability purpose diff --git a/sources/titleblocktemplate.cpp b/sources/titleblocktemplate.cpp index 63a3631a6..1e9b45a41 100644 --- a/sources/titleblocktemplate.cpp +++ b/sources/titleblocktemplate.cpp @@ -26,7 +26,6 @@ #include #include -#include /** @brief TitleBlockTemplate::TitleBlockTemplate Constructor @@ -980,11 +979,10 @@ int TitleBlockTemplate::minimumWidth() if (denominator <= 0.0) { // The relative-to-total-length columns alone already consume // 100% (or more) of the available width, so the formula above - // would divide by zero (or go negative). If there are no - // absolute-width columns, there is no meaningful minimum width - // to enforce; if there are, the template is asking for more - // than 100% of its own width, which cannot be satisfied. - return abs_total > 0 ? std::numeric_limits::max() : 0; + // would divide by zero (or go negative). There is no finite + // minimum width this formula can determine. Report "no + // constraint", the same convention maximumWidth() uses. + return -1; } return(qRound(abs_total / denominator));