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): ...@@ -86,19 +86,43 @@ class PlotStyle(QObject):
p.end() p.end()
return QIcon(pm) 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): def __reduce_ex__(self, protocol):
return self.__class__, (), self.__getstate__() return self.__class__, (), self.__getstate__()
def __getstate__(self): def __getstate__(self):
result = dict() result = self.__dict__.copy()
for k, i in self.__dict__.items():
t = type(i) ba = QByteArray()
if t in [str, int, float, QColor]: s = QDataStream(ba, QIODevice.WriteOnly)
result[k] = i 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 return result
def __setstate__(self, state): 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) self.__dict__.update(state)
class PlotStyleWidget(QWidget, loadUi('plotstylewidget.ui')): class PlotStyleWidget(QWidget, loadUi('plotstylewidget.ui')):
...@@ -347,7 +371,8 @@ if __name__ == '__main__': ...@@ -347,7 +371,8 @@ if __name__ == '__main__':
import pickle import pickle
s1 = PlotStyle() s1 = PlotStyle()
s2 = pickle.loads(pickle.dumps(s1)) s2 = pickle.loads(pickle.dumps(s1))
assert s1 == s2 assert isinstance(s2, PlotStyle)
btn = PlotStyleButton() btn = PlotStyleButton()
btn.show() btn.show()
qgsApp.exec_() 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