From 00c029a819eca601e9ac58e5c236d667505ac566 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Tue, 11 Aug 2026 10:56:40 +0200 Subject: feat(config): let the date format on a card be configured Adds [general] date_format, a QDateTime pattern for the date a thread card shows. Absent or empty means the system locale's short format, which is what every other application on the desktop uses and stays the default. The format reaches the LAYOUT, not only the painter. CardLayout::compute() reserves the date's width from widestDateSample(), so a pattern that arrived only at the drawText call would be elided into a rect sized for the old format, which is the clipping the bold-font fault already produced once. It rides on CardLayout::Input and defaults to an empty string, leaving every existing call site unchanged. Confirmed by mutation: making the width ignore the format fails the test. widestDateSample() memoised its result in a static, which would have sized every format after the first from whichever arrived first. It is a plain call now, costing one QLocale lookup per row, the same as formatting the date. Validation rejects only a pattern whose output is CONSTANT, found by formatting two different instants and comparing. QDateTime::toString() treats nearly every letter as a field, so "banana" formats as "bpmnpmnpm" and "hello" as "22ello": nonsense, but they vary with the instant, and a check claiming to find "no date field" cannot reject them. What harms the user is the pattern that prints the same text on every card, and that is what is refused, with the value named in the message. The model supplies the pattern through DateFormatRole for the same reason it supplies the tag colours: it is the one object here holding config, and a delegate reading config itself would be a second source of truth. Backlog item 62. --- src/threadlistmodel.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/threadlistmodel.h') diff --git a/src/threadlistmodel.h b/src/threadlistmodel.h index 01dd9d0..777841e 100644 --- a/src/threadlistmodel.h +++ b/src/threadlistmodel.h @@ -116,6 +116,14 @@ public: HasAttachmentRole, ///< bool IsFlaggedRole, ///< bool ReplyCountRole, ///< int; 0 when a thread has no replies. + + /// The [general] date_format pattern, or empty for the system's short + /// format. Same row value for every row. + /// + /// Supplied by the model for the same reason as PillColoursRole: it is + /// the one thing here that holds config, and a delegate reading config + /// itself would be a second source of truth. + DateFormatRole, }; /// The mark drawn on a card's second line when the message has an @@ -159,6 +167,9 @@ public: /// Without one, chips fall back to a colour generated from the tag name. void setTagColors(const TagColors *colours) { m_tagColors = colours; } + /// The pattern DateFormatRole answers with. Empty means the system format. + void setDateFormat(const QString &format) { m_dateFormat = format; } + QModelIndex index(int row, int column, const QModelIndex &parent = {}) const override; QModelIndex parent(const QModelIndex &child) const override; @@ -272,4 +283,5 @@ private: QVector m_threads; const TagColors *m_tagColors = nullptr; + QString m_dateFormat; }; -- cgit v1.2.3