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