예제 #1
0
파일: table.cpp 프로젝트: PLaGInc/CG
void table::Save(QString filePath)
{
    if (m_model->smthChanged || filePath != "")
    {
        if (m_fileName == "" && filePath == "")
        {
            SaveAs();
            return;
        }
        if (filePath == "")
        {
            filePath = m_fileName;
        }
        QFile f(filePath);
        if(f.open(QIODevice::WriteOnly))
        {
            QVariantMap data;
            for (int i = 0; i < m_model->rowCount(QModelIndex()); ++i)
            {
                data.insert(m_model->data(m_model->index(i, 0), Qt::DisplayRole).toString(),
                            m_model->data(m_model->index(i, 1), Qt::DisplayRole).toInt());
            }
            QJsonDocument doc;
            f.write(doc.fromVariant(data).toJson());
            f.close();
        }
        m_fileName = filePath;
        m_model->smthChanged = false;
        ui->actionSave->setEnabled(false);
    }
}
예제 #2
0
파일: mainwindow.cpp 프로젝트: scrinoman/CG
bool MainWindow::Save()
{
    QFile json(m_fileName);
    if(json.open(QIODevice::WriteOnly))
    {
        QJsonDocument doc;
        QList<Population> modelData = m_model->GetData();
        QVariantMap data;
        for (int i = 0; i < modelData.count(); ++i)
        {
            data.insert(modelData[i].GetCountry(), modelData[i].GetPopulation());
        }
        json.write(doc.fromVariant(data).toJson());
        json.close();

        m_isSomethingChanged  = false;
        return true;
    }
    return false;
}