-
Notifications
You must be signed in to change notification settings - Fork 9
/
cxqtutil.h
288 lines (158 loc) · 8.73 KB
/
cxqtutil.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#ifndef CXQTUTIL_H
#define CXQTUTIL_H
#include "cxglobal.h"
#include <QDateTime>
#include <QHash>
#include <QListView>
#include <QListWidget>
#include <QTableView>
#include <QTableWidget>
#include <QTreeView>
#include <QTreeWidget>
#include <QHeaderView>
#include <QItemDelegate>
#include <QStandardItem>
#include <QStandardItemModel>
#include <QSplitter>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QSpacerItem>
#include <QLabel>
#include <QPushButton>
#include <QLineEdit>
#include <QtCore/QMutex>
#define GM_QString_TR(s) (QObject::trUtf8(s))
typedef int (*fn_int_widget_t)(QWidget * oWidget);
class CxQString
{
public:
static QString gbkToQString(const std::string& s);
static QStringList gbkToQStrings(const std::vector<std::string>& ss);
static QStringList gbkToQStrings(const std::string * oSs, int iCount);
static std::vector<std::string> gbkToStdStrings(const QStringList & ss);
static std::string gbkToStdString(const QString& s);
static const QString DateTimeFormat;
static QString ToString(const int& i);
static QString ToString(const unsigned int& i);
static QString ToString(const int& i, int iZeroCount);
static QString ToString(const bool& b);
static QString ToString(const double& d);
static QString ToString(const QString& s);
static QString ToString(const std::string& s);
static QString ToString(const qlonglong& dt);
static QString ToString(const QHash<QString, QString>& keyValues);
static QString ToString(const QStringList& keyValues);
static QString ToString(const char* pData, int iLength);
static QString ToString(const char* pData);
static QString ToString(const uchar* pData, int iLength);
static int FromString(const QString& s, const int& iDefault, bool *ok=NULL);
static bool FromString(const QString& s, const bool& bDefault, bool *ok=NULL);
static float FromString(const QString& s, const float& fDefault, bool *ok=NULL);
static double FromString(const QString& s, const double& dDefault, bool *ok=NULL);
///attention error with : QString s = CommonString::FromString(s, s);
static QString FromString(const QString& s, const QString& sDefault, bool *ok=NULL);
///attention error with : qlonglong l = CommonString::FromString(s, l);
static qlonglong FromString(const QString& s, const qlonglong& dtDefault, bool *ok=NULL);
///attention error with : QHash<QString, QString> hash = CommonString::FromString(s, hash);
static QHash<QString, QString> FromString(const QString& s, const QHash<QString, QString>& hashDefault, bool *ok=NULL);
///attention error with : QStringList sl = CommonString::FromString(s, sl);
static QStringList FromString(const QString& s, const QStringList& hashDefault, bool *ok=NULL);
static QString DateTimeToString(const qlonglong& ms);
static QString DateTimeToString(int y, int m, int d, int h, int mi, int ms);
static qlonglong DateTimeFromString(const QString& str);
static QString FirstToken(QString& s, const QChar &sep);
static QString RightToken(const QString& s, const QChar &sep);
static QString ToHexstring(const char* pData, int iLength);
static QString ToHexstring(const uchar* pData, int iLength);
static QString ToHexstring(const QByteArray& data);
static QString ToHexstring(const char& v);
static QString ToHexstring(const uchar& v);
static QString ToHexstring(const short& v);
static QString ToHexstring(const ushort& v);
static QString ToHexstring(const int& v);
static QString ToHexstring(const uint& v);
static QString ToHexstring(const float& v);
static QString ToHexstring(const double& v);
static QByteArray FromHexstring(const QString& s);
static bool CompareName(const QString& name1, const QString& name2);
};
class CxQDialog
{
public:
static void ShowPrompt(const QString& sText, const QString& sTitle = "Prompt");
static void ShowWarning(const QString& sText);
static void ShowError(const QString& sText);
static bool ShowQuery(const QString& sQuery,const QString& sTitle="系统信息",const QString& sOk="确定",const QString& sCancle="取消");
static int ShowQuery3(const QString& sQuery);
static void ShowTerminate(const QString& sText);
static bool DialogOpen(QString& sFileName, const QString& sExtension = QString());
static bool DialogSave(QString& sFileName, const QString& sExtension = QString());
static QString DialogDir(const QString& sRootDir, const QString & sTitle = QString());
static bool DialogInput(const QString& sPrompt, QString& sVaule);
static bool DialogInput2(const QString &sTitle, const QString &sValue1Title, const QString &sValue2Title, QString &sValue1, QString &sValue2, int iValue1EchoMode = 0, int iValue2EchoMode = 0);
static bool DialogInput3(const QString &sTitle, const QString &sValue1Title, const QString &sValue2Title, const QString &sValue3Title, QString &sValue1, QString &sValue2, QString &sValue3, int iValue1EchoMode = 0, int iValue2EchoMode = 0, int iValue3EchoMode = 0);
static bool DialogInput4(const QString &sTitle, const QString &sPrompt, QString& sVaule);
static bool DialogCombox(const QString &sTitle, const QString &sPrompt, const QStringList& sVaules, QString& sValue );
};
class CxQWidget
{
public:
static void setQSS(QWidget * widget, const QString &fp);
static void setQSS(QWidget * widget, const std::string &fp);
//set
static int setItemValue16(QTableWidgetItem* oItem, const int & value);
static int setItemValue(QTableWidgetItem* oItem, const int & value);
static int setItemValue(QTableWidgetItem* oItem, const double & value);
static int setItemValue(QTableWidgetItem* oItem, const long long & value);
static int setItemValue(QTableWidgetItem* oItem, const char * value);
static int setItemValue(QTableWidgetItem* oItem, const std::string & value);
static int setItemValue(QTableWidgetItem* oItem, const QString & value);
static void setItemValueDateTime(QTableWidgetItem* oItem, const long long & value);
//get
static int getItemValue16(QTableWidgetItem* oItem, const int & value);
static int getItemValue(QTableWidgetItem* oItem, const int & value);
static double getItemValue(QTableWidgetItem* oItem, const double & value);
static long long getItemValue(QTableWidgetItem* oItem, const long long & value);
static std::string getItemValue(QTableWidgetItem* oItem, const std::string & value);
static QString getItemValue(QTableWidgetItem* oItem, const QString & value);
static long long getItemValueDateTime(QTableWidgetItem* oItem, const long long & value);
static int setItemValue16(QListWidgetItem* oItem, const int & value);
static int setItemValue(QListWidgetItem* oItem, const int & value);
static int setItemValue(QListWidgetItem* oItem, const double & value);
static int setItemValue(QListWidgetItem* oItem, const long long & value);
static int setItemValue(QListWidgetItem* oItem, const char * value);
static int setItemValue(QListWidgetItem* oItem, const std::string & value);
static int setItemValue(QListWidgetItem* oItem, const QString & value);
static void setItemValueDateTime(QListWidgetItem* oItem, const long long & value);
//
static int setItemValue16(QStandardItem* oItem, const int & value);
static int setItemValue(QStandardItem* oItem, const int & value);
static int setItemValue(QStandardItem* oItem, const double & value);
static int setItemValue(QStandardItem* oItem, const long long & value);
static int setItemValue(QStandardItem* oItem, const char * value);
static int setItemValue(QStandardItem* oItem, const std::string & value);
static int setItemValue(QStandardItem* oItem, const QString & value);
static int setItemValueEditRole(QStandardItem* oItem, const QString & value);
static void setItemValueDateTime(QStandardItem* oItem, const long long & value);
static std::vector<int> getSelectRows(QTableWidget * oGrid, QString *pRows = NULL);
static std::vector<int> deleteSelectRows(QTableWidget * oGrid);
//扩展数据
static void setItemValueUserEx(QTableWidgetItem *oItem,const int id,const int value);
static int getItemValueUserEx(QTableWidgetItem *oItem,const int id,const int value);
static void setItemValueUserEx(QListWidgetItem *oItem,const int id,const int value);
static int getItemValueUserEx(QListWidgetItem *oItem,const int id,const int value);
};
class CxQMutexScope
{
private:
QMutex * m_mutex;
public:
inline CxQMutexScope(QMutex * mutex) : m_mutex(mutex) {
m_mutex->lock();
}
inline CxQMutexScope(QMutex & mutex) : m_mutex(& mutex) {
m_mutex->lock();
}
inline ~CxQMutexScope() { m_mutex->unlock(); }
};
#endif // CXQTUTIL_H