From 738ecbd5fad2b46836bfd6a94aeebf165ae2bbca Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Thu, 4 Jan 2018 16:00:52 +0100 Subject: relocated source code to the root --- src/data/graphelementproperty.cpp | 59 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/data/graphelementproperty.cpp (limited to 'src/data/graphelementproperty.cpp') diff --git a/src/data/graphelementproperty.cpp b/src/data/graphelementproperty.cpp new file mode 100644 index 0000000..a50af58 --- /dev/null +++ b/src/data/graphelementproperty.cpp @@ -0,0 +1,59 @@ +#include "graphelementproperty.h" + +#include + +GraphElementProperty::GraphElementProperty (): + _key(""), _value(""), _atom(false), _keyMatch(false) +{} + +GraphElementProperty::GraphElementProperty(QString key, QString value, bool atom, bool keyMatch) : + _key(key), _value(value), _atom(atom), _keyMatch(keyMatch) +{} + +GraphElementProperty::GraphElementProperty(QString key, QString value) : + _key(key), _value(value), _atom(false), _keyMatch(false) +{} + +GraphElementProperty::GraphElementProperty(QString key, bool keyMatch) : + _key(key), _value(""), _atom(!keyMatch), _keyMatch(keyMatch) +{} + +QString GraphElementProperty::key() const +{ return _key; } + +QString GraphElementProperty::value() const +{ return _value; } + +void GraphElementProperty::setValue(const QString &value) +{ _value = value; } + +bool GraphElementProperty::atom() const +{ return _atom; } + +bool GraphElementProperty::keyMatch() const +{ return _keyMatch; } + +bool GraphElementProperty::matches(const GraphElementProperty &p) +{ + if (p.atom()) return _atom && _key == p.key(); + if (p.keyMatch()) return !_atom && _key == p.key(); + if (_keyMatch) return !p.atom() && _key == p.key(); + return !_atom && _key == p.key() && _value == p.value(); +} + +bool GraphElementProperty::operator==(const GraphElementProperty &p) +{ + return matches(p); +} + +QString GraphElementProperty::tikzEscape(QString str) +{ + QRegExp re("[0-9a-zA-Z<> \\-'.]*"); + if (re.exactMatch(str)) return str; + else return "{" + str + "}"; +} + +QString GraphElementProperty::tikz() { + if (_atom) return tikzEscape(_key); + return tikzEscape(_key) + "=" + tikzEscape(_value); +} -- cgit v1.2.3