model()->modelForSource()

This commit is contained in:
Marco Martin 2013-12-30 10:41:14 +01:00
parent dea7942533
commit a7470063a0
4 changed files with 11 additions and 9 deletions

View File

@ -64,7 +64,7 @@ bool SourcesOnRequestEngine::sourceRequestEvent(const QString &source)
// expects. So ALWAYS key the new data by the source string as below:
setData(source, "Update Count", 0);
if (!model(source)) {
if (!modelForSource(source)) {
QStandardItemModel *m = new QStandardItemModel;
m->appendRow(new QStandardItem("Item1, first update"));
m->appendRow(new QStandardItem("Item2, first update"));
@ -95,7 +95,7 @@ bool SourcesOnRequestEngine::updateSourceEvent(const QString &source)
const int updateCount = containerForSource(source)->data().value("Update Count").toInt() + 1;
setData(source, "Update Count", updateCount);
QStandardItemModel *m = qobject_cast<QStandardItemModel *>(model(source));
QStandardItemModel *m = qobject_cast<QStandardItemModel *>(modelForSource(source));
if (m) {
m->clear();
m->appendRow(new QStandardItem(QString("Item1, update %1").arg(updateCount)));

View File

@ -117,6 +117,8 @@ class PLASMA_EXPORT DataContainer : public QObject
* DataContainer itself is deleted, so it will be deleted when there won't be any
* visualization associated to this source.
*
* Normally you should set the model from DataEngine::setModel instead from here.
*
* @param model the model that will be associated with this DataContainer
*/
void setModel(QAbstractItemModel *model);

View File

@ -243,7 +243,7 @@ void DataEngine::setModel(const QString &source, QAbstractItemModel *model)
}
}
QAbstractItemModel *DataEngine::model(const QString &source)
QAbstractItemModel *DataEngine::modelForSource(const QString &source)
{
Plasma::DataContainer *s = containerForSource(source);

View File

@ -177,6 +177,12 @@ Types::NoAlignment) const;
**/
Q_INVOKABLE DataContainer *containerForSource(const QString &source);
/**
* @return The model associated to a source if any. The ownership of the model stays with the DataContainer.
* Returns 0 if there isn't any model associated or if the source doesn't exists.
*/
QAbstractItemModel *modelForSource(const QString &source);
/**
* Returns true if this engine is valid, otherwise returns false
*
@ -323,12 +329,6 @@ Types::NoAlignment) const;
*/
void setModel(const QString &source, QAbstractItemModel *model);
/**
* @return The model associated to a source if any. The ownership of the model stays with the DataContainer.
* Returns 0 if there isn't any model associated or if the source doesn't exists.
*/
QAbstractItemModel *model(const QString &source);
/**
* Adds an already constructed data source. The DataEngine takes
* ownership of the DataContainer object. The objectName of the source