瀏覽代碼

Add color specification to roasting spec editor

Neal Wilson 7 年之前
父節點
當前提交
2cf19a3f5b
共有 1 個文件被更改,包括 121 次插入18 次删除
  1. 121
    18
      config/Windows/roastspec.xml

+ 121
- 18
config/Windows/roastspec.xml 查看文件

@@ -7,16 +7,50 @@
7 7
                     <query>SELECT id, name FROM items WHERE id IN (SELECT item FROM current_items) ORDER BY name</query>
8 8
                 </sqldrop>
9 9
             </layout>
10
-            <layout type="horizontal">
11
-                <label>Expected % weight loss:</label>
12
-                <line validator="numeric" id="expectedloss" />
13
-            </layout>
14
-            <layout type="horizontal">
15
-                <label>Tolerance</label>
16
-                <line validator="numeric" id="tolerance" />
10
+            <tabbar id="tabs" />
11
+            <layout type="stack" id="pages">
12
+                <page>
13
+                    <layout type="vertical">
14
+                        <layout type="horizontal">
15
+                            <label>Expected % weight loss:</label>
16
+                            <line validator="numeric" id="expectedloss" />
17
+                        </layout>
18
+                        <layout type="horizontal">
19
+                            <label>Tolerance</label>
20
+                            <line validator="numeric" id="tolerance" />
21
+                        </layout>
22
+                        <stretch />
23
+                    </layout>
24
+                </page>
25
+                <page>
26
+                    <layout type="vertical">
27
+                        <layout type="horizontal">
28
+                            <label>Whole color:</label>
29
+                            <line validator="numeric" id="expectedwhole" />
30
+                        </layout>
31
+                        <layout type="horizontal">
32
+                            <label>Tolerance:</label>
33
+                            <line validator="numeric" id="wholetolerance" />
34
+                        </layout>
35
+                        <layout type="horizontal">
36
+                            <label>Ground color:</label>
37
+                            <line validator="numeric" id="expectedground" />
38
+                        </layout>
39
+                        <layout type="horizontal">
40
+                            <label>Tolerance:</label>
41
+                            <line validator="numeric" id="groundtolerance" />
42
+                        </layout>
43
+                        <stretch />
44
+                    </layout>
45
+                </page>
46
+                <page>
47
+                    <layout type="vertical">
48
+                        <label>Specification Notes:</label>
49
+                        <textarea id="notes" />
50
+                        <stretch />
51
+                    </layout>
52
+                </page>
17 53
             </layout>
18
-            <label>Specification Notes:</label>
19
-            <textarea id="notes" />
20 54
             <layout type="horizontal">
21 55
                 <stretch />
22 56
                 <button id="save" type="push" name="Save" />
@@ -27,14 +61,26 @@
27 61
         <![CDATA[
28 62
             var window = this;
29 63
             this.windowTitle = TTR("roastspec", "Typica - Edit Roasting Specification");
64
+            var tabs = findChildObject(this, 'tabs');
65
+            tabs.addTab("Weight Loss");
66
+            tabs.addTab("Color");
67
+            tabs.addTab("Notes");
68
+            var pages = findChildObject(this, 'pages');
69
+            tabs.currentChanged.connect(function(index) {
70
+                pages.setCurrentIndex(index);
71
+            });
30 72
             var selector = findChildObject(this, 'currentitems');
31 73
             var expected = findChildObject(this, 'expectedloss');
32 74
             var tolerance = findChildObject(this, 'tolerance');
33 75
             var notes = findChildObject(this, 'notes');
34 76
             var savebutton = findChildObject(this, 'save');
77
+            var wholecolor = findChildObject(this, 'expectedwhole');
78
+            var groundcolor = findChildObject(this, 'expectedground');
79
+            var wholetolerance = findChildObject(this, 'wholetolerance');
80
+            var groundtolerance = findChildObject(this, 'groundtolerance');
35 81
             var updateDisplay = function() {
36 82
                 var query = new QSqlQuery();
37
-                query.prepare("SELECT loss, tolerance, notes FROM roasting_specification WHERE item = :id1 AND time = (SELECT max(time) FROM roasting_specification WHERE item = :id2)");
83
+                query.prepare("SELECT loss, tolerance, notes, spec FROM roasting_specification WHERE item = :id1 AND time = (SELECT max(time) FROM roasting_specification WHERE item = :id2)");
38 84
                 query.bind(":id1", selector.currentData());
39 85
                 query.bind(":id2", selector.currentData());
40 86
                 query.exec();
@@ -50,11 +96,38 @@
50 96
                         tolerance.text = "";
51 97
                     }
52 98
                     notes.plainText = query.value(2);
99
+                    if(query.value(3).length > 0) {
100
+                        var spec = JSON.parse(query.value(3));
101
+                        if(spec.color.whole.expected === undefined) {
102
+                            wholecolor.text = "";
103
+                        } else {
104
+                            wholecolor.text = spec.color.whole.expected;
105
+                        }
106
+                        if(spec.color.whole.tolerance === undefined) {
107
+                            wholetolerance.text = "";
108
+                        } else {
109
+                            wholetolerance.text = spec.color.whole.tolerance;
110
+                        }
111
+                        if(spec.color.ground.expected === undefined) {
112
+                            groundcolor.text = "";
113
+                        } else {
114
+                            groundcolor.text = spec.color.ground.expected;
115
+                        }
116
+                        if(spec.color.ground.tolerance === undefined) {
117
+                            groundtolerance.text = "";
118
+                        } else {
119
+                            groundtolerance.text = spec.color.ground.tolerance;
120
+                        }
121
+                    }
53 122
                 } else {
54 123
                     expected.text = "";
55 124
                     tolerance.text = "";
56 125
                     notes.plainText = "";
57
-                }                
126
+                    wholecolor.text = "";
127
+                    wholetolerance.text = "";
128
+                    groundcolor.text = "";
129
+                    groundtolerance.text = "";
130
+                }
58 131
                 query = query.invalidate();
59 132
             };
60 133
             updateDisplay();
@@ -62,19 +135,47 @@
62 135
                 updateDisplay();
63 136
             });
64 137
             savebutton.clicked.connect(function() {
138
+                var specobject = new Object;
65 139
                 var query = new QSqlQuery();
66 140
                 var columnspec = "time, item, ";
67 141
                 var valuespec = "'now', :id, ";
68 142
                 if(expected.text.length > 0) {
69 143
                     columnspec += "loss, ";
70 144
                     valuespec += ":loss, ";
145
+                    var lossspec = new Object;
146
+                    lossspec.expected = expected.text;
147
+                    if(tolerance.text.length > 0) {
148
+                        columnspec += "tolerance, ";
149
+                        valuespec += ":tolerance, ";
150
+                        lossspec.tolerance = tolerance.text;
151
+                    }
152
+                    specobject.loss = lossspec;
71 153
                 }
72
-                if(tolerance.text.length > 0) {
73
-                    columnspec += "tolerance, ";
74
-                    valuespec += ":tolerance, ";
154
+                colorspec = new Object;
155
+                if(wholecolor.text.length > 0) {
156
+                    wholespec = new Object;
157
+                    wholespec.expected = wholecolor.text;
158
+                    if(wholetolerance.text.length > 0) {
159
+                        wholespec.tolerance = wholetolerance.text;
160
+                    }
161
+                    colorspec.whole = wholespec;
162
+                }
163
+                if(groundcolor.text.length > 0) {
164
+                    groundspec = new Object;
165
+                    groundspec.expected = groundcolor.text;
166
+                    if(groundtolerance.text.length > 0) {
167
+                        groundspec.tolerance = groundtolerance.text;
168
+                    }
169
+                    colorspec.ground = groundspec;
170
+                }
171
+                if(colorspec.whole || colorspec.ground) {
172
+                    specobject.color = colorspec;
173
+                }
174
+                if(notes.plainText.length > 0) {
175
+                    specobject.notes = notes.plainText;
75 176
                 }
76
-                columnspec += "notes";
77
-                valuespec += ":notes";
177
+                columnspec += "notes, spec";
178
+                valuespec += ":notes, :spec";
78 179
                 query.prepare("INSERT INTO roasting_specification (" + columnspec + ") VALUES (" + valuespec + ")");
79 180
                 query.bind(":id", selector.currentData());
80 181
                 if(expected.text.length > 0) {
@@ -84,9 +185,11 @@
84 185
                     query.bind(":tolerance", Number(tolerance.text) / 100);
85 186
                 }
86 187
                 query.bind(":notes", notes.plainText);
188
+                query.bind(":spec", JSON.stringify(specobject));
87 189
                 query.exec();
88
-                window.close();
190
+                displayInfo(TTR("roastspec", "New Specification Saved"),
191
+                            TTR("roastspec", "New roasting specification saved"));
89 192
             });
90 193
         ]]>
91 194
     </program>
92
-</window>
195
+</window>

Loading…
取消
儲存