-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcardetail.cpp
81 lines (76 loc) · 2.1 KB
/
cardetail.cpp
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
#include "cardetail.h"
#include "ui_cardetail.h"
#include "settings.h"
#include <QNetworkRequest>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonObject>
#include <QMessageBox>
#include <QDesktopWidget>
#include <QProcessEnvironment>
#include <QVBoxLayout>
#include <QLabel>
#include <QFrame>
CarDetail::CarDetail(int id, QWidget *parent) :
QDialog(parent),id(id),ui(new Ui::CarDetail)
{
ui->setupUi(this);
if(QProcessEnvironment::systemEnvironment().value("OS")!=QString("Windows_NT"))
{
QRect applicationGeometry=QApplication::desktop()->availableGeometry();
this->setFixedSize(applicationGeometry.size());
}
panel=new TouchableScrollArea(this);
ui->verticalLayout->insertWidget(0,panel);
QWidget *w=new QWidget(panel);
w->setFixedWidth(panel->width());
panel->setWidget(w);
QNetworkRequest request(QUrl(Settings::CarDetailpage));
QByteArray data;
data.append("id=").append(QString::number(id));
NAM.post(request,data);
connect(&NAM,&QNetworkAccessManager::finished,this,&CarDetail::finished);
}
CarDetail::~CarDetail()
{
delete ui;
}
long CarDetail::getId() const
{
return id;
}
void CarDetail::setId(long value)
{
id = value;
}
void CarDetail::finished(QNetworkReply *r)
{
QWidget *w = new QWidget(this);
w->setFixedWidth(panel->width()-30);
QVBoxLayout *lay=new QVBoxLayout();
w->setLayout(lay);
QByteArray raw=r->readAll();
QJsonObject JObj=QJsonDocument::fromJson(raw).object();
if(JObj["status"].toString()=="fail")
{
QMessageBox::warning(0,QString("错误"),JObj["msg"].toString());
return;
}
QJsonObject info=JObj["info"].toObject();
QLabel *l;
QFrame *line;
line=new QFrame(w);
line->setFrameShape(QFrame::HLine);
line->setLineWidth(0);
lay->addWidget(line);
foreach(QString key,info.keys())
{
l=new QLabel(key+":"+info.value(key).toString(),w);
lay->addWidget(l);
line=new QFrame(w);
line->setFrameShape(QFrame::HLine);
line->setLineWidth(0);
lay->addWidget(line);
}
panel->setWidget(w);
}