#include "output_statistic.h"
#include "QtCore\qfile.h"
#include "QtCore\qtextstream.h"
#include "exportData.h"
#include <map>

extern ConfPath g_conf_path;

#define output_init(a, b)\
textBrowser_mat[a] = ui.textBrowser_##b;

output_statistic::output_statistic(QDialog* parent)
    : QDialog(parent)
{
    ui.setupUi(this);
    this->setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);

#if defined(NumberOfSupportedCameras) && (NumberOfSupportedCameras > 0)
    output_init(0, 1);
#endif
#if defined(NumberOfSupportedCameras) && (NumberOfSupportedCameras > 1)
    output_init(1, 2);
#endif
#if defined(NumberOfSupportedCameras) && (NumberOfSupportedCameras > 2)
    output_init(2, 3);
#endif
#if defined(NumberOfSupportedCameras) && (NumberOfSupportedCameras > 3)
    output_init(3, 4);
#endif
#if defined(NumberOfSupportedCameras) && (NumberOfSupportedCameras > 4)
    output_init(4, 5);
#endif
#if defined(NumberOfSupportedCameras) && (NumberOfSupportedCameras > 5)
    output_init(5, 6);
#endif
#if defined(NumberOfSupportedCameras) && (NumberOfSupportedCameras > 6)
    output_init(6, 7);
#endif
#if defined(NumberOfSupportedCameras) && (NumberOfSupportedCameras > 7)
    output_init(7, 8);
#endif
}

output_statistic::~output_statistic()
{
}

void output_statistic::recMsgFromDialogSetup()
{
    QString file_path, file_name;
    QFile file;
    for (int i = 0; i < NumberOfSupportedCameras; i++) {
        file_name = QString(STATISTIC_FILE).arg(i);
        file_path = g_conf_path.config_path + "/" + file_name;
        file.setFileName(file_path);
        if (file.open(QIODevice::ReadOnly | QIODevice::Text))
        {
            QTextStream in(&file);
            //in.setCodec("UTF-8");
            textBrowser_mat[i]->setText(in.readAll());
        }
        else {
            std::cout << "can not open statistic file" << std::endl;
        }
        file.close();
        this->show();
    }
    //this->show();
}
