-
Notifications
You must be signed in to change notification settings - Fork 0
/
responsecookies.cpp
54 lines (47 loc) · 1.88 KB
/
responsecookies.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
#include "responsecookies.h"
#include "ui_responsecookies.h"
#include <QNetworkCookie>
#include <qdebug.h>
#include <QDateTime>
ResponseCookies::ResponseCookies(QWidget *parent) :
QWidget(parent),
ui(new Ui::ResponseCookies)
{
ui->setupUi(this);
}
ResponseCookies::~ResponseCookies()
{
delete ui;
qDebug()<<" RESPONSE COOKIES DELETED";
}
void ResponseCookies::clear() {
ui->tableWidget->clear();
}
void ResponseCookies::setCookies(const QList<QNetworkCookie>& responseCookies) {
// Create a QTableWidget
QTableWidget* tableWidget = ui->tableWidget;
tableWidget->setRowCount(responseCookies.size());
tableWidget->setColumnCount(4);
tableWidget->setHorizontalHeaderLabels({"Name", "Domain","Path","Expiration Date"});
auto tableWidgetLayout = static_cast<QWidget*>(ui->tableWidget->parent());
auto availableWidth = tableWidgetLayout->width();
auto perColumnWidth = availableWidth / ui->tableWidget->columnCount();
tableWidget->setColumnWidth(0,perColumnWidth);
tableWidget->setColumnWidth(1,perColumnWidth);
tableWidget->setColumnWidth(2,perColumnWidth);
tableWidget->setColumnWidth(3,perColumnWidth);
int row = 0;
for (const auto& cookie : responseCookies)
{
QTableWidgetItem* nameItem = new QTableWidgetItem(QString::fromUtf8(cookie.name()));
QTableWidgetItem* domainItem = new QTableWidgetItem(cookie.domain());
tableWidget->setItem(row, 0, nameItem);
tableWidget->setItem(row, 1, domainItem);
QTableWidgetItem* pathItem = new QTableWidgetItem(cookie.path());
QTableWidgetItem* expirationDateItem = new QTableWidgetItem(cookie.expirationDate().toLocalTime().toString());
tableWidget->setItem(row, 2, pathItem);
tableWidget->setItem(row, 3, expirationDateItem);
++row;
}
tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
}