qdesigner_propertycommand.cpp

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

CPP
1,210
字号
    m_newValue = newValue;    if(debugPropertyCommands)        qDebug() << "SetPropertyCommand::init()" << propertyHelperList().size() << '/' << list.size();    setDescription();    m_subPropertyMask = subPropertyMask(newValue, referenceObject);    return true;}unsigned SetPropertyCommand::subPropertyMask(const QVariant &newValue, QObject *referenceObject){    // figure out the mask of changed sub properties when comparing newValue to the current value of the reference object.    if (!referenceObject)        return SubPropertyAll;    QDesignerPropertySheetExtension* sheet = propertySheet(referenceObject);    Q_ASSERT(sheet);    const int index = sheet->indexOf(propertyName());    if (index == -1 || !sheet->isVisible(index))        return SubPropertyAll;    return compareSubProperties(sheet->property(index), newValue, specialProperty());}void SetPropertyCommand::setDescription(){    if (propertyHelperList().size() == 1) {        setText(QApplication::translate("Command", "changed '%1' of '%2'").arg(propertyName()).arg(propertyHelperList()[0].object()->objectName()));    } else {        int count = propertyHelperList().size();        setText(QApplication::translate("Command", "changed '%1' of %2 objects", "", QCoreApplication::UnicodeUTF8, count).arg(propertyName()).arg(count));    }}void SetPropertyCommand::redo(){    update(setValue(m_newValue, true, m_subPropertyMask));    QDesignerPropertyEditor *designerPropertyEditor = qobject_cast<QDesignerPropertyEditor *>(core()->propertyEditor());    if (designerPropertyEditor)        designerPropertyEditor->updatePropertySheet();}int SetPropertyCommand::id() const{    return 1976;}bool SetPropertyCommand::mergeWith(const QUndoCommand *other){    if (id() != other->id() || !formWindow()->isDirty())        return false;    // Merging: When  for example when the user types ahead in an inplace-editor,    // it makes sense to merge all the generated commands containing the one-character changes.    // In the case of subproperties, if the user changes the font size from 10 to 30 via 20    // and then changes to bold, it makes sense to merge the font size commands only.    // This is why the m_subPropertyMask is checked.    const SetPropertyCommand *cmd = static_cast<const SetPropertyCommand*>(other);    if (!propertyDescription().equals(cmd->propertyDescription()) ||        m_subPropertyMask  != cmd->m_subPropertyMask ||        !canMergeLists(cmd->propertyHelperList()))        return false;    m_newValue = cmd->newValue();    m_subPropertyMask |= cmd->m_subPropertyMask;    if(debugPropertyCommands)        qDebug() << "SetPropertyCommand::mergeWith() succeeded " << propertyName();    return true;}// ---- ResetPropertyCommand ----ResetPropertyCommand::ResetPropertyCommand(QDesignerFormWindowInterface *formWindow)    : PropertyListCommand(formWindow){}bool ResetPropertyCommand::init(QObject *object, const QString &apropertyName){    Q_ASSERT(object);    propertyHelperList().clear();    if (!add(object, apropertyName))        return false;    setDescription();    return true;}bool ResetPropertyCommand::init(const ObjectList &list, const QString &apropertyName, QObject *referenceObject){    if (!initList(list, apropertyName, referenceObject))        return false;    if(debugPropertyCommands)        qDebug() << "ResetPropertyCommand::init()" << propertyHelperList().size() << '/' << list.size();    setDescription();    return true;}void ResetPropertyCommand::setDescription(){    if (propertyHelperList().size() == 1) {        setText(QApplication::translate("Command", "reset '%1' of '%2'").arg(propertyName()).arg(propertyHelperList()[0].object()->objectName()));    } else {        int count = propertyHelperList().size();        setText(QApplication::translate("Command", "reset '%1' of %2 objects", "", QCoreApplication::UnicodeUTF8, count).arg(propertyName()).arg(count));    }}void ResetPropertyCommand::redo(){    update(restoreDefaultValue());    QDesignerPropertyEditor *designerPropertyEditor = qobject_cast<QDesignerPropertyEditor *>(core()->propertyEditor());    if (designerPropertyEditor)        designerPropertyEditor->updatePropertySheet();}AddDynamicPropertyCommand::AddDynamicPropertyCommand(QDesignerFormWindowInterface *formWindow)    : QDesignerFormWindowCommand(QString(), formWindow){}bool AddDynamicPropertyCommand::init(const QList<QObject *> &selection, QObject *current,            const QString &propertyName, const QVariant &value){    Q_ASSERT(current);    m_propertyName = propertyName;    QDesignerFormEditorInterface *core = formWindow()->core();    QDesignerDynamicPropertySheetExtension *dynamicSheet = qt_extension<QDesignerDynamicPropertySheetExtension*>(core->extensionManager(), current);    Q_ASSERT(dynamicSheet);    m_selection.clear();    if (!value.isValid())        return false;    if (!dynamicSheet->canAddDynamicProperty(m_propertyName))        return false;    m_selection.append(current);    m_value = value;    QListIterator<QObject *> it(selection);    while (it.hasNext()) {        QObject *obj = it.next();        if (m_selection.contains(obj))            continue;        dynamicSheet = qt_extension<QDesignerDynamicPropertySheetExtension*>(core->extensionManager(), obj);        Q_ASSERT(dynamicSheet);        if (dynamicSheet->canAddDynamicProperty(m_propertyName))            m_selection.append(obj);    }    setDescription();    return true;}void AddDynamicPropertyCommand::redo(){    QDesignerFormEditorInterface *core = formWindow()->core();    QListIterator<QObject *> it(m_selection);    while (it.hasNext()) {        QObject *obj = it.next();        QDesignerDynamicPropertySheetExtension *dynamicSheet = qt_extension<QDesignerDynamicPropertySheetExtension*>(core->extensionManager(), obj);        dynamicSheet->addDynamicProperty(m_propertyName, m_value);        if (QDesignerPropertyEditorInterface *propertyEditor = formWindow()->core()->propertyEditor()) {            if (propertyEditor->object() == obj)                propertyEditor->setObject(obj);        }    }}void AddDynamicPropertyCommand::undo(){    QDesignerFormEditorInterface *core = formWindow()->core();    QListIterator<QObject *> it(m_selection);    while (it.hasNext()) {        QObject *obj = it.next();        QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), obj);        QDesignerDynamicPropertySheetExtension *dynamicSheet = qt_extension<QDesignerDynamicPropertySheetExtension*>(core->extensionManager(), obj);        dynamicSheet->removeDynamicProperty(sheet->indexOf(m_propertyName));        if (QDesignerPropertyEditorInterface *propertyEditor = formWindow()->core()->propertyEditor()) {            if (propertyEditor->object() == obj)                propertyEditor->setObject(obj);        }    }}void AddDynamicPropertyCommand::setDescription(){    if (m_selection.size() == 1) {        setText(QApplication::translate("Command", "add dynamic property '%1' to '%2'").arg(m_propertyName).arg(m_selection.first()->objectName()));    } else {        int count = m_selection.size();        setText(QApplication::translate("Command", "add dynamic property '%1' to %2 objects", "", QCoreApplication::UnicodeUTF8, count).arg(m_propertyName).arg(count));    }}RemoveDynamicPropertyCommand::RemoveDynamicPropertyCommand(QDesignerFormWindowInterface *formWindow)    : QDesignerFormWindowCommand(QString(), formWindow){}bool RemoveDynamicPropertyCommand::init(const QList<QObject *> &selection, QObject *current,            const QString &propertyName){    Q_ASSERT(current);    m_propertyName = propertyName;    QDesignerFormEditorInterface *core = formWindow()->core();    QDesignerPropertySheetExtension *propertySheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), current);    Q_ASSERT(propertySheet);    QDesignerDynamicPropertySheetExtension *dynamicSheet = qt_extension<QDesignerDynamicPropertySheetExtension*>(core->extensionManager(), current);    Q_ASSERT(dynamicSheet);    m_objectToValueAndChanged.clear();    const int index = propertySheet->indexOf(m_propertyName);    if (!dynamicSheet->isDynamicProperty(index))        return false;    m_objectToValueAndChanged[current] = qMakePair(propertySheet->property(index), propertySheet->isChanged(index));    QListIterator<QObject *> it(selection);    while (it.hasNext()) {        QObject *obj = it.next();        if (m_objectToValueAndChanged.contains(obj))            continue;        propertySheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), obj);        dynamicSheet = qt_extension<QDesignerDynamicPropertySheetExtension*>(core->extensionManager(), obj);        const int idx = propertySheet->indexOf(m_propertyName);        if (dynamicSheet->isDynamicProperty(idx))            m_objectToValueAndChanged[obj] = qMakePair(propertySheet->property(idx), propertySheet->isChanged(idx));    }    setDescription();    return true;}void RemoveDynamicPropertyCommand::redo(){    QDesignerFormEditorInterface *core = formWindow()->core();    QMap<QObject *, QPair<QVariant, bool> >::ConstIterator it = m_objectToValueAndChanged.constBegin();    while (it != m_objectToValueAndChanged.constEnd()) {        QObject *obj = it.key();        QDesignerDynamicPropertySheetExtension *dynamicSheet = qt_extension<QDesignerDynamicPropertySheetExtension*>(core->extensionManager(), obj);        QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), obj);        dynamicSheet->removeDynamicProperty(sheet->indexOf(m_propertyName));        if (QDesignerPropertyEditorInterface *propertyEditor = formWindow()->core()->propertyEditor()) {            if (propertyEditor->object() == obj)                propertyEditor->setObject(obj);        }        ++it;    }}void RemoveDynamicPropertyCommand::undo(){    QDesignerFormEditorInterface *core = formWindow()->core();    QMap<QObject *, QPair<QVariant, bool> >::ConstIterator it = m_objectToValueAndChanged.constBegin();    while (it != m_objectToValueAndChanged.constEnd()) {        QObject *obj = it.key();        QDesignerPropertySheetExtension *propertySheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), obj);        QDesignerDynamicPropertySheetExtension *dynamicSheet = qt_extension<QDesignerDynamicPropertySheetExtension*>(core->extensionManager(), obj);        const int index = dynamicSheet->addDynamicProperty(m_propertyName, it.value().first);        propertySheet->setChanged(index, it.value().second);        if (QDesignerPropertyEditorInterface *propertyEditor = formWindow()->core()->propertyEditor()) {            if (propertyEditor->object() == obj)                propertyEditor->setObject(obj);        }        ++it;    }}void RemoveDynamicPropertyCommand::setDescription(){    if (m_objectToValueAndChanged.size() == 1) {        setText(QApplication::translate("Command", "remove dynamic property '%1' from '%2'").arg(m_propertyName).arg(m_objectToValueAndChanged.constBegin().key()->objectName()));    } else {        int count = m_objectToValueAndChanged.size();        setText(QApplication::translate("Command", "remove dynamic property '%1' from %2 objects", "", QCoreApplication::UnicodeUTF8, count).arg(m_propertyName).arg(count));    }}} // namespace qdesigner_internal

⌨️ 快捷键说明

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