comparison QuestionnaireViewController.mm @ 0:a223551fdc1f

First commit - copy from tweakathlon.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Fri, 10 Oct 2014 11:46:42 +0100
parents
children 27cdf475aa4b
comparison
equal deleted inserted replaced
-1:000000000000 0:a223551fdc1f
1 //
2 // QuestionnaireViewController.m
3 // oscSenderExample
4 //
5 // Created by Robert Tubb on 16/01/2013.
6 //
7 //
8
9 #import "QuestionnaireViewController.h"
10
11 #include "testApp.h"
12
13 #pragma mark -
14 #pragma mark QuestionnaireViewController
15
16 @interface QuestionnaireViewController ()
17 // the "model" is an array of questions
18 @property (strong, nonatomic) NSArray * questionArray;
19 @property (nonatomic) NSInteger currentQuestionIndex;
20 @property (nonatomic, assign) id theOFAppRef;
21
22 /*
23
24
25 */
26
27 @end
28
29 @implementation QuestionnaireViewController
30
31 @synthesize picker;
32 @synthesize nextButton = _nextButton;
33 @synthesize questionArray = _questionArray;
34
35
36 //----------------------------------------------------------------
37 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
38 {
39 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
40 if (self) {
41 // Custom initialization
42
43 [self populateQuestionArray ];
44
45 }
46 return self;
47 }
48 - (void)setAppRef:(id)theOFApp{
49 self.theOFAppRef = theOFApp;
50
51 }
52 //----------------------------------------------------------------
53 - (void)viewDidLoad
54 {
55 [super viewDidLoad];
56 // Do any additional setup after loading the view from its nib.
57 self.currentQuestionIndex = 0;
58
59 // load question 1
60 [self loadQuestion:self.currentQuestionIndex];
61
62 self.previousButton.hidden = NO; // bother
63 self.commentText.hidden = YES;
64 self.finishButton.hidden = YES;
65 self.nextButton.hidden = YES;
66
67 self.lickertOptions.hidden = NO;
68 self.interfacePreferenceOptions.hidden = YES;
69 }
70 //----------------------------------------------------------------
71 - (void)didReceiveMemoryWarning
72 {
73 [super didReceiveMemoryWarning];
74 // Dispose of any resources that can be recreated.
75 }
76 //----------------------------------------------------------------
77 - (void)dealloc {
78
79 [super dealloc];
80 }
81 //----------------------------------------------------------------
82 - (void)viewDidUnload {
83 [self.questionArray release];
84 [self setQuestionText:nil];
85 [self setTitleText:nil];
86 [self setFinishButton:nil];
87 [self setNextButton:nil];
88 [self setPreviousButton:nil];
89 [self setCommentText:nil];
90 [self setNumberChooser:nil];
91 [self setInterfacePreferenceOptions:nil];
92 [self setLickertOptions:nil];
93 [self setPleaseAnswer:nil];
94 [super viewDidUnload];
95 }
96 //----------------------------------------------------------------
97 -(IBAction)hide:(id)sender{
98 // called when finish button hit
99 // c++ call with NSArray argument??
100 // load answers into a c++ vector;
101 vector<int> answersArray;
102
103 Question *q;
104
105 for(int i=0;i<[self.questionArray count];i++){
106 q = [self.questionArray objectAtIndex:i];
107 answersArray.push_back(q.answer);
108
109 }
110 const char *userComments = [self.commentText.text cStringUsingEncoding: NSUTF8StringEncoding];
111 [self.commentText resignFirstResponder];
112
113 self.view.hidden = YES;
114 ((testApp *)self.theOFAppRef)->questionnaireHidden(answersArray, userComments);
115
116 }
117
118 //----------------------------------------------------------------
119 -(IBAction)show:(id)sender{
120 self.view.hidden = NO;
121 }
122 //----------------------------------------------------------------
123
124 - (IBAction)nextQuestionPressed:(id)sender {
125 // save answer ? no button did that hopefully
126
127 // if last question show thanks
128 // else go to next
129 self.currentQuestionIndex++;
130 if(self.currentQuestionIndex >= [self.questionArray count]){
131 [self showThanks];
132 }else{
133 [self loadQuestion:self.currentQuestionIndex];
134
135 }
136 }
137 //----------------------------------------------------------------
138 - (IBAction)previousQuestionPressed:(id)sender {
139 self.currentQuestionIndex--;
140 if(self.currentQuestionIndex < 0){
141 // nothing
142 self.currentQuestionIndex = 0;
143 }else{
144 [self loadQuestion:self.currentQuestionIndex];
145 }
146 }
147
148 //----------------------------------------------------------------
149
150 - (void)showThanks{
151 // hide next question button
152 self.nextButton.hidden = YES;
153 // hide selector
154 self.picker.hidden = YES;
155 self.previousButton.hidden = YES;
156 self.finishButton.hidden = NO;
157
158 self.lickertOptions.hidden = YES;
159 self.interfacePreferenceOptions.hidden = YES;
160
161 self.titleText.text = @"Thank you!";
162 self.numberChooser.hidden = YES;
163 self.commentText.hidden = NO;
164
165 self.questionText.text = @"Thanks for helping science help you. Feel free to add further comments in the text box below, and then press 'finish' to go back and use the app.";
166 }
167
168 //----------------------------------------------------------------
169 - (void)loadQuestion:(NSInteger)questionIndex {
170 // populate text fields with question
171 NSString *qtitle;
172 qtitle = [@"Question " stringByAppendingFormat:@"%d / %d",questionIndex+1, [self.questionArray count]];
173 self.titleText.text = qtitle;
174
175 Question *curQ = [self.questionArray objectAtIndex:self.currentQuestionIndex];
176
177 self.questionText.text = curQ.questionText;
178
179
180 // refresh picker view content
181 //[picker reloadComponent:0];
182
183 // show correct option number labels
184 if(curQ.questionType == AGREE_DISAGREE){
185 self.lickertOptions.hidden = NO;
186 self.interfacePreferenceOptions.hidden = YES;
187 }else if(curQ.questionType == SLIDERS_ZOOMER){
188 self.lickertOptions.hidden = YES;
189 self.interfacePreferenceOptions.hidden = NO;
190 }
191
192 //NSLog(@"Prev answer answerInt %d", curQ.answer);
193 //[picker selectRow:2 inComponent:0 animated:YES];
194
195 // what about unselecting segment?
196
197 }
198 // 1/3/13 removed q 6 and 15. now only 15 qs
199 //----------------------------------------------------------------
200 - (void)populateQuestionArray{
201 // potential leak
202 self.questionArray = [NSArray arrayWithObjects:
203 [[Question alloc] initWithTextAndType:@"I am familiar with music software and sound synthesis.":AGREE_DISAGREE],
204 [[Question alloc] initWithTextAndType:@"The ability to retrace my steps using the history path was useful...":AGREE_DISAGREE],
205 [[Question alloc] initWithTextAndType:@"The best interface for discovering interesting sounds quickly was...":SLIDERS_ZOOMER],
206 [[Question alloc] initWithTextAndType:@"The best interface for fine tuning a sound was...":SLIDERS_ZOOMER],
207 [[Question alloc] initWithTextAndType:@"The correspondence between the sliders and the grid was understandable.":AGREE_DISAGREE],
208 [[Question alloc] initWithTextAndType:@"Scrolling a greater distance on the grid seemed to correspond to larger difference in the sound.":AGREE_DISAGREE],
209 [[Question alloc] initWithTextAndType:@"The interface that I felt more in control using was...":SLIDERS_ZOOMER],
210 [[Question alloc] initWithTextAndType:@"Being able to see previously saved presets on the grid is useful.":AGREE_DISAGREE], //
211 [[Question alloc] initWithTextAndType:@"The interface that felt more creative was...":SLIDERS_ZOOMER],
212 [[Question alloc] initWithTextAndType:@"The range of sounds was too limited to be able to judge the eventual usefulness of the interface.":AGREE_DISAGREE],
213 [[Question alloc] initWithTextAndType:@"The interface better for generating new ideas was...":SLIDERS_ZOOMER],
214 [[Question alloc] initWithTextAndType:@"The interface better for performing live would be...":SLIDERS_ZOOMER],
215 [[Question alloc] initWithTextAndType:@"The Zoomer was an improvement on just using a randomiser.":AGREE_DISAGREE],
216 [[Question alloc] initWithTextAndType:@"The combination of Zoomer and Sliders was better than either individually.":AGREE_DISAGREE],
217 [[Question alloc] initWithTextAndType:@"I enjoy 'happy accidents' in the creative process.":AGREE_DISAGREE],
218 [[Question alloc] initWithTextAndType:@"Overall, the interface I preferred using was...":SLIDERS_ZOOMER], // ??????
219 nil];
220 // The zoomer seemed more appropriate to explore the synth sound controls (red) than the note sequence controls (blue)
221 // I enjoyed the sounds produced
222
223 }
224
225 //----------------------------------------------------------------
226 #pragma mark -
227 #pragma mark PickerView DataSource
228
229 - (NSInteger)numberOfComponentsInPickerView:
230 (UIPickerView *)pickerView
231 {
232 return 1;
233 }
234 //----------------------------------------------------------------
235 - (NSInteger)pickerView:(UIPickerView *)pickerView
236 numberOfRowsInComponent:(NSInteger)component
237 {
238
239 return NUM_CHOICES; // always 6
240 }
241 //----------------------------------------------------------------
242 - (NSString *)pickerView:(UIPickerView *)pickerView
243 titleForRow:(NSInteger)row
244 forComponent:(NSInteger)component
245 {
246 Question *curQ = [self.questionArray objectAtIndex:self.currentQuestionIndex];
247
248 // get array of answers from Question class
249 NSArray * answers = [Question answersWithType:curQ.questionType];
250 return [answers objectAtIndex:row];
251
252 }
253 //----------------------------------------------------------------
254 #pragma mark -
255 #pragma mark PickerView Delegate
256 -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
257 inComponent:(NSInteger)component
258 {
259 Question *curQ = [self.questionArray objectAtIndex:self.currentQuestionIndex];
260 // set question answerArray
261 curQ.answer = row;
262
263 // chek wot we just rote
264
265 NSLog(@"Answer: %d",curQ.answer);
266
267 }
268 //----------------------------------------------------------------
269 #pragma mark UITextViewDelegate functions
270 /*
271 This answer was useful to me, but I was also looking for the callback function from the "Go" button, which I found is:
272 - (BOOL) textFieldShouldReturn:(UITextField *)textField { // Customer code return YES; }
273
274 You will need to send the UITextField delegate to your view controller for that to work.
275
276 */
277 - (BOOL) textFieldShouldReturn:(UITextField *)textField {
278 // Customer code
279 NSLog(@"RETURN DELEGATE");
280 [self hide:self ];
281 return NO;
282 }
283 - (IBAction)answerChosen:(id)sender {
284 self.pleaseAnswer.hidden = YES;
285 UISegmentedControl *seg = (UISegmentedControl *)sender;
286 Question *curQ = [self.questionArray objectAtIndex:self.currentQuestionIndex];
287 // set question answerArray
288 curQ.answer = seg.selectedSegmentIndex;
289
290 // chek wot we just rote
291
292 NSLog(@"Answer: %d",curQ.answer);
293
294 // automatically go next q
295 self.currentQuestionIndex++;
296 if(self.currentQuestionIndex >= [self.questionArray count]){
297 [self showThanks];
298 }else{
299 [self loadQuestion:self.currentQuestionIndex];
300
301 }
302
303 }
304 @end // end implementation
305 //----------------------------------------------------------------
306 //----------------------------------------------------------------