⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qdesigner_command.cpp

📁 QT 开发环境里面一个很重要的文件
💻 CPP
📖 第 1 页 / 共 5 页
字号:
bool SetFormPropertyCommand::mergeWith(const QUndoCommand *other){    if (id() != other->id())        return false;    if (const SetFormPropertyCommand *cmd = static_cast<const SetFormPropertyCommand*>(other)) {        if (cmd->propertyName() == propertyName() && cmd->formWindow() == formWindow()) {            m_newValue = cmd->newValue();            return true;        }    }    return false;}void SetFormPropertyCommand::updateFormWindowGeometry(const QVariant &value){    if (QWidget *container = containerWindow(formWindow())) {        QRect r = container->geometry();        if (container->parentWidget() && container->parentWidget()->metaObject()->className() == QLatin1String("QWorkspaceChild")) {            QRect windowRect = container->parentWidget()->rect();            QSize diff = windowRect.size() - r.size();            windowRect.setSize(value.toRect().size() + diff);            container->parentWidget()->setGeometry(windowRect);        } else {            r.setSize(value.toRect().size());            container->setGeometry(r);        }    }}QWidget *SetFormPropertyCommand::containerWindow(QWidget *widget){    while (widget) {        if (widget->isWindow())            break;        if (widget->parentWidget() && !qstrcmp(widget->parentWidget()->metaObject()->className(), "QWorkspaceChild"))            break;        widget = widget->parentWidget();    }    return widget;}// ---- ResetPropertyCommand ----ResetPropertyCommand::ResetPropertyCommand(QDesignerFormWindowInterface *formWindow)    : QDesignerFormWindowCommand(QString(), formWindow),      m_index(-1),      m_propertySheet(0),      m_changed(false){}QObject *ResetPropertyCommand::object() const{    return m_object;}QObject *ResetPropertyCommand::parentObject() const{    return m_parentObject;}void ResetPropertyCommand::init(QObject *object, const QString &propertyName){    Q_ASSERT(object);    m_object = object;    m_parentObject = object->parent();    m_propertyName = propertyName;    QDesignerFormEditorInterface *core = formWindow()->core();    m_propertySheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), object);    Q_ASSERT(m_propertySheet);    m_index = m_propertySheet->indexOf(m_propertyName);    Q_ASSERT(m_index != -1);    m_changed = m_propertySheet->isChanged(m_index);    m_oldValue = m_propertySheet->property(m_index);    setText(QApplication::translate("Command", "reset '%1' of '%2'").arg(m_propertyName).arg(m_object->objectName()));}void ResetPropertyCommand::redo(){    Q_ASSERT(m_propertySheet);    Q_ASSERT(m_index != -1);    QObject *obj = m_object;    QDesignerPromotedWidget *promoted = qobject_cast<QDesignerPromotedWidget*>(obj);    if (promoted)        obj = promoted->child();    QVariant new_value;    if (m_propertySheet->reset(m_index)) {        new_value = m_propertySheet->property(m_index);    } else {        int item_idx =  formWindow()->core()->widgetDataBase()->indexOfObject(obj);        if (item_idx == -1) {            new_value = m_oldValue; // We simply don't know the value in this case        } else {            QDesignerWidgetDataBaseItemInterface *item                = formWindow()->core()->widgetDataBase()->item(item_idx);            QList<QVariant> default_prop_values = item->defaultPropertyValues();            if (m_index < default_prop_values.size())                new_value = default_prop_values.at(m_index);            else                new_value = m_oldValue; // Again, we just don't know        }        m_propertySheet->setProperty(m_index, new_value);    }    m_propertySheet->setChanged(m_index, false);    setTopMinMaxSize(formWindow(), qobject_cast<QWidget *>(m_object), m_propertyName, new_value);    QWidget *widget = qobject_cast<QWidget *>(m_object);    QWidget *parentWidget = qobject_cast<QWidget *>(m_parentObject);    if (m_propertyName == QLatin1String("geometry") && widget) {        checkSelection(widget);        checkParent(widget, parentWidget);    } else if (m_propertyName == QLatin1String("objectName")) {        checkObjectName(m_object);    }    if (promoted) {        if (m_propertyName == QLatin1String("minimumSize"))            promoted->setMinimumSize(new_value.toSize());        else if (m_propertyName == QLatin1String("maximumSize"))            promoted->setMaximumSize(new_value.toSize());    }    if (QDesignerPropertyEditorInterface *propertyEditor = formWindow()->core()->propertyEditor()) {        if (propertyEditor->object() == object())            propertyEditor->setPropertyValue(propertyName(), new_value, false);    }}void ResetPropertyCommand::undo(){    Q_ASSERT(m_propertySheet);    Q_ASSERT(m_index != -1);    m_propertySheet->setProperty(m_index, m_oldValue);    m_propertySheet->setChanged(m_index, m_changed);    setTopMinMaxSize(formWindow(), qobject_cast<QWidget *>(m_object), m_propertyName, m_oldValue);    QWidget *widget = qobject_cast<QWidget *>(m_object);    QWidget *parentWidget = qobject_cast<QWidget *>(m_parentObject);    if (m_propertyName == QLatin1String("geometry") && widget) {        checkSelection(widget);        checkParent(widget, parentWidget);    } else if (m_propertyName == QLatin1String("objectName")) {        checkObjectName(m_object);    }    if (QDesignerPropertyEditorInterface *propertyEditor = formWindow()->core()->propertyEditor()) {        if (propertyEditor->object() == object())            propertyEditor->setPropertyValue(propertyName(), m_oldValue, m_changed);    }    if (QDesignerPromotedWidget *promoted = qobject_cast<QDesignerPromotedWidget*>(m_object)) {        if (m_propertyName == QLatin1String("minimumSize"))            promoted->setMinimumSize(m_oldValue.toSize());        else if (m_propertyName == QLatin1String("maximumSize"))            promoted->setMaximumSize(m_oldValue.toSize());    }}// ---- InsertWidgetCommand ----InsertWidgetCommand::InsertWidgetCommand(QDesignerFormWindowInterface *formWindow)    : QDesignerFormWindowCommand(QString(), formWindow){}void InsertWidgetCommand::init(QWidget *widget, bool already_in_form){    m_widget = widget;    setText(QApplication::translate("Command", "Insert '%1'").arg(widget->objectName()));    QWidget *parentWidget = m_widget->parentWidget();    QDesignerFormEditorInterface *core = formWindow()->core();    QDesignerLayoutDecorationExtension *deco = qt_extension<QDesignerLayoutDecorationExtension*>(core->extensionManager(), parentWidget);    m_insertMode = deco ? deco->currentInsertMode() : QDesignerLayoutDecorationExtension::InsertWidgetMode;    m_cell = deco ? deco->currentCell() : qMakePair(0, 0);    m_widgetWasManaged = already_in_form;}static void recursiveUpdate(QWidget *w){    w->update();    const QObjectList &l = w->children();    QObjectList::const_iterator it = l.begin();    for (; it != l.end(); ++it) {        if (QWidget *w = qobject_cast<QWidget*>(*it))            recursiveUpdate(w);    }}void InsertWidgetCommand::redo(){    checkObjectName(m_widget);    QWidget *parentWidget = m_widget->parentWidget();    Q_ASSERT(parentWidget);    QDesignerFormEditorInterface *core = formWindow()->core();    QDesignerLayoutDecorationExtension *deco = qt_extension<QDesignerLayoutDecorationExtension*>(core->extensionManager(), parentWidget);    if (deco != 0) {        if (LayoutInfo::layoutType(core, parentWidget) == LayoutInfo::Grid) {            switch (m_insertMode) {                case QDesignerLayoutDecorationExtension::InsertRowMode: {                    deco->insertRow(m_cell.first);                } break;                case QDesignerLayoutDecorationExtension::InsertColumnMode: {                    deco->insertColumn(m_cell.second);                } break;                default: break;            } // end switch        }        deco->insertWidget(m_widget, m_cell);    }    if (!m_widgetWasManaged)        formWindow()->manageWidget(m_widget);    m_widget->show();    formWindow()->emitSelectionChanged();    if (parentWidget && parentWidget->layout()) {        recursiveUpdate(parentWidget);        parentWidget->layout()->invalidate();    }    QList<QDesignerLabel*> label_list = qFindChildren<QDesignerLabel*>(formWindow());    foreach (QDesignerLabel *label, label_list) {        QDesignerPropertySheetExtension* propertySheet            = qt_extension<QDesignerPropertySheetExtension*>                (core->extensionManager(), label);        if (propertySheet == 0)            continue;        int idx = propertySheet->indexOf(QLatin1String("buddy"));        if (idx == -1)            continue;        if (propertySheet->property(idx).toString() == m_widget->objectName())            propertySheet->setProperty(idx, m_widget->objectName());    }}void InsertWidgetCommand::undo(){    QWidget *parentWidget = m_widget->parentWidget();    QDesignerFormEditorInterface *core = formWindow()->core();    QDesignerLayoutDecorationExtension *deco = qt_extension<QDesignerLayoutDecorationExtension*>(core->extensionManager(), parentWidget);    if (deco) {        deco->removeWidget(m_widget);        deco->simplify();    }    if (!m_widgetWasManaged) {        formWindow()->unmanageWidget(m_widget);        m_widget->hide();    }    formWindow()->emitSelectionChanged();    QList<QDesignerLabel*> label_list = qFindChildren<QDesignerLabel*>(formWindow());    foreach (QDesignerLabel *label, label_list) {        QDesignerPropertySheetExtension* propertySheet            = qt_extension<QDesignerPropertySheetExtension*>                (core->extensionManager(), label);        if (propertySheet == 0)            continue;        int idx = propertySheet->indexOf(QLatin1String("buddy"));        if (idx == -1)            continue;        if (propertySheet->property(idx).toString() == m_widget->objectName())            propertySheet->setProperty(idx, m_widget->objectName());    }}// ---- RaiseWidgetCommand ----RaiseWidgetCommand::RaiseWidgetCommand(QDesignerFormWindowInterface *formWindow)    : QDesignerFormWindowCommand(QString(), formWindow){}void RaiseWidgetCommand::init(QWidget *widget){    m_widget = widget;    setText(QApplication::translate("Command", "Raise '%1'").arg(widget->objectName()));}void RaiseWidgetCommand::redo(){    m_widget->raise();}void RaiseWidgetCommand::undo(){}// ---- LowerWidgetCommand ----LowerWidgetCommand::LowerWidgetCommand(QDesignerFormWindowInterface *formWindow)    : QDesignerFormWindowCommand(QString(), formWindow){}void LowerWidgetCommand::init(QWidget *widget){    m_widget = widget;    setText(QApplication::translate("Command", "Lower '%1'").arg(widget->objectName()));}void LowerWidgetCommand::redo(){    m_widget->raise();}void LowerWidgetCommand::undo(){}// ---- DeleteWidgetCommand ----DeleteWidgetCommand::DeleteWidgetCommand(QDesignerFormWindowInterface *formWindow)    : QDesignerFormWindowCommand(QString(), formWindow){}void DeleteWidgetCommand::init(QWidget *widget){    m_widget = widget;    m_parentWidget = widget->parentWidget();    m_geometry = widget->geometry();    m_layoutType = LayoutInfo::NoLayout;    m_index = -1;    if (hasLayout(m_parentWidget)) {        m_layoutType = LayoutInfo::layoutType(formWindow()->core(), m_parentWidget);        switch (m_layoutType) {            case LayoutInfo::VBox:                m_index = static_cast<QVBoxLayout*>(m_parentWidget->layout())->indexOf(m_widget);                break;            case LayoutInfo::HBox:                m_index = static_cast<QHBoxLayout*>(m_parentWidget->layout())->indexOf(m_widget);                break;            case LayoutInfo::Grid: {                m_index = 0;                while (QLayoutItem *item = m_parentWidget->layout()->itemAt(m_index)) {                    if (item->widget() == m_widget)                        break;                    ++m_index;                }                static_cast<QGridLayout*>(m_parentWidget->layout())->getItemPosition(m_index, &m_row, &m_col, &m_rowspan, &m_colspan);            } break;            default:                break;        } // end switch    }    m_formItem = formWindow()->core()->metaDataBase()->item(formWindow());    m_tabOrderIndex = m_formItem->tabOrder().indexOf(widget);    // Build the list of managed children    m_managedChildren = QList<QPointer<QWidget> >();    QList<QWidget *>children = qFindChildren<QWidget *>(m_widget);    foreach (QPointer<QWidget> child, children) {        if (formWindow()->isManaged(child))            m_managedChildren.append(child);    }    setText(QApplication::translate("Command", "Delete '%1'").arg(widget->objectName()));}void DeleteWidgetCommand::redo(){    QDesignerFormEditorInterface *core = formWindow()->core();    if (QDesignerContainerExtension *c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_parentWidget)) {        for (int i=0; i<c->count(); ++i) {            if (c->widget(i) == m_widget) {                c->remove(i);                formWindow()->emitSelectionChanged();                return;            }        }    }    if (QDesignerLayoutDecorationExtension *deco = qt_extension<QDesignerLayoutDecorationExtension*>(core->extensionManager(), m_parentWidget)) {        deco->removeWidget(m_widget);    }    // Unmanage the managed children first    foreach (QWidget *child, m_managedChildren)        formWindow()->unmanageWidget(child);    formWindow()->unmanageWidget(m_widget);    m_widget->setParent(formWindow());    m_widget->hide();    if (m_tabOrderIndex != -1) {        QList<QWidget*> tab_order = m_formItem->tabOrder();        tab_order.removeAt(m_tabOrderIndex);        m_formItem->setTabOrder(tab_order);    }    formWindow()->emitSelectionChanged();}void DeleteWidgetCommand::undo(){    QDesignerFormEditorInterface *core = formWindow()->core();    m_widget->setParent(m_parentWidget);    if (QDesignerContainerExtension *c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_parentWidget)) {        c->addWidget(m_widget);        formWindow()->emitSelectionChanged();        return;    }

⌨️ 快捷键说明

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