玉兔远程控制 0.1.0-bate6
载入中...
搜索中...
未找到
DatabaseTree.h
1// Author: Kang Lin <kl222@126.com>
2
3#pragma once
4#include <QIcon>
5#include "Database.h"
6
7class PLUGIN_EXPORT TreeItem {
8public:
9 TreeItem();
10 TreeItem(const TreeItem& item);
11
12 bool IsNode() const;
13 bool IsLeaf() const;
14
15 enum TYPE {
16 Node,
17 Leaf
18 };
19 TYPE GetType() const;
20 void SetType(TYPE type);
21 int GetId() const;
22 void SetId(int newId);
23 QString GetName() const;
24 void SetName(const QString &newName);
25 QDateTime GetCreateTime() const;
26 void SetCreateTime(const QDateTime &newCreateTime);
27 QDateTime GetModifyTime() const;
28 void SetModifyTime(const QDateTime &newModifyTime);
29 QDateTime GetLastVisitTime() const;
30 void SetLastVisitTime(const QDateTime &newLastVisitTime);
31 int GetParentId() const;
32 void SetParentId(int newParentId);
33 int GetSortOrder() const;
34 void SetSortOrder(int newSortOrder);
35
36 int GetKey() const;
37 void SetKey(int newNKey);
38
39private:
40 TYPE m_Type;
41 int m_id;
42 QString m_szName;
43 int m_nKey;
44 QDateTime m_CreateTime;
45 QDateTime m_ModifyTime;
46 QDateTime m_LastVisitTime;
47 int m_ParentId;
48 int m_SortOrder;
49};
50
51class PLUGIN_EXPORT CDatabaseFolder : public CDatabase
52{
53 Q_OBJECT
54
55public:
56 explicit CDatabaseFolder(QObject *parent = nullptr);
57 explicit CDatabaseFolder(const QString& szPrefix, QObject *parent = nullptr);
58
59 // 文件夹操作
60 int AddFolder(const QString &name, int parentId = 0);
61 bool RenameFolder(int id, const QString &newName);
62 bool DeleteFolder(int id, std::function<int(int parentId)> cbDeleteLeaf = nullptr);
63 bool MoveFolder(int id, int newParentId);
64 // 文件夹查询
65 TreeItem GetFolder(int id);
66 QList<TreeItem> GetAllFolders();
67 QList<TreeItem> GetSubFolders(int parentId);
73 int GetCount(int parentId = 0);
74
75 virtual bool ExportToJson(QJsonObject& obj) override;
76 virtual bool ImportFromJson(const QJsonObject& obj) override;
77
78 QString GetTableName() const;
79 void SetTableName(const QString &newSzTableName);
80
81Q_SIGNALS:
82 void sigAddFolder(int id, int parentId);
83
84protected:
85 virtual bool OnDeleteLeafs(int id);
86 virtual bool OnInitializeSqliteDatabase() override;
87 virtual bool OnInitializeMySqlDatabase() override;
88
89private:
90 QString m_szTableName;
91};
92
93class PLUGIN_EXPORT CDatabaseTree : public CDatabase
94{
95 Q_OBJECT
96
97public:
98 explicit CDatabaseTree(QObject* parent = nullptr);
99 explicit CDatabaseTree(const QString& szPrefix, QObject* parent = nullptr);
100
101 // Leaf operate
102
109 virtual int Add(const TreeItem& item);
110 virtual bool Update(const TreeItem& item);
111 virtual bool Delete(int id, bool delKey = false);
112 virtual bool Delete(QList<int> items, bool delKey = false);
113 virtual bool DeleteChild(int parentId, bool delKey = false);
114 virtual bool Move(int id, int newParent);
115
116 TreeItem GetLeaf(int id);
123 QList<TreeItem> GetLeaves(int nodeId);
128 QList<TreeItem> GetLeavesByKey(int key);
129 QList<TreeItem> GetLeavesByKey(QList<int> key);
130 int GetLeafCount(int parentId = 0);
131
132 // Node operate
133 virtual int AddNode(const QString &name, int parentId = 0);
134 virtual bool RenameNode(int id, const QString &newName);
135 virtual bool DeleteNode(int id, bool delKey = false);
136 virtual bool MoveNode(int id, int newParentId);
137 TreeItem GetNode(int id);
138 QList<TreeItem> GetAllNodes();
139 QList<TreeItem> GetSubNodes(int parentId);
140 int GetNodeCount(int nParentId = 0);
141
151 int GetCount(int parentId = 0);
152
153 virtual bool OnInitializeDatabase() override;
154 virtual bool ExportToJson(QJsonObject& obj) override;
155 virtual bool ImportFromJson(const QJsonObject& obj) override;
156
157Q_SIGNALS:
158 void sigAddFolder(int id, int parentId);
159 void sigAdd(int id, int parentId);
160
161protected:
169 virtual bool OnDeleteKey(int key);
170 virtual bool OnInitializeSqliteDatabase() override;
171 virtual bool OnInitializeMySqlDatabase() override;
172
173private:
174 QString m_szTableName;
175 CDatabaseFolder m_FolderDB;
176};