<commit_before>/* This source file is part of the Tomviz project, https://tomviz.org/.
   It is released under the 3-Clause BSD License, see "LICENSE". */

#include "DataBrokerLoadDialog.h"
#include "DataBroker.h"
#include "Utilities.h"

#include "ui_DataBrokerLoadDialog.h"

#include <QDateTime>
#include <QDebug>
#include <QPushButton>
#include <QTreeWidget>

#include <pqSettings.h>

namespace tomviz {

const char* DATABROKER_GROUP = "DataBroker";
const char* FILTER_FROM_SETTINGS_LABEL = "FilterFromDate";
const char* FILTER_TO_SETTINGS_LABEL = "FilterToDate";
const char* LIMIT_SETTINGS_LABEL = "Limit";

DataBrokerLoadDialog::DataBrokerLoadDialog(DataBroker* dataBroker,
                                           QWidget* parent)
  : QDialog(parent), m_ui(new Ui::DataBrokerLoadDialog),
    m_dataBroker(dataBroker)
{
  m_ui->setupUi(this);
  allowFilter(false);
  enableFilter(false);
  m_ui->fromDateEdit->setCalendarPopup(true);
  m_ui->toDateEdit->setCalendarPopup(true);
  m_ui->fromDateEdit->setDate(QDate::currentDate().addDays(-365));
  m_ui->toDateEdit->setDate(QDate::currentDate().addDays(1));

  auto tree = m_ui->treeWidget;
  tree->setExpandsOnDoubleClick(false);
  tree->header()->setSectionResizeMode(QHeaderView::ResizeToContents);

  auto resetButton = m_ui->buttonBox->button(QDialogButtonBox::Reset);
  connect(resetButton, &QPushButton::clicked, this, [this]() {
    setEnabledOkButton(false);
    clearErrorMessage();
    this->loadCatalogs();
  });

  connect(m_ui->filterByDateCheckBox, &QPushButton::toggled, this,
          [this](bool enable) {
            this->enableFilter(enable);
            this->applyFilter();
          });

  connect(m_ui->fromDateEdit, &QDateEdit::dateChanged, this,
          [this](QDate date) { m_fromDate = date; });

  connect(m_ui->toDateEdit, &QDateEdit::dateChanged, this,
          [this](QDate date) { m_toDate = date; });

  connect(m_ui->applyFilterButton, &QPushButton::clicked, this,
          &DataBrokerLoadDialog::applyFilter);

  setEnabledOkButton(false);

  // Load settings
  QSettings* settings = pqApplicationCore::instance()->settings();
  settings->beginGroup(DATABROKER_GROUP);
  if (settings->contains(FILTER_FROM_SETTINGS_LABEL)) {
    m_fromDate = settings->value(FILTER_FROM_SETTINGS_LABEL).toDate();
    m_ui->fromDateEdit->setDate(m_fromDate);
  }

  if (settings->contains(FILTER_TO_SETTINGS_LABEL)) {
    m_toDate = settings->value(FILTER_TO_SETTINGS_LABEL).toDate();
    m_ui->toDateEdit->setDate(m_toDate);
  }

  if (settings->contains(LIMIT_SETTINGS_LABEL)) {
    m_limit = settings->value(LIMIT_SETTINGS_LABEL).toInt();
    m_ui->limitSpinBox->setValue(m_limit);
  }
  settings->endGroup();

  loadRuns(m_selectedCatalog, m_dateFilter, m_fromDate, m_toDate, m_limit);
}

DataBrokerLoadDialog::~DataBrokerLoadDialog() = default;

void DataBrokerLoadDialog::loadCatalogs()
{
  beginCall();

  auto call = m_dataBroker->catalogs();
  connect(call, &ListResourceCall::complete, call,
          [this, call](QList<QVariantMap> catalogs) {
            this->m_catalogs = catalogs;
            this->showCatalogs();
            this->setLabel("Please select a catalog");
            this->endCall();
            call->deleteLater();
          });
<commit_msg>Allow catalog to be overridden<commit_after>/* This source file is part of the Tomviz project, https://tomviz.org/.
   It is released under the 3-Clause BSD License, see "LICENSE". */

#include "DataBrokerLoadDialog.h"
#include "DataBroker.h"
#include "Utilities.h"

#include "ui_DataBrokerLoadDialog.h"

#include <QDateTime>
#include <QDebug>
#include <QProcessEnvironment>
#include <QPushButton>
#include <QTreeWidget>

#include <pqSettings.h>

namespace tomviz {

const char* DATABROKER_GROUP = "DataBroker";
const char* FILTER_FROM_SETTINGS_LABEL = "FilterFromDate";
const char* FILTER_TO_SETTINGS_LABEL = "FilterToDate";
const char* LIMIT_SETTINGS_LABEL = "Limit";

DataBrokerLoadDialog::DataBrokerLoadDialog(DataBroker* dataBroker,
                                           QWidget* parent)
  : QDialog(parent), m_ui(new Ui::DataBrokerLoadDialog),
    m_dataBroker(dataBroker)
{
  m_ui->setupUi(this);
  allowFilter(false);
  enableFilter(false);
  m_ui->fromDateEdit->setCalendarPopup(true);
  m_ui->toDateEdit->setCalendarPopup(true);
  m_ui->fromDateEdit->setDate(QDate::currentDate().addDays(-365));
  m_ui->toDateEdit->setDate(QDate::currentDate().addDays(1));

  auto tree = m_ui->treeWidget;
  tree->setExpandsOnDoubleClick(false);
  tree->header()->setSectionResizeMode(QHeaderView::ResizeToContents);

  auto resetButton = m_ui->buttonBox->button(QDialogButtonBox::Reset);
  connect(resetButton, &QPushButton::clicked, this, [this]() {
    setEnabledOkButton(false);
    clearErrorMessage();
    this->loadCatalogs();
  });

  connect(m_ui->filterByDateCheckBox, &QPushButton::toggled, this,
          [this](bool enable) {
            this->enableFilter(enable);
            this->applyFilter();
          });

  connect(m_ui->fromDateEdit, &QDateEdit::dateChanged, this,
          [this](QDate date) { m_fromDate = date; });

  connect(m_ui->toDateEdit, &QDateEdit::dateChanged, this,
          [this](QDate date) { m_toDate = date; });

  connect(m_ui->applyFilterButton, &QPushButton::clicked, this,
          &DataBrokerLoadDialog::applyFilter);

  setEnabledOkButton(false);

  // Load settings
  QSettings* settings = pqApplicationCore::instance()->settings();
  settings->beginGroup(DATABROKER_GROUP);
  if (settings->contains(FILTER_FROM_SETTINGS_LABEL)) {
    m_fromDate = settings->value(FILTER_FROM_SETTINGS_LABEL).toDate();
    m_ui->fromDateEdit->setDate(m_fromDate);
  }

  if (settings->contains(FILTER_TO_SETTINGS_LABEL)) {
    m_toDate = settings->value(FILTER_TO_SETTINGS_LABEL).toDate();
    m_ui->toDateEdit->setDate(m_toDate);
  }

  if (settings->contains(LIMIT_SETTINGS_LABEL)) {
    m_limit = settings->value(LIMIT_SETTINGS_LABEL).toInt();
    m_ui->limitSpinBox->setValue(m_limit);
  }
  settings->endGroup();

  // See we have a catalog override in the environment
  QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
  if (env.contains("TILED_CATALOG")) {
    m_selectedCatalog = env.value("TILED_CATALOG");
  }

  loadRuns(m_selectedCatalog, m_dateFilter, m_fromDate, m_toDate, m_limit);
}

DataBrokerLoadDialog::~DataBrokerLoadDialog() = default;

void DataBrokerLoadDialog::loadCatalogs()
{
  beginCall();

  auto call = m_dataBroker->catalogs();
  connect(call, &ListResourceCall::complete, call,
          [this, call](QList<QVariantMap> catalogs) {
            this->m_catalogs = catalogs;
            this->showCatalogs();
            this->setLabel("Please select a catalog");
            this->endCall();
            call->deleteLater();
          });

{'fraction_non_alphanumeric': 0.13712177121771219, 'fraction_numerical': 0.0014760147601476014, 'mean_word_length': 4.50446791226645, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 102, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5914665', 'n_tokens_mistral': 2243, 'n_tokens_neox': 2255, 'n_words': 348}