Convert to use QVariantMap throughout
This makes it possible again to use DataSource.data from QML. Some more optimizations are needed, but it already basically works.
This commit is contained in:
parent
ad08301db4
commit
f9502edb14
@ -136,10 +136,10 @@ void SortFilterModel::setSortOrder(const Qt::SortOrder order)
|
||||
sort(0, order);
|
||||
}
|
||||
|
||||
QVariantHash SortFilterModel::get(int row) const
|
||||
QVariantMap SortFilterModel::get(int row) const
|
||||
{
|
||||
QModelIndex idx = index(row, 0);
|
||||
QVariantHash hash;
|
||||
QVariantMap hash;
|
||||
|
||||
QHash<int, QByteArray>::const_iterator i;
|
||||
for (i = roleNames().constBegin(); i != roleNames().constEnd(); ++i) {
|
||||
@ -199,7 +199,7 @@ void DataModel::dataUpdated(const QString &sourceName, const Plasma::DataEngine:
|
||||
QVariantList list;
|
||||
|
||||
if (!m_dataSource->data().isEmpty()) {
|
||||
QVariantHash::const_iterator i = m_dataSource->data().constBegin();
|
||||
QVariantMap::const_iterator i = m_dataSource->data().constBegin();
|
||||
|
||||
while (i != m_dataSource->data().constEnd()) {
|
||||
if (!m_sourceFilter.isEmpty() && m_sourceFilterRE.isValid() && !m_sourceFilterRE.exactMatch(i.key())) {
|
||||
@ -252,8 +252,8 @@ void DataModel::setDataSource(QObject *object)
|
||||
|
||||
m_dataSource = source;
|
||||
|
||||
const QHash<QString, QVariant> data = source->data();
|
||||
QHash<QString, QVariant>::const_iterator i = data.constBegin();
|
||||
const QMap<QString, QVariant> data = source->data();
|
||||
QMap<QString, QVariant>::const_iterator i = data.constBegin();
|
||||
while (i != data.constEnd()) {
|
||||
dataUpdated(i.key(), i.value().value<Plasma::DataEngine::Data>());
|
||||
++i;
|
||||
@ -343,10 +343,10 @@ void DataModel::setItems(const QString &sourceName, const QVariantList &list)
|
||||
m_items[sourceName] = list.toVector();
|
||||
|
||||
if (!list.isEmpty()) {
|
||||
if (list.first().canConvert<QVariantHash>()) {
|
||||
if (list.first().canConvert<QVariantMap>()) {
|
||||
foreach (const QVariant &item, list) {
|
||||
const QVariantHash &vh = item.value<QVariantHash>();
|
||||
QHashIterator<QString, QVariant> it(vh);
|
||||
const QVariantMap &vh = item.value<QVariantMap>();
|
||||
QMapIterator<QString, QVariant> it(vh);
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
const QString &roleName = it.key();
|
||||
@ -395,7 +395,7 @@ void DataModel::removeSource(const QString &sourceName)
|
||||
if (m_keyRoleFilter.isEmpty()) {
|
||||
//source name in the map, linear scan
|
||||
for (int i = 0; i < m_items.value(QString()).count(); ++i) {
|
||||
if (m_items.value(QString())[i].value<QVariantHash>().value("DataEngineSource") == sourceName) {
|
||||
if (m_items.value(QString())[i].value<QVariantMap>().value("DataEngineSource") == sourceName) {
|
||||
beginResetModel();
|
||||
m_items[QString()].remove(i);
|
||||
endResetModel();
|
||||
@ -436,11 +436,11 @@ QVariant DataModel::data(const QModelIndex &index, int role) const
|
||||
|
||||
//is it the reserved role: DataEngineSource ?
|
||||
//also, if each source is an item DataEngineSource is a role between all the others, otherwise we know it from the role variable
|
||||
//finally, sub items are some times QVariantHash some times QVariantMaps
|
||||
//finally, sub items are some times QVariantMap some times QVariantMaps
|
||||
if (!m_keyRoleFilter.isEmpty() && m_roleNames.value(role) == "DataEngineSource") {
|
||||
return source;
|
||||
} else if (m_items.value(source).value(actualRow).canConvert<QVariantHash>()) {
|
||||
return m_items.value(source).value(actualRow).value<QVariantHash>().value(m_roleNames.value(role));
|
||||
} else if (m_items.value(source).value(actualRow).canConvert<QVariantMap>()) {
|
||||
return m_items.value(source).value(actualRow).value<QVariantMap>().value(m_roleNames.value(role));
|
||||
} else {
|
||||
return m_items.value(source).value(actualRow).value<QVariantMap>().value(m_roleNames.value(role));
|
||||
}
|
||||
@ -491,10 +491,10 @@ int DataModel::columnCount(const QModelIndex &parent) const
|
||||
return 1;
|
||||
}
|
||||
|
||||
QVariantHash DataModel::get(int row) const
|
||||
QVariantMap DataModel::get(int row) const
|
||||
{
|
||||
QModelIndex idx = index(row, 0);
|
||||
QVariantHash hash;
|
||||
QVariantMap hash;
|
||||
|
||||
QHash<int, QByteArray>::const_iterator i;
|
||||
for (i = roleNames().constBegin(); i != roleNames().constEnd(); ++i) {
|
||||
|
@ -96,7 +96,7 @@ public:
|
||||
*
|
||||
* @arg int i the row we want
|
||||
*/
|
||||
Q_INVOKABLE QVariantHash get(int i) const;
|
||||
Q_INVOKABLE QVariantMap get(int i) const;
|
||||
|
||||
Q_INVOKABLE int mapRowToSource(int i) const;
|
||||
|
||||
@ -184,7 +184,7 @@ public:
|
||||
*
|
||||
* @arg int i the row we want
|
||||
*/
|
||||
Q_INVOKABLE QVariantHash get(int i) const;
|
||||
Q_INVOKABLE QVariantMap get(int i) const;
|
||||
|
||||
protected:
|
||||
void setItems(const QString &sourceName, const QVariantList &list);
|
||||
|
@ -49,7 +49,7 @@ public:
|
||||
};
|
||||
Q_DECLARE_FLAGS(Changes, Change)
|
||||
|
||||
typedef QHash<QString, QVariant> Data;
|
||||
typedef QMap<QString, QVariant> Data;
|
||||
|
||||
DataSource(QObject* parent=0);
|
||||
|
||||
@ -89,13 +89,13 @@ public:
|
||||
|
||||
/**
|
||||
* All the data fetched by this dataengine.
|
||||
* This is an hash of hashes. At the first level, there are the source names, at the secons, they keys set by the DataEngine
|
||||
* This is a map of maps. At the first level, there are the source names, at the secons, they keys set by the DataEngine
|
||||
*/
|
||||
Q_PROPERTY(QVariantHash data READ data NOTIFY dataChanged);
|
||||
QVariantHash data() const {return m_data;}
|
||||
Q_PROPERTY(QVariantMap data READ data NOTIFY dataChanged);
|
||||
QVariantMap data() const {return m_data;}
|
||||
|
||||
Q_PROPERTY(QVariantMap tdata READ tdata NOTIFY dataChanged);
|
||||
QVariantMap tdata();
|
||||
// Q_PROPERTY(QVariantMap tdata READ tdata NOTIFY dataChanged);
|
||||
// QVariantMap tdata();
|
||||
|
||||
/**
|
||||
* @returns a Plasma::Service given a source name
|
||||
@ -134,7 +134,7 @@ private:
|
||||
QString m_id;
|
||||
int m_interval;
|
||||
QString m_engine;
|
||||
QVariantHash m_data;
|
||||
QVariantMap m_data;
|
||||
Plasma::DataEngine* m_dataEngine;
|
||||
Plasma::DataEngineConsumer* m_dataEngineConsumer;
|
||||
QStringList m_connectedSources;
|
||||
|
Loading…
Reference in New Issue
Block a user