1 #include "onscreenmodel.h"
3 #include <json-c/json.h>
5 const char _modelName[] = "OnScreenModel";
6 const char _title[] = "title";
7 const char _type[] = "type";
8 const char _contents[] = "contents";
9 const char _buttons[] = "buttons";
12 void OnScreenModel::setModel(QVariant data)
14 HMI_DEBUG(_modelName, "setModel start!");
16 struct json_object *j_title = nullptr, *j_type = nullptr, *j_contents = nullptr, *j_buttons = nullptr;
17 struct json_object *j_param = json_tokener_parse(data.toString().toStdString().c_str());
18 if(json_object_object_get_ex(j_param, _title, &j_title)) {
19 m_title = json_object_get_string(j_title);
22 HMI_DEBUG(_modelName, "title input is null");
25 if(json_object_object_get_ex(j_param, _type, &j_type)) {
26 m_type = json_object_get_string(j_type);
29 HMI_DEBUG(_modelName, "type input is null");
32 if(json_object_object_get_ex(j_param, _contents, &j_contents)) {
33 m_contents = json_object_get_string(j_contents);
36 HMI_DEBUG(_modelName, "contents input is null");
39 if(json_object_object_get_ex(j_param, _buttons, &j_buttons)) {
40 if(json_object_get_type(j_buttons) != json_type_array) {
41 HMI_DEBUG(_modelName, "buttons josn type isn't array!");
45 int len = json_object_array_length(j_buttons);
46 struct json_object *json_tmp = nullptr;
47 for (int i = 0; i < len; i++) {
48 json_tmp = json_object_array_get_idx(j_buttons, i);
49 m_buttons << QString(json_object_get_string(json_tmp));
54 HMI_DEBUG("OnScreenModel", "buttons input is null");
56 HMI_DEBUG(_modelName, "setModel end!titile=%s,type=%s,contents=%s,btnNum=%d",
57 m_title.toStdString().c_str(), m_type.toStdString().c_str(), m_contents.toStdString().c_str(), m_buttons.size());
60 QString OnScreenModel::buttonName(int index) const
62 if(index >= m_buttons.size())
65 return m_buttons[index];
68 void OnScreenModel::clearModel(void)