📄 projectmanager.cpp
字号:
// il doit devenir un projet normal de TEMPLATE app. if ( toKey( parent->data(0, Qt::UserRole) ) == "PROJECT" ) { bool subdirs = false; QTreeWidgetItem *itTemplate = item(parent, "TEMPLATE", Key); if ( itTemplate ) { QList<QTreeWidgetItem *> list; childsList(itTemplate, "DATA", list); for (int i=0; i<list.count(); i++) { if ( list.at( i )->text(0) == "subdirs" ) subdirs = true; } } if ( subdirs ) { QTreeWidgetItem *itTemplate = item(parent, "TEMPLATE", Key); if ( itTemplate ) delete itTemplate; itTemplate = insertItem(parent, "TEMPLATE", "TEMPLATE", "="); insertItem(itTemplate, "DATA", "app" ); } } m_parent->configureCompletion( projectDirectory(m_treeFiles->topLevelItem( 0 ) ) );}//void ProjectManager::loadProject(QString s, QTreeWidgetItem *newProjectItem){ QTreeWidgetItem *itemProject = newProjectItem; QFile file(s); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return; QString projectName = s.section("/",-1,-1); newProjectItem->setText(0, projectName); newProjectItem->setData(0, Qt::UserRole, toItem("PROJECT")); m_treeFiles->setItemExpanded(newProjectItem, true ); // // insertItem(newProjectItem, "absoluteNameProjectFile", s); insertItem(newProjectItem, "srcDirectory", ""); insertItem(newProjectItem, "uiDirectory", ""); QTreeWidgetItem *it; QString projectDirectory = QDir().absoluteFilePath(s).left( QDir().absoluteFilePath(s).lastIndexOf("/") ); insertItem(newProjectItem, "projectDirectory", projectDirectory); insertItem(newProjectItem, "qmake", "1"); QString key; QString data; bool toFollow = false; bool scope = false; while (!file.atEnd()) { QString line = QString( file.readLine() ); if ( !line.simplified().length() ) continue; if ( scope && !toFollow) { scope = false; newProjectItem = newProjectItem->parent(); } while ( !line.contains(QRegExp("\"")) && !line.contains(QRegExp("/")) && !line.simplified().contains(QRegExp("^#")) && line.indexOf(":")!=-1 && ( line.indexOf(":")<line.indexOf("=") || line.indexOf("=")==-1 ) ) { it = item(newProjectItem, line.section(":", 0, 0).simplified(), Data); if ( it && toKey( it->data(0, Qt::UserRole) ) == "SCOPE" ) newProjectItem = it; else newProjectItem = insertItem(newProjectItem, "SCOPE", line.section(":", 0, 0).simplified()); scope = true; line = line.section(":", 1); } if ( !line.simplified().contains(QRegExp("^#")) && !line.contains(QRegExp("\"")) && !line.contains(QRegExp("/")) && line.contains("{") ) { it = item(newProjectItem, line.section("{", 0, 0).simplified(), Data); if ( it && toKey( it->data(0, Qt::UserRole) ) == "SCOPE" ) newProjectItem = it; else newProjectItem = insertItem(newProjectItem, "SCOPE", line.section("{", 0, 0).simplified()); toFollow = true; continue; } if ( !line.simplified().contains(QRegExp("^#")) && !line.contains(QRegExp("\"")) && !line.contains(QRegExp("/")) && line.contains("}") ) { newProjectItem = newProjectItem->parent(); continue; } // if ( !line.simplified().contains(QRegExp("^#")) /*&& !line.contains(QRegExp("\""))*/ && line.contains("=") ) { QString operateur; if ( line.contains("+=") ) operateur = "+="; else if ( line.contains("-=") ) operateur = "-="; else if ( line.contains("*=") ) operateur = "*="; else if ( line.contains("~=") ) operateur = "~="; else operateur = "="; key = line.simplified().section(operateur, 0, 0).simplified(); data = line.simplified().section(operateur, 1).simplified(); toFollow = line.simplified().right(1) == "\\"; if ( data.simplified().right(1) == "\\" ) data = data.simplified().left( data.simplified().length()-1 ); QTreeWidgetItem *it = 0; for (int i=0; i<newProjectItem->childCount(); i++) { if ( toKey( newProjectItem->child( i )->data(0, Qt::UserRole) ) == key ) { it = newProjectItem->child( i ); break; } } if ( !it ) it = insertItem(newProjectItem, key, key, operateur); if ( key == "SUBDIRS" ) it->setText(0, tr("Sub-projects")); if ( toFollow ) newProjectItem = it; QString name; bool guillemet = false; data = data.simplified(); for (int i=0; i<data.length(); i++) { name += data[i]; if ( data[i] == '\"' ) { if ( !guillemet ) guillemet = true; else { insertItem(it, "DATA", name); name = ""; guillemet = false; } } if ( data[i] == ' ' && !guillemet ) { if ( name.simplified().length() ) { insertItem(it, "DATA", name.simplified()); } name = ""; } } if ( name.simplified().length() ) { insertItem(it, "DATA", name.simplified()); } } else if ( !line.simplified().contains(QRegExp("^#")) && !line.contains(QRegExp("\"")) && toFollow ) { data = line.simplified().section("\\", 0, 0).simplified(); foreach(QString name, data.simplified().split(" ")) { insertItem(newProjectItem, "DATA", name); } toFollow = line.simplified().right(1) == "\\"; if ( !toFollow ) newProjectItem = newProjectItem->parent(); } else if ( !line.simplified().contains(QRegExp("^#")) ) { QString function = line.simplified().section("\(", 0, 0).simplified(); data = line.simplified(); insertItem(newProjectItem, "DATA", data); } /*else //if ( line.contains(QRegExp("^#")) ) { insertItem(newProjectItem, "TEXTELIBRE", line); toFollow = false; }*/ // SUBDIRS loading for (int i=0; i<newProjectItem->childCount(); i++) { if ( toKey( newProjectItem->child( i )->data(0, Qt::UserRole) ) == "SUBDIRS" ) { QTreeWidgetItem *sub = newProjectItem->child( i ); m_treeFiles->setItemExpanded(sub, true ); for (int n=0; n<sub->childCount(); n++) { QString name = sub->child(n)->text(0); QString subDirName = QDir(projectDirectory+"/"+name).absolutePath(); QStringList filesList = QDir(subDirName).entryList(); foreach(QString newProjectName, filesList ) { if ( newProjectName.toLower().right(4) == ".pro" ) { loadProject(subDirName+"/"+newProjectName, sub->child( n )); insertItem(sub->child( n ), "subProjectName", name); } } } } } } // if ( findData(projectName, QString("TEMPLATE")).isEmpty() ) { QTreeWidgetItem *tmp = insertItem(itemProject, "TEMPLATE", "TEMPLATE", "="); insertItem(tmp, "DATA", "app"); } return;}//QTreeWidgetItem * ProjectManager::insertItem(QTreeWidgetItem *parent, QString key, QString data, QString op){ QString begin; if ( !op.isEmpty() && op != "=" && op != "+=" ) begin = op + " "; QTreeWidgetItem *it = new QTreeWidgetItem(parent); it->setText(0, data); it->setData(0, Qt::UserRole, toItem(key, op)); key = "|"+key+"|"; QString parentKey = "|"+toKey( it->parent()->data(0, Qt::UserRole) )+"|"; if ( !QString("|PROJECT|SUBDIRS|SOURCES|SCOPE|HEADERS|FORMS|TRANSLATIONS|RESOURCES|").contains(key) ) if (key!="|DATA|" || !QString("|PROJECT|SUBDIRS|SOURCES|SCOPE|HEADERS|FORMS|TRANSLATIONS|RESOURCES|").contains(parentKey) ) m_treeFiles->setItemHidden(it, true); if ( key == "|HEADERS|" ) { it->setText(0, begin + tr("Headers")); it->setIcon(0, QIcon(":/treeview/images/h.png")); } else if ( key == "|SOURCES|" ) { it->setText(0, begin + tr("Sources")); it->setIcon(0, QIcon(":/treeview/images/cpp.png")); } else if ( key == "|FORMS|" ) { it->setText(0, begin + tr("Dialogs")); it->setIcon(0, QIcon(":/treeview/images/designer.png")); } else if ( key == "|TRANSLATIONS|" ) { it->setText(0, begin + tr("Translations")); it->setIcon(0, QIcon(":/treeview/images/linguist.png")); } else if ( key == "|RESOURCES|" ) { it->setText(0, begin + tr("Resources")); it->setIcon(0, QIcon(":/treeview/images/qrc.png")); } QTreeWidgetItem *itemParent = it->parent(); bool hide = true; for (int i = 0; i < itemParent->childCount(); i++ ) if ( !m_treeFiles->isItemHidden(itemParent->child(i) ) ) hide = false; if ( hide && toKey( itemParent->data(0, Qt::UserRole) ) != "SCOPE" && toKey( itemParent->data(0, Qt::UserRole) ) != "PROJECT") m_treeFiles->setItemHidden(itemParent, true); else { do { m_treeFiles->setItemHidden(itemParent, false); } while ( (itemParent = itemParent->parent()) ); } return it;}//bool ProjectManager::slotSaveProject(){ if ( !isModifiedProject() ) return true; QTreeWidgetItem *itemProject = m_treeFiles->topLevelItem ( 0 ); bool ret = saveDataOfProject(itemProject, new QTextStream()); if ( ret ) { QTreeWidgetItem *it = item(m_treeFiles->topLevelItem ( 0 ), "PROJECT", Key); if ( !it ) return true; it = item(it, "absoluteNameProjectFile", Key); if ( !it ) return true; } m_isModifiedProject = false; return ret;}//bool ProjectManager::saveDataOfProject(QTreeWidgetItem *it, QTextStream *s, int nbSpace, QString endOfLine){ QTextStream *output = s; QString key = toKey( it->data(0, Qt::UserRole) ); QString op = toOp( it->data(0, Qt::UserRole) ); QString data = it->text(0); QString indent; for (int x=0; x<nbSpace; x++) indent += " "; QFile file; if ( (key == "PROJECT" && it != m_treeFiles->topLevelItem ( 0 ) ) ) { QString subProjectName = item(it, "subProjectName", Key)->text(0); *output << subProjectName + " "; *output << endOfLine; } if ( key == "PROJECT" ) { nbSpace = -1; QString absoluteName = item(it, "absoluteNameProjectFile", Key)->text(0); file.setFileName(absoluteName); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) return false; output = new QTextStream(&file); } else if ( key == "SCOPE" ) { *output << indent+data << " {\n"; if ( !it->childCount() ) { nbSpace--; for (int x=0; x<nbSpace; x++) indent += " "; *output << "\n" +indent + "}"; } } else if ( key == "DATA" ) { *output << indent+data; *output << endOfLine; } else if ( !QString("absoluteNameProjectFile:projectDirectory:subProjectName:qmake:uiDirectory:srcDirectory").contains(key) ) { *output << indent+key << " " + op; if ( !it->childCount() ) *output << "\n"; } for ( int i=0; i<it->childCount(); i++) { QString newEndLine = ""; if ( it->childCount() > 4 && i+1<it->childCount() ) newEndLine = " \\\n"; else if ( i+1 == it->childCount() ) newEndLine = "\n"; saveDataOfProject(it->child(i), ou
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -