|
void | setStatus (int code, QByteArray description) |
|
void | setHeader (QByteArray name, QByteArray value) |
|
void | setHeader (QByteArray name, int value) |
|
void | write (QByteArray data) |
|
void | write (QString data) |
|
void | write (const char *data) |
|
void | about () |
|
HttpSession | getSession () |
|
virtual void | writeHeader (HttpRequest &request, HttpResponse &response) |
|
virtual void | writeFooter (HttpRequest &request, HttpResponse &response) |
|
Protected Member Functions inherited from MRequestHandler |
bool | needsLogin (HttpRequest &request, HttpResponse &response) |
|
QString | m_javascript |
|
Protected Attributes inherited from MRequestHandler |
bool | m_needs_access_data |
|
bool | m_needs_change_settings |
|
bool | m_cacheable |
|
Definition at line 16 of file linescontroller.h.
LinesController::LinesController |
( |
| ) |
|
Constructor
Definition at line 13 of file linescontroller.cpp.
14 qRegisterMetaType<DBT_LINES>();
15 connect(
this, SIGNAL(saveLine(
DBT_LINES)), Static::db, SLOT(saveLine(
DBT_LINES)), Qt::BlockingQueuedConnection);
16 connect(
this, SIGNAL(deleteLine(
int)), Static::db, SLOT(deleteLine(
int)), Qt::QueuedConnection);
17 qRegisterMetaType<DBT_INVERTORS>();
Class describing database table LINES.
Class describing database table INVERTORS.
void LinesController::actionAdd |
( |
HttpRequest & |
request | ) |
|
|
private |
Add a line action
a form
invertor generator form
second page doing the action and redirecting
validation
invertor generation
Definition at line 129 of file linescontroller.cpp.
130 QByteArray action = request.getParameter(
"action");
132 write(QString(
"<h3>%1</h3>\n").arg(tr(
"Add a line")));
133 write(
"<form method=\"post\">\n"
134 "<input type=\"hidden\" name=\"action\" value=\"add2\" />\n");
137 write(
"<table class=\"formTable\">");
141 write(QString(
"<tr><td><h4>%1</h4></td><td></td></tr>").arg(tr(
"Generate Invertors")));
144 if(invertor.address < 1) invertor.address = 1;
148 write(QString(
"<input type=\"submit\" value=\"%1\">\n"
149 "</form>\n").arg(tr(
"Add")));
150 if(action ==
"add2") {
153 invertor.invertor = 0;
156 invertor.line = Static::db->
saveLine(line);
159 QByteArray generate = request.getParameter(
"generate");
160 int gen = (generate.isEmpty()) ? 0 : generate.toInt();
161 for(
int j = 0; j < gen; j++) {
162 emit saveInvertor(invertor);
166 QString location = QString(
"/lines?message=%1").arg(percentEncode(tr(
"Line added.")));
169 write(QString(
"<p>%1</p>").arg(tr(
"Line definition invalid.")));
static QString getEditFormContents(const DBT_LINES &line=DBT_LINES())
static QString getEditFormContents(HttpRequest &request, DBT_INVERTORS line=DBT_INVERTORS(), bool generator=false)
static void readForm(DBT_INVERTORS &invertor, HttpRequest &request)
int saveLine(QSqlDatabase &, DBT_LINES)
Insert or update LINE.
static void readForm(DBT_LINES &line, HttpRequest &request)
Class describing database table LINES.
Class describing database table INVERTORS.
void LinesController::actionDelete |
( |
HttpRequest & |
request | ) |
|
|
private |
Delete line action
Definition at line 223 of file linescontroller.cpp.
224 write(QString(
"<h3>%1</h3>\n").arg(tr(
"Delete a line")));
226 QByteArray
id = request.getParameter(
"id");
227 int idi =
id.toInt();
228 if(!
id.isEmpty() && idi > 0) {
229 emit deleteLine(idi);
230 location = QString(
"/lines?message=%1").arg(percentEncode(tr(
"Line deleted.")));
232 location = QString(
"/lines?message=%1").arg(percentEncode(tr(
"Error: Invalid line ID. Line not deleted.")));
void LinesController::actionEdit |
( |
HttpRequest & |
request | ) |
|
|
private |
Edit line action
a form
second page doing the action and redirecting validation
Definition at line 177 of file linescontroller.cpp.
178 QByteArray action = request.getParameter(
"action");
181 write(QString(
"<h3>%1</h3>\n").arg(tr(
"Edit a line")));
182 write(
"<form method=\"post\">\n"
183 "<input type=\"hidden\" name=\"action\" value=\"edit2\" />\n");
184 if(action ==
"edit") {
185 QByteArray
id = request.getParameter(
"id");
186 int idi =
id.toInt();
187 if(
id.isEmpty() || idi < 1) {
188 redirect(QString(
"/lines?message=%1").arg(percentEncode(tr(
"Error: Invalid line ID."))));
191 QList<DBT_LINES> lines = Static::db->
lines(idi);
193 redirect(QString(
"/lines?message=%1").arg(percentEncode(tr(
"Error: no such line found."))));
196 write(
"<table class=\"formTable\">");
201 write(
"<table class=\"formTable\">");
205 write(QString(
"<input type=\"submit\" value=\"%1\">\n"
206 "</form>\n").arg(tr(
"Edit")));
207 if(action ==
"edit2") {
210 if(line.line > 0 &&
true) {
212 QString location = QString(
"/lines?message=%1").arg(percentEncode(tr(
"Line edited.")));
215 write(QString(
"<p>%1</p>").arg(tr(
"Error: Line definition invalid.")));
QList< DBT_LINES > lines(int line=0)
Returns list of communications lines.
static QString getEditFormContents(const DBT_LINES &line=DBT_LINES())
static void readForm(DBT_LINES &line, HttpRequest &request)
Class describing database table LINES.
Generates an edit form contents (html input fields)
Definition at line 64 of file linescontroller.cpp.
66 s.append(QString(
"<input type=\"hidden\" name=\"id\" value=\"%1\" />\n").arg(line.line));
67 QString i (
"<tr><td><label for=\"%2\">%1</label>: </td><td><input type=\"text\" name=\"%2\" value=\"%3\" /></td></tr>\n");
68 s.append(i.arg(tr(
"Description"),
"description", line.description));
69 s.append(i.arg(tr(
"Serial Number Format"),
"sn_format", line.sn_format));
72 sel += QString(
"<option value=\"%1\" %2>%3</option>")
73 .arg(DBT_LINES::Fronius)
74 .arg((line.type == DBT_LINES::Fronius)?
"selected=\"selected\"" :
"")
75 .arg(
"Fronius (interfacebox)")
77 sel += QString(
"<option value=\"%1\" %2>%3</option>")
78 .arg(DBT_LINES::ModbusTCP)
79 .arg((line.type == DBT_LINES::ModbusTCP)?
"selected=\"selected\"" :
"")
82 s.append(QString(
"<tr><td>%1</td><td><select id=\"type\" name=\"type\">%2</select></td>")
87 s.append(i.arg(tr(
"Device"),
"device", line.device));
88 s.append(i.arg(tr(
"Hostname"),
"hostname", line.hostname));
89 s.append(i.arg(tr(
"Port number"),
"portnumber", QString::number(line.portnumber)));
91 s.append(QString(
"<tr><td><label for=\"%2\">%1</label>: </td><td><select id=\"%2\" name=\"%2\">\n").arg(tr(
"Speed"),
"speed"));
93 speeds << 110 << 300 << 600 << 1200 << 2400 << 4800 << 9600 << 19200 << 38400 << 57600 << 115200;
94 QList<int>::const_iterator ii;
95 for(ii = speeds.constBegin(); ii != speeds.constEnd(); ++ii) {
97 s.append(QString(
"<option value=\"%1\" %2>%1</option>\n")
98 .arg(sp).arg((sp == line.speed) ?
"selected=\"selected\"" :
""));
100 s.append(
"</select></td></tr>\n");
102 s.append(i.arg(tr(
"Retries"),
"retries").arg(line.retries));
103 s.append(i.arg(tr(
"Timeout [ms]"),
"timeout").arg(line.timeout));
void LinesController::readForm |
( |
DBT_LINES & |
line, |
|
|
HttpRequest & |
request |
|
) |
| |
|
static |
Read form HTTP post reply and load into the line
Definition at line 107 of file linescontroller.cpp.
108 line.line = request.getParameter(
"id").toInt();
109 line.device = request.getParameter(
"device");
110 line.description = request.getParameter(
"description");
111 line.sn_format = request.getParameter(
"sn_format");
112 QByteArray p = request.getParameter(
"speed");
113 line.speed = (p.isEmpty()) ? 9600 : p.toInt();
114 p = request.getParameter(
"retries");
115 line.retries = (p.isEmpty()) ? 5 : p.toInt();
116 p = request.getParameter(
"timeout");
117 line.timeout = (p.isEmpty()) ? 3000 : p.toInt();
118 p = request.getParameter(
"type");
119 line.type = (DBT_LINES::Type)(
120 (p.isEmpty()) ? DBT_LINES::Fronius : p.toInt()
122 line.hostname = request.getParameter(
"hostname");
123 line.portnumber = request.getParameter(
"portnumber").toInt();
void LinesController::servicePrivate |
( |
HttpRequest & |
request | ) |
|
|
virtual |
Generates the response
Default action/page
Implements WebPage.
Definition at line 21 of file linescontroller.cpp.
22 QByteArray action = request.getParameter(
"action");
23 if(action.startsWith(
"add")) {
25 }
else if(action.startsWith(
"edit")) {
27 }
else if(action.startsWith(
"delete")) {
33 QList<DBT_LINES> lines = Static::db->
lines();
34 write(QString(
"<h2>%1</h2>\n").arg(tr(
"Lines")));
35 write(QString(
"<a href=\"/lines?action=add\">%1</a>\n").arg(tr(
"Add a line")));
37 write(QString(
"<tr><th></th><th>%1</th><th>%2</th><th>%3</th><th>%4</th><th>%5</th><th>%6</th><th>%7</th><th>%8</th></tr>\n").arg(tr(
"Line"), tr(
"Device"), tr(
"IP address"), tr(
"Description"), tr(
"Serial Number Format"), tr(
"Speed"), tr(
"Retries"), tr(
"Timeout [ms]")));
39 QList<DBT_LINES>::const_iterator i;
40 for(i = lines.constBegin(); i != lines.constEnd(); ++i) {
42 write(QString(
"<tr><td>"
43 "<a href=\"/lines?action=edit&id=%1\">%9</a> "
44 "<a href=\"/lines?action=delete&id=%1\">%10</a>"
46 "<td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td><td>%6</td><td>%7</td><td>%8</td>"
50 .arg(l.hostname +
":" + QString::number(l.portnumber) )
QList< DBT_LINES > lines(int line=0)
Returns list of communications lines.
void actionEdit(HttpRequest &request)
void actionAdd(HttpRequest &request)
void actionDelete(HttpRequest &request)
Class describing database table LINES.
The documentation for this class was generated from the following files: