Page MenuHomeGitPull.it

widget.cpp
No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None

widget.cpp

#include "widget.h"
#include "ui_widget.h"
#include "timetableParser.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget) {
ui->setupUi(this);
}
Widget::~Widget() {
delete ui;
}
bool is_number(const std::string& s) {
return !s.empty() && std::find_if(s.begin(), s.end(), [](unsigned char c) { return !std::isdigit(c); }) == s.end();
}
void enter(Ui::Widget *ui) {
ui->txtId->setFocus();
// clear the text in the textBrowser
ui->txtOutput->clear();
// take the input from txtId QLineEdit
QString Qid(ui->txtId->text());
string id = Qid.toUtf8().constData();
ui->txtOutput->setText("<b>" + Qid + "</b>");
if (is_number(id)) {
// get the lines from the TimetableParser object
TimetableParser tp;
vector<Line> lines = tp.getTimetable(id);
// print the lines on txtOutput QTextBrowser
for (vector<Line>::iterator it = lines.begin() ; it != lines.end(); ++it) {
Line line = *it;
QString QOutput(QString::fromUtf8(line.getName().c_str()) + "\t");
vector<string> passages(line.getPassages());
for (vector<string>::iterator jt = passages.begin() ; jt != passages.end(); ++jt) {
string str = *jt;
QOutput += QString::fromUtf8(str.c_str()) + "\t";
}
ui->txtOutput->append(QOutput);
}
} else if (id.compare("") != 0)
ui->txtOutput->setText("\"" + QString::fromUtf8(id.c_str()) + "\" is not a valid stop id");
}
void Widget::on_btnOk_clicked() { enter(ui); }
void Widget::on_txtId_returnPressed() { enter(ui); }

File Metadata

Mime Type
text/x-c
Expires
Thu, Nov 19, 00:43 (23 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2263580
Default Alt Text
widget.cpp (1 KB)

Event Timeline