| [8b9357] | 1 | /**
|
|---|
| 2 | * taken from https://hackatool.blogspot.com/2013/05/simple-tool-to-visualize-connections.html
|
|---|
| 3 | */
|
|---|
| 4 |
|
|---|
| 5 | #include <QString>
|
|---|
| 6 | #include <QDir>
|
|---|
| 7 | #include <QDebug>
|
|---|
| 8 | #include <QFileInfo>
|
|---|
| 9 | #include <QFileInfoList>
|
|---|
| 10 | #include <QIODevice>
|
|---|
| 11 | #include <iostream>
|
|---|
| 12 |
|
|---|
| 13 | void IterateDirs(QDir dir);
|
|---|
| 14 |
|
|---|
| 15 | int main(int argc,char* argv[])
|
|---|
| 16 | {
|
|---|
| 17 | bool foundSite = false;
|
|---|
| 18 | QString site;
|
|---|
| 19 | for(int i = 1; i < argc; ++i)
|
|---|
| 20 | {
|
|---|
| 21 | if(std::string(argv[i]) == "--path" || std::string(argv[i]) == "-p")
|
|---|
| 22 | {
|
|---|
| 23 | ++i;
|
|---|
| 24 | if (i < argc)
|
|---|
| 25 | site = argv[i];
|
|---|
| 26 | else
|
|---|
| 27 | break;
|
|---|
| 28 | foundSite = true;
|
|---|
| 29 | continue;
|
|---|
| 30 | }
|
|---|
| 31 | }
|
|---|
| 32 | if (argc < 3 || !foundSite)
|
|---|
| 33 | {
|
|---|
| 34 | std::cerr << "Usage: ConVis --path <projectpath>" << std::endl;
|
|---|
| 35 | return EXIT_FAILURE;
|
|---|
| 36 | }
|
|---|
| 37 | QDir dir(site);
|
|---|
| 38 | std::cout << "digraph connections {\nconstraint=\"false\" minlen=2\n";
|
|---|
| 39 | IterateDirs(dir);
|
|---|
| 40 | std::cout << "}\n";
|
|---|
| 41 | return EXIT_SUCCESS;
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | int i = 0;
|
|---|
| 45 |
|
|---|
| 46 | void IterateDirs(QDir dir)
|
|---|
| 47 | {
|
|---|
| 48 | QStringList filter;
|
|---|
| 49 | filter << "*.cxx" << "*.hxx" << "*.cpp" << "*.hpp";
|
|---|
| 50 | QFileInfoList files = dir.entryInfoList(filter, QDir::AllDirs |
|
|---|
| 51 | QDir::NoDotAndDotDot | QDir::Files);
|
|---|
| 52 | QFileInfoList::const_iterator it = files.constBegin();
|
|---|
| 53 | QFileInfoList::const_iterator en = files.constEnd();
|
|---|
| 54 | while (it != en)
|
|---|
| 55 | {
|
|---|
| 56 | QFileInfo info = *it;
|
|---|
| 57 | //qDebug() << info.isDir() << info.absoluteFilePath() << info.isFile();
|
|---|
| 58 | if (info.isDir())
|
|---|
| 59 | IterateDirs(QDir(info.absoluteFilePath()));
|
|---|
| 60 | else if (info.isFile())
|
|---|
| 61 | {
|
|---|
| 62 | QFile f(info.absoluteFilePath());
|
|---|
| 63 | f.open(QIODevice::ReadOnly);
|
|---|
| 64 | QString content = f.readAll();
|
|---|
| 65 | f.close();
|
|---|
| 66 | QRegExp r("connect\\s*\\((.+)\\s*,\\s*SIGNAL\\((.+)\\)\\s*,\\s*(.+)\\s*,"
|
|---|
| 67 | "\\s*(?:SLOT|SIGNAL)\\((.+)\\)\\s*\\)\\s*(?:, Qt::UniqueConnection|, Qt::DirectConnection|, Qt::QueuedConnection|)\\)");
|
|---|
| 68 | r.setMinimal(true);
|
|---|
| 69 | bool output = r.indexIn(content) != -1;
|
|---|
| 70 | if (output)
|
|---|
| 71 | std::cout << "subgraph cluster_" << i << "{\n";
|
|---|
| 72 | while (r.indexIn(content) != -1)
|
|---|
| 73 | {
|
|---|
| 74 | //qDebug() << r.capturedTexts();
|
|---|
| 75 | QStringList l = r.capturedTexts();
|
|---|
| 76 | if (l.at(1).trimmed() == "this")
|
|---|
| 77 | l.replace(1, info.fileName());
|
|---|
| 78 | if (l.at(3).trimmed() == "this")
|
|---|
| 79 | l.replace(3, info.fileName());
|
|---|
| 80 | std::cout << "\"" << l.at(1).trimmed().toStdString() << "\" -> \""
|
|---|
| 81 | << l.at(3).trimmed().toStdString()
|
|---|
| 82 | << "\" [color=\"green\"" << " label=\""
|
|---|
| 83 | << l.at(2).trimmed().toStdString() << "\\n"
|
|---|
| 84 | << l.at(4).trimmed().append(")").toStdString()
|
|---|
| 85 | << "\" style=\"solid\" labeldistance=2];\n";
|
|---|
| 86 | content = content.mid(r.indexIn(content) + r.matchedLength());
|
|---|
| 87 | }
|
|---|
| 88 | if (output)
|
|---|
| 89 | std::cout << "label=\"" << info.fileName().toStdString() << "\"\n}\n";
|
|---|
| 90 | ++i;
|
|---|
| 91 | }
|
|---|
| 92 | ++it;
|
|---|
| 93 | }
|
|---|
| 94 | }
|
|---|