* 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:
parent
520553079a
commit
b8cc485705
@ -6,6 +6,7 @@ set(plasma_LIB_SRCS
|
||||
abstractrunner.cpp
|
||||
applet.cpp
|
||||
dataengine.cpp
|
||||
datasource.cpp
|
||||
datavisualization.cpp
|
||||
plasma.cpp
|
||||
interface.cpp
|
||||
@ -34,6 +35,7 @@ install( FILES
|
||||
abstractrunner.h
|
||||
applet.h
|
||||
dataengine.h
|
||||
datasource.h
|
||||
datavisualization.h
|
||||
interface.h
|
||||
plasma.h
|
||||
|
2
applet.h
2
applet.h
@ -24,7 +24,7 @@
|
||||
|
||||
#include <ksharedconfig.h>
|
||||
|
||||
#include "plasma.h"
|
||||
#include <plasma.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
@ -1,11 +1,11 @@
|
||||
#ifndef APPLEYLAYOUT_H
|
||||
#define APPLEYLAYOUT_H
|
||||
|
||||
#include "plasma_export.h"
|
||||
|
||||
#include <QLayout>
|
||||
#include <QSize>
|
||||
|
||||
#include <plasma_export.h>
|
||||
|
||||
class QLayoutItem;
|
||||
class QRect;
|
||||
namespace Plasma
|
||||
|
@ -22,63 +22,12 @@
|
||||
#include <KDebug>
|
||||
|
||||
#include "dataengine.h"
|
||||
#include "datasource.h"
|
||||
#include "datavisualization.h"
|
||||
|
||||
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
|
||||
{
|
||||
public:
|
||||
@ -150,11 +99,11 @@ void DataEngine::connectSource(const QString& source, DataVisualization* visuali
|
||||
// return;
|
||||
// }
|
||||
|
||||
connect(s, SIGNAL(updated(Plasma::DataSource::Data)),
|
||||
visualization, SLOT(updated(Plasma::DataSource::Data)));
|
||||
connect(s, SIGNAL(updated(Plasma::DataEngine::Data)),
|
||||
visualization, SLOT(updated(Plasma::DataEngine::Data)));
|
||||
}
|
||||
|
||||
DataSource::Data DataEngine::query(const QString& source)
|
||||
DataEngine::Data DataEngine::query(const QString& source)
|
||||
{
|
||||
Q_UNUSED(source)
|
||||
|
||||
|
47
dataengine.h
47
dataengine.h
@ -16,62 +16,35 @@
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_ENGINE_H
|
||||
#define PLASMA_ENGINE_H
|
||||
#ifndef PLASMA_DATAENGINE_H
|
||||
#define PLASMA_DATAENGINE_H
|
||||
|
||||
#include <QAtomic>
|
||||
#include <QtCore/QHash>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QHash>
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
|
||||
#include <plasma_export.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class DataSource;
|
||||
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
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
typedef QHash<QString, DataEngine*> Dict;
|
||||
typedef QHash<QString, QVariant> Data;
|
||||
|
||||
DataEngine(QObject* parent);
|
||||
virtual ~DataEngine();
|
||||
|
||||
virtual QStringList dataSources();
|
||||
void connectSource(const QString& source, DataVisualization* visualization);
|
||||
DataSource::Data query(const QString& source);
|
||||
Data query(const QString& source);
|
||||
|
||||
void ref();
|
||||
void deref();
|
||||
@ -96,9 +69,9 @@ class PLASMA_EXPORT DataEngine : public QObject
|
||||
|
||||
} // Plasma namespace
|
||||
|
||||
#define K_EXPORT_PLASMA_DATAENGINE(libname, classname) \
|
||||
K_EXPORT_COMPONENT_FACTORY( \
|
||||
plasma_##libname##_engine, \
|
||||
#define K_EXPORT_PLASMA_DATAENGINE(libname, classname) \
|
||||
K_EXPORT_COMPONENT_FACTORY( \
|
||||
plasma_##libname##_engine, \
|
||||
KGenericFactory<classname>("plasma_" #libname "_engine"))
|
||||
|
||||
#endif // multiple inclusion guard
|
||||
|
84
datasource.cpp
Normal file
84
datasource.cpp
Normal 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
59
datasource.h
Normal 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
|
@ -21,7 +21,7 @@
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include "dataengine.h"
|
||||
#include <dataengine.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
@ -35,7 +35,7 @@ class PLASMA_EXPORT DataVisualization : public QObject
|
||||
virtual ~DataVisualization();
|
||||
|
||||
public Q_SLOTS:
|
||||
virtual void updated(const Plasma::DataSource::Data&) = 0;
|
||||
virtual void updated(const Plasma::DataEngine::Data&) = 0;
|
||||
|
||||
private:
|
||||
class Private;
|
||||
|
@ -89,8 +89,7 @@ QRectF CheckBox::boundingRect() const
|
||||
|
||||
void CheckBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
|
||||
|
||||
Q_UNUSED(option)
|
||||
QStyleOptionButton options;
|
||||
options.rect = boundingRect().toRect();
|
||||
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&)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ class KDE_EXPORT CheckBox : public DataVisualization,public QGraphicsItem
|
||||
|
||||
|
||||
public Q_SLOTS:
|
||||
void data(const DataSource::Data&);
|
||||
void data(const DataEngine::Data&);
|
||||
Q_SIGNALS:
|
||||
void clicked();
|
||||
protected:
|
||||
|
@ -53,7 +53,7 @@ void LineEdit::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
QGraphicsTextItem::paint(painter, style, widget);
|
||||
}
|
||||
|
||||
void LineEdit::data(const DataSource::Data&)
|
||||
void LineEdit::data(const DataEngine::Data&)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ class KDE_EXPORT LineEdit : public QGraphicsTextItem,
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
||||
|
||||
public Q_SLOTS:
|
||||
void data(const DataSource::Data&);
|
||||
void data(const DataEngine::Data&);
|
||||
|
||||
};
|
||||
|
||||
|
@ -82,7 +82,7 @@ PushButton::~PushButton()
|
||||
delete d;
|
||||
}
|
||||
|
||||
void PushButton::data(const DataSource::Data &data)
|
||||
void PushButton::data(const DataEngine::Data &data)
|
||||
{
|
||||
Q_UNUSED(data)
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ class KDE_EXPORT PushButton : public DataVisualization,
|
||||
void clicked();
|
||||
|
||||
public Q_SLOTS:
|
||||
virtual void data(const DataSource::Data &);
|
||||
virtual void data(const DataEngine::Data &);
|
||||
|
||||
protected:
|
||||
bool isDown();
|
||||
|
@ -148,7 +148,7 @@ void RadioButton::setText(const QString &text)
|
||||
update();
|
||||
}
|
||||
|
||||
void RadioButton::updated(const Plasma::DataSource::Data &data)
|
||||
void RadioButton::updated(const Plasma::DataEngine::Data &data)
|
||||
{
|
||||
Q_UNUSED(data);
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ public:
|
||||
|
||||
public Q_SLOTS:
|
||||
// DataVisualization overriden virtual slots
|
||||
void updated(const Plasma::DataSource::Data &data);
|
||||
void updated(const Plasma::DataEngine::Data &data);
|
||||
|
||||
Q_SIGNALS:
|
||||
void clicked();
|
||||
|
Loading…
Reference in New Issue
Block a user