qdesigner_propertysheet.cpp
来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 933 行 · 第 1/3 页
CPP
933 行
const int idx = m_addIndex.value(propName); // have to be invisible, this was checked in canAddDynamicProperty() method setVisible(idx, true); m_addProperties.insert(idx, value); setChanged(idx, false); const int index = m_meta->indexOfProperty(propName.toUtf8()); m_info[index].defaultValue = value; return idx; } const int index = count(); m_addIndex.insert(propName, index); m_addProperties.insert(index, value); setVisible(index, true); setChanged(index, false); m_info[index].defaultValue = value; setPropertyGroup(index, tr("Dynamic Properties")); return index;}bool QDesignerPropertySheet::removeDynamicProperty(int index){ if (!m_addIndex.contains(propertyName(index))) return false; setVisible(index, false); return true;}bool QDesignerPropertySheet::isDynamic(int index) const{ if (!m_addProperties.contains(index)) return false; switch (propertyType(index)) { case PropertyBuddy: if (m_objectType == ObjectLabel) return false; break; case PropertyLayoutLeftMargin: case PropertyLayoutTopMargin: case PropertyLayoutRightMargin: case PropertyLayoutBottomMargin: case PropertyLayoutSpacing: case PropertyLayoutHorizontalSpacing: case PropertyLayoutVerticalSpacing: if (m_object->isWidgetType() && m_canHaveLayoutAttributes) return false; default: break; } return true;}bool QDesignerPropertySheet::isDynamicProperty(int index) const{ if (m_info.value(index).defaultDynamic) return false; return isDynamic(index);}void QDesignerPropertySheet::createFakeProperty(const QString &propertyName, const QVariant &value){ // fake properties const int index = m_meta->indexOfProperty(propertyName.toUtf8()); if (index != -1) { if (!m_meta->property(index).isDesignable()) return; setVisible(index, false); const QVariant v = value.isValid() ? value : metaProperty(index); m_fakeProperties.insert(index, v); } else if (value.isValid()) { // additional properties const int index = count(); m_addIndex.insert(propertyName, index); m_addProperties.insert(index, value); ensureInfo(index).propertyType = propertyTypeFromName(propertyName); }}bool QDesignerPropertySheet::isAdditionalProperty(int index) const{ return m_addProperties.contains(index);}bool QDesignerPropertySheet::isFakeProperty(int index) const{ // additional properties must be fake return (m_fakeProperties.contains(index) || isAdditionalProperty(index));}int QDesignerPropertySheet::count() const{ return m_meta->propertyCount() + m_addProperties.count();}int QDesignerPropertySheet::indexOf(const QString &name) const{ int index = m_meta->indexOfProperty(name.toUtf8()); if (index == -1) index = m_addIndex.value(name, -1); return index;}QDesignerPropertySheet::PropertyType QDesignerPropertySheet::propertyType(int index) const{ const InfoHash::const_iterator it = m_info.constFind(index); if (it == m_info.constEnd()) return PropertyNone; return it.value().propertyType;}QString QDesignerPropertySheet::propertyName(int index) const{ if (isAdditionalProperty(index)) return m_addIndex.key(index); return QString::fromUtf8(m_meta->property(index).name());}QString QDesignerPropertySheet::propertyGroup(int index) const{ const QString g = m_info.value(index).group; if (!g.isEmpty()) return g; if (propertyType(index) == PropertyAccessibility) return QString::fromUtf8("Accessibility"); if (isAdditionalProperty(index)) return QString::fromUtf8(m_meta->className()); return g;}void QDesignerPropertySheet::setPropertyGroup(int index, const QString &group){ ensureInfo(index).group = group;}QVariant QDesignerPropertySheet::property(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->property(layoutPropertySheet->indexOf(newPropName)); } } return m_addProperties.value(index); } if (isFakeProperty(index)) { return m_fakeProperties.value(index); } return metaProperty(index);}QVariant QDesignerPropertySheet::metaProperty(int index) const{ Q_ASSERT(!isFakeProperty(index)); const QMetaProperty p = m_meta->property(index); QVariant v = p.read(m_object); static const QString doubleColon = QLatin1String("::"); if (p.isFlagType()) { qdesigner_internal::FlagType e; e.value = v; const QMetaEnum me = p.enumerator(); QString scope = QString::fromUtf8(me.scope()); if (!scope.isEmpty()) scope += doubleColon; for (int i=0; i<me.keyCount(); ++i) { const QString key = scope + QLatin1String(me.key(i)); e.items.insert(key, me.keyToValue(key.toUtf8().constData())); } qVariantSetValue(v, e); } else if (p.isEnumType()) { qdesigner_internal::EnumType e; e.value = v; const QMetaEnum me = p.enumerator(); QString scope = QString::fromUtf8(me.scope()); if (!scope.isEmpty()) scope += doubleColon; for (int i=0; i<me.keyCount(); ++i) { const QString key = scope + QLatin1String(me.key(i)); e.items.insert(key, me.keyToValue(key.toUtf8().constData())); e.names.append(key); } qVariantSetValue(v, e); } return v;}QVariant QDesignerPropertySheet::resolvePropertyValue(const QVariant &value) const{ if (qVariantCanConvert<qdesigner_internal::FlagType>(value)) return qvariant_cast<qdesigner_internal::FlagType>(value).value; if (qVariantCanConvert<qdesigner_internal::EnumType>(value)) return qvariant_cast<qdesigner_internal::EnumType>(value).value; return value;}void QDesignerPropertySheet::setFakeProperty(int index, const QVariant &value){ Q_ASSERT(isFakeProperty(index)); QVariant &v = m_fakeProperties[index]; if (qVariantCanConvert<qdesigner_internal::FlagType>(value) || qVariantCanConvert<qdesigner_internal::EnumType>(value)) { v = value; } else if (qVariantCanConvert<qdesigner_internal::FlagType>(v)) { qdesigner_internal::FlagType f = qvariant_cast<qdesigner_internal::FlagType>(v); f.value = value; qVariantSetValue(v, f); Q_ASSERT(f.value.type() == QVariant::Int); } else if (qVariantCanConvert<qdesigner_internal::EnumType>(v)) { qdesigner_internal::EnumType e = qvariant_cast<qdesigner_internal::EnumType>(v); e.value = value; qVariantSetValue(v, e); Q_ASSERT(e.value.type() == QVariant::Int); } else { v = value; }}// Buddy needs to be byte array, else uic won't workstatic QVariant toByteArray(const QVariant &value) { if (value.type() == QVariant::ByteArray) return value; const QByteArray ba = value.toString().toUtf8(); return QVariant(ba);}void QDesignerPropertySheet::setProperty(int index, const QVariant &value){ if (isAdditionalProperty(index)) { if (m_objectType == ObjectLabel && propertyType(index) == PropertyBuddy) { QFormBuilderExtra::applyBuddy(value.toString(), QFormBuilderExtra::BuddyApplyVisibleOnly, qobject_cast<QLabel *>(m_object)); m_addProperties[index] = toByteArray(value); return; } if (isFakeLayoutProperty(index)) { QDesignerPropertySheetExtension *layoutPropertySheet; if (layout(&layoutPropertySheet) && layoutPropertySheet) { const QString newPropName = transformLayoutPropertyName(index); if (!newPropName.isEmpty()) layoutPropertySheet->setProperty(layoutPropertySheet->indexOf(newPropName), value); } } if (isDynamicProperty(index)) { m_object->setProperty(propertyName(index).toUtf8(), value); if (m_object->isWidgetType()) { QWidget *w = qobject_cast<QWidget *>(m_object); w->setStyleSheet(w->styleSheet()); } } m_addProperties[index] = value; } else if (isFakeProperty(index)) { setFakeProperty(index, value); } else { const QMetaProperty p = m_meta->property(index); p.write(m_object, resolvePropertyValue(value)); if (qobject_cast<QGroupBox *>(m_object) && propertyType(index) == PropertyCheckable) { const int idx = indexOf(QLatin1String("focusPolicy")); if (!isChanged(idx)) { qdesigner_internal::EnumType e = qVariantValue<qdesigner_internal::EnumType>(property(idx)); if (value.toBool()) { const QMetaProperty p = m_meta->property(idx); p.write(m_object, Qt::NoFocus); e.value = Qt::StrongFocus; QVariant v; qVariantSetValue(v, e); setFakeProperty(idx, v); } else { e.value = Qt::NoFocus; QVariant v; qVariantSetValue(v, e); setFakeProperty(idx, v); } } } }}bool QDesignerPropertySheet::hasReset(int index) const{ if (isAdditionalProperty(index)) return m_info.value(index).reset; return true;}bool QDesignerPropertySheet::reset(int index){ if (isDynamic(index)) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?