Merge lp:~rpadovani/ubuntu-calculator-app/history into lp:ubuntu-calculator-app

Proposed by Riccardo Padovani
Status: Merged
Merged at revision: 20
Proposed branch: lp:~rpadovani/ubuntu-calculator-app/history
Merge into: lp:ubuntu-calculator-app
Diff against target: 160 lines (+78/-11)
3 files modified
app/engine/CalculationHistory.qml (+70/-0)
app/ubuntu-calculator-app.qml (+6/-8)
app/ui/Screen.qml (+2/-3)
To merge this branch: bzr merge lp:~rpadovani/ubuntu-calculator-app/history
Reviewer Review Type Date Requested Status
Bartosz Kosiorek Approve
Mihir Soni Needs Information
Review via email: mp+243559@code.launchpad.net

Commit message

Created the database

Description of the change

Create the backend for the database.

Added function to create and delete calcs in the database

To post a comment you must log in.
Revision history for this message
Mihir Soni (mihirsoni) wrote :

Hi This looks great.

I can see only two fields in DB , I believe we need datetime as well ?

review: Needs Information
Revision history for this message
Bartosz Kosiorek (gang65) wrote :

+1 to save also current date.

According to this document:
https://docs.google.com/presentation/d/1EiIELGizPHrd0TY7JdNwULbiqPYfOyEEI5CS87n7QlY/edit#slide=id.g4d8c681df_076

We should also save date in history

review: Needs Fixing
Revision history for this message
Bartosz Kosiorek (gang65) wrote :

After save history with many entries, and reopen calculator, the keypad are gone.

I think we should display keypad by default after run calculator.

Revision history for this message
Bartosz Kosiorek (gang65) wrote :

Please investigate docId potential issue

review: Needs Fixing
21. By Riccardo Padovani

Fixed vars name

Revision history for this message
Riccardo Padovani (rpadovani) wrote :

Fixed all vars name as by comment.

The docId is univoque, because Database doesn't delete index of deleted docs, so calcDatabase.listDocs().length returns number of all documents added in the database, also if after they were deleted

Revision history for this message
Bartosz Kosiorek (gang65) wrote :

Looks ok for me

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'app/engine/CalculationHistory.qml'
2--- app/engine/CalculationHistory.qml 1970-01-01 00:00:00 +0000
3+++ app/engine/CalculationHistory.qml 2014-12-03 22:51:51 +0000
4@@ -0,0 +1,70 @@
5+/*
6+ * Copyright (C) 2014 Canonical, Ltd.
7+ *
8+ * This program is free software; you can redistribute it and/or modify
9+ * it under the terms of the GNU General Public License as published by
10+ * the Free Software Foundation; version 3.
11+ *
12+ * This program is distributed in the hope that it will be useful,
13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+ * GNU General Public License for more details.
16+ *
17+ * You should have received a copy of the GNU General Public License
18+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
19+ */
20+import QtQuick 2.3
21+import Ubuntu.Components 1.1
22+import U1db 1.0 as U1db
23+
24+Item {
25+ U1db.Database {
26+ id: calculationHistoryDatabase
27+ path: "com.ubuntu.calculator"
28+ }
29+
30+ U1db.Document {
31+ id: calculationDocument
32+ database: calculationHistoryDatabase
33+ }
34+
35+ U1db.Index {
36+ id: index
37+ database: calculationHistoryDatabase
38+ name: "byDocId"
39+ expression: ["formula", "result"]
40+ }
41+
42+ U1db.Query {
43+ id: query
44+ index: index
45+ }
46+
47+ SortFilterModel {
48+ id: sortedHistory
49+ model: query
50+ sort.property: "docId"
51+ sort.order: Qt.DescendingOrder
52+ }
53+
54+ function addCalculationToDatabase(formula, result) {
55+ var docId = calculationHistoryDatabase.listDocs().length;
56+ var calculationToAdd = calculationDocument;
57+
58+ calculationToAdd.docId = docId;
59+ calculationToAdd.contents = {
60+ 'formula': formula,
61+ 'result': result
62+ };
63+
64+ calculationToAdd.create = true;
65+ }
66+
67+ function getContents() {
68+ return sortedHistory;
69+ }
70+
71+ function deleteCalc(docId) {
72+ calculationHistoryDatabase.deleteDoc(docId);
73+ }
74+}
75
76=== modified file 'app/ubuntu-calculator-app.qml'
77--- app/ubuntu-calculator-app.qml 2014-12-02 17:50:22 +0000
78+++ app/ubuntu-calculator-app.qml 2014-12-03 22:51:51 +0000
79@@ -20,6 +20,7 @@
80 import Ubuntu.Components.Themes.Ambiance 0.1
81
82 import "ui"
83+import "engine"
84 import "engine/math.js" as MathJs
85
86 MainView {
87@@ -222,16 +223,15 @@
88 return;
89 }
90
91- historyModel.insert(0, {"formulaToDisplay":returnFormulaToDisplay(longFormula), "result":displayedInputText});
92+ calculationHistory.addCalculationToDatabase(returnFormulaToDisplay(longFormula), displayedInputText);
93 longFormula = result;
94 shortFormula = result;
95 numberOfOpenedBrackets = 0;
96 isAllowedToAddDot = false;
97 }
98
99- ListModel {
100- // TODO: create a separate component with storage management
101- id: historyModel
102+ CalculationHistory {
103+ id: calculationHistory
104 }
105
106 ListView {
107@@ -246,14 +246,14 @@
108 // and we set the position of the keyboard to bottom
109 verticalLayoutDirection: ListView.BottomToTop
110
111- model: historyModel
112+ model: calculationHistory.getContents()
113
114 delegate: Screen {
115 width: parent.width
116 }
117
118 header: Column {
119- width: parent.width
120+ width: parent ? parent.width : 0
121
122 TextField {
123 height: units.gu(6)
124@@ -282,8 +282,6 @@
125 selectByMouse: true
126 }
127
128- // TODO: insert here actual screen
129-
130 CalcKeyboard {
131 id: calcKeyboard
132 }
133
134=== modified file 'app/ui/Screen.qml'
135--- app/ui/Screen.qml 2014-11-28 00:01:50 +0000
136+++ app/ui/Screen.qml 2014-12-03 22:51:51 +0000
137@@ -18,7 +18,6 @@
138
139 import QtQuick 2.3
140 import Ubuntu.Components 1.1
141-import Ubuntu.Components.Themes.Ambiance 0.1
142 import Ubuntu.Components.ListItems 1.0 as ListItem
143
144 ListItem.Standard {
145@@ -26,13 +25,13 @@
146 Row {
147 id: row
148 Text {
149- text: formulaToDisplay;
150+ text: contents.formula
151 }
152 Text {
153 text: "=";
154 }
155 Text {
156- text: result;
157+ text: contents.result
158 font.bold: true
159 }
160 }

Subscribers

People subscribed via source and target branches