-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add experimental printer attribute override
- Loading branch information
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "overrider.h" | ||
#include <QMutex> | ||
#include <QStandardPaths> | ||
#include <QtDebug> | ||
|
||
Overrider::Overrider() | ||
{ | ||
// QFile file(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)+"/overrides"); | ||
QFile file(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)+"/.seaprint_overrides"); | ||
qDebug() << "AAAAAAAAAAAAAAA" << file.fileName(); | ||
if(file.open(QIODevice::ReadOnly)) | ||
{ | ||
QJsonDocument JsonDocument = QJsonDocument::fromJson(file.readAll()); | ||
|
||
_overrides = JsonDocument.object(); | ||
qDebug() << "overides loaded" << _overrides; | ||
file.close(); | ||
} | ||
} | ||
|
||
Overrider::~Overrider() { | ||
} | ||
|
||
Overrider* Overrider::m_Instance = nullptr; | ||
|
||
Overrider* Overrider::instance() | ||
{ | ||
static QMutex mutex; | ||
if (!m_Instance) | ||
{ | ||
mutex.lock(); | ||
|
||
if (!m_Instance) | ||
m_Instance = new Overrider(); | ||
|
||
mutex.unlock(); | ||
} | ||
|
||
return m_Instance; | ||
} | ||
|
||
bool Overrider::apply(QJsonObject& attrs) | ||
{ | ||
bool applied = false; | ||
foreach(const QString& key, _overrides.keys()) | ||
{ | ||
if(attrs.contains(key)) | ||
{ | ||
QString match = attrs[key].toObject()["value"].toString(); | ||
if(match != "" && _overrides[key].toObject().contains(match)) | ||
{ | ||
QJsonObject overrideden_data = _overrides[key].toObject()[match].toObject(); | ||
foreach(const QString& o_key, overrideden_data.keys()) | ||
{ | ||
attrs.insert(o_key, overrideden_data[o_key]); | ||
} | ||
applied=true; | ||
} | ||
} | ||
} | ||
return applied; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef OVERRIDER_H | ||
#define OVERRIDER_H | ||
|
||
#include <QJsonDocument> | ||
#include <QJsonObject> | ||
#include <QFile> | ||
|
||
class Overrider | ||
{ | ||
public: | ||
static Overrider* instance(); | ||
bool apply(QJsonObject& attrs); | ||
|
||
private: | ||
Overrider(); | ||
~Overrider(); | ||
Overrider(const Overrider &); | ||
Overrider& operator=(const Overrider &); | ||
|
||
static Overrider* m_Instance; | ||
QJsonObject _overrides; | ||
}; | ||
|
||
#endif // OVERRIDER_H |