Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/dde-control-center/dccmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const QString ControlCenterGroupName = "com.deepin.dde-grand-search.group.dde-co

DccManager::DccManager(QObject *parent)
: DccApp(parent)
, m_root(new DccObject(this))
, m_root(new DccObject())
, m_activeObject(m_root)
, m_hideObjects(new DccObject(this))
, m_noAddObjects(new DccObject(this))
Expand Down Expand Up @@ -206,7 +206,7 @@ void DccManager::addObject(DccObject *obj)
objs.append(m_noAddObjects->getChildren());
while (!objs.isEmpty()) {
DccObject *o = objs.takeFirst();
if (DccObject *parentObj = findParent(o)) {
if (const DccObject *parentObj = findParent(o)) {
DccObject::Private::FromObject(m_noAddObjects)->removeChild(o);
DccObject::Private::FromObject(parentObj)->addChild(o);
objs = m_noAddObjects->getChildren();
Expand Down Expand Up @@ -535,20 +535,21 @@ QVector<DccObject *> DccManager::findObjects(const QString &url, bool onlyRoot,
return rets;
}

DccObject *DccManager::findParent(const DccObject *obj)
const DccObject *DccManager::findParent(const DccObject *obj)
{
const QString &path = obj->parentName();
DccObject *p = qobject_cast<DccObject *>(obj->parent());
if (p) {
if (isEqual(path, p)) {
return p;
}
p = qobject_cast<DccObject *>(p->parent());
if (p && isEqual(path, p)) {
const DccObject *p = obj;
const QObject *op = obj;
while (op) {
op = op->parent();
p = qobject_cast<const DccObject *>(op);
if (p && !p->name().isEmpty() && isEqual(path, p)) {
return p;
}
}
return findObject(path);
qCDebug(dccLog()) << obj->name() << "find parent:" << path << ".Parent-child position error, traverse all objects to find.";
p = findObject(path);
return p;
}

bool DccManager::eventFilter(QObject *watched, QEvent *event)
Expand Down Expand Up @@ -898,7 +899,7 @@ void DccManager::onObjectDisplayChanged()

bool DccManager::addObjectToParent(DccObject *obj)
{
if (DccObject *parentObj = findParent(obj)) {
if (const DccObject *parentObj = findParent(obj)) {
DccObject::Private::FromObject(parentObj)->addChild(obj);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/dde-control-center/dccmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public Q_SLOTS:
bool isEqual(const QString &url, const DccObject *obj);
DccObject *findObject(const QString &url, bool onlyRoot = false);
QVector<DccObject *> findObjects(const QString &url, bool onlyRoot = false, bool one = false);
DccObject *findParent(const DccObject *obj);
const DccObject *findParent(const DccObject *obj);
bool eventFilter(QObject *watched, QEvent *event) override;

private Q_SLOTS:
Expand Down
2 changes: 2 additions & 0 deletions src/dde-control-center/pluginmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ void PluginManager::createModule(QQmlComponent *component)
Q_EMIT updatePluginStatus(plugin, ModuleErr | ModuleEnd, " component create module object is null:" + component->errorString());
return;
}
object->setParent(m_rootModule);
plugin->module = qobject_cast<DccObject *>(object);
Q_EMIT updatePluginStatus(plugin, ModuleEnd, "create module finished");
m_manager->addObject(plugin->module);
Expand Down Expand Up @@ -500,6 +501,7 @@ void PluginManager::createMain(QQmlComponent *component)
Q_EMIT updatePluginStatus(plugin, MainObjErr | MainObjEnd, " component create main object is null:" + component->errorString());
return;
}
object->setParent(plugin->module ? plugin->module : m_rootModule);
plugin->mainObj = qobject_cast<DccObject *>(object);
Q_EMIT updatePluginStatus(plugin, MainObjEnd, ": create main finished");
} break;
Expand Down
Loading