ResultsDialog.cpp 2.49 KB
#include "ResultsDialog.h"

#include <QLabel>
#include <QGridLayout>
#include <QDialogButtonBox>

ResultsDialog::ResultsDialog(qreal thresh1, qreal thresh2, int tp, int fp, int fn, int tn, qreal precision, qreal recall, qreal fScore, qreal accuracy, QWidget *parent)
  : QDialog(parent)
{
  setWindowTitle("Thresholds: " + QString::number(thresh1) + " - " + QString::number(thresh2));

  QLabel *refText = new QLabel("<b>Ref.</b>");
  QLabel *hypText = new QLabel("<b>Hyp.</b>");
  QLabel *yes1 = new QLabel("yes");
  QLabel *no1 = new QLabel("no");
  QLabel *yes2 = new QLabel("yes");
  QLabel *no2 = new QLabel("no");
  QLabel *tpLab = new QLabel(QString::number(tp));
  QLabel *fpLab = new QLabel(QString::number(fp));
  QLabel *fnLab = new QLabel(QString::number(fn));
  QLabel *tnLab = new QLabel(QString::number(tn));
  QLabel *precLab = new QLabel("<b>Precision:</b>");
  QLabel *recLab = new QLabel("<b>Recall:</b>");
  QLabel *fScLab = new QLabel("<b>F-Score:</b>");
  QLabel *accLab = new QLabel("<b>Accuracy:</b>");
  QLabel *prec = new QLabel(QString::number(precision, 'g', 3));
  QLabel *rec = new QLabel(QString::number(recall, 'g', 3));
  QLabel *fSc = new QLabel("<b>" + QString::number(fScore, 'g', 3) + "</b>");
  QLabel *acc = new QLabel(QString::number(accuracy, 'g', 3));

  QGridLayout *layout = new QGridLayout;
  layout->setColumnMinimumWidth(2, 50);
  layout->setColumnMinimumWidth(3, 50);
  layout->addWidget(refText, 0, 2, 1, 2, Qt::AlignHCenter);
  layout->addWidget(hypText, 2, 0, 2, 1, Qt::AlignVCenter);
  layout->addWidget(yes1, 1, 2, Qt::AlignHCenter);
  layout->addWidget(no1, 1, 3, Qt::AlignHCenter);
  layout->addWidget(yes2, 2, 1, Qt::AlignHCenter);
  layout->addWidget(no2, 3, 1, Qt::AlignHCenter);
  layout->addWidget(tpLab, 2, 2, Qt::AlignHCenter);
  layout->addWidget(fpLab, 2, 3, Qt::AlignHCenter);
  layout->addWidget(fnLab, 3, 2, Qt::AlignHCenter);
  layout->addWidget(tnLab, 3, 3, Qt::AlignHCenter);

  layout->addWidget(precLab, 4, 0, 1, 2);
  layout->addWidget(prec, 4, 2, 1, 2, Qt::AlignRight);
  layout->addWidget(recLab, 5, 0, 1, 2);
  layout->addWidget(rec, 5, 2, 1, 2, Qt::AlignRight);
  layout->addWidget(fScLab, 6, 0, 1, 2);
  layout->addWidget(fSc, 6, 2, 1, 2, Qt::AlignRight);
  layout->addWidget(accLab, 7, 0, 1, 2);
  layout->addWidget(acc, 7, 2, 1, 2, Qt::AlignRight);

  QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
  layout->addWidget(buttonBox, 8, 0, 1, 4, Qt::AlignHCenter);

  setLayout(layout);

  connect(buttonBox, SIGNAL(accepted()), SLOT(accept()));
}