void NewTabMenuManager::OpenTab (QAction *action) { QObject *pObj = action->property ("PluginObj").value<QObject*> (); IHaveTabs *tabs = qobject_cast<IHaveTabs*> (pObj); if (!tabs) { qWarning () << Q_FUNC_INFO << pObj << "doesn't implement IHaveTabs"; return; } const QByteArray& tabClass = action->property ("TabClass").toByteArray (); tabs->TabOpenRequested (tabClass); const auto& classes = tabs->GetTabClasses (); const auto pos = std::find_if (classes.begin (), classes.end (), [&tabClass] (decltype (classes.front ()) item) { return item.TabClass_ == tabClass; }); if (action->property ("Single").toBool ()) { NewTabMenu_->removeAction (action); HiddenActions_ [pObj] [tabClass] = action; ToggleHide (pObj, tabClass, false); } else if (pos != classes.end () && pos->Features_ & TFByDefault) ToggleHide (pObj, tabClass, false); }
void SeparateTabWidget::handleAddDefaultTab () { const auto& combined = XmlSettingsManager::Instance ()-> property ("DefaultNewTab").toString ().toLatin1 (); if (combined != "contextdependent") { const auto& parts = combined.split ('|'); if (parts.size () != 2) qWarning () << Q_FUNC_INFO << "incorrect split" << parts << combined; else { const QByteArray& newTabId = parts.at (0); const QByteArray& tabClass = parts.at (1); QObject *plugin = Core::Instance () .GetPluginManager ()->GetPluginByID (newTabId); IHaveTabs *iht = qobject_cast<IHaveTabs*> (plugin); if (!iht) qWarning () << Q_FUNC_INFO << "plugin with id" << newTabId << "is not a IMultiTabs"; else { iht->TabOpenRequested (tabClass); return; } } } IHaveTabs *highestIHT = 0; QByteArray highestTabClass; int highestPriority = 0; for (auto iht : Core::Instance ().GetPluginManager ()->GetAllCastableTo<IHaveTabs*> ()) for (const auto& info : iht->GetTabClasses ()) { if (!(info.Features_ & TFOpenableByRequest)) continue; if (info.Priority_ <= highestPriority) continue; highestIHT = iht; highestTabClass = info.TabClass_; highestPriority = info.Priority_; } const auto imtw = qobject_cast<ITabWidget*> (CurrentWidget ()); const int delta = 15; if (imtw && imtw->GetTabClassInfo ().Priority_ + delta > highestPriority) { highestIHT = qobject_cast<IHaveTabs*> (imtw->ParentMultiTabs ()); highestTabClass = imtw->GetTabClassInfo ().TabClass_; } if (!highestIHT) { qWarning () << Q_FUNC_INFO << "no IHT detected"; return; } highestIHT->TabOpenRequested (highestTabClass); }