/[qspeakers]/speakerdialog.cpp
ViewVC logotype

Contents of /speakerdialog.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 24 - (show annotations)
Thu Oct 9 23:14:04 2014 UTC (2 years, 8 months ago) by ben
File size: 3250 byte(s)
remove alertDialog, use QMessageBox::question
1 #include <QPushButton>
2 #include <QDebug>
3 #include "speakerdialog.h"
4 #include "ui_speakerdialog.h"
5 #include "speaker.h"
6 #include "speakerdb.h"
7
8 SpeakerDialog::SpeakerDialog(QWidget *parent) :
9 QDialog(parent),
10 ui(new Ui::SpeakerDialog)
11 {
12 ui->setupUi(this);
13
14 /* do not enable 'ok' since model and vendor are empty */
15 ui->speakerButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
16
17 connect(this, SIGNAL(accepted()), this, SLOT(onSpeakerAccepted()));
18 connect(this, SIGNAL(rejected()), this, SLOT(onSpeakerRejected()));
19 connect(ui->vendorLineEdit, SIGNAL(textChanged(QString)), this, SLOT(onVendorTextChanged(QString)));
20 connect(ui->modelLineEdit, SIGNAL(textChanged(QString)), this, SLOT(onModelTextChanged(QString)));
21 }
22
23 SpeakerDialog::SpeakerDialog(const Speaker &edit, QWidget *parent) :
24 QDialog(parent),
25 ui(new Ui::SpeakerDialog)
26 {
27 ui->setupUi(this);
28
29 ui->fsDoubleSpinBox->setValue(edit.getFs());
30 ui->qtsDoubleSpinBox->setValue(edit.getQts());
31 ui->vasDoubleSpinBox->setValue(edit.getVas());
32 ui->reDoubleSpinBox->setValue(edit.getRe());
33 ui->sdDoubleSpinBox->setValue(edit.getSd());
34 ui->xmaxDoubleSpinBox->setValue(edit.getXmax());
35
36 oldVendor = edit.getVendor();
37 oldModel = edit.getModel();
38
39 ui->vendorLineEdit->setText(oldVendor);
40 ui->modelLineEdit->setText(oldModel);
41
42 connect(this, SIGNAL(accepted()), this, SLOT(onSpeakerAccepted()));
43 connect(this, SIGNAL(rejected()), this, SLOT(onSpeakerRejected()));
44 connect(ui->vendorLineEdit, SIGNAL(textChanged(QString)), this, SLOT(onVendorTextChanged(QString)));
45 connect(ui->modelLineEdit, SIGNAL(textChanged(QString)), this, SLOT(onModelTextChanged(QString)));
46 }
47
48 SpeakerDialog::~SpeakerDialog()
49 {
50 delete ui;
51 }
52
53 void SpeakerDialog::onVendorTextChanged(QString text)
54 {
55 if (text.isNull() || text.isEmpty())
56 ui->speakerButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
57 else if (!ui->modelLineEdit->text().isNull() && !ui->modelLineEdit->text().isEmpty())
58 ui->speakerButtonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
59 }
60
61 void SpeakerDialog::onModelTextChanged(QString text)
62 {
63 if (text.isNull() || text.isEmpty())
64 ui->speakerButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
65 else if (!ui->vendorLineEdit->text().isNull() && !ui->vendorLineEdit->text().isEmpty())
66 ui->speakerButtonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
67 }
68
69 void SpeakerDialog::onSpeakerAccepted()
70 {
71 Speaker spk;
72 QString vendor = ui->vendorLineEdit->text();
73 QString model = ui->modelLineEdit->text();
74
75 spk.setVendor(vendor);
76 spk.setModel(model);
77
78 spk.setFs(ui->fsDoubleSpinBox->value());
79 spk.setVas(ui->vasDoubleSpinBox->value());
80 spk.setQts(ui->qtsDoubleSpinBox->value());
81 spk.setRe(ui->reDoubleSpinBox->value());
82 spk.setSd(ui->sdDoubleSpinBox->value());
83 spk.setXmax(ui->xmaxDoubleSpinBox->value());
84
85
86 if (oldVendor.isNull() || oldModel.isNull()) {
87 SpeakerDb::insertOrReplace(vendor, model, spk);
88 } else {
89 SpeakerDb::insertOrReplace(oldVendor, oldModel, spk);
90 }
91 emit speakerInserted(spk);
92 }
93
94 void SpeakerDialog::onSpeakerRejected()
95 {
96 emit speakerCancelled();
97 }

  ViewVC Help
Powered by ViewVC 1.1.26