Advertisement
karenaaa

Untitled

Aug 3rd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. bool KhipuData::saveData(QList<KhipuSpace*> spaceList, QString fileName)
  2. {
  3. fileName = fileName + ".json";
  4. QFile file(fileName);
  5.  
  6. if (!file.open(QIODevice::WriteOnly)) {
  7. qDebug() << "Não deu pra salvar o arquivo";
  8. return false;
  9. }
  10.  
  11. QJsonObject spaces;
  12. for (int i = 0; i < spaceList.size(); i++){
  13. QJsonObject space;
  14. space["name"] = spaceList[i]->name();
  15. space["id"] = spaceList[i]->id();
  16. space["type"] = spaceList[i]->type();
  17.  
  18. qDebug() << spaceList[i]->model()->rowCount();
  19.  
  20. QJsonObject plots;
  21. QModelIndex model;
  22.  
  23. auto *plotsModel = spaceList[i]->model();
  24.  
  25. for (int j = 0; j < spaceList[i]->model()->rowCount(); j++){
  26. QJsonObject plot;
  27. auto plotIndex = plotsModel->index(j, 0);
  28. auto data = plotsModel->data(plotIndex, Analitza::PlotsModel::DescriptionRole);
  29.  
  30. plot["expression"] = data.toString();
  31. //qDebug() << spaceList[i]->plots().at(j)->strExpression();*/
  32. plots.insert(QString::number(j),plot);
  33. }
  34. space["plots"] = plots;
  35.  
  36. spaces.insert(QString::number(i),space);
  37. }
  38.  
  39. QJsonDocument doc(spaces);
  40. file.write(doc.toJson());
  41. file.close();
  42.  
  43. return true;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement