annotate QuestionnaireViewController.mm @ 43:b91a1859829a

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