-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
158 lines (140 loc) · 5.12 KB
/
Copy pathmainwindow.cpp
File metadata and controls
158 lines (140 loc) · 5.12 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include "mainwindow.h"
void MainWindow::createActions() {
newDb=new QAction("Nuovo",this);
openDb=new QAction("Carica",this);
saveDb=new QAction("Salva",this);
newRecord=new QAction("Nuovo",this);
modifyRecord=new QAction("Modifica",this);
saveRecord=new QAction("Salva",this);
deleteRecord=new QAction("Elimina",this);
searchRecord=new QAction("Cerca",this);
calcoloImu=new QAction("Calcolo IMU",this);
}
void MainWindow::connectSignalSlot() {
connect(newDb,SIGNAL(triggered()),this,SLOT(newFile()));
connect(openDb,SIGNAL(triggered()),this,SLOT(openFile()));
connect(saveDb,SIGNAL(triggered()),this,SLOT(saveFile()));
connect(newRecord,SIGNAL(triggered()),this,SLOT(newInsert()));
connect(modifyRecord,SIGNAL(triggered()),centralWindow,SLOT(modify()));
connect(saveRecord,SIGNAL(triggered()),this,SLOT(saveToModel()));
connect(deleteRecord,SIGNAL(triggered()),this,SLOT(deleteFromModel()));
connect(searchRecord,SIGNAL(triggered()),searchWindow,SLOT(exec()));
connect(calcoloImu,SIGNAL(triggered()),this,SLOT(showImu()));
}
void MainWindow::newFile() {
controller->newFile();
}
void MainWindow::openFile() {
QString fileName=QFileDialog::getOpenFileName(this, "Apri un file qDB", QDir::currentPath(), "File qDB (*.xml)");
if (!fileName.isEmpty()) {
controller->openFile(fileName);
}
}
void MainWindow::saveFile() {
QString fileName=QFileDialog::getSaveFileName(this, "Salva un file qDB", QDir::currentPath(), "File qDB (*.xml)");
if (!fileName.isEmpty()) {
controller->saveFile(fileName);
}
}
void MainWindow::saveToModel() {
if (!controller->getActualRecord()) {
if (centralWindow->haveNewData()) {
controller->insertRecord(centralWindow->getFieldModified());
}
else
showWarning("Impossibile salvare!\nInserire almeno i dati generali.");
}
else {
controller->modifyRecord(centralWindow->getFieldModified());
}
}
void MainWindow::deleteFromModel() {
if (controller->getActualRecord()) {
controller->deleteRecord();
}
else
showWarning("Non e' stato selezionato alcun bene immobile!");
}
void MainWindow::showImu() {
Record* x=controller->getActualRecord();
if (x) {
try {
QMessageBox show;
show.setText("L'IMU calcolato per il bene immobile selezionato risulta essere di euro:");
show.setInformativeText(QString::number((*x)->calcoloImu()));
show.setIcon(QMessageBox::Information);
show.setStandardButtons(QMessageBox::Ok);
show.exec();
}
catch (Error e) {
showWarning(QString::fromStdString(e.getError()));
}
}
else
showWarning("Non e' stato selezionato alcun bene immobile!");
}
void MainWindow::newInsert() {
controller->resetActualRecord();
centralWindow->newInsert();
}
MainWindow::MainWindow(QWidget* parent): QMainWindow(parent) {
centralWindow = new CentralWidget(this);
searchWindow = new SearchDialog(this);
setCentralWidget(centralWindow);
createActions();
fileMenu = menuBar()->addMenu("DataBase");
fileMenu->addAction(newDb);
fileMenu->addAction(openDb);
fileMenu->addAction(saveDb);
toolBar = addToolBar("Record");
toolBar->addAction(newRecord);
toolBar->addAction(modifyRecord);
toolBar->addAction(saveRecord);
toolBar->addAction(deleteRecord);
toolBar->addAction(searchRecord);
toolBar->addSeparator();
toolBar->addAction(calcoloImu);
toolBar->setMovable(false);
showStatus("Pronto");
connectSignalSlot();
}
MainWindow::~MainWindow() {}
void MainWindow::setController(Controller* c) {
controller=c;
}
void MainWindow::updateView() {
Record* x=controller->getActualRecord();
centralWindow->clear();
if (x) {
bool primaCasa=false, storico=false, inagibile=false;
QString comune=QString::fromStdString((*x)->getIdentificativoCatastale().getComune());
QString foglio=QString::number((*x)->getIdentificativoCatastale().getFoglio());
QString particella=QString::number((*x)->getIdentificativoCatastale().getParticella());
QString proprietario=QString::fromStdString((*x)->getProprietario());
QString rendita=QString::number((*x)->getRenditaCatastale());
QString classe="";
Fabbricato* f=dynamic_cast<Fabbricato*>(&(**x));
if (f) {
classe=QString::fromStdString(f->getCategoriaCatastale());
primaCasa=f->isPrimaCasa();
storico=f->isStorico();
inagibile=f->isInagibile();
}
centralWindow->updateField(f,comune,foglio,particella,proprietario,rendita,classe,primaCasa,storico,inagibile);
}
}
void MainWindow::showWarning(const QString& x) {
QMessageBox::warning(this,"qDB",x,QMessageBox::Ok);
}
void MainWindow::showStatus(const QString& x, int y) {
statusBar()->showMessage(x,y);
}
void MainWindow::clearField() const {
centralWindow->clear();
}
void MainWindow::lockField() const {
centralWindow->lock();
}
void MainWindow::startSearch() {
controller->searchRecord(searchWindow->sendDataSearch());
}