! * \brief PluginManagerPrivate::dependsSort 插件依赖排序算法 * \param srcQueue 传入需要排序的插件源队列 * \return 返回排序后的Queue */
| 472 | * \return 返回排序后的Queue |
| 473 | */ |
| 474 | PluginManagerPrivate::PluginMetaQueue PluginManagerPrivate::dependsSort( |
| 475 | const PluginManagerPrivate::PluginMetaQueue &srcQueue) |
| 476 | { |
| 477 | dpfCheckTimeBegin(); |
| 478 | |
| 479 | QMutexLocker lock(&GlobalPrivate::mutex); |
| 480 | |
| 481 | PluginMetaQueue result; |
| 482 | |
| 483 | if (srcQueue.isEmpty()) |
| 484 | return result; |
| 485 | |
| 486 | PluginMetaQueue temp = srcQueue; |
| 487 | auto itera = temp.begin(); |
| 488 | while (itera != temp.end()) { |
| 489 | if ((*itera)->depends().isEmpty()) { |
| 490 | result.append(*itera); |
| 491 | itera = temp.erase(itera); |
| 492 | continue; |
| 493 | } |
| 494 | itera ++; |
| 495 | } |
| 496 | |
| 497 | auto dependsNoContains = [=](const PluginMetaQueue &src, const PluginMetaObjectPointer &elem) { |
| 498 | QList<QString> result; |
| 499 | QList<QString> srcPluginNames; |
| 500 | for (auto val : src) { |
| 501 | srcPluginNames << val->name(); |
| 502 | } |
| 503 | |
| 504 | for (auto depend : elem->depends()) { |
| 505 | if (!srcPluginNames.contains(depend.name())) { |
| 506 | result << depend.name(); |
| 507 | } |
| 508 | } |
| 509 | return result; |
| 510 | }; |
| 511 | |
| 512 | while (!temp.isEmpty()) { |
| 513 | auto itera = temp.begin(); |
| 514 | while (itera != temp.end()) { |
| 515 | auto srcNoContains = dependsNoContains(srcQueue, *itera); |
| 516 | auto dstNoContains = dependsNoContains(result, *itera); |
| 517 | if (!srcNoContains.isEmpty()) { |
| 518 | qCritical() << "Error, invalid plugin depends: " << srcNoContains |
| 519 | << " from plugin: " << (*itera)->name(); |
| 520 | for (auto noContainsVal : srcNoContains) { |
| 521 | // Delete not existen plugin depend from plugin-name |
| 522 | dstNoContains.removeOne(noContainsVal); |
| 523 | } |
| 524 | // claer not existen plugin depend from plugin-name |
| 525 | srcNoContains.clear(); |
| 526 | } |
| 527 | |
| 528 | if (dstNoContains.isEmpty()) { |
| 529 | result.append(*itera); |
| 530 | itera = temp.erase(itera); |
| 531 | continue; |