* split DataSource into its own files

* move DataSource::Data to DataEngine::Data; this means consumers of DataEngine have no need to know about DataSource as a class

svn path=/trunk/KDE/kdebase/workspace/plasma/lib/; revision=666756
This commit is contained in:
Aaron J. Seigo 2007-05-20 20:36:59 +00:00
parent 520553079a
commit b8cc485705
16 changed files with 173 additions and 107 deletions

View File

@ -6,6 +6,7 @@ set(plasma_LIB_SRCS
abstractrunner.cpp abstractrunner.cpp
applet.cpp applet.cpp
dataengine.cpp dataengine.cpp
datasource.cpp
datavisualization.cpp datavisualization.cpp
plasma.cpp plasma.cpp
interface.cpp interface.cpp
@ -34,6 +35,7 @@ install( FILES
abstractrunner.h abstractrunner.h
applet.h applet.h
dataengine.h dataengine.h
datasource.h
datavisualization.h datavisualization.h
interface.h interface.h
plasma.h plasma.h

View File

@ -24,7 +24,7 @@
#include <ksharedconfig.h> #include <ksharedconfig.h>
#include "plasma.h" #include <plasma.h>
namespace Plasma namespace Plasma
{ {

View File

@ -1,11 +1,11 @@
#ifndef APPLEYLAYOUT_H #ifndef APPLEYLAYOUT_H
#define APPLEYLAYOUT_H #define APPLEYLAYOUT_H
#include "plasma_export.h"
#include <QLayout> #include <QLayout>
#include <QSize> #include <QSize>
#include <plasma_export.h>
class QLayoutItem; class QLayoutItem;
class QRect; class QRect;
namespace Plasma namespace Plasma

View File

@ -22,63 +22,12 @@
#include <KDebug> #include <KDebug>
#include "dataengine.h" #include "dataengine.h"
#include "datasource.h"
#include "datavisualization.h" #include "datavisualization.h"
namespace Plasma namespace Plasma
{ {
class DataSource::Private
{
public:
Private()
: dirty(false)
{}
QString name;
Data data;
bool dirty;
};
DataSource::DataSource(QObject* parent)
: QObject(parent),
d(new Private())
{
}
DataSource::~DataSource()
{
delete d;
}
QString DataSource::name()
{
return objectName();
}
void DataSource::setName(const QString& name)
{
setObjectName(name);
}
const Plasma::DataSource::Data DataSource::data() const
{
return d->data;
}
void DataSource::setData(const QString& key, const QVariant& value)
{
d->data[key] = value;
d->dirty = true;
}
void DataSource::checkForUpdate()
{
if (d->dirty) {
emit updated(d->data);
d->dirty = false;
}
}
class DataEngine::Private class DataEngine::Private
{ {
public: public:
@ -150,11 +99,11 @@ void DataEngine::connectSource(const QString& source, DataVisualization* visuali
// return; // return;
// } // }
connect(s, SIGNAL(updated(Plasma::DataSource::Data)), connect(s, SIGNAL(updated(Plasma::DataEngine::Data)),
visualization, SLOT(updated(Plasma::DataSource::Data))); visualization, SLOT(updated(Plasma::DataEngine::Data)));
} }
DataSource::Data DataEngine::query(const QString& source) DataEngine::Data DataEngine::query(const QString& source)
{ {
Q_UNUSED(source) Q_UNUSED(source)

View File

@ -16,62 +16,35 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#ifndef PLASMA_ENGINE_H #ifndef PLASMA_DATAENGINE_H
#define PLASMA_ENGINE_H #define PLASMA_DATAENGINE_H
#include <QAtomic> #include <QAtomic>
#include <QtCore/QHash> #include <QHash>
#include <QtCore/QObject> #include <QObject>
#include <QtCore/QStringList> #include <QStringList>
#include <plasma_export.h> #include <plasma_export.h>
namespace Plasma namespace Plasma
{ {
class DataSource;
class DataVisualization; class DataVisualization;
class PLASMA_EXPORT DataSource : public QObject
{
Q_OBJECT
public:
typedef QHash<QString, DataSource*> Dict;
typedef QHash<QString, QVariant> Data;
typedef QHash<QString, Dict> Grouping;
explicit DataSource(QObject* parent = 0);
virtual ~DataSource();
QString name();
void setName(const QString&);
const Data data() const;
void setData(const QString& key, const QVariant& value);
void checkForUpdate();
Q_SIGNALS:
void updated(const Plasma::DataSource::Data&);
private:
class Private;
Private* const d;
};
class PLASMA_EXPORT DataEngine : public QObject class PLASMA_EXPORT DataEngine : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
typedef QHash<QString, DataEngine*> Dict; typedef QHash<QString, DataEngine*> Dict;
typedef QHash<QString, QVariant> Data;
DataEngine(QObject* parent); DataEngine(QObject* parent);
virtual ~DataEngine(); virtual ~DataEngine();
virtual QStringList dataSources(); virtual QStringList dataSources();
void connectSource(const QString& source, DataVisualization* visualization); void connectSource(const QString& source, DataVisualization* visualization);
DataSource::Data query(const QString& source); Data query(const QString& source);
void ref(); void ref();
void deref(); void deref();
@ -96,9 +69,9 @@ class PLASMA_EXPORT DataEngine : public QObject
} // Plasma namespace } // Plasma namespace
#define K_EXPORT_PLASMA_DATAENGINE(libname, classname) \ #define K_EXPORT_PLASMA_DATAENGINE(libname, classname) \
K_EXPORT_COMPONENT_FACTORY( \ K_EXPORT_COMPONENT_FACTORY( \
plasma_##libname##_engine, \ plasma_##libname##_engine, \
KGenericFactory<classname>("plasma_" #libname "_engine")) KGenericFactory<classname>("plasma_" #libname "_engine"))
#endif // multiple inclusion guard #endif // multiple inclusion guard

84
datasource.cpp Normal file
View File

@ -0,0 +1,84 @@
/*
* Copyright (C) 2006 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License version 2 as
* published by the Free Software Foundation
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QVariant>
#include <KDebug>
#include "datasource.h"
namespace Plasma
{
class DataSource::Private
{
public:
Private()
: dirty(false)
{}
QString name;
DataEngine::Data data;
bool dirty;
};
DataSource::DataSource(QObject* parent)
: QObject(parent),
d(new Private())
{
}
DataSource::~DataSource()
{
delete d;
}
QString DataSource::name()
{
return objectName();
}
void DataSource::setName(const QString& name)
{
setObjectName(name);
}
const DataEngine::Data DataSource::data() const
{
return d->data;
}
void DataSource::setData(const QString& key, const QVariant& value)
{
d->data[key] = value;
d->dirty = true;
}
void DataSource::checkForUpdate()
{
if (d->dirty) {
emit updated(d->data);
d->dirty = false;
}
}
} // Plasma namespace
#include "datasource.moc"

59
datasource.h Normal file
View File

@ -0,0 +1,59 @@
/*
* Copyright (C) 2006 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License version 2 as
* published by the Free Software Foundation
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_DATASOURCE_H
#define PLASMA_DATASOURCE_H
#include <QtCore/QHash>
#include <QtCore/QObject>
#include <plasma_export.h>
#include <dataengine.h>
namespace Plasma
{
class PLASMA_EXPORT DataSource : public QObject
{
Q_OBJECT
public:
typedef QHash<QString, DataSource*> Dict;
typedef QHash<QString, Dict> Grouping;
explicit DataSource(QObject* parent = 0);
virtual ~DataSource();
QString name();
void setName(const QString&);
const DataEngine::Data data() const;
void setData(const QString& key, const QVariant& value);
void checkForUpdate();
Q_SIGNALS:
void updated(const Plasma::DataEngine::Data&);
private:
class Private;
Private* const d;
};
} // Plasma namespace
#endif // multiple inclusion guard

View File

@ -21,7 +21,7 @@
#include <QtCore/QObject> #include <QtCore/QObject>
#include "dataengine.h" #include <dataengine.h>
namespace Plasma namespace Plasma
{ {
@ -35,7 +35,7 @@ class PLASMA_EXPORT DataVisualization : public QObject
virtual ~DataVisualization(); virtual ~DataVisualization();
public Q_SLOTS: public Q_SLOTS:
virtual void updated(const Plasma::DataSource::Data&) = 0; virtual void updated(const Plasma::DataEngine::Data&) = 0;
private: private:
class Private; class Private;

View File

@ -89,8 +89,7 @@ QRectF CheckBox::boundingRect() const
void CheckBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) void CheckBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{ {
Q_UNUSED(option)
QStyleOptionButton options; QStyleOptionButton options;
options.rect = boundingRect().toRect(); options.rect = boundingRect().toRect();
options.text = text(); options.text = text();
@ -113,7 +112,7 @@ void CheckBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
} }
void CheckBox::data(const DataSource::Data&) void CheckBox::data(const DataEngine::Data&)
{ {
} }

View File

@ -59,7 +59,7 @@ class KDE_EXPORT CheckBox : public DataVisualization,public QGraphicsItem
public Q_SLOTS: public Q_SLOTS:
void data(const DataSource::Data&); void data(const DataEngine::Data&);
Q_SIGNALS: Q_SIGNALS:
void clicked(); void clicked();
protected: protected:

View File

@ -53,7 +53,7 @@ void LineEdit::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QGraphicsTextItem::paint(painter, style, widget); QGraphicsTextItem::paint(painter, style, widget);
} }
void LineEdit::data(const DataSource::Data&) void LineEdit::data(const DataEngine::Data&)
{ {
} }

View File

@ -41,7 +41,7 @@ class KDE_EXPORT LineEdit : public QGraphicsTextItem,
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
public Q_SLOTS: public Q_SLOTS:
void data(const DataSource::Data&); void data(const DataEngine::Data&);
}; };

View File

@ -82,7 +82,7 @@ PushButton::~PushButton()
delete d; delete d;
} }
void PushButton::data(const DataSource::Data &data) void PushButton::data(const DataEngine::Data &data)
{ {
Q_UNUSED(data) Q_UNUSED(data)
} }

View File

@ -91,7 +91,7 @@ class KDE_EXPORT PushButton : public DataVisualization,
void clicked(); void clicked();
public Q_SLOTS: public Q_SLOTS:
virtual void data(const DataSource::Data &); virtual void data(const DataEngine::Data &);
protected: protected:
bool isDown(); bool isDown();

View File

@ -148,7 +148,7 @@ void RadioButton::setText(const QString &text)
update(); update();
} }
void RadioButton::updated(const Plasma::DataSource::Data &data) void RadioButton::updated(const Plasma::DataEngine::Data &data)
{ {
Q_UNUSED(data); Q_UNUSED(data);
} }

View File

@ -73,7 +73,7 @@ public:
public Q_SLOTS: public Q_SLOTS:
// DataVisualization overriden virtual slots // DataVisualization overriden virtual slots
void updated(const Plasma::DataSource::Data &data); void updated(const Plasma::DataEngine::Data &data);
Q_SIGNALS: Q_SIGNALS:
void clicked(); void clicked();