6 #ifndef SWIFT_MISC_STATUSMESSAGE_H
7 #define SWIFT_MISC_STATUSMESSAGE_H
9 #include <QReadWriteLock>
81 if (other.
isOwning()) { m_view = m_string = other.m_string; }
84 m_view = other.m_view;
97 bool isOwning()
const {
return !m_string.isNull(); }
100 QStringView
view()
const {
return m_view; }
106 return isOwning() ? m_string : m_view.toString();
112 return a.m_view.compare(b.m_view);
143 json.insert(QStringLiteral(
"value"),
toQString());
146 void convertFromJson(
const QJsonObject &json) { *
this = json.value(QLatin1String(
"value")).toString(); }
157 template <
class Derived>
200 Derived &
debug() {
return log(SeverityDebug, QString()); }
204 Derived &
debug(
const char16_t (&format)[N])
206 return log(SeverityDebug, format);
210 Derived &
debug(
const QString &format) {
return log(SeverityDebug, format); }
214 Derived &
info(
const char16_t (&format)[N])
216 return log(SeverityInfo, format);
220 Derived &
info(
const QString &format) {
return log(SeverityInfo, format); }
226 return log(SeverityWarning, format);
230 Derived &
warning(
const QString &format) {
return log(SeverityWarning, format); }
234 Derived &
error(
const char16_t (&format)[N])
236 return log(SeverityError, format);
240 Derived &
error(
const QString &format) {
return log(SeverityError, format); }
247 return log(s, format);
254 return log(s, format);
262 return log(SeverityInfo, format);
269 return log(SeverityInfo, format);
277 return log(SeverityWarning, format);
284 return log(SeverityWarning, format);
292 return log(SeverityError, format);
299 return log(SeverityError, format);
305 Derived &
debug(
const char *) =
delete;
306 Derived &
info(
const char *) =
delete;
308 Derived &
error(
const char *) =
delete;
319 template <
class T, std::enable_if_t<TParameter<std::decay_t<T>>::passBy == ParameterPassBy::Value,
int> = 0>
329 template <
class T, std::enable_if_t<TParameter<std::decay_t<T>>::passBy == ParameterPassBy::ConstRef,
int> = 0>
344 Derived &arg(
const QString &value)
349 Derived &derived() {
return static_cast<Derived &
>(*this); }
399 constexpr
static auto SeverityDebug = swift::misc::SeverityDebug;
400 constexpr
static auto SeverityInfo = swift::misc::SeverityInfo;
401 constexpr
static auto SeverityWarning = swift::misc::SeverityWarning;
402 constexpr
static auto SeverityError = swift::misc::SeverityError;
408 IndexCategoriesAsString = CPropertyIndexRef::GlobalIndexCStatusMessage,
410 IndexSeverityAsString,
413 IndexMessageNoLineBreaks,
458 bool validation =
false)
459 :
CStatusMessage(categories, severity, QStringView(message), validation)
462 bool validation =
false);
471 bool validation =
false) =
delete;
476 CStatusMessage(QtMsgType type,
const QMessageLogContext &context,
const QString &message);
480 void toQtLogTriple(QtMsgType *o_type, QString *o_category, QString *o_message)
const;
486 QString getCategoriesAsString()
const;
500 return this->m_severity == SeverityInfo || this->m_severity == SeverityDebug;
509 return this->m_severity == SeverityWarning || this->m_severity == SeverityError;
513 bool isSuccess()
const;
516 bool isFailure()
const;
522 QString getMessageNoLineBreaks()
const;
525 void prependMessage(
const QString &msg);
528 void appendMessage(
const QString &msg);
535 return std::all_of(classCategories.
begin(), classCategories.
end(),
536 [
this](
const CLogCategory &cat) { return m_categories.contains(cat); });
540 void markAsHandledBy(
const QObject *
object)
const;
543 bool wasHandledBy(
const QObject *
object)
const;
567 const QString &getSeverityAsString()
const;
570 const CIcon &getSeverityAsIcon()
const;
576 static QString severitiesToString(
const QSet<StatusSeverity> &severities);
582 static const QStringList &allSeverityStrings();
594 QString convertToQString(
bool i18n =
false)
const;
597 QString toHtml(
bool withIcon,
bool withColors)
const;
613 const QString &prefix);
624 mutable QVector<quintptr> m_handledByObjects;
625 mutable QReadWriteLock m_lock;
640 template <
class Derived>
643 const QString &prefix)
647 convertFromJson(json);
657 template <
class Derived>
660 const QString &prefix)
664 convertFromJson(jsonString);
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.
Base class for CStatusMessage and CLogMessage.
CLogCategoryList m_categories
Private.
Derived & validationError(const char *)=delete
Deleted methods to avoid accidental implicit conversion from Latin-1 or UTF-8 string literals.
Derived & info(const QString &format)
Set the severity to info, providing a format string.
Derived & info(const char *)=delete
Deleted methods to avoid accidental implicit conversion from Latin-1 or UTF-8 string literals.
Derived & warning(const char16_t(&format)[N])
Set the severity to warning, providing a format string.
bool isEmpty() const
Message empty.
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 & operator<<(const T &v)
Streaming operators.
Derived & validation(StatusSeverity s, const char16_t(&format)[N])
Set the severity to s, providing a format string, and adding the validation category.
Derived & log(StatusSeverity s, const QString &m)
Set the severity and format string.
Derived & validationError(const char16_t(&format)[N])
Set the severity to error, providing a format string, and adding the validation category.
Derived & log(StatusSeverity s, const char16_t(&m)[N])
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()
Default constructor.
CStrongStringView m_message
Private.
Derived & validationWarning(const char16_t(&format)[N])
Set the severity to warning, providing a format string, and adding the validation category.
Derived & error(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 & validation(StatusSeverity s, const QString &format)
Set the severity to s, providing a format string, and adding the validation category.
Derived & error(const char16_t(&format)[N])
Set the severity to error, providing a format string.
QStringList m_args
Private.
Derived & operator<<(T v)
Streaming operators.
StatusSeverity m_severity
Private.
Derived & log(StatusSeverity, 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 & validationInfo(const char *)=delete
Deleted methods to avoid accidental implicit conversion from Latin-1 or UTF-8 string literals.
Derived & debug(const char16_t(&format)[N])
Set the severity to debug, providing a format string.
Derived & warning(const QString &format)
Set the severity to warning, providing a format string.
void addIfNotExisting(const CLogCategoryList &categories)
Add categories if not already existing.
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 & warning(const char *)=delete
Deleted methods to avoid accidental implicit conversion from Latin-1 or UTF-8 string literals.
Derived & validationError(const QString &format)
Set the severity to error, providing a format string, and adding the validation category.
CMessageBase(const CLogCategory &category)
Construct a message with some specific category.
Derived & validationInfo(const char16_t(&format)[N])
Set the severity to info, 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 & error(const QString &format)
Set the severity to error, providing a format string.
QString message() const
Private.
Derived & info(const char16_t(&format)[N])
Set the severity to info, providing a format string.
Derived & debug(const char *)=delete
Deleted methods to avoid accidental implicit conversion from Latin-1 or UTF-8 string literals.
Derived & debug(const QString &format)
Set the severity to debug, providing a format string.
Non-owning reference to a CPropertyIndex with a subset of its features.
bool contains(const T &object) const
Return true if there is an element equal to given object. Uses the most efficient implementation avai...
iterator begin()
Returns iterator at the beginning of the sequence.
void push_back(const T &value)
Appends an element at the end of the sequence.
int remove(const T &object)
Remove all elements equal to the given object, if it is contained.
bool isEmpty() const
Synonym for empty.
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.
void addCategories(const CLogCategoryList &categories)
Add categories, avoids duplicates.
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....
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.
CStatusMessage(StatusSeverity severity, const char *message)=delete
Deleted constructor, to prevent inefficient construction from byte string literal....
const CLogCategoryList & getCategories() const
Message categories.
CIcons::IconIndex toIcon() const
Representing icon.
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....
~CStatusMessage()=default
Destructor.
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.
CStrongStringView & operator=(const CStrongStringView &other)
Copy assignment operator.
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(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.
Mix of the most commonly used mixin classes.
Entity with order attribute (can be manually ordered in views)
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...
ColumnIndex
Base class enums.
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
Cast as QString.
Free functions in swift::misc.
void registerMetadata()
Register all relevant metadata in Misc.
StatusSeverity
Status severities.
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 ...