qdesigner_propertysheet.cpp

来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 933 行 · 第 1/3 页

CPP
933
字号
        const QString propName = propertyName(index);        const QVariant oldValue = m_addProperties.value(index);        const QVariant newValue = m_info.value(index).defaultValue;        if (oldValue == newValue)            return true;        m_object->setProperty(propName.toUtf8(), newValue);        m_addProperties[index] = newValue;        return true;    } else if (!m_info.value(index).defaultValue.isNull()) {        setProperty(index, m_info.value(index).defaultValue);        return true;    }    if (isAdditionalProperty(index)) {        const PropertyType pType = propertyType(index);        if (m_objectType == ObjectLabel && pType == PropertyBuddy) {            setProperty(index, QVariant(QByteArray()));            return true;        }        if (isFakeLayoutProperty(index)) {            int value = -1;            switch (m_objectType) {            case ObjectQ3GroupBox: {                const QWidget *w = qobject_cast<const QWidget *>(m_object);                switch (pType) {                case PropertyLayoutLeftMargin:                    value = w->style()->pixelMetric(QStyle::PM_LayoutLeftMargin);                    break;                case PropertyLayoutTopMargin:                    value = w->style()->pixelMetric(QStyle::PM_LayoutTopMargin);                    break;                case PropertyLayoutRightMargin:                    value = w->style()->pixelMetric(QStyle::PM_LayoutRightMargin);                    break;                case PropertyLayoutBottomMargin:                    value = w->style()->pixelMetric(QStyle::PM_LayoutBottomMargin);                    break;                case PropertyLayoutSpacing:                case PropertyLayoutHorizontalSpacing:                case PropertyLayoutVerticalSpacing:                    value = -1;                    break;                default:                    break;                }            }                break;            case ObjectLayoutWidget:                if (pType == PropertyLayoutLeftMargin ||                        pType == PropertyLayoutTopMargin ||                        pType == PropertyLayoutRightMargin ||                        pType == PropertyLayoutBottomMargin)                    value = 0;                break;            default:                break;            }            setProperty(index, value);            return true;        }        return false;    } else if (isFakeProperty(index)) {        const QMetaProperty p = m_meta->property(index);        const bool result = p.reset(m_object);        m_fakeProperties[index] = p.read(m_object);        return result;    } else if (propertyType(index) == PropertyGeometry && m_object->isWidgetType()) {        if (QWidget *w = qobject_cast<QWidget*>(m_object)) {            QWidget *widget = w;            QDesignerFormWindowInterface *formWindow = QDesignerFormWindowInterface::findFormWindow(widget);            if (qdesigner_internal::Utils::isCentralWidget(formWindow, widget) && formWindow->parentWidget())                widget = formWindow->parentWidget();            if (widget != w && widget->parentWidget()) {                QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);                widget->parentWidget()->adjustSize();            }            QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);            widget->adjustSize();            return true;        }    }    // ### TODO: reset for fake properties.    const QMetaProperty p = m_meta->property(index);    return p.reset(m_object);}bool QDesignerPropertySheet::isChanged(int index) const{    if (isAdditionalProperty(index)) {        if (isFakeLayoutProperty(index)) {            QDesignerPropertySheetExtension *layoutPropertySheet;            if (layout(&layoutPropertySheet) && layoutPropertySheet) {                const QString newPropName = transformLayoutPropertyName(index);                if (!newPropName.isEmpty())                    return layoutPropertySheet->isChanged(layoutPropertySheet->indexOf(newPropName));            }        }    }    return m_info.value(index).changed;}void QDesignerPropertySheet::setChanged(int index, bool changed){    if (isAdditionalProperty(index)) {        if (isFakeLayoutProperty(index)) {            QDesignerPropertySheetExtension *layoutPropertySheet;            if (layout(&layoutPropertySheet) && layoutPropertySheet) {                const QString newPropName = transformLayoutPropertyName(index);                if (!newPropName.isEmpty())                    layoutPropertySheet->setChanged(layoutPropertySheet->indexOf(newPropName), changed);            }        }    }    ensureInfo(index).changed = changed;}bool QDesignerPropertySheet::isFakeLayoutProperty(int index) const{    if (!isAdditionalProperty(index))        return false;    switch (propertyType(index)) {    case PropertySizeConstraint:        return true;    case PropertyLayoutLeftMargin:    case PropertyLayoutTopMargin:    case PropertyLayoutRightMargin:    case PropertyLayoutBottomMargin:    case PropertyLayoutSpacing:    case PropertyLayoutHorizontalSpacing:    case PropertyLayoutVerticalSpacing:        return m_canHaveLayoutAttributes;    default:        break;    }    return false;}bool QDesignerPropertySheet::isVisible(int index) const{    if (isAdditionalProperty(index)) {        if (isFakeLayoutProperty(index) && m_object->isWidgetType()) {            QLayout *currentLayout = layout();            if (!currentLayout)                return false;            switch (propertyType(index)) {            case  PropertyLayoutSpacing:                if (qobject_cast<const QGridLayout *>(currentLayout))                    return false;                break;            case PropertyLayoutHorizontalSpacing:            case PropertyLayoutVerticalSpacing:                if (!qobject_cast<const QGridLayout *>(currentLayout))                    return false;                break;            default:                break;            }            return true;        }        return m_info.value(index).visible;    }    if (isFakeProperty(index))        return true;    const QMetaProperty p = m_meta->property(index);    return (p.isWritable() && p.isDesignable(m_object)) || m_info.value(index).visible;}void QDesignerPropertySheet::setVisible(int index, bool visible){    ensureInfo(index).visible = visible;}bool QDesignerPropertySheet::isAttribute(int index) const{    if (isAdditionalProperty(index))        return m_info.value(index).attribute;    if (isFakeProperty(index))        return false;    return m_info.value(index).attribute;}void QDesignerPropertySheet::setAttribute(int index, bool attribute){    ensureInfo(index).attribute = attribute;}QLayout* QDesignerPropertySheet::layout(QDesignerPropertySheetExtension **layoutPropertySheet) const{    // Return the layout and its property sheet    // only if it is managed by designer and not one created on a custom widget.    if (layoutPropertySheet)        *layoutPropertySheet = 0;    if (!m_object->isWidgetType() || !m_canHaveLayoutAttributes)        return 0;    QWidget *widget = qobject_cast<QWidget*>(m_object);    QLayout *widgetLayout = qdesigner_internal::LayoutInfo::internalLayout(widget);    if (!widgetLayout) {        m_lastLayout = 0;        m_lastLayoutPropertySheet = 0;        return 0;    }    // Smart logic to avoid retrieving the meta DB from the widget every time.    if (widgetLayout != m_lastLayout) {        m_lastLayout = widgetLayout;        m_LastLayoutByDesigner = false;        m_lastLayoutPropertySheet = 0;        // Is this a layout managed by designer or some layout on a custom widget?        if (QDesignerFormEditorInterface *core = formEditorForWidget(widget)) {            if (qdesigner_internal::LayoutInfo::managedLayout(core ,widgetLayout)) {                m_LastLayoutByDesigner = true;                m_lastLayoutPropertySheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), m_lastLayout);            }        }    }    if (!m_LastLayoutByDesigner)        return 0;    if (layoutPropertySheet)        *layoutPropertySheet = m_lastLayoutPropertySheet;    return  m_lastLayout;}QDesignerPropertySheet::Info &QDesignerPropertySheet::ensureInfo(int index){    InfoHash::iterator it = m_info.find(index);    if (it == m_info.end()) {        it = m_info.insert(index, Info());    }    return it.value();}QString QDesignerPropertySheet::transformLayoutPropertyName(int index) const{    switch (propertyType(index)) {    case PropertyLayoutLeftMargin:        return QLatin1String("leftMargin");    case PropertyLayoutTopMargin:        return QLatin1String("topMargin");    case PropertyLayoutRightMargin:        return QLatin1String("rightMargin");    case PropertyLayoutBottomMargin:        return QLatin1String("bottomMargin");    case PropertyLayoutSpacing:        return QLatin1String("spacing");    case PropertyLayoutHorizontalSpacing:        return QLatin1String("horizontalSpacing");    case PropertyLayoutVerticalSpacing:        return QLatin1String("verticalSpacing");    default:        break;    }    return QString();}// ---------- QDesignerPropertySheetFactoryQDesignerPropertySheetFactory::QDesignerPropertySheetFactory(QExtensionManager *parent)    : QExtensionFactory(parent){}QObject *QDesignerPropertySheetFactory::extension(QObject *object, const QString &iid) const{    if (!object)        return 0;    if (iid != Q_TYPEID(QDesignerPropertySheetExtension) && iid != Q_TYPEID(QDesignerDynamicPropertySheetExtension))        return 0;    if (!m_extensions.contains(object)) {        if (QObject *ext = new QDesignerPropertySheet(object, const_cast<QDesignerPropertySheetFactory*>(this))) {            connect(ext, SIGNAL(destroyed(QObject*)), this, SLOT(objectDestroyed(QObject*)));            m_extensions.insert(object, ext);        }    }    if (!m_extended.contains(object)) {        connect(object, SIGNAL(destroyed(QObject*)), this, SLOT(objectDestroyed(QObject*)));        m_extended.insert(object, true);    }    return m_extensions.value(object);}void QDesignerPropertySheetFactory::objectDestroyed(QObject *object){    QMutableMapIterator<QObject*, QObject*> it(m_extensions);    while (it.hasNext()) {        it.next();        QObject *o = it.key();        if (o == object || object == it.value()) {            it.remove();        }    }    m_extended.remove(object);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?