Skip to content

Commit

Permalink
Progress FollowMyVote#19: Add contestants to contest creation form
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielhourt committed Feb 8, 2016
1 parent e035a2d commit 319963c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 26 deletions.
92 changes: 69 additions & 23 deletions VotingApp/qml/CreateContestPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,86 @@ Page {

property var contestCreator
property VotingSystem votingSystem
property var purchaseRequest: contestCreator.getPurchaseContestRequest()

SwipeView {
id: swiper
anchors.fill: parent

Item {
ColumnLayout {
anchors.fill: parent
anchors.margins: window.dp(16)

AppTextField {
Layout.fillWidth: true
placeholderText: qsTr("Contest Name")
maximumLength: contestCreator.contestLimits[ContestLimits.NameLength]
Flickable {
id: flickable
interactive: true
flickableDirection: Flickable.VerticalFlick
contentHeight: createContestFormColumn.height
anchors {
left: parent.left
right: parent.horizontalCenter
top: parent.top
bottom: parent.bottom
margins: window.dp(16)
rightMargin: window.dp(8)
}
AppTextEdit {
Layout.fillWidth: true
placeholderText: qsTr("Description")
wrapMode: TextEdit.Wrap
}
Row {
spacing: window.dp(8)

AppText {
id: weightCoinLabel
text: qsTr("Coin to Poll:")
Column {
id: createContestFormColumn
width: parent.width

AppTextField {
width: parent.width
placeholderText: qsTr("Contest Name")
maximumLength: contestCreator.contestLimits[ContestLimits.NameLength]
}
AppTextEdit {
width: parent.width
placeholderText: qsTr("Description")
wrapMode: TextEdit.Wrap
}
Row {
spacing: window.dp(8)

AppText {
id: weightCoinLabel
text: qsTr("Coin to Poll:")
}
Controls.ComboBox {
width: window.dp(120)
model: ["a", "b", "c"]
style: ControlStyles.ComboBoxStyle {
font: weightCoinLabel.font
}
}
}
Controls.ComboBox {
width: window.dp(120)
model: ["a", "b", "c"]
style: ControlStyles.ComboBoxStyle {
font: weightCoinLabel.font
Column {
width: parent.width
Repeater {
model: purchaseRequest.contestants
delegate: Row {
width: parent.width

IconButton {
icon: IconType.remove
onClicked: purchaseRequest.contestants.remove(index)
}
IconButton {
icon: IconType.edit
}
ColumnLayout {
AppText {
text: modelData.name
}
AppText {
text: modelData.description
}
}
}
}
}
AppButton {
text: qsTr("Add Contestant")

onClicked: purchaseRequest.contestants.append({"name": "Joe", "description": "Joe is a candidate."})
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions VotingApp/wrappers/PurchaseContestRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
// 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() { \
if (!sponsorshipEnabled()) \
return {}; \
_SIMPLE_GETTER_IMPL(Sponsorship().getOptions().get ## requestField) \
} \
void PurchaseContestRequestWrapper::set ## upperProperty(type property) { \
Expand Down
6 changes: 3 additions & 3 deletions VotingApp/wrappers/PurchaseContestRequest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ QML_ENUM_CLASS(TallyAlgorithm,
class PurchaseContestRequestWrapper : public QObject
{
Q_OBJECT
Q_PROPERTY(ContestType::Type contestType READ contestType WRITE setContestType NOTIFY contestTypeChanged)
Q_PROPERTY(TallyAlgorithm::Type tallyAlgorithm READ tallyAlgorithm WRITE setTallyAlgorithm
Q_PROPERTY(swv::ContestType::Type contestType READ contestType WRITE setContestType NOTIFY contestTypeChanged)
Q_PROPERTY(swv::TallyAlgorithm::Type tallyAlgorithm READ tallyAlgorithm WRITE setTallyAlgorithm
NOTIFY tallyAlgorithmChanged)
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY descriptionChanged)
/// Contestants is a list of Javascript options containing "name" and "description" properties, each being strings
/// Contestants is a list of Javascript objects containing "name" and "description" properties, each being strings
Q_PROPERTY(QQmlVariantListModel* contestants READ contestants CONSTANT)
Q_PROPERTY(QQmlVariantListModel* promoCodes READ promoCodes CONSTANT)
Q_PROPERTY(quint64 weightCoin READ weightCoin WRITE setWeightCoin NOTIFY weightCoinChanged)
Expand Down

0 comments on commit 319963c

Please sign in to comment.