Made a start with the notification system. However need to figure out
how i want to handle multithreading and screen updates.
This commit is contained in:
parent
5494e5076b
commit
7f09d5fe07
7 changed files with 216 additions and 0 deletions
9
pglab/NotificationListWidget.cpp
Normal file
9
pglab/NotificationListWidget.cpp
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
#include "NotificationListWidget.h"
|
||||||
|
#include <QListView>
|
||||||
|
|
||||||
|
|
||||||
|
NotificationListWidget::NotificationListWidget()
|
||||||
|
: m_notificationList(new QListView(this))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
22
pglab/NotificationListWidget.h
Normal file
22
pglab/NotificationListWidget.h
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef NOTIFICATIONLISTWIDGET_H
|
||||||
|
#define NOTIFICATIONLISTWIDGET_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
class QListView;
|
||||||
|
class QTextEdit;
|
||||||
|
class Notification;
|
||||||
|
class NotificationListModel;
|
||||||
|
|
||||||
|
class NotificationListWidget: QWidget {
|
||||||
|
public:
|
||||||
|
NotificationListWidget();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QListView *m_notificationList = nullptr;
|
||||||
|
QTextEdit *m_detailMessage;
|
||||||
|
NotificationListModel *m_notificationListModel = nullptr;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NOTIFICATIONLISTWIDGET_H
|
||||||
25
pglab/NotificationModel.cpp
Normal file
25
pglab/NotificationModel.cpp
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
#include "NotificationModel.h"
|
||||||
|
#include "NotificationService.h"
|
||||||
|
|
||||||
|
NotificationModel::NotificationModel()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int NotificationModel::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
return m_notifications->count();
|
||||||
|
}
|
||||||
|
|
||||||
|
int NotificationModel::columnCount(const QModelIndex &) const
|
||||||
|
{
|
||||||
|
return static_cast<int>(Col::Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant NotificationModel::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant NotificationModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
|
{
|
||||||
|
}
|
||||||
31
pglab/NotificationModel.h
Normal file
31
pglab/NotificationModel.h
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
#ifndef NOTIFICATIONMODEL_H
|
||||||
|
#define NOTIFICATIONMODEL_H
|
||||||
|
|
||||||
|
#include <QAbstractTableModel>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
class NotificationService;
|
||||||
|
|
||||||
|
class NotificationModel: public QAbstractTableModel {
|
||||||
|
public:
|
||||||
|
enum class Col {
|
||||||
|
Severity,
|
||||||
|
ShortMessage,
|
||||||
|
DetailMessage,
|
||||||
|
|
||||||
|
Count // SHOULD BE LAST
|
||||||
|
};
|
||||||
|
|
||||||
|
NotificationModel();
|
||||||
|
|
||||||
|
virtual int rowCount(const QModelIndex &parent = {}) const override;
|
||||||
|
virtual int columnCount(const QModelIndex &parent = {}) const override;
|
||||||
|
|
||||||
|
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<NotificationService> m_notifications;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NOTIFICATIONMODEL_H
|
||||||
59
pglab/NotificationService.cpp
Normal file
59
pglab/NotificationService.cpp
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
#include "NotificationService.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
class registerMetaTypes {
|
||||||
|
public:
|
||||||
|
registerMetaTypes()
|
||||||
|
{
|
||||||
|
qRegisterMetaType<NotificationSeverity>();
|
||||||
|
qRegisterMetaType<Notification>();
|
||||||
|
}
|
||||||
|
} registerMetaTypes_instance;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<NotificationService> NotificationService::s_instance;
|
||||||
|
|
||||||
|
std::shared_ptr<NotificationService> NotificationService::instance()
|
||||||
|
{
|
||||||
|
if (!s_instance) {
|
||||||
|
s_instance = std::make_shared<NotificationService>();
|
||||||
|
}
|
||||||
|
return s_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
NotificationService::NotificationService()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void NotificationService::addInformational(const QString &msg, const QString &detail)
|
||||||
|
{
|
||||||
|
add(NotificationSeverity::Informational, msg, detail);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NotificationService::addWarning(const QString &msg, const QString &detail)
|
||||||
|
{
|
||||||
|
add(NotificationSeverity::Warning, msg, detail);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NotificationService::addError(const QString &msg, const QString &detail)
|
||||||
|
{
|
||||||
|
add(NotificationSeverity::Error, msg, detail);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NotificationService::add(NotificationSeverity severity, const QString &msg, const QString &detail)
|
||||||
|
{
|
||||||
|
m_notifications.push_back({ severity, msg, detail });
|
||||||
|
}
|
||||||
|
|
||||||
|
int NotificationService::count() const
|
||||||
|
{
|
||||||
|
return m_notifications.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
const Notification& NotificationService::notification(int index)
|
||||||
|
{
|
||||||
|
return m_notifications.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
64
pglab/NotificationService.h
Normal file
64
pglab/NotificationService.h
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
#ifndef NOTIFICATIONSERVICE_H
|
||||||
|
#define NOTIFICATIONSERVICE_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
#include <QVector>
|
||||||
|
#include <memory>
|
||||||
|
#include <shared_mutex>
|
||||||
|
|
||||||
|
enum NotificationSeverity {
|
||||||
|
Informational, ///< Use for notifications of succesful completion and other things the user likely does not need to be bothered with
|
||||||
|
Warning, ///<
|
||||||
|
Error, ///< Use for failures like not being able to save the users data
|
||||||
|
Critical ///< Don't think you should ever need this in a correct program....
|
||||||
|
};
|
||||||
|
|
||||||
|
class Notification: public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
Notification(int64_t id, NotificationSeverity severity, const QString &msg, const QString &detail = {});
|
||||||
|
|
||||||
|
int64_t id() const { return m_id; }
|
||||||
|
NotificationSeverity severity() const { return m_severity; }
|
||||||
|
QString shortMessage() const { return m_shortMessage; }
|
||||||
|
QString detailMessage() const { return m_detailMessage; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
int64_t m_id;
|
||||||
|
NotificationSeverity m_severity;
|
||||||
|
QString m_shortMessage;
|
||||||
|
QString m_detailMessage;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class NotificationService {
|
||||||
|
public:
|
||||||
|
static std::shared_ptr<NotificationService> instance();
|
||||||
|
|
||||||
|
NotificationService();
|
||||||
|
|
||||||
|
void addInformational(const QString &msg, const QString &detail = {});
|
||||||
|
void addWarning(const QString &msg, const QString &detail = {});
|
||||||
|
void addError(const QString &msg, const QString &detail = {});
|
||||||
|
void add(NotificationSeverity severity, const QString &msg, const QString &detail = {});
|
||||||
|
|
||||||
|
/// Returns the number of notifications
|
||||||
|
int count() const;
|
||||||
|
const Notification& notification(int index);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void onNewNotification(const Notification ¬ification);
|
||||||
|
private:
|
||||||
|
static std::shared_ptr<NotificationService> s_instance;
|
||||||
|
|
||||||
|
using NotificationContainer = QVector<Notification>;
|
||||||
|
|
||||||
|
std::shared_mutex m_nofiticationsMutex;
|
||||||
|
NotificationContainer m_notifications;
|
||||||
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(NotificationSeverity)
|
||||||
|
Q_DECLARE_METATYPE(Notification)
|
||||||
|
|
||||||
|
#endif // NOTIFICATIONSERVICE_H
|
||||||
|
|
@ -21,6 +21,9 @@ DEFINES += _WIN32_WINNT=0x0501
|
||||||
win32:RC_ICONS += pglab.ico
|
win32:RC_ICONS += pglab.ico
|
||||||
|
|
||||||
SOURCES += main.cpp\
|
SOURCES += main.cpp\
|
||||||
|
NotificationListWidget.cpp \
|
||||||
|
NotificationModel.cpp \
|
||||||
|
NotificationService.cpp \
|
||||||
QueryResultModel.cpp \
|
QueryResultModel.cpp \
|
||||||
QueryExplainModel.cpp \
|
QueryExplainModel.cpp \
|
||||||
CreateDatabaseDialog.cpp \
|
CreateDatabaseDialog.cpp \
|
||||||
|
|
@ -93,6 +96,9 @@ PropertyProxyModel.cpp \
|
||||||
widgets/CatalogSequencesPage.cpp
|
widgets/CatalogSequencesPage.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
NotificationListWidget.h \
|
||||||
|
NotificationModel.h \
|
||||||
|
NotificationService.h \
|
||||||
QueryResultModel.h \
|
QueryResultModel.h \
|
||||||
QueryExplainModel.h \
|
QueryExplainModel.h \
|
||||||
CreateDatabaseDialog.h \
|
CreateDatabaseDialog.h \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue