23 #include <qtablewidget.h>
24 #include <qtabwidget.h>
26 #include <QtPrintSupport/QPrinter>
27 #include <QtPrintSupport/QPrintDialog>
29 #include <qtextstream.h>
30 #include <qfiledialog.h>
31 #include <qradiobutton.h>
33 #include <qbuttongroup.h>
34 #include <qmessagebox.h>
35 #include <qheaderview.h>
47 #include <QHBoxLayout>
49 #include <QGridLayout>
55 #define TR(id) OLocalizator::getString("TYSpectreWidget", (id))
105 setWindowTitle(
TR(
"id_caption"));
142 QGridLayout* groupBoxRadioLayout =
new QGridLayout();
148 QGroupBox* groupBoxRadio =
new QGroupBox();
149 groupBoxRadio->setTitle(
"");
150 groupBoxRadio->setLayout(groupBoxRadioLayout);
179 QStringList stringList;
180 stringList.append(
TR(
"id_freq"));
181 stringList.append(
"");
182 _tableau->setHorizontalHeaderLabels(stringList);
198 QGroupBox* buttonGroupBox =
new QGroupBox(
this);
199 buttonGroupBox->setTitle(
TR(
""));
200 QGridLayout* buttonGroupBoxLayout =
new QGridLayout();
201 buttonGroupBox->setLayout(buttonGroupBoxLayout);
202 buttonGroupBoxLayout->setAlignment(Qt::AlignTop);
250 QString unite =
"dB";
267 QStringList stringList;
268 stringList.append(
TR(
"id_freq"));
269 stringList.append(unite);
270 _tableau->setHorizontalHeaderLabels(stringList);
276 for (
int i = 0; i <
_tableau->rowCount(); i++)
278 _tableau->item(i, 0)->setFlags(QFlag(0));
310 if (col == 1 &&
_tableau->item(row, col) !=
nullptr)
314 QString txt =
_tableau->item(row, col)->text();
315 int index = txt.indexOf(
',');
318 txt.replace(index, 1,
'.');
319 _tableau->item(row, col)->setText(txt);
321 _tableau->item(row, col)->text().toDouble(&ok);
332 for (
int i = 0; i <
_nbFreq; i++)
346 for (
int i = 0; i <
_nbFreq; i++)
350 _tableau->item(i, 1)->setFlags(Qt::ItemIsEditable);
354 _tableau->item(i, 1)->setFlags(QFlag(0));
363 std::vector<QString> tmp;
365 QString qFileName = QFileDialog::getOpenFileName(
this,
"Choose a file",
"",
"CSV (*.csv)");
367 if (!qFileName.isEmpty())
370 if (!qFileName.endsWith(
"csv"))
377 std::filesystem::path(qFileName.toStdWString())
379 std::filesystem::path(qFileName.toUtf8().constData())
385 const QString title =
TR(
"id_error_loading_title");
386 const QString text =
TR(
"id_error_loading_spectrum").arg(QDir::toNativeSeparators(qFileName));
388 QMessageBox::critical(
this, title, text);
390 std::cerr <<
"Failed to open file: " << qFileName.toUtf8().constData() << std::endl;
395 while (std::getline(file, line))
404 tmp.push_back(QString::fromStdString(line));
414 std::vector<double> freqListeOctave;
415 std::vector<double> freqListeTiersOctave;
420 for (
int i = 0; i < tmp.size(); i++)
422 for (
int j = 0; j < freqListeOctave.size(); j++)
424 if (tmp[i].section(
";", 0, 0).toDouble() == freqListeOctave[j])
426 else if (j == freqListeOctave.size() - 1)
437 for (
int i = 0; i < tmp.size(); i++)
439 for (
int j = 0; j < freqListeTiersOctave.size(); j++)
441 if (tmp[i].section(
";", 0, 0).toDouble() == freqListeTiersOctave[j])
445 else if (j == freqListeTiersOctave.size() - 1)
447 QMessageBox::warning(
this,
"Tympan",
TR(
"id_warning_freq_invalid"), QMessageBox::Yes);
469 if ((bOctave && (tmp.size() < 9)) ||
470 (!bOctave && (tmp.size() < 31)))
472 int ret = QMessageBox::warning(
this,
"Tympan",
TR(
"id_warning_file_not_ok"), QMessageBox::Yes,
474 if (ret == QMessageBox::No)
480 std::vector<double> freqListe = freqListeTiersOctave;
482 freqListe = freqListeOctave;
488 _tableau->setRowCount(
static_cast<int>(freqListe.size()));
489 for (
int i = 0; i < freqListe.size(); i++)
492 _tableau->setItem(i, 0,
new QTableWidgetItem(QString::number(freqListe[i])));
494 for (
int j = 0; j < tmp.size(); j++)
496 double test1 = freqListe[i];
497 double test2 = tmp[j].section(
";", 0, 0).toDouble();
500 if (tmp[j].section(
";", 0, 0).toDouble() == freqListe[i])
502 _tableau->setItem(i, 1,
new QTableWidgetItem(tmp[j].section(
";", 1, 1)));
505 else if (j == tmp.size() - 1)
509 int defVal = TY_SPECTRE_DEFAULT_VALUE;
511 defVal = TY_SPECTRE_OCT_DEFAULT_VALUE;
513 _tableau->setItem(i, 1,
new QTableWidgetItem(QString::number(defVal)));
522 QString qFileName = QFileDialog::getSaveFileName(
this,
"Choose a file",
"",
"CSV (*.csv)");
524 if (!qFileName.isEmpty())
526 if (!qFileName.endsWith(
".csv"))
533 if (f.open(QIODevice::WriteOnly))
542 s <<
TR(
"id_freq") <<
";";
555 for (
int i = 0; i < nbFreq; i++)
557 s <<
_tableau->item(i, 0)->text() <<
";" <<
_tableau->item(i, 1)->text() <<
"\n";
565 static void processEvents();
569 qApp->processEvents();
576 bool isChanged =
false;
587 *pSpectre = pSpectre->
toTOct();
596 int ret = QMessageBox::warning(
this,
"Tympan",
TR(
"id_warning_converting_TO_to_Oct"),
597 QMessageBox::Yes, QMessageBox::No);
599 if (ret == QMessageBox::No)
612 *pSpectre = pSpectre->
toOct();
628 for (
int i = 0; i <
_tableau->rowCount(); i++)
630 _tableau->item(i, 0)->setFlags(QFlag(0));
648 bool isChanged =
false;
679 for (
int i = 0; i <
_tableau->rowCount(); i++)
681 _tableau->item(i, 0)->setFlags(QFlag(0));
708 for (
int i = 0; i <
_tableau->rowCount(); i++)
741 pondASpectre.setType(spectreEnDB.
getType());
742 spectreEnDB = pondASpectre;
749 for (
int i = 0; i < nbFreq; i++)
751 _tableau->setItem(i, 0,
new QTableWidgetItem((QString().setNum(
tabFreq[i],
'f', 2))));
768 for (
int i = indexDepart; i < nbFreq; i++)
770 val =
_tableau->item(i, 1)->text().toDouble(
790 pondZSpectre.setType(pSpectre->
getType());
791 *pSpectre = pondZSpectre;
801 *pSpectre = pSpectre->
toOct();
Boite de dialogue des parametres d'impression (fichier header)
const std::vector< double > tabFreq
OTabFreq TYTabFreq
Collection des frequences.
void setForm(TYSpectreForm form)
Force the spectrum state (to use carefully ...)
unsigned int getNbValues() const
Number of values in the spectrum.
void setType(TYSpectreType type)
Set the spectrum type.
TYSpectreType getType() const
Get the spectrum type.
OSpectreAbstract & toTOct() const
Converts to one-third Octave.
OSpectreAbstract & toDB() const
Converts to dB.
OSpectreAbstract & toOct() const
Converts to Octave.
static OSpectreOctave pondA()
Build a weighted spectrum A.
double * getTabValReel() override
static OSpectre pondA()
Build a weighted spectrum A.
TYElement * getParent() const
virtual void setForm(const TYSpectreForm &form)
static int getXMLPrecision()
Get/Set de la precision de stockage des resultats (XML)
virtual TYSpectreForm getForm()
Set/Get de la forme du spectre.
virtual bool getIsReadOnly()
Set/Get du flag de conservation en BDD.
virtual QString getRemarque() const
Set/Get des remarques.
OSpectre * downcast_ospectre()
: return spectrum casted as OSpectre
static const TYTabFreq getTabFreqNorm(TYSpectreForm form=SPECTRE_FORM_TIERS)
TYSpectreForm
Spectrum representation.
TYSpectreType
Spectrum type.