4
0
mirror of https://github.com/QuasarApp/SimpleQmlNotify.git synced 2025-05-08 03:09:34 +00:00

There were fixed issues

This commit is contained in:
Alex 2023-04-10 14:59:27 +03:00
parent 43ea5822c7
commit 592f8463f1
6 changed files with 29 additions and 32 deletions

@ -5,7 +5,7 @@ import QtQuick.Controls.Material 2.15
Popup {
id: root
readonly property var historyModel: historyNotificationsModel
readonly property var historyModel: notificationService.history
ToolBar {
id: toolbar
@ -161,11 +161,4 @@ Popup {
}
}
}
Connections {
target: historyModel
function onDataInserted() {
console.log(Object.keys(historyModel))
}
}
}

@ -15,7 +15,7 @@ QVariant HistoryNotificationsModel::data(const QModelIndex &index, int role) con
switch (role) {
case Icon:
return notificationsList.at(index.row()).img();
return notificationsList.at(index.row()).img();
case Title:
return notificationsList.at(index.row()).title();
case Message:
@ -38,10 +38,15 @@ QHash<int, QByteArray> HistoryNotificationsModel::roleNames() const {
}
void HistoryNotificationsModel::setHistory(const QmlNotificationService::NotificationData &notificationData) {
beginResetModel();
notificationsList.push_back(notificationData);
endResetModel();
void HistoryNotificationsModel::addHistoryObject(const QmlNotificationService::NotificationData &notificationData) {
beginInsertRows({}, rowCount({}), rowCount({}));
notificationsList.append(notificationData);
endInsertRows();
}
void HistoryNotificationsModel::setHistory(const QList<QmlNotificationService::NotificationData> &historyList)
{
notificationsList = std::move(historyList);
}
void HistoryNotificationsModel::clearAllHistory() {
@ -51,8 +56,11 @@ void HistoryNotificationsModel::clearAllHistory() {
}
void HistoryNotificationsModel::removeNotificationItemAtIndex(const int elementIndex) {
beginResetModel();
beginRemoveRows({}, elementIndex, elementIndex);
notificationsList.removeAt(elementIndex);
endResetModel();
endRemoveRows();
}

@ -21,15 +21,11 @@ public:
int rowCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
QHash<int, QByteArray> roleNames() const override;
void setHistory(const QmlNotificationService::NotificationData &notificationData);
void addHistoryObject(const QmlNotificationService::NotificationData &notificationData);
void setHistory(const QList<QmlNotificationService::NotificationData> &historyList);
Q_INVOKABLE void clearAllHistory();
Q_INVOKABLE void removeNotificationItemAtIndex(const int index);
signals:
void dataInserted();
private:
QList<QmlNotificationService::NotificationData> notificationsList;
};

@ -7,12 +7,14 @@
#include "notificationservice.h"
#include <QSharedPointer>
namespace QmlNotificationService {
NotificationService::NotificationService(QObject * ptr): QObject (ptr) {
qRegisterMetaType<NotificationData>("NotificationData");
qRegisterMetaType<QList<NotificationData>> ("QList<NotificationData>");
qRegisterMetaType<QSharedPointer<HistoryNotificationsModel>>("QSharedPointer<HistoryNotificationsModel>");
setNotify("Test", "Test");
}
NotificationData NotificationService::notify() const {
@ -25,7 +27,7 @@ NotificationData NotificationService::question() const {
void NotificationService::setNotify(const NotificationData& notify) {
if (_notify != notify) {
_history.setHistory(notify);
_history.addHistoryObject(notify);
}
_notify = notify;
@ -103,8 +105,8 @@ NotificationService *NotificationService::getService() {
return service;
}
//const QList<NotificationData> &NotificationService::history() const {
// return _history;
//QObject *NotificationService::history() const{
// return _history.data();
//}
}

@ -6,6 +6,7 @@
#include <QHash>
#include <QObject>
#include <QSharedPointer>
namespace QmlNotificationService {
@ -24,7 +25,7 @@ class NOTIFYSERVICESHARED_EXPORT NotificationService: public QObject
Q_PROPERTY(NotificationData notify READ notify NOTIFY notifyChanged)
Q_PROPERTY(NotificationData question READ question NOTIFY questionChanged)
//Q_PROPERTY(HistoryNotificationModel history READ history NOTIFY notifyChanged)
// Q_PROPERTY(QObject* history READ history NOTIFY notifyChanged)
public:
/**
@ -115,10 +116,10 @@ public:
static NotificationService* getService();
/**
* @brief history - This method used for return notify list.
* @return list of all notify.
* @brief history - This method used for return notify history model.
* @return history model of all notify.
*/
// const HistoryNotificationModel & history() const;
// QObject* history() const;
signals:
/**

@ -7,7 +7,6 @@
#include "notificationservice.h"
#include "qmlnotifyservice.h"
#include "historynotificationsmodel.h"
#include <QQmlApplicationEngine>
#include <QQmlContext>
@ -23,12 +22,10 @@ bool init(QQmlApplicationEngine *engine) {
return false;
initSNotufyResources();
QPointer<HistoryNotificationsModel> historyModel = new HistoryNotificationsModel();
engine->addImportPath(":/");
root->setContextProperty("notificationService", NotificationService::getService());
root->setContextProperty("historyNotificationsModel", historyModel);
return true;
}
}