void WidgetBoxCategoryModel::addWidget(const QDesignerWidgetBoxInterface::Widget &widget, const QIcon &icon,bool editable) { // build item. Filter on name + class name if it is different and not a layout. QString filter = widget.name(); if (!filter.contains(QLatin1String("Layout")) && m_classNameRegExp.indexIn(widget.domXml()) != -1) { const QString className = m_classNameRegExp.cap(1); if (!filter.contains(className)) filter += className; } WidgetBoxCategoryEntry item(widget, filter, icon, editable); const QDesignerWidgetDataBaseInterface *db = m_core->widgetDataBase(); const int dbIndex = db->indexOfClassName(widget.name()); if (dbIndex != -1) { const QDesignerWidgetDataBaseItemInterface *dbItem = db->item(dbIndex); const QString toolTip = dbItem->toolTip(); if (!toolTip.isEmpty()) item.toolTip = toolTip; const QString whatsThis = dbItem->whatsThis(); if (!whatsThis.isEmpty()) item.whatsThis = whatsThis; } // insert const int row = m_items.size(); beginInsertRows(QModelIndex(), row, row); m_items.push_back(item); endInsertRows(); }
PromotionTaskMenu::PromotionState PromotionTaskMenu::createPromotionActions(QDesignerFormWindowInterface *formWindow) { // clear out old if (!m_promotionActions.empty()) { qDeleteAll(m_promotionActions); m_promotionActions.clear(); } // No promotion of main container if (formWindow->mainContainer() == m_widget) return NotApplicable; // Check for a homogenous selection const PromotionSelectionList promotionSelection = promotionSelectionList(formWindow); if (promotionSelection.empty()) return NoHomogenousSelection; QDesignerFormEditorInterface *core = formWindow->core(); // if it is promoted: demote only. if (isPromoted(formWindow->core(), m_widget)) { const QString label = m_demoteLabel.arg( promotedExtends(core , m_widget)); QAction *demoteAction = new QAction(label, this); connect(demoteAction, SIGNAL(triggered()), this, SLOT(slotDemoteFromCustomWidget())); m_promotionActions.push_back(demoteAction); return CanDemote; } // figure out candidates const QString baseClassName = WidgetFactory::classNameOf(core, m_widget); const WidgetDataBaseItemList candidates = promotionCandidates(core->widgetDataBase(), baseClassName ); if (candidates.empty()) { // Is this thing promotable at all? return QDesignerPromotionDialog::baseClassNames(core->promotion()).contains(baseClassName) ? CanPromote : NotApplicable; } // Set up a signal mapper to associate class names if (!m_promotionMapper) { m_promotionMapper = new QSignalMapper(this); connect(m_promotionMapper, SIGNAL(mapped(QString)), this, SLOT(slotPromoteToCustomWidget(QString))); } QMenu *candidatesMenu = new QMenu(); // Create a sub menu const WidgetDataBaseItemList::const_iterator cend = candidates.constEnd(); // Set up actions and map class names for (WidgetDataBaseItemList::const_iterator it = candidates.constBegin(); it != cend; ++it) { const QString customClassName = (*it)->name(); QAction *action = new QAction((*it)->name(), this); connect(action, SIGNAL(triggered()), m_promotionMapper, SLOT(map())); m_promotionMapper->setMapping(action, customClassName); candidatesMenu->addAction(action); } // Sub menu action QAction *subMenuAction = new QAction(m_promoteLabel, this); subMenuAction->setMenu(candidatesMenu); m_promotionActions.push_back(subMenuAction); return CanPromote; }
void QDesignerIntegrationPrivate::initialize() { typedef void (QDesignerIntegration::*QDesignerIntegrationUpdatePropertySlot3)(const QString &, const QVariant &, bool); // // integrate the `Form Editor component' // // Extensions QDesignerFormEditorInterface *core = q->core(); if (QDesignerPropertyEditor *designerPropertyEditor= qobject_cast<QDesignerPropertyEditor *>(core->propertyEditor())) { QObject::connect(designerPropertyEditor, &QDesignerPropertyEditor::propertyValueChanged, q, static_cast<QDesignerIntegrationUpdatePropertySlot3>(&QDesignerIntegration::updateProperty)); QObject::connect(designerPropertyEditor, &QDesignerPropertyEditor::resetProperty, q, &QDesignerIntegration::resetProperty); QObject::connect(designerPropertyEditor, &QDesignerPropertyEditor::addDynamicProperty, q, &QDesignerIntegration::addDynamicProperty); QObject::connect(designerPropertyEditor, &QDesignerPropertyEditor::removeDynamicProperty, q, &QDesignerIntegration::removeDynamicProperty); } else { QObject::connect(core->propertyEditor(), SIGNAL(propertyChanged(QString,QVariant)), q, SLOT(updatePropertyPrivate(QString,QVariant))); // ### fixme: VS Integration leftover? } QObject::connect(core->formWindowManager(), &QDesignerFormWindowManagerInterface::formWindowAdded, q, &QDesignerIntegrationInterface::setupFormWindow); QObject::connect(core->formWindowManager(), &QDesignerFormWindowManagerInterface::activeFormWindowChanged, q, &QDesignerIntegrationInterface::updateActiveFormWindow); m_gradientManager = new QtGradientManager(q); core->setGradientManager(m_gradientManager); QString designerFolder = QDir::homePath(); designerFolder += QDir::separator(); designerFolder += QStringLiteral(".designer"); m_gradientsPath = designerFolder; m_gradientsPath += QDir::separator(); m_gradientsPath += QStringLiteral("gradients.xml"); QFile f(m_gradientsPath); if (f.open(QIODevice::ReadOnly)) { QtGradientUtils::restoreState(m_gradientManager, QString::fromLatin1(f.readAll())); f.close(); } else { QFile defaultGradients(QStringLiteral(":/qt-project.org/designer/defaultgradients.xml")); if (defaultGradients.open(QIODevice::ReadOnly)) { QtGradientUtils::restoreState(m_gradientManager, QString::fromLatin1(defaultGradients.readAll())); defaultGradients.close(); } } if (WidgetDataBase *widgetDataBase = qobject_cast<WidgetDataBase*>(core->widgetDataBase())) widgetDataBase->grabStandardWidgetBoxIcons(); }