20 #include <QModelIndex>
52 for (
int i_row = 0; i_row < sampleModel->
rowCount(parentIndex); ++i_row) {
53 QModelIndex itemIndex = sampleModel->
index(i_row, 0, parentIndex);
55 if (view && !view->parentObject()) {
80 double weight1(200.0);
82 QPointF vec = view->mapToItem(other, other->boundingRect().center());
83 qreal dx = view->boundingRect().center().x() - vec.x();
84 qreal dy = view->boundingRect().center().y() - vec.y();
85 double l = (dx * dx + dy * dy);
87 xvel -= (dx * weight1) / l;
88 yvel -= (dy * weight1) / l;
92 double weight2(100.0);
94 QPointF vec = view->mapToItem(other, other->boundingRect().center());
95 qreal dx = view->boundingRect().center().x() - vec.x();
96 qreal dy = view->boundingRect().center().y() - vec.y();
100 QPointF newPos = view->pos() + QPointF(xvel, yvel);
119 QList<IView*> result;
123 QList<SessionItem*> connected_items;
130 connected_items.append(itemOfView->
parent());
132 if (itemOfView->
modelType() ==
"MultiLayer") {
135 for (
auto child : itemOfView->
children()) {
136 connected_items.append(child->children().toList());
139 connected_items.append(itemOfView->
children().toList());
141 for (
auto item : connected_items) {
162 bool force_alignment)
167 if ((force_alignment || view->pos().isNull()) && !view->parentObject())
168 view->setPos(reference);
170 if (view->parentObject()) {
171 reference = view->mapToScene(view->pos());
173 reference = view->pos();
176 int child_counter = 0;
177 for (
int i_row = 0; i_row < sampleModel->
rowCount(parentIndex); ++i_row) {
178 QModelIndex itemIndex = sampleModel->
index(i_row, 0, parentIndex);
181 QPointF child_reference =
182 reference + QPointF(-step_width(), step_height() * child_counter++);
183 alignSample(itemIndex, child_reference, force_alignment);
#define ASSERT(condition)
Defines class DesignerScene.
Defines class SampleModel.
Defines class SampleViewAligner.
DefinesStyleUtils namespace.
Main class which represents SessionModel on graphics scene.
SampleModel * getSampleModel()
IView * getViewForItem(SessionItem *item)
parent class for graphic representation of all ISampleNode's
virtual SessionItem * getItem()
Main model to hold sample items.
void advance()
Applies calculated positions to views.
void updateForces()
Calculates forces acting on all views for smart alignment.
void alignSample(SessionItem *item, QPointF reference={}, bool force_alignment=false)
Aligns sample starting from.
void smartAlign()
Spring based implified algorithm for smart alignment.
void calculateForces(IView *view)
Calculates forces acting on single view (simplified force directed spring algorithm) and deduce new p...
QList< IView * > m_views
list of all views which are subject to smart align
QList< IView * > getConnectedViews(IView *view)
Returns list of views connected with given view for the subsequent force calculation.
void updateViews(const QModelIndex &parentIndex={})
Forms list of all views which are subject for smart alignment (i.e.
QMap< IView *, QPointF > m_viewToPos
IView * getViewForIndex(const QModelIndex &index)
SampleViewAligner(DesignerScene *scene)
SessionItem * parent() const
Returns parent of this item.
QVector< SessionItem * > children() const
Returns vector of all children.
QString modelType() const
Get model type.
SessionItem * itemForIndex(const QModelIndex &index) const
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
virtual int rowCount(const QModelIndex &parent) const
QModelIndex indexOfItem(SessionItem *item) const
QSize SizeOfLetterM(const QWidget *widget=nullptr)
Returns size of largest letter of default system font.