-
Notifications
You must be signed in to change notification settings - Fork 0
/
basesdialog.cpp
85 lines (68 loc) · 2.46 KB
/
basesdialog.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
#include <QMutableVectorIterator>
#include "basesdialog.h"
#include "ui_basesdialog.h"
BasesDialog::BasesDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::basesDialog)
{
ui->setupUi(this);
//bases default
__flightBasesList = new QStandardItemModel(0, 3, this);
ui->treeView->setAlternatingRowColors(true);
ui->treeView->setRootIsDecorated(false);
__flightBasesList->setHeaderData(0, Qt::Horizontal, QObject::tr("Название"));
__flightBasesList->setHeaderData(1, Qt::Horizontal, QObject::tr("X"));
__flightBasesList->setHeaderData(2, Qt::Horizontal, QObject::tr("Y"));
ui->treeView->setModel(__flightBasesList);
}
BasesDialog::~BasesDialog()
{
delete ui;
}
void BasesDialog::setBases(QVector<FlightBase> *bases)
{
__flightBases = bases;
for(int i = __flightBases->count()-1; i >= 0; i--)
{
FlightBase temp = __flightBases->at(i);
QString *name = new QString(temp.getBaseName().c_str());
float x = temp.getBasePosition().getPointX();
float y = temp.getBasePosition().getPointY();
addBase(__flightBasesList, *name, x, y);
}
}
void BasesDialog::addBase(QStandardItemModel *bases, const QString &name, const float x, const float y)
{
bases->insertRow(0);
bases->setData(bases->index(0, 0), name);
bases->setData(bases->index(0, 1), x);
bases->setData(bases->index(0, 2), y);
}
void BasesDialog::on_plusButton_clicked()
{
__flightBasesList->insertRow(__flightBasesList->rowCount());
__flightBasesList->setData(__flightBasesList->index(__flightBasesList->rowCount()-1, 0), "Name");
__flightBasesList->setData(__flightBasesList->index(__flightBasesList->rowCount()-1, 1), 0);
__flightBasesList->setData(__flightBasesList->index(__flightBasesList->rowCount()-1, 2), 0);
}
void BasesDialog::on_minusButton_clicked()
{
QModelIndex list = ui->treeView->currentIndex();
__flightBasesList->removeRow(list.row());
}
void BasesDialog::on_okbutton_clicked()
{
__flightBases->clear();
for(int i = 0; i < __flightBasesList->rowCount(); i++ )
{
QString name = (__flightBasesList->item(i,0)->text());
float X = __flightBasesList->item(i, 1)->text().toFloat();
float Y = __flightBasesList->item(i, 2)->text().toFloat();
Coordinates cords;
cords.setPointX(X);
cords.setPointY(Y);
FlightBase *base = new FlightBase(name.toStdString(), cords);
__flightBases->append(*base);
}
this->close();
}