feat: allow TimestampElement to have extra flags

This allows you to create TimestampElements that have additional flags,
     such as an extra "Header" flag
This commit is contained in:
Rasmus Karlsson
2026-08-23 15:49:09 +02:00
parent bda2df6339
commit 8f41f3e98f
2 changed files with 30 additions and 4 deletions
+22 -4
View File
@@ -1330,6 +1330,24 @@ TimestampElement::TimestampElement(QTime time)
assert(this->element_ != nullptr);
}
TimestampElement::TimestampElement(QTime time,
const MessageElementFlags extraFlags)
: MessageElement(extraFlags | MessageElementFlag::Timestamp)
, time_(time)
, element_(this->formatTime(time))
{
assert(this->element_ != nullptr);
}
TimestampElement::TimestampElement(TimestampElement::CloneConstructorTag,
QTime time, const MessageElementFlags flags)
: MessageElement(flags)
, time_(time)
, element_(this->formatTime(time))
{
assert(this->element_ != nullptr);
}
void TimestampElement::addToContainer(MessageLayoutContainer &container,
const MessageLayoutContext &ctx)
{
@@ -1352,9 +1370,8 @@ TextElement *TimestampElement::formatTime(const QTime &time)
QString format = locale.toString(time, getSettings()->timestampFormat);
auto *text =
new TextElement(format, MessageElementFlag::Timestamp,
MessageColor::System, FontStyle::TimestampMedium);
auto *text = new TextElement(format, this->getFlags(), MessageColor::System,
FontStyle::TimestampMedium);
text->setLink(this->getLink());
text->setTooltip(this->getTooltip());
return text;
@@ -1385,7 +1402,8 @@ std::string_view TimestampElement::type() const
std::unique_ptr<MessageElement> TimestampElement::clone() const
{
auto elem = std::make_unique<TimestampElement>(this->time_);
auto elem = std::make_unique<TimestampElement>(
TimestampElement::CloneConstructorTag{}, this->time_, this->getFlags());
elem->cloneFrom(*this);
return elem;
}
+8
View File
@@ -667,11 +667,19 @@ protected:
// contains a text, formated depending on the preferences
class TimestampElement : public MessageElement
{
protected:
struct CloneConstructorTag {
};
public:
static constexpr std::string_view TYPE = "timestamp";
TimestampElement();
TimestampElement(QTime time_);
TimestampElement(QTime time_, MessageElementFlags extraFlags);
/// This is intended only for cloning the element.
TimestampElement(TimestampElement::CloneConstructorTag, QTime time_,
MessageElementFlags flags);
~TimestampElement() override = default;
void addToContainer(MessageLayoutContainer &container,