7 #include <QStringBuilder>
8 #include <QThreadStorage>
22 QThreadStorage<QString> t_tempBuffer;
24 QString arg(QStringView format,
const QStringList &args)
26 if (format.isEmpty()) {
return args.join(u
' '); }
28 QString &temp = t_tempBuffer.localData();
32 quint64 unusedArgs = (1ULL << std::min(qsizetype(63), args.size())) - 1;
33 for (
auto it = format.begin();;)
35 const auto pc = std::find(it, format.end(), u
'%');
36 temp.append(&*it, std::distance(it, pc));
37 if ((it = pc) == format.end()) {
break; }
38 if (++it == format.end())
52 int n = it->unicode() - u
'0';
54 if (++it != format.end() &&
is09(*it))
56 n = n * 10 + it->unicode() - u
'0';
60 if (n > 0 && n <= args.size())
63 unusedArgs &= ~(1ULL << (n - 1));
65 else { temp += u
'%' % QString::number(n); }
67 else { temp += u
'%'; }
69 if (unusedArgs) { temp += QStringLiteral(
" [SOME MESSAGE ARGUMENT(S) UNUSED]"); }
71 QString result = temp;
98 QReadLocker lock(&other.m_lock);
99 m_handledByObjects = other.m_handledByObjects;
104 if (
this == &other) {
return *
this; }
111 QReadLocker readLock(&other.m_lock);
112 const auto handledBy = other.m_handledByObjects;
115 QWriteLocker writeLock(&m_lock);
116 m_handledByObjects = handledBy;
191 if (this->
getSeverity() <= severity) {
return false; }
214 if (msg.isEmpty()) {
return; }
220 if (msg.isEmpty()) {
return; }
226 QWriteLocker lock(&m_lock);
227 m_handledByObjects.push_back(quintptr(
object));
232 QReadLocker lock(&m_lock);
233 return m_handledByObjects.contains(quintptr(
object));
266 static const QString d;
267 static const QString i(
":/pastel/icons/pastel/16/infomation.png");
268 static const QString w(
":/pastel/icons/pastel/16/bullet-error.png");
269 static const QString e(
":/pastel/icons/pastel/16/close-red.png");
283 const QString msgText(json.value(
"text").toString());
284 const QString severityText(json.value(
"severity").toString());
285 QString typeText(json.value(
"type").toString());
288 typeText = u
"swift.db.type." % typeText.toLower().remove(
' ');
294 const QString &prefix)
302 qRegisterMetaType<CStatusMessage::StatusSeverity>();
303 qDBusRegisterMetaType<CStatusMessage::StatusSeverity>();
309 QString severityString(severity.trimmed().toLower());
322 QChar s = severityString.at(0);
337 static const QString d(
"debug");
342 static const QString i(
"info");
347 static const QString w(
"warning");
352 static const QString e(
"error");
357 static const QString x(
"unknown severity");
358 qFatal(
"Unknown severity");
366 if (severities.isEmpty()) {
return {}; }
367 auto minmax = std::minmax_element(severities.begin(), severities.end());
368 auto min = *minmax.first;
369 auto max = *minmax.second;
372 static const QString all(
"all severities");
377 auto list = severities.values();
378 std::sort(list.begin(), list.end());
380 std::transform(list.cbegin(), list.cend(), std::back_inserter(ret),
severityToString);
381 return ret.join(
"|");
397 if (index.
isMyself()) {
return QVariant::fromValue(*
this); }
403 case IndexMessage:
return QVariant::fromValue(this->
getMessage());
404 case IndexSeverity:
return QVariant::fromValue(
m_severity);
408 case IndexMessageAsHtml:
return QVariant::fromValue(this->
toHtml(
false,
true));
454 case IndexMessageAsHtml:
456 case IndexSeverityAsString:
457 case IndexSeverityAsIcon:
459 case IndexCategoriesAsString:
472 if (!r.isEmpty()) { img = QStringLiteral(
"<img src=\"%1\"> ").arg(r); }
Value object for icons. An icon is stored in the global icon repository and identified by its index....
static const CIcon & iconByIndex(CIcons::IconIndex index)
Icon for given index.
Thrown when a convertFromJson method encounters an unrecoverable error in JSON data.
QString toString(const QString &prefix) const
As string info.
static const QString & swiftDbWebservice()
Webservice with swift DB.
A log category is an arbitrary string tag which can be attached to log messages.
A sequence of log categories.
static CLogCategoryList fromQString(const QString &string)
Convert a string, such as that returned by toQString(), into a CLogCategoryList.
QString toQString(bool i18n=false) const
Cast as QString.
Base class for CStatusMessage and CLogMessage.
CLogCategoryList m_categories
Private.
CStatusMessage & validation(StatusSeverity s, const char16_t(&format)[N])
Set the severity to s, providing a format string, and adding the validation category.
CStrongStringView m_message
Private.
QStringList m_args
Private.
StatusSeverity m_severity
Private.
QString message() const
Private.
Non-owning reference to a CPropertyIndex with a subset of its features.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
Streamable status message, e.g.
void markAsHandledBy(const QObject *object) const
Mark the message as having been handled by the given object.
QString getCategoriesAsString() const
Message categories as string.
static CStatusMessage fromJsonException(const CJsonException &ex, const CLogCategoryList &categories, const QString &prefix)
Object from JSON exception message.
bool isSuccess() const
Operation considered successful.
static const QString & convertToIconResource(CStatusMessage::StatusSeverity severity)
Representing icon.
const QString & getSeverityAsString() const
Severity as string.
constexpr static auto SeverityDebug
Status severities.
const CIcon & getSeverityAsIcon() const
Severity as icon.
void appendMessage(const QString &msg)
Append message.
bool isSeverityHigherOrEqual(CStatusMessage::StatusSeverity severity) const
Is this message's severity higher or equal.
constexpr static auto SeverityError
Status severities.
void toQtLogTriple(QtMsgType *o_type, QString *o_category, QString *o_message) const
Convert to a Qt logging triple.
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
void addValidationCategory()
Adds validation as category.
static void registerMetadata()
Register metadata.
static const QString & severityToString(StatusSeverity severity)
Severity as string.
static const CIcon & convertToIcon(const CStatusMessage &statusMessage)
Representing icon.
static StatusSeverity stringToSeverity(const QString &severity)
Severity as string, if not possible to convert.
bool clampSeverity(StatusSeverity severity)
Clip/reduce severity if higher (more critical)
StatusSeverity getSeverity() const
Message severity.
void setSeverity(StatusSeverity severity)
Severity.
QString getMessage() const
Message.
CStatusMessage()
Constructor.
CStatusMessage & operator=(const CStatusMessage &other)
Copy assignment (because of mutex)
static const QStringList & allSeverityStrings()
Severities as strings.
QString convertToQString(bool i18n=false) const
Cast as QString.
int comparePropertyByIndex(CPropertyIndexRef index, const CStatusMessage &compareValue) const
Compare for index.
void prependMessage(const QString &msg)
Prepend message.
bool wasHandledBy(const QObject *object) const
Returns true if the message was marked as having been handled by the given object.
constexpr static auto SeverityInfo
Status severities.
constexpr static auto SeverityWarning
Status severities.
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
bool isFailure() const
Operation considered unsuccessful.
static CStatusMessage fromDatabaseJson(const QJsonObject &json)
Object from JSON.
QString toHtml(bool withIcon, bool withColors) const
To HTML.
static QString severitiesToString(const QSet< StatusSeverity > &severities)
Severity set as string.
QString getMessageNoLineBreaks() const
Message without line breaks.
Special-purpose string class used by CMessageBase.
QStringView view() const
Return as a QStringView.
Mix of the most commonly used mixin classes.
Entity with order attribute (can be manually ordered in views)
static bool canHandleIndex(CPropertyIndexRef index)
Can given index be handled.
int comparePropertyByIndex(CPropertyIndexRef index, const IOrderable &compareValue) const
Compare for index.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
int comparePropertyByIndex(CPropertyIndexRef index, const ITimestampBased &compareValue) const
Compare for index.
QString getFormattedUtcTimestampYmdhms() const
As yyyy MM dd HH mm ss.
static bool canHandleIndex(CPropertyIndexRef index)
Can given index be handled.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
ColumnIndex
Base class enums.
int comparePropertyByIndex(CPropertyIndexRef index, const Derived &compareValue) const
Compare for index.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Free functions in swift::misc.
bool is09(const QChar &c)
Is 0-9 char, isDigit allows a bunch of more characters.
bool containsLineBreakOrTab(const QString &s)
Contains a line break or tab.
StatusSeverity
Status severities.
QString removeLineBreakAndTab(const QString &s)
Remove line breaks and tabs.
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
#define SWIFT_VERIFY(COND)
A weaker kind of assert.