-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathListDefHelper.h
73 lines (54 loc) · 2.38 KB
/
ListDefHelper.h
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
#ifndef LISTDEFREADER_H
#define LISTDEFREADER_H
#include <functional>
#include <map>
#include "wx/string.h"
#include "wx/propgrid/propgrid.h"
#include "wx/propgrid/advprops.h"
#include "mydefs.hpp"
class wxPropertyGridInterface;
#include "json.hpp"
using json = nlohmann::json;
class ListDefHelper
{
public:
ListDefHelper();
bool Read(const wxString &jsonFilePath);
const json& GetJson() { return m_json; }
void GetItem(const wxString &itemName, const std::function<void(const json&)> &callbackOnItem);
wxVariant GetItemDefaultValue(const wxString &itemName);
wxString GetCategoryShowName(const wxString &itemName);
wxString GetItemType(const wxString &itemName);
/**\brief Create property struct form json settings.
*
*\param
*\return
*
*/
void InitPropGrid(wxPropertyGridInterface *propGrid, const wxString& mapName);
void BindEvent(wxEvtHandler *eventHandler,
std::function<void(const wxString &propertyName, const wxString& typeName)> onItemBtnClick,
std::function<void(const wxString &propertyName, const wxString& typeName, const wxVariant& value)> onItemValueChanged);
void UnbindEvent(wxEvtHandler *eventHandler);
void SetValue(wxPropertyGridInterface *propGrid, const wxString& key, const wxVariant &value);
void SetValues(wxPropertyGridInterface *propGrid, const std::map<wxString, wxVariant> &keyValues);
void AssignValues(wxPropertyGridInterface *propGrid, std::map<wxString, wxVariant> &keyValues, bool noEmpty = false);
void ClearAllValues(wxPropertyGridInterface *propGrid);
void OnItemDClick(wxPropertyGridEvent &event);
void OnItemValueChanged(wxPropertyGridEvent &event);
void OnItemBtnClick(wxCommandEvent &event);
protected:
private:
void AddItem(wxPropertyGridInterface *propGrid, const wxString& mapName, const json& item);
void OpenRelateFile(const wxString& relatePath);
bool IsRelateFileExist(const wxString& relatePath);
void ShowFileNotExistMsg(const wxString& path);
wxPGProperty* GetCategory(wxPropertyGridInterface *propGrid, const wxString& name);
private:
json m_json;
wxString m_mapName;
std::function<void(const wxString &propertyName, const wxString& typeName)> m_onPropertyBtnClicked;
std::function<void(const wxString &propertyName, const wxString& typeName, const wxVariant& value)> m_onItemValueChanged;
wxPropertyGridInterface* m_targetGridInterface = nullptr;
};
#endif // LISTDEFREADER_H