Logo Search packages:      
Sourcecode: qt4-x11 version File versions

void qdesigner_internal::Layout::setup (  )  [virtual]

The widget list we got in the constructor might contain too much widgets (like widgets with different parents, already laid out widgets, etc.). Here we set up the list and so the only the "best" widgets get laid out.

Definition at line 143 of file layout.cpp.

References QObject::children(), QList< T >::clear(), QObject::connect(), QDesignerFormWindowInterface::core(), QList< T >::count(), QObject::destroyed(), QList< T >::first(), QWidget::geometry, QMultiMap< Key, T >::insert(), QHash< Key, T >::insert(), QDesignerWidgetDataBaseInterface::isContainer(), QList< T >::isEmpty(), QDesignerMetaDataBaseInterface::item(), QMap< Key, T >::keys(), QWidget::layout(), QDesignerFormWindowInterface::mainContainer(), QDesignerFormEditorInterface::metaDataBase(), QWidget::parentWidget(), QWidget::raise(), QMap< Key, T >::values(), QDesignerFormEditorInterface::widgetDataBase(), QDesignerFormEditorInterface::widgetFactory(), QDesignerWidgetFactoryInterface::widgetOfContainer(), QPoint::x(), QWidget::x, QPoint::y(), and QWidget::y.

{
    startPoint = QPoint(32767, 32767);

    // Go through all widgets of the list we got. As we can only
    // layout widgets which have the same parent, we first do some
    // sorting which means create a list for each parent containing
    // its child here. After that we keep working on the list of
    // childs which has the most entries.
    // Widgets which are already laid out are thrown away here too

    QMultiMap<QWidget*, QWidget*> lists;
    foreach (QWidget *w, m_widgets) {
        QWidget *p = w->parentWidget();

        if (p && LayoutInfo::layoutType(formWindow->core(), p) != LayoutInfo::NoLayout
                && formWindow->core()->metaDataBase()->item(p->layout()) != 0)
            continue;

        lists.insert(p, w);
    }

    QList<QWidget*> lastList;
    QList<QWidget*> parents = lists.keys();
    foreach (QWidget *p, parents) {
        QList<QWidget*> children = lists.values(p);

        if (children.count() > lastList.count())
            lastList = children;
    }


    // If we found no list (because no widget did fit at all) or the
    // best list has only one entry and we do not layout a container,
    // we leave here.
    QDesignerWidgetDataBaseInterface *widgetDataBase = formWindow->core()->widgetDataBase();
    if (lastList.count() < 2 &&
                        (!layoutBase ||
                          (!widgetDataBase->isContainer(layoutBase, false) &&
                            layoutBase != formWindow->mainContainer()))
                       ) {
        m_widgets.clear();
        startPoint = QPoint(0, 0);
        return;
    }

    // Now we have a new and clean widget list, which makes sense
    // to layout
    m_widgets = lastList;
    // Also use the only correct parent later, so store it

    Q_ASSERT(m_widgets.isEmpty() == false);

    m_parentWidget = formWindow->core()->widgetFactory()->widgetOfContainer(m_widgets.first()->parentWidget());
    // Now calculate the position where the layout-meta-widget should
    // be placed and connect to widgetDestroyed() signals of the
    // widgets to get informed if one gets deleted to be able to
    // handle that and do not crash in this case
    foreach (QWidget *w, m_widgets) {
        connect(w, SIGNAL(destroyed()), this, SLOT(widgetDestroyed()));
        startPoint = QPoint(qMin(startPoint.x(), w->x()), qMin(startPoint.y(), w->y()));
        QRect rc(w->geometry());

        geometries.insert(w, rc);
        // Change the Z-order, as saving/loading uses the Z-order for
        // writing/creating widgets and this has to be the same as in
        // the layout. Else saving + loading will give different results
        w->raise();
    }

    sort();
}


Generated by  Doxygen 1.6.0   Back to index