summarylogtreecommitdiffstats
path: root/widget.cpp
blob: d7645dddcf75a1e9738c9edc550dde7ba94b9ad4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "widget.h"
#include "ui_widget.h"
#include "script.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    setWindowTitle("CSVPARSE");
    setFixedSize(650, 450);
    QPalette pal = palette();
    pal.setBrush(QPalette::Window, QBrush(QColor(209, 255, 213), Qt::SolidPattern));
    setPalette(pal);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_pushButton_clicked()
{
    QString fileName = QFileDialog::getOpenFileName(nullptr, "Выберите CSV файл", "", "CSV Files (*.csv);;All Files (*)");
    if (!fileName.isEmpty()) {
        ui->label_3->setText(fileName);
 }
}

void Widget::choice_from_combobox(QMap<QString, QString> text_data, QList<QStringList> data_table_to_view){
    tableshow = new TableShow();
    dataresult = new DataResult();
    switch (ui->comboBox->currentIndex()){
    case 1:
        dataresult->show();
        break;
    case 0:
        tableshow->show();
        break;
    }
    connect(this, &Widget::show_data, dataresult, &DataResult::updateResultData);
    emit show_data(text_data);
    connect(this, &Widget::show_table_data, tableshow, &TableShow::updateTableData);
    emit show_table_data(data_table_to_view);
}


void Widget::on_pushButton_3_clicked()
{
    // Если поля вввода не пустые
    if (!ui->label_3->text().isEmpty() && !ui->lineEdit->text().isEmpty() && !ui->lineEdit_2->text().isEmpty()){

        auto start = chrono::high_resolution_clock::now();
        QMap<QString, QString> text_data;
        char delimeter = ui->lineEdit->text()[0].toLatin1();
        string key_t = ui->lineEdit_2->text().toStdString(), filename = ui->label_3->text().toStdString();

        // Вызов функций обработки данных
        data_table = read_file(filename, delimeter);
        map<string, vector<string>> data_map = convert_to_map(data_table);
        map<string, string> data = get_values(data_map, key_t);
        for (auto& [key, value]: data) text_data[QString::fromStdString(key)] = QString::fromStdString(value);

        QList<QStringList> data_table_to_view;
        for(const auto& row: data_table){
            QStringList temp_lst;
            for(const auto& elem: row){
                temp_lst.append(QString::fromStdString(elem));
            }
            data_table_to_view.append(temp_lst);
        }
        choice_from_combobox(text_data, data_table_to_view);
    }
}