Add extra optional title argument to Error constructor

This commit is contained in:
Bart De Vries 2021-07-14 20:21:55 +02:00
parent 35cfb14e1f
commit a5b021cffd
2 changed files with 22 additions and 10 deletions

View File

@ -14,7 +14,7 @@
#include "error.h" #include "error.h"
#include "feed.h" #include "feed.h"
Error::Error(const Type type, const QString url, const QString id, const int code, const QString message, const QDateTime date) Error::Error(const Type type, const QString url, const QString id, const int code, const QString message, const QDateTime date, const QString title)
: QObject(nullptr) : QObject(nullptr)
{ {
this->type = type; this->type = type;
@ -23,11 +23,13 @@ Error::Error(const Type type, const QString url, const QString id, const int cod
this->code = code; this->code = code;
this->message = message; this->message = message;
this->date = date; this->date = date;
}; this->m_title = title;
}
QString Error::title() const QString Error::title() const
{ {
QString title; QString title = m_title;
if (title.isEmpty()) {
if (!id.isEmpty()) { if (!id.isEmpty()) {
if (DataManager::instance().getEntry(id)) if (DataManager::instance().getEntry(id))
title = DataManager::instance().getEntry(id)->title(); title = DataManager::instance().getEntry(id)->title();
@ -35,6 +37,7 @@ QString Error::title() const
if (DataManager::instance().getFeed(url)) if (DataManager::instance().getFeed(url))
title = DataManager::instance().getFeed(url)->name(); title = DataManager::instance().getFeed(url)->name();
} }
}
return title; return title;
} }

View File

@ -35,7 +35,13 @@ public:
Q_PROPERTY(QString title READ title CONSTANT) Q_PROPERTY(QString title READ title CONSTANT)
Q_PROPERTY(QString description READ description CONSTANT) Q_PROPERTY(QString description READ description CONSTANT)
Error(Type type, const QString url, const QString id, const int code, const QString message, const QDateTime date); Error(Type type,
const QString url,
const QString id,
const int code,
const QString message,
const QDateTime date,
const QString title = QStringLiteral(""));
QString title() const; QString title() const;
QString description() const; QString description() const;
@ -46,4 +52,7 @@ public:
int code; int code;
QString message; QString message;
QDateTime date; QDateTime date;
private:
QString m_title;
}; };