Skip to content

Commit

Permalink
Progress #19: Add sponsorship properties to purchase request wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielhourt committed Jan 20, 2016
1 parent c868763 commit 0185628
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 10 deletions.
40 changes: 31 additions & 9 deletions VotingApp/wrappers/PurchaseContestRequest.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#include "PurchaseContestRequest.hpp"
#include "Converters.hpp"

#define _CHECK_NOT_SAME(property) \
if (property == this->property()) \
return;

// Macro to generate getter and setter for text properties
#define TEXT_GETTER_SETTER(property, upperProperty, requestField) \
QString PurchaseContestRequestWrapper::property() const { \
return convertText(request.asReader().getRequest().get ## requestField ()); \
} \
void PurchaseContestRequestWrapper::set ## upperProperty(QString property) { \
if (property == this->property()) \
return; \
_CHECK_NOT_SAME(property) \
convertText(request.getRequest().get ## requestField (), property); \
emit property ## Changed(property); \
}
Expand All @@ -19,22 +22,36 @@
return static_cast<upperProperty::Type>(request.asReader().getRequest().get ## upperProperty ()); \
} \
void PurchaseContestRequestWrapper::set ## upperProperty(upperProperty::Type property) { \
if (property == this->property()) \
return; \
_CHECK_NOT_SAME(property) \
request.getRequest().set ## upperProperty (static_cast<::ContestCreator::upperProperty ## s>(property)); \
emit property ## Changed(property); \
}

#define _SIMPLE_GETTER_IMPL(requestField) \
return request.asReader().getRequest().get ## requestField();
#define _SIMPLE_SETTER_IMPL(property, requestMethod) \
_CHECK_NOT_SAME(property) \
request.getRequest().requestMethod; \
emit property ## Changed(property);

// Macro to generate getter and setter for properties which require no special conversion steps
#define SIMPLE_GETTER_SETTER(property, upperProperty, type, requestField) \
type PurchaseContestRequestWrapper::property() const { \
return request.asReader().getRequest().get ## requestField(); \
_SIMPLE_GETTER_IMPL(requestField) \
} \
void PurchaseContestRequestWrapper::set ## upperProperty(type property) { \
if (property == this->property()) \
return; \
request.getRequest().set ## requestField(property); \
emit property ## Changed(property); \
_SIMPLE_SETTER_IMPL(property, set ## requestField(property)) \
}

// Macro to generate getter and setter for simple properties in the sponsorship options
#define SPONSORSHIP_SIMPLE_GETTER_SETTER(property, upperProperty, type, requestField) \
type PurchaseContestRequestWrapper::property() { \
_SIMPLE_GETTER_IMPL(Sponsorship().getOptions().get ## requestField) \
} \
void PurchaseContestRequestWrapper::set ## upperProperty(type property) { \
if (!sponsorshipEnabled()) \
request.getRequest().initSponsorship().initOptions(); \
_SIMPLE_SETTER_IMPL(property, getSponsorship().getOptions().set ## requestField(property)) \
}

namespace swv {
Expand Down Expand Up @@ -69,6 +86,11 @@ void PurchaseContestRequestWrapper::disableSponsorship() {
request.getRequest().initSponsorship().setNoSponsorship();
}

SPONSORSHIP_SIMPLE_GETTER_SETTER(sponsorMaxVotes, SponsorMaxVotes, qint64, MaxVotes)
SPONSORSHIP_SIMPLE_GETTER_SETTER(sponsorMaxRevotes, SponsorMaxRevotes, qint32, MaxRevotes)
SPONSORSHIP_SIMPLE_GETTER_SETTER(sponsorEndDate, SponsorEndDate, qint64, EndDate)
SPONSORSHIP_SIMPLE_GETTER_SETTER(sponsorIncentive, SponsorIncentive, qint64, Incentive)

// Converts a QQmlVariantListModel to a capnp list. Func is a callable taking an element of List and a QVariant as
// arguments which copies the QVariant into the List element
template <typename List, typename Func>
Expand Down
20 changes: 19 additions & 1 deletion VotingApp/wrappers/PurchaseContestRequest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class PurchaseContestRequestWrapper : public QObject
Q_PROPERTY(quint64 weightCoin READ weightCoin WRITE setWeightCoin NOTIFY weightCoinChanged)
Q_PROPERTY(qint64 expiration READ expiration WRITE setExpiration NOTIFY expirationChanged)
Q_PROPERTY(bool sponsorshipEnabled READ sponsorshipEnabled NOTIFY sponsorshipEnabledChanged STORED false)
Q_PROPERTY(qint64 sponsorMaxVotes READ sponsorMaxVotes WRITE setSponsorMaxVotes NOTIFY sponsorMaxVotesChanged)
Q_PROPERTY(qint32 sponsorMaxRevotes READ sponsorMaxRevotes WRITE setSponsorMaxRevotes
NOTIFY sponsorMaxRevotesChanged)
Q_PROPERTY(qint64 sponsorEndDate READ sponsorEndDate WRITE setSponsorEndDate NOTIFY sponsorEndDateChanged)
Q_PROPERTY(qint64 sponsorIncentive READ sponsorIncentive WRITE setSponsorIncentive NOTIFY sponsorIncentiveChanged)

kj::TaskSet& tasks;
QQmlVariantListModel m_contestants;
Expand Down Expand Up @@ -68,6 +73,10 @@ class PurchaseContestRequestWrapper : public QObject
QQmlVariantListModel* promoCodes() {
return &m_promoCodes;
}
qint64 sponsorMaxVotes();
qint32 sponsorMaxRevotes();
qint64 sponsorEndDate();
qint64 sponsorIncentive();

public slots:
/// @brief Submit the request to the server. This consumes the request.
Expand All @@ -80,22 +89,31 @@ public slots:
void setContestType(ContestType::Type contestType);
void setTallyAlgorithm(TallyAlgorithm::Type tallyAlgorithm);
void disableSponsorship();
void setSponsorMaxVotes(qint64 sponsorMaxVotes);
void setSponsorMaxRevotes(qint32 sponsorMaxRevotes);
void setSponsorEndDate(qint64 sponsorEndDate);
void setSponsorIncentive(qint64 sponsorIncentive);

signals:
signals:
void nameChanged(QString name);
void descriptionChanged(QString description);
void weightCoinChanged(quint64 weightCoin);
void expirationChanged(qint64 expiration);
void contestTypeChanged(ContestType::Type contestType);
void tallyAlgorithmChanged(TallyAlgorithm::Type tallyAlgorithm);
void sponsorshipEnabledChanged(bool sponsorshipEnabled);
void sponsorMaxVotesChanged(qint64 sponsorMaxVotes);
void sponsorMaxRevotesChanged(qint32 sponsorMaxRevotes);
void sponsorEndDateChanged(qint64 sponsorEndDate);
void sponsorIncentiveChanged(qint64 sponsorIncentive);

protected slots:
void updateContestants();
void updatePromoCodes();

private:
PurchaseRequest request;
qint64 m_sponsorIncentive;
};

} // namespace swv
Expand Down

0 comments on commit 0185628

Please sign in to comment.