Fotobot
Get data from your photovoltaic plant
geocontroller.cpp
Go to the documentation of this file.
1 
6 #include "geocontroller.h"
7 #include <QVariant>
8 #include <QDateTime>
9 
11  qRegisterMetaType<DBT_GEOCOORDINATES>();
12  connect(this, SIGNAL(saveGeocoordinates(DBT_GEOCOORDINATES)), Static::db, SLOT(setGeocoordinates(DBT_GEOCOORDINATES)), Qt::BlockingQueuedConnection);
13 }
14 
15 void GeoController::servicePrivate(HttpRequest& request) {
16  QByteArray action = request.getParameter("action");
17 
20  actionGeo(request);
21 }
22 
24  QString s;
25  QString i ("<tr><td><label for=\"%2\">%1</label>: </td><td><input type=\"text\" name=\"%2\" value=\"%3\" /></td></tr>\n");
26  s.append(i.arg(tr("Longitude"), "longitude", geo.longitude.toString()));
27  s.append(i.arg(tr("Latitude"), "latitude", geo.latitude.toString()));
28  return s;
29 }
30 
31 void GeoController::readGeoForm(DBT_GEOCOORDINATES& geo, HttpRequest& request) {
32  geo.longitude = request.getParameter("longitude");
33  geo.latitude = request.getParameter("latitude");
34 }
35 
39 void GeoController::actionGeo(HttpRequest& request) {
40  QByteArray action = request.getParameter("action");
43  write(QString("<h3>%1</h3>\n").arg(tr("Geographical coordinates settings")));
44  write("<form method=\"post\">\n"
45  "<input type=\"hidden\" name=\"action\" value=\"geo2\" />\n");
46  if(action != "geo2") {
47  DBT_GEOCOORDINATES g = Static::db->geocoordinates();
48  qDebug() << "GEO" << g.longitude << g.latitude;
49  write("<table class=\"formTable\">");
50  write(getGeoFormContents(g));
51  write("</table>");
52  } else {
53  readGeoForm(geo, request);
54  write("<table class=\"formTable\">");
55  write(getGeoFormContents(geo));
56  write("</table>");
57  }
58  write(QString("<input type=\"submit\" value=\"%1\">\n"
59  "</form>\n").arg(tr("Save")));
60  if(action == "geo2") {
63  if(true) {
64  emit saveGeocoordinates(geo);
65  Static::slunce->setObserver(geo.latitude.toDouble(), geo.longitude.toDouble());
66  QString location = QString("/settings?message=%1").arg(percentEncode(tr("Geographical coordinates edited.")));
67  redirect(location);
68  } else {
69  write(QString("<p>%1</p>").arg(tr("Error: Geographical coordinates definition invalid.")));
70  }
71  }
72 }
73 
Class describing database table GEOCOORDINATES.
void servicePrivate(HttpRequest &request)
void actionGeo(HttpRequest &request)
void setObserver(double lat, double lng)
Definition: slunce.cpp:40
static void readGeoForm(DBT_GEOCOORDINATES &geo, HttpRequest &request)
static QString getGeoFormContents(DBT_GEOCOORDINATES geo=DBT_GEOCOORDINATES())
DBT_GEOCOORDINATES geocoordinates()
Returns geocoordinates.
Definition: database.cpp:581