"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "gmic-qt/src/ParametersCache.cpp" between
gmic_2.8.1.tar.gz and gmic_2.8.2.tar.gz

About: G’MIC (GREY’s Magic for Image Computing) is a framework for image processing. It provides several different user interfaces to convert/manipulate/filter/ visualize generic image datasets (usable standalone or as plug-in for GIMP and Krita).

ParametersCache.cpp  (gmic_2.8.1):ParametersCache.cpp  (gmic_2.8.2)
skipping to change at line 36 skipping to change at line 36
#include <QBuffer> #include <QBuffer>
#include <QDataStream> #include <QDataStream>
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
#include <QJsonArray> #include <QJsonArray>
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
#include <iostream> #include <iostream>
#include "Common.h" #include "Common.h"
#include "Globals.h" #include "Globals.h"
#include "Logger.h"
#include "Utils.h" #include "Utils.h"
#include "gmic.h" #include "gmic.h"
QHash<QString, QList<QString>> ParametersCache::_parametersCache; QHash<QString, QList<QString>> ParametersCache::_parametersCache;
QHash<QString, GmicQt::InputOutputState> ParametersCache::_inOutPanelStates; QHash<QString, GmicQt::InputOutputState> ParametersCache::_inOutPanelStates;
QHash<QString, QList<int>> ParametersCache::_visibilityStates; QHash<QString, QList<int>> ParametersCache::_visibilityStates;
void ParametersCache::load(bool loadFiltersParameters) void ParametersCache::load(bool loadFiltersParameters)
{ {
// Load JSON file // Load JSON file
skipping to change at line 68 skipping to change at line 69
QByteArray allFile = jsonFile.readAll(); QByteArray allFile = jsonFile.readAll();
if (allFile.startsWith("{\n")) { if (allFile.startsWith("{\n")) {
jsonDoc = QJsonDocument::fromJson(allFile); jsonDoc = QJsonDocument::fromJson(allFile);
} else { } else {
jsonDoc = QJsonDocument::fromBinaryData(qUncompress(allFile)); jsonDoc = QJsonDocument::fromBinaryData(qUncompress(allFile));
} }
#else #else
QJsonDocument jsonDoc = QJsonDocument::fromBinaryData(qUncompress(jsonFile.r eadAll())); QJsonDocument jsonDoc = QJsonDocument::fromBinaryData(qUncompress(jsonFile.r eadAll()));
#endif #endif
if (jsonDoc.isNull()) { if (jsonDoc.isNull()) {
std::cerr << "[gmic-qt] Warning: cannot parse " << jsonFilename.toStdStrin Logger::warning(QString("Cannot parse ") + jsonFilename);
g() << std::endl; Logger::warning("Last filters parameters are lost!");
std::cerr << "[gmic-qt] Last filters parameters are lost!\n";
} else { } else {
if (!jsonDoc.isObject()) { if (!jsonDoc.isObject()) {
std::cerr << "[gmic-qt] Error: JSON file format is not correct (" << jso nFilename.toStdString() << ")\n"; Logger::error(QString("JSON file format is not correct (") + jsonFilenam e + ")");
} else { } else {
QJsonObject documentObject = jsonDoc.object(); QJsonObject documentObject = jsonDoc.object();
QJsonObject::iterator itFilter = documentObject.begin(); QJsonObject::iterator itFilter = documentObject.begin();
while (itFilter != documentObject.end()) { while (itFilter != documentObject.end()) {
QString hash = itFilter.key(); QString hash = itFilter.key();
QJsonObject filterObject = itFilter.value().toObject(); QJsonObject filterObject = itFilter.value().toObject();
// Retrieve parameters // Retrieve parameters
if (loadFiltersParameters) { if (loadFiltersParameters) {
QJsonValue parameters = filterObject.value("parameters"); QJsonValue parameters = filterObject.value("parameters");
if (!parameters.isUndefined()) { if (!parameters.isUndefined()) {
skipping to change at line 111 skipping to change at line 112
// Retrieve Input/Output state // Retrieve Input/Output state
if (!state.isUndefined()) { if (!state.isUndefined()) {
QJsonObject stateObject = state.toObject(); QJsonObject stateObject = state.toObject();
_inOutPanelStates[hash] = GmicQt::InputOutputState::fromJSONObject(s tateObject); _inOutPanelStates[hash] = GmicQt::InputOutputState::fromJSONObject(s tateObject);
} }
++itFilter; ++itFilter;
} }
} }
} }
} else { } else {
std::cerr << "[gmic-qt] Error: Cannot read " << jsonFilename.toStdString() < Logger::error("Cannot read " + jsonFilename);
< std::endl; Logger::error("Parameters cannot be restored");
std::cerr << "[gmic-qt] Parameters cannot be restored.\n";
} }
} }
void ParametersCache::save() void ParametersCache::save()
{ {
// JSON Document format // JSON Document format
// //
// { // {
// "51d288e6f1c6e531cc61289f17e34d8a": { // "51d288e6f1c6e531cc61289f17e34d8a": {
// "parameters": [ // "parameters": [
skipping to change at line 147 skipping to change at line 148
// 1, // 1,
// 2, // 2,
// 0 // 0
// ] // ]
// } // }
// } // }
QJsonObject documentObject; QJsonObject documentObject;
// Add Input/Output states // Add Input/Output states
QHash<QString, GmicQt::InputOutputState>::iterator itState = _inOutPanelStates .begin(); QHash<QString, GmicQt::InputOutputState>::iterator itState = _inOutPanelStates .begin();
while (itState != _inOutPanelStates.end()) { while (itState != _inOutPanelStates.end()) {
QJsonObject filterObject; QJsonObject filterObject;
QJsonObject jsonState; QJsonObject jsonState;
itState.value().toJSONObject(jsonState); itState.value().toJSONObject(jsonState);
filterObject.insert("in_out_state", jsonState); filterObject.insert("in_out_state", jsonState);
documentObject.insert(itState.key(), filterObject); documentObject.insert(itState.key(), filterObject);
++itState; ++itState;
} }
skipping to change at line 224 skipping to change at line 224
jsonFile.close(); jsonFile.close();
if (count != -1) { if (count != -1) {
// Remove obsolete 2.0.0 pre-release files // Remove obsolete 2.0.0 pre-release files
const QString & path = GmicQt::path_rc(true); const QString & path = GmicQt::path_rc(true);
QFile::remove(path + "gmic_qt_parameters.dat"); QFile::remove(path + "gmic_qt_parameters.dat");
QFile::remove(path + "gmic_qt_parameters.json"); QFile::remove(path + "gmic_qt_parameters.json");
QFile::remove(path + "gmic_qt_parameters.json.bak"); QFile::remove(path + "gmic_qt_parameters.json.bak");
QFile::remove(path + "gmic_qt_parameters_json.dat"); QFile::remove(path + "gmic_qt_parameters_json.dat");
} }
} else { } else {
std::cerr << "[gmic-qt] Error: Cannot write " << jsonFilename.toStdString() Logger::error("Cannot write " + jsonFilename);
<< std::endl; Logger::error("Parameters cannot be saved");
std::cerr << "[gmic-qt] Parameters cannot be saved.\n";
} }
} }
void ParametersCache::setValues(const QString & hash, const QList<QString> & val ues) void ParametersCache::setValues(const QString & hash, const QList<QString> & val ues)
{ {
_parametersCache[hash] = values; _parametersCache[hash] = values;
} }
QList<QString> ParametersCache::getValues(const QString & hash) QList<QString> ParametersCache::getValues(const QString & hash)
{ {
skipping to change at line 266 skipping to change at line 266
{ {
_parametersCache.remove(hash); _parametersCache.remove(hash);
_inOutPanelStates.remove(hash); _inOutPanelStates.remove(hash);
} }
GmicQt::InputOutputState ParametersCache::getInputOutputState(const QString & ha sh) GmicQt::InputOutputState ParametersCache::getInputOutputState(const QString & ha sh)
{ {
if (_inOutPanelStates.contains(hash)) { if (_inOutPanelStates.contains(hash)) {
return _inOutPanelStates[hash]; return _inOutPanelStates[hash];
} }
return GmicQt::InputOutputState::Default; return GmicQt::InputOutputState(GmicQt::UnspecifiedInputMode, GmicQt::DefaultO utputMode, GmicQt::DefaultPreviewMode);
} }
void ParametersCache::setInputOutputState(const QString & hash, const GmicQt::In putOutputState & state) void ParametersCache::setInputOutputState(const QString & hash, const GmicQt::In putOutputState & state, const GmicQt::InputMode defaultInputMode)
{ {
if (state.isDefault()) { if ((state == GmicQt::InputOutputState(defaultInputMode, GmicQt::DefaultOutput
Mode, GmicQt::DefaultPreviewMode)) //
|| (state == GmicQt::InputOutputState(GmicQt::UnspecifiedInputMode, GmicQt
::DefaultOutputMode, GmicQt::DefaultPreviewMode))) {
_inOutPanelStates.remove(hash); _inOutPanelStates.remove(hash);
return; return;
} }
_inOutPanelStates[hash] = state; _inOutPanelStates[hash] = state;
} }
void ParametersCache::cleanup(const QSet<QString> & hashesToKeep) void ParametersCache::cleanup(const QSet<QString> & hashesToKeep)
{ {
QSet<QString> obsoleteHashes; QSet<QString> obsoleteHashes;
 End of changes. 9 change blocks. 
14 lines changed or deleted 14 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)