[Marble-commits] KDE/kdeedu/marble/src/lib

Thibaut Gridel tgridel at free.fr
Sat Dec 25 09:33:30 CET 2010


SVN commit 1209153 by tgridel:

PositionTracking: save track

 M  +18 -0     CurrentLocationWidget.cpp  
 M  +1 -0      CurrentLocationWidget.h  
 M  +10 -0     CurrentLocationWidget.ui  
 M  +25 -0     PositionTracking.cpp  
 M  +5 -0      PositionTracking.h  


--- trunk/KDE/kdeedu/marble/src/lib/CurrentLocationWidget.cpp #1209152:1209153
@@ -31,6 +31,9 @@
 // Ui
 #include "ui_CurrentLocationWidget.h"
 
+#include <QtCore/QDateTime>
+#include <QtGui/QFileDialog>
+
 namespace Marble
 {
 
@@ -52,6 +55,7 @@
     void updateRecenterComboBox( int centerMode );
     void updateAutoZoomCheckBox( bool autoZoom );
     void updateActivePositionProvider( PositionProviderPlugin* );
+    void saveTrack();
     void clearTrack();
 };
 
@@ -93,6 +97,7 @@
         d->m_currentLocationUi.locationLabel->setText( html );
         d->m_currentLocationUi.locationLabel->setEnabled ( true );
         d->m_currentLocationUi.showTrackCheckBox->setEnabled( false );
+        d->m_currentLocationUi.saveTrackPushButton->setEnabled( false );
         d->m_currentLocationUi.clearTrackPushButton->setEnabled( false );
     }
 
@@ -142,6 +147,8 @@
     if ( d->m_widget->model()->positionTracking()->trackVisible() ) {
         d->m_currentLocationUi.showTrackCheckBox->setCheckState(Qt::Checked);
     }
+    connect ( d->m_currentLocationUi.saveTrackPushButton, SIGNAL( clicked(bool)),
+              this, SLOT(saveTrack()));
     connect (d->m_currentLocationUi.clearTrackPushButton, SIGNAL( clicked(bool)),
              this, SLOT(clearTrack()));
 }
@@ -235,6 +242,7 @@
     html = html.arg( distanceString ).arg( speedString + ' ' + unitString );
     d->m_currentLocationUi.locationLabel->setText( html );
     d->m_currentLocationUi.showTrackCheckBox->setEnabled( true );
+    d->m_currentLocationUi.saveTrackPushButton->setEnabled( true );
     d->m_currentLocationUi.clearTrackPushButton->setEnabled( true );
 }
 
@@ -291,10 +299,20 @@
     m_widget->centerOn(m_currentPosition, true);
 }
 
+void CurrentLocationWidgetPrivate::saveTrack()
+{
+    QString fileName = QFileDialog::getSaveFileName(m_widget, QObject::tr("Save Track"), // krazy:exclude=qclasses
+                            QDir::homePath().append('/' + QDateTime::currentDateTime().toString("yyyyMMdd_hhmmss") + ".kml"),
+                            QObject::tr("KML File (*.kml)"));
+
+    m_widget->model()->positionTracking()->saveTrack( fileName );
+}
+
 void CurrentLocationWidgetPrivate::clearTrack()
 {
     m_widget->model()->positionTracking()->clearTrack();
     m_widget->repaint();
+    m_currentLocationUi.saveTrackPushButton->setEnabled( false );
     m_currentLocationUi.clearTrackPushButton->setEnabled( false );
 }
 
--- trunk/KDE/kdeedu/marble/src/lib/CurrentLocationWidget.h #1209152:1209153
@@ -73,6 +73,7 @@
 
      Q_PRIVATE_SLOT( d, void updateActivePositionProvider( PositionProviderPlugin* ) )
 
+     Q_PRIVATE_SLOT( d, void saveTrack() )
      Q_PRIVATE_SLOT( d, void clearTrack() )
 };
 
--- trunk/KDE/kdeedu/marble/src/lib/CurrentLocationWidget.ui #1209152:1209153
@@ -50,6 +50,16 @@
     </widget>
    </item>
    <item>
+    <widget class="QPushButton" name="saveTrackPushButton">
+     <property name="enabled">
+      <bool>false</bool>
+     </property>
+     <property name="text">
+      <string>Save Track</string>
+     </property>
+    </widget>
+   </item>
+   <item>
     <widget class="QPushButton" name="clearTrackPushButton">
      <property name="enabled">
       <bool>false</bool>
--- trunk/KDE/kdeedu/marble/src/lib/PositionTracking.cpp #1209152:1209153
@@ -16,14 +16,19 @@
 #include "GeoDataPlacemark.h"
 #include "GeoDataStyle.h"
 #include "GeoDataStyleMap.h"
+#include "GeoWriter.h"
+#include "KmlElementDictionary.h"
 #include "AbstractProjection.h"
 #include "FileManager.h"
 #include "MarbleMath.h"
 #include "MarbleDebug.h"
+#include "MarbleDirs.h"
 #include "PositionProviderPlugin.h"
 
 #include "PositionTracking_p.h"
 
+#include <QtCore/QFile>
+
 using namespace Marble;
 
 void PositionTrackingPrivate::setPosition( GeoDataCoordinates position,
@@ -173,6 +178,26 @@
     d->m_document->setVisible( visible );
 }
 
+bool PositionTracking::saveTrack(QString& fileName)
+{
+
+    if ( !fileName.isEmpty() )
+    {
+        if ( !fileName.endsWith(".kml", Qt::CaseInsensitive) )
+        {
+            fileName.append( ".kml" );
+        }
+
+        GeoWriter writer;
+        //FIXME: a better way to do this?
+        writer.setDocumentType( kml::kmlTag_nameSpace22 );
+        QFile file( fileName );
+        file.open( QIODevice::ReadWrite );
+        return writer.write(&file, *d->m_document);
+    }
+    return false;
+}
+
 void PositionTracking::clearTrack()
 {
     GeoDataPlacemark *placemark = static_cast<GeoDataPlacemark*>(d->m_document->child(d->m_document->size()-1));
--- trunk/KDE/kdeedu/marble/src/lib/PositionTracking.h #1209152:1209153
@@ -84,6 +84,11 @@
     void setTrackVisible ( bool visible );
 
     /**
+      * Saves the track document to file
+      */
+    bool saveTrack( QString& fileName );
+
+    /**
       * Removes all track segments which were recorded
       */
     void clearTrack();


More information about the Marble-commits mailing list