* make DataSource emit the name of the source along with the data; this makes it possible widgets connected to multiple DataSources to have a chance of doing the right thing

* make DataEngine take a QObject in the connect, making DataVisualization somewhere superfluous. unless it ends up doing something useful soon, DataVisualization as a class will be going away.

svn path=/trunk/KDE/kdebase/workspace/plasma/lib/; revision=667167
This commit is contained in:
Aaron J. Seigo 2007-05-22 02:49:54 +00:00
parent ad5351fa3f
commit 879e215a43
13 changed files with 25 additions and 25 deletions

View File

@ -50,6 +50,7 @@ class DataEngine::Private
<< ": could not find DataSource " << sourceName
<< ", creating" << endl;
DataSource* s = new DataSource(engine);
emit engine->newDataSource(sourceName);
s->setName(sourceName);
sources.insert(sourceName, s);
return s;
@ -89,19 +90,14 @@ QStringList DataEngine::dataSources()
return d->sources.keys();
}
void DataEngine::connectSource(const QString& source, DataVisualization* visualization)
void DataEngine::connectSource(const QString& source, QObject* visualization)
{
Q_UNUSED(source)
Q_UNUSED(visualization)
DataSource* s = d->source(source);
// if (!s) {
// kDebug() << "DataEngine " << objectName() << ": could not find DataSource " << source << endl;
// return;
// }
connect(s, SIGNAL(updated(Plasma::DataEngine::Data)),
visualization, SLOT(updated(Plasma::DataEngine::Data)));
connect(s, SIGNAL(updated(QString,Plasma::DataEngine::Data)),
visualization, SLOT(updated(QString,Plasma::DataEngine::Data)));
}
DataEngine::Data DataEngine::query(const QString& source)
@ -146,6 +142,7 @@ void DataEngine::removeDataSource(const QString& source)
{
DataSource::Dict::iterator it = d->sources.find(source);
if (it != d->sources.end()) {
emit dataSourceRemoved(it.key());
d->sources.erase(it);
}
}
@ -155,6 +152,7 @@ void DataEngine::clearAllDataSources()
QMutableHashIterator<QString, Plasma::DataSource*> it(d->sources);
while (it.hasNext()) {
it.next();
emit dataSourceRemoved(it.key());
delete it.value();
it.remove();
}

View File

@ -44,13 +44,18 @@ class PLASMA_EXPORT DataEngine : public QObject
virtual ~DataEngine();
virtual QStringList dataSources();
void connectSource(const QString& source, DataVisualization* visualization);
void connectSource(const QString& source, QObject* visualization);
Data query(const QString& source);
void ref();
void deref();
bool isUsed();
Q_SIGNALS:
void newDataSource(const QString& source);
void dataSourceRemoved(const QString& source);
protected:
virtual void init();
void setData(const QString& source, const QVariant& value);

View File

@ -33,7 +33,6 @@ class DataSource::Private
: dirty(false)
{}
QString name;
DataEngine::Data data;
bool dirty;
};
@ -73,7 +72,7 @@ void DataSource::setData(const QString& key, const QVariant& value)
void DataSource::checkForUpdate()
{
if (d->dirty) {
emit updated(d->data);
emit updated(objectName(), d->data);
d->dirty = false;
}
}

View File

@ -47,7 +47,7 @@ class PLASMA_EXPORT DataSource : public QObject
void checkForUpdate();
Q_SIGNALS:
void updated(const Plasma::DataEngine::Data&);
void updated(const QString& source, const Plasma::DataEngine::Data& data);
private:
class Private;

View File

@ -35,7 +35,7 @@ class PLASMA_EXPORT DataVisualization : public QObject
virtual ~DataVisualization();
public Q_SLOTS:
virtual void updated(const Plasma::DataEngine::Data&) = 0;
virtual void updated(const QString& source, const Plasma::DataEngine::Data&) = 0;
private:
class Private;

View File

@ -112,7 +112,7 @@ void CheckBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
}
void CheckBox::updated(const DataEngine::Data&)
void CheckBox::updated(const QString&, const DataEngine::Data&)
{
}

View File

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

View File

@ -24,8 +24,7 @@ namespace Plasma
{
LineEdit::LineEdit(QGraphicsItem *parent, QGraphicsScene *scene)
: QGraphicsTextItem(parent, scene),
DataVisualization()
: QGraphicsTextItem(parent, scene)
{
setTextInteractionFlags(Qt::TextEditorInteraction);
}
@ -53,7 +52,7 @@ void LineEdit::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QGraphicsTextItem::paint(painter, style, widget);
}
void LineEdit::updated(const DataEngine::Data& data)
void LineEdit::updated(const QString&, const DataEngine::Data& data)
{
DataEngine::DataIterator it(data);

View File

@ -31,8 +31,7 @@ namespace Plasma
/**
* Class that emulates a QLineEdit inside plasma
*/
class KDE_EXPORT LineEdit : public QGraphicsTextItem,
public DataVisualization
class KDE_EXPORT LineEdit : public QGraphicsTextItem
{
public:
explicit LineEdit(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0);
@ -41,7 +40,7 @@ class KDE_EXPORT LineEdit : public QGraphicsTextItem,
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
public Q_SLOTS:
void updated(const DataEngine::Data&);
void updated(const QString&, const DataEngine::Data&);
};
} // namespace Plasma

View File

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

View File

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

View File

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

View File

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