[PlasmaCore DataModel] Don't reset model when a source is removed
REVIEW: 126687
This commit is contained in:
parent
85a5d821fb
commit
bbf295cdfa
@ -24,8 +24,6 @@
|
|||||||
#include <QQmlEngine>
|
#include <QQmlEngine>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -437,25 +435,39 @@ void DataModel::setItems(const QString &sourceName, const QVariantList &list)
|
|||||||
|
|
||||||
void DataModel::removeSource(const QString &sourceName)
|
void DataModel::removeSource(const QString &sourceName)
|
||||||
{
|
{
|
||||||
//FIXME: this could be way more efficient by not resetting the whole model
|
|
||||||
//FIXME: find a way to remove only the proper things also in the case where sources are items
|
//FIXME: find a way to remove only the proper things also in the case where sources are items
|
||||||
|
|
||||||
if (m_keyRoleFilter.isEmpty()) {
|
if (m_keyRoleFilter.isEmpty()) {
|
||||||
//source name in the map, linear scan
|
//source name in the map, linear scan
|
||||||
for (int i = 0; i < m_items.value(QString()).count(); ++i) {
|
for (int i = 0; i < m_items.value(QString()).count(); ++i) {
|
||||||
if (m_items.value(QString())[i].value<QVariantMap>().value("DataEngineSource") == sourceName) {
|
if (m_items.value(QString())[i].value<QVariantMap>().value("DataEngineSource") == sourceName) {
|
||||||
beginResetModel();
|
beginRemoveRows(QModelIndex(), i, i);
|
||||||
m_items[QString()].remove(i);
|
m_items[QString()].remove(i);
|
||||||
endResetModel();
|
endRemoveRows();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//source name as key of the map
|
|
||||||
if (m_items.contains(sourceName)) {
|
if (m_items.contains(sourceName)) {
|
||||||
beginResetModel();
|
//At what row number the first item associated to this source starts
|
||||||
|
int sourceIndex = 0;
|
||||||
|
for (auto i = m_items.constBegin(); i != m_items.constEnd(); ++i) {
|
||||||
|
if (i.key() == sourceName) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
sourceIndex += i.value().count();
|
||||||
|
}
|
||||||
|
|
||||||
|
//source name as key of the map
|
||||||
|
|
||||||
|
int count = m_items.value(sourceName).count();
|
||||||
|
if (count > 0) {
|
||||||
|
beginRemoveRows(QModelIndex(), sourceIndex, sourceIndex + count - 1);
|
||||||
|
}
|
||||||
m_items.remove(sourceName);
|
m_items.remove(sourceName);
|
||||||
endResetModel();
|
if (count > 0) {
|
||||||
|
endRemoveRows();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user