void OperationCatalogModel::gatherItems() { if (!_refresh) return; _allItems.clear(); _refresh = false; WorkSpaceModel *currentModel = uicontext()->currentWorkSpace(); bool isDefault = false; if (currentModel){ auto n = currentModel->name(); isDefault = n == "default"; } if ( currentModel == 0 || isDefault){ setDescription("main catalog for ilwis operations"); QString serviceFilter = QString("(type=%1 and catalogitemproperties.propertyname='keyword' and catalogitemproperties.propertyvalue like '%service%')").arg(itSINGLEOPERATION); _services = mastercatalog()->select(serviceFilter); }else { setView(currentModel->viewRef()); } std::vector<Resource> items = _view.items(); std::sort(items.begin(), items.end(),[](const Resource& r1, const Resource& r2){ QString name1 = r1["longname"].toString(); if ( name1 == sUNDEF) name1 = r1.name(); QString name2 = r2["longname"].toString(); if ( name2 == sUNDEF) name2 = r2.name(); return name1.toLower() < name2.toLower(); }); std::map<QString, std::vector<OperationModel *>> operationsByKey; std::set<QString> keywordset; for(const Resource& resource : items){ OperationModel *operation = new OperationModel(resource, this); QString kws = resource["keyword"].toString(); if ( kws.indexOf("internal") != -1) continue; _allItems.push_back(operation); QString keysstring = operation->resource()["keyword"].toString(); QStringList keys = keysstring.split(","); for(auto key : keys){ operationsByKey[key].push_back(operation); keywordset.insert(key); } } _operationsByKey.clear(); for( const auto& item : operationsByKey){ _operationsByKey.push_back(new OperationsByKeyModel(item.first, item.second, this)); } _keywords.clear(); for(auto keyword : keywordset) _keywords.push_back(keyword); qSort(_keywords.begin(), _keywords.end()); _keywords.push_front(""); // all OperationCatalogModel *oc = uicontext()->globalOperationCatalog(); if ( oc != this){ oc->_refresh = true; oc->operations(); } }
void OperationCatalogModel::gatherItems() { if (!_refresh) return; WorkSpaceModel *currentModel = uicontext()->currentWorkSpace(); bool isDefault = false; if (currentModel){ auto n = currentModel->name(); isDefault = n == "default"; } if ( currentModel == 0 || isDefault){ if ( !_view.isValid()){ QUrl location("ilwis://operations"); QString descr ="main catalog for ilwis operations"; Resource res(location, itCATALOGVIEW ) ; res.name("ilwis-operations",false); QStringList lst; lst << location.toString(); res.addProperty("locations", lst); res.addProperty("type", "operation" ); res.addProperty("filter",QString("(type=%1 or type=%2)").arg(itSINGLEOPERATION).arg(itWORKFLOW)); res.setDescription(descr); setView(CatalogView(res)); location = QUrl("ilwis://operations"); descr ="main catalog for ilwis services"; res = Resource(location, itCATALOGVIEW ) ; res.name("ilwis-services",false); lst.clear(); lst << location.toString(); res.addProperty("locations", lst); res.addProperty("type", "operation" ); res.addProperty("filter",QString("(type=%1 and keyword='service')").arg(itSINGLEOPERATION)); res.setDescription(descr); CatalogView view(res); view.prepare(); _services = view.items(); } }else { setView(currentModel->view()); } CatalogModel::gatherItems(); std::set<QString> keywordset; std::map<QString, std::vector<OperationModel *>> operationsByKey; for(auto item : _currentItems){ QString keywords = item->resource()["keyword"].toString(); if ( !(item->resource().ilwisType() & itOPERATIONMETADATA)) continue; if ( keywords.indexOf("internal") != -1) continue; _currentOperations.push_back(new OperationModel(item->resource(), this)); if ( keywords == sUNDEF) keywords = TR("Uncatagorized"); QStringList parts = keywords.split(","); for(auto keyword : parts){ keywordset.insert(keyword); } for(auto keyword : parts){ operationsByKey[keyword].push_back(new OperationModel(item->resource(), this)); } } _keywords.clear(); for(auto keyword : keywordset) _keywords.push_back(keyword); qSort(_keywords.begin(), _keywords.end()); _keywords.push_front(""); // all for(auto operation : operationsByKey){ _operationsByKey.push_back(new OperationsByKeyModel(operation.first, operation.second, this)); } }