annotate QuestionnaireViewController.mm @ 49:178642d134a7 tip

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