Skip to content
Snippets Groups Projects
Commit cd6498ee authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

correctly handle dynamic changes of "readOnly" status

parent 1449f214
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
-(void)setLabelFrame:(CGRect)frame; -(void)setLabelFrame:(CGRect)frame;
-(NSString *)getName; -(NSString *)getName;
-(UILabel *)getLabel; -(UILabel *)getLabel;
-(bool)isReadOnly;
+(double)getHeight; +(double)getHeight;
-(void)refresh; -(void)refresh;
@end @end
......
...@@ -45,8 +45,6 @@ ...@@ -45,8 +45,6 @@
} }
} }
-(bool) isReadOnly {return NO;}
+(double)getHeight +(double)getHeight
{ {
return 60.0f; return 60.0f;
...@@ -58,7 +56,6 @@ ...@@ -58,7 +56,6 @@
{ {
self = [super init]; self = [super init];
if(self){ if(self){
label.alpha = (string.getReadOnly())? 0.439216f : 1.0f;
[label setText:[Utils getStringFromCString:string.getShortName().c_str()]]; [label setText:[Utils getStringFromCString:string.getShortName().c_str()]];
name = [Utils getStringFromCString:string.getName().c_str()]; name = [Utils getStringFromCString:string.getName().c_str()];
button = [UIButton buttonWithType:UIButtonTypeSystem]; button = [UIButton buttonWithType:UIButtonTypeSystem];
...@@ -102,7 +99,10 @@ ...@@ -102,7 +99,10 @@
{ {
std::vector<onelab::string> string; std::vector<onelab::string> string;
onelab::server::instance()->get(string, [name UTF8String]); onelab::server::instance()->get(string, [name UTF8String]);
if(string.size() < 1) return;
[button setTitle:[Utils getStringFromCString:string[0].getValue().c_str()] forState:UIControlStateNormal]; [button setTitle:[Utils getStringFromCString:string[0].getValue().c_str()] forState:UIControlStateNormal];
[button setEnabled:(string[0].getReadOnly() ? FALSE : TRUE)];
[label setEnabled:(string[0].getReadOnly() ? FALSE : TRUE)];
} }
-(void)setFrame:(CGRect)frame -(void)setFrame:(CGRect)frame
...@@ -115,14 +115,6 @@ ...@@ -115,14 +115,6 @@
return button; return button;
} }
-(bool)isReadOnly
{
std::vector<onelab::string> string;
onelab::server::instance()->get(string, [name UTF8String]);
if(string.size() < 1) return YES;
return string[0].getReadOnly();
}
+(double)getHeight +(double)getHeight
{ {
return 60.f; return 60.f;
...@@ -134,7 +126,6 @@ ...@@ -134,7 +126,6 @@
{ {
self = [super init]; self = [super init];
if(self) { if(self) {
label.alpha = (number.getReadOnly())? 0.439216f : 1.0f;
[label setText:[Utils getStringFromCString:number.getShortName().c_str()]]; [label setText:[Utils getStringFromCString:number.getShortName().c_str()]];
name = [Utils getStringFromCString:number.getName().c_str()]; name = [Utils getStringFromCString:number.getName().c_str()];
button = [UIButton buttonWithType:UIButtonTypeSystem]; button = [UIButton buttonWithType:UIButtonTypeSystem];
...@@ -194,8 +185,11 @@ ...@@ -194,8 +185,11 @@
{ {
std::vector<onelab::number> number; std::vector<onelab::number> number;
onelab::server::instance()->get(number, [name UTF8String]); onelab::server::instance()->get(number, [name UTF8String]);
if(number.size() < 1) return;
[button setTitle:[Utils getStringFromCString:number[0].getValueLabel(number[0].getValue()).c_str()] [button setTitle:[Utils getStringFromCString:number[0].getValueLabel(number[0].getValue()).c_str()]
forState:UIControlStateNormal]; forState:UIControlStateNormal];
[button setEnabled:(number[0].getReadOnly() ? FALSE : TRUE)];
[label setEnabled:(number[0].getReadOnly() ? FALSE : TRUE)];
} }
-(void)setFrame:(CGRect)frame -(void)setFrame:(CGRect)frame
...@@ -208,14 +202,6 @@ ...@@ -208,14 +202,6 @@
return button; return button;
} }
-(bool)isReadOnly
{
std::vector<onelab::number> number;
onelab::server::instance()->get(number, [name UTF8String]);
if(number.size() < 1) return YES;
return number[0].getReadOnly();
}
+(double)getHeight +(double)getHeight
{ {
return 60.f; return 60.f;
...@@ -227,7 +213,6 @@ ...@@ -227,7 +213,6 @@
{ {
self = [super init]; self = [super init];
if(self) { if(self) {
label.alpha = (number.getReadOnly())? 0.439216f : 1.0f;
[label setText:[Utils getStringFromCString:number.getShortName().c_str()]]; [label setText:[Utils getStringFromCString:number.getShortName().c_str()]];
name = [Utils getStringFromCString:number.getName().c_str()]; name = [Utils getStringFromCString:number.getName().c_str()];
checkbox = [[UISwitch alloc] init]; checkbox = [[UISwitch alloc] init];
...@@ -241,7 +226,10 @@ ...@@ -241,7 +226,10 @@
{ {
std::vector<onelab::number> number; std::vector<onelab::number> number;
onelab::server::instance()->get(number, [name UTF8String]); onelab::server::instance()->get(number, [name UTF8String]);
if(number.size() < 1) return;
[checkbox setSelected:(number[0].getValue() == 1)]; [checkbox setSelected:(number[0].getValue() == 1)];
[checkbox setEnabled:(number[0].getReadOnly() ? FALSE : TRUE)];
[label setEnabled:(number[0].getReadOnly() ? FALSE : TRUE)];
} }
-(void) valueChange:(UISwitch *)sender -(void) valueChange:(UISwitch *)sender
...@@ -264,14 +252,6 @@ ...@@ -264,14 +252,6 @@
return checkbox; return checkbox;
} }
-(bool)isReadOnly
{
std::vector<onelab::number> number;
onelab::server::instance()->get(number, [name UTF8String]);
if(number.size() < 1) return YES;
return number[0].getReadOnly();
}
+(double)getHeight +(double)getHeight
{ {
return 40.0f; return 40.0f;
...@@ -284,7 +264,6 @@ ...@@ -284,7 +264,6 @@
self = [super init]; self = [super init];
if(self) { if(self) {
name = [Utils getStringFromCString:number.getName().c_str()]; name = [Utils getStringFromCString:number.getName().c_str()];
label.alpha = (number.getReadOnly())? 0.439216f : 1.0f;
stepper = [[UIStepper alloc] init]; stepper = [[UIStepper alloc] init];
[stepper setValue:number.getValue()]; [stepper setValue:number.getValue()];
[stepper setStepValue:1]; [stepper setStepValue:1];
...@@ -317,6 +296,8 @@ ...@@ -317,6 +296,8 @@
[stepper setValue:number[0].getValue()]; [stepper setValue:number[0].getValue()];
[label setText:[NSString stringWithFormat:@"%@ %d", [Utils getStringFromCString:number[0].getShortName().c_str()], [label setText:[NSString stringWithFormat:@"%@ %d", [Utils getStringFromCString:number[0].getShortName().c_str()],
(int)number[0].getValue()]]; (int)number[0].getValue()]];
[stepper setEnabled:(number[0].getReadOnly() ? FALSE : TRUE)];
[label setEnabled:(number[0].getReadOnly() ? FALSE : TRUE)];
} }
-(void)setFrame:(CGRect)frame -(void)setFrame:(CGRect)frame
...@@ -340,7 +321,6 @@ ...@@ -340,7 +321,6 @@
{ {
self = [super init]; self = [super init];
if(self) { if(self) {
label.alpha = (number.getReadOnly())? 0.439216f : 1.0f;
name = [Utils getStringFromCString:number.getName().c_str()]; name = [Utils getStringFromCString:number.getName().c_str()];
slider = [[UISlider alloc] init]; slider = [[UISlider alloc] init];
[slider setMaximumValue:number.getMax()]; [slider setMaximumValue:number.getMax()];
...@@ -365,6 +345,8 @@ ...@@ -365,6 +345,8 @@
[slider setValue:number[0].getValue()]; [slider setValue:number[0].getValue()];
[label setText:[NSString stringWithFormat:@"%@ %g", [Utils getStringFromCString:number[0].getShortName().c_str()], [label setText:[NSString stringWithFormat:@"%@ %g", [Utils getStringFromCString:number[0].getShortName().c_str()],
number[0].getValue()]]; number[0].getValue()]];
[slider setEnabled:(number[0].getReadOnly() ? FALSE : TRUE)];
[label setEnabled:(number[0].getReadOnly() ? FALSE : TRUE)];
} }
-(void)sliderValueChanged:(UISlider *)sender -(void)sliderValueChanged:(UISlider *)sender
...@@ -389,14 +371,6 @@ ...@@ -389,14 +371,6 @@
return slider; return slider;
} }
-(bool)isReadOnly
{
std::vector<onelab::number> number;
onelab::server::instance()->get(number, [name UTF8String]);
if(number.size() < 1) return YES;
return number[0].getReadOnly();
}
+(double)getHeight +(double)getHeight
{ {
return 65.0f; return 65.0f;
...@@ -408,7 +382,6 @@ ...@@ -408,7 +382,6 @@
{ {
self = [super init]; self = [super init];
if(self) { if(self) {
label.alpha = (number.getReadOnly())? 0.439216f : 1.0f;
[label setText:[Utils getStringFromCString:number.getShortName().c_str()]]; [label setText:[Utils getStringFromCString:number.getShortName().c_str()]];
name = [Utils getStringFromCString:number.getName().c_str()]; name = [Utils getStringFromCString:number.getName().c_str()];
textbox = [[UITextField alloc] init]; textbox = [[UITextField alloc] init];
...@@ -432,6 +405,8 @@ ...@@ -432,6 +405,8 @@
onelab::server::instance()->get(number, [name UTF8String]); onelab::server::instance()->get(number, [name UTF8String]);
if(number.size() < 1) return; if(number.size() < 1) return;
[textbox setText:[NSString stringWithFormat:@"%g", number[0].getValue()]]; [textbox setText:[NSString stringWithFormat:@"%g", number[0].getValue()]];
[textbox setEnabled:(number[0].getReadOnly() ? FALSE : TRUE)];
[label setEnabled:(number[0].getReadOnly() ? FALSE : TRUE)];
[textbox reloadInputViews]; [textbox reloadInputViews];
} }
...@@ -467,14 +442,6 @@ ...@@ -467,14 +442,6 @@
return textbox; return textbox;
} }
-(bool)isReadOnly
{
std::vector<onelab::number> number;
onelab::server::instance()->get(number, [name UTF8String]);
if(number.size() < 1) return YES;
return number[0].getReadOnly();
}
+(double)getHeight +(double)getHeight
{ {
return 60.f; return 60.f;
......
...@@ -133,8 +133,7 @@ ...@@ -133,8 +133,7 @@
} }
else if(p.getMin() >= p.getMax() || else if(p.getMin() >= p.getMax() ||
p.getMin() == -onelab::number::maxNumber() || p.getMin() == -onelab::number::maxNumber() ||
p.getMax() == onelab::number::maxNumber() || p.getMax() == onelab::number::maxNumber()) { // text box
p.getReadOnly()) { // text box
ParameterNumberTextbox *param = [[ParameterNumberTextbox alloc] initWithNumber:p]; ParameterNumberTextbox *param = [[ParameterNumberTextbox alloc] initWithNumber:p];
[section addObject:param]; [section addObject:param];
} }
...@@ -378,7 +377,6 @@ NSString *GetSectionTitle(NSString *name) ...@@ -378,7 +377,6 @@ NSString *GetSectionTitle(NSString *name)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
} }
[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
[cell setUserInteractionEnabled:!([tmp isReadOnly])];
[tmp setLabelFrame:CGRectMake(20, 5, tableView.frame.size.width - 40, cell.frame.size.height/2)]; [tmp setLabelFrame:CGRectMake(20, 5, tableView.frame.size.width - 40, cell.frame.size.height/2)];
[cell addSubview:[tmp getLabel]]; [cell addSubview:[tmp getLabel]];
if([tmp isKindOfClass:[ParameterStringList class]]) { if([tmp isKindOfClass:[ParameterStringList class]]) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment