Skycoder42
7 years ago
15 changed files with 398 additions and 61 deletions
@ -0,0 +1,25 @@ |
|||
#include "ipresenter.h" |
|||
using namespace QtMvvm; |
|||
|
|||
PresenterException::PresenterException(const QByteArray &what) : |
|||
_what(what) |
|||
{} |
|||
|
|||
PresenterException::PresenterException(const PresenterException * const other) : |
|||
_what(other->_what) |
|||
{} |
|||
|
|||
const char *PresenterException::what() const noexcept |
|||
{ |
|||
return _what.constData(); |
|||
} |
|||
|
|||
void PresenterException::raise() const |
|||
{ |
|||
throw (*this); |
|||
} |
|||
|
|||
QException *PresenterException::clone() const |
|||
{ |
|||
return new PresenterException(this); |
|||
} |
@ -0,0 +1,187 @@ |
|||
#include "message.h" |
|||
#include "message_p.h" |
|||
using namespace QtMvvm; |
|||
|
|||
MessageConfig::MessageConfig(MessageType type) : |
|||
d(new MessageConfigPrivate(type)) |
|||
{ |
|||
resetPositiveAction(); |
|||
resetNegativeAction(); |
|||
resetNeutralAction(); |
|||
} |
|||
|
|||
MessageConfig::MessageConfig(const MessageConfig &other) : |
|||
d(other.d) |
|||
{} |
|||
|
|||
MessageConfig::~MessageConfig() {} |
|||
|
|||
MessageConfig &MessageConfig::operator=(const MessageConfig &other) |
|||
{ |
|||
d = other.d; |
|||
return (*this); |
|||
} |
|||
|
|||
MessageConfig::MessageType MessageConfig::type() const |
|||
{ |
|||
return d->type; |
|||
} |
|||
|
|||
QString MessageConfig::title() const |
|||
{ |
|||
return d->title; |
|||
} |
|||
|
|||
QString MessageConfig::text() const |
|||
{ |
|||
return d->text; |
|||
} |
|||
|
|||
QString MessageConfig::positiveAction() const |
|||
{ |
|||
return d->positiveAction; |
|||
} |
|||
|
|||
QString MessageConfig::negativeAction() const |
|||
{ |
|||
return d->negativeAction; |
|||
} |
|||
|
|||
QString MessageConfig::neutralAction() const |
|||
{ |
|||
return d->neutralAction; |
|||
} |
|||
|
|||
QByteArray MessageConfig::inputType() const |
|||
{ |
|||
return d->inputType; |
|||
} |
|||
|
|||
QVariant MessageConfig::defaultValue() const |
|||
{ |
|||
return d->defaultValue; |
|||
} |
|||
|
|||
QVariantMap MessageConfig::editProperties() const |
|||
{ |
|||
return d->editProperties; |
|||
} |
|||
|
|||
void MessageConfig::setType(MessageConfig::MessageType type) |
|||
{ |
|||
d->type = type; |
|||
resetPositiveAction(); |
|||
resetNegativeAction(); |
|||
resetNeutralAction(); |
|||
} |
|||
|
|||
void MessageConfig::setTitle(QString title) |
|||
{ |
|||
d->title = title; |
|||
} |
|||
|
|||
void MessageConfig::setText(QString text) |
|||
{ |
|||
d->text = text; |
|||
} |
|||
|
|||
void MessageConfig::setPositiveAction(QString positiveAction) |
|||
{ |
|||
d->positiveAction = positiveAction; |
|||
} |
|||
|
|||
void MessageConfig::setNegativeAction(QString negativeAction) |
|||
{ |
|||
d->negativeAction = negativeAction; |
|||
} |
|||
|
|||
void MessageConfig::setNeutralAction(QString neutralAction) |
|||
{ |
|||
d->neutralAction = neutralAction; |
|||
} |
|||
|
|||
void MessageConfig::setInputType(QByteArray inputType) |
|||
{ |
|||
d->inputType = inputType; |
|||
} |
|||
|
|||
void MessageConfig::setDefaultValue(QVariant defaultValue) |
|||
{ |
|||
d->defaultValue = defaultValue; |
|||
} |
|||
|
|||
void MessageConfig::setEditProperties(QVariantMap editProperties) |
|||
{ |
|||
d->editProperties = editProperties; |
|||
} |
|||
|
|||
void MessageConfig::resetPositiveAction() |
|||
{ |
|||
switch (d->type) { |
|||
case Information: |
|||
case Warning: |
|||
case Critical: |
|||
case Input: |
|||
d->positiveAction = tr("Ok"); |
|||
break; |
|||
case Question: |
|||
d->positiveAction = tr("Yes"); |
|||
break; |
|||
default: |
|||
Q_UNREACHABLE(); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
void MessageConfig::resetNegativeAction() |
|||
{ |
|||
switch (d->type) { |
|||
case Input: |
|||
d->negativeAction = tr("Cancel"); |
|||
break; |
|||
case Question: |
|||
d->negativeAction = tr("No"); |
|||
break; |
|||
case Information: |
|||
case Warning: |
|||
case Critical: |
|||
d->negativeAction.clear(); |
|||
break; |
|||
default: |
|||
Q_UNREACHABLE(); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
void MessageConfig::resetNeutralAction() |
|||
{ |
|||
d->neutralAction.clear(); |
|||
} |
|||
|
|||
// ------------- Private Implementation -------------
|
|||
|
|||
QtMvvm::MessageConfigPrivate::MessageConfigPrivate(MessageConfig::MessageType type) : |
|||
QSharedData(), |
|||
type(type), |
|||
title(), |
|||
text(), |
|||
positiveAction(), |
|||
negativeAction(), |
|||
neutralAction(), |
|||
inputType(), |
|||
defaultValue(), |
|||
editProperties() |
|||
{} |
|||
|
|||
QtMvvm::MessageConfigPrivate::MessageConfigPrivate(const QtMvvm::MessageConfigPrivate &other) : |
|||
QSharedData(other), |
|||
type(other.type), |
|||
title(other.title), |
|||
text(other.text), |
|||
positiveAction(other.positiveAction), |
|||
negativeAction(other.negativeAction), |
|||
neutralAction(other.neutralAction), |
|||
inputType(other.inputType), |
|||
defaultValue(other.defaultValue), |
|||
editProperties(other.editProperties) |
|||
{} |
@ -0,0 +1,78 @@ |
|||
#ifndef QTMVVM_MESSAGE_H |
|||
#define QTMVVM_MESSAGE_H |
|||
|
|||
#include <QtCore/qcoreapplication.h> |
|||
#include <QtCore/qshareddata.h> |
|||
|
|||
#include "QtMvvmCore/qtmvvmcore_global.h" |
|||
|
|||
namespace QtMvvm { |
|||
|
|||
class MessageConfigPrivate; |
|||
class Q_MVVMCORE_EXPORT MessageConfig |
|||
{ |
|||
Q_GADGET |
|||
Q_DECLARE_TR_FUNCTIONS(MessageConfig) |
|||
|
|||
Q_PROPERTY(MessageType type READ type WRITE setType) |
|||
Q_PROPERTY(QString title READ title WRITE setTitle) |
|||
Q_PROPERTY(QString text READ text WRITE setText) |
|||
Q_PROPERTY(QString positiveAction READ positiveAction WRITE setPositiveAction RESET resetPositiveAction) |
|||
Q_PROPERTY(QString negativeAction READ negativeAction WRITE setNegativeAction RESET resetNegativeAction) |
|||
Q_PROPERTY(QString neutralAction READ neutralAction WRITE setNeutralAction RESET resetNeutralAction) |
|||
Q_PROPERTY(QByteArray inputType READ inputType WRITE setInputType) |
|||
Q_PROPERTY(QVariant defaultValue READ defaultValue WRITE setDefaultValue) |
|||
Q_PROPERTY(QVariantMap editProperties READ editProperties WRITE setEditProperties) |
|||
|
|||
public: |
|||
enum MessageType { |
|||
Information, |
|||
Question, |
|||
Warning, |
|||
Critical, |
|||
Input |
|||
}; |
|||
Q_ENUM(MessageType) |
|||
|
|||
MessageConfig(MessageType type = Information); |
|||
MessageConfig(const MessageConfig &other); |
|||
~MessageConfig(); |
|||
|
|||
MessageConfig &operator=(const MessageConfig &other); |
|||
|
|||
MessageType type() const; |
|||
QString title() const; |
|||
QString text() const; |
|||
QString positiveAction() const; |
|||
QString negativeAction() const; |
|||
QString neutralAction() const; |
|||
QByteArray inputType() const; |
|||
QVariant defaultValue() const; |
|||
QVariantMap editProperties() const; |
|||
|
|||
void setType(MessageType type); |
|||
void setTitle(QString title); |
|||
void setText(QString text); |
|||
void setPositiveAction(QString positiveAction); |
|||
void setNegativeAction(QString negativeAction); |
|||
void setNeutralAction(QString neutralAction); |
|||
void setInputType(QByteArray inputType); |
|||
void setDefaultValue(QVariant defaultValue); |
|||
void setEditProperties(QVariantMap editProperties); |
|||
|
|||
void resetPositiveAction(); |
|||
void resetNegativeAction(); |
|||
void resetNeutralAction(); |
|||
|
|||
private: |
|||
QSharedDataPointer<MessageConfigPrivate> d; |
|||
}; |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
Q_DECLARE_METATYPE(QtMvvm::MessageConfig) |
|||
Q_DECLARE_TYPEINFO(QtMvvm::MessageConfig, Q_MOVABLE_TYPE); |
|||
|
|||
#endif // QTMVVM_MESSAGE_H
|
@ -0,0 +1,28 @@ |
|||
#ifndef QTMVVM_MESSAGE_P_H |
|||
#define QTMVVM_MESSAGE_P_H |
|||
|
|||
#include "qtmvvmcore_global.h" |
|||
#include "message.h" |
|||
|
|||
namespace QtMvvm { |
|||
|
|||
class MessageConfigPrivate : public QSharedData |
|||
{ |
|||
public: |
|||
MessageConfigPrivate(MessageConfig::MessageType type); |
|||
MessageConfigPrivate(const MessageConfigPrivate &other); |
|||
|
|||
MessageConfig::MessageType type; |
|||
QString title; |
|||
QString text; |
|||
QString positiveAction; |
|||
QString negativeAction; |
|||
QString neutralAction; |
|||
QByteArray inputType; |
|||
QVariant defaultValue; |
|||
QVariantMap editProperties; |
|||
}; |
|||
|
|||
} |
|||
|
|||
#endif // QTMVVM_MESSAGE_P_H
|
Loading…
Reference in new issue