forked from Adapptor/QuickDialog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSampleDataBuilder.m
More file actions
701 lines (545 loc) · 31.2 KB
/
Copy pathSampleDataBuilder.m
File metadata and controls
701 lines (545 loc) · 31.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
//
// Copyright 2011 ESCOZ Inc - http://escoz.com
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
// ANY KIND, either express or implied. See the License for the specific language governing
// permissions and limitations under the License.
//
#import <objc/runtime.h>
#import "SampleDataBuilder.h"
#import "QDynamicDataSection.h"
#import "PeriodPickerValueParser.h"
@implementation SampleDataBuilder
+ (QRootElement *)createWithInitDefault {
QRootElement *subForm = [[QRootElement alloc] init];
subForm.grouped = YES;
subForm.title = @"Default Initialization";
QSection *subsection = [[QSection alloc] initWithTitle:@"SubSection"];
[subForm addSection:subsection];
[subsection addElement:[[QLabelElement alloc] init]];
[subsection addElement:[[QBadgeElement alloc] init]];
[subsection addElement:[[QBooleanElement alloc] init]];
[subsection addElement:[[QButtonElement alloc] init]];
[subsection addElement:[[QDateTimeInlineElement alloc] init]];
[subsection addElement:[[QFloatElement alloc] init]];
[subsection addElement:[[QMapElement alloc] init]];
[subsection addElement:[[QPickerElement alloc] init]];
[subsection addElement:[[QRadioElement alloc] init]];
[subsection addElement:[[QRadioItemElement alloc] init]];
[subsection addElement:[[QTextElement alloc] init]];
[subsection addElement:[[QWebElement alloc] init]];
return subForm;
}
+ (QRootElement *)createWithInitAndKey {
QRootElement *subForm = [[QRootElement alloc] init];
subForm.grouped = YES;
subForm.title = @"Initialization With Key";
QSection *subsection = [[QSection alloc] initWithTitle:@"SubSection"];
[subForm addSection:subsection];
[subsection addElement:[[QLabelElement alloc] initWithKey:@"Key1"]];
[subsection addElement:[[QMultilineElement alloc] initWithKey:@"Key3"]];
[subsection addElement:[[QBadgeElement alloc] initWithKey:@"Key1"]];
[subsection addElement:[[QBooleanElement alloc] initWithKey:@"Key1"]];
[subsection addElement:[[QButtonElement alloc] initWithKey:@"Key1"]];
[subsection addElement:[[QDateTimeInlineElement alloc] initWithKey:@"Key1"]];
[subsection addElement:[[QFloatElement alloc] initWithKey:@"Key1"]];
[subsection addElement:[[QMapElement alloc] initWithKey:@"Key1"]];
[subsection addElement:[[QRadioElement alloc] initWithKey:@"Key1"]];
[subsection addElement:[[QRadioItemElement alloc] initWithKey:@"Key1"]];
[subsection addElement:[[QTextElement alloc] initWithKey:@"Key1"]];
[subsection addElement:[[QWebElement alloc] initWithKey:@"Key1"]];
return subForm;
}
+ (QElement *)reallyLongList {
QRootElement *subForm = [[QRootElement alloc] init];
subForm.title = @"Really long list";
QSection *subsection = [[QSection alloc] initWithTitle:@"Long title for the long list of elements"];
for (int i = 0; i<1000; i++){
QBooleanElement *bool1 = [[QBooleanElement alloc] initWithTitle:[NSString stringWithFormat:@"Option %d", i] BoolValue:(i % 3 == 0)];
bool1.onImage = [UIImage imageNamed:@"imgOn"];
bool1.offImage = [UIImage imageNamed:@"imgOff"];
[subsection addElement:bool1];
}
[subForm addSection:subsection];
return subForm;
}
+ (QRootElement *)createSampleFormRoot {
QRootElement *subForm = [[QRootElement alloc] init];
QSection *subsection = [[QSection alloc] initWithTitle:@"SubSection"];
subForm.grouped = YES;
subForm.title = @"Subform";
[subsection addElement:[[QLabelElement alloc] initWithTitle:@"Some title" Value:@"Some value"]];
QEntryElement *elementEntry = [[QEntryElement alloc] initWithTitle:@"Entry" Value:nil Placeholder:@"type here"];
elementEntry.key = @"entryElement";
[subsection addElement:elementEntry];
[subsection addElement:[[QBooleanElement alloc] initWithTitle:@"boolean" BoolValue:YES]];
[subsection addElement:[[QEntryElement alloc] initWithTitle:@"Entry 2" Value:@"Some value" Placeholder:@"type here two"]];
[subForm addSection:subsection];
QSection *subsection2 = [[QSection alloc] init];
QButtonElement *myButton = [[QButtonElement alloc] initWithTitle:@"Change Entry"];
myButton.controllerAction = @"handleChangeEntryExample:";
[subsection2 addElement:myButton];
[subForm addSection:subsection2];
QSection *subsection3 = [[QSection alloc] init];
QBooleanElement *bool1 = [[QBooleanElement alloc] initWithTitle:@"First option" BoolValue:YES];
bool1.onImage = [UIImage imageNamed:@"imgOn"];
bool1.offImage = [UIImage imageNamed:@"imgOff"];
[subsection3 addElement:bool1];
QBooleanElement *bool2 = [[QBooleanElement alloc] initWithTitle:@"Second option" BoolValue:NO];
bool2.onImage = [UIImage imageNamed:@"imgOn"];
bool2.offImage = [UIImage imageNamed:@"imgOff"];
bool2.controllerAction = @"exampleAction:";
[subsection3 addElement:bool2];
QTextElement *element2 = [[QTextElement alloc] initWithText:@"You get all kinds of notifications on your iOS device: new email, texts, friend requests, and more. With Notification Center, you can keep track of them all in one convenient location. Just swipe down from the top of any screen to enter Notification Center. Choose which notifications you want to see. Even see a stock ticker and the current weather. New notifications appear briefly at the top of your screen, without interrupting what you’re doing. And the Lock screen displays notifications so you can act on them with just a swipe. Notification Center is the best way to stay on top of your life’s breaking news."];
element2.font = [UIFont boldSystemFontOfSize:12];
QSection *subsection4 = [[QSection alloc] init];
[subsection4 addElement:element2];
[subForm addSection:subsection3];
[subForm addSection:subsection4];
return subForm;
}
+ (QRootElement *)createSlidersRoot {
QRootElement *sliders = [[QRootElement alloc] init];
sliders.grouped = YES;
sliders.title = @"Sliders";
QSection *detailsSection = [[QSection alloc] initWithTitle:@"Slide left and right"];
[sliders addSection:detailsSection];
[detailsSection addElement:[[QFloatElement alloc] initWithValue:0.5]];
[detailsSection addElement:[[QFloatElement alloc] initWithTitle:@"Short" value:0.7]];
[detailsSection addElement:[[QFloatElement alloc] initWithTitle:@"Really really long title" value:1]];
return sliders;
}
+ (QElement *)createSampleControls {
QRootElement *root = [[QRootElement alloc] init];
root.grouped = YES;
root.title = @"Sample Controls";
QSection *controls = [[QSection alloc] initWithTitle:@"Change something"];
QLabelElement *element1 = [[QLabelElement alloc] initWithTitle:@"Label" Value:@"element"];
QRadioElement *radioElement = [[QRadioElement alloc] initWithItems:[[NSArray alloc] initWithObjects:@"Option 1", @"Option 2", @"Option 3", nil] selected:0 title:@"Radio"];
radioElement.key = @"radio1";
QBooleanElement *boolElement = [[QBooleanElement alloc] initWithTitle:@"Boolean Element" BoolValue:YES];
boolElement.controllerAction = @"exampleAction:";
boolElement.key = @"bool1";
QEntryElement *entryElement = [[QEntryElement alloc] initWithTitle:@"Entry Element" Value:nil Placeholder:@"type here"];
entryElement.key = @"entry1";
NSArray *values = [NSArray arrayWithObjects:@"Ferrari", @"Ms.",@"Mrs.",@"Miss",@"Mr.",@"Prof.",@"A/Prof.",nil];
QAutoEntryElement *autoElement = [[QAutoEntryElement alloc] initWithTitle:@"AutoComplete" value:nil placeholder:@"type letter M"];
autoElement.autoCompleteValues = values;
autoElement.autoCompleteColor = [UIColor orangeColor];
autoElement.key = @"entry2";
controls.footer = @"More controls will be added.";
[controls addElement:element1];
[controls addElement:radioElement];
[controls addElement:entryElement];
[controls addElement:autoElement];
[controls addElement:boolElement];
QDateTimeInlineElement *dateElement = [[QDateTimeInlineElement alloc] initWithTitle:@"DateTime" date:[NSDate date]];
dateElement.key = @"date1";
[controls addElement:dateElement];
QFloatElement *slider = [[QFloatElement alloc] initWithTitle:@"Float Element" value:0.5];
slider.key = @"slider1";
[controls addElement:slider];
QDecimalElement *decimal = [[QDecimalElement alloc] initWithTitle:@"Decimal Element" value:0.5];
decimal.key = @"decimal1";
decimal.fractionDigits = 2;
[controls addElement:decimal];
QLabelElement *element2 = [[QLabelElement alloc] initWithTitle:@"Label Different Height" Value:@"70"];
element2.height = 70;
[controls addElement:element2];
[controls addElement:[QLoadingElement new]];
QSection *btnSection = [[QSection alloc] init];
QButtonElement *button = [[QButtonElement alloc] initWithTitle:@"Show form values"];
button.onSelected = ^{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello"
message:[NSString stringWithFormat:@"1: %d\n2: %@\n3: %d\n4:%@\n5:%f\n6:%f\n7:%@",
radioElement.selected ,
entryElement.textValue,
boolElement.boolValue,
dateElement.dateValue ,
slider.floatValue,
decimal.floatValue,
autoElement.textValue]
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
};
[btnSection addElement:button];
QSection *btnSection2 = [[QSection alloc] init];
QButtonElement *button2 = [[QButtonElement alloc] initWithTitle:@"Fetch into dictionary"];
button2.onSelected = ^{
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[root fetchValueIntoObject:dict];
NSString *msg = @"Values:";
for (NSString *aKey in dict){
msg = [msg stringByAppendingFormat:@"\n- %@: %@", aKey, [dict valueForKey:aKey]];
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello"
message:msg delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
};
[btnSection2 addElement:button2];
btnSection2.footer = @"Here's a really long footer text that could be used to make your users happy!";
QSection *segmented = [[QSection alloc] initWithTitle:@"Here's a long title for this segmented control"];
segmented.footer = @"And heres a long footer text for this segmented control";
QSegmentedElement *segmentedElement = [[QSegmentedElement alloc] initWithItems:[[NSArray alloc] initWithObjects:@"Option 1", @"Option 2", @"Option 3", nil] selected:0 title:@"Radio"];
radioElement.key = @"segmented1";
[segmented addElement:segmentedElement];
[root addSection:controls];
[root addSection:segmented];
[root addSection:btnSection];
[root addSection:btnSection2];
return root;
}
+ (QElement *)createRadioRoot {
QRootElement *root = [[QRootElement alloc] init];
root.title = @"Radio";
root.grouped = YES;
QSection *section1 = [[QSection alloc] initWithTitle:@"Radio element with push"];
[section1 addElement:[[QRadioElement alloc] initWithItems:[NSArray arrayWithObjects:@"Football", @"Soccer", @"Formula 1", nil] selected:0]];
[section1 addElement:[[QRadioElement alloc] initWithItems:[NSArray arrayWithObjects:@"Football", @"Soccer", @"Formula 1", nil] selected:0 title:@"Sport"]];
[section1 addElement:[[QRadioElement alloc] initWithDict:[NSDictionary dictionaryWithObjectsAndKeys:@"FerrariObj", @"Ferrari", @"McLarenObj", @"McLaren", @"MercedesObj", @"Mercedes", nil] selected:0 title:@"With Dict"]];
QRadioElement *elementWithAction = [[QRadioElement alloc] initWithItems:[NSArray arrayWithObjects:@"Ferrari", @"McLaren", @"Lotus", nil] selected:0 title:@"WithAction"];
elementWithAction.controllerAction = @"exampleAction:";
[section1 addElement:elementWithAction];
[root addSection:section1];
QRadioSection *section2 = [[QRadioSection alloc] initWithItems:[NSArray arrayWithObjects:@"Football", @"Soccer", @"Formula 1", nil] selected:0 title:@"Sport"];
section2.onSelected = ^{ NSLog(@"selected index: %d", section2.selected); };
[root addSection:section2];
return root;
}
+ (QElement *)createPickerRoot
{
QRootElement *root = [[QRootElement alloc] init];
root.title = @"Picker";
root.grouped = YES;
QSection *simplePickerSection = [[QSection alloc] initWithTitle:@"Picker element"];
NSMutableArray *component1 = [NSMutableArray array];
for (int i = 1; i <= 12; i++) {
[component1 addObject:[NSString stringWithFormat:@"%d", i]];
}
NSArray *component2 = [NSArray arrayWithObjects:@"A", @"B", nil];
QPickerElement *simplePickerEl =
[[QPickerElement alloc] initWithTitle:@"Key"
items:[NSArray arrayWithObjects:component1, component2, nil]
value:@"3 B"];
simplePickerEl.onValueChanged = ^{ NSLog(@"Selected indexes: %@", [simplePickerEl.selectedIndexes componentsJoinedByString:@","]); };
[simplePickerSection addElement:simplePickerEl];
[root addSection:simplePickerSection];
QSection *customParserSection = [[QSection alloc] initWithTitle:@"Custom value parser"];
PeriodPickerValueParser *periodParser = [[PeriodPickerValueParser alloc] init];
QPickerElement *periodPickerEl =
[[QPickerElement alloc] initWithTitle:@"Period"
items:[NSArray arrayWithObject:periodParser.stringPeriods]
value:[NSNumber numberWithUnsignedInteger:NSMonthCalendarUnit]];
periodPickerEl.valueParser = periodParser;
periodPickerEl.onValueChanged = ^{ NSLog(@"New value: %@", periodPickerEl.value); };
[customParserSection addElement:periodPickerEl];
[root addSection:customParserSection];
return root;
}
+ (QElement *)createSelectRoot
{
QRootElement *root = [[QRootElement alloc] init];
root.title = @"Select";
root.grouped = YES;
QSelectSection *simpleSelectSection =
[[QSelectSection alloc] initWithItems:[NSArray arrayWithObjects:@"Football", @"Soccer", @"Formula 1", nil]
selectedIndexes:nil title:@"Simple select"];
QSelectSection *multipleSelectSection =
[[QSelectSection alloc] initWithItems:[NSArray arrayWithObjects:@"Football", @"Soccer", @"Formula 1", nil]
selectedIndexes:[NSArray arrayWithObjects:
[NSNumber numberWithUnsignedInteger:0],
[NSNumber numberWithUnsignedInteger:1], nil]
title:@"Multiple select"];
multipleSelectSection.multipleAllowed = YES;
[root addSection:simpleSelectSection];
[root addSection:multipleSelectSection];
return root;
}
+ (QRootElement *)createWebAndMapRoot {
QRootElement *root = [[QRootElement alloc] init];
root.title = @"Web and map";
QWebElement *element1 = [[QWebElement alloc] initWithTitle:@"ESCOZ Inc" url:@"http://escoz.com"];
element1.controllerAction = @"handleWebElementControllerAction:";
QWebElement *element2 = [[QWebElement alloc] initWithTitle:@"Quicklytics" url:@"http://escoz.com/quicklytics"];
QMapElement *element4 = [[QMapElement alloc] initWithTitle:@"Florianopolis, Brazil" coordinate:CLLocationCoordinate2DMake(-27.59, -48.55)];
QSection *section1 = [[QSection alloc] init];
[section1 addElement:element1];
[section1 addElement:element2];
[section1 addElement:element4];
[root addSection:section1];
return root;
}
+ (QRootElement *)createTextRoot {
QRootElement *root = [[QRootElement alloc] init];
root.title = @"Text";
QTextElement *element1 = [[QTextElement alloc] initWithText:
@"Preparing for her flight\n"
"I held with all my might\n"
"Fearing my deepest fright\n"
"She walked into the night\n"
"She turned for one last look\n"
"She looked me in the eye\n"
"I said, \"I Love You...\n"
"Good-bye\""];
QTextElement *element2 = [[QTextElement alloc] initWithText:@"You get all kinds of notifications on your iOS device: new email, texts, friend requests, and more. With Notification Center, you can keep track of them all in one convenient location. Just swipe down from the top of any screen to enter Notification Center. Choose which notifications you want to see. Even see a stock ticker and the current weather. New notifications appear briefly at the top of your screen, without interrupting what you’re doing. And the Lock screen displays notifications so you can act on them with just a swipe. Notification Center is the best way to stay on top of your life’s breaking news."];
element2.font = [UIFont boldSystemFontOfSize:12];
QTextElement *element3 = [[QTextElement alloc] initWithText:@"Quicklytics App!"];
element3.font = [UIFont fontWithName:@"Cochin-BoldItalic" size:24];
element3.color = [UIColor blueColor];
QSection *section1 = [[QSection alloc] init];
[section1 addElement:element3];
[section1 addElement:element1];
[section1 addElement:element2];
[root addSection:section1];
return root;
}
+ (QRootElement *)createLabelsRoot {
QRootElement *root = [[QRootElement alloc] init];
root.title = @"Labels";
root.grouped = YES;
QSection *s1 = [[QSection alloc] initWithTitle:@"LabelElement"];
[s1 addElement:[[QLabelElement alloc] initWithTitle:@"With no value" Value:nil]];
[s1 addElement:[[QLabelElement alloc] initWithTitle:@"With a value" Value:@"Value"]];
[s1 addElement:[[QLabelElement alloc] initWithTitle:@"Or a simple number" Value:@"123"]];
[s1 addElement:[[QLabelElement alloc] initWithTitle:@"Long text long text long text long text" Value:@"this is the value"]];
QSection *s2 = [[QSection alloc] initWithTitle:@"BadgeElement"];
QBadgeElement *badge1 = [[QBadgeElement alloc] initWithTitle:@"With a badge" Value:@"1"];
[s2 addElement:badge1];
QBadgeElement *badge2 = [[QBadgeElement alloc] initWithTitle:@"With a pink badge" Value:@"123"];
badge2.badgeColor = [UIColor colorWithRed:0.9518 green:0.3862 blue:0.4113 alpha:1.0000];
[s2 addElement:badge2];
QSection *secImg = [[QSection alloc] initWithTitle:@"Images"];
QLabelElement *b1 = [[QLabelElement alloc] initWithTitle:@"Processor" Value:@"OK"];
b1.image = [UIImage imageNamed:@"intel"];
[secImg addElement:b1];
QLabelElement *b2 = [[QLabelElement alloc] initWithTitle:@"iPhone" Value:@"OK"];
b2.image = [UIImage imageNamed:@"iPhone"];
[secImg addElement:b2];
QBadgeElement *b3 = [[QBadgeElement alloc] initWithTitle:@"Keyboard" Value:@"ERROR"];
b3.image = [UIImage imageNamed:@"keyboard"];
b3.badgeColor = [UIColor redColor];
[secImg addElement:b3];
QBadgeElement *badge3 = [[QBadgeElement alloc] initWithTitle:@"With some action" Value:@"123"];
badge3.badgeColor = [UIColor purpleColor];
QSection *sec = [[QSection alloc] initWithTitle:@"Jazzin.."];
[badge3 addSection:sec];
QBadgeElement *b4 = [[QBadgeElement alloc] initWithTitle:@"With a really really really long title" Value:@"YEAH"];
[s2 addElement:b4];
[s2 addElement:badge3];
[sec addElement:[[QBadgeElement alloc] initWithTitle:@"Test" Value:@"0"]];
[sec addElement:[[QBadgeElement alloc] initWithTitle:@"Test 2" Value:@"10"]];
[sec addElement:[[QBadgeElement alloc] initWithTitle:@"Test 3" Value:@"200"]];
[sec addElement:[[QBadgeElement alloc] initWithTitle:@"Test 4" Value:@"1000"]];
[sec addElement:[[QBadgeElement alloc] initWithTitle:@"Test 5" Value:@"TEST"]];
QSection *s3 = [[QSection alloc] initWithTitle:@"Labeling policies"];
QLabelElement *trimTitleEl = [[QLabelElement alloc] initWithTitle:@"QLabelingPolicyTrimTitle" Value:@"really really really long value"];
trimTitleEl.labelingPolicy = QLabelingPolicyTrimTitle; // this is default
[s3 addElement:trimTitleEl];
QLabelElement *trimValueEl = [[QLabelElement alloc] initWithTitle:@"QLabelingPolicyTrimValue" Value:@"really really really long value"];
trimValueEl.labelingPolicy = QLabelingPolicyTrimValue;
[s3 addElement:trimValueEl];
[root addSection:s1];
[root addSection:s2];
[root addSection:s3];
[root addSection:secImg];
return root;
}
+ (QRootElement *)createEntryRoot {
QRootElement *root = [[QRootElement alloc] init];
root.title = @"Entry";
root.grouped = YES;
QSection *firstSection = [[QSection alloc] initWithTitle:@"Entry Elements"];
[firstSection addElement:[[QEntryElement alloc] initWithTitle:nil Value:nil Placeholder:@"placeholder"]];
[firstSection addElement:[[QEntryElement alloc] initWithTitle:@"With Title" Value:nil Placeholder:@"text here"]];
[firstSection addElement:[[QEntryElement alloc] initWithTitle:@"With Very Long Title" Value:@"" Placeholder:@"text"]];
[root addSection:firstSection];
QSection *prefixSuffixSection = [[QSection alloc] initWithTitle:@"Prefix/suffix"];
prefixSuffixSection.footer = @"Prefix/suffix is only displayed, they're not stored in textValue";
QEntryElement *prefixElement = [[QEntryElement alloc] initWithTitle:nil Value:nil Placeholder:@"with prefix"];
prefixElement.keyboardType = UIKeyboardTypeNumberPad;
prefixElement.prefix = @"$";
QEntryElement *suffixElement = [[QEntryElement alloc] initWithTitle:nil Value:nil Placeholder:@"with suffix"];
suffixElement.keyboardType = UIKeyboardTypeNumberPad;
suffixElement.suffix = @" km";
QEntryElement *prefixSuffixElement = [[QEntryElement alloc] initWithTitle:nil Value:nil Placeholder:@"with prefix and suffix"];
prefixSuffixElement.prefix = @"* ";
prefixSuffixElement.suffix = @" *";
[prefixSuffixSection addElement:prefixElement];
[prefixSuffixSection addElement:suffixElement];
[prefixSuffixSection addElement:prefixSuffixElement];
[root addSection:prefixSuffixSection];
QSection *traitsSection = [[QSection alloc] initWithTitle:@"UITextInputTraits"];
QEntryElement *secureElement = [[QEntryElement alloc] initWithTitle:@"Secure" Value:@"" Placeholder:@"YES"];
secureElement.secureTextEntry = YES;
[traitsSection addElement:secureElement];
QEntryElement *keyboardTypeElement = [[QEntryElement alloc] initWithTitle:@"KB Type" Value:@"" Placeholder:@"NumberPad"];
keyboardTypeElement.keyboardType = UIKeyboardTypeNumberPad;
[traitsSection addElement:keyboardTypeElement];
QEntryElement *keyboardAppearanceElement = [[QEntryElement alloc] initWithTitle:@"KB Appearance" Value:@"" Placeholder:@"Alert"];
keyboardAppearanceElement.keyboardAppearance = UIKeyboardAppearanceAlert;
[traitsSection addElement:keyboardAppearanceElement];
QEntryElement *correctionElement = [[QEntryElement alloc] initWithTitle:@"Correction" Value:@"" Placeholder:@"No"];
correctionElement.autocorrectionType = UITextAutocorrectionTypeNo;
[traitsSection addElement:correctionElement];
QEntryElement *capitalizationElement = [[QEntryElement alloc] initWithTitle:@"Capitalization" Value:@"" Placeholder:@"AllCharacters"];
capitalizationElement.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
[traitsSection addElement:capitalizationElement];
QEntryElement *googleElement = [[QEntryElement alloc] initWithTitle:@"Return Key" Value:@"" Placeholder:@"Google"];
googleElement.returnKeyType = UIReturnKeyGoogle;
[traitsSection addElement:googleElement];
QEntryElement *enableReturnElement = [[QEntryElement alloc] initWithTitle:@"Auto Return" Value:@"" Placeholder:@"YES"];
enableReturnElement.enablesReturnKeyAutomatically = YES;
[traitsSection addElement:enableReturnElement];
QSection *multilineSection = [[QSection alloc] initWithTitle:@"Entry Elements"];
QMultilineElement *multiline = [QMultilineElement new];
multiline.title = @"Multiline entry";
[multilineSection addElement:multiline];
[root addSection:traitsSection];
[root addSection:multilineSection];
return root;
}
+ (QRootElement *)createSortingRoot {
QRootElement *root = [[QRootElement alloc] init];
root.title = @"Sorting";
root.grouped = YES;
QSortingSection *sortingSection = [[QSortingSection alloc] init];
sortingSection.key = @"sortedSection";
[sortingSection addElement:[[QLabelElement alloc] initWithTitle:@"First" Value:@"1"]];
[sortingSection addElement:[[QLabelElement alloc] initWithTitle:@"Second" Value:@"2"]];
[sortingSection addElement:[[QLabelElement alloc] initWithTitle:@"Third" Value:@"3"]];
[sortingSection addElement:[[QLabelElement alloc] initWithTitle:@"Forth" Value:@"4"]];
[sortingSection addElement:[[QLabelElement alloc] initWithTitle:@"Fifth" Value:@"5"]];
int i = 1;
for (QElement * el in sortingSection.elements){
el.key = [NSString stringWithFormat:@"item %d", i++];
}
[root addSection:sortingSection];
QSection *action = [[QSection alloc] init];
QButtonElement *button = [[QButtonElement alloc] initWithTitle:@"Read Order"];
button.onSelected = ^{
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[sortingSection fetchValueIntoObject:dict];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello"
message:[NSString stringWithFormat:@"Order: %@", dict ]
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
};
[action addElement:button];
[root addSection:action];
return root;
}
+ (QRootElement *)createDateTimeRoot {
QRootElement *root = [[QRootElement alloc] init];
root.title = @"Date Time";
root.grouped = YES;
QSection *section = [[QSection alloc] init];
section.title = @"Inline editing";
QDateTimeInlineElement *el2 = [[QDateTimeInlineElement alloc] initWithTitle:@"Today" date:[NSDate date]];
[section addElement:el2];
QDateTimeInlineElement *el3 = [[QDateTimeInlineElement alloc] initWithTitle:@"Date only" date:[NSDate date]];
el3.mode = UIDatePickerModeDate;
[section addElement:el3];
QDateTimeInlineElement *el4 = [[QDateTimeInlineElement alloc] initWithTitle:@"Time only" date:[NSDate date]];
el4.mode = UIDatePickerModeTime;
[section addElement:el4];
QDateTimeInlineElement *elDiffTime = [[QDateTimeInlineElement alloc] initWithTitle:@"Different date" date:
[NSDate dateWithTimeIntervalSinceNow:-36000]];
[section addElement:elDiffTime];
QSection *section2 = [[QSection alloc] init];
section2.title = @"Push editing";
QDateTimeElement *el5 = [[QDateTimeElement alloc] initWithTitle:@"Time only" date:[NSDate date]];
el5.mode = UIDatePickerModeTime;
[section2 addElement:el5];
QDateTimeElement *el6 = [[QDateTimeElement alloc] initWithTitle:@"Date only" date:[NSDate date]];
el6.mode = UIDatePickerModeDate;
[section2 addElement:el6];
QDateTimeElement *el7 = [[QDateTimeElement alloc] initWithTitle:@"Full Date" date:[NSDate date]];
el7.mode = UIDatePickerModeDateAndTime;
[section2 addElement:el7];
[root addSection:section];
[root addSection:section2];
return root;
}
+ (QElement *)createDynamicSectionRoot {
QRootElement *const root = [[QRootElement alloc] init ];
root.title = @"Dynamic Data Sections";
root.grouped = YES;
QDynamicDataSection *defaultSection = [QDynamicDataSection new];
defaultSection.title = @"Default: loading";
defaultSection.emptyMessage = @"This is empty";
[root addSection: defaultSection];
QDynamicDataSection *emptySection = [QDynamicDataSection new];
emptySection.title = @"Empty: elements = empty list";
emptySection.bind = @"iterate:empty";
emptySection.emptyMessage = @"This is empty";
emptySection.elements = [NSMutableArray array];
[root addSection: emptySection];
QDynamicDataSection *loadingSection = [QDynamicDataSection new];
loadingSection.title = @"Loading: elements = nil";
loadingSection.bind = @"iterate:nil";
loadingSection.elements = nil;
[root addSection: loadingSection];
QDynamicDataSection *section = [QDynamicDataSection new];
section.title = @"Normal: with elements";
section.bind = @"iterate:something";
section.elementTemplate = [NSDictionary dictionaryWithObjectsAndKeys:
@"QLabelElement", @"type",
@"Something here", @"title",
nil];
[root addSection: section];
[root bindToObject:[NSDictionary dictionaryWithObjectsAndKeys:
[NSArray array], @"empty",
[NSArray arrayWithObjects:@"first", @"second", nil], @"something",
nil]];
return root;
}
+ (QRootElement *)create {
QRootElement *root = [[QRootElement alloc] init];
root.grouped = YES;
root.title = @"QuickForms!";
QSection *sectionSamples = [[QSection alloc] init];
sectionSamples.headerView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"quickdialog"]];
[sectionSamples addElement:[[QRootElement alloc] initWithJSONFile:@"loginform"]];
[sectionSamples addElement:[self createSampleControls]];
[sectionSamples addElement:[self createSampleFormRoot]];
[sectionSamples addElement:[self reallyLongList]];
QSection *sectionElements = [[QSection alloc] initWithTitle:@"Usage examples"];
[sectionElements addElement:[self createLabelsRoot]];
[sectionElements addElement:[self createEntryRoot]];
[sectionElements addElement:[self createSlidersRoot]];
[sectionElements addElement:[self createRadioRoot]];
[sectionElements addElement:[self createPickerRoot]];
[sectionElements addElement:[self createSelectRoot]];
[sectionElements addElement:[self createWebAndMapRoot]];
[sectionElements addElement:[self createTextRoot]];
[sectionElements addElement:[self createDateTimeRoot]];
[sectionElements addElement:[self createSortingRoot]];
[sectionElements addElement:[self createDynamicSectionRoot]];
[sectionElements addElement:[self createWithInitDefault]];
[sectionElements addElement:[self createWithInitAndKey]];
[root addSection:sectionSamples];
[root addSection:sectionElements];
if (objc_getClass("NSJSONSerialization")!=nil) {
QSection *sectionJson = [[QSection alloc] initWithTitle:@"JSON Samples"];
[sectionJson addElement:[[QRootElement alloc] initWithJSONFile:@"loginform"]];
[sectionJson addElement:[[QRootElement alloc] initWithJSONFile:@"sample"]];
[sectionJson addElement:[[QRootElement alloc] initWithJSONFile:@"jsondatasample"]];
[sectionJson addElement:[[QRootElement alloc] initWithJSONFile:@"jsonadvancedsample"]];
[sectionJson addElement:[[QRootElement alloc] initWithJSONFile:@"jsonremote"]];
NSString *jsonSample = @"{\"title\": \"In memory struct\",\n"
" \"controllerName\": \"LoginController\", \"sections\":[]}";
id const parsedJson = [NSJSONSerialization JSONObjectWithData:[jsonSample dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableLeaves error:nil];
[sectionJson addElement:[[QRootElement alloc] initWithJSON:parsedJson andData:nil]];
[root addSection:sectionJson];
}
return root;
}
@end