Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
FMTestPOS
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhenfei.zhang
FMTestPOS
Commits
b05ea08b
Commit
b05ea08b
authored
Feb 08, 2018
by
NitefullWind
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1. 实现配置功能。可选配置文件路径。
parent
966690c1
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
481 additions
and
57 deletions
+481
-57
POS/POS.pri
+28
-25
POS/POS.rc
+0
-0
POS/main.cpp
+6
-0
POS/mainwindow.cpp
+50
-18
POS/mainwindow.h
+6
-1
POS/mainwindow.ui
+12
-0
POS/setting.cpp
+49
-9
POS/setting.h
+12
-4
POS/settingdialog.cpp
+81
-0
POS/settingdialog.h
+39
-0
POS/settingdialog.ui
+198
-0
No files found.
POS/POS.pri
View file @
b05ea08b
...
@@ -11,32 +11,35 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
...
@@ -11,32 +11,35 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
CONFIG += c++11
SOURCES += \
SOURCES += \
main.cpp \
$$PWD\main.cpp \
mainwindow.cpp \
$$PWD\mainwindow.cpp \
setting.cpp \
$$PWD\setting.cpp \
selectedwidget.cpp \
$$PWD\selectedwidget.cpp \
productwidget.cpp \
$$PWD\productwidget.cpp \
paywidget.cpp \
$$PWD\paywidget.cpp \
inputamountdialog.cpp \
$$PWD\inputamountdialog.cpp \
session.cpp \
$$PWD\session.cpp \
highlighter.cpp \
$$PWD\highlighter.cpp \
reqdatabtn.cpp
$$PWD\reqdatabtn.cpp \
$$PWD\settingdialog.cpp
HEADERS += \
HEADERS += \
mainwindow.h \
$$PWD\mainwindow.h \
setting.h \
$$PWD\setting.h \
selectedwidget.h \
$$PWD\selectedwidget.h \
productwidget.h \
$$PWD\productwidget.h \
paywidget.h \
$$PWD\paywidget.h \
session.h \
$$PWD\session.h \
inputamountdialog.h \
$$PWD\inputamountdialog.h \
highlighter.h \
$$PWD\highlighter.h \
reqdatabtn.h
$$PWD\reqdatabtn.h \
$$PWD\settingdialog.h
FORMS += \
FORMS += \
mainwindow.ui \
$$PWD\mainwindow.ui \
productwidget.ui \
$$PWD\productwidget.ui \
paywidget.ui \
$$PWD\paywidget.ui \
inputamountdialog.ui \
$$PWD\inputamountdialog.ui \
reqdatabtn.ui \
$$PWD\reqdatabtn.ui \
selectedwidget.ui
$$PWD\selectedwidget.ui \
$$PWD\settingdialog.ui
POS/POS.rc
View file @
b05ea08b
No preview for this file type
POS/main.cpp
View file @
b05ea08b
...
@@ -4,6 +4,12 @@
...
@@ -4,6 +4,12 @@
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
QApplication
a
(
argc
,
argv
);
QApplication
a
(
argc
,
argv
);
qApp
->
setOrganizationName
(
"Freemud"
);
qApp
->
setOrganizationDomain
(
"freemud.cn"
);
qApp
->
setApplicationName
(
"FMTestPOS"
);
qApp
->
setApplicationDisplayName
(
"非码测试POS"
);
MainWindow
w
;
MainWindow
w
;
w
.
show
();
w
.
show
();
...
...
POS/mainwindow.cpp
View file @
b05ea08b
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
#include "inputamountdialog.h"
#include "inputamountdialog.h"
#include "highlighter.h"
#include "highlighter.h"
#include "reqdatabtn.h"
#include "reqdatabtn.h"
#include "settingdialog.h"
#include <QPushButton>
#include <QPushButton>
#include <QDialog>
#include <QDialog>
#include <QTextEdit>
#include <QTextEdit>
...
@@ -25,14 +26,11 @@ MainWindow::MainWindow(QWidget *parent) :
...
@@ -25,14 +26,11 @@ MainWindow::MainWindow(QWidget *parent) :
needPayAmount
(
0
)
needPayAmount
(
0
)
{
{
ui
->
setupUi
(
this
);
ui
->
setupUi
(
this
);
InitProductList
();
InitPayList
();
InitReqPosBtns
();
InitReqDataBtns
();
highlighter
=
new
Highlighter
(
ui
->
console
->
document
());
highlighter
=
new
Highlighter
(
ui
->
console
->
document
());
connect
(
Setting
::
Instance
(),
&
Setting
::
newLog
,
this
,
&
MainWindow
::
onNewLog
);
connect
(
Setting
::
Instance
(),
&
Setting
::
newLog
,
this
,
&
MainWindow
::
onNewLog
);
resetTransId
();
connect
(
ui
->
menuBar
,
&
QMenuBar
::
triggered
,
this
,
&
MainWindow
::
onMenuTriggered
);
Setting
::
getSession
()
->
addData
(
"business_date"
,
QDate
::
currentDate
().
toString
(
"yyyyMMdd"
));
onInitWnd
();
}
}
MainWindow
::~
MainWindow
()
MainWindow
::~
MainWindow
()
...
@@ -42,6 +40,12 @@ MainWindow::~MainWindow()
...
@@ -42,6 +40,12 @@ MainWindow::~MainWindow()
void
MainWindow
::
InitProductList
()
void
MainWindow
::
InitProductList
()
{
{
foreach
(
ProductWidget
*
w
,
productWidgeVector
)
{
ui
->
productLayout
->
removeWidget
(
w
);
}
qDeleteAll
(
productWidgeVector
);
productWidgeVector
.
clear
();
QList
<
Setting
::
Product
>
productList
=
Setting
::
Instance
()
->
getProductList
();
QList
<
Setting
::
Product
>
productList
=
Setting
::
Instance
()
->
getProductList
();
foreach
(
Setting
::
Product
product
,
productList
)
{
foreach
(
Setting
::
Product
product
,
productList
)
{
ProductWidget
*
pro_widget
=
new
ProductWidget
(
product
,
this
);
ProductWidget
*
pro_widget
=
new
ProductWidget
(
product
,
this
);
...
@@ -86,10 +90,17 @@ void MainWindow::onProductSelectedChanged()
...
@@ -86,10 +90,17 @@ void MainWindow::onProductSelectedChanged()
void
MainWindow
::
InitPayList
()
void
MainWindow
::
InitPayList
()
{
{
foreach
(
PayWidget
*
w
,
payWidgetVector
)
{
ui
->
payListLayout
->
removeWidget
(
w
);
}
qDeleteAll
(
payWidgetVector
);
payWidgetVector
.
clear
();
QList
<
Setting
::
PayWay
>
payList
=
Setting
::
Instance
()
->
getPayList
();
QList
<
Setting
::
PayWay
>
payList
=
Setting
::
Instance
()
->
getPayList
();
foreach
(
Setting
::
PayWay
payWay
,
payList
)
{
foreach
(
Setting
::
PayWay
payWay
,
payList
)
{
PayWidget
*
payWidget
=
new
PayWidget
(
payWay
,
this
);
PayWidget
*
payWidget
=
new
PayWidget
(
payWay
,
this
);
ui
->
payListLayout
->
addWidget
(
payWidget
);
ui
->
payListLayout
->
addWidget
(
payWidget
);
payWidgetVector
.
append
(
payWidget
);
connect
(
payWidget
,
&
PayWidget
::
selected
,
this
,
&
MainWindow
::
onPaySelected
);
connect
(
payWidget
,
&
PayWidget
::
selected
,
this
,
&
MainWindow
::
onPaySelected
);
connect
(
payWidget
,
&
PayWidget
::
disSelected
,
this
,
&
MainWindow
::
onPayDisSelected
);
connect
(
payWidget
,
&
PayWidget
::
disSelected
,
this
,
&
MainWindow
::
onPayDisSelected
);
...
@@ -110,7 +121,7 @@ void MainWindow::onPaySelected()
...
@@ -110,7 +121,7 @@ void MainWindow::onPaySelected()
QJsonObject
rspObj
;
QJsonObject
rspObj
;
doRequest
(
payWdiget
->
getPayWay
().
req_pay
,
rspObj
);
doRequest
(
payWdiget
->
getPayWay
().
req_pay
,
rspObj
);
if
(
rspObj
[
"statusCode"
].
toInt
()
!=
100
)
{
if
(
rspObj
[
"statusCode"
].
toInt
()
!=
100
&&
rspObj
[
"status_code"
].
toInt
()
!=
100
)
{
consoleShow
(
QString
::
fromLocal8Bit
(
"支付失败"
),
FMLog
::
Error
);
consoleShow
(
QString
::
fromLocal8Bit
(
"支付失败"
),
FMLog
::
Error
);
}
else
{
}
else
{
Setting
::
Instance
()
->
getSession
()
->
addData
(
"fm_id"
,
rspObj
[
"fm_id"
].
toString
());
Setting
::
Instance
()
->
getSession
()
->
addData
(
"fm_id"
,
rspObj
[
"fm_id"
].
toString
());
...
@@ -125,7 +136,7 @@ void MainWindow::onPaySelected()
...
@@ -125,7 +136,7 @@ void MainWindow::onPaySelected()
if
(
payAmount
>
0
&&
payAmount
<=
needPayAmount
)
{
if
(
payAmount
>
0
&&
payAmount
<=
needPayAmount
)
{
paidAmount
+=
payAmount
;
paidAmount
+=
payAmount
;
needPayAmount
=
orderAmount
-
paidAmount
;
needPayAmount
=
orderAmount
-
paidAmount
;
p
ayWidgetMap
[
payWdiget
]
+=
payAmount
;
usedP
ayWidgetMap
[
payWdiget
]
+=
payAmount
;
}
}
showAmountInfo
();
showAmountInfo
();
}
}
...
@@ -134,8 +145,8 @@ void MainWindow::onPayDisSelected()
...
@@ -134,8 +145,8 @@ void MainWindow::onPayDisSelected()
{
{
PayWidget
*
payWdiget
=
qobject_cast
<
PayWidget
*>
(
sender
());
PayWidget
*
payWdiget
=
qobject_cast
<
PayWidget
*>
(
sender
());
int
refundAmonut
=
0
;
int
refundAmonut
=
0
;
if
(
p
ayWidgetMap
.
contains
(
payWdiget
))
{
if
(
usedP
ayWidgetMap
.
contains
(
payWdiget
))
{
refundAmonut
=
p
ayWidgetMap
[
payWdiget
];
refundAmonut
=
usedP
ayWidgetMap
[
payWdiget
];
}
}
int
payAmount
=
showPayDialog
(
refundAmonut
,
false
);
int
payAmount
=
showPayDialog
(
refundAmonut
,
false
);
...
@@ -143,7 +154,7 @@ void MainWindow::onPayDisSelected()
...
@@ -143,7 +154,7 @@ void MainWindow::onPayDisSelected()
Setting
::
Instance
()
->
getSession
()
->
addData
(
"refund_amount"
,
payAmount
);
Setting
::
Instance
()
->
getSession
()
->
addData
(
"refund_amount"
,
payAmount
);
QJsonObject
rspObj
;
QJsonObject
rspObj
;
doRequest
(
payWdiget
->
getPayWay
().
req_refund
,
rspObj
);
doRequest
(
payWdiget
->
getPayWay
().
req_refund
,
rspObj
);
if
(
rspObj
[
"statusCode"
].
toInt
()
!=
100
)
{
if
(
rspObj
[
"statusCode"
].
toInt
()
!=
100
&&
rspObj
[
"status_code"
].
toInt
()
!=
100
)
{
payAmount
=
0
;
payAmount
=
0
;
consoleShow
(
QString
::
fromLocal8Bit
(
"退款失败"
),
FMLog
::
Error
);
consoleShow
(
QString
::
fromLocal8Bit
(
"退款失败"
),
FMLog
::
Error
);
}
}
...
@@ -152,7 +163,7 @@ void MainWindow::onPayDisSelected()
...
@@ -152,7 +163,7 @@ void MainWindow::onPayDisSelected()
if
(
payAmount
>
0
&&
payAmount
<=
refundAmonut
)
{
if
(
payAmount
>
0
&&
payAmount
<=
refundAmonut
)
{
paidAmount
-=
payAmount
;
paidAmount
-=
payAmount
;
needPayAmount
=
orderAmount
-
paidAmount
;
needPayAmount
=
orderAmount
-
paidAmount
;
p
ayWidgetMap
[
payWdiget
]
-=
payAmount
;
usedP
ayWidgetMap
[
payWdiget
]
-=
payAmount
;
}
}
showAmountInfo
();
showAmountInfo
();
}
}
...
@@ -161,7 +172,7 @@ void MainWindow::showAmountInfo()
...
@@ -161,7 +172,7 @@ void MainWindow::showAmountInfo()
{
{
ui
->
orderAmountLab
->
setText
(
QString
::
number
(
orderAmount
/
100.0
,
'f'
,
2
));
ui
->
orderAmountLab
->
setText
(
QString
::
number
(
orderAmount
/
100.0
,
'f'
,
2
));
ui
->
needAmountLab
->
setText
(
QString
::
number
(
needPayAmount
/
100.0
,
'f'
,
2
));
ui
->
needAmountLab
->
setText
(
QString
::
number
(
needPayAmount
/
100.0
,
'f'
,
2
));
for
(
QMap
<
PayWidget
*
,
int
>::
const_iterator
it
=
payWidgetMap
.
begin
();
it
!=
p
ayWidgetMap
.
end
();
it
++
)
{
for
(
QMap
<
PayWidget
*
,
int
>::
const_iterator
it
=
usedPayWidgetMap
.
begin
();
it
!=
usedP
ayWidgetMap
.
end
();
it
++
)
{
PayWidget
*
pw
=
it
.
key
();
PayWidget
*
pw
=
it
.
key
();
pw
->
setPayAmount
(
it
.
value
());
pw
->
setPayAmount
(
it
.
value
());
}
}
...
@@ -170,14 +181,14 @@ void MainWindow::showAmountInfo()
...
@@ -170,14 +181,14 @@ void MainWindow::showAmountInfo()
Setting
::
Instance
()
->
getSession
()
->
addData
(
"paid_amount"
,
paidAmount
);
Setting
::
Instance
()
->
getSession
()
->
addData
(
"paid_amount"
,
paidAmount
);
QJsonArray
payList
;
QJsonArray
payList
;
foreach
(
PayWidget
*
payWidget
,
p
ayWidgetMap
.
keys
())
{
foreach
(
PayWidget
*
payWidget
,
usedP
ayWidgetMap
.
keys
())
{
if
(
p
ayWidgetMap
[
payWidget
]
<=
0
)
{
if
(
usedP
ayWidgetMap
[
payWidget
]
<=
0
)
{
continue
;
continue
;
}
}
QJsonObject
payObj
;
QJsonObject
payObj
;
payObj
[
"pay_id"
]
=
payWidget
->
getPayWay
().
pay_id
;
payObj
[
"pay_id"
]
=
payWidget
->
getPayWay
().
pay_id
;
payObj
[
"pay_str"
]
=
payWidget
->
getPayWay
().
pay_name
;
payObj
[
"pay_str"
]
=
payWidget
->
getPayWay
().
pay_name
;
payObj
[
"pay_amount"
]
=
p
ayWidgetMap
[
payWidget
];
payObj
[
"pay_amount"
]
=
usedP
ayWidgetMap
[
payWidget
];
payObj
[
"pay_transId"
]
=
payWidget
->
getPayWay
().
pay_transId
;
payObj
[
"pay_transId"
]
=
payWidget
->
getPayWay
().
pay_transId
;
payList
.
append
(
payObj
);
payList
.
append
(
payObj
);
}
}
...
@@ -261,11 +272,11 @@ void MainWindow::on_btn_reset_clicked()
...
@@ -261,11 +272,11 @@ void MainWindow::on_btn_reset_clicked()
foreach
(
ProductWidget
*
proWidget
,
productWidgeVector
)
{
foreach
(
ProductWidget
*
proWidget
,
productWidgeVector
)
{
proWidget
->
setSelectedCount
(
0
);
proWidget
->
setSelectedCount
(
0
);
}
}
for
(
QMap
<
PayWidget
*
,
int
>::
const_iterator
it
=
payWidgetMap
.
begin
();
it
!=
p
ayWidgetMap
.
end
();
it
++
)
{
for
(
QMap
<
PayWidget
*
,
int
>::
const_iterator
it
=
usedPayWidgetMap
.
begin
();
it
!=
usedP
ayWidgetMap
.
end
();
it
++
)
{
PayWidget
*
pw
=
it
.
key
();
PayWidget
*
pw
=
it
.
key
();
pw
->
setPayAmount
(
0
);
pw
->
setPayAmount
(
0
);
}
}
p
ayWidgetMap
.
clear
();
usedP
ayWidgetMap
.
clear
();
ui
->
lineEdit_undisAmount
->
setText
(
"0"
);
ui
->
lineEdit_undisAmount
->
setText
(
"0"
);
}
else
if
(
ui
->
tab_raw
)
{
}
else
if
(
ui
->
tab_raw
)
{
ui
->
textEdit_raw
->
clear
();
ui
->
textEdit_raw
->
clear
();
...
@@ -360,6 +371,27 @@ void MainWindow::on_btn_save_req_clicked()
...
@@ -360,6 +371,27 @@ void MainWindow::on_btn_save_req_clicked()
}
}
}
}
void
MainWindow
::
onMenuTriggered
(
QAction
*
action
)
{
if
(
action
->
objectName
()
==
"action_setting"
)
{
SettingDialog
settingDialog
;
int
ret
=
settingDialog
.
exec
();
if
(
ret
)
{
onInitWnd
();
}
}
}
void
MainWindow
::
onInitWnd
()
{
InitProductList
();
InitPayList
();
InitReqPosBtns
();
InitReqDataBtns
();
resetTransId
();
Setting
::
getSession
()
->
addData
(
"business_date"
,
QDate
::
currentDate
().
toString
(
"yyyyMMdd"
));
}
void
MainWindow
::
InitReqDataBtns
()
void
MainWindow
::
InitReqDataBtns
()
{
{
int
btnsCount
=
ui
->
reqData_btns_widget
->
count
();
int
btnsCount
=
ui
->
reqData_btns_widget
->
count
();
...
...
POS/mainwindow.h
View file @
b05ea08b
...
@@ -58,12 +58,17 @@ private slots:
...
@@ -58,12 +58,17 @@ private slots:
void
on_btn_save_req_clicked
();
void
on_btn_save_req_clicked
();
void
onMenuTriggered
(
QAction
*
action
);
void
onInitWnd
();
private
:
private
:
Ui
::
MainWindow
*
ui
;
Ui
::
MainWindow
*
ui
;
Highlighter
*
highlighter
;
Highlighter
*
highlighter
;
QVector
<
ProductWidget
*>
productWidgeVector
;
QVector
<
ProductWidget
*>
productWidgeVector
;
QMap
<
PayWidget
*
,
int
>
payWidgetMap
;
QVector
<
PayWidget
*>
payWidgetVector
;
QMap
<
PayWidget
*
,
int
>
usedPayWidgetMap
;
int
orderAmount
,
paidAmount
,
needPayAmount
;
int
orderAmount
,
paidAmount
,
needPayAmount
;
...
...
POS/mainwindow.ui
View file @
b05ea08b
...
@@ -301,6 +301,13 @@
...
@@ -301,6 +301,13 @@
<height>
23
</height>
<height>
23
</height>
</rect>
</rect>
</property>
</property>
<widget
class=
"QMenu"
name=
"menu"
>
<property
name=
"title"
>
<string>
选项
</string>
</property>
<addaction
name=
"action_setting"
/>
</widget>
<addaction
name=
"menu"
/>
</widget>
</widget>
<widget
class=
"QToolBar"
name=
"mainToolBar"
>
<widget
class=
"QToolBar"
name=
"mainToolBar"
>
<attribute
name=
"toolBarArea"
>
<attribute
name=
"toolBarArea"
>
...
@@ -311,6 +318,11 @@
...
@@ -311,6 +318,11 @@
</attribute>
</attribute>
</widget>
</widget>
<widget
class=
"QStatusBar"
name=
"statusBar"
/>
<widget
class=
"QStatusBar"
name=
"statusBar"
/>
<action
name=
"action_setting"
>
<property
name=
"text"
>
<string>
设置
</string>
</property>
</action>
</widget>
</widget>
<layoutdefault
spacing=
"6"
margin=
"11"
/>
<layoutdefault
spacing=
"6"
margin=
"11"
/>
<resources/>
<resources/>
...
...
POS/setting.cpp
View file @
b05ea08b
...
@@ -10,8 +10,12 @@
...
@@ -10,8 +10,12 @@
#include <QDate>
#include <QDate>
#include <QTcpSocket>
#include <QTcpSocket>
#include <QDir>
#include <QDir>
#include <QSettings>
#include <QApplication>
#include <QDebug>
#include <QDebug>
QString
Setting
::
_settingFilesPath
=
""
;
Setting
*
Setting
::
Instance
()
Setting
*
Setting
::
Instance
()
{
{
static
Setting
setting
;
static
Setting
setting
;
...
@@ -27,7 +31,14 @@ Setting::Setting(QObject *parent)
...
@@ -27,7 +31,14 @@ Setting::Setting(QObject *parent)
void
Setting
::
readSetting
()
void
Setting
::
readSetting
()
{
{
QFile
settingFile
(
QString
(
"%1/settings.json"
).
arg
(
CONFIGPATH
));
QSettings
settings
;
QStringList
filePaths
=
settings
.
value
(
"FilePaths"
,
QStringList
(
""
)).
toStringList
();
if
(
filePaths
.
isEmpty
())
{
_settingFilesPath
=
qApp
->
applicationDirPath
();
}
else
{
_settingFilesPath
=
filePaths
.
last
();
}
QFile
settingFile
(
QString
(
"%1/settings.json"
).
arg
(
_settingFilesPath
));
if
(
!
settingFile
.
open
(
QIODevice
::
ReadOnly
))
{
if
(
!
settingFile
.
open
(
QIODevice
::
ReadOnly
))
{
qDebug
()
<<
"Read setting file failed."
<<
settingFile
.
errorString
();
qDebug
()
<<
"Read setting file failed."
<<
settingFile
.
errorString
();
return
;
return
;
...
@@ -47,6 +58,12 @@ QJsonObject *Setting::getSettingJsonObj()
...
@@ -47,6 +58,12 @@ QJsonObject *Setting::getSettingJsonObj()
return
&
Instance
()
->
settingObj
;
return
&
Instance
()
->
settingObj
;
}
}
int
Setting
::
getLogLevel
()
{
static
int
level
=
Instance
()
->
settingObj
[
"Log"
].
toObject
().
value
(
"Level"
).
toInt
(
0
);
return
level
;
}
Session
*
Setting
::
getSession
()
Session
*
Setting
::
getSession
()
{
{
return
Instance
()
->
_session
;
return
Instance
()
->
_session
;
...
@@ -97,7 +114,8 @@ void Setting::setErrorString(const QString &error)
...
@@ -97,7 +114,8 @@ void Setting::setErrorString(const QString &error)
QJsonObject
Setting
::
getPosReqJsonObj
(
const
QString
&
apiName
)
QJsonObject
Setting
::
getPosReqJsonObj
(
const
QString
&
apiName
)
{
{
QFile
apiFile
(
QString
(
"postest/%1.json"
).
arg
(
apiName
));
qDebug
()
<<
_settingFilesPath
;
QFile
apiFile
(
QString
(
"%1/%2.json"
).
arg
(
_settingFilesPath
).
arg
(
apiName
));
if
(
!
apiFile
.
open
(
QIODevice
::
ReadOnly
))
{
if
(
!
apiFile
.
open
(
QIODevice
::
ReadOnly
))
{
Instance
()
->
setErrorString
(
QString
(
"Open file: %1.json failed. %2"
).
arg
(
apiName
).
arg
(
apiFile
.
errorString
()));
Instance
()
->
setErrorString
(
QString
(
"Open file: %1.json failed. %2"
).
arg
(
apiName
).
arg
(
apiFile
.
errorString
()));
return
QJsonObject
();
return
QJsonObject
();
...
@@ -172,6 +190,7 @@ QString Setting::CreateReqString(const QString &originString)
...
@@ -172,6 +190,7 @@ QString Setting::CreateReqString(const QString &originString)
}
}
default
:
default
:
Log
(
FMLog
(
QString
(
"Key: %1 Invalid qvariant type."
).
arg
(
apiKeyStr
),
FMLog
::
Warning
));
Log
(
FMLog
(
QString
(
"Key: %1 Invalid qvariant type."
).
arg
(
apiKeyStr
),
FMLog
::
Warning
));
keyValue
=
"
\"\"
"
;
break
;
break
;
}
}
}
}
...
@@ -244,7 +263,7 @@ bool Setting::doRequest(const QByteArray &reqData, QByteArray &rspData)
...
@@ -244,7 +263,7 @@ bool Setting::doRequest(const QByteArray &reqData, QByteArray &rspData)
int
sendDataLen
=
reqData
.
length
();
int
sendDataLen
=
reqData
.
length
();
// 如果需要,加上消息头
// 如果需要,加上消息头
if
(
Instance
()
->
settingObj
[
"NeedSocketHeader"
].
toBool
()
||
true
)
{
if
(
Instance
()
->
settingObj
[
"NeedSocketHeader"
].
toBool
())
{
char
*
sendDataWithHeader
=
new
char
[
sendDataLen
+
sizeof
(
FMSOCKHEADER
)];
char
*
sendDataWithHeader
=
new
char
[
sendDataLen
+
sizeof
(
FMSOCKHEADER
)];
FMSOCKHEADER
header
=
{
0
,
0
,
0
};
FMSOCKHEADER
header
=
{
0
,
0
,
0
};
header
.
flag
=
0x4d46
;
header
.
flag
=
0x4d46
;
...
@@ -278,14 +297,14 @@ bool Setting::doRequest(const QByteArray &reqData, QByteArray &rspData)
...
@@ -278,14 +297,14 @@ bool Setting::doRequest(const QByteArray &reqData, QByteArray &rspData)
bool
Setting
::
doRequest
(
const
QJsonObject
&
reqObj
,
QJsonObject
&
rspObj
)
bool
Setting
::
doRequest
(
const
QJsonObject
&
reqObj
,
QJsonObject
&
rspObj
)
{
{
QByteArray
reqData
=
Setting
::
getJsonValueString
(
reqObj
).
to
Utf8
();
QByteArray
reqData
=
Setting
::
getJsonValueString
(
reqObj
).
to
Local8Bit
();
QByteArray
recvData
;
QByteArray
recvData
;
doRequest
(
reqData
,
recvData
);
doRequest
(
reqData
,
recvData
);
QJsonParseError
parseError
;
QJsonParseError
parseError
;
QJsonDocument
doc
=
QJsonDocument
::
fromJson
(
QString
::
fromLocal8Bit
(
recvData
).
toUtf8
()
,
&
parseError
);
QJsonDocument
doc
=
QJsonDocument
::
fromJson
(
recvData
,
&
parseError
);
if
(
parseError
.
error
!=
QJsonParseError
::
NoError
)
{
if
(
parseError
.
error
!=
QJsonParseError
::
NoError
)
{
Log
(
FMLog
(
QString
(
"Parse json error: %1.
\n
Error Json: "
).
arg
(
parseError
.
errorString
()).
arg
(
recvData
.
data
()),
FMLog
::
Error
));
Log
(
FMLog
(
QString
(
"Parse json error: %1.
\n
Error Json: "
).
arg
(
parseError
.
errorString
()).
arg
(
recvData
.
data
()),
FMLog
::
Error
));
return
false
;
return
false
;
...
@@ -296,7 +315,7 @@ bool Setting::doRequest(const QJsonObject &reqObj, QJsonObject &rspObj)
...
@@ -296,7 +315,7 @@ bool Setting::doRequest(const QJsonObject &reqObj, QJsonObject &rspObj)
QStringList
Setting
::
getReqDataBtnsNames
(
const
QString
&
tag
)
QStringList
Setting
::
getReqDataBtnsNames
(
const
QString
&
tag
)
{
{
QDir
configDir
(
CONFIGPATH
);
QDir
configDir
(
_settingFilesPath
);
QStringList
nameFilters
;
QStringList
nameFilters
;
nameFilters
<<
QString
(
"%1_*.json"
).
arg
(
tag
);
nameFilters
<<
QString
(
"%1_*.json"
).
arg
(
tag
);
QStringList
fileNames
=
configDir
.
entryList
(
nameFilters
);
QStringList
fileNames
=
configDir
.
entryList
(
nameFilters
);
...
@@ -311,7 +330,7 @@ QStringList Setting::getReqDataBtnsNames(const QString &tag)
...
@@ -311,7 +330,7 @@ QStringList Setting::getReqDataBtnsNames(const QString &tag)
QString
Setting
::
getReqData
(
const
QString
&
reqName
,
const
QString
&
tag
)
QString
Setting
::
getReqData
(
const
QString
&
reqName
,
const
QString
&
tag
)
{
{
QString
fileName
=
QString
(
"%1/%2_%3.json"
).
arg
(
CONFIGPATH
).
arg
(
tag
).
arg
(
reqName
);
QString
fileName
=
QString
(
"%1/%2_%3.json"
).
arg
(
_settingFilesPath
).
arg
(
tag
).
arg
(
reqName
);
QFile
file
(
fileName
);
QFile
file
(
fileName
);
if
(
!
file
.
open
(
QFile
::
ReadOnly
))
{
if
(
!
file
.
open
(
QFile
::
ReadOnly
))
{
Instance
()
->
setErrorString
(
QString
(
"Open %1 filed. %2"
).
arg
(
fileName
).
arg
(
file
.
errorString
()));
Instance
()
->
setErrorString
(
QString
(
"Open %1 filed. %2"
).
arg
(
fileName
).
arg
(
file
.
errorString
()));
...
@@ -325,7 +344,7 @@ QString Setting::getReqData(const QString &reqName, const QString &tag)
...
@@ -325,7 +344,7 @@ QString Setting::getReqData(const QString &reqName, const QString &tag)
bool
Setting
::
setReqData
(
const
QString
&
reqName
,
const
QString
&
reqData
,
const
QString
&
tag
)
bool
Setting
::
setReqData
(
const
QString
&
reqName
,
const
QString
&
reqData
,
const
QString
&
tag
)
{
{
QString
fileName
=
QString
(
"%1/%2_%3.json"
).
arg
(
CONFIGPATH
).
arg
(
tag
).
arg
(
reqName
);
QString
fileName
=
QString
(
"%1/%2_%3.json"
).
arg
(
_settingFilesPath
).
arg
(
tag
).
arg
(
reqName
);
QFile
file
(
fileName
);
QFile
file
(
fileName
);
if
(
!
file
.
open
(
QFile
::
WriteOnly
))
{
if
(
!
file
.
open
(
QFile
::
WriteOnly
))
{
Instance
()
->
setErrorString
(
QString
(
"Open %1 filed. %2"
).
arg
(
fileName
).
arg
(
file
.
errorString
()));
Instance
()
->
setErrorString
(
QString
(
"Open %1 filed. %2"
).
arg
(
fileName
).
arg
(
file
.
errorString
()));
...
@@ -341,7 +360,7 @@ bool Setting::setReqData(const QString &reqName, const QString &reqData, const Q
...
@@ -341,7 +360,7 @@ bool Setting::setReqData(const QString &reqName, const QString &reqData, const Q
bool
Setting
::
removeReqData
(
const
QString
&
reqName
,
const
QString
&
tag
)
bool
Setting
::
removeReqData
(
const
QString
&
reqName
,
const
QString
&
tag
)
{
{
QString
fileName
=
QString
(
"%1/%2_%3.json"
).
arg
(
CONFIGPATH
).
arg
(
tag
).
arg
(
reqName
);
QString
fileName
=
QString
(
"%1/%2_%3.json"
).
arg
(
_settingFilesPath
).
arg
(
tag
).
arg
(
reqName
);
QFile
file
(
fileName
);
QFile
file
(
fileName
);
if
(
file
.
remove
())
{
if
(
file
.
remove
())
{
return
true
;
return
true
;
...
@@ -357,5 +376,26 @@ void Setting::Log(FMLog log)
...
@@ -357,5 +376,26 @@ void Setting::Log(FMLog log)
void
Setting
::
_Log
(
FMLog
log
)
void
Setting
::
_Log
(
FMLog
log
)
{
{
if
((
int
)(
log
.
type
)
<=
Setting
::
getLogLevel
())
{
emit
newLog
(
log
);
emit
newLog
(
log
);
}
}
QString
Setting
::
getSettingFilesPath
()
{
return
_settingFilesPath
;
}
void
Setting
::
setSettingFilesPath
(
const
QString
&
settingFilesPath
)
{
QSettings
settings
;
QStringList
filePaths
=
settings
.
value
(
"FilePaths"
,
QStringList
()).
toStringList
();
if
(
filePaths
.
contains
(
settingFilesPath
))
{
filePaths
.
move
(
filePaths
.
indexOf
(
settingFilesPath
),
filePaths
.
length
()
-
1
);
}
else
{
filePaths
.
append
(
settingFilesPath
);
}
settings
.
setValue
(
"FilePaths"
,
filePaths
);
qDebug
()
<<
filePaths
;
_settingFilesPath
=
settingFilesPath
;
}
}
POS/setting.h
View file @
b05ea08b
...
@@ -5,7 +5,6 @@
...
@@ -5,7 +5,6 @@
#include <QJsonObject>
#include <QJsonObject>
#include "session.h"
#include "session.h"
#define CONFIGPATH "postest"
#define TagReqData "ReqData"
#define TagReqData "ReqData"
#define TagReqPos "ReqPOS"
#define TagReqPos "ReqPOS"
...
@@ -13,10 +12,11 @@ class FMLog
...
@@ -13,10 +12,11 @@ class FMLog
{
{
public
:
public
:
enum
FMLogType
{
enum
FMLogType
{
Info
,
Off
,
Debug
,
Error
,
Warning
,
Warning
,
Error
Debug
,
Info
};
};
explicit
FMLog
(
const
QString
&
msg
,
FMLogType
type
=
Info
)
:
explicit
FMLog
(
const
QString
&
msg
,
FMLogType
type
=
Info
)
:
...
@@ -58,6 +58,8 @@ public:
...
@@ -58,6 +58,8 @@ public:
static
void
readSetting
();
static
void
readSetting
();
static
QJsonObject
*
getSettingJsonObj
();
static
QJsonObject
*
getSettingJsonObj
();
static
int
getLogLevel
();
static
Session
*
getSession
();
static
Session
*
getSession
();
static
QList
<
Product
>
getProductList
();
static
QList
<
Product
>
getProductList
();
...
@@ -86,6 +88,10 @@ public:
...
@@ -86,6 +88,10 @@ public:
static
bool
doRequest
(
const
QJsonObject
&
reqObj
,
QJsonObject
&
rspObj
);
static
bool
doRequest
(
const
QJsonObject
&
reqObj
,
QJsonObject
&
rspObj
);
static
void
Log
(
FMLog
log
);
static
void
Log
(
FMLog
log
);
static
QString
getSettingFilesPath
();
static
void
setSettingFilesPath
(
const
QString
&
settingFilesPath
);
signals
:
signals
:
void
hasError
();
void
hasError
();
void
newLog
(
FMLog
log
);
void
newLog
(
FMLog
log
);
...
@@ -106,6 +112,8 @@ private:
...
@@ -106,6 +112,8 @@ private:
void
_Log
(
FMLog
log
);
void
_Log
(
FMLog
log
);
Session
*
_session
;
Session
*
_session
;
static
QString
_settingFilesPath
;
};
};
#endif // SETTING_H
#endif // SETTING_H
POS/settingdialog.cpp
0 → 100644
View file @
b05ea08b
#
include
"settingdialog.h"
#include "ui_settingdialog.h"
#include "setting.h"
#include <QFileDialog>
#include <QMessageBox>
#include <QSettings>
#include <QDebug>
SettingDialog
::
SettingDialog
(
QWidget
*
parent
)
:
QDialog
(
parent
),
ui
(
new
Ui
::
SettingDialog
)
{
ui
->
setupUi
(
this
);
initSettingWnd
();
}
SettingDialog
::~
SettingDialog
()
{
delete
ui
;
}
void
SettingDialog
::
initSettingWnd
()
{
QSettings
setting
;
QStringList
filePaths
=
setting
.
value
(
"FilePaths"
,
QStringList
()).
toStringList
();
for
(
int
i
=
filePaths
.
length
()
-
1
;
i
>=
0
;
i
--
)
{
ui
->
comboBox_settingDir
->
addItem
(
filePaths
[
i
]);
}
}
void
SettingDialog
::
on_btn_settingOpenDir_clicked
()
{
QString
settingPath
=
QFileDialog
::
getExistingDirectory
(
this
,
QString
::
fromLocal8Bit
(
"打开配置文件夹"
),
ui
->
comboBox_settingDir
->
currentText
());
ui
->
comboBox_settingDir
->
setCurrentText
(
settingPath
);
on_btn_settingLoad_clicked
();
}
void
SettingDialog
::
on_btn_settingLoad_clicked
()
{
}
void
SettingDialog
::
on_btn_save_clicked
()
{
if
(
onSaveConfig
())
{
this
->
accept
();
}
}
void
SettingDialog
::
on_btn_apply_clicked
()
{
onSaveConfig
();
}
void
SettingDialog
::
on_btn_quit_clicked
()
{
this
->
reject
();
}
bool
SettingDialog
::
onSaveConfig
()
{
QDir
setDir
(
ui
->
comboBox_settingDir
->
currentText
());
if
(
setDir
.
exists
())
{
Setting
::
setSettingFilesPath
(
setDir
.
absolutePath
());
Setting
::
readSetting
();
}
else
{
QMessageBox
::
critical
(
this
,
QString
::
fromLocal8Bit
(
"错误"
),
QString
::
fromLocal8Bit
(
"配置文件路径不存在"
));
return
false
;
}
return
true
;
}
void
SettingDialog
::
on_btn_delCurrentDir_clicked
()
{
QString
currenText
=
ui
->
comboBox_settingDir
->
currentText
();
QSettings
setting
;
QStringList
filePaths
=
setting
.
value
(
"FilePaths"
).
toStringList
();
if
(
filePaths
.
removeOne
(
currenText
))
{
ui
->
comboBox_settingDir
->
removeItem
(
ui
->
comboBox_settingDir
->
currentIndex
());
setting
.
setValue
(
"FilePaths"
,
filePaths
);
}
}
POS/settingdialog.h
0 → 100644
View file @
b05ea08b
#ifndef SETTINGDIALOG_H
#define SETTINGDIALOG_H
#include <QDialog>
namespace
Ui
{
class
SettingDialog
;
}
class
SettingDialog
:
public
QDialog
{
Q_OBJECT
public
:
explicit
SettingDialog
(
QWidget
*
parent
=
0
);
~
SettingDialog
();
void
initSettingWnd
();
private
slots
:
void
on_btn_settingOpenDir_clicked
();
void
on_btn_settingLoad_clicked
();
void
on_btn_save_clicked
();
void
on_btn_apply_clicked
();
void
on_btn_quit_clicked
();
bool
onSaveConfig
();
void
on_btn_delCurrentDir_clicked
();
private
:
Ui
::
SettingDialog
*
ui
;
};
#endif // SETTINGDIALOG_H
POS/settingdialog.ui
0 → 100644
View file @
b05ea08b
<?xml version="1.0" encoding="UTF-8"?>
<ui
version=
"4.0"
>
<class>
SettingDialog
</class>
<widget
class=
"QDialog"
name=
"SettingDialog"
>
<property
name=
"geometry"
>
<rect>
<x>
0
</x>
<y>
0
</y>
<width>
772
</width>
<height>
576
</height>
</rect>
</property>
<property
name=
"windowTitle"
>
<string>
Dialog
</string>
</property>
<layout
class=
"QVBoxLayout"
name=
"verticalLayout"
>
<item>
<layout
class=
"QVBoxLayout"
name=
"verticalLayout_2"
>
<item>
<layout
class=
"QHBoxLayout"
name=
"horizontalLayout"
>
<item>
<widget
class=
"QLabel"
name=
"label_settingDir"
>
<property
name=
"text"
>
<string>
配置文件路径:
</string>
</property>
</widget>
</item>
<item>
<widget
class=
"QComboBox"
name=
"comboBox_settingDir"
>
<property
name=
"editable"
>
<bool>
true
</bool>
</property>
</widget>
</item>
<item>
<spacer
name=
"horizontalSpacer_2"
>
<property
name=
"orientation"
>
<enum>
Qt::Horizontal
</enum>
</property>
<property
name=
"sizeHint"
stdset=
"0"
>
<size>
<width>
40
</width>
<height>
20
</height>
</size>
</property>
</spacer>
</item>
<item>
<widget
class=
"QPushButton"
name=
"btn_settingOpenDir"
>
<property
name=
"toolTip"
>
<string>
打开本地配置文件夹
</string>
</property>
<property
name=
"whatsThis"
>
<string>
打开本地配置文件夹
</string>
</property>
<property
name=
"text"
>
<string>
打开
</string>
</property>
</widget>
</item>
<item>
<widget
class=
"QPushButton"
name=
"btn_settingLoad"
>
<property
name=
"text"
>
<string>
加载
</string>
</property>
</widget>
</item>
<item>
<widget
class=
"QPushButton"
name=
"btn_delCurrentDir"
>
<property
name=
"text"
>
<string>
删除此记录
</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget
class=
"QToolBox"
name=
"toolBox"
>
<property
name=
"currentIndex"
>
<number>
0
</number>
</property>
<widget
class=
"QWidget"
name=
"page_base"
>
<property
name=
"geometry"
>
<rect>
<x>
0
</x>
<y>
0
</y>
<width>
752
</width>
<height>
390
</height>
</rect>
</property>
<attribute
name=
"label"
>
<string>
基础信息
</string>
</attribute>
</widget>
<widget
class=
"QWidget"
name=
"page_log"
>
<property
name=
"geometry"
>
<rect>
<x>
0
</x>
<y>
0
</y>
<width>
752
</width>
<height>
390
</height>
</rect>
</property>
<attribute
name=
"label"
>
<string>
日志
</string>
</attribute>
</widget>
<widget
class=
"QWidget"
name=
"page_payList"
>
<property
name=
"geometry"
>
<rect>
<x>
0
</x>
<y>
0
</y>
<width>
752
</width>
<height>
390
</height>
</rect>
</property>
<attribute
name=
"label"
>
<string>
支付方式
</string>
</attribute>
</widget>
<widget
class=
"QWidget"
name=
"page_products"
>
<property
name=
"geometry"
>
<rect>
<x>
0
</x>
<y>
0
</y>
<width>
752
</width>
<height>
390
</height>
</rect>
</property>
<attribute
name=
"label"
>
<string>
商品信息
</string>
</attribute>
</widget>
</widget>
</item>
</layout>
</item>
<item>
<layout
class=
"QHBoxLayout"
name=
"horizontalLayout_2"
>
<item>
<spacer
name=
"horizontalSpacer"
>
<property
name=
"orientation"
>
<enum>
Qt::Horizontal
</enum>
</property>
<property
name=
"sizeHint"
stdset=
"0"
>
<size>
<width>
40
</width>
<height>
20
</height>
</size>
</property>
</spacer>
</item>
<item>
<widget
class=
"QPushButton"
name=
"btn_save"
>
<property
name=
"toolTip"
>
<string>
保存并退出
</string>
</property>
<property
name=
"whatsThis"
>
<string>
保存并退出
</string>
</property>
<property
name=
"text"
>
<string>
保存
</string>
</property>
</widget>
</item>
<item>
<widget
class=
"QPushButton"
name=
"btn_quit"
>
<property
name=
"toolTip"
>
<string>
直接退出不保存
</string>
</property>
<property
name=
"whatsThis"
>
<string>
直接退出不保存
</string>
</property>
<property
name=
"text"
>
<string>
退出
</string>
</property>
</widget>
</item>
<item>
<widget
class=
"QPushButton"
name=
"btn_apply"
>
<property
name=
"toolTip"
>
<string>
保存配置信息
</string>
</property>
<property
name=
"whatsThis"
>
<string>
保存配置信息
</string>
</property>
<property
name=
"text"
>
<string>
应用
</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment