<commit_before>//
// Created by max on 26/03/17.
//

#include <data/SettingsManager.h>
#include "SettingsDialog.h"

SettingsDialog::SettingsDialog(QWidget *)
{
    topLevelLayout = new QVBoxLayout;
    settingsItemsLayout = new QGridLayout;
    bottomButtonLayout = new QHBoxLayout;

    defaultDbLocationLabel = new QLabel("Database location:");
    defaultDbLocationEdit = new QLineEdit(SettingsManager::getInstance()->databaseLocation());
    openFileSelectButton = new QPushButton("...");
    openFileSelectButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
    openFileSelectButton->setMaximumWidth(30);
    defaultPlottypeLabel = new QLabel("Plottype:");
    defaultPlottypeCombo = new QComboBox;
    // TODO: populate combo box

    cancelButton = new QPushButton("Cancel");
    okayButton = new QPushButton("Okay");

    settingsItemsLayout->setColumnStretch(1, 4);
    settingsItemsLayout->setColumnStretch(2, 8);
    settingsItemsLayout->setColumnStretch(3, 1);

    settingsItemsLayout->addWidget(defaultDbLocationLabel, 1, 1, 1, 1);
    settingsItemsLayout->addWidget(defaultDbLocationEdit, 1, 2, 1, 1);
    settingsItemsLayout->addWidget(openFileSelectButton, 1, 3, 1, 1);
    settingsItemsLayout->addWidget(defaultPlottypeLabel, 2, 1);
    settingsItemsLayout->addWidget(defaultPlottypeCombo, 2, 2, 1, 2);

    bottomButtonLayout->addWidget(cancelButton, 1);
    bottomButtonLayout->addStretch(2);
    bottomButtonLayout->addWidget(okayButton, 1);

    topLevelLayout->addItem(settingsItemsLayout);
    topLevelLayout->addSpacerItem(new QSpacerItem(200, 5));
    topLevelLayout->addItem(bottomButtonLayout);
    setLayout(topLevelLayout);
    setMinimumWidth(640);
}

void
SettingsDialog::onPressOkay()
{
    // TODO
}<commit_msg>Added save and cancel functionality, signaling to SettingsDialog<commit_after>//
// Created by max on 26/03/17.
//

#include <data/SettingsManager.h>
#include "SettingsDialog.h"

SettingsDialog::SettingsDialog(QWidget *)
{
    topLevelLayout = new QVBoxLayout;
    settingsItemsLayout = new QGridLayout;
    bottomButtonLayout = new QHBoxLayout;

    defaultDbLocationLabel = new QLabel("Database location:");
    defaultDbLocationEdit = new QLineEdit(SettingsManager::getInstance()->databaseLocation());
    openFileSelectButton = new QPushButton("...");
    openFileSelectButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
    openFileSelectButton->setMaximumWidth(30);
    defaultPlottypeLabel = new QLabel("Plottype:");
    defaultPlottypeCombo = new QComboBox;
    {
        defaultPlottypeCombo->addItem("Cumulative");
        defaultPlottypeCombo->addItem("Cumulative with MinMax");
        defaultPlottypeCombo->addItem("Peaks");
    }
    defaultPlottypeCombo->setCurrentIndex(static_cast<int>(SettingsManager::getInstance()->defaultPlottype()));

    cancelButton = new QPushButton("Cancel");
    okayButton = new QPushButton("Okay");

    settingsItemsLayout->setColumnStretch(1, 4);
    settingsItemsLayout->setColumnStretch(2, 8);
    settingsItemsLayout->setColumnStretch(3, 1);

    settingsItemsLayout->addWidget(defaultDbLocationLabel, 1, 1, 1, 1);
    settingsItemsLayout->addWidget(defaultDbLocationEdit, 1, 2, 1, 1);
    settingsItemsLayout->addWidget(openFileSelectButton, 1, 3, 1, 1);
    settingsItemsLayout->addWidget(defaultPlottypeLabel, 2, 1);
    settingsItemsLayout->addWidget(defaultPlottypeCombo, 2, 2, 1, 2);

    bottomButtonLayout->addWidget(cancelButton, 1);
    bottomButtonLayout->addStretch(2);
    bottomButtonLayout->addWidget(okayButton, 1);

    topLevelLayout->addItem(settingsItemsLayout);
    topLevelLayout->addSpacerItem(new QSpacerItem(200, 5));
    topLevelLayout->addItem(bottomButtonLayout);
    setLayout(topLevelLayout);
    setMinimumWidth(640);

    /* signals */
    connect(SettingsManager::getInstance(), SIGNAL(databaseLocationChanged(QString)),
            defaultDbLocationEdit, SLOT(setText(QString)));
    connect(SettingsManager::getInstance(), SIGNAL(defaultPlottypeChanged(PlotType)),
            defaultPlottypeCombo, SLOT(setCurrentIndex(int)));
    connect(this, SIGNAL(dbLocationChanged(QString)), SettingsManager::getInstance(),
            SLOT(setDatabaseLocation(QString)));
    connect(this, SIGNAL(defaultPlottypeChanged(PlotType)), SettingsManager::getInstance(),
            SLOT(setDefaultPlotType(PlotType)));
    connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
    connect(okayButton, SIGNAL(clicked()), this, SLOT(onPressOkay()));
}

void
SettingsDialog::onPressOkay()
{
    emit dbLocationChanged(defaultDbLocationEdit->text());
    emit defaultPlottypeChanged(static_cast<PlotType>(defaultPlottypeCombo->currentIndex()));
    accept();
}
{'fraction_non_alphanumeric': 0.12359550561797752, 'fraction_numerical': 0.017807928768284926, 'mean_word_length': 5.5986013986013985, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6119730', 'n_tokens_mistral': 1456, 'n_tokens_neox': 1339, 'n_words': 224}