add bool isUsed() const and remove checkUsage()
This commit is contained in:
parent
69e9b84371
commit
ecbca8f142
@ -287,7 +287,7 @@ void DataContainer::disconnectVisualization(QObject *visualization)
|
||||
}
|
||||
|
||||
d->relayObjects.erase(objIt);
|
||||
checkUsage();
|
||||
d->checkUsage();
|
||||
}
|
||||
|
||||
void DataContainer::checkForUpdate()
|
||||
@ -328,13 +328,18 @@ void DataContainer::setNeedsUpdate(bool update)
|
||||
d->cached = update;
|
||||
}
|
||||
|
||||
void DataContainer::checkUsage()
|
||||
bool DataContainer::isUsed() const
|
||||
{
|
||||
if (d->relays.count() < 1 &&
|
||||
receivers(SIGNAL(dataUpdated(QString, Plasma::DataEngine::Data))) < 1) {
|
||||
return !d->relays.isEmpty() &&
|
||||
receivers(SIGNAL(dataUpdated(QString, Plasma::DataEngine::Data))) > 0;
|
||||
}
|
||||
|
||||
void DataContainerPrivate::checkUsage()
|
||||
{
|
||||
if (!q->isUsed()) {
|
||||
// DO NOT CALL ANYTHING AFTER THIS LINE AS IT MAY GET DELETED!
|
||||
kDebug() << objectName() << "is unused";
|
||||
emit becameUnused(objectName());
|
||||
//kDebug() << q->objectName() << "is unused";
|
||||
emit q->becameUnused(q->objectName());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,6 +154,11 @@ class PLASMA_EXPORT DataContainer : public QObject
|
||||
*/
|
||||
DataEngine* getDataEngine();
|
||||
|
||||
/**
|
||||
* @return true if one or more visualizations is connected to this DataContainer
|
||||
*/
|
||||
bool isUsed() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
/**
|
||||
* Disconnects an object from this DataContainer.
|
||||
@ -234,17 +239,6 @@ class PLASMA_EXPORT DataContainer : public QObject
|
||||
**/
|
||||
void setNeedsUpdate(bool update = true);
|
||||
|
||||
protected Q_SLOTS:
|
||||
/**
|
||||
* Check if the DataContainer is still in use.
|
||||
*
|
||||
* If not the signal "becameUnused" will be emitted.
|
||||
*
|
||||
* Warning: The DataContainer may be invalid after calling this function, because a listener
|
||||
* to becameUnused() may have deleted it.
|
||||
**/
|
||||
void checkUsage();
|
||||
|
||||
private:
|
||||
friend class SignalRelay;
|
||||
friend class DataContainerPrivate;
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include "service.h"
|
||||
#include "scripting/dataenginescript.h"
|
||||
|
||||
#include "private/datacontainer_p.h"
|
||||
#include "private/dataengineservice_p.h"
|
||||
#include "private/remotedataengine_p.h"
|
||||
#include "private/service_p.h"
|
||||
@ -146,7 +147,7 @@ DataEngine::Data DataEngine::query(const QString &source) const
|
||||
}
|
||||
|
||||
DataEngine::Data data = s->data();
|
||||
s->checkUsage();
|
||||
s->d->checkUsage();
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,16 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the DataContainer is still in use.
|
||||
*
|
||||
* If not the signal "becameUnused" will be emitted.
|
||||
*
|
||||
* Warning: The DataContainer may be invalid after calling this function, because a listener
|
||||
* to becameUnused() may have deleted it.
|
||||
**/
|
||||
void checkUsage();
|
||||
|
||||
SignalRelay *signalRelay(const DataContainer *dc, QObject *visualization,
|
||||
uint pollingInterval, Plasma::IntervalAlignment align,
|
||||
bool immediateUpdate);
|
||||
|
Loading…
Reference in New Issue
Block a user