forked from danmar/cppcheck
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigureprojects.cpp
More file actions
143 lines (126 loc) · 4.33 KB
/
configureprojects.cpp
File metadata and controls
143 lines (126 loc) · 4.33 KB
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
#include "configureprojects.h"
#include "ui_configureprojects.h"
#include <QFileDialog>
#include <QInputDialog>
#include <QMessageBox>
ConfigureProjects::ConfigureProjects(QWidget *parent, const ProjectList &projectlist_) :
QDialog(parent),
projectList(projectlist_),
ui(new Ui::ConfigureProjects)
{
ui->setupUi(this);
ui->projects->addItems(projectList.projectNames());
ui->projects->setCurrentRow(0);
}
ConfigureProjects::~ConfigureProjects()
{
delete ui;
}
void ConfigureProjects::selectProject()
{
const QString projectName = ui->projects->currentItem()->text();
const ProjectList::Project *project = projectList.getproject(projectName);
ui->name->setText(project ? project->name : QString());
ui->path->setText(project ? project->path : QString());
ui->defines->clear();
ui->includes->clear();
if (project != 0) {
QString defines;
foreach(const QString def, project->defines) {
defines += " " + def;
}
ui->defines->setText(defines);
ui->includes->addItems(project->includes);
ui->clangCompiler->setChecked(project->clang.compiler);
ui->clangAnalyser->setChecked(project->clang.analyser);
ui->cppcheckEnabled->setChecked(project->cppcheck.enabled);
ui->gccEnabled->setChecked(project->gcc.enabled);
}
}
void ConfigureProjects::newProject()
{
QString projectName;
for (int i = 1; i < 1000; i++) {
projectName = "Project" + QString().sprintf("%i",i);
bool exists = false;
foreach(const ProjectList::Project *p, projectList.projects) {
if (p->name == projectName) {
exists = true;
break;
}
}
if (!exists)
break;
}
ProjectList::Project *project = new ProjectList::Project;
project->name = projectName;
projectList.projects.append(project);
ui->projects->addItem(projectName);
ui->projects->sortItems();
}
void ConfigureProjects::deleteProject()
{
const QString currentString = ui->projects->currentItem()->text();
for (int i = 0; i < projectList.projects.size(); ++i) {
if (projectList.projects[i]->name == currentString) {
delete projectList.projects[i];
projectList.projects.removeAt(i);
}
}
delete ui->projects->currentItem();
}
void ConfigureProjects::nameChanged(QString name)
{
if (name.isEmpty())
ui->nameStatus->setText(tr("Empty name"));
else if (name != ui->projects->currentItem()->text() && projectList.getproject(name))
ui->nameStatus->setText(tr("Duplicate name"));
else
ui->nameStatus->setText("OK");
}
void ConfigureProjects::pathBrowse()
{
const QString dir = QFileDialog::getExistingDirectory(this, tr("Select path to scan"));
if (!dir.isEmpty()) {
ui->path->setText(dir);
apply();
}
}
void ConfigureProjects::newInclude()
{
const QString dir = QFileDialog::getExistingDirectory(this,
tr("Select directory to include"));
if (!dir.isEmpty()) {
ui->includes->addItem(dir);
}
}
void ConfigureProjects::deleteInclude()
{
ui->includes->removeItemWidget(ui->includes->currentItem());
}
void ConfigureProjects::apply()
{
const QString oldName = ui->projects->currentItem()->text();
const QString newName = ui->name->text();
ProjectList::Project *project = projectList.getproject(oldName);
if (!newName.isEmpty() && !projectList.getproject(newName))
project->name = newName;
project->path = ui->path->text();
project->defines = ui->defines->text().split("[; ]");
project->includes.clear();
foreach(const QListWidgetItem *item, ui->includes->findItems(".*",Qt::MatchRegExp)) {
project->includes << item->text();
}
const QStringList s = projectList.projectNames();
ui->projects->clear();
ui->projects->addItems(s);
ui->projects->setCurrentRow(s.indexOf(project->name));
}
void ConfigureProjects::saveCompilerSettings()
{
ProjectList::Project *project = projectList.getproject(ui->projects->currentItem()->text());
project->clang.compiler = ui->clangCompiler->isChecked();
project->clang.analyser = ui->clangAnalyser->isChecked();
project->cppcheck.enabled = ui->cppcheckEnabled->isChecked();
project->gcc.enabled = ui->gccEnabled->isChecked();
}