void FolderNode::addFileNodes(const QList<FileNode *> &files) { Q_ASSERT(projectNode()); ProjectNode *pn = projectNode(); if (files.isEmpty()) return; foreach (NodesWatcher *watcher, pn->watchers()) emit watcher->filesAboutToBeAdded(this, files); foreach (FileNode *file, files) { QTC_ASSERT(!file->parentFolderNode(), qDebug("File node has already a parent folder")); file->setParentFolderNode(this); file->setProjectNode(pn); // Now find the correct place to insert file if (m_fileNodes.count() == 0 || m_fileNodes.last() < file) { // empty list or greater then last node m_fileNodes.append(file); } else { QList<FileNode *>::iterator it = qLowerBound(m_fileNodes.begin(), m_fileNodes.end(), file); m_fileNodes.insert(it, file); } }
void ProjectModel::finishSingleMetadataUpdate(ThreadWeaver::Job* _job) { UpdateStatsJob* job = static_cast<UpdateStatsJob*>(_job); if (job->m_status != 0) { delete job; return; } const KFileMetaInfo& info=job->m_info.first(); QModelIndex index = indexForUrl(info.url()); if (!index.isValid()) return; ProjectNode* node = nodeForIndex(index); node->setFileStats(job->m_info.first()); updateDirStats(nodeForIndex(index.parent())); QModelIndex topLeft = index.sibling(index.row(), Graph); QModelIndex bottomRight = index.sibling(index.row(), ProjectModelColumnCount - 1); emit dataChanged(topLeft, bottomRight); delete job; }
void ProjectManager::loadProjectState( int argc, char **argv ) { QSettings s; s.beginGroup("LoadedProjects"); int projCount = s.beginReadArray("Projects"); for(int p =0; p < projCount; p++) { s.setArrayIndex(p); QString projName = s.value("Name").toString(); ProjectNode * projNode = new ProjectNode(projName); rootNode->addChild(projNode); QStringList l; for( int i( 0 ); i < argc; ++i ) l << argv[i]; projNode->setCommandLine( l ); int size = s.beginReadArray("files"); for(int i=0; i < size; i++) { s.setArrayIndex(i); QString file( s.value("name").toString() ); projNode->addFile( file ); } s.endArray(); } s.endArray(); s.endGroup(); }
void ProjectManager::storeProjectState() { QSettings s; s.remove("LoadedProjects"); s.beginGroup("LoadedProjects"); s.beginWriteArray("Projects"); for(int p=0; p<rootNode->childrenCount(); p++) { ProjectNode * projNode = dynamic_cast<ProjectNode*>(rootNode->child(p)); s.setArrayIndex(p); s.setValue("Name",projNode->getName()); SgProject * sgProj = projNode->getSgProject(); s.beginWriteArray("files"); for(int i=0; i < sgProj->numberOfFiles(); i++) { QString name = (*sgProj)[i]->getFileName().c_str(); s.setArrayIndex(i); s.setValue("name",name); } s.endArray(); } s.endArray(); //Projects s.endGroup(); }
void BinaryFileNode::submitFrontendTask() { ProjectNode * pn = dynamic_cast<ProjectNode*>(getParent()->getParent() ); Q_ASSERT(pn); frontendTask = new RoseFrontendTask( pn->getSgProject(), path ); connect( frontendTask, SIGNAL( finished() ), SLOT( frontendTaskFinished() ) ); ProjectManager::instance()->taskListWidget()->submitTask(frontendTask); }
void BinaryFileNode::rebuild() { ProjectNode * pn = dynamic_cast<ProjectNode*>(getParent()->getParent() ); deleteFileFromProject(sgBinaryComposite,pn->getSgProject()); sgBinaryComposite=NULL; if(sourceFiles.isEmpty()) submitFrontendTask(); else submitCompileTask(); }
void SourceFileNode::rebuild() { ProjectNode * pn = dynamic_cast<ProjectNode*>(getParent()->getParent() ); Q_ASSERT(pn); deleteFileFromProject(sgSourceFile,pn->getSgProject()); sgSourceFile = NULL; task = new RoseFrontendTask(pn->getSgProject(),path); connect(task,SIGNAL(finished()), SLOT(buildTaskFinished())); ProjectManager::instance()->taskListWidget()->submitTask(task); }
void ProjectTreeWidget::foldersAboutToBeRemoved(FolderNode *, const QList<FolderNode*> &list) { Node *n = m_explorer->currentNode(); while (n) { if (FolderNode *fn = qobject_cast<FolderNode *>(n)) { if (list.contains(fn)) { ProjectNode *pn = n->projectNode(); // Make sure the node we are switching too isn't going to be removed also while (list.contains(pn)) pn = pn->parentFolderNode()->projectNode(); m_explorer->setCurrentNode(pn); break; } } n = n->parentFolderNode(); } }
void ResourceHandler::updateResources() { ensureInitialized(); const QString fileName = m_form->fileName(); QTC_ASSERT(!fileName.isEmpty(), return) if (Designer::Constants::Internal::debug) qDebug() << "ResourceHandler::updateResources()" << fileName; ProjectExplorer::ProjectExplorerPlugin *pe = ProjectExplorer::ProjectExplorerPlugin::instance(); // filename could change in the meantime. ProjectExplorer::Project *project = pe->session()->projectForFile(fileName); // Does the file belong to a project? if (project) { // Collect project resource files. ProjectNode *root = project->rootProjectNode(); QrcFilesVisitor qrcVisitor; root->accept(&qrcVisitor); const QStringList projectQrcFiles = qrcVisitor.qrcFiles(); #if QT_VERSION >= 0x050000 m_form->activateResourceFilePaths(projectQrcFiles); m_form->setResourceFileSaveMode(QDesignerFormWindowInterface::SaveOnlyUsedResourceFiles); #else m_form->resourceSet()->activateQrcPaths(projectQrcFiles); m_form->setSaveResourcesBehaviour(qdesigner_internal::FormWindowBase::SaveOnlyUsedQrcFiles); #endif if (Designer::Constants::Internal::debug) qDebug() << "ResourceHandler::updateResources()" << fileName << " associated with project" << project->rootProjectNode()->path() << " using project qrc files" << projectQrcFiles.size(); } else { // Use resource file originally used in form #if QT_VERSION >= 0x050000 m_form->activateResourceFilePaths(m_originalUiQrcPaths); m_form->setResourceFileSaveMode(QDesignerFormWindowInterface::SaveAllResourceFiles); #else m_form->resourceSet()->activateQrcPaths(m_originalUiQrcPaths); m_form->setSaveResourcesBehaviour(qdesigner_internal::FormWindowBase::SaveAll); #endif if (Designer::Constants::Internal::debug) qDebug() << "ResourceHandler::updateResources()" << fileName << " not associated with project, using loaded qrc files."; } }
static ProjectNode *updateCMakeInputs(CMakeListsNode *root, const Utils::FileName &sourceDir, const Utils::FileName &buildDir, QList<FileNode *> &sourceInputs, QList<FileNode *> &buildInputs, QList<FileNode *> &rootInputs) { const bool hasInputs = !sourceInputs.isEmpty() || !buildInputs.isEmpty() || !rootInputs.isEmpty(); ProjectNode *cmakeVFolder = root->projectNode(CMakeInputsNode::inputsPathFromCMakeListsPath(root->filePath())); if (!cmakeVFolder) { if (hasInputs) { cmakeVFolder = new CMakeInputsNode(root->filePath()); root->addProjectNodes({ cmakeVFolder }); } } else { if (!hasInputs) root->removeProjectNodes({ cmakeVFolder }); } if (!hasInputs) return nullptr; QList<FolderNode *> toKeep; toKeep.append(setupCMakeVFolder(cmakeVFolder, sourceDir, 1000, QCoreApplication::translate("CMakeProjectManager::Internal", "<Source Directory>"), sourceInputs)); toKeep.append(setupCMakeVFolder(cmakeVFolder, buildDir, 100, QCoreApplication::translate("CMakeProjectManager::Internal", "<Build Directory>"), buildInputs)); toKeep.append(setupCMakeVFolder(cmakeVFolder, Utils::FileName(), 10, QCoreApplication::translate("CMakeProjectManager::Internal", "<Other Locations>"), rootInputs)); // Clean out unused nodes in "CMake Files": const QList<FolderNode *> tmp = filtered(cmakeVFolder->folderNodes(), [&toKeep](FolderNode *fn) { return !toKeep.contains(fn); }); cmakeVFolder->removeFolderNodes(tmp); return cmakeVFolder; }
void ProjectTree::emitFoldersAboutToBeRemoved(FolderNode *parentFolder, const QList<FolderNode *> &staleFolders) { if (!isInNodeHierarchy(parentFolder)) return; Node *n = ProjectTree::currentNode(); while (n) { if (FolderNode *fn = n->asFolderNode()) { if (staleFolders.contains(fn)) { ProjectNode *pn = n->projectNode(); // Make sure the node we are switching too isn't going to be removed also while (staleFolders.contains(pn)) pn = pn->parentFolderNode()->projectNode(); m_resetCurrentNodeFolder = true; break; } } n = n->parentFolderNode(); } emit foldersAboutToBeRemoved(parentFolder, staleFolders); }
/** * we use QRect to pass data through QVariant tunnel * * order is tran, untr, fuzzy * left() top() width() * */ QVariant ProjectModel::data(const QModelIndex& index, int role) const { if (!index.isValid()) return QVariant(); const ProjectModelColumns& column=(ProjectModelColumns)index.column(); ProjectNode* node = nodeForIndex(index); QModelIndex internalIndex = poOrPotIndexForOuter(index); if (!internalIndex.isValid()) return QVariant(); KFileItem item=itemForIndex(index); bool isDir = item.isDir(); int translated = node->translatedAsPerRole(); int fuzzy = node->fuzzyAsPerRole(); int untranslated = node->untranslated; bool hasStats = translated != -1; switch(role) { case Qt::DisplayRole: switch (column) { case FileName: return item.text(); case Graph: return hasStats?QRect(translated, untranslated, fuzzy, 0):QVariant(); case TotalCount: return hasStats?(translated + untranslated + fuzzy):QVariant(); case TranslatedCount:return hasStats?translated:QVariant(); case FuzzyCount: return hasStats?fuzzy:QVariant(); case UntranslatedCount:return hasStats?untranslated:QVariant(); case SourceDate: return node->sourceDate; case TranslationDate:return node->translationDate; case LastTranslator:return node->lastTranslator; default: return QVariant(); } case Qt::ToolTipRole: switch (column) { case FileName: return item.text(); default: return QVariant(); } case KDirModel::FileItemRole: return QVariant::fromValue(item); case Qt::DecorationRole: switch (column) { case FileName: if (isDir) return m_dirIcon; if (hasStats && fuzzy == 0 && untranslated == 0) return m_poComplIcon; else if (node->poRowNumber != -1) return m_poIcon; else if (node->potRowNumber != -1) return m_potIcon; default: return QVariant(); } case FuzzyUntrCountRole: return item.isFile()?(fuzzy + untranslated):0; case FuzzyCountRole: return item.isFile()?fuzzy:0; case UntransCountRole: return item.isFile()?untranslated:0; case TemplateOnlyRole: return item.isFile()?(node->poRowNumber == -1):0; case TransOnlyRole: return item.isFile()?(node->potRowNumber == -1):0; case TotalRole: return hasStats?(fuzzy + untranslated + translated):0; default: return QVariant(); } }