diff QuestionnaireViewController.mm @ 22:8c0783739337

Logs uploading. Questionnaire also.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Thu, 24 Jan 2013 18:14:40 +0000
parents 650589cac373
children dae6d77657a0
line wrap: on
line diff
--- a/QuestionnaireViewController.mm	Fri Jan 18 15:48:33 2013 +0000
+++ b/QuestionnaireViewController.mm	Thu Jan 24 18:14:40 2013 +0000
@@ -14,10 +14,8 @@
 #pragma mark QuestionnaireViewController
 
 @interface QuestionnaireViewController ()
-    // the "model" is an array of questions and a bunch of answers
+    // the "model" is an array of questions 
 @property (strong, nonatomic)       NSArray * questionArray;
-@property (strong, nonatomic)       NSArray * answerTypeArray;
-@property (strong, nonatomic)       NSMutableArray * answerArray;
 @property (nonatomic)               NSInteger currentQuestionIndex;
 @property (nonatomic, assign)       id theOFAppRef;
 
@@ -31,11 +29,9 @@
 @implementation QuestionnaireViewController
 
 @synthesize picker;
-@synthesize agreeAnswer;
-@synthesize agreeType;
-@synthesize answerTypeArray;
 @synthesize nextButton = _nextButton;
-@synthesize segControl = _segControl;
+@synthesize questionArray;
+
 
 //----------------------------------------------------------------
 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
@@ -45,7 +41,6 @@
         // Custom initialization
         
         [self populateQuestionArray ];
-        [self populateAnswerArray];
         
     }
     return self;
@@ -60,18 +55,12 @@
     [super viewDidLoad];
     // Do any additional setup after loading the view from its nib.
     self.currentQuestionIndex = 0;
-    // load question 1
     
-    self.agreeAnswer = [[NSArray alloc] initWithObjects:
-                        @"Strongly disagree", @"Disagree", @"Neither",
-                        @"Agree", @"Strongly agree", nil];
+    // load question 1    
+    [self loadQuestion:self.currentQuestionIndex];
     
-    self.interfaceAnswer = [[NSArray alloc] initWithObjects:
-                            @"Definitely Sliders", @"Maybe Sliders", @"Neither",
-                            @"Maybe Zoomer", @"Definitely Zoomer", nil];
-    agreeType = YES;
+    self.previousButton.hidden = YES; // dont bother
     
-    [self loadQuestion:self.currentQuestionIndex];
 }
 //----------------------------------------------------------------
 - (void)didReceiveMemoryWarning
@@ -86,7 +75,7 @@
     [_titleText release];
     [_finishButton release];
     [_nextButton release];
-    [_segControl release];
+    [_previousButton release];
     [super dealloc];
 }
 //----------------------------------------------------------------
@@ -95,19 +84,25 @@
     [self setTitleText:nil];
     [self setFinishButton:nil];
     [self setNextButton:nil];
-    [self setSegControl:nil];
+    [self setPreviousButton:nil];
     [super viewDidUnload];
 }
 //----------------------------------------------------------------
-- (IBAction)answerWasSelected:(id)sender {
-    // look at property?
+-(IBAction)hide:(id)sender{
+    // called when finish button hit
+    // c++ call with NSArray argument??
+    // load answers into a c++ vector;
+    vector<int> answersArray;
+
+    Question *q;
     
-}
-
-//----------------------------------------------------------------
--(IBAction)hide:(id)sender{
-    // c++ call with NSArray argument??
-    ((testApp *)self.theOFAppRef)->questionnaireHidden(self.answerArray);
+    for(int i=0;i<[questionArray count];i++){
+        q = [questionArray objectAtIndex:i];
+        answersArray.push_back(q.answer);
+        
+    }
+    
+    ((testApp *)self.theOFAppRef)->questionnaireHidden(answersArray);
 	self.view.hidden = YES;
 }
 //----------------------------------------------------------------
@@ -139,28 +134,15 @@
         [self loadQuestion:self.currentQuestionIndex];
     }
 }
-//----------------------------------------------------------------
 
-// NAH
-- (IBAction)answerSelected:(id)sender {
-    // nice short lines of code.
-    
-    [self.answerArray replaceObjectAtIndex:self.currentQuestionIndex withObject:[NSNumber numberWithInteger:self.segControl.selectedSegmentIndex]];
-    
-    // chek wot we just rote
-    
-    NSLog(@"%@",[self.answerArray objectAtIndex:self.currentQuestionIndex]);
-    
-    
-}
 //----------------------------------------------------------------
 
 - (void)showThanks{
     // hide next question button
     self.nextButton.hidden = YES;
     // hide selector
-    self.segControl.hidden = YES;
-    
+    self.picker.hidden = YES;
+    self.previousButton.hidden = YES;
     
     self.titleText.text = @"Thank you!";
     
@@ -174,80 +156,43 @@
     qtitle = [@"Question " stringByAppendingFormat:@"%d / 16",questionIndex+1];
     self.titleText.text = qtitle;
     
-    self.questionText.text = [self.questionArray objectAtIndex:questionIndex];
+    Question *curQ = [questionArray objectAtIndex:self.currentQuestionIndex];
     
-    // if question already answered show that
-    NSInteger answerInt = [[self.answerArray objectAtIndex:questionIndex] integerValue];
+    self.questionText.text = curQ.questionText;
     
-    // set different answer type
-    agreeType = [answerTypeArray objectAtIndex:questionIndex];
-    // then refresh picker view content
+    
+    // refresh picker view content
     [picker reloadComponent:0];
     
 
-    // DUZZNT WERK
-    if(answerInt==-1){
-        // select "neither" (2)
-        NSLog(@"No answer answerInt %d", answerInt);
-        [picker selectRow:2 inComponent:0 animated:YES];
-        
-    }else{
-        // select previous answer
-        NSLog(@"Prev answer answerInt %d", answerInt);
-        [picker selectRow:answerInt inComponent:0 animated:YES];
-    }
+    NSLog(@"Prev answer answerInt %d", curQ.answer);
+    [picker selectRow:curQ.answer inComponent:0 animated:YES];
+
 }
 //----------------------------------------------------------------
 - (void)populateQuestionArray{
-    self.questionArray = [[NSArray alloc] initWithObjects:
-                          @"I am familiar with music software and synthesisers.",
-                          @"The best way to get a feel for the possibilities of the synth was with:",
-                          @"Interesting sounds could be discovered more quickly as a result of using:",
-                          @"A sound could be fine tuned more easily using:",
-                          @"The correspondence between the sliders and the grid was understandable.",
-                          @"The interface that felt more familiar was:",
-                          @"Scrolling a greater distance the zoom grid seemed to correspond to larger  difference in the sound.",
-                          @"The ability to see other presets on the grid was useful.",
-                          @"The range of sounds was too limited to be able to judge the eventual usefulness of the interface.",
-                          @"The interface better for generating new ideas was",
-                          @"The interface better for live performance would be:",
-                          @"A specific type of sound could be found more quickly using:",
-                          @"I felt more in control when using:",
-                          @"The Zoomer was an improvement on just using a randomiser.",
-                          @"The combination of Zoomer and Sliders was more useful than either individually.",
-                          @"Overall, I preferred using:",
+
+    self.questionArray = [NSArray arrayWithObjects:
+                          [[Question alloc] initWithTextAndType:@"I am familiar with music software and sound synthesis.":AGREE_DISAGREE],
+                          [[Question alloc] initWithTextAndType:@"The best way to get a feel for the possibilities of the synth was with:":SLIDERS_ZOOMER],
+                          [[Question alloc] initWithTextAndType:@"Interesting sounds could be discovered more quickly as a result of using:":SLIDERS_ZOOMER],
+                          [[Question alloc] initWithTextAndType:@"A sound could be fine tuned more easily using:":SLIDERS_ZOOMER],
+                          [[Question alloc] initWithTextAndType:@"The correspondence between the sliders and the grid was understandable.":AGREE_DISAGREE],
+                          [[Question alloc] initWithTextAndType:@"The interface that felt more familiar was:":SLIDERS_ZOOMER],
+                          [[Question alloc] initWithTextAndType:@"Scrolling a greater distance the zoom grid seemed to correspond to larger  difference in the sound.":AGREE_DISAGREE],
+                          [[Question alloc] initWithTextAndType:@"The ability to see other presets on the grid was useful.":AGREE_DISAGREE],
+                          [[Question alloc] initWithTextAndType:@"The range of sounds was too limited to be able to judge the eventual usefulness of the interface.":AGREE_DISAGREE],
+                          [[Question alloc] initWithTextAndType:@"The interface better for generating new ideas was":SLIDERS_ZOOMER],
+                          [[Question alloc] initWithTextAndType:@"The interface better for live performance would be:":SLIDERS_ZOOMER],
+                          [[Question alloc] initWithTextAndType:@"A specific type of sound could be found more quickly using:":SLIDERS_ZOOMER],
+                          [[Question alloc] initWithTextAndType:@"I felt more in control when using:":SLIDERS_ZOOMER],
+                          [[Question alloc] initWithTextAndType:@"The Zoomer was an improvement on just using a randomiser.":AGREE_DISAGREE],
+                          [[Question alloc] initWithTextAndType:@"The combination of Zoomer and Sliders was better than either individually.":AGREE_DISAGREE],
+                          [[Question alloc] initWithTextAndType:@"Overall, I preferred using:":SLIDERS_ZOOMER],
                           nil];
-    self.answerTypeArray = [[NSArray alloc] initWithObjects:
-                            YES,
-                            NO,
-                            NO,
-                            NO,
-                            YES,
-                            NO,
-                            YES,
-                            YES,
-                            YES,
-                            NO,
-                            NO,
-                            NO,
-                            NO,
-                            YES,
-                            YES,
-                            NO,
-                            nil]
+ 
 }
-//----------------------------------------------------------------
-- (void)populateAnswerArray{
-    int N = [self.questionArray count];
 
-    //[self.answerArray initWithCapacity:N]; // necessary?
-    self.answerArray = [[NSMutableArray alloc] initWithCapacity:N];
-    // set the number to what?
-    for(int i=0;i<N;i++){
-        [self.answerArray addObject:[NSNumber numberWithInt:-1]];
-    }
-    
-}
 //----------------------------------------------------------------
 #pragma mark -
 #pragma mark PickerView DataSource
@@ -257,44 +202,38 @@
 {
     return 1;
 }
+//----------------------------------------------------------------
 - (NSInteger)pickerView:(UIPickerView *)pickerView
 numberOfRowsInComponent:(NSInteger)component
 {
-    return [agreeAnswer count]; // always 5
+    return 6; // always 6 
 }
+//----------------------------------------------------------------
 - (NSString *)pickerView:(UIPickerView *)pickerView
              titleForRow:(NSInteger)row
             forComponent:(NSInteger)component
 {
-    if(agreeType){
-        return [agreeAnswer objectAtIndex:row];
-    }else{
-        return [interfaceAnswer objectAtIndex:row];
-    }
+    Question *curQ = [questionArray objectAtIndex:self.currentQuestionIndex];
+
+    // get array of answers from Question class
+    NSArray * answers = [Question answersWithType:curQ.questionType];
+    return [answers objectAtIndex:row];
+
 }
-
+//----------------------------------------------------------------
 #pragma mark -
 #pragma mark PickerView Delegate
 -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
       inComponent:(NSInteger)component
 {
-    
+    Question *curQ = [questionArray objectAtIndex:self.currentQuestionIndex];
     // set question answerArray
-    [self.answerArray replaceObjectAtIndex:self.currentQuestionIndex withObject:[NSNumber numberWithInteger:row]];
+    curQ.answer = row;
     
     // chek wot we just rote
     
-    NSLog(@"%@",[self.answerArray objectAtIndex:self.currentQuestionIndex]);
-    /*
-     float rate = [[exchangeRates objectAtIndex:row] floatValue];
-     float dollars = [dollarText.text floatValue];
-     float result = dollars * rate;
-     
-     NSString *resultString = [[NSString alloc] initWithFormat:
-     @"%.2f USD = %.2f %@", dollars, result,
-     [countryNames objectAtIndex:row]];
-     resultLabel.text = resultString;
-     */
+    NSLog(@"Answer: %d",curQ.answer);
+
 }
 
 @end // end implementation