Serial-Studio/libs/QMapControl/html/citymap_8cpp-example.html
2021-12-06 10:56:03 -06:00

537 lines
34 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>QMapControl: citymap.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.9 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
<li><a href="examples.html"><span>Examples</span></a></li>
</ul>
</div>
</div>
<div class="contents">
<h1>citymap.cpp</h1>This demo appclication shows more features of the QMapControl. It shows images, which changes its size when changing the zoomlevel. You can display/hide layers and choose different map providers. Also it demonstrates more possibilities for user interaction:<br>
<ul>
<li>notes can be added to any coordinate (a QTextEdit is used for editing the note)<br>
</li><li>the user can measure distances between two points</li></ul>
<p>
<div align="center">
<img src="sample_citymap.png" alt="sample_citymap.png">
<p><strong>screenshot</strong></p></div>
<div class="fragment"><pre class="fragment">
<span class="preprocessor">#include "citymap.h"</span>
Citymap::Citymap(QWidget*)
{
<span class="comment">// create MapControl</span>
mc = <span class="keyword">new</span> MapControl(QSize(380,540));
mc-&gt;showScale(<span class="keyword">true</span>);
<span class="comment">// display the MapControl in the application</span>
QVBoxLayout* layout = <span class="keyword">new</span> QVBoxLayout;
layout-&gt;addWidget(mc);
QWidget* w = <span class="keyword">new</span> QWidget();
w-&gt;setLayout(layout);
setCentralWidget(w);
notepixmap = <span class="keyword">new</span> QPixmap(QCoreApplication::applicationDirPath() + <span class="stringliteral">"/images/note.png"</span>);
coord1 = QPointF();
coord2 = QPointF();
mapadapter = <span class="keyword">new</span> OSMMapAdapter();
MapAdapter* mapadapter_overlay = <span class="keyword">new</span> YahooMapAdapter(<span class="stringliteral">"us.maps3.yimg.com"</span>, <span class="stringliteral">"/aerial.maps.yimg.com/png?v=2.2&amp;t=h&amp;s=256&amp;x=%2&amp;y=%3&amp;z=%1"</span>);
<span class="comment">// create a layer with the mapadapter and type MapLayer</span>
l = <span class="keyword">new</span> MapLayer(<span class="stringliteral">"Custom Layer"</span>, mapadapter);
overlay = <span class="keyword">new</span> MapLayer(<span class="stringliteral">"Overlay"</span>, mapadapter_overlay);
overlay-&gt;setVisible(<span class="keyword">false</span>);
mc-&gt;addLayer(l);
mc-&gt;addLayer(overlay);
notes = <span class="keyword">new</span> GeometryLayer(<span class="stringliteral">"Notes"</span>, mapadapter);
createTours();
addSights();
addPubs();
addMuseums();
addZoomButtons();
createActions();
createMenus();
mc-&gt;addLayer(notes);
connect(notes, SIGNAL(geometryClicked(Geometry*, QPoint)),
<span class="keyword">this</span>, SLOT(editNote(Geometry*, QPoint)));
mc-&gt;setView(QPointF(8.26,50));
mc-&gt;setZoom(13);
ignoreClicks = <span class="keyword">false</span>;
addingNote = <span class="keyword">false</span>;
noteID = 0;
notetextedit = <span class="keyword">new</span> QTextEdit(mc);
notetextedit-&gt;setGeometry(0,0,200,100);
notepoint = <span class="keyword">new</span> Point(0, 0, notetextedit, <span class="stringliteral">"."</span>, Point::TopLeft);
notepoint-&gt;setVisible(<span class="keyword">false</span>);
notes-&gt;addGeometry(notepoint);
}
<span class="keywordtype">void</span> Citymap::createTours()
{
QPen* pen = <span class="keyword">new</span> QPen(QColor(0,0,255,100));
pen-&gt;setWidth(5);
QList&lt;Point*&gt; points;
points &lt;&lt; <span class="keyword">new</span> Point(8.2606, 50.0051);
points &lt;&lt; <span class="keyword">new</span> Point(8.2602, 50.0050);
points &lt;&lt; <span class="keyword">new</span> Point(8.2598, 50.0044);
points &lt;&lt; <span class="keyword">new</span> Point(8.2569, 50.0057);
points &lt;&lt; <span class="keyword">new</span> Point(8.2595, 50.0083);
points &lt;&lt; <span class="keyword">new</span> Point(8.2587, 50.0086);
points &lt;&lt; <span class="keyword">new</span> Point(8.2589, 50.0100);
points &lt;&lt; <span class="keyword">new</span> Point(8.2590, 50.0105);
pub_tour = <span class="keyword">new</span> LineString(points, <span class="stringliteral">""</span>, pen);
notes-&gt;addGeometry(pub_tour);
points.clear();
points &lt;&lt; <span class="keyword">new</span> Point(8.25987, 50.0018);
points &lt;&lt; <span class="keyword">new</span> Point(8.26192, 50.0019);
points &lt;&lt; <span class="keyword">new</span> Point(8.26301, 50.0031);
points &lt;&lt; <span class="keyword">new</span> Point(8.26459, 50.0026);
points &lt;&lt; <span class="keyword">new</span> Point(8.26601, 50.004);
points &lt;&lt; <span class="keyword">new</span> Point(8.26781, 50.0033);
points &lt;&lt; <span class="keyword">new</span> Point(8.27052, 50.0054);
points &lt;&lt; <span class="keyword">new</span> Point(8.2697, 50.0059);
museum_tour = <span class="keyword">new</span> LineString(points, <span class="stringliteral">""</span>, pen);
notes-&gt;addGeometry(museum_tour);
points.clear();
points &lt;&lt; <span class="keyword">new</span> Point(8.26015, 50.0015);
points &lt;&lt; <span class="keyword">new</span> Point(8.2617, 50.0012);
points &lt;&lt; <span class="keyword">new</span> Point(8.26423, 50.0002);
points &lt;&lt; <span class="keyword">new</span> Point(8.26698, 50.0024);
points &lt;&lt; <span class="keyword">new</span> Point(8.27065, 50.0012);
points &lt;&lt; <span class="keyword">new</span> Point(8.27152, 50.0016);
points &lt;&lt; <span class="keyword">new</span> Point(8.27225, 50.0004);
points &lt;&lt; <span class="keyword">new</span> Point(8.27333, 49.9994);
points &lt;&lt; <span class="keyword">new</span> Point(8.26946, 49.9983);
points &lt;&lt; <span class="keyword">new</span> Point(8.27105, 49.9973);
points &lt;&lt; <span class="keyword">new</span> Point(8.27024, 49.9972);
points &lt;&lt; <span class="keyword">new</span> Point(8.26833, 49.9958);
sights_tour = <span class="keyword">new</span> LineString(points, <span class="stringliteral">""</span>, pen);
notes-&gt;addGeometry(sights_tour);
}
<span class="keywordtype">void</span> Citymap::addSights()
{
sights = <span class="keyword">new</span> GeometryLayer(<span class="stringliteral">"Sehenswürdigkeiten"</span>, mapadapter);
mc-&gt;addLayer(sights);
Point* dom = <span class="keyword">new</span> ImagePoint(8.274167, 49.998889, QCoreApplication::applicationDirPath() + <span class="stringliteral">"/images/180-dom.jpg"</span>, <span class="stringliteral">"Mainzer Dom"</span>);
dom-&gt;setBaselevel(17);
sights-&gt;addGeometry(dom);
Point* stephan = <span class="keyword">new</span> ImagePoint(8.268611, 49.995556, QCoreApplication::applicationDirPath() + <span class="stringliteral">"/images/180-stephan.jpg"</span>,<span class="stringliteral">"St. Stephan"</span>);
stephan-&gt;setBaselevel(17);
sights-&gt;addGeometry(stephan);
Point* quitin = <span class="keyword">new</span> ImagePoint(8.272222, 50.000833, QCoreApplication::applicationDirPath() + <span class="stringliteral">"/images/180-quintin.jpg"</span>,<span class="stringliteral">"St. Quintin"</span>);
quitin-&gt;setBaselevel(17);
sights-&gt;addGeometry(quitin);
connect(sights, SIGNAL(geometryClicked(Geometry*, QPoint)),
<span class="keyword">this</span>, SLOT(geometryClicked(Geometry*, QPoint)));
}
<span class="keywordtype">void</span> Citymap::addPubs()
{
pubs = <span class="keyword">new</span> GeometryLayer(<span class="stringliteral">"Kneipe"</span>, mapadapter);
mc-&gt;addLayer(pubs);
QPixmap* pub = <span class="keyword">new</span> QPixmap(QCoreApplication::applicationDirPath() + <span class="stringliteral">"/images/pub.png"</span>);
Point* bagatelle = <span class="keyword">new</span> Point(8.2606, 50.0052, pub, <span class="stringliteral">"Bagatelle"</span>);
pubs-&gt;addGeometry(bagatelle);
Point* nirgendwo = <span class="keyword">new</span> Point(8.2595, 50.0048, pub, <span class="stringliteral">"Nirgendwo"</span>);
pubs-&gt;addGeometry(nirgendwo);
Point* krokodil = <span class="keyword">new</span> Point(8.2594,50.0106, pub, <span class="stringliteral">"Krokodil"</span>);
pubs-&gt;addGeometry(krokodil);
connect(pubs, SIGNAL(geometryClicked(Geometry*, QPoint)),
<span class="keyword">this</span>, SLOT(geometryClickEventKneipe(Geometry*, QPoint)));
}
<span class="keywordtype">void</span> Citymap::addMuseums()
{
museum = <span class="keyword">new</span> GeometryLayer(<span class="stringliteral">"Museen"</span>, mapadapter);
mc-&gt;addLayer(museum);
Point* rgzm = <span class="keyword">new</span> ImagePoint(8.269722, 50.006111, QCoreApplication::applicationDirPath() + <span class="stringliteral">"/images/180-rgzm.jpg"</span>, <span class="stringliteral">"rgzm"</span>);
rgzm-&gt;setBaselevel(17);
museum-&gt;addGeometry(rgzm);
Point* lm= <span class="keyword">new</span> ImagePoint(8.26778, 50.00385, QCoreApplication::applicationDirPath() + <span class="stringliteral">"/images/180-lm.jpg"</span>, <span class="stringliteral">"lm"</span>);
lm -&gt;setBaselevel(17);
museum-&gt;addGeometry(lm);
connect(museum, SIGNAL(geometryClicked(Geometry*, QPoint)),
<span class="keyword">this</span>, SLOT(geometryClicked(Geometry*, QPoint)));
}
<span class="keywordtype">void</span> Citymap::geometryClicked(Geometry* geometry, QPoint)
{
<span class="keywordflow">if</span> (ignoreClicks || addingNote)
<span class="keywordflow">return</span>;
InfoDialog* infodialog = <span class="keyword">new</span> InfoDialog(<span class="keyword">this</span>);
infodialog-&gt;setWindowTitle(geometry-&gt;name());
<span class="keywordflow">if</span> (geometry-&gt;name() == <span class="stringliteral">"Mainzer Dom"</span>)
{
infodialog-&gt;setInfotext(<span class="stringliteral">"&lt;h1&gt;Mainzer Dom&lt;/h1&gt;&lt;p&gt;&lt;img src=\"images/180-dom.jpg\" align=\"left\"/&gt;Der Hohe Dom zu Mainz ist die Bischofskirche der Diözese Mainz und steht unter dem Patrozinium des heiligen Martin von Tours. Der Ostchor ist dem Hl. Stephan geweiht. Der zu den Kaiserdomen zählende Bau ist in seiner heutigen Form eine dreischiffige romanische Säulenbasilika, die in ihren Anbauten sowohl gotische als auch barocke Elemente aufweist.&lt;/p&gt;"</span>);
} <span class="keywordflow">else</span> <span class="keywordflow">if</span> (geometry-&gt;name() == <span class="stringliteral">"St. Stephan"</span>)
{
infodialog-&gt;setInfotext(<span class="stringliteral">"&lt;h1&gt;St. Stephan&lt;/h1&gt;&lt;p&gt;&lt;img src=\"images/180-stephan.jpg\" align=\"left\"/&gt;Die katholische Pfarrkirche Sankt Stephan in Mainz wurde 990 von Erzbischof Willigis auf der höchsten Erhebung der Stadt gegründet. Auftraggeberin war höchstwahrscheinlich die Kaiserwitwe Theophanu. Willigis wollte mit ihr die Gebetsstätte des Reiches schaffen. In der Kirche war ursprünglich ein Stift untergebracht. Der Propst des Stiftes verwaltete eines der Archidiakonate (mittelalterliche Organisationseinheit, ähnlich den heutigen Dekanaten) des Erzbistums.&lt;/p&gt;"</span>);
} <span class="keywordflow">else</span> <span class="keywordflow">if</span> (geometry-&gt;name() == <span class="stringliteral">"St. Quintin"</span>)
{
infodialog-&gt;setInfotext(<span class="stringliteral">"&lt;h1&gt;St. Quintin&lt;/h1&gt;&lt;p&gt;&lt;img src=\"images/180-quintin.jpg\" align=\"left\"/&gt;Die Kirche St. Quintin in Mainz ist die Pfarrkirche der ältesten nachgewiesenen Pfarrei der Stadt."</span>);
} <span class="keywordflow">else</span> <span class="keywordflow">if</span> (geometry-&gt;name() == <span class="stringliteral">"rgzm"</span>)
{
infodialog-&gt;setInfotext(<span class="stringliteral">"&lt;h1&gt;Römisch-Germanisches Zentralmuseum&lt;/h1&gt;&lt;p&gt;&lt;img src=\"images/180-rgzm.jpg\" align=\"left\"/&gt;Das Römisch-Germanische Zentralmuseum (RGZM) in Mainz ist ein Forschungsinstitut für Vor- und Frühgeschichte, das von Bund und Ländern getragen wird und zur Leibniz-Gemeinschaft deutscher Forschungseinrichtungen gehört. Gegliedert in mehrere Abteilungen, arbeitet das Institut im Bereich der Alten Welt sowie seiner Kontaktzonen von der Altsteinzeit bis ins Mittelalter."</span>);
} <span class="keywordflow">else</span> <span class="keywordflow">if</span> (geometry-&gt;name() == <span class="stringliteral">"lm"</span>)
{
infodialog-&gt;setInfotext(<span class="stringliteral">"&lt;h1&gt;Landesmuseum Mainz&lt;/h1&gt;&lt;p&gt;&lt;img src=\"images/180-lm.jpg\" align=\"left\"/&gt;Das Landesmuseum Mainz ist eines der ältesten Museen in Deutschland. Eine seiner Vorgängerinstitutionen, die Städtische Gemäldesammlung, wurde bereits 1803 von Jean-Antoine Chaptal auf Veranlassung Napoléon Bonapartes durch eine Schenkung von 36 Gemälden gegründet. Das Museum, welches sich heute im ehemaligen kurfürstlichen Marstall befindet, gehört zusammen mit dem Römisch-Germanischen Zentralmuseum und dem Gutenbergmuseum zu den bedeutenden Museen in Mainz. Seine kunst- und kulturgeschichtliche Sammlung erstreckt sich von der Vorgeschichte über die römische Zeit, dem Mittelalter und Barock bis hin zur Jugendstilzeit und der Kunst des 20. Jahrhunderts."</span>);
}
<span class="keywordflow">if</span> (geometry-&gt;name() != <span class="stringliteral">""</span>)
infodialog-&gt;showMaximized();
}
<span class="keywordtype">void</span> Citymap::geometryClickEventKneipe(Geometry* geometry, QPoint)
{
<span class="keywordflow">if</span> (ignoreClicks || addingNote)
<span class="keywordflow">return</span>;
InfoDialog* infodialog = <span class="keyword">new</span> InfoDialog(<span class="keyword">this</span>);
infodialog-&gt;setWindowTitle(geometry-&gt;name());
infodialog-&gt;setInfotext(<span class="stringliteral">"&lt;h1&gt;"</span> + geometry-&gt;name() + <span class="stringliteral">"&lt;/h1&gt;"</span>);
infodialog-&gt;showNormal();
}
<span class="keywordtype">void</span> Citymap::addZoomButtons()
{
<span class="comment">// create buttons as controls for zoom</span>
QPushButton* zoomin = <span class="keyword">new</span> QPushButton(<span class="stringliteral">"+"</span>);
QPushButton* zoomout = <span class="keyword">new</span> QPushButton(<span class="stringliteral">"-"</span>);
zoomin-&gt;setMaximumWidth(50);
zoomout-&gt;setMaximumWidth(50);
connect(zoomin, SIGNAL(clicked(<span class="keywordtype">bool</span>)),
mc, SLOT(zoomIn()));
connect(zoomout, SIGNAL(clicked(<span class="keywordtype">bool</span>)),
mc, SLOT(zoomOut()));
<span class="comment">// add zoom buttons to the layout of the MapControl</span>
QVBoxLayout* innerlayout = <span class="keyword">new</span> QVBoxLayout;
innerlayout-&gt;addWidget(zoomin);
innerlayout-&gt;addWidget(zoomout);
mc-&gt;setLayout(innerlayout);
}
<span class="keywordtype">void</span> Citymap::createActions()
{
toggleSights = <span class="keyword">new</span> QAction(tr(<span class="stringliteral">"Show Sights"</span>), <span class="keyword">this</span>);
toggleSights-&gt;setCheckable(<span class="keyword">true</span>);
toggleSights-&gt;setChecked(<span class="keyword">true</span>);
connect(toggleSights, SIGNAL(triggered(<span class="keywordtype">bool</span>)),
sights, SLOT(setVisible(<span class="keywordtype">bool</span>)));
togglePub = <span class="keyword">new</span> QAction(tr(<span class="stringliteral">"Show Pubs"</span>), <span class="keyword">this</span>);
togglePub-&gt;setCheckable(<span class="keyword">true</span>);
togglePub-&gt;setChecked(<span class="keyword">true</span>);
connect(togglePub, SIGNAL(triggered(<span class="keywordtype">bool</span>)),
pubs, SLOT(setVisible(<span class="keywordtype">bool</span>)));
toggleMuseum = <span class="keyword">new</span> QAction(tr(<span class="stringliteral">"Show Museums"</span>), <span class="keyword">this</span>);
toggleMuseum-&gt;setCheckable(<span class="keyword">true</span>);
toggleMuseum-&gt;setChecked(<span class="keyword">true</span>);
connect(toggleMuseum, SIGNAL(triggered(<span class="keywordtype">bool</span>)),
museum, SLOT(setVisible(<span class="keywordtype">bool</span>)));
toggleSightTour = <span class="keyword">new</span> QAction(tr(<span class="stringliteral">"Show Sight Tour"</span>), <span class="keyword">this</span>);
toggleSightTour-&gt;setCheckable(<span class="keyword">true</span>);
toggleSightTour-&gt;setChecked(<span class="keyword">true</span>);
connect(toggleSightTour, SIGNAL(triggered(<span class="keywordtype">bool</span>)),
sights_tour, SLOT(setVisible(<span class="keywordtype">bool</span>)));
togglePubTour = <span class="keyword">new</span> QAction(tr(<span class="stringliteral">"Show Pub Tour"</span>), <span class="keyword">this</span>);
togglePubTour-&gt;setCheckable(<span class="keyword">true</span>);
togglePubTour-&gt;setChecked(<span class="keyword">true</span>);
connect(togglePubTour, SIGNAL(triggered(<span class="keywordtype">bool</span>)),
pub_tour, SLOT(setVisible(<span class="keywordtype">bool</span>)));
toggleMuseumTour = <span class="keyword">new</span> QAction(tr(<span class="stringliteral">"Show Museum Tour"</span>), <span class="keyword">this</span>);
toggleMuseumTour-&gt;setCheckable(<span class="keyword">true</span>);
toggleMuseumTour-&gt;setChecked(<span class="keyword">true</span>);
connect(toggleMuseumTour, SIGNAL(triggered(<span class="keywordtype">bool</span>)),
museum_tour, SLOT(setVisible(<span class="keywordtype">bool</span>)));
addNoteAction = <span class="keyword">new</span> QAction(tr(<span class="stringliteral">"Add Note"</span>), <span class="keyword">this</span>);
connect(addNoteAction, SIGNAL(triggered(<span class="keywordtype">bool</span>)),
<span class="keyword">this</span>, SLOT(addNote()));
toolsDistance = <span class="keyword">new</span> QAction(tr(<span class="stringliteral">"Calculate Distance"</span>), <span class="keyword">this</span>);
connect(toolsDistance, SIGNAL(triggered(<span class="keywordtype">bool</span>)),
<span class="keyword">this</span>, SLOT(calcDistance()));
QActionGroup* mapproviderGroup = <span class="keyword">new</span> QActionGroup(<span class="keyword">this</span>);
osmAction = <span class="keyword">new</span> QAction(tr(<span class="stringliteral">"OpenStreetMap"</span>), mapproviderGroup);
yahooActionMap = <span class="keyword">new</span> QAction(tr(<span class="stringliteral">"Yahoo: Map"</span>), mapproviderGroup);
yahooActionSatellite = <span class="keyword">new</span> QAction(tr(<span class="stringliteral">"Yahoo: Satellite"</span>), mapproviderGroup);
googleActionMap = <span class="keyword">new</span> QAction(tr(<span class="stringliteral">"Google: Map"</span>), mapproviderGroup);
osmAction-&gt;setCheckable(<span class="keyword">true</span>);
yahooActionMap-&gt;setCheckable(<span class="keyword">true</span>);
yahooActionSatellite-&gt;setCheckable(<span class="keyword">true</span>);
googleActionMap-&gt;setCheckable(<span class="keyword">true</span>);
osmAction-&gt;setChecked(<span class="keyword">true</span>);
connect(mapproviderGroup, SIGNAL(triggered(QAction*)),
<span class="keyword">this</span>, SLOT(mapproviderSelected(QAction*)));
yahooActionOverlay = <span class="keyword">new</span> QAction(tr(<span class="stringliteral">"Yahoo: street overlay"</span>), <span class="keyword">this</span>);
yahooActionOverlay-&gt;setCheckable(<span class="keyword">true</span>);
yahooActionOverlay-&gt;setEnabled(<span class="keyword">false</span>);
connect(yahooActionOverlay, SIGNAL(toggled(<span class="keywordtype">bool</span>)),
overlay, SLOT(setVisible(<span class="keywordtype">bool</span>)));
}
<span class="keywordtype">void</span> Citymap::createMenus()
{
layerMenu = menuBar()-&gt;addMenu(tr(<span class="stringliteral">"&amp;Layer"</span>));
layerMenu-&gt;addAction(toggleSights);
layerMenu-&gt;addAction(togglePub);
layerMenu-&gt;addAction(toggleMuseum);
tourMenu = menuBar()-&gt;addMenu(tr(<span class="stringliteral">"T&amp;ours"</span>));
tourMenu-&gt;addAction(toggleSightTour);
tourMenu-&gt;addAction(togglePubTour);
tourMenu-&gt;addAction(toggleMuseumTour);
toolsMenu = menuBar()-&gt;addMenu(tr(<span class="stringliteral">"&amp;Tools"</span>));
toolsMenu-&gt;addAction(addNoteAction);
toolsMenu-&gt;addAction(toolsDistance);
mapMenu = menuBar()-&gt;addMenu(tr(<span class="stringliteral">"&amp;Map Provider"</span>));
mapMenu-&gt;addAction(osmAction);
mapMenu-&gt;addAction(yahooActionMap);
mapMenu-&gt;addAction(yahooActionSatellite);
mapMenu-&gt;addAction(googleActionMap);
mapMenu-&gt;addSeparator();
mapMenu-&gt;addAction(yahooActionOverlay);
}
<span class="keywordtype">void</span> Citymap::addNote()
{
addingNote = <span class="keyword">true</span>;
connect(mc, SIGNAL(mouseEventCoordinate(<span class="keyword">const</span> QMouseEvent*, <span class="keyword">const</span> QPointF)),
<span class="keyword">this</span>, SLOT(writeNote(<span class="keyword">const</span> QMouseEvent*, <span class="keyword">const</span> QPointF)));
}
<span class="keywordtype">void</span> Citymap::writeNote(<span class="keyword">const</span> QMouseEvent*, <span class="keyword">const</span> QPointF coord)
{
Point* p = <span class="keyword">new</span> Point(coord.x(), coord.y(), notepixmap, QString::number(++noteID), Point::BottomLeft);
currentnoteID = noteID;
p-&gt;setBaselevel(16);
p-&gt;setMinsize(QSize(12, 10));
p-&gt;setMaxsize(QSize(47, 40));
notes-&gt;addGeometry(p);
notetextedit-&gt;clear();
notepoint-&gt;setCoordinate(coord);
notepoint-&gt;setVisible(<span class="keyword">true</span>);
mc-&gt;updateRequestNew();
disconnect(mc, SIGNAL(mouseEventCoordinate(<span class="keyword">const</span> QMouseEvent*, <span class="keyword">const</span> QPointF)),
<span class="keyword">this</span>, SLOT(writeNote(<span class="keyword">const</span> QMouseEvent*, <span class="keyword">const</span> QPointF)));
connect(mc, SIGNAL(mouseEventCoordinate(<span class="keyword">const</span> QMouseEvent*, <span class="keyword">const</span> QPointF)),
<span class="keyword">this</span>, SLOT(hideNote(<span class="keyword">const</span> QMouseEvent*, <span class="keyword">const</span> QPointF)));
}
<span class="keywordtype">void</span> Citymap::hideNote(<span class="keyword">const</span> QMouseEvent* evnt, <span class="keyword">const</span> QPointF)
{
<span class="keywordflow">if</span> (addingNote &amp;&amp; evnt-&gt;type() == QEvent::MouseButtonDblClick)
{
addingNote = <span class="keyword">false</span>;
notepoint-&gt;setVisible(<span class="keyword">false</span>);
mc-&gt;updateRequestNew();
<span class="comment">// save text</span>
notestext[currentnoteID] = notetextedit-&gt;toPlainText();
disconnect(mc, SIGNAL(mouseEventCoordinate(<span class="keyword">const</span> QMouseEvent*, <span class="keyword">const</span> QPointF)),
<span class="keyword">this</span>, SLOT(hideNote(<span class="keyword">const</span> QMouseEvent*, <span class="keyword">const</span> QPointF)));
}
}
<span class="keywordtype">void</span> Citymap::editNote(Geometry* geom, QPoint)
{
addingNote = <span class="keyword">true</span>;
currentnoteID = QVariant(geom-&gt;name()).toInt();
notetextedit-&gt;setPlainText(notestext[currentnoteID]);
notepoint-&gt;setCoordinate(geom-&gt;points().at(0)-&gt;coordinate());
notepoint-&gt;setVisible(<span class="keyword">true</span>);
mc-&gt;updateRequestNew();
connect(mc, SIGNAL(mouseEventCoordinate(<span class="keyword">const</span> QMouseEvent*, <span class="keyword">const</span> QPointF)),
<span class="keyword">this</span>, SLOT(hideNote(<span class="keyword">const</span> QMouseEvent*, <span class="keyword">const</span> QPointF)));
}
<span class="keywordtype">void</span> Citymap::calcDistance()
{
ignoreClicks = <span class="keyword">true</span>;
connect(mc, SIGNAL(mouseEventCoordinate( <span class="keyword">const</span> QMouseEvent*, <span class="keyword">const</span> QPointF )),
<span class="keyword">this</span>, SLOT(calcDistanceClick(<span class="keyword">const</span> QMouseEvent*, <span class="keyword">const</span> QPointF)));
}
<span class="keywordtype">void</span> Citymap::calcDistanceClick(<span class="keyword">const</span> QMouseEvent* evnt, <span class="keyword">const</span> QPointF coord)
{
<span class="keywordflow">if</span> (coord1 == QPointF() &amp;&amp; evnt-&gt;type() == QEvent::MouseButtonPress)
{
coord1 = coord;
l-&gt;addGeometry(<span class="keyword">new</span> ImagePoint(coord1.x(), coord1.y(), QCoreApplication::applicationDirPath() + <span class="stringliteral">"/images/flag.png"</span>, <span class="stringliteral">""</span>, Point::BottomRight));
mc-&gt;updateRequestNew();
}
<span class="keywordflow">else</span> <span class="keywordflow">if</span> (coord2 == QPointF() &amp;&amp; evnt-&gt;type() == QEvent::MouseButtonPress)
{
coord2 = coord;
<span class="keywordtype">double</span> PI = acos(-1.0);
<span class="keywordtype">double</span> a1 = coord1.x()* (PI/180.0);;
<span class="keywordtype">double</span> b1 = coord1.y()* (PI/180.0);;
<span class="keywordtype">double</span> a2 = coord2.x()* (PI/180.0);;
<span class="keywordtype">double</span> b2 = coord2.y()* (PI/180.0);;
<span class="keywordtype">double</span> r = 6378;
<span class="keywordtype">double</span> km = acos(cos(a1)*cos(b1)*cos(a2)*cos(b2) + cos(a1)*sin(b1)*cos(a2)*sin(b2) + sin(a1)*sin(a2)) * r;
QList&lt;Point*&gt; points;
points.append(<span class="keyword">new</span> Point(coord1.x(), coord1.y()));
QPixmap* pixm = <span class="keyword">new</span> QPixmap(100,20);
pixm-&gt;fill(Qt::transparent);
QPainter pain(pixm);
pain.setFont(QFont(<span class="stringliteral">"Helvetiva"</span>, 6));
pain.drawText(pixm-&gt;rect(), QString().setNum(km, <span class="charliteral">'f'</span>, 3) + <span class="stringliteral">" km"</span>);
pain.end();
points.append(<span class="keyword">new</span> Point(coord2.x(), coord2.y(), pixm, <span class="stringliteral">""</span>, Point::BottomLeft));
l-&gt;addGeometry(<span class="keyword">new</span> LineString(points));
mc-&gt;updateRequestNew();
coord1 = QPointF();
coord2 = QPointF();
ignoreClicks = <span class="keyword">false</span>;
disconnect(mc, SIGNAL(mouseEventCoordinate( <span class="keyword">const</span> QMouseEvent*, <span class="keyword">const</span> QPointF)),
<span class="keyword">this</span>, SLOT(calcDistanceClick(<span class="keyword">const</span> QMouseEvent*, <span class="keyword">const</span> QPointF)));
}
}
<span class="keywordtype">void</span> Citymap::mapproviderSelected(QAction* action)
{
<span class="keywordflow">if</span> (action == osmAction)
{
<span class="keywordtype">int</span> zoom = mapadapter-&gt;adaptedZoom();
mc-&gt;setZoom(0);
mapadapter = <span class="keyword">new</span> OSMMapAdapter();
l-&gt;setMapAdapter(mapadapter);
sights-&gt;setMapAdapter(mapadapter);
museum-&gt;setMapAdapter(mapadapter);
pubs-&gt;setMapAdapter(mapadapter);
notes-&gt;setMapAdapter(mapadapter);
mc-&gt;updateRequestNew();
mc-&gt;setZoom(zoom);
yahooActionOverlay-&gt;setEnabled(<span class="keyword">false</span>);
overlay-&gt;setVisible(<span class="keyword">false</span>);
yahooActionOverlay-&gt;setChecked(<span class="keyword">false</span>);
} <span class="keywordflow">else</span> <span class="keywordflow">if</span> (action == yahooActionMap)
{
<span class="keywordtype">int</span> zoom = mapadapter-&gt;adaptedZoom();
mc-&gt;setZoom(0);
mapadapter = <span class="keyword">new</span> YahooMapAdapter();
l-&gt;setMapAdapter(mapadapter);
sights-&gt;setMapAdapter(mapadapter);
museum-&gt;setMapAdapter(mapadapter);
pubs-&gt;setMapAdapter(mapadapter);
notes-&gt;setMapAdapter(mapadapter);
mc-&gt;updateRequestNew();
mc-&gt;setZoom(zoom);
yahooActionOverlay-&gt;setEnabled(<span class="keyword">false</span>);
overlay-&gt;setVisible(<span class="keyword">false</span>);
yahooActionOverlay-&gt;setChecked(<span class="keyword">false</span>);
} <span class="keywordflow">else</span> <span class="keywordflow">if</span> (action == yahooActionSatellite)
{
<span class="keywordtype">int</span> zoom = mapadapter-&gt;adaptedZoom();
QPointF a = mc-&gt;currentCoordinate();
mc-&gt;setZoom(0);
mapadapter = <span class="keyword">new</span> YahooMapAdapter(<span class="stringliteral">"us.maps3.yimg.com"</span>, <span class="stringliteral">"/aerial.maps.yimg.com/png?v=1.7&amp;t=a&amp;s=256&amp;x=%2&amp;y=%3&amp;z=%1"</span>);
l-&gt;setMapAdapter(mapadapter);
sights-&gt;setMapAdapter(mapadapter);
museum-&gt;setMapAdapter(mapadapter);
pubs-&gt;setMapAdapter(mapadapter);
notes-&gt;setMapAdapter(mapadapter);
mc-&gt;updateRequestNew();
mc-&gt;setZoom(zoom);
yahooActionOverlay-&gt;setEnabled(<span class="keyword">true</span>);
} <span class="keywordflow">else</span> <span class="keywordflow">if</span> (action == googleActionMap)
{
<span class="keywordtype">int</span> zoom = mapadapter-&gt;adaptedZoom();
mc-&gt;setZoom(0);
mapadapter = <span class="keyword">new</span> GoogleMapAdapter();
l-&gt;setMapAdapter(mapadapter);
sights-&gt;setMapAdapter(mapadapter);
museum-&gt;setMapAdapter(mapadapter);
pubs-&gt;setMapAdapter(mapadapter);
notes-&gt;setMapAdapter(mapadapter);
mc-&gt;updateRequestNew();
mc-&gt;setZoom(zoom);
yahooActionOverlay-&gt;setEnabled(<span class="keyword">false</span>);
overlay-&gt;setVisible(<span class="keyword">false</span>);
yahooActionOverlay-&gt;setChecked(<span class="keyword">false</span>);
}
}
Citymap::~Citymap()
{
<span class="keyword">delete</span> mc;
<span class="keyword">delete</span> mapadapter;
<span class="keyword">delete</span> notepixmap;
<span class="keyword">delete</span> sights;
<span class="keyword">delete</span> notes;
<span class="keyword">delete</span> pubs;
<span class="keyword">delete</span> museum;
}
</pre></div> </div>
<hr size="1"><address style="text-align: right;"><small>Generated on Wed Jul 29 12:38:09 2009 for QMapControl by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address>
</body>
</html>