<commit_before>/******************************************************************************

  This source file is part of the ChemData project.

  Copyright 2011-2012 Kitware, Inc.

  This source code is released under the New BSD License, (the "License").

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

******************************************************************************/

#include "quickquerywidget.h"
#include "ui_quickquerywidget.h"

#include <chemkit/molecule.h>

QuickQueryWidget::QuickQueryWidget(QWidget *parent)
  : QWidget(parent),
    ui(new Ui::QuickQueryWidget)
{
  ui->setupUi(this);

  connect(ui->queryButton, SIGNAL(clicked()), this, SIGNAL(queryClicked()));
  connect(ui->queryLineEdit, SIGNAL(returnPressed()), SIGNAL(queryClicked()));
}

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

QString QuickQueryWidget::field() const
{
  return ui->fieldComboBox->currentText();
}

QString QuickQueryWidget::value() const
{
  return ui->queryLineEdit->text();
}

mongo::Query QuickQueryWidget::query() const
{
  QString field = ui->fieldComboBox->currentText().toLower();
  QString value = ui->queryLineEdit->text();
  QString mode = ui->modeComboBox->currentText();

  if(value.isEmpty()){
    return mongo::Query();
  }
  else if(field == "structure"){
    chemkit::Molecule molecule(value.toStdString(), "smiles");
    int heavyAtomCount = molecule.atomCount() - molecule.atomCount("H");

    if(mode == "is"){
      return QUERY("heavyAtomCount" << heavyAtomCount).sort("heavyAtomCount");
    }
    else if(mode == "contains"){
      return QUERY("heavyAtomCount" << BSON("$gte" << heavyAtomCount)).sort("heavyAtomCount");
    }
  }
  else if(mode == "is"){
    return QUERY(field.toStdString() << value.toStdString());
  }
  else if(mode == "contains"){
    return QUERY(field.toStdString() << BSON("$regex" << value.toStdString()));
  }

  return mongo::Query();
}<commit_msg>Fix type conversion warning in QuickQueryWidget<commit_after>/******************************************************************************

  This source file is part of the ChemData project.

  Copyright 2011-2012 Kitware, Inc.

  This source code is released under the New BSD License, (the "License").

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

******************************************************************************/

#include "quickquerywidget.h"
#include "ui_quickquerywidget.h"

#include <chemkit/molecule.h>

QuickQueryWidget::QuickQueryWidget(QWidget *parent)
  : QWidget(parent),
    ui(new Ui::QuickQueryWidget)
{
  ui->setupUi(this);

  connect(ui->queryButton, SIGNAL(clicked()), this, SIGNAL(queryClicked()));
  connect(ui->queryLineEdit, SIGNAL(returnPressed()), SIGNAL(queryClicked()));
}

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

QString QuickQueryWidget::field() const
{
  return ui->fieldComboBox->currentText();
}

QString QuickQueryWidget::value() const
{
  return ui->queryLineEdit->text();
}

mongo::Query QuickQueryWidget::query() const
{
  QString field = ui->fieldComboBox->currentText().toLower();
  QString value = ui->queryLineEdit->text();
  QString mode = ui->modeComboBox->currentText();

  if(value.isEmpty()){
    return mongo::Query();
  }
  else if(field == "structure"){
    chemkit::Molecule molecule(value.toStdString(), "smiles");
    int heavyAtomCount =
      static_cast<int>(molecule.atomCount() - molecule.atomCount("H"));

    if(mode == "is"){
      return QUERY("heavyAtomCount" << heavyAtomCount).sort("heavyAtomCount");
    }
    else if(mode == "contains"){
      return QUERY("heavyAtomCount" << BSON("$gte" << heavyAtomCount)).sort("heavyAtomCount");
    }
  }
  else if(mode == "is"){
    return QUERY(field.toStdString() << value.toStdString());
  }
  else if(mode == "contains"){
    return QUERY(field.toStdString() << BSON("$regex" << value.toStdString()));
  }

  return mongo::Query();
}
{'fraction_non_alphanumeric': 0.20387911592241767, 'fraction_numerical': 0.0036084799278304014, 'mean_word_length': 5.246478873239437, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 32, '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': '4599454', 'n_tokens_mistral': 1341, 'n_tokens_neox': 1265, 'n_words': 319}