diff --git a/timeseriesviewer/plotstyling.py b/timeseriesviewer/plotstyling.py index 9464a5620436e4d5112783f14d9488e4a039d545..a384efc4f72455106bf52c52bcdb2abb5452db81 100644 --- a/timeseriesviewer/plotstyling.py +++ b/timeseriesviewer/plotstyling.py @@ -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_()