📄 projectmanager.cpp
字号:
QString cleTmp = toKey( tmp->data(0,Qt::UserRole) ); QString indent; for (int i=0; i<nbSpace; i++) indent += " "; if ( cleTmp == "SCOPE" || cleTmp == "PROJECT" ) nomScope = indent + tmp->text(0) + ":" + nomScope.simplified(); if ( cleTmp == "PROJECT" ) break; tmp = tmp->parent(); nbSpace++; } window->comboProjects->addItem( nomScope, addressToVariant(listeScope.at(nbScope))); if ( listeScope.at(nbScope) == it ) window->comboProjects->setCurrentIndex( window->comboProjects->count()-1); } } } // if ( window->comboProjects->count() == 1 ) window->comboProjects->setEnabled( false ); window->slotComboProjects( window->comboProjects->currentText() ); QVariant variant; QString filename; QString repCreation; window->slotFileType(); if ( window->exec() == QDialog::Accepted ) { QString line = window->filename->text(); filesList = line.split(","); repCreation = window->location->text(); variant = window->comboProjects->itemData( window->comboProjects->currentIndex() ); delete window; } else { delete window; return; } QTreeWidgetItem *item = (QTreeWidgetItem*)variantToItem(variant); projectDir = projectDirectory( item ); setQmake( projectFilename( item ) ); foreach(QString filename, filesList) { absoluteFilename = repCreation+"/"+filename.remove("\"").simplified(); QDir( projectDir ).mkdir( repCreation ); filename = QDir(projectDir).relativeFilePath(absoluteFilename).replace("\\", "/"); QFile file ( absoluteFilename ); if ( file.exists() ) { QMessageBox::warning(0, "QDevelop", tr("The file already exists in directory."), tr("Cancel") ); return; } QByteArray templateData; if ( absoluteFilename.section(".", -1, -1) == "ui" ) { // set a default content for UI files QStringList items; items << "QDialog" << "QMainWindow" << "QWidget"; bool ok; QString item = QInputDialog::getItem(0, "QDevelop", tr("Forms:"), items, 0, false, &ok); if (ok && !item.isEmpty()) { QString templateName; if ( item == "QDialog" ) templateName = ":/templates/templates/dialog.ui"; else if ( item == "QMainWindow" ) templateName = ":/templates/templates/mainwindow.ui"; else templateName = ":/templates/templates/widget.ui"; QFile templateFile(templateName); templateFile.open(QIODevice::ReadOnly); templateData = templateFile.readAll(); templateFile.close(); } else return; } else if ( filename.section(".", -1, -1) == "h" ) { // add a default content for *.h files QString defString = filename.toUpper().section("/", -1, -1); // filter out bad chars int j = defString.length(); for ( int i=0; i < j; i++ ) { if (!defString[i].isLetterOrNumber()) defString[i] = '_'; } // leading _ are because the file name can start with a digit, // while an identifier on C/C++ can not // trailing _ are for fun templateData.append( QString("#ifndef __%1__\n").arg( defString ) ); templateData.append( QString("#define __%1__\n").arg( defString ) ); templateData.append( QString("\n// place your code here\n\n") ); templateData.append( QString("#endif // __%1__\n").arg( defString ) ); } else if ((filename.section(".", -1, -1) == "c" ) || (filename.section(".", -1, -1) == "cpp" ) ) { // user added 2 files to the project, which means // source + header // lets assume users do not put "," in the file name if (filesList.count() != 1) { QString includeFile = filename.left( filename.lastIndexOf(".") ) + ".h"; includeFile = includeFile.section("/", -1, -1); templateData.append( QString("#include \"%1\"\n\n").arg( includeFile ) ); } templateData.append( QString("// place your code here\n") ); } // The (.ts) file must be created by lupdate only if ( filename.section(".", -1, -1) != "ts" ) { if ( !file.open(QIODevice::WriteOnly | QIODevice::Text) ) { QMessageBox::warning(0, "QDevelop", tr("Unable to create file."), tr("Cancel") ); return; } if (!templateData.isEmpty ()) { file.write( templateData ); } file.close(); } insertFile(item, filename); // If it's a (.ts) file, save the project then call lupdate to create the file on disk. if ( filename.section(".", -1, -1) == "ts" ) { slotSaveProject(); slotlupdate(item); } } m_isModifiedProject = true; m_parent->configureCompletion( projectDirectory(m_treeFiles->topLevelItem( 0 ) ) );}//bool ProjectManager::listContains(QList<QTreeWidgetItem *>list, QString name, findMode type){ for (int i=0; i < list.count(); i++) { if ( (type==Data && list.at( i )->text(0)==name) ) return true; else if (type==Key && toKey( list.at( i )->data(0, Qt::UserRole) )==name) return true; } return false;}//void ProjectManager::insertFile(QTreeWidgetItem *it, QString filename, bool silentMode){ filename = filename.remove("\"").simplified(); if ( filename.isEmpty() ) return; QString kindFile = filename.toLower().section(".", -1, -1); QTreeWidgetItem *newItem; if ( ( newItem = item(it, filename, Data) ) ) { if ( !silentMode) QMessageBox::warning(0, "QDevelop", tr("The file already exists."), tr("Cancel") ); //return; } else { if ( !QString("ui|cpp|h|qrc|ts").contains( kindFile ) ) { if ( !silentMode) QMessageBox::warning(0, "QDevelop", tr("This file is not permitted."), tr("Ok") ); return; } QString parentKey; if ( kindFile == "ui" ) parentKey = "FORMS"; else if ( kindFile == "cpp" ) { parentKey = "SOURCES"; } else if ( kindFile == "h" ) { parentKey = "HEADERS"; } else if ( kindFile == "qrc" ) parentKey = "RESOURCES"; else if ( kindFile == "ts" ) parentKey = "TRANSLATIONS"; // Le file de type "DATA" doit re contenu dans une clcorrespondant au type de file QTreeWidgetItem *parent = 0; for (int i=0; i<it->childCount(); i++) { if ( toKey( it->child( i )->data(0, Qt::UserRole) ) == parentKey ) { parent = it->child( i ); break; } } if ( !parent ) parent = insertItem(it, parentKey, parentKey, "+="); newItem = insertItem(parent, "DATA", filename); // do { m_treeFiles->setItemExpanded(parent, true ); } while ( (parent = parent->parent()) ); } // if ( kindFile == "cpp" || kindFile == "h") { QString projectDir = projectDirectory(newItem); QString absoluteName = QDir(projectDir+"/"+filename).absolutePath(); QFile file(absoluteName); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { QString buffer = file.readAll(); file.close(); QStringList parentsList = parents(newItem); m_treeClasses->updateClasses(absoluteName, buffer, parentsList, "."+kindFile); } }}void ProjectManager::slotAddSubProject(QTreeWidgetItem *it){ if ( !it ) it = m_treeFiles->currentItem(); if ( !it ) it = m_treeFiles->topLevelItem( 0 ); NewProjectImpl *window = new NewProjectImpl(m_parent, projectDirectory(it->text(0))); window->setWindowTitle( tr("Sub-project creation") ); window->parentProjectName->setText( it->text(0) ); if ( window->exec() == QDialog::Accepted ) { setQmake( projectFilename( it ) ); QString filename = window->filename(); bool continuer = true; QList<QTreeWidgetItem *> listeTemplate; childsList(it, "TEMPLATE", listeTemplate); if ( listeTemplate.count() ) { for (int nbTemplate=0; nbTemplate < listeTemplate.first()->childCount(); nbTemplate++) { if ( listeTemplate.first()->child(nbTemplate)->text(0) == "subdirs" ) { continuer = false; } } } while ( continuer ) { continuer = false; for (int i=0; i<it->childCount(); i++) { if ( !QString("absoluteNameProjectFile:projectDirectory").contains( toKey( it->child( i )->data(0,Qt::UserRole) ) ) ) { delete it->child( i ); continuer = true; } } } if ( !item(it, "TEMPLATE", Key ) ) insertItem( insertItem(it, "TEMPLATE", "TEMPLATE", "="), "DATA", "subdirs" ); QTreeWidgetItem *itSubdir = item(it, "SUBDIRS", Key); if ( !itSubdir ) itSubdir = insertItem(it, "SUBDIRS", "SUBDIRS", "="); itSubdir->setText(0, tr("Sub-Projects")); QTreeWidgetItem *subProjectItem = insertItem(itSubdir, "PROJECT", filename); insertItem(subProjectItem, "qmake", "1"); insertItem(subProjectItem, "absoluteNameProjectFile", window->absoluteProjectName()); insertItem(subProjectItem, "projectDirectory", window->location->text() + "/" + QFileInfo(window->projectName->text()).baseName()); insertItem(subProjectItem, "subProjectName", filename.left(filename.lastIndexOf("."))); loadProject(window->absoluteProjectName(), subProjectItem); QTreeWidgetItem *itProject = itemProject( window->filename() ); setSrcDirectory(itProject, window->srcDirectory->text()); setUiDirectory(itProject, window->uiDirectory->text()); //m_parent->configureCompletion( projectDirectory(m_treeFiles->topLevelItem( 0 ) ) ); m_parent->configureCompletion( projectDirectory( window->location->text() + "/" + QFileInfo(window->projectName->text()).baseName() ) ); } delete window;}//void ProjectManager::slotProjectPropertie(QTreeWidgetItem *it){ if ( !it ) it = m_treeFiles->currentItem(); while ( it && toKey( it->data(0,Qt::UserRole) ) != "PROJECT" ) it = it->parent(); if ( !it ) it = m_treeFiles->topLevelItem( 0 ); QString projectName = projectFilename(it); ; ProjectPropertieImpl *window = new ProjectPropertieImpl(this, m_treeFiles, it); if ( window->exec() == QDialog::Accepted ) { m_isModifiedProject = true; setQmake(projectName); setSrcDirectory(itemProject(projectName), window->srcDirectory->text() ); setUiDirectory(itemProject(projectName), window->uiDirectory->text() ); } delete window;}//void ProjectManager::slotAddScope(QTreeWidgetItem *it){ if ( !it ) it = m_treeFiles->currentItem(); if ( !it ) it = m_treeFiles->topLevelItem( 0 ); QString projectName; AddScopeImpl *window = new AddScopeImpl(this); QList<QTreeWidgetItem *> projectsList; childsList(0, "PROJECT", projectsList); for (int nbProjects=0; nbProjects < projectsList.count(); nbProjects++) { projectName = projectsList.at(nbProjects)->text(0); //projectDir = data(projectName, "projectDirectory"); QList<QTreeWidgetItem *> listeTemplate; bool ajouter = true; for (int enfant=0; enfant<projectsList.at(nbProjects)->childCount(); enfant++) { ajouter = true; if ( toKey( projectsList.at(nbProjects)->child(enfant)->data(0,Qt::UserRole) ) == "TEMPLATE") { QTreeWidgetItem *itTemplate = projectsList.at(nbProjects)->child(enfant); for (int nbTemplate=0; nbTemplate < itTemplate->childCount(); nbTemplate++) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -