[Marble-commits] KDE/kdeedu/marble/src
Dennis Nienhüser
earthwings at gentoo.org
Mon Sep 27 20:57:40 CEST 2010
SVN commit 1180350 by nienhueser:
Add an action to add a bookmark to the right mouse button menu.
M +86 -66 lib/BookmarkInfoDialog.cpp
M +12 -12 lib/BookmarkInfoDialog.h
M +10 -4 lib/BookmarkManager.cpp
M +9 -3 lib/BookmarkManager.h
M +13 -2 lib/MarbleWidgetPopupMenu.cpp
M +1 -0 lib/MarbleWidgetPopupMenu.h
M +3 -7 marble_part.cpp
M +1 -1 marble_part.h
--- trunk/KDE/kdeedu/marble/src/lib/BookmarkInfoDialog.cpp #1180349:1180350
@@ -10,72 +10,115 @@
//
#include "BookmarkInfoDialog.h"
-#include "MarbleDebug.h"
#include "BookmarkManager.h"
#include "GeoDataPlacemark.h"
#include "GeoDataPoint.h"
#include "GeoDataFolder.h"
#include "GeoDataCoordinates.h"
-#include "NewFolderInfoDialog.h"
#include "GeoDataExtendedData.h"
-#include <QtGui/QLineEdit>
-#include <QtCore/QString>
-#include <QtCore/QPointer>
-#include <QtCore/QDebug>
#include "MarbleModel.h"
-using namespace Marble;
+#include "NewFolderInfoDialog.h"
-BookmarkInfoDialog::BookmarkInfoDialog(MarbleWidget *parent)
- : QDialog( parent ),
- m_widget( parent ),
- m_manager( 0 )
+#include <QtCore/QPointer>
+
+namespace Marble {
+
+class BookmarkInfoDialogPrivate {
+public:
+ MarbleWidget *m_widget;
+ MarbleRunnerManager* m_manager;
+ GeoDataCoordinates m_bookmarkCoordinate;
+
+ BookmarkInfoDialogPrivate( BookmarkInfoDialog* q, MarbleWidget *parent );
+
+ void initComboBox();
+
+ void initialize( const GeoDataCoordinates &coordinates );
+
+private:
+ BookmarkInfoDialog* const q;
+};
+
+BookmarkInfoDialogPrivate::BookmarkInfoDialogPrivate( BookmarkInfoDialog* q_, MarbleWidget *parent ) :
+ m_widget( parent ), m_manager( 0 ), q( q_ )
{
- setupUi(this);
- setWindowTitle( tr("Add Bookmark") );
- connect( m_saveButton, SIGNAL( clicked() ), this, SLOT( addBookmark() ) );
- connect( m_newFolderButton, SIGNAL( clicked() ), this, SLOT( openNewFolderDialog() ) );
+ // nothing to do
+}
- m_manager = new MarbleRunnerManager( m_widget->model()->pluginManager(), this );
+void BookmarkInfoDialogPrivate::initialize( const GeoDataCoordinates &coordinates )
+{
+ m_bookmarkCoordinate = coordinates;
+ q->setupUi( q );
+ q->setWindowTitle( QObject::tr("Add Bookmark") );
+ QObject::connect( q->m_saveButton, SIGNAL( clicked() ), q, SLOT( addBookmark() ) );
+ QObject::connect( q->m_newFolderButton, SIGNAL( clicked() ), q, SLOT( openNewFolderDialog() ) );
//reverse geocode the bookmark point for better user experience
- connect( m_manager, SIGNAL( reverseGeocodingFinished( GeoDataCoordinates, GeoDataPlacemark ) ),
- this, SLOT( retrieveGeocodeResult( GeoDataCoordinates, GeoDataPlacemark ) ) );
-
- GeoDataCoordinates coordinates( m_widget->centerLongitude(), m_widget->centerLatitude(), 0, GeoDataCoordinates::Degree, 0 ) ;
+ m_manager = new MarbleRunnerManager( m_widget->model()->pluginManager(), q );
+ QObject::connect( m_manager, SIGNAL( reverseGeocodingFinished( GeoDataCoordinates, GeoDataPlacemark ) ),
+ q, SLOT( retrieveGeocodeResult( GeoDataCoordinates, GeoDataPlacemark ) ) );
m_manager->reverseGeocoding( coordinates );
-
- name->setText(coordinates.toString() );
- name->selectAll();
- //Initialzing ComboBox
+ q->name->setText(coordinates.toString() );
+ q->name->selectAll();
initComboBox();
}
+void BookmarkInfoDialogPrivate::initComboBox()
+{
+ q->m_folders->clear();
+ QVector<GeoDataFolder*> folders = m_widget->folders();
+ QVector<GeoDataFolder*>::const_iterator i = folders.constBegin();
+ QVector<GeoDataFolder*>::const_iterator end = folders.constEnd();
+
+ QList<QString> folderNames;
+ for (; i != end; ++i ) {
+ folderNames.append( (*i)->name() );
+ }
+
+ q->m_folders->insertItems( 0, folderNames );
+}
+
+BookmarkInfoDialog::BookmarkInfoDialog(MarbleWidget *parent)
+ : QDialog( parent ), d( new BookmarkInfoDialogPrivate( this, parent ) )
+{
+ GeoDataCoordinates coordinates( d->m_widget->centerLongitude(),
+ d->m_widget->centerLatitude(), 0,
+ GeoDataCoordinates::Degree, 0 ) ;
+ d->initialize( coordinates );
+}
+
+BookmarkInfoDialog::BookmarkInfoDialog( const GeoDataCoordinates &coordinates, MarbleWidget *parent )
+ : QDialog( parent ), d( new BookmarkInfoDialogPrivate( this, parent ) )
+{
+ d->initialize( coordinates );
+}
+
BookmarkInfoDialog::~BookmarkInfoDialog()
{
- delete m_manager;
+ delete d;
}
void BookmarkInfoDialog::retrieveGeocodeResult( const GeoDataCoordinates &coordinates, const GeoDataPlacemark &placemark)
{
Q_UNUSED(coordinates)
- GeoDataExtendedData extended = placemark.extendedData();
- QString bookmarkName = "";
- qreal distance = m_widget->distance() * KM2METER;
+ GeoDataExtendedData data = placemark.extendedData();
+ QString bookmarkName;
+ qreal distance = d->m_widget->distance() * KM2METER;
//FIXME : Optimal logic for suggestion with distance consideration is required
if( distance >= 3500 ){
- bookmarkName = extended.value("country").value().toString() ;
+ bookmarkName = data.value("country").value().toString() ;
}
else if( distance >= 200 ){
- bookmarkName = append( extended.value("city").value().toString()
- , extended.value("state").value().toString() );
- bookmarkName = append( bookmarkName, extended.value("country").value().toString() ) ;
+ bookmarkName = append( data.value("city").value().toString()
+ , data.value("state").value().toString() );
+ bookmarkName = append( bookmarkName, data.value("country").value().toString() ) ;
}
else{
- bookmarkName = append( extended.value("road").value().toString()
- , extended.value("city").value().toString());
- bookmarkName = append( bookmarkName, extended.value("country").value().toString() ) ;
+ bookmarkName = append( data.value("road").value().toString()
+ , data.value("city").value().toString());
+ bookmarkName = append( bookmarkName, data.value("country").value().toString() ) ;
}
if( bookmarkName.isEmpty() ){
@@ -83,7 +126,6 @@
}
name->setText( bookmarkName );
-
name->selectAll();
}
@@ -101,55 +143,33 @@
return bookmark + ", " + text;
}
-void BookmarkInfoDialog::initComboBox()
-{
- m_folders->clear();
- QVector<GeoDataFolder*> folders = m_widget->folders();
- QVector<GeoDataFolder*>::const_iterator i = folders.constBegin();
- QVector<GeoDataFolder*>::const_iterator end = folders.constEnd();
-
- QList<QString> folderNames;
- for (; i != end; ++i ) {
- folderNames.append( (*i)->name() );
- }
-
- m_folders->insertItems( 0, folderNames );
-}
-
void BookmarkInfoDialog::openNewFolderDialog()
{
- QPointer<NewFolderInfoDialog> dialog = new NewFolderInfoDialog( m_widget );
+ QPointer<NewFolderInfoDialog> dialog = new NewFolderInfoDialog( d->m_widget );
dialog->exec();
delete dialog;
- initComboBox();
+ d->initComboBox();
}
void BookmarkInfoDialog::addBookmark()
{
-
- mDebug() << "Adding Bookmark with "
- << " longitude : " << m_widget->centerLongitude()
- << " latitude : " << m_widget->centerLatitude()
- << " distance : " << m_widget->distance() * KM2METER;
-
-
//Create a bookmark object
GeoDataPlacemark bookmark;
bookmark.setName( name->text() );
bookmark.setDescription( description->toPlainText() );
//allow for HTML in the description
bookmark.setDescriptionCDATA( true );
- bookmark.setCoordinate( m_widget->centerLongitude(), m_widget->centerLatitude(), 0, GeoDataPoint::Degree );
+ bookmark.setCoordinate( d->m_bookmarkCoordinate );
bookmark.extendedData().addValue( GeoDataData( "isBookmark", true ) );
- GeoDataLookAt *lookAt = new GeoDataLookAt( m_widget->lookAt() ) ;
+ GeoDataLookAt *lookAt = new GeoDataLookAt( d->m_widget->lookAt() ) ;
+ lookAt->setLatitude( d->m_bookmarkCoordinate.latitude() );
+ lookAt->setLongitude( d->m_bookmarkCoordinate.longitude() );
bookmark.setLookAt( lookAt );
+ d->m_widget->addBookmark( bookmark, m_folders->currentText() );
+}
- mDebug()<<"Selected Folder for bookmark addition : "<<m_folders->currentText();
-
- m_widget->addBookmark( bookmark, m_folders->currentText() );
}
-
#include "BookmarkInfoDialog.moc"
--- trunk/KDE/kdeedu/marble/src/lib/BookmarkInfoDialog.h #1180349:1180350
@@ -8,8 +8,8 @@
// Copyright 2010 Gaurav Gupta <1989.gaurav at googlemail.com>
//
-#ifndef MARBLE_INFODIALOG_H
-#define MARBLE_INFODIALOG_H
+#ifndef MARBLE_BOOKMARKINFODIALOG_H
+#define MARBLE_BOOKMARKINFODIALOG_H
#include "ui_BookmarkInfoDialog.h"
#include "MarbleWidget.h"
@@ -19,22 +19,23 @@
namespace Marble
{
+class BookmarkInfoDialogPrivate;
+
class MARBLE_EXPORT BookmarkInfoDialog : public QDialog, private Ui::BookmarkInfoDialog
{
-
Q_OBJECT
public:
+ /** Constructor that uses the widget's center as the bookmark location */
+ explicit BookmarkInfoDialog( MarbleWidget *marbleWidget );
- explicit BookmarkInfoDialog( MarbleWidget *parent = 0);
+ /** Constructor that uses the given coordinates as the bookmark location */
+ BookmarkInfoDialog( const GeoDataCoordinates &coordinates, MarbleWidget *marbleWidget );
+ /** Destructor */
~BookmarkInfoDialog();
- void initComboBox();
-
-
- public Q_SLOTS:
-
+ private Q_SLOTS:
void addBookmark();
void openNewFolderDialog();
@@ -45,10 +46,9 @@
private:
Q_DISABLE_COPY( BookmarkInfoDialog )
- MarbleWidget *m_widget;
- MarbleRunnerManager* m_manager;
+ BookmarkInfoDialogPrivate* const d;
+ friend class BookmarkInfoDialogPrivate;
};
}
#endif
-
--- trunk/KDE/kdeedu/marble/src/lib/BookmarkManager.cpp #1180349:1180350
@@ -18,11 +18,13 @@
#include "MarbleDebug.h"
#include "MarbleDirs.h"
#include <QtCore/QFile>
-using namespace Marble;
-BookmarkManager::BookmarkManager()
- : d( new BookmarkManagerPrivate() )
+namespace Marble
{
+
+BookmarkManager::BookmarkManager( QObject *parent )
+ : QObject( parent ), d( new BookmarkManagerPrivate() )
+{
}
BookmarkManager::~BookmarkManager()
@@ -135,7 +137,7 @@
updateBookmarkFile();
}
-bool BookmarkManager::updateBookmarkFile() const
+bool BookmarkManager::updateBookmarkFile()
{
QString absoluteLocalFilePath = MarbleDirs::localPath()+ '/'+d->m_bookmarkFileRelativePath ;
@@ -167,9 +169,13 @@
qWarning( "Could not write the file." );
return false;
}
+ emit bookmarksChanged();
return true;
}
return false;
}
+}
+
+#include "BookmarkManager.moc"
--- trunk/KDE/kdeedu/marble/src/lib/BookmarkManager.h #1180349:1180350
@@ -11,6 +11,7 @@
#ifndef MARBLE_BOOKMARKMANAGER_H
#define MARBLE_BOOKMARKMANAGER_H
+#include <QtCore/QObject>
#include <QtCore/QString>
#include "BookmarkManager_p.h"
@@ -25,12 +26,13 @@
* book mark operations
*/
-class BookmarkManager
+class BookmarkManager : public QObject
{
+ Q_OBJECT
public:
- BookmarkManager();
+ explicit BookmarkManager( QObject *parent = 0 );
~BookmarkManager();
@@ -69,12 +71,16 @@
*/
void removeAllBookmarks();
+Q_SIGNALS:
+ /** One or more bookmarks were added or removed */
+ void bookmarksChanged();
+
private:
/**
* @brief updates bookmark file and return true if updated successfully
*/
- bool updateBookmarkFile() const;
+ bool updateBookmarkFile();
BookmarkManagerPrivate *d;
--- trunk/KDE/kdeedu/marble/src/lib/MarbleWidgetPopupMenu.cpp #1180349:1180350
@@ -24,6 +24,7 @@
#include "routing/RoutingManager.h"
#include "routing/RouteRequest.h"
#include "MarbleRunnerManager.h"
+#include "BookmarkInfoDialog.h"
// Qt
#include <QtCore/QMimeData>
@@ -62,6 +63,7 @@
m_rmbMenu->addAction( tr( "Directions &from here" ), this, SLOT( directionsFromHere() ) );
m_rmbMenu->addAction( tr( "Directions &to here" ), this, SLOT( directionsToHere() ) );
m_rmbMenu->addSeparator();
+ m_rmbMenu->addAction( QIcon(":/icons/bookmark-new.png"), tr( "Add &Bookmark" ), this, SLOT( addBookmark() ) );
m_setHomePointAction = new QAction( tr( "&Set Home Location" ), this);
m_rmbMenu->addAction( m_setHomePointAction );
m_rmbMenu->addSeparator();
@@ -138,7 +140,7 @@
QMenu *positionMenu = m_lmbMenu->addMenu( GeoDataCoordinates( lon, lat, GeoDataCoordinates::Radian ).toString() );
positionMenu->menuAction()->setFont( QFont( "Sans Serif", 7, 50, false ) );
positionMenu->addAction( m_copyCoordinateAction );
- positionMenu->addAction( "&Address Details", this, SLOT( startReverseGeocoding() ) );
+ positionMenu->addAction( tr( "&Address Details" ), this, SLOT( startReverseGeocoding() ) );
m_lmbMenu->popup( m_widget->mapToGlobal( curpos ) );
}
@@ -298,9 +300,18 @@
{
QString text = placemark.address();
if ( !text.isEmpty() ) {
- QMessageBox::information( m_widget, "Address Details", text, QMessageBox::Ok );
+ QMessageBox::information( m_widget, tr( "Address Details" ), text, QMessageBox::Ok );
}
}
+void MarbleWidgetPopupMenu::addBookmark()
+{
+ GeoDataCoordinates coordinates;
+ if ( mouseCoordinates( &coordinates, m_setHomePointAction ) ) {
+ QPointer<BookmarkInfoDialog> dialog = new BookmarkInfoDialog( coordinates, m_widget );
+ dialog->exec();
+ delete dialog;
+ }
+}
#include "MarbleWidgetPopupMenu.moc"
--- trunk/KDE/kdeedu/marble/src/lib/MarbleWidgetPopupMenu.h #1180349:1180350
@@ -65,6 +65,7 @@
void directionsToHere();
void startReverseGeocoding();
void showAddressInformation( const GeoDataCoordinates &coordinates, const GeoDataPlacemark &placemark );
+ void addBookmark();
private:
/**
--- trunk/KDE/kdeedu/marble/src/marble_part.cpp #1180349:1180350
@@ -814,7 +814,9 @@
connect( m_addBookmarkFolderAction, SIGNAL( triggered( ) ),
this, SLOT( openNewBookmarkFolderDialog() ) );
-
+ createFolderList();
+ connect( m_controlView->marbleWidget()->model()->bookmarkManager(),
+ SIGNAL( bookmarksChanged() ), this, SLOT( createFolderList() ) );
}
void MarblePart::createFolderList()
@@ -1491,18 +1493,14 @@
void MarblePart::openBookmarkInfoDialog()
{
-
QPointer<BookmarkInfoDialog> m_bookmarkInfoDialog = new BookmarkInfoDialog( m_controlView->marbleWidget() );
m_bookmarkInfoDialog->exec();
delete m_bookmarkInfoDialog;
- createFolderList();
- mDebug() <<" Open Bookmark Info Dialog ";
}
void MarblePart::removeAllBookmarks()
{
m_controlView->marbleWidget()->removeAllBookmarks();
- createFolderList();
}
void MarblePart::openNewBookmarkFolderDialog()
@@ -1510,8 +1508,6 @@
QPointer<NewFolderInfoDialog> dialog = new NewFolderInfoDialog( m_controlView->marbleWidget());
dialog->exec();
delete dialog;
- createFolderList();
-
}
void MarblePart::lookAtBookmark( QAction *action)
--- trunk/KDE/kdeedu/marble/src/marble_part.h #1180349:1180350
@@ -57,7 +57,6 @@
static KAboutData* createAboutData();
void createInfoBoxesMenu();
void createOnlineServicesMenu();
- void createFolderList();
void initializeCustomTimezone();
@@ -70,6 +69,7 @@
void showDateTime();
void mapThemeChanged( const QString& newMapTheme );
void createPluginMenus();
+ void createFolderList();
private Q_SLOTS:
void initObject();
More information about the Marble-commits
mailing list