6#ifndef SWIFT_MISC_STATUSMESSAGE_H
7#define SWIFT_MISC_STATUSMESSAGE_H
9#include <QReadWriteLock>
83 m_view = m_string = other.m_string;
87 m_view = other.m_view;
100 bool isOwning()
const {
return !m_string.isNull(); }
109 return isOwning() ? m_string : m_view.toString();
115 return a.m_view.
compare(b.m_view);
160 template <
class Derived>
207 Derived &
debug(
const char16_t (&format)[N])
209 return log(SeverityDebug, format);
217 Derived &
info(
const char16_t (&format)[N])
219 return log(SeverityInfo, format);
229 return log(SeverityWarning, format);
237 Derived &
error(
const char16_t (&format)[N])
239 return log(SeverityError, format);
250 return log(s, format);
257 return log(s, format);
265 return log(SeverityInfo, format);
272 return log(SeverityInfo, format);
280 return log(SeverityWarning, format);
287 return log(SeverityWarning, format);
295 return log(SeverityError, format);
302 return log(SeverityError, format);
308 Derived &
debug(
const char *) =
delete;
309 Derived &
info(
const char *) =
delete;
311 Derived &
error(
const char *) =
delete;
347 Derived &arg(
const QString &value)
352 Derived &derived() {
return static_cast<Derived &
>(*this); }
420 IndexCategoriesAsString = CPropertyIndexRef::GlobalIndexCStatusMessage,
422 IndexSeverityAsString,
425 IndexMessageNoLineBreaks,
474 bool validation =
false);
498 QString getCategoriesAsString()
const;
525 bool isSuccess()
const;
528 bool isFailure()
const;
534 QString getMessageNoLineBreaks()
const;
537 void prependMessage(
const QString &msg);
540 void appendMessage(
const QString &msg);
547 return std::all_of(classCategories.
begin(), classCategories.
end(),
548 [
this](
const CLogCategory &cat) { return m_categories.contains(cat); });
552 void markAsHandledBy(
const QObject *
object)
const;
555 bool wasHandledBy(
const QObject *
object)
const;
579 const QString &getSeverityAsString()
const;
582 const CIcon &getSeverityAsIcon()
const;
606 QString convertToQString(
bool i18n =
false)
const;
609 QString toHtml(
bool withIcon,
bool withColors)
const;
652 template <
class Derived>
669 template <
class Derived>
void convertFromJson(const QJsonObject &json)
Assign from JSON object.
CStatusMessage convertFromJsonNoThrow(const QJsonObject &json, const CLogCategoryList &categories, const QString &prefix)
Call convertFromJson, catch any CJsonException that is thrown and return it as CStatusMessage.
Value object for icons. An icon is stored in the global icon repository and identified by its index....
IconIndex
Index for each icon, allows to send them via DBus, efficiently store them, etc.
Thrown when a convertFromJson method encounters an unrecoverable error in JSON data.
static const QString & uncategorized()
Uncategorized.
static const QString & validation()
Validation.
A log category is an arbitrary string tag which can be attached to log messages.
A sequence of log categories.
Derived & validationInfo(const char *)=delete
Deleted methods to avoid accidental implicit conversion from Latin-1 or UTF-8 string literals.
CLogCategoryList m_categories
Private.
Derived & debug(const char *)=delete
Deleted methods to avoid accidental implicit conversion from Latin-1 or UTF-8 string literals.
Derived & validationError(const char16_t(&format)[N])
Set the severity to error, providing a format string, and adding the validation category.
bool isEmpty() const
Message empty.
Derived & error(const char *)=delete
Deleted methods to avoid accidental implicit conversion from Latin-1 or UTF-8 string literals.
CMessageBase(const CLogCategoryList &categories, const CLogCategory &extra)
Construct a message with some specific categories.
CMessageBase(const CLogCategoryList &categories, const CLogCategoryList &extra)
Construct a message with some specific categories.
Derived & validation(StatusSeverity, const char *)=delete
Deleted methods to avoid accidental implicit conversion from Latin-1 or UTF-8 string literals.
Derived & debug()
Set the severity to debug.
Derived & validationInfo(const QString &format)
Set the severity to info, providing a format string, and adding the validation category.
Derived & validationWarning(const char16_t(&format)[N])
Set the severity to warning, providing a format string, and adding the validation category.
Derived & validationWarning(const QString &format)
Set the severity to warning, providing a format string, and adding the validation category.
Derived & warning(const char16_t(&format)[N])
Set the severity to warning, providing a format string.
Derived & validation(StatusSeverity s, const char16_t(&format)[N])
Set the severity to s, providing a format string, and adding the validation category.
Derived & operator<<(T v)
Streaming operators.
CStrongStringView m_message
Private.
Derived & validation(StatusSeverity s, const QString &format)
Set the severity to s, providing a format string, and adding the validation category.
Derived & info(const char *)=delete
Deleted methods to avoid accidental implicit conversion from Latin-1 or UTF-8 string literals.
void addIfNotExisting(const CLogCategory &category)
Add category if not already existing.
Derived & debug(const char16_t(&format)[N])
Set the severity to debug, providing a format string.
QStringList m_args
Private.
StatusSeverity m_severity
Private.
Derived & error(const char16_t(&format)[N])
Set the severity to error, providing a format string.
Derived & log(StatusSeverity s, const QString &m)
Set the severity and format string.
Derived & validationWarning(const char *)=delete
Deleted methods to avoid accidental implicit conversion from Latin-1 or UTF-8 string literals.
CMessageBase(const CLogCategoryList &categories)
Construct a message with some specific categories.
Derived & warning(const char *)=delete
Deleted methods to avoid accidental implicit conversion from Latin-1 or UTF-8 string literals.
void addIfNotExisting(const CLogCategoryList &categories)
Add categories if not already existing.
Derived & info(const QString &format)
Set the severity to info, providing a format string.
Derived & operator<<(const T &v)
Streaming operators.
CMessageBase(const CLogCategory &category)
Construct a message with some specific category.
Derived & validationError(const char *)=delete
Deleted methods to avoid accidental implicit conversion from Latin-1 or UTF-8 string literals.
Derived & info(const char16_t(&format)[N])
Set the severity to info, providing a format string.
Derived & warning(const QString &format)
Set the severity to warning, providing a format string.
Derived & debug(const QString &format)
Set the severity to debug, providing a format string.
QString message() const
Private.
Derived & log(StatusSeverity s, const char16_t(&m)[N])
Set the severity and format string.
Derived & log(StatusSeverity, const char *)=delete
Deleted methods to avoid accidental implicit conversion from Latin-1 or UTF-8 string literals.
Derived & error(const QString &format)
Set the severity to error, providing a format string.
Derived & validationError(const QString &format)
Set the severity to error, providing a format string, and adding the validation category.
CMessageBase()=default
Default constructor.
Derived & validationInfo(const char16_t(&format)[N])
Set the severity to info, providing a format string, and adding the validation category.
Non-owning reference to a CPropertyIndex with a subset of its features.
iterator begin()
Returns iterator at the beginning of the sequence.
int remove(const T &object)
Remove all elements equal to the given object, if it is contained.
iterator end()
Returns iterator one past the end of the sequence.
Streamable status message, e.g.
void setCategory(const CLogCategory &category)
Reset category.
bool isWarningOrAbove() const
Warning or above.
static CStatusMessage fromJsonException(const CJsonException &ex, const CLogCategoryList &categories, const QString &prefix)
Object from JSON exception message.
CStatusMessage(const char16_t(&message)[N])
Constructor.
bool isSeverityInfoOrLess() const
Info or debug, no warning or error.
bool isFromClass(const T *pointer=nullptr) const
Returns true if this message was sent by an instance of class T.
static constexpr auto SeverityInfo
Status severities.
static constexpr auto SeverityError
Status severities.
void addCategories(const CLogCategoryList &categories)
Add categories, avoids duplicates.
CStatusMessage(const CLogCategory &category)
Construct a message with some specific category.
void toQtLogTriple(QtMsgType *o_type, QString *o_category, QString *o_message) const
Convert to a Qt logging triple.
void addValidationCategory()
Adds validation as category.
CStatusMessage(const CLogCategoryList &categories, StatusSeverity severity, const char *message, bool validation=false)=delete
Deleted constructor, to prevent inefficient construction from byte string literal....
static const CIcon & convertToIcon(const CStatusMessage &statusMessage)
Representing icon.
StatusSeverity getSeverity() const
Message severity.
void setSeverity(StatusSeverity severity)
Severity.
QString getMessage() const
Message.
CStatusMessage(const CLogCategoryList &categories, StatusSeverity severity, const char16_t(&message)[N], bool validation=false)
Constructor, also a validation messsage can be directly created.
void addCategory(const CLogCategory &category)
Add category, avoids duplicates.
CStatusMessage(StatusSeverity severity, const char16_t(&message)[N])
Constructor.
ColumnIndex
Properties by index.
const CLogCategoryList & getCategories() const
Message categories.
CStatusMessage(StatusSeverity severity, const char *message)=delete
Deleted constructor, to prevent inefficient construction from byte string literal....
CIcons::IconIndex toIcon() const
Representing icon.
swift::misc::StatusSeverity StatusSeverity
Status severities.
void setCategories(const CLogCategoryList &categories)
Reset categories.
QString getHumanOrTechnicalCategoriesAsString() const
The human or technical categories.
CStatusMessage(const char *message)=delete
Deleted constructor, to prevent inefficient construction from byte string literal....
static constexpr auto SeverityDebug
Status severities.
~CStatusMessage()=default
Destructor.
static constexpr auto SeverityWarning
Status severities.
Special-purpose string class used by CMessageBase.
CStrongStringView(const char16_t(&string)[N])
Construct from a UTF-16 character array.
QStringView view() const
Return as a QStringView.
friend int compare(const CStrongStringView &a, const CStrongStringView &b)
Compare two strings.
void unmarshallFromDbus(const QDBusArgument &arg)
DBus marshalling.
CStrongStringView(const QString &string)
Construct from a QString.
void convertFromJson(const QJsonObject &json)
JSON conversion.
friend size_t qHash(const CStrongStringView &obj, uint seed=0)
Hash value.
CStrongStringView(QStringView view)
Construct from a QStringView. Explicit because it could be dangerous if used without care.
void marshallToDbus(QDBusArgument &arg) const
DBus marshalling.
bool isEmpty() const
String is empty.
QString convertToQString(bool i18n=false) const
Return a copy as a QString.
QJsonObject toJson() const
JSON conversion.
CStrongStringView & operator=(const CStrongStringView &other)
Copy assignment operator.
CStrongStringView(const CStrongStringView &other)
Copy constructor.
void marshalToDataStream(QDataStream &stream) const
QDataStream marshalling.
bool isOwning() const
Does it own its string data?
CStrongStringView()=default
Default constructor.
~CStrongStringView()=default
Destructor.
void unmarshalFromDataStream(QDataStream &stream)
QDataStream marshalling.
CStrongStringView(const char *)=delete
Deleted constructor.
IOrderable()=default
Constructor.
ITimestampBased()=default
Constructor.
CRTP class template which will generate marshalling operators for a derived class with its own marsha...
CRTP class template to generate non-member QDataStream streaming operators.
CRTP class template from which a derived class can inherit operator== implemented using its compare f...
CRTP class template which will generate marshalling operators for a derived class with its own marsha...
CRTP class template from which a derived class can inherit operator< implemented using its compare fu...
CRTP class template from which a derived class can inherit string streaming operations.
QString toQString(bool i18n=false) const
Free functions in swift::misc.
void registerMetadata()
Register all relevant metadata in Misc.
StatusSeverity
Status severities.
QJsonObject::iterator insert(QLatin1StringView key, const QJsonValue &value)
void push_back(QList< T >::parameter_type value)
int compare(QChar ch) const const
bool isEmpty() const const
Trait to detect properties of function parameter types.
Stringification traits class.
#define SWIFT_MISC_EXPORT
Export a class or function from the library.
#define SWIFT_DECLARE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template declaration of mixins for a CValueObject subclass to be placed near the top of the ...