// Process the drawn lines to produces results from the model
QStringList HandwritingEngine::query(int s, int x, int y)
{
    m_results_list.clear();
    emit resultsChanged(m_results_list);

    // add a line to the current character
    m_character->add(s, x, y);

    // based on current character being drawn, we get some result
    m_result = m_recognizer->classify(*m_character, m_results_size);
    if (!m_result)
        qDebug("can't find m_result");
    else
    {
        for (u_int32_t i = 0; i < m_result->size(); ++i)
        {
//            qDebug() << "m_result found : " << QString::fromLocal8Bit(m_result->value(i));
            m_results_list << QString::fromLocal8Bit(m_result->value(i));
            emit resultsChanged(m_results_list);
        }
    }
    return m_results_list;
}
void ContestResultsApi::updateResults(capnp::List<ContestResults::TalliedOpinion>::Reader talliedOpinions) {
    // Allocate space in m_contestantResults
    m_contestantResults.clear();
    for (auto tally : talliedOpinions)
        while (tally.getContestant().isContestant() &&
               m_contestantResults.size() <= tally.getContestant().getContestant())
            m_contestantResults.append(0);

    for (auto contestantTally : talliedOpinions) {
        auto tally = QVariant(static_cast<qreal>(contestantTally.getTally()));
        if (contestantTally.getContestant().isContestant())
            m_contestantResults[contestantTally.getContestant().getContestant()] = tally;
        else
            m_writeInResults.insert(convertText(contestantTally.getContestant().getWriteIn()), tally);
    }
    emit resultsChanged();
}
/*!
  \brief Converts the last point assigned with \l setPointToConvert to all the
  notations specified in the options.
 */
void CoordinateConversionController::convertPoint()
{
  QList<Result> results;
  for (CoordinateConversionOptions* option : m_options)
  {
    if (isInputFormat(option))
      continue;

    results.append(Result(option->name(), convertPointInternal(option, m_pointToConvert), option->outputMode()));
  }

  if (results.isEmpty())
    resultsInternal()->clearResults();
  else
    resultsInternal()->setResults(std::move(results));

  emit resultsChanged();
}
bool QSpotifySearch::event(QEvent *e)
{
    if (e->type() == QEvent::User) {
        auto ev = static_cast<SearchResultEvent*>(e);
        if (ev) {
            if (auto search = ev->getSearch()) {
                g_mutex.lock();
                bool is_current = (m_sp_search == search);
                g_mutex.unlock();
                if (sp_search_error(search) == SP_ERROR_OK && is_current) {
                    if(ev->getPtr()) {
                        switch(ev->getPtr()->mType) {
                        case Albums:
                            populateAlbums(search);
                            break;
                        case Artists:
                            populateArtists(search);
                            break;
                        case Playlists:
                            populatePlaylists(search);
                            break;
                        case Tracks:
                            populateTracks(search);
                            break;
                        default:
                            populateResults(search);
                            break;
                        }
                    } else
                        populateResults(search);
                }
                clearSearch(search);
            }
        }
        setBusy(false);

        emit resultsChanged();

        e->accept();
        return true;
    }
    return QObject::event(e);
}
void HandwritingEngine::clear()
{
    m_character->clear();
    m_results_list.clear();
    emit resultsChanged(m_results_list);
}