From b3ff1cc57708fd1fe1bcfaa8389831fdd6ccbdad Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 12 Apr 2023 11:44:22 +0300 Subject: [PATCH] There was fixed bug --- notificationdata.cpp | 25 +++++++++++++++++++++++-- notificationdata.h | 5 +++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/notificationdata.cpp b/notificationdata.cpp index c01a286..5f6e0f6 100644 --- a/notificationdata.cpp +++ b/notificationdata.cpp @@ -11,11 +11,13 @@ namespace QmlNotificationService { NotificationData::NotificationData(const QString &title, const QString &text, const QString &img, int type) { - + defImgI = "qrc:/icons/info"; + defImgW = "qrc:/icons/warning"; + defImgE = "qrc:/icons/error"; _text = text; _title = title; - _img = img; _type = type; + _img = getDefaultImage(img, type); } QString NotificationData::text() const { @@ -41,6 +43,25 @@ bool NotificationData::operator !=(const NotificationData &righ) { return !operator==(righ); } +QString NotificationData::getDefaultImage(const QString &img, const int code) +{ + if(img != "") + return img; + + const auto notificationType = static_cast(code); + + switch (notificationType) { + case NotificationData::Type::Normal: + return defImgI; + case NotificationData::Type::Warning: + return defImgW; + case NotificationData::Type::Error: + return defImgE; + default: + return defImgI; + } +} + int NotificationData::type() const { return _type; } diff --git a/notificationdata.h b/notificationdata.h index 047fd11..9f9d930 100644 --- a/notificationdata.h +++ b/notificationdata.h @@ -71,10 +71,15 @@ public: bool operator !=(const NotificationData &righ); private: + QString getDefaultImage(const QString &img, const int code); + QString _text; QString _img; QString _title; int _type; + QString defImgI; + QString defImgW; + QString defImgE; }; }