graph_analysis
GridLayout.hpp
Go to the documentation of this file.
1 #ifndef GRAPH_ANALYSIS_GUI_LAYOUTS_GRID_LAYOUT_HPP
2 #define GRAPH_ANALYSIS_GUI_LAYOUTS_GRID_LAYOUT_HPP
3 
4 #include "../GraphLayout.hpp"
5 #include <QPointF>
6 #include <QGraphicsGridLayout>
7 #include <boost/function.hpp>
8 
9 namespace graph_analysis {
10 namespace gui {
11 namespace layouts {
12 
13 typedef boost::function1<std::string, const graph_analysis::Vertex::Ptr&> GetLabelFunction;
14 typedef boost::function2<void,const graph_analysis::BaseGraph::Ptr&, std::vector<std::string>& > SortLabelFunction;
15 
21 class GridLayout : public GraphLayout
22 {
23 public:
24  typedef shared_ptr<GridLayout> Ptr;
25  typedef std::string ColumnLabel;
26  typedef std::string RowLabel;
27  typedef std::vector<ColumnLabel> ColumnLabels;
28  typedef std::vector<RowLabel> RowLabels;
29 
30  GridLayout(GetLabelFunction getColumnLabelFunction = GetLabelFunction(),
31  GetLabelFunction getRowLabelFunction = GetLabelFunction());
32 
33  virtual ~GridLayout();
34 
35  virtual std::string getClassName() const { return "graph_analysis::gui::layouts::GridLayout"; }
36 
38 
39  //virtual int rowSpan() const = 0;
40  //virtual int columnSpan() const = 0;
41 
42  ColumnLabels getColumns() const { return mColumnLabels; }
43  virtual RowLabels getRows() const { return mRowLabels; }
44 
45  size_t getColumnIndex(const ColumnLabel&) const;
46  size_t getRowIndex(const RowLabel&) const;
47 
48  ColumnLabel getColumnLabel(const Vertex::Ptr& vertex) const;
49  RowLabel getRowLabel(const Vertex::Ptr& vertex) const;
50 
51  QPointF getPosition(const Vertex::Ptr& vertex) const;
52 
53  void update(const BaseGraph::Ptr& graph,
54  const std::string& layoutName,
56  QGraphicsScene* scene);
57 
58  void setColumnLabelFunction(GetLabelFunction f) { mColumnLabelFunction = f; }
59  void setRowLabelFunction(GetLabelFunction f) { mRowLabelFunction = f; }
60 
61  void setSortColumnLabelFunction(SortLabelFunction f) { mSortColumnLabelFunction = f; }
62  void setSortRowLabelFunction(SortLabelFunction f) { mSortRowLabelFunction = f; }
63 
64  void setColumnScalingFactor(double f) { mColumnScalingFactor = f; }
65  void setRowScalingFactor(double f) { mRowScalingFactor = f; }
66 
67  double getColumnScalingFactor() const { return mColumnScalingFactor; }
68  double getRowScalingFactor() const { return mRowScalingFactor; }
69 
70  void setColumnOffset(double o) { mColumnOffset = o; }
71  void setRowOffset(double o) { mRowOffset = o; }
72 
73  double getColumnOffset() const { return mColumnOffset; }
74  double getRowOffset() const { return mRowOffset; }
75 
79  double getXPosition(const ColumnLabel& columnLabel) const;
80 
84  double getYPosition(const RowLabel& rowLabel) const;
85 
86  std::set<std::string> getSupportedLayouts() const;
87 
91  float currentXPositionInScene(const ColumnLabel& columnLabel) const { return mXPositionInScene.at(columnLabel); }
92  float currentYPositionInScene(const ColumnLabel& columnLabel) const { return mYPositionInScene.at(columnLabel); }
93 
94 
95 private:
96  GetLabelFunction mColumnLabelFunction;
97  GetLabelFunction mRowLabelFunction;
98 
99  SortLabelFunction mSortColumnLabelFunction;
100  SortLabelFunction mSortRowLabelFunction;
101 
102  double mColumnScalingFactor;
103  double mRowScalingFactor;
104 
106  double mColumnOffset;
108  double mRowOffset;
109 
110  ColumnLabels mColumnLabels;
111  RowLabels mRowLabels;
112 
113  QGraphicsGridLayout* mpGridLayout;
115 
116  std::map<ColumnLabel, float> mXPositionInScene;
117  std::map<RowLabel, float> mYPositionInScene;
118 };
119 
120 } // end namespace layouts
121 } // end namespace gui
122 } // end namespace graph_analysis
123 #endif // GRAPH_ANALYSIS_GUI_LAYOUTS_GRID_LAYOUT_HPP
graph_analysis::gui::layouts::GridLayout::setColumnScalingFactor
void setColumnScalingFactor(double f)
Definition: GridLayout.hpp:64
graph_analysis::gui::layouts::GridLayout::getPosition
QPointF getPosition(const Vertex::Ptr &vertex) const
Definition: GridLayout.cpp:51
graph_analysis::gui::layouts::GridLayout::getColumnScalingFactor
double getColumnScalingFactor() const
Definition: GridLayout.hpp:67
graph_analysis::gui::layouts::GridLayout::GridLayout
GridLayout(GetLabelFunction getColumnLabelFunction=GetLabelFunction(), GetLabelFunction getRowLabelFunction=GetLabelFunction())
Definition: GridLayout.cpp:9
graph_analysis::gui::layouts::GridLayout::setRowLabelFunction
void setRowLabelFunction(GetLabelFunction f)
Definition: GridLayout.hpp:59
graph_analysis::gui::layouts::GridLayout::getXPosition
double getXPosition(const ColumnLabel &columnLabel) const
Definition: GridLayout.cpp:59
graph_analysis::gui::layouts::GridLayout::getRowLabel
RowLabel getRowLabel(const Vertex::Ptr &vertex) const
Definition: GridLayout.cpp:81
graph_analysis::gui::layouts::GridLayout::currentXPositionInScene
float currentXPositionInScene(const ColumnLabel &columnLabel) const
Definition: GridLayout.hpp:91
graph_analysis::gui::GraphLayout
Definition: GraphLayout.hpp:10
graph_analysis::gui::GraphWidget::VertexItemCoordinateCache
std::map< const graph_analysis::Vertex::Ptr, QPointF > VertexItemCoordinateCache
Definition: GraphWidget.hpp:90
graph_analysis::gui::layouts::GridLayout::getColumns
ColumnLabels getColumns() const
Definition: GridLayout.hpp:42
graph_analysis::gui::layouts::GridLayout::setSortColumnLabelFunction
void setSortColumnLabelFunction(SortLabelFunction f)
Definition: GridLayout.hpp:61
graph_analysis::gui::layouts::GridLayout::setColumnOffset
void setColumnOffset(double o)
Definition: GridLayout.hpp:70
graph_analysis::gui::layouts::GridLayout::update
void update(const BaseGraph::Ptr &graph, const std::string &layoutName, GraphWidget::VertexItemMap &map, QGraphicsScene *scene)
Definition: GridLayout.cpp:93
graph_analysis
Main namespace of the graph analysis library.
Definition: BFS.cpp:3
graph_analysis::BaseGraph::Ptr
shared_ptr< BaseGraph > Ptr
Definition: BaseGraph.hpp:34
graph_analysis::gui::layouts::GridLayout::RowLabel
std::string RowLabel
Definition: GridLayout.hpp:26
graph_analysis::gui::layouts::GridLayout::getColumnOffset
double getColumnOffset() const
Definition: GridLayout.hpp:73
graph_analysis::gui::layouts::GridLayout::setRowOffset
void setRowOffset(double o)
Definition: GridLayout.hpp:71
graph_analysis::gui::layouts::GridLayout::getYPosition
double getYPosition(const RowLabel &rowLabel) const
Definition: GridLayout.cpp:64
graph_analysis::gui::layouts::GridLayout::getCoordinates
virtual GraphWidget::VertexItemCoordinateCache getCoordinates(const BaseGraph::Ptr &graph) const
Definition: GridLayout.cpp:25
graph_analysis::gui::layouts::GridLayout::getRowOffset
double getRowOffset() const
Definition: GridLayout.hpp:74
graph_analysis::gui::layouts::GridLayout::RowLabels
std::vector< RowLabel > RowLabels
Definition: GridLayout.hpp:28
graph_analysis::gui::layouts::GridLayout::setColumnLabelFunction
void setColumnLabelFunction(GetLabelFunction f)
Definition: GridLayout.hpp:58
graph_analysis::gui::layouts::GridLayout::currentYPositionInScene
float currentYPositionInScene(const ColumnLabel &columnLabel) const
Definition: GridLayout.hpp:92
graph_analysis::gui::layouts::GridLayout::setSortRowLabelFunction
void setSortRowLabelFunction(SortLabelFunction f)
Definition: GridLayout.hpp:62
graph_analysis::gui::layouts::GridLayout::getColumnLabel
ColumnLabel getColumnLabel(const Vertex::Ptr &vertex) const
Definition: GridLayout.cpp:69
graph_analysis::gui::layouts::GridLayout::setRowScalingFactor
void setRowScalingFactor(double f)
Definition: GridLayout.hpp:65
graph_analysis::gui::layouts::GridLayout::ColumnLabels
std::vector< ColumnLabel > ColumnLabels
Definition: GridLayout.hpp:27
graph_analysis::gui::layouts::GridLayout::getSupportedLayouts
std::set< std::string > getSupportedLayouts() const
Definition: GridLayout.cpp:182
graph_analysis::gui::layouts::GridLayout::getRows
virtual RowLabels getRows() const
Definition: GridLayout.hpp:43
graph_analysis::gui::layouts::SortLabelFunction
boost::function2< void, const graph_analysis::BaseGraph::Ptr &, std::vector< std::string > & > SortLabelFunction
Definition: GridLayout.hpp:14
graph_analysis::Vertex::Ptr
shared_ptr< Vertex > Ptr
Definition: Vertex.hpp:22
graph_analysis::gui::layouts::GridLayout
Definition: GridLayout.hpp:21
graph_analysis::gui::layouts::GridLayout::ColumnLabel
std::string ColumnLabel
Definition: GridLayout.hpp:25
graph_analysis::gui::layouts::GridLayout::getRowScalingFactor
double getRowScalingFactor() const
Definition: GridLayout.hpp:68
graph_analysis::gui::layouts::GridLayout::getColumnIndex
size_t getColumnIndex(const ColumnLabel &) const
Definition: GridLayout.cpp:30
graph_analysis::gui::layouts::GridLayout::~GridLayout
virtual ~GridLayout()
Definition: GridLayout.cpp:22
graph_analysis::gui::layouts::GridLayout::getClassName
virtual std::string getClassName() const
Definition: GridLayout.hpp:35
graph_analysis::gui::layouts::GridLayout::getRowIndex
size_t getRowIndex(const RowLabel &) const
Definition: GridLayout.cpp:41
graph_analysis::gui::GraphWidget::VertexItemMap
std::map< const graph_analysis::Vertex::Ptr, VertexItemBase * > VertexItemMap
Definition: GraphWidget.hpp:51
graph_analysis::gui::layouts::GridLayout::Ptr
shared_ptr< GridLayout > Ptr
Definition: GridLayout.hpp:24
graph_analysis::gui::layouts::GetLabelFunction
boost::function1< std::string, const graph_analysis::Vertex::Ptr & > GetLabelFunction
Definition: GridLayout.hpp:13