forked from d-j-hirst/aus-polling-analyser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditModelFrame.cpp
More file actions
110 lines (94 loc) · 3.7 KB
/
EditModelFrame.cpp
File metadata and controls
110 lines (94 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "EditModelFrame.h"
#include "DateInput.h"
#include "General.h"
#include "FloatInput.h"
#include "IntInput.h"
#include "Log.h"
#include "TextInput.h"
constexpr int ControlPadding = 4;
constexpr int TextInputWidth = 520;
// IDs for the controls and the menu commands
enum ControlId
{
Base = 550, // To avoid mixing events with other frames.
Ok,
Name,
TermCode,
PartyCodes,
PreferenceFlow,
PreferenceDeviation,
PreferenceSamples,
};
EditModelFrame::EditModelFrame(Function function, OkCallback callback, StanModel model)
: wxDialog(NULL, 0, (function == Function::New ? "New Model" : "Edit Model"),
wxDefaultPosition, wxSize(700, 100 /* actual height set later */)),
model(model), callback(callback)
{
int currentY = ControlPadding;
createControls(currentY);
setFinalWindowHeight(currentY);
}
void EditModelFrame::createControls(int & y)
{
createNameInput(y);
createTermCodeInput(y);
createPartyCodesInput(y);
createPreferenceInputs(y);
createOkCancelButtons(y);
}
void EditModelFrame::createNameInput(int& y)
{
auto nameCallback = [this](std::string s) -> void {model.name = s; };
nameInput.reset(new TextInput(this, ControlId::Name, "Name:", model.name, wxPoint(2, y), nameCallback,
DefaultLabelWidth, TextInputWidth));
y += nameInput->Height + ControlPadding;
}
void EditModelFrame::createTermCodeInput(int& y)
{
auto termCodeCallback = [this](std::string s) -> void {model.termCode = s; };
termCodeInput.reset(new TextInput(this, ControlId::TermCode, "Term Code:", model.termCode, wxPoint(2, y), termCodeCallback,
DefaultLabelWidth, TextInputWidth));
y += termCodeInput->Height + ControlPadding;
}
void EditModelFrame::createPartyCodesInput(int& y)
{
auto partyCodesCallback = [this](std::string s) -> void {model.partyCodes = s; };
partyCodesInput.reset(new TextInput(this, ControlId::PartyCodes, "Party Codes:", model.partyCodes, wxPoint(2, y), partyCodesCallback,
DefaultLabelWidth, TextInputWidth));
y += partyCodesInput->Height + ControlPadding;
}
void EditModelFrame::createPreferenceInputs(int& y)
{
auto preferenceFlowCallback = [this](std::string s) -> void {model.preferenceFlow = s; };
preferenceFlowInput.reset(new TextInput(this, ControlId::PreferenceFlow, "Preference Flow (%):",
model.preferenceFlow, wxPoint(2, y), preferenceFlowCallback,
DefaultLabelWidth, TextInputWidth));
y += preferenceFlowInput->Height + ControlPadding;
auto preferenceDeviationCallback = [this](std::string s) -> void {model.preferenceDeviation = s; };
preferenceDeviationInput.reset(new TextInput(this, ControlId::PreferenceDeviation, "Preference Deviation (%):",
model.preferenceDeviation, wxPoint(2, y), preferenceDeviationCallback,
DefaultLabelWidth, TextInputWidth));
y += preferenceDeviationInput->Height + ControlPadding;
auto preferenceSamplesCallback = [this](std::string s) -> void {model.preferenceSamples = s; };
preferenceSamplesInput.reset(new TextInput(this, ControlId::PreferenceSamples, "Preference Samples:",
model.preferenceSamples, wxPoint(2, y), preferenceSamplesCallback,
DefaultLabelWidth, TextInputWidth));
y += preferenceSamplesInput->Height + ControlPadding;
}
void EditModelFrame::createOkCancelButtons(int & y)
{
// Create the OK and cancel buttons.
okButton = new wxButton(this, ControlId::Ok, "OK", wxPoint(67, y), wxSize(100, 24));
cancelButton = new wxButton(this, wxID_CANCEL, "Cancel", wxPoint(233, y), wxSize(100, 24));
// Bind events to the functions that should be carried out by them.
Bind(wxEVT_BUTTON, &EditModelFrame::OnOK, this, Ok);
y += TextInput::Height + ControlPadding;
}
void EditModelFrame::setFinalWindowHeight(int y)
{
SetClientSize(wxSize(GetClientSize().x, y));
}
void EditModelFrame::OnOK(wxCommandEvent& WXUNUSED(event)) {
callback(model);
Close();
}