own treelayout class
This commit is contained in:
1 parent
60e8cb3620
commit
213d8cd5c1
2 files changed
+52
No files matched your search
@@ -0,0 +1,20 @@
|
||||
#include "treelayout.h"
|
||||
|
||||
void
|
||||
OneLevelTreeLayout::setOneLevelLayout(std::vector<Coordinate> &childNodesCo)
|
||||
{
|
||||
if (childNodesCo.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
double y = getLevelDistance();
|
||||
double sd = getSiblingDistance();
|
||||
int n = childNodesCo.size();
|
||||
double x = - (n - 1) * sd / 2;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
childNodesCo[i].x = x;
|
||||
childNodesCo[i].y = y;
|
||||
x += sd;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef TREELAYOUT_H
|
||||
#define TREELAYOUT_H
|
||||
#include <vector>
|
||||
|
||||
class TreeLayout
|
||||
{
|
||||
public:
|
||||
struct Coordinate
|
||||
{
|
||||
double x;
|
||||
double y;
|
||||
};
|
||||
TreeLayout(){}
|
||||
virtual void setOneLevelLayout(std::vector<Coordinate> &childNodesCo){};
|
||||
void setSiblingDistance(int d) {m_siblingDistance = d;}
|
||||
void setLevelDistance(int d) {m_levelDistance = d;}
|
||||
int getSiblingDistance() {return m_siblingDistance;}
|
||||
int getLevelDistance() {return m_levelDistance;}
|
||||
virtual ~TreeLayout(){}
|
||||
private:
|
||||
int m_siblingDistance;
|
||||
int m_levelDistance;
|
||||
};
|
||||
|
||||
class OneLevelTreeLayout: public TreeLayout
|
||||
{
|
||||
public:
|
||||
OneLevelTreeLayout(){}
|
||||
virtual void setOneLevelLayout(std::vector<Coordinate> &v, int childNumber);
|
||||
virtual ~OneLevelTreeLayout(){}
|
||||
};
|
||||
#endif
|
||||
Reference in new issue
Block a user