Skip to content
Snippets Groups Projects
Commit b73025fe authored by Benjamin Jakimow's avatar Benjamin Jakimow
Browse files

PlotStyles now pickable

parent e00f9f94
No related branches found
No related tags found
No related merge requests found
......@@ -86,19 +86,43 @@ class PlotStyle(QObject):
p.end()
return QIcon(pm)
def __ne__(self, other):
return not self.__eq__(other)
def __eq__(self, other):
if not isinstance(other, PlotStyle):
return False
for k in self.__dict__.keys():
if not self.__dict__[k] == other.__dict__[k]:
return False
return True
def __reduce_ex__(self, protocol):
return self.__class__, (), self.__getstate__()
def __getstate__(self):
result = dict()
for k, i in self.__dict__.items():
t = type(i)
if t in [str, int, float, QColor]:
result[k] = i
result = self.__dict__.copy()
ba = QByteArray()
s = QDataStream(ba, QIODevice.WriteOnly)
s.writeQVariant(self.linePen)
s.writeQVariant(self.markerPen)
s.writeQVariant(self.markerBrush)
result['__tmp__'] = ba
result.pop('linePen')
result.pop('markerPen')
result.pop('markerBrush')
return result
def __setstate__(self, state):
ba = state['__tmp__']
s = QDataStream(ba)
state['linePen'] = s.readQVariant()
state['markerPen'] = s.readQVariant()
state['markerBrush'] = s.readQVariant()
self.__dict__.update(state)
class PlotStyleWidget(QWidget, loadUi('plotstylewidget.ui')):
......@@ -347,7 +371,8 @@ if __name__ == '__main__':
import pickle
s1 = PlotStyle()
s2 = pickle.loads(pickle.dumps(s1))
assert s1 == s2
assert isinstance(s2, PlotStyle)
btn = PlotStyleButton()
btn.show()
qgsApp.exec_()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment