void QSimpleResource::addCustomWidgetsToWidgetDatabase(const QDesignerFormEditorInterface *core,
                                                       QList<DomCustomWidget*>& custom_widget_list)
{
    QDesignerWidgetDataBaseInterface *db = core->widgetDataBase();
    for (int i=0; i < custom_widget_list.size(); ) {
        bool classInserted = false;
        DomCustomWidget *custom_widget = custom_widget_list[i];
        const QString customClassName = custom_widget->elementClass();
        const QString base_class = custom_widget->elementExtends();
        QString includeFile;
        IncludeType includeType = IncludeLocal;
        if (const DomHeader *header = custom_widget->elementHeader()) {
            includeFile = header->text();
            if (header->hasAttributeLocation() && header->attributeLocation() == QStringLiteral("global"))
                includeType = IncludeGlobal;
        }
        const bool domIsContainer = custom_widget->elementContainer();
        // Append a new item
        if (base_class.isEmpty()) {
            WidgetDataBaseItem *item = new WidgetDataBaseItem(customClassName);
            item->setPromoted(false);
            item->setGroup(QCoreApplication::translate("Designer", "Custom Widgets"));
            item->setIncludeFile(buildIncludeFile(includeFile, includeType));
            item->setContainer(domIsContainer);
            item->setCustom(true);
            addFakeMethodsToWidgetDataBase(custom_widget, item);
            db->append(item);
            custom_widget_list.removeAt(i);
            classInserted = true;
        } else {
            // Create a new entry cloned from base class. Note that this will ignore existing
            // classes, eg, plugin custom widgets.
            QDesignerWidgetDataBaseItemInterface *item =
                appendDerived(db, customClassName, QCoreApplication::translate("Designer", "Promoted Widgets"),
                              base_class,
                              buildIncludeFile(includeFile, includeType),
                              true,true);
            // Ok, base class found.
            if (item) {
                // Hack to accommodate for old UI-files in which "container" is not set properly:
                // Apply "container" from DOM only if true (else, eg classes from QFrame might not accept
                // dropping child widgets on them as container=false). This also allows for
                // QWidget-derived stacked pages.
                if (domIsContainer)
                    item->setContainer(domIsContainer);

                addFakeMethodsToWidgetDataBase(custom_widget, static_cast<WidgetDataBaseItem*>(item));
                custom_widget_list.removeAt(i);
                classInserted = true;
            }
        }
        // Skip failed item.
        if (!classInserted)
            i++;
    }

}
Exemplo n.º 2
0
 PromotionParameters NewPromotedClassPanel::promotionParameters() const {
      PromotionParameters rc;
      rc.m_baseClass = m_baseClassCombo->currentText();
      rc.m_className = m_classNameEdit->text();
      rc.m_includeFile = buildIncludeFile(m_includeFileEdit->text(),
                                          m_globalIncludeCheckBox->checkState() == Qt::Checked ? IncludeGlobal : IncludeLocal);
      return rc;
  }
Exemplo n.º 3
0
void PromotionModel::slotItemChanged(QStandardItem * changedItem) {
    // Retrieve DB item
    bool referenced;
    QDesignerWidgetDataBaseItemInterface *dbItem = databaseItem(changedItem, &referenced);
    Q_ASSERT(dbItem);
    // Change header or type
    switch (changedItem->column()) {
    case ClassNameColumn:
        emit classNameChanged(dbItem,  changedItem->text());
        break;
    case IncludeTypeColumn:
    case IncludeFileColumn: {
        // Get both file and type items via parent.
        const QStandardItem *baseClassItem = changedItem->parent();
        const QStandardItem *fileItem = baseClassItem->child(changedItem->row(), IncludeFileColumn);
        const QStandardItem *typeItem =  baseClassItem->child(changedItem->row(), IncludeTypeColumn);
        emit includeFileChanged(dbItem, buildIncludeFile(fileItem->text(), typeItem->checkState() == Qt::Checked ? IncludeGlobal : IncludeLocal));
    }
    break;
    }
}