[Marble-commits] KDE/kdeedu/marble/src/lib
Thibaut Gridel
tgridel at free.fr
Sat Mar 12 11:50:54 CET 2011
SVN commit 1224574 by tgridel:
Marking map themes as "favourite" in Marble by Daniel Marth
Map themes can now be marked as favorite.
GCI-task: http://www.google-melange.com/gci/task/show/google/gci2010/kde/t129303445819
REVIEW: 6303
M +1 -1 MapThemeManager.cpp
M +38 -10 MapThemeSortFilterProxyModel.cpp
M +6 -0 MapThemeSortFilterProxyModel.h
M +56 -1 MarbleThemeSelectView.cpp
M +5 -0 MarbleThemeSelectView.h
--- trunk/KDE/kdeedu/marble/src/lib/MapThemeManager.cpp #1224573:1224574
@@ -18,10 +18,10 @@
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtCore/QFileSystemWatcher>
-#include <QtGui/QStandardItemModel>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QTimer>
+#include <QtGui/QStandardItemModel>
// Local dir
#include "GeoSceneDocument.h"
--- trunk/KDE/kdeedu/marble/src/lib/MapThemeSortFilterProxyModel.cpp #1224573:1224574
@@ -11,10 +11,14 @@
#include "MapThemeSortFilterProxyModel.h"
#include <QtCore/QString>
+#include <QtCore/QModelIndex>
+#include <QtCore/QDateTime>
using namespace Marble;
/* TRANSLATOR Marble::MapThemeSortFilterProxyModel */
+QSettings MapThemeSortFilterProxyModel::sm_settings( "kde.org", "Marble Desktop Globe" );
+
MapThemeSortFilterProxyModel::MapThemeSortFilterProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
@@ -22,19 +26,23 @@
bool MapThemeSortFilterProxyModel::lessThan ( const QModelIndex & left, const QModelIndex & right ) const
{
- QString leftData = sourceModel()->data( left ).toString();
- QString rightData = sourceModel()->data( right ).toString();
- if ( leftData == tr("Atlas") ||
- leftData == tr("Satellite View") ||
- leftData == tr("OpenStreetMap") )
+ if( isFavorite( left ) ) {
+ if( !isFavorite( right ) ) {
return true;
- else if ( rightData == tr("Atlas") ||
- rightData == tr("Satellite View") ||
- rightData == tr("OpenStreetMap") )
+ }
+ }
+ else {
+ if( isFavorite( right ) ) {
return false;
- else
- return QSortFilterProxyModel::lessThan( left, right);
}
+ }
+ if( isFavorite( left ) && isFavorite( right ) ) {
+ if( favoriteDateTime( left ) != favoriteDateTime( right ) ) {
+ return favoriteDateTime( left ) > favoriteDateTime( right );
+ }
+ }
+ return sourceModel()->data( left ).toString() < sourceModel()->data( right ).toString();;
+}
bool MapThemeSortFilterProxyModel::filterAcceptsRow(int sourceRow,
const QModelIndex &sourceParent) const
@@ -45,4 +53,24 @@
}
+bool MapThemeSortFilterProxyModel::isFavorite( const QModelIndex& index )
+{
+ sm_settings.beginGroup( "Favorites" );
+ const QAbstractItemModel *model = index.model();
+ QModelIndex columnIndex = model->index( index.row(), 0, QModelIndex() );
+ bool favorite = sm_settings.contains( model->data( columnIndex ).toString() );
+ sm_settings.endGroup();
+ return favorite;
+}
+
+QDateTime MapThemeSortFilterProxyModel::favoriteDateTime( const QModelIndex& index )
+{
+ const QAbstractItemModel *model = index.model();
+ QModelIndex columnIndex = model->index( index.row(), 0, QModelIndex() );
+ sm_settings.beginGroup( "Favorites" );
+ QDateTime dateTime = sm_settings.value( model->data( columnIndex ).toString() ).toDateTime();
+ sm_settings.endGroup();
+ return dateTime;
+}
+
#include "MapThemeSortFilterProxyModel.moc"
--- trunk/KDE/kdeedu/marble/src/lib/MapThemeSortFilterProxyModel.h #1224573:1224574
@@ -12,6 +12,8 @@
#ifndef MARBLE_MAPTHEMESORTFILTERPROXYMODEL_H
#define MARBLE_MAPTHEMESORTFILTERPROXYMODEL_H
+#include <QtCore/QDateTime>
+#include <QtCore/QSettings>
#include <QtGui/QSortFilterProxyModel>
class QModelIndex;
@@ -28,6 +30,10 @@
protected:
bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
+ private:
+ static QSettings sm_settings;
+ static bool isFavorite( const QModelIndex& index );
+ static QDateTime favoriteDateTime( const QModelIndex& index );
};
--- trunk/KDE/kdeedu/marble/src/lib/MarbleThemeSelectView.cpp #1224573:1224574
@@ -20,9 +20,12 @@
#include <QtCore/QFileInfo>
#include <QtCore/QFile>
#include <QtCore/QDir>
+#include <QtCore/QDateTime>
+#include <QtCore/QModelIndex>
#include <QtGui/QResizeEvent>
#include <QtGui/QMenu>
#include <QtGui/QMessageBox>
+#include <QtGui/QStandardItemModel>
using namespace Marble;
@@ -97,6 +100,7 @@
MarbleThemeSelectView::MarbleThemeSelectView(QWidget *parent)
: QListView( parent ),
+ m_settings( "kde.org", "Marble Desktop Globe" ),
d( new Private( this ) )
{
bool const smallScreen = MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen;
@@ -115,6 +119,7 @@
setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
setEditTriggers( QAbstractItemView::NoEditTriggers );
setSelectionMode( QAbstractItemView::SingleSelection );
+ loadFavorites();
connect( this, SIGNAL( activated( QModelIndex ) ),
SLOT( selectedMapTheme( QModelIndex ) ) );
@@ -162,7 +167,13 @@
menu.addAction( "&Create a New Map...", this, SLOT( mapWizard() ) );
if( QFileInfo( MarbleDirs::localPath() + "/maps/" + d->currentThemePath() ).exists() )
menu.addAction( tr( "&Delete Map Theme" ), this, SLOT( deleteMap() ) );
- menu.addAction( "&Upload Map...", this, SLOT( uploadDialog() ) );
+ menu.addAction( tr( "&Upload Map..." ), this, SLOT( uploadDialog() ) );
+ QAction *favAction = menu.addAction( tr( "&Favorite" ), this, SLOT( toggleFavorite() ) );
+ favAction->setCheckable( true );
+ if( currentIsFavorite() )
+ favAction->setChecked( true );
+ else
+ favAction->setChecked( false );
menu.exec( mapToGlobal( pos ) );
}
@@ -183,4 +194,48 @@
}
}
+void MarbleThemeSelectView::toggleFavorite()
+{
+ QModelIndex index = currentIndex();
+ QAbstractItemModel *model = this->model();
+ QModelIndex columnIndex = model->index( index.row(), 0 );
+
+ if( currentIsFavorite() )
+ {
+ m_settings.beginGroup( "Favorites" );
+ m_settings.remove( model->data( columnIndex ).toString() );
+ }
+ else
+ {
+ m_settings.beginGroup( "Favorites" );
+ m_settings.setValue( model->data( columnIndex ).toString(), QDateTime::currentDateTime() );
+ }
+ m_settings.endGroup();
+ model->sort( 0 );
+}
+
+void MarbleThemeSelectView::loadFavorites()
+{
+ m_settings.beginGroup( "Favorites" );
+ if( !m_settings.contains( "initialized" ) ) {
+ m_settings.setValue( "initialized", true );
+ QDateTime currentDateTime = QDateTime::currentDateTime();
+ m_settings.setValue( "Atlas", currentDateTime );
+ m_settings.setValue( "OpenStreetMap", currentDateTime );
+ m_settings.setValue( "Satellite View", currentDateTime );
+ }
+ m_settings.endGroup();
+}
+
+bool MarbleThemeSelectView::currentIsFavorite()
+{
+ QModelIndex index = currentIndex();
+ const QAbstractItemModel *model = index.model();
+ QModelIndex nameIndex = model->index( index.row(), 0, QModelIndex() );
+ m_settings.beginGroup( "Favorites" );
+ bool favorite = m_settings.contains( model->data( nameIndex ).toString() );
+ m_settings.endGroup();
+ return favorite;
+}
+
#include "MarbleThemeSelectView.moc"
--- trunk/KDE/kdeedu/marble/src/lib/MarbleThemeSelectView.h #1224573:1224574
@@ -18,6 +18,7 @@
#include <QtCore/QModelIndex>
+#include <QtCore/QSettings>
#include <QtGui/QListView>
#include "marble_export.h"
@@ -46,6 +47,7 @@
void mapWizard();
void showContextMenu( const QPoint& pos );
void deleteMap();
+ void toggleFavorite();
Q_SIGNALS:
void selectMapTheme( const QString& );
@@ -55,6 +57,9 @@
private:
Q_DISABLE_COPY( MarbleThemeSelectView )
+ void loadFavorites();
+ bool currentIsFavorite();
+ QSettings m_settings;
class Private;
Private *const d;
};
More information about the Marble-commits
mailing list