forked from SiriusDely/Cascades-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.hpp
99 lines (75 loc) · 3.07 KB
/
app.hpp
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
/* Copyright (c) 2012, 2013 BlackBerry Limited.
*
* 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.
*/
#ifndef APP_HPP
#define APP_HPP
#include <bb/cascades/GroupDataModel>
class Storage;
using namespace bb::cascades;
/*
* @brief Declaration of our application's class (as opposed to the BB Cascades
* application class that contains our application).
*/
class App : public QObject
{
// Classes that inherit from QObject must have the Q_OBJECT macro so
// the meta-object compiler (MOC) can add supporting code to the application.
Q_OBJECT
Q_PROPERTY(bb::cascades::DataModel* dataModel READ dataModel CONSTANT)
public:
// Describes the possible storage locations
enum StorageLocations
{
StoreInQSettings, ///< objects are stored in QSettings
StoreInFile ///< objects are stored in custom files
};
// This allows the enum to be referred to in the qml file.
// Note: the class also has to be registered using qmlRegisterType().
// See the main.cpp file.
Q_ENUMS(StorageLocations)
// Creates a new App object
App(QObject *parent = 0);
// destroys the App object
~App();
// Creates a new person object and saves it.
Q_INVOKABLE bool addObject(const QString &firstName, const QString &lastName);
// Read all the objects from the selected storage location and
// put them in the data model
Q_INVOKABLE void refreshObjects();
// Remove all the objects from the selected storage location.
Q_INVOKABLE void clearObjects();
// Change the first and last name of the person with the
// provided id. Update the data model and storage.
Q_INVOKABLE bool updateObject(const QString &id, const QString &firstName, const QString &lastName);
// Delete the person with the given id from the selected storage location.
Q_INVOKABLE bool deleteObject(const QString &id);
// Change the location we're using for the data, and
// refresh the list.
Q_INVOKABLE void setStorageLocation(StorageLocations strLocation);
private:
void initDataModel();
void addToDataModel(const QString &key, const QString &firstName, const QString &lastName);
int load();
// A helper method to check whether @p id contains a valid numeric id.
bool validateID(const QString &id);
// A helper method to show an alert dialog.
void alert(const QString &message);
bb::cascades::GroupDataModel* dataModel() const;
// The data shown by the list view.
GroupDataModel* m_dataModel;
int m_lastCustomerID;
StorageLocations m_storageLocation;
Storage* m_storage;
};
#endif