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

Bastian Holst bastianholst at gmx.de
Sat Oct 2 21:39:22 CEST 2010


SVN commit 1181944 by bholst:

Splitting the last tab, the MapView from the MarbleControlBox.
All ControlBox tabs can now be run seperately.

 M  +2 -0      CMakeLists.txt  
 A             MapViewWidget.cpp   [License: LGPL]
 A             MapViewWidget.h   [License: LGPL]
 M  +24 -192   MarbleControlBox.cpp  
 M  +3 -18     MarbleControlBox.h  
 M  +1 -0      NavigationWidget.cpp  


--- trunk/KDE/kdeedu/marble/src/lib/CMakeLists.txt #1181943:1181944
@@ -66,6 +66,7 @@
     MarbleMap.cpp
     MarbleControlBox.cpp
     NavigationWidget.cpp
+    MapViewWidget.cpp
     FileViewWidget.cpp
     LegendWidget.cpp
     CurrentLocationWidget.cpp
@@ -309,6 +310,7 @@
     MarbleModel.h
     MarbleControlBox.h
     NavigationWidget.h
+    MapViewWidget.h
     LegendWidget.h
     FileViewWidget.h
     CurrentLocationWidget.h
--- trunk/KDE/kdeedu/marble/src/lib/MarbleControlBox.cpp #1181943:1181944
@@ -21,33 +21,27 @@
  * Boston, MA 02110-1301, USA.
  */
 
+// Self
 #include "MarbleControlBox.h"
 
-#include <QtGui/QStandardItemModel>
-#include <QtGui/QCheckBox>
-#include "global.h"
-
+// Tabs
 #include "CurrentLocationWidget.h"
 #include "NavigationWidget.h"
 #include "FileViewWidget.h"
 #include "LegendWidget.h"
+#include "MapViewWidget.h"
+#include "RoutingWidget.h"
+
+// Marble
+#include "global.h"
 #include "MarbleWidget.h"
 #include "MarbleModel.h"
-#include "RoutingWidget.h"
-#include "MathHelper.h"
-#include "MapThemeSortFilterProxyModel.h"
 #include "GeoSceneDocument.h"
 #include "GeoSceneHead.h"
-#include "Planet.h"
 #include "HttpDownloadManager.h"
 #include "MarbleDebug.h"
 
-using namespace Marble;
 
-#include "ui_NavigationWidget.h"
-#include "ui_MapViewWidget.h"
-#include "ui_CurrentLocationWidget.h"
-
 namespace Marble
 {
 
@@ -56,22 +50,16 @@
  public:
     MarbleControlBoxPrivate();
     MarbleWidget  *m_widget;
-    QStandardItemModel *m_celestialList;
 
     NavigationWidget            *m_navigationWidget;
     LegendWidget                *m_legendWidget;
-    QWidget                     *m_mapViewWidget;
-    Ui::MapViewWidget           m_mapViewUi;
+    MapViewWidget               *m_mapViewWidget;
 
     CurrentLocationWidget       *m_currentLocationWidget;
 
     FileViewWidget              *m_fileViewWidget;
 
-    QStandardItemModel     *m_mapThemeModel;
-    MapThemeSortFilterProxyModel *m_mapSortProxy;
-
     RoutingWidget  *m_routingWidget;
-    GeoSceneDocument      *mapTheme;
 };
 
 MarbleControlBoxPrivate::MarbleControlBoxPrivate() : m_routingWidget(0)
@@ -97,14 +85,7 @@
     d->m_legendWidget = new LegendWidget( this );
     addItem( d->m_legendWidget, d->m_legendWidget->windowTitle() );
 
-    d->m_mapViewWidget = new QWidget( this );
-    d->m_mapViewUi.setupUi( d->m_mapViewWidget );
-    if ( MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen ) {
-        d->m_mapViewUi.projectionLabel_2->setVisible( false );
-        d->m_mapViewUi.line->setVisible( false );
-        d->m_mapViewUi.celestialBodyLabel->setVisible( false );
-        d->m_mapViewUi.mapThemeLabel->setVisible( false );
-    }
+    d->m_mapViewWidget = new MapViewWidget( this );
     addItem( d->m_mapViewWidget, d->m_mapViewWidget->windowTitle() );
 
     d->m_fileViewWidget = new FileViewWidget( this );
@@ -114,79 +95,18 @@
 
     addItem( d->m_currentLocationWidget, d->m_currentLocationWidget->windowTitle() );
 
-    d->m_mapSortProxy = new MapThemeSortFilterProxyModel( this );
-
     setCurrentIndex(0);
 
     //default
     setCurrentLocationTabShown( true );
     setFileViewTabShown( false );
-
-    d->m_mapThemeModel = 0;
-
-    // MapView
-    connect( d->m_mapViewUi.marbleThemeSelectView, SIGNAL( selectMapTheme( const QString& ) ),
-             this,                                 SIGNAL( selectMapTheme( const QString& ) ) );
-    connect( d->m_mapViewUi.projectionComboBox,    SIGNAL( activated( int ) ),
-             this,                                 SLOT( projectionSelected( int ) ) );
-
-    d->m_mapViewUi.projectionComboBox->setEnabled( true );
-
-    // Setting up the celestial combobox
-    d->m_celestialList = new QStandardItemModel();
-
-    d->m_mapViewUi.celestialBodyComboBox->setModel( d->m_celestialList );
-    connect( d->m_mapViewUi.celestialBodyComboBox, SIGNAL( activated( const QString& ) ),
-             this,                                 SLOT( selectCurrentMapTheme( const QString& ) ) );
 }
 
 MarbleControlBox::~MarbleControlBox()
 {
-    delete d->m_celestialList;
     delete d;
 }
 
-void MarbleControlBox::setMapThemeModel( QStandardItemModel *mapThemeModel )
-{
-    if ( mapThemeModel != d->m_mapThemeModel ) {
-        delete d->m_mapThemeModel;
-    }
-
-    d->m_mapThemeModel = mapThemeModel;
-    d->m_mapSortProxy->setSourceModel( d->m_mapThemeModel );
-    int currentIndex = d->m_mapViewUi.celestialBodyComboBox->currentIndex();
-    QStandardItem * selectedItem = d->m_celestialList->item( currentIndex, 1 );
-
-    if ( selectedItem ) {
-        QString selectedId;
-        selectedId = selectedItem->text();
-        d->m_mapSortProxy->setFilterRegExp( QRegExp( selectedId, Qt::CaseInsensitive,QRegExp::FixedString ) );
-    }
-
-    d->m_mapSortProxy->sort( 0 );
-    d->m_mapViewUi.marbleThemeSelectView->setModel( d->m_mapSortProxy );
-    connect( d->m_mapThemeModel,       SIGNAL( rowsInserted( QModelIndex, int, int ) ),
-            this,                     SLOT( updateMapThemeView() ) );
-}
-
-void MarbleControlBox::updateCelestialModel()
-{
-    int row = d->m_mapThemeModel->rowCount();
-
-    for ( int i = 0; i < row; ++i )
-    {
-        QString celestialBodyId = ( d->m_mapThemeModel->data( d->m_mapThemeModel->index( i, 1 ) ).toString() ).section( '/', 0, 0 );
-        QString celestialBodyName = Planet::name( celestialBodyId );
-
-        QList<QStandardItem*> matchingItems = d->m_celestialList->findItems ( celestialBodyId, Qt::MatchExactly, 1 );
-        if ( matchingItems.isEmpty() ) {
-            d->m_celestialList->appendRow( QList<QStandardItem*>()
-                                << new QStandardItem( celestialBodyName )
-                                << new QStandardItem( celestialBodyId ) );
-        }
-    }
-}
-
 void MarbleControlBox::addMarbleWidget(MarbleWidget *widget)
 {
     d->m_widget = widget;
@@ -200,21 +120,11 @@
     d->m_fileViewWidget->setMarbleWidget( widget );
     d->m_legendWidget->setMarbleWidget( widget );
     d->m_navigationWidget->setMarbleWidget( widget );
+    d->m_mapViewWidget->setMarbleWidget( widget );
+    d->m_currentLocationWidget->setMarbleWidget( widget );
 
-    connect( this,        SIGNAL( projectionSelected( Projection ) ),
-             d->m_widget, SLOT( setProjection( Projection ) ) );
-
     connect( d->m_widget, SIGNAL( themeChanged( QString ) ),
              this,        SLOT( selectTheme( QString ) ) );
-
-    connect( d->m_widget, SIGNAL( projectionChanged( Projection ) ),
-             this,        SLOT( selectProjection( Projection ) ) );
-    selectProjection( d->m_widget->projection() );
-
-    connect( this,        SIGNAL( selectMapTheme( const QString& ) ),
-             d->m_widget, SLOT( setMapThemeId( const QString& ) ) );
-
-    d->m_currentLocationWidget->setMarbleWidget( widget );
 }
 
 void MarbleControlBox::setWidgetTabShown( QWidget * widget,
@@ -240,17 +150,6 @@
     }
 }
 
-void MarbleControlBox::updateMapThemeView()
-{
-    updateCelestialModel();
-
-    if ( d->m_widget ) {
-        QString mapThemeId = d->m_widget->mapThemeId();
-        if ( !mapThemeId.isEmpty() )
-            selectTheme( mapThemeId );
-    }
-}
-
 void MarbleControlBox::setNavigationTabShown( bool show )
 {
     QString  title = tr( "Navigation" );
@@ -300,32 +199,11 @@
 
 void MarbleControlBox::selectTheme( const QString &theme )
 {
-    if ( !d->m_mapSortProxy || !d->m_widget )
+    Q_UNUSED( theme )
+
+    if ( !d->m_widget )
         return;
-    // Check if the new selected theme is different from the current one
-    QModelIndex currentIndex = d->m_mapViewUi.marbleThemeSelectView->currentIndex();
-    QString indexTheme = d->m_mapSortProxy->data( d->m_mapSortProxy->index(
-                         currentIndex.row(), 1, QModelIndex() ) ).toString();
 
-    if ( theme != indexTheme ) {
-        /* indexTheme would be empty if the chosen map has not been set yet. As
-        this needs to be done after the mapThemeId has been set, check if that is
-        not empty first. The behaviour differs between Linux and Windows: on
-        Windows the reading of the settings is not delayed, thus the mapThemeId
-        is available earlier than on Linux.
-        */
-        if( indexTheme.isEmpty() && !d->m_widget->mapThemeId().isEmpty() ) {
-            QList<QStandardItem*> items = d->m_mapThemeModel->findItems( theme, Qt::MatchExactly, 1 );
-            if( items.size() >= 1 ) {
-                QModelIndex iterIndex = items.first()->index();
-                QModelIndex iterIndexName = d->m_mapSortProxy->mapFromSource( iterIndex.sibling( iterIndex.row(), 0 ) );
-
-                d->m_mapViewUi.marbleThemeSelectView->setCurrentIndex( iterIndexName );
-
-                d->m_mapViewUi.marbleThemeSelectView->scrollTo( iterIndexName );
-            }
-        }
-
         QString selectedId = d->m_widget->mapTheme()->head()->target();
         int routingIndex = indexOf( d->m_routingWidget );
         setItemEnabled( routingIndex, selectedId == "earth" );
@@ -333,64 +211,8 @@
         if ( locationIndex >= 0 ) {
             setItemEnabled( locationIndex, selectedId == "earth" );
         }
-
-        QList<QStandardItem*> itemList = d->m_celestialList->findItems( selectedId, Qt::MatchExactly, 1 );
-
-        if ( !itemList.isEmpty() ) {
-            QStandardItem * selectedItem = itemList.first();
-
-            if ( selectedItem ) {
-                int selectedIndex = selectedItem->row();
-                d->m_mapViewUi.celestialBodyComboBox->setCurrentIndex( selectedIndex );
-                d->m_mapSortProxy->setFilterRegExp( QRegExp( selectedId, Qt::CaseInsensitive,QRegExp::FixedString ) );
             }
 
-            d->m_mapSortProxy->sort( 0 );
-        }
-    }
-}
-
-void MarbleControlBox::selectProjection( Projection projection )
-{
-    if ( (int)projection != d->m_mapViewUi.projectionComboBox->currentIndex() )
-        d->m_mapViewUi.projectionComboBox->setCurrentIndex( (int) projection );
-}
-
-void MarbleControlBox::selectCurrentMapTheme( const QString& celestialBodyId )
-{
-    Q_UNUSED( celestialBodyId )
-
-    setMapThemeModel( d->m_mapThemeModel );
-
-    bool foundMapTheme = false;
-
-    QString currentMapThemeId = d->m_widget->mapThemeId();
-
-    int row = d->m_mapSortProxy->rowCount();
-
-    for ( int i = 0; i < row; ++i )
-    {
-        QModelIndex index = d->m_mapSortProxy->index(i,1);
-        QString itMapThemeId = d->m_mapSortProxy->data(index).toString();
-        if ( currentMapThemeId == itMapThemeId )
-        {
-            foundMapTheme = true;
-            break;
-        }
-    }
-    if ( !foundMapTheme ) {
-        QModelIndex index = d->m_mapSortProxy->index(0,1);
-        d->m_widget->setMapThemeId( d->m_mapSortProxy->data(index).toString());
-    }
-
-    updateMapThemeView();
-}
-// Relay a signal and convert the parameter from an int to a Projection.
-void MarbleControlBox::projectionSelected( int projectionIndex )
-{
-    emit projectionSelected( (Projection) projectionIndex );
-}
-
 void MarbleControlBox::setWorkOffline(bool offline)
 {
     HttpDownloadManager * const downloadManager =
@@ -402,6 +224,16 @@
     }
 }
 
+void MarbleControlBox::setMapThemeModel( QStandardItemModel *mapThemeModel )
+{
+    d->m_mapViewWidget->setMapThemeModel( mapThemeModel );
 }
 
+void MarbleControlBox::updateMapThemeView()
+{
+    d->m_mapViewWidget->updateMapThemeView();
+}
+
+}
+
 #include "MarbleControlBox.moc"
--- trunk/KDE/kdeedu/marble/src/lib/MarbleControlBox.h #1181943:1181944
@@ -29,8 +29,8 @@
  */
 
 class QResizeEvent;
-class QStandardItemModel;
 class QString;
+class QStandardItemModel;
 
 namespace Marble
 {
@@ -90,28 +90,18 @@
      */
     void addMarbleWidget( MarbleWidget *widget );
 
-    void setMapThemeModel( QStandardItemModel *mapThemeModel );
-
-    void updateCelestialModel();
-
     /**
       * Toggle offline mode of download manager and runners.
       */
     void setWorkOffline(bool offline);
 
- Q_SIGNALS:
-    void selectMapTheme( const QString& );
+    void setMapThemeModel( QStandardItemModel *mapThemeModel );
 
-    void projectionSelected( Projection );
-
  public Q_SLOTS:
-
     void selectTheme( const QString & );
 
-    void selectCurrentMapTheme( const QString& );
+    void updateMapThemeView();
 
-    void selectProjection( Projection projection );
-
     /**
      * @brief Control whether the Navigation tab is shown.
      * @param show  boolean that controls if the Navigation tab is shown.
@@ -144,11 +134,6 @@
      */
     void setRoutingTabShown( bool show );
 
-    /// whenever a new map gets inserted, the following slot will adapt the ListView accordingly
-    void updateMapThemeView();
-
-    void projectionSelected( int projectionIndex );
-
  private:
     void setWidgetTabShown( QWidget * widget, int insertIndex,
                             bool show, QString &text );
--- trunk/KDE/kdeedu/marble/src/lib/NavigationWidget.cpp #1181943:1181944
@@ -96,6 +96,7 @@
 
 NavigationWidget::~NavigationWidget()
 {
+    delete d;
 }
 
 void NavigationWidget::setMarbleWidget( MarbleWidget *widget )


More information about the Marble-commits mailing list