diff --git a/src/widgets/CustomUpdater.h b/src/widgets/CustomUpdater.h index a5f088de47dd..a724b6967ec1 100644 --- a/src/widgets/CustomUpdater.h +++ b/src/widgets/CustomUpdater.h @@ -27,6 +27,8 @@ class CustomUpdater : public RulerUpdater { UpdateOutputs& allOutputs, const RulerStruct& context, const std::any& data ) const final override; + virtual std::string Identify() const override = 0; + protected: virtual bool TickCustom(wxDC& dc, int labelIdx, wxFont font, TickOutputs outputs, diff --git a/src/widgets/CustomUpdaterPosition.h b/src/widgets/CustomUpdaterPosition.h index f15eab40dd71..93ebe8b58150 100644 --- a/src/widgets/CustomUpdaterPosition.h +++ b/src/widgets/CustomUpdaterPosition.h @@ -19,6 +19,8 @@ class CustomUpdaterPosition final : public CustomUpdater { using CustomUpdater::CustomUpdater; ~CustomUpdaterPosition() override; + std::string Identify() const override { return "CustomUpdaterPosition"; }; + protected: bool TickCustom(wxDC& dc, int labelIdx, wxFont font, TickOutputs outputs, diff --git a/src/widgets/CustomUpdaterValue.h b/src/widgets/CustomUpdaterValue.h index 113c2a1393bd..4f76f2562eee 100644 --- a/src/widgets/CustomUpdaterValue.h +++ b/src/widgets/CustomUpdaterValue.h @@ -19,6 +19,8 @@ class CustomUpdaterValue final : public CustomUpdater { using CustomUpdater::CustomUpdater; ~CustomUpdaterValue() override; + std::string Identify() const override { return "CustomUpdaterValue"; }; + protected: bool TickCustom(wxDC& dc, int labelIdx, wxFont font, TickOutputs outputs, diff --git a/src/widgets/GeneratedUpdater.h b/src/widgets/GeneratedUpdater.h index 6e491e4a7576..782962fbeb7d 100644 --- a/src/widgets/GeneratedUpdater.h +++ b/src/widgets/GeneratedUpdater.h @@ -24,6 +24,8 @@ class GeneratedUpdater : public RulerUpdater { UpdateOutputs& allOutputs, const RulerStruct& context, const std::any& data ) const override = 0; + virtual std::string Identify() const override = 0; + protected: bool Tick(wxDC& dc, int pos, double d, const TickSizes& tickSizes, wxFont font, diff --git a/src/widgets/LinearUpdater.h b/src/widgets/LinearUpdater.h index 04495d8c1a14..87211d7fdecb 100644 --- a/src/widgets/LinearUpdater.h +++ b/src/widgets/LinearUpdater.h @@ -25,6 +25,8 @@ class LinearUpdater final : public GeneratedUpdater { wxDC& dc, const Envelope* envelope, UpdateOutputs& allOutputs, const RulerStruct& context, const std::any& data ) const override; + + std::string Identify() const override { return "LinearUpdater"; }; }; #endif diff --git a/src/widgets/LogarithmicUpdater.h b/src/widgets/LogarithmicUpdater.h index bb15f763c453..47059fa2070c 100644 --- a/src/widgets/LogarithmicUpdater.h +++ b/src/widgets/LogarithmicUpdater.h @@ -22,6 +22,8 @@ class LogarithmicUpdater final : public GeneratedUpdater { wxDC& dc, const Envelope* envelope, UpdateOutputs& allOutputs, const RulerStruct& context, const std::any& data ) const override; + + std::string Identify() const override { return "LogarithmicUpdater"; }; }; #endif diff --git a/src/widgets/Ruler.cpp b/src/widgets/Ruler.cpp index afe1d0fecbaa..e13c23968e97 100644 --- a/src/widgets/Ruler.cpp +++ b/src/widgets/Ruler.cpp @@ -116,17 +116,19 @@ void Ruler::SetFormat(RulerFormat format) void Ruler::SetUpdater(std::unique_ptr pUpdater) { - // Should a comparison be made between mpUpdater and pUpdater? - // Runtime type comparison isn't clean in c++ - mpUpdater = std::move(pUpdater); - Invalidate(); + if (mpUpdater->Identify() != pUpdater->Identify()) { + mpUpdater = std::move(pUpdater); + Invalidate(); + } } -void Ruler::SetUpdaterData(const std::any &data) +void Ruler::SetUpdaterData(const std::any& data) { - mData = data; - Invalidate(); + if (&data != &mData) { + mData = data; + Invalidate(); + } } void Ruler::SetUnits(const TranslatableString &units) diff --git a/src/widgets/RulerUpdater.h b/src/widgets/RulerUpdater.h index 4717703f8d5c..d2711efa4bd4 100644 --- a/src/widgets/RulerUpdater.h +++ b/src/widgets/RulerUpdater.h @@ -93,6 +93,8 @@ class RulerUpdater { )// Envelope *speedEnv, long minSpeed, long maxSpeed ) const = 0; + virtual std::string Identify() const = 0; + protected: struct TickOutputs { Labels& labels; Bits& bits; wxRect& box; };