📄 classbrowser.cpp
字号:
#include "classbrowser.h"#include "langdef.h"#include <qpixmap.h>#include <qfileinfo.h>#include <cstring>#include <cctype>#include <new>#include "cb_class.xpm"#include "cb_meth.xpm"#include "cb_pro_meth.xpm"#include "cb_pri_meth.xpm"////////////////////////////////////////////////////////// ClassBrowservoid ClassBrowser::enumerate(const char *src){ char *srccopy = new char[strlen(src)+2]; if (!srccopy) return; strcpy(srccopy, src); parse(srccopy); delete [] srccopy;}void ClassBrowser::enumerate(HideDocList *pDocList){ HideDoc doc; QFileInfo fi; CppBrowser cb(m_pTree); JavaBrowser jb(m_pTree); clear(); for (unsigned i=0; i < pDocList->getDocPaths().count(); i++) { doc = pDocList->getByPath(pDocList->getDocPaths()[i]); fi.setFile(doc.getName()); if (IS_CPP(fi.extension(0))) cb.enumerate(doc.getData()); else if (IS_JAVA(fi.extension(0))) jb.enumerate(doc.getData()); }}////////////////////////////////////////////////////////// CppBrowservoid CppBrowser::parse(char *src){ char *line = NULL, *nextline = NULL, *p = NULL; QListViewItem *item = NULL; line = strtok(src, "\n"); while (line) { nextline = &line[strlen(line)+1]; if ((p = strstr(line, "class ")) && ((*line == ' ') || (*line == 'c')) && strncmp(line, "//", 2)) { if ((p = strtok(p, "\x20"))) { if ((p = strtok(NULL, "\0"))) // This *should* be it... { // Ruff hax 4 now... if (strchr(p, '\x20')) *strchr(p, '\x20') = '\0'; if (!strchr(p, ';')) // Forward class decl? { item = new QListViewItem(m_pTree, m_pTree->lastItem()); item->setText(0, p); item->setPixmap(0, QPixmap(const_cast<const char **>(cb_class))); parseMethods(nextline, item, p); } } } } line = strtok(nextline, "\n"); }}void CppBrowser::parseMethods(const char *cls, QListViewItem *classnode, const char *name){ char *clscopy = new char[strlen(cls)+2]; QListViewItem *item = NULL; QPixmap pixAccess = QPixmap(const_cast<const char **>(cb_pri_meth)); char *line = NULL, *nextline = NULL, *p = NULL; unsigned ob = 0, cb = 0, level = 0; if (!clscopy) return; strcpy(clscopy, cls); line = strtok(clscopy, "\n"); while (line) { nextline = &line[strlen(line)+1]; if (strchr(line, '{')) { ob++; level++; } if (strchr(line, '}')) { cb++; level--; } if ((ob && cb) && ob == cb) break; if ((p = strstr(line, "//"))) *p = '\0'; if (strstr(line, "public:") || strstr(line, "public slots:")) pixAccess = QPixmap(const_cast<const char **>(cb_meth)); else if (strstr(line, "protected:") || strstr(line, "protected slots:")) pixAccess = QPixmap(const_cast<const char **>(cb_pro_meth)); else if (strstr(line, "private:") || strstr(line, "private slots:")) pixAccess = QPixmap(const_cast<const char **>(cb_pri_meth)); // Simple for now... if (strchr(line, '(') && strchr(line, ')') && (level == 1)) { p = strtok(line, ")"); for (unsigned i=0; i < strlen(p); i++) { if (isblank(p[i])) strcpy(&p[i], &p[i+1]); else break; } item = new QListViewItem(classnode); item->setText(0, (QString) p + ")"); item->setPixmap(0, pixAccess); } line = strtok(nextline, "\n"); } delete [] clscopy;}////////////////////////////////////////////////////////// JavaBrowservoid JavaBrowser::parse(char *src){ char *line = NULL, *nextline = NULL, *p = NULL; QListViewItem *item = NULL; line = strtok(src, "\n"); while (line) { nextline = &line[strlen(line)+1]; if ((strstr(line, "public class ") || strstr(line, "protected class ") || strstr(line, "private class ") || strstr(line, "public static class ") || strstr(line, "protected static class ") || strstr(line, "private static class ")) && strncmp(line, "//", 2)) { p = strstr(line, "class "); if ((p = strtok(p, "\x20"))) { if ((p = strtok(NULL, "\0"))) // This *should* be it... { // Ruff hax 4 now... if (strchr(p, '\x20')) *strchr(p, '\x20') = '\0'; if (!strchr(p, ';')) // Forward class decl? { item = new QListViewItem(m_pTree, m_pTree->lastItem()); item->setText(0, p); item->setPixmap(0, QPixmap(const_cast<const char **>(cb_class))); parseMethods(nextline, item, p); } } } } line = strtok(nextline, "\n"); }}void JavaBrowser::parseMethods(const char *cls, QListViewItem *classnode, const char *name){ char *clscopy = new char[strlen(cls)+2]; QListViewItem *item = NULL; QPixmap pixAccess = QPixmap(const_cast<const char **>(cb_pri_meth)); char *line = NULL, *nextline = NULL, *p = NULL; unsigned ob = 1, cb = 0; if (!clscopy) return; strcpy(clscopy, cls); line = strtok(clscopy, "\n"); while (line) { nextline = &line[strlen(line)+1]; if (strchr(line, '{')) ob++; if (strchr(line, '}')) cb++; if ((ob && cb) && ob == cb) break; if ((p = strstr(line, "//"))) *p = '\0'; // Simple for now... if (strchr(line, '(') && strchr(line, ')') && (strstr(line, name) || strstr(line, "public") || strstr(line, "protected") || strstr(line, "private"))) { if ((p = strstr(line, "public "))) { pixAccess = QPixmap(const_cast<const char **>(cb_meth)); p = strchr(p, ' '); line = &p[1]; } else if ((p = strstr(line, "protected "))) { pixAccess = QPixmap(const_cast<const char **>(cb_pro_meth)); p = strchr(p, ' '); line = &p[1]; } else if ((p = strstr(line, "private "))) { pixAccess = QPixmap(const_cast<const char **>(cb_pri_meth)); p = strchr(p, ' '); line = &p[1]; } else if (strstr(line, name)) pixAccess = QPixmap(const_cast<const char **>(cb_meth)); else pixAccess = QPixmap(const_cast<const char **>(cb_pri_meth)); p = strtok(line, ")"); for (unsigned i=0; i < strlen(p); i++) { if (isblank(p[i])) strcpy(&p[i], &p[i+1]); else break; } item = new QListViewItem(classnode); item->setText(0, (QString) p + ")"); item->setPixmap(0, pixAccess); } line = strtok(nextline, "\n"); } delete [] clscopy; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -