void StatsSerializer::deserialize(const QJsonObject &source, StatsKeyValueModel &dest)
{
    QJsonArray values = source[KEY_VALUES].toArray();
    for (QJsonValue const& value : values)
    {
        QJsonObject pairObj = value.toObject();
        QStringList keys = pairObj.keys();
        if (keys.size() != 1)
        {
            assert(!"deserialize error: incorrect JSON format");
        }
        else
        {
            QString const& key = keys[0];
            dest.append(key, pairObj[key].toInt());
        }
    }
}
Exemple #2
0
void MainWindow::on_actionDeleteRow_triggered()
{
    std::set<int> deletedRows = m_ui->tableData->selectedRows();
    if (deletedRows.size() == 0)
    {
        return;
    }

    auto statsModel = m_tableModel->statsModel();
    StatsKeyValueModel newModel;
    for (size_t i = 0, n = statsModel.size(); i < n; ++i)
    {
        if (deletedRows.count(i))
        {
            continue;
        }
        newModel.append(statsModel.key(i), statsModel.value(i));
    }
    m_tableModel->setStatsModel(newModel);
    m_tableModel->setIsNotSaved();
}