-
Notifications
You must be signed in to change notification settings - Fork 0
/
qjobviewer.cpp
99 lines (84 loc) · 2.94 KB
/
qjobviewer.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "qjobviewer.h"
#include <QDir>
#include <QFile>
#include <QJsonDocument>
QJobViewer::QJobViewer(QWidget *parent)
: QMainWindow(parent)
{
central = new QWidget(this);
this->setCentralWidget(central);
auto layout = new QGridLayout(central);
// Widget for loading json to the model
inputField = new JobGetter;
layout->addWidget(inputField);
connect(inputField,&JobGetter::jsonLoaded,this,&QJobViewer::jsonLoaded);
// Tab Widget
//1. Set up tab widget
tabs = new QTabWidget;
//1.a. Set up settings tab
auto settingsPage = new QWidget;
auto settingsGrid = new QVBoxLayout(settingsPage);
settingsView = new QTableView();
settingsGrid->addWidget(settingsView);
tabs->addTab(settingsPage,"Settings");
//2. Finish tab widget
layout->addWidget(tabs);
central->setLayout(layout);
// this->setLayout(layout);
}
JobGetter::JobGetter(QWidget *parent)
: QWidget(parent)
{
auto fieldLayout = new QGridLayout(this);
m_urlInputCBox = new QComboBox;
m_urlInputCBox->setEditable(true);
m_urlInputCBox->setPlaceholderText(tr("Please type job URL"));
m_urlInputCBox->setInsertPolicy(QComboBox::InsertAtTop);
fieldLayout->addWidget(m_urlInputCBox,0,0);
m_viewButton = new QPushButton(tr("Get Job"));
m_viewButton->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
fieldLayout->addWidget(m_viewButton,0,1);
connect(m_viewButton,&QPushButton::clicked,this,&JobGetter::setURL);
auto m_fileDialog = new QFileDialog(this);
m_fileDialog->setFileMode(QFileDialog::ExistingFile);
auto m_fileButton = new QPushButton(tr("Open JobCSV"));
m_fileButton->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
fieldLayout->addWidget(m_fileButton,0,2);
connect(m_fileButton,&QPushButton::clicked,this,&JobGetter::loadFile);
m_displayLabel = new QLabel("");
fieldLayout->addWidget(m_displayLabel,1,0);
}
void JobGetter::loadFile(){
QString fileName;
#ifdef QT_DEBUG
fileName = "/home/user/qa-dev/QJobViewer/test.json";
#else
fileName = QFileDialog::getOpenFileName(this,
tr("Open JSON"), QDir::currentPath(), tr("JSON Files (*.json)"));
#endif
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)){
qWarning()<<"Couldn't open file "<<fileName;
m_displayLabel->setText("Couldn't open file "+fileName);
}
QByteArray data = file.readAll();
QJsonParseError err;
auto doc = QJsonDocument::fromJson(data,&err);
if (doc.isNull()){
qWarning()<<err.errorString();
m_displayLabel->setText(err.errorString());
}
emit jsonLoaded(doc.object());
}
void JobGetter::setURL()
{
auto txt = m_urlInputCBox->currentText();
auto url = QUrl(txt);
qWarning()<<"Validity:"<<url.isValid()<<" Content:"<<url;
if (url.isValid()){
m_displayLabel->setText(txt);
m_urlInputCBox->insertItem(0,txt);
} else {
m_displayLabel->setText("Invalid URL.");
}
}