-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
125 lines (88 loc) · 3.94 KB
/
mainwindow.cpp
File metadata and controls
125 lines (88 loc) · 3.94 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
#include "mainwindow.h"
#include "generatedclass.h"
MainWindow::MainWindow(){
setFixedSize(420, 480);
QGroupBox *m_grpBox1 = new QGroupBox("Définition de la classe",this);
m_grpBox1->setGeometry(10,10,400,80);
name = new QLineEdit(this);
motherClass = new QLineEdit(this);
QFormLayout *layout1 = new QFormLayout;
layout1->addRow("&Nom", name);
layout1->addRow("Classe &mère", motherClass);
m_grpBox1->setLayout(layout1);
// ------------------------------------------------------------------
QGroupBox *m_grpBox2 = new QGroupBox("Options",this);
m_grpBox2->setGeometry(10,100,400,150);
protectHeader = new QCheckBox("Protéger les Header contre les inclusions multiple");
defaultConstructor = new QCheckBox("Générer un constructeur par défaut");
defaultDestructor = new QCheckBox("Générer un destructeur");
QVBoxLayout *layout2 = new QVBoxLayout;
layout2->addWidget(protectHeader);
layout2->addWidget(defaultConstructor);
layout2->addWidget(defaultDestructor);
m_grpBox2->setLayout(layout2);
// ------------------------------------------------------------------
addComment = new QGroupBox(tr("Ajouter des commentaires"),this);
addComment->setGeometry(10,260,400,150);
addComment->setCheckable(true);
addComment->setChecked(false);
author = new QLineEdit(this);
creationDate = new QDateEdit(this);
classPurpose = new QTextEdit (this);
QFormLayout *layout3 = new QFormLayout;
layout3->addRow("&Auteur",author);
layout3->addRow("Da&te de création",creationDate);
layout3->addRow("&Rôle de la classe",classPurpose);
addComment->setLayout(layout3);
// ------------------------------------------------------------------
// mainLayout = new QGridLayout;
// generate = new QPushButton("Générer",this);
// exit = new QPushButton("Quitter",this);
// generate->setGeometry(200,420,100,50);
// exit->setGeometry(310,420,100,50);
// mainLayout->addWidget(m_grpBox1,0,0,2,4);
// mainLayout->addWidget(m_grpBox2,2,0,2,4);
// mainLayout->addWidget(m_grpBox3,4,0,2,4);
// mainLayout->addWidget(generate,6,2);
// mainLayout->addWidget(exit,6,3);
QVBoxLayout *mainLayout = new QVBoxLayout;
generate = new QPushButton("Générer");
exit = new QPushButton("Quitter");
mainLayout->addWidget(m_grpBox1);
mainLayout->addWidget(m_grpBox2);
mainLayout->addWidget(addComment);
mainLayout->addWidget(generate);
mainLayout->addWidget(exit);
this->setLayout(mainLayout);
// ------------------------------------------------------------------
connect(exit, SIGNAL(clicked()), qApp, SLOT(quit()));
connect(generate, SIGNAL(clicked()), this, SLOT(sendGeneratedCode()));
}
void MainWindow::sendGeneratedCode(){
QString wholeText;
QString nameUp = name->text();
nameUp = nameUp.toUpper();
if (name->text().isEmpty()){
QMessageBox::critical(this, "Erreur", "Veuillez entrer au moins un nom de classe");
return;
}
if (addComment->isChecked()){
wholeText = "/* \nAuteur: "+author->text()+"\n"
+"Date de création: "+creationDate->text()+"\n"
+"Rôle: \n"
+classPurpose->toPlainText()+"\n*/\n\n";
}
if (protectHeader->isChecked()) wholeText += "#ifndef HEADER_"+nameUp+"_H\n"
+"#define HEADER_"+nameUp+"_H\n\n";
wholeText += "class "+name->text();
if (!motherClass->text().isEmpty()) wholeText +=" : public "+motherClass->text();
wholeText +="\n{\n public:\n\n";
if (defaultConstructor->isChecked()) wholeText +=" "+name->text()+"();\n";
if (defaultConstructor->isChecked()) wholeText +=" ~"+name->text()+"();\n\n";
wholeText += " protected:\n\n private:\n\n}; #endif // "+nameUp+"_H";
GeneratedClass *newClass = new GeneratedClass(wholeText,this);
newClass->exec();
}
MainWindow::~MainWindow()
{
}