void ViewManager::AddComponent (QuarkComponent_ptr comp, QuarkManager_ptr mgr, bool force) { if (!mgr->IsValidArea ()) return; const auto& quarkId = mgr->GetManifest ().GetID (); if (!force) { if (mgr->GetManifest ().IsHiddenByDefault () && !PreviousQuarkOrder_.contains (quarkId)) return; if (RemovedIDs_.contains (quarkId)) return; } Quark2Manager_ [comp->Url_] = mgr; auto item = new QStandardItem; item->setData (comp->Url_, ViewItemsModel::Role::SourceURL); item->setData (mgr->HasSettings (), ViewItemsModel::Role::QuarkHasSettings); item->setData (quarkId, ViewItemsModel::Role::QuarkClass); const int pos = PreviousQuarkOrder_.indexOf (quarkId); if (pos == -1 || pos == PreviousQuarkOrder_.size () - 1) ViewItemsModel_->appendRow (item); else { bool added = false; for (int i = pos + 1; i < PreviousQuarkOrder_.size (); ++i) { const auto& thatId = PreviousQuarkOrder_.at (i); for (int j = 0; j < ViewItemsModel_->rowCount (); ++j) { if (ViewItemsModel_->item (j)->data (ViewItemsModel::Role::QuarkClass) != thatId) continue; ViewItemsModel_->insertRow (j, item); added = true; break; } if (added) break; } if (!added) ViewItemsModel_->appendRow (item); } }
void ViewManager::AddComponent (QuarkComponent_ptr comp) { QuarkManager_ptr mgr; try { mgr.reset (new QuarkManager (comp, this, Proxy_)); } catch (const std::exception& e) { qWarning () << Q_FUNC_INFO << e.what (); return; } AddComponent (comp, mgr); }
void ViewManager::UnhideQuark (QuarkComponent_ptr component, QuarkManager_ptr manager) { if (!manager) return; RemoveFromRemoved (manager->GetID ()); AddComponent (component, manager); }
QuarkUnhideListView::QuarkUnhideListView (const QuarkComponents_t& components, ViewManager *viewMgr, ICoreProxy_ptr proxy, QWidget *parent) : Util::UnhideListViewBase (proxy, parent) , ViewManager_ (viewMgr) { QList<QStandardItem*> items; for (const auto& comp : components) { QuarkManager_ptr manager; try { manager.reset (new QuarkManager (comp, ViewManager_, proxy)); } catch (const std::exception& e) { qWarning () << Q_FUNC_INFO << "error creating manager for quark" << comp->Url_; continue; } const auto& manifest = manager->GetManifest (); auto item = new QStandardItem; item->setData (manifest.GetID (), Util::UnhideListModel::Roles::ItemClass); item->setData (manifest.GetName (), Util::UnhideListModel::Roles::ItemName); item->setData (manifest.GetDescription (), Util::UnhideListModel::Roles::ItemDescription); item->setData (Util::GetAsBase64Src (manifest.GetIcon ().pixmap (32, 32).toImage ()), Util::UnhideListModel::Roles::ItemIcon); items << item; ID2Component_ [manifest.GetID ()] = { comp, manager }; } Model_->invisibleRootItem ()->appendRows (items); connect (rootObject (), SIGNAL (itemUnhideRequested (QString)), this, SLOT (unhide (QString)), Qt::QueuedConnection); }
void ViewManager::UnhideQuark (QuarkComponent_ptr component, QuarkManager_ptr manager) { if (!manager) return; RemoveFromRemoved (manager->GetManifest ().GetID ()); AddComponent (component, manager, true); SaveQuarkOrder (); }