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))
88 setWindowTitle(
TR(
"id_caption"));
125 QGridLayout* groupBoxRadioLayout =
new QGridLayout();
131 QGroupBox* groupBoxRadio =
new QGroupBox();
132 groupBoxRadio->setTitle(
"");
133 groupBoxRadio->setLayout(groupBoxRadioLayout);
162 QStringList stringList;
163 stringList.append(
TR(
"id_freq"));
164 stringList.append(
"");
165 _tableau->setHorizontalHeaderLabels(stringList);
181 QGroupBox* buttonGroupBox =
new QGroupBox(
this);
182 buttonGroupBox->setTitle(
TR(
""));
183 QGridLayout* buttonGroupBoxLayout =
new QGridLayout();
184 buttonGroupBox->setLayout(buttonGroupBoxLayout);
185 buttonGroupBoxLayout->setAlignment(Qt::AlignTop);
231 QString unite =
"dB";
248 QStringList stringList;
249 stringList.append(
TR(
"id_freq"));
250 stringList.append(unite);
251 _tableau->setHorizontalHeaderLabels(stringList);
257 for (
int i = 0; i <
_tableau->rowCount(); i++)
259 _tableau->item(i, 0)->setFlags(QFlag(0));
291 if (col == 1 &&
_tableau->item(row, col) !=
nullptr)
295 QString txt =
_tableau->item(row, col)->text();
296 int index = txt.indexOf(
',');
299 txt.replace(index, 1,
'.');
300 _tableau->item(row, col)->setText(txt);
302 _tableau->item(row, col)->text().toDouble(&ok);
313 for (
int i = 0; i <
_nbFreq; i++)
327 for (
int i = 0; i <
_nbFreq; i++)
331 _tableau->item(i, 1)->setFlags(Qt::ItemIsEditable);
335 _tableau->item(i, 1)->setFlags(QFlag(0));
344 std::vector<QString> tmp;
346 QString qFileName = QFileDialog::getOpenFileName(
this,
"Choose a file",
"",
"CSV (*.csv)");
348 if (!qFileName.isEmpty())
351 if (!qFileName.endsWith(
"csv"))
356 std::ifstream file(qFileName.toStdString());
360 std::cerr <<
"Failed to open file: " << qFileName.toStdString() << std::endl;
365 while (std::getline(file, line))
374 tmp.push_back(QString::fromStdString(line));
384 std::vector<double> freqListeOctave;
385 std::vector<double> freqListeTiersOctave;
390 for (
int i = 0; i < tmp.size(); i++)
392 for (
int j = 0; j < freqListeOctave.size(); j++)
394 if (tmp[i].section(
";", 0, 0).toDouble() == freqListeOctave[j])
396 else if (j == freqListeOctave.size() - 1)
407 for (
int i = 0; i < tmp.size(); i++)
409 for (
int j = 0; j < freqListeTiersOctave.size(); j++)
411 if (tmp[i].section(
";", 0, 0).toDouble() == freqListeTiersOctave[j])
415 else if (j == freqListeTiersOctave.size() - 1)
417 QMessageBox::warning(
this,
"Tympan",
TR(
"id_warning_freq_invalid"), QMessageBox::Yes);
439 if ((bOctave && (tmp.size() < 9)) ||
440 (!bOctave && (tmp.size() < 31)))
442 int ret = QMessageBox::warning(
this,
"Tympan",
TR(
"id_warning_file_not_ok"), QMessageBox::Yes,
444 if (ret == QMessageBox::No)
450 std::vector<double> freqListe = freqListeTiersOctave;
452 freqListe = freqListeOctave;
458 _tableau->setRowCount(
static_cast<int>(freqListe.size()));
459 for (
int i = 0; i < freqListe.size(); i++)
462 _tableau->setItem(i, 0,
new QTableWidgetItem(QString::number(freqListe[i])));
464 for (
int j = 0; j < tmp.size(); j++)
466 double test1 = freqListe[i];
467 double test2 = tmp[j].section(
";", 0, 0).toDouble();
470 if (tmp[j].section(
";", 0, 0).toDouble() == freqListe[i])
472 _tableau->setItem(i, 1,
new QTableWidgetItem(tmp[j].section(
";", 1, 1)));
475 else if (j == tmp.size() - 1)
479 int defVal = TY_SPECTRE_DEFAULT_VALUE;
481 defVal = TY_SPECTRE_OCT_DEFAULT_VALUE;
483 _tableau->setItem(i, 1,
new QTableWidgetItem(QString::number(defVal)));
492 QString qFileName = QFileDialog::getSaveFileName(
this,
"Choose a file",
"",
"CSV (*.csv)");
494 if (!qFileName.isEmpty())
496 if (!qFileName.endsWith(
".csv"))
503 if (f.open(QIODevice::WriteOnly))
512 s <<
TR(
"id_freq") <<
";";
525 for (
int i = 0; i < nbFreq; i++)
527 s <<
_tableau->item(i, 0)->text() <<
";" <<
_tableau->item(i, 1)->text() <<
"\n";
535 static void processEvents();
539 qApp->processEvents();
546 bool isChanged =
false;
557 *pSpectre = pSpectre->
toTOct();
564 int ret = QMessageBox::warning(
this,
"Tympan",
TR(
"id_warning_converting_TO_to_Oct"),
565 QMessageBox::Yes, QMessageBox::No);
566 if (ret == QMessageBox::No)
578 *pSpectre = pSpectre->
toOct();
594 for (
int i = 0; i <
_tableau->rowCount(); i++)
596 _tableau->item(i, 0)->setFlags(QFlag(0));
614 bool isChanged =
false;
645 for (
int i = 0; i <
_tableau->rowCount(); i++)
647 _tableau->item(i, 0)->setFlags(QFlag(0));
674 for (
int i = 0; i <
_tableau->rowCount(); i++)
705 pondASpectre.setType(pSpectre->
getType());
706 pSpectre = &pondASpectre;
713 for (
int i = 0; i < nbFreq; i++)
715 _tableau->setItem(i, 0,
new QTableWidgetItem((QString().setNum(
tabFreq[i],
'f', 2))));
732 for (
int i = indexDepart; i < nbFreq; i++)
734 val =
_tableau->item(i, 1)->text().toDouble(
754 pondZSpectre.setType(pSpectre->
getType());
755 *pSpectre = pondZSpectre;
765 *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 & 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.