Пример #1
0
bool Profile::loadProfile(QString fileName, bool loadDefault) {

  QFile file(fileName);

  // Check if file exists, if not create default profile
  if(!file.exists()) {

    if(loadDefault) {
      loadDefaultProfile();
      return true;
    }
    else
      return false;
  }

  // Read profile data from file

  dataPoints.clear();

  QJsonDocument json;

  if(file.open(QFile::ReadOnly)) {
    qDebug() << "Loading profile data from " << fileName;

    QJsonParseError error;

    json = QJsonDocument().fromJson(file.readAll(), &error);

    // Check if JSON was correctly parsed
    if (error.error != QJsonParseError::NoError) {

      qDebug() << error.errorString();
      return false;
    }

    // Read JSON values
    QJsonObject object     = json.object();
    QJsonArray profileData = object.value("profileData").toArray();

    profileName = object.value("profileName").toString();

    // Convert the JSON array to a Trade List
    for(int i = 0; i < profileData.size(); i++) {

      // Convert the JSON values
      QJsonObject dataPointObject = profileData[i].toObject();

      float time = dataPointObject.value("time").toDouble();
      float temp = dataPointObject.value("temp").toDouble();

      // Create a trade object from the converted values
      DataPoint dataPoint(time, temp);

      // Append the new trade object to the trade list
      dataPoints.append(dataPoint);
    }
  }

  return true;
}
Пример #2
0
/** Constructor.
 *
 * Initialises other modules.
 *
 */
ProfileManager::ProfileManager(const std::string profilename)
    : logger("ProfileManager", std::cerr)
{
    xmlProfileDoc = 0;
    if (profilename.empty()) {
        loadDefaultProfile();
    } else {
        loadProfile(profilename);
    }
}