-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialoginsert.cpp
49 lines (38 loc) · 1.46 KB
/
dialoginsert.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
#include "dialoginsert.h"
#include "ui_dialoginsert.h"
DialogInsert::DialogInsert(CDSYSTEM *sys_, QWidget *parent)
: QDialog(parent), ui(new Ui::DialogInsert) {
ui->setupUi(this);
sys = sys_;
connect(ui->pushButton, &QPushButton::clicked, this, &DialogInsert::insert);
}
DialogInsert::~DialogInsert() {
delete ui;
}
void DialogInsert::addCdToComboBox(string name) {
ui->comboBox->addItem(QString::fromStdString(name));
}
void DialogInsert::removeCdFromComboBox(string name) {
ui->comboBox->removeItem(ui->comboBox->findText(QString::fromStdString(name)));
}
void DialogInsert::clearCdFromComboBox() {
ui->comboBox->clear();
}
void DialogInsert::insert() {
for (int i = 0; i < sys->ejectedCds.size(); i++) {
if (sys->ejectedCds[i]->portName == ui->comboBox->currentText().toStdString()) {
ui->comboBox->removeItem(ui->comboBox->findText(ui->comboBox->currentText()));
sys->insertedCds.push_back(sys->ejectedCds[i]);
sys->ejectedCds.erase(sys->ejectedCds.begin() + i);
}
}
}
void DialogInsert::on_pushButton_clicked() {
ui->comboBox->removeItem(ui->comboBox->findText(ui->comboBox->currentText()));
for (int i = 0; i < sys->ejectedCds.size(); i++) {
if (sys->ejectedCds[i]->portName == ui->comboBox->currentText().toStdString()) {
sys->insertedCds.push_back(sys->ejectedCds[i]);
sys->ejectedCds.erase(sys->ejectedCds.begin() + i);
}
}
}