bool ModelManager::loadSnapshot( const Snapshot& ss1, const Snapshot& ss2, const Snapshot& ss3, const Snapshot& ss4, double c1, double c2, double c3, double c4 ){ const int N = 4; Snapshot::const_iterator it[N] = {ss1.begin(), ss2.begin(), ss3.begin(), ss4.begin()}; double cs[N] = {c1,c2,c3,c4}; while(ss1.end() != it[0] && ss2.end() != it[1] && ss3.end() != it[2] && ss4.end() != it[3]){ /* First, sort strings into A <= B <= C <= D if(A == B && B == C && C == D){ interpolate ++itA; ++itB; ++itC; ++itD; } else if(C != D) ++itA; ++itB; ++itC; else if(B != C) ++itA; ++itB; else if(A != B) ++itA; */ int sort[N]; // = 0, 1, 2, ..., N-1 for(int i=0;i<N;++i) sort[i]=i; // do a shell sort int cmp13 = it[sort[0]]->first.compare(it[sort[2]]->first); int cmp24 = it[sort[1]]->first.compare(it[sort[3]]->first); if(cmp13 > 0) std::swap(sort[0], sort[2]); if(cmp24 > 0) std::swap(sort[1], sort[3]); int cmpAB = it[sort[0]]->first.compare(it[sort[1]]->first); int cmpCD = it[sort[2]]->first.compare(it[sort[3]]->first); if(cmpAB > 0) std::swap(sort[0], sort[1]); if(cmpCD > 0) std::swap(sort[2], sort[3]); int cmpBC = it[sort[1]]->first.compare(it[sort[2]]->first); if(cmpAB==0 && cmpBC==0 && cmpCD==0){ NamedModels::const_iterator itState = mState.find(it[0]->first); if(mState.end() != itState){ // found model with this id, lock and load! const Data * D[N]; for(int i=0; i<N; ++i) D[i] = &(it[i]->second); Data temp = *D[0]; temp.clone(); temp.mix<N>(D, cs); itState->second->setData(temp); } for(int i=0;i<N;++i) ++(it[i]); } else if(cmpCD){ for(int i=0;i<N-1;++i) ++(it[i]); } else if(cmpBC){ for(int i=0;i<N-2;++i) ++(it[i]); } else if(cmpAB){ for(int i=0;i<N-3;++i) ++(it[i]); } } return true; }
static ClassDocumentPtrPair findClassRecursively(const LookupContext &context, const QString &className, unsigned maxIncludeDepth, QString *namespaceName) { const Document::Ptr doc = context.thisDocument(); const Snapshot docTable = context.snapshot(); if (Designer::Constants::Internal::debug) qDebug() << Q_FUNC_INFO << doc->fileName() << className << maxIncludeDepth; // Check document if (const Class *cl = findClass(doc->globalNamespace(), context, className, namespaceName)) return ClassDocumentPtrPair(cl, doc); if (maxIncludeDepth) { // Check the includes const unsigned recursionMaxIncludeDepth = maxIncludeDepth - 1u; const auto includedFiles = doc->includedFiles(); for (const QString &include : includedFiles) { const Snapshot::const_iterator it = docTable.find(include); if (it != docTable.end()) { const Document::Ptr includeDoc = it.value(); LookupContext context(includeDoc, docTable); const ClassDocumentPtrPair irc = findClassRecursively(context, className, recursionMaxIncludeDepth, namespaceName); if (irc.first) return irc; } } } return ClassDocumentPtrPair(0, Document::Ptr()); }
void QueryResultsNode::update(Snapshot &updates) { typedef QMap<QueryResultItem *, Union> Map; qint32 lastColumn = columnCount(QModelIndex()) - 1; QueryResultPropertyItem *property; QueryResultItem *item; Map map; for (Snapshot::iterator i = updates.begin(), end = updates.end(); i != end; i = updates.erase(i)) { item = (*i).first.as<QueryResultItem>(); property = static_cast<QueryResultPropertyItem *>(item->parent()); map[property].add(property->indexOf(item)); if (item->size()) { beginRemoveRows(Model::index(item), 0, item->size() - 1); static_cast<QueryResultRootPathValueItem *>(item)->update((*i).second); endRemoveRows(); } else static_cast<QueryResultRootPathValueItem *>(item)->update((*i).second); static_cast<QueryResultValueItem *>(item)->unlock(); } for (Map::const_iterator i = map.constBegin(), end = map.constEnd(); i != end; ++i) for (Union::List::size_type q = 0, size = (*i).size(); q < size; ++q) emit dataChanged(createIndex((*i).at(q).top(), 0, i.key()->at((*i).at(q).top())), createIndex((*i).at(q).bottom(), lastColumn, i.key()->at((*i).at(q).bottom()))); }
//----------------------------------------------------------------------- bool OperatorManager::checkSnapshot(const Snapshot& snapshot) const { GroupMap::const_iterator itGroup = mGroups.begin(); Snapshot::const_iterator itSnapshot = snapshot.begin(); while (itGroup != mGroups.end()) { const Group* group = itGroup->second; if (!group->getUndoOperators().empty()) { if (itSnapshot == snapshot.end()) return false; if (itGroup->first != itSnapshot->first) return false; if (group->getUndoOperators().front()->getTimestamp() != itSnapshot->second) return false; ++itSnapshot; } ++itGroup; } return itSnapshot == snapshot.end(); }
bool ModelManager::loadSnapshot(const Snapshot& ss1, const Snapshot& ss2, double c1, double c2){ Snapshot::const_iterator it1 = ss1.begin(); Snapshot::const_iterator it2 = ss2.begin(); while(ss1.end() != it1 && ss2.end() != it2){ const std::string& id1 = it1->first; const std::string& id2 = it2->first; int cmp = id1.compare(id2); if(0 == cmp){ // ids match, attempt interpolation NamedModels::const_iterator itState = mState.find(id1); if(mState.end() != itState){ // found model with this id, lock and load! const Data& data1 = it1->second; const Data& data2 = it2->second; Data temp = data1; temp.clone(); temp.mix(data1, data2, c1, c2); itState->second->setData(temp); } ++it1; ++it2; } else if(cmp < 0){ // first id less than second id ++it1; // let first iterator catch up with second } else{ // first id greater than second id ++it2; // let second iterator catch up with first } } return true; }
bool DependencyTable::isValidFor(const Snapshot &snapshot) const { const int documentCount = snapshot.size(); if (documentCount != files.size()) return false; for (Snapshot::const_iterator it = snapshot.begin(); it != snapshot.end(); ++it) { QHash<QString, QStringList>::const_iterator i = includesPerFile.find(it.key()); if (i == includesPerFile.end()) return false; if (i.value() != it.value()->includedFiles()) return false; } return true; }
void QueryResultsNode::unlock(const Snapshot &snapshot) { typedef QMap<QueryResultItem *, Union> Map; qint32 lastColumn = columnCount(QModelIndex()) - 1; QueryResultPropertyItem *property; Map map; for (Snapshot::const_iterator i = snapshot.begin(), end = snapshot.end(); i != end; ++i) { property = static_cast<QueryResultPropertyItem *>((*i).first->parent()); map[property].add(property->indexOf((*i).first.data())); (*i).first.as<QueryResultValueItem>()->unlock(); } for (Map::const_iterator i = map.constBegin(), end = map.constEnd(); i != end; ++i) for (Union::List::size_type q = 0, size = (*i).size(); q < size; ++q) emit dataChanged(createIndex((*i).at(q).top(), 0, i.key()->at((*i).at(q).top())), createIndex((*i).at(q).bottom(), lastColumn, i.key()->at((*i).at(q).bottom()))); }
void DependencyTable::build(const Snapshot &snapshot) { includesPerFile.clear(); files.clear(); fileIndex.clear(); includes.clear(); includeMap.clear(); const int documentCount = snapshot.size(); files.resize(documentCount); includeMap.resize(documentCount); int i = 0; for (Snapshot::const_iterator it = snapshot.begin(); it != snapshot.end(); ++it, ++i) { files[i] = it.key(); fileIndex[it.key()] = i; } for (int i = 0; i < files.size(); ++i) { const QString fileName = files.at(i); if (Document::Ptr doc = snapshot.document(files.at(i))) { QBitArray bitmap(files.size()); QList<int> directIncludes; const QStringList documentIncludes = doc->includedFiles(); includesPerFile.insert(fileName, documentIncludes); foreach (const QString &includedFile, documentIncludes) { int index = fileIndex.value(includedFile); if (index == -1) continue; else if (! directIncludes.contains(index)) directIncludes.append(index); bitmap.setBit(index, true); } includeMap[i] = bitmap; includes[i] = directIncludes; }
bool QtCreatorIntegration::navigateToSlot(const QString &objectName, const QString &signalSignature, const QStringList ¶meterNames, QString *errorMessage) { typedef QMap<int, Document::Ptr> DocumentMap; const Utils::FileName currentUiFile = FormEditorW::activeEditor()->document()->filePath(); #if 0 return Designer::Internal::navigateToSlot(currentUiFile.toString(), objectName, signalSignature, parameterNames, errorMessage); #endif // TODO: we should pass to findDocumentsIncluding an absolute path to generated .h file from ui. // Currently we are guessing the name of ui_<>.h file and pass the file name only to the findDocumentsIncluding(). // The idea is that the .pro file knows if the .ui files is inside, and the .pro file knows it will // be generating the ui_<>.h file for it, and the .pro file knows what the generated file's name and its absolute path will be. // So we should somehow get that info from project manager (?) const QFileInfo fi = currentUiFile.toFileInfo(); const QString uiFolder = fi.absolutePath(); const QString uicedName = "ui_" + fi.completeBaseName() + ".h"; // Retrieve code model snapshot restricted to project of ui file or the working copy. Snapshot docTable = CppTools::CppModelManager::instance()->snapshot(); Snapshot newDocTable; const Project *uiProject = SessionManager::projectForFile(currentUiFile); if (uiProject) { for (Snapshot::const_iterator i = docTable.begin(), ei = docTable.end(); i != ei; ++i) { const Project *project = SessionManager::projectForFile(i.key()); if (project == uiProject) newDocTable.insert(i.value()); } } else { const CppTools::WorkingCopy workingCopy = CppTools::CppModelManager::instance()->workingCopy(); const Utils::FileName configFileName = Utils::FileName::fromString(CppTools::CppModelManager::configurationFileName()); QHashIterator<Utils::FileName, QPair<QByteArray, unsigned> > it = workingCopy.iterator(); while (it.hasNext()) { it.next(); const Utils::FileName &fileName = it.key(); if (fileName != configFileName) newDocTable.insert(docTable.document(fileName)); } } docTable = newDocTable; // take all docs, find the ones that include the ui_xx.h. // Sort into a map, putting the ones whose path closely matches the ui-folder path // first in case there are project subdirectories that contain identical file names. const QList<Document::Ptr> docList = findDocumentsIncluding(docTable, uicedName, true); // change to false when we know the absolute path to generated ui_<>.h file DocumentMap docMap; for (const Document::Ptr &d : docList) { const QFileInfo docFi(d->fileName()); docMap.insert(qAbs(docFi.absolutePath().compare(uiFolder, Qt::CaseInsensitive)), d); } if (Designer::Constants::Internal::debug) qDebug() << Q_FUNC_INFO << objectName << signalSignature << "Looking for " << uicedName << " returned " << docList.size(); if (docMap.isEmpty()) { *errorMessage = tr("No documents matching \"%1\" could be found.\nRebuilding the project might help.").arg(uicedName); return false; } QDesignerFormWindowInterface *fwi = FormEditorW::activeWidgetHost()->formWindow(); const QString uiClass = uiClassName(fwi->mainContainer()->objectName()); if (Designer::Constants::Internal::debug) qDebug() << "Checking docs for " << uiClass; // Find the class definition (ui class defined as member or base class) // in the file itself or in the directly included files (order 1). QString namespaceName; const Class *cl = 0; Document::Ptr doc; for (const Document::Ptr &d : qAsConst(docMap)) { LookupContext context(d, docTable); const ClassDocumentPtrPair cd = findClassRecursively(context, uiClass, 1u , &namespaceName); if (cd.first) { cl = cd.first; doc = cd.second; break; } } if (!cl) { *errorMessage = msgClassNotFound(uiClass, docList); return false; } Overview o; const QString className = namespaceName + o.prettyName(cl->name()); if (Designer::Constants::Internal::debug) qDebug() << "Found class " << className << doc->fileName(); const QString functionName = "on_" + objectName + '_' + signalSignature; const QString functionNameWithParameterNames = addParameterNames(functionName, parameterNames); if (Designer::Constants::Internal::debug) qDebug() << Q_FUNC_INFO << "Found " << uiClass << doc->fileName() << " checking " << functionName << functionNameWithParameterNames; int line = 0; Document::Ptr sourceDoc; if (Function *fun = findDeclaration(cl, functionName)) { sourceDoc = findDefinition(fun, &line); if (!sourceDoc) { // add function definition to cpp file sourceDoc = addDefinition(docTable, doc->fileName(), className, functionNameWithParameterNames, &line); } } else { // add function declaration to cl CppTools::WorkingCopy workingCopy = CppTools::CppModelManager::instance()->workingCopy(); const QString fileName = doc->fileName(); getParsedDocument(fileName, workingCopy, docTable); addDeclaration(docTable, fileName, cl, functionNameWithParameterNames); // add function definition to cpp file sourceDoc = addDefinition(docTable, fileName, className, functionNameWithParameterNames, &line); } if (!sourceDoc) { *errorMessage = tr("Unable to add the method definition."); return false; } // jump to function definition, position within code Core::EditorManager::openEditorAt(sourceDoc->fileName(), line + 2, indentation); return true; }