Skip to content

Commit

Permalink
Identify the type of Updater for Invalidation
Browse files Browse the repository at this point in the history
  • Loading branch information
micpap25 committed Aug 16, 2022
1 parent 24e2e50 commit 8e22263
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/widgets/CustomUpdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/CustomUpdaterPosition.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/CustomUpdaterValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/GeneratedUpdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/LinearUpdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/widgets/LogarithmicUpdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions src/widgets/Ruler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,19 @@ void Ruler::SetFormat(RulerFormat format)

void Ruler::SetUpdater(std::unique_ptr<RulerUpdater> 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)
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/RulerUpdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; };

Expand Down

0 comments on commit 8e22263

Please sign in to comment.