forked from quickshell/quickshell
feat: add PersistentProperties
This commit is contained in:
parent
ed62193978
commit
083fff57be
5 changed files with 86 additions and 1 deletions
24
src/cpp/persistentprops.cpp
Normal file
24
src/cpp/persistentprops.cpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
#include "persistentprops.hpp"
|
||||
|
||||
#include <qobject.h>
|
||||
#include <qtmetamacros.h>
|
||||
|
||||
void PersistentProperties::onReload(QObject* oldInstance) {
|
||||
if (qobject_cast<PersistentProperties*>(oldInstance) == nullptr) {
|
||||
emit this->loaded();
|
||||
return;
|
||||
}
|
||||
|
||||
const auto* metaObject = this->metaObject();
|
||||
for (auto i = metaObject->propertyOffset(); i < metaObject->propertyCount(); i++) {
|
||||
const auto prop = metaObject->property(i);
|
||||
auto oldProp = oldInstance->property(prop.name());
|
||||
|
||||
if (oldProp.isValid()) {
|
||||
this->setProperty(prop.name(), oldProp);
|
||||
}
|
||||
}
|
||||
|
||||
emit this->loaded();
|
||||
emit this->reloaded();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue