[Marble-commits] KDE/kdeedu/marble/src/plugins/render/earthquake
Torsten Rahn
tackat at kde.org
Wed Jan 5 19:32:39 CET 2011
SVN commit 1212104 by rahn:
- Earthquake configuration dialog
http://reviewboard.kde.org/r/6269/
by Daniel Marth.
M +3 -0 CMakeLists.txt
M +34 -5 EarthquakeModel.cpp
M +12 -0 EarthquakeModel.h
M +108 -2 EarthquakePlugin.cpp
M +29 -0 EarthquakePlugin.h
--- trunk/KDE/kdeedu/marble/src/plugins/render/earthquake/CMakeLists.txt #1212103:1212104
@@ -12,6 +12,9 @@
EarthquakeModel.cpp
EarthquakeItem.cpp
)
+set( earthquake_UI EarthquakeConfigWidget.ui )
+
+qt4_wrap_ui(my_SRCS ${earthquake_UI})
qt4_add_resources(my_SRCS earthquake.qrc)
qt4_automoc( ${my_SRCS} )
--- trunk/KDE/kdeedu/marble/src/plugins/render/earthquake/EarthquakeModel.cpp #1212103:1212104
@@ -15,6 +15,7 @@
#include "MarbleDataFacade.h"
#include "GeoDataCoordinates.h"
#include "GeoDataLatLonAltBox.h"
+#include "MarbleDebug.h"
#include <QtCore/QDebug>
#include <QtCore/QString>
@@ -26,9 +27,12 @@
namespace Marble {
-EarthquakeModel::EarthquakeModel( PluginManager *pluginManager,
- QObject *parent )
- : AbstractDataPluginModel( "earthquake", pluginManager, parent )
+EarthquakeModel::EarthquakeModel( PluginManager *pluginManager, QObject *parent )
+ : AbstractDataPluginModel( "earthquake", pluginManager, parent ),
+ m_numResults( numberOfItemsOnScreen ),
+ m_minMagnitude( 0.0 ),
+ m_startDate( QDateTime::fromString( "2006-02-04", "yyyy-MM-dd" ) ),
+ m_endDate( QDateTime::currentDateTime() )
{
// nothing to do
}
@@ -37,8 +41,30 @@
{
}
+void EarthquakeModel::setNumResults( int numResults )
+{
+ m_numResults = numResults;
+}
+
+void EarthquakeModel::setMinMagnitude( double minMagnitude )
+{
+ m_minMagnitude = minMagnitude;
+}
+
+void EarthquakeModel::setStartDate( const QDateTime& startDate )
+{
+ m_startDate = startDate;
+}
+
+void EarthquakeModel::setEndDate( const QDateTime& endDate )
+{
+ m_endDate = endDate;
+}
+
void EarthquakeModel::getAdditionalItems( const GeoDataLatLonAltBox& box, MarbleDataFacade *facade, qint32 number )
{
+ Q_UNUSED( number );
+
if( facade->target() != "earth" ) {
return;
}
@@ -48,8 +74,8 @@
geonamesUrl += "&south=" + QString::number( box.south() * RAD2DEG );
geonamesUrl += "&east=" + QString::number( box.east() * RAD2DEG );
geonamesUrl += "&west=" + QString::number( box.west() * RAD2DEG );
- geonamesUrl += "&date=" + QDate::currentDate().addMonths( -1 ).toString( "yyyy-MM-dd" );
- geonamesUrl += "&maxRows=" + QString::number( number );
+ geonamesUrl += "&date=" + m_endDate.toString( "yyyy-MM-dd" );
+ geonamesUrl += "&maxRows=" + QString::number( m_numResults );
geonamesUrl += "&formatted=true";
downloadDescriptionFile( QUrl( geonamesUrl ) );
}
@@ -77,6 +103,7 @@
QDateTime date = QDateTime::fromString( data, "yyyy-MM-dd hh:mm:ss" );
double depth = iterator.value().property( "depth" ).toNumber();
+ if( date <= m_endDate && date >= m_startDate && magnitude >= m_minMagnitude ) {
if( !itemExists( eqid ) ) {
// If it does not exists, create it
GeoDataCoordinates coordinates( longitude, latitude, 0.0, GeoDataCoordinates::Degree );
@@ -93,7 +120,9 @@
}
}
}
+}
+
}
#include "EarthquakeModel.moc"
--- trunk/KDE/kdeedu/marble/src/plugins/render/earthquake/EarthquakeModel.h #1212103:1212104
@@ -12,6 +12,7 @@
#define EARTHQUAKEMODEL_H
#include "AbstractDataPluginModel.h"
+#include <QtCore/QDateTime>
namespace Marble
{
@@ -30,6 +31,11 @@
~EarthquakeModel();
+ void setNumResults( int numResults );
+ void setMinMagnitude( double minMagnitude );
+ void setStartDate( const QDateTime& startDate );
+ void setEndDate( const QDateTime& endDate );
+
protected:
/**
* Generates the download url for the description file from the web service depending on
@@ -42,6 +48,12 @@
* prepares the data for usage.
**/
void parseFile( const QByteArray& file );
+
+private:
+ int m_numResults;
+ double m_minMagnitude;
+ QDateTime m_startDate;
+ QDateTime m_endDate;
};
}
--- trunk/KDE/kdeedu/marble/src/plugins/render/earthquake/EarthquakePlugin.cpp #1212103:1212104
@@ -10,20 +10,32 @@
#include "EarthquakePlugin.h"
#include "EarthquakeModel.h"
+#include "ui_EarthquakeConfigWidget.h"
+#include <QtGui/QPushButton>
+#include <QtGui/QSlider>
+
namespace Marble {
EarthquakePlugin::EarthquakePlugin()
- : m_isInitialized( false )
+ : m_isInitialized( false ),
+ m_configDialog( 0 )
{
setNameId( "earthquake" );
setEnabled( true ); // Plugin is enabled by default
setVisible( false ); // Plugin is invisible by default
+ connect( this, SIGNAL( settingsChanged( QString ) ),
+ this, SLOT( updateSettings() ) );
}
void EarthquakePlugin::initialize()
{
- setModel( new EarthquakeModel( pluginManager(), this ) );
+ EarthquakeModel *m = new EarthquakeModel( pluginManager(), this );
+ m->setNumResults( ui_configWidget->m_numResults->value() );
+ m->setMinMagnitude( ui_configWidget->m_minMagnitude->value() );
+ m->setEndDate( ui_configWidget->m_endDate->dateTime() );
+ m->setStartDate( ui_configWidget->m_startDate->dateTime() );
+ setModel( m );
setNumberOfItems( numberOfItemsOnScreen );
m_isInitialized = true;
}
@@ -53,8 +65,102 @@
return QIcon();
}
+QDialog *EarthquakePlugin::configDialog() const
+{
+ if ( !m_configDialog ) {
+ // Initializing configuration dialog
+ m_configDialog = new QDialog();
+ ui_configWidget = new Ui::EarthquakeConfigWidget;
+ ui_configWidget->setupUi( m_configDialog );
+ ui_configWidget->m_numResults->setRange( 1, numberOfItemsOnScreen );
+ readSettings();
+ connect( ui_configWidget->m_buttonBox, SIGNAL( accepted() ),
+ SLOT( writeSettings() ) );
+ connect( ui_configWidget->m_buttonBox, SIGNAL( rejected() ),
+ SLOT( readSettings() ) );
+ QPushButton *applyButton = ui_configWidget->m_buttonBox->button( QDialogButtonBox::Apply );
+ connect( applyButton, SIGNAL( clicked() ),
+ SLOT( writeSettings() ) );
+ connect( ui_configWidget->m_endDate, SIGNAL( dateTimeChanged ( const QDateTime& ) ),
+ SLOT( validateDateRange() ) );
}
+ return m_configDialog;
+}
+QHash<QString,QVariant> EarthquakePlugin::settings() const
+{
+ return m_settings;
+}
+
+void EarthquakePlugin::setSettings( QHash<QString,QVariant> settings )
+{
+ if ( !settings.contains( "numResults" ) ) {
+ settings.insert( "numResults", numberOfItemsOnScreen );
+ }
+ if ( !settings.contains( "minMagnitude" ) ) {
+ settings.insert( "minMagnitude", 0.0 );
+ }
+ if ( !settings.contains( "startDate" ) ) {
+ settings.insert( "startDate", QDateTime::fromString( "2006-02-04", "yyyy-MM-dd" ) );
+ }
+ if ( !settings.contains( "endDate" ) ) {
+ settings.insert( "endDate", QDateTime::currentDateTime() );
+ }
+
+ m_settings = settings;
+ readSettings();
+ emit settingsChanged( nameId() );
+}
+
+void EarthquakePlugin::readSettings() const
+{
+ if ( !m_configDialog )
+ return;
+
+ ui_configWidget->m_numResults->setValue( m_settings.value( "numResults" ).toInt() );
+ ui_configWidget->m_minMagnitude->setValue( m_settings.value( "minMagnitude" ).toDouble() );
+ ui_configWidget->m_startDate->setDateTime( m_settings.value( "startDate" ).toDateTime() );
+ ui_configWidget->m_endDate->setDateTime( m_settings.value( "endDate" ).toDateTime() );
+ ui_configWidget->m_startDate->setMaximumDateTime( ui_configWidget->m_endDate->dateTime() );
+}
+
+void EarthquakePlugin::writeSettings()
+{
+ m_settings.insert( "numResults", ui_configWidget->m_numResults->value() );
+ m_settings.insert( "minMagnitude", ui_configWidget->m_minMagnitude->value() );
+ m_settings.insert( "startDate", ui_configWidget->m_startDate->dateTime() );
+ m_settings.insert( "endDate", ui_configWidget->m_endDate->dateTime() );
+
+ emit settingsChanged( nameId() );
+}
+
+void EarthquakePlugin::updateSettings()
+{
+ EarthquakeModel *m = dynamic_cast<EarthquakeModel *>( model() );
+
+ if( m != NULL )
+ {
+ m = new EarthquakeModel( pluginManager(), this );
+ m->setNumResults( ui_configWidget->m_numResults->value() );
+ m->setMinMagnitude( ui_configWidget->m_minMagnitude->value() );
+ m->setEndDate( ui_configWidget->m_endDate->dateTime() );
+ m->setStartDate( ui_configWidget->m_startDate->dateTime() );
+ setModel( m );
+ }
+}
+
+void EarthquakePlugin::validateDateRange()
+{
+ if( ui_configWidget->m_startDate->dateTime() >
+ ui_configWidget->m_endDate->dateTime() )
+ {
+ ui_configWidget->m_startDate->setDateTime( ui_configWidget->m_endDate->dateTime() );
+ }
+ ui_configWidget->m_startDate->setMaximumDateTime( ui_configWidget->m_endDate->dateTime() );
+}
+
+}
+
Q_EXPORT_PLUGIN2( EarthquakePlugin, Marble::EarthquakePlugin )
#include "EarthquakePlugin.moc"
--- trunk/KDE/kdeedu/marble/src/plugins/render/earthquake/EarthquakePlugin.h #1212103:1212104
@@ -15,8 +15,14 @@
#include "RenderPlugin.h"
#include "RenderPluginInterface.h"
+#include <QtCore/QHash>
#include <QtGui/QIcon>
+namespace Ui
+{
+ class EarthquakeConfigWidget;
+}
+
namespace Marble
{
@@ -43,8 +49,31 @@
QIcon icon() const;
+ QDialog *configDialog() const;
+
+ /**
+ * @return: The settings of the item.
+ */
+ virtual QHash<QString,QVariant> settings() const;
+
+ /**
+ * Set the settings of the item.
+ */
+ virtual void setSettings( QHash<QString,QVariant> settings );
+
+public slots:
+ void readSettings() const;
+ void writeSettings();
+ void updateSettings();
+
private:
bool m_isInitialized;
+ mutable Ui::EarthquakeConfigWidget *ui_configWidget;
+ mutable QDialog *m_configDialog;
+ QHash<QString,QVariant> m_settings;
+
+private slots:
+ void validateDateRange();
};
}
More information about the Marble-commits
mailing list