void WidgetDataBase::grabDefaultPropertyValues() { const int itemCount = count(); for (int i = 0; i < itemCount; ++i) { QDesignerWidgetDataBaseItemInterface *dbItem = item(i); const QList<QVariant> default_prop_values = defaultPropertyValues(dbItem->name()); dbItem->setDefaultPropertyValues(default_prop_values); } }
void QDesignerPromotionDialog::slotRemove() { unsigned flags; QDesignerWidgetDataBaseItemInterface *dbItem = databaseItemAt(m_treeView->selectionModel()->selection(), flags); if (!dbItem || (flags & Referenced)) return; QString errorMessage; if (m_promotion->removePromotedClass(dbItem->name(), &errorMessage)) { slotUpdateFromWidgetDatabase(); } else { displayError(errorMessage); } }
void WidgetDataBase::grabStandardWidgetBoxIcons() { // At this point, grab the default icons for the non-custom widgets from // the widget box. They will show up in the object inspector. if (const QDesignerWidgetBox *wb = qobject_cast<const QDesignerWidgetBox *>(m_core->widgetBox())) { const QString qWidgetClass = QLatin1String("QWidget"); const int itemCount = count(); for (int i = 0; i < itemCount; ++i) { QDesignerWidgetDataBaseItemInterface *dbItem = item(i); if (!dbItem->isCustom() && dbItem->icon().isNull()) { // Careful not to catch the layout icons when looking for // QWidget const QString name = dbItem->name(); if (name == qWidgetClass) { dbItem->setIcon(wb->iconForWidget(name, QLatin1String("Containers"))); } else { dbItem->setIcon(wb->iconForWidget(name)); } } } } }
void WidgetDataBase::loadPlugins() { typedef QMap<QString, int> NameIndexMap; typedef QList<QDesignerWidgetDataBaseItemInterface*> ItemList; typedef QMap<QString, QDesignerWidgetDataBaseItemInterface*> NameItemMap; typedef QSet<QString> NameSet; // 1) create a map of existing custom classes NameIndexMap existingCustomClasses; NameSet nonCustomClasses; const int count = m_items.size(); for (int i = 0; i < count; i++) { const QDesignerWidgetDataBaseItemInterface* item = m_items[i]; if (item->isCustom() && !item->isPromoted()) existingCustomClasses.insert(item->name(), i); else nonCustomClasses.insert(item->name()); } // 2) create a list plugins ItemList pluginList; const QDesignerPluginManager *pm = m_core->pluginManager(); foreach(QDesignerCustomWidgetInterface* c, pm->registeredCustomWidgets()) pluginList += createCustomWidgetItem(c, pm->customWidgetData(c)); // 3) replace custom classes or add new ones, remove them from existingCustomClasses, // leaving behind deleted items unsigned replacedPlugins = 0; unsigned addedPlugins = 0; unsigned removedPlugins = 0; if (!pluginList.empty()) { ItemList::const_iterator cend = pluginList.constEnd(); for (ItemList::const_iterator it = pluginList.constBegin();it != cend; ++it ) { QDesignerWidgetDataBaseItemInterface* pluginItem = *it; const QString pluginName = pluginItem->name(); NameIndexMap::iterator existingIt = existingCustomClasses.find(pluginName); if (existingIt == existingCustomClasses.end()) { // Add new class. if (nonCustomClasses.contains(pluginName)) { designerWarning(tr("A custom widget plugin whose class name (%1) matches that of an existing class has been found.").arg(pluginName)); } else { append(pluginItem); addedPlugins++; } } else { // replace existing info const int existingIndex = existingIt.value(); delete m_items[existingIndex]; m_items[existingIndex] = pluginItem; existingCustomClasses.erase(existingIt); replacedPlugins++; } } } // 4) remove classes that have not been matched. The stored indexes become invalid while deleting. if (!existingCustomClasses.empty()) { NameIndexMap::const_iterator cend = existingCustomClasses.constEnd(); for (NameIndexMap::const_iterator it = existingCustomClasses.constBegin();it != cend; ++it ) { const int index = indexOfClassName(it.key()); if (index != -1) { remove(index); removedPlugins++; } } } if (debugWidgetDataBase) qDebug() << "WidgetDataBase::loadPlugins(): " << addedPlugins << " added, " << replacedPlugins << " replaced, " << removedPlugins << "deleted."; }