diff --git a/src/gui/control/graph.cpp b/src/gui/control/graph.cpp index 7733176a..9a539772 100644 --- a/src/gui/control/graph.cpp +++ b/src/gui/control/graph.cpp @@ -14,6 +14,7 @@ DECLARE_TYPEOF_COLLECTION(GraphAxisP); DECLARE_TYPEOF_COLLECTION(GraphElementP); DECLARE_TYPEOF_COLLECTION(GraphGroup); +DECLARE_TYPEOF_COLLECTION(int); typedef map map_String_UInt; DECLARE_TYPEOF(map_String_UInt); @@ -257,6 +258,19 @@ void GraphControl::onMouseDown(wxMouseEvent& ev) { } } +bool GraphControl::hasSelection(size_t axis) const { + return current_item.size() >= axis && current_item[axis] >= 0; +} +void GraphControl::getSelection(vector& out) const { + out.clear(); + if (!graph) return; + FOR_EACH_2_CONST(i, current_item, a, graph->getData().axes) { + if (i >= 0) { + out.push_back((size_t)i < a->groups.size() ? a->groups[i].name : wxEmptyString); + } + } +} + BEGIN_EVENT_TABLE(GraphControl, wxControl) EVT_PAINT (GraphControl::onPaint) EVT_SIZE (GraphControl::onSize) diff --git a/src/gui/control/graph.hpp b/src/gui/control/graph.hpp index 30546fc5..df148b71 100644 --- a/src/gui/control/graph.hpp +++ b/src/gui/control/graph.hpp @@ -90,6 +90,8 @@ class Graph { virtual bool findItem(const RealPoint& pos, const RealRect& rect, vector& out) const { return false; } /// Change the data virtual void setData(const GraphDataP& d) { data = d; } + /// Get the data + inline const GraphData& getData() const { return *data; } protected: /// Data of the graph @@ -162,6 +164,11 @@ class GraphControl : public wxControl { /// Update the data in the graph void setData(const GraphDataP& data); + /// Is there a selection on the given axis? + bool hasSelection(size_t axis) const; + /// Get the current item, returns the selected value on each axis in out + void getSelection(vector& out) const; + private: /// Graph object GraphP graph; diff --git a/src/gui/set/stats_panel.cpp b/src/gui/set/stats_panel.cpp index df67509b..b8d6b715 100644 --- a/src/gui/set/stats_panel.cpp +++ b/src/gui/set/stats_panel.cpp @@ -18,6 +18,7 @@ #include DECLARE_TYPEOF_COLLECTION(StatsDimensionP); +DECLARE_TYPEOF_COLLECTION(String); DECLARE_TYPEOF_COLLECTION(CardP); // ----------------------------------------------------------------------------- : StatCategoryList @@ -131,6 +132,24 @@ void StatsPanel::onCommand(int id) { } } +class StatsFilter : public CardListFilter { + public: + StatsFilter(Set& set, const vector& dims, const vector& values) + : set(set), dims(dims), values(values) + {} + virtual bool keep(const CardP& card) { + Context& ctx = set.getContext(card); + FOR_EACH_2(d, dims, v, values) { + if (*d->script.invoke(ctx) != v) return false; + } + return true; + } + private: + Set& set; + vector dims; + vector values; +}; + // ----------------------------------------------------------------------------- : Selection CardP StatsPanel::selectedCard() const {