I'm waiting for your appreciated reviews and feedback.
Thanks and Regards, Gehad Elrobey
>From c6e4ad14683cf720b79393949516cc97766b76ab Mon Sep 17 00:00:00 2001 From: Gehad elrobey <gehadelro...@gmail.com> Date: Tue, 25 Mar 2014 14:59:25 +0200 Subject: [PATCH] Exporting a World-Map prototype This patch is a proof of concept for the world map exporter. I added worldmap-save.c that writes the html to the file, I used google maps v3 API to put the place marks on the map. This patch is missing interfacing the membuff before writing to the file directly as the xml-save also some functions need to be seperated and to be able to change some options rather than just dumping static html to the file. I also added the save HTML action in the mainwindow user interface, some neat interfacing is missing with the existing File interfaces. Also some additional dive information should appear by mouse hovering. Signed-off-by: Gehad elrobey <gehadelro...@gmail.com> --- qt-ui/mainwindow.cpp | 10 ++++++ qt-ui/mainwindow.h | 1 + qt-ui/mainwindow.ui | 6 ++++ subsurface.pro | 2 ++ worldmap-save.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++ worldmap-save.h | 16 +++++++++ 6 files changed, 135 insertions(+) create mode 100644 worldmap-save.c create mode 100644 worldmap-save.h diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index e77fa6b..69eca9d 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -38,6 +38,7 @@ #include "about.h" #include "printdialog.h" #include "divelogimportdialog.h" +#include "worldmap-save.h" MainWindow *MainWindow::m_Instance = NULL; @@ -262,6 +263,15 @@ void MainWindow::on_actionExportUDDF_triggered() export_dives_uddf(filename.toUtf8(), false); } +void MainWindow::on_actionExportHTMLworldmap_triggered() +{ + QFileInfo fi(system_default_filename()); + QString filename = QFileDialog::getSaveFileName(this, tr("Save File as"), fi.absolutePath(), + tr("HTML files (*.html)")); + if (!filename.isNull() && !filename.isEmpty()) + writeinfile(filename.toStdString().c_str()); +} + void MainWindow::on_actionPrint_triggered() { PrintDialog dlg(this); diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index e249398..37f6f86 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -91,6 +91,7 @@ slots: void on_actionSaveAs_triggered(); void on_actionClose_triggered(); void on_actionExportUDDF_triggered(); + void on_actionExportHTMLworldmap_triggered(); void on_actionPrint_triggered(); void on_actionPreferences_triggered(); void on_actionQuit_triggered(); diff --git a/qt-ui/mainwindow.ui b/qt-ui/mainwindow.ui index a933a2d..329015e 100644 --- a/qt-ui/mainwindow.ui +++ b/qt-ui/mainwindow.ui @@ -551,6 +551,7 @@ <addaction name="separator"/> <addaction name="actionClose"/> <addaction name="actionExportUDDF"/> + <addaction name="actionExportHTMLworldmap"/> <addaction name="actionPrint"/> <addaction name="actionPreferences"/> <addaction name="separator"/> @@ -681,6 +682,11 @@ <string>Ctrl+U</string> </property> </action> + <action name="actionExportHTMLworldmap"> + <property name="text"> + <string>Export &HTML</string> + </property> + </action> <action name="actionPrint"> <property name="text"> <string>&Print</string> diff --git a/subsurface.pro b/subsurface.pro index 98f23b7..e27e235 100644 --- a/subsurface.pro +++ b/subsurface.pro @@ -27,6 +27,7 @@ HEADERS = \ helpers.h \ libdivecomputer.h \ planner.h \ + worldmap-save.h \ pref.h \ profile.h \ qt-gui.h \ @@ -90,6 +91,7 @@ SOURCES = \ parse-xml.c \ planner.c \ profile.c \ + worldmap-save.c \ qt-gui.cpp \ qthelper.cpp \ qt-ui/about.cpp \ diff --git a/worldmap-save.c b/worldmap-save.c new file mode 100644 index 0000000..f794d3f --- /dev/null +++ b/worldmap-save.c @@ -0,0 +1,100 @@ +#include <stdarg.h> +#include <stdlib.h> +#include <string.h> +#include <stdio.h> +#include "dive.h" +#include "worldmap-save.h" + + +char* getlonlat(degrees_t lat,degrees_t lon) +{ + char* output = malloc(50*sizeof(char)); + sprintf(output,"%f,%f",lat.udeg/1000000.0,(float)lon.udeg/1000000.0); + return output; +} + +char* getdate(int when) +{ + char* output = malloc(50*sizeof(char)); + struct tm t; + utc_mkdate(when, &t); + sprintf(output,"%04u-%02u-%02u", + t.tm_year + 1900, t.tm_mon + 1, t.tm_mday); + return output; +} + +void writeMarkers(FILE *f){ + int i; + struct dive *dive; + + for_each_dive(i, dive) { + //if (!dive->selected) + // continue; + char* latlng = getlonlat ( dive->latitude , dive->longitude ); + char* month = getdate( dive->when ); + //get these data from dives + + fputs("\ttemp = new google.maps.Marker({\n\ + position: new google.maps.LatLng(",f); + fputs(latlng,f); + fputs("),\n\ + title:\"",f); + fputs(month,f); + fputs("\"\n\ + });\n\ + markers.push(temp);\n",f); + free(latlng); + free(month); + } +} + +void writeinfile(const char* x){ + FILE *f; + char filename[256]; + strcpy(filename,x); + strcat(filename,".html"); + f = fopen(filename,"w+"); + if(!f)printf("error"); + + fputs("<!DOCTYPE html>\n\ + <html>\n\ + <head>\n\ + <meta name=\"viewport\" content=\"initial-scale=1.0, user-scalable=no\" />\n\ + <style type=\"text/css\">\n\ + html { height: 100% }\n\ + body { height: 100%; margin: 0; padding: 0 }\n\ + #map-canvas { height: 100% }\n\ + </style>\n",f); + fputs("\t<script type=\"text/javascript\"\ +src=\"https://maps.googleapis.com/maps/api/js?key=AIzaSyDzo9PWsqYDDSddVswg_13rpD9oH_dLuoQ&sensor=false\">\n\ + </script>\n\ + <script type=\"text/javascript\">\n\ + var map;\n\ + function initialize() {\n\ + var mapOptions = {\n\ + center: new google.maps.LatLng(0,0),\n\ + zoom: 3,\n\ + minZoom: 2,\n\ + mapTypeId: google.maps.MapTypeId.SATELLITE,\n\ + rotateControl: false,\n\ + streetViewControl: false,\n\ + mapTypeControl: false\n\ + };\n\ + map = new google.maps.Map(document.getElementById(\"map-canvas\"),\ +mapOptions);\n\ + var markers = new Array();\n",f); + //put dynamic markers into file + fputs("\tvar temp;\n",f); + writeMarkers(f); + fputs("\tfor(var i=0;i<markers.length;i++)\n\ + markers[i].setMap(map);\n}\n",f); + fputs("\ + google.maps.event.addDomListener(window, 'load', initialize);\n\ + </script>\n",f); + fputs("\t</head>\n\ + <body>\n\ + <div id=\"map-canvas\"/>\n\ + </body>\n\ + </html>",f); + fclose(f); +} diff --git a/worldmap-save.h b/worldmap-save.h new file mode 100644 index 0000000..c011bed --- /dev/null +++ b/worldmap-save.h @@ -0,0 +1,16 @@ +#ifndef WORLDMAPSAVE_H +#define WORLDMAPSAVE_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern void writeinfile(const char* x); + + + +#ifdef __cplusplus +} +#endif + +#endif -- 1.8.3.2
_______________________________________________ subsurface mailing list subsurface@hohndel.org http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface