Last active
August 29, 2015 14:15
-
-
Save drewpts/2e77d5fcc36b2d715c16 to your computer and use it in GitHub Desktop.
Draft variant for save function. It's in gists because there is no task for it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace { | |
template <typename T> | |
bool appendToJsonInTextRepresentation(const T& valToAppend, const char * whereToAppend, std::string& str) | |
{ | |
int positionOfFilesKey = str.find(whereToAppend); | |
int positionOfClosingBracket = str.find (string("]"), positionOfFilesKey); | |
switch (str.at(positionOfClosingBracket - 1)) | |
{ | |
case ' ': | |
{ | |
str.insert(positionOfClosingBracket - 1, (string(", \"") + valToAppend).append("\"")); | |
} | |
break; | |
case '\"': | |
{ | |
str.insert(positionOfClosingBracket, (string(", \"") + valToAppend).append("\"")); | |
} | |
break; | |
default: | |
{ | |
return false; | |
} | |
break; | |
} | |
return true; | |
} | |
} | |
void LibprojPlugin::saveProjectData(const string & WhatToAppend, const string & WhereToAppend) | |
{ | |
qDebug() << QString(WhatToAppend.c_str()); | |
string | |
dumpedData = project->getProjectData().dump(), | |
errors; | |
bool result = appendToJsonInTextRepresentation<string>(WhatToAppend, WhereToAppend.c_str(), dumpedData); | |
if (result) { | |
project->setProjectData(Json::parse(dumpedData, errors)); | |
} | |
else | |
qWarning() << "Error when modifying json representation"; | |
qDebug() << QString(errors.c_str()); | |
QFile projectFile(projectFilename); | |
if(!projectFile.open( QIODevice::ReadWrite | QIODevice::Text )) | |
qDebug() << "File unsuccessfully opened"; | |
else | |
qDebug() << "File successfully opened"; | |
QTextStream outStream(&projectFile); | |
outStream << dumpedData.c_str(); | |
projectFile.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment