From kde-commits Tue Jul 31 22:33:32 2007 From: Sebastian Sauer Date: Tue, 31 Jul 2007 22:33:32 +0000 To: kde-commits Subject: KDE/kdeutils/superkaramba Message-Id: <1185921212.716050.13511.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=118592122121086 SVN commit 694855 by sebsauer: some more work to connect Plasma::DataEngine together with SK. M +85 -30 skapplet/skengineadaptor.h M +3 -1 src/meters/meter.h --- trunk/KDE/kdeutils/superkaramba/skapplet/skengineadaptor.h #694854:694855 @@ -26,9 +26,61 @@ #include #include +#include "../src/meters/meter.h" + namespace Skip { /** +* This is a helper class that connects a Plasma::DataEngine together +* with a SuperKaramba Meter. +*/ +class EngineConnector : public QObject +{ + Q_OBJECT + public: + explicit EngineConnector(Meter *meter) : QObject(meter), m_meter(meter) { Q_ASSERT(m_meter); } + virtual ~EngineConnector() {} + Meter* meter() const { return m_meter; } + + public Q_SLOTS: + + /** + * Returns the name of the data source. + */ + QString source() const { return m_source; } + + /** + * Set the name of the data source. + */ + void setSource(const QString& source) { m_source = source; } + + /** + * Return the format the data should used for displaying. + */ + QString format() const { return m_format; } + + /** + * Set the format the data should use for displaying. + */ + void setFormat(const QString& format) { m_format = format; } + + private Q_SLOTS: + + void updated(const QString& source, Plasma::DataEngine::Data data) { + Q_UNUSED(source); + Q_UNUSED(data); + kDebug()<<"##################### EngineConnector::updated()"<setValue(m_format, data.contains(m_data) ? data[m_data] : QVariant()); + } + + private: + Meter *m_meter; + QString m_source; + QString m_format; +}; + +/** * The EngineAdaptor class implements an adaptor for * Plasma::DataEngine objects. */ @@ -43,23 +95,6 @@ } virtual ~EngineAdaptor() {} - QVariantMap dataToMap(Plasma::DataEngine::Data data) { - QVariantMap map; - Plasma::DataEngine::DataIterator it(data); - while( it.hasNext() ) { - it.next(); - map.insert(it.key(), it.value()); - } - return map; - } - - Plasma::DataEngine::Data mapToData(QVariantMap map) { - Plasma::DataEngine::Data data; - for(QVariantMap::Iterator it = map.begin(); it != map.end(); ++it) - data.insert(it.key(), it.value()); - return data; - } - public Q_SLOTS: /** @@ -87,40 +122,43 @@ * the sourceUpdated() signal will be emitted. */ void connectSource(const QString& source, QObject* visualization = 0) { - m_engine->connectSource(source, visualization ? visualization : this); + if( Meter* m = dynamic_cast(visualization) ) + m_engine->connectSource(source, new EngineConnector(m)); + else + m_engine->connectSource(source, visualization ? visualization : this); } /** * Disconnect from a source. */ void disconnectSource(const QString& source, QObject* visualization = 0) { - m_engine->disconnectSource(source, visualization ? visualization : this); + if( Meter* m = dynamic_cast(visualization) ) { + foreach(EngineConnector* c, m->findChildren()) + if( c->meter() == m ) + delete c; + } + else + m_engine->disconnectSource(source, visualization ? visualization : this); } -#if 0 - /** - * Request to update the source. - */ - void updateSource(const QString& source, QVariantMap data = QVariantMap()) { - //QMetaObject::invokeMethod(m_engine, "checkForUpdates"); - updated(source, mapToData(data)); - } -#endif - Q_SIGNALS: /** * Emitted when a new data source is created + * \param source The name of the data source. **/ void sourceAdded(const QString& source); /** * Emitted when a data source is removed. + * \param source The name of the data source. **/ void sourceRemoved(const QString& source); /** - * Emitted when a data source is removed. + * Emitted when a data source got updated. + * \param source The name of the data source. + * \param data The map of the data that got changed. **/ void sourceUpdated(const QString& source, QVariantMap data); @@ -133,6 +171,23 @@ private: Plasma::DataEngine* m_engine; + + QVariantMap dataToMap(Plasma::DataEngine::Data data) { + QVariantMap map; + Plasma::DataEngine::DataIterator it(data); + while( it.hasNext() ) { + it.next(); + map.insert(it.key(), it.value()); + } + return map; + } + + Plasma::DataEngine::Data mapToData(QVariantMap map) { + Plasma::DataEngine::Data data; + for(QVariantMap::Iterator it = map.begin(); it != map.end(); ++it) + data.insert(it.key(), it.value()); + return data; + } }; } // end of namespace SuperKarambaPlasmaApplet --- trunk/KDE/kdeutils/superkaramba/src/meters/meter.h #694854:694855 @@ -15,10 +15,12 @@ #include #include +#include "../superkaramba_export.h" + class QPainter; class Karamba; -class Meter : public QObject, public QGraphicsItem +class SUPERKARAMBA_EXPORT Meter : public QObject, public QGraphicsItem { Q_OBJECT public: