cutter/src/widgets/GraphLayout.h

52 lines
1.3 KiB
C
Raw Normal View History

#ifndef GRAPHLAYOUT_H
#define GRAPHLAYOUT_H
#include "core/Cutter.h"
#include <unordered_map>
class GraphLayout
{
public:
2021-01-24 14:50:13 +00:00
struct GraphEdge
{
ut64 target;
QPolygonF polyline;
2021-01-24 14:50:13 +00:00
enum ArrowDirection { Down, Left, Up, Right, None };
2019-08-03 13:10:44 +00:00
ArrowDirection arrow = ArrowDirection::Down;
2021-01-24 14:50:13 +00:00
explicit GraphEdge(ut64 target) : target(target) {}
};
2021-01-24 14:50:13 +00:00
struct GraphBlock
{
int x = 0;
int y = 0;
int width = 0;
int height = 0;
// This is a unique identifier, e.g. offset in the case of rizin blocks
ut64 entry;
// Edges
std::vector<GraphEdge> edges;
};
2019-08-03 13:10:44 +00:00
using Graph = std::unordered_map<ut64, GraphBlock>;
2021-01-24 14:50:13 +00:00
struct LayoutConfig
{
int blockVerticalSpacing = 40;
int blockHorizontalSpacing = 20;
int edgeVerticalSpacing = 10;
int edgeHorizontalSpacing = 10;
};
GraphLayout(const LayoutConfig &layout_config) : layoutConfig(layout_config) {}
virtual ~GraphLayout() {}
2021-01-24 14:50:13 +00:00
virtual void CalculateLayout(Graph &blocks, ut64 entry, int &width, int &height) const = 0;
virtual void setLayoutConfig(const LayoutConfig &config) { this->layoutConfig = config; };
protected:
LayoutConfig layoutConfig;
};
#endif // GRAPHLAYOUT_H