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
35 changes: 28 additions & 7 deletions src/dde-control-center/plugin/dccobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
, m_pageType(Menu)
, m_weight(-1)
, m_flags(0)
, m_componentComplete(false)
, q_ptr(obj)
, m_parent(nullptr)
, m_currentObject(nullptr)
Expand Down Expand Up @@ -331,17 +332,25 @@
{
if (p_ptr->m_icon != icon) {
p_ptr->m_icon = icon;
if (!icon.isEmpty()) {
QQmlContext *context = qmlContext(this);
p_ptr->m_iconSource = context ? context->resolvedUrl(icon) : icon;
} else {
p_ptr->m_iconSource.clear();
}
Q_EMIT iconChanged(p_ptr->m_icon);
Q_EMIT iconSourceChanged(p_ptr->m_iconSource);
// 只在组件完成后才解析 URL
if (p_ptr->m_componentComplete) {
updateIconSource();
}
}
}

void DccObject::updateIconSource()
{
if (!p_ptr->m_icon.isEmpty()) {
QQmlContext *context = qmlContext(this);
p_ptr->m_iconSource = context ? context->resolvedUrl(p_ptr->m_icon) : p_ptr->m_icon;
} else {
p_ptr->m_iconSource.clear();
}
Q_EMIT iconSourceChanged(p_ptr->m_iconSource);
}

QUrl DccObject::iconSource() const
{
return p_ptr->m_iconSource;
Expand Down Expand Up @@ -488,4 +497,16 @@
return p_ptr->getChildren();
}

void DccObject::classBegin()

Check warning on line 500 in src/dde-control-center/plugin/dccobject.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'classBegin' is never used.
{
}

void DccObject::componentComplete()

Check warning on line 504 in src/dde-control-center/plugin/dccobject.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'componentComplete' is never used.
{
p_ptr->m_componentComplete = true;
if (!p_ptr->m_icon.isEmpty()) {
updateIconSource();
}
}

} // namespace dccV25
13 changes: 12 additions & 1 deletion src/dde-control-center/plugin/dccobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
#ifndef DCCOBJECT_H
#define DCCOBJECT_H

#include <QObject>

Check warning on line 7 in src/dde-control-center/plugin/dccobject.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QObject> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QQmlComponent>

Check warning on line 8 in src/dde-control-center/plugin/dccobject.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QQmlComponent> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QQmlListProperty>

Check warning on line 9 in src/dde-control-center/plugin/dccobject.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QQmlListProperty> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QQmlParserStatus>

Check warning on line 10 in src/dde-control-center/plugin/dccobject.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QQmlParserStatus> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QQuickItem>

Check warning on line 11 in src/dde-control-center/plugin/dccobject.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QQuickItem> not found. Please note: Cppcheck does not need standard library headers to get proper results.

namespace dccV25 {
class DccObject : public QObject
class DccModel;
class DccObject : public QObject, public QQmlParserStatus
{
Q_OBJECT
Q_INTERFACES(QQmlParserStatus)
QML_ELEMENT
public:
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Expand Down Expand Up @@ -118,6 +121,11 @@
QQmlListProperty<QObject> data();
const QVector<DccObject *> &getChildren() const;

// QQmlParserStatus interface
void classBegin() override;
void componentComplete() override;


class Private;

Q_SIGNALS:
Expand Down Expand Up @@ -162,6 +170,9 @@

protected:
DccObject::Private *p_ptr;

private:
void updateIconSource();
};
} // namespace dccV25
#endif // DCCOBJECT_H
1 change: 1 addition & 0 deletions src/dde-control-center/plugin/dccobject_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class DccObject::Private
quint8 m_pageType;
quint16 m_weight;
quint32 m_flags;
bool m_componentComplete;

DccObject *q_ptr; // q指针
DccObject *m_parent; // 父项
Expand Down
Loading