Commit 0fcecd6c authored by Arjen Hiemstra's avatar Arjen Hiemstra
Browse files

Add reset functionality to FaceLoader

It will discard the existing face to make sure that we don't carry over
any changes that we want to discard.
parent 8c2387fd
......@@ -31,8 +31,7 @@ void FaceLoader::setDataObject(PageDataObject * newDataObject)
}
if (m_faceController) {
m_faceController->deleteLater();
m_faceController = nullptr;
m_faceController->disconnect(m_dataObject);
}
m_dataObject = newDataObject;
......@@ -50,11 +49,13 @@ void FaceLoader::setDataObject(PageDataObject * newDataObject)
if (s_faceCache.contains(faceConfig)) {
m_faceController = s_faceCache.value(faceConfig);
return;
} else {
auto configGroup = m_dataObject->config()->group(faceConfig);
m_faceController = new SensorFaceController(configGroup, qmlEngine(this));
m_faceController->setShouldSync(false);
s_faceCache.insert(faceConfig, m_faceController);
}
auto configGroup = m_dataObject->config()->group(faceConfig);
m_faceController = new SensorFaceController(configGroup, qmlEngine(this));
connect(m_faceController, &SensorFaceController::faceIdChanged, m_dataObject, &PageDataObject::markDirty);
connect(m_faceController, &SensorFaceController::titleChanged, m_dataObject, &PageDataObject::markDirty);
connect(m_faceController, &SensorFaceController::totalSensorsChanged, m_dataObject, &PageDataObject::markDirty);
......@@ -62,11 +63,14 @@ void FaceLoader::setDataObject(PageDataObject * newDataObject)
connect(m_faceController, &SensorFaceController::lowPrioritySensorIdsChanged, m_dataObject, &PageDataObject::markDirty);
connect(m_faceController, &SensorFaceController::sensorColorsChanged, m_dataObject, &PageDataObject::markDirty);
s_faceCache.insert(faceConfig, m_faceController);
Q_EMIT controllerChanged();
}
if (m_oldController) {
delete m_oldController;
m_oldController = nullptr;
}
Q_EMIT dataObjectChanged();
}
......@@ -74,3 +78,18 @@ SensorFaceController * FaceLoader::controller() const
{
return m_faceController;
}
void FaceLoader::reset()
{
auto faceConfig = m_dataObject->value(QStringLiteral("face")).toString();
if (s_faceCache.contains(faceConfig)) {
s_faceCache.remove(faceConfig);
}
// Deleting the controller here, even when using deleteLater will trigger a
// crash in the QML runtime because it still has references to the object
// that do not get cleared. So instead, only delete it once we have a new
// face controller.
m_oldController = m_faceController;
m_faceController = nullptr;
}
......@@ -29,9 +29,12 @@ public:
KSysGuard::SensorFaceController *controller() const;
Q_SIGNAL void controllerChanged();
void reset();
private:
PageDataObject *m_dataObject = nullptr;
KSysGuard::SensorFaceController *m_faceController = nullptr;
KSysGuard::SensorFaceController *m_oldController = nullptr;
static QHash<QString, KSysGuard::SensorFaceController *> s_faceCache;
};
......@@ -271,6 +271,10 @@ void PageDataObject::reset()
{
markClean();
if (m_faceLoader) {
m_faceLoader->reset();
}
for (auto child : qAsConst(m_children)) {
child->reset();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment