Skip to content

Commit

Permalink
Progress FollowMyVote#19: Initial work: sponsorship in PurchaseContes…
Browse files Browse the repository at this point in the history
…tRequestWrapper

Also, refactor all inline methods to the cpp file, more cleanup with
macros
  • Loading branch information
nathanielhourt committed Jan 13, 2016
1 parent 6d25dba commit 4d82f60
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
25 changes: 23 additions & 2 deletions VotingApp/wrappers/PurchaseContestRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,28 @@

// Macro to generate getter and setter for enum properties
#define ENUM_GETTER_SETTER(property, upperProperty) \
upperProperty::Type swv::PurchaseContestRequestWrapper::property() const { \
upperProperty::Type PurchaseContestRequestWrapper::property() const { \
return static_cast<upperProperty::Type>(request.asReader().getRequest().get ## upperProperty ()); \
} \
void swv::PurchaseContestRequestWrapper::set ## upperProperty(upperProperty::Type property) { \
void PurchaseContestRequestWrapper::set ## upperProperty(upperProperty::Type property) { \
if (property == this->property()) \
return; \
request.getRequest().set ## upperProperty (static_cast<::ContestCreator::upperProperty ## s>(property)); \
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(); \
} \
void PurchaseContestRequestWrapper::set ## upperProperty(type property) { \
if (property == this->property()) \
return; \
request.getRequest().set ## requestField(property); \
emit property ## Changed(property); \
}

namespace swv {
PurchaseContestRequestWrapper::PurchaseContestRequestWrapper(PurchaseRequest&& request, kj::TaskSet& taskTracker, QObject* parent)
: QObject(parent),
Expand All @@ -37,4 +49,13 @@ ENUM_GETTER_SETTER(contestType, ContestType)
ENUM_GETTER_SETTER(tallyAlgorithm, TallyAlgorithm)
TEXT_GETTER_SETTER(name, Name, ContestName)
TEXT_GETTER_SETTER(description, Description, ContestDescription)
SIMPLE_GETTER_SETTER(weightCoin, WeightCoin, quint64, WeightCoin)
SIMPLE_GETTER_SETTER(expiration, Expiration, qint64, ContestExpiration)

bool PurchaseContestRequestWrapper::sponsorshipEnabled() const {
return request.asReader().getRequest().getSponsorship().isOptions();
}
void PurchaseContestRequestWrapper::disableSponsorship() {
request.getRequest().initSponsorship().setNoSponsorship();
}
} // namespace swv
32 changes: 8 additions & 24 deletions VotingApp/wrappers/PurchaseContestRequest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class PurchaseContestRequestWrapper : public QObject
Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY descriptionChanged)
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)

kj::TaskSet& tasks;
public:
Expand All @@ -50,41 +51,23 @@ class PurchaseContestRequestWrapper : public QObject

QString name() const;
QString description() const;
quint64 weightCoin() const
{
return request.asReader().getRequest().getWeightCoin();
}
qint64 expiration() const
{
return request.asReader().getRequest().getContestExpiration();
}
quint64 weightCoin() const;
qint64 expiration() const;
ContestType::Type contestType() const;
TallyAlgorithm::Type tallyAlgorithm() const;
bool sponsorshipEnabled() const;

public slots:
/// @brief Submit the request to the server. This consumes the request.
void submit(){}

void setName(QString name);
void setDescription(QString description);
void setWeightCoin(quint64 weightCoin)
{
if (weightCoin == this->weightCoin())
return;

request.getRequest().setWeightCoin(weightCoin);
emit weightCoinChanged(weightCoin);
}
void setExpiration(qint64 expiration)
{
if (expiration == this->expiration())
return;

request.getRequest().setContestExpiration(expiration);
emit expirationChanged(expiration);
}
void setWeightCoin(quint64 weightCoin);
void setExpiration(qint64 expiration);
void setContestType(ContestType::Type contestType);
void setTallyAlgorithm(TallyAlgorithm::Type tallyAlgorithm);
void disableSponsorship();

signals:
void nameChanged(QString name);
Expand All @@ -93,6 +76,7 @@ public slots:
void expirationChanged(qint64 expiration);
void contestTypeChanged(ContestType::Type contestType);
void tallyAlgorithmChanged(TallyAlgorithm::Type tallyAlgorithm);
void sponsorshipEnabledChanged(bool sponsorshipEnabled);

private:
PurchaseRequest request;
Expand Down

0 comments on commit 4d82f60

Please sign in to comment.