forked from fpoussin/qtcreator-doxygen
-
Notifications
You must be signed in to change notification settings - Fork 10
/
doxygenfilesdialog.cpp
161 lines (135 loc) · 5.33 KB
/
doxygenfilesdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include "doxygenfilesdialog.h"
#include "ui_doxygenfilesdialog.h"
DoxygenFilesDialog::DoxygenFilesDialog(QWidget* parent)
: QDialog(parent)
, ui(new Ui::DoxygenFilesDialog)
{
ui->setupUi(this);
connect(ui->b_all, SIGNAL(clicked(bool)), this, SLOT(checkAll()));
connect(ui->b_none, SIGNAL(clicked(bool)), this, SLOT(checkNone()));
connect(ui->b_cancel, SIGNAL(clicked(bool)), this, SLOT(reject()));
connect(ui->b_ok, SIGNAL(clicked(bool)), this, SLOT(accept()));
connect(ui->treeWidget, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(updateChecks(QTreeWidgetItem*, int)));
}
DoxygenFilesDialog::~DoxygenFilesDialog()
{
delete ui;
}
void DoxygenFilesDialog::initFileTree(ProjectExplorer::Node* rootNode)
{
createLeaf(rootNode, new QTreeWidgetItem(ui->treeWidget, QStringList(rootNode->displayName())));
ui->treeWidget->expandAll();
}
void DoxygenFilesDialog::createLeaf(ProjectExplorer::Node* parentNode, QTreeWidgetItem* parentItem)
{
parentItem->setCheckState(0, Qt::Checked);
if (parentNode->asFolderNode()) {
ProjectExplorer::FolderNode* currentFolderNode = parentNode->asFolderNode();
parentItem->setIcon(0, currentFolderNode->icon());
foreach (ProjectExplorer::FileNode* fileNode, currentFolderNode->fileNodes()) {
QString fileName = fileNode->filePath().toString();
if ((QRegExp("\\.(h|hpp|c|cpp)$").indexIn(fileName)) != -1) {
QTreeWidgetItem* child = new QTreeWidgetItem(parentItem, QStringList(fileName));
child->setCheckState(0, Qt::Checked);
parentItem->addChild(child);
}
}
foreach (ProjectExplorer::FolderNode* folderNode, currentFolderNode->folderNodes()) {
createLeaf(folderNode, new QTreeWidgetItem(parentItem, QStringList(folderNode->displayName())));
}
} else if (parentNode->asProjectNode()) {
ProjectExplorer::ProjectNode* currentProjectNode = parentNode->asProjectNode();
parentItem->setIcon(0, currentProjectNode->icon());
foreach (ProjectExplorer::FileNode* fileNode, currentProjectNode->fileNodes()) {
QString fileName = fileNode->filePath().toString();
if ((QRegExp("\\.(h|hpp|c|cpp)$").indexIn(fileName)) != -1) {
QTreeWidgetItem* child = new QTreeWidgetItem(parentItem, QStringList(fileName));
child->setCheckState(0, Qt::Checked);
parentItem->addChild(child);
}
}
foreach (ProjectExplorer::FolderNode* folderNode, currentProjectNode->folderNodes()) {
createLeaf(folderNode, new QTreeWidgetItem(parentItem, QStringList(folderNode->displayName())));
}
createLeaf(currentProjectNode, new QTreeWidgetItem(parentItem, QStringList(currentProjectNode->displayName())));
}
if (parentItem->childCount() == 0) {
delete (parentItem);
}
}
uint DoxygenFilesDialog::getFilesList(QTreeWidgetItem* parent, QStringList* out, int count)
{
if (!parent->childCount()) {
if (parent->checkState(0) == Qt::Checked) {
out->append(parent->text(0));
count++;
}
} else {
for (int i = 0; i < parent->childCount(); i++) {
getFilesList(parent->child(i), out, count);
}
}
return count;
}
uint DoxygenFilesDialog::getFilesList(QStringList* out)
{
uint count = 0;
for (int i = 0; i < ui->treeWidget->topLevelItemCount(); i++) {
getFilesList(ui->treeWidget->topLevelItem(i), out, count);
}
return count;
}
void DoxygenFilesDialog::changeCheckState(QTreeWidgetItem* parent, Qt::CheckState state)
{
if (!parent->childCount()) {
if (parent->checkState(0) != state) {
parent->setCheckState(0, state);
}
} else {
for (int i = 0; i < parent->childCount(); i++) {
changeCheckState(parent->child(i), state);
}
}
}
void DoxygenFilesDialog::checkAll()
{
for (int i = 0; i < ui->treeWidget->topLevelItemCount(); i++) {
changeCheckState(ui->treeWidget->topLevelItem(i), Qt::Checked);
}
}
void DoxygenFilesDialog::checkNone()
{
for (int i = 0; i < ui->treeWidget->topLevelItemCount(); i++) {
changeCheckState(ui->treeWidget->topLevelItem(i), Qt::Unchecked);
}
}
void DoxygenFilesDialog::updateChecks(QTreeWidgetItem* item, int column)
{
bool diff = false;
if (column != 0 && column != -1) {
return;
}
if (item->childCount() != 0 && item->checkState(0) != Qt::PartiallyChecked && column != -1) {
Qt::CheckState checkState = item->checkState(0);
for (int i = 0; i < item->childCount(); ++i) {
item->child(i)->setCheckState(0, checkState);
}
} else if (item->childCount() == 0 || column == -1) {
if (item->parent() == nullptr) {
return;
}
for (int j = 0; j < item->parent()->childCount(); ++j) {
if (j != item->parent()->indexOfChild(item) && item->checkState(0) != item->parent()->child(j)->checkState(0)) {
diff = true;
}
}
if (diff) {
item->parent()->setCheckState(0, Qt::PartiallyChecked);
} else {
item->parent()->setCheckState(0, item->checkState(0));
}
if (item->parent() != nullptr) {
updateChecks(item->parent(), -1);
}
}
}