/[qspeakers]/branches/qtcharts/speakerdialog.cpp
ViewVC logotype

Contents of /branches/qtcharts/speakerdialog.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 270 - (show annotations)
Sun Oct 25 20:46:15 2020 UTC (7 months, 2 weeks ago) by ben
File size: 4096 byte(s)
Implement dual VC display
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->zDoubleSpinBox->setValue(edit.getZ());
33 ui->diaDoubleSpinBox->setValue(edit.getDia());
34 ui->reDoubleSpinBox->setValue(edit.getRe());
35 ui->sdDoubleSpinBox->setValue(edit.getSd());
36 ui->xmaxDoubleSpinBox->setValue(edit.getXmax());
37 ui->leDoubleSpinBox->setValue(edit.getLe());
38 ui->qmsDoubleSpinBox->setValue(edit.getQms());
39 ui->qesDoubleSpinBox->setValue(edit.getQes());
40 ui->splDoubleSpinBox->setValue(edit.getSpl());
41 ui->peDoubleSpinBox->setValue(edit.getPe());
42 ui->blDoubleSpinBox->setValue(edit.getBL());
43 ui->vcSpinBox->setValue(edit.getVc());
44
45 oldVendor = edit.getVendor();
46 oldModel = edit.getModel();
47
48 ui->vendorLineEdit->setText(oldVendor);
49 ui->modelLineEdit->setText(oldModel);
50
51 connect(this, SIGNAL(accepted()), this, SLOT(onSpeakerAccepted()));
52 connect(this, SIGNAL(rejected()), this, SLOT(onSpeakerRejected()));
53 connect(ui->vendorLineEdit, SIGNAL(textChanged(QString)), this, SLOT(onVendorTextChanged(QString)));
54 connect(ui->modelLineEdit, SIGNAL(textChanged(QString)), this, SLOT(onModelTextChanged(QString)));
55 }
56
57 SpeakerDialog::~SpeakerDialog()
58 {
59 delete ui;
60 }
61
62 void SpeakerDialog::onVendorTextChanged(QString text)
63 {
64 if (text.isNull() || text.isEmpty())
65 ui->speakerButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
66 else if (!ui->modelLineEdit->text().isNull() && !ui->modelLineEdit->text().isEmpty())
67 ui->speakerButtonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
68 }
69
70 void SpeakerDialog::onModelTextChanged(QString text)
71 {
72 if (text.isNull() || text.isEmpty())
73 ui->speakerButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
74 else if (!ui->vendorLineEdit->text().isNull() && !ui->vendorLineEdit->text().isEmpty())
75 ui->speakerButtonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
76 }
77
78 void SpeakerDialog::onSpeakerAccepted()
79 {
80 Speaker spk;
81 QString vendor = ui->vendorLineEdit->text();
82 QString model = ui->modelLineEdit->text();
83
84 spk.setVendor(vendor);
85 spk.setModel(model);
86
87 spk.setFs(ui->fsDoubleSpinBox->value());
88 spk.setVas(ui->vasDoubleSpinBox->value());
89 spk.setQts(ui->qtsDoubleSpinBox->value());
90 spk.setZ(ui->zDoubleSpinBox->value());
91 spk.setDia(ui->diaDoubleSpinBox->value());
92 spk.setRe(ui->reDoubleSpinBox->value());
93 spk.setSd(ui->sdDoubleSpinBox->value());
94 spk.setXmax(ui->xmaxDoubleSpinBox->value());
95 spk.setLe(ui->leDoubleSpinBox->value());
96 spk.setQms(ui->qmsDoubleSpinBox->value());
97 spk.setQes(ui->qesDoubleSpinBox->value());
98 spk.setSpl(ui->splDoubleSpinBox->value());
99 spk.setPe(ui->peDoubleSpinBox->value());
100 spk.setBL(ui->blDoubleSpinBox->value());
101 spk.setVc(ui->vcSpinBox->value());
102
103
104 if (oldVendor.isNull() || oldModel.isNull()) {
105 SpeakerDb::insertOrReplace(vendor, model, spk);
106 } else {
107 SpeakerDb::insertOrReplace(oldVendor, oldModel, spk);
108 }
109 emit speakerInserted(spk);
110 }
111
112 void SpeakerDialog::onSpeakerRejected()
113 {
114 emit speakerCancelled();
115 }

  ViewVC Help
Powered by ViewVC 1.1.26